using System; using System.Collections.Generic; using Chickensoft.AutoInject; using Chickensoft.Introspection; using Chickensoft.Sync.Primitives; using Gamesmiths.Forge.Godot.Resources.Abilities; using Godot; using Movementtests.systems; namespace Movementtests.managers; [GlobalClass, Meta(typeof(IAutoNode))] public partial class InventoryManager : Node, IDisposable { public override void _Notification(int what) => this.Notify(what); private AutoSet _startedFlyingAbilities = new(); private AutoSet _flyingTickAbilities = new(); private AutoSet _stoppedFlyingAbilities = new(); private AutoSet _startedPlantedAbilities = new(); private AutoSet _plantedTickAbilities = new(); private AutoSet _stoppedPlantedAbilities = new(); public IAutoSet StartedFlyingAbilities => _startedFlyingAbilities; public IAutoSet FlyingTickAbilities => _flyingTickAbilities; public IAutoSet StoppedFlyingAbilities => _stoppedFlyingAbilities; public IAutoSet StartedPlantedAbilities => _startedPlantedAbilities; public IAutoSet PlantedTickAbilities => _plantedTickAbilities; public IAutoSet StoppedPlantedAbilities => _stoppedPlantedAbilities; private readonly AutoMap> _weaponEventsInventory = new(); public IAutoMap> WeaponEventsInventory => _weaponEventsInventory; public void OnReady() { _weaponEventsInventory[WeaponSystem.WeaponEvent.StartedFlying] = _startedFlyingAbilities; _weaponEventsInventory[WeaponSystem.WeaponEvent.StoppedFlying] = _stoppedFlyingAbilities; _weaponEventsInventory[WeaponSystem.WeaponEvent.FlyingTick] = _flyingTickAbilities; _weaponEventsInventory[WeaponSystem.WeaponEvent.StartedPlanted] = _startedPlantedAbilities; _weaponEventsInventory[WeaponSystem.WeaponEvent.StoppedPlanted] = _stoppedPlantedAbilities; _weaponEventsInventory[WeaponSystem.WeaponEvent.PlantedTick] = _plantedTickAbilities; } public void InitializeFromResource(WeaponInventory inventory) { var eventMap = inventory.GetEventAbilitiesMap(); _startedFlyingAbilities = new AutoSet(eventMap[WeaponSystem.WeaponEvent.StartedFlying]); _stoppedFlyingAbilities = new AutoSet(eventMap[WeaponSystem.WeaponEvent.StoppedFlying]); _flyingTickAbilities = new AutoSet(eventMap[WeaponSystem.WeaponEvent.FlyingTick]); _startedPlantedAbilities = new AutoSet(eventMap[WeaponSystem.WeaponEvent.StartedPlanted]); _stoppedPlantedAbilities = new AutoSet(eventMap[WeaponSystem.WeaponEvent.StoppedPlanted]); _plantedTickAbilities = new AutoSet(eventMap[WeaponSystem.WeaponEvent.PlantedTick]); } public new void Dispose() { GC.SuppressFinalize(this); _startedFlyingAbilities.Dispose(); _stoppedFlyingAbilities.Dispose(); _flyingTickAbilities.Dispose(); _startedPlantedAbilities.Dispose(); _stoppedPlantedAbilities.Dispose(); _plantedTickAbilities.Dispose(); _weaponEventsInventory.Dispose(); base.Dispose(); } public void AddAbilityForWeaponEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior) { var inventoryForEvent = _weaponEventsInventory[forEvent]; inventoryForEvent.Add(abilityBehavior); } public void RemoveAbilityForWeaponEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior) { var inventoryForEvent = _weaponEventsInventory[forEvent]; inventoryForEvent.Remove(abilityBehavior); } }