Пример #1
0
  // 打開收信夾 ?封信件顯示標題
  public S_Mail(L1PcInstance pc, int type) {
    List<L1Mail> mails = Lists.newList();
    MailTable.getInstance();
    for (L1Mail mail : MailTable.getAllMail()) {
      if (mail.getInBoxId() == pc.getId()) {
        if (mail.getType() == type) {
          mails.add(mail);
        }
      }
    }

    writeC(Opcodes.S_OPCODE_MAIL);
    writeC(type);
    writeH(mails.size());

    if (mails.isEmpty()) {
      return;
    }

    for (int i = 0; i < mails.size(); i++) {
      L1Mail mail = mails.get(i);
      writeD(mail.getId());
      writeC(mail.getReadStatus());
      writeD((int) (mail.getDate().getTime() / 1000));
      writeC(mail.getSenderName().equalsIgnoreCase(pc.getName()) ? 1 : 0); // 寄件/備份
      writeS(
          mail.getSenderName().equalsIgnoreCase(pc.getName())
              ? mail.getReceiverName()
              : mail.getSenderName());
      writeByte(mail.getSubject());
    }
  }
Пример #2
0
 private L1Shop loadShop(int npcId, ResultSet rs) throws SQLException {
   List<L1ShopItem> sellingList = Lists.newList();
   List<L1ShopItem> purchasingList = Lists.newList();
   while (rs.next()) {
     int itemId = rs.getInt("item_id");
     int sellingPrice = rs.getInt("selling_price");
     int purchasingPrice = rs.getInt("purchasing_price");
     int packCount = rs.getInt("pack_count");
     packCount = packCount == 0 ? 1 : packCount;
     if (0 <= sellingPrice) {
       L1ShopItem item = new L1ShopItem(itemId, sellingPrice, packCount);
       sellingList.add(item);
     }
     if (0 <= purchasingPrice) {
       L1ShopItem item = new L1ShopItem(itemId, purchasingPrice, packCount);
       purchasingList.add(item);
     }
   }
   return new L1Shop(npcId, sellingList, purchasingList);
 }
Пример #3
0
 public static void loadGetBack() {
   _getback.clear();
   Connection con = null;
   PreparedStatement pstm = null;
   ResultSet rs = null;
   try {
     con = L1DatabaseFactory.getInstance().getConnection();
     // 同マップでエリア指定と無指定が混在していたら、エリア指定を先に読み込む為にarea_x1 DESC
     String sSQL = "SELECT * FROM getback ORDER BY area_mapid,area_x1 DESC ";
     pstm = con.prepareStatement(sSQL);
     rs = pstm.executeQuery();
     while (rs.next()) {
       Getback getback = new Getback();
       getback._areaX1 = rs.getInt("area_x1");
       getback._areaY1 = rs.getInt("area_y1");
       getback._areaX2 = rs.getInt("area_x2");
       getback._areaY2 = rs.getInt("area_y2");
       getback._areaMapId = rs.getInt("area_mapid");
       getback._getbackX1 = rs.getInt("getback_x1");
       getback._getbackY1 = rs.getInt("getback_y1");
       getback._getbackX2 = rs.getInt("getback_x2");
       getback._getbackY2 = rs.getInt("getback_y2");
       getback._getbackX3 = rs.getInt("getback_x3");
       getback._getbackY3 = rs.getInt("getback_y3");
       getback._getbackMapId = rs.getInt("getback_mapid");
       getback._getbackTownId = rs.getInt("getback_townid");
       getback._getbackTownIdForElf = rs.getInt("getback_townid_elf");
       getback._getbackTownIdForDarkelf = rs.getInt("getback_townid_darkelf");
       rs.getBoolean("scrollescape");
       List<Getback> getbackList = _getback.get(getback._areaMapId);
       if (getbackList == null) {
         getbackList = Lists.newList();
         _getback.put(getback._areaMapId, getbackList);
       }
       getbackList.add(getback);
     }
   } catch (Exception e) {
     _log.log(Level.SEVERE, "could not Get Getback data", e);
   } finally {
     SQLUtil.close(rs);
     SQLUtil.close(pstm);
     SQLUtil.close(con);
   }
 }
Пример #4
0
  private List<Integer> enumNpcIds() {
    List<Integer> ids = Lists.newList();

    Connection con = null;
    PreparedStatement pstm = null;
    ResultSet rs = null;
    try {
      con = L1DatabaseFactory.getInstance().getConnection();
      pstm = con.prepareStatement("SELECT DISTINCT npc_id FROM shop");
      rs = pstm.executeQuery();
      while (rs.next()) {
        ids.add(rs.getInt("npc_id"));
      }
    } catch (SQLException e) {
      _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    } finally {
      SQLUtil.close(rs, pstm, con);
    }
    return ids;
  }
public class L1NpcMakeItemAction extends L1NpcXmlAction {
  private final List<L1ObjectAmount<Integer>> _materials = Lists.newList();

  private final List<L1ObjectAmount<Integer>> _items = Lists.newList();

  private final boolean _isAmountInputable;

  private final L1NpcAction _actionOnSucceed;

  private final L1NpcAction _actionOnFail;

