Inventory management of granted abilities

This commit is contained in:
2026-04-21 11:38:04 +02:00
parent 667d6b2588
commit b0fe2549ea
18 changed files with 322 additions and 92 deletions

View File

@@ -240,9 +240,9 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
Events.Subscribe(WeaponStoppedFlyingEventTag, _ => { _weaponFlyingAbility.Cancel(); });
}
private List<ActiveEffectHandle> _grantedWeaponStartedFlyingAbilities = new List<ActiveEffectHandle>();
private List<ActiveEffectHandle> _grantedWeaponStoppedFlyingAbilities = new List<ActiveEffectHandle>();
private List<ActiveEffectHandle> _grantedWeaponFlyingTickAbilities = new List<ActiveEffectHandle>();
private Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> _grantedWeaponStartedFlyingAbilities = new ();
private Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> _grantedWeaponStoppedFlyingAbilities = new ();
private Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> _grantedWeaponFlyingTickAbilities = new ();
public enum WeaponEvent
{
@@ -253,12 +253,9 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
public void GrantNewAbilityForEvent(WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
{
var abilitiesMap = new Dictionary<WeaponEvent, List<ActiveEffectHandle>>
{
{ WeaponEvent.StartedFlying, _grantedWeaponStartedFlyingAbilities },
{ WeaponEvent.StoppedFlying, _grantedWeaponStoppedFlyingAbilities },
{ WeaponEvent.FlyingTick, _grantedWeaponFlyingTickAbilities },
};
var relevantMap = GetGrantedAbilities(forEvent);
GD.Print($"Granted {abilityBehavior} for {forEvent}");
if (relevantMap.ContainsKey(abilityBehavior)) return;
var eventTagsMap = new Dictionary<WeaponEvent, Tag>
{
@@ -288,10 +285,28 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
effectComponents: [leftGrantComponent]);
var effectHandle = EffectsManager.ApplyEffect(new Effect(leftGrantEffect, new EffectOwnership(this, this)));
if (effectHandle == null) return;
abilitiesMap[forEvent].Add(effectHandle);
relevantMap[abilityBehavior] = effectHandle;
}
public void RemoveAbilityForEvent(WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
{
var relevantMap = GetGrantedAbilities(forEvent);
if (!relevantMap.TryGetValue(abilityBehavior, out var effectHandle)) return;
EffectsManager.RemoveEffect(effectHandle);
relevantMap.Remove(abilityBehavior);
}
public Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> GetGrantedAbilities(WeaponEvent forEvent)
{
var abilitiesMap = new Dictionary<WeaponEvent, Dictionary<ForgeAbilityBehavior, ActiveEffectHandle>>
{
{ WeaponEvent.StartedFlying, _grantedWeaponStartedFlyingAbilities },
{ WeaponEvent.StoppedFlying, _grantedWeaponStoppedFlyingAbilities },
{ WeaponEvent.FlyingTick, _grantedWeaponFlyingTickAbilities },
};
return abilitiesMap[forEvent];
}
public void WeaponLeft()
{

View File

@@ -2,7 +2,11 @@
[ext_resource type="PackedScene" uid="uid://duju3atqgltkg" path="res://scenes/explosion/explosion.tscn" id="1_mnals"]
[ext_resource type="Script" uid="uid://bnee6amtc2bhj" path="res://forge/abilities/ForgeExplodingSwordBehavior.cs" id="1_ot53g"]
[ext_resource type="Texture2D" uid="uid://c2akxlg7tdb67" path="res://assets/ui/IconGodotNode/node/icon_projectile.png" id="2_l3coe"]
[resource]
script = ExtResource("1_ot53g")
Explosion = ExtResource("1_mnals")
Name = "Exploding Sword"
Description = "Make the sword explode"
Icon = ExtResource("2_l3coe")

View File

@@ -6,4 +6,5 @@
[resource]
script = ExtResource("2_f5qgs")
EffectData = ExtResource("1_hlq5f")
Name = "Flying tick application"
metadata/_custom_type_script = "uid://cl5hudinl1rex"

View File

@@ -717,7 +717,8 @@ public partial class PlayerController : CharacterBody3D,
_parryDash.StateEntered += OnDashParryStarted;
// Inventory Management
InventoryManager.Instance.WeaponEventInventoryChanged += OnWeaponEventInventoryChanged;
InventoryManager.Instance.WeaponEventAbilityAdded += OnWeaponEventAbilityAdded;
InventoryManager.Instance.WeaponEventAbilityRemoved += OnWeaponEventAbilityRemoved;
// Forge events
var weaponLeftToken = WeaponSystem.Events.Subscribe(WeaponSystem.WeaponStartedFlyingEventTag, OnWeaponLeft);
@@ -751,9 +752,18 @@ public partial class PlayerController : CharacterBody3D,
out var failures);
}
public void OnWeaponEventInventoryChanged(WeaponEventInventoryChangedData data)
public void OnWeaponEventAbilityAdded(WeaponEventAbilityData data)
{
WeaponSystem.GrantNewAbilityForEvent(data.ForEvent, WeaponExplosionBehavior);
if (data.Ability is not ForgeAbilityBehavior abilityBehavior) return;
WeaponSystem.GrantNewAbilityForEvent(data.ForEvent, abilityBehavior);
}
public void OnWeaponEventAbilityRemoved(WeaponEventAbilityData data)
{
if (data.Ability is not ForgeAbilityBehavior abilityBehavior) return;
WeaponSystem.RemoveAbilityForEvent(data.ForEvent, abilityBehavior);
}
///////////////////////////
@@ -1162,7 +1172,7 @@ public partial class PlayerController : CharacterBody3D,
var tween = GetTree().CreateTween();
tween.SetParallel();
tween.SetTrans(Tween.TransitionType.Cubic);
tween.SetEase(Tween.EaseType.InOut);
tween.SetEase(Tween.EaseType.In);
tween.TweenProperty(this, "global_position", targetLocation, tweenTime);
return tween;
@@ -2024,8 +2034,8 @@ public partial class PlayerController : CharacterBody3D,
public void OnAimingEntered()
{
if (!CanPerformEmpoweredAction())
return;
// if (!CanPerformEmpoweredAction())
// return;
// DashIndicatorMesh.Visible = true;
if (!isOnFloorCustom())
@@ -2039,8 +2049,8 @@ public partial class PlayerController : CharacterBody3D,
// DashIndicatorMeshCylinder.Height = DashSystem.PlannedLocation.DistanceTo(GlobalPosition);
// DashIndicatorNode.LookAt(DashSystem.PlannedLocation);
if (CanPerformEmpoweredAction())
DashSystem.PrepareDash();
// if (CanPerformEmpoweredAction())
DashSystem.PrepareDash();
}
public void OnAimingExited()
{
@@ -2490,22 +2500,23 @@ public partial class PlayerController : CharacterBody3D,
if (!HasSword) return;
if (_onWallHanging.Active) return;
if (_aiming.Active && WeaponSystem.InHandState.Active && CanPerformEmpoweredAction())
if (_aiming.Active && WeaponSystem.InHandState.Active)
{
ThrowWeapon();
return;
}
if (WeaponSystem.FlyingState.Active)
if (WeaponSystem.FlyingState.Active && CanPerformEmpoweredAction())
{
DashToFlyingWeapon();
return;
}
if (WeaponSystem.PlantedState.Active)
if (WeaponSystem.PlantedState.Active && CanPerformEmpoweredAction())
{
DashToPlantedWeapon();
return;
}
if (!WeaponSystem.InHandState.Active) return;
var attackToDo = _isEnemyInDashAttackRange ? "dash_attack" : "standard_attack";
_playerState.SendEvent(attackToDo);