Skip to content

Make Glasses Fragile and Damage On Slip #34184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Content.Shared/Clothing/Components/DamageOnSlipComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Content.Shared.Damage;

namespace Content.Shared.Clothing.Components;

/// <summary>
/// A component to give clothing a chance to be damaged when slipping
/// </summary>
/// <remarks>
/// Pairs best with a `Destructible` component
/// </remarks>
[RegisterComponent]
public sealed partial class DamageOnSlipComponent : Component
{
/// <summary>
/// Chance the clothing will be damaged when slipped
/// </summary>
[DataField]
[ViewVariables(VVAccess.ReadWrite)]
public float DamageChance = 0.01f;

/// <summary>
/// Damage per instance of unlucky slip
/// </summary>
[DataField(required: true)]
[ViewVariables(VVAccess.ReadWrite)]
public DamageSpecifier Damage;

/// <summary>
/// Damage multiplier maximum
/// </summary>
/// <remarks>
/// Will multiply the damage specifier by a random integer from 1 to maximum (non inclusive)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why a random integer and not a float?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intention was to give the possibility of slipping once to shatter your glasses despite not damaging them previously by doubling the damage. This only required a multiplier of 1 or 2. Otherwise, it very much could be a float.

/// </remarks>
[DataField]
[ViewVariables(VVAccess.ReadWrite)]
public int? MultiplierMax;
}
36 changes: 36 additions & 0 deletions Content.Shared/Clothing/EntitySystems/DamageOnSlipSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Content.Shared.Clothing.Components;
using Content.Shared.Inventory;
using Content.Shared.Slippery;
using Robust.Shared.Network;
using Robust.Shared.Random;
using Content.Shared.Damage;

namespace Content.Shared.Clothing.EntitySystems;

public sealed class BreakOnSlipSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly DamageableSystem _damageableSystem = default!;

public override void Initialize()
{
SubscribeLocalEvent<DamageOnSlipComponent, InventoryRelayedEvent<SlippedEvent>>(OnSlip);
}

private void OnSlip(Entity<DamageOnSlipComponent> ent, ref InventoryRelayedEvent<SlippedEvent> args)
{
if (!_random.Prob(ent.Comp.DamageChance) || _net.IsClient)
return;
if (ent.Comp.MultiplierMax is null)
{
_damageableSystem.TryChangeDamage(ent.Owner, ent.Comp.Damage);
}
else
{
var damage = ent.Comp.Damage * _random.Next(1, ent.Comp.MultiplierMax.Value);
_damageableSystem.TryChangeDamage(ent.Owner, damage);
}

}
}
1 change: 1 addition & 0 deletions Content.Shared/Inventory/InventorySystem.Relay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void InitializeRelay()
SubscribeLocalEvent<InventoryComponent, TargetBeforeHyposprayInjectsEvent>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, SelfBeforeGunShotEvent>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, SelfBeforeClimbEvent>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, SlippedEvent>(RefRelayInventoryEvent);

// by-ref events
SubscribeLocalEvent<InventoryComponent, GetExplosionResistanceEvent>(RefRelayInventoryEvent);
Expand Down
17 changes: 15 additions & 2 deletions Content.Shared/Slippery/SlipperySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace Content.Shared.Slippery;

