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

@@ -9,59 +9,69 @@ using Movementtests.systems;
namespace Movementtests.managers;
public partial class WeaponEventAbilityData(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior ability)
: RefCounted
{
public WeaponSystem.WeaponEvent ForEvent { get; private set; } = forEvent;
public ForgeAbilityBehavior Ability { get; private set; } = ability;
}
[GlobalClass, Meta(typeof(IAutoNode))]
public partial class InventoryManager : Node, IDisposable
{
public override void _Notification(int what) => this.Notify(what);
#region Signals
[Signal]
public delegate void WeaponEventAbilityAddedEventHandler(WeaponEventAbilityData data);
[Signal]
public delegate void WeaponEventAbilityRemovedEventHandler(WeaponEventAbilityData data);
#endregion
private AutoSet<ForgeAbilityBehavior> _startedFlyingAbilities = new();
private AutoSet<ForgeAbilityBehavior> _flyingTickAbilities = new();
private AutoSet<ForgeAbilityBehavior> _stoppedFlyingAbilities = new();
private AutoSet<ForgeAbilityBehavior> _startedPlantedAbilities = new();
private AutoSet<ForgeAbilityBehavior> _plantedTickAbilities = new();
private AutoSet<ForgeAbilityBehavior> _stoppedPlantedAbilities = new();
public IAutoSet<ForgeAbilityBehavior> StartedFlyingAbilities => _startedFlyingAbilities;
public IAutoSet<ForgeAbilityBehavior> FlyingTickAbilities => _flyingTickAbilities;
public IAutoSet<ForgeAbilityBehavior> StoppedFlyingAbilities => _stoppedFlyingAbilities;
public IAutoSet<ForgeAbilityBehavior> StartedPlantedAbilities => _startedPlantedAbilities;
public IAutoSet<ForgeAbilityBehavior> PlantedTickAbilities => _plantedTickAbilities;
public IAutoSet<ForgeAbilityBehavior> StoppedPlantedAbilities => _stoppedPlantedAbilities;
private readonly AutoMap<WeaponSystem.WeaponEvent, AutoSet<ForgeAbilityBehavior>> _weaponEventsInventory = new();
public IAutoMap<WeaponSystem.WeaponEvent, AutoSet<ForgeAbilityBehavior>> WeaponEventsInventory => _weaponEventsInventory;
public Dictionary<WeaponSystem.WeaponEvent, AutoSet<ForgeAbilityBehavior>> GetEventElements()
{
return new Dictionary<WeaponSystem.WeaponEvent, AutoSet<ForgeAbilityBehavior>>
{
{ WeaponSystem.WeaponEvent.StartedFlying, _startedFlyingAbilities },
{ WeaponSystem.WeaponEvent.StoppedFlying, _stoppedFlyingAbilities},
{ WeaponSystem.WeaponEvent.FlyingTick, _flyingTickAbilities },
{ WeaponSystem.WeaponEvent.StartedPlanted, _startedPlantedAbilities },
{ WeaponSystem.WeaponEvent.StoppedPlanted, _stoppedPlantedAbilities },
{ WeaponSystem.WeaponEvent.PlantedTick, _plantedTickAbilities },
};
}
public void OnReady()
{
_weaponEventsInventory[WeaponSystem.WeaponEvent.StartedFlying] = _startedFlyingAbilities;
_weaponEventsInventory[WeaponSystem.WeaponEvent.FlyingTick] = _flyingTickAbilities;
_weaponEventsInventory[WeaponSystem.WeaponEvent.StoppedFlying] = _stoppedFlyingAbilities;
foreach (var (forEvent, behaviorSet) in GetEventElements())
{
_weaponEventsInventory[forEvent] = behaviorSet;
}
}
public void InitializeFromResource(WeaponInventory inventory)
{
_startedFlyingAbilities = new AutoSet<ForgeAbilityBehavior>(inventory.OnWeaponStartedFlyingAbilities);
_flyingTickAbilities = new AutoSet<ForgeAbilityBehavior>(inventory.OnWeaponFlyingTickAbilities);
_stoppedFlyingAbilities = new AutoSet<ForgeAbilityBehavior>(inventory.OnWeaponStoppedFlyingAbilities);
var elements = GetEventElements();
foreach (var forEvent in elements.Keys)
{
elements[forEvent] = new AutoSet<ForgeAbilityBehavior>(inventory.EventMap[forEvent]);
}
}
public new void Dispose()
{
GC.SuppressFinalize(this);
_startedFlyingAbilities.Dispose();
_flyingTickAbilities.Dispose();
_stoppedFlyingAbilities.Dispose();
foreach (var element in GetEventElements().Values)
element.Dispose();
_weaponEventsInventory.Dispose();
base.Dispose();