Mark.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. using UnityEngine;
  2. using System.Collections;
  3. public class Mark
  4. {
  5. private MarkData mData;
  6. private Fighter mTarget;
  7. private bool bStop = false;
  8. private bool bStarted = false;
  9. private int mCurLayer = 0;
  10. private int mTotalFrame = 0;
  11. private int mLeftFrame = 0;
  12. private int mEffectInstId = 0;
  13. public bool Valid { get { return null == mData ? false : mData.Valid; } }
  14. public int Id { get { return null == mData ? 0 : mData.markId; } }
  15. public bool Stopped { get { return null == mData ? true : bStop; } }
  16. public int Layer { get { return mCurLayer; } }
  17. public Mark(int markId)
  18. {
  19. mData = new MarkData(markId);
  20. if(mData.Valid)
  21. {
  22. mTotalFrame = (int)(mData.duration * Constants.frame_to_time);
  23. }
  24. }
  25. ~Mark()
  26. {
  27. Dispose();
  28. }
  29. public SFloat GetFunValue(Buff_Function_Type funType)
  30. {
  31. if (mCurLayer == 0) return 0;
  32. SFloat val = 0;
  33. if(mData.funList != null)
  34. {
  35. for(int idx =0; idx < mData.funList.Count;idx++)
  36. {
  37. var fun = mData.funList[idx];
  38. if(fun.id == (int)funType)
  39. {
  40. val += fun.val + (mCurLayer - 1) * GetFunIncVal(funType);
  41. }
  42. }
  43. }
  44. return val;
  45. }
  46. public SFloat GetFunPercent(Buff_Function_Type funType)
  47. {
  48. if (mCurLayer == 0) return 0;
  49. SFloat val = 0;
  50. if (mData.funList != null)
  51. {
  52. for (int idx = 0; idx < mData.funList.Count; idx++)
  53. {
  54. var fun = mData.funList[idx];
  55. if (fun.id == (int)funType)
  56. {
  57. val += (fun.val * 0.01f) + (mCurLayer - 1) * GetFunIncPercent(funType);
  58. }
  59. }
  60. }
  61. return val;
  62. }
  63. private float GetFunIncVal(Buff_Function_Type funType)
  64. {
  65. if (mData.funIncList == null) return 0;
  66. for(int idx =0; idx < mData.funIncList.Count;idx++)
  67. {
  68. if(mData.funIncList[idx].id == (int)funType)
  69. {
  70. return mData.funIncList[idx].val;
  71. }
  72. }
  73. return 0;
  74. }
  75. private SFloat GetFunIncPercent(Buff_Function_Type funType)
  76. {
  77. if (mData.funIncList == null) return 0;
  78. for (int idx = 0; idx < mData.funIncList.Count; idx++)
  79. {
  80. if (mData.funIncList[idx].id == (int)funType)
  81. {
  82. return mData.funIncList[idx].val * 0.01f;
  83. }
  84. }
  85. return 0;
  86. }
  87. public void AddLayer(Fighter target,int layer)
  88. {
  89. mTarget = target;
  90. mCurLayer += layer;
  91. if(mCurLayer > mData.maxLayer)
  92. {
  93. mCurLayer = mData.maxLayer;
  94. }
  95. if(!bStarted)
  96. {
  97. Start();
  98. }
  99. else
  100. {
  101. mLeftFrame = mTotalFrame;
  102. }
  103. ShowIcon();
  104. }
  105. public void DecLayer(int layer)
  106. {
  107. mCurLayer -= layer;
  108. if(mCurLayer < 0)
  109. {
  110. mCurLayer = 0;
  111. }
  112. if(mCurLayer == 0)
  113. {
  114. Stop();
  115. }else
  116. {
  117. ShowIcon();
  118. }
  119. }
  120. private void ShowIcon()
  121. {
  122. if (!string.IsNullOrEmpty(mData.markIcon))
  123. {
  124. int layer = mData.maxLayer == 1 ? 0 : mCurLayer;
  125. if(mData.IsShow(MarkData.EnShowType.En_ShowBattle))
  126. mTarget.ShowBuffIcon(mData.markIcon, layer);
  127. }
  128. }
  129. public void Update(float deltaTime)
  130. {
  131. if (!bStarted) return;
  132. mLeftFrame -= 1;
  133. if(mLeftFrame <= 0)
  134. {
  135. Stop();
  136. }
  137. }
  138. public void Start()
  139. {
  140. bStarted = true;
  141. bStop = false;
  142. mLeftFrame = mTotalFrame;
  143. if(mData.effectId > 0)
  144. {
  145. mEffectInstId = EffectManager.Instance.PlayEffect(mData.effectId, mTarget, mTarget);
  146. }
  147. }
  148. public void Stop()
  149. {
  150. if (mData != null && !string.IsNullOrEmpty(mData.markIcon))
  151. {
  152. if (mData.IsShow(MarkData.EnShowType.En_ShowBattle))
  153. mTarget.RemoveBuffIcon(mData.markIcon);
  154. }
  155. if (mEffectInstId > 0)
  156. {
  157. EffectManager.Instance.RemoveEffectByInstanceID(mEffectInstId);
  158. mEffectInstId = 0;
  159. }
  160. bStarted = false;
  161. bStop = true;
  162. }
  163. public void Dispose()
  164. {
  165. mData = null;
  166. mTarget = null;
  167. }
  168. }