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()
|
||||
{
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
|
||||
[ext_resource type="Script" uid="uid://iii3wfto4t5b" path="res://scenes/player_controller/components/weapon/WeaponSystem.cs" id="1_csqwk"]
|
||||
[ext_resource type="Script" uid="uid://jitubgv6judn" path="res://scenes/components/damage/RDamage.cs" id="2_m0v1h"]
|
||||
[ext_resource type="Resource" uid="uid://cu0685gspk2fk" path="res://scenes/player_controller/resources/forge/exploding_sword_weapon_land.tres" id="2_pgbtr"]
|
||||
[ext_resource type="Script" uid="uid://cxihb42t2mfqi" path="res://addons/forge/nodes/ForgeAttributeSet.cs" id="3_3xjpi"]
|
||||
[ext_resource type="Script" uid="uid://couw105c3bde4" path="res://addons/godot_state_charts/state_chart.gd" id="3_5owyf"]
|
||||
[ext_resource type="Resource" uid="uid://busdbvfi3jiic" path="res://scenes/player_controller/resources/forge/exploding_sword_weapon_left.tres" id="3_7bruw"]
|
||||
[ext_resource type="ArrayMesh" uid="uid://cho5fixitrbds" path="res://assets/meshes/swords/resources/sword23.tres" id="3_svc06"]
|
||||
[ext_resource type="Resource" uid="uid://btnnpqann3ktp" path="res://scenes/player_controller/resources/forge/weapon_flying_tick_ability.tres" id="4_7bruw"]
|
||||
[ext_resource type="Script" uid="uid://ccovd5i0wr3kk" path="res://addons/forge/editor/attributes/AttributeValues.cs" id="4_q6xv7"]
|
||||
[ext_resource type="Script" uid="uid://jk2jm1g6q853" path="res://addons/godot_state_charts/compound_state.gd" id="4_svc06"]
|
||||
[ext_resource type="Script" uid="uid://cytafq8i1y8qm" path="res://addons/godot_state_charts/atomic_state.gd" id="5_m0v1h"]
|
||||
@@ -56,6 +59,8 @@ continuous_cd = true
|
||||
contact_monitor = true
|
||||
max_contacts_reported = 1
|
||||
script = ExtResource("1_csqwk")
|
||||
WeaponAbilities = [ExtResource("2_pgbtr"), ExtResource("3_7bruw")]
|
||||
FlyingTickAbility = ExtResource("4_7bruw")
|
||||
RDamage = SubResource("Resource_jpdh0")
|
||||
|
||||
[node name="WeaponAttributeSet" type="Node" parent="." unique_id=14845649]
|
||||
|
||||
Reference in New Issue
Block a user