Ability.cs 18 KB

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