Ability.cs 17 KB

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