/// <summary> /// Attempts to set the damage value for the given <see cref="DamageType"/>. /// </summary> /// <returns> /// True if successful, false if this container does not support that type. /// </returns> public bool TrySetDamageValue(DamageType type, int newValue) { if (newValue < 0) { return(false); } var damageClass = type.ToClass(); if (SupportedClasses.Contains(damageClass)) { var old = _damageList[type] = newValue; _damageList[type] = newValue; var delta = newValue - old; var datum = new HealthChangeData(type, newValue, delta); var data = new List <HealthChangeData> { datum }; OnHealthChanged(data); return(true); } return(false); }
/// <summary> /// Attempts to change the damage value for the given /// <see cref="DamageType"/> /// </summary> /// <returns> /// True if successful, false if this container does not support that type. /// </returns> public bool TryChangeDamageValue(DamageType type, int delta) { var damageClass = type.ToClass(); if (SupportsDamageClass(damageClass)) { var current = _damageList[type]; current = _damageList[type] = current + delta; if (_damageList[type] < 0) { _damageList[type] = 0; delta = -current; current = 0; } var datum = new HealthChangeData(type, current, delta); var data = new List <HealthChangeData> { datum }; OnHealthChanged(data); return(true); } return(false); }
public bool SupportsDamageType(DamageType type) { return(SupportedClasses.Contains(type.ToClass())); }