updating mana through cues

This commit is contained in:
2026-03-18 16:59:52 +01:00
parent 4bcbda9690
commit d1f83525b1
5 changed files with 82 additions and 19 deletions

View File

@@ -10,13 +10,10 @@ public partial class ForgeManager : Node
public TagsManager TagsManager { get; private set; } = new TagsManager(
[
"character.player",
"class.warrior",
"status.stunned",
"status.burning",
"status.immune.fire",
"cues.damage.fire",
"events.combat.damage",
"events.combat.hit",
"cooldown.empoweredAction",
"cues.resources.mana",
]);
}

View File

@@ -1,4 +1,5 @@
using Gamesmiths.Forge.Abilities;
using Gamesmiths.Forge.Cues;
using Gamesmiths.Forge.Effects;
using Gamesmiths.Forge.Effects.Components;
using Gamesmiths.Forge.Effects.Duration;
@@ -25,7 +26,7 @@ public partial class REmpoweredAction(float cost, float cooldown, float manaRege
{
}
public EffectData CostEffect()
public EffectData CostEffect(TagsManager tagsManager)
{
return new(
"Empowered Action Mana Cost",
@@ -40,6 +41,16 @@ public partial class REmpoweredAction(float cost, float cooldown, float manaRege
new ScalableFloat(-Cost)
)
)
},
cues: new []
{
new CueData(
CueTags: Tag.RequestTag(tagsManager, "cues.resources.mana").GetSingleTagContainer(),
MinValue: 0,
MaxValue: 100,
MagnitudeType: CueMagnitudeType.AttributeValueChange,
MagnitudeAttribute: "PlayerAttributeSet.Mana"
)
});
}

View File

@@ -1,8 +1,10 @@
using Gamesmiths.Forge.Cues;
using Gamesmiths.Forge.Effects;
using Gamesmiths.Forge.Effects.Duration;
using Gamesmiths.Forge.Effects.Magnitudes;
using Gamesmiths.Forge.Effects.Modifiers;
using Gamesmiths.Forge.Effects.Periodic;
using Gamesmiths.Forge.Tags;
using Godot;
namespace Movementtests.tools.effects;
@@ -20,7 +22,7 @@ public partial class RManaRegen(float manaRegenRate, float frequency) : Resource
{
}
public EffectData ManaRegen()
public EffectData ManaRegen(TagsManager tagsManager)
{
return new EffectData(
"Mana Regen",
@@ -36,6 +38,16 @@ public partial class RManaRegen(float manaRegenRate, float frequency) : Resource
new ScalableFloat(ManaRegenRate * Frequency))
)
],
cues: new []
{
new CueData(
CueTags: Tag.RequestTag(tagsManager, "cues.resources.mana").GetSingleTagContainer(),
MinValue: 0,
MaxValue: 100,
MagnitudeType: CueMagnitudeType.AttributeValueChange,
MagnitudeAttribute: "PlayerAttributeSet.Mana"
)
},
periodicData: new PeriodicData(
Period: new ScalableFloat(Frequency),
ExecuteOnApplication: true,

View File

@@ -1,9 +1,13 @@
using Godot;
using System;
using Gamesmiths.Forge.Core;
using Gamesmiths.Forge.Cues;
using Gamesmiths.Forge.Tags;
using Movementtests.interfaces;
using Movementtests.tools;
[GlobalClass, Icon("res://assets/ui/IconGodotNode/control/icon_text_panel.png")]
public partial class PlayerUi : Control
public partial class PlayerUi : Control, ICueHandler
{
internal TextureRect[] DashIcons = new TextureRect[3];
private TextureRect _enemyTarget = null!;
@@ -33,11 +37,17 @@ public partial class PlayerUi : Control
_enemyTarget = GetNode<TextureRect>("%EnemyTarget");
_healthbar = GetNode<Healthbar>("%Healthbar");
_manabar = GetNode<Healthbar>("%Manabar");
var forgeManager = GetTree().Root.GetNode<ForgeManager>("ForgeManager")!;
var tagsManager = forgeManager.TagsManager;
var cuesManager = forgeManager.CuesManager;
cuesManager.RegisterCue(Tag.RequestTag(tagsManager, "cues.resources.mana"), this);
}
public void Initialize(float initialHealth)
public void Initialize(float initialHealth, float initialMana)
{
_healthbar.Initialize(initialHealth);
_manabar.Initialize(initialMana);
}
public void SetEnemyTargetProperties(TargetProperties targetProperties)
@@ -77,4 +87,38 @@ public partial class PlayerUi : Control
{
_manabar.CurrentHealth = newValue;
}
public void OnExecute(IForgeEntity? target, CueParameters? parameters)
{
// One-shot effect (like impact)
// Called when an instant effect with this cue is applied
// Also called when a periodic effect with this cue executes its period
if (target == null || !parameters.HasValue) return;
// Extract parameters
float magnitude = parameters.Value.Magnitude;
float normalizedMagnitude = parameters.Value.NormalizedMagnitude;
// Play effects scaled by magnitude
// PlayFireImpactSound(normalizedMagnitude);
// SpawnFireImpactParticles(target, magnitude);
GD.Print(_manabar.CurrentHealth);
_manabar.CurrentHealth += magnitude;
}
public void OnApply(IForgeEntity? target, CueParameters? parameters)
{
return;
}
public void OnRemove(IForgeEntity? target, bool interrupted)
{
return;
}
public void OnUpdate(IForgeEntity? target, CueParameters? parameters)
{
return;
}
}

