From 5e6c7368592c0fbaa4d9d4320767d3cdcfd0261e Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Tue, 12 Jun 2012 20:03:46 +0000 Subject: 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 --- source/cCraftingWindow.cpp | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) (limited to 'source/cCraftingWindow.cpp') diff --git a/source/cCraftingWindow.cpp b/source/cCraftingWindow.cpp index 8d499c514..c84121a06 100644 --- a/source/cCraftingWindow.cpp +++ b/source/cCraftingWindow.cpp @@ -3,7 +3,6 @@ #include "cCraftingWindow.h" #include "cItem.h" -#include "cRecipeChecker.h" #include "CraftingRecipes.h" #include "cPlayer.h" #include "cClientHandle.h" @@ -71,34 +70,24 @@ void cCraftingWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_P if ((a_ClickPacket->m_SlotNum >= 0) && (a_ClickPacket->m_SlotNum < 10)) { - cItem CookedItem; + cCraftingGrid Grid(GetSlots() + 1, 3, 3); + cCraftingRecipe Recipe(Grid); + + cRoot::Get()->GetCraftingRecipes()->GetRecipe(Grid, Recipe); + if ((a_ClickPacket->m_SlotNum == 0) && !bDontCook) { - // 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 ); - } - } - else - { - 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 ); - } + // Consume the items from the crafting grid: + Recipe.ConsumeIngredients(Grid); + + // Propagate grid back to m_Slots: + Grid.CopyToItems(GetSlots() + 1); + + // Get the recipe for the new grid contents: + cRoot::Get()->GetCraftingRecipes()->GetRecipe(Grid, Recipe); } - *GetSlot(0) = CookedItem; - LOG("You cooked: %i x %i !!", GetSlot(0)->m_ItemID, GetSlot(0)->m_ItemCount ); + *GetSlot(0) = Recipe.GetResult(); + LOGD("You cooked: %i x %i !!", GetSlot(0)->m_ItemID, GetSlot(0)->m_ItemCount ); } SendWholeWindow( a_Player.GetClientHandle() ); a_Player.GetInventory().SendWholeInventory( a_Player.GetClientHandle() ); -- cgit v1.2.3