private static void transfer( Player player, PortalTemplate portalTemplate, WorldMapInstance instance, boolean reenter) { ExitPoint exitPoint = TeleportService.getExitPointByRace(portalTemplate, player.getRace()); player.setInstanceStartPos(exitPoint.getX(), exitPoint.getY(), exitPoint.getZ()); InstanceService.registerPlayerWithInstance(instance, player); TeleportService.teleportTo( player, exitPoint.getMapId(), instance.getInstanceId(), exitPoint.getX(), exitPoint.getY(), exitPoint.getZ(), 3000, true); int instanceCooldownRate = InstanceService.getInstanceRate(player, exitPoint.getMapId()); int useDelay = 0; int instanceCoolTime = DataManager.INSTANCE_COOLTIME_DATA.getInstanceEntranceCooltime(instance.getMapId()); if (instanceCooldownRate > 0) { useDelay = instanceCoolTime * 60 * 1000 / instanceCooldownRate; } if (useDelay > 0 && !reenter) { player.getPortalCooldownList().addPortalCooldown(exitPoint.getMapId(), useDelay); } }
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; }
/** * Returns the player with given objId (if such player exists) * * @param playerObjId * @param account * @return Player */ public static Player getPlayer(int playerObjId, Account account) { Player player = playerCache.get(playerObjId); if (player != null) return player; /** Player common data and appearance should be already loaded in account */ PlayerAccountData playerAccountData = account.getPlayerAccountData(playerObjId); PlayerCommonData pcd = playerAccountData.getPlayerCommonData(); PlayerAppearance appearance = playerAccountData.getAppereance(); player = new Player(new PlayerController(), pcd, appearance, account); LegionMember legionMember = LegionService.getInstance().getLegionMember(player.getObjectId()); if (legionMember != null) player.setLegionMember(legionMember); MacroList macroses = DAOManager.getDAO(PlayerMacrossesDAO.class).restoreMacrosses(playerObjId); player.setMacroList(macroses); player.setSkillList(DAOManager.getDAO(PlayerSkillListDAO.class).loadSkillList(playerObjId)); player.setKnownlist(new KnownList(player)); player.setFriendList(DAOManager.getDAO(FriendListDAO.class).load(player)); player.setBlockList(DAOManager.getDAO(BlockListDAO.class).load(player)); player.setTitleList(DAOManager.getDAO(PlayerTitleListDAO.class).loadTitleList(playerObjId)); DAOManager.getDAO(PlayerSettingsDAO.class).loadSettings(player); DAOManager.getDAO(AbyssRankDAO.class).loadAbyssRank(player); DAOManager.getDAO(PlayerNpcFactionsDAO.class).loadNpcFactions(player); DAOManager.getDAO(MotionDAO.class).loadMotionList(player); player.setVars(DAOManager.getDAO(PlayerVarsDAO.class).load(player.getObjectId())); Equipment equipment = DAOManager.getDAO(InventoryDAO.class).loadEquipment(player); ItemService.loadItemStones(equipment.getEquippedItemsWithoutStigma()); equipment.setOwner(player); player.setEquipment(equipment); player.setEffectController(new PlayerEffectController(player)); player.setFlyController(new FlyController(player)); PlayerStatFunctions.addPredefinedStatFunctions(player); player.setQuestStateList(DAOManager.getDAO(PlayerQuestListDAO.class).load(player)); player.setRecipeList(DAOManager.getDAO(PlayerRecipesDAO.class).load(player.getObjectId())); /** Account warehouse should be already loaded in account */ Storage accWarehouse = account.getAccountWarehouse(); player.setStorage(accWarehouse, StorageType.ACCOUNT_WAREHOUSE); Storage inventory = DAOManager.getDAO(InventoryDAO.class).loadStorage(playerObjId, StorageType.CUBE); ItemService.loadItemStones(inventory.getItems()); player.setStorage(inventory, StorageType.CUBE); for (int petBagId = 32; petBagId < 36; petBagId++) { Storage petBag = DAOManager.getDAO(InventoryDAO.class) .loadStorage(playerObjId, StorageType.getStorageTypeById(petBagId)); ItemService.loadItemStones(petBag.getItems()); player.setStorage(petBag, StorageType.getStorageTypeById(petBagId)); } Storage warehouse = DAOManager.getDAO(InventoryDAO.class) .loadStorage(playerObjId, StorageType.REGULAR_WAREHOUSE); ItemService.loadItemStones(warehouse.getItems()); player.setStorage(warehouse, StorageType.REGULAR_WAREHOUSE); /** Apply equipment stats (items and manastones were loaded in account) */ player.getEquipment().onLoadApplyEquipmentStats(); DAOManager.getDAO(PlayerPunishmentsDAO.class) .loadPlayerPunishments(player, PunishmentType.PRISON); DAOManager.getDAO(PlayerPunishmentsDAO.class) .loadPlayerPunishments(player, PunishmentType.GATHER); // update passive stats after effect controller, stats and equipment are initialized player.getController().updatePassiveStats(); // load saved effects DAOManager.getDAO(PlayerEffectsDAO.class).loadPlayerEffects(player); // load saved player cooldowns DAOManager.getDAO(PlayerCooldownsDAO.class).loadPlayerCooldowns(player); // load item cooldowns DAOManager.getDAO(ItemCooldownsDAO.class).loadItemCooldowns(player); // load portal cooldowns DAOManager.getDAO(PortalCooldownsDAO.class).loadPortalCooldowns(player); // load bind point DAOManager.getDAO(PlayerBindPointDAO.class).loadBindPoint(player); // load craft cooldowns DAOManager.getDAO(CraftCooldownsDAO.class).loadCraftCooldowns(player); if (player.getCommonData().getTitleId() > 0) { TitleChangeListener.onTitleChange( player.getGameStats(), player.getCommonData().getTitleId(), true); } DAOManager.getDAO(PlayerLifeStatsDAO.class).loadPlayerLifeStat(player); DAOManager.getDAO(PlayerEmotionListDAO.class).loadEmotions(player); // analyze current instance InstanceService.onPlayerLogin(player); if (CacheConfig.CACHE_PLAYERS) playerCache.put(playerObjId, player); return player; }