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;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ public class Enemy : Entity
|
|||
public EnemyAbility ability;
|
||||
public float currentCooldown;
|
||||
}
|
||||
public static event Action OnDamaged;
|
||||
[Header("Targetting")]
|
||||
public Entity closestTarget;
|
||||
public float engagementRange;
|
||||
|
|
@ -112,6 +113,12 @@ public class Enemy : Entity
|
|||
}
|
||||
}
|
||||
|
||||
public override void TakeDamage(float damage)
|
||||
{
|
||||
base.TakeDamage(damage);
|
||||
OnDamaged?.Invoke();
|
||||
}
|
||||
|
||||
protected virtual void DropUpgrade(UpgradeDrop drop)
|
||||
{
|
||||
float random = Random.Range(0, 100);
|
||||
|
|
|
|||
|
|
@ -29,10 +29,14 @@ public class EnemySpawner : MonoBehaviour
|
|||
[SerializeField] private float currentSpawnTime;
|
||||
[Header("Boss")]
|
||||
public Enemy bossEnemy;
|
||||
private Enemy bossEnemyInstance;
|
||||
public Transform bossSpawnPoint;
|
||||
[SerializeField] private GameObject bossUI;
|
||||
[SerializeField] private Transform bossHealthBar;
|
||||
[Header("Cache")]
|
||||
[SerializeField] private Transform enemyFolder;
|
||||
[SerializeField] private Marisa player;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (canSpawn)
|
||||
|
|
@ -46,16 +50,24 @@ public class EnemySpawner : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
public void SpawnEnemy(Enemy enemy, Vector3 location)
|
||||
public Enemy SpawnEnemy(Enemy enemy, Vector3 location)
|
||||
{
|
||||
Enemy newEnemy = Instantiate(enemy, location, Quaternion.identity);
|
||||
newEnemy.transform.SetParent(enemyFolder);
|
||||
newEnemy.closestTarget = player; //idk if there's actually gonna be any other target lol
|
||||
return newEnemy;
|
||||
}
|
||||
|
||||
public void StartBoss()
|
||||
{
|
||||
SpawnEnemy(bossEnemy, bossSpawnPoint.position);
|
||||
bossEnemyInstance = SpawnEnemy(bossEnemy, bossSpawnPoint.position);
|
||||
bossUI.SetActive(true);
|
||||
canSpawn = false;
|
||||
Enemy.OnDamaged += UpdateBossHealthBar; //this kinda sucks but it technically works??
|
||||
}
|
||||
|
||||
private void UpdateBossHealthBar()
|
||||
{
|
||||
bossHealthBar.localScale = new Vector3(Math.Clamp(bossEnemyInstance.health / bossEnemyInstance.maxHealth, 0, bossEnemyInstance.maxHealth), 1, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class Entity : MonoBehaviour
|
||||
|
|
@ -11,6 +12,7 @@ public class Entity : MonoBehaviour
|
|||
[Header("Stats")]
|
||||
public float health;
|
||||
public float maxHealth;
|
||||
|
||||
[Header("Movement")]
|
||||
[SerializeField] private bool isFacingRight;
|
||||
[SerializeField] protected Rigidbody2D rb;
|
||||
|
|
@ -37,7 +39,7 @@ public class Entity : MonoBehaviour
|
|||
rb.linearVelocity = moveDirection * speed;
|
||||
}
|
||||
}
|
||||
public void TakeDamage(float damage)
|
||||
public virtual void TakeDamage(float damage)
|
||||
{
|
||||
health -= damage;
|
||||
if (health < 0)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ public class Marisa : Entity
|
|||
public Vector2 mouseWorldPos;
|
||||
public Transform firingPointBase;
|
||||
public Transform firingPoint;
|
||||
[Header("UI")]
|
||||
[SerializeField] private Transform hpBarUI;
|
||||
private void Update()
|
||||
{
|
||||
mouseWorldPos = cam.ScreenToWorldPoint(Input.mousePosition);
|
||||
|
|
@ -20,4 +22,15 @@ public class Marisa : Entity
|
|||
moveDirection = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
|
||||
base.FixedUpdate();
|
||||
}
|
||||
|
||||
public override void TakeDamage(float damage)
|
||||
{
|
||||
base.TakeDamage(damage);
|
||||
UpdateHealthUI();
|
||||
}
|
||||
|
||||
private void UpdateHealthUI()
|
||||
{
|
||||
hpBarUI.localScale = new Vector3(Math.Clamp(health/maxHealth,0,maxHealth), 1,1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
9
Assets/Scripts/LevelSwitcher.cs
Normal file
9
Assets/Scripts/LevelSwitcher.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class LevelSwitcher : MonoBehaviour
|
||||
{
|
||||
public void ChangeLevel()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/LevelSwitcher.cs.meta
Normal file
2
Assets/Scripts/LevelSwitcher.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 717ca245990ccea7580364c54b200c8d
|
||||
|
|
@ -21,7 +21,7 @@ public class StoredAbilityUpgradeUI : MonoBehaviour, IBeginDragHandler, IDragHan
|
|||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
parentAfterDrag = transform.parent;
|
||||
parentAfterDrag = icon.transform.parent;
|
||||
icon.raycastTarget = false;
|
||||
icon.transform.SetParent(transform.root);
|
||||
icon.transform.SetAsLastSibling();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue