61 lines
2.5 KiB
C#
61 lines
2.5 KiB
C#
using System.Collections.Generic;
|
|
using Chickensoft.AutoInject;
|
|
using Chickensoft.Introspection;
|
|
using Gamesmiths.Forge.Godot.Resources.Abilities;
|
|
using Godot;
|
|
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]
|
|
public partial class InventoryManager : Node
|
|
{
|
|
#region Signals
|
|
|
|
[Signal]
|
|
public delegate void WeaponEventAbilityAddedEventHandler(WeaponEventAbilityData data);
|
|
[Signal]
|
|
public delegate void WeaponEventAbilityRemovedEventHandler(WeaponEventAbilityData data);
|
|
|
|
#endregion
|
|
|
|
public Dictionary<WeaponSystem.WeaponEvent, HashSet<ForgeAbilityBehavior>> WeaponEventsInventory { get; private set; }
|
|
= new() {
|
|
{ WeaponSystem.WeaponEvent.FlyingTick, [] },
|
|
{ WeaponSystem.WeaponEvent.StartedFlying, [] },
|
|
{ WeaponSystem.WeaponEvent.StoppedFlying, [] }
|
|
};
|
|
|
|
public void InitializeFromResource(WeaponInventory inventory)
|
|
{
|
|
WeaponEventsInventory[WeaponSystem.WeaponEvent.FlyingTick] = new HashSet<ForgeAbilityBehavior>(inventory.OnWeaponFlyingTickAbilities);
|
|
WeaponEventsInventory[WeaponSystem.WeaponEvent.StartedFlying] = new HashSet<ForgeAbilityBehavior>(inventory.OnWeaponStartedFlyingAbilities);
|
|
WeaponEventsInventory[WeaponSystem.WeaponEvent.StoppedFlying] = new HashSet<ForgeAbilityBehavior>(inventory.OnWeaponStoppedFlyingAbilities);
|
|
}
|
|
|
|
public void AddAbilityForWeaponEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
|
|
{
|
|
var inventoryForEvent = WeaponEventsInventory[forEvent];
|
|
var addedAbilityToInventory = inventoryForEvent.Add(abilityBehavior);
|
|
if (!addedAbilityToInventory) return;
|
|
|
|
EmitSignalWeaponEventAbilityAdded(new WeaponEventAbilityData(forEvent, abilityBehavior));
|
|
}
|
|
|
|
public void RemoveAbilityForWeaponEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
|
|
{
|
|
var inventoryForEvent = WeaponEventsInventory[forEvent];
|
|
var removedFromInventory = inventoryForEvent.Remove(abilityBehavior);
|
|
if (!removedFromInventory) return;
|
|
|
|
EmitSignalWeaponEventAbilityRemoved(new WeaponEventAbilityData(forEvent, abilityBehavior));
|
|
}
|
|
}
|