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 allStepImageIcons = new List(); 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] int phaseAttack = 0; public List attackLoop = new List(); [SerializeField] private int hp; [SerializeField] private int localarmor; [SerializeField] private Image armorIcon; [SerializeField] private Text armorText; [HideInInspector] public List effectsName = new List(); [HideInInspector] public List effectsTurns = new List(); [HideInInspector] public List effectsDamage = new List(); [HideInInspector] public List effectsLink = new List(); [HideInInspector] public bool hasStun = false; private void Start() { NewInformation(); UpdateNextStepIconAndText(); } public void onClick() { DeckManager.main.ActionInEnemy(this); } public void ChangeHp(int damage) { if (damage < 0) { hp -= damage; } else { AddArmor(-damage); if (localarmor < 0) { hp -= Mathf.Abs(localarmor); AddArmor(-localarmor); } } if (hp <= 0) { Death(); } else if (hp > enemyConfig.enemyCharacteristics.maxHp) { hp = enemyConfig.enemyCharacteristics.maxHp; } enemyHp.text = hp.ToString(); enemyHealthbar.value = hp; } public void AddArmor(int value) { localarmor += value; ReupdateArmorIconAndText(); } 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; AddArmor(_character.armor); } public void ReupdateArmorIconAndText() { if (localarmor <= 0) { armorIcon.enabled = false; armorText.text = ""; } else { armorIcon.enabled = true; armorText.text = localarmor.ToString(); } } public void Death() { Image _image = buttonInEnemy.image; _image.sprite = null; Session.main.EnemyDeath(gameObject); } public void EffectsBy() { for (int i = 0; i < effectsName.Count; i++) { if (effectsName[i] == "poison") { LibraryEffects.main.Poison(gameObject, effectsDamage[i]); effectsTurns[i] -= 1; } if (effectsName[i] == "stun") { LibraryEffects.main.Stun(gameObject); effectsTurns[i] -= 1; } } var _dopCounter = 0; var _effectsCount = effectsName.Count; for (int i = 0; i < _effectsCount; i++) { if (effectsTurns[_dopCounter] <= 0) { effectsName.Remove(effectsName[_dopCounter]); effectsTurns.Remove(effectsTurns[_dopCounter]); effectsDamage.Remove(effectsDamage[_dopCounter]); Destroy(effectsLink[_dopCounter]); effectsLink.RemoveAt(_dopCounter); } else { _dopCounter += 1; } } } 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 "HealingSelf": enemyStepIcon.sprite = allStepImageIcons[1]; enemyStepIconText.text = enemyConfig.enemyCharacteristics.selfHealing.ToString(); break; case "HealingAlly": enemyStepIcon.sprite = allStepImageIcons[2]; enemyStepIconText.text = enemyConfig.enemyCharacteristics.allyHealing.ToString(); break; case "HealingAll": enemyStepIcon.sprite = allStepImageIcons[3]; enemyStepIconText.text = enemyConfig.enemyCharacteristics.allHealing.ToString(); break; 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; case "Poison": enemyStepIcon.sprite = LibraryEffects.main.effectIcons[0].icon; enemyStepIconText.text = ""; break; case "Stun": enemyStepIcon.sprite = LibraryEffects.main.effectIcons[1].icon; enemyStepIconText.text = ""; break; } } public void Turn() { int _phase = phaseAttack % attackLoop.Count; if (hasStun is false) { attackLoop[_phase]?.Invoke(); phaseAttack++; UpdateNextStepIconAndText(); } else { hasStun = false; } } public int CheckHp() { return hp; } public int CheckArmor() { return localarmor; } public void OnMarker() { marker.enabled = true; } public void OffMarker() { marker.enabled = false; } public bool CheckMarker() { return marker.enabled; } }