Ability.cs 14 KB

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