59 lines
2.3 KiB
C#
59 lines
2.3 KiB
C#
using System.Collections.Generic;
|
|
using Gamesmiths.Forge.Godot.Resources.Abilities;
|
|
using Godot;
|
|
using Movementtests.systems;
|
|
|
|
namespace Movementtests.managers;
|
|
|
|
public partial class WeaponEventAbilityData(WeaponSystem.WeaponEvent forEvent, Resource ability)
|
|
: RefCounted
|
|
{
|
|
public WeaponSystem.WeaponEvent ForEvent { get; private set; } = forEvent;
|
|
public Resource Ability { get; private set; } = ability;
|
|
}
|
|
|
|
public partial class InventoryManager : Node
|
|
{
|
|
[Signal]
|
|
public delegate void InventoryChangedEventHandler();
|
|
|
|
[Signal]
|
|
public delegate void WeaponEventInventoryChangedEventHandler();
|
|
[Signal]
|
|
public delegate void WeaponEventAbilityAddedEventHandler(WeaponEventAbilityData data);
|
|
[Signal]
|
|
public delegate void WeaponEventAbilityRemovedEventHandler(WeaponEventAbilityData data);
|
|
|
|
public Dictionary<WeaponSystem.WeaponEvent, HashSet<Resource>> WeaponEventsInventory { get; } = [];
|
|
|
|
public static InventoryManager Instance { get; private set; }
|
|
|
|
public override void _Ready()
|
|
{
|
|
Instance = this;
|
|
WeaponEventsInventory[WeaponSystem.WeaponEvent.FlyingTick] = new HashSet<Resource>();
|
|
WeaponEventsInventory[WeaponSystem.WeaponEvent.StartedFlying] = new HashSet<Resource>();
|
|
WeaponEventsInventory[WeaponSystem.WeaponEvent.StoppedFlying] = new HashSet<Resource>();
|
|
}
|
|
|
|
public void AddAbilityForWeaponEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
|
|
{
|
|
var inventoryForEvent = WeaponEventsInventory[forEvent];
|
|
var addedAbilityToInventory = inventoryForEvent.Add(abilityBehavior);
|
|
if (!addedAbilityToInventory) return;
|
|
|
|
EmitSignalWeaponEventInventoryChanged();
|
|
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;
|
|
|
|
EmitSignalWeaponEventInventoryChanged();
|
|
EmitSignalWeaponEventAbilityRemoved(new WeaponEventAbilityData(forEvent, abilityBehavior));
|
|
}
|
|
}
|