From 0c2b307eab67b7f37d82a7862a6acbcd96b45adb Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 20 Jan 2014 18:22:08 +0100 Subject: first changes for enchanting (not finished) - added enchanting table block handler and added it to the blockhandler - added enchanting window - drop item in the slot 0 when the player close the window - added enchanting packet (1.7 only) - some more... --- src/UI/SlotArea.cpp | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'src/UI/SlotArea.cpp') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index bfcad3d92..ae6bfccb5 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -562,6 +562,92 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player) +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cSlotAreaEnchanting: + +cSlotAreaEnchanting::cSlotAreaEnchanting(int a_NumSlots, cWindow & a_ParentWindow) : +cSlotAreaTemporary(a_NumSlots, a_ParentWindow) +{ +} + + + + + +void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) +{ + LOG("Clicked"); + // Check if Slot is in the Enchantment Table + if (a_SlotNum == 0) + { + if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick)) + { + ShiftClickedResult(a_Player); + } + else + { + ClickedResult(a_Player); + } + return; + } + super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); +} + + + + + +void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) +{ + // Toss the item in the enchanting slot + TossItems(a_Player, 0, 0); + // Player not found - that is acceptable +} + + + + + +void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) +{ + LOG("Click!"); + + if (a_Player.GetDraggingItem().IsEmpty()) + { + LOG("EMPTY"); + this->m_ParentWindow.SetProperty(0, NULL); + this->m_ParentWindow.SetProperty(1, NULL); + this->m_ParentWindow.SetProperty(2, NULL); + } + else if (a_Player.GetDraggingItem().IsEnchantable) + { + LOG("Enchantable"); + this->m_ParentWindow.SetProperty(0, 30); + this->m_ParentWindow.SetProperty(1, 20); + this->m_ParentWindow.SetProperty(2, 10); + } + else + { + LOG("Not Enchantable"); + this->m_ParentWindow.SetProperty(0, NULL); + this->m_ParentWindow.SetProperty(1, NULL); + this->m_ParentWindow.SetProperty(2, NULL); + } +} + + + + + +void cSlotAreaEnchanting::ShiftClickedResult(cPlayer & a_Player) +{ + LOG("Shift Click!"); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaEnderChest: -- cgit v1.2.3 From bfac00f2807a6740e876adebd689cc3ae6e075ed Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Fri, 24 Jan 2014 20:01:21 +0100 Subject: Some updates for enchanting --- src/UI/SlotArea.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/UI/SlotArea.cpp') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index ae6bfccb5..a226d027b 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -576,7 +576,7 @@ cSlotAreaTemporary(a_NumSlots, a_ParentWindow) void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) { - LOG("Clicked"); + LOGWARN("Clicked"); // Check if Slot is in the Enchantment Table if (a_SlotNum == 0) { @@ -610,28 +610,28 @@ void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) { - LOG("Click!"); + LOGWARN("Click!"); if (a_Player.GetDraggingItem().IsEmpty()) { - LOG("EMPTY"); - this->m_ParentWindow.SetProperty(0, NULL); - this->m_ParentWindow.SetProperty(1, NULL); - this->m_ParentWindow.SetProperty(2, NULL); + LOGWARN("EMPTY"); + this->m_ParentWindow.SetProperty(0, 0); + this->m_ParentWindow.SetProperty(1, 0); + this->m_ParentWindow.SetProperty(2, 0); } else if (a_Player.GetDraggingItem().IsEnchantable) { - LOG("Enchantable"); + LOGWARN("Enchantable"); this->m_ParentWindow.SetProperty(0, 30); this->m_ParentWindow.SetProperty(1, 20); this->m_ParentWindow.SetProperty(2, 10); } else { - LOG("Not Enchantable"); - this->m_ParentWindow.SetProperty(0, NULL); - this->m_ParentWindow.SetProperty(1, NULL); - this->m_ParentWindow.SetProperty(2, NULL); + LOGWARN("Not Enchantable"); + this->m_ParentWindow.SetProperty(0, 0); + this->m_ParentWindow.SetProperty(1, 0); + this->m_ParentWindow.SetProperty(2, 0); } } @@ -641,7 +641,7 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) void cSlotAreaEnchanting::ShiftClickedResult(cPlayer & a_Player) { - LOG("Shift Click!"); + LOGWARN("Shift Click!"); } -- cgit v1.2.3 From af566d5a79134842854bea78de577676d507949f Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 7 Apr 2014 19:52:35 +0200 Subject: Added Enchantment-Slot-Level generating --- src/UI/SlotArea.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'src/UI/SlotArea.cpp') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index a226d027b..03bfd275a 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -13,6 +13,8 @@ #include "Window.h" #include "../CraftingRecipes.h" #include "../Root.h" +#include "../FastRandom.h" +#include "../BlockArea.h" @@ -615,23 +617,31 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) if (a_Player.GetDraggingItem().IsEmpty()) { LOGWARN("EMPTY"); - this->m_ParentWindow.SetProperty(0, 0); - this->m_ParentWindow.SetProperty(1, 0); - this->m_ParentWindow.SetProperty(2, 0); + m_ParentWindow.SetProperty(0, 0); + m_ParentWindow.SetProperty(1, 0); + m_ParentWindow.SetProperty(2, 0); } else if (a_Player.GetDraggingItem().IsEnchantable) { + int bookshelves = 15; // TODO: Check Bookshelves + + cFastRandom Random; + int base = (Random.GenerateRandomInteger(1, 8) + floor(bookshelves / 2) + Random.GenerateRandomInteger(0, bookshelves)); + int topSlot = std::max(base / 3, 1); + int middleSlot = (base * 2) / 3 + 1; + int bottomSlot = std::max(base, bookshelves * 2); + LOGWARN("Enchantable"); - this->m_ParentWindow.SetProperty(0, 30); - this->m_ParentWindow.SetProperty(1, 20); - this->m_ParentWindow.SetProperty(2, 10); + m_ParentWindow.SetProperty(0, topSlot); + m_ParentWindow.SetProperty(1, middleSlot); + m_ParentWindow.SetProperty(2, bottomSlot); } else { LOGWARN("Not Enchantable"); - this->m_ParentWindow.SetProperty(0, 0); - this->m_ParentWindow.SetProperty(1, 0); - this->m_ParentWindow.SetProperty(2, 0); + m_ParentWindow.SetProperty(0, 0); + m_ParentWindow.SetProperty(1, 0); + m_ParentWindow.SetProperty(2, 0); } } -- cgit v1.2.3 From e6e702e7fdbc8b7475d3dbecc0f81a08304997ae Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 12 Apr 2014 14:58:46 +0200 Subject: Added complete Enchanting System http://minecraft.gamepedia.com/Enchantment_mechanics --- src/UI/SlotArea.cpp | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) (limited to 'src/UI/SlotArea.cpp') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 9463bc593..f76b11380 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -608,7 +608,6 @@ cSlotAreaTemporary(a_NumSlots, a_ParentWindow) void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) { - LOGWARN("Clicked"); // Check if Slot is in the Enchantment Table if (a_SlotNum == 0) { @@ -642,17 +641,39 @@ void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) { - LOGWARN("Click!"); - if (a_Player.GetDraggingItem().IsEmpty()) { - LOGWARN("EMPTY"); - m_ParentWindow.SetProperty(0, 0); - m_ParentWindow.SetProperty(1, 0); - m_ParentWindow.SetProperty(2, 0); + m_ParentWindow.SetProperty(0, 0, a_Player); + m_ParentWindow.SetProperty(1, 0, a_Player); + m_ParentWindow.SetProperty(2, 0, a_Player); } else if (a_Player.GetDraggingItem().IsEnchantable) { + int PosX = 0; + int PosY = 0; + int PosZ = 0; + cEnchantingWindow * Window = (cEnchantingWindow*)&m_ParentWindow; + Window->GetBlockPos(PosX, PosY, PosZ); + + cBlockArea Area; + Area.Read(a_Player.GetWorld(), PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); + + for (int x = 0; x < 7; x++) + { + for (int y = 0; y < 2; y++) + { + for (int z = 0; z < 7; z++) + { + LOG(Printf("%i", Area.GetBlockType(x, y, z)).c_str()); + + if (Area.GetBlockType(x, y, z) == E_BLOCK_BOOKCASE) + { + LOG("BookShelf"); + } + } + } + } + int bookshelves = 15; // TODO: Check Bookshelves cFastRandom Random; @@ -661,17 +682,15 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) int middleSlot = (base * 2) / 3 + 1; int bottomSlot = std::max(base, bookshelves * 2); - LOGWARN("Enchantable"); - m_ParentWindow.SetProperty(0, topSlot); - m_ParentWindow.SetProperty(1, middleSlot); - m_ParentWindow.SetProperty(2, bottomSlot); + m_ParentWindow.SetProperty(0, topSlot, a_Player); + m_ParentWindow.SetProperty(1, middleSlot, a_Player); + m_ParentWindow.SetProperty(2, bottomSlot, a_Player); } else { - LOGWARN("Not Enchantable"); - m_ParentWindow.SetProperty(0, 0); - m_ParentWindow.SetProperty(1, 0); - m_ParentWindow.SetProperty(2, 0); + m_ParentWindow.SetProperty(0, 0, a_Player); + m_ParentWindow.SetProperty(1, 0, a_Player); + m_ParentWindow.SetProperty(2, 0, a_Player); } } -- cgit v1.2.3 From dd1f8fb1f5640d9f9d58098c8aefbc1c1ad308ab Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 12 Apr 2014 18:52:17 +0200 Subject: Fixed Bookshelves Checking (not completly) --- src/UI/SlotArea.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/UI/SlotArea.cpp') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index f76b11380..d43b91700 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -658,17 +658,20 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) cBlockArea Area; Area.Read(a_Player.GetWorld(), PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); - for (int x = 0; x < 7; x++) + for (int x = 0; x < 6; x++) { - for (int y = 0; y < 2; y++) + for (int y = 0; y < 3; y++) { - for (int z = 0; z < 7; z++) + for (int z = 0; z < 6; z++) { - LOG(Printf("%i", Area.GetBlockType(x, y, z)).c_str()); - - if (Area.GetBlockType(x, y, z) == E_BLOCK_BOOKCASE) + if ((((x == 0) || (x == 5)) || ((z == 0) || (z == 5))) && ((y == 0) || y == 1)) { - LOG("BookShelf"); + LOG("%i", Area.GetRelBlockType(x, y, z)); + + if (Area.GetRelBlockType(x, y, z) == E_BLOCK_BOOKCASE) + { + LOG("BookShelf"); + } } } } -- cgit v1.2.3 From 1429d2f1b1802e1be5f5551df890562b4a014342 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sun, 13 Apr 2014 13:33:47 +0200 Subject: Some Fixes --- src/UI/SlotArea.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/UI/SlotArea.cpp') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index d43b91700..352558d9e 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -647,7 +647,7 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) m_ParentWindow.SetProperty(1, 0, a_Player); m_ParentWindow.SetProperty(2, 0, a_Player); } - else if (a_Player.GetDraggingItem().IsEnchantable) + else if (cItem::IsEnchantable(a_Player.GetDraggingItem().m_ItemType)) { int PosX = 0; int PosY = 0; -- cgit v1.2.3 From fce9ea65c35ab7f94c23bb361386b5ce223279eb Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sun, 13 Apr 2014 22:15:10 +0200 Subject: Fixed invisibility enchantments --- src/UI/SlotArea.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/UI/SlotArea.cpp') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 352558d9e..35230cffb 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -600,6 +600,8 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player) cSlotAreaEnchanting::cSlotAreaEnchanting(int a_NumSlots, cWindow & a_ParentWindow) : cSlotAreaTemporary(a_NumSlots, a_ParentWindow) { + cEnchantingWindow * Window = (cEnchantingWindow *)&m_ParentWindow; + Window->m_SlotArea = this; } -- cgit v1.2.3 From 856e900bf8e74cb478904d6322dcb6310ff7a3b2 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 14 Apr 2014 11:48:12 +0200 Subject: Bug fixes --- src/UI/SlotArea.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src/UI/SlotArea.cpp') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 35230cffb..673c036b6 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -608,8 +608,21 @@ cSlotAreaTemporary(a_NumSlots, a_ParentWindow) +void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) +{ + // Toss the item in the enchanting slot + TossItems(a_Player, 0, 1); + // Player not found - that is acceptable +} + + + + + void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) { + super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); + // Check if Slot is in the Enchantment Table if (a_SlotNum == 0) { @@ -621,20 +634,7 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio { ClickedResult(a_Player); } - return; } - super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); -} - - - - - -void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) -{ - // Toss the item in the enchanting slot - TossItems(a_Player, 0, 0); - // Player not found - that is acceptable } @@ -643,13 +643,15 @@ void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) { - if (a_Player.GetDraggingItem().IsEmpty()) + cItem Item = *GetSlot(0, a_Player); + + if (Item.IsEmpty()) { m_ParentWindow.SetProperty(0, 0, a_Player); m_ParentWindow.SetProperty(1, 0, a_Player); m_ParentWindow.SetProperty(2, 0, a_Player); } - else if (cItem::IsEnchantable(a_Player.GetDraggingItem().m_ItemType)) + else if (cItem::IsEnchantable(Item.m_ItemType)) { int PosX = 0; int PosY = 0; -- cgit v1.2.3 From fb26d2ba870f63deb5515521ecf5ce0c35780a2b Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 14 Apr 2014 11:56:50 +0200 Subject: Fixed Bookshelf Checking Code by LO1ZB --- src/UI/SlotArea.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/UI/SlotArea.cpp') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 673c036b6..23108c256 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -659,29 +659,31 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) cEnchantingWindow * Window = (cEnchantingWindow*)&m_ParentWindow; Window->GetBlockPos(PosX, PosY, PosZ); + int bookshelves = 0; cBlockArea Area; Area.Read(a_Player.GetWorld(), PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); - for (int x = 0; x < 6; x++) + for (int y = 0; y <= 2; y++) { - for (int y = 0; y < 3; y++) + for (int x = 0; x <= 4; x++) { - for (int z = 0; z < 6; z++) + for (int z = 0; z <= 4; z++) { - if ((((x == 0) || (x == 5)) || ((z == 0) || (z == 5))) && ((y == 0) || y == 1)) + if ((((x == 0) || (x == 4)) || ((z == 0) || (z == 4))) && ((y == 0) || y == 1)) { - LOG("%i", Area.GetRelBlockType(x, y, z)); - if (Area.GetRelBlockType(x, y, z) == E_BLOCK_BOOKCASE) { - LOG("BookShelf"); + bookshelves++; } } } } } - int bookshelves = 15; // TODO: Check Bookshelves + if (bookshelves > 15) + { + bookshelves = 15; + } cFastRandom Random; int base = (Random.GenerateRandomInteger(1, 8) + floor(bookshelves / 2) + Random.GenerateRandomInteger(0, bookshelves)); -- cgit v1.2.3 From a51a099c81f34f875c76d560e6729889b2fdd4fa Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 14 Apr 2014 13:39:44 +0200 Subject: Blocked enchanting a item twice --- src/UI/SlotArea.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/UI/SlotArea.cpp') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 23108c256..eb528d7ca 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -628,11 +628,11 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio { if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick)) { - ShiftClickedResult(a_Player); + ShiftClickedSlot(a_Player); } else { - ClickedResult(a_Player); + ClickedSlot(a_Player); } } } @@ -641,7 +641,7 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio -void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) +void cSlotAreaEnchanting::ClickedSlot(cPlayer & a_Player) { cItem Item = *GetSlot(0, a_Player); @@ -651,7 +651,7 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) m_ParentWindow.SetProperty(1, 0, a_Player); m_ParentWindow.SetProperty(2, 0, a_Player); } - else if (cItem::IsEnchantable(Item.m_ItemType)) + else if (cItem::IsEnchantable(Item.m_ItemType) && Item.m_Enchantments.IsEmpty()) { int PosX = 0; int PosY = 0; @@ -707,9 +707,11 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) -void cSlotAreaEnchanting::ShiftClickedResult(cPlayer & a_Player) +void cSlotAreaEnchanting::ShiftClickedSlot(cPlayer & a_Player) { - LOGWARN("Shift Click!"); + m_ParentWindow.SetProperty(0, 0, a_Player); + m_ParentWindow.SetProperty(1, 0, a_Player); + m_ParentWindow.SetProperty(2, 0, a_Player); } -- cgit v1.2.3 From b5401ec03ad74782129e6a68eac3e9c0ccb573e2 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 14 Apr 2014 22:05:04 +0200 Subject: Added ItemPlaceCount in SlotArea Thanks to Howaner for helping --- src/UI/SlotArea.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/UI/SlotArea.cpp') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index eb528d7ca..9ea2e0021 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -135,6 +135,12 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA cItem tmp(DraggingItem); DraggingItem = Slot; Slot = tmp; + int ItemPlaceCount = GetItemPlaceCount(Slot); + if (Slot.m_ItemCount > ItemPlaceCount) + { + DraggingItem.m_ItemCount += Slot.m_ItemCount - ItemPlaceCount; + Slot.m_ItemCount = ItemPlaceCount; + } } else { @@ -147,6 +153,13 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA FreeSlots = 0; } int Filling = (FreeSlots > DraggingItem.m_ItemCount) ? DraggingItem.m_ItemCount : FreeSlots; + + int ItemPlaceCount = GetItemPlaceCount(DraggingItem); + if (Filling > ItemPlaceCount) + { + Filling = ItemPlaceCount; + } + Slot.m_ItemCount += (char)Filling; DraggingItem.m_ItemCount -= (char)Filling; if (DraggingItem.m_ItemCount <= 0) @@ -315,6 +328,16 @@ bool cSlotArea::CollectItemsToHand(cItem & a_Dragging, cPlayer & a_Player, bool +int cSlotArea::GetItemPlaceCount(cItem & a_Item) +{ + cItemHandler * Handler = ItemHandler(a_Item.m_ItemType); + return Handler->GetMaxStackSize(); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaChest: @@ -718,6 +741,15 @@ void cSlotAreaEnchanting::ShiftClickedSlot(cPlayer & a_Player) +int cSlotAreaEnchanting::GetItemPlaceCount(cItem & a_Item) +{ + return 1; +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaEnderChest: -- cgit v1.2.3 From e81fc2779e4b9a8ce847d63864537259033c9cb9 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 15 Apr 2014 21:10:44 +0200 Subject: Add more checks to cSlotAreaEnchanting --- src/UI/SlotArea.cpp | 286 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 198 insertions(+), 88 deletions(-) (limited to 'src/UI/SlotArea.cpp') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 9ea2e0021..46ed493d8 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -135,12 +135,6 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA cItem tmp(DraggingItem); DraggingItem = Slot; Slot = tmp; - int ItemPlaceCount = GetItemPlaceCount(Slot); - if (Slot.m_ItemCount > ItemPlaceCount) - { - DraggingItem.m_ItemCount += Slot.m_ItemCount - ItemPlaceCount; - Slot.m_ItemCount = ItemPlaceCount; - } } else { @@ -154,12 +148,6 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA } int Filling = (FreeSlots > DraggingItem.m_ItemCount) ? DraggingItem.m_ItemCount : FreeSlots; - int ItemPlaceCount = GetItemPlaceCount(DraggingItem); - if (Filling > ItemPlaceCount) - { - Filling = ItemPlaceCount; - } - Slot.m_ItemCount += (char)Filling; DraggingItem.m_ItemCount -= (char)Filling; if (DraggingItem.m_ItemCount <= 0) @@ -182,7 +170,6 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA { m_ParentWindow.BroadcastWholeWindow(); } - } @@ -328,16 +315,6 @@ bool cSlotArea::CollectItemsToHand(cItem & a_Dragging, cPlayer & a_Player, bool -int cSlotArea::GetItemPlaceCount(cItem & a_Item) -{ - cItemHandler * Handler = ItemHandler(a_Item.m_ItemType); - return Handler->GetMaxStackSize(); -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaChest: @@ -620,51 +597,200 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaEnchanting: -cSlotAreaEnchanting::cSlotAreaEnchanting(int a_NumSlots, cWindow & a_ParentWindow) : -cSlotAreaTemporary(a_NumSlots, a_ParentWindow) +cSlotAreaEnchanting::cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow) : + cSlotAreaTemporary(1, a_ParentWindow) { - cEnchantingWindow * Window = (cEnchantingWindow *)&m_ParentWindow; - Window->m_SlotArea = this; + a_ParentWindow.m_SlotArea = this; } -void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) +void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) { - // Toss the item in the enchanting slot - TossItems(a_Player, 0, 1); - // Player not found - that is acceptable + ASSERT((a_SlotNum >= 0) && (a_SlotNum < GetNumSlots())); + + bool bAsync = false; + if (GetSlot(a_SlotNum, a_Player) == NULL) + { + LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum); + return; + } + + switch (a_ClickAction) + { + case caShiftLeftClick: + case caShiftRightClick: + { + ShiftClicked(a_Player, a_SlotNum, a_ClickedItem); + return; + } + + case caDblClick: + { + DblClicked(a_Player, a_SlotNum); + return; + } + default: + { + break; + } + } + + cItem Slot(*GetSlot(a_SlotNum, a_Player)); + if (!Slot.IsSameType(a_ClickedItem)) + { + LOGWARNING("*** Window lost sync at item %d in SlotArea with %d items ***", a_SlotNum, m_NumSlots); + LOGWARNING("My item: %s", ItemToFullString(Slot).c_str()); + LOGWARNING("Their item: %s", ItemToFullString(a_ClickedItem).c_str()); + bAsync = true; + } + cItem & DraggingItem = a_Player.GetDraggingItem(); + switch (a_ClickAction) + { + case caRightClick: + { + // Right-clicked + if (DraggingItem.IsEmpty()) + { + DraggingItem = Slot.CopyOne(); + Slot.Empty(); + break; + } + + if (Slot.IsEmpty()) + { + Slot = DraggingItem.CopyOne(); + DraggingItem.m_ItemCount -= 1; + if (DraggingItem.m_ItemCount <= 0) + { + DraggingItem.Empty(); + } + } + else if ((!DraggingItem.IsEqual(Slot)) && (DraggingItem.m_ItemCount == 1)) + { + // Swap contents + cItem tmp(DraggingItem); + DraggingItem = Slot; + Slot = tmp; + } + break; + } + + case caLeftClick: + { + // Left-clicked + if (DraggingItem.IsEmpty()) + { + DraggingItem = Slot.CopyOne(); + Slot.Empty(); + break; + } + + if (DraggingItem.IsEqual(Slot)) + { + // Do nothing + break; + } + + if (!Slot.IsEmpty()) + { + if (DraggingItem.m_ItemCount == 1) + { + // Swap contents + cItem tmp(DraggingItem); + DraggingItem = Slot; + Slot = tmp; + } + } + else + { + Slot = DraggingItem.CopyOne(); + DraggingItem.m_ItemCount -= 1; + if (DraggingItem.m_ItemCount <= 0) + { + DraggingItem.Empty(); + } + } + break; + } + default: + { + LOGWARNING("SlotArea: Unhandled click action: %d (%s)", a_ClickAction, ClickActionToString(a_ClickAction)); + m_ParentWindow.BroadcastWholeWindow(); + return; + } + } // switch (a_ClickAction + + SetSlot(a_SlotNum, a_Player, Slot); + if (bAsync) + { + m_ParentWindow.BroadcastWholeWindow(); + } + UpdateResult(a_Player); } -void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) +void cSlotAreaEnchanting::DblClicked(cPlayer & a_Player, int a_SlotNum) { - super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); + cItem & Dragging = a_Player.GetDraggingItem(); + if ((!Dragging.IsEmpty()) || (a_SlotNum != 0)) + { + return; + } + + cItem Item = *GetSlot(0, a_Player); + if (!m_ParentWindow.CollectItemsToHand(Item, *this, a_Player, false)) + { + m_ParentWindow.CollectItemsToHand(Item, *this, a_Player, true); + } +} - // Check if Slot is in the Enchantment Table - if (a_SlotNum == 0) + + + + +void cSlotAreaEnchanting::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_Apply, bool a_KeepEmptySlots) +{ + const cItem * Slot = GetSlot(0, a_Player); + if (!Slot->IsEmpty()) { - if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick)) - { - ShiftClickedSlot(a_Player); - } - else - { - ClickedSlot(a_Player); - } + return; } + + if (a_Apply) + { + SetSlot(0, a_Player, a_ItemStack.CopyOne()); + } + a_ItemStack.m_ItemCount -= 1; + if (a_ItemStack.m_ItemCount <= 0) + { + a_ItemStack.Empty(); + } + + UpdateResult(a_Player); +} + + + + + +void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) +{ + // Toss the item in the enchanting slot + TossItems(a_Player, 0, 1); + // Player not found - that is acceptable } -void cSlotAreaEnchanting::ClickedSlot(cPlayer & a_Player) +void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player) { cItem Item = *GetSlot(0, a_Player); @@ -676,43 +802,13 @@ void cSlotAreaEnchanting::ClickedSlot(cPlayer & a_Player) } else if (cItem::IsEnchantable(Item.m_ItemType) && Item.m_Enchantments.IsEmpty()) { - int PosX = 0; - int PosY = 0; - int PosZ = 0; - cEnchantingWindow * Window = (cEnchantingWindow*)&m_ParentWindow; - Window->GetBlockPos(PosX, PosY, PosZ); - - int bookshelves = 0; - cBlockArea Area; - Area.Read(a_Player.GetWorld(), PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); - - for (int y = 0; y <= 2; y++) - { - for (int x = 0; x <= 4; x++) - { - for (int z = 0; z <= 4; z++) - { - if ((((x == 0) || (x == 4)) || ((z == 0) || (z == 4))) && ((y == 0) || y == 1)) - { - if (Area.GetRelBlockType(x, y, z) == E_BLOCK_BOOKCASE) - { - bookshelves++; - } - } - } - } - } - - if (bookshelves > 15) - { - bookshelves = 15; - } + int Bookshelves = GetBookshelvesCount(a_Player.GetWorld()); cFastRandom Random; - int base = (Random.GenerateRandomInteger(1, 8) + floor(bookshelves / 2) + Random.GenerateRandomInteger(0, bookshelves)); + int base = (Random.GenerateRandomInteger(1, 8) + floor(Bookshelves / 2) + Random.GenerateRandomInteger(0, Bookshelves)); int topSlot = std::max(base / 3, 1); int middleSlot = (base * 2) / 3 + 1; - int bottomSlot = std::max(base, bookshelves * 2); + int bottomSlot = std::max(base, Bookshelves * 2); m_ParentWindow.SetProperty(0, topSlot, a_Player); m_ParentWindow.SetProperty(1, middleSlot, a_Player); @@ -730,20 +826,34 @@ void cSlotAreaEnchanting::ClickedSlot(cPlayer & a_Player) -void cSlotAreaEnchanting::ShiftClickedSlot(cPlayer & a_Player) +int cSlotAreaEnchanting::GetBookshelvesCount(cWorld * a_World) { - m_ParentWindow.SetProperty(0, 0, a_Player); - m_ParentWindow.SetProperty(1, 0, a_Player); - m_ParentWindow.SetProperty(2, 0, a_Player); -} - - + int PosX, PosY, PosZ; + ((cEnchantingWindow*)&m_ParentWindow)->GetBlockPos(PosX, PosY, PosZ); + int Bookshelves = 0; + cBlockArea Area; + Area.Read(a_World, PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); - -int cSlotAreaEnchanting::GetItemPlaceCount(cItem & a_Item) -{ - return 1; + for (int y = 0; y <= 2; y++) + { + for (int x = 0; x <= 4; x++) + { + for (int z = 0; z <= 4; z++) + { + if ((((x == 0) || (x == 4)) || ((z == 0) || (z == 4))) && ((y == 0) || y == 1)) + { + if (Area.GetRelBlockType(x, y, z) == E_BLOCK_BOOKCASE) + { + Bookshelves++; + } + } + } + } + } + + Bookshelves = std::min(Bookshelves, 15); + return Bookshelves; } -- cgit v1.2.3 From 36f747d6746b32c4352354933b25ae7ead6f1b7f Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Tue, 15 Apr 2014 21:43:52 +0200 Subject: Added Book Enchanting --- src/UI/SlotArea.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/UI/SlotArea.cpp') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 46ed493d8..d8d02f458 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -800,7 +800,7 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player) m_ParentWindow.SetProperty(1, 0, a_Player); m_ParentWindow.SetProperty(2, 0, a_Player); } - else if (cItem::IsEnchantable(Item.m_ItemType) && Item.m_Enchantments.IsEmpty()) + else if (cItem::IsEnchantable(Item.m_ItemType) || Item.m_ItemType == E_ITEM_BOOK && Item.m_Enchantments.IsEmpty()) { int Bookshelves = GetBookshelvesCount(a_Player.GetWorld()); -- cgit v1.2.3 From 8c33b3c4155b030e2174a453ca067be969473736 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Wed, 16 Apr 2014 13:31:37 +0200 Subject: Fixed double enchanting items --- src/UI/SlotArea.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/UI/SlotArea.cpp') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index d8d02f458..621854518 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -794,13 +794,13 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player) { cItem Item = *GetSlot(0, a_Player); - if (Item.IsEmpty()) + if (Item.IsEmpty() || !Item.m_Enchantments.IsEmpty()) { m_ParentWindow.SetProperty(0, 0, a_Player); m_ParentWindow.SetProperty(1, 0, a_Player); m_ParentWindow.SetProperty(2, 0, a_Player); } - else if (cItem::IsEnchantable(Item.m_ItemType) || Item.m_ItemType == E_ITEM_BOOK && Item.m_Enchantments.IsEmpty()) + else if (cItem::IsEnchantable(Item.m_ItemType) || Item.m_ItemType == E_ITEM_BOOK) { int Bookshelves = GetBookshelvesCount(a_Player.GetWorld()); -- cgit v1.2.3 From f9343a8490b50cb28a62c7327c0013da48ca2745 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Thu, 17 Apr 2014 13:15:35 +0200 Subject: Modified many things --- src/UI/SlotArea.cpp | 66 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 16 deletions(-) (limited to 'src/UI/SlotArea.cpp') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 621854518..26fdfe928 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -802,7 +802,7 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player) } else if (cItem::IsEnchantable(Item.m_ItemType) || Item.m_ItemType == E_ITEM_BOOK) { - int Bookshelves = GetBookshelvesCount(a_Player.GetWorld()); + int Bookshelves = std::min(GetBookshelvesCount(a_Player.GetWorld()), 15); cFastRandom Random; int base = (Random.GenerateRandomInteger(1, 8) + floor(Bookshelves / 2) + Random.GenerateRandomInteger(0, Bookshelves)); @@ -835,24 +835,58 @@ int cSlotAreaEnchanting::GetBookshelvesCount(cWorld * a_World) cBlockArea Area; Area.Read(a_World, PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); - for (int y = 0; y <= 2; y++) + static const struct { - for (int x = 0; x <= 4; x++) + int m_BookX, m_BookY, m_BookZ; // Coords to check for bookcases + int m_AirX, m_AirY, m_AirZ; // Coords to check for air; if not air, the bookcase won\'t be counted + } CheckCoords[] = + { + { 0, 0, 0, 1, 0, 1 }, // Bookcase at {0, 0, 0}, air at {1, 0, 1} + { 0, 0, 1, 1, 0, 1 }, // Bookcase at {0, 0, 1}, air at {1, 0, 1} + { 0, 0, 2, 1, 0, 2 }, // Bookcase at {0, 0, 2}, air at {1, 0, 2} + { 0, 0, 3, 1, 0, 3 }, // Bookcase at {0, 0, 3}, air at {1, 0, 3} + { 0, 0, 4, 1, 0, 3 }, // Bookcase at {0, 0, 4}, air at {1, 0, 3} + { 1, 0, 4, 1, 0, 3 }, // Bookcase at {1, 0, 4}, air at {1, 0, 3} + { 2, 0, 4, 2, 0, 3 }, // Bookcase at {2, 0, 4}, air at {2, 0, 3} + { 3, 0, 4, 3, 0, 3 }, // Bookcase at {3, 0, 4}, air at {3, 0, 3} + { 4, 0, 4, 3, 0, 3 }, // Bookcase at {4, 0, 4}, air at {3, 0, 3} + { 4, 0, 3, 3, 0, 3 }, // Bookcase at {4, 0, 3}, air at {3, 0, 3} + { 4, 0, 2, 3, 0, 2 }, // Bookcase at {4, 0, 2}, air at {3, 0, 2} + { 4, 0, 1, 3, 0, 1 }, // Bookcase at {4, 0, 1}, air at {3, 0, 1} + { 4, 0, 0, 3, 0, 1 }, // Bookcase at {4, 0, 0}, air at {3, 0, 1} + { 3, 0, 0, 3, 0, 1 }, // Bookcase at {3, 0, 0}, air at {3, 0, 1} + { 2, 0, 0, 2, 0, 1 }, // Bookcase at {2, 0, 0}, air at {2, 0, 1} + { 1, 0, 0, 1, 0, 1 }, // Bookcase at {1, 0, 0}, air at {1, 0, 1} + + { 0, 1, 0, 1, 1, 1 }, // Bookcase at {0, 1, 0}, air at {1, 1, 1} + { 0, 1, 1, 1, 1, 1 }, // Bookcase at {0, 1, 1}, air at {1, 1, 1} + { 0, 1, 2, 1, 1, 2 }, // Bookcase at {0, 1, 2}, air at {1, 1, 2} + { 0, 1, 3, 1, 1, 3 }, // Bookcase at {0, 1, 3}, air at {1, 1, 3} + { 0, 1, 4, 1, 1, 3 }, // Bookcase at {0, 1, 4}, air at {1, 1, 3} + { 1, 1, 4, 1, 1, 3 }, // Bookcase at {1, 1, 4}, air at {1, 1, 3} + { 2, 1, 4, 2, 1, 3 }, // Bookcase at {2, 1, 4}, air at {2, 1, 3} + { 3, 1, 4, 3, 1, 3 }, // Bookcase at {3, 1, 4}, air at {3, 1, 3} + { 4, 1, 4, 3, 1, 3 }, // Bookcase at {4, 1, 4}, air at {3, 1, 3} + { 4, 1, 3, 3, 1, 3 }, // Bookcase at {4, 1, 3}, air at {3, 1, 3} + { 4, 1, 2, 3, 1, 2 }, // Bookcase at {4, 1, 2}, air at {3, 1, 2} + { 4, 1, 1, 3, 1, 1 }, // Bookcase at {4, 1, 1}, air at {3, 1, 1} + { 4, 1, 0, 3, 1, 1 }, // Bookcase at {4, 1, 0}, air at {3, 1, 1} + { 3, 1, 0, 3, 1, 1 }, // Bookcase at {3, 1, 0}, air at {3, 1, 1} + { 2, 1, 0, 2, 1, 1 }, // Bookcase at {2, 1, 0}, air at {2, 1, 1} + { 1, 1, 0, 1, 1, 1 }, // Bookcase at {1, 1, 0}, air at {1, 1, 1} + }; + + for (size_t i = 0; i < ARRAYCOUNT(CheckCoords); i++) + { + if ( + (Area.GetRelBlockType(CheckCoords[i].m_AirX, CheckCoords[i].m_AirY, CheckCoords[i].m_AirZ) == E_BLOCK_AIR) && // There's air in the checkspot + (Area.GetRelBlockType(CheckCoords[i].m_BookX, CheckCoords[i].m_BookY, CheckCoords[i].m_BookZ) == E_BLOCK_BOOKCASE) // There's bookcase in the wanted place + ) { - for (int z = 0; z <= 4; z++) - { - if ((((x == 0) || (x == 4)) || ((z == 0) || (z == 4))) && ((y == 0) || y == 1)) - { - if (Area.GetRelBlockType(x, y, z) == E_BLOCK_BOOKCASE) - { - Bookshelves++; - } - } - } + Bookshelves++; } - } - - Bookshelves = std::min(Bookshelves, 15); + } // for i - CheckCoords + return Bookshelves; } -- cgit v1.2.3 From a6de7bf1cd80847abed22e3b962a5b8650b2911c Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 19 Apr 2014 15:10:50 +0200 Subject: Fixed Code --- src/UI/SlotArea.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/UI/SlotArea.cpp') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 26fdfe928..5f74b4fa3 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -783,7 +783,8 @@ void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) { // Toss the item in the enchanting slot TossItems(a_Player, 0, 1); - // Player not found - that is acceptable + + super::OnPlayerRemoved(a_Player); } @@ -838,7 +839,7 @@ int cSlotAreaEnchanting::GetBookshelvesCount(cWorld * a_World) static const struct { int m_BookX, m_BookY, m_BookZ; // Coords to check for bookcases - int m_AirX, m_AirY, m_AirZ; // Coords to check for air; if not air, the bookcase won\'t be counted + int m_AirX, m_AirY, m_AirZ; // Coords to check for air; if not air, the bookcase won't be counted } CheckCoords[] = { { 0, 0, 0, 1, 0, 1 }, // Bookcase at {0, 0, 0}, air at {1, 0, 1} -- cgit v1.2.3