Ability.cs 20 KB

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