using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Player : MonoBehaviour { public static Player main; [SerializeField] private Text playerName; [SerializeField] private Text playerMaxHp; [SerializeField] private Text playerHp; [SerializeField] private Slider playerHealthbar; [SerializeField] private Image marker; [SerializeField] private Button buttonInPlayer; //[SerializeField] private Sprite armorSprite; [SerializeField] private Image armorIcon; [SerializeField] private Text armorText; [Header("dont touch this. standart preset, change session")] public PlayerConfig playerConfig; [SerializeField] private int hp; [SerializeField] private int armor; public List effectsName = new List(); public List effectsTurns = new List(); public List effectsDamage = new List(); [HideInInspector] public List effectsLink = new List(); [HideInInspector] public bool hasStun = false; private void Awake() { if (main != null && main != this) { Debug.LogWarning("2 session on the scene"); Destroy(this); return; } main = this; } public void NewInformation() { var _character = playerConfig.characterCharacteristics; Image _image = buttonInPlayer.image; _image.sprite = playerConfig.characterCharacteristics.sprite; playerName.text = _character.namePlayer; playerMaxHp.text = _character.maxHp.ToString(); playerHp.text = playerMaxHp.text; playerHealthbar.maxValue = _character.maxHp; playerHealthbar.value = playerHealthbar.maxValue; hp = _character.maxHp; AddArmor(_character.armor); } public void ReupdateArmorIconAndText() { if(armor <= 0) { armorIcon.enabled = false; armorText.text = ""; } else { armorIcon.enabled = true; armorText.text = armor.ToString(); } } public void ChangeHp(int damage) { if (damage < 0) { hp -= damage; } else { AddArmor(-damage); if (armor < 0) { hp -= Mathf.Abs(armor); AddArmor(-armor); } } if (hp <= 0) { hp = 0; Death(); } else if (hp > playerConfig.characterCharacteristics.maxHp) { hp = playerConfig.characterCharacteristics.maxHp; } playerMaxHp.text = hp.ToString(); playerHealthbar.value = hp; } public void EffectsBy() { for (int i = 0; i < effectsName.Count; i++) { if (effectsName[i] == "poison") { LibraryEffects.main.Poison(gameObject, effectsDamage[i]); effectsTurns[i] -= 1; } if (effectsName[i] == "stun") { LibraryEffects.main.Stun(gameObject); effectsTurns[i] -= 1; } } var _dopCounter = 0; var _effectsCount = effectsName.Count; for (int i = 0; i < _effectsCount; i++) { if (effectsTurns[_dopCounter] <= 0) { effectsName.Remove(effectsName[_dopCounter]); effectsTurns.Remove(effectsTurns[_dopCounter]); effectsDamage.Remove(effectsDamage[_dopCounter]); Destroy(effectsLink[_dopCounter]); effectsLink.RemoveAt(_dopCounter); } else { _dopCounter += 1; } } } public void OnClick() { //DeckManager.main.ActionInPlayer(); } public void AddArmor(int value) { armor += value; ReupdateArmorIconAndText(); } public void Death() { Session.main.Defeat(); } public void OnMarker() { marker.enabled = true; } public void OffMarker() { marker.enabled = false; } public bool CheckMarker() { return marker.enabled; } }