Ability.cs 18 KB

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