Ability.cs 19 KB

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