PO/Assets/Scripts/Enemy/Enemy.cs

123 lines
3.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>();
[SerializeField] private Text enemyName;
[SerializeField] private Text enemyMaxHp;
[SerializeField] private Text enemyHp;
[SerializeField] private Slider enemyHealthbar;
[SerializeField] private Image marker;
[Header("For checking. dont touch this")]
[SerializeField] private int hp;
public EnemyConfig enemyConfig;
public GameObject enemyPosition;
[SerializeField] int phaseAttack = 0;
public List<UnityEvent> attackLoop = new List<UnityEvent>();
private void Start()
{
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()
{
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;
}
public void Death()
{
SpriteRenderer _sprRend = enemyPosition.GetComponent<SpriteRenderer>();
_sprRend.sprite = null;
Session.main.EnemyDeath();
Destroy(gameObject);
}
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();
}
}
public void Turn()
{
BaseEnemyTurn.basic.FindLoopTurn(this.gameObject, phaseAttack);
phaseAttack++;
print(gameObject.name + " Next step " + BaseEnemyTurn.basic.phase.ToString());
UpdateNextStepIconAndText();
}
public int CheckHp()
{
return hp;
}
public void OnMarker()
{
marker.enabled = true;
}
public void OffMarker()
{
marker.enabled = false;
}
public bool CheckMarker()
{
return marker.enabled;
}
}