Skill.cs 17 KB

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