From 42ff38f39bc11263edd39d95816231d2f5ed2841 Mon Sep 17 00:00:00 2001 From: Minimata Date: Sun, 29 Mar 2026 17:30:14 +0200 Subject: [PATCH] yow it's working or wat --- forge/ForgeManager.cs | 14 +- forge/abilities/RAbilityBase.cs | 21 +- forge/abilities/RExplodingSword.cs | 77 +---- forge/calculators/FlyingWeaponExecution.cs | 7 +- interfaces/IAbilityBase.cs | 7 +- .../components/weapon/WeaponSystem.cs | 278 +++++++++++++----- .../scripts/PlayerController.cs | 108 ++----- 7 files changed, 276 insertions(+), 236 deletions(-) diff --git a/forge/ForgeManager.cs b/forge/ForgeManager.cs index 85f207d5..522d4c0b 100644 --- a/forge/ForgeManager.cs +++ b/forge/ForgeManager.cs @@ -17,6 +17,10 @@ public partial class ForgeManager : Node // Statuses "status.stunned", + "status.weapon.inHand", + "status.weapon.flying", + "status.weapon.planted", + // Abilities "abilities.weapon.land", "abilities.weapon.flying", @@ -25,9 +29,15 @@ public partial class ForgeManager : Node // Events "events.combat.damage", "events.combat.hit", - "events.weapon.left", + "events.weapon.flyingTick", - "events.weapon.land", + "events.weapon.startedFlying", + "events.weapon.stoppedFlying", + "events.weapon.handToFlying", + "events.weapon.flyingToHand", + "events.weapon.plantedToHand", + "events.weapon.plantedToFlying", + "events.weapon.planted", // Cooldowns "cooldown.empoweredAction", diff --git a/forge/abilities/RAbilityBase.cs b/forge/abilities/RAbilityBase.cs index bc37b174..3c7da47e 100644 --- a/forge/abilities/RAbilityBase.cs +++ b/forge/abilities/RAbilityBase.cs @@ -13,28 +13,13 @@ using Movementtests.interfaces; namespace Movementtests.forge.abilities; [GlobalClass] -public partial class RAbilityBase(float cost, float cooldown) : Resource, IAbilityBase +public partial class RAbilityBase : Resource { - [Export(PropertyHint.Range, "0,100,1,or_greater")] - public float Cost { get; set; } = cost; - [Export(PropertyHint.Range, "0,10,0.1,or_greater")] - public float Cooldown { get; set; } = cooldown; - - public RAbilityBase() : this(20.0f, 0.0f) + public RAbilityBase() { } - public virtual AbilityData Ability(TagsManager tagsManager, TagContainer? tags, Node3D owner) - { - throw new NotImplementedException(); - } - - public virtual EffectData CostEffect(TagsManager tagsManager) - { - throw new NotImplementedException(); - } - - public virtual EffectData CooldownEffect(TagsManager tagsManager) + public virtual AbilityData Ability(TagContainer? tags, Node3D owner) { throw new NotImplementedException(); } diff --git a/forge/abilities/RExplodingSword.cs b/forge/abilities/RExplodingSword.cs index 02e6311c..14db21a9 100644 --- a/forge/abilities/RExplodingSword.cs +++ b/forge/abilities/RExplodingSword.cs @@ -8,74 +8,32 @@ using Gamesmiths.Forge.Effects.Magnitudes; using Gamesmiths.Forge.Effects.Modifiers; using Gamesmiths.Forge.Tags; using Godot; +using Movementtests.interfaces; using Movementtests.systems; namespace Movementtests.forge.abilities; +public record struct ExplodingSwordCreation(Node3D Owner); + [GlobalClass, Icon("res://assets/ui/IconGodotNode/white/icon_projectile.png")] -public partial class RExplodingSword(PackedScene? explosion, float cost, float cooldown) : RAbilityBase(cost, cooldown) +public partial class RExplodingSword(PackedScene? explosion) : Resource, IAbilityBase { [Export] public PackedScene? Explosion { get; set; } = explosion; - public RExplodingSword() : this(null, 20.0f, 0.0f) - { - } + public RExplodingSword() : this(null) {} - public override AbilityData Ability(TagsManager tagsManager, TagContainer? tags, Node3D owner) + public AbilityData Ability(ExplodingSwordCreation creationData, TagContainer? tags) { return new AbilityData( name: "Exploding Sword Throw", - costEffect: CostEffect(tagsManager), - cooldownEffects: [CooldownEffect(tagsManager)], abilityTags: tags, instancingPolicy: AbilityInstancingPolicy.PerEntity, - behaviorFactory: () => new ExplodingSwordThrowBehavior(owner, Explosion)); + behaviorFactory: () => new ExplodingSwordThrowBehavior(creationData.Owner, Explosion)); } - - public override EffectData CostEffect(TagsManager tagsManager) - { - return new( - "Exploding Sword Throw Mana Cost", - new DurationData(DurationType.Instant), - new[] - { - new Modifier( - "PlayerAttributeSet.Mana", - ModifierOperation.FlatBonus, - new ModifierMagnitude( - MagnitudeCalculationType.ScalableFloat, - new ScalableFloat(-Cost) - ) - ) - }, - cues: new [] - { - new CueData( - CueTags: Tag.RequestTag(tagsManager, "cues.resources.mana").GetSingleTagContainer(), - MinValue: 0, - MaxValue: 100, - MagnitudeType: CueMagnitudeType.AttributeValueChange, - MagnitudeAttribute: "PlayerAttributeSet.Mana" - ) - }); - } - - public override EffectData CooldownEffect(TagsManager tagsManager) + public IAbilityBehavior Behavior(ExplodingSwordCreation creationData) { - return new( - "Exploding Sword Throw Cooldown", - new DurationData( - DurationType.HasDuration, - new ModifierMagnitude( - MagnitudeCalculationType.ScalableFloat, - new ScalableFloat(Cooldown))), - effectComponents: new[] - { - new ModifierTagsEffectComponent( - tagsManager.RequestTagContainer(new[] { "cooldown.empoweredSwordThrow" }) - ) - }); + return new ExplodingSwordThrowBehavior(creationData.Owner, Explosion); } } @@ -85,18 +43,21 @@ public class ExplodingSwordThrowBehavior(Node3D owner, PackedScene? ex private PackedScene? _explosion = explosion; public void OnStarted(AbilityBehaviorContext context, TPayload payload) { - GD.Print(payload); if (_explosion?.Instantiate() is not Explosion explosion) { + GD.Print("Cannot instantiate"); context.InstanceHandle.End(); return; } if (!_owner.IsInsideTree()) { + GD.Print("Not inside tree"); context.InstanceHandle.End(); return; } + GD.Print("EXPLOSION"); + explosion.Radius = 6f; _owner.GetTree().GetRoot().CallDeferred(Node.MethodName.AddChild, explosion); @@ -109,16 +70,4 @@ public class ExplodingSwordThrowBehavior(Node3D owner, PackedScene? ex public void OnEnded(AbilityBehaviorContext context) { } -} - -public class TestBehavior( - Action callback) : IAbilityBehavior -{ - public void OnStarted(AbilityBehaviorContext context, TPayload data) - { - callback(context, data); - context.InstanceHandle.End(); - } - - public void OnEnded(AbilityBehaviorContext context){} } \ No newline at end of file diff --git a/forge/calculators/FlyingWeaponExecution.cs b/forge/calculators/FlyingWeaponExecution.cs index 8a595c5e..21f7e808 100644 --- a/forge/calculators/FlyingWeaponExecution.cs +++ b/forge/calculators/FlyingWeaponExecution.cs @@ -11,17 +11,18 @@ using Movementtests.systems; namespace Movementtests.tools.calculators; + public class FlyingWeaponExecution(WeaponSystem weaponSystem) : CustomExecution { public override ModifierEvaluatedData[] EvaluateExecution(Effect effect, IForgeEntity target, EffectEvaluatedData? effectEvaluatedData) { GD.Print("Custom execution executed"); - weaponSystem.Events.Raise(new EventData + weaponSystem.Events.Raise(new EventData { - EventTags = weaponSystem.WeaponFlyingTickTag.GetSingleTagContainer()!, + EventTags = weaponSystem.WeaponFlyingTickEventTag.GetSingleTagContainer()!, Source = weaponSystem, EventMagnitude = 12f, - Payload = new WeaponFlyingPayload(Message: "flying") + Payload = new WeaponEventPayload(Message: "flying") }); return []; diff --git a/interfaces/IAbilityBase.cs b/interfaces/IAbilityBase.cs index ac097a0d..d3746387 100644 --- a/interfaces/IAbilityBase.cs +++ b/interfaces/IAbilityBase.cs @@ -5,9 +5,8 @@ using Godot; namespace Movementtests.interfaces; -public interface IAbilityBase +public interface IAbilityBase { - AbilityData Ability(TagsManager tagsManager, TagContainer? tags, Node3D owner); - EffectData CostEffect(TagsManager tagsManager); - EffectData CooldownEffect(TagsManager tagsManager); + AbilityData Ability(TCreation creationData, TagContainer? tags); + IAbilityBehavior Behavior(TCreation creationData); } \ No newline at end of file diff --git a/scenes/player_controller/components/weapon/WeaponSystem.cs b/scenes/player_controller/components/weapon/WeaponSystem.cs index 99829587..a44222c6 100644 --- a/scenes/player_controller/components/weapon/WeaponSystem.cs +++ b/scenes/player_controller/components/weapon/WeaponSystem.cs @@ -1,20 +1,41 @@ using System; +using System.Collections.Generic; +using Gamesmiths.Forge.Abilities; using Gamesmiths.Forge.Core; using Gamesmiths.Forge.Effects; +using Gamesmiths.Forge.Effects.Calculator; +using Gamesmiths.Forge.Effects.Components; +using Gamesmiths.Forge.Effects.Duration; +using Gamesmiths.Forge.Effects.Magnitudes; +using Gamesmiths.Forge.Effects.Periodic; using Gamesmiths.Forge.Events; using Gamesmiths.Forge.Tags; using Godot; using GodotStateCharts; +using Movementtests.addons.godot_state_charts.csharp; +using Movementtests.forge.abilities; using Movementtests.interfaces; using Movementtests.scenes.player_controller.components.weapon; using Movementtests.systems.damage; using Movementtests.tools; +using Movementtests.tools.calculators; namespace Movementtests.systems; -public record struct WeaponLandPayload(); -public record struct WeaponFlyingPayload(string Message); -public record struct WeaponLeftPayload(); +public record struct WeaponEventPayload(String Message); + + +public class ClosureBehavior( + Action callback) : IAbilityBehavior +{ + public void OnStarted(AbilityBehaviorContext context, TPayload data) + { + callback(context, data); + context.InstanceHandle.End(); + } + + public void OnEnded(AbilityBehaviorContext context){} +} [GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_sword.png")] public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity @@ -38,10 +59,16 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity public EntityAbilities Abilities { get; set; } = null!; public EventManager Events { get; set; } = null!; - private StateChart _weaponState = null!; + private StateChart _weaponState = null!; public StateChartState InHandState = null!; public StateChartState FlyingState = null!; public StateChartState PlantedState = null!; + private Transition _handToFlying = null!; + private Transition _flyingToHand = null!; + private Transition _plantedToHand = null!; + private Transition _plantedToFlying = null!; + private Transition _toPlanted = null!; + private ShapeCast3D _dashCast3D = null!; public Timer WeaponFlyingTick = null!; @@ -56,10 +83,24 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity public MeshInstance3D WeaponLocationIndicator { get; set; } = null!; public StandardMaterial3D WeaponLocationIndicatorMaterial { get; set; } = null!; public MeshInstance3D WeaponMesh { get; set; } = null!; + + public Tag WeaponFlyingTickEventTag; + public Tag WeaponStartedFlyingEventTag; + public Tag WeaponStoppedFlyingEventTag; + public Tag WeaponHandToFlyingEventTag; + public Tag WeaponFlyingToHandEventTag; + public Tag WeaponPlantedToHandEventTag; + public Tag WeaponPlantedToFlyingEventTag; + public Tag WeaponPlantedEventTag; - public Tag WeaponLeftTag; - public Tag WeaponFlyingTickTag; - public Tag WeaponLandTag; + public Tag WeaponInHandStatusTag; + public Tag WeaponFlyingStatusTag; + public Tag WeaponPlantedStatusTag; + + public Tag WeaponFlyingAbilityTag; + + private RAbilityBase? _flyingAbility; + public List AbilityLoadout { get; } = []; public void Init() { @@ -67,6 +108,11 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity InHandState = StateChartState.Of(GetNode("StateChart/Root/InHand")); FlyingState = StateChartState.Of(GetNode("StateChart/Root/Flying")); PlantedState = StateChartState.Of(GetNode("StateChart/Root/Planted")); + _handToFlying = Transition.Of(GetNode("StateChart/Root/InHand/ToFlying")); + _flyingToHand = Transition.Of(GetNode("StateChart/Root/Flying/ToHand")); + _plantedToHand = Transition.Of(GetNode("StateChart/Root/Planted/ToHand")); + _plantedToFlying = Transition.Of(GetNode("StateChart/Root/Planted/ToFlying")); + _toPlanted = Transition.Of(GetNode("StateChart/Root/ToPlanted")); WeaponLocationIndicator = GetNode("WeaponLocationIndicator"); WeaponLocationIndicator.Visible = false; @@ -81,12 +127,29 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity Freeze = true; Visible = false; + // Forge var tagsManager = ForgeManager.GetTagsManager(this); var cuesManager = ForgeManager.GetCuesManager(this); + + WeaponFlyingTickEventTag = Tag.RequestTag(tagsManager, "events.weapon.flyingTick"); + WeaponStartedFlyingEventTag = Tag.RequestTag(tagsManager, "events.weapon.startedFlying"); + WeaponStoppedFlyingEventTag = Tag.RequestTag(tagsManager, "events.weapon.stoppedFlying"); + WeaponHandToFlyingEventTag = Tag.RequestTag(tagsManager, "events.weapon.handToFlying"); + WeaponFlyingToHandEventTag = Tag.RequestTag(tagsManager, "events.weapon.flyingToHand"); + WeaponPlantedToHandEventTag = Tag.RequestTag(tagsManager, "events.weapon.plantedToHand"); + WeaponPlantedToFlyingEventTag = Tag.RequestTag(tagsManager, "events.weapon.plantedToFlying"); + WeaponPlantedEventTag = Tag.RequestTag(tagsManager, "events.weapon.planted"); + + WeaponInHandStatusTag = Tag.RequestTag(tagsManager, "status.weapon.inHand"); + WeaponFlyingStatusTag = Tag.RequestTag(tagsManager, "status.weapon.flying"); + WeaponPlantedStatusTag = Tag.RequestTag(tagsManager, "status.weapon.planted"); + + WeaponFlyingAbilityTag = Tag.RequestTag(tagsManager,"abilities.weapon.flying"); + var baseTags = new TagContainer( tagsManager, [ - Tag.RequestTag(tagsManager, "weapon") + Tag.RequestTag(tagsManager, "weapon"), ]); Attributes = new EntityAttributes(new WeaponAttributeSet()); @@ -95,29 +158,149 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity Abilities = new(this); Events = new(); - WeaponLeftTag = Tag.RequestTag(tagsManager, "events.weapon.left"); - WeaponFlyingTickTag = Tag.RequestTag(tagsManager, "events.weapon.flyingTick"); - WeaponLandTag = Tag.RequestTag(tagsManager, "events.weapon.land"); + CreateFlyingAbility(); BodyEntered += OnThrownWeaponReachesGround; InHandState.StateExited += WeaponLeft; InHandState.StateEntered += WeaponBack; - FlyingState.StateEntered += FlyingStarted; - FlyingState.StateExited += FlyingEnded; - // WeaponFlyingTick.Timeout += RaiseWeaponFlyingTickEvent; + _handToFlying.Taken += () => + { + Events.Raise(new EventData + { + EventTags = WeaponHandToFlyingEventTag.GetSingleTagContainer()!, + Source = this, + Payload = new WeaponEventPayload(Message: "handToFlying") + }); + Events.Raise(new EventData + { + EventTags = WeaponStartedFlyingEventTag.GetSingleTagContainer()!, + Source = this, + Payload = new WeaponEventPayload(Message: "startedFlying") + }); + }; + + _flyingToHand.Taken += () => + { + Events.Raise(new EventData + { + EventTags = WeaponFlyingToHandEventTag.GetSingleTagContainer()!, + Source = this, + Payload = new WeaponEventPayload(Message: "flyingToHand") + }); + Events.Raise(new EventData + { + EventTags = WeaponStoppedFlyingEventTag.GetSingleTagContainer()!, + Source = this, + Payload = new WeaponEventPayload(Message: "stoppedFlying") + }); + }; + + _plantedToHand.Taken += () => + { + Events.Raise(new EventData + { + EventTags = WeaponPlantedToHandEventTag.GetSingleTagContainer()!, + Source = this, + Payload = new WeaponEventPayload(Message: "plantedToHand") + }); + }; + + _plantedToFlying.Taken += () => + { + Events.Raise(new EventData + { + EventTags = WeaponPlantedToFlyingEventTag.GetSingleTagContainer()!, + Source = this, + Payload = new WeaponEventPayload(Message: "plantedToFlying") + }); + Events.Raise(new EventData + { + EventTags = WeaponStartedFlyingEventTag.GetSingleTagContainer()!, + Source = this, + Payload = new WeaponEventPayload(Message: "startedFlying") + }); + }; + + _toPlanted.Taken += () => + { + Events.Raise(new EventData + { + EventTags = WeaponPlantedEventTag.GetSingleTagContainer()!, + Source = this, + Target = _plantedEntity, + Payload = new WeaponEventPayload(Message: "planted") + }); + Events.Raise(new EventData + { + EventTags = WeaponStoppedFlyingEventTag.GetSingleTagContainer()!, + Source = this, + Payload = new WeaponEventPayload(Message: "stoppedFlying") + }); + }; + + Events.Subscribe(WeaponStoppedFlyingEventTag, data => + { + GD.Print("This is removing the periodic effect to the flying weapon"); + GD.Print(data.Payload.Message); + if (_flyingWeaponEffectHandle is { IsValid: true }) EffectsManager.RemoveEffect(_flyingWeaponEffectHandle); + }); + } + private ActiveEffectHandle? _flyingWeaponEffectHandle; + + public void CreateFlyingAbility() + { + var flyingWeaponEffectData = new EffectData( + "Flying Weapon Effect Data", + new DurationData(DurationType.Infinite), + customExecutions: + [ + new FlyingWeaponExecution(this) + ], + periodicData: new PeriodicData(new ScalableFloat(0.2f), false, PeriodInhibitionRemovedPolicy.ResetPeriod) + ); + + var weaponHandToFlyingAbilityData = new AbilityData( + name: "WeaponHandToFlyingSword", + abilityTags: WeaponFlyingAbilityTag.GetSingleTagContainer(), + instancingPolicy: AbilityInstancingPolicy.PerEntity, + abilityTriggerData: AbilityTriggerData.ForEvent(WeaponStartedFlyingEventTag), + behaviorFactory: () => new ClosureBehavior((ctx, payload) => + { + GD.Print("This is applying the periodic effect to the flying weapon"); + GD.Print(payload.Message); + _flyingWeaponEffectHandle = EffectsManager.ApplyEffect(new Effect(flyingWeaponEffectData, new EffectOwnership(this, this))); + })); + Abilities.GrantAbilityPermanently(weaponHandToFlyingAbilityData, 1, LevelComparison.None, this); } - public void FlyingStarted() + public void GrantNewAbilityForWeaponFly(RExplodingSword ability) { - RaiseWeaponFlyingTickEvent(); - WeaponFlyingTick.Start(); - } - - public void FlyingEnded() - { - WeaponFlyingTick.Stop(); + var weaponFlyingAbilityData = new AbilityData( + name: "WeaponFlyingSwordAbility", + abilityTags: WeaponFlyingAbilityTag.GetSingleTagContainer(), + instancingPolicy: AbilityInstancingPolicy.PerEntity, + abilityTriggerData: AbilityTriggerData.ForEvent(WeaponFlyingTickEventTag), + behaviorFactory: () => ability.Behavior(new ExplodingSwordCreation(this))); + + var weaponFlyGrantAbilityConfig = new GrantAbilityConfig( + weaponFlyingAbilityData, + ScalableLevel: new ScalableInt(1), + RemovalPolicy: AbilityDeactivationPolicy.CancelImmediately, + InhibitionPolicy: AbilityDeactivationPolicy.CancelImmediately, + TryActivateOnGrant: false, + TryActivateOnEnable: false, + LevelOverridePolicy: LevelComparison.Higher); + + var weaponFlyGrantComponent = new GrantAbilityEffectComponent([weaponFlyGrantAbilityConfig]); + var weaponFlyGrantEffect = new EffectData( + "Grant Weapon Fly Ability", + new DurationData(DurationType.Infinite), + effectComponents: [weaponFlyGrantComponent]); + EffectsManager.ApplyEffect(new Effect(weaponFlyGrantEffect, new EffectOwnership(this, this))); + + GD.Print("New weapon flight ability granted"); } public void WeaponLeft() @@ -145,9 +328,6 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity public void ThrowWeapon(Vector3 end, bool hasHit, Vector3 collisionLocation, Vector3 collisionNormal, Node collidedObject) { _weaponState.SendEvent("throw"); - RaiseWeaponLeftEvent(); - - // WeaponLocationIndicatorMaterial.StencilColor = new Color(1f, 1f, 1f); _throwDirection = (end - GlobalPosition).Normalized(); PlantLocation = collisionLocation; @@ -165,48 +345,14 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity tween.Finished += ThrowWeaponOnCurve; } - public void RaiseWeaponLandEvent(IForgeEntity? victim = null) - { - Events.Raise(new EventData - { - EventTags = WeaponLandTag.GetSingleTagContainer(), - Source = this, - Target = victim, - EventMagnitude = 25f, - Payload = new WeaponLandPayload() - }); - } - - public void RaiseWeaponLeftEvent() - { - Events.Raise(new EventData - { - EventTags = WeaponLeftTag.GetSingleTagContainer(), - Source = this, - EventMagnitude = 25f, - Payload = new WeaponLeftPayload() - }); - } - - - public void RaiseWeaponFlyingTickEvent() - { - Events.Raise(new EventData - { - EventTags = WeaponFlyingTickTag.GetSingleTagContainer(), - Source = this, - EventMagnitude = 12f, - Payload = new WeaponFlyingPayload(Message: "flying") - }); - } - + private IForgeEntity? _plantedEntity; public void PlantInEnemy(Node3D enemy) { GetTree().GetRoot().CallDeferred(Node.MethodName.RemoveChild, this); enemy.CallDeferred(Node.MethodName.AddChild, this); - if (enemy is IForgeEntity victim) RaiseWeaponLandEvent(victim); - else RaiseWeaponLandEvent(); + if (enemy is IForgeEntity victim) _plantedEntity = victim; + else _plantedEntity = null; if (enemy is IDamageable damageable) { @@ -217,7 +363,6 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity public void RethrowWeapon() { _weaponState.SendEvent("throw"); - RaiseWeaponLeftEvent(); _throwDirection = Vector3.Up; ThrowWeaponOnCurve(); @@ -231,17 +376,14 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity public void PlantWeaponInWall() { - _weaponState.SendEvent("plant"); - Freeze = true; WeaponMesh.Rotation = _startMeshRotation; // WeaponLocationIndicatorMaterial.StencilColor = new Color(1f, 0.2f, 0.2f); if (PlantObject is Node3D node) - { PlantInEnemy(node); - } - else RaiseWeaponLandEvent(); + + _weaponState.SendEvent("plant"); CallDeferred(Node3D.MethodName.SetGlobalPosition, PlantLocation); CallDeferred(Node3D.MethodName.LookAt, GlobalTransform.Origin + PlantNormal, Vector3.Up, true); diff --git a/scenes/player_controller/scripts/PlayerController.cs b/scenes/player_controller/scripts/PlayerController.cs index abfbeb86..09937c67 100644 --- a/scenes/player_controller/scripts/PlayerController.cs +++ b/scenes/player_controller/scripts/PlayerController.cs @@ -113,7 +113,7 @@ public partial class PlayerController : CharacterBody3D, [ExportGroup("Abilities")] [ExportSubgroup("WeaponThrow")] - [Export] public RAbilityBase[] AbilityLoadout = []; + [Export] public RExplodingSword[] AbilityLoadout = []; // Combat stuff [ExportCategory("Combat")] @@ -712,93 +712,49 @@ public partial class PlayerController : CharacterBody3D, foreach (var weaponLandAbility in AbilityLoadout) { - // var weaponLeftTag = Tag.RequestTag(tagsManager,"abilities.weapon.left").GetSingleTagContainer(); - // var leftGrantAbilityConfig = new GrantAbilityConfig( - // weaponLandAbility.Ability(tagsManager, weaponLeftTag, WeaponSystem), - // ScalableLevel: new ScalableInt(1), - // RemovalPolicy: AbilityDeactivationPolicy.CancelImmediately, - // InhibitionPolicy: AbilityDeactivationPolicy.CancelImmediately, - // TryActivateOnGrant: false, - // TryActivateOnEnable: false, - // LevelOverridePolicy: LevelComparison.Higher); - // - // var leftGrantComponent = new GrantAbilityEffectComponent([leftGrantAbilityConfig]); - // var leftGrantEffect = new EffectData( - // "Grant Weapon Left Ability", - // new DurationData(DurationType.Infinite), - // effectComponents: [leftGrantComponent]); - // EffectsManager.ApplyEffect(new Effect(leftGrantEffect, new EffectOwnership(this, this))); - // - // var weaponLandedTag = Tag.RequestTag(tagsManager, "abilities.weapon.land").GetSingleTagContainer(); - // var landGrantAbilityConfig = new GrantAbilityConfig( - // weaponLandAbility.Ability(tagsManager, weaponLandedTag, WeaponSystem), - // ScalableLevel: new ScalableInt(1), - // RemovalPolicy: AbilityDeactivationPolicy.CancelImmediately, - // InhibitionPolicy: AbilityDeactivationPolicy.CancelImmediately, - // TryActivateOnGrant: false, - // TryActivateOnEnable: false, - // LevelOverridePolicy: LevelComparison.Higher); - // - // var landGrantComponent = new GrantAbilityEffectComponent([landGrantAbilityConfig]); - // var landGrantEffect = new EffectData( - // "Grant Weapon Land Ability", - // new DurationData(DurationType.Infinite), - // effectComponents: [landGrantComponent]); - // EffectsManager.ApplyEffect(new Effect(landGrantEffect, new EffectOwnership(this, this))); - // - ////////////////////////////////////////////// - - var weaponFlyingTag = Tag.RequestTag(tagsManager,"abilities.weapon.flying").GetSingleTagContainer(); - var weaponFlyingAbilityData = new AbilityData( - name: "Exploding Flying Sword", - abilityTags: weaponFlyingTag, - instancingPolicy: AbilityInstancingPolicy.PerEntity, - abilityTriggerData: AbilityTriggerData.ForEvent(WeaponSystem.WeaponFlyingTickTag), - behaviorFactory: () => new ExplodingSwordThrowBehavior(WeaponSystem, Explosion)); - - var flyingGrantAbilityConfig = new GrantAbilityConfig( - weaponFlyingAbilityData, + var weaponLeftTag = Tag.RequestTag(tagsManager,"abilities.weapon.left").GetSingleTagContainer(); + var leftGrantAbilityConfig = new GrantAbilityConfig( + weaponLandAbility.Ability(new ExplodingSwordCreation(WeaponSystem), weaponLeftTag), ScalableLevel: new ScalableInt(1), RemovalPolicy: AbilityDeactivationPolicy.CancelImmediately, InhibitionPolicy: AbilityDeactivationPolicy.CancelImmediately, TryActivateOnGrant: false, - TryActivateOnEnable: true, + TryActivateOnEnable: false, LevelOverridePolicy: LevelComparison.Higher); - var flyingGrantComponent = new GrantAbilityEffectComponent([flyingGrantAbilityConfig]); - var flyingGrantEffect = new EffectData( - "Grant Weapon Flying Ability", + var leftGrantComponent = new GrantAbilityEffectComponent([leftGrantAbilityConfig]); + var leftGrantEffect = new EffectData( + "Grant Weapon Left Ability", new DurationData(DurationType.Infinite), - effectComponents: [flyingGrantComponent] - ); + effectComponents: [leftGrantComponent]); + EffectsManager.ApplyEffect(new Effect(leftGrantEffect, new EffectOwnership(this, this))); - EffectsManager.ApplyEffect(new Effect(flyingGrantEffect, new EffectOwnership(this, this))); - - flyingWeaponEffect = new EffectData( - "Flying Weapon", + var weaponLandedTag = Tag.RequestTag(tagsManager, "abilities.weapon.land").GetSingleTagContainer(); + var landGrantAbilityConfig = new GrantAbilityConfig( + weaponLandAbility.Ability(new ExplodingSwordCreation(WeaponSystem), weaponLandedTag), + ScalableLevel: new ScalableInt(1), + RemovalPolicy: AbilityDeactivationPolicy.CancelImmediately, + InhibitionPolicy: AbilityDeactivationPolicy.CancelImmediately, + TryActivateOnGrant: false, + TryActivateOnEnable: false, + LevelOverridePolicy: LevelComparison.Higher); + + var landGrantComponent = new GrantAbilityEffectComponent([landGrantAbilityConfig]); + var landGrantEffect = new EffectData( + "Grant Weapon Land Ability", new DurationData(DurationType.Infinite), - customExecutions: - [ - new FlyingWeaponExecution(WeaponSystem) - ], - periodicData: new PeriodicData(new ScalableFloat(1f), false, PeriodInhibitionRemovedPolicy.ResetPeriod) - ); - flyingWeaponEffectHandle = EffectsManager.ApplyEffect(new Effect(flyingWeaponEffect, new EffectOwnership(this, this))); - flyingWeaponEffectHandle?.SetInhibit(true); + effectComponents: [landGrantComponent]); + EffectsManager.ApplyEffect(new Effect(landGrantEffect, new EffectOwnership(this, this))); + + GetTree().CreateTimer(5).Timeout += () => WeaponSystem.GrantNewAbilityForWeaponFly(weaponLandAbility); } // Forge events - var weaponLeftToken = WeaponSystem.Events.Subscribe(WeaponSystem.WeaponLeftTag, OnWeaponLeft); - var weaponFlyingToken = WeaponSystem.Events.Subscribe(WeaponSystem.WeaponFlyingTickTag, data => Events.Raise(data)); - var weaponLandedToken = WeaponSystem.Events.Subscribe(WeaponSystem.WeaponLandTag, OnWeaponLanded); + var weaponLeftToken = WeaponSystem.Events.Subscribe(WeaponSystem.WeaponStartedFlyingEventTag, OnWeaponLeft); + var weaponLandedToken = WeaponSystem.Events.Subscribe(WeaponSystem.WeaponStoppedFlyingEventTag, OnWeaponLanded); } - private EffectData flyingWeaponEffect; - private ActiveEffectHandle? flyingWeaponEffectHandle; - - public void OnWeaponLeft(EventData data) + public void OnWeaponLeft(EventData data) { - //flyingWeaponEffectHandle?.SetInhibit(false); - var target = data.Target; var tagsManager = ForgeManager.GetTagsManager(this); @@ -807,10 +763,8 @@ public partial class PlayerController : CharacterBody3D, Abilities.TryActivateAbilitiesByTag(weaponLeftTag, target, out var landedFailures); } - public void OnWeaponLanded(EventData data) + public void OnWeaponLanded(EventData data) { - flyingWeaponEffectHandle?.SetInhibit(true); - var source = data.Source; var target = data.Target; var magnitude = data.EventMagnitude;