Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server.Administration.Managers;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Body.Systems;
using Content.Server.Electrocution;
Expand Down Expand Up @@ -96,6 +97,7 @@ public sealed partial class AdminVerbSystem
[Dependency] private readonly GibbingSystem _gibbing = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;


private readonly EntProtoId _actionViewLawsProtoId = "ActionViewLaws";
private readonly ProtoId<SiliconLawsetPrototype> _crewsimovLawset = "Crewsimov";

Expand Down
5 changes: 3 additions & 2 deletions Content.Server/ImmovableRod/ImmovableRodSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Server.Destructible;
using Content.Server.Polymorph.Components;
using Content.Server.Popups;
using Content.Shared._Persistence14.PersistentIdentifier;
using Content.Shared.Administration.Logs;
using Content.Shared.Body;
using Content.Shared.Damage.Systems;
Expand Down Expand Up @@ -31,6 +32,7 @@ public sealed class ImmovableRodSystem : EntitySystem
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedMapSystem _map = default!;
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private PersistentIdentifierSystem _pid = default!;

public override void Update(float frameTime)
{
Expand Down Expand Up @@ -111,8 +113,7 @@ private void OnCollide(EntityUid uid, ImmovableRodComponent component, ref Start
// dont delete/hurt self if polymoprhed into a rod
if (TryComp<PolymorphedEntityComponent>(uid, out var polymorphed))
{
if (polymorphed.Parent == ent)
return;
return;
}

// gib or damage em
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Content.Server.Polymorph.Systems;
using Content.Shared._Persistence14.PersistentIdentifier;
using Content.Shared._Persistence14.PersistentIdentifier.Reference;
using Content.Shared.Polymorph;

namespace Content.Server.Polymorph.Components;

[RegisterComponent]
[Access(typeof(PolymorphSystem))]
[Access(typeof(PolymorphSystem), typeof(PersistentIdentifierSystem))]
public sealed partial class PolymorphedEntityComponent : Component
{
/// <summary>
Expand All @@ -17,8 +19,8 @@ public sealed partial class PolymorphedEntityComponent : Component
/// <summary>
/// The original entity that the player will revert back into
/// </summary>
[DataField(required: true)]
public EntityUid? Parent;
[DataField]
public string ParentPersistentId;

/// <summary>
/// Whether this polymorph has been reverted.
Expand Down
111 changes: 78 additions & 33 deletions Content.Server/Polymorph/Systems/PolymorphSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
using Content.Server.Actions;
using Content.Server.Administration.Managers;
using Content.Server.Administration.Systems;
using Content.Server.Database;
using Content.Server.Inventory;
using Content.Server.Polymorph.Components;
using Content.Server._Persistence14.EntityVoid;
using Content.Shared._Persistence14.PersistentIdentifier;
using Content.Shared.Administration;
using Content.Shared.Body;
using Content.Shared.Buckle;
using Content.Shared.Coordinates;
Expand All @@ -15,12 +21,17 @@
using Content.Shared.Nutrition;
using Content.Shared.Polymorph;
using Content.Shared.Popups;
using Content.Shared.Verbs;
using Robust.Server.Audio;
using Robust.Server.Containers;
using Robust.Server.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using Content.Shared._Persistence14.EntityVoid;

namespace Content.Server.Polymorph.Systems;

Expand All @@ -43,6 +54,11 @@ public sealed partial class PolymorphSystem : EntitySystem
[Dependency] private readonly SharedVisualBodySystem _visualBody = default!;
[Dependency] private readonly SharedMindSystem _mindSystem = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private PersistentIdentifierSystem _pid = default!;
[Dependency] private AdminVerbSystem _adminVerb = default!;
[Dependency] private readonly IAdminManager _adminManager = default!;
[Dependency] private readonly ILogManager _log = default!;
[Dependency] private EntityVoidSystem _void = default!;

private const string RevertPolymorphId = "ActionRevertPolymorph";

Expand All @@ -58,6 +74,8 @@ public override void Initialize()
SubscribeLocalEvent<PolymorphedEntityComponent, DestructionEventArgs>(OnDestruction);
SubscribeLocalEvent<PolymorphedEntityComponent, EntityTerminatingEvent>(OnPolymorphedTerminating);

SubscribeLocalEvent<PolymorphedEntityComponent, GetVerbsEvent<Verb>>(AddPolymorphVerbs);

InitializeMap();
}

Expand Down Expand Up @@ -104,11 +122,13 @@ private void OnMapInit(Entity<PolymorphedEntityComponent> ent, ref MapInitEvent
if (component.Configuration.Forced)
return;

if (_actions.AddAction(uid, ref component.Action, out var action, RevertPolymorphId))
/*
if (_actions.AddAction(uid, ref component.Action, out var action, RevertPolymorphId) &&
_pid.TryResolveId(component.Parent, out var parentEnt))
{
_actions.SetEntityIcon((component.Action.Value, action), component.Parent);
_actions.SetEntityIcon((component.Action.Value, action), parentEnt);
_actions.SetUseDelay(component.Action.Value, TimeSpan.FromSeconds(component.Configuration.Delay));
}
}*/
}

private void OnPolymorphActionEvent(Entity<PolymorphableComponent> ent, ref PolymorphActionEvent args)
Expand Down Expand Up @@ -155,10 +175,6 @@ private void OnPolymorphedTerminating(Entity<PolymorphedEntityComponent> ent, re

if (ent.Comp.Configuration.RevertOnDelete)
Revert(ent.AsNullable());

// Remove our original entity too
// Note that Revert will set Parent to null, so reverted entities will not be deleted
QueueDel(ent.Comp.Parent);
}

/// <summary>
Expand All @@ -180,6 +196,9 @@ private void OnPolymorphedTerminating(Entity<PolymorphedEntityComponent> ent, re
/// <returns>The new entity, or null if the polymorph failed.</returns>
public EntityUid? PolymorphEntity(EntityUid uid, PolymorphConfiguration configuration)
{
if (HasComp<VoidedComponent>(uid))
return null;

// If they're morphed, check their current config to see if they can be
// morphed again
if (!configuration.IgnoreAllowRepeatedMorphs
Expand All @@ -194,6 +213,8 @@ private void OnPolymorphedTerminating(Entity<PolymorphedEntityComponent> ent, re
_gameTiming.CurTime < polymorphableComponent.LastPolymorphEnd + configuration.Cooldown)
return null;

var pid = _pid.EnsureId(uid, out var pidEntity);

// mostly just for vehicles
_buckle.TryUnbuckle(uid, uid, true);

Expand All @@ -213,8 +234,8 @@ private void OnPolymorphedTerminating(Entity<PolymorphedEntityComponent> ent, re
_mindSystem.MakeSentient(child);

var polymorphedComp = Factory.GetComponent<PolymorphedEntityComponent>();
polymorphedComp.Parent = uid;
polymorphedComp.Configuration = configuration;
polymorphedComp.ParentPersistentId = pid;
AddComp(child, polymorphedComp);

var childXform = Transform(child);
Expand Down Expand Up @@ -268,10 +289,13 @@ private void OnPolymorphedTerminating(Entity<PolymorphedEntityComponent> ent, re
if (_mindSystem.TryGetMind(uid, out var mindId, out var mind))
_mindSystem.TransferTo(mindId, child, mind: mind);

//Ensures a map to banish the entity to
EnsurePausedMap();
if (PausedMap != null)
_transform.SetParent(uid, targetTransformComp, PausedMap.Value);
if (!_void.TryVoidEntity(uid))
{
if (_mindSystem.TryGetMind(child, out var childMindId, out var childMind))
_mindSystem.TransferTo(child, childMindId, mind: childMind);
QueueDel(child);
return null;
}

// Raise an event to inform anything that wants to know about the entity swap
var ev = new PolymorphedEvent(uid, child, false);
Expand All @@ -298,42 +322,40 @@ private void OnPolymorphedTerminating(Entity<PolymorphedEntityComponent> ent, re
if (Deleted(uid))
return null;

if (component.Parent is not { } parent)
return null;

if (Deleted(parent))
if (ent.Comp?.ParentPersistentId is not { } pid)
return null;

var uidXform = Transform(uid);
var parentXform = Transform(parent);

// Don't swap back onto a terminating grid
if (TerminatingOrDeleted(uidXform.ParentUid))
return null;

var coords = _transform.ToMapCoordinates(uidXform.Coordinates);

if (!_void.TryReconstructEntity(pid, coords, out var parentEnt))
return null;

if (component.Configuration.ExitPolymorphSound != null)
_audio.PlayPvs(component.Configuration.ExitPolymorphSound, uidXform.Coordinates);

_transform.SetParent(parent, parentXform, uidXform.ParentUid);
_transform.SetCoordinates(parent, parentXform, uidXform.Coordinates, uidXform.LocalRotation);

component.Reverted = true;

if (component.Configuration.TransferDamage &&
TryComp<DamageableComponent>(parent, out var damageParent) &&
_mobThreshold.GetScaledDamage(uid, parent, out var damage) &&
TryComp<DamageableComponent>(parentEnt, out var damageParent) &&
_mobThreshold.GetScaledDamage(uid, parentEnt, out var damage) &&
damage != null)
{
_damageable.SetDamage((parent, damageParent), damage);
_damageable.SetDamage((parentEnt, damageParent), damage);
}

if (component.Configuration.Inventory == PolymorphInventoryChange.Transfer)
{
_inventory.TransferEntityInventories(uid, parent);
_inventory.TransferEntityInventories(uid, parentEnt);
foreach (var held in _hands.EnumerateHeld(uid))
{
_hands.TryDrop(uid, held);
_hands.TryPickupAnyHand(parent, held, checkActionBlocker: false);
_hands.TryPickupAnyHand(parentEnt, held, checkActionBlocker: false);
}
}
else if (component.Configuration.Inventory == PolymorphInventoryChange.Drop)
Expand All @@ -353,30 +375,32 @@ private void OnPolymorphedTerminating(Entity<PolymorphedEntityComponent> ent, re
}

if (_mindSystem.TryGetMind(uid, out var mindId, out var mind))
_mindSystem.TransferTo(mindId, parent, mind: mind);
_mindSystem.TransferTo(mindId, parentEnt, mind: mind);

if (TryComp<PolymorphableComponent>(parent, out var polymorphableComponent))
if (TryComp<PolymorphableComponent>(parentEnt, out var polymorphableComponent))
polymorphableComponent.LastPolymorphEnd = _gameTiming.CurTime;

var parentXform = Transform(parentEnt);

// if an item polymorph was picked up, put it back down after reverting
_transform.AttachToGridOrMap(parent, parentXform);
_transform.AttachToGridOrMap(parentEnt, parentXform);

// Raise an event to inform anything that wants to know about the entity swap
var ev = new PolymorphedEvent(uid, parent, true);
var ev = new PolymorphedEvent(uid, parentEnt, true);
RaiseLocalEvent(uid, ref ev);

// visual effect spawn
if (component.Configuration.EffectProto != null)
SpawnAttachedTo(component.Configuration.EffectProto, parent.ToCoordinates());
SpawnAttachedTo(component.Configuration.EffectProto, parentEnt.ToCoordinates());

if (component.Configuration.ExitPolymorphPopup != null)
_popup.PopupEntity(Loc.GetString(component.Configuration.ExitPolymorphPopup,
("parent", Identity.Entity(uid, EntityManager)),
("child", Identity.Entity(parent, EntityManager))),
parent);
("child", Identity.Entity(parentEnt, EntityManager))),
parentEnt);
QueueDel(uid);

return parent;
return parentEnt;
}

/// <summary>
Expand Down Expand Up @@ -420,4 +444,25 @@ public void RemovePolymorphAction(ProtoId<PolymorphPrototype> id, Entity<Polymor
if (actions.TryGetValue(id, out var action))
_actions.RemoveAction(target.Owner, action);
}

public void AddPolymorphVerbs(EntityUid uid, PolymorphedEntityComponent component, ref GetVerbsEvent<Verb> args)
{
if (!TryComp(args.User, out ActorComponent? actor))
return;

var player = actor.PlayerSession;

if (!_adminManager.HasAdminFlag(player, AdminFlags.Admin))
return;

if (HasComp<MapComponent>(args.Target) || HasComp<MapGridComponent>(args.Target))
return;

args.Verbs.Add(new Verb
{
Text = "revert-polymorph-verb",
Category = VerbCategory.Admin,
Act = () => Revert((uid, component)),
});
}
}
Loading
Loading