  public L1NpcMakeItemAction(Element element) {
    super(element);

    _isAmountInputable = L1NpcXmlParser.getBoolAttribute(element, "AmountInputable", true);
    NodeList list = element.getChildNodes();
    for (Element elem : new IterableElementList(list)) {
      if (elem.getNodeName().equalsIgnoreCase("Material")) {
        int id = Integer.valueOf(elem.getAttribute("ItemId"));
        int amount = Integer.valueOf(elem.getAttribute("Amount"));
        _materials.add(new L1ObjectAmount<Integer>(id, amount));
        continue;
      }
      if (elem.getNodeName().equalsIgnoreCase("Item")) {
        int id = Integer.valueOf(elem.getAttribute("ItemId"));
        int amount = Integer.valueOf(elem.getAttribute("Amount"));
        _items.add(new L1ObjectAmount<Integer>(id, amount));
        continue;
      }
    }

    if (_items.isEmpty() || _materials.isEmpty()) {
      throw new IllegalArgumentException();
    }

    Element elem = L1NpcXmlParser.getFirstChildElementByTagName(element, "Succeed");
    _actionOnSucceed = elem == null ? null : new L1NpcListedAction(elem);
    elem = L1NpcXmlParser.getFirstChildElementByTagName(element, "Fail");
    _actionOnFail = elem == null ? null : new L1NpcListedAction(elem);
  }

  private boolean makeItems(L1PcInstance pc, String npcName, int amount) {
    if (amount <= 0) {
      return false;
    }

    boolean isEnoughMaterials = true;
    for (L1ObjectAmount<Integer> material : _materials) {
      if (!pc.getInventory()
          .checkItemNotEquipped(material.getObject(), material.getAmount() * amount)) {
        L1Item temp = ItemTable.getInstance().getTemplate(material.getObject());
        pc.sendPackets(
            new S_ServerMessage(
                337,
                temp.getName()
                    + "("
                    + ((material.getAmount() * amount)
                        - pc.getInventory().countItems(temp.getItemId()))
                    + ")")); // \f1%0が不足しています。
        isEnoughMaterials = false;
      }
    }
    if (!isEnoughMaterials) {
      return false;
    }

    // 容量と重量の計算
    int countToCreate = 0; // アイテムの個数(纏まる物は1個)
    int weight = 0;

    for (L1ObjectAmount<Integer> makingItem : _items) {
      L1Item temp = ItemTable.getInstance().getTemplate(makingItem.getObject());
      if (temp.isStackable()) {
        if (!pc.getInventory().checkItem(makingItem.getObject())) {
          countToCreate += 1;
        }
      } else {
        countToCreate += makingItem.getAmount() * amount;
      }
      weight += temp.getWeight() * (makingItem.getAmount() * amount) / 1000;
    }
    // 容量確認
    if (pc.getInventory().getSize() + countToCreate > 180) {
      pc.sendPackets(new S_ServerMessage(263)); // \f1一人のキャラクターが持って歩けるアイテムは最大180個までです。
      return false;
    }
    // 重量確認
    if (pc.getMaxWeight() < pc.getInventory().getWeight() + weight) {
      pc.sendPackets(new S_ServerMessage(82)); // アイテムが重すぎて、これ以上持てません。
      return false;
    }

    for (L1ObjectAmount<Integer> material : _materials) {
      // 材料消費
      pc.getInventory().consumeItem(material.getObject(), material.getAmount() * amount);
    }

    for (L1ObjectAmount<Integer> makingItem : _items) {
      L1ItemInstance item =
          pc.getInventory().storeItem(makingItem.getObject(), makingItem.getAmount() * amount);
      if (item != null) {
        String itemName = ItemTable.getInstance().getTemplate(makingItem.getObject()).getName();
        if (makingItem.getAmount() * amount > 1) {
          itemName = itemName + " (" + makingItem.getAmount() * amount + ")";
        }
        pc.sendPackets(new S_ServerMessage(143, npcName, itemName)); // \f1%0が%1をくれました。
      }
    }
    return true;
  }

  /** 指定されたインベントリ内に、素材が何セットあるか数える */
  private int countNumOfMaterials(L1PcInventory inv) {
    int count = Integer.MAX_VALUE;
    for (L1ObjectAmount<Integer> material : _materials) {
      int numOfSet = inv.countItems(material.getObject()) / material.getAmount();
      count = Math.min(count, numOfSet);
    }
    return count;
  }

  @Override
  public L1NpcHtml execute(String actionName, L1PcInstance pc, L1Object obj, byte[] args) {
    int numOfMaterials = countNumOfMaterials(pc.getInventory());
    if ((1 < numOfMaterials) && _isAmountInputable) {
      pc.sendPackets(new S_HowManyMake(obj.getId(), numOfMaterials, actionName));
      return null;
    }
    return executeWithAmount(actionName, pc, obj, 1);
  }

  @Override
  public L1NpcHtml executeWithAmount(String actionName, L1PcInstance pc, L1Object obj, int amount) {
    L1NpcInstance npc = (L1NpcInstance) obj;
    L1NpcHtml result = null;
    if (makeItems(pc, npc.getNpcTemplate().get_name(), amount)) {
      if (_actionOnSucceed != null) {
        result = _actionOnSucceed.execute(actionName, pc, obj, new byte[0]);
      }
    } else {
      if (_actionOnFail != null) {
        result = _actionOnFail.execute(actionName, pc, obj, new byte[0]);
      }
    }
    return result == null ? L1NpcHtml.HTML_CLOSE : result;
  }
}