2022-01-12 10:06:03 +03:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
2022-01-13 11:00:37 +03:00
|
|
|
|
using UnityEngine.Events;
|
2022-01-12 10:06:03 +03:00
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
public class Enemy : MonoBehaviour
|
|
|
|
|
{
|
2022-01-15 00:55:46 +03:00
|
|
|
|
[SerializeField] private Image enemyStepIcon;
|
|
|
|
|
[SerializeField] private Text enemyStepIconText;
|
2022-01-13 11:00:37 +03:00
|
|
|
|
|
2022-01-15 00:55:46 +03:00
|
|
|
|
[SerializeField] private List<Sprite> allStepImageIcons = new List<Sprite>();
|
2022-01-13 11:00:37 +03:00
|
|
|
|
|
2022-01-12 10:06:03 +03:00
|
|
|
|
[SerializeField] private Text enemyName;
|
|
|
|
|
[SerializeField] private Text enemyMaxHp;
|
|
|
|
|
[SerializeField] private Text enemyHp;
|
|
|
|
|
[SerializeField] private Slider enemyHealthbar;
|
2022-01-14 10:42:43 +03:00
|
|
|
|
[SerializeField] private Image marker;
|
2022-01-13 12:07:16 +03:00
|
|
|
|
|
2022-01-13 11:00:37 +03:00
|
|
|
|
|
|
|
|
|
[Header("For checking. dont touch this")]
|
2022-01-13 12:07:16 +03:00
|
|
|
|
[SerializeField] private int hp;
|
|
|
|
|
public EnemyConfig enemyConfig;
|
|
|
|
|
public GameObject enemyPosition;
|
2022-01-13 11:00:37 +03:00
|
|
|
|
[SerializeField] int phaseAttack = 0;
|
|
|
|
|
public List<UnityEvent> attackLoop = new List<UnityEvent>();
|
|
|
|
|
|
2022-01-15 00:55:46 +03:00
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
UpdateNextStepIconAndText();
|
|
|
|
|
}
|
2022-01-13 11:00:37 +03:00
|
|
|
|
|
2022-01-13 12:07:16 +03:00
|
|
|
|
public void onClick()
|
|
|
|
|
{
|
|
|
|
|
DeckManager.main.ActionInEnemy(this);
|
|
|
|
|
}
|
2022-01-13 11:00:37 +03:00
|
|
|
|
|
2022-01-12 10:06:03 +03:00
|
|
|
|
public void ChangeHp(int damage)
|
|
|
|
|
{
|
|
|
|
|
hp -= damage;
|
2022-01-13 11:00:37 +03:00
|
|
|
|
|
|
|
|
|
if (hp <= 0)
|
2022-01-12 10:06:03 +03:00
|
|
|
|
{
|
|
|
|
|
Death();
|
|
|
|
|
}
|
2022-01-13 11:00:37 +03:00
|
|
|
|
else if (hp > enemyConfig.enemyCharacteristics.maxHp)
|
2022-01-12 10:06:03 +03:00
|
|
|
|
{
|
|
|
|
|
hp = enemyConfig.enemyCharacteristics.maxHp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enemyHp.text = hp.ToString();
|
|
|
|
|
enemyHealthbar.value = hp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void NewInformation()
|
|
|
|
|
{
|
|
|
|
|
SpriteRenderer _sprRend = enemyPosition.GetComponent<SpriteRenderer>();
|
|
|
|
|
_sprRend.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;
|
2022-01-13 12:07:16 +03:00
|
|
|
|
|
2022-01-12 10:06:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Death()
|
|
|
|
|
{
|
|
|
|
|
SpriteRenderer _sprRend = enemyPosition.GetComponent<SpriteRenderer>();
|
|
|
|
|
_sprRend.sprite = null;
|
2022-01-14 10:42:43 +03:00
|
|
|
|
Session.main.EnemyDeath();
|
2022-01-13 12:07:16 +03:00
|
|
|
|
Destroy(gameObject);
|
2022-01-12 10:06:03 +03:00
|
|
|
|
}
|
2022-01-13 11:00:37 +03:00
|
|
|
|
|
2022-01-15 00:55:46 +03:00
|
|
|
|
public void UpdateNextStepIconAndText()
|
|
|
|
|
{
|
|
|
|
|
BaseEnemyTurn.basic.FindLoopForLocal(gameObject, phaseAttack);
|
|
|
|
|
int _phase = BaseEnemyTurn.basic.phase;
|
|
|
|
|
//Пока всего две фазы атаки пойдет, но надо переписать
|
|
|
|
|
enemyStepIcon.sprite = allStepImageIcons[_phase];
|
|
|
|
|
//А вот это тем более
|
|
|
|
|
if (_phase == 0)
|
|
|
|
|
{
|
|
|
|
|
enemyStepIconText.text = enemyConfig.enemyCharacteristics.damage.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
enemyStepIconText.text = enemyConfig.enemyCharacteristics.selfHealing.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-13 11:00:37 +03:00
|
|
|
|
public void Turn()
|
|
|
|
|
{
|
|
|
|
|
BaseEnemyTurn.basic.FindLoopTurn(this.gameObject, phaseAttack);
|
|
|
|
|
phaseAttack++;
|
2022-01-15 00:55:46 +03:00
|
|
|
|
print(gameObject.name + " Next step " + BaseEnemyTurn.basic.phase.ToString());
|
|
|
|
|
UpdateNextStepIconAndText();
|
2022-01-13 11:00:37 +03:00
|
|
|
|
}
|
2022-01-14 10:42:43 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int CheckHp()
|
|
|
|
|
{
|
|
|
|
|
return hp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnMarker()
|
|
|
|
|
{
|
|
|
|
|
marker.enabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OffMarker()
|
|
|
|
|
{
|
|
|
|
|
marker.enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CheckMarker()
|
|
|
|
|
{
|
|
|
|
|
return marker.enabled;
|
|
|
|
|
}
|
2022-01-12 10:06:03 +03:00
|
|
|
|
}
|