Remove ILand (#4582)
* Remove ILand * Make land not handleable * Rename ILand
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using Content.Server.Damage.Components;
|
||||
using Content.Server.Stunnable.Components;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Damage.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Damage.Systems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
internal sealed class DamageOnHighSpeedImpactSystem: EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<DamageOnHighSpeedImpactComponent, StartCollideEvent>(HandleCollide);
|
||||
}
|
||||
|
||||
private void HandleCollide(EntityUid uid, DamageOnHighSpeedImpactComponent component, StartCollideEvent args)
|
||||
{
|
||||
if (!ComponentManager.TryGetComponent(uid, out IDamageableComponent? damageable)) return;
|
||||
|
||||
var otherBody = args.OtherFixture.Body.Owner;
|
||||
var speed = args.OurFixture.Body.LinearVelocity.Length;
|
||||
|
||||
if (speed < component.MinimumSpeed) return;
|
||||
|
||||
SoundSystem.Play(Filter.Pvs(otherBody), component.SoundHit.GetSound(), otherBody, AudioHelpers.WithVariation(0.125f).WithVolume(-0.125f));
|
||||
|
||||
if ((_gameTiming.CurTime - component.LastHit).TotalSeconds < component.DamageCooldown)
|
||||
return;
|
||||
|
||||
component.LastHit = _gameTiming.CurTime;
|
||||
|
||||
var damage = (int) (component.BaseDamage * (speed / component.MinimumSpeed) * component.Factor);
|
||||
|
||||
if (ComponentManager.TryGetComponent(uid, out StunnableComponent? stun) && _robustRandom.Prob(component.StunChance))
|
||||
stun.Stun(component.StunSeconds);
|
||||
|
||||
damageable.TryChangeDamage(component.DamageType, damage);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Content.Server/Damage/Systems/DamageOnLandSystem.cs
Normal file
35
Content.Server/Damage/Systems/DamageOnLandSystem.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Content.Server.Damage.Components;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Components;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Damage.Systems
|
||||
{
|
||||
public sealed class DamageOnLandSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<DamageOnLandComponent, ComponentInit>(HandleInit);
|
||||
SubscribeLocalEvent<DamageOnLandComponent, LandEvent>(DamageOnLand);
|
||||
}
|
||||
|
||||
private void HandleInit(EntityUid uid, DamageOnLandComponent component, ComponentInit args)
|
||||
{
|
||||
component.DamageType = _protoManager.Index<DamageTypePrototype>(component.DamageTypeId);
|
||||
}
|
||||
|
||||
private void DamageOnLand(EntityUid uid, DamageOnLandComponent component, LandEvent args)
|
||||
{
|
||||
if (!ComponentManager.TryGetComponent<IDamageableComponent>(uid, out var damageable))
|
||||
return;
|
||||
|
||||
damageable.TryChangeDamage(component.DamageType, component.Amount, component.IgnoreResistances);
|
||||
}
|
||||
}
|
||||
}
|
||||
23
Content.Server/Damage/Systems/DamageOtherOnHitSystem.cs
Normal file
23
Content.Server/Damage/Systems/DamageOtherOnHitSystem.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Content.Server.Damage.Components;
|
||||
using Content.Shared.Damage.Components;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Damage.Systems
|
||||
{
|
||||
public class DamageOtherOnHitSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<DamageOtherOnHitComponent, ThrowDoHitEvent>(OnDoHit);
|
||||
}
|
||||
|
||||
private void OnDoHit(EntityUid uid, DamageOtherOnHitComponent component, ThrowDoHitEvent args)
|
||||
{
|
||||
if (!args.Target.TryGetComponent(out IDamageableComponent? damageable))
|
||||
return;
|
||||
|
||||
damageable.TryChangeDamage(component.DamageType, component.Amount, component.IgnoreResistances);
|
||||
}
|
||||
}
|
||||
}
|
||||
136
Content.Server/Damage/Systems/GodmodeSystem.cs
Normal file
136
Content.Server/Damage/Systems/GodmodeSystem.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Components;
|
||||
using Content.Shared.GameTicking;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Damage.Systems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class GodmodeSystem : EntitySystem
|
||||
{
|
||||
private readonly Dictionary<IEntity, OldEntityInformation> _entities = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
|
||||
}
|
||||
|
||||
public void Reset(RoundRestartCleanupEvent ev)
|
||||
{
|
||||
_entities.Clear();
|
||||
}
|
||||
|
||||
public bool EnableGodmode(IEntity entity)
|
||||
{
|
||||
if (_entities.ContainsKey(entity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_entities[entity] = new OldEntityInformation(entity);
|
||||
|
||||
if (entity.TryGetComponent(out MovedByPressureComponent? moved))
|
||||
{
|
||||
moved.Enabled = false;
|
||||
}
|
||||
|
||||
if (entity.TryGetComponent(out IDamageableComponent? damageable))
|
||||
{
|
||||
damageable.SupportedDamageTypes.Clear();
|
||||
damageable.FullySupportedDamageGroups.Clear();
|
||||
damageable.ApplicableDamageGroups.Clear();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool HasGodmode(IEntity entity)
|
||||
{
|
||||
return _entities.ContainsKey(entity);
|
||||
}
|
||||
|
||||
public bool DisableGodmode(IEntity entity)
|
||||
{
|
||||
if (!_entities.Remove(entity, out var old))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entity.TryGetComponent(out MovedByPressureComponent? moved))
|
||||
{
|
||||
moved.Enabled = old.MovedByPressure;
|
||||
}
|
||||
|
||||
if (entity.TryGetComponent(out IDamageableComponent? damageable))
|
||||
{
|
||||
if (old.SupportedDamageTypes != null)
|
||||
{
|
||||
damageable.SupportedDamageTypes.UnionWith(old.SupportedDamageTypes);
|
||||
}
|
||||
|
||||
if (old.SupportedDamageGroups != null)
|
||||
{
|
||||
damageable.FullySupportedDamageGroups.UnionWith(old.SupportedDamageGroups);
|
||||
}
|
||||
|
||||
if (old.ApplicableDamageGroups != null)
|
||||
{
|
||||
damageable.ApplicableDamageGroups.UnionWith(old.ApplicableDamageGroups);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Toggles godmode for a given entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity to toggle godmode for.</param>
|
||||
/// <returns>true if enabled, false if disabled.</returns>
|
||||
public bool ToggleGodmode(IEntity entity)
|
||||
{
|
||||
if (HasGodmode(entity))
|
||||
{
|
||||
DisableGodmode(entity);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
EnableGodmode(entity);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class OldEntityInformation
|
||||
{
|
||||
public OldEntityInformation(IEntity entity)
|
||||
{
|
||||
Entity = entity;
|
||||
MovedByPressure = entity.IsMovedByPressure();
|
||||
|
||||
if (entity.TryGetComponent(out IDamageableComponent? damageable))
|
||||
{
|
||||
SupportedDamageTypes = damageable.SupportedDamageTypes.ToHashSet();
|
||||
SupportedDamageGroups = damageable.FullySupportedDamageGroups.ToHashSet();
|
||||
ApplicableDamageGroups = damageable.ApplicableDamageGroups.ToHashSet();
|
||||
}
|
||||
}
|
||||
|
||||
public IEntity Entity { get; }
|
||||
|
||||
public bool MovedByPressure { get; }
|
||||
|
||||
public HashSet<DamageTypePrototype>? SupportedDamageTypes { get; }
|
||||
|
||||
public HashSet<DamageGroupPrototype>? SupportedDamageGroups { get; }
|
||||
|
||||
public HashSet<DamageGroupPrototype>? ApplicableDamageGroups { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user