Re-organize all projects (#4166)

This commit is contained in:
DrSmugleaf
2021-06-09 22:19:39 +02:00
committed by GitHub
parent 9f50e4061b
commit ff1a2d97ea
1773 changed files with 5258 additions and 5508 deletions

View File

@@ -0,0 +1,169 @@
using System;
using Content.Shared.Damage;
using Content.Shared.Physics;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Player;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Timing;
namespace Content.Server.Projectiles.Components
{
/// <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;
var coordinates = user.Transform.Coordinates.Offset(offset);
SoundSystem.Play(Filter.Pvs(coordinates), _soundHitWall, coordinates);
}
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;
}
}
}

View File

@@ -0,0 +1,104 @@
using System.Collections.Generic;
using Content.Server.Camera;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Projectiles;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics.Collision;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Player;
using Robust.Shared.Players;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Projectiles.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedProjectileComponent))]
public class ProjectileComponent : SharedProjectileComponent, IStartCollide
{
[DataField("damages")] private Dictionary<DamageType, int> _damages = new();
[ViewVariables]
public Dictionary<DamageType, int> Damages
{
get => _damages;
set => _damages = value;
}
[DataField("deleteOnCollide")]
public bool DeleteOnCollide { get; } = true;
// Get that juicy FPS hit sound
[DataField("soundHit")]
private string? _soundHit = default;
[DataField("soundHitSpecies")]
private string? _soundHitSpecies = default;
private bool _damagedEntity;
public float TimeLeft { get; set; } = 10;
/// <summary>
/// Function that makes the collision of this object ignore a specific entity so we don't collide with ourselves
/// </summary>
/// <param name="shooter"></param>
public void IgnoreEntity(IEntity shooter)
{
Shooter = shooter.Uid;
Dirty();
}
/// <summary>
/// Applies the damage when our projectile collides with its victim
/// </summary>
void IStartCollide.CollideWith(Fixture ourFixture, Fixture otherFixture, in Manifold manifold)
{
// This is so entities that shouldn't get a collision are ignored.
if (!otherFixture.Hard || _damagedEntity)
{
return;
}
var coordinates = otherFixture.Body.Owner.Transform.Coordinates;
var playerFilter = Filter.Pvs(coordinates);
if (otherFixture.Body.Owner.TryGetComponent(out IDamageableComponent? damage) && _soundHitSpecies != null)
{
SoundSystem.Play(playerFilter, _soundHitSpecies, coordinates);
}
else if (_soundHit != null)
{
SoundSystem.Play(playerFilter, _soundHit, coordinates);
}
if (damage != null)
{
Owner.EntityManager.TryGetEntity(Shooter, out var shooter);
foreach (var (damageType, amount) in _damages)
{
damage.ChangeDamage(damageType, amount, false, shooter);
}
_damagedEntity = true;
}
// Damaging it can delete it
if (!otherFixture.Body.Deleted && otherFixture.Body.Owner.TryGetComponent(out CameraRecoilComponent? recoilComponent))
{
var direction = ourFixture.Body.LinearVelocity.Normalized;
recoilComponent.Kick(direction);
}
if(DeleteOnCollide)
Owner.QueueDelete();
}
public override ComponentState GetComponentState(ICommonSession player)
{
return new ProjectileComponentState(Shooter, IgnoreShooter);
}
}
}

View File

@@ -0,0 +1,25 @@
using Content.Server.Projectiles.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Projectiles
{
[UsedImplicitly]
internal sealed class ProjectileSystem : EntitySystem
{
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var component in ComponentManager.EntityQuery<ProjectileComponent>(true))
{
component.TimeLeft -= frameTime;
if (component.TimeLeft <= 0)
{
component.Owner.Delete();
}
}
}
}
}