Fix robusted dionas not being recoverable (#21636)
* Fix robusted dionas not being recoverable * Implement a polymorph cooldown field, used for TreeMorph Allows the polymorphed Diona some time to work off robust harvest without immediately polymorphing again. * Minor adjustment to polymorph cooldown timing * Apply suggestions from code review Co-authored-by: Kara <lunarautomaton6@gmail.com> * fix: trigger polymorph revert on destruction As suggested by mirrorcult, DamageThresholdReached is not the ideal candidate for reverting a polymorph on destruction, as there exists a DestructionEventArgs to listen for instead. --------- Co-authored-by: Kara <lunarautomaton6@gmail.com>
This commit is contained in:
@@ -12,6 +12,12 @@ namespace Content.Server.Polymorph.Components
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Dictionary<string, EntityUid>? PolymorphActions = null;
|
public Dictionary<string, EntityUid>? PolymorphActions = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Timestamp for when the most recent polymorph ended.
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
|
public TimeSpan? LastPolymorphEnd = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The polymorphs that the entity starts out being able to do.
|
/// The polymorphs that the entity starts out being able to do.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using Content.Server.Polymorph.Components;
|
|||||||
using Content.Shared.Actions;
|
using Content.Shared.Actions;
|
||||||
using Content.Shared.Buckle;
|
using Content.Shared.Buckle;
|
||||||
using Content.Shared.Damage;
|
using Content.Shared.Damage;
|
||||||
|
using Content.Shared.Destructible;
|
||||||
using Content.Shared.Hands.EntitySystems;
|
using Content.Shared.Hands.EntitySystems;
|
||||||
using Content.Shared.IdentityManagement;
|
using Content.Shared.IdentityManagement;
|
||||||
using Content.Shared.Mind;
|
using Content.Shared.Mind;
|
||||||
@@ -20,6 +21,7 @@ using Robust.Server.Containers;
|
|||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
|
using Robust.Shared.Timing;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Server.Polymorph.Systems
|
namespace Content.Server.Polymorph.Systems
|
||||||
@@ -44,6 +46,7 @@ namespace Content.Server.Polymorph.Systems
|
|||||||
[Dependency] private readonly TransformSystem _transform = default!;
|
[Dependency] private readonly TransformSystem _transform = default!;
|
||||||
[Dependency] private readonly SharedMindSystem _mindSystem = default!;
|
[Dependency] private readonly SharedMindSystem _mindSystem = default!;
|
||||||
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
||||||
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||||
|
|
||||||
private ISawmill _sawmill = default!;
|
private ISawmill _sawmill = default!;
|
||||||
|
|
||||||
@@ -59,6 +62,7 @@ namespace Content.Server.Polymorph.Systems
|
|||||||
SubscribeLocalEvent<PolymorphedEntityComponent, BeforeFullyEatenEvent>(OnBeforeFullyEaten);
|
SubscribeLocalEvent<PolymorphedEntityComponent, BeforeFullyEatenEvent>(OnBeforeFullyEaten);
|
||||||
SubscribeLocalEvent<PolymorphedEntityComponent, BeforeFullySlicedEvent>(OnBeforeFullySliced);
|
SubscribeLocalEvent<PolymorphedEntityComponent, BeforeFullySlicedEvent>(OnBeforeFullySliced);
|
||||||
SubscribeLocalEvent<PolymorphedEntityComponent, RevertPolymorphActionEvent>(OnRevertPolymorphActionEvent);
|
SubscribeLocalEvent<PolymorphedEntityComponent, RevertPolymorphActionEvent>(OnRevertPolymorphActionEvent);
|
||||||
|
SubscribeLocalEvent<PolymorphedEntityComponent, DestructionEventArgs>(OnDestruction);
|
||||||
|
|
||||||
InitializeCollide();
|
InitializeCollide();
|
||||||
InitializeMap();
|
InitializeMap();
|
||||||
@@ -122,6 +126,24 @@ namespace Content.Server.Polymorph.Systems
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// It is possible to be polymorphed into an entity that can't "die", but is instead
|
||||||
|
/// destroyed. This handler ensures that destruction is treated like death.
|
||||||
|
/// </summary>
|
||||||
|
private void OnDestruction(EntityUid uid, PolymorphedEntityComponent comp, DestructionEventArgs args)
|
||||||
|
{
|
||||||
|
if (!_proto.TryIndex<PolymorphPrototype>(comp.Prototype, out var proto))
|
||||||
|
{
|
||||||
|
_sawmill.Error($"Invalid polymorph prototype {comp.Prototype}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (proto.RevertOnDeath)
|
||||||
|
{
|
||||||
|
Revert(uid, comp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnBeforeFullySliced(EntityUid uid, PolymorphedEntityComponent comp, BeforeFullySlicedEvent args)
|
private void OnBeforeFullySliced(EntityUid uid, PolymorphedEntityComponent comp, BeforeFullySlicedEvent args)
|
||||||
{
|
{
|
||||||
if (!_proto.TryIndex<PolymorphPrototype>(comp.Prototype, out var proto))
|
if (!_proto.TryIndex<PolymorphPrototype>(comp.Prototype, out var proto))
|
||||||
@@ -164,6 +186,13 @@ namespace Content.Server.Polymorph.Systems
|
|||||||
if (!proto.AllowRepeatedMorphs && HasComp<PolymorphedEntityComponent>(uid))
|
if (!proto.AllowRepeatedMorphs && HasComp<PolymorphedEntityComponent>(uid))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
// If this polymorph has a cooldown, check if that amount of time has passed since the
|
||||||
|
// last polymorph ended.
|
||||||
|
if (TryComp<PolymorphableComponent>(uid, out var polymorphableComponent) &&
|
||||||
|
polymorphableComponent.LastPolymorphEnd != null &&
|
||||||
|
_gameTiming.CurTime < polymorphableComponent.LastPolymorphEnd + proto.Cooldown)
|
||||||
|
return null;
|
||||||
|
|
||||||
// mostly just for vehicles
|
// mostly just for vehicles
|
||||||
_buckle.TryUnbuckle(uid, uid, true);
|
_buckle.TryUnbuckle(uid, uid, true);
|
||||||
|
|
||||||
@@ -302,6 +331,9 @@ namespace Content.Server.Polymorph.Systems
|
|||||||
if (_mindSystem.TryGetMind(uid, out var mindId, out var mind))
|
if (_mindSystem.TryGetMind(uid, out var mindId, out var mind))
|
||||||
_mindSystem.TransferTo(mindId, parent, mind: mind);
|
_mindSystem.TransferTo(mindId, parent, mind: mind);
|
||||||
|
|
||||||
|
if (TryComp<PolymorphableComponent>(parent, out var polymorphableComponent))
|
||||||
|
polymorphableComponent.LastPolymorphEnd = _gameTiming.CurTime;
|
||||||
|
|
||||||
// if an item polymorph was picked up, put it back down after reverting
|
// if an item polymorph was picked up, put it back down after reverting
|
||||||
Transform(parent).AttachToGridOrMap();
|
Transform(parent).AttachToGridOrMap();
|
||||||
|
|
||||||
|
|||||||
@@ -97,6 +97,14 @@ namespace Content.Shared.Polymorph
|
|||||||
|
|
||||||
[DataField("allowRepeatedMorphs", serverOnly: true)]
|
[DataField("allowRepeatedMorphs", serverOnly: true)]
|
||||||
public bool AllowRepeatedMorphs = false;
|
public bool AllowRepeatedMorphs = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The amount of time that should pass after this polymorph has ended, before a new one
|
||||||
|
/// can occur.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("cooldown", serverOnly: true)]
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public TimeSpan Cooldown = TimeSpan.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum PolymorphInventoryChange : byte
|
public enum PolymorphInventoryChange : byte
|
||||||
|
|||||||
@@ -101,7 +101,8 @@
|
|||||||
forced: true
|
forced: true
|
||||||
transferName: true
|
transferName: true
|
||||||
revertOnDeath: true
|
revertOnDeath: true
|
||||||
|
inventory: Drop
|
||||||
|
cooldown: 160
|
||||||
|
|
||||||
# this is the monkey polymorph for artifact.
|
# this is the monkey polymorph for artifact.
|
||||||
- type: polymorph
|
- type: polymorph
|
||||||
|
|||||||
Reference in New Issue
Block a user