Off-hand/shield slot functional, save and load slot, bow + arrow functional (#3725)
Fixes #3714.
This commit is contained in:
parent
8a890cf945
commit
84bdba345d
@ -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",
|
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 =
|
GetInventoryGrid =
|
||||||
{
|
{
|
||||||
Returns =
|
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",
|
Notes = "Sets the specified hotbar slot contents",
|
||||||
},
|
},
|
||||||
|
SetShieldSlot =
|
||||||
|
{
|
||||||
|
Params =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
Name = "Item",
|
||||||
|
Type = "cItem",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Notes = "Sets the shield slot content",
|
||||||
|
},
|
||||||
SetInventorySlot =
|
SetInventorySlot =
|
||||||
{
|
{
|
||||||
Params =
|
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",
|
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 =
|
invNumSlots =
|
||||||
{
|
{
|
||||||
Notes = "Total number of slots in a cInventory",
|
Notes = "Total number of slots in a cInventory",
|
||||||
|
@ -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)
|
// A plugin doesn't agree with the action. The plugin itself is responsible for handling the consequences (possible inventory mismatch)
|
||||||
return;
|
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);
|
ItemHandler->OnItemShoot(m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
|
||||||
}
|
}
|
||||||
return;
|
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);
|
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);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ cInventory::cInventory(cPlayer & a_Owner) :
|
|||||||
m_ArmorSlots (1, 4), // 1 x 4 slots
|
m_ArmorSlots (1, 4), // 1 x 4 slots
|
||||||
m_InventorySlots(9, 3), // 9 x 3 slots
|
m_InventorySlots(9, 3), // 9 x 3 slots
|
||||||
m_HotbarSlots (9, 1), // 9 x 1 slots
|
m_HotbarSlots (9, 1), // 9 x 1 slots
|
||||||
|
m_ShieldSlots (1, 1), // 1 x 1 slots
|
||||||
m_Owner(a_Owner)
|
m_Owner(a_Owner)
|
||||||
{
|
{
|
||||||
// Ask each ItemGrid to report changes to us:
|
// Ask each ItemGrid to report changes to us:
|
||||||
@ -40,6 +41,7 @@ void cInventory::Clear(void)
|
|||||||
m_ArmorSlots.Clear();
|
m_ArmorSlots.Clear();
|
||||||
m_InventorySlots.Clear();
|
m_InventorySlots.Clear();
|
||||||
m_HotbarSlots.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 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)
|
if (RemovedItems < a_ItemStack.m_ItemCount)
|
||||||
{
|
{
|
||||||
@ -214,7 +221,8 @@ int cInventory::HowManyItems(const cItem & a_Item)
|
|||||||
return
|
return
|
||||||
m_ArmorSlots.HowManyItems(a_Item) +
|
m_ArmorSlots.HowManyItems(a_Item) +
|
||||||
m_InventorySlots.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()
|
void cInventory::SendEquippedSlot()
|
||||||
{
|
{
|
||||||
int EquippedSlotNum = cInventory::invArmorCount + cInventory::invInventoryCount + GetEquippedSlotNum();
|
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
|
const cItem & cInventory::GetEquippedItem(void) const
|
||||||
{
|
{
|
||||||
return GetHotbarSlot(m_EquippedSlotNum);
|
return GetHotbarSlot(m_EquippedSlotNum);
|
||||||
@ -617,13 +643,18 @@ void cInventory::SaveToJson(Json::Value & a_Value)
|
|||||||
a_Value.append(JSON_Item);
|
a_Value.append(JSON_Item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The hotbar is the last:
|
// The hotbar:
|
||||||
for (int i = 0; i < invHotbarCount; i++)
|
for (int i = 0; i < invHotbarCount; i++)
|
||||||
{
|
{
|
||||||
Json::Value JSON_Item;
|
Json::Value JSON_Item;
|
||||||
m_HotbarSlots.GetSlot(i).GetJson(JSON_Item);
|
m_HotbarSlots.GetSlot(i).GetJson(JSON_Item);
|
||||||
a_Value.append(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,9 +709,15 @@ const cItemGrid * cInventory::GetGridForSlotNum(int a_SlotNum, int & a_GridSlotN
|
|||||||
a_GridSlotNum = a_SlotNum;
|
a_GridSlotNum = a_SlotNum;
|
||||||
return &m_InventorySlots;
|
return &m_InventorySlots;
|
||||||
}
|
}
|
||||||
a_GridSlotNum = a_SlotNum - invInventoryCount;
|
a_SlotNum -= invInventoryCount;
|
||||||
|
if (a_SlotNum < invHotbarCount)
|
||||||
|
{
|
||||||
|
a_GridSlotNum = a_SlotNum;
|
||||||
return &m_HotbarSlots;
|
return &m_HotbarSlots;
|
||||||
}
|
}
|
||||||
|
a_GridSlotNum = a_SlotNum - invHotbarCount;
|
||||||
|
return &m_ShieldSlots;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -701,9 +738,15 @@ cItemGrid * cInventory::GetGridForSlotNum(int a_SlotNum, int & a_GridSlotNum)
|
|||||||
a_GridSlotNum = a_SlotNum;
|
a_GridSlotNum = a_SlotNum;
|
||||||
return &m_InventorySlots;
|
return &m_InventorySlots;
|
||||||
}
|
}
|
||||||
a_GridSlotNum = a_SlotNum - invInventoryCount;
|
a_SlotNum -= invInventoryCount;
|
||||||
|
if (a_SlotNum < invHotbarCount)
|
||||||
|
{
|
||||||
|
a_GridSlotNum = a_SlotNum;
|
||||||
return &m_HotbarSlots;
|
return &m_HotbarSlots;
|
||||||
}
|
}
|
||||||
|
a_GridSlotNum = a_SlotNum - invHotbarCount;
|
||||||
|
return &m_ShieldSlots;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,11 +43,13 @@ public:
|
|||||||
invArmorCount = 4,
|
invArmorCount = 4,
|
||||||
invInventoryCount = 9 * 3,
|
invInventoryCount = 9 * 3,
|
||||||
invHotbarCount = 9,
|
invHotbarCount = 9,
|
||||||
|
invShieldCount = 1, // Number of slots in shield slots grid
|
||||||
|
|
||||||
invArmorOffset = 0,
|
invArmorOffset = 0,
|
||||||
invInventoryOffset = invArmorOffset + invArmorCount,
|
invInventoryOffset = invArmorOffset + invArmorCount,
|
||||||
invHotbarOffset = invInventoryOffset + invInventoryCount,
|
invHotbarOffset = invInventoryOffset + invInventoryCount,
|
||||||
invNumSlots = invHotbarOffset + invHotbarCount
|
invShieldOffset = invHotbarOffset + invHotbarCount, // Offset where shield slots start
|
||||||
|
invNumSlots = invShieldOffset + invShieldCount
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
// tolua_end
|
// tolua_end
|
||||||
@ -120,17 +122,31 @@ public:
|
|||||||
|
|
||||||
// tolua_begin
|
// tolua_begin
|
||||||
|
|
||||||
|
/** Returns current item in a_SlotNum slot */
|
||||||
const cItem & GetSlot(int a_SlotNum) const;
|
const cItem & GetSlot(int a_SlotNum) const;
|
||||||
|
/** Returns current item in a_ArmorSlotNum in armor slots */
|
||||||
const cItem & GetArmorSlot(int a_ArmorSlotNum) const;
|
const cItem & GetArmorSlot(int a_ArmorSlotNum) const;
|
||||||
|
/** Returns current item in a_ArmorSlotNum in inventory slots */
|
||||||
const cItem & GetInventorySlot(int a_InventorySlotNum) const;
|
const cItem & GetInventorySlot(int a_InventorySlotNum) const;
|
||||||
|
/** Returns current item in a_ArmorSlotNum in hotbar slots */
|
||||||
const cItem & GetHotbarSlot(int a_HotBarSlotNum) const;
|
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;
|
const cItem & GetEquippedItem(void) const;
|
||||||
|
/** Puts a_Item item in a_SlotNum slot number */
|
||||||
void SetSlot(int a_SlotNum, const cItem & a_Item);
|
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);
|
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);
|
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);
|
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);
|
void SetEquippedSlotNum(int a_SlotNum);
|
||||||
|
/** Returns slot number of equiped item */
|
||||||
int GetEquippedSlotNum(void) { return m_EquippedSlotNum; }
|
int GetEquippedSlotNum(void) { return m_EquippedSlotNum; }
|
||||||
|
|
||||||
/** Adds (or subtracts, if a_AddToCount is negative) to the count of items in the specified slot.
|
/** 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_ArmorSlots;
|
||||||
cItemGrid m_InventorySlots;
|
cItemGrid m_InventorySlots;
|
||||||
cItemGrid m_HotbarSlots;
|
cItemGrid m_HotbarSlots;
|
||||||
|
cItemGrid m_ShieldSlots;
|
||||||
|
|
||||||
int m_EquippedSlotNum;
|
int m_EquippedSlotNum;
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ cInventoryWindow::cInventoryWindow(cPlayer & a_Player) :
|
|||||||
m_SlotAreas.push_back(new cSlotAreaArmor(*this));
|
m_SlotAreas.push_back(new cSlotAreaArmor(*this));
|
||||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||||
|
m_SlotAreas.push_back(new cSlotAreaShield(*this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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 */
|
/** Handles the armor area of the player's inventory */
|
||||||
class cSlotAreaArmor :
|
class cSlotAreaArmor :
|
||||||
public cSlotAreaInventoryBase
|
public cSlotAreaInventoryBase
|
||||||
|
Loading…
Reference in New Issue
Block a user