diff --git a/Content.Shared/Delivery/DeliveryFragileComponent.cs b/Content.Shared/Delivery/DeliveryFragileComponent.cs new file mode 100644 index 0000000000..df8b0f131d --- /dev/null +++ b/Content.Shared/Delivery/DeliveryFragileComponent.cs @@ -0,0 +1,31 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Delivery; + +/// +/// Component given to deliveries. +/// Allows the delivery to be broken. +/// If intact, applies a small multiplier, otherwise substracts it. +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +[Access(typeof(DeliveryModifierSystem))] +public sealed partial class DeliveryFragileComponent : Component +{ + /// + /// Multiplier to use when the delivery is intact. + /// + [DataField] + public float IntactMultiplierOffset = 0.15f; + + /// + /// Multiplier to use when the delivery is broken. + /// + [DataField] + public float BrokenMultiplierOffset = -0.33f; + + /// + /// Whether this priority has already been broken or not. + /// + [DataField, AutoNetworkedField] + public bool Broken; +} diff --git a/Content.Shared/Delivery/DeliveryModifierSystem.cs b/Content.Shared/Delivery/DeliveryModifierSystem.cs index c4ad1bb3a6..15a903537b 100644 --- a/Content.Shared/Delivery/DeliveryModifierSystem.cs +++ b/Content.Shared/Delivery/DeliveryModifierSystem.cs @@ -1,5 +1,5 @@ +using Content.Shared.Destructible; using Content.Shared.Examine; -using Content.Shared.GameTicking; using Content.Shared.NameModifier.EntitySystems; using Robust.Shared.Random; using Robust.Shared.Serialization; @@ -27,6 +27,11 @@ public sealed partial class DeliveryModifierSystem : EntitySystem SubscribeLocalEvent(OnPriorityMapInit); SubscribeLocalEvent(OnPriorityExamine); SubscribeLocalEvent(OnGetPriorityMultiplier); + + SubscribeLocalEvent(OnFragileMapInit); + SubscribeLocalEvent(OnFragileBreakage); + SubscribeLocalEvent(OnFragileExamine); + SubscribeLocalEvent(OnGetFragileMultiplier); } #region Random @@ -70,6 +75,38 @@ public sealed partial class DeliveryModifierSystem : EntitySystem } #endregion + #region Fragile + private void OnFragileMapInit(Entity ent, ref MapInitEvent args) + { + _delivery.UpdateBrokenVisuals(ent, true); + } + + private void OnFragileBreakage(Entity ent, ref BreakageEventArgs args) + { + ent.Comp.Broken = true; + _delivery.UpdateBrokenVisuals(ent, true); + Dirty(ent); + } + + private void OnFragileExamine(Entity ent, ref ExaminedEvent args) + { + var trueName = _nameModifier.GetBaseName(ent.Owner); + + if (ent.Comp.Broken) + args.PushMarkup(Loc.GetString("delivery-fragile-broken-examine", ("type", trueName))); + else + args.PushMarkup(Loc.GetString("delivery-fragile-examine", ("type", trueName))); + } + + private void OnGetFragileMultiplier(Entity ent, ref GetDeliveryMultiplierEvent args) + { + if (ent.Comp.Broken) + args.AdditiveMultiplier += ent.Comp.BrokenMultiplierOffset; + else + args.AdditiveMultiplier += ent.Comp.IntactMultiplierOffset; + } + #endregion + #region Update Loops public override void Update(float frameTime) { diff --git a/Content.Shared/Delivery/DeliveryPriorityComponent.cs b/Content.Shared/Delivery/DeliveryPriorityComponent.cs index 769c6af0f8..dc06af6239 100644 --- a/Content.Shared/Delivery/DeliveryPriorityComponent.cs +++ b/Content.Shared/Delivery/DeliveryPriorityComponent.cs @@ -12,13 +12,13 @@ namespace Content.Shared.Delivery; public sealed partial class DeliveryPriorityComponent : Component { /// - /// The highest the random multiplier can go. + /// The multiplier to apply when delivered in time. /// [DataField] public float InTimeMultiplierOffset = 0.2f; /// - /// The lowest the random multiplier can go. + /// The multiplier to apply when delivered late. /// [DataField] public float ExpiredMultiplierOffset = -0.1f; diff --git a/Content.Shared/Delivery/SharedDeliverySystem.cs b/Content.Shared/Delivery/SharedDeliverySystem.cs index 0f67c3459e..db5b849c75 100644 --- a/Content.Shared/Delivery/SharedDeliverySystem.cs +++ b/Content.Shared/Delivery/SharedDeliverySystem.cs @@ -231,6 +231,7 @@ public abstract class SharedDeliverySystem : EntitySystem } } + #region Visual Updates // TODO: generic updateVisuals from component data private void UpdateAntiTamperVisuals(EntityUid uid, bool isLocked) { @@ -252,10 +253,17 @@ public abstract class SharedDeliverySystem : EntitySystem } } + public void UpdateBrokenVisuals(Entity ent, bool isFragile) + { + _appearance.SetData(ent, DeliveryVisuals.IsBroken, ent.Comp.Broken); + _appearance.SetData(ent, DeliveryVisuals.IsFragile, isFragile); + } + protected void UpdateDeliverySpawnerVisuals(EntityUid uid, int contents) { _appearance.SetData(uid, DeliverySpawnerVisuals.Contents, contents > 0); } + #endregion /// /// Gathers the total multiplier for a delivery. diff --git a/Resources/Locale/en-US/delivery/delivery-component.ftl b/Resources/Locale/en-US/delivery/delivery-component.ftl index c7f2347da4..54f45a578d 100644 --- a/Resources/Locale/en-US/delivery/delivery-component.ftl +++ b/Resources/Locale/en-US/delivery/delivery-component.ftl @@ -25,3 +25,6 @@ delivery-teleporter-empty-verb = Take mail # modifiers delivery-priority-examine = This is a [color=orange]priority {$type}[/color]. You have [color=orange]{$time}[/color] left to deliver it to get a bonus. delivery-priority-expired-examine = This is a [color=orange]priority {$type}[/color]. It seems you ran out of time. + +delivery-fragile-examine = This is a [color=red]fragile {$type}[/color]. Deliver it intact for a bonus. +delivery-fragile-broken-examine = This is a [color=red]fragile {$type}[/color]. It looks badly damaged. diff --git a/Resources/Prototypes/Entities/Objects/Deliveries/deliveries.yml b/Resources/Prototypes/Entities/Objects/Deliveries/deliveries.yml index e90a99510f..d1e9969bbb 100644 --- a/Resources/Prototypes/Entities/Objects/Deliveries/deliveries.yml +++ b/Resources/Prototypes/Entities/Objects/Deliveries/deliveries.yml @@ -137,6 +137,8 @@ children: - id: DeliveryModifierPriority prob: 0.25 + - id: DeliveryModifierFragile + prob: 0.25 - type: entity id: DeliveryModifierPriority @@ -144,3 +146,34 @@ categories: [ HideSpawnMenu ] components: - type: DeliveryPriority + +- type: entity + id: DeliveryModifierFragile + description: Components to add when a delivery is rolled as fragile. + categories: [ HideSpawnMenu ] + components: + - type: DeliveryFragile + - type: Damageable + damageContainer: Inorganic + - type: DamageOnHighSpeedImpact + minimumSpeed: 0.1 + damage: + types: + Blunt: 1 + soundHit: + collection: WeakHit + - type: DamageOnLand + damage: + types: + Blunt: 1 + - type: Destructible + thresholds: + - trigger: + !type:DamageTrigger + damage: 1 + behaviors: + - !type:PlaySoundBehavior + sound: + collection: DeliveryOpenSounds + - !type:DoActsBehavior + acts: [ "Breakage" ]