/** * Return the number of playable characters in a defined radius around the specified object. * * @param range : the radius in which to look for players * @param npc : the object whose knownlist to check * @param playable : if {@code true}, count summons and pets aswell * @param invisible : if {@code true}, count invisible characters aswell * @return the number of targets found */ public static int getPlayersCountInRadius( int range, L2Object npc, boolean playable, boolean invisible) { int count = 0; final Collection<L2Object> objs = npc.getKnownList().getKnownObjects().values(); for (L2Object obj : objs) { if ((obj != null) && ((obj.isPlayable() && playable) || obj.isPet())) { if (obj.isPlayer() && !invisible && obj.getActingPlayer().getAppearance().getInvisible()) { continue; } final L2Character cha = (L2Character) obj; if (((cha.getZ() < (npc.getZ() - 100)) && (cha.getZ() > (npc.getZ() + 100))) || !(GeoData.getInstance() .canSeeTarget( cha.getX(), cha.getY(), cha.getZ(), npc.getX(), npc.getY(), npc.getZ()))) { continue; } if (Util.checkIfInRange(range, npc, obj, true) && !cha.isDead()) { count++; } } } return count; }
@Override public boolean useUserCommand(int id, L2PcInstance activeChar) { if (id != COMMAND_IDS[0]) { return false; } int nobleObjId = activeChar.getObjectId(); final L2Object target = activeChar.getTarget(); if (target != null) { if (target.isPlayer() && target.getActingPlayer().isNoble()) { nobleObjId = target.getObjectId(); } else { activeChar.sendPacket(SystemMessageId.NOBLESSE_ONLY); return false; } } else if (!activeChar.isNoble()) { activeChar.sendPacket(SystemMessageId.NOBLESSE_ONLY); return false; } final SystemMessage sm = SystemMessage.getSystemMessage( SystemMessageId .THE_CURRENT_RECORD_FOR_THIS_OLYMPIAD_SESSION_IS_S1_MATCHES_S2_WINS_S3_DEFEATS_YOU_HAVE_EARNED_S4_OLYMPIAD_POINTS); sm.addInt(Olympiad.getInstance().getCompetitionDone(nobleObjId)); sm.addInt(Olympiad.getInstance().getCompetitionWon(nobleObjId)); sm.addInt(Olympiad.getInstance().getCompetitionLost(nobleObjId)); sm.addInt(Olympiad.getInstance().getNoblePoints(nobleObjId)); activeChar.sendPacket(sm); final SystemMessage sm2 = SystemMessage.getSystemMessage( SystemMessageId .YOU_HAVE_S1_MATCHES_REMAINING_THAT_YOU_CAN_PARTECIPATE_IN_THIS_WEEK_S2_CLASSED_S3_NON_CLASSED_S4_TEAM); sm2.addInt(Olympiad.getInstance().getRemainingWeeklyMatches(nobleObjId)); sm2.addInt(Olympiad.getInstance().getRemainingWeeklyMatchesClassed(nobleObjId)); sm2.addInt(Olympiad.getInstance().getRemainingWeeklyMatchesNonClassed(nobleObjId)); sm2.addInt(Olympiad.getInstance().getRemainingWeeklyMatchesTeam(nobleObjId)); activeChar.sendPacket(sm2); return true; }
/** * Perform a couple social action. * * @param id the couple social action Id */ private void useCoupleSocial(final int id) { final L2PcInstance requester = getActiveChar(); if (requester == null) { return; } final L2Object target = requester.getTarget(); if ((target == null) || !target.isPlayer()) { sendPacket(SystemMessageId.INVALID_TARGET); return; } final int distance = (int) requester.calculateDistance(target, false, false); if ((distance > 125) || (distance < 15) || (requester.getObjectId() == target.getObjectId())) { sendPacket( SystemMessageId .THE_REQUEST_CANNOT_BE_COMPLETED_BECAUSE_THE_TARGET_DOES_NOT_MEET_LOCATION_REQUIREMENTS); return; } SystemMessage sm; if (requester.isInStoreMode() || requester.isInCraftMode()) { sm = SystemMessage.getSystemMessage( SystemMessageId .C1_IS_IN_PRIVATE_STORE_MODE_OR_IN_A_BATTLE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(requester); sendPacket(sm); return; } if (requester.isInCombat() || requester.isInDuel() || AttackStanceTaskManager.getInstance().hasAttackStanceTask(requester)) { sm = SystemMessage.getSystemMessage( SystemMessageId.C1_IS_IN_A_BATTLE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(requester); sendPacket(sm); return; } if (requester.isFishing()) { sendPacket(SystemMessageId.YOU_CANNOT_DO_THAT_WHILE_FISHING); return; } if (requester.getReputation() < 0) { sm = SystemMessage.getSystemMessage( SystemMessageId.C1_IS_IN_A_CHAOTIC_STATE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(requester); sendPacket(sm); return; } if (requester.isInOlympiadMode()) { sm = SystemMessage.getSystemMessage( SystemMessageId .C1_IS_PARTICIPATING_IN_THE_OLYMPIAD_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(requester); sendPacket(sm); return; } if (requester.isInSiege()) { sm = SystemMessage.getSystemMessage( SystemMessageId.C1_IS_IN_A_CASTLE_SIEGE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(requester); sendPacket(sm); return; } if (requester.isInHideoutSiege()) { sm = SystemMessage.getSystemMessage( SystemMessageId .C1_IS_PARTICIPATING_IN_A_CLAN_HALL_SIEGE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(requester); sendPacket(sm); } if (requester.isMounted() || requester.isFlyingMounted() || requester.isInBoat() || requester.isInAirShip()) { sm = SystemMessage.getSystemMessage( SystemMessageId .C1_IS_RIDING_A_SHIP_STEED_OR_STRIDER_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(requester); sendPacket(sm); return; } if (requester.isTransformed()) { sm = SystemMessage.getSystemMessage( SystemMessageId .C1_IS_CURRENTLY_TRANSFORMING_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(requester); sendPacket(sm); return; } if (requester.isAlikeDead()) { sm = SystemMessage.getSystemMessage( SystemMessageId.C1_IS_CURRENTLY_DEAD_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(requester); sendPacket(sm); return; } // Checks for partner. final L2PcInstance partner = target.getActingPlayer(); if (partner.isInStoreMode() || partner.isInCraftMode()) { sm = SystemMessage.getSystemMessage( SystemMessageId .C1_IS_IN_PRIVATE_STORE_MODE_OR_IN_A_BATTLE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(partner); sendPacket(sm); return; } if (partner.isInCombat() || partner.isInDuel() || AttackStanceTaskManager.getInstance().hasAttackStanceTask(partner)) { sm = SystemMessage.getSystemMessage( SystemMessageId.C1_IS_IN_A_BATTLE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(partner); sendPacket(sm); return; } if (partner.getMultiSociaAction() > 0) { sm = SystemMessage.getSystemMessage( SystemMessageId .C1_IS_ALREADY_PARTICIPATING_IN_A_COUPLE_ACTION_AND_CANNOT_BE_REQUESTED_FOR_ANOTHER_COUPLE_ACTION); sm.addPcName(partner); sendPacket(sm); return; } if (partner.isFishing()) { sm = SystemMessage.getSystemMessage( SystemMessageId.C1_IS_FISHING_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(partner); sendPacket(sm); return; } if (partner.getReputation() < 0) { sm = SystemMessage.getSystemMessage( SystemMessageId.C1_IS_IN_A_CHAOTIC_STATE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(partner); sendPacket(sm); return; } if (partner.isInOlympiadMode()) { sm = SystemMessage.getSystemMessage( SystemMessageId .C1_IS_PARTICIPATING_IN_THE_OLYMPIAD_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(partner); sendPacket(sm); return; } if (partner.isInHideoutSiege()) { sm = SystemMessage.getSystemMessage( SystemMessageId .C1_IS_PARTICIPATING_IN_A_CLAN_HALL_SIEGE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(partner); sendPacket(sm); return; } if (partner.isInSiege()) { sm = SystemMessage.getSystemMessage( SystemMessageId.C1_IS_IN_A_CASTLE_SIEGE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(partner); sendPacket(sm); return; } if (partner.isMounted() || partner.isFlyingMounted() || partner.isInBoat() || partner.isInAirShip()) { sm = SystemMessage.getSystemMessage( SystemMessageId .C1_IS_RIDING_A_SHIP_STEED_OR_STRIDER_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(partner); sendPacket(sm); return; } if (partner.isTeleporting()) { sm = SystemMessage.getSystemMessage( SystemMessageId .C1_IS_CURRENTLY_TELEPORTING_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(partner); sendPacket(sm); return; } if (partner.isTransformed()) { sm = SystemMessage.getSystemMessage( SystemMessageId .C1_IS_CURRENTLY_TRANSFORMING_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(partner); sendPacket(sm); return; } if (partner.isAlikeDead()) { sm = SystemMessage.getSystemMessage( SystemMessageId.C1_IS_CURRENTLY_DEAD_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION); sm.addPcName(partner); sendPacket(sm); return; } if (requester.isAllSkillsDisabled() || partner.isAllSkillsDisabled()) { sendPacket(SystemMessageId.THE_COUPLE_ACTION_WAS_CANCELLED); return; } requester.setMultiSocialAction(id, partner.getObjectId()); sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_REQUESTED_A_COUPLE_ACTION_WITH_C1); sm.addPcName(partner); sendPacket(sm); if ((requester.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE) || (partner.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)) { final NextAction nextAction = new NextAction( CtrlEvent.EVT_ARRIVED, CtrlIntention.AI_INTENTION_MOVE_TO, () -> partner.sendPacket(new ExAskCoupleAction(requester.getObjectId(), id))); requester.getAI().setNextAction(nextAction); return; } if (requester.isCastingNow() || requester.isCastingSimultaneouslyNow()) { final NextAction nextAction = new NextAction( CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> partner.sendPacket(new ExAskCoupleAction(requester.getObjectId(), id))); requester.getAI().setNextAction(nextAction); return; } partner.sendPacket(new ExAskCoupleAction(requester.getObjectId(), id)); }
@Override protected void runImpl() { L2PcInstance player = getActiveChar(); if (player == null) { return; } if (!player.getAccessLevel().allowTransaction()) { player.sendMessage("Transactions are disabled for your current Access Level."); sendPacket(ActionFailed.STATIC_PACKET); return; } BuffInfo info = player.getEffectList().getBuffInfoByAbnormalType(AbnormalType.BOT_PENALTY); if (info != null) { for (AbstractEffect effect : info.getEffects()) { if (!effect.checkCondition(BotReportTable.TRADE_ACTION_BLOCK_ID)) { player.sendPacket(SystemMessageId.YOU_HAVE_BEEN_REPORTED_SO_ACTIONS_NOT_ALLOWED); player.sendPacket(ActionFailed.STATIC_PACKET); return; } } } final L2Object target = L2World.getInstance().findObject(_objectId); // If there is no target, target is far away or // they are in different instances (except multiverse) // trade request is ignored and there is no system message. if ((target == null) || !player.getKnownList().knowsObject(target) || ((target.getInstanceId() != player.getInstanceId()) && (player.getInstanceId() != -1))) { return; } // If target and acting player are the same, trade request is ignored // and the following system message is sent to acting player. if (target.getObjectId() == player.getObjectId()) { player.sendPacket(SystemMessageId.TARGET_IS_INCORRECT); return; } if (!target.isPlayer()) { player.sendPacket(SystemMessageId.INCORRECT_TARGET); return; } final L2PcInstance partner = target.getActingPlayer(); if (partner.isInOlympiadMode() || player.isInOlympiadMode()) { player.sendMessage( "A user currently participating in the Olympiad cannot accept or request a trade."); return; } info = partner.getEffectList().getBuffInfoByAbnormalType(AbnormalType.BOT_PENALTY); if (info != null) { for (AbstractEffect effect : info.getEffects()) { if (!effect.checkCondition(BotReportTable.TRADE_ACTION_BLOCK_ID)) { final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_REPORTED_AND_IS_BEING_INVESTIGATED); sm.addCharName(partner); player.sendPacket(sm); player.sendPacket(ActionFailed.STATIC_PACKET); return; } } } // L2J Customs: Karma punishment if (!Config.ALT_GAME_KARMA_PLAYER_CAN_TRADE && (player.getKarma() > 0)) { player.sendMessage("You cannot trade while you are in a chaotic state."); return; } if (!Config.ALT_GAME_KARMA_PLAYER_CAN_TRADE && (partner.getKarma() > 0)) { player.sendMessage("You cannot request a trade while your target is in a chaotic state."); return; } if (Config.JAIL_DISABLE_TRANSACTION && (player.isJailed() || partner.isJailed())) { player.sendMessage("You cannot trade while you are in in Jail."); return; } if ((player.getPrivateStoreType() != PrivateStoreType.NONE) || (partner.getPrivateStoreType() != PrivateStoreType.NONE)) { player.sendPacket(SystemMessageId.CANNOT_TRADE_DISCARD_DROP_ITEM_WHILE_IN_SHOPMODE); return; } if (player.isProcessingTransaction()) { if (Config.DEBUG) { _log.fine("Already trading with someone else."); } player.sendPacket(SystemMessageId.ALREADY_TRADING); return; } SystemMessage sm; if (partner.isProcessingRequest() || partner.isProcessingTransaction()) { if (Config.DEBUG) { _log.info("Transaction already in progress."); } sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_BUSY_TRY_LATER); sm.addString(partner.getName()); player.sendPacket(sm); return; } if (partner.getTradeRefusal()) { player.sendMessage("That person is in trade refusal mode."); return; } if (BlockList.isBlocked(partner, player)) { sm = SystemMessage.getSystemMessage(SystemMessageId.S1_HAS_ADDED_YOU_TO_IGNORE_LIST); sm.addCharName(partner); player.sendPacket(sm); return; } if (player.calculateDistance(partner, true, false) > 150) { player.sendPacket(SystemMessageId.TARGET_TOO_FAR); return; } player.onTransactionRequest(partner); partner.sendPacket(new SendTradeRequest(player.getObjectId())); sm = SystemMessage.getSystemMessage(SystemMessageId.REQUEST_C1_FOR_TRADE); sm.addString(partner.getName()); player.sendPacket(sm); }