Moved the exploding sword forge object from the code only hardcoded stuff to the resource based stuff
This commit is contained in:
@@ -13,6 +13,7 @@ using Gamesmiths.Forge.Events;
|
||||
using Gamesmiths.Forge.Godot.Core;
|
||||
using Gamesmiths.Forge.Godot.Nodes;
|
||||
using Gamesmiths.Forge.Godot.Resources;
|
||||
using Gamesmiths.Forge.Godot.Resources.Abilities;
|
||||
using Gamesmiths.Forge.Tags;
|
||||
using Godot;
|
||||
using GodotStateCharts;
|
||||
@@ -26,20 +27,6 @@ using Movementtests.tools.calculators;
|
||||
|
||||
namespace Movementtests.systems;
|
||||
|
||||
public record struct WeaponEventPayload(String Message);
|
||||
|
||||
|
||||
public class ClosureBehavior<TPayload>(
|
||||
Action<AbilityBehaviorContext, TPayload> callback) : IAbilityBehavior<TPayload>
|
||||
{
|
||||
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
|
||||
@@ -50,9 +37,10 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
[Signal]
|
||||
public delegate void WeaponRetrievedEventHandler();
|
||||
|
||||
|
||||
[Export]
|
||||
public ForgeTagContainer BaseTags { get; set; } = new();
|
||||
[Export] public ForgeAbilityData[] WeaponAbilities { get; set; } = Array.Empty<ForgeAbilityData>();
|
||||
[Export] public ForgeAbilityData FlyingTickAbility { get; set; } = new();
|
||||
|
||||
[Export]
|
||||
public RDamage RDamage { get; set; }
|
||||
@@ -107,6 +95,8 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
|
||||
public Tag WeaponFlyingAbilityTag;
|
||||
|
||||
private AbilityHandle? _weaponFlyingAbility;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
_weaponState = StateChart.Of(GetNode("StateChart"));
|
||||
@@ -171,7 +161,27 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
Abilities = new(this);
|
||||
Events = new();
|
||||
|
||||
CreateFlyingAbility();
|
||||
// TODO: Waiting on bug resolve
|
||||
// _weaponFlyingAbility = Abilities.GrantAbilityPermanently(FlyingTickAbility.GetAbilityData(), 1, LevelComparison.None, this);
|
||||
|
||||
foreach (var ability in WeaponAbilities)
|
||||
{
|
||||
var leftGrantAbilityConfig = new GrantAbilityConfig(
|
||||
ability.GetAbilityData(),
|
||||
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 Ability",
|
||||
new DurationData(DurationType.Infinite),
|
||||
effectComponents: [leftGrantComponent]);
|
||||
EffectsManager.ApplyEffect(new Effect(leftGrantEffect, new EffectOwnership(this, this)));
|
||||
}
|
||||
|
||||
BodyEntered += OnThrownWeaponReachesGround;
|
||||
|
||||
@@ -180,136 +190,76 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
|
||||
_handToFlying.Taken += () =>
|
||||
{
|
||||
Events.Raise(new EventData<WeaponEventPayload>
|
||||
Events.Raise(new EventData
|
||||
{
|
||||
EventTags = WeaponHandToFlyingEventTag.GetSingleTagContainer()!,
|
||||
Source = this,
|
||||
Payload = new WeaponEventPayload(Message: "handToFlying")
|
||||
Source = this
|
||||
});
|
||||
Events.Raise(new EventData<WeaponEventPayload>
|
||||
Events.Raise(new EventData
|
||||
{
|
||||
EventTags = WeaponStartedFlyingEventTag.GetSingleTagContainer()!,
|
||||
Source = this,
|
||||
Payload = new WeaponEventPayload(Message: "startedFlying")
|
||||
Source = this
|
||||
});
|
||||
};
|
||||
|
||||
_flyingToHand.Taken += () =>
|
||||
{
|
||||
Events.Raise(new EventData<WeaponEventPayload>
|
||||
Events.Raise(new EventData
|
||||
{
|
||||
EventTags = WeaponFlyingToHandEventTag.GetSingleTagContainer()!,
|
||||
Source = this,
|
||||
Payload = new WeaponEventPayload(Message: "flyingToHand")
|
||||
Source = this
|
||||
});
|
||||
Events.Raise(new EventData<WeaponEventPayload>
|
||||
Events.Raise(new EventData
|
||||
{
|
||||
EventTags = WeaponStoppedFlyingEventTag.GetSingleTagContainer()!,
|
||||
Source = this,
|
||||
Payload = new WeaponEventPayload(Message: "stoppedFlying")
|
||||
Source = this
|
||||
});
|
||||
};
|
||||
|
||||
_plantedToHand.Taken += () =>
|
||||
{
|
||||
Events.Raise(new EventData<WeaponEventPayload>
|
||||
Events.Raise(new EventData
|
||||
{
|
||||
EventTags = WeaponPlantedToHandEventTag.GetSingleTagContainer()!,
|
||||
Source = this,
|
||||
Payload = new WeaponEventPayload(Message: "plantedToHand")
|
||||
Source = this
|
||||
});
|
||||
};
|
||||
|
||||
_plantedToFlying.Taken += () =>
|
||||
{
|
||||
Events.Raise(new EventData<WeaponEventPayload>
|
||||
Events.Raise(new EventData
|
||||
{
|
||||
EventTags = WeaponPlantedToFlyingEventTag.GetSingleTagContainer()!,
|
||||
Source = this,
|
||||
Payload = new WeaponEventPayload(Message: "plantedToFlying")
|
||||
Source = this
|
||||
});
|
||||
Events.Raise(new EventData<WeaponEventPayload>
|
||||
Events.Raise(new EventData
|
||||
{
|
||||
EventTags = WeaponStartedFlyingEventTag.GetSingleTagContainer()!,
|
||||
Source = this,
|
||||
Payload = new WeaponEventPayload(Message: "startedFlying")
|
||||
Source = this
|
||||
});
|
||||
};
|
||||
|
||||
_toPlanted.Taken += () =>
|
||||
{
|
||||
Events.Raise(new EventData<WeaponEventPayload>
|
||||
Events.Raise(new EventData
|
||||
{
|
||||
EventTags = WeaponPlantedEventTag.GetSingleTagContainer()!,
|
||||
Source = this,
|
||||
Target = _plantedEntity,
|
||||
Payload = new WeaponEventPayload(Message: "planted")
|
||||
Target = _plantedEntity
|
||||
});
|
||||
Events.Raise(new EventData<WeaponEventPayload>
|
||||
Events.Raise(new EventData
|
||||
{
|
||||
EventTags = WeaponStoppedFlyingEventTag.GetSingleTagContainer()!,
|
||||
Source = this,
|
||||
Payload = new WeaponEventPayload(Message: "stoppedFlying")
|
||||
Source = this
|
||||
});
|
||||
};
|
||||
|
||||
Events.Subscribe<WeaponEventPayload>(WeaponStoppedFlyingEventTag, data =>
|
||||
Events.Subscribe(WeaponStoppedFlyingEventTag, data =>
|
||||
{
|
||||
_weaponFlyingAbility.Cancel();
|
||||
// TODO: Waiting on bug resolve
|
||||
// _weaponFlyingAbility.Cancel();
|
||||
});
|
||||
}
|
||||
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<WeaponEventPayload>(WeaponStartedFlyingEventTag),
|
||||
behaviorFactory: () => new FlyingSwordBehavior(this, flyingWeaponEffectData));
|
||||
_weaponFlyingAbility = Abilities.GrantAbilityPermanently(weaponHandToFlyingAbilityData, 1, LevelComparison.None, this);
|
||||
}
|
||||
|
||||
private AbilityHandle _weaponFlyingAbility;
|
||||
|
||||
public void GrantNewAbilityForWeaponFly(RExplodingSword ability)
|
||||
{
|
||||
var weaponFlyingAbilityData = new AbilityData(
|
||||
name: "WeaponFlyingSwordAbility",
|
||||
abilityTags: WeaponFlyingAbilityTag.GetSingleTagContainer(),
|
||||
instancingPolicy: AbilityInstancingPolicy.PerEntity,
|
||||
abilityTriggerData: AbilityTriggerData.ForEvent<WeaponEventPayload>(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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user