Skip to content
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

Make Glasses Fragile and Damage On Slip #34184

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
36 changes: 36 additions & 0 deletions Content.Shared/Clothing/Components/BreakOnSlipComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace Content.Shared.Clothing.Components;

/// <summary>
/// A component to give clothing a chance to "break" when slipping
/// </summary>
[RegisterComponent]
public sealed partial class BreakOnSlipComponent : Component
{
/// <summary>
/// Chance the clothing will break when slipped
/// </summary>
[DataField("breakChance")]
thetolbean marked this conversation as resolved.
Show resolved Hide resolved
[ViewVariables(VVAccess.ReadWrite)]
public float BreakChance = 0.01f;

/// <summary>
/// The slot to equip the replacement clothing to
/// </summary>
[DataField("slot",required: true)]
thetolbean marked this conversation as resolved.
Show resolved Hide resolved
[ViewVariables(VVAccess.ReadWrite)]
public string Slot;

/// <summary>
/// The clothing prototype to swap to when broken
/// </summary>
[DataField("replacementPrototype",required: true)]
thetolbean marked this conversation as resolved.
Show resolved Hide resolved
[ViewVariables(VVAccess.ReadWrite)]
public string ReplacementPrototype;

/// <summary>
/// The message to show in the popup when it breaks
/// </summary>
[DataField("message",required: true)]
thetolbean marked this conversation as resolved.
Show resolved Hide resolved
[ViewVariables(VVAccess.ReadWrite)]
public string Message;
thetolbean marked this conversation as resolved.
Show resolved Hide resolved
}
31 changes: 31 additions & 0 deletions Content.Shared/Clothing/EntitySystems/BreakOnSlipSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Content.Shared.Clothing.Components;
using Content.Shared.Inventory;
using Content.Shared.Popups;
using Content.Shared.Slippery;
using Robust.Shared.Network;
using Robust.Shared.Random;

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 InventorySystem _inventorySystem = default!;
thetolbean marked this conversation as resolved.
Show resolved Hide resolved
[Dependency] private readonly SharedPopupSystem _popup = default!;

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

private void OnSlip(EntityUid uid, BreakOnSlipComponent component, InventoryRelayedEvent<SlippedEvent> args)
thetolbean marked this conversation as resolved.
Show resolved Hide resolved
{
if (!_random.Prob(component.BreakChance) || _net.IsClient)
return;
EntityManager.DeleteEntity(uid);
thetolbean marked this conversation as resolved.
Show resolved Hide resolved
var replacement = Spawn(component.ReplacementPrototype, Transform(args.Args.Slipped).Coordinates);
_inventorySystem.TryEquip(args.Args.Slipped, replacement, component.Slot);
_popup.PopupEntity(component.Message, args.Args.Slipped, PopupType.Medium);
}
}
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);
thetolbean marked this conversation as resolved.
Show resolved Hide resolved

// 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;
}
27 changes: 26 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,33 @@
- type: Clothing
sprite: Clothing/Eyes/Glasses/glasses.rsi
- type: VisionCorrection
- type: BreakOnSlip
slot: eyes
replacementPrototype: ClothingEyesGlassesBroken
message: Your glasses crack from hitting the floor
- 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 +213,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