Move damage class and type mappings to DamageSystem (#2784)
* Move damage class and type mappings to DamageSystem * Make the properties static again
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Damage
|
||||
@@ -18,27 +20,21 @@ namespace Content.Shared.Damage
|
||||
|
||||
public static class DamageClassExtensions
|
||||
{
|
||||
// TODO DAMAGE This but not hardcoded
|
||||
private static readonly ImmutableDictionary<DamageClass, List<DamageType>> ClassToType =
|
||||
new Dictionary<DamageClass, List<DamageType>>
|
||||
{
|
||||
{DamageClass.Brute, new List<DamageType> {DamageType.Blunt, DamageType.Slash, DamageType.Piercing}},
|
||||
{DamageClass.Burn, new List<DamageType> {DamageType.Heat, DamageType.Shock, DamageType.Cold}},
|
||||
{DamageClass.Toxin, new List<DamageType> {DamageType.Poison, DamageType.Radiation}},
|
||||
{DamageClass.Airloss, new List<DamageType> {DamageType.Asphyxiation, DamageType.Bloodloss}},
|
||||
{DamageClass.Genetic, new List<DamageType> {DamageType.Cellular}}
|
||||
}.ToImmutableDictionary();
|
||||
|
||||
public static List<DamageType> ToTypes(this DamageClass @class)
|
||||
public static ImmutableList<DamageType> ToTypes(this DamageClass @class)
|
||||
{
|
||||
return ClassToType[@class];
|
||||
return DamageSystem.ClassToType[@class];
|
||||
}
|
||||
|
||||
public static Dictionary<DamageClass, int> ToDictionary()
|
||||
public static Dictionary<DamageClass, T> ToNewDictionary<T>()
|
||||
{
|
||||
return Enum.GetValues(typeof(DamageClass))
|
||||
.Cast<DamageClass>()
|
||||
.ToDictionary(@class => @class, type => 0);
|
||||
.ToDictionary(@class => @class, _ => default(T));
|
||||
}
|
||||
|
||||
public static Dictionary<DamageClass, int> ToNewDictionary()
|
||||
{
|
||||
return ToNewDictionary<int>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Damage
|
||||
@@ -24,38 +25,26 @@ namespace Content.Shared.Damage
|
||||
|
||||
public static class DamageTypeExtensions
|
||||
{
|
||||
// TODO: Automatically generate this
|
||||
private static readonly ImmutableDictionary<DamageType, DamageClass> TypeToClass =
|
||||
new Dictionary<DamageType, DamageClass>
|
||||
{
|
||||
{DamageType.Blunt, DamageClass.Brute},
|
||||
{DamageType.Slash, DamageClass.Brute},
|
||||
{DamageType.Piercing, DamageClass.Brute},
|
||||
{DamageType.Heat, DamageClass.Burn},
|
||||
{DamageType.Shock, DamageClass.Burn},
|
||||
{DamageType.Cold, DamageClass.Burn},
|
||||
{DamageType.Poison, DamageClass.Toxin},
|
||||
{DamageType.Radiation, DamageClass.Toxin},
|
||||
{DamageType.Asphyxiation, DamageClass.Airloss},
|
||||
{DamageType.Bloodloss, DamageClass.Airloss},
|
||||
{DamageType.Cellular, DamageClass.Genetic}
|
||||
}.ToImmutableDictionary();
|
||||
|
||||
public static DamageClass ToClass(this DamageType type)
|
||||
{
|
||||
return TypeToClass[type];
|
||||
return DamageSystem.TypeToClass[type];
|
||||
}
|
||||
|
||||
public static Dictionary<DamageType, int> ToDictionary()
|
||||
public static Dictionary<DamageType, T> ToNewDictionary<T>()
|
||||
{
|
||||
return Enum.GetValues(typeof(DamageType))
|
||||
.Cast<DamageType>()
|
||||
.ToDictionary(type => type, type => 0);
|
||||
.ToDictionary(type => type, _ => default(T));
|
||||
}
|
||||
|
||||
public static Dictionary<DamageType, int> ToNewDictionary()
|
||||
{
|
||||
return ToNewDictionary<int>();
|
||||
}
|
||||
|
||||
public static Dictionary<DamageClass, int> ToClassDictionary(IReadOnlyDictionary<DamageType, int> types)
|
||||
{
|
||||
var classes = DamageClassExtensions.ToDictionary();
|
||||
var classes = DamageClassExtensions.ToNewDictionary();
|
||||
|
||||
foreach (var @class in classes.Keys.ToList())
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Content.Shared.GameObjects.Components.Damage
|
||||
|
||||
public override uint? NetID => ContentNetIDs.DAMAGEABLE;
|
||||
|
||||
private readonly Dictionary<DamageType, int> _damageList = DamageTypeExtensions.ToDictionary();
|
||||
private readonly Dictionary<DamageType, int> _damageList = DamageTypeExtensions.ToNewDictionary();
|
||||
private readonly HashSet<DamageType> _supportedTypes = new();
|
||||
private readonly HashSet<DamageClass> _supportedClasses = new();
|
||||
private DamageFlag _flags;
|
||||
|
||||
67
Content.Shared/GameObjects/EntitySystems/DamageSystem.cs
Normal file
67
Content.Shared/GameObjects/EntitySystems/DamageSystem.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using Content.Shared.Damage;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
|
||||
namespace Content.Shared.GameObjects.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class DamageSystem : EntitySystem
|
||||
{
|
||||
public static ImmutableDictionary<DamageClass, ImmutableList<DamageType>> ClassToType { get; } = DefaultClassToType();
|
||||
|
||||
public static ImmutableDictionary<DamageType, DamageClass> TypeToClass { get; } = DefaultTypeToClass();
|
||||
|
||||
private static ImmutableDictionary<DamageClass, ImmutableList<DamageType>> DefaultClassToType()
|
||||
{
|
||||
return new Dictionary<DamageClass, ImmutableList<DamageType>>
|
||||
{
|
||||
[DamageClass.Brute] = new List<DamageType>
|
||||
{
|
||||
DamageType.Blunt,
|
||||
DamageType.Slash,
|
||||
DamageType.Piercing
|
||||
}.ToImmutableList(),
|
||||
[DamageClass.Burn] = new List<DamageType>
|
||||
{
|
||||
DamageType.Heat,
|
||||
DamageType.Shock,
|
||||
DamageType.Cold
|
||||
}.ToImmutableList(),
|
||||
[DamageClass.Toxin] = new List<DamageType>
|
||||
{
|
||||
DamageType.Poison,
|
||||
DamageType.Radiation
|
||||
}.ToImmutableList(),
|
||||
[DamageClass.Airloss] = new List<DamageType>
|
||||
{
|
||||
DamageType.Asphyxiation,
|
||||
DamageType.Bloodloss
|
||||
}.ToImmutableList(),
|
||||
[DamageClass.Genetic] = new List<DamageType>
|
||||
{
|
||||
DamageType.Cellular
|
||||
}.ToImmutableList()
|
||||
}.ToImmutableDictionary();
|
||||
}
|
||||
|
||||
private static ImmutableDictionary<DamageType, DamageClass> DefaultTypeToClass()
|
||||
{
|
||||
return new Dictionary<DamageType, DamageClass>
|
||||
{
|
||||
{DamageType.Blunt, DamageClass.Brute},
|
||||
{DamageType.Slash, DamageClass.Brute},
|
||||
{DamageType.Piercing, DamageClass.Brute},
|
||||
{DamageType.Heat, DamageClass.Burn},
|
||||
{DamageType.Shock, DamageClass.Burn},
|
||||
{DamageType.Cold, DamageClass.Burn},
|
||||
{DamageType.Poison, DamageClass.Toxin},
|
||||
{DamageType.Radiation, DamageClass.Toxin},
|
||||
{DamageType.Asphyxiation, DamageClass.Airloss},
|
||||
{DamageType.Bloodloss, DamageClass.Airloss},
|
||||
{DamageType.Cellular, DamageClass.Genetic}
|
||||
}.ToImmutableDictionary();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user