[UsedImplicitly]
[UsedImplicitly]
public sealed class SlipperySystem : EntitySystem
{
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
Expand Down Expand Up @@ -83,7 +83,7 @@ private void OnEntityExit(EntityUid uid, SlipperyComponent component, ref EndCol
{
if (HasComp<SpeedModifiedByContactComponent>(args.OtherEntity))
_speedModifier.AddModifiedEntity(args.OtherEntity);
}
}

private bool CanSlip(EntityUid uid, EntityUid toSlip)
{
Expand Down Expand Up @@ -112,6 +112,9 @@ public void TrySlip(EntityUid uid, SlipperyComponent component, EntityUid other,
var ev = new SlipEvent(other);
RaiseLocalEvent(uid, ref ev);

var slippedEv = new SlippedEvent(other);
RaiseLocalEvent(other, ref slippedEv);

if (TryComp(other, out PhysicsComponent? physics) && !HasComp<SlidingComponent>(other))
{
_physics.SetLinearVelocity(other, physics.LinearVelocity * component.LaunchForwardsMultiplier, body: physics);
Expand Down Expand Up @@ -162,3 +165,13 @@ public record struct SlipCausingAttemptEvent (bool Cancelled);
/// <param name="Slipped">The entity being slipped</param>
[ByRefEvent]
public readonly record struct SlipEvent(EntityUid Slipped);

/// <summary>
/// Raised on the entity that WAS slipped, passed on to all equipped clothing
/// </summary>
[ByRefEvent]
public sealed class SlippedEvent(EntityUid slipped) : EntityEventArgs, IInventoryRelayEvent
{
public EntityUid Slipped = slipped;
public SlotFlags TargetSlots => SlotFlags.All;
}
1 change: 1 addition & 0 deletions Resources/Locale/en-US/clothing/glasses.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
clothing-glasses-shatter = The glasses shatter
59 changes: 58 additions & 1 deletion Resources/Prototypes/Entities/Clothing/Eyes/glasses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,65 @@
- type: Clothing
sprite: Clothing/Eyes/Glasses/glasses.rsi
- type: VisionCorrection
- type: DamageOnSlip
damageChance: 0.01
damage:
types:
Blunt: 5
multiplierMax: 3
- type: Damageable
damageContainer: Inorganic
- type: DamageOnLand
damage:
types:
Blunt: 2 # Can be thrown 5 times w/o hitting wall, if not dropped
- type: Destructible
thresholds:
- trigger:
!type:DamageTypeTrigger
damageType: Blunt
damage: 10
behaviors:
- !type:SpawnEntitiesBehavior
spawn:
ClothingEyesGlassesBroken:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
you can try did it like this with Breakage, and also add Repairable component, io be able to fix the glasses back up. But that's up to you, I don't require it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The glasses are currently "repairable" via a crafting recipe using the broken glasses and a piece of glass. I'll experiment with using the breakage and repairable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think making them repairable would be the nicer way to do this rather than adding a crafting recipe specifically for glasses.

min: 1
max: 1
ShardGlass:
min: 0
max: 1
- !type:PlaySoundBehavior
sound:
collection: GlassBreak
params:
volume: -5
- !type:PopupBehavior
popup: "clothing-glasses-shatter"
- !type:DoActsBehavior
acts: [ "Destruction" ]
- type: Construction
graph: RepairBrokenGlasses
node: glasses
- type: Tag
tags:
- HamsterWearable
- WhitelistChameleon

- type: entity
parent: ClothingEyesBase
id: ClothingEyesGlassesBroken
name: broken glasses
description: A pair of no longer spectacular spectacles featuring cracked lenses.
components:
- type: Sprite
sprite: Clothing/Eyes/Glasses/brokenglasses.rsi
- type: Clothing
sprite: Clothing/Eyes/Glasses/brokenglasses.rsi
- type: VisionCorrection
correctionPower: 1.4
- type: Tag
tags:
- BrokenGlasses
- HamsterWearable
- WhitelistChameleon

Expand Down Expand Up @@ -188,7 +245,7 @@
parent: [ClothingEyesBase, BaseCommandContraband]
id: ClothingEyesGlassesCommand
name: administration glasses
description: Upgraded sunglasses that provide flash immunity and show ID card status.
description: Upgraded sunglasses that provide flash immunity and show ID card status.
components:
- type: Sprite
sprite: Clothing/Eyes/Glasses/commandglasses.rsi
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
- type: constructionGraph
id: RepairBrokenGlasses
start: start
graph:
- node: start
edges:
- to: glasses
steps:
- tag: BrokenGlasses
name: broken glasses
icon:
sprite: Clothing/Eyes/Glasses/brokenglasses.rsi
state: icon
- material: Glass
amount: 1
doAfter: 4
- node: glasses
entity: ClothingEyesGlasses
13 changes: 12 additions & 1 deletion Resources/Prototypes/Recipes/Construction/clothing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@
icon: { sprite: Clothing/Shoes/Misc/duck-slippers.rsi, state: icon }
objectType: Item

- type: construction
name: repair broken glasses
id: ClothingEyesGlasses
graph: RepairBrokenGlasses
startNode: start
targetNode: glasses
category: construction-category-clothing
description: Replace the cracked lenses with new lenses.
icon: { sprite: Clothing/Eyes/Glasses/glasses.rsi, state: icon }
objectType: Item

- type: construction
name: security glasses
id: ClothingEyesGlassesSecurity
Expand Down Expand Up @@ -128,4 +139,4 @@
category: construction-category-clothing
description: Advanced security gear. Protects the station from ne'er-do-wells.
icon: { sprite: Clothing/Head/Helmets/justice.rsi, state: icon }
objectType: Item
objectType: Item
3 changes: 3 additions & 0 deletions Resources/Prototypes/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@
- type: Tag
id: BrimFlatcapGrey

- type: Tag
id: BrokenGlasses

- type: Tag
id: Brutepack

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Modified variant of sprite taken from tgstation at commit https://github.com/tgstation/tgstation/commit/5a73e8f825ff279e82949b9329783a9e3070e2da",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "icon"
},
{
"name": "equipped-EYES",
"directions": 4
},
{
"name": "equipped-EYES-hamster",
"directions": 4
},
{
"name": "inhand-left",
"directions": 4
},
{
"name": "inhand-right",
"directions": 4
}
]
}
Loading