Skill.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System;
  4. using System.Xml;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. public class Skill : SkillRoot
  10. {
  11. #region Config
  12. #region 配置
  13. public float UnlockAheadAmt
  14. {
  15. get { return UnlockAheadBaseAmt + (UnlockLv - Manager.GardenLevel - 1) * UnlockAheadDeltaAmt; }
  16. }
  17. public override string FullID
  18. {
  19. get { return SkillFullIDPrefix + ID; }
  20. }
  21. public bool CoolLock;
  22. public float CD;
  23. public float Person;
  24. public float SkillCD;
  25. public float UseAmt;
  26. public float Duration;
  27. public float CoinOnce;
  28. public float CoinPerson;
  29. public float DiamondOnce;
  30. public double UpgradeAmt;
  31. public float Plus;
  32. public float CdBuff = 1;
  33. public float PersonBuff;
  34. public float SkillCdBuff;
  35. public float CoinOnceBuff;
  36. public int UnlockLv;
  37. public float UnlockAmt;
  38. public float UnlockAheadBaseAmt;
  39. public float UnlockAheadDeltaAmt;
  40. public string UnlockPos;
  41. public Current BuyCur;
  42. public Current UnlockCur;
  43. public Current UpgradeCur;
  44. public Current UnlockAheadCur;
  45. public string Label;
  46. public string Anim;
  47. public string UpgradeCD;
  48. public string UpgradeFml;
  49. public string UpgradePlus;
  50. public string UpgradePerson;
  51. public string UpgradeDuration;
  52. public string UpgradeCoinOnce;
  53. #endregion
  54. public float UseTimer;
  55. public float CoolTimer;
  56. public float NewPlus;
  57. public float NewPerson;
  58. public float NewSkillCD;
  59. public float NewDuration;
  60. public float NewCoinOnce;
  61. public float NewSkillCdBuff;
  62. public float NewPersonBuff;
  63. public float NewCoinPerson;
  64. public float NewCoinOnceBuff;
  65. public double NewUpgradeAmt;
  66. public override SkillStatus ItemStatus
  67. {
  68. get { return itemStatus; }
  69. set
  70. {
  71. itemStatus = value;
  72. if (itemStatus == SkillStatus.Buy)
  73. {
  74. button.interactable = true;
  75. if (BuyCur == Current.AD)
  76. {
  77. LanguageManager.Add(ButtonTitle, new MulLanStr(LanguageLabel.Common__AD));
  78. }
  79. else
  80. {
  81. LanguageManager.Add(ButtonTitle, new MulLanStr(LanguageLabel.UI__Fe_BtnLab3), "\n", Auxiliary.ImageParse(BuyCur), UseAmt.ToString("0"));
  82. }
  83. }
  84. else if (itemStatus == SkillStatus.Use)
  85. {
  86. button.interactable = false;
  87. }
  88. else if (itemStatus == SkillStatus.Lock)
  89. {
  90. button.interactable = true;
  91. LanguageManager.Add(ButtonTitle, new MulLanStr(LanguageLabel.UI__Fe_BtnLab0), "\n", new MulLanStr(LanguageLabel.UI__Fe_BtnLab4), UnlockLv.ToString());
  92. }
  93. else if (itemStatus == SkillStatus.Cool)
  94. {
  95. button.interactable = false;
  96. }
  97. }
  98. }
  99. #endregion
  100. public Skill(XmlAttributeCollection attribute)
  101. {
  102. #region 配置
  103. ID = int.Parse(attribute[0].Value);
  104. icon = attribute[31].Value;
  105. Anim = attribute[32].Value;
  106. Label = attribute[33].Value;
  107. UnlockPos = attribute[19].Value;
  108. UpgradeCD = attribute[29].Value;
  109. UpgradeFml = attribute[24].Value;
  110. UpgradePlus = attribute[25].Value;
  111. UpgradePerson = attribute[26].Value;
  112. UpgradeDuration = attribute[28].Value;
  113. UpgradeCoinOnce = attribute[27].Value;
  114. UnlockLv = Auxiliary.StringToInt(attribute[13].Value,0);
  115. ItemIndex = Auxiliary.StringToInt(attribute[3].Value,0);
  116. CD = Auxiliary.StringToFloat(attribute[12].Value,0);
  117. UseAmt = Auxiliary.StringToFloat(attribute[21].Value,0);
  118. Duration = Auxiliary.StringToFloat(attribute[11].Value,0);
  119. UnlockAmt = Auxiliary.StringToFloat(attribute[18].Value,0);
  120. DiamondOnce = Auxiliary.StringToFloat(attribute[9].Value,0);
  121. UnlockAheadBaseAmt = Auxiliary.StringToFloat(attribute[16].Value,0);
  122. UnlockAheadDeltaAmt = Auxiliary.StringToFloat(attribute[15].Value, 0);
  123. SkillTab = SkillClassParse(attribute[2].Value);
  124. CoolLock = Auxiliary.StringToBool(attribute[5].Value, false);
  125. UpgradeAmt = GetUpgradeAmt(attribute[23].Value);
  126. BuyCur = Auxiliary.CurrentParse(attribute[20].Value);
  127. UnlockCur = Auxiliary.CurrentParse(attribute[17].Value);
  128. UpgradeCur = Auxiliary.CurrentParse(attribute[22].Value);
  129. UnlockAheadCur = Auxiliary.CurrentParse(attribute[14].Value);
  130. ValueBuffParse(out Person, out PersonBuff, attribute[7].Value);
  131. ValueBuffParse(out SkillCD, out SkillCdBuff, attribute[10].Value);
  132. ValueBuffParse(out CoinOnce, out CoinOnceBuff, attribute[8].Value);
  133. ValueBuffParse(out CoinPerson, out Plus, attribute[6].Value);
  134. #endregion
  135. SkillType = SkillType.Skill;
  136. }
  137. public virtual void AnnulBuff()
  138. {
  139. Manager.SkillPlus -= NewPlus;
  140. Manager.SkillPerson -= NewPerson;
  141. Manager.SkillPersonBuff -= NewPersonBuff;
  142. Manager.SkillCoinPerson -= NewCoinPerson;
  143. if (!NewSkillCD.Equal(0))
  144. {
  145. for (int i = 0; i < Manager.SkillList.Count; i++)
  146. {
  147. Manager.SkillList[i].Cool(-NewSkillCD, true, false);
  148. }
  149. }
  150. if (!NewSkillCdBuff.Equal(0))
  151. {
  152. for (int i = 0; i < Manager.SkillList.Count; i++)
  153. {
  154. Manager.SkillList[i].Cool(-NewSkillCdBuff, true, true);
  155. }
  156. }
  157. }
  158. public virtual bool DoCD()
  159. {
  160. CoolTimer -= Time.deltaTime;
  161. TimeSpan timeSpan = new TimeSpan(0, 0, Mathf.CeilToInt(CoolTimer));
  162. if (timeSpan.Hours >= 1)
  163. {
  164. ButtonTitle.text = string.Format("{0}\n{1}{2}:{3}", Language.GetStr(LanguageLabel.UI__Fe_BtnLab6), Language.GetStr(LanguageLabel.UI__Fe_BtnLab7), timeSpan.Hours.ToString("00"), timeSpan.Minutes.ToString("00"));
  165. }
  166. else
  167. {
  168. ButtonTitle.text = string.Format("{0}\n{1}{2}:{3}", Language.GetStr(LanguageLabel.UI__Fe_BtnLab6), Language.GetStr(LanguageLabel.UI__Fe_BtnLab7), timeSpan.Minutes.ToString("00"), timeSpan.Seconds.ToString("00"));
  169. }
  170. if (CoolTimer <= 0)
  171. {
  172. ItemStatus = SkillStatus.Buy;
  173. return true;
  174. }
  175. else
  176. {
  177. return false;
  178. }
  179. }
  180. public override bool DoUpdate()
  181. {
  182. UseTimer -= Time.deltaTime;
  183. TimeSpan timeSpan = new TimeSpan(0, 0, Mathf.CeilToInt(UseTimer));
  184. if (timeSpan.Hours >= 1)
  185. {
  186. ButtonTitle.text = string.Format("{0}\n{1}{2}:{3}", Language.GetStr(LanguageLabel.UI__Fe_BtnLab8), Language.GetStr(LanguageLabel.UI__Fe_BtnLab7), timeSpan.Hours.ToString("00"), timeSpan.Minutes.ToString("00"));
  187. }
  188. else
  189. {
  190. ButtonTitle.text = string.Format("{0}\n{1}{2}:{3}", Language.GetStr(LanguageLabel.UI__Fe_BtnLab8), Language.GetStr(LanguageLabel.UI__Fe_BtnLab7), timeSpan.Minutes.ToString("00"), timeSpan.Seconds.ToString("00"));
  191. }
  192. if (UseTimer <= 0)
  193. {
  194. AnnulEffect();
  195. return true;
  196. }
  197. else
  198. {
  199. return false;
  200. }
  201. }
  202. public override void AnnulEffect()
  203. {
  204. CoolTimer = CD * CdBuff - 1;
  205. ItemStatus = SkillStatus.Cool;
  206. Manager.CoolSkillList.Add(this);
  207. AnnulBuff();
  208. }
  209. public override void UpdateStatus()
  210. {
  211. if (!Manager.Inited)
  212. {
  213. return;
  214. }
  215. if (Manager.GardenLevel >= UnlockLv)
  216. {
  217. if (ItemStatus == SkillStatus.Lock)
  218. {
  219. SkillIcon.material = null;
  220. ItemStatus = SkillStatus.Buy;
  221. }
  222. }
  223. }
  224. protected virtual void GetAward()
  225. {
  226. float temp = NewCoinOnce + Manager.CoinPerson * NewCoinOnceBuff;
  227. Manager.AddCoin(temp, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.AD);
  228. Manager.AddDiamond(DiamondOnce, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.AD);
  229. StringBuilder sb = new StringBuilder();
  230. if (!temp.Equal(0))
  231. {
  232. sb.AppendFormat("{0}{1}{2}", Language.GetStr(LanguageLabel.UI__J_Info0), TransferLabel.CoinSprite, temp.ToString("0"));
  233. }
  234. if (!DiamondOnce.Equal(0))
  235. {
  236. sb.AppendFormat("{0}{1}{2}", Language.GetStr(LanguageLabel.UI__J_Info0), TransferLabel.DiamondSprite, DiamondOnce.ToString("0"));
  237. }
  238. string str = sb.ToString();
  239. if (!string.IsNullOrEmpty(str))
  240. {
  241. InfoBoxManager.GardenInfoBox.Display(sb.ToString(), 10f, Color.white, ResourceManager.LoadSprite("Atlas", Folder.Atlas));
  242. }
  243. }
  244. protected virtual void GetBuff()
  245. {
  246. if (UseTimer.Equal(-1))
  247. {
  248. AnnulEffect();
  249. }
  250. else
  251. {
  252. ItemStatus = SkillStatus.Use;
  253. Manager.UsingSkillList.Add(this);
  254. }
  255. Manager.SkillPlus += NewPlus;
  256. Manager.SkillPerson += NewPerson;
  257. Manager.SkillPersonBuff += NewPersonBuff;
  258. Manager.SkillCoinPerson += NewCoinPerson;
  259. if (!NewSkillCD.Equal(0))
  260. {
  261. for (int i = 0; i < Manager.SkillList.Count; i++)
  262. {
  263. Manager.SkillList[i].Cool(NewSkillCD, true, false);
  264. }
  265. }
  266. if (!NewSkillCdBuff.Equal(0))
  267. {
  268. for (int i = 0; i < Manager.SkillList.Count; i++)
  269. {
  270. Manager.SkillList[i].Cool(NewSkillCdBuff, true, true);
  271. }
  272. }
  273. }
  274. protected virtual void Buy()
  275. {
  276. if (ID == 5)
  277. {
  278. StaticsManager.GetInstance().AdClicked(1);
  279. }
  280. else if (ID == 6)
  281. {
  282. StaticsManager.GetInstance().AdClicked(2);
  283. }
  284. Manager.Pay
  285. (
  286. FullID,
  287. UseAmt,
  288. BuyCur,
  289. () =>
  290. {
  291. AudioManager.PlayClip(AudioLabel.UseSkill);
  292. if (BuyCur != Current.AD)
  293. {
  294. Manager.UseSkillAmt++;
  295. }
  296. UseTimer = NewDuration - 1;
  297. GetBuff();
  298. GetAward();
  299. InfoBoxManager.GardenInfoBox.Display(string.Format("{0}{1}", Language.GetStr(LanguageLabel.UI__J_Info1), Language.GetStr(LanguageLabel.CombineLanguageLabel(LanguageLabel.SkillName, FullID))), 10f, Color.white, ResourceManager.LoadSprite(ResourceLabel.Atlas, Folder.Atlas));
  300. },
  301. StaticsManager.ItemID.使用技能,
  302. StaticsManager.ConsumeModule.Shop
  303. );
  304. }
  305. protected virtual void OnClick()
  306. {
  307. AudioManager.PlayClip(AudioLabel.ClickButton);
  308. if (ItemStatus == SkillStatus.Buy)
  309. {
  310. if (BuyCur == Current.AD)
  311. {
  312. Buy();
  313. }
  314. else
  315. {
  316. ResourceManager.Get(CanvasLabel.Fe_Info).TweenForCG();
  317. ResourceManager.SetText(CanvasLabel.Fe_Tit, Name);
  318. ResourceManager.SetSprite(CanvasLabel.Fe_Icon, Icon);
  319. ResourceManager.SetText(CanvasLabel.Fe_Lab0, "");
  320. ResourceManager.SetText(CanvasLabel.Fe_Lab1, GetDescription(0));
  321. ResourceManager.SetText(CanvasLabel.Fe_BtnLab, string.Format("{0}({1}{2:0})", Language.GetStr(LanguageLabel.UI__Fe_BtnLab3), Auxiliary.ImageParse(BuyCur), UseAmt));
  322. ResourceManager.SetButtonEvent
  323. (
  324. CanvasLabel.Fe_Btn,
  325. () =>
  326. {
  327. Buy();
  328. ResourceManager.Get(CanvasLabel.Fe_Info).TweenBacCG();
  329. }
  330. );
  331. }
  332. }
  333. else if (ItemStatus == SkillStatus.Lock)
  334. {
  335. ResourceManager.Get(CanvasLabel.Fe_Info).TweenForCG();
  336. ResourceManager.SetText(CanvasLabel.Fe_Tit, Name);
  337. ResourceManager.SetSprite(CanvasLabel.Fe_Icon, Icon);
  338. ResourceManager.SetText(CanvasLabel.Fe_Lab0, "");
  339. ResourceManager.SetText(CanvasLabel.Fe_Lab1, GetDescription(0));
  340. ResourceManager.SetText(CanvasLabel.Fe_BtnLab, string.Format("{0}({1}{2:0})", Language.GetStr(LanguageLabel.UI__Fe_BtnLab0), Auxiliary.ImageParse(UnlockAheadCur), UnlockAheadAmt.ToString("0")));
  341. ResourceManager.SetButtonEvent
  342. (
  343. CanvasLabel.Fe_Btn,
  344. () =>
  345. {
  346. UnlockAhead();
  347. ResourceManager.Get(CanvasLabel.Fe_Info).TweenBacCG();
  348. }
  349. );
  350. }
  351. }
  352. protected virtual void UnlockAhead()
  353. {
  354. Manager.Pay
  355. (
  356. FullID,
  357. UnlockAheadAmt,
  358. UnlockAheadCur,
  359. () =>
  360. {
  361. AudioManager.PlayClip(AudioLabel.ClickButton);
  362. SkillIcon.material = null;
  363. ItemStatus = SkillStatus.Buy;
  364. },
  365. StaticsManager.ItemID.提前解锁技能,
  366. StaticsManager.ConsumeModule.Shop
  367. );
  368. }
  369. public override void Reactive()
  370. {
  371. if (ItemStatus == SkillStatus.Use)
  372. {
  373. AnnulBuff();
  374. Manager.UsingSkillList.Remove(this);
  375. }
  376. else if (ItemStatus == SkillStatus.Cool)
  377. {
  378. Manager.CoolSkillList.Remove(this);
  379. }
  380. }
  381. public override void Init(bool firstInit, float elapse, List<List<Skill>> useList, XmlAttributeCollection attribute)
  382. {
  383. Level = int.Parse(attribute[3].Value);
  384. UseTimer = float.Parse(attribute[5].Value);
  385. CoolTimer = float.Parse(attribute[4].Value);
  386. itemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), attribute[2].Value);
  387. NewPlus = Plus;
  388. NewPerson = Person;
  389. NewSkillCD = SkillCD;
  390. NewDuration = Duration;
  391. NewCoinOnce = CoinOnce;
  392. NewSkillCdBuff = SkillCdBuff;
  393. NewPersonBuff = PersonBuff;
  394. NewCoinPerson = CoinPerson;
  395. NewUpgradeAmt = UpgradeAmt;
  396. NewCoinOnceBuff = CoinOnceBuff;
  397. if (itemStatus == SkillStatus.Lock || itemStatus == SkillStatus.UnLock)
  398. {
  399. SkillIcon.material = Lib.GrayMat;
  400. }
  401. else
  402. {
  403. SkillIcon.material = null;
  404. }
  405. if (itemStatus == SkillStatus.Use)
  406. {
  407. GetBuff();
  408. if (UseTimer < elapse)
  409. {
  410. Manager.UsingSkillList.Remove(this);
  411. if (useList.Count > 0)
  412. {
  413. if (UseTimer < Manager.IncomeCircleTimer)
  414. {
  415. useList[0].UniqueAdd(this);
  416. }
  417. else
  418. {
  419. int circle = 1 + Mathf.FloorToInt((UseTimer - Manager.IncomeCircleTimer)/Manager.IncomeCircleTime);
  420. useList[circle].UniqueAdd(this);
  421. }
  422. }
  423. }
  424. else
  425. {
  426. UseTimer -= elapse;
  427. }
  428. }
  429. else if (itemStatus == SkillStatus.Cool)
  430. {
  431. CoolTimer -= elapse;
  432. Manager.CoolSkillList.Add(this);
  433. }
  434. button.onClick.RemoveAllListeners();
  435. button.onClick.AddListener(OnClick);
  436. DescriptionText.text = GetDescription(0);
  437. ItemStatus = ItemStatus;
  438. }
  439. public override void Cool(float amt, bool current, bool buff)
  440. {
  441. if (!CoolLock)
  442. {
  443. return;
  444. }
  445. if (current)
  446. {
  447. if (ItemStatus != SkillStatus.Cool)
  448. {
  449. return;
  450. }
  451. if (buff)
  452. {
  453. CoolTimer -= CD * amt;
  454. }
  455. else
  456. {
  457. CoolTimer -= amt;
  458. }
  459. }
  460. else
  461. {
  462. if (buff)
  463. {
  464. CdBuff = 1 - amt;
  465. }
  466. else
  467. {
  468. CD -= amt;
  469. }
  470. }
  471. }
  472. protected double GetUpgradeAmt(string str)
  473. {
  474. if (string.IsNullOrEmpty(str))
  475. {
  476. return UnlockAmt;
  477. }
  478. else
  479. {
  480. return double.Parse(str);
  481. }
  482. }
  483. protected override string GetDescription(int offset)
  484. {
  485. float temp;
  486. string[] strings = Desc.Split(TransferLabel.OpenChar, TransferLabel.CloseChar);
  487. StringBuilder stringBuilder = new StringBuilder();
  488. for (int i = 0; i < strings.Length; i++)
  489. {
  490. if (strings[i].Contains(TransferLabel.Level))
  491. {
  492. }
  493. else if (strings[i].Contains(TransferLabel.Person))
  494. {
  495. #region MyRegion
  496. if (!Person.Equal(0))
  497. {
  498. temp = NewPerson;
  499. UpgradeValue(ref temp, Person, UpgradePerson, offset);
  500. UpgradeUnit(ref temp, strings[i]);
  501. float remainder = temp % 1;
  502. if (remainder > 0)
  503. {
  504. stringBuilder.Append(temp.ToString("0") + "+");
  505. }
  506. else
  507. {
  508. stringBuilder.Append(temp.ToString("0"));
  509. }
  510. }
  511. else if (!PersonBuff.Equal(0))
  512. {
  513. temp = NewPersonBuff;
  514. UpgradeValue(ref temp, UpgradePerson, offset);
  515. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  516. }
  517. #endregion
  518. }
  519. else if (strings[i].Contains(TransferLabel.Duration))
  520. {
  521. #region MyRegion
  522. temp = NewDuration;
  523. UpgradeValue(ref temp, Duration, UpgradeDuration, offset);
  524. UpgradeUnit(ref temp, strings[i]);
  525. stringBuilder.Append(temp.ToString("0"));
  526. #endregion
  527. }
  528. else if (strings[i].Contains(TransferLabel.CoinOnce))
  529. {
  530. #region MyRegion
  531. if (!CoinOnce.Equal(0))
  532. {
  533. temp = NewCoinOnce;
  534. UpgradeValue(ref temp, CoinOnce, UpgradeCoinOnce, offset);
  535. stringBuilder.Append(temp.ToString("0"));
  536. }
  537. else if (!CoinOnceBuff.Equal(0))
  538. {
  539. temp = NewCoinOnceBuff;
  540. UpgradeValue(ref temp, UpgradeCoinOnce, offset);
  541. stringBuilder.Append(temp.ToString("0"));
  542. }
  543. #endregion
  544. }
  545. else if (strings[i].Contains(TransferLabel.DiamondOnce))
  546. {
  547. #region MyRegion
  548. stringBuilder.Append(DiamondOnce.ToString("0"));
  549. #endregion
  550. }
  551. else if (strings[i].Contains(TransferLabel.CoinPerson))
  552. {
  553. #region MyRegion
  554. if (!CoinPerson.Equal(0))
  555. {
  556. temp = NewCoinPerson;
  557. UpgradeValue(ref temp, CoinPerson, UpgradePlus, offset);
  558. float remainder = temp % 1;
  559. if (remainder > 0)
  560. {
  561. stringBuilder.Append(temp.ToString("0") + "+");
  562. }
  563. else
  564. {
  565. stringBuilder.Append(temp.ToString("0"));
  566. }
  567. }
  568. else if (!Plus.Equal(0))
  569. {
  570. temp = NewPlus;
  571. UpgradeValue(ref temp, UpgradePlus, offset);
  572. stringBuilder.Append(string.Format("{0:0}%", temp * 100));
  573. }
  574. else
  575. {
  576. throw new Exception();
  577. }
  578. #endregion
  579. }
  580. else
  581. {
  582. stringBuilder.Append(strings[i]);
  583. }
  584. }
  585. return stringBuilder.ToString();
  586. }
  587. }