/** * Called on every onAction in L2PcIstance<br> * <br> * * @param playerInstance * @param targetedPlayerObjectId * @return boolean: true if player is allowed to target, otherwise false */ public static boolean onAction(L2PcInstance playerInstance, int targetedPlayerObjectId) { if ((playerInstance == null) || !isStarted()) { return true; } if (playerInstance.isGM()) { return true; } final byte playerTeamId = getParticipantTeamId(playerInstance.getObjectId()); final byte targetedPlayerTeamId = getParticipantTeamId(targetedPlayerObjectId); if (((playerTeamId != -1) && (targetedPlayerTeamId == -1)) || ((playerTeamId == -1) && (targetedPlayerTeamId != -1))) { return false; } if ((playerTeamId != -1) && (targetedPlayerTeamId != -1) && (playerTeamId == targetedPlayerTeamId) && (playerInstance.getObjectId() != targetedPlayerObjectId) && !Config.TVT_EVENT_TARGET_TEAM_MEMBERS_ALLOWED) { return false; } return true; }
/** * @param source * @param target * @param skill * @return true if player valid for skill */ public static final boolean checkForTvTSkill( L2PcInstance source, L2PcInstance target, Skill skill) { if (!isStarted()) { return true; } // TvT is started final int sourcePlayerId = source.getObjectId(); final int targetPlayerId = target.getObjectId(); final boolean isSourceParticipant = isPlayerParticipant(sourcePlayerId); final boolean isTargetParticipant = isPlayerParticipant(targetPlayerId); // both players not participating if (!isSourceParticipant && !isTargetParticipant) { return true; } // one player not participating if (!(isSourceParticipant && isTargetParticipant)) { return false; } // players in the different teams ? if (getParticipantTeamId(sourcePlayerId) != getParticipantTeamId(targetPlayerId)) { if (!skill.isBad()) { return false; } } return true; }
/** * Is called when a player is killed<br> * <br> * * @param killerCharacter as L2Character<br> * @param killedPlayerInstance as L2PcInstance<br> */ public static void onKill(L2Character killerCharacter, L2PcInstance killedPlayerInstance) { if ((killedPlayerInstance == null) || !isStarted()) { return; } final byte killedTeamId = getParticipantTeamId(killedPlayerInstance.getObjectId()); if (killedTeamId == -1) { return; } new TvTEventTeleporter( killedPlayerInstance, _teams[killedTeamId].getCoordinates(), false, false); if (killerCharacter == null) { return; } L2PcInstance killerPlayerInstance = null; if ((killerCharacter instanceof L2PetInstance) || (killerCharacter instanceof L2ServitorInstance)) { killerPlayerInstance = ((L2Summon) killerCharacter).getOwner(); if (killerPlayerInstance == null) { return; } } else if (killerCharacter instanceof L2PcInstance) { killerPlayerInstance = (L2PcInstance) killerCharacter; } else { return; } final byte killerTeamId = getParticipantTeamId(killerPlayerInstance.getObjectId()); if ((killerTeamId != -1) && (killedTeamId != -1) && (killerTeamId != killedTeamId)) { final TvTEventTeam killerTeam = _teams[killerTeamId]; killerTeam.increasePoints(); final CreatureSay cs = new CreatureSay( killerPlayerInstance.getObjectId(), ChatType.WHISPER, killerPlayerInstance.getName(), "I have killed " + killedPlayerInstance.getName() + "!"); for (L2PcInstance playerInstance : _teams[killerTeamId].getParticipatedPlayers().values()) { if (playerInstance != null) { playerInstance.sendPacket(cs); } } // Notify to scripts. EventDispatcher.getInstance() .notifyEventAsync( new OnTvTEventKill(killerPlayerInstance, killedPlayerInstance, killerTeam)); } }
/** * Called on Appearing packet received (player finished teleporting) * * @param playerInstance */ public static void onTeleported(L2PcInstance playerInstance) { if (!isStarted() || (playerInstance == null) || !isPlayerParticipant(playerInstance.getObjectId())) { return; } if (playerInstance.isMageClass()) { if ((Config.TVT_EVENT_MAGE_BUFFS != null) && !Config.TVT_EVENT_MAGE_BUFFS.isEmpty()) { for (Entry<Integer, Integer> e : Config.TVT_EVENT_MAGE_BUFFS.entrySet()) { final Skill skill = SkillData.getInstance().getSkill(e.getKey(), e.getValue()); if (skill != null) { skill.applyEffects(playerInstance, playerInstance); } } } } else { if ((Config.TVT_EVENT_FIGHTER_BUFFS != null) && !Config.TVT_EVENT_FIGHTER_BUFFS.isEmpty()) { for (Entry<Integer, Integer> e : Config.TVT_EVENT_FIGHTER_BUFFS.entrySet()) { final Skill skill = SkillData.getInstance().getSkill(e.getKey(), e.getValue()); if (skill != null) { skill.applyEffects(playerInstance, playerInstance); } } } } }
private void exitInstance(L2PcInstance player) { final InstanceWorld inst = InstanceManager.getInstance().getWorld(player.getInstanceId()); if (inst instanceof NornilsWorld) { final NornilsWorld world = ((NornilsWorld) inst); world.removeAllowed(player.getObjectId()); teleportPlayer(player, EXIT_PPL, 0); } }
/** * Called when a player logs out<br> * <br> * * @param playerInstance as L2PcInstance<br> */ public static void onLogout(L2PcInstance playerInstance) { if ((playerInstance != null) && (isStarting() || isStarted() || isParticipating())) { if (removeParticipant(playerInstance.getObjectId())) { playerInstance.setXYZInvisible( (Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES[0] + Rnd.get(101)) - 50, (Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES[1] + Rnd.get(101)) - 50, Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES[2]); } } }
private static int highestLevelPcInstanceOf(Map<Integer, L2PcInstance> players) { int maxLevel = Integer.MIN_VALUE, maxLevelId = -1; for (L2PcInstance player : players.values()) { if (player.getLevel() >= maxLevel) { maxLevel = player.getLevel(); maxLevelId = player.getObjectId(); } } return maxLevelId; }
/** * Called when a player logs in<br> * <br> * * @param playerInstance as L2PcInstance<br> */ public static void onLogin(L2PcInstance playerInstance) { if ((playerInstance == null) || (!isStarting() && !isStarted())) { return; } final byte teamId = getParticipantTeamId(playerInstance.getObjectId()); if (teamId == -1) { return; } _teams[teamId].addPlayer(playerInstance); new TvTEventTeleporter(playerInstance, _teams[teamId].getCoordinates(), true, false); }
private final synchronized String enterInstance(L2Npc npc, L2PcInstance player) { InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player); if (world != null) { if (!(world instanceof NornilsWorld) || (world.getTemplateId() != TEMPLATE_ID)) { player.sendPacket( SystemMessageId .YOU_HAVE_ENTERED_ANOTHER_INSTANT_ZONE_THEREFORE_YOU_CANNOT_ENTER_CORRESPONDING_DUNGEON); return null; } // check for level difference again on reenter if ((player.getLevel() > INSTANCE_LVL_MAX) || (player.getLevel() < INSTANCE_LVL_MIN)) { final SystemMessage sm = SystemMessage.getSystemMessage( SystemMessageId.C1_S_LEVEL_DOES_NOT_CORRESPOND_TO_THE_REQUIREMENTS_FOR_ENTRY); sm.addPcName(player); player.sendPacket(sm); return null; } // check what instance still exist final Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId()); if (inst != null) { teleportPlayer(player, SPAWN_PPL, world.getInstanceId()); } return null; } // Creating new instance final String result = checkConditions(npc, player); if (!(result.equalsIgnoreCase("ok"))) { return result; } final int instanceId = InstanceManager.getInstance().createDynamicInstance("NornilsGarden.xml"); final Instance inst = InstanceManager.getInstance().getInstance(instanceId); inst.setName(InstanceManager.getInstance().getInstanceIdName(TEMPLATE_ID)); inst.setExitLoc(new Location(player)); inst.setAllowSummon(false); inst.setDuration(DURATION_TIME * 60000); inst.setEmptyDestroyTime(EMPTY_DESTROY_TIME * 60000); world = new NornilsWorld(); world.setInstanceId(instanceId); world.setTemplateId(TEMPLATE_ID); InstanceManager.getInstance().addWorld(world); _log.info( "Nornils Garden: started, Instance: " + instanceId + " created by player: " + player.getName()); prepareInstance((NornilsWorld) world); // and finally teleport party into instance final L2Party party = player.getParty(); if (party != null) { for (L2PcInstance partyMember : party.getMembers()) { world.addAllowed(partyMember.getObjectId()); teleportPlayer(partyMember, SPAWN_PPL, instanceId); } } return null; }
@Override public void runImpl() { final L2PcInstance activeChar = getClient().getActiveChar(); if ((activeChar == null) || !Config.ALLOW_MAIL || !Config.ALLOW_ATTACHMENTS) { return; } if (!getClient().getFloodProtectors().getTransaction().tryPerformAction("cancelpost")) { return; } final Message msg = MailManager.getInstance().getMessage(_msgId); if (msg == null) { return; } if (msg.getSenderId() != activeChar.getObjectId()) { Util.handleIllegalPlayerAction( activeChar, "Player " + activeChar.getName() + " tried to cancel not own post!", Config.DEFAULT_PUNISH); return; } if (!activeChar.isInsideZone(ZoneId.PEACE)) { activeChar.sendPacket(SystemMessageId.YOU_CANNOT_CANCEL_IN_A_NON_PEACE_ZONE_LOCATION); return; } if (activeChar.getActiveTradeList() != null) { activeChar.sendPacket(SystemMessageId.YOU_CANNOT_CANCEL_DURING_AN_EXCHANGE); return; } if (activeChar.hasItemRequest()) { activeChar.sendPacket( SystemMessageId.YOU_CANNOT_CANCEL_DURING_AN_ITEM_ENHANCEMENT_OR_ATTRIBUTE_ENHANCEMENT); return; } if (activeChar.getPrivateStoreType() != PrivateStoreType.NONE) { activeChar.sendPacket( SystemMessageId.YOU_CANNOT_CANCEL_BECAUSE_THE_PRIVATE_STORE_OR_WORKSHOP_IS_IN_PROGRESS); return; } if (!msg.hasAttachments()) { activeChar.sendPacket( SystemMessageId.YOU_CANNOT_CANCEL_SENT_MAIL_SINCE_THE_RECIPIENT_RECEIVED_IT); return; } final ItemContainer attachments = msg.getAttachments(); if ((attachments == null) || (attachments.getSize() == 0)) { activeChar.sendPacket( SystemMessageId.YOU_CANNOT_CANCEL_SENT_MAIL_SINCE_THE_RECIPIENT_RECEIVED_IT); return; } int weight = 0; int slots = 0; for (L2ItemInstance item : attachments.getItems()) { if (item == null) { continue; } if (item.getOwnerId() != activeChar.getObjectId()) { Util.handleIllegalPlayerAction( activeChar, "Player " + activeChar.getName() + " tried to get not own item from cancelled attachment!", Config.DEFAULT_PUNISH); return; } if (item.getItemLocation() != ItemLocation.MAIL) { Util.handleIllegalPlayerAction( activeChar, "Player " + activeChar.getName() + " tried to get items not from mail !", Config.DEFAULT_PUNISH); return; } if (item.getLocationSlot() != msg.getId()) { Util.handleIllegalPlayerAction( activeChar, "Player " + activeChar.getName() + " tried to get items from different attachment!", Config.DEFAULT_PUNISH); return; } weight += item.getCount() * item.getItem().getWeight(); if (!item.isStackable()) { slots += item.getCount(); } else if (activeChar.getInventory().getItemByItemId(item.getId()) == null) { slots++; } } if (!activeChar.getInventory().validateCapacity(slots)) { activeChar.sendPacket( SystemMessageId.YOU_COULD_NOT_CANCEL_RECEIPT_BECAUSE_YOUR_INVENTORY_IS_FULL); return; } if (!activeChar.getInventory().validateWeight(weight)) { activeChar.sendPacket( SystemMessageId.YOU_COULD_NOT_CANCEL_RECEIPT_BECAUSE_YOUR_INVENTORY_IS_FULL); return; } // Proceed to the transfer final InventoryUpdate playerIU = Config.FORCE_INVENTORY_UPDATE ? null : new InventoryUpdate(); for (L2ItemInstance item : attachments.getItems()) { if (item == null) { continue; } final long count = item.getCount(); final L2ItemInstance newItem = attachments.transferItem( attachments.getName(), item.getObjectId(), count, activeChar.getInventory(), activeChar, null); if (newItem == null) { return; } if (playerIU != null) { if (newItem.getCount() > count) { playerIU.addModifiedItem(newItem); } else { playerIU.addNewItem(newItem); } } final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_ACQUIRED_S2_S1); sm.addItemName(item.getId()); sm.addLong(count); activeChar.sendPacket(sm); } msg.removeAttachments(); // Send updated item list to the player if (playerIU != null) { activeChar.sendPacket(playerIU); } else { activeChar.sendPacket(new ItemList(activeChar, false)); } // Update current load status on player activeChar.sendPacket(new ExUserInfoInvenWeight(activeChar)); final L2PcInstance receiver = L2World.getInstance().getPlayer(msg.getReceiverId()); if (receiver != null) { final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANCELED_THE_SENT_MAIL); sm.addCharName(activeChar); receiver.sendPacket(sm); receiver.sendPacket(new ExChangePostState(true, _msgId, Message.DELETED)); } MailManager.getInstance().deleteMessageInDb(_msgId); activeChar.sendPacket(new ExChangePostState(false, _msgId, Message.DELETED)); activeChar.sendPacket(SystemMessageId.MAIL_SUCCESSFULLY_CANCELLED); }
public PcFreight(L2PcInstance owner) { _owner = owner; _ownerId = owner.getObjectId(); }