ServitorShare.java 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 2004-2015 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.ThreadPoolManager;
  21. import com.l2jserver.gameserver.model.StatsSet;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.conditions.Condition;
  24. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  25. import com.l2jserver.gameserver.model.effects.EffectFlag;
  26. import com.l2jserver.gameserver.model.effects.L2EffectType;
  27. import com.l2jserver.gameserver.model.skills.BuffInfo;
  28. /**
  29. * Servitor Share effect implementation.<br>
  30. * Synchronizing effects on player and servitor if one of them gets removed for some reason the same will happen to another. Partner's effect exit is executed in own thread, since there is no more queue to schedule the effects,<br>
  31. * partner's effect is called while this effect is still exiting issuing an exit call for the effect, causing a stack over flow.
  32. * @author UnAfraid, Zoey76
  33. */
  34. public final class ServitorShare extends AbstractEffect
  35. {
  36. private static final class ScheduledEffectExitTask implements Runnable
  37. {
  38. private final L2Character _effected;
  39. private final int _skillId;
  40. public ScheduledEffectExitTask(L2Character effected, int skillId)
  41. {
  42. _effected = effected;
  43. _skillId = skillId;
  44. }
  45. @Override
  46. public void run()
  47. {
  48. _effected.stopSkillEffects(false, _skillId);
  49. }
  50. }
  51. public ServitorShare(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  52. {
  53. super(attachCond, applyCond, set, params);
  54. }
  55. @Override
  56. public int getEffectFlags()
  57. {
  58. return EffectFlag.SERVITOR_SHARE.getMask();
  59. }
  60. @Override
  61. public L2EffectType getEffectType()
  62. {
  63. return L2EffectType.BUFF;
  64. }
  65. @Override
  66. public void onExit(BuffInfo info)
  67. {
  68. final L2Character effected = info.getEffected().isPlayer() ? info.getEffected().getSummon() : info.getEffected().getActingPlayer();
  69. if (effected != null)
  70. {
  71. ThreadPoolManager.getInstance().scheduleEffect(new ScheduledEffectExitTask(effected, info.getSkill().getId()), 100);
  72. }
  73. }
  74. }