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,166 @@
#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Content.Server.Throwing;
using Content.Shared.Explosion;
using Content.Shared.Interaction;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Explosion.Components
{
[RegisterComponent]
public sealed class ClusterFlashComponent : Component, IInteractUsing, IUse
{
public override string Name => "ClusterFlash";
private Container _grenadesContainer = default!;
/// <summary>
/// What we fill our prototype with if we want to pre-spawn with grenades.
/// </summary>
[ViewVariables] [DataField("fillPrototype")]
private string? _fillPrototype;
/// <summary>
/// If we have a pre-fill how many more can we spawn.
/// </summary>
private int _unspawnedCount;
/// <summary>
/// Maximum grenades in the container.
/// </summary>
[ViewVariables] [DataField("maxGrenadesCount")]
private int _maxGrenades = 3;
/// <summary>
/// How long until our grenades are shot out and armed.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)] [DataField("delay")]
private float _delay = 1;
/// <summary>
/// Max distance grenades can be thrown.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)] [DataField("distance")]
private float _throwDistance = 50;
/// <summary>
/// This is the end.
/// </summary>
private bool _countDown;
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs args)
{
if (_grenadesContainer.ContainedEntities.Count >= _maxGrenades || !args.Using.HasComponent<FlashExplosiveComponent>())
return false;
_grenadesContainer.Insert(args.Using);
UpdateAppearance();
return true;
}
public override void Initialize()
{
base.Initialize();
_grenadesContainer = ContainerHelpers.EnsureContainer<Container>(Owner, "cluster-flash");
}
protected override void Startup()
{
base.Startup();
if (_fillPrototype != null)
{
_unspawnedCount = Math.Max(0, _maxGrenades - _grenadesContainer.ContainedEntities.Count);
UpdateAppearance();
}
}
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
{
if (_countDown || (_grenadesContainer.ContainedEntities.Count + _unspawnedCount) <= 0)
return false;
Owner.SpawnTimer((int) (_delay * 1000), () =>
{
if (Owner.Deleted)
return;
_countDown = true;
var random = IoCManager.Resolve<IRobustRandom>();
var delay = 20;
var grenadesInserted = _grenadesContainer.ContainedEntities.Count + _unspawnedCount;
var thrownCount = 0;
var segmentAngle = (int) (360 / grenadesInserted);
while (TryGetGrenade(out var grenade))
{
var angleMin = segmentAngle * thrownCount;
var angleMax = segmentAngle * (thrownCount + 1);
var angle = Angle.FromDegrees(random.Next(angleMin, angleMax));
// var distance = random.NextFloat() * _throwDistance;
delay += random.Next(550, 900);
thrownCount++;
// TODO: Suss out throw strength
grenade.TryThrow(angle.ToVec().Normalized * _throwDistance);
grenade.SpawnTimer(delay, () =>
{
if (grenade.Deleted)
return;
if (grenade.TryGetComponent(out OnUseTimerTriggerComponent? useTimer))
{
useTimer.Trigger(eventArgs.User);
}
});
}
Owner.Delete();
});
return true;
}
private bool TryGetGrenade([NotNullWhen(true)] out IEntity? grenade)
{
grenade = null;
if (_unspawnedCount > 0)
{
_unspawnedCount--;
grenade = Owner.EntityManager.SpawnEntity(_fillPrototype, Owner.Transform.MapPosition);
return true;
}
if (_grenadesContainer.ContainedEntities.Count > 0)
{
grenade = _grenadesContainer.ContainedEntities[0];
// This shouldn't happen but you never know.
if (!_grenadesContainer.Remove(grenade))
return false;
return true;
}
return false;
}
private void UpdateAppearance()
{
if (!Owner.TryGetComponent(out AppearanceComponent? appearance)) return;
appearance.SetData(ClusterFlashVisuals.GrenadesCounter, _grenadesContainer.ContainedEntities.Count + _unspawnedCount);
}
}
}

View File

