More weapon events and abilities

This commit is contained in:
2026-05-06 11:05:55 +02:00
parent 1db30eafd9
commit bcc748ca6b
14 changed files with 455 additions and 190 deletions

View File

@@ -59,6 +59,10 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
Dash,
MantleDash
}
public record struct EventElements(
AutoSet<ForgeAbilityBehavior>.Binding Binding,
IAutoSet<ForgeAbilityBehavior> Inventory);
#endregion
@@ -110,6 +114,16 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
public required EntityAbilities Abilities { get; set; }
public required EventManager Events { get; set; }
public required Variables SharedVariables { get; set; }
public Dictionary<WeaponSystem.WeaponEvent, EventElements> EventElementsMap { get; private set; } = [];
public AutoSet<ForgeAbilityBehavior>.Binding StartedFlyingBinding { get; set; }
public AutoSet<ForgeAbilityBehavior>.Binding FlyingTickBinding { get; set; }
public AutoSet<ForgeAbilityBehavior>.Binding StoppedFlyingBinding { get; set; }
public AutoSet<ForgeAbilityBehavior>.Binding StartedPlantedBinding { get; set; }
public AutoSet<ForgeAbilityBehavior>.Binding PlantedTickBinding { get; set; }
public AutoSet<ForgeAbilityBehavior>.Binding StoppedPlantedBinding { get; set; }
#endregion
@@ -729,37 +743,34 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
}
// Inventory changes signal binding
StartedFlyingBinding = InventoryManager.StartedFlyingAbilities.Bind();
StartedFlyingBinding
.OnAdd(behavior => WeaponSystem.GrantNewAbilityForEvent(WeaponSystem.WeaponEvent.StartedFlying, behavior))
.OnRemove(behavior => WeaponSystem.RemoveAbilityForEvent(WeaponSystem.WeaponEvent.StartedFlying, behavior))
.OnClear(() => WeaponSystem.RemoveAbilitiesForEvent(WeaponSystem.WeaponEvent.StartedFlying));
FlyingTickBinding = InventoryManager.FlyingTickAbilities.Bind();
FlyingTickBinding
.OnAdd(behavior => WeaponSystem.GrantNewAbilityForEvent(WeaponSystem.WeaponEvent.FlyingTick, behavior))
.OnRemove(behavior => WeaponSystem.RemoveAbilityForEvent(WeaponSystem.WeaponEvent.FlyingTick, behavior))
.OnClear(() => WeaponSystem.RemoveAbilitiesForEvent(WeaponSystem.WeaponEvent.FlyingTick));
StoppedFlyingBinding = InventoryManager.StoppedFlyingAbilities.Bind();
StoppedFlyingBinding
.OnAdd(behavior => WeaponSystem.GrantNewAbilityForEvent(WeaponSystem.WeaponEvent.StoppedFlying, behavior))
.OnRemove(behavior => WeaponSystem.RemoveAbilityForEvent(WeaponSystem.WeaponEvent.StoppedFlying, behavior))
.OnClear(() => WeaponSystem.RemoveAbilitiesForEvent(WeaponSystem.WeaponEvent.StoppedFlying));
EventElementsMap = new Dictionary<WeaponSystem.WeaponEvent, EventElements>
{
{ WeaponSystem.WeaponEvent.StartedFlying, new EventElements(StartedFlyingBinding, InventoryManager.StartedFlyingAbilities) },
{ WeaponSystem.WeaponEvent.StoppedFlying, new EventElements(StoppedFlyingBinding, InventoryManager.StoppedFlyingAbilities)},
{ WeaponSystem.WeaponEvent.FlyingTick, new EventElements(FlyingTickBinding, InventoryManager.FlyingTickAbilities) },
{ WeaponSystem.WeaponEvent.StartedPlanted, new EventElements(StartedPlantedBinding, InventoryManager.StartedPlantedAbilities) },
{ WeaponSystem.WeaponEvent.StoppedPlanted, new EventElements(StoppedPlantedBinding, InventoryManager.StoppedPlantedAbilities) },
{ WeaponSystem.WeaponEvent.PlantedTick, new EventElements(PlantedTickBinding, InventoryManager.PlantedTickAbilities) },
};
// InventoryManager.WeaponEventAbilityAdded += OnWeaponEventAbilityAdded;
// InventoryManager.WeaponEventAbilityRemoved += OnWeaponEventAbilityRemoved;
foreach (var forEvent in EventElementsMap.Keys)
{
var element = EventElementsMap[forEvent];
element.Binding = element.Inventory.Bind();
element.Binding
.OnAdd(behavior => WeaponSystem.GrantNewAbilityForEvent(forEvent, behavior))
.OnRemove(behavior => WeaponSystem.RemoveAbilityForEvent(forEvent, behavior))
.OnClear(() => WeaponSystem.RemoveAbilitiesForEvent(forEvent));
}
}
public AutoSet<ForgeAbilityBehavior>.Binding StartedFlyingBinding { get; set; }
public AutoSet<ForgeAbilityBehavior>.Binding FlyingTickBinding { get; set; }
public AutoSet<ForgeAbilityBehavior>.Binding StoppedFlyingBinding { get; set; }
public new void Dispose()
{
GC.SuppressFinalize(this);
StartedFlyingBinding.Dispose();
FlyingTickBinding.Dispose();
StoppedFlyingBinding.Dispose();
foreach (var element in EventElementsMap.Values)
element.Binding.Dispose();
base.Dispose();
}
@@ -801,16 +812,6 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
out var failures);
}
public void OnWeaponEventAbilityAdded(WeaponEventAbilityData data)
{
WeaponSystem.GrantNewAbilityForEvent(data.ForEvent, data.Ability);
}
public void OnWeaponEventAbilityRemoved(WeaponEventAbilityData data)
{
WeaponSystem.RemoveAbilityForEvent(data.ForEvent, data.Ability);
}
#endregion
#region Settings