136 lines
3.7 KiB
C#
136 lines
3.7 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.Events;
|
||
using UnityEngine.UI;
|
||
|
||
public class Enemy : MonoBehaviour
|
||
{
|
||
[SerializeField] private Image enemyStepIcon;
|
||
[SerializeField] private Text enemyStepIconText;
|
||
|
||
[SerializeField] private List<Sprite> allStepImageIcons = new List<Sprite>();
|
||
public EnemyConfig enemyConfig;
|
||
[SerializeField] private Text enemyName;
|
||
[SerializeField] private Text enemyMaxHp;
|
||
[SerializeField] private Text enemyHp;
|
||
[SerializeField] private Slider enemyHealthbar;
|
||
[SerializeField] private Image marker;
|
||
[SerializeField] private Button buttonInEnemy;
|
||
[SerializeField] public int currentPosition;
|
||
|
||
[Header("For checking. dont touch this")]
|
||
[SerializeField] private int hp;
|
||
|
||
[SerializeField] int phaseAttack = 0;
|
||
public List<UnityEvent> attackLoop = new List<UnityEvent>();
|
||
|
||
private void Start()
|
||
{
|
||
NewInformation();
|
||
UpdateNextStepIconAndText();
|
||
}
|
||
|
||
public void onClick()
|
||
{
|
||
DeckManager.main.ActionInEnemy(this);
|
||
}
|
||
|
||
public void ChangeHp(int damage)
|
||
{
|
||
hp -= damage;
|
||
|
||
if (hp <= 0)
|
||
{
|
||
Death();
|
||
}
|
||
else if (hp > enemyConfig.enemyCharacteristics.maxHp)
|
||
{
|
||
hp = enemyConfig.enemyCharacteristics.maxHp;
|
||
}
|
||
|
||
enemyHp.text = hp.ToString();
|
||
enemyHealthbar.value = hp;
|
||
}
|
||
|
||
public void NewInformation()
|
||
{
|
||
|
||
Image _image = buttonInEnemy.image;
|
||
_image.sprite = enemyConfig.enemyCharacteristics.sprite;
|
||
var _character = enemyConfig.enemyCharacteristics;
|
||
enemyName.text = _character.name;
|
||
enemyMaxHp.text = _character.maxHp.ToString();
|
||
enemyHp.text = _character.maxHp.ToString();
|
||
enemyHealthbar.maxValue = _character.maxHp;
|
||
enemyHealthbar.value = _character.maxHp;
|
||
hp = _character.maxHp;
|
||
|
||
}
|
||
|
||
public void Death()
|
||
{
|
||
Image _image = buttonInEnemy.image;
|
||
|
||
_image.sprite = null;
|
||
Session.main.EnemyDeath(gameObject);
|
||
|
||
}
|
||
|
||
public void UpdateNextStepIconAndText()
|
||
{
|
||
int _phase = phaseAttack % attackLoop.Count;
|
||
//Пока всего две фазы атаки пойдет, но надо переписать
|
||
|
||
//А вот это тем более
|
||
switch(attackLoop[_phase].GetPersistentMethodName(0))
|
||
{
|
||
case "Attack":
|
||
enemyStepIcon.sprite = allStepImageIcons[0];
|
||
enemyStepIconText.text = enemyConfig.enemyCharacteristics.damage.ToString();
|
||
break;
|
||
case "SelfHealing":
|
||
enemyStepIcon.sprite = allStepImageIcons[1];
|
||
enemyStepIconText.text = enemyConfig.enemyCharacteristics.selfHealing.ToString();
|
||
break;
|
||
case "AllyHealing":
|
||
enemyStepIcon.sprite = allStepImageIcons[2];
|
||
enemyStepIconText.text = enemyConfig.enemyCharacteristics.allyHealing.ToString();
|
||
break;
|
||
case "AllHealing":
|
||
enemyStepIcon.sprite = allStepImageIcons[3];
|
||
enemyStepIconText.text = enemyConfig.enemyCharacteristics.allHealing.ToString();
|
||
break;
|
||
}
|
||
}
|
||
|
||
public void Turn()
|
||
{
|
||
int _phase = phaseAttack % attackLoop.Count;
|
||
attackLoop[_phase]?.Invoke();
|
||
phaseAttack++;
|
||
UpdateNextStepIconAndText();
|
||
}
|
||
|
||
|
||
public int CheckHp()
|
||
{
|
||
return hp;
|
||
}
|
||
|
||
public void OnMarker()
|
||
{
|
||
marker.enabled = true;
|
||
}
|
||
|
||
public void OffMarker()
|
||
{
|
||
marker.enabled = false;
|
||
}
|
||
|
||
public bool CheckMarker()
|
||
{
|
||
return marker.enabled;
|
||
}
|
||
}
|