Ability.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  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 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. public SkillStatus ItemStatus_;
  80. #endregion
  81. public Ability(XmlAttributeCollection attribute)
  82. {
  83. #region 配置
  84. ID_ = int.Parse(attribute[0].Value);
  85. Icon_ = attribute[20].Value;
  86. Anim = attribute[21].Value;
  87. Label = attribute[22].Value;
  88. UnlockPos = attribute[12].Value;
  89. UpgradeCD = attribute[18].Value;
  90. UpgradeFml = attribute[15].Value;
  91. UpgradePlus = attribute[16].Value;
  92. UpgradePerson = attribute[17].Value;
  93. UnlockLv = Auxiliary.IntParse(attribute[7].Value,0);
  94. ItemIndex = Auxiliary.IntParse(attribute[3].Value,0);
  95. UnlockAmt = Auxiliary.FloatParse(attribute[11].Value,0);
  96. UnlockAheadAmt = Auxiliary.FloatParse(attribute[9].Value,0);
  97. SkillTab = SkillClassParse(attribute[2].Value);
  98. UpgradeAmt = UpgradeAmtParse(attribute[14].Value);
  99. UnlockCur = CurrentParse(attribute[10].Value);
  100. UpgradeCur = CurrentParse(attribute[13].Value);
  101. UnlockAheadCur = CurrentParse(attribute[8].Value);
  102. ValueBuffParse(out Person, out PersonBuff, attribute[5].Value);
  103. ValueBuffParse(out SkillCD, out SkillCdBuff, attribute[6].Value);
  104. ValueBuffParse(out CoinPerson, out Plus, attribute[4].Value);
  105. #endregion
  106. SkillType = SkillType.Ability;
  107. }
  108. public void UnlockTab()
  109. {
  110. ManaReso.Get<Graphic>("F_Elf").material = null;
  111. ManaReso.Get<Graphic>("F_Store").material = null;
  112. ManaReso.Get<Graphic>("F_Magic").material = null;
  113. ManaReso.Get<Graphic>("F_ElfLab").material = null;
  114. ManaReso.Get<Graphic>("F_StoreLab").material = null;
  115. ManaReso.Get<Graphic>("F_MagicLab").material = null;
  116. ManaReso.Get<Button>("F_Elf").interactable = true;
  117. ManaReso.Get<Button>("F_Store").interactable = true;
  118. ManaReso.Get<Button>("F_Magic").interactable = true;
  119. }
  120. public override void Reactive()
  121. {
  122. if (Level > 0)
  123. {
  124. AnnulA();
  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, Plus, UpgradePlus, Level - 1);
  153. UpgradeValue(ref NewPersonBuff, PersonBuff, 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.SkillDepth++;
  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. ID,
  288. UnlockAmt,
  289. UnlockCur,
  290. () =>
  291. {
  292. ManaAudio.PlayClip(Clip.SkillClip);
  293. if (UnlockCur != Current.Free)
  294. {
  295. ManaUI.SkillDepth--;
  296. }
  297. ItemStatus = SkillStatus.Upgrade;
  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, Plus, UpgradePlus, 1);
  382. UpgradeValue(ref NewPersonBuff, PersonBuff, 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. ManaUI.SkillDepth++;
  459. ItemStatus = SkillStatus.UnLock;
  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, PersonBuff, 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, Plus, 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. }