EffectChanceSkillTrigger.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. // Special constructor to steal this effect
  35. public EffectChanceSkillTrigger(Env env, L2Effect effect)
  36. {
  37. super(env, effect);
  38. _triggeredId = effect.getEffectTemplate().triggeredId;
  39. _triggeredLevel = effect.getEffectTemplate().triggeredLevel;
  40. _chanceCondition = effect.getEffectTemplate().chanceCondition;
  41. }
  42. @Override
  43. protected boolean effectCanBeStolen()
  44. {
  45. return true;
  46. }
  47. @Override
  48. public L2EffectType getEffectType()
  49. {
  50. return L2EffectType.CHANCE_SKILL_TRIGGER;
  51. }
  52. @Override
  53. public boolean onStart()
  54. {
  55. getEffected().addChanceTrigger(this);
  56. getEffected().onStartChanceEffect(getSkill().getElement());
  57. return super.onStart();
  58. }
  59. @Override
  60. public boolean onActionTime()
  61. {
  62. getEffected().onActionTimeChanceEffect(getSkill().getElement());
  63. return false;
  64. }
  65. @Override
  66. public void onExit()
  67. {
  68. // trigger only if effect in use and successfully ticked to the end
  69. if (getInUse() && getCount() == 0)
  70. getEffected().onExitChanceEffect(getSkill().getElement());
  71. getEffected().removeChanceEffect(this);
  72. super.onExit();
  73. }
  74. @Override
  75. public int getTriggeredChanceId()
  76. {
  77. return _triggeredId;
  78. }
  79. @Override
  80. public int getTriggeredChanceLevel()
  81. {
  82. return _triggeredLevel;
  83. }
  84. @Override
  85. public boolean triggersChanceSkill()
  86. {
  87. return _triggeredId > 1;
  88. }
  89. @Override
  90. public ChanceCondition getTriggeredChanceCondition()
  91. {
  92. return _chanceCondition;
  93. }
  94. }