2022-01-13 11:00:37 +03:00
|
|
|
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;
|
2022-01-14 10:42:43 +03:00
|
|
|
[SerializeField] private Image marker;
|
2022-01-15 10:29:16 +03:00
|
|
|
[SerializeField] private Button buttonInPlayer;
|
2022-01-15 21:47:03 +03:00
|
|
|
|
|
|
|
//[SerializeField] private Sprite armorSprite;
|
|
|
|
[SerializeField] private Image armorIcon;
|
|
|
|
[SerializeField] private Text armorText;
|
|
|
|
|
2022-01-14 10:42:43 +03:00
|
|
|
[Header("dont touch this. standart preset, change session")]
|
2022-01-13 11:00:37 +03:00
|
|
|
public PlayerConfig playerConfig;
|
2022-01-15 10:29:16 +03:00
|
|
|
|
2022-01-13 11:00:37 +03:00
|
|
|
[SerializeField] private int hp;
|
2022-01-15 21:47:03 +03:00
|
|
|
[SerializeField] private int armor;
|
2022-01-13 11:00:37 +03:00
|
|
|
|
2022-01-14 10:42:43 +03:00
|
|
|
|
2022-01-13 11:00:37 +03:00
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
if (main != null && main != this)
|
|
|
|
{
|
|
|
|
Debug.LogWarning("2 session on the scene");
|
|
|
|
Destroy(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-15 21:47:03 +03:00
|
|
|
main = this;
|
2022-01-13 11:00:37 +03:00
|
|
|
}
|
2022-01-15 21:47:03 +03:00
|
|
|
|
2022-01-13 11:00:37 +03:00
|
|
|
public void NewInformation()
|
|
|
|
{
|
|
|
|
var _character = playerConfig.characterCharacteristics;
|
2022-01-15 10:29:16 +03:00
|
|
|
|
|
|
|
Image _image = buttonInPlayer.image;
|
|
|
|
_image.sprite = playerConfig.characterCharacteristics.sprite;
|
2022-01-15 21:47:03 +03:00
|
|
|
|
2022-01-13 11:00:37 +03:00
|
|
|
playerName.text = _character.namePlayer;
|
|
|
|
playerMaxHp.text = _character.maxHp.ToString();
|
|
|
|
playerHp.text = playerMaxHp.text;
|
|
|
|
playerHealthbar.maxValue = _character.maxHp;
|
|
|
|
playerHealthbar.value = playerHealthbar.maxValue;
|
|
|
|
hp = _character.maxHp;
|
2022-01-15 23:26:40 +03:00
|
|
|
AddArmor(_character.armor);
|
2022-01-15 21:47:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ReupdateArmorIconAndText()
|
|
|
|
{
|
|
|
|
if(armor <= 0)
|
|
|
|
{
|
|
|
|
armorIcon.enabled = false;
|
|
|
|
|
|
|
|
armorText.text = "";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
armorIcon.enabled = true;
|
|
|
|
armorText.text = armor.ToString();
|
|
|
|
}
|
2022-01-13 11:00:37 +03:00
|
|
|
}
|
2022-01-15 21:47:03 +03:00
|
|
|
|
2022-01-13 11:00:37 +03:00
|
|
|
public void ChangeHp(int damage)
|
|
|
|
{
|
2022-01-15 21:47:03 +03:00
|
|
|
if (damage < 0)
|
|
|
|
{
|
|
|
|
hp -= damage;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-15 23:26:40 +03:00
|
|
|
AddArmor(-damage);
|
2022-01-15 21:47:03 +03:00
|
|
|
if (armor < 0)
|
|
|
|
{
|
|
|
|
hp -= Mathf.Abs(armor);
|
2022-01-15 23:26:40 +03:00
|
|
|
AddArmor(-armor);
|
|
|
|
|
2022-01-15 21:47:03 +03:00
|
|
|
}
|
|
|
|
}
|
2022-01-13 11:00:37 +03:00
|
|
|
|
|
|
|
if (hp <= 0)
|
|
|
|
{
|
|
|
|
hp = 0;
|
|
|
|
Death();
|
|
|
|
}
|
|
|
|
else if (hp > playerConfig.characterCharacteristics.maxHp)
|
|
|
|
{
|
|
|
|
hp = playerConfig.characterCharacteristics.maxHp;
|
|
|
|
}
|
|
|
|
|
|
|
|
playerMaxHp.text = hp.ToString();
|
|
|
|
playerHealthbar.value = hp;
|
2022-01-15 23:26:40 +03:00
|
|
|
|
2022-01-15 21:47:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public void OnClick()
|
|
|
|
{
|
2022-01-15 23:26:40 +03:00
|
|
|
//DeckManager.main.ActionInPlayer();
|
2022-01-15 21:47:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public void AddArmor(int value)
|
|
|
|
{
|
|
|
|
armor += value;
|
2022-01-15 23:26:40 +03:00
|
|
|
ReupdateArmorIconAndText();
|
2022-01-13 11:00:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Death()
|
|
|
|
{
|
2022-01-14 10:42:43 +03:00
|
|
|
Session.main.Defeat();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnMarker()
|
|
|
|
{
|
|
|
|
marker.enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OffMarker()
|
|
|
|
{
|
|
|
|
marker.enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool CheckMarker()
|
|
|
|
{
|
|
|
|
return marker.enabled;
|
2022-01-13 11:00:37 +03:00
|
|
|
}
|
|
|
|
}
|