View File

@@ -433,8 +433,7 @@ public partial class PlayerController : CharacterBody3D,
var baseTags = new TagContainer(
forgeManager.TagsManager,
[
Tag.RequestTag(forgeManager.TagsManager, "character.player"),
Tag.RequestTag(forgeManager.TagsManager, "class.warrior")
Tag.RequestTag(forgeManager.TagsManager, "character.player")
]);
Attributes = new EntityAttributes(new PlayerAttributeSet());
@@ -445,7 +444,7 @@ public partial class PlayerController : CharacterBody3D,
var empoweredActionData = new AbilityData(
name: "Empowered Action",
costEffect: EmpoweredAction.CostEffect(),
costEffect: EmpoweredAction.CostEffect(forgeManager.TagsManager),
cooldownEffects: [EmpoweredAction.CooldownEffect(forgeManager.TagsManager)],
instancingPolicy: AbilityInstancingPolicy.PerEntity,
behaviorFactory: () => new EmpoweredActionBehavior());
@@ -457,7 +456,7 @@ public partial class PlayerController : CharacterBody3D,
levelOverridePolicy: LevelComparison.None,
sourceEntity: this);
var manaRegenEffect = new Effect(ManaRegen.ManaRegen(), new EffectOwnership(this, this));
var manaRegenEffect = new Effect(ManaRegen.ManaRegen(forgeManager.TagsManager), new EffectOwnership(this, this));
_manaRegenEffectHandle = EffectsManager.ApplyEffect(manaRegenEffect);
var health = Attributes["PlayerAttributeSet.Health"].CurrentValue; // 100
@@ -529,7 +528,7 @@ public partial class PlayerController : CharacterBody3D,
}
if (RKnockback != null) CKnockback!.RKnockback = RKnockback;
PlayerUi.Initialize(CHealth.CurrentHealth);
PlayerUi.Initialize(CHealth.CurrentHealth, Attributes["PlayerAttributeSet.Mana"].BaseValue);
CDamageable.DamageTaken += (damageable, record) => ReduceHealth(damageable, record);
CDamageable.DamageTaken += (_, record) => RegisterKnockback(new KnockbackRecord(record));
CHealth.HealthChanged += PlayerUi.OnHealthChanged;
@@ -765,7 +764,7 @@ public partial class PlayerController : CharacterBody3D,
{
RHealth.StartingHealth = newHealthValue;
CHealth!.CurrentHealth = newHealthValue;
PlayerUi.Initialize(CHealth.CurrentHealth);
PlayerUi.Initialize(CHealth.CurrentHealth, Attributes["PlayerAttributeSet.Mana"].BaseValue);
}
public void SetPlayerDamageOverride(float newDamageValue)
{
@@ -2309,7 +2308,7 @@ public partial class PlayerController : CharacterBody3D,
HandleEnemyTargeting();
}
private float _oldMana = 100;
// private float _oldMana = 100;
public override void _Process(double delta)
{
// Manage head and camera movement
@@ -2317,10 +2316,10 @@ public partial class PlayerController : CharacterBody3D,
EffectsManager.UpdateEffects(delta);
// TODO: change for actual Cue
var currentMana = Attributes["PlayerAttributeSet.Mana"].CurrentValue;
if (Mathf.Abs(currentMana - _oldMana) > Mathf.Epsilon)
PlayerUi.OnManaChanged(currentMana);
_oldMana = currentMana;
// var currentMana = Attributes["PlayerAttributeSet.Mana"].CurrentValue;
// if (Mathf.Abs(currentMana - _oldMana) > Mathf.Epsilon)
// PlayerUi.OnManaChanged(currentMana);
// _oldMana = currentMana;
}
///////////////////////////