diff --git a/forge/attribute_sets/CharacterAttributeSet.cs b/forge/attribute_sets/CharacterAttributeSet.cs new file mode 100644 index 00000000..8c7f1a5f --- /dev/null +++ b/forge/attribute_sets/CharacterAttributeSet.cs @@ -0,0 +1,13 @@ +using Gamesmiths.Forge.Attributes; + +namespace Movementtests.forge.attribute_sets; + +public class CharacterAttributeSet : AttributeSet +{ + public EntityAttribute Health { get; } + + public CharacterAttributeSet() + { + Health = InitializeAttribute(nameof(Health), 100, 0, 100); + } +} \ No newline at end of file diff --git a/forge/attribute_sets/CharacterAttributeSet.cs.uid b/forge/attribute_sets/CharacterAttributeSet.cs.uid new file mode 100644 index 00000000..4969802a --- /dev/null +++ b/forge/attribute_sets/CharacterAttributeSet.cs.uid @@ -0,0 +1 @@ +uid://cikbxmilitd1m diff --git a/forge/attribute_sets/EnemyAttributeSet.cs b/forge/attribute_sets/EnemyAttributeSet.cs index 1429f2d7..92583a62 100644 --- a/forge/attribute_sets/EnemyAttributeSet.cs +++ b/forge/attribute_sets/EnemyAttributeSet.cs @@ -1,15 +1,14 @@ using Gamesmiths.Forge.Attributes; + namespace Movementtests.scenes.enemies; public class EnemyAttributeSet : AttributeSet { - public EntityAttribute Health { get; } public EntityAttribute Strength { get; } public EntityAttribute Speed { get; } public EnemyAttributeSet() { - Health = InitializeAttribute(nameof(Health), 100, 0, 100); Strength = InitializeAttribute(nameof(Strength), 10, 0, 99); Speed = InitializeAttribute(nameof(Speed), 5, 0, 10); } diff --git a/forge/attribute_sets/MetaAttributeSet.cs b/forge/attribute_sets/MetaAttributeSet.cs index b03d4172..ab938d76 100644 --- a/forge/attribute_sets/MetaAttributeSet.cs +++ b/forge/attribute_sets/MetaAttributeSet.cs @@ -7,6 +7,6 @@ public class MetaAttributeSet : AttributeSet public MetaAttributeSet() { - IncomingDamage = InitializeAttribute(nameof(IncomingDamage), 0, 0, 1000, channels: 2); + IncomingDamage = InitializeAttribute(nameof(IncomingDamage), 0, 0, 1000, channels: 4); } } \ No newline at end of file diff --git a/forge/attribute_sets/PlayerAttributeSet.cs b/forge/attribute_sets/PlayerAttributeSet.cs index 4a404506..85fae5e8 100644 --- a/forge/attribute_sets/PlayerAttributeSet.cs +++ b/forge/attribute_sets/PlayerAttributeSet.cs @@ -4,16 +4,10 @@ namespace Movementtests.scenes.player_controller.scripts; public class PlayerAttributeSet : AttributeSet { - public EntityAttribute Health { get; } public EntityAttribute Mana { get; } - public EntityAttribute Strength { get; } - public EntityAttribute Speed { get; } public PlayerAttributeSet() { - Health = InitializeAttribute(nameof(Health), 100, 0, 100); Mana = InitializeAttribute(nameof(Mana), 100, 0, 100); - Strength = InitializeAttribute(nameof(Strength), 10, 0, 99); - Speed = InitializeAttribute(nameof(Speed), 5, 0, 10); } } \ No newline at end of file diff --git a/forge/calculators/DamageType.cs b/forge/calculators/DamageType.cs new file mode 100644 index 00000000..301beb72 --- /dev/null +++ b/forge/calculators/DamageType.cs @@ -0,0 +1,19 @@ +namespace Movementtests.tools.calculators; + +public enum DamageType +{ + /// + /// Physical damage. + /// + Physical = 0, + + /// + /// Magical damage. + /// + Magical = 1, + + /// + /// Elemental damage. + /// + Elemental = 2, +} \ No newline at end of file diff --git a/forge/calculators/DamageType.cs.uid b/forge/calculators/DamageType.cs.uid new file mode 100644 index 00000000..22862f2e --- /dev/null +++ b/forge/calculators/DamageType.cs.uid @@ -0,0 +1 @@ +uid://bne5gra0fmvsr diff --git a/forge/calculators/ForgeDamageExecution.cs b/forge/calculators/ForgeDamageExecution.cs new file mode 100644 index 00000000..8b769039 --- /dev/null +++ b/forge/calculators/ForgeDamageExecution.cs @@ -0,0 +1,134 @@ +using System.Collections.Generic; +using Gamesmiths.Forge.Attributes; +using Gamesmiths.Forge.Core; +using Gamesmiths.Forge.Effects; +using Gamesmiths.Forge.Effects.Calculator; +using Gamesmiths.Forge.Effects.Magnitudes; +using Gamesmiths.Forge.Effects.Modifiers; +using Gamesmiths.Forge.Events; +using Gamesmiths.Forge.Godot.Core; +using Gamesmiths.Forge.Godot.Resources; +using Gamesmiths.Forge.Godot.Resources.Calculators; +using Gamesmiths.Forge.Tags; +using Godot; + +namespace Movementtests.tools.calculators; + +public record DamageDone(DamageType DamageType, float Damage, float OverkillDamage); + +public class DamageExecution : CustomExecution +{ + private readonly DamageType _damageType; + private readonly ForgeTagContainer? _damageDealerEventTags; + private readonly ForgeTagContainer? _damageReceiverEventTags; + + // Define attributes to capture and modify + public AttributeCaptureDefinition TargetHealth { get; } + + public AttributeCaptureDefinition TargetIncomingDamage { get; } + + public DamageExecution(DamageType damageType, ForgeTagContainer? damageDealerEventTags, ForgeTagContainer? damageReceiverEventTags) + { + // Capture target mana and magic resistance + TargetHealth = new AttributeCaptureDefinition( + "CharacterAttributeSet.Health", + AttributeCaptureSource.Target, + false); + + TargetIncomingDamage = new AttributeCaptureDefinition( + "MetaAttributeSet.IncomingDamage", + AttributeCaptureSource.Target); + + // Register attributes for capture + AttributesToCapture.Add(TargetHealth); + AttributesToCapture.Add(TargetIncomingDamage); + + _damageType = damageType; + _damageDealerEventTags = damageDealerEventTags; + _damageReceiverEventTags = damageReceiverEventTags; + } + + public override ModifierEvaluatedData[] EvaluateExecution( + Effect effect, IForgeEntity target, EffectEvaluatedData? effectEvaluatedData) + { + var results = new List(); + + float targetIncomingDamage = CaptureAttributeMagnitude( + TargetIncomingDamage, + effect, + target, + effectEvaluatedData); + + if (targetIncomingDamage <= 0) + { + return [.. results]; + } + + if (effectEvaluatedData?.TryGetContextData(out float multiplier) == true) + { + targetIncomingDamage *= multiplier; + } + + // Apply health reduction to target if attribute exists + if (TargetHealth.TryGetAttribute(target, out EntityAttribute? targetHealthAttribute)) + { + results.Add(new ModifierEvaluatedData( + targetHealthAttribute, + ModifierOperation.FlatBonus, + -targetIncomingDamage)); // Negative for damage + } + + var finalDamage = targetIncomingDamage; + var overkillDamage = 0.0f; + if (targetHealthAttribute!.CurrentValue - targetIncomingDamage <= targetHealthAttribute.Min) + { + finalDamage = targetHealthAttribute.CurrentValue - targetHealthAttribute.Min; + overkillDamage = targetIncomingDamage - finalDamage; + } + + if (_damageReceiverEventTags is null) return [.. results]; + + target.Events.Raise(new EventData + { + EventTags = _damageReceiverEventTags.GetTagContainer(), + Source = effect.Ownership.Owner, + Target = target, + EventMagnitude = finalDamage, + Payload = new DamageDone(_damageType, finalDamage, overkillDamage) + }); + + if (effect.Ownership.Source is null || _damageDealerEventTags is null) + { + return [.. results]; + } + + effect.Ownership.Source.Events.Raise(new EventData + { + EventTags = _damageDealerEventTags.GetTagContainer(), + Source = effect.Ownership.Owner, + Target = target, + EventMagnitude = finalDamage, + Payload = new DamageDone(_damageType, finalDamage, overkillDamage) + }); + + return [.. results]; + } +} + + +[Tool] +[GlobalClass] +public partial class ForgeDamageExecution : ForgeCustomExecution +{ + [Export] + public DamageType DamageType { get; set; } = DamageType.Physical; + [Export] + public ForgeTagContainer? DamageDealerEventTags { get; set; } + [Export] + public ForgeTagContainer? DamageReceiverEventTags { get; set; } + + public override CustomExecution GetExecutionClass() + { + return new DamageExecution(DamageType, DamageDealerEventTags, DamageReceiverEventTags); + } +} \ No newline at end of file diff --git a/forge/calculators/ForgeDamageExecution.cs.uid b/forge/calculators/ForgeDamageExecution.cs.uid new file mode 100644 index 00000000..366dbf9a --- /dev/null +++ b/forge/calculators/ForgeDamageExecution.cs.uid @@ -0,0 +1 @@ +uid://cfx62w40nd84v diff --git a/forge/forge_data.tres b/forge/forge_data.tres index e1686ca2..2dd65578 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", "status.invincible", "events.combat.death", "cooldown.hit", "events.player.hit", "cues.enemy.health"]) +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"]) diff --git a/forge/resources/ability_datas/empowered_action.tres b/forge/resources/ability_datas/empowered_action.tres index cea6ea47..a38bd0e4 100644 --- a/forge/resources/ability_datas/empowered_action.tres +++ b/forge/resources/ability_datas/empowered_action.tres @@ -1,16 +1,85 @@ [gd_resource type="Resource" script_class="ForgeAbilityData" format=3 uid="uid://dccuj66egxfwh"] -[ext_resource type="Resource" uid="uid://crgwob8t8yysq" path="res://forge/resources/behaviors/instant_end_behavior.tres" id="1_x7d0c"] [ext_resource type="Script" uid="uid://cw525n4mjqgw0" path="res://addons/forge/resources/ForgeTagContainer.cs" id="2_prg0a"] [ext_resource type="Script" uid="uid://dngf30hxy5go4" path="res://addons/forge/resources/components/ModifierTags.cs" id="3_k72m0"] [ext_resource type="Script" uid="uid://cn3b4ya15fg7e" path="res://addons/forge/resources/magnitudes/ForgeScalableFloat.cs" id="4_5fdax"] [ext_resource type="Script" uid="uid://2gm1hdhi8u08" path="res://addons/forge/resources/magnitudes/ForgeModifierMagnitude.cs" id="5_5qmmj"] [ext_resource type="Script" uid="uid://1hgogislo1l6" path="res://addons/forge/resources/magnitudes/ForgeScalableInt.cs" id="6_yi0bg"] [ext_resource type="Script" uid="uid://b83hf13nj37k3" path="res://addons/forge/resources/ForgeEffectData.cs" id="7_0rp6y"] +[ext_resource type="Script" uid="uid://cl5hudinl1rex" path="res://forge/abilities/ForgeEffectApplicationBehavior.cs" id="7_ent4t"] [ext_resource type="Resource" uid="uid://dn7b8frkoxpxr" path="res://forge/resources/cues/player_mana_changed_cue.tres" id="8_0olwd"] +[ext_resource type="Resource" uid="uid://cw2ytd34jsxj" path="res://forge/resources/tag_containers/immune_damage.tres" id="8_ent4t"] [ext_resource type="Script" uid="uid://bdfcavbjyhxxa" path="res://addons/forge/resources/ForgeModifier.cs" id="9_wluo0"] [ext_resource type="Script" uid="uid://dhxfbxh54pyxp" path="res://addons/forge/resources/abilities/ForgeAbilityData.cs" id="10_2sq4o"] +[sub_resource type="Resource" id="Resource_xltxv"] +script = ExtResource("3_k72m0") +TagsToAdd = ExtResource("8_ent4t") +metadata/_custom_type_script = "uid://dngf30hxy5go4" + +[sub_resource type="Resource" id="Resource_60xl1"] +script = ExtResource("4_5fdax") +BaseValue = 1.0 + +[sub_resource type="Resource" id="Resource_2rev5"] +script = ExtResource("4_5fdax") + +[sub_resource type="Resource" id="Resource_kxytj"] +script = ExtResource("4_5fdax") + +[sub_resource type="Resource" id="Resource_e5nje"] +script = ExtResource("4_5fdax") +BaseValue = 1.0 + +[sub_resource type="Resource" id="Resource_xc8ja"] +script = ExtResource("4_5fdax") + +[sub_resource type="Resource" id="Resource_tan32"] +script = ExtResource("4_5fdax") + +[sub_resource type="Resource" id="Resource_l52b0"] +script = ExtResource("4_5fdax") +BaseValue = 0.3 +metadata/_custom_type_script = "uid://cn3b4ya15fg7e" + +[sub_resource type="Resource" id="Resource_6jn6y"] +script = ExtResource("5_5qmmj") +ScalableFloat = SubResource("Resource_l52b0") +Coefficient = SubResource("Resource_e5nje") +PreMultiplyAdditiveValue = SubResource("Resource_tan32") +PostMultiplyAdditiveValue = SubResource("Resource_xc8ja") +CalculatorCoefficient = SubResource("Resource_60xl1") +CalculatorPreMultiplyAdditiveValue = SubResource("Resource_kxytj") +CalculatorPostMultiplyAdditiveValue = SubResource("Resource_2rev5") +metadata/_custom_type_script = "uid://2gm1hdhi8u08" + +[sub_resource type="Resource" id="Resource_ev6w4"] +script = ExtResource("6_yi0bg") +BaseValue = 1 + +[sub_resource type="Resource" id="Resource_u8xa8"] +script = ExtResource("6_yi0bg") +BaseValue = 1 + +[sub_resource type="Resource" id="Resource_xsfte"] +script = ExtResource("7_0rp6y") +Name = "ApplyInvincibility" +Modifiers = [] +Components = Array[Object]([SubResource("Resource_xltxv")]) +Executions = null +DurationType = 2 +Duration = SubResource("Resource_6jn6y") +StackLimit = SubResource("Resource_u8xa8") +InitialStack = SubResource("Resource_ev6w4") +Cues = null +metadata/_custom_type_script = "uid://b83hf13nj37k3" + +[sub_resource type="Resource" id="Resource_xh53a"] +script = ExtResource("7_ent4t") +EffectData = SubResource("Resource_xsfte") +Name = "Apply invincibility" +metadata/_custom_type_script = "uid://cl5hudinl1rex" + [sub_resource type="Resource" id="Resource_h116a"] script = ExtResource("2_prg0a") ContainerTags = Array[String](["cooldown.empoweredaction"]) @@ -78,6 +147,42 @@ InitialStack = SubResource("Resource_lmnuh") Cues = [] metadata/_custom_type_script = "uid://b83hf13nj37k3" +[sub_resource type="Resource" id="Resource_3usj8"] +script = ExtResource("4_5fdax") +BaseValue = 1.0 + +[sub_resource type="Resource" id="Resource_5q60v"] +script = ExtResource("4_5fdax") + +[sub_resource type="Resource" id="Resource_eo5h0"] +script = ExtResource("4_5fdax") + +[sub_resource type="Resource" id="Resource_c7uae"] +script = ExtResource("4_5fdax") +BaseValue = 1.0 + +[sub_resource type="Resource" id="Resource_7d1b0"] +script = ExtResource("4_5fdax") + +[sub_resource type="Resource" id="Resource_jiq0x"] +script = ExtResource("4_5fdax") + +[sub_resource type="Resource" id="Resource_kpieu"] +script = ExtResource("4_5fdax") +BaseValue = 0.3 +metadata/_custom_type_script = "uid://cn3b4ya15fg7e" + +[sub_resource type="Resource" id="Resource_rwc4g"] +script = ExtResource("5_5qmmj") +ScalableFloat = SubResource("Resource_kpieu") +Coefficient = SubResource("Resource_c7uae") +PreMultiplyAdditiveValue = SubResource("Resource_jiq0x") +PostMultiplyAdditiveValue = SubResource("Resource_7d1b0") +CalculatorCoefficient = SubResource("Resource_3usj8") +CalculatorPreMultiplyAdditiveValue = SubResource("Resource_eo5h0") +CalculatorPostMultiplyAdditiveValue = SubResource("Resource_5q60v") +metadata/_custom_type_script = "uid://2gm1hdhi8u08" + [sub_resource type="Resource" id="Resource_8dsdw"] script = ExtResource("6_yi0bg") BaseValue = 1 @@ -129,6 +234,7 @@ Name = "Empowered Action Cost" Modifiers = Array[Object]([SubResource("Resource_dhni4")]) Components = [] Executions = [] +Duration = SubResource("Resource_rwc4g") StackLimit = SubResource("Resource_w5rmc") InitialStack = SubResource("Resource_8dsdw") Cues = Array[Object]([ExtResource("8_0olwd")]) @@ -139,5 +245,5 @@ script = ExtResource("10_2sq4o") Name = "Empowered Action" CooldownEffects = [SubResource("Resource_egh2b")] CostEffect = SubResource("Resource_mtef8") -AbilityBehavior = ExtResource("1_x7d0c") +AbilityBehavior = SubResource("Resource_xh53a") metadata/_custom_type_script = "uid://dhxfbxh54pyxp" diff --git a/forge/resources/ability_datas/grounded_enemy_hit.tres b/forge/resources/ability_datas/grounded_enemy_hit.tres index 63abac37..f427c037 100644 --- a/forge/resources/ability_datas/grounded_enemy_hit.tres +++ b/forge/resources/ability_datas/grounded_enemy_hit.tres @@ -1,9 +1,9 @@ [gd_resource type="Resource" script_class="ForgeAbilityData" format=3 uid="uid://qpdw62ubaclc"] -[ext_resource type="Resource" uid="uid://cw2ytd34jsxj" path="res://forge/resources/tag_containers/status_invincible.tres" id="1_f6jpb"] -[ext_resource type="Script" uid="uid://b0eq12mjqfage" path="res://addons/forge/resources/components/TargetTagRequirements.cs" id="2_mnqxs"] +[ext_resource type="Resource" uid="uid://bpovqvlqv5bs5" path="res://forge/resources/effect_components/damageable.tres" id="1_q2jt5"] +[ext_resource type="Resource" uid="uid://dlu7l5egpexnn" path="res://forge/resources/custom_executions/raise_damage_dealing_events.tres" id="2_2dxcu"] +[ext_resource type="Resource" uid="uid://4rkwr10pc6tp" path="res://forge/resources/custom_executions/physical_damage_calculator.tres" id="2_f6jpb"] [ext_resource type="Script" uid="uid://cw525n4mjqgw0" path="res://addons/forge/resources/ForgeTagContainer.cs" id="4_0mce3"] -[ext_resource type="Script" uid="uid://br7ut4lbau66w" path="res://forge/calculators/ForgeRaiseEventTagExecution.cs" id="5_1yqf2"] [ext_resource type="Script" uid="uid://1hgogislo1l6" path="res://addons/forge/resources/magnitudes/ForgeScalableInt.cs" id="6_41lep"] [ext_resource type="Script" uid="uid://cn3b4ya15fg7e" path="res://addons/forge/resources/magnitudes/ForgeScalableFloat.cs" id="7_jf6ii"] [ext_resource type="Script" uid="uid://bdfcavbjyhxxa" path="res://addons/forge/resources/ForgeModifier.cs" id="8_51ikp"] @@ -13,27 +13,6 @@ [ext_resource type="Script" uid="uid://2gm1hdhi8u08" path="res://addons/forge/resources/magnitudes/ForgeModifierMagnitude.cs" id="12_2x5q6"] [ext_resource type="Script" uid="uid://dhxfbxh54pyxp" path="res://addons/forge/resources/abilities/ForgeAbilityData.cs" id="13_4nn3y"] -[sub_resource type="Resource" id="Resource_nt1hl"] -script = ExtResource("2_mnqxs") -ApplicationIgnoredTags = ExtResource("1_f6jpb") -metadata/_custom_type_script = "uid://b0eq12mjqfage" - -[sub_resource type="Resource" id="Resource_f35o6"] -script = ExtResource("4_0mce3") -ContainerTags = Array[String](["events.combat.hit"]) -metadata/_custom_type_script = "uid://cw525n4mjqgw0" - -[sub_resource type="Resource" id="Resource_46obe"] -script = ExtResource("4_0mce3") -ContainerTags = Array[String](["events.combat.damage"]) -metadata/_custom_type_script = "uid://cw525n4mjqgw0" - -[sub_resource type="Resource" id="Resource_33a4r"] -script = ExtResource("5_1yqf2") -EventTags = SubResource("Resource_f35o6") -TargetEventTags = SubResource("Resource_46obe") -metadata/_custom_type_script = "uid://br7ut4lbau66w" - [sub_resource type="Resource" id="Resource_rjo6h"] script = ExtResource("6_41lep") BaseValue = 1 @@ -60,12 +39,13 @@ script = ExtResource("7_jf6ii") [sub_resource type="Resource" id="Resource_1s1j3"] script = ExtResource("7_jf6ii") -BaseValue = -10.0 +BaseValue = 10.0 metadata/_custom_type_script = "uid://cn3b4ya15fg7e" [sub_resource type="Resource" id="Resource_khx4r"] script = ExtResource("8_51ikp") -Attribute = "PlayerAttributeSet.Health" +Attribute = "MetaAttributeSet.IncomingDamage" +Operation = 2 ScalableFloat = SubResource("Resource_1s1j3") Coefficient = SubResource("Resource_ugrvo") PreMultiplyAdditiveValue = SubResource("Resource_x0rol") @@ -83,8 +63,8 @@ BaseValue = 1 script = ExtResource("9_bcnlx") Name = "SimpleHitEffect" Modifiers = Array[Object]([SubResource("Resource_khx4r")]) -Components = [SubResource("Resource_nt1hl")] -Executions = [SubResource("Resource_33a4r")] +Components = [ExtResource("1_q2jt5")] +Executions = [ExtResource("2_f6jpb"), ExtResource("2_2dxcu")] StackLimit = SubResource("Resource_xmw7i") InitialStack = SubResource("Resource_rjo6h") Cues = [] diff --git a/forge/resources/ability_datas/on_hit_invinciblity.tres b/forge/resources/ability_datas/on_hit_invinciblity.tres index edda6dd2..56d26d9c 100644 --- a/forge/resources/ability_datas/on_hit_invinciblity.tres +++ b/forge/resources/ability_datas/on_hit_invinciblity.tres @@ -1,6 +1,6 @@ [gd_resource type="Resource" script_class="ForgeAbilityData" format=3 uid="uid://b0ikxp5j8fn3n"] -[ext_resource type="Script" uid="uid://cw525n4mjqgw0" path="res://addons/forge/resources/ForgeTagContainer.cs" id="1_xjqwu"] +[ext_resource type="Resource" uid="uid://cw2ytd34jsxj" path="res://forge/resources/tag_containers/immune_damage.tres" id="1_xjqwu"] [ext_resource type="Script" uid="uid://dngf30hxy5go4" path="res://addons/forge/resources/components/ModifierTags.cs" id="2_a16tf"] [ext_resource type="Script" uid="uid://cn3b4ya15fg7e" path="res://addons/forge/resources/magnitudes/ForgeScalableFloat.cs" id="3_1wliv"] [ext_resource type="Script" uid="uid://2gm1hdhi8u08" path="res://addons/forge/resources/magnitudes/ForgeModifierMagnitude.cs" id="4_7dtdc"] @@ -10,14 +10,9 @@ [ext_resource type="Script" uid="uid://dpakv7agvir6y" path="res://addons/forge/resources/ForgeTag.cs" id="8_4vjp3"] [ext_resource type="Script" uid="uid://dhxfbxh54pyxp" path="res://addons/forge/resources/abilities/ForgeAbilityData.cs" id="9_go27d"] -[sub_resource type="Resource" id="Resource_87uc3"] -script = ExtResource("1_xjqwu") -ContainerTags = Array[String](["status.invincible"]) -metadata/_custom_type_script = "uid://cw525n4mjqgw0" - [sub_resource type="Resource" id="Resource_5ht6k"] script = ExtResource("2_a16tf") -TagsToAdd = SubResource("Resource_87uc3") +TagsToAdd = ExtResource("1_xjqwu") metadata/_custom_type_script = "uid://dngf30hxy5go4" [sub_resource type="Resource" id="Resource_bn2qi"] diff --git a/forge/resources/ability_datas/player_hit.tres b/forge/resources/ability_datas/player_hit.tres index a5842430..4b9ab6cf 100644 --- a/forge/resources/ability_datas/player_hit.tres +++ b/forge/resources/ability_datas/player_hit.tres @@ -2,42 +2,16 @@ [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://br7ut4lbau66w" path="res://forge/calculators/ForgeRaiseEventTagExecution.cs" id="2_0cyim"] [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="Script" uid="uid://b0eq12mjqfage" path="res://addons/forge/resources/components/TargetTagRequirements.cs" id="2_l5emy"] +[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="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_sgtcb"] -script = ExtResource("1_w1wo0") -ContainerTags = Array[String](["status.invincible"]) -metadata/_custom_type_script = "uid://cw525n4mjqgw0" - -[sub_resource type="Resource" id="Resource_3p0ly"] -script = ExtResource("2_l5emy") -ApplicationIgnoredTags = SubResource("Resource_sgtcb") -metadata/_custom_type_script = "uid://b0eq12mjqfage" - -[sub_resource type="Resource" id="Resource_6x2ov"] -script = ExtResource("1_w1wo0") -ContainerTags = Array[String](["events.combat.hit"]) -metadata/_custom_type_script = "uid://cw525n4mjqgw0" - -[sub_resource type="Resource" id="Resource_ml8x2"] -script = ExtResource("1_w1wo0") -ContainerTags = Array[String](["events.combat.damage"]) -metadata/_custom_type_script = "uid://cw525n4mjqgw0" - -[sub_resource type="Resource" id="Resource_1uqo4"] -script = ExtResource("2_0cyim") -EventTags = SubResource("Resource_6x2ov") -TargetEventTags = SubResource("Resource_ml8x2") -metadata/_custom_type_script = "uid://br7ut4lbau66w" - [sub_resource type="Resource" id="Resource_0cyim"] script = ExtResource("1_l0l1a") BaseValue = 1 @@ -64,12 +38,13 @@ script = ExtResource("4_c4wry") [sub_resource type="Resource" id="Resource_uinv8"] script = ExtResource("4_c4wry") -BaseValue = -50.0 +BaseValue = 40.0 metadata/_custom_type_script = "uid://cn3b4ya15fg7e" [sub_resource type="Resource" id="Resource_04hqa"] script = ExtResource("3_c4wry") -Attribute = "EnemyAttributeSet.Health" +Attribute = "MetaAttributeSet.IncomingDamage" +Operation = 2 ScalableFloat = SubResource("Resource_uinv8") Coefficient = SubResource("Resource_no8t2") PreMultiplyAdditiveValue = SubResource("Resource_m6xnn") @@ -87,8 +62,8 @@ BaseValue = 1 script = ExtResource("2_5vjbv") Name = "Player Hit Effect" Modifiers = Array[Object]([SubResource("Resource_04hqa")]) -Components = Array[Object]([SubResource("Resource_3p0ly")]) -Executions = Array[Object]([SubResource("Resource_1uqo4")]) +Components = Array[Object]([ExtResource("1_r7waw")]) +Executions = Array[Object]([ExtResource("2_l5emy")]) StackLimit = SubResource("Resource_8fbeq") InitialStack = SubResource("Resource_0cyim") Cues = [] @@ -138,7 +113,7 @@ script = ExtResource("4_c4wry") [sub_resource type="Resource" id="Resource_bvwi7"] script = ExtResource("4_c4wry") -BaseValue = 0.5 +BaseValue = 0.3 metadata/_custom_type_script = "uid://cn3b4ya15fg7e" [sub_resource type="Resource" id="Resource_3wf5l"] @@ -176,6 +151,7 @@ metadata/_custom_type_script = "uid://b83hf13nj37k3" [resource] script = ExtResource("3_w1wo0") Name = "PlayerHitAbility" +RetriggerInstancedAbility = true CooldownEffects = [SubResource("Resource_cmmfb")] AbilityBehavior = SubResource("Resource_r7waw") ActivationBlockedTags = SubResource("Resource_qk2av") diff --git a/forge/resources/custom_executions/physical_damage_calculator.tres b/forge/resources/custom_executions/physical_damage_calculator.tres new file mode 100644 index 00000000..9c9cf1c9 --- /dev/null +++ b/forge/resources/custom_executions/physical_damage_calculator.tres @@ -0,0 +1,11 @@ +[gd_resource type="Resource" script_class="ForgeDamageExecution" format=3 uid="uid://4rkwr10pc6tp"] + +[ext_resource type="Script" uid="uid://cfx62w40nd84v" path="res://forge/calculators/ForgeDamageExecution.cs" id="1_bo86y"] +[ext_resource type="Resource" uid="uid://sn6kndc6ukic" path="res://forge/resources/tag_containers/on_damage_dealt.tres" id="1_hmxxf"] +[ext_resource type="Resource" uid="uid://5tr54q0rdpho" path="res://forge/resources/tag_containers/on_damage_taken.tres" id="2_6r7e6"] + +[resource] +script = ExtResource("1_bo86y") +DamageDealerEventTags = ExtResource("1_hmxxf") +DamageReceiverEventTags = ExtResource("2_6r7e6") +metadata/_custom_type_script = "uid://cfx62w40nd84v" diff --git a/forge/resources/custom_executions/raise_damage_dealing_events.tres b/forge/resources/custom_executions/raise_damage_dealing_events.tres new file mode 100644 index 00000000..48ee15e7 --- /dev/null +++ b/forge/resources/custom_executions/raise_damage_dealing_events.tres @@ -0,0 +1,11 @@ +[gd_resource type="Resource" script_class="ForgeRaiseEventTagExecution" format=3 uid="uid://dlu7l5egpexnn"] + +[ext_resource type="Resource" uid="uid://sn6kndc6ukic" path="res://forge/resources/tag_containers/on_damage_dealt.tres" id="1_cum8v"] +[ext_resource type="Resource" uid="uid://5tr54q0rdpho" path="res://forge/resources/tag_containers/on_damage_taken.tres" id="2_w48xp"] +[ext_resource type="Script" uid="uid://br7ut4lbau66w" path="res://forge/calculators/ForgeRaiseEventTagExecution.cs" id="3_ggrwn"] + +[resource] +script = ExtResource("3_ggrwn") +EventTags = ExtResource("1_cum8v") +TargetEventTags = ExtResource("2_w48xp") +metadata/_custom_type_script = "uid://br7ut4lbau66w" diff --git a/forge/resources/custom_executions/raise_flying_tick_event.tres b/forge/resources/custom_executions/raise_flying_tick_event.tres index 5e236495..a26d1854 100644 --- a/forge/resources/custom_executions/raise_flying_tick_event.tres +++ b/forge/resources/custom_executions/raise_flying_tick_event.tres @@ -1,6 +1,6 @@ [gd_resource type="Resource" script_class="ForgeRaiseEventTagExecution" format=3 uid="uid://oe2suroa1klj"] -[ext_resource type="Resource" uid="uid://x7vtcobi7s4r" path="res://forge/resources/tag_containers/weapon_flyingtick_tagcontainer.tres" id="1_ce5fv"] +[ext_resource type="Resource" uid="uid://x7vtcobi7s4r" path="res://forge/resources/tag_containers/on_weapon_flyingtick.tres" id="1_ce5fv"] [ext_resource type="Script" uid="uid://br7ut4lbau66w" path="res://forge/calculators/ForgeRaiseEventTagExecution.cs" id="2_am2ak"] [resource] diff --git a/forge/resources/effect_components/damageable.tres b/forge/resources/effect_components/damageable.tres new file mode 100644 index 00000000..54cee0b4 --- /dev/null +++ b/forge/resources/effect_components/damageable.tres @@ -0,0 +1,11 @@ +[gd_resource type="Resource" script_class="TargetTagRequirements" format=3 uid="uid://bpovqvlqv5bs5"] + +[ext_resource type="Resource" uid="uid://cw2ytd34jsxj" path="res://forge/resources/tag_containers/immune_damage.tres" id="1_8qlnl"] +[ext_resource type="Resource" uid="uid://bsogx7yhedjry" path="res://forge/resources/tag_containers/trait_damageable.tres" id="2_vxkk1"] +[ext_resource type="Script" uid="uid://b0eq12mjqfage" path="res://addons/forge/resources/components/TargetTagRequirements.cs" id="3_1mj5a"] + +[resource] +script = ExtResource("3_1mj5a") +ApplicationRequiredTags = ExtResource("2_vxkk1") +ApplicationIgnoredTags = ExtResource("1_8qlnl") +metadata/_custom_type_script = "uid://b0eq12mjqfage" diff --git a/forge/resources/tag_containers/enemy_base_tags.tres b/forge/resources/tag_containers/enemy_base_tags.tres new file mode 100644 index 00000000..807f0a99 --- /dev/null +++ b/forge/resources/tag_containers/enemy_base_tags.tres @@ -0,0 +1,8 @@ +[gd_resource type="Resource" script_class="ForgeTagContainer" format=3 uid="uid://bocsykxbh8l0g"] + +[ext_resource type="Script" uid="uid://cw525n4mjqgw0" path="res://addons/forge/resources/ForgeTagContainer.cs" id="1_kdy2b"] + +[resource] +script = ExtResource("1_kdy2b") +ContainerTags = Array[String](["character.enemy", "traits.damageable"]) +metadata/_custom_type_script = "uid://cw525n4mjqgw0" diff --git a/forge/resources/tag_containers/status_invincible.tres b/forge/resources/tag_containers/immune_damage.tres similarity index 85% rename from forge/resources/tag_containers/status_invincible.tres rename to forge/resources/tag_containers/immune_damage.tres index 2bace4d3..731fe7e8 100644 --- a/forge/resources/tag_containers/status_invincible.tres +++ b/forge/resources/tag_containers/immune_damage.tres @@ -4,5 +4,5 @@ [resource] script = ExtResource("1_vmvhu") -ContainerTags = Array[String](["status.invincible"]) +ContainerTags = Array[String](["immunity.damage"]) metadata/_custom_type_script = "uid://cw525n4mjqgw0" diff --git a/forge/resources/tag_containers/on_damage_dealt.tres b/forge/resources/tag_containers/on_damage_dealt.tres new file mode 100644 index 00000000..87177143 --- /dev/null +++ b/forge/resources/tag_containers/on_damage_dealt.tres @@ -0,0 +1,8 @@ +[gd_resource type="Resource" script_class="ForgeTagContainer" format=3 uid="uid://sn6kndc6ukic"] + +[ext_resource type="Script" uid="uid://cw525n4mjqgw0" path="res://addons/forge/resources/ForgeTagContainer.cs" id="1_4beov"] + +[resource] +script = ExtResource("1_4beov") +ContainerTags = Array[String](["events.combat.hit"]) +metadata/_custom_type_script = "uid://cw525n4mjqgw0" diff --git a/forge/resources/tag_containers/on_damage_taken.tres b/forge/resources/tag_containers/on_damage_taken.tres new file mode 100644 index 00000000..c91098fb --- /dev/null +++ b/forge/resources/tag_containers/on_damage_taken.tres @@ -0,0 +1,8 @@ +[gd_resource type="Resource" script_class="ForgeTagContainer" format=3 uid="uid://5tr54q0rdpho"] + +[ext_resource type="Script" uid="uid://cw525n4mjqgw0" path="res://addons/forge/resources/ForgeTagContainer.cs" id="1_nvopg"] + +[resource] +script = ExtResource("1_nvopg") +ContainerTags = Array[String](["events.combat.damage"]) +metadata/_custom_type_script = "uid://cw525n4mjqgw0" diff --git a/forge/resources/tag_containers/weapon_flyingtick_tagcontainer.tres b/forge/resources/tag_containers/on_weapon_flyingtick.tres similarity index 100% rename from forge/resources/tag_containers/weapon_flyingtick_tagcontainer.tres rename to forge/resources/tag_containers/on_weapon_flyingtick.tres diff --git a/forge/resources/tag_containers/trait_damageable.tres b/forge/resources/tag_containers/trait_damageable.tres new file mode 100644 index 00000000..61090e45 --- /dev/null +++ b/forge/resources/tag_containers/trait_damageable.tres @@ -0,0 +1,8 @@ +[gd_resource type="Resource" script_class="ForgeTagContainer" format=3 uid="uid://bsogx7yhedjry"] + +[ext_resource type="Script" uid="uid://cw525n4mjqgw0" path="res://addons/forge/resources/ForgeTagContainer.cs" id="1_wyb42"] + +[resource] +script = ExtResource("1_wyb42") +ContainerTags = Array[String](["traits.damageable"]) +metadata/_custom_type_script = "uid://cw525n4mjqgw0" diff --git a/scenes/enemies/Enemy.cs b/scenes/enemies/Enemy.cs index 24e77a3f..e9670bdc 100644 --- a/scenes/enemies/Enemy.cs +++ b/scenes/enemies/Enemy.cs @@ -15,6 +15,7 @@ using Godot; using Movementtests.interfaces; using Movementtests.systems; using Movementtests.tools; +using Movementtests.tools.calculators; using Node = Godot.Node; [GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_beetle.png"), Meta(typeof(IAutoNode))] @@ -132,7 +133,6 @@ public partial class Enemy : CharacterBody3D, [Node("ForgeEntityNode")] public required ForgeEntityNode ForgeEntity { get; set;} private AbilityHandle? _hitAbilityHandle; - private EntityAttribute _healthAttribute; public void OnReady() { @@ -144,11 +144,10 @@ public partial class Enemy : CharacterBody3D, { CMovement = GetNode("CMovement") as IMoveable ?? throw new Exception("Movement component not found"); CMovement.RMovement = RMovement; - _healthAttribute = Attributes["EnemyAttributeSet.Health"]; - CDamageable = (GetNode("CDamageable") as IDamageable)!; - CHealth = (GetNode("CHealth") as IHealthable)!; - CKnockback = (GetNode("CKnockback") as IKnockbackable)!; + CDamageable = GetNode("CDamageable") as IDamageable ?? throw new Exception("Damageable component not found"); + CHealth = GetNode("CHealth") as IHealthable ?? throw new Exception("Health component not found"); + CKnockback = GetNode("CKnockback") as IKnockbackable ?? throw new Exception("Knockback component not found"); CHealth.RHealth = RHealth; CHealth.CurrentHealth = RHealth.StartingHealth; @@ -156,15 +155,16 @@ public partial class Enemy : CharacterBody3D, _hitAbilityHandle = Abilities.GrantAbilityPermanently(HitAbility.GetAbilityData(), 1, LevelComparison.None, this); } - + public void OnResolved() { - HealthBarWrapper.ResourceBar.Init(_healthAttribute); - // CuesManager.RegisterCue(Tag.RequestTag(TagsManager, "cues.enemy.health"), HealthBarWrapper.ResourceBar); + var healthAttribute = Attributes["CharacterAttributeSet.Health"]; + HealthBarWrapper.ResourceBar.Init(healthAttribute); + healthAttribute.OnValueChanged += OnHealthChanged; Events.Subscribe(Tag.RequestTag(TagsManager, "events.combat.hit"), data => {GD.Print("Hit!");}); - Events.Subscribe(Tag.RequestTag(TagsManager, "events.combat.damage"), OnDamageReceived); + Events.Subscribe(Tag.RequestTag(TagsManager, "events.combat.damage"), OnDamageReceived); Events.Subscribe(Tag.RequestTag(TagsManager, "events.combat.death"), OnDeath); } @@ -216,19 +216,25 @@ public partial class Enemy : CharacterBody3D, return CMovement is null ? Vector3.Zero : CMovement.ComputeVelocity(inputs); } - public void OnDamageReceived(EventData data) + public void OnDamageReceived(EventData data) { - var newHealth = _healthAttribute.CurrentValue + data.EventMagnitude; - if (newHealth > _healthAttribute.Min) return; + var source = data.Source as Node; + var sourceName = source?.Name ?? "unknown damage dealer"; + GD.Print($"Ouch! Fuck you {sourceName}!"); + if (data.Payload.OverkillDamage > 0) GD.Print($"Overkill! {data.Payload.OverkillDamage} damage"); + } + + private void OnHealthChanged(EntityAttribute healthAttribute, int i) + { + if (healthAttribute.CurrentValue > healthAttribute.Min) return; Events.Raise(new EventData { - EventTags = Tag.RequestTag(TagsManager, "events.combat.death").GetSingleTagContainer()!, - Source = data.Source, - Target = data.Target + EventTags = Tag.RequestTag(TagsManager, "events.combat.death").GetSingleTagContainer()! }); } + public void OnDeath(EventData data) { // Remove weapon that might be planted there diff --git a/scenes/enemies/flying_enemy/flying_enemy.tscn b/scenes/enemies/flying_enemy/flying_enemy.tscn index e56b216e..68f1bd34 100644 --- a/scenes/enemies/flying_enemy/flying_enemy.tscn +++ b/scenes/enemies/flying_enemy/flying_enemy.tscn @@ -12,17 +12,12 @@ [ext_resource type="PackedScene" uid="uid://dmw5ibwrb483f" path="res://scenes/components/movement/CFlyingMovement.tscn" id="7_vaeds"] [ext_resource type="PackedScene" uid="uid://bwx2um43k0ou4" path="res://scenes/components/health/CHealthbar.tscn" id="7_ykkxn"] [ext_resource type="Script" uid="uid://ccovd5i0wr3kk" path="res://addons/forge/editor/attributes/AttributeValues.cs" id="8_46wn3"] -[ext_resource type="Script" uid="uid://cw525n4mjqgw0" path="res://addons/forge/resources/ForgeTagContainer.cs" id="8_oj1ws"] +[ext_resource type="Resource" uid="uid://bocsykxbh8l0g" path="res://forge/resources/tag_containers/enemy_base_tags.tres" id="8_oj1ws"] [ext_resource type="Script" uid="uid://dtpxijlnb2c5" path="res://scenes/components/movement/RMovement.cs" id="8_on7rt"] [ext_resource type="Script" uid="uid://b0u23nkpaimyc" path="res://scenes/components/damage/CDamageable.cs" id="8_uotso"] [ext_resource type="PackedScene" uid="uid://bctpe34ddamg5" path="res://scenes/components/knockback/CKnockback.tscn" id="10_dejyg"] [ext_resource type="Resource" uid="uid://dt7a1io5o0b8s" path="res://scenes/enemies/flying_enemy/flying_enemy_knockback.tres" id="11_mpa2u"] -[sub_resource type="Resource" id="Resource_46wn3"] -script = ExtResource("8_oj1ws") -ContainerTags = Array[String](["character.enemy"]) -metadata/_custom_type_script = "uid://cw525n4mjqgw0" - [sub_resource type="Resource" id="Resource_wxisp"] script = ExtResource("8_46wn3") Default = 2 @@ -35,7 +30,7 @@ Default = 1 Min = 1 Max = 100 -[sub_resource type="ViewportTexture" id="ViewportTexture_oj1ws"] +[sub_resource type="ViewportTexture" id="ViewportTexture_46wn3"] viewport_path = NodePath("SubViewport") [sub_resource type="Resource" id="Resource_jnv07"] @@ -87,17 +82,15 @@ RMovement = ExtResource("4_dejyg") [node name="ForgeEntityNode" type="Node3D" parent="." unique_id=1255429192] script = ExtResource("7_46wn3") -BaseTags = SubResource("Resource_46wn3") +BaseTags = ExtResource("8_oj1ws") metadata/_custom_type_script = "uid://rpcbb54q4atx" -[node name="ForgeAttributeSet" type="Node" parent="ForgeEntityNode" unique_id=1840910245] +[node name="CharacterAttributeSet" type="Node" parent="ForgeEntityNode" unique_id=418635308] script = ExtResource("7_2digf") -AttributeSetClass = "EnemyAttributeSet" +AttributeSetClass = "CharacterAttributeSet" InitialAttributeValues = Dictionary[String, ExtResource("8_46wn3")]({ -"Health": Object(RefCounted,"script":ExtResource("8_46wn3"),"Default":50,"Min":0,"Max":50) -, -"Speed": SubResource("Resource_wxisp"), -"Strength": SubResource("Resource_yk4hc") +"Health": Object(RefCounted,"script":ExtResource("8_46wn3"),"Default":100,"Min":0,"Max":100) + }) metadata/_custom_type_script = "uid://cxihb42t2mfqi" @@ -110,6 +103,17 @@ InitialAttributeValues = Dictionary[String, ExtResource("8_46wn3")]({ }) metadata/_custom_type_script = "uid://cxihb42t2mfqi" +[node name="EnemyAttributeSet" type="Node" parent="ForgeEntityNode" unique_id=1840910245] +script = ExtResource("7_2digf") +AttributeSetClass = "EnemyAttributeSet" +InitialAttributeValues = Dictionary[String, ExtResource("8_46wn3")]({ +"Health": Object(RefCounted,"script":ExtResource("8_46wn3"),"Default":50,"Min":0,"Max":50) +, +"Speed": SubResource("Resource_wxisp"), +"Strength": SubResource("Resource_yk4hc") +}) +metadata/_custom_type_script = "uid://cxihb42t2mfqi" + [node name="CHealth" type="Node" parent="." unique_id=1717035166] script = ExtResource("4_ys4jv") RHealth = ExtResource("2_ma2bq") @@ -117,7 +121,7 @@ metadata/_custom_type_script = "uid://bjwrpv3jpsc1e" [node name="CHealthBar" parent="." unique_id=1635725931 instance=ExtResource("7_ykkxn")] transform = Transform3D(0.3, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.70000005, 0) -texture = SubResource("ViewportTexture_oj1ws") +texture = SubResource("ViewportTexture_46wn3") [node name="CDamageable" type="Node" parent="." unique_id=1785297232] script = ExtResource("8_uotso") diff --git a/scenes/enemies/grounded_enemy/grounded_enemy.tscn b/scenes/enemies/grounded_enemy/grounded_enemy.tscn index 08444d03..9aab203c 100644 --- a/scenes/enemies/grounded_enemy/grounded_enemy.tscn +++ b/scenes/enemies/grounded_enemy/grounded_enemy.tscn @@ -13,16 +13,11 @@ [ext_resource type="Script" uid="uid://rpcbb54q4atx" path="res://forge/ForgeEntityNode.cs" id="7_f22p3"] [ext_resource type="PackedScene" uid="uid://dbr7ioio158ew" path="res://scenes/components/movement/CGroundedMovement.tscn" id="7_qyswd"] [ext_resource type="Script" uid="uid://ccovd5i0wr3kk" path="res://addons/forge/editor/attributes/AttributeValues.cs" id="7_x50ya"] -[ext_resource type="Script" uid="uid://cw525n4mjqgw0" path="res://addons/forge/resources/ForgeTagContainer.cs" id="8_4jf2q"] +[ext_resource type="Resource" uid="uid://bocsykxbh8l0g" path="res://forge/resources/tag_containers/enemy_base_tags.tres" id="8_4jf2q"] [ext_resource type="Script" uid="uid://dtpxijlnb2c5" path="res://scenes/components/movement/RMovement.cs" id="8_6d4gl"] [ext_resource type="PackedScene" uid="uid://bctpe34ddamg5" path="res://scenes/components/knockback/CKnockback.tscn" id="10_jqqi6"] [ext_resource type="Resource" uid="uid://cektf6waf4s04" path="res://scenes/enemies/grounded_enemy/grounded_enemy_knockback.tres" id="11_8k3xb"] -[sub_resource type="Resource" id="Resource_4jf2q"] -script = ExtResource("8_4jf2q") -ContainerTags = Array[String](["character.enemy"]) -metadata/_custom_type_script = "uid://cw525n4mjqgw0" - [sub_resource type="Resource" id="Resource_x50ya"] script = ExtResource("7_x50ya") Default = 1 @@ -35,7 +30,7 @@ Default = 1 Min = 1 Max = 100 -[sub_resource type="ViewportTexture" id="ViewportTexture_ub34u"] +[sub_resource type="ViewportTexture" id="ViewportTexture_4jf2q"] viewport_path = NodePath("SubViewport") [sub_resource type="Resource" id="Resource_qj0ob"] @@ -87,17 +82,15 @@ RMovement = ExtResource("4_na24f") [node name="ForgeEntityNode" type="Node3D" parent="." unique_id=289553407] script = ExtResource("7_f22p3") -BaseTags = SubResource("Resource_4jf2q") +BaseTags = ExtResource("8_4jf2q") metadata/_custom_type_script = "uid://rpcbb54q4atx" -[node name="ForgeAttributeSet" type="Node" parent="ForgeEntityNode" unique_id=804252284] +[node name="CharacterAttributeSet" type="Node" parent="ForgeEntityNode" unique_id=1699781551] script = ExtResource("6_yk4hc") -AttributeSetClass = "EnemyAttributeSet" +AttributeSetClass = "CharacterAttributeSet" InitialAttributeValues = Dictionary[String, ExtResource("7_x50ya")]({ "Health": Object(RefCounted,"script":ExtResource("7_x50ya"),"Default":100,"Min":0,"Max":100) -, -"Speed": SubResource("Resource_x50ya"), -"Strength": SubResource("Resource_yk4hc") + }) metadata/_custom_type_script = "uid://cxihb42t2mfqi" @@ -110,6 +103,17 @@ InitialAttributeValues = Dictionary[String, ExtResource("7_x50ya")]({ }) metadata/_custom_type_script = "uid://cxihb42t2mfqi" +[node name="EnnemyAttributeSet" type="Node" parent="ForgeEntityNode" unique_id=804252284] +script = ExtResource("6_yk4hc") +AttributeSetClass = "EnemyAttributeSet" +InitialAttributeValues = Dictionary[String, ExtResource("7_x50ya")]({ +"Health": Object(RefCounted,"script":ExtResource("7_x50ya"),"Default":100,"Min":0,"Max":100) +, +"Speed": SubResource("Resource_x50ya"), +"Strength": SubResource("Resource_yk4hc") +}) +metadata/_custom_type_script = "uid://cxihb42t2mfqi" + [node name="CHealth" type="Node" parent="." unique_id=188153645] script = ExtResource("2_gsmti") RHealth = ExtResource("2_w4lm8") @@ -117,7 +121,7 @@ metadata/_custom_type_script = "uid://bjwrpv3jpsc1e" [node name="CHealthBar" parent="." unique_id=1278247727 instance=ExtResource("7_18xwy")] transform = Transform3D(0.4, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.2, 0) -texture = SubResource("ViewportTexture_ub34u") +texture = SubResource("ViewportTexture_4jf2q") [node name="CDamageable" type="Node" parent="." unique_id=1601518000] script = ExtResource("7_1tw73") diff --git a/scenes/player_controller/PlayerController.tscn b/scenes/player_controller/PlayerController.tscn index c1fe7fe4..1de3d8a8 100644 --- a/scenes/player_controller/PlayerController.tscn +++ b/scenes/player_controller/PlayerController.tscn @@ -62,7 +62,7 @@ [sub_resource type="Resource" id="Resource_mpigw"] script = ExtResource("2_u8yay") -ContainerTags = Array[String](["character.player"]) +ContainerTags = Array[String](["character.player", "traits.damageable"]) metadata/_custom_type_script = "uid://cw525n4mjqgw0" [sub_resource type="Resource" id="Resource_5gbhg"] @@ -72,7 +72,7 @@ metadata/_custom_type_script = "uid://dpakv7agvir6y" [sub_resource type="Resource" id="Resource_2rkt1"] script = ExtResource("11_u8yay") -Tag = "status.invincible" +Tag = "immunity.damage" metadata/_custom_type_script = "uid://dpakv7agvir6y" [sub_resource type="Resource" id="Resource_cb2lu"] @@ -224,6 +224,15 @@ InitialAttributeValues = Dictionary[String, ExtResource("11_2rkt1")]({ }) metadata/_custom_type_script = "uid://cxihb42t2mfqi" +[node name="CharaAttributeSet" type="Node" parent="." unique_id=2058864775] +script = ExtResource("10_pw5r7") +AttributeSetClass = "CharacterAttributeSet" +InitialAttributeValues = Dictionary[String, ExtResource("11_2rkt1")]({ +"Health": Object(RefCounted,"script":ExtResource("11_2rkt1"),"Default":100,"Min":0,"Max":100) + +}) +metadata/_custom_type_script = "uid://cxihb42t2mfqi" + [node name="MetaAttributeSet" type="Node" parent="." unique_id=1777903944] script = ExtResource("10_pw5r7") AttributeSetClass = "MetaAttributeSet" diff --git a/scenes/player_controller/scripts/PlayerController.cs b/scenes/player_controller/scripts/PlayerController.cs index bc629749..a7a4d3f3 100644 --- a/scenes/player_controller/scripts/PlayerController.cs +++ b/scenes/player_controller/scripts/PlayerController.cs @@ -26,6 +26,7 @@ using Movementtests.systems; using Movementtests.player_controller.Scripts; using Movementtests.managers; using Movementtests.tools; +using Movementtests.tools.calculators; using RustyOptions; using Node = Godot.Node; @@ -457,7 +458,7 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl // General use stuff Attributes = new EntityAttributes([.. ForgeUtils.CollectAttributeList(this)]); - HealthAttribute = Attributes["PlayerAttributeSet.Health"]; + HealthAttribute = Attributes["CharacterAttributeSet.Health"]; ManaAttribute = Attributes["PlayerAttributeSet.Mana"]; Tags = new(BaseTags.GetTagContainer()); @@ -666,6 +667,8 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl #endregion // Forge events + HealthAttribute.OnValueChanged += OnHealthChanged; + var weaponLeftToken = WeaponSystem.Events.Subscribe(WeaponSystem.WeaponStartedFlyingEventTag, OnWeaponLeft); var weaponLandedToken = WeaponSystem.Events.Subscribe(WeaponSystem.WeaponStoppedFlyingEventTag, OnWeaponLanded); } @@ -725,7 +728,7 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl }); } - Events.Subscribe(Tag.RequestTag(TagsManager, "events.combat.damage"), OnDamageReceived); + Events.Subscribe(Tag.RequestTag(TagsManager, "events.combat.damage"), OnDamageReceived); Events.Subscribe(Tag.RequestTag(TagsManager, "events.combat.death"), OnDeath); #endregion @@ -2642,9 +2645,19 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl } // Forge Damage handling - public void OnDamageReceived(EventData data) + private void OnHealthChanged(EntityAttribute healthAttribute, int i) + { + if (healthAttribute.CurrentValue > HealthAttribute.Min) return; + + var tagsManager = TagsManager; + Events.Raise(new EventData + { + EventTags = Tag.RequestTag(tagsManager, "events.combat.death").GetSingleTagContainer()!, + }); + } + + public void OnDamageReceived(EventData data) { - var newHealth = HealthAttribute.CurrentValue + data.EventMagnitude; CuesManager.ExecuteCue( Tag.RequestTag(TagsManager, "cues.resources.health"), this, @@ -2657,16 +2670,6 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl {"test", "hello"} }) ); - - if (newHealth > HealthAttribute.Min) return; - - var tagsManager = TagsManager; - Events.Raise(new EventData - { - EventTags = Tag.RequestTag(tagsManager, "events.combat.death").GetSingleTagContainer()!, - Source = data.Source, - Target = data.Target - }); } public void OnExecute(IForgeEntity? target, CueParameters? parameters) @@ -2674,7 +2677,7 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl if (target == null || !parameters.HasValue) return; float magnitude = parameters.Value.Magnitude; - if (magnitude >= 0) return; + if (magnitude <= 0) return; HeadSystem.OnGetHit(); _audioStream.SwitchToClipByName("damage_taken");