Skill.cs 18 KB

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