Added complete Enchanting System
http://minecraft.gamepedia.com/Enchantment_mechanics
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -808,7 +808,10 @@ cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
|
||||
// cEnchantingWindow:
|
||||
|
||||
cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
|
||||
cWindow(wtEnchantment, "Enchant")
|
||||
cWindow(wtEnchantment, "Enchant"),
|
||||
m_BlockX(a_BlockX),
|
||||
m_BlockY(a_BlockY),
|
||||
m_BlockZ(a_BlockZ)
|
||||
{
|
||||
m_SlotAreas.push_back(new cSlotAreaEnchanting(1, *this));
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
@@ -819,6 +822,87 @@ cWindow(wtEnchantment, "Enchant")
|
||||
|
||||
|
||||
|
||||
void cEnchantingWindow::SetProperty(int a_Property, int a_Value)
|
||||
{
|
||||
if (a_Property == 0)
|
||||
{
|
||||
m_PropertyValue0 = a_Value;
|
||||
}
|
||||
else if (a_Property == 1)
|
||||
{
|
||||
m_PropertyValue1 = a_Value;
|
||||
}
|
||||
else if (a_Property == 2)
|
||||
{
|
||||
m_PropertyValue2 = a_Value;
|
||||
}
|
||||
|
||||
cCSLock Lock(m_CS);
|
||||
for (cPlayerList::iterator itr = m_OpenedBy.begin(), end = m_OpenedBy.end(); itr != end; ++itr)
|
||||
{
|
||||
(*itr)->GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value);
|
||||
} // for itr - m_OpenedBy[]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Player)
|
||||
{
|
||||
if (a_Property == 0)
|
||||
{
|
||||
m_PropertyValue0 = a_Value;
|
||||
}
|
||||
else if (a_Property == 1)
|
||||
{
|
||||
m_PropertyValue1 = a_Value;
|
||||
}
|
||||
else if (a_Property == 2)
|
||||
{
|
||||
m_PropertyValue2 = a_Value;
|
||||
}
|
||||
|
||||
a_Player.GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int cEnchantingWindow::GetPropertyValue(int a_Property)
|
||||
{
|
||||
if (a_Property == 0)
|
||||
{
|
||||
return m_PropertyValue0;
|
||||
}
|
||||
else if (a_Property == 1)
|
||||
{
|
||||
return m_PropertyValue1;
|
||||
}
|
||||
else if (a_Property == 2)
|
||||
{
|
||||
return m_PropertyValue2;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cEnchantingWindow::GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ)
|
||||
{
|
||||
a_PosX = m_BlockX;
|
||||
a_PosY = m_BlockY;
|
||||
a_PosZ = m_BlockZ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cChestWindow:
|
||||
|
||||
|
||||
@@ -136,11 +136,11 @@ public:
|
||||
void SetWindowTitle(const AString & a_WindowTitle ) { m_WindowTitle = a_WindowTitle; }
|
||||
|
||||
/// Sends the UpdateWindowProperty (0x69) packet to all clients of the window
|
||||
void SetProperty(int a_Property, int a_Value);
|
||||
virtual void SetProperty(int a_Property, int a_Value);
|
||||
|
||||
/// Sends the UpdateWindowPropert(0x69) packet to the specified player
|
||||
void SetProperty(int a_Property, int a_Value, cPlayer & a_Player);
|
||||
|
||||
virtual void SetProperty(int a_Property, int a_Value, cPlayer & a_Player);
|
||||
|
||||
// tolua_end
|
||||
|
||||
void OwnerDestroyed(void);
|
||||
@@ -165,7 +165,7 @@ public:
|
||||
|
||||
/// Used by cSlotAreas to send individual slots to clients, a_RelativeSlotNum is the slot number relative to a_SlotArea
|
||||
void SendSlot(cPlayer & a_Player, cSlotArea * a_SlotArea, int a_RelativeSlotNum);
|
||||
|
||||
|
||||
protected:
|
||||
cSlotAreas m_SlotAreas;
|
||||
|
||||
@@ -237,6 +237,18 @@ class cEnchantingWindow :
|
||||
typedef cWindow super;
|
||||
public:
|
||||
cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ);
|
||||
virtual void SetProperty(int a_Property, int a_Value, cPlayer & a_Player) override;
|
||||
virtual void SetProperty(int a_Property, int a_Value) override;
|
||||
|
||||
/** Return the Value of a Property */
|
||||
int GetPropertyValue(int a_Property);
|
||||
|
||||
/** Set the Position Values to the Position of the Enchantment Table */
|
||||
void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ);
|
||||
|
||||
protected:
|
||||
int m_PropertyValue0, m_PropertyValue1, m_PropertyValue2;
|
||||
int m_BlockX, m_BlockY, m_BlockZ;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user