-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description Fixes the DropOnSlipSystem to actually work now. It also improves it, so now your items go flying when you drop them! :) Requires #113 # Changelog :cl: - add: Added fun! - tweak: Tweaked fun! - fix: Fixed fun! - remove: Removed fun!
- Loading branch information
1 parent
3a7ac33
commit 87240ed
Showing
5 changed files
with
122 additions
and
70 deletions.
There are no files selected for viewing
25 changes: 14 additions & 11 deletions
25
Content.Server/SimpleStation14/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 |
---|---|---|
@@ -1,13 +1,16 @@ | ||
namespace Content.Server.Slippery | ||
namespace Content.Server.SimpleStation14.Slippery; | ||
|
||
/// <summary> | ||
/// Uses provided chance to try and drop the item when slipped, if equipped. | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed class DropOnSlipComponent : Component | ||
{ | ||
/// <summary> | ||
/// Uses provided chance to try and drop the item when slipped, if equipped. | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed class DropOnSlipComponent : Component | ||
{ | ||
[DataField("chance")] | ||
[ViewVariables(VVAccess.ReadWrite)] | ||
public int Chance = 20; | ||
} | ||
[DataField("chance")] | ||
[ViewVariables(VVAccess.ReadWrite)] | ||
public int Chance = 20; | ||
|
||
[DataField("chanceToThrow")] | ||
[ViewVariables(VVAccess.ReadWrite)] | ||
public int ChanceToThrow = 40; | ||
} |
97 changes: 97 additions & 0 deletions
97
Content.Server/SimpleStation14/Slippery/DropOnSlipSystem.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,97 @@ | ||
using Content.Shared.Administration.Logs; | ||
using Content.Shared.Database; | ||
using Content.Shared.Inventory; | ||
using Robust.Shared.Random; | ||
using Content.Server.Popups; | ||
using Content.Shared.Popups; | ||
using Content.Shared.Slippery; | ||
using Content.Shared.Interaction.Components; | ||
using Robust.Shared.Physics.Systems; | ||
using Robust.Shared.Physics.Components; | ||
using Content.Shared.Throwing; | ||
|
||
namespace Content.Server.SimpleStation14.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 _invSystem = default!; | ||
[Dependency] private readonly SharedPhysicsSystem _physics = default!; | ||
[Dependency] private readonly ThrowingSystem _throwing = default!; | ||
|
||
private static readonly float PocketDropChance = 10f; | ||
private static readonly float PocketThrowChance = 5f; | ||
|
||
private static readonly float ClumsyDropChance = 5f; | ||
private static readonly float ClumsyThrowChance = 90f; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<InventoryComponent, ParkSlipEvent>(HandleSlip); | ||
} | ||
|
||
|
||
private void HandleSlip(EntityUid entity, InventoryComponent invComp, ParkSlipEvent args) | ||
{ | ||
if (!_invSystem.TryGetSlots(entity, out var slotDefinitions, invComp)) | ||
return; | ||
|
||
foreach (var slot in slotDefinitions) | ||
{ | ||
if (!_invSystem.TryGetSlotEntity(entity, slot.Name, out var item)) | ||
continue; | ||
|
||
// A check for DropOnSlipComponent. | ||
if (slot.Name != "pocket1" && slot.Name != "pocket2" && EntityManager.TryGetComponent<DropOnSlipComponent>(item, out var dropComp) && _random.NextFloat(0, 100) < dropComp.Chance) | ||
{ | ||
var popupString = Loc.GetString("system-drop-on-slip-text-component", ("name", entity), ("item", item)); | ||
|
||
Drop(entity, item.Value, slot.Name, popupString); | ||
continue; | ||
} | ||
|
||
// A check for any items in pockets. | ||
if (slot.Name == "pocket1" | slot.Name == "pocket2" && _random.NextFloat(0, 100) < PocketDropChance) | ||
{ | ||
var popupString = Loc.GetString("system-drop-on-slip-text-pocket", ("name", entity), ("item", item)); | ||
|
||
Drop(entity, item.Value, slot.Name, popupString); | ||
continue; | ||
} | ||
|
||
// A check for ClumsyComponent. | ||
if (slot.Name != "jumpsuit" && _random.NextFloat(0, 100) < ClumsyDropChance && HasComp<ClumsyComponent>(entity)) | ||
{ | ||
var popupString = Loc.GetString("system-drop-on-slip-text-clumsy", ("name", entity), ("item", item)); | ||
|
||
Drop(entity, item.Value, slot.Name, popupString); | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
private void Drop(EntityUid entity, EntityUid item, string slot, string popupString) | ||
{ | ||
if (!_invSystem.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 = (_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}"); | ||
} | ||
} |
59 changes: 0 additions & 59 deletions
59
Content.Server/SimpleStation14/Slippery/Systems/DropOnSlipSystem.cs
This file was deleted.
Oops, something went wrong.
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
2 changes: 2 additions & 0 deletions
2
Resources/Locale/en-US/SimpleStation14/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 |
---|---|---|
@@ -1,3 +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. |