BigSkill.cs 14 KB

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