BigSkill.cs 17 KB

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