knockback forge implemented

This commit is contained in:
2026-05-04 16:22:30 +02:00
parent b2b7baffe8
commit a139990390
21 changed files with 194 additions and 70 deletions

View File

@@ -6,20 +6,27 @@ using Godot;
namespace Movementtests.forge.abilities;
public record SimpleHitEffectData(Vector3 SourceLocation, Vector3 TargetLocation);
public class SimpleHitBehavior(ForgeEffectData? damage) : IAbilityBehavior
{
public void OnStarted(AbilityBehaviorContext context)
{
if (context.Target == null || damage == null) return;
var effect = new Effect(damage.GetEffectData(), new EffectOwnership(context.Owner, context.Owner));
context.Target.EffectsManager.ApplyEffect(effect);
var sourceLocation = (context.Source as Node3D)?.GlobalPosition ?? Vector3.Zero;
var targetLocation = (context.Target as Node3D)?.GlobalPosition ?? Vector3.Zero;
context.AbilityHandle.CommitAbility();
context.InstanceHandle.End();
var effect = new Effect(damage.GetEffectData(), new EffectOwnership(context.Owner, context.Owner));
context.Target.EffectsManager.ApplyEffect(effect, new SimpleHitEffectData(sourceLocation, targetLocation));
// context.InstanceHandle.End();
}
public void OnEnded(AbilityBehaviorContext context) {}
public void OnEnded(AbilityBehaviorContext context)
{
context.AbilityHandle.CommitAbility();
}
}
[Tool]

View File

@@ -0,0 +1,102 @@
using System.Collections.Generic;
using Gamesmiths.Forge.Core;
using Gamesmiths.Forge.Effects;
using Gamesmiths.Forge.Effects.Calculator;
using Gamesmiths.Forge.Effects.Magnitudes;
using Gamesmiths.Forge.Events;
using Gamesmiths.Forge.Godot.Resources;
using Gamesmiths.Forge.Godot.Resources.Calculators;
using Godot;
using Movementtests.forge.abilities;
using Movementtests.scenes.components.knockback;
namespace Movementtests.tools.calculators;
public record KnockbackDone(float KnockbackValue, Vector3 knockbackDirection);
public class KnockbackExecution : CustomExecution
{
private readonly RKnockback _knockback;
private readonly ForgeTag _knockbackTag;
private readonly ForgeTagContainer? _knockbackReceiverEventTags;
private readonly ForgeTagContainer? _knockbackDealerEventTags;
public AttributeCaptureDefinition TargetIncomingDamage { get; }
public KnockbackExecution(ForgeTag knockbackTag, RKnockback knockback, ForgeTagContainer? knockbackDealerEventTags, ForgeTagContainer? knockbackReceiverEventTags)
{
_knockback = knockback;
_knockbackTag = knockbackTag;
_knockbackDealerEventTags = knockbackDealerEventTags;
_knockbackReceiverEventTags = knockbackReceiverEventTags;
TargetIncomingDamage = new AttributeCaptureDefinition(
"MetaAttributeSet.IncomingDamage",
AttributeCaptureSource.Target);
AttributesToCapture.Add(TargetIncomingDamage);
}
public override ModifierEvaluatedData[] EvaluateExecution(Effect effect, IForgeEntity target, EffectEvaluatedData? effectEvaluatedData)
{
var results = new List<ModifierEvaluatedData>();
if (!target.Tags.CombinedTags.HasTag(_knockbackTag.GetTag()))
return [.. results];
float targetIncomingDamage = CaptureAttributeMagnitude(
TargetIncomingDamage,
effect,
target,
effectEvaluatedData);
if (targetIncomingDamage <= 0)
return [.. results];
var knockbackValue = _knockback.Modifier * targetIncomingDamage / 100.0f;
if (_knockbackReceiverEventTags is null)
return [.. results];
var knockbackDirection = Vector3.Zero;
if (effectEvaluatedData?.TryGetContextData(out SimpleHitEffectData? hitEffectData) == true)
{
knockbackDirection = hitEffectData.SourceLocation.DirectionTo(hitEffectData.TargetLocation);
}
target.Events.Raise(new EventData<KnockbackDone>
{
EventTags = _knockbackReceiverEventTags.GetTagContainer(),
Source = effect.Ownership.Owner,
Target = target,
EventMagnitude = knockbackValue,
Payload = new KnockbackDone(knockbackValue, knockbackDirection)
});
if (effect.Ownership.Source is null || _knockbackDealerEventTags is null)
return [.. results];
effect.Ownership.Source.Events.Raise(new EventData<KnockbackDone>
{
EventTags = _knockbackDealerEventTags.GetTagContainer(),
Source = effect.Ownership.Owner,
Target = target,
EventMagnitude = knockbackValue,
Payload = new KnockbackDone(knockbackValue, knockbackDirection)
});
return [.. results];
}
}
[GlobalClass]
public partial class ForgeKnockbackExecution : ForgeCustomExecution
{
[Export] public ForgeTag? KnockbackableTag { get; set; }
[Export] public RKnockback? Knockback { get; set; }
[Export] public ForgeTagContainer? KnockbackDealerEventTags { get; set; }
[Export] public ForgeTagContainer? KnockbackReceiverEventTags { get; set; }
public override CustomExecution GetExecutionClass()
{
if (Knockback == null || KnockbackableTag == null) throw new System.ArgumentException("Knockback or KnockbackableTag is null");
return new KnockbackExecution(KnockbackableTag, Knockback, KnockbackDealerEventTags, KnockbackReceiverEventTags);
}
}

