ConditionPlayerState.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (C) 2004-2014 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server 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 Server 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 com.l2jserver.gameserver.model.conditions;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.model.base.PlayerState;
  23. import com.l2jserver.gameserver.model.stats.Env;
  24. /**
  25. * The Class ConditionPlayerState.
  26. * @author mkizub
  27. */
  28. public class ConditionPlayerState extends Condition
  29. {
  30. private final PlayerState _check;
  31. private final boolean _required;
  32. /**
  33. * Instantiates a new condition player state.
  34. * @param check the player state to be verified.
  35. * @param required the required value.
  36. */
  37. public ConditionPlayerState(PlayerState check, boolean required)
  38. {
  39. _check = check;
  40. _required = required;
  41. }
  42. /**
  43. *
  44. */
  45. @Override
  46. public boolean testImpl(Env env)
  47. {
  48. final L2Character character = env.getCharacter();
  49. final L2PcInstance player = env.getPlayer();
  50. switch (_check)
  51. {
  52. case RESTING:
  53. if (player != null)
  54. {
  55. return (player.isSitting() == _required);
  56. }
  57. return !_required;
  58. case MOVING:
  59. return character.isMoving() == _required;
  60. case RUNNING:
  61. return character.isRunning() == _required;
  62. case STANDING:
  63. if (player != null)
  64. {
  65. return (_required != (player.isSitting() || player.isMoving()));
  66. }
  67. return (_required != character.isMoving());
  68. case FLYING:
  69. return (character.isFlying() == _required);
  70. case BEHIND:
  71. return (character.isBehindTarget() == _required);
  72. case FRONT:
  73. return (character.isInFrontOfTarget() == _required);
  74. case CHAOTIC:
  75. if (player != null)
  76. {
  77. return ((player.getKarma() > 0) == _required);
  78. }
  79. return !_required;
  80. case OLYMPIAD:
  81. if (player != null)
  82. {
  83. return (player.isInOlympiadMode() == _required);
  84. }
  85. return !_required;
  86. }
  87. return !_required;
  88. }
  89. }