* 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 * Fix dupe pulling * Zumzum's based fix * Don't run tile friction for non-predicted bodies * Experimental pulling improvement * Everything's a poly now * Optimise AI region debugging a bit Could still be better but should improve default performance a LOT * Mover no updater * Crazy kinematic body idea * Good collisions * KinematicController * Fix aghost * Throwing refactor * Pushing cleanup * Fix throwing and footstep sounds * Frametime in ICollideBehavior * Fix stuff * Actually fix weightlessness * Optimise collision behaviors a lot * Make open lockers still collide with walls * powwweeerrrrr * Merge master proper * AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA * AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA * AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA * Ch ch ch changesss * SHIP IT * Fix #if DEBUG * Fix vaulting and item locker collision * Fix throwing * Editing yaml by hand what can go wrong * on * Last yaml fixes * Okay now it's fixed * Linter Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com> Co-authored-by: Vera Aguilera Puerto <zddm@outlook.es>
170 lines
5.8 KiB
C#
170 lines
5.8 KiB
C#
using System;
|
|
using Content.Shared.Damage;
|
|
using Content.Shared.Physics;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Physics;
|
|
using Robust.Shared.Physics.Dynamics;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.Timing;
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
|
|
namespace Content.Server.GameObjects.Components.Projectiles
|
|
{
|
|
/// <summary>
|
|
/// Lasers etc.
|
|
/// </summary>
|
|
[RegisterComponent]
|
|
public class HitscanComponent : Component
|
|
{
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
|
|
public override string Name => "Hitscan";
|
|
public CollisionGroup CollisionMask => (CollisionGroup) _collisionMask;
|
|
|
|
[DataField("layers")] //todo WithFormat.Flags<CollisionLayer>()
|
|
private int _collisionMask = (int) CollisionGroup.Opaque;
|
|
|
|
public float Damage
|
|
{
|
|
get => _damage;
|
|
set => _damage = value;
|
|
}
|
|
[DataField("damage")]
|
|
private float _damage = 10f;
|
|
public DamageType DamageType => _damageType;
|
|
[DataField("damageType")]
|
|
private DamageType _damageType = DamageType.Heat;
|
|
public float MaxLength => 20.0f;
|
|
|
|
private TimeSpan _startTime;
|
|
private TimeSpan _deathTime;
|
|
|
|
public float ColorModifier { get; set; } = 1.0f;
|
|
[DataField("spriteName")]
|
|
private string _spriteName = "Objects/Weapons/Guns/Projectiles/laser.png";
|
|
[DataField("muzzleFlash")]
|
|
private string _muzzleFlash;
|
|
[DataField("impactFlash")]
|
|
private string _impactFlash;
|
|
[DataField("soundHitWall")]
|
|
private string _soundHitWall = "/Audio/Weapons/Guns/Hits/laser_sear_wall.ogg";
|
|
|
|
public void FireEffects(IEntity user, float distance, Angle angle, IEntity hitEntity = null)
|
|
{
|
|
var effectSystem = EntitySystem.Get<EffectSystem>();
|
|
_startTime = _gameTiming.CurTime;
|
|
_deathTime = _startTime + TimeSpan.FromSeconds(1);
|
|
|
|
var afterEffect = AfterEffects(user.Transform.Coordinates, angle, distance, 1.0f);
|
|
if (afterEffect != null)
|
|
{
|
|
effectSystem.CreateParticle(afterEffect);
|
|
}
|
|
|
|
// if we're too close we'll stop the impact and muzzle / impact sprites from clipping
|
|
if (distance > 1.0f)
|
|
{
|
|
var impactEffect = ImpactFlash(distance, angle);
|
|
if (impactEffect != null)
|
|
{
|
|
effectSystem.CreateParticle(impactEffect);
|
|
}
|
|
|
|
var muzzleEffect = MuzzleFlash(user.Transform.Coordinates, angle);
|
|
if (muzzleEffect != null)
|
|
{
|
|
effectSystem.CreateParticle(muzzleEffect);
|
|
}
|
|
}
|
|
|
|
if (hitEntity != null && _soundHitWall != null)
|
|
{
|
|
// TODO: No wall component so ?
|
|
var offset = angle.ToVec().Normalized / 2;
|
|
EntitySystem.Get<AudioSystem>().PlayAtCoords(_soundHitWall, user.Transform.Coordinates.Offset(offset));
|
|
}
|
|
|
|
Owner.SpawnTimer((int) _deathTime.TotalMilliseconds, () =>
|
|
{
|
|
if (!Owner.Deleted)
|
|
{
|
|
Owner.Delete();
|
|
}
|
|
});
|
|
}
|
|
|
|
private EffectSystemMessage MuzzleFlash(EntityCoordinates grid, Angle angle)
|
|
{
|
|
if (_muzzleFlash == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var offset = angle.ToVec().Normalized / 2;
|
|
|
|
var message = new EffectSystemMessage
|
|
{
|
|
EffectSprite = _muzzleFlash,
|
|
Born = _startTime,
|
|
DeathTime = _deathTime,
|
|
Coordinates = grid.Offset(offset),
|
|
//Rotated from east facing
|
|
Rotation = (float) angle.Theta,
|
|
Color = Vector4.Multiply(new Vector4(255, 255, 255, 750), ColorModifier),
|
|
ColorDelta = new Vector4(0, 0, 0, -1500f),
|
|
Shaded = false
|
|
};
|
|
|
|
return message;
|
|
}
|
|
|
|
private EffectSystemMessage AfterEffects(EntityCoordinates origin, Angle angle, float distance, float offset = 0.0f)
|
|
{
|
|
var midPointOffset = angle.ToVec() * distance / 2;
|
|
var message = new EffectSystemMessage
|
|
{
|
|
EffectSprite = _spriteName,
|
|
Born = _startTime,
|
|
DeathTime = _deathTime,
|
|
Size = new Vector2(distance - offset, 1f),
|
|
Coordinates = origin.Offset(midPointOffset),
|
|
//Rotated from east facing
|
|
Rotation = (float) angle.Theta,
|
|
Color = Vector4.Multiply(new Vector4(255, 255, 255, 750), ColorModifier),
|
|
ColorDelta = new Vector4(0, 0, 0, -1500f),
|
|
|
|
Shaded = false
|
|
};
|
|
|
|
return message;
|
|
}
|
|
|
|
private EffectSystemMessage ImpactFlash(float distance, Angle angle)
|
|
{
|
|
if (_impactFlash == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var message = new EffectSystemMessage
|
|
{
|
|
EffectSprite = _impactFlash,
|
|
Born = _startTime,
|
|
DeathTime = _deathTime,
|
|
Coordinates = Owner.Transform.Coordinates.Offset(angle.ToVec() * distance),
|
|
//Rotated from east facing
|
|
Rotation = (float) angle.FlipPositive(),
|
|
Color = Vector4.Multiply(new Vector4(255, 255, 255, 750), ColorModifier),
|
|
ColorDelta = new Vector4(0, 0, 0, -1500f),
|
|
Shaded = false
|
|
};
|
|
|
|
return message;
|
|
}
|
|
}
|
|
}
|