Ability.cs 16 KB

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