]>
jfr.im git - irc/gameservirc.git/blob - gameserv-2.0/libgameservgldl/src/GameLayer/Helpers/InventoryManager.cpp
1 #include <GameServ/GameLayer/Helpers/InventoryManager.h>
2 using namespace GameServ::GameLayer::Helpers
;
4 #include <boost/smart_ptr/shared_ptr.hpp>
14 boost::shared_ptr
<InventoryManager
> InventoryManager::mInstance
= boost::shared_ptr
<InventoryManager
>();
16 InventoryManager::InventoryManager()
20 InventoryManager::~InventoryManager()
22 mInventoryTable
.clear();
26 boost::shared_ptr
<InventoryManager
> InventoryManager::Instance(void)
30 mInstance
= boost::shared_ptr
<InventoryManager
>(new InventoryManager());
35 void InventoryManager::AddItem(const string
&PlayerId
, boost::shared_ptr
<ItemGO
> spItem
)
37 mInventoryTable
[PlayerId
].push_back(spItem
);
40 void InventoryManager::RemoveItem(const string
&PlayerId
, boost::shared_ptr
<ItemGO
> spItem
)
43 PlayerInventoryMap::const_iterator iter
= mInventoryTable
.find(PlayerId
);
44 if (iter
!= mInventoryTable
.end())
46 if (iter
->second
.size() > 0)
48 ItemList::iterator itemIter
= find(mInventoryTable
[PlayerId
].begin(),
49 mInventoryTable
[PlayerId
].end(), spItem
);
50 if (itemIter
!= mInventoryTable
[PlayerId
].end())
52 mInventoryTable
[PlayerId
].erase(itemIter
);
58 bool InventoryManager::PlayerHasInventory(const string
&PlayerId
) const
60 PlayerInventoryMap::const_iterator iter
= mInventoryTable
.find(PlayerId
);
61 return (iter
!= mInventoryTable
.end());
64 ItemList
InventoryManager::GetInventory(const string
&PlayerId
) const
66 PlayerInventoryMap::const_iterator iter
= mInventoryTable
.find(PlayerId
);
67 if (iter
!= mInventoryTable
.end())