BigSkill.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System;
  4. using System.Xml;
  5. using System.Text;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. public class BigSkill : Skill
  9. {
  10. #region 变量
  11. public Sprite BarIcon
  12. {
  13. get
  14. {
  15. return ManaReso.Load<Sprite>(Icon_ + "副", Folder.UI);
  16. }
  17. }
  18. public int BarIndex;
  19. public Text BarLab;
  20. public Image BarBk0;
  21. public Image BarBk1;
  22. public Button BarBtn;
  23. public SkillStatus BarStatus
  24. {
  25. get { return BarStatus_; }
  26. set
  27. {
  28. BarStatus_ = value;
  29. if (BarStatus_ == SkillStatus.Cool)
  30. {
  31. BarBk0.SetActive(true);
  32. BarBk1.SetActive(false);
  33. }
  34. else if (BarStatus_ == SkillStatus.UnLock)
  35. {
  36. BarBk0.SetActive(false);
  37. BarBk1.SetActive(true);
  38. }
  39. else if (BarStatus_ == SkillStatus.Buy)
  40. {
  41. BarBk0.SetActive(false);
  42. BarBk1.SetActive(true);
  43. BarBtn.interactable = true;
  44. }
  45. }
  46. }
  47. public override SkillStatus ItemStatus
  48. {
  49. get { return ItemStatus_; }
  50. set
  51. {
  52. ItemStatus_ = value;
  53. if (SkillTab == SkillTab.Null)
  54. {
  55. return;
  56. }
  57. if (ItemStatus_ == SkillStatus.Lock)
  58. {
  59. ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab0"), "\n", new LanStr("UI", "Fe_BtnLab4"), UnlockLv);
  60. }
  61. else if (ItemStatus_ == SkillStatus.UnLock)
  62. {
  63. if (UnlockCur == Current.Free)
  64. {
  65. ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab1"));
  66. }
  67. else
  68. {
  69. ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab1"), "\n", ImageParse(UnlockCur), UnlockAmt.ToString("0"));
  70. }
  71. }
  72. else if (ItemStatus_ == SkillStatus.Upgrade)
  73. {
  74. ManaLan.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab2"), "\n", ImageParse(UpgradeCur), Auxiliary.ShrinkNumberStr(NewUpgradeAmt));
  75. }
  76. }
  77. }
  78. public SkillStatus BarStatus_;
  79. #endregion
  80. public BigSkill(XmlAttributeCollection attribute) : base(attribute)
  81. {
  82. BarIndex = Auxiliary.IntParse(attribute[4].Value,0);
  83. SkillType = SkillType.BigSkill;
  84. }
  85. public override void Annul()
  86. {
  87. CoolTimer = CD * (1 + CdBuff);
  88. //BarLab.color = Color.white;
  89. BarStatus = SkillStatus.Cool;
  90. ManaData.CoolList.Add(this);
  91. AnnulA();
  92. }
  93. public override void AnnulA()
  94. {
  95. ManaData.SkillPlus -= NewPlus;
  96. ManaData.SkillPerson -= NewPerson;
  97. ManaData.SkillPersonBuff -= NewPersonBuff;
  98. ManaData.SkillCoinPerson -= NewCoinPerson;
  99. }
  100. public override bool DoUse()
  101. {
  102. UseTimer -= Time.deltaTime;
  103. TimeSpan timeSpan = new TimeSpan(0, 0, 0, (int)UseTimer);
  104. BarLab.text = string.Format("{0} : {1}", timeSpan.Minutes.ToString("00"), timeSpan.Seconds.ToString("00"));
  105. if (UseTimer <= 0)
  106. {
  107. Annul();
  108. return true;
  109. }
  110. else
  111. {
  112. return false;
  113. }
  114. }
  115. public override bool DoCool()
  116. {
  117. CoolTimer -= Time.deltaTime;
  118. TimeSpan timeSpan = new TimeSpan(0, 0, 0, (int)CoolTimer);
  119. BarLab.text = string.Format("{0} : {1}", timeSpan.Minutes.ToString("00"), timeSpan.Seconds.ToString("00"));
  120. BarBk0.fillAmount = CoolTimer / CD;
  121. if (CoolTimer <= 0)
  122. {
  123. BarLab.text = "";
  124. BarStatus = SkillStatus.Buy;
  125. return true;
  126. }
  127. else
  128. {
  129. return false;
  130. }
  131. }
  132. public override void Reactive()
  133. {
  134. if (BarStatus == SkillStatus.Use)
  135. {
  136. AnnulA();
  137. ManaData.UseList.Remove(this);
  138. }
  139. else if (BarStatus == SkillStatus.Cool)
  140. {
  141. ManaData.CoolList.Remove(this);
  142. }
  143. }
  144. public override void RegistValue(float elapse, List<List<Skill>> useList, XmlAttributeCollection attribute)
  145. {
  146. Level = int.Parse(attribute[4].Value);
  147. UseTimer = float.Parse(attribute[6].Value);
  148. CoolTimer = float.Parse(attribute[5].Value);
  149. BarBk1.material = Bundle.Effect.LoadAsset<Material>("GrayMat");
  150. BarStatus_ = (SkillStatus)Enum.Parse(typeof(SkillStatus), attribute[3].Value);
  151. ItemStatus_ = (SkillStatus)Enum.Parse(typeof(SkillStatus), attribute[2].Value);
  152. NewPlus = Plus;
  153. NewPerson = Person;
  154. NewSkillCD = SkillCD;
  155. NewDuration = Duration;
  156. NewCoinOnce = CoinOnce;
  157. NewSkillCdBuff = SkillCdBuff;
  158. NewPersonBuff = PersonBuff;
  159. NewCoinPerson = CoinPerson;
  160. NewUpgradeAmt = UpgradeAmt;
  161. NewCoinOnceBuff = CoinOnceBuff;
  162. if (SkillTab == SkillTab.Null)
  163. {
  164. BarBk1.sprite = BarIcon;
  165. BarBtn.onClick.RemoveAllListeners();
  166. BarBtn.onClick.AddListener(Buy);
  167. }
  168. else
  169. {
  170. BarBk1.sprite = BarIcon;
  171. ItemLab.text = Description(0);
  172. BarBtn.onClick.RemoveAllListeners();
  173. BarBtn.onClick.AddListener(Buy);
  174. ItemBtn.onClick.RemoveAllListeners();
  175. ItemBtn.onClick.AddListener(OnClick);
  176. if (Level > 0)
  177. {
  178. for (int i = 0; i < Level - 1; i++)
  179. {
  180. NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString());
  181. }
  182. UpgradeValue(ref NewPlus, Plus, UpgradePlus, Level - 1);
  183. UpgradeValue(ref NewSkillCdBuff, UpgradeCD, Level - 1);
  184. UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, Level - 1);
  185. UpgradeValue(ref NewCoinOnceBuff, UpgradeCoinOnce, Level - 1);
  186. UpgradeValue(ref NewPerson, Person, UpgradePerson, Level - 1);
  187. UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, Level - 1);
  188. UpgradeValue(ref NewDuration, Duration, UpgradeDuration, Level - 1);
  189. UpgradeValue(ref NewCoinOnce, CoinOnce, UpgradeCoinOnce, Level - 1);
  190. UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, Level - 1);
  191. }
  192. }
  193. if (BarStatus_ == SkillStatus.Use)
  194. {
  195. UseA();
  196. if (UseTimer < elapse)
  197. {
  198. if (useList.Count > 0)
  199. {
  200. if (UseTimer < ManaData.CircleTimer)
  201. {
  202. useList[0].UniqueAdd(this);
  203. }
  204. else
  205. {
  206. int ffCircle = 1 + Mathf.FloorToInt((UseTimer - ManaData.CircleTimer) / ManaData.CircleTime);
  207. useList[ffCircle].UniqueAdd(this);
  208. }
  209. }
  210. }
  211. else
  212. {
  213. UseTimer -= elapse;
  214. BarBk1.SetActive(true);
  215. }
  216. }
  217. else if (BarStatus_ == SkillStatus.Cool)
  218. {
  219. CoolTimer -= elapse;
  220. ManaData.CoolList.Add(this);
  221. }
  222. if (BarStatus != SkillStatus.UnLock)
  223. {
  224. BarBk1.material = null;
  225. }
  226. BarStatus = BarStatus;
  227. ItemStatus = ItemStatus;
  228. }
  229. public override void ReceiveCool(float amt, bool current, bool buff)
  230. {
  231. if (!ReduceCD)
  232. {
  233. return;
  234. }
  235. if (current)
  236. {
  237. if (BarStatus != SkillStatus.Cool)
  238. {
  239. return;
  240. }
  241. if (buff)
  242. {
  243. CoolTimer -= CD * amt;
  244. }
  245. else
  246. {
  247. CoolTimer -= amt;
  248. }
  249. }
  250. else
  251. {
  252. if (buff)
  253. {
  254. CdBuff -= amt;
  255. }
  256. else
  257. {
  258. CD -= amt;
  259. }
  260. }
  261. }
  262. public override void UpdateStatus()
  263. {
  264. if (ManaData.Level >= UnlockLv)
  265. {
  266. if (SkillTab == SkillTab.Null)
  267. {
  268. if (BarStatus == SkillStatus.UnLock)
  269. {
  270. Unlock();
  271. }
  272. }
  273. else
  274. {
  275. if (ItemStatus == SkillStatus.Lock)
  276. {
  277. ItemStatus = SkillStatus.UnLock;
  278. }
  279. }
  280. }
  281. }
  282. public override void RegistReference()
  283. {
  284. base.RegistReference();
  285. BarLab = ManaReso.Get<Text>(string.Format("F_SkillLab{0}", BarIndex));
  286. BarBk0 = ManaReso.Get<Image>(string.Format("F_SkillBk{0}0", BarIndex));
  287. BarBk1 = ManaReso.Get<Image>(string.Format("F_SkillBk{0}1", BarIndex));
  288. BarBtn = BarBk1.GetComponent<Button>();
  289. }
  290. public override void SwitchLanguage()
  291. {
  292. base.SwitchLanguage();
  293. ItemStatus = ItemStatus;
  294. }
  295. protected void Unlock()
  296. {
  297. ManaData.Pay(ID, UnlockAmt, UnlockCur, () =>
  298. {
  299. ManaAudio.PlayClip(Clip.SkillClip);
  300. BarStatus = SkillStatus.Buy;
  301. ItemStatus = SkillStatus.Upgrade;
  302. Level = 1;
  303. BarBk1.material = null;
  304. });
  305. }
  306. protected void Upgrade()
  307. {
  308. ManaData.Pay(ID, NewUpgradeAmt, UpgradeCur, () =>
  309. {
  310. ManaAudio.PlayClip(Clip.SkillClip);
  311. Level++;
  312. if (BarStatus == SkillStatus.Use)
  313. {
  314. AnnulA();
  315. }
  316. NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString());
  317. UpgradeValue(ref NewPlus, Plus, UpgradePlus, 1);
  318. UpgradeValue(ref NewSkillCdBuff, UpgradeCD, 1);
  319. UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, 1);
  320. UpgradeValue(ref NewCoinOnceBuff, UpgradeCoinOnce, 1);
  321. UpgradeValue(ref NewPerson, Person, UpgradePerson, 1);
  322. UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, 1);
  323. UpgradeValue(ref NewDuration, Duration, UpgradeDuration, 1);
  324. UpgradeValue(ref NewCoinOnce, CoinOnce, UpgradeCoinOnce, 1);
  325. UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, 1);
  326. if (BarStatus == SkillStatus.Use)
  327. {
  328. UseA();
  329. }
  330. });
  331. }
  332. protected override void Buy()
  333. {
  334. if (ManaServer.Connect == false)
  335. {
  336. ManaReso.Get("Fg_Reconnect").TweenForCG();
  337. return;
  338. }
  339. ManaData.Pay(ID, UseAmt, BuyCur, () =>
  340. {
  341. ManaReso.GetLightwall();
  342. ManaAudio.PlayClip(Clip.SkillClip);
  343. ManaData.SkillAmt++;
  344. UseTimer = NewDuration;
  345. BarStatus = SkillStatus.Use;
  346. //BarLab.color = Color.blue;
  347. UseA();
  348. UseB();
  349. });
  350. }
  351. protected override void UseA()
  352. {
  353. //BarLab.color = Color.blue;
  354. BarBtn.interactable = false;
  355. ManaData.UseList.Add(this);
  356. ManaData.SkillPlus += NewPlus;
  357. ManaData.SkillPerson += NewPerson;
  358. ManaData.SkillPersonBuff += NewPersonBuff;
  359. ManaData.SkillCoinPerson += NewCoinPerson;
  360. if (Math.Abs(NewSkillCD) > 0.0005f)
  361. {
  362. for (int i = 0; i < ManaData.SkillList.Count; i++)
  363. {
  364. ManaData.SkillList[i].ReceiveCool(NewSkillCD, true, false);
  365. }
  366. }
  367. if (Math.Abs(NewSkillCdBuff) > 0.0005f)
  368. {
  369. for (int i = 0; i < ManaData.SkillList.Count; i++)
  370. {
  371. ManaData.SkillList[i].ReceiveCool(NewSkillCdBuff, true, true);
  372. }
  373. }
  374. }
  375. protected override void OnClick()
  376. {
  377. ManaAudio.PlayClip(Clip.BtnClip);
  378. ManaReso.Get("Fe_Info").TweenForCG();
  379. ManaReso.SetText("Fe_Tit", Name);
  380. ManaReso.SetSprite("Fe_Icon", Icon);
  381. if (ItemStatus == SkillStatus.Lock)
  382. {
  383. ManaReso.SetText("Fe_Lab0", "");
  384. ManaReso.SetText("Fe_Lab1", Description(0));
  385. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab0"), ImageParse(UnlockAheadCur), UnlockAheadAmt));
  386. ManaReso.SetButtonEvent
  387. (
  388. "Fe_Btn",
  389. () =>
  390. {
  391. UnlockAhead();
  392. ManaReso.Get("Fe_Info").TweenBacCG();
  393. }
  394. );
  395. }
  396. else if (ItemStatus == SkillStatus.UnLock)
  397. {
  398. ManaReso.SetText("Fe_Lab0", "");
  399. ManaReso.SetText("Fe_Lab1", Description(0));
  400. if (UnlockCur == Current.Free)
  401. {
  402. ManaReso.SetText("Fe_BtnLab", string.Format("{0}", Language.GetStr("UI", "Fe_BtnLab1")));
  403. }
  404. else
  405. {
  406. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab1"), ImageParse(UnlockCur), UnlockAmt));
  407. }
  408. ManaReso.SetButtonEvent
  409. (
  410. "Fe_Btn",
  411. () =>
  412. {
  413. Unlock();
  414. ManaReso.Get("Fe_Info").TweenBacCG();
  415. }
  416. );
  417. }
  418. else if (ItemStatus == SkillStatus.Upgrade)
  419. {
  420. ManaReso.SetText("Fe_Lab0", Description(0));
  421. ManaReso.SetText("Fe_Lab1", Description(1));
  422. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab2"), ImageParse(UpgradeCur), Auxiliary.ShrinkNumberStr(NewUpgradeAmt)));
  423. ManaReso.SetButtonEvent
  424. (
  425. "Fe_Btn",
  426. () =>
  427. {
  428. Upgrade();
  429. ItemLab.text = Description(0);
  430. ItemBtnLab.text = Language.GetStr("UI", "Fe_BtnLab2") + "\n" + ImageParse(UpgradeCur) + Auxiliary.ShrinkNumberStr(NewUpgradeAmt);
  431. ManaReso.SetText("Fe_Tit", Name);
  432. ManaReso.SetText("Fe_Lab0", Description(0));
  433. ManaReso.SetText("Fe_Lab1", Description(1));
  434. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab2"), ImageParse(UpgradeCur), Auxiliary.ShrinkNumberStr(NewUpgradeAmt)));
  435. }
  436. );
  437. }
  438. }
  439. protected override void UnlockAhead()
  440. {
  441. if (ItemStatus != SkillStatus.Lock)
  442. {
  443. ManaDebug.Log("您并不需要提前解锁");
  444. return;
  445. }
  446. ManaData.Pay(ID, UnlockAheadAmt, UnlockAheadCur, () =>
  447. {
  448. ManaAudio.PlayClip(Clip.SkillClip);
  449. ItemStatus = SkillStatus.UnLock;
  450. });
  451. }
  452. }