1
0

Updated the crafting recipes architecture to better support crafting hooks. Removed the old recipe file and implementation altogether.

git-svn-id: http://mc-server.googlecode.com/svn/trunk@597 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com
2012-06-12 20:03:46 +00:00
parent e147996f06
commit 5e6c736859
19 changed files with 1401 additions and 1040 deletions

View File

@@ -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;
}