summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Server/Plugins/APIDump/APIDesc.lua29
-rw-r--r--src/ClientHandle.cpp10
-rw-r--r--src/Inventory.cpp57
-rw-r--r--src/Inventory.h21
-rw-r--r--src/UI/InventoryWindow.cpp1
-rw-r--r--src/UI/SlotArea.h17
6 files changed, 126 insertions, 9 deletions
diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua
index 4ca81d5d3..2733e9462 100644
--- a/Server/Plugins/APIDump/APIDesc.lua
+++ b/Server/Plugins/APIDump/APIDesc.lua
@@ -7970,6 +7970,16 @@ These ItemGrids are available in the API and can be manipulated by the plugins,
},
Notes = "Returns the specified hotbar slot contents. Note that the returned item is read-only",
},
+ GetShieldSlot =
+ {
+ Returns =
+ {
+ {
+ Type = "cItem",
+ },
+ },
+ Notes = "Returns current item in shield slot.",
+ },
GetInventoryGrid =
{
Returns =
@@ -8177,6 +8187,17 @@ These ItemGrids are available in the API and can be manipulated by the plugins,
},
Notes = "Sets the specified hotbar slot contents",
},
+ SetShieldSlot =
+ {
+ Params =
+ {
+ {
+ Name = "Item",
+ Type = "cItem",
+ },
+ },
+ Notes = "Sets the shield slot content",
+ },
SetInventorySlot =
{
Params =
@@ -8234,6 +8255,14 @@ These ItemGrids are available in the API and can be manipulated by the plugins,
{
Notes = "Starting slot number of the main inventory part",
},
+ invShieldCount =
+ {
+ Notes = "Number of slots in the Shield part",
+ },
+ invShieldOffset =
+ {
+ Notes = "Starting slot number of the Shield part",
+ },
invNumSlots =
{
Notes = "Total number of slots in a cInventory",
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 669138f72..17b93a62c 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -1111,6 +1111,11 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB
// A plugin doesn't agree with the action. The plugin itself is responsible for handling the consequences (possible inventory mismatch)
return;
}
+ // When bow is in off-hand / shield slot
+ if (m_Player->GetInventory().GetShieldSlot().m_ItemType == E_ITEM_BOW)
+ {
+ ItemHandler = cItemHandler::GetItemHandler(m_Player->GetInventory().GetShieldSlot());
+ }
ItemHandler->OnItemShoot(m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
}
return;
@@ -1524,6 +1529,11 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
ItemHandler->OnItemUse(World, m_Player, PluginInterface, Equipped, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
PlgMgr->CallHookPlayerUsedItem(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ);
}
+ // Charge bow when it's in slot off-hand / shield
+ if ((a_BlockFace == BLOCK_FACE_NONE) && (m_Player->GetInventory().GetShieldSlot().m_ItemType == E_ITEM_BOW))
+ {
+ m_Player->StartChargingBow();
+ }
}
diff --git a/src/Inventory.cpp b/src/Inventory.cpp
index 5add53a12..ad356d3ae 100644
--- a/src/Inventory.cpp
+++ b/src/Inventory.cpp
@@ -21,6 +21,7 @@ cInventory::cInventory(cPlayer & a_Owner) :
m_ArmorSlots (1, 4), // 1 x 4 slots
m_InventorySlots(9, 3), // 9 x 3 slots
m_HotbarSlots (9, 1), // 9 x 1 slots
+ m_ShieldSlots (1, 1), // 1 x 1 slots
m_Owner(a_Owner)
{
// Ask each ItemGrid to report changes to us:
@@ -40,6 +41,7 @@ void cInventory::Clear(void)
m_ArmorSlots.Clear();
m_InventorySlots.Clear();
m_HotbarSlots.Clear();
+ m_ShieldSlots.Clear();
}
@@ -178,7 +180,12 @@ int cInventory::AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks)
int cInventory::RemoveItem(const cItem & a_ItemStack)
{
- int RemovedItems = m_HotbarSlots.RemoveItem(a_ItemStack);
+ int RemovedItems = m_ShieldSlots.RemoveItem(a_ItemStack);
+
+ if (RemovedItems < a_ItemStack.m_ItemCount)
+ {
+ RemovedItems += m_HotbarSlots.RemoveItem(a_ItemStack);
+ }
if (RemovedItems < a_ItemStack.m_ItemCount)
{
@@ -214,7 +221,8 @@ int cInventory::HowManyItems(const cItem & a_Item)
return
m_ArmorSlots.HowManyItems(a_Item) +
m_InventorySlots.HowManyItems(a_Item) +
- m_HotbarSlots.HowManyItems(a_Item);
+ m_HotbarSlots.HowManyItems(a_Item) +
+ m_ShieldSlots.HowManyItems(a_Item);
}
@@ -280,6 +288,15 @@ void cInventory::SetHotbarSlot(int a_HotBarSlotNum, const cItem & a_Item)
+void cInventory::SetShieldSlot(const cItem & a_Item)
+{
+ m_ShieldSlots.SetSlot(0, a_Item);
+}
+
+
+
+
+
void cInventory::SendEquippedSlot()
{
int EquippedSlotNum = cInventory::invArmorCount + cInventory::invInventoryCount + GetEquippedSlotNum();
@@ -354,6 +371,15 @@ const cItem & cInventory::GetHotbarSlot(int a_SlotNum) const
+const cItem & cInventory::GetShieldSlot() const
+{
+ return m_ShieldSlots.GetSlot(0);
+}
+
+
+
+
+
const cItem & cInventory::GetEquippedItem(void) const
{
return GetHotbarSlot(m_EquippedSlotNum);
@@ -617,13 +643,18 @@ void cInventory::SaveToJson(Json::Value & a_Value)
a_Value.append(JSON_Item);
}
- // The hotbar is the last:
+ // The hotbar:
for (int i = 0; i < invHotbarCount; i++)
{
Json::Value JSON_Item;
m_HotbarSlots.GetSlot(i).GetJson(JSON_Item);
a_Value.append(JSON_Item);
}
+
+ // Shield slot is the last
+ Json::Value JSON_Item;
+ m_ShieldSlots.GetSlot(0).GetJson(JSON_Item);
+ a_Value.append(JSON_Item);
}
@@ -678,8 +709,14 @@ const cItemGrid * cInventory::GetGridForSlotNum(int a_SlotNum, int & a_GridSlotN
a_GridSlotNum = a_SlotNum;
return &m_InventorySlots;
}
- a_GridSlotNum = a_SlotNum - invInventoryCount;
- return &m_HotbarSlots;
+ a_SlotNum -= invInventoryCount;
+ if (a_SlotNum < invHotbarCount)
+ {
+ a_GridSlotNum = a_SlotNum;
+ return &m_HotbarSlots;
+ }
+ a_GridSlotNum = a_SlotNum - invHotbarCount;
+ return &m_ShieldSlots;
}
@@ -701,8 +738,14 @@ cItemGrid * cInventory::GetGridForSlotNum(int a_SlotNum, int & a_GridSlotNum)
a_GridSlotNum = a_SlotNum;
return &m_InventorySlots;
}
- a_GridSlotNum = a_SlotNum - invInventoryCount;
- return &m_HotbarSlots;
+ a_SlotNum -= invInventoryCount;
+ if (a_SlotNum < invHotbarCount)
+ {
+ a_GridSlotNum = a_SlotNum;
+ return &m_HotbarSlots;
+ }
+ a_GridSlotNum = a_SlotNum - invHotbarCount;
+ return &m_ShieldSlots;
}
diff --git a/src/Inventory.h b/src/Inventory.h
index ec159ec8e..2507cceed 100644
--- a/src/Inventory.h
+++ b/src/Inventory.h
@@ -43,11 +43,13 @@ public:
invArmorCount = 4,
invInventoryCount = 9 * 3,
invHotbarCount = 9,
+ invShieldCount = 1, // Number of slots in shield slots grid
invArmorOffset = 0,
invInventoryOffset = invArmorOffset + invArmorCount,
invHotbarOffset = invInventoryOffset + invInventoryCount,
- invNumSlots = invHotbarOffset + invHotbarCount
+ invShieldOffset = invHotbarOffset + invHotbarCount, // Offset where shield slots start
+ invNumSlots = invShieldOffset + invShieldCount
} ;
// tolua_end
@@ -120,17 +122,31 @@ public:
// tolua_begin
+ /** Returns current item in a_SlotNum slot */
const cItem & GetSlot(int a_SlotNum) const;
+ /** Returns current item in a_ArmorSlotNum in armor slots */
const cItem & GetArmorSlot(int a_ArmorSlotNum) const;
+ /** Returns current item in a_ArmorSlotNum in inventory slots */
const cItem & GetInventorySlot(int a_InventorySlotNum) const;
+ /** Returns current item in a_ArmorSlotNum in hotbar slots */
const cItem & GetHotbarSlot(int a_HotBarSlotNum) const;
+ /** Returns current item in shield slot */
+ const cItem & GetShieldSlot() const;
+ /** Returns current equiped item */
const cItem & GetEquippedItem(void) const;
+ /** Puts a_Item item in a_SlotNum slot number */
void SetSlot(int a_SlotNum, const cItem & a_Item);
+ /** Puts a_Item item in a_ArmorSlotNum slot number in armor slots */
void SetArmorSlot(int a_ArmorSlotNum, const cItem & a_Item);
+ /** Puts a_Item item in a_InventorySlotNum slot number in inventory slots */
void SetInventorySlot(int a_InventorySlotNum, const cItem & a_Item);
+ /** Puts a_Item item in a_HotBarSlotNum slot number in hotbar slots */
void SetHotbarSlot(int a_HotBarSlotNum, const cItem & a_Item);
-
+ /** Sets current item in shield slot */
+ void SetShieldSlot(const cItem & a_Item);
+ /** Sets equiped item to the a_SlotNum slot number */
void SetEquippedSlotNum(int a_SlotNum);
+ /** Returns slot number of equiped item */
int GetEquippedSlotNum(void) { return m_EquippedSlotNum; }
/** Adds (or subtracts, if a_AddToCount is negative) to the count of items in the specified slot.
@@ -170,6 +186,7 @@ protected:
cItemGrid m_ArmorSlots;
cItemGrid m_InventorySlots;
cItemGrid m_HotbarSlots;
+ cItemGrid m_ShieldSlots;
int m_EquippedSlotNum;
diff --git a/src/UI/InventoryWindow.cpp b/src/UI/InventoryWindow.cpp
index 0f876e559..571651d20 100644
--- a/src/UI/InventoryWindow.cpp
+++ b/src/UI/InventoryWindow.cpp
@@ -19,6 +19,7 @@ cInventoryWindow::cInventoryWindow(cPlayer & a_Player) :
m_SlotAreas.push_back(new cSlotAreaArmor(*this));
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
+ m_SlotAreas.push_back(new cSlotAreaShield(*this));
}
diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h
index 005ba6e7f..5a94a26af 100644
--- a/src/UI/SlotArea.h
+++ b/src/UI/SlotArea.h
@@ -145,6 +145,23 @@ public:
+/** Handles the shield of each player */
+class cSlotAreaShield :
+ public cSlotAreaInventoryBase
+{
+ typedef cSlotAreaInventoryBase super;
+
+public:
+ cSlotAreaShield(cWindow & a_ParentWindow) :
+ cSlotAreaInventoryBase(cInventory::invShieldCount, cInventory::invShieldOffset, a_ParentWindow)
+ {
+ }
+};
+
+
+
+
+
/** Handles the armor area of the player's inventory */
class cSlotAreaArmor :
public cSlotAreaInventoryBase