/** psinventorycache.cpp * * Copyright (C) 2006 Atomic Blue (info@planeshift.it, http://www.atomicblue.org) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 of the License) * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Client's inventory cache. */ #include #include "net/messages.h" #include "psinventorycache.h" #include "globals.h" psInventoryCache::psInventoryCache () { msgHandler = psengine->GetMsgHandler(); EmptyInventory(); } psInventoryCache::~psInventoryCache () { } bool psInventoryCache::GetInventory (void) { if (!msgHandler) return false; // testing if need to request full inventory or // just to refresh local cache. if (cacheStatus == INVALID) { // full list request psGUIInventoryMessage outGoingMessage; msgHandler->SendMessage( outGoingMessage.msg ); } else { // updates request psGUIInventoryMessage outGoingMessage(psGUIInventoryMessage::UPDATE_REQUEST); msgHandler->SendMessage( outGoingMessage.msg ); } return true; } void psInventoryCache::EmptyInventory(void) { // empty bulk inventory for ( int slot = 0; slot < INVENTORY_BULK_COUNT; slot++ ) EmptyInventoryItem(slot, CONTAINER_INVENTORY_BULK); // empty equip inventory for ( int slot = 0; slot < INVENTORY_EQUIP_COUNT; slot++ ) EmptyInventoryItem(slot, CONTAINER_INVENTORY_EQUIPMENT); } bool psInventoryCache::EmptyInventoryItem(int slot, int container) { // empty item in the appropriate inventory if (container == CONTAINER_INVENTORY_BULK && slot < INVENTORY_BULK_COUNT) { bulkItems[slot].stackCount = 0; bulkItems[slot].iconImage.Clear(); return true; } else if (container == CONTAINER_INVENTORY_EQUIPMENT && slot < INVENTORY_EQUIP_COUNT) { equipItems[slot].stackCount = 0; equipItems[slot].iconImage.Clear(); return true; } else return false; } bool psInventoryCache::SetInventoryItem(int slot, int container, csString name, float weight, float size, int stackCount, csString iconImage, int purifyStatus) { // store this item in the appropriate inventory if (container == CONTAINER_INVENTORY_BULK && slot < INVENTORY_BULK_COUNT) { bulkItems[slot].name = name; bulkItems[slot].weight = weight; bulkItems[slot].size = size; bulkItems[slot].stackCount = stackCount; bulkItems[slot].iconImage = iconImage; bulkItems[slot].purifyStatus = purifyStatus; return true; } else if (container == CONTAINER_INVENTORY_EQUIPMENT && slot < INVENTORY_EQUIP_COUNT) { equipItems[slot].name = name; equipItems[slot].weight = weight; equipItems[slot].size = size; equipItems[slot].stackCount = stackCount; equipItems[slot].iconImage = iconImage; equipItems[slot].purifyStatus = purifyStatus; return true; } else return false; } bool psInventoryCache::GetInventoryItem(int slot, int container, CachedItemDescription* item) { // get cache item if (container == CONTAINER_INVENTORY_BULK && slot < INVENTORY_BULK_COUNT) { *item = bulkItems[slot]; return true; } else if (container == CONTAINER_INVENTORY_EQUIPMENT && slot < INVENTORY_EQUIP_COUNT) { *item = equipItems[slot]; return true; } return false; }