BattleManager.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class BattleManager : MonoBehaviour
  5. {
  6. public Material DeathMaterial;
  7. public Texture[] CharacterTextures;
  8. public GameObject PlayerWarriorPrefab;
  9. public GameObject PlayerArcherPrefab;
  10. public GameObject EnemyWarriorPrefab;
  11. public GameObject EnemyArcherPrefab;
  12. public GameObject GoldForDeadPrefab;
  13. public UpgradeLevels[] WarriorUpgradeLevel;
  14. [HideInInspector] public List<Warrior> EnemyStageWarriors = new List<Warrior>();
  15. [HideInInspector] public List<Warrior> PlayerStageWarriors = new List<Warrior>();
  16. private int _counter;
  17. private bool _isStageEnd;
  18. public void StartBattle()
  19. {
  20. // EnemyStageWarriors.Clear();
  21. _isStageEnd = false;
  22. EnemyStageWarriors = ComponentsManager.StagesManager.GetCurrentStageItem.Enemys;
  23. PlayerStageWarriors = ComponentsManager.PlayerArmyManager.PlayerWarriors;
  24. for (int i = 0; i < EnemyStageWarriors.Count; i++)
  25. {
  26. EnemyStageWarriors[i].IsStop = false;
  27. EnemyStageWarriors[i].SearchTarget();
  28. }
  29. for (int i = 0; i < PlayerStageWarriors.Count; i++)
  30. {
  31. PlayerStageWarriors[i].IsStop = false;
  32. PlayerStageWarriors[i].SearchTarget();
  33. }
  34. }
  35. public void CheckStatus()
  36. {
  37. EnemyStageWarriors = ComponentsManager.StagesManager.GetCurrentStageItem.Enemys;
  38. PlayerStageWarriors = ComponentsManager.PlayerArmyManager.PlayerWarriors;
  39. //Player Win
  40. if (EnemyStageWarriors.Count <= 0)
  41. {
  42. if (!_isStageEnd)
  43. {
  44. _isStageEnd = true;
  45. if (ComponentsManager.StagesManager.NextStage())
  46. {
  47. _counter = 0;
  48. for (int i = 0; i < PlayerStageWarriors.Count; i++)
  49. {
  50. PlayerStageWarriors[i].IsStop = true;
  51. PlayerStageWarriors[i]
  52. .GoToNextPoint(ComponentsManager.StagesManager.GetCurrentStageItem.GetPlayerPoint(_counter).position);
  53. _counter++;
  54. }
  55. StartCoroutine(StageWin());
  56. }
  57. else
  58. {
  59. for (int i = 0; i < PlayerStageWarriors.Count; i++)
  60. PlayerStageWarriors[i].PlayerWinner();
  61. ComponentsManager.GameUI.PlayerWinner();
  62. }
  63. }
  64. }
  65. //Player Lose
  66. if (PlayerStageWarriors.Count <= 0)
  67. {
  68. if (!_isStageEnd)
  69. {
  70. _isStageEnd = true;
  71. for (int i = 0; i < EnemyStageWarriors.Count; i++)
  72. {
  73. EnemyStageWarriors[i].IsStop = true;
  74. EnemyStageWarriors[i].PlayerWinner();
  75. }
  76. ComponentsManager.GameUI.PlayerLose();
  77. }
  78. }
  79. }
  80. IEnumerator StageWin()
  81. {
  82. yield return new WaitForSeconds(1.5f);
  83. ComponentsManager.CameraScript.SetCameraPosition(new Vector3(-3.75f, 13f,
  84. -16f + (ComponentsManager.StagesManager.StageLevel * 23)));
  85. yield return new WaitForSeconds(4f);
  86. ComponentsManager.PlayerArmyManager.ResetPlayerWarriors();
  87. ComponentsManager.MenuUI.ActivateMenu(true);
  88. }
  89. }