BigSkill.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System;
  4. using System.Xml;
  5. using System.Text;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. public class BigSkill : Skill
  9. {
  10. #region 变量
  11. #region 配置
  12. public int SkillIndex;
  13. #endregion
  14. public Text BarLab;
  15. public Image BarBk0;
  16. public Image BarBk1;
  17. public Button BarBtn;
  18. public SkillStatus BarStatus
  19. {
  20. get { return _BarStatus; }
  21. set
  22. {
  23. _BarStatus = value;
  24. if (_BarStatus == SkillStatus.Cool)
  25. {
  26. BarBk0.SetActive(true);
  27. BarBk1.SetActive(false);
  28. ManaData.CoolList.Add(this);
  29. }
  30. else if (_BarStatus == SkillStatus.Buy)
  31. {
  32. if (SkillTab != SkillTab.Null && ItemStatus != SkillStatus.Upgrade)
  33. {
  34. BarBk0.SetActive(false);
  35. BarBk1.SetActive(true);
  36. BarBtn.interactable = false;
  37. BarLab.text = "";
  38. BarBk1.material = ManaReso.Load<Material>("Gray", Folder.Shader);
  39. }
  40. else
  41. {
  42. BarBk0.SetActive(false);
  43. BarBk1.SetActive(true);
  44. BarBtn.interactable = true;
  45. BarLab.text = "";
  46. }
  47. }
  48. else if (_BarStatus == SkillStatus.Use)
  49. {
  50. ManaData.UseList.Add(this);
  51. }
  52. else
  53. {
  54. throw new Exception();
  55. }
  56. }
  57. }
  58. public new SkillStatus ItemStatus
  59. {
  60. get { return _ItemStatus; }
  61. set
  62. {
  63. _ItemStatus = value;
  64. if (SkillTab == SkillTab.Null)
  65. {
  66. return;
  67. }
  68. if (_ItemStatus == SkillStatus.Lock)
  69. {
  70. ItemBtnLab.text = string.Format("{0}\n{1}{2}", Language.GetStr("UI", "Fe_BtnLab0"), Language.GetStr("UI", "Fe_BtnLab4"), UnlockLv);
  71. }
  72. else if (_ItemStatus == SkillStatus.UnLock)
  73. {
  74. ItemBtnLab.text = string.Format(Language.GetStr("UI", "Fe_BtnLab1"));
  75. }
  76. else if (_ItemStatus == SkillStatus.Upgrade)
  77. {
  78. ItemBtnLab.text = string.Format(Language.GetStr("UI", "Fe_BtnLab2"));
  79. }
  80. else
  81. {
  82. throw new Exception(_ItemStatus.ToString());
  83. }
  84. }
  85. }
  86. public SkillStatus _BarStatus;
  87. #endregion
  88. public BigSkill(XmlAttributeCollection attributes) : base(attributes)
  89. {
  90. SkillIndex = IntParse(attributes[4].Value);
  91. SkillType = SkillType.BigSkill;
  92. }
  93. public override void Annul()
  94. {
  95. CoolTimer = CD * (1 + CdBuff);
  96. BarLab.color = Color.white;
  97. BarStatus = SkillStatus.Cool;
  98. ManaData.SkillPlus -= NewPlus;
  99. ManaData.SkillPerson -= NewPerson;
  100. ManaData.SkillPersonBuff -= NewPersonBuff;
  101. ManaData.SkillCoinPerson -= NewCoinPerson;
  102. if (Math.Abs(NewSkillCD) > 0.0005f)
  103. {
  104. for (int i = 0; i < ManaData.SkillList.Count; i++)
  105. {
  106. ManaData.SkillList[i].ReceiveCool(-NewSkillCD, true, false);
  107. }
  108. }
  109. if (Math.Abs(NewSkillCdBuff) > 0.0005f)
  110. {
  111. for (int i = 0; i < ManaData.SkillList.Count; i++)
  112. {
  113. ManaData.SkillList[i].ReceiveCool(-NewSkillCdBuff, true, true);
  114. }
  115. }
  116. ManaDebug.Log(string.Format("技能结束 <color=red>{0}</color>", Name));
  117. }
  118. public override bool DoUse()
  119. {
  120. UseTimer -= Time.deltaTime;
  121. BarLab.text = UseTimer.ToString("0.0");
  122. if (UseTimer <= 0)
  123. {
  124. Annul();
  125. ManaData.UseList.Remove(this);
  126. return true;
  127. }
  128. else
  129. {
  130. return false;
  131. }
  132. }
  133. public override bool DoCool()
  134. {
  135. CoolTimer -= Time.deltaTime;
  136. TimeSpan timeSpan = new TimeSpan(0, 0, 0, (int)CoolTimer);
  137. BarLab.text = string.Format("{0} : {1}", timeSpan.Minutes, timeSpan.Seconds);
  138. BarBk0.fillAmount = CoolTimer / CD;
  139. if (CoolTimer <= 0)
  140. {
  141. BarStatus = SkillStatus.Buy;
  142. ManaData.CoolList.Remove(this);
  143. return true;
  144. }
  145. else
  146. {
  147. return false;
  148. }
  149. }
  150. public override void RegistValue(float elapse, List<List<SkillRoot>> ffList)
  151. {
  152. BarBtn.onClick.AddListener(Buy);
  153. BarBk1.sprite = ManaReso.Load<Sprite>(Icon + "副", Folder.Skill);
  154. NewPlus = Plus;
  155. NewPerson = Person;
  156. NewSkillCD = SkillCD;
  157. NewDuration = Duration;
  158. NewCoinOnce = CoinOnce;
  159. NewSkillCdBuff = SkillCdBuff;
  160. NewPersonBuff = PersonBuff;
  161. NewCoinPerson = CoinPerson;
  162. NewUpgradeAmt = UpgradeAmt;
  163. NewCoinOnceBuff = CoinOnceBuff;
  164. if (SkillTab == SkillTab.Null)
  165. {
  166. BarBk1.material = null;
  167. }
  168. else
  169. {
  170. ItemTit.text = Name;
  171. ItemLab.text = Description(0);
  172. ItemBtn.onClick.AddListener(OnClick);
  173. for (int i = 0; i < Level; i++)
  174. {
  175. NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString());
  176. }
  177. UpgradeValue(ref NewPlus, Plus, UpgradePlus, Level);
  178. UpgradeValue(ref NewSkillCdBuff, UpgradeCD, Level);
  179. UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, Level);
  180. UpgradeValue(ref NewCoinOnceBuff, UpgradeCoinOnce, Level);
  181. UpgradeValue(ref NewPerson, Person, UpgradePerson, Level);
  182. UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, Level);
  183. UpgradeValue(ref NewDuration, Duration, UpgradeDuration, Level);
  184. UpgradeValue(ref NewCoinOnce, CoinOnce, UpgradeCoinOnce, Level);
  185. UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, Level);
  186. if (_ItemStatus == SkillStatus.Upgrade)
  187. {
  188. BarBk1.material = null;
  189. ShowSkillBar();
  190. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁 等级 : {1}", Name, Level));
  191. }
  192. if (_BarStatus == SkillStatus.Use)
  193. {
  194. UsePerma();
  195. if (UseTimer < elapse)
  196. {
  197. if (ffList.Count > 0)
  198. {
  199. if (UseTimer < ManaData.CircleTimer)
  200. {
  201. ffList[0].UniqueAdd(this);
  202. }
  203. else
  204. {
  205. int ffCircle = 1 + Mathf.FloorToInt(((UseTimer - ManaData.CircleTimer) / ManaData.CircleTime));
  206. ffList[ffCircle].UniqueAdd(this);
  207. }
  208. }
  209. }
  210. else
  211. {
  212. UseTimer -= elapse;
  213. BarLab.color = Color.blue;
  214. }
  215. }
  216. else if (_BarStatus == SkillStatus.Cool)
  217. {
  218. CoolTimer -= elapse;
  219. }
  220. }
  221. ItemStatus = ItemStatus;
  222. BarStatus = BarStatus;
  223. }
  224. public override void ReceiveCool(float amt, bool current, bool buff)
  225. {
  226. if (!ReduceCD)
  227. {
  228. return;
  229. }
  230. if (current)
  231. {
  232. if (BarStatus != SkillStatus.Cool)
  233. {
  234. return;
  235. }
  236. if (buff)
  237. {
  238. CoolTimer -= CD * amt;
  239. }
  240. else
  241. {
  242. CoolTimer -= amt;
  243. }
  244. }
  245. else
  246. {
  247. if (buff)
  248. {
  249. CdBuff -= amt;
  250. }
  251. else
  252. {
  253. CD -= amt;
  254. }
  255. }
  256. }
  257. public override void RegistReference()
  258. {
  259. base.RegistReference();
  260. BarLab = ManaReso.Get<Text>(string.Format("F_SkillLab{0}", SkillIndex - 1));
  261. BarBk0 = ManaReso.Get<Image>(string.Format("F_SkillBk{0}0", SkillIndex - 1));
  262. BarBk1 = ManaReso.Get<Image>(string.Format("F_SkillBk{0}1", SkillIndex - 1));
  263. BarBtn = BarBk1.GetComponent<Button>();
  264. }
  265. private void ShowSkillBar()
  266. {
  267. if (!ManaData.SkillBar)
  268. {
  269. ManaData.SkillBar = true;
  270. ManaReso.Get("Fa_Scrr").TweenForRect();
  271. if (ManaReso.Get("Fa_Garden").gameObject.activeSelf)
  272. {
  273. ManaReso.SetActive("Ff_SkillBar", true);
  274. }
  275. }
  276. }
  277. protected override void Buy()
  278. {
  279. if (ManaData.Connect == false)
  280. {
  281. ManaReso.Get("Fg_Reconnect").TweenForCG();
  282. return;
  283. }
  284. if (ManaData.Pay(UseAmt, BuyCur))
  285. {
  286. UseTimer = NewDuration;
  287. if (Math.Abs(Duration) < 0.0005f)
  288. {
  289. BarStatus = SkillStatus.Cool;
  290. }
  291. else
  292. {
  293. BarStatus = SkillStatus.Use;
  294. BarLab.color = Color.blue;
  295. }
  296. UsePerma();
  297. UseImmed();
  298. #region 调试输出
  299. StringBuilder strb = new StringBuilder();
  300. strb.AppendFormat("使用技能 : <color=red>{0}</color>", Name);
  301. if (Math.Abs(NewPlus) > 0.0005f)
  302. {
  303. strb.AppendFormat(" 收入加成<color=red>+{0}%</color>", NewPlus * 100);
  304. }
  305. if (Math.Abs(NewPerson) > 0.0005f)
  306. {
  307. strb.AppendFormat(" 参观人次<color=red>+{0}</color>", NewPerson);
  308. }
  309. if (Math.Abs(NewPersonBuff) > 0.0005f)
  310. {
  311. strb.AppendFormat(" 参观人次<color=red>+{0}%</color>", NewPersonBuff * 100);
  312. }
  313. if (Math.Abs(NewCoinPerson) > 0.0005f)
  314. {
  315. strb.AppendFormat(" 每次金币<color=red>+{0}</color>", NewCoinPerson);
  316. }
  317. if (Math.Abs(NewSkillCD) > 0.0005f)
  318. {
  319. strb.AppendFormat(" 减少冷却<color=red>{0}</color>", NewSkillCD);
  320. }
  321. if (Math.Abs(NewSkillCdBuff) > 0.0005f)
  322. {
  323. strb.AppendFormat(" 减少冷却<color=red>{0}%</color>", NewSkillCdBuff * 100);
  324. }
  325. if (Math.Abs(NewCoinOnce) > 0.0005f)
  326. {
  327. strb.AppendFormat(" 获得金币<color=red>{0}</color>", NewCoinOnce);
  328. }
  329. if (Math.Abs(NewCoinOnceBuff) > 0.0005f)
  330. {
  331. strb.AppendFormat(" 获得金币<color=red>{0}</color>", ManaData.Person * ManaData.CoinPerson * ManaData.CircleTime * NewCoinOnceBuff);
  332. }
  333. if (Math.Abs(DiamondOnce) > 0.0005f)
  334. {
  335. strb.AppendFormat(" 获得钻石<color=red>{0}</color>", DiamondOnce);
  336. }
  337. if (Math.Abs(NewDuration) > 0.0005f)
  338. {
  339. strb.AppendFormat(" 持续时间<color=red>{0}</color>秒", NewDuration);
  340. }
  341. else
  342. {
  343. strb.Append(" <color=red>永久有效</color>");
  344. }
  345. ManaDebug.Log(strb.ToString());
  346. #endregion
  347. }
  348. }
  349. protected override void Unlock()
  350. {
  351. if (ManaData.Pay(UnlockAmt, UnlockCur))
  352. {
  353. ShowSkillBar();
  354. BarBk1.material = null;
  355. ItemStatus = SkillStatus.Upgrade;
  356. BarStatus = SkillStatus.Buy;
  357. if (SkillTab != SkillTab.Null)
  358. {
  359. ItemStatus = SkillStatus.Upgrade;
  360. }
  361. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
  362. }
  363. }
  364. protected override void Upgrade()
  365. {
  366. if (ManaData.Pay(NewUpgradeAmt, UpgradeCur))
  367. {
  368. Level++;
  369. NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString());
  370. UpgradeValue(ref NewPlus, Plus, UpgradePlus, 1);
  371. UpgradeValue(ref NewSkillCdBuff, UpgradeCD, 1);
  372. UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, 1);
  373. UpgradeValue(ref NewCoinOnceBuff, UpgradeCoinOnce, 1);
  374. UpgradeValue(ref NewPerson, Person, UpgradePerson, 1);
  375. UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, 1);
  376. UpgradeValue(ref NewDuration, Duration, UpgradeDuration, 1);
  377. UpgradeValue(ref NewCoinOnce, CoinOnce, UpgradeCoinOnce, 1);
  378. UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, 1);
  379. ItemLab.text = Description(0);
  380. ManaReso.SetText("Fe_Lab0", Description(0));
  381. ManaReso.SetText("Fe_Lab1", Description(1));
  382. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab2"), UpgradeCur, NewUpgradeAmt));
  383. ManaDebug.Log(string.Format("<color=red>{0}</color> 升级 : {1}", Name, Level));
  384. if (BarStatus == SkillStatus.Use)
  385. {
  386. Annul();
  387. UsePerma();
  388. }
  389. }
  390. }
  391. protected override void UnlockAhead()
  392. {
  393. if (ItemStatus != SkillStatus.Lock)
  394. {
  395. ManaDebug.Log("您并不需要提前解锁");
  396. return;
  397. }
  398. if (ManaData.Pay(UnlockAheadAmt, UnlockAheadCur))
  399. {
  400. BarStatus = SkillStatus.Buy;
  401. ItemStatus = SkillStatus.Upgrade;
  402. ManaReso.Get("Fe_Info").TweenBacCG();
  403. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
  404. }
  405. }
  406. }