Ability.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System;
  4. using System.Xml;
  5. using System.Text;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using Random = UnityEngine.Random;
  9. public class Ability : SkillRoot
  10. {
  11. #region 变量
  12. #region 配置
  13. public override string ID
  14. {
  15. get { return "Ability" + ID_; }
  16. }
  17. protected float Person;
  18. protected float SkillCD;
  19. protected float CoinPerson;
  20. protected double UpgradeAmt;
  21. protected float Plus;
  22. protected float PersonBuff;
  23. protected float SkillCdBuff;
  24. protected int UnlockLv;
  25. protected float UnlockAmt;
  26. protected float UnlockAheadAmt;
  27. protected string UnlockPos;
  28. protected Current UnlockCur;
  29. protected Current UpgradeCur;
  30. protected Current UnlockAheadCur;
  31. protected string Label;
  32. protected string Anim;
  33. protected string UpgradeCD;
  34. protected string UpgradeFml;
  35. protected string UpgradePlus;
  36. protected string UpgradePerson;
  37. #endregion
  38. protected bool ValidAnim = true;
  39. protected string Elf;
  40. protected string Item;
  41. protected float NewPlus;
  42. protected float NewPerson;
  43. protected float NewSkillCD;
  44. protected float NewSkillCdBuff;
  45. protected float NewPersonBuff;
  46. protected float NewCoinPerson;
  47. protected double NewUpgradeAmt;
  48. public SkillStatus ItemStatus
  49. {
  50. get { return ItemStatus_; }
  51. set
  52. {
  53. ItemStatus_ = value;
  54. if (ItemStatus_ == SkillStatus.Lock)
  55. {
  56. if (UnlockAheadCur == Current.Free)
  57. {
  58. ItemBtn.interactable = false;
  59. ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab1"), "\n", new LanStr("UI", "Fe_BtnLab4"), UnlockLv.ToString());
  60. }
  61. else
  62. {
  63. ItemBtn.interactable = true;
  64. ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab0"), "\n", new LanStr("UI", "Fe_BtnLab4"), UnlockLv.ToString());
  65. }
  66. }
  67. else if (ItemStatus_ == SkillStatus.UnLock)
  68. {
  69. ItemBtn.interactable = true;
  70. if (UnlockCur == Current.Free)
  71. {
  72. ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab1"));
  73. }
  74. else
  75. {
  76. ItemBtnLab.text = Language.GetStr("UI", "Fe_BtnLab1") + "\n" + ImageParse(UnlockCur) + Auxiliary.ShrinkNumberStr(UnlockAmt);
  77. }
  78. }
  79. else if (ItemStatus_ == SkillStatus.Upgrade)
  80. {
  81. ItemBtn.interactable = true;
  82. ItemBtnLab.text = Language.GetStr("UI", "Fe_BtnLab2") + "\n" + ImageParse(UpgradeCur) + Auxiliary.ShrinkNumberStr(NewUpgradeAmt);
  83. }
  84. }
  85. }
  86. public SkillStatus ItemStatus_;
  87. #endregion
  88. public Ability(XmlAttributeCollection attribute)
  89. {
  90. #region 配置
  91. ID_ = int.Parse(attribute[0].Value);
  92. Icon_ = attribute[20].Value;
  93. Anim = attribute[21].Value;
  94. Label = attribute[22].Value;
  95. UnlockPos = attribute[12].Value;
  96. UpgradeCD = attribute[18].Value;
  97. UpgradeFml = attribute[15].Value;
  98. UpgradePlus = attribute[16].Value;
  99. UpgradePerson = attribute[17].Value;
  100. UnlockLv = Auxiliary.IntParse(attribute[7].Value,0);
  101. ItemIndex = Auxiliary.IntParse(attribute[3].Value,0);
  102. UnlockAmt = Auxiliary.FloatParse(attribute[11].Value,0);
  103. UnlockAheadAmt = Auxiliary.FloatParse(attribute[9].Value,0);
  104. SkillTab = SkillClassParse(attribute[2].Value);
  105. UpgradeAmt = UpgradeAmtParse(attribute[14].Value);
  106. UnlockCur = CurrentParse(attribute[10].Value);
  107. UpgradeCur = CurrentParse(attribute[13].Value);
  108. UnlockAheadCur = CurrentParse(attribute[8].Value);
  109. ValueBuffParse(out Person, out PersonBuff, attribute[5].Value);
  110. ValueBuffParse(out SkillCD, out SkillCdBuff, attribute[6].Value);
  111. ValueBuffParse(out CoinPerson, out Plus, attribute[4].Value);
  112. #endregion
  113. SkillType = SkillType.Ability;
  114. }
  115. public override void Reactive()
  116. {
  117. if (Level > 0)
  118. {
  119. Annul();
  120. }
  121. }
  122. public override void RegistValue(float elapse, List<List<Skill>> useList, XmlAttributeCollection attribute)
  123. {
  124. Level = int.Parse(attribute[3].Value);
  125. ItemStatus_ = (SkillStatus)Enum.Parse(typeof(SkillStatus), attribute[2].Value);
  126. NewPlus = Plus;
  127. NewPerson = Person;
  128. NewSkillCD = SkillCD;
  129. NewSkillCdBuff = SkillCdBuff;
  130. NewPersonBuff = PersonBuff;
  131. NewCoinPerson = CoinPerson;
  132. NewUpgradeAmt = UpgradeAmt;
  133. if (ID == "Ability1")
  134. {
  135. ManaCenter.Level = Level;
  136. if (Level > 0)
  137. {
  138. UnlockTab();
  139. }
  140. }
  141. if (ItemStatus_ == SkillStatus.Upgrade)
  142. {
  143. if (Level > 0)
  144. {
  145. for (int i = 0; i < Level - 1; i++)
  146. {
  147. NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString());
  148. }
  149. UpgradeValue(ref NewPlus, Plus, UpgradePlus, Level - 1);
  150. UpgradeSkillCdBuff(ref NewSkillCdBuff, UpgradeCD, Level - 1);
  151. UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, Level - 1);
  152. UpgradeValue(ref NewPerson, Person, UpgradePerson, Level - 1);
  153. UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, Level - 1);
  154. UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, Level - 1);
  155. }
  156. UseA();
  157. UseC();
  158. }
  159. ItemStatus = ItemStatus;
  160. ItemBtn.onClick.RemoveAllListeners();
  161. ItemBtn.onClick.AddListener(OnClick);
  162. ItemLab.text = Description(0);
  163. }
  164. public override void SwitchLanguage()
  165. {
  166. base.SwitchLanguage();
  167. ItemStatus = ItemStatus;
  168. }
  169. protected void UnlockTab()
  170. {
  171. ManaReso.Get<Graphic>("F_Elf").material = null;
  172. ManaReso.Get<Graphic>("F_Store").material = null;
  173. ManaReso.Get<Graphic>("F_Magic").material = null;
  174. ManaReso.Get<Graphic>("F_ElfLab").material = null;
  175. ManaReso.Get<Graphic>("F_StoreLab").material = null;
  176. ManaReso.Get<Graphic>("F_MagicLab").material = null;
  177. ManaReso.Get<Button>("F_Elf").interactable = true;
  178. ManaReso.Get<Button>("F_Store").interactable = true;
  179. ManaReso.Get<Button>("F_Magic").interactable = true;
  180. }
  181. protected void UseA()
  182. {
  183. if (ValidAnim)
  184. {
  185. ValidAnim = false;
  186. if (!string.IsNullOrEmpty(Anim))
  187. {
  188. if (Anim.Contains("Elf"))
  189. {
  190. string[] strings = Anim.Split(',');
  191. for (int i = 1; i < strings.Length; i++)
  192. {
  193. ManaGarden.ElfList.Add((ObjType)Enum.Parse(typeof(ObjType), strings[i]));
  194. }
  195. Elf = strings[1];
  196. }
  197. else if (Anim.Contains("Item"))
  198. {
  199. string[] strings = Anim.Split(',');
  200. for (int i = 1; i < strings.Length; i++)
  201. {
  202. ManaReso.Get(strings[i]).TweenForSr();
  203. }
  204. Item = strings[1];
  205. }
  206. }
  207. }
  208. ManaCenter.Person += NewPerson;
  209. ManaCenter.CoinPerson += NewCoinPerson;
  210. ManaCenter.SkillPlus += NewPlus;
  211. ManaCenter.SkillPersonBuff += NewPersonBuff;
  212. if (!NewSkillCD.Equal(0))
  213. {
  214. for (int i = 0; i < ManaCenter.SkillList.Count; i++)
  215. {
  216. ManaCenter.SkillList[i].ReceiveCool(NewSkillCD, false, false);
  217. }
  218. }
  219. if (!NewSkillCdBuff.Equal(0))
  220. {
  221. for (int i = 0; i < ManaCenter.SkillList.Count; i++)
  222. {
  223. ManaCenter.SkillList[i].ReceiveCool(NewSkillCdBuff, false, true);
  224. }
  225. }
  226. }
  227. protected void UseB()
  228. {
  229. if (!string.IsNullOrEmpty(Elf))
  230. {
  231. ManaCenter.ElfLevel++;
  232. }
  233. }
  234. protected void UseC()
  235. {
  236. for (int i = 0; i < Auxiliary.IntParse(UnlockPos, 0); i++)
  237. {
  238. ManaGarden.UnlockSlot();
  239. }
  240. }
  241. protected void Zoom()
  242. {
  243. if (!string.IsNullOrEmpty(Elf))
  244. {
  245. if (ManaGarden.PlantList.Count == 0)
  246. {
  247. return;
  248. }
  249. ManaGarden.ElfTimer = Random.Range(5f, 30f);
  250. Flower flower = ManaGarden.PlantList.Random().Flower;
  251. flower.GetElf(ManaGarden.ElfList.Last(0), 0, 0, 0, 0);
  252. ManaReso.Get("Fe_Info").TweenBacCG();
  253. ManaReso.Get("F_Manage").TweenBacGra();
  254. TweenRoot tween = ManaReso.Get("F_Manage0").GetTweenVec();
  255. tween.AddEventOnetime
  256. (
  257. EventType.BackwardFinish,
  258. () =>
  259. {
  260. ManaReso.Get("MainCamera").Zoom2D(1.5f, 3f, 1, flower.ElfList.Last(0), Curve.EaseOutQuad);
  261. }
  262. );
  263. }
  264. else if (!string.IsNullOrEmpty(Item))
  265. {
  266. TweenRoot tween = ManaReso.Get(Item).GetTweenSr();
  267. Vector3 pos = ManaReso.Get(Item).position;
  268. pos.z = -2;
  269. tween.AddEventOnetime
  270. (
  271. EventType.ForwardFinish,
  272. () =>
  273. {
  274. ManaReso.GetFirework(pos);
  275. }
  276. );
  277. ManaReso.Get("Fe_Info").TweenBacCG();
  278. ManaReso.Get("F_Manage").TweenBacGra();
  279. tween = ManaReso.Get("F_Manage0").GetTweenVec();
  280. tween.AddEventOnetime
  281. (
  282. EventType.BackwardFinish,
  283. () =>
  284. {
  285. ManaReso.Get("MainCamera").Zoom2D(3.5f, 3f, 1, ManaReso.Get(Item), Curve.EaseOutQuad);
  286. }
  287. );
  288. }
  289. }
  290. protected void Unlock()
  291. {
  292. ManaCenter.Pay(ID, UnlockAmt, UnlockCur, () =>
  293. {
  294. ItemStatus = SkillStatus.Upgrade;
  295. ManaAudio.PlayClip(Clip.SkillClip);
  296. Level = 1;
  297. UseA();
  298. UseB();
  299. UseC();
  300. if (ID == "Ability1")
  301. {
  302. ManaCenter.Level = 1;
  303. UnlockTab();
  304. }
  305. Zoom();
  306. });
  307. }
  308. protected void OnClick()
  309. {
  310. ManaAudio.PlayClip(Clip.BtnClip);
  311. ManaReso.Get("Fe_Info").TweenForCG();
  312. ManaReso.SetText("Fe_Tit", Name);
  313. ManaReso.SetSprite("Fe_Icon", Icon);
  314. if (ItemStatus == SkillStatus.Lock)
  315. {
  316. ManaReso.SetText("Fe_Lab0", "");
  317. ManaReso.SetText("Fe_Lab1", Description(0));
  318. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab0"), ImageParse(UnlockAheadCur), UnlockAheadAmt));
  319. ManaReso.SetButtonEvent
  320. (
  321. "Fe_Btn",
  322. () =>
  323. {
  324. UnlockAhead();
  325. ManaReso.Get("Fe_Info").TweenBacCG();
  326. }
  327. );
  328. }
  329. else if (ItemStatus == SkillStatus.UnLock)
  330. {
  331. ManaReso.SetText("Fe_Lab0", "");
  332. ManaReso.SetText("Fe_Lab1", Description(0));
  333. if (UnlockCur == Current.Free)
  334. {
  335. ManaReso.SetText("Fe_BtnLab", string.Format("{0}", Language.GetStr("UI", "Fe_BtnLab1")));
  336. }
  337. else
  338. {
  339. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab1"), ImageParse(UnlockCur), UnlockAmt));
  340. }
  341. ManaReso.SetButtonEvent
  342. (
  343. "Fe_Btn",
  344. () =>
  345. {
  346. Unlock();
  347. ManaReso.Get("Fe_Info").TweenBacCG();
  348. }
  349. );
  350. }
  351. else if (ItemStatus == SkillStatus.Upgrade)
  352. {
  353. ManaReso.SetText("Fe_Lab0", Description(0));
  354. ManaReso.SetText("Fe_Lab1", Description(1));
  355. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab2"), ImageParse(UpgradeCur), Auxiliary.ShrinkNumberStr(NewUpgradeAmt)));
  356. ManaReso.SetButtonEvent
  357. (
  358. "Fe_Btn",
  359. () =>
  360. {
  361. Upgrade();
  362. ItemLab.text = Description(0);
  363. ItemBtnLab.text = Language.GetStr("UI", "Fe_BtnLab2") + "\n" + ImageParse(UpgradeCur) + Auxiliary.ShrinkNumberStr(NewUpgradeAmt);
  364. ManaReso.SetText("Fe_Tit", Name);
  365. ManaReso.SetText("Fe_Lab0", Description(0));
  366. ManaReso.SetText("Fe_Lab1", Description(1));
  367. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab2"), ImageParse(UpgradeCur), Auxiliary.ShrinkNumberStr(NewUpgradeAmt)));
  368. }
  369. );
  370. }
  371. }
  372. protected void Upgrade()
  373. {
  374. ManaCenter.Pay(ID, NewUpgradeAmt, UpgradeCur, () =>
  375. {
  376. Level += 1;
  377. ManaAudio.PlayClip(Clip.SkillClip);
  378. Annul();
  379. NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString());
  380. UpgradeValue(ref NewPerson, Person, UpgradePerson, 1);
  381. UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, 1);
  382. UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, 1);
  383. UpgradeValue(ref NewPlus, Plus, UpgradePlus, 1);
  384. UpgradeSkillCdBuff(ref NewSkillCdBuff, UpgradeCD, 1);
  385. UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, 1);
  386. UseA();
  387. UseB();
  388. if (ID == "Ability1")
  389. {
  390. ManaCenter.Level += 1;
  391. }
  392. });
  393. }
  394. protected void UnlockAhead()
  395. {
  396. if (ItemStatus != SkillStatus.Lock)
  397. {
  398. Toast.Show(1.5f, "您并不需要提前解锁");
  399. return;
  400. }
  401. ManaCenter.Pay(ID, UnlockAheadAmt, UnlockAheadCur, () =>
  402. {
  403. if (UnlockCur == Current.Free)
  404. {
  405. Unlock();
  406. }
  407. else
  408. {
  409. ManaAudio.PlayClip(Clip.SkillClip);
  410. ItemStatus = SkillStatus.UnLock;
  411. }
  412. });
  413. }
  414. public override void Annul()
  415. {
  416. ManaCenter.Person -= NewPerson;
  417. ManaCenter.CoinPerson -= NewCoinPerson;
  418. ManaCenter.SkillPlus -= NewPlus;
  419. ManaCenter.SkillPersonBuff -= NewPersonBuff;
  420. for (int i = 0; i < Auxiliary.IntParse(UnlockPos, 0); i++)
  421. {
  422. ManaGarden.LockSlot();
  423. }
  424. if (Math.Abs(NewSkillCD) > 0.0005f)
  425. {
  426. for (int i = 0; i < ManaCenter.SkillList.Count; i++)
  427. {
  428. ManaCenter.SkillList[i].ReceiveCool(-NewSkillCD, false, false);
  429. }
  430. }
  431. if (Math.Abs(NewSkillCdBuff) > 0.0005f)
  432. {
  433. for (int i = 0; i < ManaCenter.SkillList.Count; i++)
  434. {
  435. ManaCenter.SkillList[i].ReceiveCool(-NewSkillCdBuff, false, true);
  436. }
  437. }
  438. }
  439. public override void UpdateStatus()
  440. {
  441. if (!ManaCenter.Complete)
  442. {
  443. return;
  444. }
  445. if (ManaCenter.Level >= UnlockLv)
  446. {
  447. if (ItemStatus == SkillStatus.Lock)
  448. {
  449. if (UnlockCur == Current.Free)
  450. {
  451. Unlock();
  452. }
  453. else
  454. {
  455. ItemStatus = SkillStatus.UnLock;
  456. }
  457. }
  458. }
  459. }
  460. #region 解读器
  461. protected double UpgradeAmtParse(string str)
  462. {
  463. if (string.IsNullOrEmpty(str))
  464. {
  465. return UnlockAmt;
  466. }
  467. else
  468. {
  469. return double.Parse(str);
  470. }
  471. }
  472. protected override string Description(int offset)
  473. {
  474. float temp;
  475. string[] strings = Desc.Split('[', ']');
  476. StringBuilder stringBuilder = new StringBuilder();
  477. for (int i = 0; i < strings.Length; i++)
  478. {
  479. if (strings[i].Contains("lv"))
  480. {
  481. }
  482. else if (strings[i].Contains("&person&"))
  483. {
  484. #region MyRegion
  485. if (Math.Abs(Person) > 0.0005f)
  486. {
  487. temp = NewPerson;
  488. UpgradeValue(ref temp, Person, UpgradePerson, offset);
  489. UpgradeUnit(ref temp, strings[i]);
  490. float remainder = temp % 1;
  491. if (remainder > 0)
  492. {
  493. stringBuilder.Append(temp.ToString("0") + "+");
  494. }
  495. else
  496. {
  497. stringBuilder.Append(temp.ToString("0"));
  498. }
  499. }
  500. else if (Math.Abs(PersonBuff) > 0.0005f)
  501. {
  502. temp = NewPersonBuff;
  503. UpgradeValue(ref temp, PersonBuff, UpgradePerson, offset);
  504. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  505. }
  506. #endregion
  507. }
  508. else if (strings[i].Contains("&skill_cd&"))
  509. {
  510. #region MyRegion
  511. if (Math.Abs(SkillCD) > 0.0005f)
  512. {
  513. temp = NewSkillCD;
  514. UpgradeValue(ref temp, SkillCD, UpgradeCD, offset);
  515. UpgradeUnit(ref temp, strings[i]);
  516. stringBuilder.Append(temp.ToString("0"));
  517. }
  518. else if (Math.Abs(SkillCdBuff) > 0.0005f)
  519. {
  520. temp = NewSkillCdBuff;
  521. UpgradeSkillCdBuff(ref temp, UpgradeCD, offset);
  522. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  523. }
  524. #endregion
  525. }
  526. else if (strings[i].Contains("&coin_person&"))
  527. {
  528. #region MyRegion
  529. if (Math.Abs(CoinPerson) > 0.0005f)
  530. {
  531. temp = NewCoinPerson;
  532. UpgradeValue(ref temp, CoinPerson, UpgradePlus, offset);
  533. UpgradeUnit(ref temp, strings[i]);
  534. float remainder = temp % 1;
  535. if (remainder > 0)
  536. {
  537. stringBuilder.Append(temp.ToString("0") + "+");
  538. }
  539. else
  540. {
  541. stringBuilder.Append(temp.ToString("0"));
  542. }
  543. }
  544. else if (Math.Abs(Plus) > 0.0005f)
  545. {
  546. temp = NewPlus;
  547. UpgradeValue(ref temp, Plus, UpgradePlus, offset);
  548. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  549. }
  550. #endregion
  551. }
  552. else
  553. {
  554. stringBuilder.Append(strings[i]);
  555. }
  556. }
  557. return stringBuilder.ToString();
  558. }
  559. #endregion
  560. }