2023-01-06 21:54:50 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
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();
|
2023-01-06 21:54:50 +01:00
|
|
|
|
}
|
2022-12-29 14:25:07 +01:00
|
|
|
|
else if(item.name == "Medium Health Potion")
|
|
|
|
|
{
|
|
|
|
|
HealthMediumPotion();
|
2023-01-06 21:54:50 +01:00
|
|
|
|
}
|
2022-12-29 14:25:07 +01:00
|
|
|
|
else if(item.name == "Small Health Potion")
|
|
|
|
|
{
|
|
|
|
|
HealthSmallPotion();
|
2023-01-06 21:54:50 +01:00
|
|
|
|
}
|
|
|
|
|
else if(item.name == "Beer")
|
|
|
|
|
{
|
|
|
|
|
GameObject.FindObjectOfType<CamerFollow>().Drink();
|
|
|
|
|
}
|
|
|
|
|
else if(item.name == "Crab Venom")
|
|
|
|
|
{
|
|
|
|
|
CrabPoison();
|
|
|
|
|
}
|
|
|
|
|
else if(item.name == "Mushroom Venom")
|
|
|
|
|
{
|
|
|
|
|
MushroomPoison();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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);
|
2023-01-06 21:54:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
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);
|
2023-01-06 21:54:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2023-01-06 21:54:50 +01:00
|
|
|
|
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
|
|
|
|
|
}
|