summaryrefslogtreecommitdiffstats
path: root/source/cInventory.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/cInventory.cpp85
1 files changed, 75 insertions, 10 deletions
diff --git a/source/cInventory.cpp b/source/cInventory.cpp
index 93edf2c57..e3c92f307 100644
--- a/source/cInventory.cpp
+++ b/source/cInventory.cpp
@@ -6,7 +6,6 @@
#include "cClientHandle.h"
#include "cWindow.h"
#include "cItem.h"
-#include "cRecipeChecker.h"
#include "cRoot.h"
#include <json/json.h>
@@ -27,6 +26,10 @@ cInventory::~cInventory()
CloseWindow();
}
+
+
+
+
cInventory::cInventory(cPlayer* a_Owner)
{
m_Owner = a_Owner;
@@ -52,6 +55,10 @@ cInventory::cInventory(cPlayer* a_Owner)
}
}
+
+
+
+
bool cInventory::AddItem( cItem & a_Item )
{
cItem BackupSlots[c_NumSlots];
@@ -84,6 +91,10 @@ bool cInventory::AddItem( cItem & a_Item )
return (a_Item.m_ItemCount == 0);
}
+
+
+
+
// TODO: Right now if you dont have enough items, the items you did have are removed, and the function returns false anyway
bool cInventory::RemoveItem( cItem & a_Item )
{
@@ -138,13 +149,21 @@ bool cInventory::RemoveItem( cItem & a_Item )
return false;
}
+
+
+
+
void cInventory::Clear()
{
for(unsigned int i = 0; i < c_NumSlots; i++)
m_Slots[i].Empty();
}
-cItem* cInventory::GetSlotsForType( int a_Type )
+
+
+
+
+cItem * cInventory::GetSlotsForType( int a_Type )
{
switch( a_Type )
{
@@ -158,19 +177,26 @@ cItem* cInventory::GetSlotsForType( int a_Type )
return 0;
}
+
+
+
+
int cInventory::GetSlotCountForType( int a_Type )
{
- switch( a_Type )
+ switch (a_Type)
{
- case -1:
- return 36;
- case -2:
- case -3:
- return 4;
+ case -1:
+ return 36;
+ case -2:
+ case -3:
+ return 4;
}
return 0;
}
-
+
+
+
+
cItem* cInventory::GetSlot( int a_SlotNum )
{
@@ -178,18 +204,33 @@ cItem* cInventory::GetSlot( int a_SlotNum )
return &m_Slots[a_SlotNum];
}
+
+
+
+
cItem* cInventory::GetFromHotBar( int a_SlotNum )
{
- if( a_SlotNum < 0 || a_SlotNum >= 9 ) return 0;
+ if ((a_SlotNum < 0) || (a_SlotNum >= 9))
+ {
+ return NULL;
+ }
return &m_HotSlots[a_SlotNum];
}
+
+
+
+
void cInventory::SetEquippedSlot( int a_SlotNum )
{
if( a_SlotNum < 0 || a_SlotNum >= 9 ) m_EquippedSlot = 0;
else m_EquippedSlot = (short)a_SlotNum;
}
+
+
+
+
cItem & cInventory::GetEquippedItem()
{
cItem* Item = GetFromHotBar( m_EquippedSlot );
@@ -205,12 +246,20 @@ cItem & cInventory::GetEquippedItem()
return *m_EquippedItem;
}
+
+
+
+
void cInventory::SendWholeInventory( cClientHandle* a_Client )
{
cPacket_WholeInventory Inventory( this );
a_Client->Send( Inventory );
}
+
+
+
+
void cInventory::SendSlot( int a_SlotNum )
{
cItem* Item = GetSlot( a_SlotNum );
@@ -226,6 +275,10 @@ void cInventory::SendSlot( int a_SlotNum )
}
}
+
+
+
+
bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size, bool* a_bChangedSlots, int a_Mode /* = 0 */ )
{
// Fill already present stacks
@@ -273,6 +326,10 @@ bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size,
return true;
}
+
+
+
+
void cInventory::SaveToJson(Json::Value & a_Value)
{
for(unsigned int i = 0; i < c_NumSlots; i++)
@@ -283,6 +340,10 @@ void cInventory::SaveToJson(Json::Value & a_Value)
}
}
+
+
+
+
bool cInventory::LoadFromJson(Json::Value & a_Value)
{
int SlotIdx = 0;
@@ -293,3 +354,7 @@ bool cInventory::LoadFromJson(Json::Value & a_Value)
}
return true;
}
+
+
+
+