/** * This method is used for creating new players * * @param playerCommonData * @param playerAppearance * @return Player */ public static Player newPlayer( PlayerCommonData playerCommonData, PlayerAppearance playerAppearance) { PlayerInitialData playerInitialData = DataManager.PLAYER_INITIAL_DATA; LocationData ld = playerInitialData.getSpawnLocation(playerCommonData.getRace()); WorldPosition position = World.getInstance() .createPosition(ld.getMapId(), ld.getX(), ld.getY(), ld.getZ(), ld.getHeading()); playerCommonData.setPosition(position); Player newPlayer = new Player(new PlayerController(), playerCommonData, playerAppearance); // Starting skills SkillLearnService.addNewSkills(newPlayer, true); // Starting items PlayerCreationData playerCreationData = playerInitialData.getPlayerCreationData(playerCommonData.getPlayerClass()); List<ItemType> items = playerCreationData.getItems(); Storage playerInventory = new Storage(StorageType.CUBE); Storage regularWarehouse = new Storage(StorageType.REGULAR_WAREHOUSE); Storage accountWarehouse = new Storage(StorageType.ACCOUNT_WAREHOUSE); Equipment equipment = new Equipment(newPlayer); newPlayer.setStorage(playerInventory, StorageType.CUBE); newPlayer.setStorage(regularWarehouse, StorageType.REGULAR_WAREHOUSE); newPlayer.setStorage(accountWarehouse, StorageType.ACCOUNT_WAREHOUSE); newPlayer.setEquipment(equipment); newPlayer.setMailbox(new Mailbox()); for (ItemType itemType : items) { int itemId = itemType.getTemplate().getTemplateId(); Item item = ItemService.newItem(itemId, itemType.getCount()); if (item == null) continue; // When creating new player - all equipment that has slot values will be equipped // Make sure you will not put into xml file more items than possible to equip. ItemTemplate itemTemplate = item.getItemTemplate(); item.setOwnerId(newPlayer.getObjectId()); if (itemTemplate.isArmor() || itemTemplate.isWeapon()) { item.setEquipped(true); List<ItemSlot> itemSlots = ItemSlot.getSlotsFor(itemTemplate.getItemSlot()); item.setEquipmentSlot(itemSlots.get(0).getSlotIdMask()); equipment.onLoadHandler(item); } else ItemService.onLoadHandler(newPlayer, newPlayer.getInventory(), item); } equipment.onLoadApplyEquipmentStats(); /** Mark inventory and equipment as UPDATE_REQUIRED to be saved during character creation */ playerInventory.setPersistentState(PersistentState.UPDATE_REQUIRED); equipment.setPersistentState(PersistentState.UPDATE_REQUIRED); return newPlayer; }
public void moveItem( Player player, int itemObjId, int sourceStorageType, int destinationStorageType, int slot) { Storage sourceStorage = player.getStorage(sourceStorageType); Item item = player.getStorage(sourceStorageType).getItemByObjId(itemObjId); if (item == null) return; item.setEquipmentSlot(slot); if (sourceStorageType == destinationStorageType) return; Storage destinationStorage = player.getStorage(destinationStorageType); List<Item> existingItems = destinationStorage.getItemsByItemId(item.getItemTemplate().getTemplateId()); int count = item.getItemCount(); int maxStackCount = item.getItemTemplate().getMaxStackCount(); for (Item existingItem : existingItems) { if (count == 0) break; int freeCount = maxStackCount - existingItem.getItemCount(); if (count <= freeCount) { existingItem.increaseItemCount(count); count = 0; sendDeleteItemPacket(player, sourceStorageType, item.getObjectId()); sourceStorage.removeFromBag(item, true); } else { existingItem.increaseItemCount(freeCount); count -= freeCount; } sendStorageUpdatePacket(player, destinationStorageType, existingItem); } while (!destinationStorage.isFull() && count > 0) { // item count still more than maxStack value if (count > maxStackCount) { count -= maxStackCount; Item newitem = newItem(item.getItemTemplate().getTemplateId(), maxStackCount); newitem = destinationStorage.putToBag(newitem); sendStorageUpdatePacket(player, destinationStorageType, newitem); } else { item.setItemCount(count); sourceStorage.removeFromBag(item, false); sendDeleteItemPacket(player, sourceStorageType, item.getObjectId()); Item newitem = destinationStorage.putToBag(item); sendStorageUpdatePacket(player, destinationStorageType, newitem); count = 0; } } if (count > 0) // if storage is full and some items left { item.setItemCount(count); sendUpdateItemPacket(player, sourceStorageType, item); } }
public void switchStoragesItems( Player player, int sourceStorageType, int sourceItemObjId, int replaceStorageType, int replaceItemObjId) { Storage sourceStorage = player.getStorage(sourceStorageType); Storage replaceStorage = player.getStorage(replaceStorageType); Item sourceItem = sourceStorage.getItemByObjId(sourceItemObjId); if (sourceItem == null) return; Item replaceItem = replaceStorage.getItemByObjId(replaceItemObjId); if (replaceItem == null) return; int sourceSlot = sourceItem.getEquipmentSlot(); int replaceSlot = replaceItem.getEquipmentSlot(); sourceItem.setEquipmentSlot(replaceSlot); replaceItem.setEquipmentSlot(sourceSlot); sourceStorage.removeFromBag(sourceItem, false); replaceStorage.removeFromBag(replaceItem, false); Item newSourceItem = sourceStorage.putToBag(replaceItem); Item newReplaceItem = replaceStorage.putToBag(sourceItem); sendDeleteItemPacket(player, sourceStorageType, sourceItemObjId); sendStorageUpdatePacket(player, sourceStorageType, newSourceItem); sendDeleteItemPacket(player, replaceStorageType, replaceItemObjId); sendStorageUpdatePacket(player, replaceStorageType, newReplaceItem); }
/** * Used to split item into 2 items * * @param player * @param itemObjId * @param splitAmount * @param slotNum * @param sourceStorageType * @param desetinationStorageType */ public void splitItem( Player player, int itemObjId, int splitAmount, int slotNum, int sourceStorageType, int destinationStorageType) { Storage sourceStorage = player.getStorage(sourceStorageType); Storage destinationStorage = player.getStorage(destinationStorageType); Item itemToSplit = sourceStorage.getItemByObjId(itemObjId); if (itemToSplit == null) { itemToSplit = sourceStorage.getKinahItem(); if (itemToSplit.getObjectId() != itemObjId || itemToSplit == null) { log.warn( String.format( "CHECKPOINT: attempt to split null item %d %d %d", itemObjId, splitAmount, slotNum)); return; } } // To move kinah from inventory to warehouse and vise versa client using split item packet if (itemToSplit.getItemTemplate().isKinah()) { moveKinah(player, sourceStorage, splitAmount); return; } int oldItemCount = itemToSplit.getItemCount() - splitAmount; if (itemToSplit.getItemCount() < splitAmount || oldItemCount == 0) return; Item newItem = newItem(itemToSplit.getItemTemplate().getTemplateId(), splitAmount); newItem.setEquipmentSlot(slotNum); if (destinationStorage.putToBag(newItem) != null) { itemToSplit.decreaseItemCount(splitAmount); List<Item> itemsToUpdate = new ArrayList<Item>(); itemsToUpdate.add(newItem); sendStorageUpdatePacket(player, destinationStorageType, itemsToUpdate.get(0)); sendUpdateItemPacket(player, sourceStorageType, itemToSplit); } else { releaseItemId(newItem); } }
/** * Used to merge 2 items in inventory * * @param player * @param sourceItemObjId * @param itemAmount * @param destinationObjId */ public void mergeItems( Player player, int sourceItemObjId, int itemAmount, int destinationObjId, int sourceStorageType, int destinationStorageType) { if (itemAmount == 0) return; Storage sourceStorage = player.getStorage(sourceStorageType); Storage destinationStorage = player.getStorage(destinationStorageType); Item sourceItem = sourceStorage.getItemByObjId(sourceItemObjId); Item destinationItem = destinationStorage.getItemByObjId(destinationObjId); if (sourceItem == null || destinationItem == null) return; // Invalid object id provided if (sourceItem.getItemTemplate().getTemplateId() != destinationItem.getItemTemplate().getTemplateId()) return; // Invalid item type if (sourceItem.getItemCount() < itemAmount) return; // Invalid item amount if (sourceItem.getItemCount() == itemAmount) { destinationItem.increaseItemCount(itemAmount); sourceStorage.removeFromBag(sourceItem, true); sendDeleteItemPacket(player, sourceStorageType, sourceItem.getObjectId()); sendUpdateItemPacket(player, destinationStorageType, destinationItem); } else if (sourceItem.getItemCount() > itemAmount) { sourceItem.decreaseItemCount(itemAmount); destinationItem.increaseItemCount(itemAmount); sendUpdateItemPacket(player, sourceStorageType, sourceItem); sendUpdateItemPacket(player, destinationStorageType, destinationItem); } else return; // cant happen in theory, but... }
/** * Adds item count to player inventory I moved this method to service cause right implementation * of it is critical to server operation and could cause starvation of object ids. * * <p>This packet will send necessary packets to client (initialize used only from quest engine * * @param player * @param itemId * @param count - amount of item that were not added to player's inventory */ public int addItem(Player player, int itemId, int count, boolean isQuestItem) { Storage inventory = player.getInventory(); ItemTemplate itemTemplate = DataManager.ITEM_DATA.getItemTemplate(itemId); if (itemTemplate == null) return count; int maxStackCount = itemTemplate.getMaxStackCount(); if (itemId == ItemId.KINAH.value()) { inventory.increaseKinah(count); return 0; } else { /** Increase count of existing items */ List<Item> existingItems = inventory.getAllItemsByItemId( itemId); // look for existing in equipment. need for power shards. for (Item existingItem : existingItems) { if (count == 0) break; int freeCount = maxStackCount - existingItem.getItemCount(); if (count <= freeCount) { existingItem.increaseItemCount(count); count = 0; } else { existingItem.increaseItemCount(freeCount); count -= freeCount; } updateItem(player, existingItem, false); } /** Create new stacks */ while (!inventory.isFull() && count > 0) { // item count still more than maxStack value if (count > maxStackCount) { Item item = newItem(itemId, maxStackCount); item.setQuest(isQuestItem); count -= maxStackCount; inventory.putToBag(item); updateItem(player, item, true); } else { Item item = newItem(itemId, count); item.setQuest(isQuestItem); inventory.putToBag(item); updateItem(player, item, true); count = 0; } } return count; } }
/** * 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; }
/** {@inheritDoc} */ @Override protected void runImpl() { AionConnection client = getConnection(); Account account = client.getAccount(); PlayerAccountData playerAccData = client.getAccount().getPlayerAccountData(objectId); if (playerAccData == null) { // Somebody wanted to login on character that is not at his account return; } Player player = PlayerService.getPlayer(objectId, account); if (player != null && client.setActivePlayer(player)) { player.setClientConnection(client); /* * Store player into World. */ World.getInstance().storeObject(player); sendPacket(new SM_SKILL_LIST(player)); StigmaService.onPlayerLogin(player); if (player.getSkillCoolDowns() != null) sendPacket(new SM_SKILL_COOLDOWN(player.getSkillCoolDowns())); if (player.getItemCoolDowns() != null) sendPacket(new SM_ITEM_COOLDOWN(player.getItemCoolDowns())); sendPacket(new SM_QUEST_LIST(player)); sendPacket(new SM_RECIPE_LIST(player.getRecipeList().getRecipeList())); /* * Needed */ sendPacket(new SM_ENTER_WORLD_CHECK()); byte[] uiSettings = player.getPlayerSettings().getUiSettings(); byte[] shortcuts = player.getPlayerSettings().getShortcuts(); if (uiSettings != null) sendPacket(new SM_UI_SETTINGS(uiSettings, 0)); if (shortcuts != null) sendPacket(new SM_UI_SETTINGS(shortcuts, 1)); // Cubesize limit set in inventory. int cubeSize = player.getCubeSize(); player.getInventory().setLimit(27 + cubeSize * 9); // items Storage inventory = player.getInventory(); List<Item> equipedItems = player.getEquipment().getEquippedItems(); if (equipedItems.size() != 0) { sendPacket(new SM_INVENTORY_INFO(player.getEquipment().getEquippedItems(), cubeSize)); } List<Item> unequipedItems = inventory.getAllItems(); int itemsSize = unequipedItems.size(); if (itemsSize != 0) { int index = 0; while (index + 10 < itemsSize) { sendPacket(new SM_INVENTORY_INFO(unequipedItems.subList(index, index + 10), cubeSize)); index += 10; } sendPacket(new SM_INVENTORY_INFO(unequipedItems.subList(index, itemsSize), cubeSize)); } sendPacket(new SM_INVENTORY_INFO()); PlayerService.playerLoggedIn(player); sendPacket(new SM_STATS_INFO(player)); sendPacket(new SM_CUBE_UPDATE(player, 6)); KiskService.onLogin(player); TeleportService.sendSetBindPoint(player); sendPacket(new SM_MACRO_LIST(player)); sendPacket(new SM_GAME_TIME()); player.getController().updateNearbyQuests(); sendPacket(new SM_TITLE_LIST(player)); sendPacket(new SM_CHANNEL_INFO(player.getPosition())); sendPacket(new SM_PLAYER_SPAWN(player)); sendPacket(new SM_EMOTION_LIST()); sendPacket(new SM_INFLUENCE_RATIO()); sendPacket(new SM_PRICES(player.getPrices())); sendPacket(new SM_PLAYER_ID(player)); sendPacket(new SM_ABYSS_RANK(player.getAbyssRank())); sendPacket( new SM_MESSAGE( 0, null, "Welcome to " + GSConfig.SERVER_NAME + " server\nPowered by aion-unique software\ndeveloped by www.aion-unique.org team.\nCopyright 2010", ChatType.ANNOUNCEMENTS)); if (player.isInPrison()) PunishmentService.updatePrisonStatus(player); if (player.isLegionMember()) LegionService.getInstance().onLogin(player); if (player.isInGroup()) GroupService.getInstance().onLogin(player); player.setRates(Rates.getRatesFor(client.getAccount().getMembership())); ClassChangeService.showClassChangeDialog(player); /** Notify mail service to load all mails */ MailService.getInstance().onPlayerLogin(player); /** Schedule periodic saving of this player */ PeriodicSaveService.getInstance().onPlayerLogin(player); /** Notify player if have broker settled items */ BrokerService.getInstance().onPlayerLogin(player); /** Start initializing chat connection(/1, /2, /3, /4 channels) */ if (!GSConfig.DISABLE_CHAT_SERVER) ChatService.onPlayerLogin(player); } else { // TODO this is an client error - inform client. } }
public void moveKinah(Player player, Storage source, int splitAmount) { if (source.getKinahItem().getItemCount() < splitAmount) return; switch (source.getStorageType()) { case 0: { Storage destination = player.getStorage(StorageType.ACCOUNT_WAREHOUSE.getId()); int chksum = (source.getKinahItem().getItemCount() - splitAmount) + (destination.getKinahItem().getItemCount() + splitAmount); if (chksum != source.getKinahItem().getItemCount() + destination.getKinahItem().getItemCount()) return; source.decreaseKinah(splitAmount); destination.increaseKinah(splitAmount); break; } case 2: { Storage destination = player.getStorage(StorageType.CUBE.getId()); int chksum = (source.getKinahItem().getItemCount() - splitAmount) + (destination.getKinahItem().getItemCount() + splitAmount); if (chksum != source.getKinahItem().getItemCount() + destination.getKinahItem().getItemCount()) return; source.decreaseKinah(splitAmount); destination.increaseKinah(splitAmount); break; } default: break; } }