2012-01-29 14:28:19 -05:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
#include "cCraftingWindow.h"
|
|
|
|
#include "cItem.h"
|
|
|
|
#include "cRecipeChecker.h"
|
2012-06-04 08:08:20 -04:00
|
|
|
#include "CraftingRecipes.h"
|
2011-10-03 14:41:19 -04:00
|
|
|
#include "cPlayer.h"
|
|
|
|
#include "cClientHandle.h"
|
|
|
|
#include "cInventory.h"
|
|
|
|
#include "cPickup.h"
|
|
|
|
#include "cRoot.h"
|
2012-06-06 16:18:50 -04:00
|
|
|
#include "cWorld.h"
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
#include "packets/cPacket_WindowClick.h"
|
|
|
|
#include "packets/cPacket_InventorySlot.h"
|
|
|
|
|
2012-06-04 08:08:20 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
cCraftingWindow::cCraftingWindow( cWindowOwner* a_Owner, bool a_bInventoryVisible )
|
|
|
|
: cWindow( a_Owner, a_bInventoryVisible )
|
|
|
|
{
|
|
|
|
SetWindowID( 1 );
|
2011-12-25 08:44:22 -05:00
|
|
|
SetWindowType( cWindow::Workbench ); // Workbench
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
cItem* Slots = new cItem[10];
|
|
|
|
SetSlots( Slots, 10 );
|
|
|
|
}
|
|
|
|
|
2012-06-04 08:08:20 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
void cCraftingWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_Player )
|
|
|
|
{
|
|
|
|
bool bDontCook = false;
|
|
|
|
// Override for craft result slot
|
|
|
|
if( a_ClickPacket->m_SlotNum == 0 )
|
|
|
|
{
|
|
|
|
LOG("In craft slot: %i x %i !!", GetSlot(0)->m_ItemID, GetSlot(0)->m_ItemCount );
|
|
|
|
cItem* DraggingItem = GetDraggingItem( &a_Player );
|
|
|
|
if( DraggingItem->m_ItemID <= 0 )
|
|
|
|
{
|
|
|
|
*DraggingItem = *GetSlot(0);
|
|
|
|
GetSlot(0)->Empty();
|
|
|
|
}
|
|
|
|
else if( DraggingItem->Equals( *GetSlot(0) ) )
|
|
|
|
{
|
|
|
|
if( DraggingItem->m_ItemCount + GetSlot(0)->m_ItemCount <= 64 )
|
|
|
|
{
|
|
|
|
DraggingItem->m_ItemCount += GetSlot(0)->m_ItemCount;
|
|
|
|
GetSlot(0)->Empty();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bDontCook = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bDontCook = true;
|
|
|
|
}
|
|
|
|
LOG("Dragging Dish %i", DraggingItem->m_ItemCount );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cWindow::Clicked( a_ClickPacket, a_Player );
|
|
|
|
}
|
|
|
|
|
2012-06-04 08:08:20 -04:00
|
|
|
if ((a_ClickPacket->m_SlotNum >= 0) && (a_ClickPacket->m_SlotNum < 10))
|
2011-10-03 14:41:19 -04:00
|
|
|
{
|
|
|
|
cItem CookedItem;
|
2012-06-04 08:08:20 -04:00
|
|
|
if ((a_ClickPacket->m_SlotNum == 0) && !bDontCook)
|
2011-10-03 14:41:19 -04:00
|
|
|
{
|
2012-06-04 08:08:20 -04:00
|
|
|
// Consume the ingredients from the crafting grid:
|
|
|
|
CookedItem = cRoot::Get()->GetCraftingRecipes()->Craft(GetSlots() + 1, 3, 3);
|
|
|
|
LOGD("New recipes crafted: %i x %i", CookedItem.m_ItemID, CookedItem.m_ItemCount);
|
|
|
|
// Upgrade the crafting result from the new crafting grid contents:
|
|
|
|
CookedItem = cRoot::Get()->GetCraftingRecipes()->Offer(GetSlots() + 1, 3, 3);
|
|
|
|
if (CookedItem.IsEmpty())
|
|
|
|
{
|
|
|
|
// Fallback to the old recipes:
|
|
|
|
CookedItem = cRoot::Get()->GetRecipeChecker()->CookIngredients( GetSlots()+1, 3, 3, true );
|
|
|
|
LOGD("Old recipes crafted: %i x %i", CookedItem.m_ItemID, CookedItem.m_ItemCount );
|
|
|
|
}
|
2011-10-03 14:41:19 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-04 08:08:20 -04:00
|
|
|
CookedItem = cRoot::Get()->GetCraftingRecipes()->Offer(GetSlots() + 1, 3, 3);
|
|
|
|
LOGD("New recipes offer: %i x %i", CookedItem.m_ItemID, CookedItem.m_ItemCount );
|
|
|
|
if (CookedItem.IsEmpty())
|
|
|
|
{
|
|
|
|
// Fallback to the old recipes
|
|
|
|
CookedItem = cRoot::Get()->GetRecipeChecker()->CookIngredients( GetSlots()+1, 3, 3 );
|
|
|
|
LOGD("Old recipes offer: %i x %i", CookedItem.m_ItemID, CookedItem.m_ItemCount );
|
|
|
|
}
|
2011-10-03 14:41:19 -04:00
|
|
|
}
|
|
|
|
*GetSlot(0) = CookedItem;
|
|
|
|
LOG("You cooked: %i x %i !!", GetSlot(0)->m_ItemID, GetSlot(0)->m_ItemCount );
|
|
|
|
}
|
|
|
|
SendWholeWindow( a_Player.GetClientHandle() );
|
|
|
|
a_Player.GetInventory().SendWholeInventory( a_Player.GetClientHandle() );
|
2012-06-04 08:08:20 -04:00
|
|
|
|
|
|
|
// Separate packet for result =/ Don't know why
|
2011-10-03 14:41:19 -04:00
|
|
|
cPacket_InventorySlot Packet;
|
|
|
|
Packet.m_WindowID = (char)GetWindowID();
|
|
|
|
Packet.m_SlotNum = 0;
|
|
|
|
Packet.m_ItemID = (short)GetSlot(0)->m_ItemID;
|
|
|
|
Packet.m_ItemCount = GetSlot(0)->m_ItemCount;
|
|
|
|
Packet.m_ItemUses = (char)GetSlot(0)->m_ItemHealth;
|
|
|
|
a_Player.GetClientHandle()->Send( Packet );
|
|
|
|
}
|
|
|
|
|
2012-06-04 08:08:20 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-06 16:18:50 -04:00
|
|
|
void cCraftingWindow::Close(cPlayer & a_Player)
|
2011-10-03 14:41:19 -04:00
|
|
|
{
|
|
|
|
// Start from slot 1, don't drop what's in the result slot
|
2012-06-06 16:18:50 -04:00
|
|
|
cItems Drops;
|
2011-10-03 14:41:19 -04:00
|
|
|
for( int i = 1; i < GetNumSlots(); i++ )
|
|
|
|
{
|
2012-06-06 16:18:50 -04:00
|
|
|
cItem * Item = GetSlot(i);
|
|
|
|
if (!Item->IsEmpty())
|
2011-10-03 14:41:19 -04:00
|
|
|
{
|
2012-06-06 16:18:50 -04:00
|
|
|
Drops.push_back(*Item);
|
2011-10-03 14:41:19 -04:00
|
|
|
}
|
|
|
|
Item->Empty();
|
|
|
|
}
|
2012-06-06 16:18:50 -04:00
|
|
|
float vX = 0, vY = 0, vZ = 0;
|
|
|
|
EulerToVector( -a_Player.GetRotation(), a_Player.GetPitch(), vZ, vX, vY);
|
|
|
|
vY = -vY*2 + 1.f;
|
|
|
|
a_Player.GetWorld()->SpawnItemPickups(Drops, a_Player.GetPosX(), a_Player.GetPosY() + 1.6f, a_Player.GetPosZ(), vX * 2, vY * 2, vZ * 2);
|
|
|
|
cWindow::Close(a_Player);
|
2012-06-04 08:08:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|