ResistanceSet Yaml serialization (#1484)
* ResistanceSet serialization * DefaultResistanceSet * remove wall resistance * ResistanceSet ExposeData fix * Remove commented out code Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
@@ -34,7 +34,8 @@ namespace Content.Server.GameObjects
|
|||||||
public IReadOnlyDictionary<DamageType, int> CurrentDamage => _currentDamage;
|
public IReadOnlyDictionary<DamageType, int> CurrentDamage => _currentDamage;
|
||||||
private Dictionary<DamageType, int> _currentDamage = new Dictionary<DamageType, int>();
|
private Dictionary<DamageType, int> _currentDamage = new Dictionary<DamageType, int>();
|
||||||
|
|
||||||
Dictionary<DamageType, List<DamageThreshold>> Thresholds = new Dictionary<DamageType, List<DamageThreshold>>();
|
[ViewVariables]
|
||||||
|
public Dictionary<DamageType, List<DamageThreshold>> Thresholds = new Dictionary<DamageType, List<DamageThreshold>>();
|
||||||
|
|
||||||
public event EventHandler<DamageThresholdPassedEventArgs> DamageThresholdPassed;
|
public event EventHandler<DamageThresholdPassedEventArgs> DamageThresholdPassed;
|
||||||
public event EventHandler<DamageEventArgs> Damaged;
|
public event EventHandler<DamageEventArgs> Damaged;
|
||||||
@@ -47,12 +48,7 @@ namespace Content.Server.GameObjects
|
|||||||
public override void ExposeData(ObjectSerializer serializer)
|
public override void ExposeData(ObjectSerializer serializer)
|
||||||
{
|
{
|
||||||
base.ExposeData(serializer);
|
base.ExposeData(serializer);
|
||||||
|
serializer.DataField(this, x => Resistances, "resistances", ResistanceSet.DefaultResistanceSet);
|
||||||
// TODO: Writing.
|
|
||||||
serializer.DataReadFunction("resistanceset", "honk", name =>
|
|
||||||
{
|
|
||||||
Resistances = ResistanceSet.GetResistanceSet(name);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsDead()
|
public bool IsDead()
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Content.Shared.GameObjects;
|
using Content.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.Serialization;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
using Robust.Shared.ViewVariables;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects
|
namespace Content.Server.GameObjects
|
||||||
{
|
{
|
||||||
@@ -8,49 +11,31 @@ namespace Content.Server.GameObjects
|
|||||||
/// Resistance set used by damageable objects.
|
/// Resistance set used by damageable objects.
|
||||||
/// For each damage type, has a coefficient, damage reduction and "included in total" value.
|
/// For each damage type, has a coefficient, damage reduction and "included in total" value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ResistanceSet
|
public class ResistanceSet : IExposeData
|
||||||
{
|
{
|
||||||
Dictionary<DamageType, ResistanceSetSettings> _resistances = new Dictionary<DamageType, ResistanceSetSettings>();
|
public static ResistanceSet DefaultResistanceSet = new ResistanceSet();
|
||||||
static Dictionary<string, ResistanceSet> _resistanceSets = new Dictionary<string, ResistanceSet>();
|
|
||||||
|
[ViewVariables]
|
||||||
|
private readonly Dictionary<DamageType, ResistanceSetSettings> _resistances = new Dictionary<DamageType, ResistanceSetSettings>();
|
||||||
|
|
||||||
//TODO: make it load from YAML instead of hardcoded like this
|
|
||||||
public ResistanceSet()
|
public ResistanceSet()
|
||||||
{
|
{
|
||||||
_resistances.Add(DamageType.Total, new ResistanceSetSettings(1f, 0, true));
|
foreach (DamageType damageType in Enum.GetValues(typeof(DamageType)))
|
||||||
_resistances.Add(DamageType.Acid, new ResistanceSetSettings(1f, 0, true));
|
|
||||||
_resistances.Add(DamageType.Brute, new ResistanceSetSettings(1f, 0, true));
|
|
||||||
_resistances.Add(DamageType.Heat, new ResistanceSetSettings(1f, 0, true));
|
|
||||||
_resistances.Add(DamageType.Cold, new ResistanceSetSettings(1f, 0, true));
|
|
||||||
_resistances.Add(DamageType.Toxic, new ResistanceSetSettings(1f, 0, true));
|
|
||||||
_resistances.Add(DamageType.Electric, new ResistanceSetSettings(1f, 0, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Loads a resistance set with the given name.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="setName">Name of the resistance set.</param>
|
|
||||||
/// <returns>Resistance set by given name</returns>
|
|
||||||
public static ResistanceSet GetResistanceSet(string setName)
|
|
||||||
{
|
|
||||||
ResistanceSet resistanceSet = null;
|
|
||||||
|
|
||||||
if (!_resistanceSets.TryGetValue(setName, out resistanceSet))
|
|
||||||
{
|
{
|
||||||
resistanceSet = Load(setName);
|
_resistances[damageType] = new ResistanceSetSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
return resistanceSet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ResistanceSet Load(string setName)
|
public void ExposeData(ObjectSerializer serializer)
|
||||||
{
|
{
|
||||||
//TODO: only creates a standard set RN, should be YAMLed
|
foreach (DamageType damageType in Enum.GetValues(typeof(DamageType)))
|
||||||
|
{
|
||||||
ResistanceSet resistanceSet = new ResistanceSet();
|
var resistanceName = damageType.ToString().ToLower();
|
||||||
|
serializer.DataReadFunction(resistanceName, new ResistanceSetSettings(), resistanceSetting =>
|
||||||
_resistanceSets.Add(setName, resistanceSet);
|
{
|
||||||
|
_resistances[damageType] = resistanceSetting;
|
||||||
return resistanceSet;
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -78,23 +63,23 @@ namespace Content.Server.GameObjects
|
|||||||
{
|
{
|
||||||
//Damage that goes straight to total (for whatever reason) never applies twice
|
//Damage that goes straight to total (for whatever reason) never applies twice
|
||||||
|
|
||||||
return damageType == DamageType.Total ? false : _resistances[damageType].AppliesToTotal;
|
return damageType != DamageType.Total && _resistances[damageType].AppliesToTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Settings for a specific damage type in a resistance set.
|
/// Settings for a specific damage type in a resistance set.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
struct ResistanceSetSettings
|
public class ResistanceSetSettings : IExposeData
|
||||||
{
|
{
|
||||||
public float Coefficient { get; private set; }
|
public float Coefficient { get; private set; } = 1;
|
||||||
public int DamageReduction { get; private set; }
|
public int DamageReduction { get; private set; } = 0;
|
||||||
public bool AppliesToTotal { get; private set; }
|
public bool AppliesToTotal { get; private set; } = true;
|
||||||
|
|
||||||
public ResistanceSetSettings(float coefficient, int damageReduction, bool appliesInTotal)
|
public void ExposeData(ObjectSerializer serializer)
|
||||||
{
|
{
|
||||||
Coefficient = coefficient;
|
serializer.DataField(this, x => Coefficient, "coefficient", 1);
|
||||||
DamageReduction = damageReduction;
|
serializer.DataField(this, x => DamageReduction, "damageReduction", 0);
|
||||||
AppliesToTotal = appliesInTotal;
|
serializer.DataField(this, x => AppliesToTotal, "appliesToTotal", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
- type: entity
|
- type: entity
|
||||||
id: base_wall
|
id: base_wall
|
||||||
name: basewall
|
name: basewall
|
||||||
description: Keeps the air in and the greytide out.
|
description: Keeps the air in and the greytide out.
|
||||||
|
|||||||
Reference in New Issue
Block a user