Skill.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System;
  4. using System.Xml;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. public class Skill : SkillRoot
  10. {
  11. #region 变量
  12. #region 配置
  13. public override string ID
  14. {
  15. get
  16. {
  17. return "Skill" + ID_;
  18. }
  19. }
  20. public bool CoolLock;
  21. public float CD;
  22. public float Person;
  23. public float SkillCD;
  24. public float UseAmt;
  25. public float Duration;
  26. public float CoinOnce;
  27. public float CoinPerson;
  28. public float DiamondOnce;
  29. public double UpgradeAmt;
  30. public float Plus;
  31. public float CdBuff = 1;
  32. public float PersonBuff;
  33. public float SkillCdBuff;
  34. public float CoinOnceBuff;
  35. public int UnlockLv;
  36. public float UnlockAmt;
  37. public float UnlockAheadAmt;
  38. public string UnlockPos;
  39. public Current BuyCur;
  40. public Current UnlockCur;
  41. public Current UpgradeCur;
  42. public Current UnlockAheadCur;
  43. public string Label;
  44. public string Anim;
  45. public string UpgradeCD;
  46. public string UpgradeFml;
  47. public string UpgradePlus;
  48. public string UpgradePerson;
  49. public string UpgradeDuration;
  50. public string UpgradeCoinOnce;
  51. #endregion
  52. public float UseTimer;
  53. public float CoolTimer;
  54. public float NewPlus;
  55. public float NewPerson;
  56. public float NewSkillCD;
  57. public float NewDuration;
  58. public float NewCoinOnce;
  59. public float NewSkillCdBuff;
  60. public float NewPersonBuff;
  61. public float NewCoinPerson;
  62. public float NewCoinOnceBuff;
  63. public double NewUpgradeAmt;
  64. public override SkillStatus ItemStatus
  65. {
  66. get { return ItemStatus_; }
  67. set
  68. {
  69. ItemStatus_ = value;
  70. if (ItemStatus_ == SkillStatus.Buy)
  71. {
  72. ItemBtn.interactable = true;
  73. if (BuyCur == Current.AD)
  74. {
  75. ManaLan.Add(ItemBtnLab, new LanStr("Common", "AD"));
  76. }
  77. else
  78. {
  79. ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab3"), "\n", ImageParse(BuyCur), UseAmt.ToString("0"));
  80. }
  81. }
  82. else if (ItemStatus_ == SkillStatus.Use)
  83. {
  84. ItemBtn.interactable = false;
  85. }
  86. else if (ItemStatus_ == SkillStatus.Lock)
  87. {
  88. ItemBtn.interactable = false;
  89. ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab0"), "\n", new LanStr("UI", "Fe_BtnLab4"), UnlockLv.ToString());
  90. }
  91. else if (ItemStatus_ == SkillStatus.Cool)
  92. {
  93. ItemBtn.interactable = false;
  94. }
  95. }
  96. }
  97. #endregion
  98. public Skill(XmlAttributeCollection attribute)
  99. {
  100. #region 配置
  101. ID_ = int.Parse(attribute[0].Value);
  102. Icon_ = attribute[30].Value;
  103. Anim = attribute[31].Value;
  104. Label = attribute[32].Value;
  105. UnlockPos = attribute[18].Value;
  106. UpgradeCD = attribute[28].Value;
  107. UpgradeFml = attribute[23].Value;
  108. UpgradePlus = attribute[24].Value;
  109. UpgradePerson = attribute[25].Value;
  110. UpgradeDuration = attribute[27].Value;
  111. UpgradeCoinOnce = attribute[26].Value;
  112. UnlockLv = Auxiliary.IntParse(attribute[13].Value,0);
  113. ItemIndex = Auxiliary.IntParse(attribute[3].Value,0);
  114. CD = Auxiliary.FloatParse(attribute[12].Value,0);
  115. UseAmt = Auxiliary.FloatParse(attribute[20].Value,0);
  116. Duration = Auxiliary.FloatParse(attribute[11].Value,0);
  117. UnlockAmt = Auxiliary.FloatParse(attribute[17].Value,0);
  118. DiamondOnce = Auxiliary.FloatParse(attribute[9].Value,0);
  119. UnlockAheadAmt = Auxiliary.FloatParse(attribute[15].Value,0);
  120. SkillTab = SkillClassParse(attribute[2].Value);
  121. CoolLock = Auxiliary.BoolParse(attribute[5].Value, false);
  122. UpgradeAmt = UpgradeAmtParse(attribute[22].Value);
  123. BuyCur = CurrentParse(attribute[19].Value);
  124. UnlockCur = CurrentParse(attribute[16].Value);
  125. UpgradeCur = CurrentParse(attribute[21].Value);
  126. UnlockAheadCur = CurrentParse(attribute[14].Value);
  127. ValueBuffParse(out Person, out PersonBuff, attribute[7].Value);
  128. ValueBuffParse(out SkillCD, out SkillCdBuff, attribute[10].Value);
  129. ValueBuffParse(out CoinOnce, out CoinOnceBuff, attribute[8].Value);
  130. ValueBuffParse(out CoinPerson, out Plus, attribute[6].Value);
  131. #endregion
  132. SkillType = SkillType.Skill;
  133. }
  134. public virtual void AnnulB()
  135. {
  136. ManaCenter.SkillPlus -= NewPlus;
  137. ManaCenter.SkillPerson -= NewPerson;
  138. ManaCenter.SkillPersonBuff -= NewPersonBuff;
  139. ManaCenter.SkillCoinPerson -= NewCoinPerson;
  140. if (!NewSkillCD.Equal(0))
  141. {
  142. for (int i = 0; i < ManaCenter.SkillList.Count; i++)
  143. {
  144. ManaCenter.SkillList[i].ReceiveCool(-NewSkillCD, true, false);
  145. }
  146. }
  147. if (!NewSkillCdBuff.Equal(0))
  148. {
  149. for (int i = 0; i < ManaCenter.SkillList.Count; i++)
  150. {
  151. ManaCenter.SkillList[i].ReceiveCool(-NewSkillCdBuff, true, true);
  152. }
  153. }
  154. }
  155. public virtual bool DoCool()
  156. {
  157. CoolTimer -= Time.fixedDeltaTime;
  158. TimeSpan timeSpan = new TimeSpan(0, 0, Mathf.CeilToInt(CoolTimer));
  159. if (timeSpan.Hours >= 1)
  160. {
  161. ItemBtnLab.text = string.Format("{0}\n{1}{2}:{3}", Language.GetStr("UI", "Fe_BtnLab6"), Language.GetStr("UI", "Fe_BtnLab7"), timeSpan.Hours.ToString("00"), timeSpan.Minutes.ToString("00"));
  162. }
  163. else
  164. {
  165. ItemBtnLab.text = string.Format("{0}\n{1}{2}:{3}", Language.GetStr("UI", "Fe_BtnLab6"), Language.GetStr("UI", "Fe_BtnLab7"), timeSpan.Minutes.ToString("00"), timeSpan.Seconds.ToString("00"));
  166. }
  167. if (CoolTimer <= 0)
  168. {
  169. ItemStatus = SkillStatus.Buy;
  170. return true;
  171. }
  172. else
  173. {
  174. return false;
  175. }
  176. }
  177. public override bool DoUse()
  178. {
  179. UseTimer -= Time.fixedDeltaTime;
  180. TimeSpan timeSpan = new TimeSpan(0, 0, Mathf.CeilToInt(UseTimer));
  181. if (timeSpan.Hours >= 1)
  182. {
  183. ItemBtnLab.text = string.Format("{0}\n{1}{2}:{3}", Language.GetStr("UI", "Fe_BtnLab8"), Language.GetStr("UI", "Fe_BtnLab7"), timeSpan.Hours.ToString("00"), timeSpan.Minutes.ToString("00"));
  184. }
  185. else
  186. {
  187. ItemBtnLab.text = string.Format("{0}\n{1}{2}:{3}", Language.GetStr("UI", "Fe_BtnLab8"), Language.GetStr("UI", "Fe_BtnLab7"), timeSpan.Minutes.ToString("00"), timeSpan.Seconds.ToString("00"));
  188. }
  189. if (UseTimer <= 0)
  190. {
  191. AnnulA();
  192. return true;
  193. }
  194. else
  195. {
  196. return false;
  197. }
  198. }
  199. public override void AnnulA()
  200. {
  201. CoolTimer = CD * CdBuff - 1;
  202. ItemStatus = SkillStatus.Cool;
  203. ManaCenter.CoolList.Add(this);
  204. AnnulB();
  205. }
  206. public override void UpdateStatus()
  207. {
  208. if (!ManaCenter.Complete)
  209. {
  210. return;
  211. }
  212. if (ManaCenter.Level >= UnlockLv)
  213. {
  214. if (ItemStatus == SkillStatus.Lock)
  215. {
  216. ItemStatus = SkillStatus.Buy;
  217. }
  218. }
  219. }
  220. protected virtual void UseB()
  221. {
  222. float temp = NewCoinOnce + ManaCenter.CoinPerson * NewCoinOnceBuff;
  223. ManaCenter.Coin += temp;
  224. ManaCenter.Diamond += DiamondOnce;
  225. StringBuilder sb = new StringBuilder();
  226. if (!temp.Equal(0))
  227. {
  228. sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), "<(金币)>", temp.ToString("0"));
  229. }
  230. if (!DiamondOnce.Equal(0))
  231. {
  232. sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), "<(钻石)>", DiamondOnce.ToString("0"));
  233. }
  234. string str = sb.ToString();
  235. if (!string.IsNullOrEmpty(str))
  236. {
  237. ManaInfo.Show(sb.ToString(), 10f);
  238. }
  239. }
  240. protected virtual void UseA()
  241. {
  242. if (UseTimer.Equal(-1))
  243. {
  244. AnnulA();
  245. }
  246. else
  247. {
  248. ItemStatus = SkillStatus.Use;
  249. ManaCenter.UseList.Add(this);
  250. }
  251. ManaCenter.SkillPlus += NewPlus;
  252. ManaCenter.SkillPerson += NewPerson;
  253. ManaCenter.SkillPersonBuff += NewPersonBuff;
  254. ManaCenter.SkillCoinPerson += NewCoinPerson;
  255. if (!NewSkillCD.Equal(0))
  256. {
  257. for (int i = 0; i < ManaCenter.SkillList.Count; i++)
  258. {
  259. ManaCenter.SkillList[i].ReceiveCool(NewSkillCD, true, false);
  260. }
  261. }
  262. if (!NewSkillCdBuff.Equal(0))
  263. {
  264. for (int i = 0; i < ManaCenter.SkillList.Count; i++)
  265. {
  266. ManaCenter.SkillList[i].ReceiveCool(NewSkillCdBuff, true, true);
  267. }
  268. }
  269. }
  270. protected virtual void Buy()
  271. {
  272. ManaCenter.Pay
  273. (
  274. ID,
  275. UseAmt,
  276. BuyCur,
  277. () =>
  278. {
  279. ManaAudio.PlayClip(Clip.SkillClip);
  280. if (BuyCur != Current.AD)
  281. {
  282. ManaCenter.SkillAmt++;
  283. }
  284. UseTimer = NewDuration - 1;
  285. UseA();
  286. UseB();
  287. ManaInfo.Show(string.Format("{0}{1}", Language.GetStr("UI", "J_Info1"), Language.GetStr("SkillName", ID)), 10f);
  288. }
  289. );
  290. }
  291. protected virtual void OnClick()
  292. {
  293. ManaAudio.PlayClip(Clip.BtnClip);
  294. if (ItemStatus == SkillStatus.Buy)
  295. {
  296. if (BuyCur == Current.AD)
  297. {
  298. Buy();
  299. }
  300. else
  301. {
  302. ManaReso.Get("Fe_Info").TweenForCG();
  303. ManaReso.SetText("Fe_Tit", Name);
  304. ManaReso.SetSprite("Fe_Icon", Icon);
  305. ManaReso.SetText("Fe_Lab0", "");
  306. ManaReso.SetText("Fe_Lab1", GetDescription(0));
  307. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab3"), ImageParse(BuyCur), UseAmt));
  308. ManaReso.SetButtonEvent
  309. (
  310. "Fe_Btn",
  311. () =>
  312. {
  313. Buy();
  314. ManaReso.Get("Fe_Info").TweenBacCG();
  315. }
  316. );
  317. }
  318. }
  319. else if (ItemStatus == SkillStatus.Lock)
  320. {
  321. ManaReso.Get("Fe_Info").TweenForCG();
  322. ManaReso.SetText("Fe_Tit", Name);
  323. ManaReso.SetSprite("Fe_Icon", Icon);
  324. ManaReso.SetText("Fe_Lab0", "");
  325. ManaReso.SetText("Fe_Lab1", GetDescription(0));
  326. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab0"), ImageParse(UnlockAheadCur), UnlockAheadAmt));
  327. ManaReso.SetButtonEvent
  328. (
  329. "Fe_Btn",
  330. () =>
  331. {
  332. UnlockAhead();
  333. ManaReso.Get("Fe_Info").TweenBacCG();
  334. }
  335. );
  336. }
  337. }
  338. protected virtual void UnlockAhead()
  339. {
  340. ManaCenter.Pay
  341. (
  342. ID,
  343. UnlockAheadAmt,
  344. UnlockAheadCur,
  345. () =>
  346. {
  347. ManaAudio.PlayClip(Clip.BtnClip);
  348. ItemStatus = SkillStatus.Buy;
  349. }
  350. );
  351. }
  352. public override void Reactive()
  353. {
  354. if (ItemStatus == SkillStatus.Use)
  355. {
  356. AnnulB();
  357. ManaCenter.UseList.Remove(this);
  358. }
  359. else if (ItemStatus == SkillStatus.Cool)
  360. {
  361. ManaCenter.CoolList.Remove(this);
  362. }
  363. }
  364. public override void RegistValue(bool firstRegist, float elapse, List<List<Skill>> useList, XmlAttributeCollection attribute)
  365. {
  366. Level = int.Parse(attribute[3].Value);
  367. UseTimer = float.Parse(attribute[5].Value);
  368. CoolTimer = float.Parse(attribute[4].Value);
  369. ItemStatus_ = (SkillStatus)Enum.Parse(typeof(SkillStatus), attribute[2].Value);
  370. NewPlus = Plus;
  371. NewPerson = Person;
  372. NewSkillCD = SkillCD;
  373. NewDuration = Duration;
  374. NewCoinOnce = CoinOnce;
  375. NewSkillCdBuff = SkillCdBuff;
  376. NewPersonBuff = PersonBuff;
  377. NewCoinPerson = CoinPerson;
  378. NewUpgradeAmt = UpgradeAmt;
  379. NewCoinOnceBuff = CoinOnceBuff;
  380. if (ItemStatus_ == SkillStatus.Use)
  381. {
  382. UseA();
  383. if (UseTimer < elapse)
  384. {
  385. if (useList.Count > 0)
  386. {
  387. if (UseTimer < ManaCenter.CircleTimer)
  388. {
  389. useList[0].UniqueAdd(this);
  390. }
  391. else
  392. {
  393. int circle = 1 + Mathf.FloorToInt((UseTimer - ManaCenter.CircleTimer)/ManaCenter.CircleTime);
  394. useList[circle].UniqueAdd(this);
  395. }
  396. }
  397. }
  398. else
  399. {
  400. UseTimer -= elapse;
  401. }
  402. }
  403. else if (ItemStatus_ == SkillStatus.Cool)
  404. {
  405. CoolTimer -= elapse;
  406. ManaCenter.CoolList.Add(this);
  407. }
  408. ItemBtn.onClick.RemoveAllListeners();
  409. ItemBtn.onClick.AddListener(OnClick);
  410. ItemLab.text = GetDescription(0);
  411. ItemStatus = ItemStatus;
  412. }
  413. public override void ReceiveCool(float amt, bool current, bool buff)
  414. {
  415. if (!CoolLock)
  416. {
  417. return;
  418. }
  419. if (current)
  420. {
  421. if (ItemStatus != SkillStatus.Cool)
  422. {
  423. return;
  424. }
  425. if (buff)
  426. {
  427. CoolTimer -= CD * amt;
  428. }
  429. else
  430. {
  431. CoolTimer -= amt;
  432. }
  433. }
  434. else
  435. {
  436. if (buff)
  437. {
  438. CdBuff = 1 - amt;
  439. }
  440. else
  441. {
  442. CD -= amt;
  443. }
  444. }
  445. }
  446. #region 解读器
  447. protected double UpgradeAmtParse(string str)
  448. {
  449. if (string.IsNullOrEmpty(str))
  450. {
  451. return UnlockAmt;
  452. }
  453. else
  454. {
  455. return double.Parse(str);
  456. }
  457. }
  458. protected override string GetDescription(int offset)
  459. {
  460. float temp;
  461. string[] strings = Desc.Split('[', ']');
  462. StringBuilder stringBuilder = new StringBuilder();
  463. for (int i = 0; i < strings.Length; i++)
  464. {
  465. if (strings[i].Contains("lv"))
  466. {
  467. }
  468. else if (strings[i].Contains("&person&"))
  469. {
  470. #region MyRegion
  471. if (!Person.Equal(0))
  472. {
  473. temp = NewPerson;
  474. UpgradeValue(ref temp, Person, UpgradePerson, offset);
  475. UpgradeUnit(ref temp, strings[i]);
  476. float remainder = temp % 1;
  477. if (remainder > 0)
  478. {
  479. stringBuilder.Append(temp.ToString("0") + "+");
  480. }
  481. else
  482. {
  483. stringBuilder.Append(temp.ToString("0"));
  484. }
  485. }
  486. else if (!PersonBuff.Equal(0))
  487. {
  488. temp = NewPersonBuff;
  489. UpgradeValue(ref temp, UpgradePerson, offset);
  490. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  491. }
  492. #endregion
  493. }
  494. else if (strings[i].Contains("&duration&"))
  495. {
  496. #region MyRegion
  497. temp = NewDuration;
  498. UpgradeValue(ref temp, Duration, UpgradeDuration, offset);
  499. UpgradeUnit(ref temp, strings[i]);
  500. stringBuilder.Append(temp.ToString("0"));
  501. #endregion
  502. }
  503. else if (strings[i].Contains("&coin_once&"))
  504. {
  505. #region MyRegion
  506. if (!CoinOnce.Equal(0))
  507. {
  508. temp = NewCoinOnce;
  509. UpgradeValue(ref temp, CoinOnce, UpgradeCoinOnce, offset);
  510. stringBuilder.Append(temp.ToString("0"));
  511. }
  512. else if (!CoinOnceBuff.Equal(0))
  513. {
  514. temp = NewCoinOnceBuff;
  515. UpgradeValue(ref temp, UpgradeCoinOnce, offset);
  516. stringBuilder.Append(temp.ToString("0"));
  517. }
  518. #endregion
  519. }
  520. else if (strings[i].Contains("&diamond_once&"))
  521. {
  522. #region MyRegion
  523. stringBuilder.Append(DiamondOnce.ToString("0"));
  524. #endregion
  525. }
  526. else if (strings[i].Contains("&coin_person&"))
  527. {
  528. #region MyRegion
  529. if (!CoinPerson.Equal(0))
  530. {
  531. temp = NewCoinPerson;
  532. UpgradeValue(ref temp, CoinPerson, UpgradePlus, offset);
  533. float remainder = temp % 1;
  534. if (remainder > 0)
  535. {
  536. stringBuilder.Append(temp.ToString("0") + "+");
  537. }
  538. else
  539. {
  540. stringBuilder.Append(temp.ToString("0"));
  541. }
  542. }
  543. else if (!Plus.Equal(0))
  544. {
  545. temp = NewPlus;
  546. UpgradeValue(ref temp, UpgradePlus, offset);
  547. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  548. }
  549. else
  550. {
  551. throw new Exception();
  552. }
  553. #endregion
  554. }
  555. else
  556. {
  557. stringBuilder.Append(strings[i]);
  558. }
  559. }
  560. return stringBuilder.ToString();
  561. }
  562. #endregion
  563. }