CatStation/Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs
ScarKy0 091180655d
Changeling Chemicals (#45239)
* initially works i think

* yeah

* pulled these numbers outta my ass

* text

* silly

* fixy fix

* fix

* This sure is a videogame

* init test fuck everything

* sprites

* fix dirty

* query

* another query

* craftable changeling sting

* remove todo

* \n

* doc
2026-08-19 19:25:16 +00:00

252 lines
8.4 KiB
C#

using Content.Shared.Actions.Events;
using Content.Shared.Bed.Sleep;
using Content.Shared.Buckle.Components;
using Content.Shared.CombatMode.Pacification;
using Content.Shared.Cuffs;
using Content.Shared.Damage.ForceSay;
using Content.Shared.Damage.Systems;
using Content.Shared.Emoting;
using Content.Shared.Hands;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory.Events;
using Content.Shared.Item;
using Content.Shared.Mobs.Components;
using Content.Shared.Movement.Events;
using Content.Shared.Pointing;
using Content.Shared.Pulling.Events;
using Content.Shared.Speech;
using Content.Shared.Standing;
using Content.Shared.Strip.Components;
using Content.Shared.Throwing;
using Content.Shared.Tools.Systems;
using System.Linq;
using Content.Shared.Popups;
namespace Content.Shared.Mobs.Systems;
public partial class MobStateSystem
{
//General purpose event subscriptions. If you can avoid it register these events inside their own systems
private void SubscribeEvents()
{
SubscribeLocalEvent<MobStateComponent, ChangeDirectionAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, UseAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, AttackAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, ThrowAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, EmoteAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, DropAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, PickupAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, StartPullAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, UpdateCanMoveEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, StandAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, PointAttemptEvent>(CheckAct);
}
[SubscribeLocalEvent]
private void OnUnbuckleAttempt(Entity<MobStateComponent> ent, ref UnbuckleAttemptEvent args)
{
// TODO is this necessary?
// Shouldn't the interaction have already been blocked by a general interaction check?
if (args.User == ent.Owner && IsIncapacitated(ent))
args.Cancelled = true;
}
private void Down(EntityUid target)
{
_standing.Down(target);
var ev = new DropHandItemsEvent();
RaiseLocalEvent(target, ref ev);
}
[SubscribeLocalEvent]
private void CheckConcious(Entity<MobStateComponent> ent, ref ConsciousAttemptEvent args)
{
switch (ent.Comp.CurrentState)
{
case MobState.Dead:
case MobState.Critical:
args.Cancelled = true;
break;
}
}
private void OnStateExitSubscribers(EntityUid target, MobStateComponent component, MobState state)
{
switch (state)
{
case MobState.Alive:
//unused
break;
case MobState.Critical:
_standing.Stand(target);
break;
case MobState.Dead:
RemComp<CollisionWakeComponent>(target);
_standing.Stand(target);
break;
case MobState.Invalid:
//unused
break;
default:
throw new NotImplementedException();
}
}
private void OnStateEnteredSubscribers(EntityUid target, MobStateComponent component, MobState state)
{
// All of the state changes here should already be networked, so we do nothing if we are currently applying a
// server state.
if (_timing.ApplyingState)
return;
_blocker.UpdateCanMove(target); //update movement anytime a state changes
switch (state)
{
case MobState.Alive:
{
_standing.Stand(target);
_appearance.SetData(target, MobStateVisuals.State, MobState.Alive);
break;
}
case MobState.Critical:
{
Down(target);
_appearance.SetData(target, MobStateVisuals.State, MobState.Critical);
break;
}
case MobState.Dead:
{
EnsureComp<CollisionWakeComponent>(target);
Down(target);
_appearance.SetData(target, MobStateVisuals.State, MobState.Dead);
break;
}
case MobState.Invalid:
{
//unused;
break;
}
default:
{
throw new NotImplementedException();
}
}
}
[SubscribeLocalEvent]
private void OnAttemptToolRefine(Entity<MobStateComponent> ent, ref AttemptToolRefineEvent args)
{
if (!IsDead(ent, ent))
{
args = args with { IsCancelled = true, BlockCause = Loc.GetString("refined-slice-verb-target-isnt-dead") };
}
}
#region Event Subscribers
[SubscribeLocalEvent]
private void OnSleepAttempt(EntityUid target, MobStateComponent component, ref TryingToSleepEvent args)
{
if (IsDead(target, component))
args.Cancelled = true;
}
[SubscribeLocalEvent]
private void OnGettingStripped(EntityUid target, MobStateComponent component, BeforeGettingStrippedEvent args)
{
// Incapacitated or dead targets get stripped two or three times as fast. Makes stripping corpses less tedious.
if (IsDead(target, component))
args.Multiplier /= 3;
else if (IsCritical(target, component))
args.Multiplier /= 2;
}
[SubscribeLocalEvent]
private void OnSpeakAttempt(EntityUid uid, MobStateComponent component, SpeakAttemptEvent args)
{
if (HasComp<AllowNextCritSpeechComponent>(uid))
{
RemCompDeferred<AllowNextCritSpeechComponent>(uid);
return;
}
CheckAct(uid, component, args);
}
private void CheckAct(EntityUid target, MobStateComponent component, CancellableEntityEventArgs args)
{
switch (component.CurrentState)
{
case MobState.Dead:
case MobState.Critical:
args.Cancel();
break;
}
}
[SubscribeLocalEvent]
private void OnEquipAttempt(EntityUid target, MobStateComponent component, IsEquippingAttemptEvent args)
{
// is this a self-equip, or are they being stripped?
if (args.User == target)
CheckAct(target, component, args);
}
[SubscribeLocalEvent]
private void OnUnequipAttempt(EntityUid target, MobStateComponent component, IsUnequippingAttemptEvent args)
{
// is this a self-equip, or are they being stripped?
if (args.User == target)
CheckAct(target, component, args);
}
[SubscribeLocalEvent]
private void OnCombatModeShouldHandInteract(EntityUid uid, MobStateComponent component, ref CombatModeShouldHandInteractEvent args)
{
// Disallow empty-hand-interacting in combat mode
// for non-dead mobs
if (!IsDead(uid, component))
args.Cancelled = true;
}
[SubscribeLocalEvent]
private void OnAttemptPacifiedAttack(Entity<MobStateComponent> ent, ref AttemptPacifiedAttackEvent args)
{
args.Cancelled = true;
}
[SubscribeLocalEvent]
private void OnDamageModify(Entity<MobStateComponent> ent, ref DamageModifyEvent args)
{
args.Damage *= _damageable.UniversalMobDamageModifier;
}
[SubscribeLocalEvent]
private void OnMobStateActionAttempt(Entity<ActionRequireMobStateComponent> ent, ref ActionAttemptEvent args)
{
if (_mobStateQuery.TryComp(args.User, out var mobState) &&
ent.Comp.States.Contains(mobState.CurrentState))
{
return;
}
if (ent.Comp.FailReason != null)
{
var states = string.Join(", ", ent.Comp.States.Order().Select(s => Loc.GetString($"mob-state-{s}")));
args.Reason = Loc.GetString(ent.Comp.FailReason, ("states", states));
args.Type = ent.Comp.FailReasonPopupType;
}
args.Cancelled = true;
}
[SubscribeLocalEvent]
private void OnIncapCuffCheck(Entity<MobStateComponent> ent, ref CheckIncapacitatedCuffEvent args)
{
if (IsIncapacitated(ent, ent.Comp))
args.Incapacitated = true;
}
#endregion
}