Ability.cs 19 KB

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