magic bread wand (#17044)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -3,6 +3,7 @@ using Content.Server.Humanoid;
|
||||
using Content.Server.Inventory;
|
||||
using Content.Server.Mind.Commands;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Nutrition;
|
||||
using Content.Server.Polymorph.Components;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
@@ -41,7 +42,7 @@ namespace Content.Server.Polymorph.Systems
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
[Dependency] private readonly TransformSystem _transform = default!;
|
||||
|
||||
private readonly ISawmill _saw = default!;
|
||||
private ISawmill _sawmill = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -50,10 +51,14 @@ namespace Content.Server.Polymorph.Systems
|
||||
SubscribeLocalEvent<PolymorphableComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<PolymorphableComponent, PolymorphActionEvent>(OnPolymorphActionEvent);
|
||||
SubscribeLocalEvent<PolymorphedEntityComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<PolymorphedEntityComponent, BeforeFullyEatenEvent>(OnBeforeFullyEaten);
|
||||
SubscribeLocalEvent<PolymorphedEntityComponent, BeforeFullySlicedEvent>(OnBeforeFullySliced);
|
||||
SubscribeLocalEvent<PolymorphedEntityComponent, RevertPolymorphActionEvent>(OnRevertPolymorphActionEvent);
|
||||
|
||||
InitializeCollide();
|
||||
InitializeMap();
|
||||
|
||||
_sawmill = Logger.GetSawmill("polymorph");
|
||||
}
|
||||
|
||||
private void OnStartup(EntityUid uid, PolymorphableComponent component, ComponentStartup args)
|
||||
@@ -82,7 +87,7 @@ namespace Content.Server.Polymorph.Systems
|
||||
if (!_proto.TryIndex(component.Prototype, out PolymorphPrototype? proto))
|
||||
{
|
||||
// warning instead of error because of the all-comps one entity test.
|
||||
Logger.Warning($"{nameof(PolymorphSystem)} encountered an improperly set up polymorph component while initializing. Entity {ToPrettyString(uid)}. Prototype: {component.Prototype}");
|
||||
_sawmill.Warning($"{nameof(PolymorphSystem)} encountered an improperly set up polymorph component while initializing. Entity {ToPrettyString(uid)}. Prototype: {component.Prototype}");
|
||||
RemCompDeferred(uid, component);
|
||||
return;
|
||||
}
|
||||
@@ -102,6 +107,36 @@ namespace Content.Server.Polymorph.Systems
|
||||
_actions.AddAction(uid, act, null);
|
||||
}
|
||||
|
||||
private void OnBeforeFullyEaten(EntityUid uid, PolymorphedEntityComponent comp, BeforeFullyEatenEvent args)
|
||||
{
|
||||
if (!_proto.TryIndex<PolymorphPrototype>(comp.Prototype, out var proto))
|
||||
{
|
||||
_sawmill.Error("Invalid polymorph prototype {comp.Prototype}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (proto.RevertOnEat)
|
||||
{
|
||||
args.Cancel();
|
||||
Revert(uid, comp);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBeforeFullySliced(EntityUid uid, PolymorphedEntityComponent comp, BeforeFullySlicedEvent args)
|
||||
{
|
||||
if (!_proto.TryIndex<PolymorphPrototype>(comp.Prototype, out var proto))
|
||||
{
|
||||
_sawmill.Error("Invalid polymorph prototype {comp.Prototype}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (proto.RevertOnEat)
|
||||
{
|
||||
args.Cancel();
|
||||
Revert(uid, comp);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Polymorphs the target entity into the specific polymorph prototype
|
||||
/// </summary>
|
||||
@@ -111,7 +146,7 @@ namespace Content.Server.Polymorph.Systems
|
||||
{
|
||||
if (!_proto.TryIndex<PolymorphPrototype>(id, out var proto))
|
||||
{
|
||||
_saw.Error("Invalid polymorph prototype");
|
||||
_sawmill.Error("Invalid polymorph prototype {id}");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -225,7 +260,7 @@ namespace Content.Server.Polymorph.Systems
|
||||
|
||||
if (!_proto.TryIndex(component.Prototype, out PolymorphPrototype? proto))
|
||||
{
|
||||
Logger.Error($"{nameof(PolymorphSystem)} encountered an improperly initialized polymorph component while reverting. Entity {ToPrettyString(uid)}. Prototype: {component.Prototype}");
|
||||
_sawmill.Error($"{nameof(PolymorphSystem)} encountered an improperly initialized polymorph component while reverting. Entity {ToPrettyString(uid)}. Prototype: {component.Prototype}");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -236,9 +271,6 @@ namespace Content.Server.Polymorph.Systems
|
||||
parentXform.Coordinates = uidXform.Coordinates;
|
||||
parentXform.LocalRotation = uidXform.LocalRotation;
|
||||
|
||||
if (_container.TryGetContainingContainer(uid, out var cont))
|
||||
cont.Insert(component.Parent);
|
||||
|
||||
if (proto.TransferDamage &&
|
||||
TryComp<DamageableComponent>(parent, out var damageParent) &&
|
||||
_mobThreshold.GetScaledDamage(uid, parent, out var damage) &&
|
||||
@@ -277,6 +309,9 @@ namespace Content.Server.Polymorph.Systems
|
||||
mind.Mind.TransferTo(parent);
|
||||
}
|
||||
|
||||
// if an item polymorph was picked up, put it back down after reverting
|
||||
Transform(parent).AttachToGridOrMap();
|
||||
|
||||
_popup.PopupEntity(Loc.GetString("polymorph-revert-popup-generic",
|
||||
("parent", Identity.Entity(uid, EntityManager)),
|
||||
("child", Identity.Entity(parent, EntityManager))),
|
||||
@@ -293,7 +328,7 @@ namespace Content.Server.Polymorph.Systems
|
||||
{
|
||||
if (!_proto.TryIndex<PolymorphPrototype>(id, out var polyproto))
|
||||
{
|
||||
_saw.Error("Invalid polymorph prototype");
|
||||
_sawmill.Error("Invalid polymorph prototype");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -335,27 +370,32 @@ namespace Content.Server.Polymorph.Systems
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
foreach (var comp in EntityQuery<PolymorphedEntityComponent>())
|
||||
var query = EntityQueryEnumerator<PolymorphedEntityComponent>();
|
||||
while (query.MoveNext(out var uid, out var comp))
|
||||
{
|
||||
comp.Time += frameTime;
|
||||
var ent = comp.Owner;
|
||||
|
||||
if (!_proto.TryIndex(comp.Prototype, out PolymorphPrototype? proto))
|
||||
{
|
||||
Logger.Error($"{nameof(PolymorphSystem)} encountered an improperly initialized polymorph component while updating. Entity {ToPrettyString(ent)}. Prototype: {comp.Prototype}");
|
||||
RemCompDeferred(ent, comp);
|
||||
_sawmill.Error($"{nameof(PolymorphSystem)} encountered an improperly initialized polymorph component while updating. Entity {ToPrettyString(uid)}. Prototype: {comp.Prototype}");
|
||||
RemCompDeferred(uid, comp);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(proto.Duration != null && comp.Time >= proto.Duration)
|
||||
Revert(ent, comp);
|
||||
if (proto.Duration != null && comp.Time >= proto.Duration)
|
||||
{
|
||||
Revert(uid, comp);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!TryComp<MobStateComponent>(ent, out var mob))
|
||||
if (!TryComp<MobStateComponent>(uid, out var mob))
|
||||
continue;
|
||||
|
||||
if (proto.RevertOnDeath && _mobState.IsDead(ent, mob) ||
|
||||
proto.RevertOnCrit && _mobState.IsIncapacitated(ent, mob))
|
||||
Revert(ent, comp);
|
||||
if (proto.RevertOnDeath && _mobState.IsDead(uid, mob) ||
|
||||
proto.RevertOnCrit && _mobState.IsIncapacitated(uid, mob))
|
||||
{
|
||||
Revert(uid, comp);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateCollide();
|
||||
|
||||
Reference in New Issue
Block a user