-
Notifications
You must be signed in to change notification settings - Fork 3
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
Port Drop on Slip #54
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
58c6fae
Port over drop on slip files
vaketola 1125c76
Clean up codes from review
Finket fa2071a
Remove unused variable
vaketola ea03e29
Merge branch 'master' into droponslip
vaketola e0443a9
Move from SimpleStation14 to Parkstation namespaces
vaketola bd7f518
Fix variables
vaketola e197e49
Refactor DropOnSlipSystem
vaketola e55cac8
Merge branch 'master' of https://github.com/Simple-Station/Parkstatio…
DEATHB4DEFEAT f9bfddd
fix test
DEATHB4DEFEAT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Content.Server.SimpleStation14.Slippery; | ||
|
||
/// <summary> | ||
/// Uses provided chance to try and drop the item when slipped, if equipped. | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed partial class DropOnSlipComponent : Component | ||
{ | ||
[DataField("chance")] | ||
[ViewVariables(VVAccess.ReadWrite)] | ||
public int Chance = 20; | ||
|
||
[DataField("chanceToThrow")] | ||
[ViewVariables(VVAccess.ReadWrite)] | ||
public int ChanceToThrow = 40; | ||
Finket marked this conversation as resolved.
Show resolved
Hide resolved
Finket marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
98 changes: 98 additions & 0 deletions
98
Content.Server/SimpleStation14/Slippery/DropOnSlipSystem.cs
Finket marked this conversation as resolved.
Show resolved
Hide resolved
|
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,98 @@ | ||
using System.Numerics; | ||
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!; | ||
Finket marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[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; | ||
Finket marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Finket marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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)) | ||
Finket marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return; | ||
|
||
foreach (var slot in slotDefinitions) | ||
{ | ||
if (!_invSystem.TryGetSlotEntity(entity, slot.Name, out var item)) | ||
Finket marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue; | ||
|
||
// A check for DropOnSlipComponent. | ||
Finket marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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. | ||
Finket marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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. | ||
Finket marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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)) | ||
Finket marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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/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 |
---|---|---|
@@ -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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently looking at https://www.github.com/space-wizards/space-station-14/issues/9702 as the solution.