ConditionPlayerState.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.model.conditions;
  16. import com.l2jserver.gameserver.model.actor.L2Character;
  17. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  18. import com.l2jserver.gameserver.model.base.PlayerState;
  19. import com.l2jserver.gameserver.model.stats.Env;
  20. /**
  21. * The Class ConditionPlayerState.
  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. * @param check the player state to be verified.
  31. * @param required the required value.
  32. */
  33. public ConditionPlayerState(PlayerState check, boolean required)
  34. {
  35. _check = check;
  36. _required = required;
  37. }
  38. /**
  39. * @see com.l2jserver.gameserver.model.conditions.Condition#testImpl(com.l2jserver.gameserver.model.stats.Env)
  40. */
  41. @Override
  42. public boolean testImpl(Env env)
  43. {
  44. final L2Character character = env.getCharacter();
  45. final L2PcInstance player = env.getPlayer();
  46. switch (_check)
  47. {
  48. case RESTING:
  49. if (player != null)
  50. {
  51. return (player.isSitting() == _required);
  52. }
  53. return !_required;
  54. case MOVING:
  55. return character.isMoving() == _required;
  56. case RUNNING:
  57. return character.isRunning() == _required;
  58. case STANDING:
  59. if (player != null)
  60. {
  61. return (_required != (player.isSitting() || player.isMoving()));
  62. }
  63. return (_required != character.isMoving());
  64. case FLYING:
  65. return (character.isFlying() == _required);
  66. case BEHIND:
  67. return (character.isBehindTarget() == _required);
  68. case FRONT:
  69. return (character.isInFrontOfTarget() == _required);
  70. case CHAOTIC:
  71. if (player != null)
  72. {
  73. return ((player.getKarma() > 0) == _required);
  74. }
  75. return !_required;
  76. case OLYMPIAD:
  77. if (player != null)
  78. {
  79. return (player.isInOlympiadMode() == _required);
  80. }
  81. return !_required;
  82. }
  83. return !_required;
  84. }
  85. }