1
0
Fork 0

Remove SetProperty(...cPlayer)

Enchantment table, anvil windows are already opened one per-player.
This commit is contained in:
Tiger Wang 2020-10-02 14:22:17 +01:00 committed by peterbell10
parent cd1b507745
commit 21068011c6
15 changed files with 99 additions and 143 deletions

View File

@ -189,7 +189,7 @@ bool cBrewingstandEntity::UsedBy(cPlayer * a_Player)
void cBrewingstandEntity::BroadcastProgress(short a_ProgressbarID, short a_Value) void cBrewingstandEntity::BroadcastProgress(size_t a_ProgressbarID, short a_Value)
{ {
cWindow * Window = GetWindow(); cWindow * Window = GetWindow();
if (Window != nullptr) if (Window != nullptr)

View File

@ -137,7 +137,7 @@ protected:
short m_RemainingFuel; short m_RemainingFuel;
/** Sends the specified progressbar value to all clients of the window */ /** Sends the specified progressbar value to all clients of the window */
void BroadcastProgress(short a_ProgressbarID, short a_Value); void BroadcastProgress(size_t a_ProgressbarID, short a_Value);
// /** Broadcasts progressbar updates, if needed */ // /** Broadcasts progressbar updates, if needed */
void UpdateProgressBars(bool a_ForceUpdate = false); void UpdateProgressBars(bool a_ForceUpdate = false);

View File

@ -192,7 +192,7 @@ int cFurnaceEntity::GetAndResetReward(void)
void cFurnaceEntity::BroadcastProgress(short a_ProgressbarID, short a_Value) void cFurnaceEntity::BroadcastProgress(size_t a_ProgressbarID, short a_Value)
{ {
cWindow * Window = GetWindow(); cWindow * Window = GetWindow();
if (Window != nullptr) if (Window != nullptr)

View File

@ -145,7 +145,7 @@ protected:
bool m_IsLoading; bool m_IsLoading;
/** Sends the specified progressbar value to all clients of the window */ /** Sends the specified progressbar value to all clients of the window */
void BroadcastProgress(short a_ProgressbarID, short a_Value); void BroadcastProgress(size_t a_ProgressbarID, short a_Value);
/** One item finished cooking */ /** One item finished cooking */
void FinishOne(); void FinishOne();

View File

@ -3251,7 +3251,7 @@ void cClientHandle::SendWindowOpen(const cWindow & a_Window)
void cClientHandle::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value) void cClientHandle::SendWindowProperty(const cWindow & a_Window, size_t a_Property, short a_Value)
{ {
m_Protocol->SendWindowProperty(a_Window, a_Property, a_Value); m_Protocol->SendWindowProperty(a_Window, a_Property, a_Value);
} }

View File

@ -233,7 +233,7 @@ public: // tolua_export
void SendWholeInventory (const cWindow & a_Window); void SendWholeInventory (const cWindow & a_Window);
void SendWindowClose (const cWindow & a_Window); void SendWindowClose (const cWindow & a_Window);
void SendWindowOpen (const cWindow & a_Window); void SendWindowOpen (const cWindow & a_Window);
void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value); void SendWindowProperty (const cWindow & a_Window, size_t a_Property, short a_Value);
// tolua_begin // tolua_begin
const AString & GetUsername(void) const; const AString & GetUsername(void) const;

View File

@ -440,7 +440,7 @@ public:
virtual void SendWholeInventory (const cWindow & a_Window) = 0; virtual void SendWholeInventory (const cWindow & a_Window) = 0;
virtual void SendWindowClose (const cWindow & a_Window) = 0; virtual void SendWindowClose (const cWindow & a_Window) = 0;
virtual void SendWindowOpen (const cWindow & a_Window) = 0; virtual void SendWindowOpen (const cWindow & a_Window) = 0;
virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) = 0; virtual void SendWindowProperty (const cWindow & a_Window, size_t a_Property, short a_Value) = 0;
/** Returns the ServerID used for authentication through session.minecraft.net */ /** Returns the ServerID used for authentication through session.minecraft.net */
virtual AString GetAuthServerID(void) = 0; virtual AString GetAuthServerID(void) = 0;

View File

@ -1694,13 +1694,13 @@ void cProtocol_1_8_0::SendWindowOpen(const cWindow & a_Window)
void cProtocol_1_8_0::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value) void cProtocol_1_8_0::SendWindowProperty(const cWindow & a_Window, size_t a_Property, short a_Value)
{ {
ASSERT(m_State == 3); // In game mode? ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, pktWindowProperty); cPacketizer Pkt(*this, pktWindowProperty);
Pkt.WriteBEUInt8(static_cast<UInt8>(a_Window.GetWindowID())); Pkt.WriteBEUInt8(static_cast<UInt8>(a_Window.GetWindowID()));
Pkt.WriteBEInt16(a_Property); Pkt.WriteBEInt16(static_cast<Int16>(a_Property));
Pkt.WriteBEInt16(a_Value); Pkt.WriteBEInt16(a_Value);
} }

