Mobstate Refactor (#13389)
Refactors mobstate and moves mob health thresholds to their own component Co-authored-by: DrSmugleaf <drsmugleaf@gmail.com>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Revenant.Components;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.MobState;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.Mobs;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Content.Shared.Revenant.Components;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
@@ -20,13 +20,18 @@ public sealed class EssenceSystem : EntitySystem
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<EssenceComponent, ComponentStartup>(UpdateEssenceAmount);
|
||||
SubscribeLocalEvent<EssenceComponent, MobStateChangedEvent>(UpdateEssenceAmount);
|
||||
SubscribeLocalEvent<EssenceComponent, MindAddedMessage>(UpdateEssenceAmount);
|
||||
SubscribeLocalEvent<EssenceComponent, MindRemovedMessage>(UpdateEssenceAmount);
|
||||
SubscribeLocalEvent<EssenceComponent, ComponentStartup>(OnEssenceEventReceived);
|
||||
SubscribeLocalEvent<EssenceComponent, MobStateChangedEvent>(OnMobstateChanged);
|
||||
SubscribeLocalEvent<EssenceComponent, MindAddedMessage>(OnEssenceEventReceived);
|
||||
SubscribeLocalEvent<EssenceComponent, MindRemovedMessage>(OnEssenceEventReceived);
|
||||
SubscribeLocalEvent<EssenceComponent, ExaminedEvent>(OnExamine);
|
||||
}
|
||||
|
||||
private void OnMobstateChanged(EntityUid uid, EssenceComponent component, MobStateChangedEvent args)
|
||||
{
|
||||
UpdateEssenceAmount(uid, component);
|
||||
}
|
||||
|
||||
private void OnExamine(EntityUid uid, EssenceComponent component, ExaminedEvent args)
|
||||
{
|
||||
if (!component.SearchComplete || !HasComp<RevenantComponent>(args.Examiner))
|
||||
@@ -49,23 +54,28 @@ public sealed class EssenceSystem : EntitySystem
|
||||
args.PushMarkup(Loc.GetString(message, ("target", uid)));
|
||||
}
|
||||
|
||||
private void UpdateEssenceAmount(EntityUid uid, EssenceComponent component, EntityEventArgs args)
|
||||
private void OnEssenceEventReceived(EntityUid uid, EssenceComponent component, EntityEventArgs args)
|
||||
{
|
||||
UpdateEssenceAmount(uid, component);
|
||||
}
|
||||
|
||||
private void UpdateEssenceAmount(EntityUid uid, EssenceComponent component)
|
||||
{
|
||||
if (!TryComp<MobStateComponent>(uid, out var mob))
|
||||
return;
|
||||
|
||||
switch (mob.CurrentState)
|
||||
{
|
||||
case DamageState.Alive:
|
||||
case MobState.Alive:
|
||||
if (TryComp<MindComponent>(uid, out var mind) && mind.Mind != null)
|
||||
component.EssenceAmount = _random.NextFloat(75f, 100f);
|
||||
else
|
||||
component.EssenceAmount = _random.NextFloat(45f, 70f);
|
||||
break;
|
||||
case DamageState.Critical:
|
||||
case MobState.Critical:
|
||||
component.EssenceAmount = _random.NextFloat(35f, 50f);
|
||||
break;
|
||||
case DamageState.Dead:
|
||||
case MobState.Dead:
|
||||
component.EssenceAmount = _random.NextFloat(15f, 20f);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Shared.Revenant;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Map;
|
||||
using Content.Shared.Tag;
|
||||
using Content.Shared.Maps;
|
||||
@@ -19,7 +17,6 @@ using Content.Server.Disease;
|
||||
using Content.Server.Disease.Components;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Bed.Sleep;
|
||||
using Content.Shared.MobState;
|
||||
using System.Linq;
|
||||
using Content.Server.Beam;
|
||||
using Content.Server.Emag;
|
||||
@@ -29,6 +26,9 @@ using Content.Server.Revenant.Components;
|
||||
using Content.Server.Store.Components;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Humanoid;
|
||||
using Content.Shared.Mobs;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Content.Shared.Mobs.Systems;
|
||||
using Content.Shared.Revenant.Components;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Utility;
|
||||
@@ -43,6 +43,7 @@ public sealed partial class RevenantSystem
|
||||
[Dependency] private readonly DiseaseSystem _disease = default!;
|
||||
[Dependency] private readonly EmagSystem _emag = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!;
|
||||
[Dependency] private readonly GhostSystem _ghost = default!;
|
||||
[Dependency] private readonly TileSystem _tile = default!;
|
||||
|
||||
@@ -143,7 +144,7 @@ public sealed partial class RevenantSystem
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryComp<MobStateComponent>(target, out var mobstate) && mobstate.CurrentState == DamageState.Alive && !HasComp<SleepingComponent>(target))
|
||||
if (TryComp<MobStateComponent>(target, out var mobstate) && mobstate.CurrentState == MobState.Alive && !HasComp<SleepingComponent>(target))
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("revenant-soul-too-powerful"), target, uid);
|
||||
return;
|
||||
@@ -197,8 +198,8 @@ public sealed partial class RevenantSystem
|
||||
}
|
||||
|
||||
//KILL THEMMMM
|
||||
var damage = _mobState.GetEarliestDeadState(mobstate, 0)?.threshold;
|
||||
if (damage == null)
|
||||
|
||||
if (!_mobThresholdSystem.TryGetThresholdForState(args.Target, MobState.Dead, out var damage))
|
||||
return;
|
||||
DamageSpecifier dspec = new();
|
||||
dspec.DamageDict.Add("Poison", damage.Value);
|
||||
|
||||
@@ -10,7 +10,6 @@ using Content.Shared.Revenant;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Random;
|
||||
using Content.Shared.StatusEffect;
|
||||
using Content.Server.MobState;
|
||||
using Content.Server.Visible;
|
||||
using Content.Shared.Examine;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -21,6 +20,7 @@ using Content.Server.Store.Systems;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Player;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Mobs.Systems;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Revenant.Components;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user