Ability.cs 16 KB

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