BigSkill.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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>("Gray", 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. ManaData.UseList.Add(this);
  51. }
  52. else
  53. {
  54. throw new Exception();
  55. }
  56. }
  57. }
  58. public new SkillStatus ItemStatus
  59. {
  60. get { return _ItemStatus; }
  61. set
  62. {
  63. _ItemStatus = value;
  64. if (SkillTab == SkillTab.Null)
  65. {
  66. return;
  67. }
  68. if (_ItemStatus == SkillStatus.Lock)
  69. {
  70. ItemBtnLab.text = string.Format("{0}\n{1}{2}", Language.GetStr("UI", "Fe_BtnLab0"), Language.GetStr("UI", "Fe_BtnLab4"), UnlockLv);
  71. }
  72. else if (_ItemStatus == SkillStatus.UnLock)
  73. {
  74. ItemBtnLab.text = string.Format(Language.GetStr("UI", "Fe_BtnLab1"));
  75. }
  76. else if (_ItemStatus == SkillStatus.Upgrade)
  77. {
  78. ItemTit.text = Name + " " + (Level + 1);
  79. ItemBtnLab.text = string.Format(Language.GetStr("UI", "Fe_BtnLab2"));
  80. }
  81. else
  82. {
  83. throw new Exception(_ItemStatus.ToString());
  84. }
  85. }
  86. }
  87. public SkillStatus _BarStatus;
  88. #endregion
  89. public BigSkill(XmlAttributeCollection attributes) : base(attributes)
  90. {
  91. SkillIndex = IntParse(attributes[4].Value);
  92. SkillType = SkillType.BigSkill;
  93. }
  94. public override void Annul()
  95. {
  96. CoolTimer = CD * (1 + CdBuff);
  97. BarLab.color = Color.white;
  98. BarStatus = SkillStatus.Cool;
  99. ManaData.SkillPlus -= NewPlus;
  100. ManaData.SkillPerson -= NewPerson;
  101. ManaData.SkillPersonBuff -= NewPersonBuff;
  102. ManaData.SkillCoinPerson -= NewCoinPerson;
  103. if (Math.Abs(NewSkillCD) > 0.0005f)
  104. {
  105. for (int i = 0; i < ManaData.SkillList.Count; i++)
  106. {
  107. ManaData.SkillList[i].ReceiveCool(-NewSkillCD, true, false);
  108. }
  109. }
  110. if (Math.Abs(NewSkillCdBuff) > 0.0005f)
  111. {
  112. for (int i = 0; i < ManaData.SkillList.Count; i++)
  113. {
  114. ManaData.SkillList[i].ReceiveCool(-NewSkillCdBuff, true, true);
  115. }
  116. }
  117. ManaDebug.Log(string.Format("技能结束 <color=red>{0}</color>", Name));
  118. }
  119. public override bool DoUse()
  120. {
  121. UseTimer -= Time.deltaTime;
  122. BarLab.text = UseTimer.ToString("0.0");
  123. if (UseTimer <= 0)
  124. {
  125. Annul();
  126. ManaData.UseList.Remove(this);
  127. return true;
  128. }
  129. else
  130. {
  131. return false;
  132. }
  133. }
  134. public override bool DoCool()
  135. {
  136. CoolTimer -= Time.deltaTime;
  137. TimeSpan timeSpan = new TimeSpan(0, 0, 0, (int)CoolTimer);
  138. BarLab.text = string.Format("{0} : {1}", timeSpan.Minutes, timeSpan.Seconds);
  139. BarBk0.fillAmount = CoolTimer / CD;
  140. if (CoolTimer <= 0)
  141. {
  142. BarStatus = SkillStatus.Buy;
  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. if (Math.Abs(Duration) < 0.0005f)
  289. {
  290. BarStatus = SkillStatus.Cool;
  291. }
  292. else
  293. {
  294. BarStatus = SkillStatus.Use;
  295. BarLab.color = Color.blue;
  296. }
  297. UseConti();
  298. UseImmed();
  299. #region 调试输出
  300. StringBuilder strb = new StringBuilder();
  301. strb.AppendFormat("使用技能 : <color=red>{0}</color>", Name);
  302. if (Math.Abs(NewPlus) > 0.0005f)
  303. {
  304. strb.AppendFormat(" 收入加成<color=red>+{0}%</color>", NewPlus * 100);
  305. }
  306. if (Math.Abs(NewPerson) > 0.0005f)
  307. {
  308. strb.AppendFormat(" 参观人次<color=red>+{0}</color>", NewPerson);
  309. }
  310. if (Math.Abs(NewPersonBuff) > 0.0005f)
  311. {
  312. strb.AppendFormat(" 参观人次<color=red>+{0}%</color>", NewPersonBuff * 100);
  313. }
  314. if (Math.Abs(NewCoinPerson) > 0.0005f)
  315. {
  316. strb.AppendFormat(" 每次金币<color=red>+{0}</color>", NewCoinPerson);
  317. }
  318. if (Math.Abs(NewSkillCD) > 0.0005f)
  319. {
  320. strb.AppendFormat(" 减少冷却<color=red>{0}</color>", NewSkillCD);
  321. }
  322. if (Math.Abs(NewSkillCdBuff) > 0.0005f)
  323. {
  324. strb.AppendFormat(" 减少冷却<color=red>{0}%</color>", NewSkillCdBuff * 100);
  325. }
  326. if (Math.Abs(NewCoinOnce) > 0.0005f)
  327. {
  328. strb.AppendFormat(" 获得金币<color=red>{0}</color>", NewCoinOnce);
  329. }
  330. if (Math.Abs(NewCoinOnceBuff) > 0.0005f)
  331. {
  332. strb.AppendFormat(" 获得金币<color=red>{0}</color>", ManaData.Person * ManaData.CoinPerson * ManaData.CircleTime * NewCoinOnceBuff);
  333. }
  334. if (Math.Abs(DiamondOnce) > 0.0005f)
  335. {
  336. strb.AppendFormat(" 获得钻石<color=red>{0}</color>", DiamondOnce);
  337. }
  338. if (Math.Abs(NewDuration) > 0.0005f)
  339. {
  340. strb.AppendFormat(" 持续时间<color=red>{0}</color>秒", NewDuration);
  341. }
  342. else
  343. {
  344. strb.Append(" <color=red>永久有效</color>");
  345. }
  346. ManaDebug.Log(strb.ToString());
  347. #endregion
  348. }
  349. }
  350. protected override void Unlock()
  351. {
  352. if (ManaData.Pay(UnlockAmt, UnlockCur))
  353. {
  354. ShowSkillBar();
  355. BarBk1.material = null;
  356. ItemStatus = SkillStatus.Upgrade;
  357. BarStatus = SkillStatus.Buy;
  358. if (SkillTab != SkillTab.Null)
  359. {
  360. ItemStatus = SkillStatus.Upgrade;
  361. }
  362. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
  363. }
  364. }
  365. protected override void Upgrade()
  366. {
  367. if (ManaData.Pay(NewUpgradeAmt, UpgradeCur))
  368. {
  369. Level++;
  370. if (BarStatus == SkillStatus.Use)
  371. {
  372. Annul();
  373. }
  374. NewUpgradeAmt = Auxiliary.FmlParse(UpgradeFml, "a", NewUpgradeAmt.ToString());
  375. UpgradeValue(ref NewPlus, Plus, UpgradePlus, 1);
  376. UpgradeValue(ref NewSkillCdBuff, UpgradeCD, 1);
  377. UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, 1);
  378. UpgradeValue(ref NewCoinOnceBuff, UpgradeCoinOnce, 1);
  379. UpgradeValue(ref NewPerson, Person, UpgradePerson, 1);
  380. UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, 1);
  381. UpgradeValue(ref NewDuration, Duration, UpgradeDuration, 1);
  382. UpgradeValue(ref NewCoinOnce, CoinOnce, UpgradeCoinOnce, 1);
  383. UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, 1);
  384. ItemTit.text = Name + " " + (Level+1);
  385. ItemLab.text = Description(0);
  386. ManaReso.SetText("Fe_Lab0", Description(0));
  387. ManaReso.SetText("Fe_Lab1", Description(1));
  388. ManaReso.SetText("Fe_BtnLab", string.Format("{0}({1}{2:0})", Language.GetStr("UI", "Fe_BtnLab2"), UpgradeCur, NewUpgradeAmt));
  389. ManaDebug.Log(string.Format("<color=red>{0}</color> 升级 : {1}", Name, Level));
  390. if (BarStatus == SkillStatus.Use)
  391. {
  392. UseConti();
  393. }
  394. }
  395. }
  396. protected override void UnlockAhead()
  397. {
  398. if (ItemStatus != SkillStatus.Lock)
  399. {
  400. ManaDebug.Log("您并不需要提前解锁");
  401. return;
  402. }
  403. if (ManaData.Pay(UnlockAheadAmt, UnlockAheadCur))
  404. {
  405. ShowSkillBar();
  406. BarBk1.material = null;
  407. ItemStatus = SkillStatus.Upgrade;
  408. BarStatus = SkillStatus.Buy;
  409. ManaReso.Get("Fe_Info").TweenBacCG();
  410. ManaDebug.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
  411. }
  412. }
  413. }