mirror of
https://github.com/space-wizards/space-station-14.git
synced 2026-02-14 19:29:53 +01:00
Repairing borgs now takes multiple doafters (#41638)
* borg repair is now multiple doafters * is a float now * use else * remove random new line i added for some reason * add new line at the end of the file * add documentation * made repair system super robust * borg heal faster from crit * forgot to make it a datafield * less overpower * cant repair futher than the threshold for alive if not alive or dead * fix math * more math * fixes * some comentary * more accurate * simple solution * new solution * better numbers * more accurate * use helper function * fine tunning the number * better way to restart the doafter * update AutoDoAfter * not used * more clear * remove inline if * improve helper methods * updare pop up message * another unused * nuke consecutive repair bonus * increase the repair (so it doesn't take ages to fix a borg) * back to 10 per repair * heal evenly * fix for edge case * fix * fix * it works now * add / fix comments * small clean up * make easier to understand * use FixedPoint2.Zero * make it smaller * add support for group even heal * ops * easier to read * typo * make the HealEvenly better * rename to GetDamage * negative value * Update Content.Shared/Repairable/RepairableSystem.cs --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
This commit is contained in:
@@ -17,15 +17,26 @@ public sealed partial class RepairableComponent : Component
|
||||
/// <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.
|
||||
/// This will only be used if <see cref="DamageValue"/> is not null.
|
||||
/// If this is null and so is <see cref="DamageValue"/> then all damage will be repaired at once.
|
||||
/// </remarks>
|
||||
[DataField, AutoNetworkedField]
|
||||
public DamageSpecifier? Damage;
|
||||
|
||||
/// <summary>
|
||||
/// Amount of damage to repair of the entity equaly distributed among the damage types the entity has.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// in order to heal/repair the damage values have to be negative.
|
||||
/// </remarks>
|
||||
[DataField, AutoNetworkedField]
|
||||
public float? DamageValue;
|
||||
|
||||
/// <summary>
|
||||
/// Cost of fuel used to repair this device.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public int FuelCost = 5;
|
||||
public float FuelCost = 5f;
|
||||
|
||||
/// <summary>
|
||||
/// Tool quality necessary to repair this device.
|
||||
@@ -39,6 +50,12 @@ public sealed partial class RepairableComponent : Component
|
||||
[DataField, AutoNetworkedField]
|
||||
public int DoAfterDelay = 1;
|
||||
|
||||
/// <summary>
|
||||
/// If true and after the repair there still damage, a new doafter starts automatically
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public bool AutoDoAfter = true;
|
||||
|
||||
/// <summary>
|
||||
/// A multiplier that will be applied to the above if an entity is repairing themselves.
|
||||
/// </summary>
|
||||
|
||||
@@ -20,10 +20,10 @@ public sealed partial class RepairableSystem : EntitySystem
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<RepairableComponent, InteractUsingEvent>(Repair);
|
||||
SubscribeLocalEvent<RepairableComponent, RepairFinishedEvent>(OnRepairFinished);
|
||||
SubscribeLocalEvent<RepairableComponent, RepairDoAfterEvent>(OnRepairDoAfter);
|
||||
}
|
||||
|
||||
private void OnRepairFinished(Entity<RepairableComponent> ent, ref RepairFinishedEvent args)
|
||||
private void OnRepairDoAfter(Entity<RepairableComponent> ent, ref RepairDoAfterEvent args)
|
||||
{
|
||||
if (args.Cancelled)
|
||||
return;
|
||||
@@ -31,24 +31,62 @@ public sealed partial class RepairableSystem : EntitySystem
|
||||
if (!TryComp(ent.Owner, out DamageableComponent? damageable) || damageable.TotalDamage == 0)
|
||||
return;
|
||||
|
||||
if (ent.Comp.Damage != null)
|
||||
{
|
||||
var damageChanged = _damageableSystem.ChangeDamage(ent.Owner, ent.Comp.Damage, true, false, origin: args.User);
|
||||
_adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(ent.Owner):target} by {damageChanged.GetTotal()}");
|
||||
}
|
||||
|
||||
if (ent.Comp.DamageValue != null)
|
||||
RepairSomeDamage((ent, damageable), ent.Comp.DamageValue.Value, args.User);
|
||||
else if (ent.Comp.Damage != null)
|
||||
RepairSomeDamage((ent, damageable), ent.Comp.Damage, args.User);
|
||||
else
|
||||
RepairAllDamage((ent, damageable), args.User);
|
||||
|
||||
args.Repeat = ent.Comp.AutoDoAfter && damageable.TotalDamage > 0;
|
||||
args.Args.Event.Repeat = args.Repeat;
|
||||
args.Handled = true;
|
||||
|
||||
if (!args.Repeat)
|
||||
{
|
||||
// Repair all damage
|
||||
_damageableSystem.SetAllDamage((ent.Owner, damageable), 0);
|
||||
_adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(ent.Owner):target} back to full health");
|
||||
var str = Loc.GetString("comp-repairable-repair", ("target", ent.Owner), ("tool", args.Used!));
|
||||
_popup.PopupClient(str, ent.Owner, args.User);
|
||||
|
||||
var ev = new RepairedEvent(ent, args.User);
|
||||
RaiseLocalEvent(ent.Owner, ref ev);
|
||||
}
|
||||
}
|
||||
|
||||
var str = Loc.GetString("comp-repairable-repair", ("target", ent.Owner), ("tool", args.Used!));
|
||||
_popup.PopupClient(str, ent.Owner, args.User);
|
||||
/// <summary>
|
||||
/// Repairs some damage of a entity.
|
||||
/// The healed amount will be evenly distributed among all damage types the entity has.
|
||||
/// If one of the damage types of the entity is too low. it will heal that completly and distribute the excess healing among the other damage types
|
||||
/// </summary>
|
||||
/// <param name="ent">entity to be repaired</param>
|
||||
/// <param name="damageAmount">how much damage to repair (value have to be negative to repair)</param>
|
||||
/// <param name="user">who is doing the repair</param>
|
||||
private void RepairSomeDamage(Entity<DamageableComponent?> ent, float damageAmount, EntityUid user)
|
||||
{
|
||||
var damageChanged = _damageableSystem.HealEvenly(ent.Owner, damageAmount, origin: user);
|
||||
_adminLogger.Add(LogType.Healed, $"{ToPrettyString(user):user} repaired {ToPrettyString(ent.Owner):target} by {damageChanged.GetTotal()}");
|
||||
}
|
||||
|
||||
var ev = new RepairedEvent(ent, args.User);
|
||||
RaiseLocalEvent(ent.Owner, ref ev);
|
||||
/// <summary>
|
||||
/// Repairs some damage of a entity
|
||||
/// </summary>
|
||||
/// <param name="ent">entity to be repaired</param>
|
||||
/// <param name="damageAmount">how much damage to repair (values have to be negative to repair)</param>
|
||||
/// <param name="user">who is doing the repair</param>
|
||||
private void RepairSomeDamage(Entity<DamageableComponent?> ent, Damage.DamageSpecifier damageAmount, EntityUid user)
|
||||
{
|
||||
var damageChanged = _damageableSystem.ChangeDamage(ent.Owner, damageAmount, true, false, origin: user);
|
||||
_adminLogger.Add(LogType.Healed, $"{ToPrettyString(user):user} repaired {ToPrettyString(ent.Owner):target} by {damageChanged.GetTotal()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Repairs all damage of a entity
|
||||
/// </summary>
|
||||
/// <param name="ent">entity to be repaired</param>
|
||||
/// <param name="user">who is doing the repair</param>
|
||||
private void RepairAllDamage(Entity<DamageableComponent?> ent, EntityUid user)
|
||||
{
|
||||
_damageableSystem.ClearAllDamage(ent);
|
||||
_adminLogger.Add(LogType.Healed, $"{ToPrettyString(user):user} repaired {ToPrettyString(ent.Owner):target} back to full health");
|
||||
}
|
||||
|
||||
private void Repair(Entity<RepairableComponent> ent, ref InteractUsingEvent args)
|
||||
@@ -72,7 +110,7 @@ public sealed partial class RepairableSystem : EntitySystem
|
||||
}
|
||||
|
||||
// Run the repairing doafter
|
||||
args.Handled = _toolSystem.UseTool(args.Used, args.User, ent.Owner, delay, ent.Comp.QualityNeeded, new RepairFinishedEvent(), ent.Comp.FuelCost);
|
||||
args.Handled = _toolSystem.UseTool(args.Used, args.User, ent.Owner, delay, ent.Comp.QualityNeeded, new RepairDoAfterEvent(), ent.Comp.FuelCost);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,5 +122,9 @@ public sealed partial class RepairableSystem : EntitySystem
|
||||
[ByRefEvent]
|
||||
public readonly record struct RepairedEvent(Entity<RepairableComponent> Ent, EntityUid User);
|
||||
|
||||
/// <summary>
|
||||
/// Do after event started when you try to fix a entity with RepairableComponent.
|
||||
/// This doafter is repeated if the entity has <see cref="AutoDoAfter"> set to true and not all damage was fixed yet.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed partial class RepairFinishedEvent : SimpleDoAfterEvent;
|
||||
public sealed partial class RepairDoAfterEvent : SimpleDoAfterEvent;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
### Interaction Messages
|
||||
|
||||
# Shown when repairing something
|
||||
comp-repairable-repair = You repair {PROPER($target) ->
|
||||
comp-repairable-repair = You finish repairing {PROPER($target) ->
|
||||
[true] {""}
|
||||
*[false] the{" "}
|
||||
}{$target} with {PROPER($tool) ->
|
||||
|
||||
@@ -103,7 +103,9 @@
|
||||
- Science
|
||||
- type: ZombieImmune
|
||||
- type: Repairable
|
||||
doAfterDelay: 10
|
||||
damageValue: -10 # 10 seconds to repair from crit
|
||||
doAfterDelay: 1
|
||||
fuelCost: 0.5
|
||||
allowSelfRepair: false
|
||||
- type: BorgChassis
|
||||
- type: LockingWhitelist
|
||||
@@ -453,8 +455,6 @@
|
||||
- Mothership
|
||||
- Xenoborg
|
||||
- Binary
|
||||
- type: Repairable
|
||||
doAfterDelay: 13 # 25% more HP, so 30% more time to heal
|
||||
- type: BorgChassis
|
||||
maxModules: 0
|
||||
hasMindState: robot_e
|
||||
|
||||
@@ -129,8 +129,6 @@
|
||||
- cell_slot
|
||||
- !type:DoActsBehavior
|
||||
acts: [ "Destruction" ]
|
||||
- type: Repairable
|
||||
doAfterDelay: 25 # more HP, more time to heal
|
||||
- type: ContainerFill
|
||||
containers:
|
||||
borg_brain:
|
||||
|
||||
Reference in New Issue
Block a user