Remove IMoveSpeedModifier in favor of events (#5212)
* Remove IMoveSpeedModifier * fucking magboots * yope * rabiews
This commit is contained in:
21
Content.Client/Clothing/MagbootsSystem.cs
Normal file
21
Content.Client/Clothing/MagbootsSystem.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using Content.Shared.Clothing;
|
||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
|
||||||
|
namespace Content.Client.Clothing
|
||||||
|
{
|
||||||
|
public class MagbootsSystem : EntitySystem
|
||||||
|
{
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
SubscribeLocalEvent<MagbootsComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnRefreshMovespeed(EntityUid uid, MagbootsComponent component, RefreshMovementSpeedModifiersEvent args)
|
||||||
|
{
|
||||||
|
args.ModifySpeed(component.WalkSpeedModifier, component.SprintSpeedModifier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,8 +3,10 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Client.Clothing;
|
using Content.Client.Clothing;
|
||||||
using Content.Shared.CharacterAppearance;
|
using Content.Shared.CharacterAppearance;
|
||||||
|
using Content.Shared.Chemistry;
|
||||||
using Content.Shared.Inventory;
|
using Content.Shared.Inventory;
|
||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
@@ -81,46 +83,6 @@ namespace Content.Client.Inventory
|
|||||||
return item != null && _slots.Values.Any(e => e == item);
|
return item != null && _slots.Values.Any(e => e == item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override float WalkSpeedModifier
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var mod = 1f;
|
|
||||||
foreach (var slot in _slots.Values)
|
|
||||||
{
|
|
||||||
if (slot != null)
|
|
||||||
{
|
|
||||||
foreach (var modifier in slot.GetAllComponents<IMoveSpeedModifier>())
|
|
||||||
{
|
|
||||||
mod *= modifier.WalkSpeedModifier;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return mod;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override float SprintSpeedModifier
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var mod = 1f;
|
|
||||||
foreach (var slot in _slots.Values)
|
|
||||||
{
|
|
||||||
if (slot != null)
|
|
||||||
{
|
|
||||||
foreach (var modifier in slot.GetAllComponents<IMoveSpeedModifier>())
|
|
||||||
{
|
|
||||||
mod *= modifier.SprintSpeedModifier;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return mod;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||||
{
|
{
|
||||||
base.HandleComponentState(curState, nextState);
|
base.HandleComponentState(curState, nextState);
|
||||||
@@ -161,10 +123,7 @@ namespace Content.Client.Inventory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? mod))
|
EntitySystem.Get<MovementSpeedModifierSystem>().RefreshMovementSpeedModifiers(OwnerUid);
|
||||||
{
|
|
||||||
mod.RefreshMovementSpeedModifiers();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _setSlot(Slots slot, IEntity entity)
|
private void _setSlot(Slots slot, IEntity entity)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using Content.Client.HUD;
|
|||||||
using Content.Client.Items.Components;
|
using Content.Client.Items.Components;
|
||||||
using Content.Shared.Input;
|
using Content.Shared.Input;
|
||||||
using Content.Shared.Inventory;
|
using Content.Shared.Inventory;
|
||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
using Content.Shared.Slippery;
|
using Content.Shared.Slippery;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
@@ -29,6 +30,7 @@ namespace Content.Client.Inventory
|
|||||||
SubscribeLocalEvent<ClientInventoryComponent, PlayerDetachedEvent>((_, component, _) => component.PlayerDetached());
|
SubscribeLocalEvent<ClientInventoryComponent, PlayerDetachedEvent>((_, component, _) => component.PlayerDetached());
|
||||||
|
|
||||||
SubscribeLocalEvent<ClientInventoryComponent, SlipAttemptEvent>(OnSlipAttemptEvent);
|
SubscribeLocalEvent<ClientInventoryComponent, SlipAttemptEvent>(OnSlipAttemptEvent);
|
||||||
|
SubscribeLocalEvent<ClientInventoryComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// jesus christ, this is duplicated to server/client, should really just be shared..
|
// jesus christ, this is duplicated to server/client, should really just be shared..
|
||||||
@@ -40,6 +42,17 @@ namespace Content.Client.Inventory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnRefreshMovespeed(EntityUid uid, ClientInventoryComponent component, RefreshMovementSpeedModifiersEvent args)
|
||||||
|
{
|
||||||
|
foreach (var (_, ent) in component.AllSlots)
|
||||||
|
{
|
||||||
|
if (ent != null)
|
||||||
|
{
|
||||||
|
RaiseLocalEvent(ent.Uid, args, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void Shutdown()
|
public override void Shutdown()
|
||||||
{
|
{
|
||||||
CommandBinds.Unregister<ClientInventorySystem>();
|
CommandBinds.Unregister<ClientInventorySystem>();
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
using Content.Shared.Nutrition.Components;
|
using Content.Shared.Nutrition.Components;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
|
||||||
@@ -21,10 +22,7 @@ namespace Content.Client.Nutrition.Components
|
|||||||
|
|
||||||
_currentHungerThreshold = hunger.CurrentThreshold;
|
_currentHungerThreshold = hunger.CurrentThreshold;
|
||||||
|
|
||||||
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? movement))
|
EntitySystem.Get<MovementSpeedModifierSystem>().RefreshMovementSpeedModifiers(OwnerUid);
|
||||||
{
|
|
||||||
movement.RefreshMovementSpeedModifiers();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
using Content.Shared.Nutrition.Components;
|
using Content.Shared.Nutrition.Components;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
|
||||||
@@ -21,10 +22,7 @@ namespace Content.Client.Nutrition.Components
|
|||||||
|
|
||||||
_currentThirstThreshold = thirst.CurrentThreshold;
|
_currentThirstThreshold = thirst.CurrentThreshold;
|
||||||
|
|
||||||
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? movement))
|
EntitySystem.Get<MovementSpeedModifierSystem>().RefreshMovementSpeedModifiers(OwnerUid);
|
||||||
{
|
|
||||||
movement.RefreshMovementSpeedModifiers();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System;
|
|||||||
using Content.Shared.Chemistry.Components;
|
using Content.Shared.Chemistry.Components;
|
||||||
using Content.Shared.Chemistry.Reagent;
|
using Content.Shared.Chemistry.Reagent;
|
||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
@@ -38,8 +39,6 @@ namespace Content.Server.Chemistry.ReagentEffects
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override void Metabolize(IEntity solutionEntity, Solution.ReagentQuantity amount)
|
public override void Metabolize(IEntity solutionEntity, Solution.ReagentQuantity amount)
|
||||||
{
|
{
|
||||||
if (!solutionEntity.TryGetComponent(out MovementSpeedModifierComponent? movement)) return;
|
|
||||||
|
|
||||||
solutionEntity.EnsureComponent(out MovespeedModifierMetabolismComponent status);
|
solutionEntity.EnsureComponent(out MovespeedModifierMetabolismComponent status);
|
||||||
|
|
||||||
// Only refresh movement if we need to.
|
// Only refresh movement if we need to.
|
||||||
@@ -52,7 +51,7 @@ namespace Content.Server.Chemistry.ReagentEffects
|
|||||||
IncreaseTimer(status, StatusLifetime * amount.Quantity.Float());
|
IncreaseTimer(status, StatusLifetime * amount.Quantity.Float());
|
||||||
|
|
||||||
if (modified)
|
if (modified)
|
||||||
movement.RefreshMovementSpeedModifiers();
|
EntitySystem.Get<MovementSpeedModifierSystem>().RefreshMovementSpeedModifiers(solutionEntity.Uid);
|
||||||
|
|
||||||
}
|
}
|
||||||
public void IncreaseTimer(MovespeedModifierMetabolismComponent status, float time)
|
public void IncreaseTimer(MovespeedModifierMetabolismComponent status, float time)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Content.Server.Clothing.Components;
|
using Content.Server.Clothing.Components;
|
||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
using Content.Shared.Slippery;
|
using Content.Shared.Slippery;
|
||||||
using Content.Shared.Verbs;
|
using Content.Shared.Verbs;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
@@ -14,6 +15,12 @@ namespace Content.Server.Clothing
|
|||||||
|
|
||||||
SubscribeLocalEvent<MagbootsComponent, GetActivationVerbsEvent>(AddToggleVerb);
|
SubscribeLocalEvent<MagbootsComponent, GetActivationVerbsEvent>(AddToggleVerb);
|
||||||
SubscribeLocalEvent<MagbootsComponent, SlipAttemptEvent>(OnSlipAttempt);
|
SubscribeLocalEvent<MagbootsComponent, SlipAttemptEvent>(OnSlipAttempt);
|
||||||
|
SubscribeLocalEvent<MagbootsComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnRefreshMovespeed(EntityUid uid, MagbootsComponent component, RefreshMovementSpeedModifiersEvent args)
|
||||||
|
{
|
||||||
|
args.ModifySpeed(component.WalkSpeedModifier, component.SprintSpeedModifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddToggleVerb(EntityUid uid, MagbootsComponent component, GetActivationVerbsEvent args)
|
private void AddToggleVerb(EntityUid uid, MagbootsComponent component, GetActivationVerbsEvent args)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using Content.Shared.ActionBlocker;
|
|||||||
using Content.Shared.Acts;
|
using Content.Shared.Acts;
|
||||||
using Content.Shared.Inventory;
|
using Content.Shared.Inventory;
|
||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
using Content.Shared.Popups;
|
using Content.Shared.Popups;
|
||||||
using Content.Shared.Verbs;
|
using Content.Shared.Verbs;
|
||||||
using Robust.Server.Console;
|
using Robust.Server.Console;
|
||||||
@@ -60,46 +61,6 @@ namespace Content.Server.Inventory.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override float WalkSpeedModifier
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var mod = 1f;
|
|
||||||
foreach (var slot in _slotContainers.Values)
|
|
||||||
{
|
|
||||||
if (slot.ContainedEntity != null)
|
|
||||||
{
|
|
||||||
foreach (var modifier in slot.ContainedEntity.GetAllComponents<IMoveSpeedModifier>())
|
|
||||||
{
|
|
||||||
mod *= modifier.WalkSpeedModifier;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return mod;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override float SprintSpeedModifier
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var mod = 1f;
|
|
||||||
foreach (var slot in _slotContainers.Values)
|
|
||||||
{
|
|
||||||
if (slot.ContainedEntity != null)
|
|
||||||
{
|
|
||||||
foreach (var modifier in slot.ContainedEntity.GetAllComponents<IMoveSpeedModifier>())
|
|
||||||
{
|
|
||||||
mod *= modifier.SprintSpeedModifier;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return mod;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnRemove()
|
protected override void OnRemove()
|
||||||
{
|
{
|
||||||
var slots = _slotContainers.Keys.ToList();
|
var slots = _slotContainers.Keys.ToList();
|
||||||
@@ -333,10 +294,7 @@ namespace Content.Server.Inventory.Components
|
|||||||
|
|
||||||
private void UpdateMovementSpeed()
|
private void UpdateMovementSpeed()
|
||||||
{
|
{
|
||||||
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? mod))
|
EntitySystem.Get<MovementSpeedModifierSystem>().RefreshMovementSpeedModifiers(OwnerUid);
|
||||||
{
|
|
||||||
mod.RefreshMovementSpeedModifiers();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ForceUnequip(Slots slot)
|
public void ForceUnequip(Slots slot)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using Content.Shared.Inventory;
|
|||||||
using Content.Shared.Slippery;
|
using Content.Shared.Slippery;
|
||||||
using Content.Shared.Damage;
|
using Content.Shared.Damage;
|
||||||
using Content.Shared.Electrocution;
|
using Content.Shared.Electrocution;
|
||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ namespace Content.Server.Inventory
|
|||||||
SubscribeLocalEvent<InventoryComponent, DamageModifyEvent>(OnDamageModify);
|
SubscribeLocalEvent<InventoryComponent, DamageModifyEvent>(OnDamageModify);
|
||||||
SubscribeLocalEvent<InventoryComponent, ElectrocutionAttemptEvent>(OnElectrocutionAttempt);
|
SubscribeLocalEvent<InventoryComponent, ElectrocutionAttemptEvent>(OnElectrocutionAttempt);
|
||||||
SubscribeLocalEvent<InventoryComponent, SlipAttemptEvent>(OnSlipAttemptEvent);
|
SubscribeLocalEvent<InventoryComponent, SlipAttemptEvent>(OnSlipAttemptEvent);
|
||||||
|
SubscribeLocalEvent<InventoryComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSlipAttemptEvent(EntityUid uid, InventoryComponent component, SlipAttemptEvent args)
|
private void OnSlipAttemptEvent(EntityUid uid, InventoryComponent component, SlipAttemptEvent args)
|
||||||
@@ -33,6 +35,11 @@ namespace Content.Server.Inventory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnRefreshMovespeed(EntityUid uid, InventoryComponent component, RefreshMovementSpeedModifiersEvent args)
|
||||||
|
{
|
||||||
|
RelayInventoryEvent(component, args);
|
||||||
|
}
|
||||||
|
|
||||||
private static void HandleInvRemovedFromContainer(EntityUid uid, InventoryComponent component, EntRemovedFromContainerMessage args)
|
private static void HandleInvRemovedFromContainer(EntityUid uid, InventoryComponent component, EntRemovedFromContainerMessage args)
|
||||||
{
|
{
|
||||||
component.ForceUnequip(args.Container, args.Entity);
|
component.ForceUnequip(args.Container, args.Entity);
|
||||||
@@ -45,31 +52,25 @@ namespace Content.Server.Inventory
|
|||||||
|
|
||||||
private void OnHighPressureEvent(EntityUid uid, InventoryComponent component, HighPressureEvent args)
|
private void OnHighPressureEvent(EntityUid uid, InventoryComponent component, HighPressureEvent args)
|
||||||
{
|
{
|
||||||
RelayPressureEvent(component, args);
|
RelayInventoryEvent(component, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnLowPressureEvent(EntityUid uid, InventoryComponent component, LowPressureEvent args)
|
private void OnLowPressureEvent(EntityUid uid, InventoryComponent component, LowPressureEvent args)
|
||||||
{
|
{
|
||||||
RelayPressureEvent(component, args);
|
RelayInventoryEvent(component, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnElectrocutionAttempt(EntityUid uid, InventoryComponent component, ElectrocutionAttemptEvent args)
|
private void OnElectrocutionAttempt(EntityUid uid, InventoryComponent component, ElectrocutionAttemptEvent args)
|
||||||
{
|
{
|
||||||
foreach (var equipped in component.GetAllHeldItems())
|
RelayInventoryEvent(component, args);
|
||||||
{
|
|
||||||
RaiseLocalEvent(equipped.Uid, args, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDamageModify(EntityUid uid, InventoryComponent component, DamageModifyEvent args)
|
private void OnDamageModify(EntityUid uid, InventoryComponent component, DamageModifyEvent args)
|
||||||
{
|
{
|
||||||
foreach (var equipped in component.GetAllHeldItems())
|
RelayInventoryEvent(component, args);
|
||||||
{
|
|
||||||
RaiseLocalEvent(equipped.Uid, args, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RelayPressureEvent<T>(InventoryComponent component, T args) where T : PressureEvent
|
private void RelayInventoryEvent<T>(InventoryComponent component, T args) where T : EntityEventArgs
|
||||||
{
|
{
|
||||||
foreach (var equipped in component.GetAllHeldItems())
|
foreach (var equipped in component.GetAllHeldItems())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using Content.Shared.Alert;
|
|||||||
using Content.Shared.Damage;
|
using Content.Shared.Damage;
|
||||||
using Content.Shared.MobState;
|
using Content.Shared.MobState;
|
||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
using Content.Shared.Nutrition.Components;
|
using Content.Shared.Nutrition.Components;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
@@ -86,7 +87,7 @@ namespace Content.Server.Nutrition.Components
|
|||||||
if (_lastHungerThreshold == HungerThreshold.Starving && _currentHungerThreshold != HungerThreshold.Dead &&
|
if (_lastHungerThreshold == HungerThreshold.Starving && _currentHungerThreshold != HungerThreshold.Dead &&
|
||||||
Owner.TryGetComponent(out MovementSpeedModifierComponent? movementSlowdownComponent))
|
Owner.TryGetComponent(out MovementSpeedModifierComponent? movementSlowdownComponent))
|
||||||
{
|
{
|
||||||
movementSlowdownComponent.RefreshMovementSpeedModifiers();
|
EntitySystem.Get<MovementSpeedModifierSystem>().RefreshMovementSpeedModifiers(OwnerUid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update UI
|
// Update UI
|
||||||
@@ -122,10 +123,7 @@ namespace Content.Server.Nutrition.Components
|
|||||||
case HungerThreshold.Starving:
|
case HungerThreshold.Starving:
|
||||||
// TODO: If something else bumps this could cause mega-speed.
|
// TODO: If something else bumps this could cause mega-speed.
|
||||||
// If some form of speed update system if multiple things are touching it use that.
|
// If some form of speed update system if multiple things are touching it use that.
|
||||||
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? movementSlowdownComponent1))
|
EntitySystem.Get<MovementSpeedModifierSystem>().RefreshMovementSpeedModifiers(OwnerUid);
|
||||||
{
|
|
||||||
movementSlowdownComponent1.RefreshMovementSpeedModifiers();
|
|
||||||
}
|
|
||||||
_lastHungerThreshold = _currentHungerThreshold;
|
_lastHungerThreshold = _currentHungerThreshold;
|
||||||
_actualDecayRate = _baseDecayRate * 0.6f;
|
_actualDecayRate = _baseDecayRate * 0.6f;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using Content.Shared.Alert;
|
|||||||
using Content.Shared.Damage;
|
using Content.Shared.Damage;
|
||||||
using Content.Shared.MobState;
|
using Content.Shared.MobState;
|
||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
using Content.Shared.Nutrition.Components;
|
using Content.Shared.Nutrition.Components;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
@@ -85,7 +86,7 @@ namespace Content.Server.Nutrition.Components
|
|||||||
if (_lastThirstThreshold == ThirstThreshold.Parched && _currentThirstThreshold != ThirstThreshold.Dead &&
|
if (_lastThirstThreshold == ThirstThreshold.Parched && _currentThirstThreshold != ThirstThreshold.Dead &&
|
||||||
Owner.TryGetComponent(out MovementSpeedModifierComponent? movementSlowdownComponent))
|
Owner.TryGetComponent(out MovementSpeedModifierComponent? movementSlowdownComponent))
|
||||||
{
|
{
|
||||||
movementSlowdownComponent.RefreshMovementSpeedModifiers();
|
EntitySystem.Get<MovementSpeedModifierSystem>().RefreshMovementSpeedModifiers(OwnerUid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update UI
|
// Update UI
|
||||||
@@ -119,10 +120,7 @@ namespace Content.Server.Nutrition.Components
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
case ThirstThreshold.Parched:
|
case ThirstThreshold.Parched:
|
||||||
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? movementSlowdownComponent1))
|
EntitySystem.Get<MovementSpeedModifierSystem>().RefreshMovementSpeedModifiers(OwnerUid);
|
||||||
{
|
|
||||||
movementSlowdownComponent1.RefreshMovementSpeedModifiers();
|
|
||||||
}
|
|
||||||
_lastThirstThreshold = _currentThirstThreshold;
|
_lastThirstThreshold = _currentThirstThreshold;
|
||||||
_actualDecayRate = _baseDecayRate * 0.6f;
|
_actualDecayRate = _baseDecayRate * 0.6f;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -34,10 +34,9 @@ namespace Content.Server.Stunnable
|
|||||||
ServerAlertsComponent? alerts = null;
|
ServerAlertsComponent? alerts = null;
|
||||||
StandingStateComponent? standingState = null;
|
StandingStateComponent? standingState = null;
|
||||||
AppearanceComponent? appearance = null;
|
AppearanceComponent? appearance = null;
|
||||||
MovementSpeedModifierComponent? speedModifier = null;
|
|
||||||
|
|
||||||
// Let the actual methods log errors for these.
|
// Let the actual methods log errors for these.
|
||||||
Resolve(otherUid, ref alerts, ref standingState, ref appearance, ref speedModifier, false);
|
Resolve(otherUid, ref alerts, ref standingState, ref appearance, false);
|
||||||
|
|
||||||
_stunSystem.TryStun(otherUid, TimeSpan.FromSeconds(component.StunAmount), status, alerts);
|
_stunSystem.TryStun(otherUid, TimeSpan.FromSeconds(component.StunAmount), status, alerts);
|
||||||
|
|
||||||
@@ -45,7 +44,7 @@ namespace Content.Server.Stunnable
|
|||||||
status, alerts);
|
status, alerts);
|
||||||
|
|
||||||
_stunSystem.TrySlowdown(otherUid, TimeSpan.FromSeconds(component.SlowdownAmount),
|
_stunSystem.TrySlowdown(otherUid, TimeSpan.FromSeconds(component.SlowdownAmount),
|
||||||
component.WalkSpeedMultiplier, component.RunSpeedMultiplier, status, speedModifier, alerts);
|
component.WalkSpeedMultiplier, component.RunSpeedMultiplier, status, alerts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using Robust.Shared.Players;
|
|||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
using System;
|
using System;
|
||||||
|
using Robust.Shared.Analyzers;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
@@ -13,7 +14,7 @@ namespace Content.Shared.Chemistry.Components
|
|||||||
//TODO: refactor movement modifier component because this is a pretty poor solution
|
//TODO: refactor movement modifier component because this is a pretty poor solution
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
[NetworkedComponent]
|
[NetworkedComponent]
|
||||||
public sealed class MovespeedModifierMetabolismComponent : Component, IMoveSpeedModifier
|
public sealed class MovespeedModifierMetabolismComponent : Component
|
||||||
{
|
{
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public override string Name => "MovespeedModifierMetabolism";
|
public override string Name => "MovespeedModifierMetabolism";
|
||||||
|
|||||||
@@ -6,13 +6,16 @@ using Robust.Shared.Timing;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
using static Content.Shared.Chemistry.Components.MovespeedModifierMetabolismComponent;
|
using static Content.Shared.Chemistry.Components.MovespeedModifierMetabolismComponent;
|
||||||
|
|
||||||
namespace Content.Shared.Chemistry
|
namespace Content.Shared.Chemistry
|
||||||
{
|
{
|
||||||
|
// TODO CONVERT THIS TO A STATUS EFFECT!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
public class MetabolismMovespeedModifierSystem : EntitySystem
|
public class MetabolismMovespeedModifierSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||||
|
[Dependency] private readonly MovementSpeedModifierSystem _movespeed = default!;
|
||||||
|
|
||||||
private readonly List<MovespeedModifierMetabolismComponent> _components = new();
|
private readonly List<MovespeedModifierMetabolismComponent> _components = new();
|
||||||
|
|
||||||
@@ -22,6 +25,7 @@ namespace Content.Shared.Chemistry
|
|||||||
|
|
||||||
SubscribeLocalEvent<MovespeedModifierMetabolismComponent, ComponentHandleState>(OnMovespeedHandleState);
|
SubscribeLocalEvent<MovespeedModifierMetabolismComponent, ComponentHandleState>(OnMovespeedHandleState);
|
||||||
SubscribeLocalEvent<MovespeedModifierMetabolismComponent, ComponentStartup>(AddComponent);
|
SubscribeLocalEvent<MovespeedModifierMetabolismComponent, ComponentStartup>(AddComponent);
|
||||||
|
SubscribeLocalEvent<MovespeedModifierMetabolismComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMovespeedHandleState(EntityUid uid, MovespeedModifierMetabolismComponent component, ref ComponentHandleState args)
|
private void OnMovespeedHandleState(EntityUid uid, MovespeedModifierMetabolismComponent component, ref ComponentHandleState args)
|
||||||
@@ -33,7 +37,7 @@ namespace Content.Shared.Chemistry
|
|||||||
(!component.WalkSpeedModifier.Equals(cast.WalkSpeedModifier) ||
|
(!component.WalkSpeedModifier.Equals(cast.WalkSpeedModifier) ||
|
||||||
!component.SprintSpeedModifier.Equals(cast.SprintSpeedModifier)))
|
!component.SprintSpeedModifier.Equals(cast.SprintSpeedModifier)))
|
||||||
{
|
{
|
||||||
modifier.RefreshMovementSpeedModifiers();
|
_movespeed.RefreshMovementSpeedModifiers(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
component.WalkSpeedModifier = cast.WalkSpeedModifier;
|
component.WalkSpeedModifier = cast.WalkSpeedModifier;
|
||||||
@@ -41,6 +45,12 @@ namespace Content.Shared.Chemistry
|
|||||||
component.ModifierTimer = cast.ModifierTimer;
|
component.ModifierTimer = cast.ModifierTimer;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnRefreshMovespeed(EntityUid uid, MovespeedModifierMetabolismComponent component, RefreshMovementSpeedModifiersEvent args)
|
||||||
|
{
|
||||||
|
args.ModifySpeed(component.WalkSpeedModifier, component.SprintSpeedModifier);
|
||||||
|
}
|
||||||
|
|
||||||
private void AddComponent(EntityUid uid, MovespeedModifierMetabolismComponent component, ComponentStartup args)
|
private void AddComponent(EntityUid uid, MovespeedModifierMetabolismComponent component, ComponentStartup args)
|
||||||
{
|
{
|
||||||
_components.Add(component);
|
_components.Add(component);
|
||||||
@@ -65,12 +75,9 @@ namespace Content.Shared.Chemistry
|
|||||||
if (component.ModifierTimer > currentTime) continue;
|
if (component.ModifierTimer > currentTime) continue;
|
||||||
|
|
||||||
_components.RemoveAt(i);
|
_components.RemoveAt(i);
|
||||||
EntityManager.RemoveComponent<MovespeedModifierMetabolismComponent>(component.Owner.Uid);
|
EntityManager.RemoveComponent<MovespeedModifierMetabolismComponent>(component.OwnerUid);
|
||||||
|
|
||||||
if (component.Owner.TryGetComponent(out MovementSpeedModifierComponent? modifier))
|
_movespeed.RefreshMovementSpeedModifiers(component.OwnerUid);
|
||||||
{
|
|
||||||
modifier.RefreshMovementSpeedModifiers();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
@@ -7,16 +9,19 @@ using Robust.Shared.Serialization;
|
|||||||
namespace Content.Shared.Clothing
|
namespace Content.Shared.Clothing
|
||||||
{
|
{
|
||||||
[NetworkedComponent()]
|
[NetworkedComponent()]
|
||||||
public abstract class SharedMagbootsComponent : Component, IMoveSpeedModifier
|
public abstract class SharedMagbootsComponent : Component
|
||||||
{
|
{
|
||||||
public sealed override string Name => "Magboots";
|
public sealed override string Name => "Magboots";
|
||||||
|
|
||||||
public abstract bool On { get; set; }
|
public abstract bool On { get; set; }
|
||||||
|
|
||||||
|
|
||||||
protected void OnChanged()
|
protected void OnChanged()
|
||||||
{
|
{
|
||||||
MovementSpeedModifierComponent.RefreshItemModifiers(Owner);
|
// inventory system will automatically hook into the event raised by this and update accordingly
|
||||||
|
if (Owner.TryGetContainer(out var container))
|
||||||
|
{
|
||||||
|
EntitySystem.Get<MovementSpeedModifierSystem>().RefreshMovementSpeedModifiers(container.Owner.Uid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public float WalkSpeedModifier => On ? 0.85f : 1;
|
public float WalkSpeedModifier => On ? 0.85f : 1;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ using static Content.Shared.Inventory.EquipmentSlotDefines;
|
|||||||
namespace Content.Shared.Inventory
|
namespace Content.Shared.Inventory
|
||||||
{
|
{
|
||||||
[NetworkedComponent()]
|
[NetworkedComponent()]
|
||||||
public abstract class SharedInventoryComponent : Component, IMoveSpeedModifier
|
public abstract class SharedInventoryComponent : Component
|
||||||
{
|
{
|
||||||
[Dependency] protected readonly IReflectionManager ReflectionManager = default!;
|
[Dependency] protected readonly IReflectionManager ReflectionManager = default!;
|
||||||
[Dependency] protected readonly IDynamicTypeFactory DynamicTypeFactory = default!;
|
[Dependency] protected readonly IDynamicTypeFactory DynamicTypeFactory = default!;
|
||||||
@@ -98,8 +98,5 @@ namespace Content.Shared.Inventory
|
|||||||
Slot = slot;
|
Slot = slot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract float WalkSpeedModifier { get; }
|
|
||||||
public abstract float SprintSpeedModifier { get; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
|
using Robust.Shared.Analyzers;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
@@ -7,7 +9,7 @@ using Robust.Shared.ViewVariables;
|
|||||||
namespace Content.Shared.Movement.Components
|
namespace Content.Shared.Movement.Components
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
[NetworkedComponent]
|
[NetworkedComponent, Friend(typeof(MovementSpeedModifierSystem))]
|
||||||
public sealed class MovementSpeedModifierComponent : Component
|
public sealed class MovementSpeedModifierComponent : Component
|
||||||
{
|
{
|
||||||
public const float DefaultBaseWalkSpeed = 4.0f;
|
public const float DefaultBaseWalkSpeed = 4.0f;
|
||||||
@@ -15,26 +17,11 @@ namespace Content.Shared.Movement.Components
|
|||||||
|
|
||||||
public override string Name => "MovementSpeedModifier";
|
public override string Name => "MovementSpeedModifier";
|
||||||
|
|
||||||
private float _cachedWalkSpeedModifier = 1.0f;
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public float WalkSpeedModifier
|
public float WalkSpeedModifier = 1.0f;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
RecalculateMovementSpeedModifiers();
|
|
||||||
return _cachedWalkSpeedModifier;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private float _cachedSprintSpeedModifier;
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public float SprintSpeedModifier
|
public float SprintSpeedModifier = 1.0f;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
RecalculateMovementSpeedModifiers();
|
|
||||||
return _cachedSprintSpeedModifier;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
public float BaseWalkSpeedVV
|
public float BaseWalkSpeedVV
|
||||||
@@ -68,52 +55,5 @@ namespace Content.Shared.Movement.Components
|
|||||||
public float CurrentWalkSpeed => WalkSpeedModifier * BaseWalkSpeed;
|
public float CurrentWalkSpeed => WalkSpeedModifier * BaseWalkSpeed;
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public float CurrentSprintSpeed => SprintSpeedModifier * BaseSprintSpeed;
|
public float CurrentSprintSpeed => SprintSpeedModifier * BaseSprintSpeed;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// set to warn us that a component's movespeed modifier has changed
|
|
||||||
/// </summary>
|
|
||||||
private bool _movespeedModifiersNeedRefresh = true;
|
|
||||||
|
|
||||||
public void RefreshMovementSpeedModifiers()
|
|
||||||
{
|
|
||||||
_movespeedModifiersNeedRefresh = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RefreshItemModifiers(IEntity item)
|
|
||||||
{
|
|
||||||
if (item.TryGetContainer(out var container) &&
|
|
||||||
container.Owner.TryGetComponent(out MovementSpeedModifierComponent? mod))
|
|
||||||
{
|
|
||||||
mod.RefreshMovementSpeedModifiers();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Recalculate movement speed with current modifiers, or return early if no change
|
|
||||||
/// </summary>
|
|
||||||
private void RecalculateMovementSpeedModifiers()
|
|
||||||
{
|
|
||||||
{
|
|
||||||
if (!_movespeedModifiersNeedRefresh)
|
|
||||||
return;
|
|
||||||
var movespeedModifiers = Owner.GetAllComponents<IMoveSpeedModifier>();
|
|
||||||
float walkSpeedModifier = 1.0f;
|
|
||||||
float sprintSpeedModifier = 1.0f;
|
|
||||||
foreach (var component in movespeedModifiers)
|
|
||||||
{
|
|
||||||
walkSpeedModifier *= component.WalkSpeedModifier;
|
|
||||||
sprintSpeedModifier *= component.SprintSpeedModifier;
|
|
||||||
}
|
|
||||||
_cachedWalkSpeedModifier = walkSpeedModifier;
|
|
||||||
_cachedSprintSpeedModifier = sprintSpeedModifier;
|
|
||||||
}
|
|
||||||
_movespeedModifiersNeedRefresh = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface IMoveSpeedModifier
|
|
||||||
{
|
|
||||||
float WalkSpeedModifier { get; }
|
|
||||||
float SprintSpeedModifier { get; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
@@ -8,6 +10,18 @@ namespace Content.Shared.Movement.EntitySystems
|
|||||||
{
|
{
|
||||||
public sealed class MovementSpeedModifierSystem : EntitySystem
|
public sealed class MovementSpeedModifierSystem : EntitySystem
|
||||||
{
|
{
|
||||||
|
private readonly HashSet<EntityUid> _needsRefresh = new();
|
||||||
|
|
||||||
|
public override void Update(float frameTime)
|
||||||
|
{
|
||||||
|
foreach (var uid in _needsRefresh)
|
||||||
|
{
|
||||||
|
RecalculateMovementSpeedModifiers(uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
_needsRefresh.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
@@ -31,6 +45,25 @@ namespace Content.Shared.Movement.EntitySystems
|
|||||||
component.BaseSprintSpeed = state.BaseSprintSpeed;
|
component.BaseSprintSpeed = state.BaseSprintSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RefreshMovementSpeedModifiers(EntityUid uid)
|
||||||
|
{
|
||||||
|
_needsRefresh.Add(uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RecalculateMovementSpeedModifiers(EntityUid uid, MovementSpeedModifierComponent? move = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref move, false))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var ev = new RefreshMovementSpeedModifiersEvent();
|
||||||
|
RaiseLocalEvent(uid, ev, false);
|
||||||
|
|
||||||
|
move.WalkSpeedModifier = ev.WalkSpeedModifier;
|
||||||
|
move.SprintSpeedModifier = ev.SprintSpeedModifier;
|
||||||
|
|
||||||
|
move.Dirty();
|
||||||
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
private sealed class MovementSpeedModifierComponentState : ComponentState
|
private sealed class MovementSpeedModifierComponentState : ComponentState
|
||||||
{
|
{
|
||||||
@@ -38,4 +71,21 @@ namespace Content.Shared.Movement.EntitySystems
|
|||||||
public float BaseSprintSpeed;
|
public float BaseSprintSpeed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Raised on an entity to determine its new movement speed. Any system that wishes to change movement speed
|
||||||
|
/// should hook into this event and set it then. If you want this event to be raised,
|
||||||
|
/// call <see cref="MovementSpeedModifierSystem.RefreshMovementSpeedModifiers"/>.
|
||||||
|
/// </summary>
|
||||||
|
public class RefreshMovementSpeedModifiersEvent : EntityEventArgs
|
||||||
|
{
|
||||||
|
public float WalkSpeedModifier { get; private set; } = 1.0f;
|
||||||
|
public float SprintSpeedModifier { get; private set; } = 1.0f;
|
||||||
|
|
||||||
|
public void ModifySpeed(float walk, float sprint)
|
||||||
|
{
|
||||||
|
WalkSpeedModifier *= walk;
|
||||||
|
SprintSpeedModifier *= sprint;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,37 +8,13 @@ using Robust.Shared.ViewVariables;
|
|||||||
namespace Content.Shared.Nutrition.Components
|
namespace Content.Shared.Nutrition.Components
|
||||||
{
|
{
|
||||||
[NetworkedComponent()]
|
[NetworkedComponent()]
|
||||||
public abstract class SharedHungerComponent : Component, IMoveSpeedModifier
|
public abstract class SharedHungerComponent : Component
|
||||||
{
|
{
|
||||||
public sealed override string Name => "Hunger";
|
public sealed override string Name => "Hunger";
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public abstract HungerThreshold CurrentHungerThreshold { get; }
|
public abstract HungerThreshold CurrentHungerThreshold { get; }
|
||||||
|
|
||||||
|
|
||||||
float IMoveSpeedModifier.WalkSpeedModifier
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (CurrentHungerThreshold == HungerThreshold.Starving)
|
|
||||||
{
|
|
||||||
return 0.75f;
|
|
||||||
}
|
|
||||||
return 1.0f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
float IMoveSpeedModifier.SprintSpeedModifier
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (CurrentHungerThreshold == HungerThreshold.Starving)
|
|
||||||
{
|
|
||||||
return 0.75f;
|
|
||||||
}
|
|
||||||
return 1.0f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
protected sealed class HungerComponentState : ComponentState
|
protected sealed class HungerComponentState : ComponentState
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,36 +8,13 @@ using Robust.Shared.ViewVariables;
|
|||||||
namespace Content.Shared.Nutrition.Components
|
namespace Content.Shared.Nutrition.Components
|
||||||
{
|
{
|
||||||
[NetworkedComponent()]
|
[NetworkedComponent()]
|
||||||
public abstract class SharedThirstComponent : Component, IMoveSpeedModifier
|
public abstract class SharedThirstComponent : Component
|
||||||
{
|
{
|
||||||
public sealed override string Name => "Thirst";
|
public sealed override string Name => "Thirst";
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public abstract ThirstThreshold CurrentThirstThreshold { get; }
|
public abstract ThirstThreshold CurrentThirstThreshold { get; }
|
||||||
|
|
||||||
float IMoveSpeedModifier.SprintSpeedModifier
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (CurrentThirstThreshold == ThirstThreshold.Parched)
|
|
||||||
{
|
|
||||||
return 0.75f;
|
|
||||||
}
|
|
||||||
return 1.0f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
float IMoveSpeedModifier.WalkSpeedModifier
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (CurrentThirstThreshold == ThirstThreshold.Parched)
|
|
||||||
{
|
|
||||||
return 0.75f;
|
|
||||||
}
|
|
||||||
return 1.0f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
protected sealed class ThirstComponentState : ComponentState
|
protected sealed class ThirstComponentState : ComponentState
|
||||||
{
|
{
|
||||||
|
|||||||
22
Content.Shared/Nutrition/EntitySystems/SharedHungerSystem.cs
Normal file
22
Content.Shared/Nutrition/EntitySystems/SharedHungerSystem.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
|
using Content.Shared.Nutrition.Components;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
|
||||||
|
namespace Content.Shared.Nutrition.EntitySystems
|
||||||
|
{
|
||||||
|
public class SharedHungerSystem : EntitySystem
|
||||||
|
{
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
SubscribeLocalEvent<SharedHungerComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnRefreshMovespeed(EntityUid uid, SharedHungerComponent component, RefreshMovementSpeedModifiersEvent args)
|
||||||
|
{
|
||||||
|
float mod = component.CurrentHungerThreshold == HungerThreshold.Starving ? 0.75f : 1.0f;
|
||||||
|
args.ModifySpeed(mod, mod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
Content.Shared/Nutrition/EntitySystems/SharedThirstSystem.cs
Normal file
22
Content.Shared/Nutrition/EntitySystems/SharedThirstSystem.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
|
using Content.Shared.Nutrition.Components;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
|
||||||
|
namespace Content.Shared.Nutrition.EntitySystems
|
||||||
|
{
|
||||||
|
public class SharedThirstSystem : EntitySystem
|
||||||
|
{
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
SubscribeLocalEvent<SharedThirstComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnRefreshMovespeed(EntityUid uid, SharedThirstComponent component, RefreshMovementSpeedModifiersEvent args)
|
||||||
|
{
|
||||||
|
float mod = component.CurrentThirstThreshold == ThirstThreshold.Parched ? 0.75f : 1.0f;
|
||||||
|
args.ModifySpeed(mod, mod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ namespace Content.Shared.Pulling.Components
|
|||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
[Friend(typeof(SharedPullingStateManagementSystem))]
|
[Friend(typeof(SharedPullingStateManagementSystem))]
|
||||||
public class SharedPullerComponent : Component, IMoveSpeedModifier
|
public class SharedPullerComponent : Component
|
||||||
{
|
{
|
||||||
public override string Name => "Puller";
|
public override string Name => "Puller";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Content.Shared.Alert;
|
using Content.Shared.Alert;
|
||||||
using Content.Shared.Hands;
|
using Content.Shared.Hands;
|
||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
using Content.Shared.Physics.Pull;
|
using Content.Shared.Physics.Pull;
|
||||||
using Content.Shared.Pulling.Components;
|
using Content.Shared.Pulling.Components;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
@@ -13,6 +14,7 @@ namespace Content.Shared.Pulling.Systems
|
|||||||
public sealed class SharedPullerSystem : EntitySystem
|
public sealed class SharedPullerSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly SharedPullingSystem _pullSystem = default!;
|
[Dependency] private readonly SharedPullingSystem _pullSystem = default!;
|
||||||
|
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifierSystem = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -21,6 +23,7 @@ namespace Content.Shared.Pulling.Systems
|
|||||||
SubscribeLocalEvent<SharedPullerComponent, PullStartedMessage>(PullerHandlePullStarted);
|
SubscribeLocalEvent<SharedPullerComponent, PullStartedMessage>(PullerHandlePullStarted);
|
||||||
SubscribeLocalEvent<SharedPullerComponent, PullStoppedMessage>(PullerHandlePullStopped);
|
SubscribeLocalEvent<SharedPullerComponent, PullStoppedMessage>(PullerHandlePullStopped);
|
||||||
SubscribeLocalEvent<SharedPullerComponent, VirtualItemDeletedEvent>(OnVirtualItemDeleted);
|
SubscribeLocalEvent<SharedPullerComponent, VirtualItemDeletedEvent>(OnVirtualItemDeleted);
|
||||||
|
SubscribeLocalEvent<SharedPullerComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnVirtualItemDeleted(EntityUid uid, SharedPullerComponent component, VirtualItemDeletedEvent args)
|
private void OnVirtualItemDeleted(EntityUid uid, SharedPullerComponent component, VirtualItemDeletedEvent args)
|
||||||
@@ -37,7 +40,7 @@ namespace Content.Shared.Pulling.Systems
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void PullerHandlePullStarted(
|
private void PullerHandlePullStarted(
|
||||||
EntityUid uid,
|
EntityUid uid,
|
||||||
SharedPullerComponent component,
|
SharedPullerComponent component,
|
||||||
PullStartedMessage args)
|
PullStartedMessage args)
|
||||||
@@ -51,7 +54,7 @@ namespace Content.Shared.Pulling.Systems
|
|||||||
RefreshMovementSpeed(component);
|
RefreshMovementSpeed(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void PullerHandlePullStopped(
|
private void PullerHandlePullStopped(
|
||||||
EntityUid uid,
|
EntityUid uid,
|
||||||
SharedPullerComponent component,
|
SharedPullerComponent component,
|
||||||
PullStoppedMessage args)
|
PullStoppedMessage args)
|
||||||
@@ -65,13 +68,14 @@ namespace Content.Shared.Pulling.Systems
|
|||||||
RefreshMovementSpeed(component);
|
RefreshMovementSpeed(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RefreshMovementSpeed(SharedPullerComponent component)
|
private void OnRefreshMovespeed(EntityUid uid, SharedPullerComponent component, RefreshMovementSpeedModifiersEvent args)
|
||||||
{
|
{
|
||||||
// Before changing how this is updated, please see SharedPullerComponent
|
args.ModifySpeed(component.WalkSpeedModifier, component.SprintSpeedModifier);
|
||||||
if (component.Owner.TryGetComponent<MovementSpeedModifierComponent>(out var speed))
|
}
|
||||||
{
|
|
||||||
speed.RefreshMovementSpeedModifiers();
|
private void RefreshMovementSpeed(SharedPullerComponent component)
|
||||||
}
|
{
|
||||||
|
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers(component.OwnerUid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using Content.Shared.Inventory.Events;
|
|||||||
using Content.Shared.Item;
|
using Content.Shared.Item;
|
||||||
using Content.Shared.Movement;
|
using Content.Shared.Movement;
|
||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
|
using Content.Shared.Movement.EntitySystems;
|
||||||
using Content.Shared.Speech;
|
using Content.Shared.Speech;
|
||||||
using Content.Shared.Standing;
|
using Content.Shared.Standing;
|
||||||
using Content.Shared.StatusEffect;
|
using Content.Shared.StatusEffect;
|
||||||
@@ -27,6 +28,7 @@ namespace Content.Shared.Stunnable
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly StandingStateSystem _standingStateSystem = default!;
|
[Dependency] private readonly StandingStateSystem _standingStateSystem = default!;
|
||||||
[Dependency] private readonly StatusEffectsSystem _statusEffectSystem = default!;
|
[Dependency] private readonly StatusEffectsSystem _statusEffectSystem = default!;
|
||||||
|
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifierSystem = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -44,6 +46,7 @@ namespace Content.Shared.Stunnable
|
|||||||
|
|
||||||
// helping people up if they're knocked down
|
// helping people up if they're knocked down
|
||||||
SubscribeLocalEvent<KnockedDownComponent, InteractHandEvent>(OnInteractHand);
|
SubscribeLocalEvent<KnockedDownComponent, InteractHandEvent>(OnInteractHand);
|
||||||
|
SubscribeLocalEvent<SlowedDownComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
|
||||||
|
|
||||||
// Attempt event subscriptions.
|
// Attempt event subscriptions.
|
||||||
SubscribeLocalEvent<StunnedComponent, MovementAttemptEvent>(OnMoveAttempt);
|
SubscribeLocalEvent<StunnedComponent, MovementAttemptEvent>(OnMoveAttempt);
|
||||||
@@ -97,22 +100,17 @@ namespace Content.Shared.Stunnable
|
|||||||
|
|
||||||
private void OnSlowInit(EntityUid uid, SlowedDownComponent component, ComponentInit args)
|
private void OnSlowInit(EntityUid uid, SlowedDownComponent component, ComponentInit args)
|
||||||
{
|
{
|
||||||
// needs to be done so the client can also refresh when the addition is replicated,
|
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers(uid);
|
||||||
// if the initial status effect addition wasn't predicted
|
|
||||||
if (EntityManager.TryGetComponent<MovementSpeedModifierComponent>(uid, out var move))
|
|
||||||
{
|
|
||||||
move.RefreshMovementSpeedModifiers();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSlowRemove(EntityUid uid, SlowedDownComponent component, ComponentRemove args)
|
private void OnSlowRemove(EntityUid uid, SlowedDownComponent component, ComponentRemove args)
|
||||||
{
|
{
|
||||||
if (EntityManager.TryGetComponent<MovementSpeedModifierComponent>(uid, out var move))
|
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers(uid);
|
||||||
{
|
}
|
||||||
component.SprintSpeedModifier = 1.0f;
|
|
||||||
component.WalkSpeedModifier = 1.0f;
|
private void OnRefreshMovespeed(EntityUid uid, SlowedDownComponent component, RefreshMovementSpeedModifiersEvent args)
|
||||||
move.RefreshMovementSpeedModifiers();
|
{
|
||||||
}
|
args.ModifySpeed(component.WalkSpeedModifier, component.SprintSpeedModifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO STUN: Make events for different things. (Getting modifiers, attempt events, informative events...)
|
// TODO STUN: Make events for different things. (Getting modifiers, attempt events, informative events...)
|
||||||
@@ -127,6 +125,9 @@ namespace Content.Shared.Stunnable
|
|||||||
if (time <= TimeSpan.Zero)
|
if (time <= TimeSpan.Zero)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!Resolve(uid, ref status, false))
|
||||||
|
return false;
|
||||||
|
|
||||||
Resolve(uid, ref alerts, false);
|
Resolve(uid, ref alerts, false);
|
||||||
|
|
||||||
return _statusEffectSystem.TryAddStatusEffect<StunnedComponent>(uid, "Stun", time, alerts: alerts);
|
return _statusEffectSystem.TryAddStatusEffect<StunnedComponent>(uid, "Stun", time, alerts: alerts);
|
||||||
@@ -142,6 +143,9 @@ namespace Content.Shared.Stunnable
|
|||||||
if (time <= TimeSpan.Zero)
|
if (time <= TimeSpan.Zero)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!Resolve(uid, ref status, false))
|
||||||
|
return false;
|
||||||
|
|
||||||
Resolve(uid, ref alerts, false);
|
Resolve(uid, ref alerts, false);
|
||||||
|
|
||||||
return _statusEffectSystem.TryAddStatusEffect<KnockedDownComponent>(uid, "KnockedDown", time, alerts: alerts);
|
return _statusEffectSystem.TryAddStatusEffect<KnockedDownComponent>(uid, "KnockedDown", time, alerts: alerts);
|
||||||
@@ -154,6 +158,9 @@ namespace Content.Shared.Stunnable
|
|||||||
StatusEffectsComponent? status = null,
|
StatusEffectsComponent? status = null,
|
||||||
SharedAlertsComponent? alerts = null)
|
SharedAlertsComponent? alerts = null)
|
||||||
{
|
{
|
||||||
|
if (!Resolve(uid, ref status))
|
||||||
|
return false;
|
||||||
|
|
||||||
// Optional component.
|
// Optional component.
|
||||||
Resolve(uid, ref alerts, false);
|
Resolve(uid, ref alerts, false);
|
||||||
|
|
||||||
@@ -166,11 +173,13 @@ namespace Content.Shared.Stunnable
|
|||||||
public bool TrySlowdown(EntityUid uid, TimeSpan time,
|
public bool TrySlowdown(EntityUid uid, TimeSpan time,
|
||||||
float walkSpeedMultiplier = 1f, float runSpeedMultiplier = 1f,
|
float walkSpeedMultiplier = 1f, float runSpeedMultiplier = 1f,
|
||||||
StatusEffectsComponent? status = null,
|
StatusEffectsComponent? status = null,
|
||||||
MovementSpeedModifierComponent? speedModifier = null,
|
|
||||||
SharedAlertsComponent? alerts = null)
|
SharedAlertsComponent? alerts = null)
|
||||||
{
|
{
|
||||||
|
if (!Resolve(uid, ref status))
|
||||||
|
return false;
|
||||||
|
|
||||||
// "Optional" component.
|
// "Optional" component.
|
||||||
Resolve(uid, ref speedModifier, false);
|
Resolve(uid, ref alerts, false);
|
||||||
|
|
||||||
if (time <= TimeSpan.Zero)
|
if (time <= TimeSpan.Zero)
|
||||||
return false;
|
return false;
|
||||||
@@ -185,7 +194,7 @@ namespace Content.Shared.Stunnable
|
|||||||
slowed.WalkSpeedModifier *= walkSpeedMultiplier;
|
slowed.WalkSpeedModifier *= walkSpeedMultiplier;
|
||||||
slowed.SprintSpeedModifier *= runSpeedMultiplier;
|
slowed.SprintSpeedModifier *= runSpeedMultiplier;
|
||||||
|
|
||||||
speedModifier?.RefreshMovementSpeedModifiers();
|
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers(uid);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace Content.Shared.Stunnable
|
|||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
[NetworkedComponent]
|
[NetworkedComponent]
|
||||||
[Friend(typeof(SharedStunSystem))]
|
[Friend(typeof(SharedStunSystem))]
|
||||||
public class SlowedDownComponent : Component, IMoveSpeedModifier
|
public class SlowedDownComponent : Component
|
||||||
{
|
{
|
||||||
public override string Name => "SlowedDown";
|
public override string Name => "SlowedDown";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user