BigSkill.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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 (ManaData.Connect == false)
  288. {
  289. ManaReso.Get("Fg_Reconnect").TweenForCG();
  290. return;
  291. }
  292. if (ManaData.Pay(UseAmt, BuyCur))
  293. {
  294. ManaData.Skill++;
  295. UseTimer = NewDuration;
  296. ManaData.UseList.Add(this);
  297. if (Math.Abs(Duration) < 0.0005f)
  298. {
  299. BarStatus = SkillStatus.Cool;
  300. }
  301. else
  302. {
  303. BarStatus = SkillStatus.Use;
  304. BarLab.color = Color.blue;
  305. }
  306. UseConti();
  307. UseImmed();
  308. #region 调试输出
  309. StringBuilder strb = new StringBuilder();
  310. strb.AppendFormat("使用技能 : <color=red>{0}</color>", Name);
  311. if (Math.Abs(NewPlus) > 0.0005f)
  312. {
  313. strb.AppendFormat(" 收入加成<color=red>+{0}%</color>", NewPlus * 100);
  314. }
  315. if (Math.Abs(NewPerson) > 0.0005f)
  316. {
  317. strb.AppendFormat(" 参观人次<color=red>+{0}</color>", NewPerson);
  318. }
  319. if (Math.Abs(NewPersonBuff) > 0.0005f)
  320. {
  321. strb.AppendFormat(" 参观人次<color=red>+{0}%</color>", NewPersonBuff * 100);
  322. }
  323. if (Math.Abs(NewCoinPerson) > 0.0005f)
  324. {
  325. strb.AppendFormat(" 每次金币<color=red>+{0}</color>", NewCoinPerson);
  326. }
  327. if (Math.Abs(NewSkillCD) > 0.0005f)
  328. {
  329. strb.AppendFormat(" 减少冷却<color=red>{0}</color>", NewSkillCD);
  330. }
  331. if (Math.Abs(NewSkillCdBuff) > 0.0005f)
  332. {
  333. strb.AppendFormat(" 减少冷却<color=red>{0}%</color>", NewSkillCdBuff * 100);
  334. }
  335. if (Math.Abs(NewCoinOnce) > 0.0005f)
  336. {
  337. strb.AppendFormat(" 获得金币<color=red>{0}</color>", NewCoinOnce);
  338. }
  339. if (Math.Abs(NewCoinOnceBuff) > 0.0005f)
  340. {
  341. strb.AppendFormat(" 获得金币<color=red>{0}</color>", ManaData.Person * ManaData.CoinPerson * ManaData.CircleTime * NewCoinOnceBuff);
  342. }
  343. if (Math.Abs(DiamondOnce) > 0.0005f)
  344. {
  345. strb.AppendFormat(" 获得钻石<color=red>{0}</color>", DiamondOnce);
  346. }
  347. if (Math.Abs(NewDuration) > 0.0005f)
  348. {
  349. strb.AppendFormat(" 持续时间<color=red>{0}</color>秒", NewDuration);
  350. }
  351. else
  352. {
  353. strb.Append(" <color=red>永久有效</color>");
  354. }
  355. ManaDebug.Log(strb.ToString());
  356. #endregion
  357. }
  358. }
  359. protected override void Unlock()
  360. {
  361. if (ManaData.Pay(UnlockAmt, UnlockCur))
  362. {
  363. ShowSkillBar();
  364. BarBk1.material = null;
  365. ItemStatus = SkillStatus.Upgrade;
  366. BarStatus = SkillStatus.Buy;
  367. if (SkillTab != SkillTab.Null)
  368. {
  369. ItemStatus = SkillStatus.Upgrade;
  370. }
  371. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
  372. }
  373. }
  374. protected override void Upgrade()
  375. {
  376. if (ManaData.Pay(NewUpgradeAmt, UpgradeCur))
  377. {
  378. Level++;
  379. if (BarStatus == SkillStatus.Use)
  380. {
  381. Annul();
  382. }
  383. NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString());
  384. UpgradeValue(ref NewPlus, Plus, UpgradePlus, 1);
  385. UpgradeValue(ref NewSkillCdBuff, UpgradeCD, 1);
  386. UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, 1);
  387. UpgradeValue(ref NewCoinOnceBuff, UpgradeCoinOnce, 1);
  388. UpgradeValue(ref NewPerson, Person, UpgradePerson, 1);
  389. UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, 1);
  390. UpgradeValue(ref NewDuration, Duration, UpgradeDuration, 1);
  391. UpgradeValue(ref NewCoinOnce, CoinOnce, UpgradeCoinOnce, 1);
  392. UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, 1);
  393. ManaText.Add(ItemTit, new LanStr("SkillName", _Name), " ", (Level + 1).ToString());
  394. ItemLab.text = Description(0);
  395. ManaReso.SetText("Fe_Lab0", Description(0));
  396. ManaReso.SetText("Fe_Lab1", Description(1));
  397. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab2"), UpgradeCur, NewUpgradeAmt));
  398. ManaDebug.Log(string.Format("<color=red>{0}</color> 升级 : {1}", Name, Level));
  399. if (BarStatus == SkillStatus.Use)
  400. {
  401. UseConti();
  402. }
  403. }
  404. }
  405. protected override void UnlockAhead()
  406. {
  407. if (ItemStatus != SkillStatus.Lock)
  408. {
  409. ManaDebug.Log("您并不需要提前解锁");
  410. return;
  411. }
  412. if (ManaData.Pay(UnlockAheadAmt, UnlockAheadCur))
  413. {
  414. ShowSkillBar();
  415. BarBk1.material = null;
  416. ItemStatus = SkillStatus.Upgrade;
  417. BarStatus = SkillStatus.Buy;
  418. ManaReso.Get("Fe_Info").TweenBacCG();
  419. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
  420. }
  421. }
  422. }