Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
 /**
  * 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);
   } else {
     DAOManager.getDAO(PlayerMacrossesDAO.class)
         .updateMacro(player.getObjectId(), macroOrder, macroXML);
   }
 }
Exemplo n.º 3
0
  private void initBrokerService() {
    int loadedBrokerItemsCount = 0;
    int loadedSettledItemsCount = 0;

    List<BrokerItem> brokerItems = DAOManager.getDAO(BrokerDAO.class).loadBroker();

    for (BrokerItem item : brokerItems) {
      if (item.getItemBrokerRace() == BrokerRace.ASMODIAN) {
        if (item.isSettled()) {
          asmodianSettledItems.put(item.getItemUniqueId(), item);
          loadedSettledItemsCount++;
        } else {
          asmodianBrokerItems.put(item.getItemUniqueId(), item);
          loadedBrokerItemsCount++;
        }
      } else if (item.getItemBrokerRace() == BrokerRace.ELYOS) {
        if (item.isSettled()) {
          elyosSettledItems.put(item.getItemUniqueId(), item);
          loadedSettledItemsCount++;
        } else {
          elyosBrokerItems.put(item.getItemUniqueId(), item);
          loadedBrokerItemsCount++;
        }
      }
    }

    log.info("Loaded " + loadedBrokerItemsCount + " Broker Items");
    log.info("Loaded " + loadedSettledItemsCount + " Settled Items");
    log.info("Broker loaded successfully");
  }
Exemplo n.º 4
0
  public static Map<Integer, String> getPlayerNames(Collection<Integer> playerObjIds) {

    // if there is no ids - return just empty map
    if (GenericValidator.isBlankOrNull(playerObjIds)) {
      return Collections.emptyMap();
    }

    final Map<Integer, String> result = Maps.newHashMap();

    // Copy ids to separate set
    // It's dangerous to modify input collection, can have side results
    final Set<Integer> playerObjIdsCopy = Sets.newHashSet(playerObjIds);

    // Get names of all online players
    // Certain names can be changed in runtime
    // this should prevent errors
    World.getInstance()
        .doOnAllPlayers(
            new Visitor<Player>() {
              @Override
              public void visit(Player object) {
                if (playerObjIdsCopy.contains(object.getObjectId())) {
                  result.put(object.getObjectId(), object.getName());
                  playerObjIdsCopy.remove(object.getObjectId());
                }
              }
            });

    result.putAll(DAOManager.getDAO(PlayerDAO.class).getPlayerNames(playerObjIdsCopy));
    return result;
  }
Exemplo n.º 5
0
  public static void breakWeapons(Player player, int weaponToBreakUniqueId) {
    Item weaponToBreak = player.getInventory().getItemByObjId(weaponToBreakUniqueId);
    if (weaponToBreak == null)
      weaponToBreak = player.getEquipment().getEquippedItemByObjId(weaponToBreakUniqueId);

    if (weaponToBreak == null || !(player.getTarget() instanceof Npc)) return;

    if (!weaponToBreak.hasFusionedItem()) {
      PacketSendUtility.sendPacket(
          player, SM_SYSTEM_MESSAGE.STR_DECOMPOUND_ERROR_NOT_AVAILABLE(weaponToBreak.getNameID()));
      return;
    }

    weaponToBreak.setFusionedItem(0);
    ItemService.removeAllFusionStone(player, weaponToBreak);
    DAOManager.getDAO(InventoryDAO.class).store(weaponToBreak, player.getObjectId());

    PacketSendUtility.sendPacket(player, new SM_UPDATE_ITEM(weaponToBreak));

    PacketSendUtility.sendPacket(
        player,
        SM_SYSTEM_MESSAGE.STR_COMPOUNDED_ITEM_DECOMPOUND_SUCCESS(weaponToBreak.getNameID()));
  }
Exemplo n.º 6
0
  public static void fusionWeapons(Player player, int firstItemUniqueId, int secondItemUniqueId) {
    Item firstItem = player.getInventory().getItemByObjId(firstItemUniqueId);
    if (firstItem == null)
      firstItem = player.getEquipment().getEquippedItemByObjId(firstItemUniqueId);

    Item secondItem = player.getInventory().getItemByObjId(secondItemUniqueId);
    if (secondItem == null)
      secondItem = player.getEquipment().getEquippedItemByObjId(secondItemUniqueId);

    /*
     * Need to have items in bag, and target the fusion NPC
     */
    if (firstItem == null || secondItem == null || !(player.getTarget() instanceof Npc)) return;
    if (!MathUtil.isIn3dRange(player.getTarget(), player, 10)) return;
    /*
     * Both have to be 2h weapons
     */
    if (!firstItem.getItemTemplate().isWeapon() || !secondItem.getItemTemplate().isWeapon()) {
      Logger.getLogger(ArmsfusionService.class)
          .info("[AUDIT]Player: " + player.getName() + " trying to fusion non-weapon. Hacking!");
      return;
    }
    if (firstItem.getItemTemplate().getWeaponType() == null
        || secondItem.getItemTemplate().getWeaponType() == null) return;
    else {
      switch (firstItem.getItemTemplate().getWeaponType()) {
        case DAGGER_1H:
        case MACE_1H:
        case SWORD_1H:
        case TOOLHOE_1H:
          Logger.getLogger(ArmsfusionService.class)
              .info("[AUDIT]Player: " + player.getName() + " trying to fusion 1h weapon. Hacking!");
          return;
      }
      switch (secondItem.getItemTemplate().getWeaponType()) {
        case DAGGER_1H:
        case MACE_1H:
        case SWORD_1H:
        case TOOLHOE_1H:
          Logger.getLogger(ArmsfusionService.class)
              .info("[AUDIT]Player: " + player.getName() + " trying to fusion 1h weapon. Hacking!");
          return;
      }
    }

    // check if both items are fusionable
    if (!firstItem.getItemTemplate().isCanFuse() || !secondItem.getItemTemplate().isCanFuse())
      return;

    double rarity = rarityRate(firstItem.getItemTemplate().getItemQuality());
    double priceRate = player.getPrices().getGlobalPrices(player.getCommonData().getRace()) * .01;
    double taxRate = player.getPrices().getTaxes(player.getCommonData().getRace()) * .01;
    int priceMod = player.getPrices().getGlobalPricesModifier() * 2;
    int level = firstItem.getItemTemplate().getLevel();
    int price = (int) (priceMod * priceRate * taxRate * rarity * level * level);
    log.debug(
        "Rarity: "
            + rarity
            + " Price Rate: "
            + priceRate
            + " Tax Rate: "
            + taxRate
            + " Price Mod: "
            + priceMod
            + " Weapon Level: "
            + level);
    log.debug("Price: " + price);

    if (player.getInventory().getKinahItem().getItemCount() < price) {
      PacketSendUtility.sendPacket(
          player,
          SM_SYSTEM_MESSAGE.STR_COMPOUND_ERROR_NOT_ENOUGH_MONEY(
              firstItem.getNameID(), secondItem.getNameID()));
      return;
    }

    /*
     * Fusioned weapons must have same type
     */
    if (firstItem.getItemTemplate().getWeaponType()
        != secondItem.getItemTemplate().getWeaponType()) {
      PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_COMPOUND_ERROR_DIFFERENT_TYPE);
      return;
    }

    /*
     * Second weapon must have inferior or equal lvl. in relation to first weapon
     */
    if (secondItem.getItemTemplate().getLevel() > firstItem.getItemTemplate().getLevel()) {
      PacketSendUtility.sendPacket(
          player, SM_SYSTEM_MESSAGE.STR_COMPOUND_ERROR_MAIN_REQUIRE_HIGHER_LEVEL);
      return;
    }

    boolean decreaseResult = player.getInventory().decreaseKinah(price);
    if (!decreaseResult) return;

    boolean removeResult = player.getInventory().removeFromBagByObjectId(secondItemUniqueId, 1);
    if (!removeResult) return;

    firstItem.setFusionedItem(secondItem.getItemTemplate().getTemplateId());

    ItemService.removeAllFusionStone(player, firstItem);

    if (secondItem.hasOptionalSocket()) {
      firstItem.setOptionalFusionSocket(secondItem.getOptionalSocket());
    } else {
      firstItem.setOptionalFusionSocket(0);
    }

    Set<ManaStone> manastones = secondItem.getItemStones();
    for (ManaStone stone : manastones) ItemService.addFusionStone(firstItem, stone.getItemId());

    if (firstItem.getPersistentState() != PersistentState.NEW
        && firstItem.getPersistentState() != PersistentState.UPDATE_REQUIRED)
      firstItem.setPersistentState(PersistentState.UPDATE_REQUIRED);

    DAOManager.getDAO(InventoryDAO.class).store(firstItem, player.getObjectId());

    PacketSendUtility.sendPacket(player, new SM_DELETE_ITEM(secondItemUniqueId));

    PacketSendUtility.sendPacket(player, new SM_UPDATE_ITEM(firstItem));

    PacketSendUtility.sendPacket(
        player,
        SM_SYSTEM_MESSAGE.STR_COMPOUND_SUCCESS(firstItem.getNameID(), secondItem.getNameID()));
  }
