Ability.cs 17 KB

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