Beispiel #1
0
std::string Inventory::getReloadText()
{
  std::ostringstream oss;
  oss << "-- Player's inventory" << std::endl;
  oss << "-- Items in Backpack" << std::endl;

  for( size_t backpackNr=0; backpackNr<backpackItems.size(); ++backpackNr )
  {
    InventoryItem* curBackpackItem = backpackItems[ backpackNr ];
    Item* curItem = curBackpackItem->getItem();
    oss << "DawnInterface.restoreItemInBackpack( itemDatabase[\""
        << curItem->getID() << "\"], "
        << curBackpackItem->getInventoryPosX()
        << ", " << curBackpackItem->getInventoryPosY() << ", "
        << curBackpackItem->getCurrentStackSize() << " );"
        << std::endl;
  }

  oss << "-- equipped Items" << std::endl;
  size_t numEquippable = static_cast<size_t>( ItemSlot::COUNT );
  for( size_t curEquippable=0; curEquippable<numEquippable; ++curEquippable )
  {
    if( equippedItems[ curEquippable ] != NULL )
    {
      Item* curItem = equippedItems[ curEquippable ]->getItem();
      /* if the item is two-handed and we're inspecting the off-hand slot
         don't output it. */
      if( !( curItem->isTwoHandedWeapon() == true &&
             curEquippable == static_cast<size_t>( ItemSlot::OFF_HAND ) ) )
      {
        oss << "DawnInterface.restoreWieldItem( " << curEquippable << ", "
            << "itemDatabase[\"" << curItem->getID() << "\"] " << ");"
            << std::endl;
      }
    }
  }

  return oss.str();
}
Beispiel #2
0
InventoryItem* Inventory::getItemAt( size_t invPosX, size_t invPosY )
{
  assert( !isPositionFree( invPosX, invPosY ) );

  size_t numBackItems = backpackItems.size();
  for( size_t curBackItemNr=0; curBackItemNr<numBackItems; ++curBackItemNr )
  {
    InventoryItem* curItem = backpackItems[ curBackItemNr ];
    size_t itemPosX = curItem->getInventoryPosX();
    size_t itemPosY = curItem->getInventoryPosY();
    size_t itemSizeX = curItem->getItem()->getSizeX();
    size_t itemSizeY = curItem->getItem()->getSizeY();

    if( itemPosX <= invPosX && itemPosX + itemSizeX > invPosX &&
        itemPosY <= invPosY && itemPosY + itemSizeY > invPosY )
    {
      return curItem;
    }
  }

  // should have found an item so should never reach here
  abort();
}