fix upgrades
This commit is contained in:
parent
d8c49317a3
commit
5dcbd3c313
17 changed files with 477 additions and 83 deletions
|
|
@ -21,18 +21,12 @@ public class AbilityManager : MonoBehaviour
|
|||
}
|
||||
|
||||
#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();
|
||||
[Header("Upgrades")]
|
||||
public AbilityUpgrade[] allUpgrades;
|
||||
public Dictionary<AbilityUpgrade, int> upgradesInventory = new();
|
||||
private void Start()
|
||||
{
|
||||
// upgradeButton.onClick.AddListener((() => AddUpgrade(upgradeToAdd, player.mainAttackInstance)));
|
||||
|
|
@ -41,72 +35,42 @@ public class AbilityManager : MonoBehaviour
|
|||
|
||||
public void StoreUpgrade(AbilityUpgrade upgradeToStore)
|
||||
{
|
||||
foreach (StoredUpgrade storedUpgrade in upgradesInventory)
|
||||
if (!upgradesInventory.ContainsKey(upgradeToStore))
|
||||
{
|
||||
if (storedUpgrade.upgrade == upgradeToStore)
|
||||
{
|
||||
storedUpgrade.count++;
|
||||
Debug.Log($"Added upgrade {storedUpgrade.upgrade.upgradeName}. Current count: {storedUpgrade.count}");
|
||||
AbilityUIHandler.instance.UpdateInventory();
|
||||
return;
|
||||
}
|
||||
upgradesInventory[upgradeToStore] = 0;
|
||||
}
|
||||
|
||||
StoredUpgrade newUpgrade = new()
|
||||
{
|
||||
upgrade = upgradeToStore,
|
||||
count = 1
|
||||
};
|
||||
upgradesInventory.Add(newUpgrade);
|
||||
Debug.Log($"Added upgrade {newUpgrade.upgrade.upgradeName}. Current count: {newUpgrade.count}");
|
||||
upgradesInventory[upgradeToStore]++;
|
||||
Debug.Log($"Added upgrade {upgradeToStore.upgradeName}. Current count: {upgradesInventory[upgradeToStore]}");
|
||||
AbilityUIHandler.instance.UpdateInventory();
|
||||
}
|
||||
|
||||
public int GetUpgradeCount(AbilityUpgrade upgrade)
|
||||
{
|
||||
if (!upgradesInventory.ContainsKey(upgrade))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return upgradesInventory[upgrade];
|
||||
}
|
||||
public void AddUpgrade(AbilityUpgrade upgrade, PlayerAbility ability)
|
||||
{
|
||||
foreach (StoredUpgrade storedUpgrade in upgradesInventory.ToArray())
|
||||
if (upgradesInventory.ContainsKey(upgrade))
|
||||
{
|
||||
if (storedUpgrade.upgrade == upgrade)
|
||||
upgradesInventory[upgrade]--;
|
||||
if (upgradesInventory[upgrade] <= 0)
|
||||
{
|
||||
storedUpgrade.count--;
|
||||
if (storedUpgrade.count <= 0)
|
||||
{
|
||||
upgradesInventory.Remove(storedUpgrade);
|
||||
AbilityUIHandler.instance.UpdateInventory();
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
upgradesInventory.Remove(upgrade);
|
||||
}
|
||||
ability.AddUpgrade(upgrade);
|
||||
AbilityUIHandler.instance.UpdateInventory();
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveUpgrade(AbilityUpgrade upgrade, PlayerAbility ability)
|
||||
{
|
||||
if (ability.attachedUpgrades.TryGetValue(upgrade, out AbilityUpgrade foundUpgrade))
|
||||
if (ability.RemoveUpgrade(upgrade))
|
||||
{
|
||||
if (foundUpgrade.count > 1)
|
||||
{
|
||||
foundUpgrade.ApplyRemoval();
|
||||
foundUpgrade.count--;
|
||||
}
|
||||
else
|
||||
{
|
||||
foundUpgrade.ApplyRemoval();
|
||||
ability.attachedUpgrades.Remove(foundUpgrade);
|
||||
}
|
||||
StoreUpgrade(upgrade);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,10 +45,14 @@ public class AbilityUIHandler : MonoBehaviour
|
|||
{
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
foreach (AbilityManager.StoredUpgrade storedUpgrade in AbilityManager.instance.upgradesInventory)
|
||||
foreach (AbilityUpgrade upgrade in AbilityManager.instance.allUpgrades)
|
||||
{
|
||||
StoredAbilityUpgradeUI newUI = Instantiate(templateStoredUpgradeUI, upgradeGrid);
|
||||
newUI.SetUpgrade(storedUpgrade.upgrade, storedUpgrade.count);
|
||||
int upgradeCount = AbilityManager.instance.GetUpgradeCount(upgrade);
|
||||
if (upgradeCount > 0)
|
||||
{
|
||||
StoredAbilityUpgradeUI newUI = Instantiate(templateStoredUpgradeUI, upgradeGrid);
|
||||
newUI.SetUpgrade(upgrade, upgradeCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,9 +34,12 @@ public class AbilityUIObject : MonoBehaviour
|
|||
piercing.text = $"Piercing: {isBullet.pierceAmount}";
|
||||
projectileCount.text = $"Projectiles: {isBullet.projectileCount}";
|
||||
}
|
||||
foreach (AbilityUpgrade upgrade in thisAbility.attachedUpgrades)
|
||||
foreach (AbilityUpgrade upgrade in AbilityManager.instance.allUpgrades)
|
||||
{
|
||||
AddUpgradeBox(upgrade);
|
||||
if (thisAbility.GetUpgradeCount(upgrade) > 0)
|
||||
{
|
||||
AddUpgradeBox(upgrade);
|
||||
}
|
||||
}
|
||||
|
||||
int upgradeBoxesToAdd = Math.Abs(upgradeSlotAmount - upgradeBoxes.Count);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class PlayerAbility : MonoBehaviour
|
|||
[Header("Stats")]
|
||||
public float power;
|
||||
public float projectileCount;
|
||||
public HashSet<AbilityUpgrade> attachedUpgrades = new();
|
||||
public Dictionary<AbilityUpgrade, int> attachedUpgrades = new();
|
||||
|
||||
public void TryAbility()
|
||||
{
|
||||
|
|
@ -37,4 +37,37 @@ public class PlayerAbility : MonoBehaviour
|
|||
currentCooldown -= Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddUpgrade(AbilityUpgrade upgrade)
|
||||
{
|
||||
if (!attachedUpgrades.ContainsKey(upgrade))
|
||||
{
|
||||
attachedUpgrades[upgrade] = 0;
|
||||
}
|
||||
attachedUpgrades[upgrade]++;
|
||||
upgrade.ApplyUpgrade(this);
|
||||
}
|
||||
|
||||
public bool RemoveUpgrade(AbilityUpgrade upgrade)
|
||||
{
|
||||
if (attachedUpgrades.ContainsKey(upgrade))
|
||||
{
|
||||
attachedUpgrades[upgrade]--;
|
||||
if (attachedUpgrades[upgrade] >= 0)
|
||||
{
|
||||
attachedUpgrades.Remove(upgrade);
|
||||
}
|
||||
upgrade.ApplyRemoval(this);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public int GetUpgradeCount(AbilityUpgrade upgrade)
|
||||
{
|
||||
if (!attachedUpgrades.ContainsKey(upgrade))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return attachedUpgrades[upgrade];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,21 +5,20 @@ public class AbilityUpgrade : ScriptableObject
|
|||
[Header("Identification")]
|
||||
public string upgradeName;
|
||||
public Sprite upgradeIcon;
|
||||
public PlayerAbility thisPlayerAbility;
|
||||
[Header("Stats")]
|
||||
public int count = 1;
|
||||
public PlayerAbility thisPlayerAbility;
|
||||
|
||||
public virtual void ApplyUpgrade()
|
||||
public void ApplyUpgrade(PlayerAbility abilityToUpgrade)
|
||||
{
|
||||
UpgradeEffects();
|
||||
UpgradeEffects(abilityToUpgrade);
|
||||
}
|
||||
|
||||
protected virtual void UpgradeEffects()
|
||||
protected virtual void UpgradeEffects(PlayerAbility abilityToUpgrade)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void ApplyRemoval()
|
||||
public virtual void ApplyRemoval(PlayerAbility abilityToRemove)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@ public class AttackSpeedUpgrade : AbilityUpgrade
|
|||
{
|
||||
[SerializeField] private float speedUpgradeAmount;
|
||||
|
||||
public override void ApplyUpgrade()
|
||||
protected override void UpgradeEffects(PlayerAbility abilityToUpgrade)
|
||||
{
|
||||
base.ApplyUpgrade();
|
||||
thisPlayerAbility.cooldown *= speedUpgradeAmount;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ using UnityEngine;
|
|||
[CreateAssetMenu(fileName = "Projectile Count Upgrade", menuName = "AbilityUpgrades/ProjectileCountUpgrade")]
|
||||
public class ProjectileCountUpgrade : AbilityUpgrade
|
||||
{
|
||||
protected override void UpgradeEffects()
|
||||
protected override void UpgradeEffects(PlayerAbility abilityToUpgrade)
|
||||
{
|
||||
thisPlayerAbility.projectileCount++; //idk how this will work for the stacking.
|
||||
abilityToUpgrade.projectileCount++; //idk how this will work for the stacking.
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,12 +17,11 @@ public class UpgradeBoxUI : MonoBehaviour, IDropHandler
|
|||
return;
|
||||
}
|
||||
counterUI.gameObject.SetActive(true);
|
||||
counterUI.text = $"x{thisAbilityUpgrade.count}";
|
||||
counterUI.text = $"x{thisPlayerAbility.attachedUpgrades[thisAbilityUpgrade]}";
|
||||
}
|
||||
|
||||
public void OnDrop(PointerEventData eventData)
|
||||
{
|
||||
Debug.Log("A");
|
||||
if (eventData.pointerDrag.TryGetComponent(out StoredAbilityUpgradeUI isStoredUpgrade) && (!thisAbilityUpgrade || isStoredUpgrade.storedUpgrade == thisAbilityUpgrade))
|
||||
{
|
||||
thisAbilityUpgrade = isStoredUpgrade.storedUpgrade;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue