Ability.cs 19 KB

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