@@ -0,0 +1,30 @@
using Content.Server.Throwing;
using Content.Shared.Acts;
using Robust.Shared.GameObjects;
namespace Content.Server.Explosion.Components
{
[RegisterComponent]
public class ExplosionLaunchedComponent : Component, IExAct
{
public override string Name => "ExplosionLaunched";
void IExAct.OnExplosion(ExplosionEventArgs eventArgs)
{
if (Owner.Deleted)
return;
var sourceLocation = eventArgs.Source;
var targetLocation = eventArgs.Target.Transform.Coordinates;
var direction = (targetLocation.ToMapPos(Owner.EntityManager) - sourceLocation.ToMapPos(Owner.EntityManager)).Normalized;
var throwForce = eventArgs.Severity switch
{
ExplosionSeverity.Heavy => 30,
ExplosionSeverity.Light => 20,
_ => 0,
};
Owner.TryThrow(direction * throwForce);
}
}
}

View File

@@ -0,0 +1,48 @@
using Content.Shared.Acts;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Explosion.Components
{
[RegisterComponent]
public class ExplosiveComponent : Component, ITimerTrigger, IDestroyAct
{
public override string Name => "Explosive";
[DataField("devastationRange")]
public int DevastationRange;
[DataField("heavyImpactRange")]
public int HeavyImpactRange;
[DataField("lightImpactRange")]
public int LightImpactRange;
[DataField("flashRange")]
public int FlashRange;
public bool Exploding { get; private set; } = false;
public bool Explosion()
{
if (Exploding)
{
return false;
}
else
{
Exploding = true;
Owner.SpawnExplosion(DevastationRange, HeavyImpactRange, LightImpactRange, FlashRange);
Owner.QueueDelete();
return true;
}
}
bool ITimerTrigger.Trigger(TimerTriggerEventArgs eventArgs)
{
return Explosion();
}
void IDestroyAct.OnDestroy(DestructionEventArgs eventArgs)
{
Explosion();
}
}
}

View File

@@ -0,0 +1,27 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Physics.Collision;
using Robust.Shared.Physics.Dynamics;
namespace Content.Server.Explosion.Components
{
[RegisterComponent]
public class ExplosiveProjectileComponent : Component, IStartCollide
{
public override string Name => "ExplosiveProjectile";
public override void Initialize()
{
base.Initialize();
Owner.EnsureComponent<ExplosiveComponent>();
}
void IStartCollide.CollideWith(Fixture ourFixture, Fixture otherFixture, in Manifold manifold)
{
if (Owner.TryGetComponent(out ExplosiveComponent? explosive))
{
explosive.Explosion();
}
}
}
}

View File

@@ -0,0 +1,61 @@
using Content.Server.Flash.Components;
using Content.Server.Storage.Components;
using Content.Shared.Acts;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Player;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Explosion.Components
{
/// <summary>
/// When triggered will flash in an area around the object and destroy itself
/// </summary>
[RegisterComponent]
public class FlashExplosiveComponent : Component, ITimerTrigger, IDestroyAct
{
public override string Name => "FlashExplosive";
[DataField("range")]
private float _range = 7.0f;
[DataField("duration")]
private float _duration = 8.0f;
[DataField("sound")]
private string _sound = "/Audio/Effects/flash_bang.ogg";
[DataField("deleteOnFlash")]
private bool _deleteOnFlash = true;
public bool Explode()
{
// If we're in a locker or whatever then can't flash anything
Owner.TryGetContainer(out var container);
if (container == null || !container.Owner.HasComponent<EntityStorageComponent>())
{
FlashableComponent.FlashAreaHelper(Owner, _range, _duration);
}
if (_sound != null)
{
SoundSystem.Play(Filter.Pvs(Owner), _sound, Owner.Transform.Coordinates);
}
if (_deleteOnFlash && !Owner.Deleted)
{
Owner.Delete();
}
return true;
}
bool ITimerTrigger.Trigger(TimerTriggerEventArgs eventArgs)
{
return Explode();
}
void IDestroyAct.OnDestroy(DestructionEventArgs eventArgs)
{
Explode();
}
}
}

View File

@@ -0,0 +1,33 @@
#nullable enable
using System;
using Content.Shared.Interaction;
using Content.Shared.Trigger;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Explosion.Components
{
[RegisterComponent]
public class OnUseTimerTriggerComponent : Component, IUse
{
public override string Name => "OnUseTimerTrigger";
[DataField("delay")]
private float _delay = 0f;
public void Trigger(IEntity user)
{
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
appearance.SetData(TriggerVisuals.VisualState, TriggerVisualState.Primed);
EntitySystem.Get<TriggerSystem>().HandleTimerTrigger(TimeSpan.FromSeconds(_delay), user, Owner);
}
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
{
Trigger(eventArgs.User);
return true;
}
}
}