ConditionPlayerState.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.L2Character;
  17. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  18. import com.l2jserver.gameserver.model.base.PlayerState;
  19. import com.l2jserver.gameserver.skills.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.skills.conditions.Condition#testImpl(com.l2jserver.gameserver.skills.Env)
  40. */
  41. @Override
  42. public boolean testImpl(Env env)
  43. {
  44. final L2Character character = env.player;
  45. L2PcInstance player = null;
  46. switch (_check)
  47. {
  48. case RESTING:
  49. player = character.getActingPlayer();
  50. if (player != null)
  51. {
  52. return (player.isSitting() == _required);
  53. }
  54. return !_required;
  55. case MOVING:
  56. return character.isMoving() == _required;
  57. case RUNNING:
  58. return character.isRunning() == _required;
  59. case STANDING:
  60. player = character.getActingPlayer();
  61. if (player != null)
  62. {
  63. return (_required != (player.isSitting() || player.isMoving()));
  64. }
  65. return (_required != character.isMoving());
  66. case FLYING:
  67. return (character.isFlying() == _required);
  68. case BEHIND:
  69. return (character.isBehindTarget() == _required);
  70. case FRONT:
  71. return (character.isInFrontOfTarget() == _required);
  72. case CHAOTIC:
  73. player = character.getActingPlayer();
  74. if (player != null)
  75. {
  76. return ((player.getKarma() > 0) == _required);
  77. }
  78. return !_required;
  79. case OLYMPIAD:
  80. player = character.getActingPlayer();
  81. if (player != null)
  82. {
  83. return (player.isInOlympiadMode() == _required);
  84. }
  85. return !_required;
  86. }
  87. return !_required;
  88. }
  89. }