HurtChangeValueFromTargetAttr.cs 2.3 KB

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