BigSkill.cs 17 KB

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