Staff of Animation Fixes (#35491)

* staff of animation fixes and system

* requested changes

* size back to normal

* Update AnimateSpellSystem.cs

---------

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>
This commit is contained in:
ActiveMammmoth
2025-02-27 14:11:57 -05:00
committed by GitHub
parent 3c20f63292
commit cec05d697e
8 changed files with 86 additions and 58 deletions

View File

@@ -0,0 +1,8 @@
using Robust.Shared.GameStates;
namespace Content.Shared.Magic.Components;
// Added to objects when they are made animate
[RegisterComponent, NetworkedComponent]
public sealed partial class AnimateComponent : Component;

View File

@@ -1,16 +0,0 @@
using Content.Shared.Actions;
using Robust.Shared.Prototypes;
namespace Content.Shared.Magic.Events;
public sealed partial class AnimateSpellEvent : EntityTargetActionEvent, ISpeakSpell
{
[DataField]
public string? Speech { get; private set; }
[DataField]
public ComponentRegistry AddComponents = new();
[DataField]
public HashSet<string> RemoveComponents = new();
}

View File

@@ -1,4 +1,4 @@
using Content.Shared.Actions;
using Content.Shared.Actions;
using Robust.Shared.Prototypes;
namespace Content.Shared.Magic.Events;
@@ -11,14 +11,17 @@ public sealed partial class ChangeComponentsSpellEvent : EntityTargetActionEvent
// TODO allow it to set component data-fields?
// for now a Hackish way to do that is to remove & add, but that doesn't allow you to selectively set specific data fields.
[DataField("toAdd")]
[DataField]
[AlwaysPushInheritance]
public ComponentRegistry ToAdd = new();
[DataField("toRemove")]
[DataField]
[AlwaysPushInheritance]
public HashSet<string> ToRemove = new();
[DataField("speech")]
[DataField]
public string? Speech { get; private set; }
[DataField]
public bool DoSpeech { get; private set; }
}

View File

@@ -1,4 +1,3 @@
using System.Linq;
using System.Numerics;
using Content.Shared.Actions;
using Content.Shared.Body.Components;
@@ -27,8 +26,6 @@ using Robust.Shared.Audio.Systems;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Network;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
@@ -84,7 +81,6 @@ public abstract class SharedMagicSystem : EntitySystem
SubscribeLocalEvent<RandomGlobalSpawnSpellEvent>(OnRandomGlobalSpawnSpell);
SubscribeLocalEvent<MindSwapSpellEvent>(OnMindSwapSpell);
SubscribeLocalEvent<VoidApplauseSpellEvent>(OnVoidApplause);
SubscribeLocalEvent<AnimateSpellEvent>(OnAnimateSpell);
}
private void OnBeforeCastSpell(Entity<MagicComponent> ent, ref BeforeCastSpellEvent args)
@@ -301,6 +297,7 @@ public abstract class SharedMagicSystem : EntitySystem
return;
ev.Handled = true;
if (ev.DoSpeech)
Speak(ev);
RemoveComponents(ev.Target, ev.ToRemove);
@@ -532,33 +529,6 @@ public abstract class SharedMagicSystem : EntitySystem
_stun.TryParalyze(ev.Performer, ev.PerformerStunDuration, true);
}
#endregion
#region Animation Spells
private void OnAnimateSpell(AnimateSpellEvent ev)
{
if (ev.Handled || !PassesSpellPrerequisites(ev.Action, ev.Performer) || !TryComp<FixturesComponent>(ev.Target, out var fixtures) ||
!TryComp<PhysicsComponent>(ev.Target, out var physics))
return;
ev.Handled = true;
//Speak(ev);
RemoveComponents(ev.Target, ev.RemoveComponents);
AddComponents(ev.Target, ev.AddComponents);
var xform = Transform(ev.Target);
var fixture = fixtures.Fixtures.First();
_transform.Unanchor(ev.Target);
_physics.SetCanCollide(ev.Target, true, true, false, fixtures, physics);
_physics.SetCollisionMask(ev.Target, fixture.Key, fixture.Value, (int)CollisionGroup.FlyingMobMask, fixtures, physics);
_physics.SetCollisionLayer(ev.Target, fixture.Key, fixture.Value, (int)CollisionGroup.FlyingMobLayer, fixtures, physics);
_physics.SetBodyType(ev.Target, BodyType.KinematicController, fixtures, physics, xform);
_physics.SetBodyStatus(ev.Target, physics, BodyStatus.InAir, true);
_physics.SetFixedRotation(ev.Target, false, true, fixtures, physics);
}
#endregion
// End Spells
#endregion

