FighterBuffManager.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. public class FighterBuffManager
  4. {
  5. Fighter mFighter;
  6. readonly List<BattleBuff> mBuffList;
  7. public List<BattleBuff> BuffList { get { return mBuffList; } }
  8. public FighterBuffManager (Fighter fighter)
  9. {
  10. mFighter = fighter;
  11. mBuffList = new List<BattleBuff> ();
  12. }
  13. public BattleBuff AddBuff(BaseSkill skill, BuffData buffData)
  14. {
  15. if (buffData == null) return null;
  16. //if (skill != null)
  17. //{
  18. // float rate = skill.GetBuffRate(buffData);
  19. // if (rate < 1 && mBattle.RandomValue(true) > rate)
  20. // return;
  21. //}
  22. //同一帧中不能叠加同样的buff
  23. BattleBuff buff = GetBuff(buffData.buffID);
  24. if (buff != null && buff.CastFrameCnt == Time.frameCount) return null;
  25. BattleBuff newBuff = new BattleBuff(buffData, mFighter,skill);
  26. newBuff.Start();
  27. mBuffList.Add(newBuff);
  28. return newBuff;
  29. }
  30. public BattleBuff GetBuff(int buffId)
  31. {
  32. for(int idx =0; idx < mBuffList.Count;idx++)
  33. {
  34. if (mBuffList[idx].BuffId == buffId) return mBuffList[idx];
  35. }
  36. return null;
  37. }
  38. public bool HasEnhanceBuff()
  39. {
  40. if (mBuffList == null) return false;
  41. for(int idx = mBuffList.Count -1; idx>=0;idx--)
  42. {
  43. if (mBuffList[idx].IsEnhance) return true;
  44. }
  45. return false;
  46. }
  47. public void Update (float deltaTime)
  48. {
  49. for (int i = mBuffList.Count - 1; i >= 0; i--)
  50. {
  51. mBuffList[i].Update(deltaTime);
  52. }
  53. for (int i = mBuffList.Count - 1; i >= 0; i--)
  54. {
  55. if (mBuffList [i].HasBeenStop) {
  56. mBuffList.RemoveAt (i);
  57. }
  58. }
  59. }
  60. public void OnFightingEnd ()
  61. {
  62. Clear();
  63. }
  64. public void Clear ()
  65. {
  66. for (int i = mBuffList.Count - 1; i >= 0; i--)
  67. mBuffList [i].Stop ();
  68. }
  69. public void Dispose()
  70. {
  71. Clear ();
  72. mFighter = null;
  73. }
  74. }