BigSkill.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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. #region 配置
  12. public int SkillIndex;
  13. #endregion
  14. public Text BarLab;
  15. public Image BarBk0;
  16. public Image BarBk1;
  17. public Button BarBtn;
  18. public SkillStatus BarStatus
  19. {
  20. get { return _BarStatus; }
  21. set
  22. {
  23. _BarStatus = value;
  24. if (_BarStatus == SkillStatus.Cool)
  25. {
  26. BarBk0.SetActive(true);
  27. BarBk1.SetActive(false);
  28. ManaData.CoolList.Add(this);
  29. }
  30. else if (_BarStatus == SkillStatus.Buy)
  31. {
  32. if (SkillTab != SkillTab.Null && ItemStatus != SkillStatus.Upgrade)
  33. {
  34. BarBk0.SetActive(false);
  35. BarBk1.SetActive(true);
  36. BarBtn.interactable = false;
  37. BarLab.text = "";
  38. }
  39. else
  40. {
  41. BarBk0.SetActive(false);
  42. BarBk1.SetActive(true);
  43. BarBtn.interactable = true;
  44. BarLab.text = "";
  45. }
  46. }
  47. else if (_BarStatus == SkillStatus.Use)
  48. {
  49. }
  50. else
  51. {
  52. throw new Exception();
  53. }
  54. }
  55. }
  56. public new SkillStatus ItemStatus
  57. {
  58. get { return _ItemStatus; }
  59. set
  60. {
  61. _ItemStatus = value;
  62. if (SkillTab == SkillTab.Null)
  63. {
  64. return;
  65. }
  66. if (_ItemStatus == SkillStatus.Lock)
  67. {
  68. ManaText.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab0"), "\n", new LanStr("UI", "Fe_BtnLab4"), UnlockLv);
  69. }
  70. else if (_ItemStatus == SkillStatus.UnLock)
  71. {
  72. ManaText.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab1"));
  73. }
  74. else if (_ItemStatus == SkillStatus.Upgrade)
  75. {
  76. ManaText.Add(ItemTit, new LanStr("SkillName", _Name), " ", Level.ToString());
  77. ManaText.Add(ItemBtnLab, new LanStr("UI", "Fe_BtnLab2"));
  78. }
  79. else
  80. {
  81. throw new Exception(_ItemStatus.ToString());
  82. }
  83. }
  84. }
  85. public SkillStatus _BarStatus;
  86. #endregion
  87. public BigSkill(XmlAttributeCollection attribute) : base(attribute)
  88. {
  89. SkillIndex = IntParse(attribute[4].Value);
  90. SkillType = SkillType.BigSkill;
  91. }
  92. public override void Annul()
  93. {
  94. CoolTimer = CD * (1 + CdBuff);
  95. BarLab.color = Color.white;
  96. BarStatus = SkillStatus.Cool;
  97. AnnulConti();
  98. ManaDebug.Log(string.Format("技能结束 <color=red>{0}</color>", Name));
  99. }
  100. public override void AnnulConti()
  101. {
  102. ManaData.SkillPlus -= NewPlus;
  103. ManaData.SkillPerson -= NewPerson;
  104. ManaData.SkillPersonBuff -= NewPersonBuff;
  105. ManaData.SkillCoinPerson -= NewCoinPerson;
  106. if (Math.Abs(NewSkillCD) > 0.0005f)
  107. {
  108. for (int i = 0; i < ManaData.SkillList.Count; i++)
  109. {
  110. ManaData.SkillList[i].ReceiveCool(-NewSkillCD, true, false);
  111. }
  112. }
  113. if (Math.Abs(NewSkillCdBuff) > 0.0005f)
  114. {
  115. for (int i = 0; i < ManaData.SkillList.Count; i++)
  116. {
  117. ManaData.SkillList[i].ReceiveCool(-NewSkillCdBuff, true, true);
  118. }
  119. }
  120. }
  121. public override bool DoUse()
  122. {
  123. UseTimer -= Time.deltaTime;
  124. BarLab.text = UseTimer.ToString("0.0");
  125. if (UseTimer <= 0)
  126. {
  127. Annul();
  128. ManaData.UseList.Remove(this);
  129. return true;
  130. }
  131. else
  132. {
  133. return false;
  134. }
  135. }
  136. public override bool DoCool()
  137. {
  138. CoolTimer -= Time.deltaTime;
  139. TimeSpan timeSpan = new TimeSpan(0, 0, 0, (int)CoolTimer);
  140. BarLab.text = string.Format("{0} : {1}", timeSpan.Minutes, timeSpan.Seconds);
  141. BarBk0.fillAmount = CoolTimer / CD;
  142. if (CoolTimer <= 0)
  143. {
  144. BarStatus = SkillStatus.Buy;
  145. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已冷却", Name));
  146. ManaData.CoolList.Remove(this);
  147. return true;
  148. }
  149. else
  150. {
  151. return false;
  152. }
  153. }
  154. public override void RegistValue(float elapse, List<List<Skill>> ffList, XmlAttributeCollection attribute)
  155. {
  156. Level = int.Parse(attribute[4].Value);
  157. UseTimer = float.Parse(attribute[6].Value);
  158. CoolTimer = float.Parse(attribute[5].Value);
  159. _ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), attribute[2].Value);
  160. _BarStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), attribute[3].Value);
  161. BarBtn.onClick.AddListener(Buy);
  162. BarBk1.sprite = ManaReso.Load<Sprite>(Icon + "副", Folder.Skill);
  163. NewPlus = Plus;
  164. NewPerson = Person;
  165. NewSkillCD = SkillCD;
  166. NewDuration = Duration;
  167. NewCoinOnce = CoinOnce;
  168. NewSkillCdBuff = SkillCdBuff;
  169. NewPersonBuff = PersonBuff;
  170. NewCoinPerson = CoinPerson;
  171. NewUpgradeAmt = UpgradeAmt;
  172. NewCoinOnceBuff = CoinOnceBuff;
  173. if (SkillTab == SkillTab.Null)
  174. {
  175. BarBk1.material = null;
  176. }
  177. else
  178. {
  179. ManaText.Add(ItemTit, new LanStr("SkillName", _Name));
  180. ItemLab.text = Description(0);
  181. ItemBtn.onClick.AddListener(OnClick);
  182. for (int i = 0; i < Level; i++)
  183. {
  184. NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString());
  185. }
  186. UpgradeValue(ref NewPlus, Plus, UpgradePlus, Level);
  187. UpgradeValue(ref NewSkillCdBuff, UpgradeCD, Level);
  188. UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, Level);
  189. UpgradeValue(ref NewCoinOnceBuff, UpgradeCoinOnce, Level);
  190. UpgradeValue(ref NewPerson, Person, UpgradePerson, Level);
  191. UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, Level);
  192. UpgradeValue(ref NewDuration, Duration, UpgradeDuration, Level);
  193. UpgradeValue(ref NewCoinOnce, CoinOnce, UpgradeCoinOnce, Level);
  194. UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, Level);
  195. if (_ItemStatus == SkillStatus.Upgrade)
  196. {
  197. ShowSkillBar();
  198. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁 等级 : {1}", Name, Level));
  199. }
  200. if (_BarStatus == SkillStatus.Use)
  201. {
  202. UseConti();
  203. if (UseTimer < elapse)
  204. {
  205. if (ffList.Count > 0)
  206. {
  207. if (UseTimer < ManaData.CircleTimer)
  208. {
  209. ffList[0].UniqueAdd(this);
  210. }
  211. else
  212. {
  213. int ffCircle = 1 + Mathf.FloorToInt(((UseTimer - ManaData.CircleTimer) / ManaData.CircleTime));
  214. ffList[ffCircle].UniqueAdd(this);
  215. }
  216. }
  217. }
  218. else
  219. {
  220. UseTimer -= elapse;
  221. ManaData.UseList.Add(this);
  222. BarBk1.SetActive(true);
  223. BarLab.color = Color.blue;
  224. }
  225. }
  226. else if (_BarStatus == SkillStatus.Cool)
  227. {
  228. CoolTimer -= elapse;
  229. }
  230. }
  231. ItemStatus = ItemStatus;
  232. BarStatus = BarStatus;
  233. }
  234. public override void ReceiveCool(float amt, bool current, bool buff)
  235. {
  236. if (!ReduceCD)
  237. {
  238. return;
  239. }
  240. if (current)
  241. {
  242. if (BarStatus != SkillStatus.Cool)
  243. {
  244. return;
  245. }
  246. if (buff)
  247. {
  248. CoolTimer -= CD * amt;
  249. }
  250. else
  251. {
  252. CoolTimer -= amt;
  253. }
  254. }
  255. else
  256. {
  257. if (buff)
  258. {
  259. CdBuff -= amt;
  260. }
  261. else
  262. {
  263. CD -= amt;
  264. }
  265. }
  266. }
  267. public override void RegistReference()
  268. {
  269. base.RegistReference();
  270. BarLab = ManaReso.Get<Text>(string.Format("F_SkillLab{0}", SkillIndex - 1));
  271. BarBk0 = ManaReso.Get<Image>(string.Format("F_SkillBk{0}0", SkillIndex - 1));
  272. BarBk1 = ManaReso.Get<Image>(string.Format("F_SkillBk{0}1", SkillIndex - 1));
  273. BarBtn = BarBk1.GetComponent<Button>();
  274. }
  275. private void ShowSkillBar()
  276. {
  277. if (!ManaData.SkillBar)
  278. {
  279. ManaData.SkillBar = true;
  280. ManaReso.Get("Fa_Scrr").TweenForRect();
  281. if (ManaReso.Get("Fa_Garden").gameObject.activeSelf)
  282. {
  283. ManaReso.SetActive("Ff_SkillBar", true);
  284. }
  285. }
  286. }
  287. protected override void Buy()
  288. {
  289. if (ManaTutorial.TutorialA)
  290. {
  291. TutorialBuy();
  292. }
  293. else
  294. {
  295. RegularBuy();
  296. }
  297. }
  298. protected override void Unlock()
  299. {
  300. if (ManaData.Pay(UnlockAmt, UnlockCur))
  301. {
  302. ShowSkillBar();
  303. ItemStatus = SkillStatus.Upgrade;
  304. if (SkillTab != SkillTab.Null)
  305. {
  306. ItemStatus = SkillStatus.Upgrade;
  307. }
  308. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
  309. }
  310. }
  311. protected override void Upgrade()
  312. {
  313. if (ManaTutorial.TutorialA || ManaTutorial.TutorialB && ManaData.Level >= 200)
  314. {
  315. TutorialUpgrade();
  316. }
  317. else
  318. {
  319. RegularUpgrade();
  320. }
  321. }
  322. protected override void UnlockAhead()
  323. {
  324. if (ItemStatus != SkillStatus.Lock)
  325. {
  326. ManaDebug.Log("您并不需要提前解锁");
  327. return;
  328. }
  329. if (ManaData.Pay(UnlockAheadAmt, UnlockAheadCur))
  330. {
  331. ShowSkillBar();
  332. ItemStatus = SkillStatus.Upgrade;
  333. ManaReso.Get("Fe_Info").TweenBacCG();
  334. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
  335. }
  336. }
  337. private void TutorialBuy()
  338. {
  339. ManaTutorial.EndStep9();
  340. ManaData.Skill++;
  341. UseTimer = NewDuration;
  342. ManaData.UseList.Add(this);
  343. if (Math.Abs(Duration) < 0.0005f)
  344. {
  345. BarStatus = SkillStatus.Cool;
  346. }
  347. else
  348. {
  349. BarStatus = SkillStatus.Use;
  350. BarLab.color = Color.blue;
  351. }
  352. UseConti();
  353. UseImmed();
  354. #region 调试输出
  355. StringBuilder strb = new StringBuilder();
  356. strb.AppendFormat("使用技能 : <color=red>{0}</color>", Name);
  357. if (Math.Abs(NewPlus) > 0.0005f)
  358. {
  359. strb.AppendFormat(" 收入加成<color=red>+{0}%</color>", NewPlus*100);
  360. }
  361. if (Math.Abs(NewPerson) > 0.0005f)
  362. {
  363. strb.AppendFormat(" 参观人次<color=red>+{0}</color>", NewPerson);
  364. }
  365. if (Math.Abs(NewPersonBuff) > 0.0005f)
  366. {
  367. strb.AppendFormat(" 参观人次<color=red>+{0}%</color>", NewPersonBuff*100);
  368. }
  369. if (Math.Abs(NewCoinPerson) > 0.0005f)
  370. {
  371. strb.AppendFormat(" 每次金币<color=red>+{0}</color>", NewCoinPerson);
  372. }
  373. if (Math.Abs(NewSkillCD) > 0.0005f)
  374. {
  375. strb.AppendFormat(" 减少冷却<color=red>{0}</color>", NewSkillCD);
  376. }
  377. if (Math.Abs(NewSkillCdBuff) > 0.0005f)
  378. {
  379. strb.AppendFormat(" 减少冷却<color=red>{0}%</color>", NewSkillCdBuff*100);
  380. }
  381. if (Math.Abs(NewCoinOnce) > 0.0005f)
  382. {
  383. strb.AppendFormat(" 获得金币<color=red>{0}</color>", NewCoinOnce);
  384. }
  385. if (Math.Abs(NewCoinOnceBuff) > 0.0005f)
  386. {
  387. strb.AppendFormat(" 获得金币<color=red>{0}</color>", ManaData.Person*ManaData.CoinPerson*ManaData.CircleTime*NewCoinOnceBuff);
  388. }
  389. if (Math.Abs(DiamondOnce) > 0.0005f)
  390. {
  391. strb.AppendFormat(" 获得钻石<color=red>{0}</color>", DiamondOnce);
  392. }
  393. if (Math.Abs(NewDuration) > 0.0005f)
  394. {
  395. strb.AppendFormat(" 持续时间<color=red>{0}</color>秒", NewDuration);
  396. }
  397. else
  398. {
  399. strb.Append(" <color=red>永久有效</color>");
  400. }
  401. ManaDebug.Log(strb.ToString());
  402. #endregion
  403. }
  404. private void RegularBuy()
  405. {
  406. if (ManaData.Connect == false)
  407. {
  408. ManaReso.Get("Fg_Reconnect").TweenForCG();
  409. return;
  410. }
  411. if (ManaData.Pay(UseAmt, BuyCur))
  412. {
  413. ManaData.Skill++;
  414. UseTimer = NewDuration;
  415. ManaData.UseList.Add(this);
  416. if (Math.Abs(Duration) < 0.0005f)
  417. {
  418. BarStatus = SkillStatus.Cool;
  419. }
  420. else
  421. {
  422. BarStatus = SkillStatus.Use;
  423. BarLab.color = Color.blue;
  424. }
  425. UseConti();
  426. UseImmed();
  427. #region 调试输出
  428. StringBuilder strb = new StringBuilder();
  429. strb.AppendFormat("使用技能 : <color=red>{0}</color>", Name);
  430. if (Math.Abs(NewPlus) > 0.0005f)
  431. {
  432. strb.AppendFormat(" 收入加成<color=red>+{0}%</color>", NewPlus * 100);
  433. }
  434. if (Math.Abs(NewPerson) > 0.0005f)
  435. {
  436. strb.AppendFormat(" 参观人次<color=red>+{0}</color>", NewPerson);
  437. }
  438. if (Math.Abs(NewPersonBuff) > 0.0005f)
  439. {
  440. strb.AppendFormat(" 参观人次<color=red>+{0}%</color>", NewPersonBuff * 100);
  441. }
  442. if (Math.Abs(NewCoinPerson) > 0.0005f)
  443. {
  444. strb.AppendFormat(" 每次金币<color=red>+{0}</color>", NewCoinPerson);
  445. }
  446. if (Math.Abs(NewSkillCD) > 0.0005f)
  447. {
  448. strb.AppendFormat(" 减少冷却<color=red>{0}</color>", NewSkillCD);
  449. }
  450. if (Math.Abs(NewSkillCdBuff) > 0.0005f)
  451. {
  452. strb.AppendFormat(" 减少冷却<color=red>{0}%</color>", NewSkillCdBuff * 100);
  453. }
  454. if (Math.Abs(NewCoinOnce) > 0.0005f)
  455. {
  456. strb.AppendFormat(" 获得金币<color=red>{0}</color>", NewCoinOnce);
  457. }
  458. if (Math.Abs(NewCoinOnceBuff) > 0.0005f)
  459. {
  460. strb.AppendFormat(" 获得金币<color=red>{0}</color>", ManaData.Person * ManaData.CoinPerson * ManaData.CircleTime * NewCoinOnceBuff);
  461. }
  462. if (Math.Abs(DiamondOnce) > 0.0005f)
  463. {
  464. strb.AppendFormat(" 获得钻石<color=red>{0}</color>", DiamondOnce);
  465. }
  466. if (Math.Abs(NewDuration) > 0.0005f)
  467. {
  468. strb.AppendFormat(" 持续时间<color=red>{0}</color>秒", NewDuration);
  469. }
  470. else
  471. {
  472. strb.Append(" <color=red>永久有效</color>");
  473. }
  474. ManaDebug.Log(strb.ToString());
  475. #endregion
  476. }
  477. }
  478. private void TutorialUpgrade()
  479. {
  480. if (Level == 0)
  481. {
  482. BarStatus = SkillStatus.Buy;
  483. BarBk1.material = null;
  484. return;
  485. }
  486. Level++;
  487. if (BarStatus == SkillStatus.Use)
  488. {
  489. AnnulConti();
  490. }
  491. NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString());
  492. UpgradeValue(ref NewPlus, Plus, UpgradePlus, 1);
  493. UpgradeValue(ref NewSkillCdBuff, UpgradeCD, 1);
  494. UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, 1);
  495. UpgradeValue(ref NewCoinOnceBuff, UpgradeCoinOnce, 1);
  496. UpgradeValue(ref NewPerson, Person, UpgradePerson, 1);
  497. UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, 1);
  498. UpgradeValue(ref NewDuration, Duration, UpgradeDuration, 1);
  499. UpgradeValue(ref NewCoinOnce, CoinOnce, UpgradeCoinOnce, 1);
  500. UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, 1);
  501. ManaText.Add(ItemTit, new LanStr("SkillName", _Name), " ", Level.ToString());
  502. ItemLab.text = Description(0);
  503. ManaReso.SetText("Fe_Lab0", Description(0));
  504. ManaReso.SetText("Fe_Lab1", Description(1));
  505. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab2"), ImageParse(UpgradeCur), NewUpgradeAmt));
  506. ManaDebug.Log(string.Format("<color=red>{0}</color> 升级 : {1}", Name, Level));
  507. if (BarStatus == SkillStatus.Use)
  508. {
  509. UseConti();
  510. }
  511. }
  512. private void RegularUpgrade()
  513. {
  514. if (ManaData.Pay(NewUpgradeAmt, UpgradeCur))
  515. {
  516. if (Level == 0)
  517. {
  518. BarStatus = SkillStatus.Buy;
  519. BarBk1.material = null;
  520. return;
  521. }
  522. Level++;
  523. if (BarStatus == SkillStatus.Use)
  524. {
  525. AnnulConti();
  526. }
  527. NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString());
  528. UpgradeValue(ref NewPlus, Plus, UpgradePlus, 1);
  529. UpgradeValue(ref NewSkillCdBuff, UpgradeCD, 1);
  530. UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, 1);
  531. UpgradeValue(ref NewCoinOnceBuff, UpgradeCoinOnce, 1);
  532. UpgradeValue(ref NewPerson, Person, UpgradePerson, 1);
  533. UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, 1);
  534. UpgradeValue(ref NewDuration, Duration, UpgradeDuration, 1);
  535. UpgradeValue(ref NewCoinOnce, CoinOnce, UpgradeCoinOnce, 1);
  536. UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, 1);
  537. ManaText.Add(ItemTit, new LanStr("SkillName", _Name), " ", Level.ToString());
  538. ItemLab.text = Description(0);
  539. ManaReso.SetText("Fe_Lab0", Description(0));
  540. ManaReso.SetText("Fe_Lab1", Description(1));
  541. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab2"), ImageParse(UpgradeCur), NewUpgradeAmt));
  542. ManaDebug.Log(string.Format("<color=red>{0}</color> 升级 : {1}", Name, Level));
  543. if (BarStatus == SkillStatus.Use)
  544. {
  545. UseConti();
  546. }
  547. }
  548. }
  549. }