Scriptum/Assets/Scripts/REFACTORING/Application/Item/Effects/PotionEffectsManager.cs

142 lines
4.0 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using System.Collections;
class PotionEffectsManager : ItemEffectsManager
{
public static new PotionEffectsManager Instance;
public override void Awake()
{
if (Instance == null)
{
Instance = this;
}
else
{
Destroy(gameObject);
}
}
public override void UseItemEffect(ItemSlot itemSlot, PanelTypeEnum originPanel)
{
// origin panel is passed for script to be able to recognize from which list to remove the object etc...
DetectPotionType(itemSlot);
// use other action binded to item 2
itemSlot.Item?.InvokeEffectAction();
// remove potion from a slot in specific panel...
var panelUiManager = DetectOriginPanel(originPanel);
panelUiManager.RemoveByPosition(itemSlot.Number);
panelUiManager.UpdateList(); // refresh view
}
public void DetectPotionType(ItemSlot itemSlot)
{
var item = itemSlot.Item;
// detect potion and use matched action
2022-12-29 14:25:07 +01:00
if (item.name == "Full Health Potion")
{
HealthBigPotion();
}
2022-12-29 14:25:07 +01:00
else if(item.name == "Medium Health Potion")
{
HealthMediumPotion();
}
2022-12-29 14:25:07 +01:00
else if(item.name == "Small Health Potion")
{
HealthSmallPotion();
}
else if(item.name == "Beer")
{
Drink();
}
else if(item.name == "Crab Venom")
{
CrabPoison();
}
else if(item.name == "Mushroom Venom")
{
MushroomPoison();
}
}
public void Drink()
{
PlayerPrefs.SetInt("drunk", 1);
StartCoroutine(SoberUp());
}
public IEnumerator SoberUp()
{
yield return new WaitForSecondsRealtime(6);
PlayerPrefs.SetInt("drunk", 2);
}
// use below function in one above - depending on the condition
public void HealthBigPotion()
{
2022-12-29 14:25:07 +01:00
var playerMaxHealth = PlayerPrefs.GetFloat("maxHealth");
var playerCurrentHealth = PlayerPrefs.GetFloat("health");
playerCurrentHealth = playerMaxHealth;
PlayerPrefs.SetFloat("health", playerCurrentHealth);
}
2022-12-29 14:25:07 +01:00
public void HealthMediumPotion()
{
var playerMaxHealth = PlayerPrefs.GetFloat("maxHealth");
var playerCurrentHealth = PlayerPrefs.GetFloat("health");
if(playerCurrentHealth < playerMaxHealth / 2)
{
playerCurrentHealth = playerCurrentHealth + playerMaxHealth / 2;
}
else
{
playerCurrentHealth = playerMaxHealth;
}
PlayerPrefs.SetFloat("health", playerCurrentHealth);
}
public void HealthSmallPotion()
2022-12-29 14:25:07 +01:00
{
var playerMaxHealth = PlayerPrefs.GetFloat("maxHealth");
var playerCurrentHealth = PlayerPrefs.GetFloat("health");
if(playerCurrentHealth < playerMaxHealth*3/4)
{
playerCurrentHealth = playerCurrentHealth + playerMaxHealth / 4;
}
else
{
playerCurrentHealth = playerMaxHealth;
}
PlayerPrefs.SetFloat("health", playerCurrentHealth);
}
public void CrabPoison()
{
var playerMaxHealth = PlayerPrefs.GetFloat("maxHealth");
var playerCurrentHealth = PlayerPrefs.GetFloat("health");
playerCurrentHealth = playerMaxHealth * 3/4;
PlayerPrefs.SetFloat("health", playerCurrentHealth);
}
public void MushroomPoison()
{
var playerMaxHealth = PlayerPrefs.GetFloat("maxHealth");
var playerCurrentHealth = PlayerPrefs.GetFloat("health");
playerCurrentHealth = playerMaxHealth * 1 / 2;
PlayerPrefs.SetFloat("health", playerCurrentHealth);
}
// Add and invoke your own functions
}