Speed Boots [Tier 3 Civ-Service] (#21438)

* Speed Boots

* validate

* monkey
This commit is contained in:
Nemanja
2023-11-07 20:25:43 -05:00
committed by GitHub
parent a6985e5b4b
commit 94368f1f00
24 changed files with 296 additions and 33 deletions

View File

@@ -1,6 +1,11 @@
using Content.Shared.Actions;
using Content.Shared.Clothing.Components;
using Content.Shared.Examine;
using Content.Shared.IdentityManagement;
using Content.Shared.Inventory;
using Content.Shared.Movement.Systems;
using Content.Shared.PowerCell;
using Content.Shared.Toggleable;
using Content.Shared.Verbs;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
@@ -10,9 +15,13 @@ namespace Content.Shared.Clothing;
public sealed class ClothingSpeedModifierSystem : EntitySystem
{
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeed = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly ClothingSpeedModifierSystem _clothingSpeedModifier = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly ExamineSystemShared _examine = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeed = default!;
[Dependency] private readonly SharedPowerCellSystem _powerCell = default!;
public override void Initialize()
{
@@ -22,6 +31,12 @@ public sealed class ClothingSpeedModifierSystem : EntitySystem
SubscribeLocalEvent<ClothingSpeedModifierComponent, ComponentHandleState>(OnHandleState);
SubscribeLocalEvent<ClothingSpeedModifierComponent, InventoryRelayedEvent<RefreshMovementSpeedModifiersEvent>>(OnRefreshMoveSpeed);
SubscribeLocalEvent<ClothingSpeedModifierComponent, GetVerbsEvent<ExamineVerb>>(OnClothingVerbExamine);
SubscribeLocalEvent<ToggleClothingSpeedComponent, GetVerbsEvent<ActivationVerb>>(AddToggleVerb);
SubscribeLocalEvent<ToggleClothingSpeedComponent, GetItemActionsEvent>(OnGetActions);
SubscribeLocalEvent<ToggleClothingSpeedComponent, ToggleClothingSpeedEvent>(OnToggleSpeed);
SubscribeLocalEvent<ToggleClothingSpeedComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<ToggleClothingSpeedComponent, PowerCellSlotEmptyEvent>(OnPowerCellSlotEmpty);
}
// Public API
@@ -34,7 +49,7 @@ public sealed class ClothingSpeedModifierSystem : EntitySystem
if (component.Enabled != enabled)
{
component.Enabled = enabled;
Dirty(component);
Dirty(uid, component);
// inventory system will automatically hook into the event raised by this and update accordingly
if (_container.TryGetContainingContainer(uid, out var container))
@@ -126,4 +141,61 @@ public sealed class ClothingSpeedModifierSystem : EntitySystem
_examine.AddDetailedExamineVerb(args, component, msg, Loc.GetString("clothing-speed-examinable-verb-text"), "/Textures/Interface/VerbIcons/outfit.svg.192dpi.png", Loc.GetString("clothing-speed-examinable-verb-message"));
}
private void OnMapInit(Entity<ToggleClothingSpeedComponent> uid, ref MapInitEvent args)
{
_actions.AddAction(uid, ref uid.Comp.ToggleActionEntity, uid.Comp.ToggleAction);
}
private void OnToggleSpeed(Entity<ToggleClothingSpeedComponent> uid, ref ToggleClothingSpeedEvent args)
{
if (args.Handled)
return;
args.Handled = true;
SetSpeedToggleEnabled(uid, !uid.Comp.Enabled, args.Performer);
}
private void SetSpeedToggleEnabled(Entity<ToggleClothingSpeedComponent> uid, bool value, EntityUid? user)
{
if (uid.Comp.Enabled == value)
return;
TryComp<PowerCellDrawComponent>(uid, out var draw);
if (value && !_powerCell.HasDrawCharge(uid, draw, user: user))
return;
uid.Comp.Enabled = value;
_appearance.SetData(uid, ToggleVisuals.Toggled, uid.Comp.Enabled);
_actions.SetToggled(uid.Comp.ToggleActionEntity, uid.Comp.Enabled);
_clothingSpeedModifier.SetClothingSpeedModifierEnabled(uid.Owner, uid.Comp.Enabled);
_powerCell.SetPowerCellDrawEnabled(uid, uid.Comp.Enabled, draw);
Dirty(uid, uid.Comp);
}
private void AddToggleVerb(Entity<ToggleClothingSpeedComponent> uid, ref GetVerbsEvent<ActivationVerb> args)
{
if (!args.CanAccess || !args.CanInteract)
return;
var user = args.User;
ActivationVerb verb = new()
{
Text = Loc.GetString("toggle-clothing-verb-text",
("entity", Identity.Entity(uid, EntityManager))),
Act = () => SetSpeedToggleEnabled(uid, !uid.Comp.Enabled, user)
};
args.Verbs.Add(verb);
}
private void OnGetActions(Entity<ToggleClothingSpeedComponent> uid, ref GetItemActionsEvent args)
{
args.AddAction(ref uid.Comp.ToggleActionEntity, uid.Comp.ToggleAction);
}
private void OnPowerCellSlotEmpty(Entity<ToggleClothingSpeedComponent> uid, ref PowerCellSlotEmptyEvent args)
{
SetSpeedToggleEnabled(uid, false, null);
}
}