Makes repairable component able to heal a set amount of damage (#6852)

This commit is contained in:
SplinterGP
2022-02-23 21:00:39 -03:00
committed by GitHub
parent bee627ac6a
commit 351c518582
2 changed files with 23 additions and 3 deletions

View File

@@ -1,3 +1,4 @@
using Content.Shared.Damage;
using Content.Shared.Tools;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
@@ -9,6 +10,16 @@ namespace Content.Server.Repairable
[RegisterComponent]
public sealed class RepairableComponent : Component
{
/// <summary>
/// All the damage to change information is stored in this <see cref="DamageSpecifier"/>.
/// </summary>
/// <remarks>
/// If this data-field is specified, it will change damage by this amount instead of setting all damage to 0.
/// in order to heal/repair the damage values have to be negative.
/// </remarks>
[ViewVariables(VVAccess.ReadWrite)] [DataField("damage")]
public DamageSpecifier? Damage;
[ViewVariables(VVAccess.ReadWrite)] [DataField("fuelCost")]
public int FuelCost = 5;

View File

@@ -34,9 +34,18 @@ namespace Content.Server.Repairable
if (!await _toolSystem.UseTool(args.Used, args.User, uid, component.FuelCost, component.DoAfterDelay, component.QualityNeeded))
return;
// Repair all damage
_damageableSystem.SetAllDamage(damageable, 0);
_logSystem.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired ${ToPrettyString(uid):target} back to full health");
if (component.Damage != null)
{
var damageChanged = _damageableSystem.TryChangeDamage(uid, component.Damage, true, false);
_logSystem.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(uid):target} by {damageChanged?.Total}");
}
else
{
// Repair all damage
_damageableSystem.SetAllDamage(damageable, 0);
_logSystem.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(uid):target} back to full health");
}
component.Owner.PopupMessage(args.User,
Loc.GetString("comp-repairable-repair",