Ability.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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 bool ValidSlot;
  31. protected string Label;
  32. protected string Anim;
  33. protected string UpgradeCD;
  34. protected string UpgradeFml;
  35. protected string UpgradePlus;
  36. protected string UpgradePerson;
  37. #endregion
  38. protected float NewPlus;
  39. protected float NewPerson;
  40. protected float NewSkillCD;
  41. protected float NewSkillCdBuff;
  42. protected float NewPersonBuff;
  43. protected float NewCoinPerson;
  44. protected double NewUpgradeAmt;
  45. public SkillStatus ItemStatus
  46. {
  47. get { return ItemStatus_; }
  48. set
  49. {
  50. ItemStatus_ = value;
  51. if (ItemStatus_ == SkillStatus.Lock)
  52. {
  53. if (UnlockAheadCur == Current.Free)
  54. {
  55. ItemBtn.interactable = false;
  56. ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab4"), UnlockLv.ToString());
  57. }
  58. else
  59. {
  60. ItemBtn.interactable = true;
  61. ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab0"), "\n", new LanStr("UI", "Fe_BtnLab4"), UnlockLv.ToString());
  62. }
  63. }
  64. else if (ItemStatus_ == SkillStatus.UnLock)
  65. {
  66. ItemBtn.interactable = true;
  67. if (UnlockCur == Current.Free)
  68. {
  69. ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab1"));
  70. }
  71. else
  72. {
  73. ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab1"), "\n", ImageParse(UnlockCur), UnlockAmt.ToString("0"));
  74. }
  75. }
  76. else if (ItemStatus_ == SkillStatus.Upgrade)
  77. {
  78. ItemBtn.interactable = true;
  79. ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab2"), "\n", ImageParse(UpgradeCur), UpgradeAmt.ToString("0"));
  80. }
  81. }
  82. }
  83. public SkillStatus ItemStatus_;
  84. #endregion
  85. public Ability(XmlAttributeCollection attribute)
  86. {
  87. #region 配置
  88. ID_ = int.Parse(attribute[0].Value);
  89. Icon_ = attribute[20].Value;
  90. Anim = attribute[21].Value;
  91. Label = attribute[22].Value;
  92. UnlockPos = attribute[12].Value;
  93. UpgradeCD = attribute[18].Value;
  94. UpgradeFml = attribute[15].Value;
  95. UpgradePlus = attribute[16].Value;
  96. UpgradePerson = attribute[17].Value;
  97. ItemIndex = IntParse(attribute[3].Value);
  98. UnlockLv = IntParse(attribute[7].Value);
  99. UnlockAmt = FloatParse(attribute[11].Value);
  100. UnlockAheadAmt = FloatParse(attribute[9].Value);
  101. SkillTab = SkillClassParse(attribute[2].Value);
  102. UpgradeAmt = UpgradeAmtParse(attribute[14].Value);
  103. UnlockCur = CurrentParse(attribute[10].Value);
  104. UpgradeCur = CurrentParse(attribute[13].Value);
  105. UnlockAheadCur = CurrentParse(attribute[8].Value);
  106. ValueBuffParse(out Person, out PersonBuff, attribute[5].Value);
  107. ValueBuffParse(out SkillCD, out SkillCdBuff, attribute[6].Value);
  108. ValueBuffParse(out CoinPerson, out Plus, attribute[4].Value);
  109. #endregion
  110. ValueBuffParse(out NewPerson, out NewPersonBuff, UpgradePerson);
  111. ValueBuffParse(out NewSkillCD, out NewSkillCdBuff, UpgradeCD);
  112. ValueBuffParse(out NewCoinPerson, out NewPlus, UpgradePlus);
  113. SkillType = SkillType.Ability;
  114. }
  115. public override void Annul()
  116. {
  117. if (ID == "Ability1")
  118. {
  119. ManaData.Person -= NewPerson;
  120. ManaData.CoinPerson -= NewCoinPerson;
  121. }
  122. else
  123. {
  124. ManaData.SkillPerson -= NewPerson;
  125. ManaData.SkillCoinPerson -= NewCoinPerson;
  126. }
  127. ManaData.SkillPlus -= NewPlus;
  128. ManaData.SkillPersonBuff -= NewPersonBuff;
  129. if (Math.Abs(NewSkillCD) > 0.0005f)
  130. {
  131. for (int i = 0; i < ManaData.SkillList.Count; i++)
  132. {
  133. ManaData.SkillList[i].ReceiveCool(-NewSkillCD, false, false);
  134. }
  135. }
  136. if (Math.Abs(NewSkillCdBuff) > 0.0005f)
  137. {
  138. for (int i = 0; i < ManaData.SkillList.Count; i++)
  139. {
  140. ManaData.SkillList[i].ReceiveCool(-NewSkillCdBuff, false, true);
  141. }
  142. }
  143. }
  144. public override void RegistValue(float elapse, List<List<Skill>> useList, XmlAttributeCollection attribute)
  145. {
  146. Level = int.Parse(attribute[3].Value);
  147. ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), attribute[2].Value);
  148. NewPlus = Plus;
  149. NewPerson = Person;
  150. NewSkillCD = SkillCD;
  151. NewSkillCdBuff = SkillCdBuff;
  152. NewPersonBuff = PersonBuff;
  153. NewCoinPerson = CoinPerson;
  154. NewUpgradeAmt = UpgradeAmt;
  155. ItemLab.text = Description(0);
  156. ItemBtn.onClick.AddListener(OnClick);
  157. if (ItemStatus == SkillStatus.Upgrade)
  158. {
  159. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁 等级 : {1}", Name, Level));
  160. for (int i = 0; i < Level; i++)
  161. {
  162. NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString());
  163. }
  164. UpgradeValue(ref NewPlus, Plus, UpgradePlus, Level);
  165. UpgradeValue(ref NewSkillCdBuff, UpgradeCD, Level);
  166. UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, Level);
  167. UpgradeValue(ref NewPerson, Person, UpgradePerson, Level);
  168. UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, Level);
  169. UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, Level);
  170. UseA();
  171. if (!string.IsNullOrEmpty(Anim))
  172. {
  173. string[] strings = Anim.Split(',');
  174. if (strings.Length == 1)
  175. {
  176. ManaData.Elf += Level;
  177. }
  178. }
  179. }
  180. }
  181. public override void UpdateStatus()
  182. {
  183. if (ManaData.Level >= UnlockLv)
  184. {
  185. if (ItemStatus == SkillStatus.Lock)
  186. {
  187. ItemStatus = SkillStatus.UnLock;
  188. }
  189. }
  190. }
  191. protected void Unlock()
  192. {
  193. if (!ManaData.Pay(UnlockAmt, UnlockCur))
  194. {
  195. return;
  196. }
  197. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
  198. if (UpgradeCur != Current.Free)
  199. {
  200. ItemStatus = SkillStatus.Upgrade;
  201. }
  202. else
  203. {
  204. throw new Exception();
  205. }
  206. UseA();
  207. UseB();
  208. UseC();
  209. }
  210. protected void OnClick()
  211. {
  212. if (ManaServer.Connect == false)
  213. {
  214. ManaReso.Get("Fg_Reconnect").TweenForCG();
  215. return;
  216. }
  217. ManaReso.Get("Fe_Info").TweenForCG();
  218. ManaReso.SetText("Fe_Tit", Name);
  219. ManaReso.SetSprite("Fe_Icon", ItemIcon.sprite);
  220. if (ItemStatus == SkillStatus.Lock)
  221. {
  222. ManaReso.SetText("Fe_Lab0", "");
  223. ManaReso.SetText("Fe_Lab1", Description(0));
  224. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab0"), ImageParse(UnlockAheadCur), UnlockAheadAmt));
  225. ManaReso.SetButtonEvent
  226. (
  227. "Fe_Btn",
  228. () =>
  229. {
  230. UnlockAhead();
  231. ManaReso.Get("Fe_Info").TweenBacCG();
  232. }
  233. );
  234. }
  235. else if (ItemStatus == SkillStatus.UnLock)
  236. {
  237. ManaReso.SetText("Fe_Lab0", "");
  238. ManaReso.SetText("Fe_Lab1", Description(0));
  239. if (UnlockCur == Current.Free)
  240. {
  241. ManaReso.SetText("Fe_BtnLab", string.Format("{0}", Language.GetStr("UI", "Fe_BtnLab1")));
  242. }
  243. else
  244. {
  245. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab1"), ImageParse(UnlockCur), UnlockAmt));
  246. }
  247. ManaReso.SetButtonEvent
  248. (
  249. "Fe_Btn",
  250. () =>
  251. {
  252. Unlock();
  253. ManaReso.Get("Fe_Info").TweenBacCG();
  254. }
  255. );
  256. }
  257. else if (ItemStatus == SkillStatus.Upgrade)
  258. {
  259. ManaReso.SetText("Fe_Lab0", Description(0));
  260. ManaReso.SetText("Fe_Lab1", Description(1));
  261. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab2"), ImageParse(UpgradeCur), NewUpgradeAmt));
  262. ManaReso.SetButtonEvent
  263. (
  264. "Fe_Btn",
  265. () =>
  266. {
  267. Upgrade();
  268. ItemLab.text = Description(0);
  269. ManaReso.SetText("Fe_Tit", NameParse());
  270. ManaReso.SetText("Fe_Lab0", Description(0));
  271. ManaReso.SetText("Fe_Lab1", Description(1));
  272. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab2"), ImageParse(UpgradeCur), NewUpgradeAmt));
  273. ManaDebug.Log(string.Format("<color=red>{0}</color>升级 : {1}", Name, Level));
  274. }
  275. );
  276. }
  277. else
  278. {
  279. throw new Exception();
  280. }
  281. }
  282. protected void Upgrade()
  283. {
  284. if (!ManaData.Pay(NewUpgradeAmt, UpgradeCur))
  285. {
  286. return;
  287. }
  288. if (ID == "Ability1")
  289. {
  290. Level += 20;
  291. ManaData.Level += 20;
  292. }
  293. else
  294. {
  295. Level++;
  296. }
  297. Annul();
  298. NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString());
  299. UpgradeValue(ref NewPerson, Person, UpgradePerson, 1);
  300. UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, 1);
  301. UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, 1);
  302. UpgradeValue(ref NewPlus, Plus, UpgradePlus, 1);
  303. UpgradeValue(ref NewSkillCdBuff, UpgradeCD, 1);
  304. UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, 1);
  305. UseA();
  306. UseC();
  307. }
  308. protected void UseA()
  309. {
  310. if (!string.IsNullOrEmpty(Anim))
  311. {
  312. string[] strings = Anim.Split(',');
  313. if (strings.Length == 1)
  314. {
  315. ManaGarden.AnimList.Add((ObjType) Enum.Parse(typeof(ObjType), strings[0]));
  316. }
  317. else if (strings.Length > 1)
  318. {
  319. ManaReso.Get(strings[0], Folder.Scene, true, ManaReso.Get(strings[1]), false);
  320. }
  321. }
  322. if (ValidSlot == false)
  323. {
  324. ValidSlot = true;
  325. if (!string.IsNullOrEmpty(UnlockPos))
  326. {
  327. for (int i = 0; i < int.Parse(UnlockPos); i++)
  328. {
  329. ManaGarden.UnlockSlot();
  330. }
  331. }
  332. }
  333. ManaData.Person += NewPerson;
  334. ManaData.CoinPerson += NewCoinPerson;
  335. ManaData.SkillPlus += NewPlus;
  336. ManaData.SkillPersonBuff += NewPersonBuff;
  337. if (Math.Abs(NewSkillCD) > 0.0005f)
  338. {
  339. for (int i = 0; i < ManaData.SkillList.Count; i++)
  340. {
  341. ManaData.SkillList[i].ReceiveCool(NewSkillCD, false, false);
  342. }
  343. }
  344. if (Math.Abs(NewSkillCdBuff) > 0.0005f)
  345. {
  346. for (int i = 0; i < ManaData.SkillList.Count; i++)
  347. {
  348. ManaData.SkillList[i].ReceiveCool(NewSkillCdBuff, false, true);
  349. }
  350. }
  351. #region 调试输出
  352. StringBuilder strb = new StringBuilder();
  353. strb.AppendFormat("使用技能 : <color=red>{0}</color>", Name);
  354. if (Math.Abs(NewPlus) > 0.0005f)
  355. {
  356. strb.AppendFormat(" 收入加成<color=red>+{0}%</color>", NewPlus*100);
  357. }
  358. if (Math.Abs(NewPerson) > 0.0005f)
  359. {
  360. strb.AppendFormat(" 参观人次<color=red>+{0}</color>", NewPerson);
  361. }
  362. if (Math.Abs(NewPersonBuff) > 0.0005f)
  363. {
  364. strb.AppendFormat(" 参观人次<color=red>+{0}%</color>", NewPersonBuff*100);
  365. }
  366. if (Math.Abs(NewCoinPerson) > 0.0005f)
  367. {
  368. strb.AppendFormat(" 每次金币<color=red>+{0}</color>", NewCoinPerson);
  369. }
  370. if (Math.Abs(SkillCD) > 0.0005f)
  371. {
  372. strb.AppendFormat(" 减少冷却上限<color=red>{0}</color>", SkillCD);
  373. }
  374. if (Math.Abs(SkillCdBuff) > 0.0005f)
  375. {
  376. strb.AppendFormat(" 减少冷却上限<color=red>{0}%</color>", SkillCdBuff*100);
  377. }
  378. if (!string.IsNullOrEmpty(UnlockPos))
  379. {
  380. int amt = int.Parse(UnlockPos);
  381. strb.AppendFormat(" 解锁了<color=red>{0}</color>块土地", amt);
  382. }
  383. strb.Append(" <color=red>永久有效</color>");
  384. ManaDebug.Log(strb.ToString());
  385. #endregion
  386. }
  387. protected void UseB()
  388. {
  389. if (!string.IsNullOrEmpty(Anim))
  390. {
  391. string[] strings = Anim.Split(',');
  392. if (strings.Length == 1)
  393. {
  394. if (ManaGarden.PlantList.Count == 0)
  395. {
  396. return;
  397. }
  398. Flower flower = ManaGarden.PlantList.Random().Flower;
  399. flower.PlayAnim(ManaGarden.AnimList.Last(0));
  400. ManaReso.Get<Button>("F_Close").onClick.Invoke();
  401. Tween tween = ManaReso.Get("F_Manage0").GetTweenVec();
  402. ManaReso.Get("MainCamera").CreateZoom2D();
  403. tween.AddEventOnetime
  404. (
  405. EventType.BackwardFinish,
  406. () =>
  407. {
  408. ManaReso.Get("MainCamera").Zoom2D(1.5f, 1f, 1, flower.transform.GetChild(4), Curve.EaseOutQuad);
  409. }
  410. );
  411. }
  412. else if (strings.Length > 1)
  413. {
  414. ManaReso.Get<Button>("F_Close").onClick.Invoke();
  415. Tween tween0 = ManaReso.Get(strings[0]).CreateTweenSr(0, 1, 1, true, true, Curve.EaseOutQuad, false, true);
  416. tween0.InOrigin = true;
  417. Tween tween1 = ManaReso.Get("F_Manage0").GetTweenVec();
  418. ManaReso.Get("MainCamera").CreateZoom2D();
  419. tween1.AddEventOnetime
  420. (
  421. EventType.BackwardFinish,
  422. () =>
  423. {
  424. tween0.StartForward();
  425. ManaReso.Get("MainCamera").Zoom2D(3.5f, 1f, 1, ManaReso.Get(strings[0]), Curve.EaseOutQuad);
  426. }
  427. );
  428. }
  429. }
  430. }
  431. protected void UseC()
  432. {
  433. if (!string.IsNullOrEmpty(Anim))
  434. {
  435. string[] strings = Anim.Split(',');
  436. if (strings.Length == 1)
  437. {
  438. ManaData.Elf++;
  439. }
  440. }
  441. }
  442. protected void UnlockAhead()
  443. {
  444. if (ItemStatus != SkillStatus.Lock)
  445. {
  446. ManaDebug.Log("您并不需要提前解锁");
  447. return;
  448. }
  449. if (ManaData.Pay(UnlockAheadAmt, UnlockAheadCur))
  450. {
  451. ManaData.Elf++;
  452. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
  453. ItemStatus = SkillStatus.Upgrade;
  454. }
  455. }
  456. #region 解读器
  457. protected override string Description(int offset)
  458. {
  459. float temp;
  460. string[] strings = Desc.Split('[', ']');
  461. StringBuilder stringBuilder = new StringBuilder();
  462. for (int i = 0; i < strings.Length; i++)
  463. {
  464. if (strings[i].Contains("lv"))
  465. {
  466. }
  467. else if (strings[i].Contains("&person&"))
  468. {
  469. #region MyRegion
  470. if (Math.Abs(Person) > 0.0005f)
  471. {
  472. temp = NewPerson;
  473. UpgradeValue(ref temp, Person, UpgradePerson, offset);
  474. UpgradeUnit(ref temp, strings[i]);
  475. stringBuilder.Append(temp.ToString("0"));
  476. }
  477. else if (Math.Abs(PersonBuff) > 0.0005f)
  478. {
  479. temp = NewPersonBuff;
  480. UpgradeValue(ref temp, PersonBuff, UpgradePerson, offset);
  481. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  482. }
  483. #endregion
  484. }
  485. else if (strings[i].Contains("&skill_cd&"))
  486. {
  487. #region MyRegion
  488. if (Math.Abs(SkillCD) > 0.0005f)
  489. {
  490. temp = NewSkillCD;
  491. UpgradeValue(ref temp, SkillCD, UpgradeCD, offset);
  492. UpgradeUnit(ref temp, strings[i]);
  493. stringBuilder.Append(temp.ToString("0"));
  494. }
  495. else if (Math.Abs(SkillCdBuff) > 0.0005f)
  496. {
  497. temp = NewSkillCdBuff;
  498. UpgradeValue(ref temp, UpgradeCD, offset);
  499. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  500. }
  501. #endregion
  502. }
  503. else if (strings[i].Contains("&coin_person&"))
  504. {
  505. #region MyRegion
  506. if (Math.Abs(CoinPerson) > 0.0005f)
  507. {
  508. temp = NewCoinPerson;
  509. UpgradeValue(ref temp, CoinPerson, UpgradePlus, offset);
  510. UpgradeUnit(ref temp, strings[i]);
  511. stringBuilder.Append(temp.ToString("0.0"));
  512. }
  513. else if (Math.Abs(Plus) > 0.0005f)
  514. {
  515. temp = NewPlus;
  516. UpgradeValue(ref temp, Plus, UpgradePlus, offset);
  517. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  518. }
  519. #endregion
  520. }
  521. else
  522. {
  523. stringBuilder.Append(strings[i]);
  524. }
  525. }
  526. return stringBuilder.ToString();
  527. }
  528. protected double UpgradeAmtParse(string str)
  529. {
  530. if (string.IsNullOrEmpty(str))
  531. {
  532. return UnlockAmt;
  533. }
  534. else
  535. {
  536. return double.Parse(str);
  537. }
  538. }
  539. #endregion
  540. }