Setup empowered action as a Forge ability

This commit is contained in:
2026-03-10 09:22:39 +01:00
parent 9d612682ec
commit 14d29d68bb
10 changed files with 168 additions and 9 deletions

View File

@@ -11,7 +11,6 @@ public class PlayerAttributeSet : AttributeSet
public PlayerAttributeSet()
{
// Initialize the attributes with the current, min and max values.
Health = InitializeAttribute(nameof(Health), 100, 0, 150);
Mana = InitializeAttribute(nameof(Mana), 100, 0, 100);
Strength = InitializeAttribute(nameof(Strength), 10, 0, 99);

View File

@@ -1,17 +1,25 @@
using System;
using System.Collections.Generic;
using Gamesmiths.Forge.Abilities;
using Gamesmiths.Forge.Core;
using Gamesmiths.Forge.Effects;
using Gamesmiths.Forge.Effects.Components;
using Gamesmiths.Forge.Effects.Duration;
using Gamesmiths.Forge.Effects.Magnitudes;
using Gamesmiths.Forge.Events;
using Gamesmiths.Forge.Tags;
using Godot;
using GodotStateCharts;
using Movementtests.addons.godot_state_charts.csharp;
using Movementtests.interfaces;
using Movementtests.systems;
using Movementtests.player_controller.Scripts;
using Movementtests.scenes.player_controller.scripts;
using Movementtests.tools;
using Movementtests.forge.abilities;
using RustyOptions;
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_character.png")]
@@ -398,6 +406,8 @@ public partial class PlayerController : CharacterBody3D,
private ShapeCast3D _closeEnemyDetector = null!;
private RayCast3D _aimAssisRayCast = null!;
private Camera3D _camera = null!;
private AbilityHandle? _empoweredActionHandle;
public override void _Ready()
{
@@ -428,12 +438,26 @@ public partial class PlayerController : CharacterBody3D,
EffectsManager = new EffectsManager(this, forgeManager.CuesManager);
Abilities = new(this);
Events = new();
var empoweredAction = new EmpoweredAction(forgeManager.TagsManager);
var empoweredActionData = new AbilityData(
name: "Empowered Action",
costEffect: empoweredAction.EmpoweredActionCostEffect,
cooldownEffects: [empoweredAction.EmpoweredActionCooldown],
instancingPolicy: AbilityInstancingPolicy.PerEntity,
behaviorFactory: () => new EmpoweredActionBehavior());
// Grant permanently
_empoweredActionHandle = Abilities.GrantAbilityPermanently(
empoweredActionData,
abilityLevel: 1,
levelOverridePolicy: LevelComparison.None,
sourceEntity: this);
var health = Attributes["PlayerAttributeSet.Health"].CurrentValue; // 100
var mana = Attributes["PlayerAttributeSet.Mana"].CurrentValue; // 100
var strength = Attributes["PlayerAttributeSet.Strength"].CurrentValue; // 10
var speed = Attributes["PlayerAttributeSet.Speed"].CurrentValue; // 5
GD.Print(health, mana, strength, speed);
// DashIndicator = GetNode<TextureRect>("%DashIndicator");
PowerCooldownIndicator = GetNode<ColorRect>("%DashCooldownIndicator");
@@ -1913,10 +1937,47 @@ public partial class PlayerController : CharacterBody3D,
public bool CanPerformEmpoweredAction()
{
if(_empoweredActionHandle == null) return false;
var cooldowns = _empoweredActionHandle.GetCooldownData();
foreach (var cd in cooldowns)
{
//GD.Print($"Cooldown remaining: {cd.RemainingTime}");
}
var costs = _empoweredActionHandle.GetCostData();
foreach (var cost in costs)
{
// Assuming you want to check Mana costs
if (cost.Attribute == "PlayerAttributeSet.Mana")
{
//GD.Print($"Mana Cost: {cost.Cost}");
}
}
var canActivate = _empoweredActionHandle.CanActivate(out var failures);
if (!canActivate)
{
GD.PrintErr($"Cannot activate empowered action: {failures}");
if (failures.HasFlag(AbilityActivationFailures.Cooldown)) GD.PrintErr("In Cooldown");
if (failures.HasFlag(AbilityActivationFailures.InsufficientResources)) GD.PrintErr("Not Enough Mana");
}
return canActivate;
return EmpoweredActionsLeft > 0 && TutorialDone;
}
public void PerformEmpoweredAction()
{
if(_empoweredActionHandle == null) return;
var canActivate = _empoweredActionHandle.Activate(out var failures);
if (!canActivate)
{
GD.PrintErr($"Cannot activate empowered action: {failures}");
if (failures.HasFlag(AbilityActivationFailures.Cooldown)) GD.PrintErr("In Cooldown");
if (failures.HasFlag(AbilityActivationFailures.InsufficientResources)) GD.PrintErr("Not Enough Mana");
}
else
{
GD.Print($"Remaining mana: {Attributes["PlayerAttributeSet.Mana"].CurrentValue}");
}
_isWallJumpAvailable = true;
_canDashAirborne = true;
EmpoweredActionsLeft--;