Skill.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  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.AddCoin(temp, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.AD);
  231. ManaCenter.AddDiamond(DiamondOnce, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.AD);
  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. if (ID_ == 5)
  280. {
  281. StaticsManager.GetInstance().AdClicked(1);
  282. }
  283. else if (ID_ == 6)
  284. {
  285. StaticsManager.GetInstance().AdClicked(2);
  286. }
  287. ManaCenter.Pay
  288. (
  289. ID,
  290. UseAmt,
  291. BuyCur,
  292. () =>
  293. {
  294. ManaAudio.PlayClip(Clip.SkillClip);
  295. if (BuyCur != Current.AD)
  296. {
  297. ManaCenter.SkillAmt++;
  298. }
  299. UseTimer = NewDuration - 1;
  300. UseA();
  301. UseB();
  302. ManaInfo.Show(string.Format("{0}{1}", Language.GetStr("UI", "J_Info1"), Language.GetStr("SkillName", ID)), 10f);
  303. },
  304. StaticsManager.ItemID.使用技能,
  305. StaticsManager.ConsumeModule.Shop
  306. );
  307. }
  308. protected virtual void OnClick()
  309. {
  310. ManaAudio.PlayClip(Clip.BtnClip);
  311. if (ItemStatus == SkillStatus.Buy)
  312. {
  313. if (BuyCur == Current.AD)
  314. {
  315. Buy();
  316. }
  317. else
  318. {
  319. ManaReso.Get("Fe_Info").TweenForCG();
  320. ManaReso.SetText("Fe_Tit", Name);
  321. ManaReso.SetSprite("Fe_Icon", Icon);
  322. ManaReso.SetText("Fe_Lab0", "");
  323. ManaReso.SetText("Fe_Lab1", GetDescription(0));
  324. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab3"), Auxiliary.ImageParse(BuyCur), UseAmt));
  325. ManaReso.SetButtonEvent
  326. (
  327. "Fe_Btn",
  328. () =>
  329. {
  330. Buy();
  331. ManaReso.Get("Fe_Info").TweenBacCG();
  332. }
  333. );
  334. }
  335. }
  336. else if (ItemStatus == SkillStatus.Lock)
  337. {
  338. ManaReso.Get("Fe_Info").TweenForCG();
  339. ManaReso.SetText("Fe_Tit", Name);
  340. ManaReso.SetSprite("Fe_Icon", Icon);
  341. ManaReso.SetText("Fe_Lab0", "");
  342. ManaReso.SetText("Fe_Lab1", GetDescription(0));
  343. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab0"), Auxiliary.ImageParse(UnlockAheadCur), UnlockAheadAmt.ToString("0")));
  344. ManaReso.SetButtonEvent
  345. (
  346. "Fe_Btn",
  347. () =>
  348. {
  349. UnlockAhead();
  350. ManaReso.Get("Fe_Info").TweenBacCG();
  351. }
  352. );
  353. }
  354. }
  355. protected virtual void UnlockAhead()
  356. {
  357. ManaCenter.Pay
  358. (
  359. ID,
  360. UnlockAheadAmt,
  361. UnlockAheadCur,
  362. () =>
  363. {
  364. ManaAudio.PlayClip(Clip.BtnClip);
  365. ItemIcon.material = null;
  366. ItemStatus = SkillStatus.Buy;
  367. },
  368. StaticsManager.ItemID.提前解锁技能,
  369. StaticsManager.ConsumeModule.Shop
  370. );
  371. }
  372. public override void Reactive()
  373. {
  374. if (ItemStatus == SkillStatus.Use)
  375. {
  376. AnnulB();
  377. ManaCenter.UseList.Remove(this);
  378. }
  379. else if (ItemStatus == SkillStatus.Cool)
  380. {
  381. ManaCenter.CoolList.Remove(this);
  382. }
  383. }
  384. public override void RegistValue(bool firstRegist, float elapse, List<List<Skill>> useList, XmlAttributeCollection attribute)
  385. {
  386. Level = int.Parse(attribute[3].Value);
  387. UseTimer = float.Parse(attribute[5].Value);
  388. CoolTimer = float.Parse(attribute[4].Value);
  389. ItemStatus_ = (SkillStatus)Enum.Parse(typeof(SkillStatus), attribute[2].Value);
  390. NewPlus = Plus;
  391. NewPerson = Person;
  392. NewSkillCD = SkillCD;
  393. NewDuration = Duration;
  394. NewCoinOnce = CoinOnce;
  395. NewSkillCdBuff = SkillCdBuff;
  396. NewPersonBuff = PersonBuff;
  397. NewCoinPerson = CoinPerson;
  398. NewUpgradeAmt = UpgradeAmt;
  399. NewCoinOnceBuff = CoinOnceBuff;
  400. if (ItemStatus_ == SkillStatus.Lock || ItemStatus_ == SkillStatus.UnLock)
  401. {
  402. ItemIcon.material = Lib.GrayMat;
  403. }
  404. else
  405. {
  406. ItemIcon.material = null;
  407. }
  408. if (ItemStatus_ == SkillStatus.Use)
  409. {
  410. UseA();
  411. if (UseTimer < elapse)
  412. {
  413. ManaCenter.UseList.Remove(this);
  414. if (useList.Count > 0)
  415. {
  416. if (UseTimer < ManaCenter.CircleTimer)
  417. {
  418. useList[0].UniqueAdd(this);
  419. }
  420. else
  421. {
  422. int circle = 1 + Mathf.FloorToInt((UseTimer - ManaCenter.CircleTimer)/ManaCenter.CircleTime);
  423. useList[circle].UniqueAdd(this);
  424. }
  425. }
  426. }
  427. else
  428. {
  429. UseTimer -= elapse;
  430. }
  431. }
  432. else if (ItemStatus_ == SkillStatus.Cool)
  433. {
  434. CoolTimer -= elapse;
  435. ManaCenter.CoolList.Add(this);
  436. }
  437. ItemBtn.onClick.RemoveAllListeners();
  438. ItemBtn.onClick.AddListener(OnClick);
  439. ItemLab.text = GetDescription(0);
  440. ItemStatus = ItemStatus;
  441. }
  442. public override void ReceiveCool(float amt, bool current, bool buff)
  443. {
  444. if (!CoolLock)
  445. {
  446. return;
  447. }
  448. if (current)
  449. {
  450. if (ItemStatus != SkillStatus.Cool)
  451. {
  452. return;
  453. }
  454. if (buff)
  455. {
  456. CoolTimer -= CD * amt;
  457. }
  458. else
  459. {
  460. CoolTimer -= amt;
  461. }
  462. }
  463. else
  464. {
  465. if (buff)
  466. {
  467. CdBuff = 1 - amt;
  468. }
  469. else
  470. {
  471. CD -= amt;
  472. }
  473. }
  474. }
  475. #region 解读器
  476. protected double UpgradeAmtParse(string str)
  477. {
  478. if (string.IsNullOrEmpty(str))
  479. {
  480. return UnlockAmt;
  481. }
  482. else
  483. {
  484. return double.Parse(str);
  485. }
  486. }
  487. protected override string GetDescription(int offset)
  488. {
  489. float temp;
  490. string[] strings = Desc.Split('[', ']');
  491. StringBuilder stringBuilder = new StringBuilder();
  492. for (int i = 0; i < strings.Length; i++)
  493. {
  494. if (strings[i].Contains("lv"))
  495. {
  496. }
  497. else if (strings[i].Contains("&person&"))
  498. {
  499. #region MyRegion
  500. if (!Person.Equal(0))
  501. {
  502. temp = NewPerson;
  503. UpgradeValue(ref temp, Person, UpgradePerson, offset);
  504. UpgradeUnit(ref temp, strings[i]);
  505. float remainder = temp % 1;
  506. if (remainder > 0)
  507. {
  508. stringBuilder.Append(temp.ToString("0") + "+");
  509. }
  510. else
  511. {
  512. stringBuilder.Append(temp.ToString("0"));
  513. }
  514. }
  515. else if (!PersonBuff.Equal(0))
  516. {
  517. temp = NewPersonBuff;
  518. UpgradeValue(ref temp, UpgradePerson, offset);
  519. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  520. }
  521. #endregion
  522. }
  523. else if (strings[i].Contains("&duration&"))
  524. {
  525. #region MyRegion
  526. temp = NewDuration;
  527. UpgradeValue(ref temp, Duration, UpgradeDuration, offset);
  528. UpgradeUnit(ref temp, strings[i]);
  529. stringBuilder.Append(temp.ToString("0"));
  530. #endregion
  531. }
  532. else if (strings[i].Contains("&coin_once&"))
  533. {
  534. #region MyRegion
  535. if (!CoinOnce.Equal(0))
  536. {
  537. temp = NewCoinOnce;
  538. UpgradeValue(ref temp, CoinOnce, UpgradeCoinOnce, offset);
  539. stringBuilder.Append(temp.ToString("0"));
  540. }
  541. else if (!CoinOnceBuff.Equal(0))
  542. {
  543. temp = NewCoinOnceBuff;
  544. UpgradeValue(ref temp, UpgradeCoinOnce, offset);
  545. stringBuilder.Append(temp.ToString("0"));
  546. }
  547. #endregion
  548. }
  549. else if (strings[i].Contains("&diamond_once&"))
  550. {
  551. #region MyRegion
  552. stringBuilder.Append(DiamondOnce.ToString("0"));
  553. #endregion
  554. }
  555. else if (strings[i].Contains("&coin_person&"))
  556. {
  557. #region MyRegion
  558. if (!CoinPerson.Equal(0))
  559. {
  560. temp = NewCoinPerson;
  561. UpgradeValue(ref temp, CoinPerson, UpgradePlus, offset);
  562. float remainder = temp % 1;
  563. if (remainder > 0)
  564. {
  565. stringBuilder.Append(temp.ToString("0") + "+");
  566. }
  567. else
  568. {
  569. stringBuilder.Append(temp.ToString("0"));
  570. }
  571. }
  572. else if (!Plus.Equal(0))
  573. {
  574. temp = NewPlus;
  575. UpgradeValue(ref temp, UpgradePlus, offset);
  576. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  577. }
  578. else
  579. {
  580. throw new Exception();
  581. }
  582. #endregion
  583. }
  584. else
  585. {
  586. stringBuilder.Append(strings[i]);
  587. }
  588. }
  589. return stringBuilder.ToString();
  590. }
  591. #endregion
  592. }