EffectChanceSkillTrigger.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.skills.effects;
  16. import com.l2jserver.gameserver.model.ChanceCondition;
  17. import com.l2jserver.gameserver.model.IChanceSkillTrigger;
  18. import com.l2jserver.gameserver.model.L2Effect;
  19. import com.l2jserver.gameserver.skills.Env;
  20. import com.l2jserver.gameserver.templates.effects.EffectTemplate;
  21. import com.l2jserver.gameserver.templates.skills.L2EffectType;
  22. public class EffectChanceSkillTrigger extends L2Effect implements IChanceSkillTrigger
  23. {
  24. private final int _triggeredId;
  25. private final int _triggeredLevel;
  26. private final ChanceCondition _chanceCondition;
  27. public EffectChanceSkillTrigger(Env env, EffectTemplate template)
  28. {
  29. super(env, template);
  30. _triggeredId = template.triggeredId;
  31. _triggeredLevel = template.triggeredLevel;
  32. _chanceCondition = template.chanceCondition;
  33. }
  34. @Override
  35. public L2EffectType getEffectType()
  36. {
  37. return L2EffectType.CHANCE_SKILL_TRIGGER;
  38. }
  39. @Override
  40. public boolean onStart()
  41. {
  42. getEffected().addChanceTrigger(this);
  43. getEffected().onStartChanceEffect(getSkill().getElement());
  44. return super.onStart();
  45. }
  46. @Override
  47. public boolean onActionTime()
  48. {
  49. getEffected().onActionTimeChanceEffect(getSkill().getElement());
  50. return false;
  51. }
  52. @Override
  53. public void onExit()
  54. {
  55. // trigger only if effect in use and successfully ticked to the end
  56. if (getInUse() && getCount() == 0)
  57. getEffected().onExitChanceEffect(getSkill().getElement());
  58. getEffected().removeChanceEffect(this);
  59. super.onExit();
  60. }
  61. @Override
  62. public int getTriggeredChanceId()
  63. {
  64. return _triggeredId;
  65. }
  66. @Override
  67. public int getTriggeredChanceLevel()
  68. {
  69. return _triggeredLevel;
  70. }
  71. @Override
  72. public boolean triggersChanceSkill()
  73. {
  74. return _triggeredId > 1;
  75. }
  76. @Override
  77. public ChanceCondition getTriggeredChanceCondition()
  78. {
  79. return _chanceCondition;
  80. }
  81. }