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-02-09 21:22:43 +03:00
|
|
|
|
{
|
|
|
|
|
|
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-15 10:29:16 +03:00
|
|
|
|
public EnemyConfig enemyConfig;
|
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-15 10:29:16 +03:00
|
|
|
|
[SerializeField] private Button buttonInEnemy;
|
2022-01-15 12:11:34 +03:00
|
|
|
|
[SerializeField] public int currentPosition;
|
2022-01-13 11:00:37 +03:00
|
|
|
|
|
|
|
|
|
[Header("For checking. dont touch this")]
|
|
|
|
|
[SerializeField] int phaseAttack = 0;
|
|
|
|
|
public List<UnityEvent> attackLoop = new List<UnityEvent>();
|
|
|
|
|
|
2022-01-15 21:47:03 +03:00
|
|
|
|
[SerializeField] private int hp;
|
|
|
|
|
[SerializeField] private int localarmor;
|
|
|
|
|
|
|
|
|
|
[SerializeField] private Image armorIcon;
|
|
|
|
|
[SerializeField] private Text armorText;
|
|
|
|
|
|
2022-02-09 21:22:43 +03:00
|
|
|
|
public List<string> effectsName = new List<string>();
|
|
|
|
|
public List<int> effectsTurns = new List<int>();
|
|
|
|
|
public List<int> effectsDamage = new List<int>();
|
|
|
|
|
|
2022-01-15 00:55:46 +03:00
|
|
|
|
private void Start()
|
|
|
|
|
{
|
2022-01-15 10:29:16 +03:00
|
|
|
|
NewInformation();
|
2022-01-15 00:55:46 +03:00
|
|
|
|
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)
|
|
|
|
|
{
|
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 (localarmor < 0)
|
|
|
|
|
{
|
|
|
|
|
hp -= Mathf.Abs(localarmor);
|
2022-01-15 23:26:40 +03:00
|
|
|
|
AddArmor(-localarmor);
|
2022-01-15 21:47:03 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2022-01-15 23:26:40 +03:00
|
|
|
|
|
2022-01-12 10:06:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-15 21:47:03 +03:00
|
|
|
|
public void AddArmor(int value)
|
2022-01-12 10:06:03 +03:00
|
|
|
|
{
|
2022-01-15 21:47:03 +03:00
|
|
|
|
localarmor += value;
|
2022-01-15 23:26:40 +03:00
|
|
|
|
ReupdateArmorIconAndText();
|
2022-01-15 21:47:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void NewInformation()
|
|
|
|
|
{
|
2022-01-15 10:29:16 +03:00
|
|
|
|
Image _image = buttonInEnemy.image;
|
|
|
|
|
_image.sprite = enemyConfig.enemyCharacteristics.sprite;
|
2022-01-12 10:06:03 +03:00
|
|
|
|
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-15 23:26:40 +03:00
|
|
|
|
AddArmor(_character.armor);
|
2022-01-15 21:47:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ReupdateArmorIconAndText()
|
|
|
|
|
{
|
|
|
|
|
if (localarmor <= 0)
|
|
|
|
|
{
|
|
|
|
|
armorIcon.enabled = false;
|
|
|
|
|
|
|
|
|
|
armorText.text = "";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
armorIcon.enabled = true;
|
|
|
|
|
armorText.text = localarmor.ToString();
|
|
|
|
|
}
|
2022-01-12 10:06:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Death()
|
|
|
|
|
{
|
2022-01-15 10:29:16 +03:00
|
|
|
|
Image _image = buttonInEnemy.image;
|
|
|
|
|
|
|
|
|
|
_image.sprite = null;
|
|
|
|
|
Session.main.EnemyDeath(gameObject);
|
|
|
|
|
|
2022-01-12 10:06:03 +03:00
|
|
|
|
}
|
2022-01-13 11:00:37 +03:00
|
|
|
|
|
2022-02-09 21:22:43 +03:00
|
|
|
|
public void EffectsBy()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < effectsName.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if(effectsTurns[i] == 0)
|
|
|
|
|
{
|
|
|
|
|
effectsName.Remove(effectsName[i]);
|
|
|
|
|
effectsTurns.Remove(effectsTurns[i]);
|
|
|
|
|
effectsDamage.Remove(effectsDamage[i]);
|
|
|
|
|
}
|
|
|
|
|
else if(effectsName[i] == "poison")
|
|
|
|
|
{
|
|
|
|
|
LibraryEffects.main.Poison(gameObject, effectsDamage[i]);
|
|
|
|
|
effectsTurns[i] -= 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-15 00:55:46 +03:00
|
|
|
|
public void UpdateNextStepIconAndText()
|
|
|
|
|
{
|
2022-01-15 10:29:16 +03:00
|
|
|
|
int _phase = phaseAttack % attackLoop.Count;
|
2022-01-15 00:55:46 +03:00
|
|
|
|
//Пока всего две фазы атаки пойдет, но надо переписать
|
2022-01-15 10:29:16 +03:00
|
|
|
|
|
2022-01-15 00:55:46 +03:00
|
|
|
|
//А вот это тем более
|
2022-01-15 10:29:16 +03:00
|
|
|
|
switch(attackLoop[_phase].GetPersistentMethodName(0))
|
2022-01-15 00:55:46 +03:00
|
|
|
|
{
|
2022-01-15 10:29:16 +03:00
|
|
|
|
case "Attack":
|
|
|
|
|
enemyStepIcon.sprite = allStepImageIcons[0];
|
|
|
|
|
enemyStepIconText.text = enemyConfig.enemyCharacteristics.damage.ToString();
|
|
|
|
|
break;
|
2022-01-15 23:26:40 +03:00
|
|
|
|
case "HealingSelf":
|
2022-01-15 10:29:16 +03:00
|
|
|
|
enemyStepIcon.sprite = allStepImageIcons[1];
|
|
|
|
|
enemyStepIconText.text = enemyConfig.enemyCharacteristics.selfHealing.ToString();
|
|
|
|
|
break;
|
2022-01-15 23:26:40 +03:00
|
|
|
|
case "HealingAlly":
|
2022-01-15 10:29:16 +03:00
|
|
|
|
enemyStepIcon.sprite = allStepImageIcons[2];
|
|
|
|
|
enemyStepIconText.text = enemyConfig.enemyCharacteristics.allyHealing.ToString();
|
|
|
|
|
break;
|
2022-01-15 23:26:40 +03:00
|
|
|
|
case "HealingAll":
|
2022-01-15 10:29:16 +03:00
|
|
|
|
enemyStepIcon.sprite = allStepImageIcons[3];
|
|
|
|
|
enemyStepIconText.text = enemyConfig.enemyCharacteristics.allHealing.ToString();
|
|
|
|
|
break;
|
2022-01-15 23:26:40 +03:00
|
|
|
|
case "AddArmorSelf":
|
|
|
|
|
enemyStepIcon.sprite = allStepImageIcons[4];
|
|
|
|
|
enemyStepIconText.text = enemyConfig.enemyCharacteristics.addArmorSelf.ToString();
|
|
|
|
|
break;
|
|
|
|
|
case "AddArmorAlly":
|
|
|
|
|
enemyStepIcon.sprite = allStepImageIcons[4];
|
|
|
|
|
enemyStepIconText.text = enemyConfig.enemyCharacteristics.addArmorAlly.ToString();
|
|
|
|
|
break;
|
|
|
|
|
case "AddArmorAll":
|
|
|
|
|
enemyStepIcon.sprite = allStepImageIcons[4];
|
|
|
|
|
enemyStepIconText.text = enemyConfig.enemyCharacteristics.addArmorAll.ToString();
|
|
|
|
|
break;
|
2022-01-15 00:55:46 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-13 11:00:37 +03:00
|
|
|
|
public void Turn()
|
|
|
|
|
{
|
2022-01-15 10:29:16 +03:00
|
|
|
|
int _phase = phaseAttack % attackLoop.Count;
|
|
|
|
|
attackLoop[_phase]?.Invoke();
|
2022-01-13 11:00:37 +03:00
|
|
|
|
phaseAttack++;
|
2022-01-15 00:55:46 +03:00
|
|
|
|
UpdateNextStepIconAndText();
|
2022-01-13 11:00:37 +03:00
|
|
|
|
}
|
2022-01-14 10:42:43 +03:00
|
|
|
|
|
|
|
|
|
public int CheckHp()
|
|
|
|
|
{
|
|
|
|
|
return hp;
|
|
|
|
|
}
|
2022-01-15 23:26:40 +03:00
|
|
|
|
public int CheckArmor()
|
|
|
|
|
{
|
|
|
|
|
return localarmor;
|
|
|
|
|
}
|
2022-01-14 10:42:43 +03:00
|
|
|
|
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
|
|
|
|
}
|