View File

@ -120,7 +120,7 @@ public:
virtual void SendWholeInventory (const cWindow & a_Window) override; virtual void SendWholeInventory (const cWindow & a_Window) override;
virtual void SendWindowClose (const cWindow & a_Window) override; virtual void SendWindowClose (const cWindow & a_Window) override;
virtual void SendWindowOpen (const cWindow & a_Window) override; virtual void SendWindowOpen (const cWindow & a_Window) override;
virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override; virtual void SendWindowProperty (const cWindow & a_Window, size_t a_Property, short a_Value) override;
virtual AString GetAuthServerID(void) override { return m_AuthServerID; } virtual AString GetAuthServerID(void) override { return m_AuthServerID; }

View File

@ -26,25 +26,9 @@ cEnchantingWindow::cEnchantingWindow(Vector3i a_BlockPos, const AString & a_Titl
void cEnchantingWindow::SetProperty(short a_Property, short a_Value, cPlayer & a_Player) void cEnchantingWindow::SetProperty(size_t a_Property, short a_Value)
{ {
ASSERT(a_Property >= 0); if (a_Property < m_PropertyValue.size())
if (static_cast<size_t>(a_Property) < m_PropertyValue.size())
{
m_PropertyValue[a_Property] = a_Value;
}
Super::SetProperty(a_Property, a_Value, a_Player);
}
void cEnchantingWindow::SetProperty(short a_Property, short a_Value)
{
ASSERT(a_Property >= 0);
if (static_cast<size_t>(a_Property) < m_PropertyValue.size())
{ {
m_PropertyValue[a_Property] = a_Value; m_PropertyValue[a_Property] = a_Value;
} }
@ -56,14 +40,9 @@ void cEnchantingWindow::SetProperty(short a_Property, short a_Value)
short cEnchantingWindow::GetProperty(short a_Property) short cEnchantingWindow::GetProperty(size_t a_Property)
{ {
if ((a_Property < 0) || (static_cast<size_t>(a_Property) >= m_PropertyValue.size())) ASSERT(a_Property < m_PropertyValue.size());
{
ASSERT(!"a_Property is invalid");
return 0;
}
return m_PropertyValue[a_Property]; return m_PropertyValue[a_Property];
} }

View File

@ -21,7 +21,7 @@ class cSlotAreaEnchanting;
class cEnchantingWindow: class cEnchantingWindow final :
public cWindow public cWindow
{ {
using Super = cWindow; using Super = cWindow;
@ -32,14 +32,10 @@ public:
/** Sends enchantment properties to the client. /** Sends enchantment properties to the client.
If the property represents a level requirement, stores it for later GetProperty retrieval. */ If the property represents a level requirement, stores it for later GetProperty retrieval. */
virtual void SetProperty(short a_Property, short a_Value, cPlayer & a_Player) override; virtual void SetProperty(size_t a_Property, short a_Value) override;
/** Sends enchantment properties to the client.
If the property represents a level requirement, stores it for later GetProperty retrieval. */
virtual void SetProperty(short a_Property, short a_Value) override;
/** Return the level requirement of the given enchantment slot. */ /** Return the level requirement of the given enchantment slot. */
short GetProperty(short a_Property); short GetProperty(size_t a_Property);
virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override; virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override;

View File

@ -1059,7 +1059,7 @@ void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player)
{ {
SetSlot(1, a_Player, cItem()); SetSlot(1, a_Player, cItem());
} }
m_ParentWindow.SetProperty(0, static_cast<short>(m_MaximumCost), a_Player); m_ParentWindow.SetProperty(0, static_cast<short>(m_MaximumCost));
m_MaximumCost = 0; m_MaximumCost = 0;
static_cast<cAnvilWindow &>(m_ParentWindow).SetRepairedItemName("", nullptr); static_cast<cAnvilWindow &>(m_ParentWindow).SetRepairedItemName("", nullptr);
@ -1135,7 +1135,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
{ {
Output.Empty(); Output.Empty();
SetSlot(2, a_Player, Output); SetSlot(2, a_Player, Output);
m_ParentWindow.SetProperty(0, 0, a_Player); m_ParentWindow.SetProperty(0, 0);
return; return;
} }
@ -1157,7 +1157,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
// No enchantment // No enchantment
Output.Empty(); Output.Empty();
SetSlot(2, a_Player, Output); SetSlot(2, a_Player, Output);
m_ParentWindow.SetProperty(0, 0, a_Player); m_ParentWindow.SetProperty(0, 0);
return; return;
} }
@ -1180,7 +1180,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
// No enchantment // No enchantment
Output.Empty(); Output.Empty();
SetSlot(2, a_Player, Output); SetSlot(2, a_Player, Output);
m_ParentWindow.SetProperty(0, 0, a_Player); m_ParentWindow.SetProperty(0, 0);
return; return;
} }
@ -1264,7 +1264,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
} }
SetSlot(2, a_Player, Input); SetSlot(2, a_Player, Input);
m_ParentWindow.SetProperty(0, static_cast<Int16>(m_MaximumCost), a_Player); m_ParentWindow.SetProperty(0, static_cast<Int16>(m_MaximumCost));
} }
@ -1700,10 +1700,10 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player)
// Properties set according to: https://wiki.vg/Protocol#Window_Property // Properties set according to: https://wiki.vg/Protocol#Window_Property
// Fake a "seed" for the client to draw Standard Galactic Alphabet glyphs: // Fake a "seed" for the client to draw Standard Galactic Alphabet glyphs:
m_ParentWindow.SetProperty(3, Random.RandInt<short>(), a_Player); m_ParentWindow.SetProperty(3, Random.RandInt<short>());
// Calculate an enchanting possibility for each option (top, middle and bottom) and send details to window: // Calculate an enchanting possibility for each option (top, middle and bottom) and send details to window:
for (short i = 0; i != OptionLevels.size(); i++) for (size_t i = 0; i != OptionLevels.size(); i++)
{ {
// A copy of the item. // A copy of the item.
cItem EnchantedItem = Item.CopyOne(); cItem EnchantedItem = Item.CopyOne();
@ -1714,20 +1714,20 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player)
LOGD("Generated enchanted item %d with enchantments: %s", i, EnchantedItem.m_Enchantments.ToString()); LOGD("Generated enchanted item %d with enchantments: %s", i, EnchantedItem.m_Enchantments.ToString());
// Send the level requirement for the enchantment option: // Send the level requirement for the enchantment option:
m_ParentWindow.SetProperty(i, static_cast<short>(OptionLevels[i]), a_Player); m_ParentWindow.SetProperty(i, static_cast<short>(OptionLevels[i]));
// Get the first enchantment ID, which must exist: // Get the first enchantment ID, which must exist:
ASSERT(EnchantedItem.m_Enchantments.begin() != EnchantedItem.m_Enchantments.end()); ASSERT(EnchantedItem.m_Enchantments.begin() != EnchantedItem.m_Enchantments.end());
const short EnchantmentID = static_cast<short>(EnchantedItem.m_Enchantments.begin()->first); const short EnchantmentID = static_cast<short>(EnchantedItem.m_Enchantments.begin()->first);
// Send the enchantment ID of the first enchantment on our item: // Send the enchantment ID of the first enchantment on our item:
m_ParentWindow.SetProperty(4 + i, EnchantmentID, a_Player); m_ParentWindow.SetProperty(4 + i, EnchantmentID);
const short EnchantmentLevel = static_cast<short>(EnchantedItem.m_Enchantments.GetLevel(EnchantmentID)); const short EnchantmentLevel = static_cast<short>(EnchantedItem.m_Enchantments.GetLevel(EnchantmentID));
ASSERT(EnchantmentLevel > 0); ASSERT(EnchantmentLevel > 0);
// Send the level for the first enchantment on our item: // Send the level for the first enchantment on our item:
m_ParentWindow.SetProperty(7 + i, EnchantmentLevel, a_Player); m_ParentWindow.SetProperty(7 + i, EnchantmentLevel);
// Store the item we've enchanted as an option to be retrieved later: // Store the item we've enchanted as an option to be retrieved later:
m_EnchantedItemOptions[i] = std::move(EnchantedItem); m_EnchantedItemOptions[i] = std::move(EnchantedItem);

View File

@ -379,7 +379,7 @@ protected:
class cSlotAreaEnchanting: class cSlotAreaEnchanting final :
public cSlotAreaTemporary public cSlotAreaTemporary
{ {
using Super = cSlotAreaTemporary; using Super = cSlotAreaTemporary;

View File

@ -347,6 +347,75 @@ bool cWindow::ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse)
void cWindow::BroadcastSlot(cSlotArea * a_Area, int a_LocalSlotNum)
{
// Translate local slot num into global slot num:
int SlotNum = 0;
bool HasFound = false;
for (cSlotAreas::const_iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr)
{
if (a_Area == *itr)
{
SlotNum += a_LocalSlotNum;
HasFound = true;
break;
}
SlotNum += (*itr)->GetNumSlots();
} // for itr - m_SlotAreas[]
if (!HasFound)
{
LOGWARNING("%s: Invalid slot area parameter", __FUNCTION__);
ASSERT(!"Invalid slot area");
return;
}
// Broadcast the update packet:
cCSLock Lock(m_CS);
for (cPlayerList::iterator itr = m_OpenedBy.begin(); itr != m_OpenedBy.end(); ++itr)
{
(*itr)->GetClientHandle()->SendInventorySlot(m_WindowID, static_cast<short>(SlotNum), *a_Area->GetSlot(a_LocalSlotNum, **itr));
} // for itr - m_OpenedBy[]
}
void cWindow::SendWholeWindow(cClientHandle & a_Client)
{
a_Client.SendWholeInventory(*this);
}
void cWindow::BroadcastWholeWindow(void)
{
cCSLock Lock(m_CS);
for (auto Player : m_OpenedBy)
{
SendWholeWindow(*Player->GetClientHandle());
}
}
void cWindow::SetProperty(size_t a_Property, short a_Value)
{
cCSLock Lock(m_CS);
for (auto Player : m_OpenedBy)
{
Player->GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value);
}
}
void cWindow::OwnerDestroyed() void cWindow::OwnerDestroyed()
{ {
m_Owner = nullptr; m_Owner = nullptr;
@ -685,84 +754,3 @@ int cWindow::DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int
} // for itr - SlotNums[] } // for itr - SlotNums[]
return NumDistributed; return NumDistributed;
} }
void cWindow::BroadcastSlot(cSlotArea * a_Area, int a_LocalSlotNum)
{
// Translate local slot num into global slot num:
int SlotNum = 0;
bool HasFound = false;
for (cSlotAreas::const_iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr)
{
if (a_Area == *itr)
{
SlotNum += a_LocalSlotNum;
HasFound = true;
break;
}
SlotNum += (*itr)->GetNumSlots();
} // for itr - m_SlotAreas[]
if (!HasFound)
{
LOGWARNING("%s: Invalid slot area parameter", __FUNCTION__);
ASSERT(!"Invalid slot area");
return;
}
// Broadcast the update packet:
cCSLock Lock(m_CS);
for (cPlayerList::iterator itr = m_OpenedBy.begin(); itr != m_OpenedBy.end(); ++itr)
{
(*itr)->GetClientHandle()->SendInventorySlot(m_WindowID, static_cast<short>(SlotNum), *a_Area->GetSlot(a_LocalSlotNum, **itr));
} // for itr - m_OpenedBy[]
}
void cWindow::SendWholeWindow(cClientHandle & a_Client)
{
a_Client.SendWholeInventory(*this);
}
void cWindow::BroadcastWholeWindow(void)
{
cCSLock Lock(m_CS);
for (cPlayerList::iterator itr = m_OpenedBy.begin(); itr != m_OpenedBy.end(); ++itr)
{
SendWholeWindow(*(*itr)->GetClientHandle());
} // for itr - m_OpenedBy[]
}
void cWindow::SetProperty(short a_Property, short 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 cWindow::SetProperty(short a_Property, short a_Value, cPlayer & a_Player)
{
a_Player.GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value);
}

