ConductController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. using UnityEngine;
  2. using Sirenix.OdinInspector;
  3. using System.Collections.Generic;
  4. using System;
  5. using System.Linq;
  6. using TMPro;
  7. public class ConductController : MonoBehaviour
  8. {
  9. //组件
  10. private PlayerController playerController;
  11. private ConductManager conductManager;
  12. private GameManager gameManager;
  13. private SoldierLevelRecord soldierLevelRecord;
  14. [LabelText("品质")] public int[] rarity;
  15. public float[] conversionRate;
  16. public float[] totalCD;
  17. public float[] cd;
  18. [LabelText("融魂技")] public ConductSkills[] conductSkills;
  19. [Serializable] public struct Giant
  20. {
  21. public GameObject bigGiant;
  22. [LabelText("临时血量基数")]
  23. public int temptHp;
  24. [LabelText("临时血量持续时间")]
  25. public float temptTime;
  26. }
  27. private bool ShowGiant() => conductSkills.Contains(ConductSkills.Giant);
  28. [ShowIf("ShowGiant")][LabelText("合成大胖子参数")]
  29. public Giant giant;
  30. [Serializable]public struct Photon
  31. {
  32. public GameObject obj;
  33. [LabelText("血量基数")]
  34. public int photosphereHp;
  35. [DisplayOnly] public bool havePhoton;
  36. [HideInInspector] public Photosphere photosphere;
  37. }
  38. private bool ShowPhotosphere() => conductSkills.Contains(ConductSkills.Photon);
  39. [ShowIf("ShowPhotosphere")][LabelText("光球参数")]
  40. public Photon photon;
  41. private void Awake()
  42. {
  43. playerController = GetComponent<PlayerController>();
  44. conductManager = ConductManager.instance;
  45. gameManager = GameManager.instance;
  46. soldierLevelRecord = gameManager.GetComponent<SoldierLevelRecord>();
  47. for (int i = 0; i < 3; i++)
  48. {
  49. int demonicRarity = rarity[i];
  50. switch (conductSkills[i])
  51. {
  52. case ConductSkills.NetherfireRebirth:
  53. ConductManager.NetherfireRebirth netherfireRebirth = conductManager.netherfireRebirth;
  54. conversionRate[i] = netherfireRebirth.sacrificeRatio[demonicRarity];
  55. totalCD[i] = netherfireRebirth.cd[demonicRarity];
  56. break;
  57. case ConductSkills.FlyingSwords:
  58. ConductManager.FlyingSwords flyingSwords = conductManager.flyingSwords;
  59. conversionRate[i] = flyingSwords.sacrificeRatio[demonicRarity];
  60. totalCD[i] = flyingSwords.cd[demonicRarity];
  61. break;
  62. case ConductSkills.IceRain:
  63. ConductManager.IceRain iceRain = conductManager.iceRain;
  64. conversionRate[i] = iceRain.sacrificeRatio[demonicRarity];
  65. totalCD[i] = iceRain.cd[demonicRarity];
  66. break;
  67. }
  68. }
  69. }
  70. void Start()
  71. {
  72. }
  73. void Update()
  74. {
  75. for(int i = 0; i < 3; i++)
  76. {
  77. TextMeshProUGUI text = GameUI.instance.CD.GetChild(i).GetComponent<TextMeshProUGUI>();
  78. if (cd[i] > 0)
  79. {
  80. cd[i] -= Time.deltaTime;
  81. text.text = $"{(int)cd[i]}";
  82. text.gameObject.SetActive(true);
  83. }
  84. else
  85. {
  86. text.gameObject.SetActive(false);
  87. }
  88. }
  89. }
  90. public void Conduct(int demonicId)
  91. {
  92. int boostNum = playerController.demonicDic[demonicId].Count;
  93. int dienum = (int)(boostNum * conversionRate[demonicId]/100f + 0.5f);
  94. if (dienum == 0 && boostNum >= 1)
  95. {
  96. dienum = 1;
  97. }
  98. if (dienum > 0)
  99. {
  100. cd[demonicId] = totalCD[demonicId];
  101. GameObject obj;
  102. List<int> dieId = new List<int>();
  103. List<Demonic> dieDemonic = new List<Demonic>();
  104. List<Demonic> demonicDic = new List<Demonic>(playerController.demonicDic[demonicId]);
  105. for(int i = 0; i < dienum; i++)
  106. {
  107. int id = UnityEngine.Random.Range(0, demonicDic.Count);
  108. dieId.Add(id);
  109. dieDemonic.Add(demonicDic[id]);
  110. demonicDic.RemoveAt(id);
  111. }
  112. foreach (Demonic d in dieDemonic)
  113. {
  114. d.ChangeState(CharacterState.Die);
  115. }
  116. int attackDamage = playerController.demonicPrefabs[demonicId].GetComponent<Demonic>().attackController.attackMethod_summon[0].attackInfo.damage
  117. + soldierLevelRecord.seb[demonicId].summonAttack
  118. + gameManager.damage;
  119. List<int> myTreasureTag = gameManager.myTreasuresTag;
  120. float tagAdd = 1;
  121. int demonicRarity = rarity[demonicId];
  122. switch (conductSkills[demonicId])
  123. {
  124. case ConductSkills.NetherfireRebirth:
  125. ConductManager.NetherfireRebirth netherfireRebirth = conductManager.netherfireRebirth;
  126. for (int i = 0;i<dienum * netherfireRebirth.power[demonicRarity]; i++)
  127. {
  128. Demonic demonic = playerController.CreateDemonic(demonicId);
  129. if (netherfireRebirth.canDie)
  130. {
  131. demonic.summonEndToDie = true;
  132. }
  133. Vector3 targetPos = transform.position + new Vector3(
  134. UnityEngine.Random.Range(-netherfireRebirth.randomRange.x / 2, netherfireRebirth.randomRange.x / 2),
  135. UnityEngine.Random.Range(-netherfireRebirth.randomRange.y / 2, netherfireRebirth.randomRange.y / 2),
  136. 0);
  137. if (targetPos.y < 0)
  138. {
  139. targetPos.y = 0;
  140. }
  141. demonic.gameObject.transform.position = targetPos;
  142. demonic.attackController.attackSummonId = 0;
  143. tagAdd += netherfireRebirth.effectBonus[demonicRarity] * myTreasureTag [(int)netherfireRebirth.attributeTag - 1]/ 100;
  144. int damage = demonic.attackController.attackMethod_summon[0].attackInfo.damage;
  145. damage = (int)(damage * tagAdd);
  146. demonic.attackController.attackMethod_summon[0].attackInfo.damage = damage;
  147. demonic.Attack_summon();
  148. playerController.lastSoldier = SoldierType.Conduct;
  149. }
  150. break;
  151. case ConductSkills.FlyingSwords:
  152. ConductManager.FlyingSwords flyingSwords = conductManager.flyingSwords;
  153. obj = PoolManager.Instantiate(flyingSwords.obj);
  154. FanFlyingSwords FFS = obj.GetComponent<FanFlyingSwords>();
  155. FFS.owner = playerController;
  156. FFS.swordsNum = dienum * flyingSwords.power[demonicRarity];
  157. tagAdd += flyingSwords.effectBonus[demonicRarity] * myTreasureTag[(int)flyingSwords.attributeTag - 1] / 100;
  158. FFS.damage = (int)(attackDamage * tagAdd);
  159. FFS.Biu();
  160. break;
  161. case ConductSkills.IceRain:
  162. ConductManager.IceRain iceRain = conductManager.iceRain;
  163. obj = PoolManager.Instantiate(iceRain.obj);
  164. IceRainController iceRainController = obj.GetComponent<IceRainController>();
  165. iceRainController.owner = playerController;
  166. iceRainController.swordsNum = dienum * iceRain.power[demonicRarity];
  167. tagAdd += iceRain.effectBonus[demonicRarity] * myTreasureTag[(int)iceRain.attributeTag - 1] / 100;
  168. iceRainController.damage = (int)(attackDamage * tagAdd);
  169. iceRainController.Biu();
  170. break;
  171. /*胖子*/
  172. //融合大胖子
  173. case ConductSkills.Giant:
  174. GameObject demonicObj = PoolManager.Instantiate(giant.bigGiant);
  175. BigSoldier bs = demonicObj.GetComponent<BigSoldier>();
  176. bs.id = demonicId + 3;
  177. playerController.demonicDic[bs.id].Add(bs);
  178. if (bs.id < 3)
  179. {
  180. playerController.demonicNums[bs.id].text = playerController.demonicDic[bs.id].Count.ToString();
  181. }
  182. int tempthp = boostNum * giant.temptHp;
  183. bs.playerID = playerController.playerId;
  184. demonicObj.transform.parent = null;
  185. demonicObj.transform.localEulerAngles = Vector3.zero;
  186. bs.boostNum = boostNum;
  187. if (playerController.isInSoulTower)
  188. {
  189. playerController.ls.AddDenomic(bs);
  190. }
  191. bs.player = playerController;
  192. bs.Settings();
  193. bs.GetTemptHP(tempthp, giant.temptTime);
  194. int order = bs.baseSortingOrder + playerController.demonicDic[bs.id].Count;
  195. bs.SetSortingOrder(order);
  196. Vector3 offset = playerController.demonicSummonPos[0] * 2;
  197. if (playerController.bodyTrans.localScale.x > 0)
  198. {
  199. demonicObj.transform.position = transform.position + offset;
  200. if (bs.bodyTrans.localScale.x < 0)
  201. {
  202. bs.Turn();
  203. }
  204. }
  205. else
  206. {
  207. demonicObj.transform.position = transform.position + new Vector3(-offset.x, offset.y, offset.z);
  208. if (bs.bodyTrans.localScale.x > 0)
  209. {
  210. bs.Turn();
  211. }
  212. }
  213. bs.Attack_summon();
  214. demonicObj.SetActive(true);
  215. break;
  216. //光球
  217. case ConductSkills.Photon:
  218. playerController.conductCanRelease[demonicId] = false;
  219. obj = PoolManager.Instantiate(photon.obj);
  220. obj.transform.position = transform.position + Vector3.up;
  221. Photosphere photosphere = obj.GetComponent<Photosphere>();
  222. photosphere.owner = playerController;
  223. photosphere.conductId = demonicId;
  224. photosphere.hp = boostNum * photon.photosphereHp;
  225. photosphere.conductController = this;
  226. photon.photosphere = photosphere;
  227. photon.havePhoton = true;
  228. break;
  229. // case ConductSkills.SwordsControl:
  230. // conductCanRelease[cacheConductId] = false;
  231. // obj = Instantiate(flyingSwordsObj, transform);
  232. // obj.transform.position = transform.position + Vector3.up;
  233. // SwordsControl swordsControl = obj.GetComponentInChildren<SwordsControl>();
  234. // swordsControl.owner = this;
  235. // swordsControl.conductId = cacheConductId;
  236. // swordsControl.boostNum = boostNum;
  237. // break;
  238. }
  239. }
  240. }
  241. public bool HavePhoton(Character attackFrom, int damage)
  242. {
  243. if (photon.havePhoton)
  244. {
  245. photon.photosphere.Reflex(attackFrom.beHitTrigger, damage);
  246. return true;
  247. }
  248. return false;
  249. }
  250. }