private TownService() { elyosTowns = DAOManager.getDAO(TownDAO.class).load(Race.ELYOS); asmosTowns = DAOManager.getDAO(TownDAO.class).load(Race.ASMODIANS); if (elyosTowns.size() == 0 && asmosTowns.size() == 0) { for (HousingLand land : DataManager.HOUSE_DATA.getLands()) { for (HouseAddress address : land.getAddresses()) { if (address.getTownId() == 0) { continue; } else { Race townRace = DataManager.NPC_DATA.getNpcTemplate(land.getManagerNpcId()).getTribe() == TribeClass.GENERAL ? Race.ELYOS : Race.ASMODIANS; if ((townRace == Race.ELYOS && !elyosTowns.containsKey(address.getTownId())) || (townRace == Race.ASMODIANS && !asmosTowns.containsKey(address.getTownId()))) { Town town = new Town(address.getTownId(), townRace); if (townRace == Race.ELYOS) { elyosTowns.put(town.getId(), town); } else { asmosTowns.put(town.getId(), town); } DAOManager.getDAO(TownDAO.class).store(town); } } } } } log.info("Loaded " + asmosTowns.size() + " elyos towns."); log.info("Loaded " + asmosTowns.size() + " asmodians towns."); }
/** * Stores newly created player * * @param player player to store * @return true if character was successful saved. */ public static boolean storeNewPlayer(Player player, String accountName, int accountId) { return DAOManager.getDAO(PlayerDAO.class) .saveNewPlayer(player.getCommonData(), accountId, accountName) && DAOManager.getDAO(PlayerAppearanceDAO.class).store(player) && DAOManager.getDAO(PlayerSkillListDAO.class).storeSkills(player) && DAOManager.getDAO(InventoryDAO.class).store(player.getDirtyItemsToUpdate()) && DAOManager.getDAO(PlayerTitleListDAO.class).storeTitles(player); }
/** * This method is called when player leaves the game, which includes just two cases: either player * goes back to char selection screen or it's leaving the game [closing client].<br> * <br> * <b><font color='red'>NOTICE: </font> This method is called only from {@link AionConnection} and * {@link CM_QUIT} and must not be called from anywhere else</b> * * @param player */ public static void playerLoggedOut(final Player player) { log.info( "Player logged out: " + player.getName() + " Account: " + player.getClientConnection().getAccount().getName()); player.onLoggedOut(); // Update prison timer if (player.isInPrison()) { long prisonTimer = System.currentTimeMillis() - player.getStartPrison(); prisonTimer = player.getPrisonTimer() - prisonTimer; player.setPrisonTimer(prisonTimer); log.debug("Update prison timer to " + prisonTimer / 1000 + " seconds !"); } // store current effects DAOManager.getDAO(PlayerEffectsDAO.class).storePlayerEffects(player); DAOManager.getDAO(ItemCooldownsDAO.class).storeItemCooldowns(player); DAOManager.getDAO(PlayerLifeStatsDAO.class).updatePlayerLifeStat(player); player.getEffectController().removeAllEffects(); player.getLifeStats().cancelAllTasks(); if (player.getLifeStats().isAlreadyDead()) TeleportService.moveToBindLocation(player, false); if (DuelService.getInstance().isDueling(player.getObjectId())) DuelService.getInstance().loseDuel(player); if (player.getSummon() != null) player.getSummon().getController().release(UnsummonType.LOGOUT); PunishmentService.stopPrisonTask(player, true); player.getCommonData().setOnline(false); player.getCommonData().setLastOnline(new Timestamp(System.currentTimeMillis())); player.setClientConnection(null); if (player.isLegionMember()) LegionService.getInstance().onLogout(player); if (player.isInGroup()) GroupService.getInstance().scheduleRemove(player); if (player.isInAlliance()) AllianceService.getInstance().onLogout(player); player.getController().delete(); DAOManager.getDAO(PlayerDAO.class).onlinePlayer(player, false); if (!GSConfig.DISABLE_CHAT_SERVER) ChatService.onPlayerLogout(player); storePlayer(player); player.getEquipment().setOwner(null); }
/** * Stores player data into db * * @param player */ private static void storePlayer(Player player) { DAOManager.getDAO(PlayerDAO.class).storePlayer(player); DAOManager.getDAO(PlayerSkillListDAO.class).storeSkills(player); DAOManager.getDAO(PlayerSettingsDAO.class).saveSettings(player); DAOManager.getDAO(PlayerQuestListDAO.class).store(player); DAOManager.getDAO(PlayerTitleListDAO.class).storeTitles(player); DAOManager.getDAO(AbyssRankDAO.class).storeAbyssRank(player); DAOManager.getDAO(PlayerPunishmentsDAO.class).storePlayerPunishments(player); DAOManager.getDAO(InventoryDAO.class).store(player.getDirtyItemsToUpdate()); DAOManager.getDAO(ItemStoneListDAO.class).save(player); DAOManager.getDAO(MailDAO.class).storeMailbox(player); }
@Override public void onRespawn() { super.onRespawn(); cancelTask(TaskId.DECAY); Npc owner = getOwner(); if (owner != null && owner.isCustom()) { DAOManager.getDAO(SpawnDAO.class) .setSpawned(owner.getSpawn().getSpawnId(), owner.getObjectId(), true); } // set state from npc templates if (owner.getObjectTemplate().getState() != 0) owner.setState(owner.getObjectTemplate().getState()); else owner.setState(CreatureState.NPC_IDLE); owner.getLifeStats().setCurrentHpPercent(100); owner.getLifeStats().setCurrentMpPercent(100); owner.getAi().handleEvent(Event.RESPAWNED); if (owner.getSpawn().getNpcFlyState() != 0) { owner.setState(CreatureState.FLYING); } }
/** * This method is called just after player logged in to the game.<br> * <br> * <b><font color='red'>NOTICE: </font> This method called only from {@link CM_ENTER_WORLD} and * must not be called from anywhere else.</b> * * @param player */ public static void playerLoggedIn(Player player) { log.info( "Player logged in: " + player.getName() + " Account: " + player.getClientConnection().getAccount().getName()); player.getCommonData().setOnline(true); DAOManager.getDAO(PlayerDAO.class).onlinePlayer(player, true); player.getFriendList().setStatus(Status.ONLINE); player.onLoggedIn(); }
/** * Initialize all helper services, that are not directly related to aion gs, which includes: * * <ul> * <li>Logging * <li>Database factory * <li>Thread pool * </ul> * * This method also initializes {@link Config} * * @throws Log4jInitializationError */ private static void initUtilityServicesAndConfig() throws Log4jInitializationError { // Set default uncaught exception handler Thread.setDefaultUncaughtExceptionHandler(new ThreadUncaughtExceptionHandler()); // First of all we must initialize logging LoggingService.init(); // init config Config.load(); // Second should be database factory DatabaseFactory.init(); // Initialize DAOs DAOManager.init(); // Initialize thread pools ThreadPoolManager.getInstance(); }
public void add(int emotionId, int dispearTime, boolean isNew) { if (emotions == null) { emotions = new HashMap<Integer, Emotion>(); } Emotion emotion = new Emotion(emotionId, dispearTime); emotions.put(emotionId, emotion); if (isNew) { if (emotion.getExpireTime() != 0) { ExpireTimerTask.getInstance().addTask(emotion, owner); } DAOManager.getDAO(PlayerEmotionListDAO.class).insertEmotion(owner, emotion); PacketSendUtility.sendPacket( owner, new SM_EMOTION_LIST((byte) 1, Collections.singletonList(emotion))); } }
public void onDespawn(boolean forced) { if (forced) cancelTask(TaskId.DECAY); Npc owner = getOwner(); if (owner == null || !owner.isSpawned()) return; if (owner != null && owner.isCustom()) { DAOManager.getDAO(SpawnDAO.class) .setSpawned( owner.getSpawn().getSpawnId(), owner.getSpawn().isNoRespawn(1) ? -1 : owner.getObjectId(), false); } owner.getAi().handleEvent(Event.DESPAWN); World.getInstance().despawn(owner); }
/** * Loads item stones from DB for each item in a list if item is ARMOR or WEAPON * * @param itemList */ public void loadItemStones(Player player) { List<Item> itemList = new ArrayList<Item>(); itemList.addAll(player.getStorage(StorageType.CUBE.getId()).getStorageItems()); itemList.addAll(player.getStorage(StorageType.REGULAR_WAREHOUSE.getId()).getStorageItems()); itemList.addAll(player.getStorage(StorageType.ACCOUNT_WAREHOUSE.getId()).getStorageItems()); itemList.addAll(player.getEquipment().getEquippedItems()); for (Item item : itemList) { if (item.getItemTemplate().isArmor() || item.getItemTemplate().isWeapon()) { item.setItemStones(DAOManager.getDAO(ItemStoneListDAO.class).load(item.getObjectId())); // if item equipped - apply stats of item stone if (item.isEquipped() && item.getEquipmentSlot() != ItemSlot.MAIN_OFF_HAND.getSlotIdMask() && item.getEquipmentSlot() != ItemSlot.SUB_OFF_HAND.getSlotIdMask()) { for (ItemStone itemStone : item.getItemStones()) { ItemEquipmentListener.addStoneStats(itemStone, player.getGameStats()); } } } } }
/** * Remove macro with specified index from specified player * * @param player Player * @param macroOrder Macro order index */ public static void removeMacro(Player player, int macroOrder) { if (player.getMacroList().removeMacro(macroOrder)) { DAOManager.getDAO(PlayerMacrossesDAO.class).deleteMacro(player.getObjectId(), macroOrder); } }
/** * Add macro for player * * @param player Player * @param macroOrder Macro order * @param macroXML Macro XML */ public static void addMacro(Player player, int macroOrder, String macroXML) { if (player.getMacroList().addMacro(macroOrder, macroXML)) { DAOManager.getDAO(PlayerMacrossesDAO.class) .addMacro(player.getObjectId(), macroOrder, macroXML); } }
/** * @param objectId * @param creationDate */ public static void storeCreationTime(int objectId, Timestamp creationDate) { DAOManager.getDAO(PlayerDAO.class).storeCreationTime(objectId, creationDate); }
/** * Updates deletion time in database * * @param accData PlayerAccountData */ private static void storeDeletionTime(PlayerAccountData accData) { DAOManager.getDAO(PlayerDAO.class) .updateDeletionTime( accData.getPlayerCommonData().getPlayerObjId(), accData.getDeletionDate()); }
/** * Completely removes player from database * * @param playerId id of player to delete from db */ public static void deletePlayerFromDB(int playerId) { DAOManager.getDAO(PlayerDAO.class).deletePlayer(playerId); DAOManager.getDAO(InventoryDAO.class).deletePlayerItems(playerId); DAOManager.getDAO(PlayerLifeStatsDAO.class).deletePlayerLifeStat(playerId); }
/** * Retuns {@link com.aionemu.gameserver.dao.TaskFromDBDAO} , just a shortcut * * @return {@link com.aionemu.gameserver.dao.TaskFromDBDAO} */ private static TaskFromDBDAO getDAO() { return DAOManager.getDAO(TaskFromDBDAO.class); }
/** * 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); LegionMember legionMember = LegionService.getInstance().getLegionMember(player.getObjectId()); if (legionMember != null) player.setLegionMember(legionMember); if (GroupService.getInstance().isGroupMember(playerObjId)) GroupService.getInstance().setGroup(player); if (AllianceService.getInstance().isAllianceMember(playerObjId)) AllianceService.getInstance().setAlliance(player); 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); PlayerStatsData playerStatsData = DataManager.PLAYER_STATS_DATA; player.setPlayerStatsTemplate(playerStatsData.getTemplate(player)); player.setGameStats(new PlayerGameStats(playerStatsData, player)); Equipment equipment = DAOManager.getDAO(InventoryDAO.class).loadEquipment(player); ItemService.loadItemStones(equipment.getEquippedItemsWithoutStigma()); equipment.setOwner(player); player.setEquipment(equipment); player.setLifeStats(new PlayerLifeStats(player)); player.setEffectController(new PlayerEffectController(player)); player.setFlyController(new FlyController(player)); player.setReviveController(new ReviveController(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(player, player.getObjectId(), StorageType.CUBE); ItemService.loadItemStones(inventory.getStorageItems()); player.setStorage(inventory, StorageType.CUBE); Storage warehouse = DAOManager.getDAO(InventoryDAO.class) .loadStorage(player, player.getObjectId(), StorageType.REGULAR_WAREHOUSE); ItemService.loadItemStones(warehouse.getStorageItems()); 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); ItemService.restoreKinah(player); // update passive stats after effect controller, stats and equipment are initialized player.getController().updatePassiveStats(); // load saved effects DAOManager.getDAO(PlayerEffectsDAO.class).loadPlayerEffects(player); // load item cooldowns DAOManager.getDAO(ItemCooldownsDAO.class).loadItemCooldowns(player); if (player.getCommonData().getTitleId() > 0) { TitleChangeListener.onTitleChange( player.getGameStats(), player.getCommonData().getTitleId(), true); } player.getGameStats().recomputeStats(); DAOManager.getDAO(PlayerLifeStatsDAO.class).loadPlayerLifeStat(player); // analyze current instance InstanceService.onPlayerLogin(player); if (CacheConfig.CACHE_PLAYERS) playerCache.put(playerObjId, player); return player; }
/** * Returns {@link com.aionemu.loginserver.dao.AccountTimeDAO}, just a shortcut * * @return {@link com.aionemu.loginserver.dao.AccountTimeDAO} */ private static AccountTimeDAO getAccountTimeDAO() { return DAOManager.getDAO(AccountTimeDAO.class); }
public void remove(int emotionId) { emotions.remove(emotionId); DAOManager.getDAO(PlayerEmotionListDAO.class).deleteEmotion(owner.getObjectId(), emotionId); PacketSendUtility.sendPacket(owner, new SM_EMOTION_LIST((byte) 0, getEmotions())); }
/** * Checks if name is already taken or not * * @param name character name * @return true if is free, false in other case */ public static boolean isFreeName(String name) { return !DAOManager.getDAO(PlayerDAO.class).isNameUsed(name); }