View File

@ -142,11 +142,7 @@ public:
/** Updates a numerical property associated with the window. Typically used for furnace progressbars. /** Updates a numerical property associated with the window. Typically used for furnace progressbars.
Sends the UpdateWindowProperty packet to all clients of the window */ Sends the UpdateWindowProperty packet to all clients of the window */
virtual void SetProperty(short a_Property, short a_Value); virtual void SetProperty(size_t a_Property, short a_Value);
/** Updates a numerical property associated with the window. Typically used for furnace progressbars.
Sends the UpdateWindowProperty packet only to the specified player */
virtual void SetProperty(short a_Property, short a_Value, cPlayer & a_Player);
// tolua_end // tolua_end
@ -179,6 +175,7 @@ public:
void SendSlot(cPlayer & a_Player, cSlotArea * a_SlotArea, int a_RelativeSlotNum); void SendSlot(cPlayer & a_Player, cSlotArea * a_SlotArea, int a_RelativeSlotNum);
protected: protected:
cSlotAreas m_SlotAreas; cSlotAreas m_SlotAreas;
char m_WindowID; char m_WindowID;
@ -227,7 +224,3 @@ protected:
@param a_LimitItems if false, no checks are performed on a_Item.m_ItemCount. */ @param a_LimitItems if false, no checks are performed on a_Item.m_ItemCount. */
int DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int a_NumToEachSlot, const cSlotNums & a_SlotNums, bool a_LimitItems = true); int DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int a_NumToEachSlot, const cSlotNums & a_SlotNums, bool a_LimitItems = true);
} ; // tolua_export } ; // tolua_export