Skip to content

Commit

Permalink
Move OnGhostAttempt to GhostSystem (#31445)
Browse files Browse the repository at this point in the history
* Move OnGhostAttempt to GhostSystem

* Remove unused dependencies and sort them
  • Loading branch information
Winkarst-cpu authored Aug 26, 2024
1 parent 84caaec commit 2d85b4e
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 158 deletions.
14 changes: 7 additions & 7 deletions Content.Server/Bed/Cryostorage/CryostorageSystem.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
using System.Globalization;
using System.Linq;
using Content.Server.Chat.Managers;
using Content.Server.Chat.Systems;
using Content.Server.GameTicking;
using Content.Server.Ghost;
using Content.Server.Hands.Systems;
using Content.Server.Inventory;
using Content.Server.Popups;
using Content.Server.Chat.Systems;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Server.StationRecords;
using Content.Server.StationRecords.Systems;
using Content.Shared.StationRecords;
using Content.Shared.UserInterface;
using Content.Shared.Access.Systems;
using Content.Shared.Bed.Cryostorage;
using Content.Shared.Chat;
using Content.Shared.Climbing.Systems;
using Content.Shared.Database;
using Content.Shared.Hands.Components;
using Content.Shared.Mind.Components;
using Content.Shared.StationRecords;
using Content.Shared.UserInterface;
using Robust.Server.Audio;
using Robust.Server.Containers;
using Robust.Server.GameObjects;
Expand All @@ -27,6 +26,7 @@
using Robust.Shared.Enums;
using Robust.Shared.Network;
using Robust.Shared.Player;
using System.Globalization;

namespace Content.Server.Bed.Cryostorage;

Expand All @@ -40,7 +40,7 @@ public sealed class CryostorageSystem : SharedCryostorageSystem
[Dependency] private readonly ChatSystem _chatSystem = default!;
[Dependency] private readonly ClimbSystem _climb = default!;
[Dependency] private readonly ContainerSystem _container = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;
[Dependency] private readonly GhostSystem _ghostSystem = default!;
[Dependency] private readonly HandsSystem _hands = default!;
[Dependency] private readonly ServerInventorySystem _inventory = default!;
[Dependency] private readonly PopupSystem _popup = default!;
Expand Down Expand Up @@ -210,7 +210,7 @@ public void HandleEnterCryostorage(Entity<CryostorageContainedComponent> ent, Ne
if (userId != null && Mind.TryGetMind(userId.Value, out var mind) &&
HasComp<CryostorageContainedComponent>(mind.Value.Comp.CurrentEntity))
{
_gameTicker.OnGhostAttempt(mind.Value, false);
_ghostSystem.OnGhostAttempt(mind.Value, false);
}
}

Expand Down
6 changes: 3 additions & 3 deletions Content.Server/Body/Systems/BodySystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Content.Server.Body.Components;
using Content.Server.GameTicking;
using Content.Server.Ghost;
using Content.Server.Humanoid;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
Expand All @@ -17,7 +17,7 @@ namespace Content.Server.Body.Systems;

public sealed class BodySystem : SharedBodySystem
{
[Dependency] private readonly GameTicker _ticker = default!;
[Dependency] private readonly GhostSystem _ghostSystem = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly HumanoidAppearanceSystem _humanoidSystem = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
Expand All @@ -43,7 +43,7 @@ private void OnRelayMoveInput(Entity<BodyComponent> ent, ref MoveInputEvent args
if (_mobState.IsDead(ent) && _mindSystem.TryGetMind(ent, out var mindId, out var mind))
{
mind.TimeOfDeath ??= _gameTiming.RealTime;
_ticker.OnGhostAttempt(mindId, canReturnGlobal: true, mind: mind);
_ghostSystem.OnGhostAttempt(mindId, canReturnGlobal: true, mind: mind);
}
}

Expand Down
12 changes: 6 additions & 6 deletions Content.Server/Chat/SuicideSystem.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using Content.Server.GameTicking;
using Content.Server.Ghost;
using Content.Shared.Administration.Logs;
using Content.Shared.Chat;
using Content.Shared.Damage;
using Content.Shared.Database;
using Content.Shared.Hands.Components;
using Content.Shared.Interaction.Events;
using Content.Shared.Item;
using Content.Shared.Mind;
using Content.Shared.Mind.Components;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Popups;
using Content.Shared.Tag;
using Robust.Shared.Player;
using Content.Shared.Administration.Logs;
using Content.Shared.Chat;
using Content.Shared.Mind.Components;

namespace Content.Server.Chat;

Expand All @@ -23,7 +23,7 @@ public sealed class SuicideSystem : EntitySystem
[Dependency] private readonly TagSystem _tagSystem = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;
[Dependency] private readonly GhostSystem _ghostSystem = default!;
[Dependency] private readonly SharedSuicideSystem _suicide = default!;

public override void Initialize()
Expand Down Expand Up @@ -82,7 +82,7 @@ private void OnSuicideGhost(Entity<MindContainerComponent> victim, ref SuicideGh
if (_tagSystem.HasTag(victim, "CannotSuicide"))
args.CanReturnToBody = true;

if (_gameTicker.OnGhostAttempt(victim.Comp.Mind.Value, args.CanReturnToBody, mind: mindComponent))
if (_ghostSystem.OnGhostAttempt(victim.Comp.Mind.Value, args.CanReturnToBody, mind: mindComponent))
args.Handled = true;
}

Expand Down
6 changes: 3 additions & 3 deletions Content.Server/Clothing/Systems/CursedMaskSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Content.Server.Administration.Logs;
using Content.Server.GameTicking;
using Content.Server.Ghost;
using Content.Server.Mind;
using Content.Server.NPC;
using Content.Server.NPC.HTN;
Expand All @@ -21,7 +21,7 @@ namespace Content.Server.Clothing.Systems;
public sealed class CursedMaskSystem : SharedCursedMaskSystem
{
[Dependency] private readonly IAdminLogManager _adminLog = default!;
[Dependency] private readonly GameTicker _ticker = default!;
[Dependency] private readonly GhostSystem _ghostSystem = default!;
[Dependency] private readonly HTNSystem _htn = default!;
[Dependency] private readonly MindSystem _mind = default!;
[Dependency] private readonly NPCSystem _npc = default!;
Expand All @@ -39,7 +39,7 @@ protected override void TryTakeover(Entity<CursedMaskComponent> ent, EntityUid w
if (TryComp<ActorComponent>(wearer, out var actor) && actor.PlayerSession.GetMind() is { } mind)
{
var session = actor.PlayerSession;
if (!_ticker.OnGhostAttempt(mind, false))
if (!_ghostSystem.OnGhostAttempt(mind, false))
return;

ent.Comp.StolenMind = mind;
Expand Down
118 changes: 3 additions & 115 deletions Content.Server/GameTicking/GameTicker.GamePreset.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
using Content.Server.GameTicking.Presets;
using Content.Server.Maps;
using Content.Shared.CCVar;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.Database;
using Content.Shared.FixedPoint;
using Content.Shared.Ghost;
using Content.Shared.Mind;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using JetBrains.Annotations;
using Robust.Shared.Player;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;

namespace Content.Server.GameTicking
{
public sealed partial class GameTicker
{
[Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!;

public const float PresetFailedCooldownIncrease = 30f;

/// <summary>
Expand Down Expand Up @@ -198,94 +187,6 @@ public void StartGamePresetRules()
}
}

public bool OnGhostAttempt(EntityUid mindId, bool canReturnGlobal, bool viaCommand = false, MindComponent? mind = null)
{
if (!Resolve(mindId, ref mind))
return false;

var playerEntity = mind.CurrentEntity;

if (playerEntity != null && viaCommand)
_adminLogger.Add(LogType.Mind, $"{EntityManager.ToPrettyString(playerEntity.Value):player} is attempting to ghost via command");

var handleEv = new GhostAttemptHandleEvent(mind, canReturnGlobal);
RaiseLocalEvent(handleEv);

// Something else has handled the ghost attempt for us! We return its result.
if (handleEv.Handled)
return handleEv.Result;

if (mind.PreventGhosting)
{
if (mind.Session != null) // Logging is suppressed to prevent spam from ghost attempts caused by movement attempts
{
_chatManager.DispatchServerMessage(mind.Session, Loc.GetString("comp-mind-ghosting-prevented"),
true);
}

return false;
}

if (TryComp<GhostComponent>(playerEntity, out var comp) && !comp.CanGhostInteract)
return false;

if (mind.VisitingEntity != default)
{
_mind.UnVisit(mindId, mind: mind);
}

var position = Exists(playerEntity)
? Transform(playerEntity.Value).Coordinates
: GetObserverSpawnPoint();

if (position == default)
return false;

// Ok, so, this is the master place for the logic for if ghosting is "too cheaty" to allow returning.
// There's no reason at this time to move it to any other place, especially given that the 'side effects required' situations would also have to be moved.
// + If CharacterDeadPhysically applies, we're physically dead. Therefore, ghosting OK, and we can return (this is critical for gibbing)
// Note that we could theoretically be ICly dead and still physically alive and vice versa.
// (For example, a zombie could be dead ICly, but may retain memories and is definitely physically active)
// + If we're in a mob that is critical, and we're supposed to be able to return if possible,
// we're succumbing - the mob is killed. Therefore, character is dead. Ghosting OK.
// (If the mob survives, that's a bug. Ghosting is kept regardless.)
var canReturn = canReturnGlobal && _mind.IsCharacterDeadPhysically(mind);

if (_configurationManager.GetCVar(CCVars.GhostKillCrit) &&
canReturnGlobal &&
TryComp(playerEntity, out MobStateComponent? mobState))
{
if (_mobState.IsCritical(playerEntity.Value, mobState))
{
canReturn = true;

//todo: what if they dont breathe lol
//cry deeply

FixedPoint2 dealtDamage = 200;
if (TryComp<DamageableComponent>(playerEntity, out var damageable)
&& TryComp<MobThresholdsComponent>(playerEntity, out var thresholds))
{
var playerDeadThreshold = _mobThresholdSystem.GetThresholdForState(playerEntity.Value, MobState.Dead, thresholds);
dealtDamage = playerDeadThreshold - damageable.TotalDamage;
}

DamageSpecifier damage = new(_prototypeManager.Index<DamageTypePrototype>("Asphyxiation"), dealtDamage);

_damageable.TryChangeDamage(playerEntity, damage, true);
}
}

var ghost = _ghost.SpawnGhost((mindId, mind), position, canReturn);
if (ghost == null)
return false;

if (playerEntity != null)
_adminLogger.Add(LogType.Mind, $"{EntityManager.ToPrettyString(playerEntity.Value):player} ghosted{(!canReturn ? " (non-returnable)" : "")}");

return true;
}

private void IncrementRoundNumber()
{
var playerIds = _playerGameStatuses.Keys.Select(player => player.UserId).ToArray();
Expand All @@ -304,17 +205,4 @@ private void IncrementRoundNumber()
RoundId = task.GetAwaiter().GetResult();
}
}

public sealed class GhostAttemptHandleEvent : HandledEntityEventArgs
{
public MindComponent Mind { get; }
public bool CanReturnGlobal { get; }
public bool Result { get; set; }

public GhostAttemptHandleEvent(MindComponent mind, bool canReturnGlobal)
{
Mind = mind;
CanReturnGlobal = canReturnGlobal;
}
}
}
3 changes: 1 addition & 2 deletions Content.Server/Ghost/GhostCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Content.Server.GameTicking;
using Content.Server.Popups;
using Content.Shared.Administration;
using Content.Shared.Mind;
Expand Down Expand Up @@ -41,7 +40,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
mind = _entities.GetComponent<MindComponent>(mindId);
}

if (!_entities.System<GameTicker>().OnGhostAttempt(mindId, true, true, mind))
if (!_entities.System<GhostSystem>().OnGhostAttempt(mindId, true, true, mind))
{
shell.WriteLine(Loc.GetString("ghost-command-denied"));
}
Expand Down
Loading

0 comments on commit 2d85b4e

Please sign in to comment.