示例#1
0
  public void deletePet(ItemInstance item, Creature owner) {
    int petObjectId = 0;

    Connection con = null;
    PreparedStatement statement = null;
    ResultSet rset = null;
    try {
      int itemObjId = item.getObjectId();
      con = DatabaseFactory.getInstance().getConnection();
      statement = con.prepareStatement(SELECT_SQL_QUERY);
      statement.setInt(1, itemObjId);
      rset = statement.executeQuery();
      while (rset.next()) petObjectId = rset.getInt("objId");

      DbUtils.close(statement, rset);

      Player player = owner.getPlayer();

      PetInstance pet = player.getPet();
      if (pet != null && pet.getObjectId() == petObjectId) pet.unSummon(false);

      if (player != null && player.isMounted() && player.getMountControlItemObjId() == itemObjId)
        player.getMount().onControlItemDelete();

      // if it's a pet control item, delete the pet
      statement = con.prepareStatement(DELETE_SQL_QUERY);
      statement.setInt(1, itemObjId);
      statement.execute();
    } catch (Exception e) {
      _log.error("CharNameTable.deletePet(ItemInstance, Creature): " + e, e);
    } finally {
      DbUtils.closeQuietly(con, statement, rset);
    }
  }
示例#2
0
  /**
   * Проверяет возможность передачи вещи
   *
   * @param player
   * @param item
   * @return
   */
  public static final boolean checkIfCanDiscard(Player player, ItemInstance item) {
    if (item.isHeroItem()) return false;

    if (player.getMountControlItemObjId() == item.getObjectId()) return false;

    if (player.getPetControlItem() == item) return false;

    if (player.getEnchantScroll() == item) return false;

    if (item.isCursed()) return false;

    if (item.getTemplate().isQuest()) return false;

    return true;
  }