HurtChangeValueFromCasterAttr.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using UnityEngine;
  2. using System.Collections;
  3. public class HurtChangeValueFromCasterAttr : DurationFunctionEvent
  4. {
  5. public static DurationFunctionEvent Creator(BuffFunctionData data)
  6. {
  7. return new HurtChangeValueFromCasterAttr(data);
  8. }
  9. //float internalTime = 0;
  10. //float nextTime = 0;
  11. int intervalFrame = 0;
  12. int nextFrame = 0;
  13. Fighter mFighter = null;
  14. public HurtChangeValueFromCasterAttr(BuffFunctionData data):base(data)
  15. {
  16. mType = data.functionType;
  17. intervalFrame = (int)(data.intervalTime*Constants.frame_to_time);
  18. }
  19. public override void Enter(Fighter fighter)
  20. {
  21. base.Enter(fighter);
  22. mFighter = fighter;
  23. AddHurt();
  24. //Debug.LogError("fighter:" + mFighter.Name + " Enter "+ internalTime);
  25. }
  26. public override void Update(float deltaTime)
  27. {
  28. base.Update(deltaTime);
  29. nextFrame--;
  30. if (nextFrame <= 0)
  31. {
  32. AddHurt();
  33. }
  34. }
  35. public override void Exit(Fighter fighter)
  36. {
  37. //Debug.LogError("fighter:" + mFighter.Name + " Exit");
  38. base.Exit(fighter);
  39. mFighter = null;
  40. }
  41. void AddHurt()
  42. {
  43. nextFrame = intervalFrame;
  44. int subHp = 0;
  45. if (mType == Buff_Function_Type.Add_Duration_Hurt)
  46. {
  47. subHp = (int)Data.value;
  48. }
  49. else
  50. {
  51. subHp = (int)(Caster.GetAttrByType(Data.fromAttr) * Data.value * 0.01f);
  52. }
  53. if (null == mFighter)
  54. return;
  55. //Debug.LogError("fighter:" + mFighter.Name + " AddHurt:" + subHp);
  56. if(subHp > 0)
  57. {
  58. if (mFighter.StateData.IsInvincible)
  59. return;
  60. mFighter.Life -= subHp;
  61. if (null == mFighter || mFighter.Life <= 0)
  62. return;
  63. if (Caster!=null)
  64. {
  65. if (Caster.Statistics != null)
  66. Caster.Statistics.StatOtherDamage(Caster, subHp);
  67. if (subHp > 0)
  68. Caster.Battle.Output(OutputType.Damage, Caster, mFighter, "", (int)subHp);
  69. }
  70. UIEventParamFighterHurt hurtParam = new UIEventParamFighterHurt(Caster, mFighter, Mathf.RoundToInt(subHp), false, 0, 1, 1, 1, 0,0,0);
  71. EventMgr.DispatchEvent<UIEventParamFighterHurt>(new CoreEvent<UIEventParamFighterHurt>(ECoreEventType.EID_FIGHTER_HURT, hurtParam));
  72. }
  73. }
  74. }