PassiveSkillTriggerEvent.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using UnityEngine;
  2. using System.Collections;
  3. public class PassiveSkillTriggerEvent : DurationFunctionEvent
  4. {
  5. public static DurationFunctionEvent Creator(BuffFunctionData data)
  6. {
  7. return new PassiveSkillTriggerEvent(data);
  8. }
  9. public PassiveSkillTriggerEvent(BuffFunctionData data) : base(data)
  10. {
  11. mType = data.functionType;
  12. }
  13. int buffId = 0;
  14. BuffTriggerType tType;
  15. int intervalFrame = 0;
  16. int nextFrame = 0;
  17. Fighter mFighter = null;
  18. public override void Enter(Fighter fighter)
  19. {
  20. base.Enter(fighter);
  21. mFighter = fighter;
  22. buffId = (int)Data.BaseValue;
  23. float buffRate = Data.IncVal * 0.01f;
  24. int temp = 0;
  25. if (Data.fromAttr.Length > 0)
  26. temp = Data.fromAttr[0];
  27. int casterType = temp / 100;
  28. int type = temp - casterType * 100;
  29. tType = (BuffTriggerType)type;
  30. if(tType != BuffTriggerType.Trigger_FixedTime)
  31. {
  32. BuffTriggerCasterType cType = (BuffTriggerCasterType)casterType;
  33. TriggerBuffData buffData = new TriggerBuffData(buffId, buffRate, Data.intervalTime, tType, cType,Data.extendParam);
  34. buffData.BuffLevel = Data.SkillLv;
  35. if (!string.IsNullOrEmpty(Data.extendParam))
  36. {
  37. int val = 0;
  38. int.TryParse(Data.extendParam, out val);
  39. buffData.CheckVal = val;
  40. }
  41. fighter.AddTriggerBuffData(buffData);
  42. }
  43. else
  44. {
  45. intervalFrame = (int)(Data.intervalTime * Constants.frame_to_time);
  46. nextFrame = intervalFrame;
  47. }
  48. }
  49. public override void Update(float deltaTime)
  50. {
  51. base.Update(deltaTime);
  52. if(tType == BuffTriggerType.Trigger_FixedTime)
  53. {
  54. nextFrame--;
  55. if (nextFrame <= 0)
  56. {
  57. TriggerBuff();
  58. }
  59. }
  60. }
  61. public override void Exit(Fighter fighter)
  62. {
  63. fighter.RemoveTriggerBuffData(buffId);
  64. base.Exit(fighter);
  65. mFighter = null;
  66. }
  67. private void TriggerBuff()
  68. {
  69. nextFrame = intervalFrame;
  70. mFighter.CastBuff(null, buffId, Data.SkillLv);
  71. }
  72. }