Ability.cs 14 KB

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