Inventory management of granted abilities
This commit is contained in:
@@ -240,9 +240,9 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
Events.Subscribe(WeaponStoppedFlyingEventTag, _ => { _weaponFlyingAbility.Cancel(); });
|
||||
}
|
||||
|
||||
private List<ActiveEffectHandle> _grantedWeaponStartedFlyingAbilities = new List<ActiveEffectHandle>();
|
||||
private List<ActiveEffectHandle> _grantedWeaponStoppedFlyingAbilities = new List<ActiveEffectHandle>();
|
||||
private List<ActiveEffectHandle> _grantedWeaponFlyingTickAbilities = new List<ActiveEffectHandle>();
|
||||
private Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> _grantedWeaponStartedFlyingAbilities = new ();
|
||||
private Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> _grantedWeaponStoppedFlyingAbilities = new ();
|
||||
private Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> _grantedWeaponFlyingTickAbilities = new ();
|
||||
|
||||
public enum WeaponEvent
|
||||
{
|
||||
@@ -253,12 +253,9 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
|
||||
public void GrantNewAbilityForEvent(WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
|
||||
{
|
||||
var abilitiesMap = new Dictionary<WeaponEvent, List<ActiveEffectHandle>>
|
||||
{
|
||||
{ WeaponEvent.StartedFlying, _grantedWeaponStartedFlyingAbilities },
|
||||
{ WeaponEvent.StoppedFlying, _grantedWeaponStoppedFlyingAbilities },
|
||||
{ WeaponEvent.FlyingTick, _grantedWeaponFlyingTickAbilities },
|
||||
};
|
||||
var relevantMap = GetGrantedAbilities(forEvent);
|
||||
GD.Print($"Granted {abilityBehavior} for {forEvent}");
|
||||
if (relevantMap.ContainsKey(abilityBehavior)) return;
|
||||
|
||||
var eventTagsMap = new Dictionary<WeaponEvent, Tag>
|
||||
{
|
||||
@@ -288,10 +285,28 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
effectComponents: [leftGrantComponent]);
|
||||
var effectHandle = EffectsManager.ApplyEffect(new Effect(leftGrantEffect, new EffectOwnership(this, this)));
|
||||
if (effectHandle == null) return;
|
||||
|
||||
abilitiesMap[forEvent].Add(effectHandle);
|
||||
relevantMap[abilityBehavior] = effectHandle;
|
||||
}
|
||||
|
||||
public void RemoveAbilityForEvent(WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
|
||||
{
|
||||
var relevantMap = GetGrantedAbilities(forEvent);
|
||||
if (!relevantMap.TryGetValue(abilityBehavior, out var effectHandle)) return;
|
||||
EffectsManager.RemoveEffect(effectHandle);
|
||||
relevantMap.Remove(abilityBehavior);
|
||||
}
|
||||
|
||||
public Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> GetGrantedAbilities(WeaponEvent forEvent)
|
||||
{
|
||||
var abilitiesMap = new Dictionary<WeaponEvent, Dictionary<ForgeAbilityBehavior, ActiveEffectHandle>>
|
||||
{
|
||||
{ WeaponEvent.StartedFlying, _grantedWeaponStartedFlyingAbilities },
|
||||
{ WeaponEvent.StoppedFlying, _grantedWeaponStoppedFlyingAbilities },
|
||||
{ WeaponEvent.FlyingTick, _grantedWeaponFlyingTickAbilities },
|
||||
};
|
||||
|
||||
return abilitiesMap[forEvent];
|
||||
}
|
||||
|
||||
|
||||
public void WeaponLeft()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user