Move OnGhostAttempt to GhostSystem (#31445)
* Move OnGhostAttempt to GhostSystem * Remove unused dependencies and sort them
This commit is contained in:
@@ -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>
|
||||
@@ -198,94 +187,6 @@ namespace Content.Server.GameTicking
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
@@ -304,17 +205,4 @@ namespace Content.Server.GameTicking
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user