Ability.cs 15 KB

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