BigSkill.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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 (Tab != SkillTab.Null) //有技能条
  33. {
  34. #region MyRegion
  35. if (ItemStatus == SkillStatus.Upgrade) //可以使用
  36. {
  37. BarBk0.SetActive(false);
  38. BarBk1.SetActive(true);
  39. BarBtn.interactable = true;
  40. BarLab.text = "";
  41. }
  42. else if (ItemStatus == SkillStatus.Buy) //需要购买
  43. {
  44. BarBk0.SetActive(false);
  45. BarBk1.SetActive(true);
  46. BarBtn.interactable = true;
  47. BarLab.text = "";
  48. }
  49. else //未解锁
  50. {
  51. BarBk0.SetActive(false);
  52. BarBk1.SetActive(true);
  53. BarBtn.interactable = false;
  54. BarLab.text = "";
  55. BarBk1.material = ManaReso.Load<Material>("Gray", Folder.Shader);
  56. }
  57. #endregion
  58. }
  59. else //没有技能条
  60. {
  61. #region MyRegion
  62. BarBk0.SetActive(false);
  63. BarBk1.SetActive(true);
  64. BarBtn.interactable = true;
  65. BarLab.text = "";
  66. #endregion
  67. }
  68. }
  69. else if (_BarStatus == SkillStatus.Use)
  70. {
  71. ManaData.UsingList.Add(this);
  72. }
  73. else
  74. {
  75. throw new Exception();
  76. }
  77. }
  78. }
  79. public new SkillStatus ItemStatus
  80. {
  81. get { return _ItemStatus; }
  82. set
  83. {
  84. _ItemStatus = value;
  85. if (Tab == SkillTab.Null) //该技能不生成技能条
  86. {
  87. return;
  88. }
  89. if (_ItemStatus == SkillStatus.Lock)
  90. {
  91. ItemBtnLab.text = string.Format("提前解锁\n等级{0}", UnlockLv);
  92. }
  93. else if (_ItemStatus == SkillStatus.UnLock)
  94. {
  95. ItemBtnLab.text = string.Format("解锁");
  96. }
  97. else if (_ItemStatus == SkillStatus.Upgrade)
  98. {
  99. ItemBtnLab.text = string.Format("升级");
  100. BarStatus = SkillStatus.Buy;
  101. }
  102. else
  103. {
  104. throw new Exception(_ItemStatus.ToString());
  105. }
  106. }
  107. }
  108. public SkillStatus _BarStatus;
  109. #endregion
  110. public BigSkill(XmlAttributeCollection attributes) : base(attributes)
  111. {
  112. SkillIndex = IntParse(attributes[4].Value);
  113. SkillType = SkillType.BigSkill;
  114. }
  115. public override bool DoCool()
  116. {
  117. CoolTimer -= Time.deltaTime;
  118. TimeSpan timeSpan = new TimeSpan(0, 0, 0, (int)CoolTimer);
  119. BarLab.text = string.Format("{0} : {1}", timeSpan.Minutes, timeSpan.Seconds);
  120. BarBk0.fillAmount = (float)CoolTimer / CD;
  121. if (CoolTimer <= 0)
  122. {
  123. BarStatus = SkillStatus.Buy;
  124. ManaData.CoolList.Remove(this);
  125. return true;
  126. }
  127. else
  128. {
  129. return false;
  130. }
  131. }
  132. public override void RegistValue(double elapse, List<List<SkillRoot>> ffList)
  133. {
  134. BarBtn.onClick.AddListener(Use);
  135. BarBk1.sprite = ManaReso.Load<Sprite>(Icon + "副", Folder.Skill);
  136. NewPlus = Plus;
  137. NewPerson = Person;
  138. NewSkillCD = SkillCD;
  139. NewDuration = Duration;
  140. NewCoinOnce = CoinOnce;
  141. NewSkillCdBuff = SkillCdBuff;
  142. NewPersonBuff = PersonBuff;
  143. NewCoinPerson = CoinPerson;
  144. NewUpgradeAmt = UpgradeAmt;
  145. NewCoinOnceBuff = CoinOnceBuff;
  146. if (!string.IsNullOrEmpty(UpgradeFml))
  147. {
  148. for (int i = 0; i < Level; i++)
  149. {
  150. NewUpgradeAmt = FmlParse(UpgradeFml, NewUpgradeAmt);
  151. }
  152. }
  153. UpgradeValue(ref NewPlus, Plus, UpgradePlus, Level);
  154. UpgradeValue(ref NewSkillCdBuff, UpgradeCD, Level);
  155. UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, Level);
  156. UpgradeValue(ref NewCoinOnceBuff, UpgradeCoinOnce, Level);
  157. UpgradeValue(ref NewPerson, Person, UpgradePerson, Level);
  158. UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, Level);
  159. UpgradeValue(ref NewDuration, Duration, UpgradeDuration, Level);
  160. UpgradeValue(ref NewCoinOnce, CoinOnce, UpgradeCoinOnce, Level);
  161. UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, Level);
  162. if (Tab != SkillTab.Null)
  163. {
  164. ItemTit.text = Name;
  165. ItemLab.text = GetDescription(0);
  166. ItemBtn.onClick.AddListener(OnClick);
  167. }
  168. if (_ItemStatus == SkillStatus.Lock || _ItemStatus == SkillStatus.UnLock)
  169. {
  170. BarBk1.material = ManaReso.Load<Material>("Gray", Folder.Shader);
  171. }
  172. else
  173. {
  174. BarBk1.material = null;
  175. }
  176. if (_ItemStatus == SkillStatus.Upgrade)
  177. {
  178. ManaLog.Log(string.Format("初始化<color=red>{0}</color> 等级 : {1}", Name, Level));
  179. ShowSkillBar();
  180. }
  181. if (_BarStatus == SkillStatus.Use)
  182. {
  183. Effect();
  184. if (UsingTimer < elapse)
  185. {
  186. if (ffList.Count > 0)
  187. {
  188. if (UsingTimer < ManaData.CircleTimer)
  189. {
  190. ffList[0].UniqueAdd(this);
  191. }
  192. else
  193. {
  194. int ffCircle = 1 + Mathf.FloorToInt((float)((UsingTimer - ManaData.CircleTimer) / ManaData.CircleTime));
  195. ffList[ffCircle].UniqueAdd(this);
  196. }
  197. }
  198. }
  199. else
  200. {
  201. ManaLog.Log(string.Format("初始化<color=red>{0}</color> 等级 : {1}", Name, Level));
  202. UsingTimer -= elapse;
  203. BarLab.color = new Color(38 / 255f, 155 / 255f, 1, 1);
  204. }
  205. }
  206. else if (_BarStatus == SkillStatus.Cool)
  207. {
  208. CoolTimer -= elapse;
  209. }
  210. ItemStatus = ItemStatus;
  211. BarStatus = BarStatus;
  212. }
  213. public override void ReceiveCool(float amt, bool isCurrent, bool isBuff)
  214. {
  215. if (!ReduceCD)
  216. {
  217. return;
  218. }
  219. if (isCurrent) //减少当前值
  220. {
  221. if (isBuff) //按比例减少
  222. {
  223. CoolTimer -= CD * amt;
  224. }
  225. else //按数值减少
  226. {
  227. CoolTimer -= amt;
  228. }
  229. }
  230. else //减少最大值
  231. {
  232. if (isBuff) //按比例减少
  233. {
  234. CdBuff -= amt;
  235. }
  236. else //按数值减少
  237. {
  238. CD -= amt;
  239. }
  240. }
  241. }
  242. private void ShowSkillBar()
  243. {
  244. if (!ManaData.SkillBar)
  245. {
  246. ManaReso.Get("Fa_Scrr").TweenForRect();
  247. ManaData.SkillBar = true;
  248. if (ManaReso.Get("Fa_Garden").gameObject.activeSelf)
  249. {
  250. ManaReso.SetActive("Ff_SkillBar", true);
  251. }
  252. }
  253. }
  254. public override void RegistReference()
  255. {
  256. BarLab = ManaReso.Get<Text>(string.Format("F_SkillLab{0}", SkillIndex - 1));
  257. BarBk0 = ManaReso.Get<Image>(string.Format("F_SkillBk{0}0", SkillIndex - 1));
  258. BarBk1 = ManaReso.Get<Image>(string.Format("F_SkillBk{0}1", SkillIndex - 1));
  259. BarBtn = BarBk1.GetComponent<Button>();
  260. }
  261. protected override void Use()
  262. {
  263. if (ManaData.Connect == false)
  264. {
  265. ManaReso.Get("Fg_Reconnect").TweenForCG();
  266. return;
  267. }
  268. if (BarStatus == SkillStatus.Use)
  269. {
  270. return;
  271. }
  272. if (ManaData.Pay(UseAmt, UseCur))
  273. {
  274. CoolTimer = CD * (1 + CdBuff);
  275. UsingTimer = NewDuration;
  276. if (Math.Abs(Duration) < 0.0005f)
  277. {
  278. BarStatus = SkillStatus.Cool;
  279. }
  280. else
  281. {
  282. BarStatus = SkillStatus.Use;
  283. BarLab.color = new Color(38/255f, 155/255f, 1, 1);
  284. }
  285. Effect();
  286. EffectOnce();
  287. #region 调试输出
  288. StringBuilder strb = new StringBuilder();
  289. strb.AppendFormat("使用技能 : <color=red>{0}</color>", Name);
  290. if (Math.Abs(NewPlus) > 0.0005f)
  291. {
  292. strb.AppendFormat(" 收入加成<color=red>+{0}%</color>", NewPlus * 100);
  293. }
  294. if (Math.Abs(NewPerson) > 0.0005f)
  295. {
  296. strb.AppendFormat(" 参观人次<color=red>+{0}</color>", NewPerson);
  297. }
  298. if (Math.Abs(NewPersonBuff) > 0.0005f)
  299. {
  300. strb.AppendFormat(" 参观人次<color=red>+{0}%</color>", NewPersonBuff * 100);
  301. }
  302. if (Math.Abs(NewCoinPerson) > 0.0005f)
  303. {
  304. strb.AppendFormat(" 每次金币<color=red>+{0}</color>", NewCoinPerson);
  305. }
  306. if (Math.Abs(NewSkillCD) > 0.0005f)
  307. {
  308. strb.AppendFormat(" 减少冷却<color=red>{0}</color>", NewSkillCD);
  309. }
  310. if (Math.Abs(NewSkillCdBuff) > 0.0005f)
  311. {
  312. strb.AppendFormat(" 减少冷却<color=red>{0}%</color>", NewSkillCdBuff * 100);
  313. }
  314. if (Math.Abs(NewCoinOnce) > 0.0005f)
  315. {
  316. strb.AppendFormat(" 获得金币<color=red>{0}</color>", NewCoinOnce);
  317. }
  318. if (Math.Abs(NewCoinOnceBuff) > 0.0005f)
  319. {
  320. strb.AppendFormat(" 获得金币<color=red>{0}</color>", ManaData.Person * ManaData.CoinPerson * ManaData.CircleTime * NewCoinOnceBuff);
  321. }
  322. if (Math.Abs(DiamondOnce) > 0.0005f)
  323. {
  324. strb.AppendFormat(" 获得钻石<color=red>{0}</color>", DiamondOnce);
  325. }
  326. if (Math.Abs(NewDuration) > 0.0005f)
  327. {
  328. strb.AppendFormat(" 持续时间<color=red>{0}</color>秒", NewDuration);
  329. }
  330. else
  331. {
  332. strb.Append(" <color=red>永久有效</color>");
  333. }
  334. ManaLog.Log(strb.ToString());
  335. #endregion
  336. }
  337. }
  338. protected override void Unlock()
  339. {
  340. if (ManaData.Pay(UnlockAmt, UnlockCur))
  341. {
  342. ShowSkillBar();
  343. BarStatus = SkillStatus.Buy;
  344. if (Tab != SkillTab.Null) //该技能有技能条
  345. {
  346. if (UpgradeCur != Current.Free) //升级类型
  347. {
  348. ItemStatus = SkillStatus.Upgrade;
  349. }
  350. else
  351. {
  352. throw new Exception();
  353. }
  354. }
  355. else
  356. {
  357. ItemStatus = SkillStatus.Buy;
  358. }
  359. BarBk1.material = null;
  360. ManaLog.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
  361. }
  362. }
  363. protected override void UnlockAhead()
  364. {
  365. if (ItemStatus != SkillStatus.Lock)
  366. {
  367. ManaLog.Log("您并不需要提前解锁");
  368. return;
  369. }
  370. if (ManaData.Pay(UnlockAheadAmt, UnlockAheadCur))
  371. {
  372. BarStatus = SkillStatus.Buy;
  373. ManaReso.Get("Fe_Info").TweenBacCG();
  374. if (UpgradeCur != Current.Free) //升级类型
  375. {
  376. ItemStatus = SkillStatus.Upgrade;
  377. }
  378. else
  379. {
  380. throw new Exception();
  381. }
  382. ManaLog.Log(string.Format("技能<color=red>{0}</color>已解锁", Name));
  383. }
  384. }
  385. protected override void Upgrade()
  386. {
  387. if (ManaData.Pay(NewUpgradeAmt, UpgradeCur))
  388. {
  389. Level++;
  390. NewUpgradeAmt = FmlParse(UpgradeFml, NewUpgradeAmt);
  391. UpgradeValue(ref NewPlus, Plus, UpgradePlus, 1);
  392. UpgradeValue(ref NewSkillCdBuff, UpgradeCD, 1);
  393. UpgradeValue(ref NewPersonBuff, PersonBuff, UpgradePerson, 1);
  394. UpgradeValue(ref NewCoinOnceBuff, UpgradeCoinOnce, 1);
  395. UpgradeValue(ref NewPerson, Person, UpgradePerson, 1);
  396. UpgradeValue(ref NewSkillCD, SkillCD, UpgradeCD, 1);
  397. UpgradeValue(ref NewDuration, Duration, UpgradeDuration, 1);
  398. UpgradeValue(ref NewCoinOnce, CoinOnce, UpgradeCoinOnce, 1);
  399. UpgradeValue(ref NewCoinPerson, CoinPerson, UpgradePlus, 1);
  400. ItemLab.text = GetDescription(0);
  401. ManaReso.SetText("Fe_Lab0", GetDescription(0));
  402. ManaReso.SetText("Fe_Lab1", GetDescription(1));
  403. ManaReso.SetText("Fe_BtnLab", string.Format("升级({0}{1:0})", UpgradeCur, NewUpgradeAmt));
  404. ManaLog.Log(string.Format("<color=red>{0}</color> 升级 : {1}", Name, Level));
  405. if (BarStatus == SkillStatus.Use) //更新技能效果
  406. {
  407. Annul();
  408. Effect();
  409. }
  410. }
  411. }
  412. public override void Annul() //注销技能
  413. {
  414. BarLab.color = new Color(1, 1, 1, 1);
  415. BarStatus = SkillStatus.Cool;
  416. ManaData.SkillPlus -= NewPlus;
  417. ManaData.SkillPerson -= NewPerson;
  418. ManaData.SkillPersonBuff -= NewPersonBuff;
  419. ManaData.SkillCoinPerson -= NewCoinPerson;
  420. if (Math.Abs(NewSkillCD) > 0.0005f)
  421. {
  422. for (int i = 0; i < ManaData.SkillList.Count; i++)
  423. {
  424. ManaData.SkillList[i].ReceiveCool(-NewSkillCD, true, false);
  425. }
  426. }
  427. if (Math.Abs(NewSkillCdBuff) > 0.0005f)
  428. {
  429. for (int i = 0; i < ManaData.SkillList.Count; i++)
  430. {
  431. ManaData.SkillList[i].ReceiveCool(-NewSkillCdBuff, true, true);
  432. }
  433. }
  434. ManaLog.Log(string.Format("技能结束 <color=red>{0}</color>", Name));
  435. }
  436. public override bool DoUse()
  437. {
  438. UsingTimer -= Time.deltaTime;
  439. BarLab.text = UsingTimer.ToString("0.0");
  440. if (UsingTimer <= 0)
  441. {
  442. Annul();
  443. ManaData.UsingList.Remove(this);
  444. return true;
  445. }
  446. else
  447. {
  448. return false;
  449. }
  450. }
  451. }