예제 #1
0
파일: Auction.java 프로젝트: impos89/l2emu
 /**
  * Take Item in WHC
  *
  * @param bidder
  * @param itemId
  * @param quantity
  */
 private boolean takeItem(L2Player bidder, int itemId, int quantity) {
   if (bidder.getClan() != null && bidder.getClan().getWarehouse().getAdena() >= quantity) {
     bidder
         .getClan()
         .getWarehouse()
         .destroyItemByItemId("Auction", PcInventory.ADENA_ID, quantity, bidder, bidder);
     return true;
   }
   bidder.sendPacket(SystemMessageId.NOT_ENOUGH_ADENA_IN_CWH);
   return false;
 }
예제 #2
0
파일: Auction.java 프로젝트: impos89/l2emu
  /** Update auction in DB */
  private void updateInDB(L2Player bidder, int bid) {
    Connection con = null;
    try {
      con = L2DatabaseFactory.getInstance().getConnection(con);
      PreparedStatement statement;

      if (getBidders().get(bidder.getClanId()) != null) {
        statement =
            con.prepareStatement(
                "UPDATE auction_bid SET bidderId=?, bidderName=?, maxBid=?, time_bid=? WHERE auctionId=? AND bidderId=?");
        statement.setInt(1, bidder.getClanId());
        statement.setString(2, bidder.getClan().getLeaderName());
        statement.setInt(3, bid);
        statement.setLong(4, System.currentTimeMillis());
        statement.setInt(5, getId());
        statement.setInt(6, bidder.getClanId());
        statement.execute();
        statement.close();
      } else {
        statement =
            con.prepareStatement(
                "INSERT INTO auction_bid (id, auctionId, bidderId, bidderName, maxBid, clan_name, time_bid) VALUES (?, ?, ?, ?, ?, ?, ?)");
        statement.setInt(1, IdFactory.getInstance().getNextId());
        statement.setInt(2, getId());
        statement.setInt(3, bidder.getClanId());
        statement.setString(4, bidder.getName());
        statement.setInt(5, bid);
        statement.setString(6, bidder.getClan().getName());
        statement.setLong(7, System.currentTimeMillis());
        statement.execute();
        statement.close();
        L2Player highest = L2World.getInstance().getPlayer(_highestBidderName);
        if (highest != null) highest.sendMessage("You have been out bidded");
      }
      _highestBidderId = bidder.getClanId();
      _highestBidderMaxBid = bid;
      _highestBidderName = bidder.getClan().getLeaderName();
      if (_bidders.get(_highestBidderId) == null) {
        _bidders.put(
            _highestBidderId,
            new Bidder(
                _highestBidderName, bidder.getClan().getName(), bid, System.currentTimeMillis()));
      } else {
        _bidders.get(_highestBidderId).setBid(bid);
        _bidders.get(_highestBidderId).setTimeBid(System.currentTimeMillis());
      }
      bidder.sendPacket(SystemMessageId.BID_IN_CLANHALL_AUCTION);
    } catch (Exception e) {
      _log.fatal("Exception: Auction.updateInDB(L2Player bidder, int bid): ", e);
    } finally {
      L2DatabaseFactory.close(con);
    }
  }
예제 #3
0
파일: Auction.java 프로젝트: impos89/l2emu
  /** Set a bid */
  public synchronized void setBid(L2Player bidder, int bid) {
    int requiredAdena = bid;
    if (getHighestBidderName().equals(bidder.getClan().getLeaderName()))
      requiredAdena = bid - getHighestBidderMaxBid();

    if ((getHighestBidderId() > 0 && bid > getHighestBidderMaxBid())
        || (getHighestBidderId() == 0 && bid >= getStartingBid())) {
      if (takeItem(bidder, PcInventory.ADENA_ID, requiredAdena)) {
        updateInDB(bidder, bid);
        bidder.getClan().setAuctionBiddedAt(_id, true);
        return;
      }
    }
    if ((bid < getStartingBid()) || (bid <= getHighestBidderMaxBid()))
      bidder.sendPacket(SystemMessageId.BID_PRICE_MUST_BE_HIGHER);
  }
예제 #4
0
  public static void checkCrowns(L2Player activeChar) {
    if (activeChar == null) return;

    int crownId = -1;
    boolean isLeader = false;

    final L2Clan clan = activeChar.getClan();

    if (clan != null) {
      final Castle castle = CastleManager.getInstance().getCastleByOwner(clan);

      if (castle != null) crownId = CrownTable.getCrownId(castle.getCastleId());

      if (clan.getLeaderId() == activeChar.getObjectId()) isLeader = true;
    }

    boolean alreadyFoundCirclet = false;
    boolean alreadyFoundCrown = false;

    for (L2ItemInstance item : activeChar.getInventory().getItems()) {
      if (ArrayUtils.contains(CrownTable.getCrownIds(), item.getItemId())) {
        if (crownId > 0) {
          if (item.getItemId() == crownId) {
            if (!alreadyFoundCirclet) {
              alreadyFoundCirclet = true;
              continue;
            }
          } else if (item.getItemId() == 6841 && isLeader) {
            if (!alreadyFoundCrown) {
              alreadyFoundCrown = true;
              continue;
            }
          }
        }

        // WRONG! The crown is not sellable/tradeable/dropable
        // And the circlets are sellable!!!, but not tradeable or dropable
        // Unequip is what happens
        if (item.getItemId() == 6841 || Config.ALT_REMOVE_CASTLE_CIRCLETS)
          activeChar.destroyItem("Removing Crown", item, activeChar, true);
        else if (item.isEquipped())
          activeChar.getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_HAIR2);

        // No need to update every item in the inventory
        // activeChar.getInventory().updateDatabase();
      }
    }
  }