BigSkill.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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. ItemBtnLab.text = string.Format("{0}\n{1}{2}", Language.GetStr("UI", "Fe_BtnLab0"), Language.GetStr("UI", "Fe_BtnLab4"), UnlockLv);
  70. }
  71. else if (_ItemStatus == SkillStatus.UnLock)
  72. {
  73. ItemBtnLab.text = string.Format(Language.GetStr("UI", "Fe_BtnLab1"));
  74. }
  75. else if (_ItemStatus == SkillStatus.Upgrade)
  76. {
  77. ItemTit.text = Name + " " + (Level + 1);
  78. ItemBtnLab.text = string.Format(Language.GetStr("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 attributes) : base(attributes)
  89. {
  90. SkillIndex = IntParse(attributes[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)
  152. {
  153. BarBtn.onClick.AddListener(Buy);
  154. BarBk1.sprite = ManaReso.Load<Sprite>(Icon + "副", Folder.Skill);
  155. NewPlus = Plus;
  156. NewPerson = Person;
  157. NewSkillCD = SkillCD;
  158. NewDuration = Duration;
  159. NewCoinOnce = CoinOnce;
  160. NewSkillCdBuff = SkillCdBuff;
  161. NewPersonBuff = PersonBuff;
  162. NewCoinPerson = CoinPerson;
  163. NewUpgradeAmt = UpgradeAmt;
  164. NewCoinOnceBuff = CoinOnceBuff;
  165. if (SkillTab == SkillTab.Null)
  166. {
  167. BarBk1.material = null;
  168. }
  169. else
  170. {
  171. ItemTit.text = Name;
  172. ItemLab.text = Description(0);
  173. ItemBtn.onClick.AddListener(OnClick);
  174. for (int i = 0; i < Level; i++)
  175. {
  176. NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString());
  177. }
  178. UpgradeValue(ref NewPlus, Plus, UpgradePlus, Level);
  179. UpgradeValue(ref NewSkillCdBuff, UpgradeCD, Level);
  180. UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, Level);
  181. UpgradeValue(ref NewCoinOnceBuff, UpgradeCoinOnce, Level);
  182. UpgradeValue(ref NewPerson, Person, UpgradePerson, Level);
  183. UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, Level);
  184. UpgradeValue(ref NewDuration, Duration, UpgradeDuration, Level);
  185. UpgradeValue(ref NewCoinOnce, CoinOnce, UpgradeCoinOnce, Level);
  186. UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, Level);
  187. if (_ItemStatus == SkillStatus.Upgrade)
  188. {
  189. BarBk1.material = null;
  190. ShowSkillBar();
  191. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁 等级 : {1}", Name, Level));
  192. }
  193. if (_BarStatus == SkillStatus.Use)
  194. {
  195. UseConti();
  196. if (UseTimer < elapse)
  197. {
  198. if (ffList.Count > 0)
  199. {
  200. if (UseTimer < ManaData.CircleTimer)
  201. {
  202. ffList[0].UniqueAdd(this);
  203. }
  204. else
  205. {
  206. int ffCircle = 1 + Mathf.FloorToInt(((UseTimer - ManaData.CircleTimer) / ManaData.CircleTime));
  207. ffList[ffCircle].UniqueAdd(this);
  208. }
  209. }
  210. }
  211. else
  212. {
  213. UseTimer -= elapse;
  214. BarLab.color = Color.blue;
  215. }
  216. }
  217. else if (_BarStatus == SkillStatus.Cool)
  218. {
  219. CoolTimer -= elapse;
  220. }
  221. }
  222. ItemStatus = ItemStatus;
  223. BarStatus = BarStatus;
  224. }
  225. public override void ReceiveCool(float amt, bool current, bool buff)
  226. {
  227. if (!ReduceCD)
  228. {
  229. return;
  230. }
  231. if (current)
  232. {
  233. if (BarStatus != SkillStatus.Cool)
  234. {
  235. return;
  236. }
  237. if (buff)
  238. {
  239. CoolTimer -= CD * amt;
  240. }
  241. else
  242. {
  243. CoolTimer -= amt;
  244. }
  245. }
  246. else
  247. {
  248. if (buff)
  249. {
  250. CdBuff -= amt;
  251. }
  252. else
  253. {
  254. CD -= amt;
  255. }
  256. }
  257. }
  258. public override void RegistReference()
  259. {
  260. base.RegistReference();
  261. BarLab = ManaReso.Get<Text>(string.Format("F_SkillLab{0}", SkillIndex - 1));
  262. BarBk0 = ManaReso.Get<Image>(string.Format("F_SkillBk{0}0", SkillIndex - 1));
  263. BarBk1 = ManaReso.Get<Image>(string.Format("F_SkillBk{0}1", SkillIndex - 1));
  264. BarBtn = BarBk1.GetComponent<Button>();
  265. }
  266. private void ShowSkillBar()
  267. {
  268. if (!ManaData.SkillBar)
  269. {
  270. ManaData.SkillBar = true;
  271. ManaReso.Get("Fa_Scrr").TweenForRect();
  272. if (ManaReso.Get("Fa_Garden").gameObject.activeSelf)
  273. {
  274. ManaReso.SetActive("Ff_SkillBar", true);
  275. }
  276. }
  277. }
  278. protected override void Buy()
  279. {
  280. if (ManaData.Connect == false)
  281. {
  282. ManaReso.Get("Fg_Reconnect").TweenForCG();
  283. return;
  284. }
  285. if (ManaData.Pay(UseAmt, BuyCur))
  286. {
  287. UseTimer = NewDuration;
  288. ManaData.UseList.Add(this);
  289. if (Math.Abs(Duration) < 0.0005f)
  290. {
  291. BarStatus = SkillStatus.Cool;
  292. }
  293. else
  294. {
  295. BarStatus = SkillStatus.Use;
  296. BarLab.color = Color.blue;
  297. }
  298. UseConti();
  299. UseImmed();
  300. #region 调试输出
  301. StringBuilder strb = new StringBuilder();
  302. strb.AppendFormat("使用技能 : <color=red>{0}</color>", Name);
  303. if (Math.Abs(NewPlus) > 0.0005f)
  304. {
  305. strb.AppendFormat(" 收入加成<color=red>+{0}%</color>", NewPlus * 100);
  306. }
  307. if (Math.Abs(NewPerson) > 0.0005f)
  308. {
  309. strb.AppendFormat(" 参观人次<color=red>+{0}</color>", NewPerson);
  310. }
  311. if (Math.Abs(NewPersonBuff) > 0.0005f)
  312. {
  313. strb.AppendFormat(" 参观人次<color=red>+{0}%</color>", NewPersonBuff * 100);
  314. }
  315. if (Math.Abs(NewCoinPerson) > 0.0005f)
  316. {
  317. strb.AppendFormat(" 每次金币<color=red>+{0}</color>", NewCoinPerson);
  318. }
  319. if (Math.Abs(NewSkillCD) > 0.0005f)
  320. {
  321. strb.AppendFormat(" 减少冷却<color=red>{0}</color>", NewSkillCD);
  322. }
  323. if (Math.Abs(NewSkillCdBuff) > 0.0005f)
  324. {
  325. strb.AppendFormat(" 减少冷却<color=red>{0}%</color>", NewSkillCdBuff * 100);
  326. }
  327. if (Math.Abs(NewCoinOnce) > 0.0005f)
  328. {
  329. strb.AppendFormat(" 获得金币<color=red>{0}</color>", NewCoinOnce);
  330. }
  331. if (Math.Abs(NewCoinOnceBuff) > 0.0005f)
  332. {
  333. strb.AppendFormat(" 获得金币<color=red>{0}</color>", ManaData.Person * ManaData.CoinPerson * ManaData.CircleTime * NewCoinOnceBuff);
  334. }
  335. if (Math.Abs(DiamondOnce) > 0.0005f)
  336. {
  337. strb.AppendFormat(" 获得钻石<color=red>{0}</color>", DiamondOnce);
  338. }
  339. if (Math.Abs(NewDuration) > 0.0005f)
  340. {
  341. strb.AppendFormat(" 持续时间<color=red>{0}</color>秒", NewDuration);
  342. }
  343. else
  344. {
  345. strb.Append(" <color=red>永久有效</color>");
  346. }
  347. ManaDebug.Log(strb.ToString());
  348. #endregion
  349. }
  350. }
  351. protected override void Unlock()
  352. {
  353. if (ManaData.Pay(UnlockAmt, UnlockCur))
  354. {
  355. ShowSkillBar();
  356. BarBk1.material = null;
  357. ItemStatus = SkillStatus.Upgrade;
  358. BarStatus = SkillStatus.Buy;
  359. if (SkillTab != SkillTab.Null)
  360. {
  361. ItemStatus = SkillStatus.Upgrade;
  362. }
  363. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
  364. }
  365. }
  366. protected override void Upgrade()
  367. {
  368. if (ManaData.Pay(NewUpgradeAmt, UpgradeCur))
  369. {
  370. Level++;
  371. if (BarStatus == SkillStatus.Use)
  372. {
  373. Annul();
  374. }
  375. NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString());
  376. UpgradeValue(ref NewPlus, Plus, UpgradePlus, 1);
  377. UpgradeValue(ref NewSkillCdBuff, UpgradeCD, 1);
  378. UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, 1);
  379. UpgradeValue(ref NewCoinOnceBuff, UpgradeCoinOnce, 1);
  380. UpgradeValue(ref NewPerson, Person, UpgradePerson, 1);
  381. UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, 1);
  382. UpgradeValue(ref NewDuration, Duration, UpgradeDuration, 1);
  383. UpgradeValue(ref NewCoinOnce, CoinOnce, UpgradeCoinOnce, 1);
  384. UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, 1);
  385. ItemTit.text = Name + " " + (Level+1);
  386. ItemLab.text = Description(0);
  387. ManaReso.SetText("Fe_Lab0", Description(0));
  388. ManaReso.SetText("Fe_Lab1", Description(1));
  389. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab2"), UpgradeCur, NewUpgradeAmt));
  390. ManaDebug.Log(string.Format("<color=red>{0}</color> 升级 : {1}", Name, Level));
  391. if (BarStatus == SkillStatus.Use)
  392. {
  393. UseConti();
  394. }
  395. }
  396. }
  397. protected override void UnlockAhead()
  398. {
  399. if (ItemStatus != SkillStatus.Lock)
  400. {
  401. ManaDebug.Log("您并不需要提前解锁");
  402. return;
  403. }
  404. if (ManaData.Pay(UnlockAheadAmt, UnlockAheadCur))
  405. {
  406. ShowSkillBar();
  407. BarBk1.material = null;
  408. ItemStatus = SkillStatus.Upgrade;
  409. BarStatus = SkillStatus.Buy;
  410. ManaReso.Get("Fe_Info").TweenBacCG();
  411. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
  412. }
  413. }
  414. }