ChanceSkillTrigger.java 2.9 KB

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