Skill.cs 19 KB

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