コード例 #1
0
ファイル: ItemContainer.java プロジェクト: zografakos/filemon
  /**
   * Destroy item from inventory and updates database
   *
   * @param process : String Identifier of process triggering this action
   * @param item : L2ItemInstance to be destroyed
   * @param actor : L2PcInstance Player requesting the item destroy
   * @param reference : Object Object referencing current action like NPC selling item or previous
   *     item in transformation
   * @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
   */
  public L2ItemInstance destroyItem(
      String process, L2ItemInstance item, long count, L2PcInstance actor, Object reference) {
    synchronized (item) {
      // Adjust item quantity
      if (item.getCount() > count) {
        item.changeCount(process, -count, actor, reference);
        item.setLastChange(L2ItemInstance.MODIFIED);

        // don't update often for untraced items
        if (process != null || GameTimeController.getGameTicks() % 10 == 0) {
          item.updateDatabase();
        }

        refreshWeight();

        return item;
      } else {
        if (item.getCount() < count) return null;

        boolean removed = this.removeItem(item);
        if (!removed) return null;

        ItemTable.getInstance().destroyItem(process, item, actor, reference);

        item.updateDatabase();
        refreshWeight();
      }
    }
    return item;
  }
コード例 #2
0
 public void notifyChangeMode() {
   try {
     if (GameTimeController.getInstance().isNowNight()) changeMode(1);
     else changeMode(0);
   } catch (Exception e) {
     _log.log(Level.WARNING, "Error while notifyChangeMode(): " + e.getMessage(), e);
   }
 }
コード例 #3
0
 private String gameTime() {
   int t = GameTimeController.getInstance().getGameTime();
   int h = t / 60;
   int m = t % 60;
   SimpleDateFormat format = new SimpleDateFormat("H:mm");
   Calendar cal = Calendar.getInstance();
   cal.set(Calendar.HOUR_OF_DAY, h);
   cal.set(Calendar.MINUTE, m);
   return format.format(cal.getTime());
 }
コード例 #4
0
  public L2RaidBossInstance handleBoss(L2Spawn spawnDat) {
    if (_bosses.containsKey(spawnDat)) return _bosses.get(spawnDat);

    if (GameTimeController.getInstance().isNowNight()) {
      L2RaidBossInstance raidboss = (L2RaidBossInstance) spawnDat.doSpawn();
      _bosses.put(spawnDat, raidboss);

      return raidboss;
    }

    _bosses.put(spawnDat, null);
    return null;
  }
コード例 #5
0
ファイル: ItemContainer.java プロジェクト: zografakos/filemon
  /**
   * Adds item to inventory
   *
   * @param process : String Identifier of process triggering this action
   * @param itemId : int Item Identifier of the item to be added
   * @param count : int Quantity of items to be added
   * @param actor : L2PcInstance Player requesting the item add
   * @param reference : Object Object referencing current action like NPC selling item or previous
   *     item in transformation
   * @return L2ItemInstance corresponding to the new item or the updated item in inventory
   */
  public L2ItemInstance addItem(
      String process, int itemId, long count, L2PcInstance actor, Object reference) {
    L2ItemInstance item = getItemByItemId(itemId);

    // If stackable item is found in inventory just add to current quantity
    if (item != null && item.isStackable()) {
      item.changeCount(process, count, actor, reference);
      item.setLastChange(L2ItemInstance.MODIFIED);
      // Updates database
      if (itemId == 57 && count < 10000 * Config.RATE_DROP_ITEMS_ID.get(57)) {
        // Small adena changes won't be saved to database all the time
        if (GameTimeController.getGameTicks() % 5 == 0) item.updateDatabase();
      } else item.updateDatabase();
    }
    // If item hasn't be found in inventory, create new one
    else {
      for (int i = 0; i < count; i++) {
        L2Item template = ItemTable.getInstance().getTemplate(itemId);
        if (template == null) {
          _log.log(
              Level.WARNING,
              (actor != null ? "[" + actor.getName() + "] " : "") + "Invalid ItemId requested: ",
              itemId);
          return null;
        }

        item =
            ItemTable.getInstance()
                .createItem(process, itemId, template.isStackable() ? count : 1, actor, reference);
        item.setOwnerId(getOwnerId());
        item.setLocation(getBaseLocation());
        item.setLastChange(L2ItemInstance.ADDED);

        // Add item in inventory
        addItem(item);
        // Updates database
        item.updateDatabase();

        // If stackable, end loop as entire count is included in 1 instance of item
        if (template.isStackable() || !Config.MULTIPLE_ITEM_DROP) break;
      }
    }

    refreshWeight();
    return item;
  }
コード例 #6
0
ファイル: ItemContainer.java プロジェクト: zografakos/filemon
  /**
   * Adds item to inventory
   *
   * @param process : String Identifier of process triggering this action
   * @param item : L2ItemInstance to be added
   * @param actor : L2PcInstance Player requesting the item add
   * @param reference : Object Object referencing current action like NPC selling item or previous
   *     item in transformation
   * @return L2ItemInstance corresponding to the new item or the updated item in inventory
   */
  public L2ItemInstance addItem(
      String process, L2ItemInstance item, L2PcInstance actor, Object reference) {
    L2ItemInstance olditem = getItemByItemId(item.getItemId());

    // If stackable item is found in inventory just add to current quantity
    if (olditem != null && olditem.isStackable()) {
      long count = item.getCount();
      olditem.changeCount(process, count, actor, reference);
      olditem.setLastChange(L2ItemInstance.MODIFIED);

      // And destroys the item
      ItemTable.getInstance().destroyItem(process, item, actor, reference);
      item.updateDatabase();
      item = olditem;

      // Updates database
      if (item.getItemId() == 57 && count < 10000 * Config.RATE_DROP_ITEMS_ID.get(57)) {
        // Small adena changes won't be saved to database all the time
        if (GameTimeController.getGameTicks() % 5 == 0) item.updateDatabase();
      } else item.updateDatabase();
    }
    // If item hasn't be found in inventory, create new one
    else {
      item.setOwnerId(process, getOwnerId(), actor, reference);
      item.setLocation(getBaseLocation());
      item.setLastChange((L2ItemInstance.ADDED));

      // Add item in inventory
      addItem(item);

      // Updates database
      item.updateDatabase();
    }

    refreshWeight();
    return item;
  }