void CMap::CheckForItem(int x, int y) { // Go through all of the items to check if we have a match for(int i = 0; i < (int)m_vItems.size(); i++) { CItem *pItem = &m_vItems[i]; // Check if the player position is the same as the current item if(x == pItem->GetIndex().X && y == pItem->GetIndex().Y) { // Create a new item and then copy the current item's data to the new item CItem newItem; memcpy(&newItem, pItem, sizeof(CItem)); // Check if this item has a special key with it g_ActionKeys.HandleKey(pItem->GetActionKey()); // If our inventory isn't full, let's add it, otherwise do nothing if(g_Player.GetInventorySize() < kMaxItems) { // Let's add the new item and then delete it from the map g_Player.AddItem(newItem); m_vItems.erase(m_vItems.begin() + i); } return; } } }
void ItemPromptSell() { // If the player finally decides to sell their item, this function is called. // First we get the item and then calculate it's USED price (false). CItem *pItem = g_Shop.GetSelectedItem(); int salePrice = CalculateItemPrice(pItem, false); // Drop the item and delete it from the map to get rid of it from the player g_Player.DropItem(pItem); g_Map.DeleteTile(kItemType, pItem->GetIndex().X, pItem->GetIndex().Y); // Add the money made to our current gold g_Player.SetGold(g_Player.GetGold() + salePrice); // Display the transaction made char szMessage[80] = {0}; sprintf(szMessage, "You recieved %d gold for the %s.", salePrice, pItem->GetItemName()); g_Shop.DrawMessageBox(szMessage); Sleep(1000); }
void CMap::CheckForItem(int x, int y) { // Go through all of the items to check if we have a match for(int i = 0; i < (int)m_vItems.size(); i++) { CItem *pItem = &m_vItems[i]; // Check if the player position is the same as the current item if(x == pItem->GetIndex().X && y == pItem->GetIndex().Y) { // Create a new item and then copy the current item's data to the new item CItem newItem; memcpy(&newItem, pItem, sizeof(CItem)); //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // After we pick up an item we want to check if there is something special // that needs to be done. We use this in the game for when we pick up the // treasure in Valkar's palace. The game is over at that point. // We just pass the action key into our action key object and handle it. g_ActionKeys.HandleKey(pItem->GetActionKey()); //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // If our inventory isn't full, let's add it, otherwise do nothing if(g_Player.GetInventorySize() < kMaxItems) { // Let's add the new item and then delete it from the map g_Player.AddItem(newItem); m_vItems.erase(m_vItems.begin() + i); } return; } } }
void CItemSlot::Clear() { std::vector< CItem* >::iterator iter; CItem* pItem = NULL; for( iter = m_listItems.begin(); iter != m_listItems.end(); ++iter ) { pItem = *iter; if( pItem ) { pItem->Clear(); m_pEvent->SetID( CTEventItem::EID_DEL_ITEM ); m_pEvent->SetIndex( pItem->GetIndex() ); m_pEvent->SetItem( pItem ); SetChanged(); NotifyObservers( m_pEvent ); delete pItem; *iter = NULL; } } }