Ability.cs 19 KB

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