-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description A Parkstation list item from #2 I have not made any changes to the code, it might be worth looking at the clothing YAMLs to see if anything should be added or changed. --- # Todo - [ ] Add end of round stat when #50 is merged --- # Changelog <!-- You can add an author after the `:cl:` to change the name that appears in the changelog, ex: `:cl: Death`, it will default to your GitHub display name --> :cl: - add: Added chance to drop certain items when slipped --------- Co-authored-by: Finket <[email protected]> Co-authored-by: DEATHB4DEFEAT <[email protected]> Co-authored-by: DEATHB4DEFEAT <[email protected]>
- Loading branch information
1 parent
764e617
commit e67ed83
Showing
13 changed files
with
329 additions
and
4 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
Content.Server/Parkstation/Slippery/DropOnSlipComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Content.Server.Parkstation.Slippery; | ||
|
||
/// <summary> | ||
/// Marks this item as one that may be dropped when its wearer slips with it equipped. | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed partial class DropOnSlipComponent : Component | ||
{ | ||
/// <summary> | ||
/// Percent chance to drop this item when slipping | ||
/// </summary> | ||
[DataField("chance")] | ||
[ViewVariables(VVAccess.ReadWrite)] | ||
public int Chance = 20; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System.Numerics; | ||
using Content.Server.Popups; | ||
using Content.Shared.Administration.Logs; | ||
using Content.Shared.Database; | ||
using Content.Shared.Interaction.Components; | ||
using Content.Shared.Inventory; | ||
using Content.Shared.Popups; | ||
using Content.Shared.Slippery; | ||
using Content.Shared.Throwing; | ||
using Robust.Shared.Physics.Components; | ||
using Robust.Shared.Physics.Systems; | ||
using Robust.Shared.Random; | ||
|
||
namespace Content.Server.Parkstation.Slippery; | ||
|
||
public sealed class DropOnSlipSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; | ||
[Dependency] private readonly PopupSystem _popup = default!; | ||
[Dependency] private readonly IRobustRandom _random = default!; | ||
[Dependency] private readonly InventorySystem _inventory = default!; | ||
[Dependency] private readonly SharedPhysicsSystem _physics = default!; | ||
[Dependency] private readonly ThrowingSystem _throwing = default!; | ||
|
||
public float PocketDropChance = 10f; | ||
public float PocketThrowChance = 5f; | ||
|
||
public float ClumsyDropChance = 5f; | ||
public float ClumsyThrowChance = 90f; | ||
|
||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<InventoryComponent, ParkSlipEvent>(HandleSlip); | ||
} | ||
|
||
|
||
private void HandleSlip(EntityUid entity, InventoryComponent invComp, ParkSlipEvent args) | ||
{ | ||
if (!_inventory.TryGetSlots(entity, out var slotDefinitions)) | ||
return; | ||
|
||
foreach (var slot in slotDefinitions) | ||
{ | ||
if (!_inventory.TryGetSlotEntity(entity, slot.Name, out var item)) | ||
continue; | ||
|
||
if (ShouldBeDropped(entity, slot, item)) | ||
{ | ||
var popupString = Loc.GetString("system-drop-on-slip-text-component", ("name", entity), ("item", item)); | ||
|
||
Drop(entity, item.Value, slot.Name, popupString); | ||
} | ||
} | ||
} | ||
|
||
private bool ShouldBeDropped(EntityUid entity, SlotDefinition slot, EntityUid? item) | ||
{ | ||
// Check for any items in pockets or other criteria | ||
if (slot.SlotFlags == SlotFlags.POCKET && _random.NextFloat(0, 100) < PocketDropChance) | ||
return true; | ||
|
||
// Check for DropOnSlipComponent | ||
if (EntityManager.TryGetComponent<Parkstation.Slippery.DropOnSlipComponent>(item, out var dropComp) && _random.NextFloat(0, 100) < dropComp.Chance) | ||
return true; | ||
|
||
// Check for ClumsyComponent | ||
if (slot.Name != "jumpsuit" && _random.NextFloat(0, 100) < ClumsyDropChance && HasComp<ClumsyComponent>(entity)) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
private void Drop(EntityUid entity, EntityUid item, string slot, string popupString) | ||
{ | ||
if (!_inventory.TryUnequip(entity, slot, false, true)) | ||
return; | ||
|
||
EntityManager.TryGetComponent<PhysicsComponent>(entity, out var entPhysComp); | ||
|
||
if (entPhysComp != null) | ||
{ | ||
var strength = entPhysComp.LinearVelocity.Length() / 1.5f; | ||
Vector2 direction = new Vector2(_random.Next(-8, 8), _random.Next(-8, 8)); | ||
|
||
_throwing.TryThrow(item, direction, strength, entity); | ||
} | ||
|
||
_popup.PopupEntity(popupString, item, PopupType.MediumCaution); | ||
|
||
var logMessage = Loc.GetString("system-drop-on-slip-log", ("entity", ToPrettyString(entity)), ("item", ToPrettyString(item))); | ||
_adminLogger.Add(LogType.Slip, LogImpact.Low, $"{logMessage}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
Resources/Locale/en-US/parkstation/Content/Slippery/dropOnSlip.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
system-drop-on-slip-text-component = {$name}'s {$item} slips off! | ||
system-drop-on-slip-text-pocket = Something falls out of {$name}'s pocket! | ||
system-drop-on-slip-text-clumsy = The {$item} tumbles off of {$name}! | ||
system-drop-on-slip-log = {$entity} dropped {$item} when slipping. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.