Confusion.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 java.util.Collection;
  21. import java.util.List;
  22. import javolution.util.FastList;
  23. import com.l2jserver.gameserver.ai.CtrlIntention;
  24. import com.l2jserver.gameserver.model.L2Object;
  25. import com.l2jserver.gameserver.model.actor.L2Character;
  26. import com.l2jserver.gameserver.model.effects.EffectFlag;
  27. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  28. import com.l2jserver.gameserver.model.effects.L2Effect;
  29. import com.l2jserver.gameserver.model.effects.L2EffectType;
  30. import com.l2jserver.gameserver.model.stats.Env;
  31. import com.l2jserver.util.Rnd;
  32. /**
  33. * Implementation of the Confusion Effect.<br>
  34. * Zoey76: TODO: Review onActionTime() method.
  35. * @author littlecrow
  36. */
  37. public class Confusion extends L2Effect
  38. {
  39. public Confusion(Env env, EffectTemplate template)
  40. {
  41. super(env, template);
  42. }
  43. @Override
  44. public L2EffectType getEffectType()
  45. {
  46. return L2EffectType.CONFUSION;
  47. }
  48. @Override
  49. public boolean onStart()
  50. {
  51. getEffected().startConfused();
  52. onActionTime();
  53. return true;
  54. }
  55. @Override
  56. public void onExit()
  57. {
  58. getEffected().stopConfused(this);
  59. }
  60. @Override
  61. public boolean onActionTime()
  62. {
  63. List<L2Character> targetList = new FastList<>();
  64. // Getting the possible targets
  65. Collection<L2Object> objs = getEffected().getKnownList().getKnownObjects().values();
  66. // synchronized (getEffected().getKnownList().getKnownObjects())
  67. {
  68. for (L2Object obj : objs)
  69. {
  70. if ((obj instanceof L2Character) && (obj != getEffected()))
  71. {
  72. targetList.add((L2Character) obj);
  73. }
  74. }
  75. }
  76. // if there is no target, exit function
  77. if (targetList.isEmpty())
  78. {
  79. return true;
  80. }
  81. // Choosing randomly a new target
  82. int nextTargetIdx = Rnd.nextInt(targetList.size());
  83. L2Object target = targetList.get(nextTargetIdx);
  84. // Attacking the target
  85. getEffected().setTarget(target);
  86. getEffected().getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  87. return true;
  88. }
  89. @Override
  90. public int getEffectFlags()
  91. {
  92. return EffectFlag.CONFUSED.getMask();
  93. }
  94. }