Ability.cs 19 KB

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