Cherrypicks 3 (#382)
* Mobs burn to ashes on excessive heat damage (#26971) * mobs burn to ashes on excessive heat damage * remove comment, remove random lines I didn't mean to add * combine code into behavior * clean unused * fix namespace * drop next to * fix spawn entities behavior spawning entities outside container * fix burning to ash not working on all mobs (#27158) * add ghostnado button to warp menu (#27556) * add ghostnado button to warp menu * translator ops --------- Co-authored-by: deltanedas <@deltanedas:kde.org> * Make arguments and parameters wrap to one variable per line (#27766) * Fix ghosts getting spawned in nullspace (#27617) * Add tests for ghost spawn position * Make ghosts spawn immediately * Format mind system * Move ghost spawning to GhostSystem * Spawn ghost on grid or map This fixes the ghosts being attached the parent entity instead of the grid. * Move logging out of the ghost system * Make round start observer spawn using GhostSystem * Move GameTicker ghost spawning to GhostSystem Moved the more robust character name selection code over. Moved the TimeOfDeath code over. Added canReturn logic. * Add overrides and default for ghost spawn coordinates * Add warning log to ghost spawn fail * Clean up test * Dont spawn ghost on map delete * Minor changes to the role test * Fix role test failing to spawn ghost It was failing the map check due to using Nullspace * Fix ghost tests when running in parallel Not sure what happened, but it seems to be because they were running simultaneously and overwriting values. * Clean up ghost tests * Test that map deletion does not spawn ghosts * Spawn ghost on the next available map * Disallow spawning on deleted maps * Fix map deletion ghost test * Cleanup --------- Co-authored-by: Whisper <121047731+QuietlyWhisper@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: ShadowCommander <shadowjjt@gmail.com>
This commit is contained in:
@@ -29,6 +29,7 @@ using Robust.Server.Player;
|
||||
using Content.Shared._White;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Player;
|
||||
@@ -55,11 +56,19 @@ namespace Content.Server.Ghost
|
||||
[Dependency] private readonly VisibilitySystem _visibilitySystem = default!;
|
||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
private EntityQuery<GhostComponent> _ghostQuery;
|
||||
private EntityQuery<PhysicsComponent> _physicsQuery;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_ghostQuery = GetEntityQuery<GhostComponent>();
|
||||
_physicsQuery = GetEntityQuery<PhysicsComponent>();
|
||||
|
||||
SubscribeLocalEvent<GhostComponent, ComponentStartup>(OnGhostStartup);
|
||||
SubscribeLocalEvent<GhostComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<GhostComponent, ComponentShutdown>(OnGhostShutdown);
|
||||
@@ -75,6 +84,7 @@ namespace Content.Server.Ghost
|
||||
SubscribeNetworkEvent<GhostWarpsRequestEvent>(OnGhostWarpsRequest);
|
||||
SubscribeNetworkEvent<GhostReturnToBodyRequest>(OnGhostReturnToBodyRequest);
|
||||
SubscribeNetworkEvent<GhostWarpToTargetRequestEvent>(OnGhostWarpToTargetRequest);
|
||||
SubscribeNetworkEvent<GhostnadoRequestEvent>(OnGhostnadoRequest);
|
||||
|
||||
SubscribeNetworkEvent<GhostReturnToRoundRequest>(OnGhostReturnToRoundRequest);
|
||||
|
||||
@@ -319,7 +329,7 @@ namespace Content.Server.Ghost
|
||||
private void OnGhostReturnToBodyRequest(GhostReturnToBodyRequest msg, EntitySessionEventArgs args)
|
||||
{
|
||||
if (args.SenderSession.AttachedEntity is not {Valid: true} attached
|
||||
|| !TryComp(attached, out GhostComponent? ghost)
|
||||
|| !_ghostQuery.TryComp(attached, out var ghost)
|
||||
|| !ghost.CanReturnToBody
|
||||
|| !TryComp(attached, out ActorComponent? actor))
|
||||
{
|
||||
@@ -335,7 +345,7 @@ namespace Content.Server.Ghost
|
||||
private void OnGhostWarpsRequest(GhostWarpsRequestEvent msg, EntitySessionEventArgs args)
|
||||
{
|
||||
if (args.SenderSession.AttachedEntity is not {Valid: true} entity
|
||||
|| !HasComp<GhostComponent>(entity))
|
||||
|| !_ghostQuery.HasComp(entity))
|
||||
{
|
||||
Log.Warning($"User {args.SenderSession.Name} sent a {nameof(GhostWarpsRequestEvent)} without being a ghost.");
|
||||
return;
|
||||
@@ -348,7 +358,7 @@ namespace Content.Server.Ghost
|
||||
private void OnGhostWarpToTargetRequest(GhostWarpToTargetRequestEvent msg, EntitySessionEventArgs args)
|
||||
{
|
||||
if (args.SenderSession.AttachedEntity is not {Valid: true} attached
|
||||
|| !TryComp(attached, out GhostComponent? _))
|
||||
|| !_ghostQuery.HasComp(attached))
|
||||
{
|
||||
Log.Warning($"User {args.SenderSession.Name} tried to warp to {msg.Target} without being a ghost.");
|
||||
return;
|
||||
@@ -362,17 +372,37 @@ namespace Content.Server.Ghost
|
||||
return;
|
||||
}
|
||||
|
||||
if ((TryComp(target, out WarpPointComponent? warp) && warp.Follow) || HasComp<MobStateComponent>(target))
|
||||
WarpTo(attached, target);
|
||||
}
|
||||
|
||||
private void OnGhostnadoRequest(GhostnadoRequestEvent msg, EntitySessionEventArgs args)
|
||||
{
|
||||
if (args.SenderSession.AttachedEntity is not {} uid
|
||||
|| !_ghostQuery.HasComp(uid))
|
||||
{
|
||||
_followerSystem.StartFollowingEntity(attached, target);
|
||||
Log.Warning($"User {args.SenderSession.Name} tried to ghostnado without being a ghost.");
|
||||
return;
|
||||
}
|
||||
|
||||
var xform = Transform(attached);
|
||||
_transformSystem.SetCoordinates(attached, xform, Transform(target).Coordinates);
|
||||
_transformSystem.AttachToGridOrMap(attached, xform);
|
||||
if (TryComp(attached, out PhysicsComponent? physics))
|
||||
_physics.SetLinearVelocity(attached, Vector2.Zero, body: physics);
|
||||
if (_followerSystem.GetMostFollowed() is not {} target)
|
||||
return;
|
||||
|
||||
WarpTo(uid, target);
|
||||
}
|
||||
|
||||
private void WarpTo(EntityUid uid, EntityUid target)
|
||||
{
|
||||
if ((TryComp(target, out WarpPointComponent? warp) && warp.Follow) || HasComp<MobStateComponent>(target))
|
||||
{
|
||||
_followerSystem.StartFollowingEntity(uid, target);
|
||||
return;
|
||||
}
|
||||
|
||||
var xform = Transform(uid);
|
||||
_transformSystem.SetCoordinates(uid, xform, Transform(target).Coordinates);
|
||||
_transformSystem.AttachToGridOrMap(uid, xform);
|
||||
if (_physicsQuery.TryComp(uid, out var physics))
|
||||
_physics.SetLinearVelocity(uid, Vector2.Zero, body: physics);
|
||||
}
|
||||
|
||||
private IEnumerable<GhostWarp> GetLocationWarps()
|
||||
@@ -444,5 +474,59 @@ namespace Content.Server.Ghost
|
||||
|
||||
return ghostBoo.Handled;
|
||||
}
|
||||
|
||||
public EntityUid? SpawnGhost(Entity<MindComponent?> mind, EntityUid targetEntity,
|
||||
bool canReturn = false)
|
||||
{
|
||||
_transformSystem.TryGetMapOrGridCoordinates(targetEntity, out var spawnPosition);
|
||||
return SpawnGhost(mind, spawnPosition, canReturn);
|
||||
}
|
||||
|
||||
public EntityUid? SpawnGhost(Entity<MindComponent?> mind, EntityCoordinates? spawnPosition = null,
|
||||
bool canReturn = false)
|
||||
{
|
||||
if (!Resolve(mind, ref mind.Comp))
|
||||
return null;
|
||||
|
||||
// Test if the map is being deleted
|
||||
var mapUid = spawnPosition?.GetMapUid(EntityManager);
|
||||
if (mapUid == null || TerminatingOrDeleted(mapUid.Value))
|
||||
spawnPosition = null;
|
||||
|
||||
spawnPosition ??= _ticker.GetObserverSpawnPoint();
|
||||
|
||||
if (!spawnPosition.Value.IsValid(EntityManager))
|
||||
{
|
||||
Log.Warning($"No spawn valid ghost spawn position found for {mind.Comp.CharacterName}"
|
||||
+ " \"{ToPrettyString(mind)}\"");
|
||||
_minds.TransferTo(mind.Owner, null, createGhost: false, mind: mind.Comp);
|
||||
return null;
|
||||
}
|
||||
|
||||
var ghost = SpawnAtPosition(GameTicker.ObserverPrototypeName, spawnPosition.Value);
|
||||
var ghostComponent = Comp<GhostComponent>(ghost);
|
||||
|
||||
// Try setting the ghost entity name to either the character name or the player name.
|
||||
// If all else fails, it'll default to the default entity prototype name, "observer".
|
||||
// However, that should rarely happen.
|
||||
if (!string.IsNullOrWhiteSpace(mind.Comp.CharacterName))
|
||||
_metaData.SetEntityName(ghost, mind.Comp.CharacterName);
|
||||
else if (!string.IsNullOrWhiteSpace(mind.Comp.Session?.Name))
|
||||
_metaData.SetEntityName(ghost, mind.Comp.Session.Name);
|
||||
|
||||
if (mind.Comp.TimeOfDeath.HasValue)
|
||||
{
|
||||
SetTimeOfDeath(ghost, mind.Comp.TimeOfDeath!.Value, ghostComponent);
|
||||
}
|
||||
|
||||
SetCanReturnToBody(ghostComponent, canReturn);
|
||||
|
||||
if (canReturn)
|
||||
_minds.Visit(mind.Owner, ghost, mind.Comp);
|
||||
else
|
||||
_minds.TransferTo(mind.Owner, ghost, mind: mind.Comp);
|
||||
Log.Debug($"Spawned ghost \"{ToPrettyString(ghost)}\" for {mind.Comp.CharacterName}.");
|
||||
return ghost;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user