ConditionPlayerCanResurrect.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.L2Summon;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.stats.Env;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  26. /**
  27. * Player Can Resurrect condition implementation.
  28. * @author UnAfraid
  29. */
  30. public class ConditionPlayerCanResurrect extends Condition
  31. {
  32. private final boolean _val;
  33. public ConditionPlayerCanResurrect(boolean val)
  34. {
  35. _val = val;
  36. }
  37. @Override
  38. public boolean testImpl(Env env)
  39. {
  40. // Need skill rework for fix that properly
  41. if (env.getSkill().getAffectRange() > 0)
  42. {
  43. return true;
  44. }
  45. boolean canResurrect = true;
  46. final L2Character caster = env.getCharacter();
  47. final L2Character target = env.getTarget();
  48. if (target.isPlayer())
  49. {
  50. final L2PcInstance player = target.getActingPlayer();
  51. if (!player.isDead())
  52. {
  53. canResurrect = false;
  54. if (caster.isPlayer())
  55. {
  56. final SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  57. msg.addSkillName(env.getSkill());
  58. caster.sendPacket(msg);
  59. }
  60. }
  61. else if (player.isResurrectionBlocked())
  62. {
  63. canResurrect = false;
  64. if (caster.isPlayer())
  65. {
  66. caster.sendPacket(SystemMessageId.REJECT_RESURRECTION);
  67. }
  68. }
  69. else if (player.isReviveRequested())
  70. {
  71. canResurrect = false;
  72. if (caster.isPlayer())
  73. {
  74. caster.sendPacket(SystemMessageId.RES_HAS_ALREADY_BEEN_PROPOSED);
  75. }
  76. }
  77. }
  78. else if (target.isSummon())
  79. {
  80. final L2Summon summon = (L2Summon) target;
  81. final L2PcInstance player = summon.getOwner();
  82. if (!summon.isDead())
  83. {
  84. canResurrect = false;
  85. if (caster.isPlayer())
  86. {
  87. final SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  88. msg.addSkillName(env.getSkill());
  89. caster.sendPacket(msg);
  90. }
  91. }
  92. else if (summon.isResurrectionBlocked())
  93. {
  94. canResurrect = false;
  95. if (caster.isPlayer())
  96. {
  97. caster.sendPacket(SystemMessageId.REJECT_RESURRECTION);
  98. }
  99. }
  100. else if ((player != null) && player.isRevivingPet())
  101. {
  102. canResurrect = false;
  103. if (caster.isPlayer())
  104. {
  105. caster.sendPacket(SystemMessageId.RES_HAS_ALREADY_BEEN_PROPOSED); // Resurrection is already been proposed.
  106. }
  107. }
  108. }
  109. return (_val == canResurrect);
  110. }
  111. }