Zombie Rework & Polymorph Expansion (#8413)
Co-authored-by: Kara <lunarautomaton6@gmail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -4,15 +4,16 @@ using Content.Server.Inventory;
|
||||
using Content.Server.Mind.Commands;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Polymorph.Components;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Content.Shared.CharacterAppearance.Components;
|
||||
using Content.Shared.CharacterAppearance.Systems;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Polymorph;
|
||||
using Robust.Server.Containers;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -27,8 +28,9 @@ namespace Content.Server.Polymorph.Systems
|
||||
[Dependency] private readonly ServerInventorySystem _inventory = default!;
|
||||
[Dependency] private readonly SharedHandsSystem _sharedHands = default!;
|
||||
[Dependency] private readonly DamageableSystem _damageable = default!;
|
||||
[Dependency] private readonly PopupSystem _popup = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly SharedHumanoidAppearanceSystem _sharedHuApp = default!;
|
||||
[Dependency] private readonly ContainerSystem _container = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -61,15 +63,15 @@ namespace Content.Server.Polymorph.Systems
|
||||
/// </summary>
|
||||
/// <param name="target">The entity that will be transformed</param>
|
||||
/// <param name="id">The id of the polymorph prototype</param>
|
||||
public void PolymorphEntity(EntityUid target, String id)
|
||||
public EntityUid? PolymorphEntity(EntityUid target, String id)
|
||||
{
|
||||
if (!_proto.TryIndex<PolymorphPrototype>(id, out var proto))
|
||||
{
|
||||
_saw.Error("Invalid polymorph prototype");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
PolymorphEntity(target, proto);
|
||||
return PolymorphEntity(target, proto);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -77,8 +79,12 @@ namespace Content.Server.Polymorph.Systems
|
||||
/// </summary>
|
||||
/// <param name="target">The entity that will be transformed</param>
|
||||
/// <param name="proto">The polymorph prototype</param>
|
||||
public void PolymorphEntity(EntityUid target, PolymorphPrototype proto)
|
||||
public EntityUid? PolymorphEntity(EntityUid target, PolymorphPrototype proto)
|
||||
{
|
||||
/// This is the big papa function. This handles the transformation, moving the old entity
|
||||
/// logic and conditions specified in the prototype, and everything else that may be needed.
|
||||
/// I am clinically insane - emo
|
||||
|
||||
// mostly just for vehicles
|
||||
if (TryComp<BuckleComponent>(target, out var buckle))
|
||||
buckle.TryUnbuckle(target, true);
|
||||
@@ -93,42 +99,72 @@ namespace Content.Server.Polymorph.Systems
|
||||
comp.Prototype = proto;
|
||||
RaiseLocalEvent(child, new PolymorphComponentSetupEvent());
|
||||
|
||||
var targetXform = Transform(target);
|
||||
var childXform = Transform(child);
|
||||
childXform.LocalRotation = targetXform.LocalRotation;
|
||||
|
||||
if (_container.TryGetContainingContainer(target, out var cont))
|
||||
cont.Insert(child);
|
||||
|
||||
//Transfers all damage from the original to the new one
|
||||
if (TryComp<DamageableComponent>(child, out var damageParent) &&
|
||||
if (proto.TransferDamage &&
|
||||
TryComp<DamageableComponent>(child, out var damageParent) &&
|
||||
_damageable.GetScaledDamage(target, child, out var damage) &&
|
||||
damage != null)
|
||||
{
|
||||
_damageable.SetDamage(damageParent, damage);
|
||||
}
|
||||
|
||||
if (proto.DropInventory)
|
||||
if (proto.Inventory == PolymorphInventoryChange.Transfer)
|
||||
{
|
||||
//drops everything in the user's inventory
|
||||
if (_inventory.TryGetContainerSlotEnumerator(target, out var enumerator))
|
||||
{
|
||||
while (enumerator.MoveNext(out var containerSlot))
|
||||
{
|
||||
containerSlot.EmptyContainer();
|
||||
}
|
||||
}
|
||||
//drops everything in the user's hands
|
||||
_inventory.TransferEntityInventories(target, child);
|
||||
foreach (var hand in _sharedHands.EnumerateHeld(target))
|
||||
{
|
||||
hand.TryRemoveFromContainer();
|
||||
_sharedHands.TryPickupAnyHand(child, hand);
|
||||
}
|
||||
}
|
||||
else if (proto.Inventory == PolymorphInventoryChange.Drop)
|
||||
{
|
||||
if(_inventory.TryGetContainerSlotEnumerator(target, out var enumerator))
|
||||
while (enumerator.MoveNext(out var slot))
|
||||
slot.EmptyContainer();
|
||||
|
||||
foreach (var hand in _sharedHands.EnumerateHeld(target))
|
||||
hand.TryRemoveFromContainer();
|
||||
}
|
||||
|
||||
if (proto.TransferName &&
|
||||
TryComp<MetaDataComponent>(target, out var targetMeta) &&
|
||||
TryComp<MetaDataComponent>(child, out var childMeta))
|
||||
{
|
||||
childMeta.EntityName = targetMeta.EntityName;
|
||||
}
|
||||
|
||||
if (proto.TransferHumanoidAppearance &&
|
||||
TryComp<HumanoidAppearanceComponent>(target, out var targetHuApp) &&
|
||||
TryComp<HumanoidAppearanceComponent>(child, out var childHuApp))
|
||||
{
|
||||
_sharedHuApp.UpdateAppearance(child, targetHuApp.Appearance);
|
||||
_sharedHuApp.ForceAppearanceUpdate(child);
|
||||
}
|
||||
|
||||
if (TryComp<MindComponent>(target, out var mind) && mind.Mind != null)
|
||||
mind.Mind.TransferTo(child);
|
||||
mind.Mind.TransferTo(child);
|
||||
|
||||
//Ensures a map to banish the entity to
|
||||
EnsurePausesdMap();
|
||||
if(PausedMap != null)
|
||||
if (PausedMap != null)
|
||||
targetTransformComp.AttachParent(Transform(PausedMap.Value));
|
||||
|
||||
_popup.PopupEntity(Loc.GetString("polymorph-popup-generic", ("parent", target), ("child", child)), child, Filter.Pvs(child));
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a sidebar action for an entity to be able to polymorph at will
|
||||
/// </summary>
|
||||
/// <param name="id">The string of the id of the polymorph action</param>
|
||||
/// <param name="target">The entity that will be gaining the action</param>
|
||||
public void CreatePolymorphAction(string id, EntityUid target)
|
||||
{
|
||||
if (!_proto.TryIndex<PolymorphPrototype>(id, out var polyproto))
|
||||
@@ -136,7 +172,7 @@ namespace Content.Server.Polymorph.Systems
|
||||
_saw.Error("Invalid polymorph prototype");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!TryComp<PolymorphableComponent>(target, out var polycomp))
|
||||
return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user