diff --git a/forge/forge_data.tres b/forge/forge_data.tres index a9c1254c..f59d6d03 100644 --- a/forge/forge_data.tres +++ b/forge/forge_data.tres @@ -4,4 +4,4 @@ [resource] script = ExtResource("1_l686n") -RegisteredTags = Array[String](["character.player", "character.enemy", "weapon", "status.stunned", "status.burning", "status.frozen", "abilities.weapon.land", "abilities.weapon.flying", "abilities.weapon.left", "events.combat.damage", "events.combat.hit", "events.weapon.flyingTick", "events.weapon.startedFlying", "events.weapon.stoppedFlying", "events.weapon.handToFlying", "events.weapon.flyingToHand", "events.weapon.plantedToHand", "events.weapon.plantedToFlying", "events.weapon.planted", "cooldown.empoweredAction", "cooldown.empoweredSwordThrow", "cues.resources.mana", "events.player.empowered_action_used", "cues.resources.mana.inhibited", "cues.resources.health", "cooldown.enemy.hit", "events.combat.death", "cooldown.hit", "events.player.hit", "cues.enemy.health", "immunity.damage", "status", "traits.damageable", "traits.knockbackable", "events.combat.knockback_dealt", "events.combat.knockback_received"]) +RegisteredTags = Array[String](["character.player", "character.enemy", "weapon", "status.stunned", "status.burning", "status.frozen", "abilities.weapon.land", "abilities.weapon.flying", "abilities.weapon.left", "events.combat.damage", "events.combat.hit", "events.weapon.flyingTick", "events.weapon.startedFlying", "events.weapon.stoppedFlying", "events.weapon.handToFlying", "events.weapon.flyingToHand", "events.weapon.plantedToHand", "events.weapon.plantedToFlying", "events.weapon.planted", "cooldown.empoweredAction", "cooldown.empoweredSwordThrow", "cues.resources.mana", "events.player.empowered_action_used", "cues.resources.mana.inhibited", "cues.resources.health", "cooldown.enemy.hit", "events.combat.death", "cooldown.hit", "events.player.hit", "cues.enemy.health", "immunity.damage", "status", "traits.damageable", "traits.knockbackable", "events.combat.knockback_dealt", "events.combat.knockback_received", "events.weapon.plantedtick", "events.weapon.unplanted", "abilities.weapon.planted"]) diff --git a/forge/resources/ability_datas/player_hit.tres b/forge/resources/ability_datas/player_hit.tres index 3fa1eae2..36e73285 100644 --- a/forge/resources/ability_datas/player_hit.tres +++ b/forge/resources/ability_datas/player_hit.tres @@ -1,78 +1,18 @@ [gd_resource type="Resource" script_class="ForgeAbilityData" format=3 uid="uid://dgjsi1my7nlnk"] +[ext_resource type="Resource" uid="uid://bn1getr10b4dx" path="res://forge/resources/effect_datas/simple_player_hit.tres" id="1_c4wry"] [ext_resource type="Script" uid="uid://1hgogislo1l6" path="res://addons/forge/resources/magnitudes/ForgeScalableInt.cs" id="1_l0l1a"] [ext_resource type="Script" uid="uid://n6efm5o4uxvr" path="res://forge/abilities/ForgeSimpleHitBehavior.cs" id="1_n2s8d"] -[ext_resource type="Resource" uid="uid://bpovqvlqv5bs5" path="res://forge/resources/effect_components/damageable.tres" id="1_r7waw"] [ext_resource type="Script" uid="uid://cw525n4mjqgw0" path="res://addons/forge/resources/ForgeTagContainer.cs" id="1_w1wo0"] [ext_resource type="Script" uid="uid://b83hf13nj37k3" path="res://addons/forge/resources/ForgeEffectData.cs" id="2_5vjbv"] [ext_resource type="Script" uid="uid://dngf30hxy5go4" path="res://addons/forge/resources/components/ModifierTags.cs" id="2_jwyed"] -[ext_resource type="Resource" uid="uid://4rkwr10pc6tp" path="res://forge/resources/custom_executions/physical_damage_calculator.tres" id="2_l5emy"] -[ext_resource type="Script" uid="uid://bdfcavbjyhxxa" path="res://addons/forge/resources/ForgeModifier.cs" id="3_c4wry"] -[ext_resource type="Resource" uid="uid://cc1qrmbp12fk8" path="res://forge/resources/custom_executions/player_hit_knoback_calculation.tres" id="3_l5emy"] [ext_resource type="Script" uid="uid://dhxfbxh54pyxp" path="res://addons/forge/resources/abilities/ForgeAbilityData.cs" id="3_w1wo0"] [ext_resource type="Script" uid="uid://cn3b4ya15fg7e" path="res://addons/forge/resources/magnitudes/ForgeScalableFloat.cs" id="4_c4wry"] [ext_resource type="Script" uid="uid://2gm1hdhi8u08" path="res://addons/forge/resources/magnitudes/ForgeModifierMagnitude.cs" id="5_0cyim"] -[sub_resource type="Resource" id="Resource_0cyim"] -script = ExtResource("1_l0l1a") -BaseValue = 1 - -[sub_resource type="Resource" id="Resource_h8gc3"] -script = ExtResource("4_c4wry") -BaseValue = 1.0 - -[sub_resource type="Resource" id="Resource_ewmvj"] -script = ExtResource("4_c4wry") - -[sub_resource type="Resource" id="Resource_8wvcn"] -script = ExtResource("4_c4wry") - -[sub_resource type="Resource" id="Resource_no8t2"] -script = ExtResource("4_c4wry") -BaseValue = 1.0 - -[sub_resource type="Resource" id="Resource_vioyh"] -script = ExtResource("4_c4wry") - -[sub_resource type="Resource" id="Resource_m6xnn"] -script = ExtResource("4_c4wry") - -[sub_resource type="Resource" id="Resource_uinv8"] -script = ExtResource("4_c4wry") -BaseValue = 40.0 -metadata/_custom_type_script = "uid://cn3b4ya15fg7e" - -[sub_resource type="Resource" id="Resource_04hqa"] -script = ExtResource("3_c4wry") -Attribute = "MetaAttributeSet.IncomingDamage" -Operation = 2 -ScalableFloat = SubResource("Resource_uinv8") -Coefficient = SubResource("Resource_no8t2") -PreMultiplyAdditiveValue = SubResource("Resource_m6xnn") -PostMultiplyAdditiveValue = SubResource("Resource_vioyh") -CalculatorCoefficient = SubResource("Resource_h8gc3") -CalculatorPreMultiplyAdditiveValue = SubResource("Resource_8wvcn") -CalculatorPostMultiplyAdditiveValue = SubResource("Resource_ewmvj") -metadata/_custom_type_script = "uid://bdfcavbjyhxxa" - -[sub_resource type="Resource" id="Resource_8fbeq"] -script = ExtResource("1_l0l1a") -BaseValue = 1 - -[sub_resource type="Resource" id="Resource_ees2v"] -script = ExtResource("2_5vjbv") -Name = "Player Hit Effect" -Modifiers = Array[Object]([SubResource("Resource_04hqa")]) -Components = Array[Object]([ExtResource("1_r7waw")]) -Executions = Array[Object]([ExtResource("2_l5emy"), ExtResource("3_l5emy")]) -StackLimit = SubResource("Resource_8fbeq") -InitialStack = SubResource("Resource_0cyim") -Cues = [] -metadata/_custom_type_script = "uid://b83hf13nj37k3" - [sub_resource type="Resource" id="Resource_r7waw"] script = ExtResource("1_n2s8d") -DamageEffect = SubResource("Resource_ees2v") +DamageEffect = ExtResource("1_c4wry") Name = "PlayerHitEffect" Description = "Effect applied to target on player hit" metadata/_custom_type_script = "uid://n6efm5o4uxvr" diff --git a/forge/resources/ability_datas/weapon_planted_tick_ability.tres b/forge/resources/ability_datas/weapon_planted_tick_ability.tres new file mode 100644 index 00000000..4609db2f --- /dev/null +++ b/forge/resources/ability_datas/weapon_planted_tick_ability.tres @@ -0,0 +1,63 @@ +[gd_resource type="Resource" script_class="ForgeAbilityData" format=3 uid="uid://0oo3na61ot1o"] + +[ext_resource type="Resource" uid="uid://bk3rv5jrutfjw" path="res://forge/resources/tag_containers/on_weapon_plantedtick.tres" id="1_4dvtr"] +[ext_resource type="Script" uid="uid://br7ut4lbau66w" path="res://forge/calculators/ForgeRaiseEventTagExecution.cs" id="2_oo2u8"] +[ext_resource type="Script" uid="uid://dpakv7agvir6y" path="res://addons/forge/resources/ForgeTag.cs" id="2_wolay"] +[ext_resource type="Script" uid="uid://1hgogislo1l6" path="res://addons/forge/resources/magnitudes/ForgeScalableInt.cs" id="3_cykp3"] +[ext_resource type="Script" uid="uid://dhxfbxh54pyxp" path="res://addons/forge/resources/abilities/ForgeAbilityData.cs" id="3_mqsqr"] +[ext_resource type="Script" uid="uid://b83hf13nj37k3" path="res://addons/forge/resources/ForgeEffectData.cs" id="4_4348y"] +[ext_resource type="Script" uid="uid://cn3b4ya15fg7e" path="res://addons/forge/resources/magnitudes/ForgeScalableFloat.cs" id="4_oo2u8"] +[ext_resource type="Script" uid="uid://cl5hudinl1rex" path="res://forge/abilities/ForgeEffectApplicationBehavior.cs" id="5_drdls"] + +[sub_resource type="Resource" id="Resource_l3tir"] +script = ExtResource("2_oo2u8") +EventTags = ExtResource("1_4dvtr") +metadata/_custom_type_script = "uid://br7ut4lbau66w" + +[sub_resource type="Resource" id="Resource_yc0gp"] +script = ExtResource("3_cykp3") +BaseValue = 1 + +[sub_resource type="Resource" id="Resource_cykp3"] +script = ExtResource("4_oo2u8") +BaseValue = 0.5 +metadata/_custom_type_script = "uid://cn3b4ya15fg7e" + +[sub_resource type="Resource" id="Resource_rvogu"] +script = ExtResource("3_cykp3") +BaseValue = 1 + +[sub_resource type="Resource" id="Resource_hgeae"] +script = ExtResource("4_4348y") +Name = "Raise Planted Tick Periodically" +Modifiers = null +Components = null +Executions = Array[Object]([SubResource("Resource_l3tir")]) +DurationType = 1 +HasPeriodicApplication = true +Period = SubResource("Resource_cykp3") +ExecuteOnApplication = true +StackLimit = SubResource("Resource_rvogu") +InitialStack = SubResource("Resource_yc0gp") +Cues = null +metadata/_custom_type_script = "uid://b83hf13nj37k3" + +[sub_resource type="Resource" id="Resource_jiqxq"] +script = ExtResource("5_drdls") +EffectData = SubResource("Resource_hgeae") +metadata/_custom_type_script = "uid://cl5hudinl1rex" + +[sub_resource type="Resource" id="Resource_4aw8y"] +script = ExtResource("2_wolay") +Tag = "events.weapon.planted" +metadata/_custom_type_script = "uid://dpakv7agvir6y" + +[resource] +script = ExtResource("3_mqsqr") +Name = "Weapon Planted Tick" +RetriggerInstancedAbility = true +CooldownEffects = [] +AbilityBehavior = SubResource("Resource_jiqxq") +TriggerSource = 1 +TriggerTag = SubResource("Resource_4aw8y") +metadata/_custom_type_script = "uid://dhxfbxh54pyxp" diff --git a/forge/resources/behaviors/flying tick application ability behavior.tres b/forge/resources/behaviors/flying tick application ability behavior.tres index aa069e07..ec7096fd 100644 --- a/forge/resources/behaviors/flying tick application ability behavior.tres +++ b/forge/resources/behaviors/flying tick application ability behavior.tres @@ -6,5 +6,5 @@ [resource] script = ExtResource("2_f5qgs") EffectData = ExtResource("1_hlq5f") -Name = "Flying tick application" +Name = "Planted tick application" metadata/_custom_type_script = "uid://cl5hudinl1rex" diff --git a/forge/resources/effect_datas/raise_flying_tick_event_periodically.tres b/forge/resources/effect_datas/raise_flying_tick_event_periodically.tres index 595f8047..f0161d88 100644 --- a/forge/resources/effect_datas/raise_flying_tick_event_periodically.tres +++ b/forge/resources/effect_datas/raise_flying_tick_event_periodically.tres @@ -20,7 +20,7 @@ BaseValue = 1 [resource] script = ExtResource("4_7ma6b") -Name = "Call Flying Tick Event Periodically" +Name = "Call Planted Tick Event Periodically" Modifiers = [] Components = [] Executions = Array[Object]([ExtResource("1_cd13a")]) diff --git a/forge/resources/effect_datas/simple_player_hit.tres b/forge/resources/effect_datas/simple_player_hit.tres new file mode 100644 index 00000000..1356f249 --- /dev/null +++ b/forge/resources/effect_datas/simple_player_hit.tres @@ -0,0 +1,66 @@ +[gd_resource type="Resource" script_class="ForgeEffectData" format=3 uid="uid://bn1getr10b4dx"] + +[ext_resource type="Resource" uid="uid://bpovqvlqv5bs5" path="res://forge/resources/effect_components/damageable.tres" id="1_uev3b"] +[ext_resource type="Resource" uid="uid://4rkwr10pc6tp" path="res://forge/resources/custom_executions/physical_damage_calculator.tres" id="2_o3goh"] +[ext_resource type="Resource" uid="uid://cc1qrmbp12fk8" path="res://forge/resources/custom_executions/player_hit_knoback_calculation.tres" id="3_bydif"] +[ext_resource type="Script" uid="uid://1hgogislo1l6" path="res://addons/forge/resources/magnitudes/ForgeScalableInt.cs" id="4_sd5hm"] +[ext_resource type="Script" uid="uid://cn3b4ya15fg7e" path="res://addons/forge/resources/magnitudes/ForgeScalableFloat.cs" id="5_l6rea"] +[ext_resource type="Script" uid="uid://bdfcavbjyhxxa" path="res://addons/forge/resources/ForgeModifier.cs" id="6_juqkp"] +[ext_resource type="Script" uid="uid://b83hf13nj37k3" path="res://addons/forge/resources/ForgeEffectData.cs" id="7_njbpb"] + +[sub_resource type="Resource" id="Resource_0cyim"] +script = ExtResource("4_sd5hm") +BaseValue = 1 + +[sub_resource type="Resource" id="Resource_h8gc3"] +script = ExtResource("5_l6rea") +BaseValue = 1.0 + +[sub_resource type="Resource" id="Resource_ewmvj"] +script = ExtResource("5_l6rea") + +[sub_resource type="Resource" id="Resource_8wvcn"] +script = ExtResource("5_l6rea") + +[sub_resource type="Resource" id="Resource_no8t2"] +script = ExtResource("5_l6rea") +BaseValue = 1.0 + +[sub_resource type="Resource" id="Resource_vioyh"] +script = ExtResource("5_l6rea") + +[sub_resource type="Resource" id="Resource_m6xnn"] +script = ExtResource("5_l6rea") + +[sub_resource type="Resource" id="Resource_uinv8"] +script = ExtResource("5_l6rea") +BaseValue = 40.0 +metadata/_custom_type_script = "uid://cn3b4ya15fg7e" + +[sub_resource type="Resource" id="Resource_04hqa"] +script = ExtResource("6_juqkp") +Attribute = "MetaAttributeSet.IncomingDamage" +Operation = 2 +ScalableFloat = SubResource("Resource_uinv8") +Coefficient = SubResource("Resource_no8t2") +PreMultiplyAdditiveValue = SubResource("Resource_m6xnn") +PostMultiplyAdditiveValue = SubResource("Resource_vioyh") +CalculatorCoefficient = SubResource("Resource_h8gc3") +CalculatorPreMultiplyAdditiveValue = SubResource("Resource_8wvcn") +CalculatorPostMultiplyAdditiveValue = SubResource("Resource_ewmvj") +metadata/_custom_type_script = "uid://bdfcavbjyhxxa" + +[sub_resource type="Resource" id="Resource_8fbeq"] +script = ExtResource("4_sd5hm") +BaseValue = 1 + +[resource] +script = ExtResource("7_njbpb") +Name = "Player Hit Effect" +Modifiers = Array[Object]([SubResource("Resource_04hqa")]) +Components = Array[Object]([ExtResource("1_uev3b")]) +Executions = Array[Object]([ExtResource("2_o3goh"), ExtResource("3_bydif")]) +StackLimit = SubResource("Resource_8fbeq") +InitialStack = SubResource("Resource_0cyim") +Cues = [] +metadata/_custom_type_script = "uid://b83hf13nj37k3" diff --git a/forge/resources/tag_containers/on_weapon_plantedtick.tres b/forge/resources/tag_containers/on_weapon_plantedtick.tres new file mode 100644 index 00000000..53674013 --- /dev/null +++ b/forge/resources/tag_containers/on_weapon_plantedtick.tres @@ -0,0 +1,8 @@ +[gd_resource type="Resource" script_class="ForgeTagContainer" format=3 uid="uid://bk3rv5jrutfjw"] + +[ext_resource type="Script" uid="uid://cw525n4mjqgw0" path="res://addons/forge/resources/ForgeTagContainer.cs" id="1_gt2iq"] + +[resource] +script = ExtResource("1_gt2iq") +ContainerTags = Array[String](["events.weapon.plantedtick"]) +metadata/_custom_type_script = "uid://cw525n4mjqgw0" diff --git a/managers/InventoryManager.cs b/managers/InventoryManager.cs index 4cd92d30..1c863168 100644 --- a/managers/InventoryManager.cs +++ b/managers/InventoryManager.cs @@ -9,59 +9,69 @@ using Movementtests.systems; namespace Movementtests.managers; -public partial class WeaponEventAbilityData(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior ability) - : RefCounted -{ - public WeaponSystem.WeaponEvent ForEvent { get; private set; } = forEvent; - public ForgeAbilityBehavior Ability { get; private set; } = ability; -} [GlobalClass, Meta(typeof(IAutoNode))] public partial class InventoryManager : Node, IDisposable { public override void _Notification(int what) => this.Notify(what); - #region Signals - - [Signal] - public delegate void WeaponEventAbilityAddedEventHandler(WeaponEventAbilityData data); - [Signal] - public delegate void WeaponEventAbilityRemovedEventHandler(WeaponEventAbilityData data); - - #endregion - private AutoSet _startedFlyingAbilities = new(); private AutoSet _flyingTickAbilities = new(); private AutoSet _stoppedFlyingAbilities = new(); + private AutoSet _startedPlantedAbilities = new(); + private AutoSet _plantedTickAbilities = new(); + private AutoSet _stoppedPlantedAbilities = new(); + public IAutoSet StartedFlyingAbilities => _startedFlyingAbilities; public IAutoSet FlyingTickAbilities => _flyingTickAbilities; public IAutoSet StoppedFlyingAbilities => _stoppedFlyingAbilities; + + public IAutoSet StartedPlantedAbilities => _startedPlantedAbilities; + public IAutoSet PlantedTickAbilities => _plantedTickAbilities; + public IAutoSet StoppedPlantedAbilities => _stoppedPlantedAbilities; private readonly AutoMap> _weaponEventsInventory = new(); public IAutoMap> WeaponEventsInventory => _weaponEventsInventory; + + public Dictionary> GetEventElements() + { + return new Dictionary> + { + { WeaponSystem.WeaponEvent.StartedFlying, _startedFlyingAbilities }, + { WeaponSystem.WeaponEvent.StoppedFlying, _stoppedFlyingAbilities}, + { WeaponSystem.WeaponEvent.FlyingTick, _flyingTickAbilities }, + + { WeaponSystem.WeaponEvent.StartedPlanted, _startedPlantedAbilities }, + { WeaponSystem.WeaponEvent.StoppedPlanted, _stoppedPlantedAbilities }, + { WeaponSystem.WeaponEvent.PlantedTick, _plantedTickAbilities }, + }; + } public void OnReady() { - _weaponEventsInventory[WeaponSystem.WeaponEvent.StartedFlying] = _startedFlyingAbilities; - _weaponEventsInventory[WeaponSystem.WeaponEvent.FlyingTick] = _flyingTickAbilities; - _weaponEventsInventory[WeaponSystem.WeaponEvent.StoppedFlying] = _stoppedFlyingAbilities; + foreach (var (forEvent, behaviorSet) in GetEventElements()) + { + _weaponEventsInventory[forEvent] = behaviorSet; + } } public void InitializeFromResource(WeaponInventory inventory) { - _startedFlyingAbilities = new AutoSet(inventory.OnWeaponStartedFlyingAbilities); - _flyingTickAbilities = new AutoSet(inventory.OnWeaponFlyingTickAbilities); - _stoppedFlyingAbilities = new AutoSet(inventory.OnWeaponStoppedFlyingAbilities); + var elements = GetEventElements(); + foreach (var forEvent in elements.Keys) + { + elements[forEvent] = new AutoSet(inventory.EventMap[forEvent]); + } } public new void Dispose() { GC.SuppressFinalize(this); - _startedFlyingAbilities.Dispose(); - _flyingTickAbilities.Dispose(); - _stoppedFlyingAbilities.Dispose(); + foreach (var element in GetEventElements().Values) + element.Dispose(); + _weaponEventsInventory.Dispose(); base.Dispose(); diff --git a/managers/WeaponInventory.cs b/managers/WeaponInventory.cs index cd6e851f..10704a64 100644 --- a/managers/WeaponInventory.cs +++ b/managers/WeaponInventory.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Gamesmiths.Forge.Godot.Resources.Abilities; using Godot; +using Movementtests.systems; namespace Movementtests.managers; @@ -8,15 +9,41 @@ namespace Movementtests.managers; public partial class WeaponInventory( ForgeAbilityBehavior[] onWeaponStartedFlyingAbilities, ForgeAbilityBehavior[] onWeaponFlyingTickAbilities, - ForgeAbilityBehavior[] onWeaponStoppedFlyingAbilities + ForgeAbilityBehavior[] onWeaponStoppedFlyingAbilities, + ForgeAbilityBehavior[] onWeaponStartedPlantedAbilities, + ForgeAbilityBehavior[] onWeaponPlantedTickAbilities, + ForgeAbilityBehavior[] onWeaponStoppedPlantedAbilities ) : Resource { + [ExportGroup("Flying abilities")] [Export] public ForgeAbilityBehavior[] OnWeaponStartedFlyingAbilities { get; set; } = onWeaponStartedFlyingAbilities; [Export] public ForgeAbilityBehavior[] OnWeaponFlyingTickAbilities { get; set; } = onWeaponFlyingTickAbilities; [Export] public ForgeAbilityBehavior[] OnWeaponStoppedFlyingAbilities { get; set; } = onWeaponStoppedFlyingAbilities; + + [ExportGroup("Planted abilities")] + [Export] + public ForgeAbilityBehavior[] OnWeaponStartedPlantedAbilities { get; set; } = onWeaponStartedPlantedAbilities; + [Export] + public ForgeAbilityBehavior[] OnWeaponPlantedTickAbilities { get; set; } = onWeaponPlantedTickAbilities; + [Export] + public ForgeAbilityBehavior[] OnWeaponStoppedPlantedAbilities { get; set; } = onWeaponStoppedPlantedAbilities; - public WeaponInventory() : this([], [], []) {} + public Dictionary EventMap { get; private set; } = []; + + public WeaponInventory() : this([], [], [], [], [], []) + { + EventMap = new Dictionary + { + { WeaponSystem.WeaponEvent.StartedFlying, OnWeaponStartedFlyingAbilities }, + { WeaponSystem.WeaponEvent.StoppedFlying, OnWeaponStoppedFlyingAbilities }, + { WeaponSystem.WeaponEvent.FlyingTick, OnWeaponFlyingTickAbilities }, + + { WeaponSystem.WeaponEvent.StartedPlanted, OnWeaponStartedPlantedAbilities }, + { WeaponSystem.WeaponEvent.StoppedPlanted, OnWeaponStoppedPlantedAbilities }, + { WeaponSystem.WeaponEvent.PlantedTick, OnWeaponPlantedTickAbilities }, + }; + } } \ No newline at end of file diff --git a/menus/scenes/overlaid_menus/InventoryUi.cs b/menus/scenes/overlaid_menus/InventoryUi.cs index 8aa95fb5..187bc72e 100644 --- a/menus/scenes/overlaid_menus/InventoryUi.cs +++ b/menus/scenes/overlaid_menus/InventoryUi.cs @@ -14,6 +14,11 @@ using Movementtests.systems; public partial class InventoryUi : Control, IDisposable { public override void _Notification(int what) => this.Notify(what); + + public record struct EventElements( + AbilitySelection AbilitySelection, + AutoSet.Binding Binding, + IAutoSet Inventory); #region Dependencies [Dependency] @@ -27,53 +32,67 @@ public partial class InventoryUi : Control, IDisposable public required AbilitySelection WhileFlying { get; set; } [Node] public required AbilitySelection StoppedFlying { get; set; } + + [Node] + public required AbilitySelection StartedPlanted { get; set; } + [Node] + public required AbilitySelection WhilePlanted { get; set; } + [Node] + public required AbilitySelection StoppedPlanted { get; set; } #endregion Nodes - public AutoSet.Binding StartedFlyingBinding { get; set; } - public AutoSet.Binding FlyingTickBinding { get; set; } - public AutoSet.Binding StoppedFlyingBinding { get; set; } + public required AutoSet.Binding StartedFlyingBinding { get; set; } + public required AutoSet.Binding FlyingTickBinding { get; set; } + public required AutoSet.Binding StoppedFlyingBinding { get; set; } + + public required AutoSet.Binding StartedPlantedBinding { get; set; } + public required AutoSet.Binding PlantedTickBinding { get; set; } + public required AutoSet.Binding StoppedPlantedBinding { get; set; } + + public Dictionary EventElementsMap { get; private set; } = []; public void OnReady() { - StartedFlying.AbilityAdded += AddAbilityForEvent; - WhileFlying.AbilityAdded += AddAbilityForEvent; - StoppedFlying.AbilityAdded += AddAbilityForEvent; - - StartedFlying.AbilityRemoved += RemoveAbilityForEvent; - WhileFlying.AbilityRemoved += RemoveAbilityForEvent; - StoppedFlying.AbilityRemoved += RemoveAbilityForEvent; } public void OnResolved() { - StartedFlying.Initialize(InventoryManager.WeaponEventsInventory[WeaponSystem.WeaponEvent.StartedFlying]); - WhileFlying.Initialize(InventoryManager.WeaponEventsInventory[WeaponSystem.WeaponEvent.FlyingTick]); - StoppedFlying.Initialize(InventoryManager.WeaponEventsInventory[WeaponSystem.WeaponEvent.StoppedFlying]); + EventElementsMap = new Dictionary + { + { WeaponSystem.WeaponEvent.StartedFlying, new EventElements(StartedFlying, StartedFlyingBinding, InventoryManager.StartedFlyingAbilities) }, + { WeaponSystem.WeaponEvent.StoppedFlying, new EventElements(StoppedFlying, StoppedFlyingBinding, InventoryManager.StoppedFlyingAbilities)}, + { WeaponSystem.WeaponEvent.FlyingTick, new EventElements(WhileFlying, FlyingTickBinding, InventoryManager.FlyingTickAbilities) }, + + { WeaponSystem.WeaponEvent.StartedPlanted, new EventElements(StartedPlanted, StartedPlantedBinding, InventoryManager.StartedPlantedAbilities) }, + { WeaponSystem.WeaponEvent.StoppedPlanted, new EventElements(StoppedPlanted, StoppedPlantedBinding, InventoryManager.StoppedPlantedAbilities) }, + { WeaponSystem.WeaponEvent.PlantedTick, new EventElements(WhilePlanted, PlantedTickBinding, InventoryManager.PlantedTickAbilities) }, + }; - StartedFlyingBinding = InventoryManager.StartedFlyingAbilities.Bind(); - StartedFlyingBinding - .OnAdd(behavior => OnWeaponEventInventoryAdded(WeaponSystem.WeaponEvent.StartedFlying, behavior)) - .OnRemove(behavior => OnWeaponEventInventoryRemoved(WeaponSystem.WeaponEvent.StartedFlying, behavior)) - .OnClear(() => OnWeaponEventInventoryCleared(WeaponSystem.WeaponEvent.StartedFlying)); - FlyingTickBinding = InventoryManager.FlyingTickAbilities.Bind(); - FlyingTickBinding - .OnAdd(behavior => OnWeaponEventInventoryAdded(WeaponSystem.WeaponEvent.FlyingTick, behavior)) - .OnRemove(behavior => OnWeaponEventInventoryRemoved(WeaponSystem.WeaponEvent.FlyingTick, behavior)) - .OnClear(() => OnWeaponEventInventoryCleared(WeaponSystem.WeaponEvent.FlyingTick)); - StoppedFlyingBinding = InventoryManager.StoppedFlyingAbilities.Bind(); - StoppedFlyingBinding - .OnAdd(behavior => OnWeaponEventInventoryAdded(WeaponSystem.WeaponEvent.StoppedFlying, behavior)) - .OnRemove(behavior => OnWeaponEventInventoryRemoved(WeaponSystem.WeaponEvent.StoppedFlying, behavior)) - .OnClear(() => OnWeaponEventInventoryCleared(WeaponSystem.WeaponEvent.StoppedFlying)); + foreach (var (forEvent, element) in EventElementsMap) + { + element.AbilitySelection.AbilityAdded += AddAbilityForEvent; + element.AbilitySelection.AbilityRemoved += RemoveAbilityForEvent; + + var elem = EventElementsMap[forEvent]; + elem.AbilitySelection.Initialize(InventoryManager.WeaponEventsInventory[forEvent]); + elem.Binding = element.Inventory.Bind(); + elem.Binding + .OnAdd(behavior => OnWeaponEventInventoryAdded(forEvent, behavior)) + .OnRemove(behavior => OnWeaponEventInventoryRemoved(forEvent, behavior)) + .OnClear(() => OnWeaponEventInventoryCleared(forEvent)); + } + + foreach (var forEvent in EventElementsMap.Keys) + { + } } public new void Dispose() { GC.SuppressFinalize(this); - StartedFlying.Dispose(); - WhileFlying.Dispose(); - StoppedFlying.Dispose(); + foreach (var element in EventElementsMap.Values) + element.Binding.Dispose(); base.Dispose(); } @@ -108,13 +127,6 @@ public partial class InventoryUi : Control, IDisposable public AbilitySelection GetAbilitySelection(WeaponSystem.WeaponEvent forEvent) { - var abilitiesSelectionsMap = new Dictionary - { - { WeaponSystem.WeaponEvent.StartedFlying, StartedFlying }, - { WeaponSystem.WeaponEvent.StoppedFlying, StoppedFlying }, - { WeaponSystem.WeaponEvent.FlyingTick, WhileFlying }, - }; - - return abilitiesSelectionsMap[forEvent]; + return EventElementsMap[forEvent].AbilitySelection; } } diff --git a/menus/scenes/overlaid_menus/inventory.tscn b/menus/scenes/overlaid_menus/inventory.tscn index fc5f37a5..f58310b8 100644 --- a/menus/scenes/overlaid_menus/inventory.tscn +++ b/menus/scenes/overlaid_menus/inventory.tscn @@ -72,24 +72,47 @@ layout_mode = 2 text = "Weapon abilities" horizontal_alignment = 1 -[node name="HBoxContainer" type="HBoxContainer" parent="Inventory/MenuPanelContainer/MarginContainer/BoxContainer/PlayerSectionMargin/PlayerSection" unique_id=75337901] +[node name="FlyingHBoxContainer" type="HBoxContainer" parent="Inventory/MenuPanelContainer/MarginContainer/BoxContainer/PlayerSectionMargin/PlayerSection" unique_id=75337901] layout_mode = 2 script = ExtResource("2_ijoei") search_depth = 10 -[node name="StartedFlying" parent="Inventory/MenuPanelContainer/MarginContainer/BoxContainer/PlayerSectionMargin/PlayerSection/HBoxContainer" unique_id=1373426933 instance=ExtResource("3_ijoei")] +[node name="StartedFlying" parent="Inventory/MenuPanelContainer/MarginContainer/BoxContainer/PlayerSectionMargin/PlayerSection/FlyingHBoxContainer" unique_id=1373426933 instance=ExtResource("3_ijoei")] unique_name_in_owner = true layout_mode = 2 Title = "Started flying" -[node name="WhileFlying" parent="Inventory/MenuPanelContainer/MarginContainer/BoxContainer/PlayerSectionMargin/PlayerSection/HBoxContainer" unique_id=1771285257 instance=ExtResource("3_ijoei")] +[node name="WhileFlying" parent="Inventory/MenuPanelContainer/MarginContainer/BoxContainer/PlayerSectionMargin/PlayerSection/FlyingHBoxContainer" unique_id=1771285257 instance=ExtResource("3_ijoei")] unique_name_in_owner = true layout_mode = 2 ForEvent = 2 Title = "While flying" -[node name="StoppedFlying" parent="Inventory/MenuPanelContainer/MarginContainer/BoxContainer/PlayerSectionMargin/PlayerSection/HBoxContainer" unique_id=324047638 instance=ExtResource("3_ijoei")] +[node name="StoppedFlying" parent="Inventory/MenuPanelContainer/MarginContainer/BoxContainer/PlayerSectionMargin/PlayerSection/FlyingHBoxContainer" unique_id=324047638 instance=ExtResource("3_ijoei")] unique_name_in_owner = true layout_mode = 2 ForEvent = 1 Title = "Stopped flying" + +[node name="PlantedHBoxContainer" type="HBoxContainer" parent="Inventory/MenuPanelContainer/MarginContainer/BoxContainer/PlayerSectionMargin/PlayerSection" unique_id=1198840955] +layout_mode = 2 +script = ExtResource("2_ijoei") +search_depth = 10 + +[node name="StartedPlanted" parent="Inventory/MenuPanelContainer/MarginContainer/BoxContainer/PlayerSectionMargin/PlayerSection/PlantedHBoxContainer" unique_id=1231817717 instance=ExtResource("3_ijoei")] +unique_name_in_owner = true +layout_mode = 2 +ForEvent = 3 +Title = "On weapon planted" + +[node name="WhilePlanted" parent="Inventory/MenuPanelContainer/MarginContainer/BoxContainer/PlayerSectionMargin/PlayerSection/PlantedHBoxContainer" unique_id=1222663623 instance=ExtResource("3_ijoei")] +unique_name_in_owner = true +layout_mode = 2 +ForEvent = 5 +Title = "While planted" + +[node name="StoppedPlanted" parent="Inventory/MenuPanelContainer/MarginContainer/BoxContainer/PlayerSectionMargin/PlayerSection/PlantedHBoxContainer" unique_id=2136675723 instance=ExtResource("3_ijoei")] +unique_name_in_owner = true +layout_mode = 2 +ForEvent = 4 +Title = "On weapon unplanted" diff --git a/scenes/player_controller/components/weapon/WeaponSystem.cs b/scenes/player_controller/components/weapon/WeaponSystem.cs index 8a851ae2..c98a4a67 100644 --- a/scenes/player_controller/components/weapon/WeaponSystem.cs +++ b/scenes/player_controller/components/weapon/WeaponSystem.cs @@ -49,7 +49,10 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity { StartedFlying, StoppedFlying, - FlyingTick + FlyingTick, + StartedPlanted, + StoppedPlanted, + PlantedTick } #endregion @@ -70,6 +73,10 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity private readonly Dictionary _grantedWeaponStoppedFlyingAbilities = new(); private readonly Dictionary _grantedWeaponFlyingTickAbilities = new(); + private readonly Dictionary _grantedWeaponStartedPlantedAbilities = new(); + private readonly Dictionary _grantedWeaponStoppedPlantedAbilities = new(); + private readonly Dictionary _grantedWeaponPlantedTickAbilities = new(); + public Tag WeaponFlyingTickEventTag; public Tag WeaponStartedFlyingEventTag; public Tag WeaponStoppedFlyingEventTag; @@ -78,24 +85,31 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity public Tag WeaponPlantedToHandEventTag; public Tag WeaponPlantedToFlyingEventTag; public Tag WeaponPlantedEventTag; + public Tag WeaponPlantedTickEventTag; + public Tag WeaponUnplantedEventTag; public Tag WeaponInHandStatusTag; public Tag WeaponFlyingStatusTag; public Tag WeaponPlantedStatusTag; public Tag WeaponFlyingAbilityTag; + public Tag WeaponPlantedAbilityTag; private AbilityHandle? _weaponFlyingAbility; + private AbilityHandle? _weaponPlantedAbility; #endregion #region Inspector - [Export] public ForgeAbilityData? FlyingTickAbility { get; set; } - + [ExportGroup("Throwing")] [Export(PropertyHint.Range, "0,2,0.01,or_greater")] public float ThrowForce { get; set; } = 1f; [Export(PropertyHint.Range, "0,0.2,0.01,or_greater")] public float StraightThrowDuration { get; set; } = 0.1f; + + [ExportGroup("Tick raising abilities")] + [Export] public ForgeAbilityData? FlyingTickAbility { get; set; } + [Export] public ForgeAbilityData? PlantedTickAbility { get; set; } #endregion @@ -168,6 +182,9 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity private Vector3 _startMeshRotation; private Vector3 _throwDirection; + + private IForgeEntity? _plantedEntity; + private AbilityHandle? _plantedInEnemyHandle; #endregion @@ -208,22 +225,33 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity WeaponPlantedToHandEventTag = Tag.RequestTag(TagsManager, "events.weapon.plantedToHand"); WeaponPlantedToFlyingEventTag = Tag.RequestTag(TagsManager, "events.weapon.plantedToFlying"); WeaponPlantedEventTag = Tag.RequestTag(TagsManager, "events.weapon.planted"); + WeaponPlantedTickEventTag = Tag.RequestTag(TagsManager, "events.weapon.plantedtick"); + WeaponUnplantedEventTag = Tag.RequestTag(TagsManager, "events.weapon.unplanted"); // WeaponInHandStatusTag = Tag.RequestTag(TagsManager, "status.weapon.inHand"); // WeaponFlyingStatusTag = Tag.RequestTag(TagsManager, "status.weapon.flying"); // WeaponPlantedStatusTag = Tag.RequestTag(TagsManager, "status.weapon.planted"); - // Manage weapon flying tick raising ability - WeaponFlyingAbilityTag = Tag.RequestTag(TagsManager,"abilities.weapon.flying"); - _weaponFlyingAbility = Abilities.GrantAbilityPermanently(FlyingTickAbility.GetAbilityData(), 1, LevelComparison.None, this); - Events.Subscribe(WeaponStoppedFlyingEventTag, _ => { _weaponFlyingAbility.Cancel(); }); + // Manage weapon tick raising abilities + if (FlyingTickAbility != null) + { + WeaponFlyingAbilityTag = Tag.RequestTag(TagsManager,"abilities.weapon.flying"); + _weaponFlyingAbility = Abilities.GrantAbilityPermanently(FlyingTickAbility.GetAbilityData(), 1, LevelComparison.None, this); + Events.Subscribe(WeaponStoppedFlyingEventTag, _ => { _weaponFlyingAbility.Cancel(); }); + } + if (PlantedTickAbility != null) + { + WeaponPlantedAbilityTag = Tag.RequestTag(TagsManager,"abilities.weapon.planted"); + _weaponPlantedAbility = Abilities.GrantAbilityPermanently(PlantedTickAbility.GetAbilityData(), 1, LevelComparison.None, this); + Events.Subscribe(WeaponUnplantedEventTag, _ => { _weaponPlantedAbility.Cancel(); }); + } + + #region EventRaising BodyEntered += OnThrownWeaponReachesGround; InHandState.StateExited += WeaponLeft; InHandState.StateEntered += WeaponBack; - #region EventRaising - _handToFlying.Taken += () => { Events.Raise(new EventData @@ -257,7 +285,15 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity Events.Raise(new EventData { EventTags = WeaponPlantedToHandEventTag.GetSingleTagContainer()!, - Source = this + Source = this, + Target = _plantedEntity + }); + + Events.Raise(new EventData + { + EventTags = WeaponUnplantedEventTag.GetSingleTagContainer()!, + Source = this, + Target = _plantedEntity }); }; @@ -273,6 +309,12 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity EventTags = WeaponStartedFlyingEventTag.GetSingleTagContainer()!, Source = this }); + Events.Raise(new EventData + { + EventTags = WeaponUnplantedEventTag.GetSingleTagContainer()!, + Source = this, + Target = _plantedEntity + }); }; _toPlanted.Taken += () => @@ -303,6 +345,9 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity { WeaponEvent.StartedFlying, WeaponStartedFlyingEventTag }, { WeaponEvent.StoppedFlying, WeaponStoppedFlyingEventTag }, { WeaponEvent.FlyingTick, WeaponFlyingTickEventTag }, + { WeaponEvent.StartedPlanted, WeaponPlantedEventTag }, + { WeaponEvent.StoppedPlanted, WeaponUnplantedEventTag }, + { WeaponEvent.PlantedTick, WeaponPlantedTickEventTag }, }; var ability = new AbilityData( @@ -362,6 +407,10 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity { WeaponEvent.StartedFlying, _grantedWeaponStartedFlyingAbilities }, { WeaponEvent.StoppedFlying, _grantedWeaponStoppedFlyingAbilities }, { WeaponEvent.FlyingTick, _grantedWeaponFlyingTickAbilities }, + + { WeaponEvent.StartedPlanted, _grantedWeaponStartedPlantedAbilities }, + { WeaponEvent.StoppedPlanted, _grantedWeaponStoppedPlantedAbilities }, + { WeaponEvent.PlantedTick, _grantedWeaponPlantedTickAbilities }, }; return abilitiesMap[forEvent]; @@ -409,7 +458,6 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity tween.Finished += ThrowWeaponOnCurve; } - private IForgeEntity? _plantedEntity; public void PlantInEnemy(Node3D enemy) { GetTree().GetRoot().CallDeferred(Node.MethodName.RemoveChild, this); @@ -417,11 +465,6 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity if (enemy is IForgeEntity victim) _plantedEntity = victim; else _plantedEntity = null; - - // if (enemy is IDamageable damageable) - // { - // damageable.TakeDamage(new DamageRecord(GlobalPosition, RDamage)); - // } } public void RethrowWeapon() @@ -470,12 +513,10 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity public override void _IntegrateForces(PhysicsDirectBodyState3D state) { base._IntegrateForces(state); - - if (!Freeze && state.GetContactCount() > 0) - { - PlantLocation = state.GetContactLocalPosition(0); - PlantNormal = state.GetContactLocalNormal(0); - } + + if (Freeze || state.GetContactCount() <= 0) return; + PlantLocation = state.GetContactLocalPosition(0); + PlantNormal = state.GetContactLocalNormal(0); } public override void _Process(double delta) diff --git a/scenes/player_controller/components/weapon/weapon.tscn b/scenes/player_controller/components/weapon/weapon.tscn index 41f537d8..e4a98350 100644 --- a/scenes/player_controller/components/weapon/weapon.tscn +++ b/scenes/player_controller/components/weapon/weapon.tscn @@ -1,9 +1,11 @@ [gd_scene format=3 uid="uid://ckm3d6k08a72u"] [ext_resource type="Script" uid="uid://iii3wfto4t5b" path="res://scenes/player_controller/components/weapon/WeaponSystem.cs" id="1_csqwk"] +[ext_resource type="Resource" uid="uid://dgjsi1my7nlnk" path="res://forge/resources/ability_datas/player_hit.tres" id="2_2wsgo"] [ext_resource type="Script" uid="uid://cw525n4mjqgw0" path="res://addons/forge/resources/ForgeTagContainer.cs" id="2_l1xlx"] [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://0oo3na61ot1o" path="res://forge/resources/ability_datas/weapon_planted_tick_ability.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://forge/resources/ability_datas/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"] @@ -11,6 +13,15 @@ [ext_resource type="Script" uid="uid://rpcbb54q4atx" path="res://forge/ForgeEntityNode.cs" id="5_7bruw"] [ext_resource type="Script" uid="uid://cytafq8i1y8qm" path="res://addons/godot_state_charts/atomic_state.gd" id="5_m0v1h"] [ext_resource type="Script" uid="uid://cf1nsco3w0mf6" path="res://addons/godot_state_charts/transition.gd" id="6_jpdh0"] +[ext_resource type="Script" uid="uid://dps0oef50noil" path="res://addons/forge/nodes/ForgeEffect.cs" id="9_vs841"] +[ext_resource type="Resource" uid="uid://bn1getr10b4dx" path="res://forge/resources/effect_datas/simple_player_hit.tres" id="10_fyov3"] +[ext_resource type="Script" uid="uid://1hgogislo1l6" path="res://addons/forge/resources/magnitudes/ForgeScalableInt.cs" id="10_rgbou"] +[ext_resource type="Script" uid="uid://b83hf13nj37k3" path="res://addons/forge/resources/ForgeEffectData.cs" id="11_fyov3"] +[ext_resource type="Script" uid="uid://n6efm5o4uxvr" path="res://forge/abilities/ForgeSimpleHitBehavior.cs" id="12_2o32x"] +[ext_resource type="Script" uid="uid://dpakv7agvir6y" path="res://addons/forge/resources/ForgeTag.cs" id="12_fyov3"] +[ext_resource type="Script" uid="uid://dhxfbxh54pyxp" path="res://addons/forge/resources/abilities/ForgeAbilityData.cs" id="13_i0iid"] +[ext_resource type="Script" uid="uid://72kj3n4lm1em" path="res://addons/forge/resources/components/ForgeGrantAbilityConfig.cs" id="14_i0jsb"] +[ext_resource type="Script" uid="uid://b3wo2uge4ddnj" path="res://addons/forge/resources/components/GrantAbility.cs" id="15_a8u16"] [sub_resource type="Resource" id="Resource_7bruw"] script = ExtResource("2_l1xlx") @@ -23,6 +34,62 @@ Default = 1 Min = 1 Max = 100 +[sub_resource type="Resource" id="Resource_weq0w"] +script = ExtResource("12_2o32x") +DamageEffect = ExtResource("10_fyov3") +Name = "On planted simple hit" +Description = "Causes hit on enemy planted" +metadata/_custom_type_script = "uid://n6efm5o4uxvr" + +[sub_resource type="Resource" id="Resource_2o32x"] +script = ExtResource("12_fyov3") +Tag = "events.weapon.planted" +metadata/_custom_type_script = "uid://dpakv7agvir6y" + +[sub_resource type="Resource" id="Resource_bua0c"] +script = ExtResource("13_i0iid") +Name = "On Planted in Enemy" +InstancingPolicy = 1 +CooldownEffects = [] +AbilityBehavior = SubResource("Resource_weq0w") +TriggerSource = 1 +TriggerTag = SubResource("Resource_2o32x") +metadata/_custom_type_script = "uid://dhxfbxh54pyxp" + +[sub_resource type="Resource" id="Resource_xhc8e"] +script = ExtResource("10_rgbou") +BaseValue = 1 + +[sub_resource type="Resource" id="Resource_hnni7"] +script = ExtResource("14_i0jsb") +AbilityData = SubResource("Resource_bua0c") +AbilityLevel = SubResource("Resource_xhc8e") +metadata/_custom_type_script = "uid://72kj3n4lm1em" + +[sub_resource type="Resource" id="Resource_rr8s3"] +script = ExtResource("15_a8u16") +GrantAbilityConfigs = [SubResource("Resource_hnni7")] +metadata/_custom_type_script = "uid://b3wo2uge4ddnj" + +[sub_resource type="Resource" id="Resource_8jrha"] +script = ExtResource("10_rgbou") +BaseValue = 1 + +[sub_resource type="Resource" id="Resource_l026a"] +script = ExtResource("10_rgbou") +BaseValue = 1 + +[sub_resource type="Resource" id="Resource_x33lk"] +script = ExtResource("11_fyov3") +Name = "Grant abilities" +Modifiers = [] +Components = Array[Object]([SubResource("Resource_rr8s3")]) +Executions = [] +StackLimit = SubResource("Resource_l026a") +InitialStack = SubResource("Resource_8jrha") +Cues = [] +metadata/_custom_type_script = "uid://b83hf13nj37k3" + [sub_resource type="CylinderShape3D" id="CylinderShape3D_avini"] height = 1.0 radius = 0.1 @@ -58,7 +125,9 @@ continuous_cd = true contact_monitor = true max_contacts_reported = 1 script = ExtResource("1_csqwk") +OnPlantedInEnemy = ExtResource("2_2wsgo") FlyingTickAbility = ExtResource("4_7bruw") +PlantedTickAbility = ExtResource("3_7bruw") [node name="ForgeEntityNode" type="Node3D" parent="." unique_id=1798885192] script = ExtResource("5_7bruw") @@ -73,6 +142,11 @@ InitialAttributeValues = Dictionary[String, ExtResource("4_q6xv7")]({ }) metadata/_custom_type_script = "uid://cxihb42t2mfqi" +[node name="GrantAbilities" type="Node" parent="ForgeEntityNode" unique_id=180593118] +script = ExtResource("9_vs841") +EffectData = SubResource("Resource_x33lk") +metadata/_custom_type_script = "uid://dps0oef50noil" + [node name="WeaponFlyingTick" type="Timer" parent="." unique_id=656309486] wait_time = 0.2 diff --git a/scenes/player_controller/scripts/PlayerController.cs b/scenes/player_controller/scripts/PlayerController.cs index 5118a086..1bfaff04 100644 --- a/scenes/player_controller/scripts/PlayerController.cs +++ b/scenes/player_controller/scripts/PlayerController.cs @@ -59,6 +59,10 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl Dash, MantleDash } + + public record struct EventElements( + AutoSet.Binding Binding, + IAutoSet Inventory); #endregion @@ -110,6 +114,16 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl public required EntityAbilities Abilities { get; set; } public required EventManager Events { get; set; } public required Variables SharedVariables { get; set; } + + public Dictionary EventElementsMap { get; private set; } = []; + + public AutoSet.Binding StartedFlyingBinding { get; set; } + public AutoSet.Binding FlyingTickBinding { get; set; } + public AutoSet.Binding StoppedFlyingBinding { get; set; } + + public AutoSet.Binding StartedPlantedBinding { get; set; } + public AutoSet.Binding PlantedTickBinding { get; set; } + public AutoSet.Binding StoppedPlantedBinding { get; set; } #endregion @@ -729,37 +743,34 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl } // Inventory changes signal binding - StartedFlyingBinding = InventoryManager.StartedFlyingAbilities.Bind(); - StartedFlyingBinding - .OnAdd(behavior => WeaponSystem.GrantNewAbilityForEvent(WeaponSystem.WeaponEvent.StartedFlying, behavior)) - .OnRemove(behavior => WeaponSystem.RemoveAbilityForEvent(WeaponSystem.WeaponEvent.StartedFlying, behavior)) - .OnClear(() => WeaponSystem.RemoveAbilitiesForEvent(WeaponSystem.WeaponEvent.StartedFlying)); - FlyingTickBinding = InventoryManager.FlyingTickAbilities.Bind(); - FlyingTickBinding - .OnAdd(behavior => WeaponSystem.GrantNewAbilityForEvent(WeaponSystem.WeaponEvent.FlyingTick, behavior)) - .OnRemove(behavior => WeaponSystem.RemoveAbilityForEvent(WeaponSystem.WeaponEvent.FlyingTick, behavior)) - .OnClear(() => WeaponSystem.RemoveAbilitiesForEvent(WeaponSystem.WeaponEvent.FlyingTick)); - StoppedFlyingBinding = InventoryManager.StoppedFlyingAbilities.Bind(); - StoppedFlyingBinding - .OnAdd(behavior => WeaponSystem.GrantNewAbilityForEvent(WeaponSystem.WeaponEvent.StoppedFlying, behavior)) - .OnRemove(behavior => WeaponSystem.RemoveAbilityForEvent(WeaponSystem.WeaponEvent.StoppedFlying, behavior)) - .OnClear(() => WeaponSystem.RemoveAbilitiesForEvent(WeaponSystem.WeaponEvent.StoppedFlying)); + EventElementsMap = new Dictionary + { + { WeaponSystem.WeaponEvent.StartedFlying, new EventElements(StartedFlyingBinding, InventoryManager.StartedFlyingAbilities) }, + { WeaponSystem.WeaponEvent.StoppedFlying, new EventElements(StoppedFlyingBinding, InventoryManager.StoppedFlyingAbilities)}, + { WeaponSystem.WeaponEvent.FlyingTick, new EventElements(FlyingTickBinding, InventoryManager.FlyingTickAbilities) }, + + { WeaponSystem.WeaponEvent.StartedPlanted, new EventElements(StartedPlantedBinding, InventoryManager.StartedPlantedAbilities) }, + { WeaponSystem.WeaponEvent.StoppedPlanted, new EventElements(StoppedPlantedBinding, InventoryManager.StoppedPlantedAbilities) }, + { WeaponSystem.WeaponEvent.PlantedTick, new EventElements(PlantedTickBinding, InventoryManager.PlantedTickAbilities) }, + }; - // InventoryManager.WeaponEventAbilityAdded += OnWeaponEventAbilityAdded; - // InventoryManager.WeaponEventAbilityRemoved += OnWeaponEventAbilityRemoved; + foreach (var forEvent in EventElementsMap.Keys) + { + var element = EventElementsMap[forEvent]; + element.Binding = element.Inventory.Bind(); + element.Binding + .OnAdd(behavior => WeaponSystem.GrantNewAbilityForEvent(forEvent, behavior)) + .OnRemove(behavior => WeaponSystem.RemoveAbilityForEvent(forEvent, behavior)) + .OnClear(() => WeaponSystem.RemoveAbilitiesForEvent(forEvent)); + } } - - public AutoSet.Binding StartedFlyingBinding { get; set; } - public AutoSet.Binding FlyingTickBinding { get; set; } - public AutoSet.Binding StoppedFlyingBinding { get; set; } public new void Dispose() { GC.SuppressFinalize(this); - StartedFlyingBinding.Dispose(); - FlyingTickBinding.Dispose(); - StoppedFlyingBinding.Dispose(); + foreach (var element in EventElementsMap.Values) + element.Binding.Dispose(); base.Dispose(); } @@ -801,16 +812,6 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl out var failures); } - public void OnWeaponEventAbilityAdded(WeaponEventAbilityData data) - { - WeaponSystem.GrantNewAbilityForEvent(data.ForEvent, data.Ability); - } - - public void OnWeaponEventAbilityRemoved(WeaponEventAbilityData data) - { - WeaponSystem.RemoveAbilityForEvent(data.ForEvent, data.Ability); - } - #endregion #region Settings