示例#1
0
  public void select(Castle castle) {
    Connection con = null;
    PreparedStatement statement = null;
    ResultSet rset = null;

    try {
      con = DatabaseFactory.getInstance().getConnection();
      statement = con.prepareStatement(SELECT_SQL_QUERY);
      statement.setInt(1, castle.getId());
      rset = statement.executeQuery();
      if (rset.next()) {
        castle.setTaxPercent(rset.getInt("tax_percent"));
        castle.setTreasury(rset.getLong("treasury"));
        castle.setRewardCount(rset.getInt("reward_count"));
        castle.getSiegeDate().setTimeInMillis(rset.getLong("siege_date") * 1000L);
        castle.getLastSiegeDate().setTimeInMillis(rset.getLong("last_siege_date") * 1000L);
        castle.getOwnDate().setTimeInMillis(rset.getLong("own_date") * 1000L);
        castle.setResidenceSide(ResidenceSide.VALUES[rset.getInt("side")], true);
      }
    } catch (Exception e) {
      _log.error("CastleDAO.select(Castle):" + e, e);
    } finally {
      DbUtils.closeQuietly(con, statement, rset);
    }
  }
示例#2
0
 private void update0(Castle castle) {
   Connection con = null;
   PreparedStatement statement = null;
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement(UPDATE_SQL_QUERY);
     statement.setInt(1, castle.getTaxPercent0());
     statement.setLong(2, castle.getTreasury());
     statement.setInt(3, castle.getRewardCount());
     statement.setInt(4, (int) (castle.getSiegeDate().getTimeInMillis() / 1000L));
     statement.setInt(5, (int) (castle.getLastSiegeDate().getTimeInMillis() / 1000L));
     statement.setInt(6, (int) (castle.getOwnDate().getTimeInMillis() / 1000L));
     statement.setInt(7, castle.getResidenceSide().ordinal());
     statement.setInt(8, castle.getId());
     statement.execute();
   } catch (Exception e) {
     _log.warn("CastleDAO#update0(Castle): " + e, e);
   } finally {
     DbUtils.closeQuietly(con, statement);
   }
 }
示例#3
0
  public void update(Castle residence) {
    if (!residence.getJdbcState().isUpdatable()) return;

    residence.setJdbcState(JdbcEntityState.STORED);
    update0(residence);
  }
示例#4
0
  @Override
  protected void runImpl() {
    Player activeChar = getClient().getActiveChar();
    if (activeChar == null || _count == 0) return;

    // Проверяем, не подменили ли id
    if (activeChar.getBuyListId() != _listId)
      // TODO audit
      return;

    if (activeChar.isActionsDisabled()) {
      activeChar.sendActionFailed();
      return;
    }

    if (activeChar.isInStoreMode()) {
      activeChar.sendPacket(
          SystemMsg
              .WHILE_OPERATING_A_PRIVATE_STORE_OR_WORKSHOP_YOU_CANNOT_DISCARD_DESTROY_OR_TRADE_AN_ITEM);
      return;
    }

    if (activeChar.isInTrade()) {
      activeChar.sendActionFailed();
      return;
    }

    if (activeChar.isFishing()) {
      activeChar.sendPacket(SystemMsg.YOU_CANNOT_DO_THAT_WHILE_FISHING);
      return;
    }

    if (!Config.ALT_GAME_KARMA_PLAYER_CAN_SHOP && activeChar.isPK() && !activeChar.isGM()) {
      activeChar.sendActionFailed();
      return;
    }

    NpcInstance merchant = activeChar.getLastNpc();
    boolean isValidMerchant = merchant != null && merchant.isMerchantNpc();
    if (!activeChar.isGM()
        && (merchant == null
            || !isValidMerchant
            || !activeChar.isInRange(merchant, Creature.INTERACTION_DISTANCE))) {
      activeChar.sendActionFailed();
      return;
    }

    NpcTradeList list = BuyListHolder.getInstance().getBuyList(_listId);
    if (list == null) {
      // TODO audit
      activeChar.sendActionFailed();
      return;
    }

    int slots = 0;
    long weight = 0;
    long totalPrice = 0;
    long tax = 0;
    double taxRate = 0;

    Castle castle = null;
    if (merchant != null) {
      castle = merchant.getCastle(activeChar);
      if (castle != null) taxRate = castle.getTaxRate();
    }

    List<TradeItem> buyList = new ArrayList<TradeItem>(_count);
    List<TradeItem> tradeList = list.getItems();
    try {
      loop:
      for (int i = 0; i < _count; i++) {
        int itemId = _items[i];
        long count = _itemQ[i];
        long price = 0;

        for (TradeItem ti : tradeList)
          if (ti.getItemId() == itemId) {
            if (ti.isCountLimited() && ti.getCurrentValue() < count) continue loop;
            price = ti.getOwnersPrice();
          }

        if (price == 0 && (!activeChar.isGM() || !activeChar.getPlayerAccess().UseGMShop)) {
          // TODO audit
          activeChar.sendActionFailed();
          return;
        }

        totalPrice = SafeMath.addAndCheck(totalPrice, SafeMath.mulAndCheck(count, price));

        TradeItem ti = new TradeItem();
        ti.setItemId(itemId);
        ti.setCount(count);
        ti.setOwnersPrice(price);

        weight =
            SafeMath.addAndCheck(weight, SafeMath.mulAndCheck(count, ti.getItem().getWeight()));
        if (!ti.getItem().isStackable()
            || activeChar.getInventory().getItemByItemId(itemId) == null) slots++;

        buyList.add(ti);
      }

      tax = (long) (totalPrice * taxRate);

      totalPrice = SafeMath.addAndCheck(totalPrice, tax);

      if (!activeChar.getInventory().validateWeight(weight)) {
        activeChar.sendPacket(SystemMsg.YOU_HAVE_EXCEEDED_THE_WEIGHT_LIMIT);
        return;
      }

      if (!activeChar.getInventory().validateCapacity(slots)) {
        activeChar.sendPacket(SystemMsg.YOUR_INVENTORY_IS_FULL);
        return;
      }

      if (!activeChar.reduceAdena(totalPrice)) {
        activeChar.sendPacket(SystemMsg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
        return;
      }

      for (TradeItem ti : buyList) activeChar.getInventory().addItem(ti.getItemId(), ti.getCount());

      // Для магазинов с ограниченным количеством товара число продаваемых предметов уменьшаем после
      // всех проверок
      list.updateItems(buyList);

      // Add tax to castle treasury if not owned by npc clan
      if (castle != null)
        if (tax > 0
            && castle.getOwnerId() > 0
            && activeChar.getReflection() == ReflectionManager.DEFAULT)
          castle.addToTreasury(tax, true, false);
    } catch (ArithmeticException ae) {
      // TODO audit
      activeChar.sendPacket(SystemMsg.YOU_HAVE_EXCEEDED_THE_QUANTITY_THAT_CAN_BE_INPUTTED);
      return;
    }

    sendPacket(new ExBuySellListPacket.SellRefundList(activeChar, true));
    activeChar.sendChanges();
  }