Revert "Refactor Damage to use Protoypes (#4262)"

This reverts commit 20bf5739a9.
This commit is contained in:
Silver
2021-08-24 00:50:39 -06:00
committed by Silver
parent 20bf5739a9
commit e708091518
121 changed files with 711 additions and 10237 deletions

View File

@@ -1,6 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using Content.Server.Administration;
using Content.Shared.Administration;
@@ -10,7 +9,6 @@ using Robust.Server.Player;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.Server.Damage.Commands
{
@@ -21,24 +19,22 @@ namespace Content.Server.Damage.Commands
public string Description => "Ouch";
public string Help => $"Usage: {Command} <type/?> <amount> (<entity uid/_>) (<ignoreResistances>)";
private readonly IPrototypeManager _prototypeManager = default!;
public HurtCommand() {
_prototypeManager = IoCManager.Resolve<IPrototypeManager>();
}
private string DamageTypes()
{
var msg = new StringBuilder();
foreach (var damageGroup in _prototypeManager.EnumeratePrototypes<DamageGroupPrototype>())
foreach (var dClass in Enum.GetNames(typeof(DamageClass)))
{
msg.Append($"\n{damageGroup.ID}");
if (damageGroup.DamageTypes.Any())
msg.Append($"\n{dClass}");
var types = Enum.Parse<DamageClass>(dClass).ToTypes();
if (types.Count > 0)
{
msg.Append(": ");
msg.AppendJoin('|', damageGroup.DamageTypes);
msg.AppendJoin('|', types);
}
}
return $"Damage Types:{msg}";
}
@@ -89,8 +85,6 @@ namespace Content.Server.Damage.Commands
string[] args,
[NotNullWhen(true)] out Damage? func)
{
if (!int.TryParse(args[1], out var amount))
{
shell.WriteLine($"{args[1]} is not a valid damage integer.");
@@ -99,50 +93,42 @@ namespace Content.Server.Damage.Commands
return false;
}
<<<<<<< HEAD
<<<<<<< refs/remotes/origin/master
if (Enum.TryParse<DamageClass>(args[0], true, out var damageClass))
=======
if (_prototypeManager.TryIndex<DamageGroupPrototype>(args[0], out var damageGroup))
>>>>>>> Refactor damageablecomponent update (#4406)
=======
if (_prototypeManager.TryIndex<DamageGroupPrototype>(args[0], out var damageGroup))
>>>>>>> refactor-damageablecomponent
{
func = (damageable, ignoreResistances) =>
{
if (!damageable.ApplicableDamageGroups.Contains(damageGroup))
if (!damageable.DamageClasses.ContainsKey(damageClass))
{
shell.WriteLine($"Entity {damageable.Owner.Name} with id {damageable.Owner.Uid} can not be damaged with damage group {damageGroup}");
shell.WriteLine($"Entity {damageable.Owner.Name} with id {damageable.Owner.Uid} can not be damaged with damage class {damageClass}");
return;
}
if (!damageable.TryChangeDamage(damageGroup, amount, ignoreResistances))
if (!damageable.ChangeDamage(damageClass, amount, ignoreResistances))
{
shell.WriteLine($"Entity {damageable.Owner.Name} with id {damageable.Owner.Uid} received no damage.");
return;
}
shell.WriteLine($"Damaged entity {damageable.Owner.Name} with id {damageable.Owner.Uid} for {amount} {damageGroup} damage{(ignoreResistances ? ", ignoring resistances." : ".")}");
shell.WriteLine($"Damaged entity {damageable.Owner.Name} with id {damageable.Owner.Uid} for {amount} {damageClass} damage{(ignoreResistances ? ", ignoring resistances." : ".")}");
};
return true;
}
// Fall back to DamageType
else if (_prototypeManager.TryIndex<DamageTypePrototype>(args[0], out var damageType))
else if (Enum.TryParse<DamageType>(args[0], true, out var damageType))
{
func = (damageable, ignoreResistances) =>
{
if (!damageable.IsSupportedDamageType(damageType))
if (!damageable.DamageTypes.ContainsKey(damageType))
{
shell.WriteLine($"Entity {damageable.Owner.Name} with id {damageable.Owner.Uid} can not be damaged with damage type {damageType}");
shell.WriteLine($"Entity {damageable.Owner.Name} with id {damageable.Owner.Uid} can not be damaged with damage class {damageType}");
return;
}
if (!damageable.TryChangeDamage(damageType, amount, ignoreResistances))
if (!damageable.ChangeDamage(damageType, amount, ignoreResistances))
{
shell.WriteLine($"Entity {damageable.Owner.Name} with id {damageable.Owner.Uid} received no damage.");
@@ -150,10 +136,9 @@ namespace Content.Server.Damage.Commands
}
shell.WriteLine($"Damaged entity {damageable.Owner.Name} with id {damageable.Owner.Uid} for {amount} {damageType} damage{(ignoreResistances ? ", ignoring resistances." : ".")}");
};
return true;
return true;
}
else
{

View File

@@ -3,9 +3,6 @@ using Content.Shared.Damage;
using Content.Shared.Sound;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Damage.Components
{
@@ -17,14 +14,8 @@ namespace Content.Server.Damage.Components
{
public override string Name => "DamageOnHighSpeedImpact";
<<<<<<< HEAD
<<<<<<< refs/remotes/origin/master
[DataField("damage")]
public DamageType Damage { get; set; } = DamageType.Blunt;
=======
>>>>>>> Refactor damageablecomponent update (#4406)
=======
>>>>>>> refactor-damageablecomponent
[DataField("minimumSpeed")]
public float MinimumSpeed { get; set; } = 20f;
[DataField("baseDamage")]
@@ -43,17 +34,5 @@ namespace Content.Server.Damage.Components
public float DamageCooldown { get; set; } = 2f;
internal TimeSpan LastHit = TimeSpan.Zero;
// TODO PROTOTYPE Replace this datafield variable with prototype references, once they are supported.
// Also remove Initialize override, if no longer needed.
[DataField("damageType")]
private readonly string _damageTypeID = "Blunt";
[ViewVariables(VVAccess.ReadWrite)]
public DamageTypePrototype DamageType = default!;
protected override void Initialize()
{
base.Initialize();
DamageType = IoCManager.Resolve<IPrototypeManager>().Index<DamageTypePrototype>(_damageTypeID);
}
}
}

View File

@@ -3,9 +3,6 @@ using Content.Shared.Damage.Components;
using Content.Shared.Throwing;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Prototypes;
using Robust.Shared.IoC;
using Robust.Shared.ViewVariables;
namespace Content.Server.Damage.Components
{
@@ -14,59 +11,20 @@ namespace Content.Server.Damage.Components
{
public override string Name => "DamageOnLand";
<<<<<<< HEAD
<<<<<<< refs/remotes/origin/master
[DataField("damageType")]
private DamageType _damageType = DamageType.Blunt;
=======
>>>>>>> Refactor damageablecomponent update (#4406)
=======
>>>>>>> refactor-damageablecomponent
[DataField("amount")]
[ViewVariables(VVAccess.ReadWrite)]
private int _amount = 1;
[DataField("ignoreResistances")]
[ViewVariables(VVAccess.ReadWrite)]
private bool _ignoreResistances;
// TODO PROTOTYPE Replace this datafield variable with prototype references, once they are supported.
// Also remove Initialize override, if no longer needed.
[DataField("damageType")]
private readonly string _damageTypeID = "Blunt";
[ViewVariables(VVAccess.ReadWrite)]
public DamageTypePrototype DamageType = default!;
protected override void Initialize()
<<<<<<< HEAD
{
base.Initialize();
DamageType = IoCManager.Resolve<IPrototypeManager>().Index<DamageTypePrototype>(_damageTypeID);
}
void ILand.Land(LandEventArgs eventArgs)
{
<<<<<<< refs/remotes/origin/master
if (!Owner.TryGetComponent(out IDamageableComponent? damageable)) return;
damageable.ChangeDamage(_damageType, _amount, _ignoreResistances, eventArgs.User);
=======
if (!Owner.TryGetComponent(out IDamageableComponent? damageable))
return;
damageable.TryChangeDamage(DamageType, _amount, _ignoreResistances);
>>>>>>> Refactor damageablecomponent update (#4406)
=======
{
base.Initialize();
DamageType = IoCManager.Resolve<IPrototypeManager>().Index<DamageTypePrototype>(_damageTypeID);
}
void ILand.Land(LandEventArgs eventArgs)
{
if (!Owner.TryGetComponent(out IDamageableComponent? damageable))
return;
damageable.TryChangeDamage(DamageType, _amount, _ignoreResistances);
>>>>>>> refactor-damageablecomponent
}
}
}

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using Content.Server.Tools.Components;
using Content.Shared.Damage;
@@ -7,16 +7,12 @@ using Content.Shared.Interaction;
using Content.Shared.Tool;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Prototypes;
using Robust.Shared.IoC;
using Robust.Shared.ViewVariables;
namespace Content.Server.Damage.Components
{
[RegisterComponent]
public class DamageOnToolInteractComponent : Component, IInteractUsing
{
public override string Name => "DamageOnToolInteract";
[DataField("damage")]
@@ -25,32 +21,6 @@ namespace Content.Server.Damage.Components
[DataField("tools")]
private List<ToolQuality> _tools = new();
<<<<<<< HEAD
<<<<<<< refs/remotes/origin/master
=======
=======
>>>>>>> refactor-damageablecomponent
// TODO PROTOTYPE Replace these datafield variable with prototype references, once they are supported.
// Also remove Initialize override, if no longer needed.
[DataField("weldingDamageType")]
private readonly string _weldingDamageTypeID = "Heat";
[ViewVariables(VVAccess.ReadWrite)]
public DamageTypePrototype WeldingDamageType = default!;
[DataField("defaultDamageType")]
private readonly string _defaultDamageTypeID = "Blunt";
[ViewVariables(VVAccess.ReadWrite)]
public DamageTypePrototype DefaultDamageType = default!;
protected override void Initialize()
{
base.Initialize();
WeldingDamageType = IoCManager.Resolve<IPrototypeManager>().Index<DamageTypePrototype>(_weldingDamageTypeID);
DefaultDamageType = IoCManager.Resolve<IPrototypeManager>().Index<DamageTypePrototype>(_defaultDamageTypeID);
}
<<<<<<< HEAD
>>>>>>> Refactor damageablecomponent update (#4406)
=======
>>>>>>> refactor-damageablecomponent
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
if (eventArgs.Using.TryGetComponent<ToolComponent>(out var tool))
@@ -74,26 +44,17 @@ namespace Content.Server.Damage.Components
protected bool CallDamage(InteractUsingEventArgs eventArgs, ToolComponent tool)
{
if (!eventArgs.Target.TryGetComponent<IDamageableComponent>(out var damageable))
return false;
if (eventArgs.Target.TryGetComponent<IDamageableComponent>(out var damageable))
{
damageable.ChangeDamage(tool.HasQuality(ToolQuality.Welding)
? DamageType.Heat
: DamageType.Blunt,
Damage, false, eventArgs.User);
<<<<<<< HEAD
<<<<<<< refs/remotes/origin/master
return true;
}
=======
=======
>>>>>>> refactor-damageablecomponent
damageable.TryChangeDamage(tool.HasQuality(ToolQuality.Welding)
? WeldingDamageType
: DefaultDamageType,
Damage);
<<<<<<< HEAD
>>>>>>> Refactor damageablecomponent update (#4406)
=======
>>>>>>> refactor-damageablecomponent
return true;
return false;
}
}
}

View File

@@ -2,8 +2,6 @@ using Content.Shared.Damage;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Prototypes;
using Robust.Shared.IoC;
namespace Content.Server.Damage.Components
{
@@ -13,47 +11,13 @@ namespace Content.Server.Damage.Components
{
public override string Name => "DamageOtherOnHit";
<<<<<<< HEAD
<<<<<<< refs/remotes/origin/master
<<<<<<< refs/remotes/origin/master
[DataField("damageType")]
public DamageType DamageType { get; } = DamageType.Blunt;
=======
[DataField("damageType",required: true)]
private readonly string _damageType = default!;
>>>>>>> update damagecomponent across shared and server
=======
>>>>>>> Refactor damageablecomponent update (#4406)
=======
>>>>>>> refactor-damageablecomponent
[DataField("amount")]
public int Amount { get; } = 1;
[DataField("ignoreResistances")]
<<<<<<< HEAD
<<<<<<< refs/remotes/origin/master
<<<<<<< refs/remotes/origin/master
public bool IgnoreResistances { get; } = false;
=======
private bool _ignoreResistances;
=======
public bool IgnoreResistances { get; } = false;
>>>>>>> Bring refactor-damageablecomponent branch up-to-date with master (#4510)
=======
public bool IgnoreResistances { get; } = false;
>>>>>>> refactor-damageablecomponent
// TODO PROTOTYPE Replace this datafield variable with prototype references, once they are supported.
// Also remove Initialize override, if no longer needed.
[DataField("damageType")]
private readonly string _damageTypeID = "Blunt";
public DamageTypePrototype DamageType { get; set; } = default!;
protected override void Initialize()
{
base.Initialize();
DamageType = IoCManager.Resolve<IPrototypeManager>().Index<DamageTypePrototype>(_damageTypeID);
}
>>>>>>> update damagecomponent across shared and server
}
}

View File

@@ -46,7 +46,7 @@ namespace Content.Server.Damage
if (ComponentManager.TryGetComponent(uid, out StunnableComponent? stun) && _robustRandom.Prob(component.StunChance))
stun.Stun(component.StunSeconds);
damageable.TryChangeDamage(component.DamageType, damage);
damageable.ChangeDamage(component.Damage, damage, false, args.OtherFixture.Body.Owner);
}
}
}

View File

@@ -17,15 +17,7 @@ namespace Content.Server.Damage
if (!args.Target.TryGetComponent(out IDamageableComponent? damageable))
return;
<<<<<<< HEAD
<<<<<<< refs/remotes/origin/master
damageable.ChangeDamage(component.DamageType, component.Amount, component.IgnoreResistances, args.User);
=======
damageable.TryChangeDamage(component.DamageType, component.Amount, component.IgnoreResistances);
>>>>>>> Bring refactor-damageablecomponent branch up-to-date with master (#4510)
=======
damageable.TryChangeDamage(component.DamageType, component.Amount, component.IgnoreResistances);
>>>>>>> refactor-damageablecomponent
}
}
}

View File

@@ -1,22 +1,9 @@
<<<<<<< HEAD
<<<<<<< refs/remotes/origin/master
<<<<<<< refs/remotes/origin/master
using System.Collections.Generic;
using Content.Server.Atmos.Components;
=======
#nullable enable
using System.Collections.Generic;
>>>>>>> Merge fixes
=======
using System.Collections.Generic;
>>>>>>> Refactor damageablecomponent update (#4406)
=======
using System.Collections.Generic;
>>>>>>> refactor-damageablecomponent
using System.Linq;
using Content.Server.Atmos.Components;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Resistances;
using Content.Shared.GameTicking;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
@@ -56,9 +43,8 @@ namespace Content.Server.Damage
if (entity.TryGetComponent(out IDamageableComponent? damageable))
{
damageable.SupportedDamageTypes.Clear();
damageable.FullySupportedDamageGroups.Clear();
damageable.ApplicableDamageGroups.Clear();
damageable.SupportedTypes.Clear();
damageable.SupportedClasses.Clear();
}
return true;
@@ -83,33 +69,14 @@ namespace Content.Server.Damage
if (entity.TryGetComponent(out IDamageableComponent? damageable))
{
if (old.SupportedDamageTypes != null)
<<<<<<< HEAD
if (old.SupportedTypes != null)
{
damageable.SupportedDamageTypes.UnionWith(old.SupportedDamageTypes);
damageable.SupportedTypes.UnionWith(old.SupportedTypes);
}
if (old.SupportedDamageGroups != null)
if (old.SupportedClasses != null)
{
damageable.FullySupportedDamageGroups.UnionWith(old.SupportedDamageGroups);
}
if (old.ApplicableDamageGroups != null)
{
=======
{
damageable.SupportedDamageTypes.UnionWith(old.SupportedDamageTypes);
}
if (old.SupportedDamageGroups != null)
{
damageable.FullySupportedDamageGroups.UnionWith(old.SupportedDamageGroups);
}
if (old.ApplicableDamageGroups != null)
{
>>>>>>> refactor-damageablecomponent
damageable.ApplicableDamageGroups.UnionWith(old.ApplicableDamageGroups);
damageable.SupportedClasses.UnionWith(old.SupportedClasses);
}
}
@@ -144,9 +111,8 @@ namespace Content.Server.Damage
if (entity.TryGetComponent(out IDamageableComponent? damageable))
{
SupportedDamageTypes = damageable.SupportedDamageTypes.ToHashSet();
SupportedDamageGroups = damageable.FullySupportedDamageGroups.ToHashSet();
ApplicableDamageGroups = damageable.ApplicableDamageGroups.ToHashSet();
SupportedTypes = damageable.SupportedTypes.ToHashSet();
SupportedClasses = damageable.SupportedClasses.ToHashSet();
}
}
@@ -154,11 +120,9 @@ namespace Content.Server.Damage
public bool MovedByPressure { get; }
public HashSet<DamageTypePrototype>? SupportedDamageTypes { get; }
public HashSet<DamageType>? SupportedTypes { get; }
public HashSet<DamageGroupPrototype>? SupportedDamageGroups { get; }
public HashSet<DamageGroupPrototype>? ApplicableDamageGroups { get; }
public HashSet<DamageClass>? SupportedClasses { get; }
}
}
}

View File

@@ -61,7 +61,7 @@ namespace Content.Server.Damage
{
if (target.TryGetComponent(out IDamageableComponent? damage))
{
damage.TrySetAllDamage(0);
damage.Heal();
}
if (target.TryGetComponent(out IMobStateComponent? mobState))