Пример #1
0
  public static void populateInventory(
      Table targetTable,
      Array<InventoryItemLocation> inventoryItems,
      DragAndDrop draganddrop,
      String defaultName,
      boolean disableNonDefaultItems) {
    clearInventoryItems(targetTable);

    Array<Cell> cells = targetTable.getCells();
    for (int i = 0; i < inventoryItems.size; i++) {
      InventoryItemLocation itemLocation = inventoryItems.get(i);
      ItemTypeID itemTypeID = ItemTypeID.valueOf(itemLocation.getItemTypeAtLocation());
      InventorySlot inventorySlot =
          ((InventorySlot) cells.get(itemLocation.getLocationIndex()).getActor());

      for (int index = 0; index < itemLocation.getNumberItemsAtLocation(); index++) {
        InventoryItem item = InventoryItemFactory.getInstance().getInventoryItem(itemTypeID);
        String itemName = itemLocation.getItemNameProperty();
        if (itemName == null || itemName.isEmpty()) {
          item.setName(defaultName);
        } else {
          item.setName(itemName);
        }

        inventorySlot.add(item);
        if (item.getName().equalsIgnoreCase(defaultName)) {
          draganddrop.addSource(new InventorySlotSource(inventorySlot, draganddrop));
        } else if (disableNonDefaultItems == false) {
          draganddrop.addSource(new InventorySlotSource(inventorySlot, draganddrop));
        }
      }
    }
  }
Пример #2
0
 public void removeQuestItemFromInventory(String questID) {
   Array<Cell> sourceCells = _inventorySlotTable.getCells();
   for (int index = 0; index < sourceCells.size; index++) {
     InventorySlot inventorySlot = ((InventorySlot) sourceCells.get(index).getActor());
     if (inventorySlot == null) continue;
     InventoryItem item = inventorySlot.getTopInventoryItem();
     if (item == null) continue;
     String inventoryItemName = item.getName();
     if (inventoryItemName != null && inventoryItemName.equals(questID)) {
       inventorySlot.clearAllInventoryItems(false);
     }
   }
 }
Пример #3
0
  public void addEntityToInventory(Entity entity, String itemName) {
    Array<Cell> sourceCells = _inventorySlotTable.getCells();
    int index = 0;

    for (; index < sourceCells.size; index++) {
      InventorySlot inventorySlot = ((InventorySlot) sourceCells.get(index).getActor());
      if (inventorySlot == null) continue;
      int numItems = inventorySlot.getNumItems();
      if (numItems == 0) {
        InventoryItem inventoryItem =
            InventoryItemFactory.getInstance()
                .getInventoryItem(ItemTypeID.valueOf(entity.getEntityConfig().getItemTypeID()));
        inventoryItem.setName(itemName);
        inventorySlot.add(inventoryItem);
        _dragAndDrop.addSource(new InventorySlotSource(inventorySlot, _dragAndDrop));
        break;
      }
    }
  }
Пример #4
0
  @Override
  public void onNotify(InventorySlot slot, SlotEvent event) {
    switch (event) {
      case ADDED_ITEM:
        InventoryItem addItem = slot.getTopInventoryItem();
        if (addItem == null) return;
        if (addItem.isInventoryItemOffensive()) {
          _APVal += addItem.getItemUseTypeValue();
          _APValLabel.setText(String.valueOf(_APVal));
          notify(String.valueOf(_APVal), InventoryObserver.InventoryEvent.UPDATED_AP);

          if (addItem.isInventoryItemOffensiveWand()) {
            notify(
                String.valueOf(addItem.getItemUseTypeValue()),
                InventoryObserver.InventoryEvent.ADD_WAND_AP);
          }

        } else if (addItem.isInventoryItemDefensive()) {
          _DPVal += addItem.getItemUseTypeValue();
          _DPValLabel.setText(String.valueOf(_DPVal));
          notify(String.valueOf(_DPVal), InventoryObserver.InventoryEvent.UPDATED_DP);
        }
        break;
      case REMOVED_ITEM:
        InventoryItem removeItem = slot.getTopInventoryItem();
        if (removeItem == null) return;
        if (removeItem.isInventoryItemOffensive()) {
          _APVal -= removeItem.getItemUseTypeValue();
          _APValLabel.setText(String.valueOf(_APVal));
          notify(String.valueOf(_APVal), InventoryObserver.InventoryEvent.UPDATED_AP);

          if (removeItem.isInventoryItemOffensiveWand()) {
            notify(
                String.valueOf(removeItem.getItemUseTypeValue()),
                InventoryObserver.InventoryEvent.REMOVE_WAND_AP);
          }

        } else if (removeItem.isInventoryItemDefensive()) {
          _DPVal -= removeItem.getItemUseTypeValue();
          _DPValLabel.setText(String.valueOf(_DPVal));
          notify(String.valueOf(_DPVal), InventoryObserver.InventoryEvent.UPDATED_DP);
        }
        break;
      default:
        break;
    }
  }