Ability.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  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. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
  190. UseConti();
  191. if (UpgradeCur != Current.Free)
  192. {
  193. ItemStatus = SkillStatus.Upgrade;
  194. }
  195. else
  196. {
  197. throw new Exception();
  198. }
  199. }
  200. }
  201. protected void OnClick()
  202. {
  203. if (ManaData.Connect == false)
  204. {
  205. ManaReso.Get("Fg_Reconnect").TweenForCG();
  206. return;
  207. }
  208. ManaReso.Get("Fe_Info").TweenForCG();
  209. ManaReso.SetText("Fe_Tit", Name);
  210. if (ItemStatus == SkillStatus.Lock)
  211. {
  212. ManaReso.SetText("Fe_Lab0", "");
  213. ManaReso.SetText("Fe_Lab1", Description(0));
  214. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab0"), ImageParse(UnlockAheadCur), UnlockAheadAmt));
  215. ManaReso.SetButtonEvent
  216. (
  217. "Fe_Btn",
  218. () =>
  219. {
  220. UnlockAhead();
  221. ManaReso.Get("Fe_Info").TweenBacCG();
  222. }
  223. );
  224. }
  225. else if (ItemStatus == SkillStatus.UnLock)
  226. {
  227. ManaReso.SetText("Fe_Lab0", "");
  228. ManaReso.SetText("Fe_Lab1", Description(0));
  229. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab1"), ImageParse(UnlockCur), UnlockAmt));
  230. ManaReso.SetButtonEvent
  231. (
  232. "Fe_Btn",
  233. () =>
  234. {
  235. Unlock();
  236. ManaReso.Get("Fe_Info").TweenBacCG();
  237. }
  238. );
  239. }
  240. else if (ItemStatus == SkillStatus.Upgrade)
  241. {
  242. ManaReso.SetText("Fe_Lab0", Description(0));
  243. ManaReso.SetText("Fe_Lab1", Description(1));
  244. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab2"), ImageParse(UpgradeCur), NewUpgradeAmt));
  245. ManaReso.SetButtonEvent
  246. (
  247. "Fe_Btn",
  248. () =>
  249. {
  250. Upgrade();
  251. }
  252. );
  253. }
  254. else
  255. {
  256. throw new Exception();
  257. }
  258. }
  259. protected void Upgrade()
  260. {
  261. if (ManaData.Pay(NewUpgradeAmt, UpgradeCur))
  262. {
  263. Level++;
  264. Annul();
  265. NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString());
  266. UpgradeValue(ref NewPerson, Person, UpgradePerson, 1);
  267. UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, 1);
  268. UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, 1);
  269. UpgradeValue(ref NewPlus, Plus, UpgradePlus, 1);
  270. UpgradeValue(ref NewSkillCdBuff, UpgradeCD, 1);
  271. UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, 1);
  272. ManaText.Add(ItemTit, new LanStr("SkillName", _Name), " ", (Level + 1).ToString());
  273. ItemLab.text = Description(0);
  274. ManaReso.SetText("Fe_Lab0", Description(0));
  275. ManaReso.SetText("Fe_Lab1", Description(1));
  276. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab2"), ImageParse(UpgradeCur), NewUpgradeAmt));
  277. ManaDebug.Log(string.Format("<color=red>{0}</color> 升级 : {1}", Name, Level));
  278. UseConti();
  279. }
  280. }
  281. protected void UseConti()
  282. {
  283. if (ValidAnim == false)
  284. {
  285. ValidAnim = true;
  286. if (!string.IsNullOrEmpty(Anim))
  287. {
  288. string[] strings = Anim.Split(',');
  289. if (strings.Length == 1)
  290. {
  291. ManaGarden.AnimList.Add((ObjType) Enum.Parse(typeof(ObjType), strings[0]));
  292. }
  293. else if (strings.Length > 1)
  294. {
  295. ManaReso.Get(strings[0], Folder.Character, false, ManaReso.Get(strings[1]), true);
  296. }
  297. }
  298. }
  299. if (ValidSlot == false)
  300. {
  301. ValidSlot = true;
  302. if (!string.IsNullOrEmpty(UnlockPos))
  303. {
  304. for (int i = 0; i < int.Parse(UnlockPos); i++)
  305. {
  306. ManaGarden.UnlockSlot();
  307. }
  308. }
  309. }
  310. ManaData.Person += NewPerson;
  311. ManaData.CoinPerson += NewCoinPerson;
  312. ManaData.SkillPlus += NewPlus;
  313. ManaData.SkillPersonBuff += NewPersonBuff;
  314. if (Math.Abs(NewSkillCD) > 0.0005f)
  315. {
  316. for (int i = 0; i < ManaData.SkillList.Count; i++)
  317. {
  318. ManaData.SkillList[i].ReceiveCool(NewSkillCD, false, false);
  319. }
  320. }
  321. if (Math.Abs(NewSkillCdBuff) > 0.0005f)
  322. {
  323. for (int i = 0; i < ManaData.SkillList.Count; i++)
  324. {
  325. ManaData.SkillList[i].ReceiveCool(NewSkillCdBuff, false, true);
  326. }
  327. }
  328. #region 调试输出
  329. StringBuilder strb = new StringBuilder();
  330. strb.AppendFormat("使用技能 : <color=red>{0}</color>", Name);
  331. if (Math.Abs(NewPlus) > 0.0005f)
  332. {
  333. strb.AppendFormat(" 收入加成<color=red>+{0}%</color>", NewPlus * 100);
  334. }
  335. if (Math.Abs(NewPerson) > 0.0005f)
  336. {
  337. strb.AppendFormat(" 参观人次<color=red>+{0}</color>", NewPerson);
  338. }
  339. if (Math.Abs(NewPersonBuff) > 0.0005f)
  340. {
  341. strb.AppendFormat(" 参观人次<color=red>+{0}%</color>", NewPersonBuff * 100);
  342. }
  343. if (Math.Abs(NewCoinPerson) > 0.0005f)
  344. {
  345. strb.AppendFormat(" 每次金币<color=red>+{0}</color>", NewCoinPerson);
  346. }
  347. if (Math.Abs(SkillCD) > 0.0005f)
  348. {
  349. strb.AppendFormat(" 减少冷却上限<color=red>{0}</color>", SkillCD);
  350. }
  351. if (Math.Abs(SkillCdBuff) > 0.0005f)
  352. {
  353. strb.AppendFormat(" 减少冷却上限<color=red>{0}%</color>", SkillCdBuff * 100);
  354. }
  355. if (!string.IsNullOrEmpty(UnlockPos))
  356. {
  357. int amt = int.Parse(UnlockPos);
  358. strb.AppendFormat(" 解锁了<color=red>{0}</color>块土地", amt);
  359. }
  360. strb.Append(" <color=red>永久有效</color>");
  361. ManaDebug.Log(strb.ToString());
  362. #endregion
  363. }
  364. protected void UnlockAhead()
  365. {
  366. if (ItemStatus != SkillStatus.Lock)
  367. {
  368. ManaDebug.Log("您并不需要提前解锁");
  369. return;
  370. }
  371. if (ManaData.Pay(UnlockAheadAmt, UnlockAheadCur))
  372. {
  373. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
  374. UseConti();
  375. if (UpgradeCur != Current.Free)
  376. {
  377. ItemStatus = SkillStatus.Upgrade;
  378. }
  379. else
  380. {
  381. throw new Exception();
  382. }
  383. }
  384. }
  385. #region 解读器
  386. protected override string Description(int offset)
  387. {
  388. float temp;
  389. string[] strings = Desc.Split('[', ']');
  390. StringBuilder stringBuilder = new StringBuilder();
  391. for (int i = 0; i < strings.Length; i++)
  392. {
  393. if (strings[i].Contains("lv"))
  394. {
  395. }
  396. else if (strings[i].Contains("&person&"))
  397. {
  398. #region MyRegion
  399. if (Math.Abs(Person) > 0.0005f)
  400. {
  401. temp = NewPerson;
  402. UpgradeValue(ref temp, Person, UpgradePerson, offset);
  403. UpgradeUnit(ref temp, strings[i]);
  404. stringBuilder.Append(temp.ToString("0"));
  405. }
  406. else if (Math.Abs(PersonBuff) > 0.0005f)
  407. {
  408. temp = NewPersonBuff;
  409. UpgradeValue(ref temp, PersonBuff, UpgradePerson, offset);
  410. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  411. }
  412. #endregion
  413. }
  414. else if (strings[i].Contains("&skill_cd&"))
  415. {
  416. #region MyRegion
  417. if (Math.Abs(SkillCD) > 0.0005f)
  418. {
  419. temp = NewSkillCD;
  420. UpgradeValue(ref temp, SkillCD, UpgradeCD, offset);
  421. UpgradeUnit(ref temp, strings[i]);
  422. stringBuilder.Append(temp.ToString("0"));
  423. }
  424. else if (Math.Abs(SkillCdBuff) > 0.0005f)
  425. {
  426. temp = NewSkillCdBuff;
  427. UpgradeValue(ref temp, UpgradeCD, offset);
  428. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  429. }
  430. #endregion
  431. }
  432. else if (strings[i].Contains("&coin_person&"))
  433. {
  434. #region MyRegion
  435. if (Math.Abs(CoinPerson) > 0.0005f)
  436. {
  437. temp = NewCoinPerson;
  438. UpgradeValue(ref temp, CoinPerson, UpgradePlus, offset);
  439. UpgradeUnit(ref temp, strings[i]);
  440. stringBuilder.Append(temp.ToString("0.0"));
  441. }
  442. else if (Math.Abs(Plus) > 0.0005f)
  443. {
  444. temp = NewPlus;
  445. UpgradeValue(ref temp, Plus, UpgradePlus, offset);
  446. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  447. }
  448. #endregion
  449. }
  450. else
  451. {
  452. stringBuilder.Append(strings[i]);
  453. }
  454. }
  455. return stringBuilder.ToString();
  456. }
  457. protected double UpgradeAmtParse(string str)
  458. {
  459. if (string.IsNullOrEmpty(str))
  460. {
  461. return UnlockAmt;
  462. }
  463. else
  464. {
  465. return double.Parse(str);
  466. }
  467. }
  468. #endregion
  469. }