Fix weightlessness status effect appearing only after something checks if an entity is weightless (#2434)
* Revert "Add weightlessness status effect. (#2384)"
This reverts commit 9b751fc079.
* Bring back the icon and status
* Make weightless status track gravity and parent
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Content.Server.GameObjects.Components.Atmos;
|
using Content.Server.GameObjects.Components.Atmos;
|
||||||
using Content.Server.GameObjects.Components.Buckle;
|
using Content.Server.GameObjects.Components.Buckle;
|
||||||
using Content.Server.GameObjects.Components.GUI;
|
|
||||||
using Content.Server.GameObjects.Components.Movement;
|
using Content.Server.GameObjects.Components.Movement;
|
||||||
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
using Content.Shared.GameObjects.Components.Mobs;
|
using Content.Shared.GameObjects.Components.Mobs;
|
||||||
using Content.Shared.GameObjects.Components.Pulling;
|
using Content.Shared.GameObjects.Components.Pulling;
|
||||||
using Content.Shared.GameObjects.EntitySystems;
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
@@ -23,6 +23,20 @@ namespace Content.Server.GameObjects.Components.Mobs
|
|||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
private readonly Dictionary<StatusEffect, StatusEffectStatus> _statusEffects = new Dictionary<StatusEffect, StatusEffectStatus>();
|
private readonly Dictionary<StatusEffect, StatusEffectStatus> _statusEffects = new Dictionary<StatusEffect, StatusEffectStatus>();
|
||||||
|
|
||||||
|
protected override void Startup()
|
||||||
|
{
|
||||||
|
base.Startup();
|
||||||
|
|
||||||
|
EntitySystem.Get<WeightlessSystem>().AddStatus(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnRemove()
|
||||||
|
{
|
||||||
|
EntitySystem.Get<WeightlessSystem>().RemoveStatus(this);
|
||||||
|
|
||||||
|
base.OnRemove();
|
||||||
|
}
|
||||||
|
|
||||||
public override ComponentState GetComponentState()
|
public override ComponentState GetComponentState()
|
||||||
{
|
{
|
||||||
return new StatusEffectComponentState(_statusEffects);
|
return new StatusEffectComponentState(_statusEffects);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Linq;
|
|||||||
using Content.Server.GameObjects.Components.Gravity;
|
using Content.Server.GameObjects.Components.Gravity;
|
||||||
using Content.Server.GameObjects.Components.Mobs;
|
using Content.Server.GameObjects.Components.Mobs;
|
||||||
using Content.Shared.GameObjects.Components.Gravity;
|
using Content.Shared.GameObjects.Components.Gravity;
|
||||||
|
using Content.Shared.GameObjects.EntitySystemMessages.Gravity;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.GameObjects.EntitySystems;
|
using Robust.Server.GameObjects.EntitySystems;
|
||||||
using Robust.Server.Interfaces.Player;
|
using Robust.Server.Interfaces.Player;
|
||||||
@@ -52,12 +53,11 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
{
|
{
|
||||||
if (grid.HasGravity && !gridsWithGravity.Contains(grid.Index))
|
if (grid.HasGravity && !gridsWithGravity.Contains(grid.Index))
|
||||||
{
|
{
|
||||||
grid.HasGravity = false;
|
DisableGravity(grid);
|
||||||
ScheduleGridToShake(grid.Index, ShakeTimes);
|
}
|
||||||
} else if (!grid.HasGravity && gridsWithGravity.Contains(grid.Index))
|
else if (!grid.HasGravity && gridsWithGravity.Contains(grid.Index))
|
||||||
{
|
{
|
||||||
grid.HasGravity = true;
|
EnableGravity(grid);
|
||||||
ScheduleGridToShake(grid.Index, ShakeTimes);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,6 +68,26 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void EnableGravity(IMapGrid grid)
|
||||||
|
{
|
||||||
|
grid.HasGravity = true;
|
||||||
|
ScheduleGridToShake(grid.Index, ShakeTimes);
|
||||||
|
|
||||||
|
var message = new GravityChangedMessage(grid);
|
||||||
|
|
||||||
|
RaiseLocalEvent(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DisableGravity(IMapGrid grid)
|
||||||
|
{
|
||||||
|
grid.HasGravity = false;
|
||||||
|
ScheduleGridToShake(grid.Index, ShakeTimes);
|
||||||
|
|
||||||
|
var message = new GravityChangedMessage(grid);
|
||||||
|
|
||||||
|
RaiseLocalEvent(message);
|
||||||
|
}
|
||||||
|
|
||||||
private void ScheduleGridToShake(GridId gridId, uint shakeTimes)
|
private void ScheduleGridToShake(GridId gridId, uint shakeTimes)
|
||||||
{
|
{
|
||||||
if (!_gridsToShake.Keys.Contains(gridId))
|
if (!_gridsToShake.Keys.Contains(gridId))
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
using Content.Shared.GameObjects.Components.Mobs;
|
|
||||||
using Content.Shared.GameObjects.EntitySystemMessages;
|
|
||||||
using Robust.Shared.GameObjects.Systems;
|
|
||||||
|
|
||||||
namespace Content.Shared.GameObjects.EntitySystems
|
|
||||||
{
|
|
||||||
|
|
||||||
public sealed class WeightlessStatusSystem : EntitySystem
|
|
||||||
{
|
|
||||||
|
|
||||||
public override void Initialize()
|
|
||||||
{
|
|
||||||
base.Initialize();
|
|
||||||
SubscribeLocalEvent<WeightlessChangeMessage>(HandleWeightlessChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void HandleWeightlessChanged(WeightlessChangeMessage msg)
|
|
||||||
{
|
|
||||||
var ent = msg.Entity;
|
|
||||||
if (!ent.TryGetComponent(out SharedStatusEffectsComponent status))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(msg.Weightless)
|
|
||||||
{
|
|
||||||
status.ChangeStatusEffect(StatusEffect.Weightless,"/Textures/Interface/StatusEffects/Weightless/weightless.png",null);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
status.RemoveStatusEffect(StatusEffect.Weightless);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
109
Content.Server/GameObjects/EntitySystems/WeightlessSystem.cs
Normal file
109
Content.Server/GameObjects/EntitySystems/WeightlessSystem.cs
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Content.Server.GameObjects.Components.Mobs;
|
||||||
|
using Content.Shared.GameObjects.Components.Mobs;
|
||||||
|
using Content.Shared.GameObjects.EntitySystemMessages.Gravity;
|
||||||
|
using Content.Shared.GameTicking;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using Robust.Shared.GameObjects.Components.Map;
|
||||||
|
using Robust.Shared.GameObjects.EntitySystemMessages;
|
||||||
|
using Robust.Shared.GameObjects.Systems;
|
||||||
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
|
namespace Content.Server.GameObjects.EntitySystems
|
||||||
|
{
|
||||||
|
[UsedImplicitly]
|
||||||
|
public class WeightlessSystem : EntitySystem, IResettingEntitySystem
|
||||||
|
{
|
||||||
|
private readonly Dictionary<GridId, List<ServerStatusEffectsComponent>> _statuses = new Dictionary<GridId, List<ServerStatusEffectsComponent>>();
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
SubscribeLocalEvent<GravityChangedMessage>(GravityChanged);
|
||||||
|
SubscribeLocalEvent<EntParentChangedMessage>(EntParentChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
_statuses.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddStatus(ServerStatusEffectsComponent status)
|
||||||
|
{
|
||||||
|
var grid = status.Owner.Transform.GridID;
|
||||||
|
var statuses = _statuses.GetOrNew(grid);
|
||||||
|
|
||||||
|
statuses.Add(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveStatus(ServerStatusEffectsComponent status)
|
||||||
|
{
|
||||||
|
var grid = status.Owner.Transform.GridID;
|
||||||
|
if (!_statuses.TryGetValue(grid, out var statuses))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
statuses.Remove(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GravityChanged(GravityChangedMessage ev)
|
||||||
|
{
|
||||||
|
if (!_statuses.TryGetValue(ev.Grid.Index, out var statuses))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ev.HasGravity)
|
||||||
|
{
|
||||||
|
foreach (var status in statuses)
|
||||||
|
{
|
||||||
|
RemoveWeightless(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var status in statuses)
|
||||||
|
{
|
||||||
|
AddWeightless(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddWeightless(ServerStatusEffectsComponent status)
|
||||||
|
{
|
||||||
|
status.ChangeStatusEffect(StatusEffect.Weightless, "/Textures/Interface/StatusEffects/Weightless/weightless.png", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RemoveWeightless(ServerStatusEffectsComponent status)
|
||||||
|
{
|
||||||
|
status.RemoveStatusEffect(StatusEffect.Weightless);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EntParentChanged(EntParentChangedMessage ev)
|
||||||
|
{
|
||||||
|
if (!ev.Entity.TryGetComponent(out ServerStatusEffectsComponent status))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ev.OldParent != null &&
|
||||||
|
ev.OldParent.TryGetComponent(out IMapGridComponent mapGrid))
|
||||||
|
{
|
||||||
|
var oldGrid = mapGrid.GridIndex;
|
||||||
|
|
||||||
|
if (_statuses.TryGetValue(oldGrid, out var oldStatuses))
|
||||||
|
{
|
||||||
|
oldStatuses.Remove(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var newGrid = ev.Entity.Transform.GridID;
|
||||||
|
var newStatuses = _statuses.GetOrNew(newGrid);
|
||||||
|
|
||||||
|
newStatuses.Add(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
using System;
|
|
||||||
using Content.Shared.GameObjects.Components.Mobs;
|
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.Interfaces.Physics;
|
using Robust.Shared.Interfaces.Physics;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Content.Shared.GameObjects.EntitySystemMessages;
|
|
||||||
|
|
||||||
namespace Content.Shared.GameObjects.Components.Movement
|
namespace Content.Shared.GameObjects.Components.Movement
|
||||||
{
|
{
|
||||||
@@ -21,10 +18,8 @@ namespace Content.Shared.GameObjects.Components.Movement
|
|||||||
{
|
{
|
||||||
physicsManager ??= IoCManager.Resolve<IPhysicsManager>();
|
physicsManager ??= IoCManager.Resolve<IPhysicsManager>();
|
||||||
|
|
||||||
var isWeightless = !entity.HasComponent<MovementIgnoreGravityComponent>() &&
|
return !entity.HasComponent<MovementIgnoreGravityComponent>() &&
|
||||||
physicsManager.IsWeightless(entity.Transform.Coordinates);
|
physicsManager.IsWeightless(entity.Transform.Coordinates);
|
||||||
entity.EntityManager.EventBus.RaiseEvent(EventSource.Local, new WeightlessChangeMessage(entity,isWeightless));
|
|
||||||
return isWeightless;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Map;
|
||||||
|
|
||||||
|
namespace Content.Shared.GameObjects.EntitySystemMessages.Gravity
|
||||||
|
{
|
||||||
|
public class GravityChangedMessage : EntitySystemMessage
|
||||||
|
{
|
||||||
|
public GravityChangedMessage(IMapGrid grid)
|
||||||
|
{
|
||||||
|
Grid = grid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IMapGrid Grid { get; }
|
||||||
|
|
||||||
|
public bool HasGravity => Grid.HasGravity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
|
||||||
using Robust.Shared.Serialization;
|
|
||||||
|
|
||||||
namespace Content.Shared.GameObjects.EntitySystemMessages
|
|
||||||
{
|
|
||||||
[Serializable, NetSerializable]
|
|
||||||
public sealed class WeightlessChangeMessage : EntitySystemMessage
|
|
||||||
{
|
|
||||||
public readonly IEntity Entity;
|
|
||||||
public readonly bool Weightless;
|
|
||||||
|
|
||||||
public WeightlessChangeMessage(IEntity ent, bool isNowWeightless)
|
|
||||||
{
|
|
||||||
Entity = ent;
|
|
||||||
Weightless = isNowWeightless;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user