Skill.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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. protected bool CoolLock;
  21. protected float CD;
  22. protected float Person;
  23. protected float SkillCD;
  24. protected float UseAmt;
  25. protected float Duration;
  26. protected float CoinOnce;
  27. protected float CoinPerson;
  28. protected float DiamondOnce;
  29. protected double UpgradeAmt;
  30. protected float Plus;
  31. protected float CdBuff = 1;
  32. protected float PersonBuff;
  33. protected float SkillCdBuff;
  34. protected float CoinOnceBuff;
  35. protected int UnlockLv;
  36. protected float UnlockAmt;
  37. protected float UnlockAheadAmt;
  38. protected string UnlockPos;
  39. protected Current BuyCur;
  40. protected Current UnlockCur;
  41. protected Current UpgradeCur;
  42. protected Current UnlockAheadCur;
  43. protected string Label;
  44. protected string Anim;
  45. protected string UpgradeCD;
  46. protected string UpgradeFml;
  47. protected string UpgradePlus;
  48. protected string UpgradePerson;
  49. protected string UpgradeDuration;
  50. protected string UpgradeCoinOnce;
  51. #endregion
  52. public float UseTimer;
  53. public float CoolTimer;
  54. protected float NewPlus;
  55. protected float NewPerson;
  56. protected float NewSkillCD;
  57. protected float NewDuration;
  58. protected float NewCoinOnce;
  59. protected float NewSkillCdBuff;
  60. protected float NewPersonBuff;
  61. protected float NewCoinPerson;
  62. protected float NewCoinOnceBuff;
  63. protected 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. 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"));
  160. if (CoolTimer <= 0)
  161. {
  162. ItemStatus = SkillStatus.Buy;
  163. return true;
  164. }
  165. else
  166. {
  167. return false;
  168. }
  169. }
  170. public override bool DoUse()
  171. {
  172. UseTimer -= Time.fixedDeltaTime;
  173. TimeSpan timeSpan = new TimeSpan(0, 0, Mathf.CeilToInt(UseTimer));
  174. 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"));
  175. if (UseTimer <= 0)
  176. {
  177. AnnulA();
  178. return true;
  179. }
  180. else
  181. {
  182. return false;
  183. }
  184. }
  185. public override void AnnulA()
  186. {
  187. CoolTimer = CD * CdBuff;
  188. ItemStatus = SkillStatus.Cool;
  189. ManaCenter.CoolList.Add(this);
  190. AnnulB();
  191. }
  192. public override void UpdateStatus()
  193. {
  194. if (!ManaCenter.Complete)
  195. {
  196. return;
  197. }
  198. if (ManaCenter.Level >= UnlockLv)
  199. {
  200. if (ItemStatus == SkillStatus.Lock)
  201. {
  202. ItemStatus = SkillStatus.Buy;
  203. }
  204. }
  205. }
  206. protected virtual void UseB()
  207. {
  208. float temp = NewCoinOnce + ManaCenter.CoinPerson * NewCoinOnceBuff;
  209. ManaCenter.Coin += temp;
  210. ManaCenter.Diamond += DiamondOnce;
  211. StringBuilder sb = new StringBuilder();
  212. if (!temp.Equal(0))
  213. {
  214. sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), "<(金币)>", temp.ToString("0"));
  215. }
  216. if (!DiamondOnce.Equal(0))
  217. {
  218. sb.AppendFormat("{0}{1}{2}", Language.GetStr("UI", "J_Info0"), "<(钻石)>", DiamondOnce.ToString("0"));
  219. }
  220. string str = sb.ToString();
  221. if (!string.IsNullOrEmpty(str))
  222. {
  223. ManaInfo.Show(sb.ToString(), 10f);
  224. }
  225. }
  226. protected virtual void UseA()
  227. {
  228. ManaCenter.UseList.Add(this);
  229. ManaCenter.SkillPlus += NewPlus;
  230. ManaCenter.SkillPerson += NewPerson;
  231. ManaCenter.SkillPersonBuff += NewPersonBuff;
  232. ManaCenter.SkillCoinPerson += NewCoinPerson;
  233. if (!NewSkillCD.Equal(0))
  234. {
  235. for (int i = 0; i < ManaCenter.SkillList.Count; i++)
  236. {
  237. ManaCenter.SkillList[i].ReceiveCool(NewSkillCD, true, false);
  238. }
  239. }
  240. if (!NewSkillCdBuff.Equal(0))
  241. {
  242. for (int i = 0; i < ManaCenter.SkillList.Count; i++)
  243. {
  244. ManaCenter.SkillList[i].ReceiveCool(NewSkillCdBuff, true, true);
  245. }
  246. }
  247. }
  248. protected virtual void Buy()
  249. {
  250. ManaCenter.Pay
  251. (
  252. ID,
  253. UseAmt,
  254. BuyCur,
  255. () =>
  256. {
  257. ManaAudio.PlayClip(Clip.SkillClip);
  258. if (BuyCur != Current.AD)
  259. {
  260. ManaCenter.SkillAmt++;
  261. }
  262. UseTimer = NewDuration;
  263. if (Duration.Equal(0))
  264. {
  265. ItemStatus = SkillStatus.Cool;
  266. }
  267. else
  268. {
  269. ItemStatus = SkillStatus.Use;
  270. }
  271. UseA();
  272. UseB();
  273. ManaInfo.Show(string.Format("{0}{1}", Language.GetStr("UI", "J_Info1"), Language.GetStr("SkillName", ID)), 10f);
  274. }
  275. );
  276. }
  277. protected virtual void OnClick()
  278. {
  279. ManaAudio.PlayClip(Clip.BtnClip);
  280. if (ItemStatus == SkillStatus.Buy)
  281. {
  282. if (BuyCur == Current.AD)
  283. {
  284. Buy();
  285. }
  286. else
  287. {
  288. ManaReso.Get("Fe_Info").TweenForCG();
  289. ManaReso.SetText("Fe_Tit", Name);
  290. ManaReso.SetSprite("Fe_Icon", Icon);
  291. ManaReso.SetText("Fe_Lab0", "");
  292. ManaReso.SetText("Fe_Lab1", GetDescription(0));
  293. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab3"), ImageParse(BuyCur), UseAmt));
  294. ManaReso.SetButtonEvent
  295. (
  296. "Fe_Btn",
  297. () =>
  298. {
  299. Buy();
  300. ManaReso.Get("Fe_Info").TweenBacCG();
  301. }
  302. );
  303. }
  304. }
  305. else if (ItemStatus == SkillStatus.Lock)
  306. {
  307. ManaReso.Get("Fe_Info").TweenForCG();
  308. ManaReso.SetText("Fe_Tit", Name);
  309. ManaReso.SetSprite("Fe_Icon", Icon);
  310. ManaReso.SetText("Fe_Lab0", "");
  311. ManaReso.SetText("Fe_Lab1", GetDescription(0));
  312. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab0"), ImageParse(UnlockAheadCur), UnlockAheadAmt));
  313. ManaReso.SetButtonEvent
  314. (
  315. "Fe_Btn",
  316. () =>
  317. {
  318. UnlockAhead();
  319. ManaReso.Get("Fe_Info").TweenBacCG();
  320. }
  321. );
  322. }
  323. }
  324. protected virtual void UnlockAhead()
  325. {
  326. ManaCenter.Pay
  327. (
  328. ID,
  329. UnlockAheadAmt,
  330. UnlockAheadCur,
  331. () =>
  332. {
  333. ManaAudio.PlayClip(Clip.BtnClip);
  334. ItemStatus = SkillStatus.Buy;
  335. }
  336. );
  337. }
  338. public override void Reactive()
  339. {
  340. if (ItemStatus == SkillStatus.Use)
  341. {
  342. AnnulB();
  343. ManaCenter.UseList.Remove(this);
  344. }
  345. else if (ItemStatus == SkillStatus.Cool)
  346. {
  347. ManaCenter.CoolList.Remove(this);
  348. }
  349. }
  350. public override void RegistValue(float elapse, List<List<Skill>> useList, XmlAttributeCollection attribute)
  351. {
  352. Level = int.Parse(attribute[3].Value);
  353. UseTimer = float.Parse(attribute[5].Value);
  354. CoolTimer = float.Parse(attribute[4].Value);
  355. ItemStatus_ = (SkillStatus)Enum.Parse(typeof(SkillStatus), attribute[2].Value);
  356. NewPlus = Plus;
  357. NewPerson = Person;
  358. NewSkillCD = SkillCD;
  359. NewDuration = Duration;
  360. NewCoinOnce = CoinOnce;
  361. NewSkillCdBuff = SkillCdBuff;
  362. NewPersonBuff = PersonBuff;
  363. NewCoinPerson = CoinPerson;
  364. NewUpgradeAmt = UpgradeAmt;
  365. NewCoinOnceBuff = CoinOnceBuff;
  366. if (ItemStatus_ == SkillStatus.Use)
  367. {
  368. UseA();
  369. if (UseTimer < elapse)
  370. {
  371. if (useList.Count > 0)
  372. {
  373. if (UseTimer < ManaCenter.CircleTimer)
  374. {
  375. useList[0].UniqueAdd(this);
  376. }
  377. else
  378. {
  379. int circle = 1 + Mathf.FloorToInt((UseTimer - ManaCenter.CircleTimer)/ManaCenter.CircleTime);
  380. useList[circle].UniqueAdd(this);
  381. }
  382. }
  383. }
  384. else
  385. {
  386. UseTimer -= elapse;
  387. }
  388. }
  389. else if (ItemStatus_ == SkillStatus.Cool)
  390. {
  391. CoolTimer -= elapse;
  392. ManaCenter.CoolList.Add(this);
  393. }
  394. ItemBtn.onClick.RemoveAllListeners();
  395. ItemBtn.onClick.AddListener(OnClick);
  396. ItemLab.text = GetDescription(0);
  397. ItemStatus = ItemStatus;
  398. }
  399. public override void ReceiveCool(float amt, bool current, bool buff)
  400. {
  401. if (!CoolLock)
  402. {
  403. return;
  404. }
  405. if (current)
  406. {
  407. if (ItemStatus != SkillStatus.Cool)
  408. {
  409. return;
  410. }
  411. if (buff)
  412. {
  413. CoolTimer -= CD * amt;
  414. }
  415. else
  416. {
  417. CoolTimer -= amt;
  418. }
  419. }
  420. else
  421. {
  422. if (buff)
  423. {
  424. CdBuff = 1 - amt;
  425. }
  426. else
  427. {
  428. CD -= amt;
  429. }
  430. }
  431. }
  432. #region 解读器
  433. protected double UpgradeAmtParse(string str)
  434. {
  435. if (string.IsNullOrEmpty(str))
  436. {
  437. return UnlockAmt;
  438. }
  439. else
  440. {
  441. return double.Parse(str);
  442. }
  443. }
  444. protected override string GetDescription(int offset)
  445. {
  446. float temp;
  447. string[] strings = Desc.Split('[', ']');
  448. StringBuilder stringBuilder = new StringBuilder();
  449. for (int i = 0; i < strings.Length; i++)
  450. {
  451. if (strings[i].Contains("lv"))
  452. {
  453. }
  454. else if (strings[i].Contains("&person&"))
  455. {
  456. #region MyRegion
  457. if (!Person.Equal(0))
  458. {
  459. temp = NewPerson;
  460. UpgradeValue(ref temp, Person, UpgradePerson, offset);
  461. UpgradeUnit(ref temp, strings[i]);
  462. float remainder = temp % 1;
  463. if (remainder > 0)
  464. {
  465. stringBuilder.Append(temp.ToString("0") + "+");
  466. }
  467. else
  468. {
  469. stringBuilder.Append(temp.ToString("0"));
  470. }
  471. }
  472. else if (!PersonBuff.Equal(0))
  473. {
  474. temp = NewPersonBuff;
  475. UpgradeValue(ref temp, PersonBuff, UpgradePerson, offset);
  476. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  477. }
  478. #endregion
  479. }
  480. else if (strings[i].Contains("&duration&"))
  481. {
  482. #region MyRegion
  483. temp = NewDuration;
  484. UpgradeValue(ref temp, Duration, UpgradeDuration, offset);
  485. UpgradeUnit(ref temp, strings[i]);
  486. stringBuilder.Append(temp.ToString("0"));
  487. #endregion
  488. }
  489. else if (strings[i].Contains("&coin_once&"))
  490. {
  491. #region MyRegion
  492. if (!CoinOnce.Equal(0))
  493. {
  494. temp = NewCoinOnce;
  495. UpgradeValue(ref temp, CoinOnce, UpgradeCoinOnce, offset);
  496. stringBuilder.Append(temp.ToString("0"));
  497. }
  498. else if (!CoinOnceBuff.Equal(0))
  499. {
  500. temp = NewCoinOnceBuff;
  501. UpgradeValue(ref temp, UpgradeCoinOnce, offset);
  502. stringBuilder.Append(temp.ToString("0"));
  503. }
  504. #endregion
  505. }
  506. else if (strings[i].Contains("&diamond_once&"))
  507. {
  508. #region MyRegion
  509. stringBuilder.Append(DiamondOnce.ToString("0"));
  510. #endregion
  511. }
  512. else if (strings[i].Contains("&coin_person&"))
  513. {
  514. #region MyRegion
  515. if (!CoinPerson.Equal(0))
  516. {
  517. temp = NewCoinPerson;
  518. UpgradeValue(ref temp, CoinPerson, UpgradePlus, offset);
  519. float remainder = temp % 1;
  520. if (remainder > 0)
  521. {
  522. stringBuilder.Append(temp.ToString("0") + "+");
  523. }
  524. else
  525. {
  526. stringBuilder.Append(temp.ToString("0"));
  527. }
  528. }
  529. else if (!Plus.Equal(0))
  530. {
  531. temp = NewPlus;
  532. UpgradeValue(ref temp, Plus, UpgradePlus, offset);
  533. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  534. }
  535. else
  536. {
  537. throw new Exception();
  538. }
  539. #endregion
  540. }
  541. else
  542. {
  543. stringBuilder.Append(strings[i]);
  544. }
  545. }
  546. return stringBuilder.ToString();
  547. }
  548. #endregion
  549. }