private static void port(Player requester, PortalTemplate portalTemplate, boolean reenter) { WorldMapInstance instance = null; int worldId = TeleportService.getExitPointByRace(portalTemplate, requester.getRace()).getMapId(); if (portalTemplate.isInstance()) { instance = InstanceService.getNextAvailableInstance(worldId); InstanceService.registerPlayerWithInstance(instance, requester); transfer(requester, portalTemplate, instance, reenter); } else { /*WorldMap worldMap = World.getInstance().getWorldMap(worldId); if (worldMap == null) { log.warn("There is no registered map with id " + worldId); return; } instance = worldMap.getWorldMapInstance();*/ easyTransfer(requester, portalTemplate, reenter); } }
private static void analyzePortation(final Player player, PortalTemplate portalTemplate) { boolean instanceTitleReq = false; boolean instanceLevelReq = false; boolean instanceRaceReq = false; boolean instanceQuestReq = false; boolean instanceGroupReq = false; int instanceCooldownRate = 0; ExitPoint exit = TeleportService.getExitPointByRace(portalTemplate, player.getRace()); if (exit == null) { return; } int mapId = exit.getMapId(); if (player.getAccessLevel() < AdminConfig.INSTANCE_REQ) { instanceTitleReq = !player.havePermission(MembershipConfig.INSTANCES_TITLE_REQ); instanceLevelReq = !player.havePermission(MembershipConfig.INSTANCES_LEVEL_REQ); instanceRaceReq = !player.havePermission(MembershipConfig.INSTANCES_RACE_REQ); instanceQuestReq = !player.havePermission(MembershipConfig.INSTANCES_QUEST_REQ); instanceGroupReq = !player.havePermission(MembershipConfig.INSTANCES_GROUP_REQ); instanceCooldownRate = InstanceService.getInstanceRate(player, mapId); } if (portalTemplate.getKinahCount() != 0) { if (player.getInventory().getKinah() >= portalTemplate.getKinahCount()) player.getInventory().decreaseKinah(portalTemplate.getKinahCount()); else { PacketSendUtility.sendPacket( player, SM_SYSTEM_MESSAGE.STR_CANNOT_REGISTER_RESURRECT_POINT_NOT_ENOUGH_FEE); return; } } if (portalTemplate.getInstanceSiegeId() != 0) { int LocationId = portalTemplate.getInstanceSiegeId(); FortressLocation loc = SiegeService.getInstance().getFortress(LocationId); if (loc != null) if (loc.getRace().getRaceId() != player.getRace().getRaceId() && instanceRaceReq) { PacketSendUtility.sendPacket( player, SM_SYSTEM_MESSAGE.STR_MOVE_PORTAL_ERROR_INVALID_RACE); return; } } if (portalTemplate.getIdTitle() != 0 && player.getCommonData().getTitleId() != portalTemplate.getIdTitle() && instanceTitleReq) return; if (!portalTemplate.existsExitForRace(player.getRace()) && instanceRaceReq) { PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_MOVE_PORTAL_ERROR_INVALID_RACE); return; } if (!(portalTemplate.isInstance() && DataManager.INSTANCE_COOLTIME_DATA.getInstanceCooltimeByWorldId(mapId) != null && DataManager.INSTANCE_COOLTIME_DATA .getInstanceCooltimeByWorldId(mapId) .getCanEnterMentor() && player.isMentor())) { if (((portalTemplate.getMaxLevel() != 0 && player.getLevel() > portalTemplate.getMaxLevel()) || player.getLevel() < portalTemplate.getMinLevel()) && instanceLevelReq) { PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_MSG_CANT_INSTANCE_ENTER_LEVEL); return; } } PlayerGroup group = player.getPlayerGroup2(); PlayerAlliance allianceGroup = player.getPlayerAlliance2(); switch (portalTemplate.getPlayerSize()) { case 12: case 24: case 48: if (allianceGroup == null && instanceGroupReq) { // to do sniff PacketSendUtility.sendMessage(player, "You must be in Alliance."); return; } break; case 6: if (group == null && instanceGroupReq) { PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_MSG_ENTER_ONLY_PARTY_DON); return; } break; } if (instanceQuestReq && portalTemplate.needQuest()) { int[][] quests = portalTemplate.getQuests(); boolean present = false; for (int i = 0; i < quests.length; i++) { // TEMP: please remove when Quest 1044 get fixed if (quests[i][0] == 1044) { present = true; break; } final QuestState qs = player.getQuestStateList().getQuestState(quests[i][0]); if (qs != null) { if ((quests[i][1] == 0 && qs.getStatus() == QuestStatus.COMPLETE) || (quests[i][1] != 0 && (qs.getStatus() == QuestStatus.COMPLETE || qs.getQuestVarById(0) >= quests[i][1]))) { present = true; break; } } } if (!present) { PacketSendUtility.sendMessage(player, "You must complete the entrance quest."); return; } } if (CustomConfig.INSTANCE_KEYCHECK) { if (portalTemplate.getPortalItem() != null && !portalTemplate.getPortalItem().isEmpty()) { for (PortalItem pi : portalTemplate.getPortalItem()) { if (!player.getInventory().decreaseByItemId(pi.getItemid(), pi.getQuantity())) { // TODO: find correct message PacketSendUtility.sendPacket( player, SM_SYSTEM_MESSAGE.STR_CANNOT_OPEN_DOOR_NEED_KEY_ITEM); return; } } } } boolean reenter = false; int useDelay = 0; int instanceCooldown = DataManager.INSTANCE_COOLTIME_DATA.getInstanceEntranceCooltime(mapId); if (instanceCooldownRate > 0) { useDelay = instanceCooldown / instanceCooldownRate; } WorldMapInstance instance = null; if (player.getPortalCooldownList().isPortalUseDisabled(mapId) && useDelay > 0) { switch (portalTemplate.getPlayerSize()) { case 6: // group if (player.getPlayerGroup2() != null) { instance = InstanceService.getRegisteredInstance(mapId, player.getPlayerGroup2().getTeamId()); } break; case 12: // alliance case 24: case 48: if (player.isInAlliance2()) { instance = InstanceService.getRegisteredInstance( mapId, player.getPlayerAlliance2().getTeamId()); } break; default: // solo instance = InstanceService.getRegisteredInstance(mapId, player.getObjectId()); break; } if (instance == null) { PacketSendUtility.sendPacket( player, SM_SYSTEM_MESSAGE.STR_MSG_CANNOT_MAKE_INSTANCE_COOL_TIME); return; } else { if (!instance.isRegistered(player.getObjectId())) { PacketSendUtility.sendPacket( player, SM_SYSTEM_MESSAGE.STR_MSG_CANNOT_MAKE_INSTANCE_COOL_TIME); return; } else { reenter = true; log.debug(player.getName() + "has been in intance and also have cd, can reenter."); } } } else { log.debug( player.getName() + "doesn't have cd of this instance, can enter and will be registed to this intance"); } switch (portalTemplate.getPlayerSize()) { case 6: if (group != null || !instanceGroupReq) { // If there is a group (whatever group requirement exists or not)... if (group != null) { instance = InstanceService.getRegisteredInstance(mapId, group.getTeamId()); } // But if there is no group (and solo is enabled, of course) else { instance = InstanceService.getRegisteredInstance(mapId, player.getObjectId()); } // No instance (for group), group on and default requirement off if (instance == null && group != null && !instanceGroupReq) { // For each player from group for (Player member : group.getMembers()) { // Get his instance instance = InstanceService.getRegisteredInstance(mapId, member.getObjectId()); // If some player is soloing and I found no one else yet, I get his instance if (instance != null) { break; } } // No solo instance found if (instance == null) instance = registerGroup(group, mapId); } // No instance and default requirement on = Group on else if (instance == null && instanceGroupReq) { instance = registerGroup(group, mapId); } // No instance, default requirement off, no group = Register new instance with player ID else if (instance == null && !instanceGroupReq && group == null) { instance = InstanceService.getNextAvailableInstance(mapId); } transfer(player, portalTemplate, instance, reenter); } break; case 12: case 24: case 48: if (allianceGroup != null || !instanceGroupReq) { if (allianceGroup != null) { instance = InstanceService.getRegisteredInstance(mapId, allianceGroup.getObjectId()); } else { instance = InstanceService.getRegisteredInstance(mapId, player.getObjectId()); } if (instance == null && allianceGroup != null && !instanceGroupReq) { for (Player member : allianceGroup.getMembers()) { instance = InstanceService.getRegisteredInstance(mapId, member.getObjectId()); if (instance != null) { break; } } if (instance == null) { instance = registerAlliance(allianceGroup, mapId); } } else if (instance == null && instanceGroupReq) { instance = registerAlliance(allianceGroup, mapId); } else if (instance == null && !instanceGroupReq && allianceGroup == null) { instance = InstanceService.getNextAvailableInstance(mapId); } if (instance.getPlayersInside().size() < portalTemplate.getPlayerSize()) { transfer(player, portalTemplate, instance, reenter); } } break; default: // If there is a group (whatever group requirement exists or not)... if (group != null && !instanceGroupReq) { instance = InstanceService.getRegisteredInstance(mapId, group.getTeamId()); } // But if there is no group, go to solo else { instance = InstanceService.getRegisteredInstance(mapId, player.getObjectId()); } // No group instance, group on and default requirement off if (instance == null && group != null && !instanceGroupReq) { // For each player from group for (Player member : group.getMembers()) { // Get his instance instance = InstanceService.getRegisteredInstance(mapId, member.getObjectId()); // If some player is soloing and I found no one else yet, I get his instance if (instance != null) { break; } } // No solo instance found if (instance == null && portalTemplate.isInstance()) instance = registerGroup(group, mapId); } // if already registered - just teleport if (instance != null) { reenter = true; transfer(player, portalTemplate, instance, reenter); return; } port(player, portalTemplate, reenter); break; } }
private static WorldMapInstance registerAlliance(PlayerAlliance group, int mapId) { WorldMapInstance instance = InstanceService.getNextAvailableInstance(mapId); InstanceService.registerAllianceWithInstance(instance, group); return instance; }