Potion Logic

Most of the potion logic for now
This commit is contained in:
2025-08-02 02:54:53 +02:00
parent 65f3409eba
commit 630c54f7ff
20 changed files with 981 additions and 95 deletions

View File

@@ -13,6 +13,7 @@ public class CardManager : MonoBehaviour
private PlayerSkillTree playerSkillTree;
private GameObject cards;
private PotionHandler potionHandler;
private void Awake()
@@ -25,6 +26,7 @@ public class CardManager : MonoBehaviour
{
Destroy(gameObject);
}
}
private void Start()
@@ -79,9 +81,9 @@ public class CardManager : MonoBehaviour
}
}
public void SelectCard(PlayerSkillTree.Skills skill)
public void SelectCard(PlayerSkillTree.Skills skill, PotionHandler.PotionType potionType)
{
playerSkillTree.UnlockSkill(skill);
playerSkillTree.UnlockSkill(skill, potionType);
foreach (Transform child in cardsParent)
{

View File

@@ -7,6 +7,8 @@ public class CardUI : MonoBehaviour
[SerializeField] private string cardname;
[SerializeField] private PlayerSkillTree.Skills skill;
[SerializeField] private PotionHandler.PotionType potionType = PotionHandler.PotionType.None;
public PlayerSkillTree.Skills Skill { get => skill; private set => skill = value; }
public string Name { get => cardname; private set => cardname = value; }
@@ -18,6 +20,6 @@ public class CardUI : MonoBehaviour
private void OnCardClicked()
{
CardManager.Instance.SelectCard(Skill);
CardManager.Instance.SelectCard(Skill, potionType);
}
}

View File

@@ -28,6 +28,18 @@ public class PlayerMovement : MonoBehaviour
{
HandleDash();
}
if (Input.GetKeyDown(KeyCode.L))
{
if(PlayerSkills.TryUsePotion(PotionHandler.PotionType.HealthBig))
{
Debug.Log("Potion used!");
}
else
{
Debug.Log("Potion not available!");
}
}
}
void FixedUpdate()

View File

@@ -6,6 +6,7 @@ public class PlayerSkillTree
{
private static PlayerSkillTree _instance;
private PotionHandler potionHandler;
public static PlayerSkillTree Instance
{
@@ -23,9 +24,13 @@ public class PlayerSkillTree
public enum Skills
{
Dash,
Rush,
Kek,
LMAO
Reflection1,
Reflection2,
Shockwave,
Spin,
Potion,
Arrows1,
Arrows2
}
private List<Skills> playerSkills;
@@ -33,13 +38,29 @@ public class PlayerSkillTree
public PlayerSkillTree()
{
playerSkills = new List<Skills>();
potionHandler = new PotionHandler();
}
public void UnlockSkill(Skills skill)
public void UnlockSkill(Skills skill, PotionHandler.PotionType potionType)
{
if(skill == Skills.Potion){
potionHandler.AddPotion(potionType);
return;
}
if (playerSkills.Contains(skill)) return;
playerSkills.Add(skill);
}
public bool TryUsePotion(PotionHandler.PotionType potionType)
{
if(potionHandler.IsEmpty(potionType)) return false;
return potionHandler.UsePotion(potionType);
}
public bool IsSkillUnlocked(Skills skill)
{
return playerSkills.Contains(skill);

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9c6ab0dc1eb08ce43bbbb64d72bec3b1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,61 @@
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class PotionHandler:MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
private Dictionary<PotionType, int> potions = new Dictionary<PotionType, int>();
[SerializeField] private TextMeshProUGUI textMeshProUGUI;
[SerializeField] private PotionType potionType;
public enum PotionType
{
HealthSmall,
HealthBig,
Mana,
None
}
public PotionHandler()
{
foreach (PotionType type in System.Enum.GetValues(typeof(PotionType)))
{
potions.Add(type, 0);
}
//textMeshProUGUI.text = potions[potionType].ToString();
}
public void AddPotion(PotionType type, int amount = 1)
{
potions[type] += amount;
Debug.Log(potions[type]);
if(type == potionType)
{
textMeshProUGUI.text= potions[type].ToString();
}
//Debug.Log("Text is: " + textMeshProUGUI.text);
}
public bool UsePotion(PotionType type, int amount = 1)
{
potions[type] -= amount;
return true;
}
public int GetAmount(PotionType type)
{
return potions[type];
}
public bool IsEmpty(PotionType type)
{
return GetAmount(type) == 0;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9e65daa0fc513fe4fa2efcaf544035ff