Ability.cs 17 KB

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