Ability.cs 17 KB

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