* Content side new physics structure * BroadPhase outline done * But we need to fix WorldAABB * Fix static pvs AABB * Fix import * Rando fixes * B is for balloon * Change human mob hitbox to circle * Decent movement * Start adding friction to player controller I think it's the best way to go about it to keep other objects somewhat consistent for physics. * This baby can fit so many physics bugs in it. * Slight mob mover optimisations. * Player mover kinda works okay. * Beginnings of testbed * More testbed * Circlestack bed * Namespaces * BB fixes * Pull WorldAABB * Joint pulling * Semi-decent movement I guess. * Pulling better * Bullet controller + old movement * im too dumb for this shit * Use kinematic mob controller again It's probably for the best TBH * Stashed shitcode * Remove SlipController * In which movement code is entirely refactored * Singularity fix * Fix ApplyLinearImpulse * MoveRelay fix * Fix door collisions * Disable subfloor collisions Saves on broadphase a fair bit * Re-implement ClimbController * Zumzum's pressure * Laggy item throwing * Minor atmos change * Some caching * Optimise controllers * Optimise CollideWith to hell and back * Re-do throwing and tile friction * Landing too * Optimise controllers * Move CCVars and other stuff swept is beautiful * Cleanup a bunch of controllers * Fix shooting and high pressure movement controller * Flashing improvements * Stuff and things * Combat collisions * Combat mode collisions * Pulling distance joint again * Cleanup physics interfaces * More like scuffedularity * Shit's fucked * Haha tests go green * Bigmoneycrab Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
75 lines
3.0 KiB
C#
75 lines
3.0 KiB
C#
using System;
|
|
using Content.Server.GameObjects.Components.Mobs;
|
|
using Content.Shared.Audio;
|
|
using Content.Shared.Damage;
|
|
using Content.Shared.GameObjects.Components.Damage;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Physics;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Server.GameObjects.Components.Damage
|
|
{
|
|
[RegisterComponent]
|
|
public class DamageOnHighSpeedImpactComponent : Component, ICollideBehavior
|
|
{
|
|
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
|
|
public override string Name => "DamageOnHighSpeedImpact";
|
|
|
|
public DamageType Damage { get; set; } = DamageType.Blunt;
|
|
public float MinimumSpeed { get; set; } = 20f;
|
|
public int BaseDamage { get; set; } = 5;
|
|
public float Factor { get; set; } = 0.75f;
|
|
public string SoundHit { get; set; } = "";
|
|
public float StunChance { get; set; } = 0.25f;
|
|
public int StunMinimumDamage { get; set; } = 10;
|
|
public float StunSeconds { get; set; } = 1f;
|
|
public float DamageCooldown { get; set; } = 2f;
|
|
private TimeSpan _lastHit = TimeSpan.Zero;
|
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
{
|
|
base.ExposeData(serializer);
|
|
|
|
serializer.DataField(this, x => x.Damage, "damage", DamageType.Blunt);
|
|
serializer.DataField(this, x => x.MinimumSpeed, "minimumSpeed", 20f);
|
|
serializer.DataField(this, x => x.BaseDamage, "baseDamage", 5);
|
|
serializer.DataField(this, x => x.Factor, "factor", 1f);
|
|
serializer.DataField(this, x => x.SoundHit, "soundHit", "");
|
|
serializer.DataField(this, x => x.StunChance, "stunChance", 0.25f);
|
|
serializer.DataField(this, x => x.StunSeconds, "stunSeconds", 1f);
|
|
serializer.DataField(this, x => x.DamageCooldown, "damageCooldown", 2f);
|
|
serializer.DataField(this, x => x.StunMinimumDamage, "stunMinimumDamage", 10);
|
|
}
|
|
|
|
public void CollideWith(IPhysBody ourBody, IPhysBody otherBody)
|
|
{
|
|
if (!Owner.TryGetComponent(out IDamageableComponent damageable)) return;
|
|
|
|
var speed = ourBody.LinearVelocity.Length;
|
|
|
|
if (speed < MinimumSpeed) return;
|
|
|
|
if(!string.IsNullOrEmpty(SoundHit))
|
|
EntitySystem.Get<AudioSystem>().PlayFromEntity(SoundHit, otherBody.Entity, AudioHelpers.WithVariation(0.125f).WithVolume(-0.125f));
|
|
|
|
if ((_gameTiming.CurTime - _lastHit).TotalSeconds < DamageCooldown)
|
|
return;
|
|
|
|
_lastHit = _gameTiming.CurTime;
|
|
|
|
var damage = (int) (BaseDamage * (speed / MinimumSpeed) * Factor);
|
|
|
|
if (Owner.TryGetComponent(out StunnableComponent stun) && _robustRandom.Prob(StunChance))
|
|
stun.Stun(StunSeconds);
|
|
|
|
damageable.ChangeDamage(Damage, damage, false, otherBody.Entity);
|
|
}
|
|
}
|
|
}
|