99 lines
2.8 KiB
C#
99 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class AbilityManager : MonoBehaviour
|
|
{
|
|
#region Statication
|
|
|
|
public static AbilityManager instance;
|
|
|
|
private void Awake()
|
|
{
|
|
if (instance != null && instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
instance = this;
|
|
}
|
|
|
|
#endregion
|
|
|
|
public class StoredUpgrade
|
|
{
|
|
public AbilityUpgrade upgrade;
|
|
public int count;
|
|
}
|
|
public MarisaAbilityHandler player;
|
|
public AbilityUpgrade upgradeToAdd;
|
|
public Button upgradeButton;
|
|
|
|
[Header("Upgrades")]
|
|
public HashSet<StoredUpgrade> upgradesInventory = new();
|
|
private void Start()
|
|
{
|
|
// upgradeButton.onClick.AddListener((() => AddUpgrade(upgradeToAdd, player.mainAttackInstance)));
|
|
}
|
|
|
|
public void StoreUpgrade(AbilityUpgrade upgradeToStore)
|
|
{
|
|
foreach (StoredUpgrade storedUpgrade in upgradesInventory)
|
|
{
|
|
if (storedUpgrade.upgrade == upgradeToStore)
|
|
{
|
|
storedUpgrade.count++;
|
|
Debug.Log($"Added upgrade {storedUpgrade.upgrade.upgradeName}. Current count: {storedUpgrade.count}");
|
|
AbilityUIHandler.instance.UpdateInventory();
|
|
return;
|
|
}
|
|
}
|
|
|
|
StoredUpgrade newUpgrade = new()
|
|
{
|
|
upgrade = upgradeToStore,
|
|
count = 1
|
|
};
|
|
upgradesInventory.Add(newUpgrade);
|
|
Debug.Log($"Added upgrade {newUpgrade.upgrade.upgradeName}. Current count: {newUpgrade.count}");
|
|
AbilityUIHandler.instance.UpdateInventory();
|
|
}
|
|
|
|
public void AddUpgrade(AbilityUpgrade upgrade, PlayerAbility ability)
|
|
{
|
|
if (!ability.attachedUpgrades.Contains(upgrade))
|
|
{
|
|
AbilityUpgrade newUpgrade = Instantiate(upgrade, ability.transform);
|
|
ability.attachedUpgrades.Add(newUpgrade);
|
|
newUpgrade.thisPlayerAbility = ability;
|
|
newUpgrade.ApplyUpgrade();
|
|
}
|
|
else
|
|
{
|
|
ability.attachedUpgrades.TryGetValue(upgrade, out AbilityUpgrade foundUpgrade);
|
|
if (foundUpgrade)
|
|
{
|
|
foundUpgrade.count++;
|
|
foundUpgrade.ApplyUpgrade();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void RemoveUpgrade(AbilityUpgrade upgrade, PlayerAbility ability)
|
|
{
|
|
if (ability.attachedUpgrades.TryGetValue(upgrade, out AbilityUpgrade foundUpgrade))
|
|
{
|
|
if (foundUpgrade.count > 1)
|
|
{
|
|
foundUpgrade.ApplyRemoval();
|
|
foundUpgrade.count--;
|
|
}
|
|
else
|
|
{
|
|
foundUpgrade.ApplyRemoval();
|
|
ability.attachedUpgrades.Remove(foundUpgrade);
|
|
}
|
|
}
|
|
}
|
|
}
|