Polymorphs and Transformation (#8185)

This commit is contained in:
EmoGarbage404
2022-05-18 00:05:22 -04:00
committed by GitHub
parent dac8540705
commit 2697bbf8c7
16 changed files with 625 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ using System.Linq;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using Content.Shared.Inventory;
using Content.Shared.MobState.Components;
using Content.Shared.Radiation.Events;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
@@ -234,6 +235,45 @@ namespace Content.Shared.Damage
DamageChanged(component, delta);
}
}
/// <summary>
/// Takes the damage from one entity and scales it relative to the health of another
/// </summary>
/// <param name="ent1">The entity whose damage will be scaled</param>
/// <param name="ent2">The entity whose health the damage will scale to</param>
/// <param name="damage">The newly scaled damage. Can be null</param>
public bool GetScaledDamage(EntityUid ent1, EntityUid ent2, out DamageSpecifier? damage)
{
damage = null;
if (!TryComp<DamageableComponent>(ent1, out var olddamage))
return false;
if (!TryComp<MobStateComponent>(ent1, out var oldstate) ||
!TryComp<MobStateComponent>(ent2, out var newstate))
return false;
int ent1DeadState = 0;
foreach (var state in oldstate._highestToLowestStates)
{
if (state.Value.IsDead())
{
ent1DeadState = state.Key;
}
}
int ent2DeadState = 0;
foreach (var state in newstate._highestToLowestStates)
{
if (state.Value.IsDead())
{
ent2DeadState = state.Key;
}
}
damage = (olddamage.Damage / ent1DeadState) * ent2DeadState;
return true;
}
}
/// <summary>

View File

@@ -0,0 +1,74 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Shared.Polymorph
{
/// <summary>
/// Polymorphs generally describe any type of transformation that can be applied to an entity.
/// </summary>
[Prototype("polymorph")]
[DataDefinition]
public sealed class PolymorphPrototype : IPrototype, IInheritingPrototype
{
[ViewVariables]
[IdDataFieldAttribute]
public string ID { get; } = default!;
[DataField("name")]
public string Name { get; } = string.Empty;
[ParentDataField(typeof(AbstractPrototypeIdSerializer<PolymorphPrototype>))]
public string? Parent { get; private set; }
[NeverPushInheritance]
[AbstractDataFieldAttribute]
public bool Abstract { get; private set; }
/// <summary>
/// What entity the polymorph will turn the target into
/// must be in here because it makes no sense if it isn't
/// </summary>
[DataField("entity", required: true, serverOnly: true, customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string Entity = string.Empty;
/// <summary>
/// The delay between the polymorph's uses in seconds
/// Slightly weird as of right now.
/// </summary>
[DataField("delay", serverOnly: true)]
public int Delay = 60;
/// <summary>
/// The duration of the transformation in seconds
/// can be null if there is not one
/// </summary>
[DataField("duration", serverOnly: true)]
public int? Duration = null;
/// <summary>
/// whether or not the target can transform as will
/// set to true for things like polymorph spells and curses
/// </summary>
[DataField("forced", serverOnly: true)]
public bool Forced = false;
/// <summary>
/// Whether or not the target will drop their inventory
/// when they are polymorphed (includes items in hands)
/// </summary>
[DataField("dropInventory", serverOnly: true)]
public bool DropInventory = false;
/// <summary>
/// Whether or not the polymorph reverts when the entity goes into crit.
/// </summary>
[DataField("revertOnCrit", serverOnly: true)]
public bool RevertOnCrit = true;
/// <summary>
/// Whether or not the polymorph reverts when the entity dies.
/// </summary>
[DataField("revertOnDeath", serverOnly: true)]
public bool RevertOnDeath = true;
}
}