Ability.cs 15 KB

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