Skill.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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", 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 = false;
  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 = CurrentParse(attribute[20].Value);
  130. UnlockCur = CurrentParse(attribute[17].Value);
  131. UpgradeCur = CurrentParse(attribute[22].Value);
  132. UnlockAheadCur = 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. ItemStatus = SkillStatus.Buy;
  223. }
  224. }
  225. }
  226. protected virtual void UseB()
  227. {
  228. float temp = NewCoinOnce + ManaCenter.CoinPerson * NewCoinOnceBuff;
  229. ManaCenter.Coin += temp;
  230. ManaCenter.Diamond += DiamondOnce;
  231. StringBuilder sb = new StringBuilder();
  232. if (!temp.Equal(0))
  233. {
  234. sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), "<(金币)>", temp.ToString("0"));
  235. }
  236. if (!DiamondOnce.Equal(0))
  237. {
  238. sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), "<(钻石)>", DiamondOnce.ToString("0"));
  239. }
  240. string str = sb.ToString();
  241. if (!string.IsNullOrEmpty(str))
  242. {
  243. ManaInfo.Show(sb.ToString(), 10f);
  244. }
  245. }
  246. protected virtual void UseA()
  247. {
  248. if (UseTimer.Equal(-1))
  249. {
  250. AnnulA();
  251. }
  252. else
  253. {
  254. ItemStatus = SkillStatus.Use;
  255. ManaCenter.UseList.Add(this);
  256. }
  257. ManaCenter.SkillPlus += NewPlus;
  258. ManaCenter.SkillPerson += NewPerson;
  259. ManaCenter.SkillPersonBuff += NewPersonBuff;
  260. ManaCenter.SkillCoinPerson += NewCoinPerson;
  261. if (!NewSkillCD.Equal(0))
  262. {
  263. for (int i = 0; i < ManaCenter.SkillList.Count; i++)
  264. {
  265. ManaCenter.SkillList[i].ReceiveCool(NewSkillCD, true, false);
  266. }
  267. }
  268. if (!NewSkillCdBuff.Equal(0))
  269. {
  270. for (int i = 0; i < ManaCenter.SkillList.Count; i++)
  271. {
  272. ManaCenter.SkillList[i].ReceiveCool(NewSkillCdBuff, true, true);
  273. }
  274. }
  275. }
  276. protected virtual void Buy()
  277. {
  278. ManaCenter.Pay
  279. (
  280. ID,
  281. UseAmt,
  282. BuyCur,
  283. () =>
  284. {
  285. ManaAudio.PlayClip(Clip.SkillClip);
  286. if (BuyCur != Current.AD)
  287. {
  288. ManaCenter.SkillAmt++;
  289. }
  290. UseTimer = NewDuration - 1;
  291. UseA();
  292. UseB();
  293. ManaInfo.Show(string.Format("{0}{1}", Language.GetStr("UI", "J_Info1"), Language.GetStr("SkillName", ID)), 10f);
  294. }
  295. );
  296. }
  297. protected virtual void OnClick()
  298. {
  299. ManaAudio.PlayClip(Clip.BtnClip);
  300. if (ItemStatus == SkillStatus.Buy)
  301. {
  302. if (BuyCur == Current.AD)
  303. {
  304. Buy();
  305. }
  306. else
  307. {
  308. ManaReso.Get("Fe_Info").TweenForCG();
  309. ManaReso.SetText("Fe_Tit", Name);
  310. ManaReso.SetSprite("Fe_Icon", Icon);
  311. ManaReso.SetText("Fe_Lab0", "");
  312. ManaReso.SetText("Fe_Lab1", GetDescription(0));
  313. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab3"), ImageParse(BuyCur), UseAmt));
  314. ManaReso.SetButtonEvent
  315. (
  316. "Fe_Btn",
  317. () =>
  318. {
  319. Buy();
  320. ManaReso.Get("Fe_Info").TweenBacCG();
  321. }
  322. );
  323. }
  324. }
  325. else if (ItemStatus == SkillStatus.Lock)
  326. {
  327. ManaReso.Get("Fe_Info").TweenForCG();
  328. ManaReso.SetText("Fe_Tit", Name);
  329. ManaReso.SetSprite("Fe_Icon", Icon);
  330. ManaReso.SetText("Fe_Lab0", "");
  331. ManaReso.SetText("Fe_Lab1", GetDescription(0));
  332. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab0"), ImageParse(UnlockAheadCur), UnlockAheadAmt.ToString("0")));
  333. ManaReso.SetButtonEvent
  334. (
  335. "Fe_Btn",
  336. () =>
  337. {
  338. UnlockAhead();
  339. ManaReso.Get("Fe_Info").TweenBacCG();
  340. }
  341. );
  342. }
  343. }
  344. protected virtual void UnlockAhead()
  345. {
  346. ManaCenter.Pay
  347. (
  348. ID,
  349. UnlockAheadAmt,
  350. UnlockAheadCur,
  351. () =>
  352. {
  353. ManaAudio.PlayClip(Clip.BtnClip);
  354. ItemStatus = SkillStatus.Buy;
  355. }
  356. );
  357. }
  358. public override void Reactive()
  359. {
  360. if (ItemStatus == SkillStatus.Use)
  361. {
  362. AnnulB();
  363. ManaCenter.UseList.Remove(this);
  364. }
  365. else if (ItemStatus == SkillStatus.Cool)
  366. {
  367. ManaCenter.CoolList.Remove(this);
  368. }
  369. }
  370. public override void RegistValue(bool firstRegist, float elapse, List<List<Skill>> useList, XmlAttributeCollection attribute)
  371. {
  372. Level = int.Parse(attribute[3].Value);
  373. UseTimer = float.Parse(attribute[5].Value);
  374. CoolTimer = float.Parse(attribute[4].Value);
  375. ItemStatus_ = (SkillStatus)Enum.Parse(typeof(SkillStatus), attribute[2].Value);
  376. NewPlus = Plus;
  377. NewPerson = Person;
  378. NewSkillCD = SkillCD;
  379. NewDuration = Duration;
  380. NewCoinOnce = CoinOnce;
  381. NewSkillCdBuff = SkillCdBuff;
  382. NewPersonBuff = PersonBuff;
  383. NewCoinPerson = CoinPerson;
  384. NewUpgradeAmt = UpgradeAmt;
  385. NewCoinOnceBuff = CoinOnceBuff;
  386. if (ItemStatus_ == SkillStatus.Use)
  387. {
  388. UseA();
  389. if (UseTimer < elapse)
  390. {
  391. ManaCenter.UseList.Remove(this);
  392. if (useList.Count > 0)
  393. {
  394. if (UseTimer < ManaCenter.CircleTimer)
  395. {
  396. useList[0].UniqueAdd(this);
  397. }
  398. else
  399. {
  400. int circle = 1 + Mathf.FloorToInt((UseTimer - ManaCenter.CircleTimer)/ManaCenter.CircleTime);
  401. useList[circle].UniqueAdd(this);
  402. }
  403. }
  404. }
  405. else
  406. {
  407. UseTimer -= elapse;
  408. }
  409. }
  410. else if (ItemStatus_ == SkillStatus.Cool)
  411. {
  412. CoolTimer -= elapse;
  413. ManaCenter.CoolList.Add(this);
  414. }
  415. ItemBtn.onClick.RemoveAllListeners();
  416. ItemBtn.onClick.AddListener(OnClick);
  417. ItemLab.text = GetDescription(0);
  418. ItemStatus = ItemStatus;
  419. }
  420. public override void ReceiveCool(float amt, bool current, bool buff)
  421. {
  422. if (!CoolLock)
  423. {
  424. return;
  425. }
  426. if (current)
  427. {
  428. if (ItemStatus != SkillStatus.Cool)
  429. {
  430. return;
  431. }
  432. if (buff)
  433. {
  434. CoolTimer -= CD * amt;
  435. }
  436. else
  437. {
  438. CoolTimer -= amt;
  439. }
  440. }
  441. else
  442. {
  443. if (buff)
  444. {
  445. CdBuff = 1 - amt;
  446. }
  447. else
  448. {
  449. CD -= amt;
  450. }
  451. }
  452. }
  453. #region 解读器
  454. protected double UpgradeAmtParse(string str)
  455. {
  456. if (string.IsNullOrEmpty(str))
  457. {
  458. return UnlockAmt;
  459. }
  460. else
  461. {
  462. return double.Parse(str);
  463. }
  464. }
  465. protected override string GetDescription(int offset)
  466. {
  467. float temp;
  468. string[] strings = Desc.Split('[', ']');
  469. StringBuilder stringBuilder = new StringBuilder();
  470. for (int i = 0; i < strings.Length; i++)
  471. {
  472. if (strings[i].Contains("lv"))
  473. {
  474. }
  475. else if (strings[i].Contains("&person&"))
  476. {
  477. #region MyRegion
  478. if (!Person.Equal(0))
  479. {
  480. temp = NewPerson;
  481. UpgradeValue(ref temp, Person, UpgradePerson, offset);
  482. UpgradeUnit(ref temp, strings[i]);
  483. float remainder = temp % 1;
  484. if (remainder > 0)
  485. {
  486. stringBuilder.Append(temp.ToString("0") + "+");
  487. }
  488. else
  489. {
  490. stringBuilder.Append(temp.ToString("0"));
  491. }
  492. }
  493. else if (!PersonBuff.Equal(0))
  494. {
  495. temp = NewPersonBuff;
  496. UpgradeValue(ref temp, UpgradePerson, offset);
  497. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  498. }
  499. #endregion
  500. }
  501. else if (strings[i].Contains("&duration&"))
  502. {
  503. #region MyRegion
  504. temp = NewDuration;
  505. UpgradeValue(ref temp, Duration, UpgradeDuration, offset);
  506. UpgradeUnit(ref temp, strings[i]);
  507. stringBuilder.Append(temp.ToString("0"));
  508. #endregion
  509. }
  510. else if (strings[i].Contains("&coin_once&"))
  511. {
  512. #region MyRegion
  513. if (!CoinOnce.Equal(0))
  514. {
  515. temp = NewCoinOnce;
  516. UpgradeValue(ref temp, CoinOnce, UpgradeCoinOnce, offset);
  517. stringBuilder.Append(temp.ToString("0"));
  518. }
  519. else if (!CoinOnceBuff.Equal(0))
  520. {
  521. temp = NewCoinOnceBuff;
  522. UpgradeValue(ref temp, UpgradeCoinOnce, offset);
  523. stringBuilder.Append(temp.ToString("0"));
  524. }
  525. #endregion
  526. }
  527. else if (strings[i].Contains("&diamond_once&"))
  528. {
  529. #region MyRegion
  530. stringBuilder.Append(DiamondOnce.ToString("0"));
  531. #endregion
  532. }
  533. else if (strings[i].Contains("&coin_person&"))
  534. {
  535. #region MyRegion
  536. if (!CoinPerson.Equal(0))
  537. {
  538. temp = NewCoinPerson;
  539. UpgradeValue(ref temp, CoinPerson, UpgradePlus, offset);
  540. float remainder = temp % 1;
  541. if (remainder > 0)
  542. {
  543. stringBuilder.Append(temp.ToString("0") + "+");
  544. }
  545. else
  546. {
  547. stringBuilder.Append(temp.ToString("0"));
  548. }
  549. }
  550. else if (!Plus.Equal(0))
  551. {
  552. temp = NewPlus;
  553. UpgradeValue(ref temp, UpgradePlus, offset);
  554. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  555. }
  556. else
  557. {
  558. throw new Exception();
  559. }
  560. #endregion
  561. }
  562. else
  563. {
  564. stringBuilder.Append(strings[i]);
  565. }
  566. }
  567. return stringBuilder.ToString();
  568. }
  569. #endregion
  570. }