Exemplo n.º 7
0
 @Override
 public void run() {
   if (brokerItem != null) DAOManager.getDAO(BrokerDAO.class).store(brokerItem);
   if (item != null) DAOManager.getDAO(InventoryDAO.class).store(item, playerId);
   if (kinahItem != null) DAOManager.getDAO(InventoryDAO.class).store(kinahItem, playerId);
 }
Exemplo n.º 8
0
 /**
  * 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);
   }
 }
Exemplo n.º 9
0
 /**
  * @param objectId
  * @param creationDate
  */
 public static void storeCreationTime(int objectId, Timestamp creationDate) {
   DAOManager.getDAO(PlayerDAO.class).storeCreationTime(objectId, creationDate);
 }
Exemplo n.º 10
0
 /**
  * Updates deletion time in database
  *
  * @param accData PlayerAccountData
  */
 private static void storeDeletionTime(PlayerAccountData accData) {
   DAOManager.getDAO(PlayerDAO.class)
       .updateDeletionTime(
           accData.getPlayerCommonData().getPlayerObjId(), accData.getDeletionDate());
 }
Exemplo n.º 11
0
 /**
  * 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);
   DAOManager.getDAO(OldNamesDAO.class).deleteNames(playerId);
 }
Exemplo n.º 12
0
  /**
   * 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;
  }
Exemplo n.º 13
0
 /**
  * Stores player data into db
  *
  * @param player
  */
 public 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(AbyssRankDAO.class).storeAbyssRank(player);
   DAOManager.getDAO(PlayerPunishmentsDAO.class)
       .storePlayerPunishments(player, PunishmentType.PRISON);
   DAOManager.getDAO(PlayerPunishmentsDAO.class)
       .storePlayerPunishments(player, PunishmentType.GATHER);
   DAOManager.getDAO(InventoryDAO.class).store(player);
   DAOManager.getDAO(ItemStoneListDAO.class).save(player);
   DAOManager.getDAO(MailDAO.class).storeMailbox(player);
   DAOManager.getDAO(PortalCooldownsDAO.class).storePortalCooldowns(player);
   DAOManager.getDAO(CraftCooldownsDAO.class).storeCraftCooldowns(player);
   DAOManager.getDAO(PlayerNpcFactionsDAO.class).storeNpcFactions(player);
 }
Exemplo n.º 14
0
 public static boolean isOldName(String name) {
   return DAOManager.getDAO(OldNamesDAO.class).isOldName(name);
 }
Exemplo n.º 15
0
 /**
  * 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);
 }