Files
OldThink/Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs
Remuchi e2b6002076 Merge remote-tracking branch 'origin/master' into upstream
# Conflicts:
#	Content.Server/Antag/AntagSelectionSystem.cs
#	Content.Server/Changeling/ChangelingRuleSystem.cs
#	Content.Server/Changeling/ChangelingSystem.Abilities.cs
#	Content.Server/Doors/Systems/DoorSystem.cs
#	Content.Server/GameTicking/Rules/NukeopsRuleSystem.cs
#	Content.Server/GameTicking/Rules/RevolutionaryRuleSystem.cs
#	Content.Server/GameTicking/Rules/TraitorRuleSystem.cs
#	Content.Server/GameTicking/Rules/ZombieRuleSystem.cs
#	Content.Server/Holosign/HolosignSystem.cs
#	Content.Server/Revenant/EntitySystems/RevenantSystem.Abilities.cs
#	Content.Server/_White/Cult/GameRule/CultRuleComponent.cs
#	Content.Server/_White/Cult/GameRule/CultRuleSystem.cs
#	Content.Server/_White/Cult/Runes/Systems/CultSystem.Rune.cs
#	Content.Server/_White/Keyhole/KeyholeSystem.cs
#	Content.Server/_White/MeatyOre/MeatyOreStoreSystem.cs
#	Content.Shared/Projectiles/SharedProjectileSystem.cs
#	Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs
#	Content.Shared/_White/Keyhole/Components/KeyBaseComponent.cs
#	Resources/Locale/ru-RU/White/stuff.ftl/runes-entities.ftl
#	Resources/Locale/ru-RU/_white/cult/blood-spear.ftl
#	Resources/Locale/ru-RU/_white/cult/bolt-barrage.ftl
#	Resources/Locale/ru-RU/_white/cult/cult.ftl
#	Resources/Locale/ru-RU/_white/cult/gui.ftl
#	Resources/Locale/ru-RU/cult/cult-structure.ftl
#	Resources/Locale/ru-RU/cult/pylon.ftl
#	Resources/Maps/White/Scoupidia.yml
#	Resources/Maps/White/Void.yml
#	Resources/Maps/White/WonderBox.yml
#	Resources/Prototypes/Actions/types.yml
#	Resources/Prototypes/Atmospherics/gases.yml
#	Resources/Prototypes/Catalog/Cargo/cargo_atmospherics.yml
#	Resources/Prototypes/Catalog/Cargo/cargo_vending.yml
#	Resources/Prototypes/Catalog/Fills/Lockers/dressers.yml
#	Resources/Prototypes/Catalog/Fills/Lockers/heads.yml
#	Resources/Prototypes/Catalog/Fills/Lockers/misc.yml
#	Resources/Prototypes/Catalog/uplink_catalog.yml
#	Resources/Prototypes/Entities/Clothing/OuterClothing/armor.yml
#	Resources/Prototypes/Entities/Objects/Misc/subdermal_implants.yml
#	Resources/Prototypes/Entities/Objects/Tools/jaws_of_life.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Melee/sledgehammer.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Melee/sword.yml
#	Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_assembly.yml
#	Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_structureairlocks.yml
#	Resources/Prototypes/Entities/Structures/Doors/Firelocks/firelock.yml
#	Resources/Prototypes/Entities/Structures/Doors/Firelocks/frame.yml
#	Resources/Prototypes/Entities/Structures/Doors/SecretDoor/secret_door.yml
#	Resources/Prototypes/Entities/Structures/Doors/Windoors/assembly.yml
#	Resources/Prototypes/Entities/Structures/Doors/Windoors/base_structurewindoors.yml
#	Resources/Prototypes/Entities/Structures/Furniture/dresser.yml
#	Resources/Prototypes/Entities/Structures/Lighting/base_lighting.yml
#	Resources/Prototypes/Entities/Structures/Power/cable_terminal.yml
#	Resources/Prototypes/Entities/Structures/Walls/grille.yml
#	Resources/Prototypes/Entities/Structures/Walls/walls.yml
#	Resources/Prototypes/Entities/Structures/stairs.yml
#	Resources/Prototypes/_White/Entities/Objects/Misc/books.yml
2024-04-13 13:59:00 +07:00

168 lines
6.3 KiB
C#

using Content.Shared.Bed.Sleep;
using Content.Shared.CombatMode.Pacification;
using Content.Shared.Damage.ForceSay;
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;
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, BeforeGettingStrippedEvent>(OnGettingStripped);
SubscribeLocalEvent<MobStateComponent, ChangeDirectionAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, UseAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, AttackAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, ConsciousAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, ThrowAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, SpeakAttemptEvent>(OnSpeakAttempt);
SubscribeLocalEvent<MobStateComponent, IsEquippingAttemptEvent>(OnEquipAttempt);
SubscribeLocalEvent<MobStateComponent, EmoteAttemptEvent>(CheckAct);
SubscribeLocalEvent<MobStateComponent, IsUnequippingAttemptEvent>(OnUnequipAttempt);
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<MobStateComponent, TryingToSleepEvent>(OnSleepAttempt);
SubscribeLocalEvent<MobStateComponent, CombatModeShouldHandInteractEvent>(OnCombatModeShouldHandInteract);
SubscribeLocalEvent<MobStateComponent, AttemptPacifiedAttackEvent>(OnAttemptPacifiedAttack);
}
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:
_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:
_standing.Down(target);
_appearance.SetData(target, MobStateVisuals.State, MobState.Critical);
break;
case MobState.Dead:
_standing.Down(target);
_appearance.SetData(target, MobStateVisuals.State, MobState.Dead);
break;
case MobState.Invalid:
//unused;
break;
default:
throw new NotImplementedException();
}
}
#region Event Subscribers
private void OnSleepAttempt(EntityUid target, MobStateComponent component, ref TryingToSleepEvent args)
{
if (IsDead(target, component))
args.Cancelled = true;
}
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;
}
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;
}
}
private void OnEquipAttempt(EntityUid target, MobStateComponent component, IsEquippingAttemptEvent args)
{
// is this a self-equip, or are they being stripped?
if (args.Equipee == target)
CheckAct(target, component, args);
}
private void OnUnequipAttempt(EntityUid target, MobStateComponent component, IsUnequippingAttemptEvent args)
{
// is this a self-equip, or are they being stripped?
if (args.Unequipee == target)
CheckAct(target, component, args);
}
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;
}
private void OnAttemptPacifiedAttack(Entity<MobStateComponent> ent, ref AttemptPacifiedAttackEvent args)
{
args.Cancelled = true;
}
#endregion
}