ConditionPlayerState.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.conditions;
  16. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  17. import com.l2jserver.gameserver.model.base.PlayerState;
  18. import com.l2jserver.gameserver.skills.Env;
  19. /**
  20. * The Class ConditionPlayerState.
  21. *
  22. * @author mkizub
  23. */
  24. public class ConditionPlayerState extends Condition
  25. {
  26. private final PlayerState _check;
  27. private final boolean _required;
  28. /**
  29. * Instantiates a new condition player state.
  30. *
  31. * @param check the check
  32. * @param required the required
  33. */
  34. public ConditionPlayerState(PlayerState check, boolean required)
  35. {
  36. _check = check;
  37. _required = required;
  38. }
  39. /* (non-Javadoc)
  40. * @see com.l2jserver.gameserver.skills.conditions.Condition#testImpl(com.l2jserver.gameserver.skills.Env)
  41. */
  42. @Override
  43. public boolean testImpl(Env env)
  44. {
  45. L2PcInstance player;
  46. switch (_check)
  47. {
  48. case RESTING:
  49. if (env.player instanceof L2PcInstance)
  50. return ((L2PcInstance) env.player).isSitting() == _required;
  51. return !_required;
  52. case MOVING:
  53. return env.player.isMoving() == _required;
  54. case RUNNING:
  55. return env.player.isMoving() == _required && env.player.isRunning() == _required;
  56. case FLYING:
  57. return env.player.isFlying() == _required;
  58. case BEHIND:
  59. return env.player.isBehindTarget() == _required;
  60. case FRONT:
  61. return env.player.isInFrontOfTarget() == _required;
  62. case CHAOTIC:
  63. player = env.player.getActingPlayer();
  64. if (player != null)
  65. return player.getKarma() > 0 == _required;
  66. return !_required;
  67. case OLYMPIAD:
  68. player = env.player.getActingPlayer();
  69. if (player != null)
  70. return player.isInOlympiadMode() == _required;
  71. return !_required;
  72. }
  73. return !_required;
  74. }
  75. }