Skill.cs 19 KB

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