Setup empowered action as a Forge ability
This commit is contained in:
@@ -126,6 +126,7 @@
|
||||
<ItemGroup>
|
||||
<Folder Include="addons\" />
|
||||
<Folder Include="tests\" />
|
||||
<Folder Include="tools\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="RustyOptions" Version="0.10.1" />
|
||||
|
||||
@@ -13,15 +13,10 @@ public partial class ForgeManager : Node
|
||||
"class.warrior",
|
||||
"status.stunned",
|
||||
"status.burning",
|
||||
"status.enraged",
|
||||
"status.immune.fire",
|
||||
"cues.damage.fire",
|
||||
"events.combat.damage",
|
||||
"events.combat.hit",
|
||||
"cooldown.fireball"
|
||||
"cooldown.empoweredAction",
|
||||
]);
|
||||
|
||||
public ForgeManager()
|
||||
{
|
||||
}
|
||||
}
|
||||
56
forge/abilities/EmpoweredActionBehavior.cs
Normal file
56
forge/abilities/EmpoweredActionBehavior.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Gamesmiths.Forge.Abilities;
|
||||
using Gamesmiths.Forge.Effects;
|
||||
using Gamesmiths.Forge.Effects.Components;
|
||||
using Gamesmiths.Forge.Effects.Duration;
|
||||
using Gamesmiths.Forge.Effects.Magnitudes;
|
||||
using Gamesmiths.Forge.Effects.Modifiers;
|
||||
using Gamesmiths.Forge.Tags;
|
||||
|
||||
namespace Movementtests.forge.abilities;
|
||||
|
||||
public class EmpoweredAction(TagsManager tagsManager)
|
||||
{
|
||||
public EffectData EmpoweredActionCostEffect = new(
|
||||
"Empowered Action Mana Cost",
|
||||
new DurationData(DurationType.Instant),
|
||||
new[] {
|
||||
new Modifier(
|
||||
"PlayerAttributeSet.Mana",
|
||||
ModifierOperation.FlatBonus,
|
||||
new ModifierMagnitude(
|
||||
MagnitudeCalculationType.ScalableFloat,
|
||||
new ScalableFloat(-20)
|
||||
)
|
||||
)
|
||||
});
|
||||
|
||||
public EffectData EmpoweredActionCooldown = new(
|
||||
"Empowered Action Cooldown",
|
||||
new DurationData(
|
||||
DurationType.HasDuration,
|
||||
new ModifierMagnitude(
|
||||
MagnitudeCalculationType.ScalableFloat,
|
||||
new ScalableFloat(1.0f))),
|
||||
effectComponents: new[] {
|
||||
new ModifierTagsEffectComponent(
|
||||
tagsManager.RequestTagContainer(new[] { "cooldown.empoweredAction" })
|
||||
)
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class EmpoweredActionBehavior : IAbilityBehavior
|
||||
{
|
||||
public void OnStarted(AbilityBehaviorContext context)
|
||||
{
|
||||
// Apply costs and cooldowns
|
||||
context.AbilityHandle.CommitAbility();
|
||||
context.InstanceHandle.End();
|
||||
}
|
||||
|
||||
public void OnEnded(AbilityBehaviorContext context)
|
||||
{
|
||||
// Do any necessary cleanups
|
||||
}
|
||||
}
|
||||
1
forge/abilities/EmpoweredActionBehavior.cs.uid
Normal file
1
forge/abilities/EmpoweredActionBehavior.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://d0l07gcx1ef18
|
||||
@@ -1,7 +1,14 @@
|
||||
using System;
|
||||
using Gamesmiths.Forge.Core;
|
||||
using Gamesmiths.Forge.Effects;
|
||||
using Gamesmiths.Forge.Events;
|
||||
using Gamesmiths.Forge.Tags;
|
||||
using Godot;
|
||||
using Movementtests.interfaces;
|
||||
using Movementtests.scenes.enemies;
|
||||
using Movementtests.scenes.player_controller.scripts;
|
||||
using Movementtests.systems;
|
||||
using Movementtests.tools;
|
||||
|
||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_beetle.png")]
|
||||
public partial class Enemy : CharacterBody3D,
|
||||
@@ -13,7 +20,8 @@ public partial class Enemy : CharacterBody3D,
|
||||
ISpawnable,
|
||||
IKnockbackable,
|
||||
ITargetable,
|
||||
IStunnable
|
||||
IStunnable,
|
||||
IForgeEntity
|
||||
{
|
||||
// Signals and events
|
||||
public event Action<IDamageable, DamageRecord> DamageTaken = null!;
|
||||
@@ -55,6 +63,12 @@ public partial class Enemy : CharacterBody3D,
|
||||
set => CHealth.CurrentHealth = value;
|
||||
}
|
||||
|
||||
public EntityAttributes Attributes { get; set; } = null!;
|
||||
public EntityTags Tags { get; set; } = null!;
|
||||
public EffectsManager EffectsManager { get; set; } = null!;
|
||||
public EntityAbilities Abilities { get; set; } = null!;
|
||||
public EventManager Events { get; set; } = null!;
|
||||
|
||||
// Private stuff
|
||||
private Area3D _damageBox = null!;
|
||||
internal Node3D _target = null!;
|
||||
@@ -71,6 +85,21 @@ public partial class Enemy : CharacterBody3D,
|
||||
_damageBox = GetNode<Area3D>("DamageBox");
|
||||
_target = GetNode<Node3D>("CTarget");
|
||||
|
||||
// Forge stuff
|
||||
var forgeManager = GetTree().Root.GetNode<ForgeManager>("ForgeManager")!;
|
||||
var baseTags = new TagContainer(
|
||||
forgeManager.TagsManager,
|
||||
[
|
||||
Tag.RequestTag(forgeManager.TagsManager, "character.player"),
|
||||
Tag.RequestTag(forgeManager.TagsManager, "class.warrior")
|
||||
]);
|
||||
|
||||
Attributes = new EntityAttributes(new EnemyAttributeSet());
|
||||
Tags = new EntityTags(baseTags);
|
||||
EffectsManager = new EffectsManager(this, forgeManager.CuesManager);
|
||||
Abilities = new(this);
|
||||
Events = new();
|
||||
|
||||
CDamageable = (GetNode<Node>("CDamageable") as IDamageable)!;
|
||||
CMovement = (GetNode<Node>("CMovement") as IMoveable)!;
|
||||
CHealth = (GetNode<Node>("CHealth") as IHealthable)!;
|
||||
|
||||
16
scenes/enemies/EnemyAttributeSet.cs
Normal file
16
scenes/enemies/EnemyAttributeSet.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
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, 150);
|
||||
Strength = InitializeAttribute(nameof(Strength), 10, 0, 99);
|
||||
Speed = InitializeAttribute(nameof(Speed), 5, 0, 10);
|
||||
}
|
||||
}
|
||||
1
scenes/enemies/EnemyAttributeSet.cs.uid
Normal file
1
scenes/enemies/EnemyAttributeSet.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://nqxdkkg3l7go
|
||||
@@ -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);
|
||||
|
||||
@@ -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")]
|
||||
@@ -399,6 +407,8 @@ public partial class PlayerController : CharacterBody3D,
|
||||
private RayCast3D _aimAssisRayCast = null!;
|
||||
private Camera3D _camera = null!;
|
||||
|
||||
private AbilityHandle? _empoweredActionHandle;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
LoadSettings();
|
||||
@@ -429,11 +439,25 @@ public partial class PlayerController : CharacterBody3D,
|
||||
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--;
|
||||
|
||||
Reference in New Issue
Block a user