View File

@@ -0,0 +1,48 @@
using Content.Shared.Magic.Components;
using Content.Shared.Physics;
using Robust.Shared.Containers;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
using System.Linq;
namespace Content.Shared.Magic.Systems;
public sealed class AnimateSpellSystem : EntitySystem
{
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
public override void Initialize()
{
SubscribeLocalEvent<AnimateComponent, MapInitEvent>(OnAnimate);
}
private void OnAnimate(Entity<AnimateComponent> ent, ref MapInitEvent args)
{
// Physics bullshittery necessary for object to behave properly
if (!TryComp<FixturesComponent>(ent, out var fixtures) || !TryComp<PhysicsComponent>(ent, out var physics))
return;
var xform = Transform(ent);
var fixture = fixtures.Fixtures.First();
_transform.Unanchor(ent); // If left anchored they are effectively stuck/immobile and not a threat
_physics.SetCanCollide(ent, true, true, false, fixtures, physics);
_physics.SetCollisionMask(ent, fixture.Key, fixture.Value, (int)CollisionGroup.FlyingMobMask, fixtures, physics);
_physics.SetCollisionLayer(ent, fixture.Key, fixture.Value, (int)CollisionGroup.FlyingMobLayer, fixtures, physics);
_physics.SetBodyType(ent, BodyType.KinematicController, fixtures, physics, xform);
_physics.SetBodyStatus(ent, physics, BodyStatus.InAir, true);
_physics.SetFixedRotation(ent, false, true, fixtures, physics);
_physics.SetHard(ent, fixture.Value, true, fixtures);
_container.AttachParentToContainerOrGrid((ent, xform)); // Items animated inside inventory now exit, they can't be picked up and so can't escape otherwise
var ev = new AnimateSpellEvent();
RaiseLocalEvent(ref ev);
}
}
[ByRefEvent]
public readonly record struct AnimateSpellEvent;

View File

@@ -9,13 +9,16 @@
itemIconStyle: BigAction
whitelist:
components:
- Animateable # Currently on: SeatBase, TableBase, ClosetBase, BaseMachine, ConstructibleMachine, BaseComputer, BaseItem, CrateGeneric, StorageTank, GasCanister
- Animateable # Currently on: SeatBase, TableBase, ClosetBase, BaseMachine, ConstructibleMachine, BaseComputer, BaseItem, CrateGeneric, StorageTank, GasCanister, BaseTarget
blacklist:
components:
- MindContainer
- NukeDisk
- GravityGenerator
- AnomalyGenerator
- TegGenerator
- TegCirculator
- Artifact
canTargetSelf: false
interactOnMiss: false
sound: !type:SoundPathSpecifier
@@ -23,8 +26,9 @@
icon:
sprite: Objects/Magic/magicactions.rsi
state: spell_default
event: !type:AnimateSpellEvent
addComponents:
event: !type:ChangeComponentsSpellEvent
toAdd:
- type: Animate
- type: MindContainer
- type: InputMover
- type: MobMover
@@ -65,6 +69,9 @@
collection: MetalBreak
- type: Hands
- type: CanEscapeInventory
removeComponents:
toRemove:
- RequireProjectileTarget
- BlockMovement
- Item
speech: action-speech-spell-animate
doSpeech: false

View File

@@ -181,8 +181,6 @@
orGroup: Magics
- id: BlinkBook
orGroup: Magics
- id: SmiteBook
orGroup: Magics
- id: KnockSpellbook
orGroup: Magics
- id: FireballSpellbook
@@ -203,4 +201,8 @@
orGroup: Magics
- id: WeaponStaffPolymorphDoor
orGroup: Magics
- id: AnimationStaff
orGroup: Magics
- id: RGBStaff
orGroup: Magics
speech: action-speech-spell-summon-magic

View File

@@ -27,6 +27,7 @@
hostile:
- PetsNT
- AllHostile
- Wizard
- type: npcFaction
id: Passive
@@ -39,6 +40,7 @@
- Zombie
- Xeno
- AllHostile
- Wizard
- type: npcFaction
id: SimpleHostile
@@ -123,7 +125,11 @@
hostile:
- NanoTrasen
- Dragon
- Mouse
- Passive
- PetsNT
- SimpleHostile
- SimpleNeutral
- Syndicate
- Xeno
- Zombie