Ability.cs 18 KB

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