View File

@@ -0,0 +1 @@
uid://diondfg5xp78h

View File

@@ -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"])
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"])

View File

@@ -8,6 +8,7 @@
[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"]
@@ -63,7 +64,7 @@ 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")])
Executions = Array[Object]([ExtResource("2_l5emy"), ExtResource("3_l5emy")])
StackLimit = SubResource("Resource_8fbeq")
InitialStack = SubResource("Resource_0cyim")
Cues = []

View File

@@ -0,0 +1,20 @@
[gd_resource type="Resource" script_class="ForgeKnockbackExecution" format=3 uid="uid://cc1qrmbp12fk8"]
[ext_resource type="Script" uid="uid://b44cse62qru7j" path="res://scenes/components/knockback/RKnockback.cs" id="1_kcl5u"]
[ext_resource type="Resource" uid="uid://bhn27s8ne0uyg" path="res://forge/resources/tag_containers/on_knockback_dealt.tres" id="2_oqtq1"]
[ext_resource type="Resource" uid="uid://bkr6uu57wm3o3" path="res://forge/resources/tag_containers/on_knockback_received.tres" id="3_1va1b"]
[ext_resource type="Resource" uid="uid://45l7vnfs72b" path="res://forge/resources/tag_containers/knockbackable_tag.tres" id="4_0i0oh"]
[ext_resource type="Script" uid="uid://diondfg5xp78h" path="res://forge/calculators/ForgeKnockbackExecution.cs" id="5_babc1"]
[sub_resource type="Resource" id="Resource_6x2ov"]
script = ExtResource("1_kcl5u")
Modifier = 50.0
metadata/_custom_type_script = "uid://b44cse62qru7j"
[resource]
script = ExtResource("5_babc1")
KnockbackableTag = ExtResource("4_0i0oh")
Knockback = SubResource("Resource_6x2ov")
KnockbackDealerEventTags = ExtResource("2_oqtq1")
KnockbackReceiverEventTags = ExtResource("3_1va1b")
metadata/_custom_type_script = "uid://diondfg5xp78h"

View File

@@ -4,5 +4,5 @@
[resource]
script = ExtResource("1_kdy2b")
ContainerTags = Array[String](["character.enemy", "traits.damageable"])
ContainerTags = Array[String](["character.enemy", "traits.damageable", "traits.knockbackable"])
metadata/_custom_type_script = "uid://cw525n4mjqgw0"

View File

@@ -0,0 +1,8 @@
[gd_resource type="Resource" script_class="ForgeTag" format=3 uid="uid://45l7vnfs72b"]
[ext_resource type="Script" uid="uid://dpakv7agvir6y" path="res://addons/forge/resources/ForgeTag.cs" id="1_1cy5u"]
[resource]
script = ExtResource("1_1cy5u")
Tag = "traits.knockbackable"
metadata/_custom_type_script = "uid://dpakv7agvir6y"

View File

@@ -0,0 +1,8 @@
[gd_resource type="Resource" script_class="ForgeTagContainer" format=3 uid="uid://bhn27s8ne0uyg"]
[ext_resource type="Script" uid="uid://cw525n4mjqgw0" path="res://addons/forge/resources/ForgeTagContainer.cs" id="1_kgxiq"]
[resource]
script = ExtResource("1_kgxiq")
ContainerTags = Array[String](["events.combat.knockback_dealt"])
metadata/_custom_type_script = "uid://cw525n4mjqgw0"

View File

@@ -0,0 +1,8 @@
[gd_resource type="Resource" script_class="ForgeTagContainer" format=3 uid="uid://bkr6uu57wm3o3"]
[ext_resource type="Script" uid="uid://cw525n4mjqgw0" path="res://addons/forge/resources/ForgeTagContainer.cs" id="1_ro1gp"]
[resource]
script = ExtResource("1_ro1gp")
ContainerTags = Array[String](["events.combat.knockback_received"])
metadata/_custom_type_script = "uid://cw525n4mjqgw0"