本文整理汇总了C++中cItem::IsEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ cItem::IsEmpty方法的具体用法?C++ cItem::IsEmpty怎么用?C++ cItem::IsEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cItem
的用法示例。
在下文中一共展示了cItem::IsEmpty方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DistributeStack
void cSlotAreaAnvil::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots)
{
for (int i = 0; i < 2; i++)
{
const cItem * Slot = GetSlot(i, a_Player);
if (!Slot->IsEqual(a_ItemStack) && (!Slot->IsEmpty() || a_KeepEmptySlots))
{
// Different items
continue;
}
int NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount;
if (NumFit <= 0)
{
// Full stack already
continue;
}
if (NumFit > a_ItemStack.m_ItemCount)
{
NumFit = a_ItemStack.m_ItemCount;
}
if (a_ShouldApply)
{
cItem NewSlot(a_ItemStack);
NewSlot.m_ItemCount = Slot->m_ItemCount + NumFit;
SetSlot(i, a_Player, NewSlot);
}
a_ItemStack.m_ItemCount -= NumFit;
if (a_ItemStack.IsEmpty())
{
UpdateResult(a_Player);
return;
}
} // for i - Slots
UpdateResult(a_Player);
}
示例2:
void cProtocol125::WriteItem(const cItem & a_Item)
{
short ItemType = a_Item.m_ItemType;
ASSERT(ItemType >= -1); // Check validity of packets in debug runtime
if (ItemType <= 0)
{
// Fix, to make sure no invalid values are sent.
ItemType = -1;
}
WriteShort(ItemType);
if (a_Item.IsEmpty())
{
return;
}
WriteChar (a_Item.m_ItemCount);
WriteShort(a_Item.m_ItemDamage);
if (cItem::IsEnchantable(a_Item.m_ItemType))
{
// TODO: Implement enchantments
WriteShort(-1);
}
}
示例3: DistributeStack
void cWindow::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, cSlotArea * a_ExcludeArea, bool a_ShouldApply)
{
// Ask each slot area to take as much of the stack as it can.
// First ask only slots that already have the same kind of item
// Then ask any remaining slots
for (int Pass = 0; Pass < 2; ++Pass)
{
if (m_ShouldDistributeToHotbarFirst)
{
// First distribute into the hotbar:
if (a_ExcludeArea != m_SlotAreas.back())
{
m_SlotAreas.back()->DistributeStack(a_ItemStack, a_Player, a_ShouldApply, (Pass == 0));
if (a_ItemStack.IsEmpty())
{
// Distributed it all
return;
}
}
}
// The distribute to all other areas:
cSlotAreas::iterator end = m_ShouldDistributeToHotbarFirst ? (m_SlotAreas.end() - 1) : m_SlotAreas.end();
for (cSlotAreas::iterator itr = m_SlotAreas.begin(); itr != end; ++itr)
{
if (*itr == a_ExcludeArea)
{
continue;
}
(*itr)->DistributeStack(a_ItemStack, a_Player, a_ShouldApply, (Pass == 0));
if (a_ItemStack.IsEmpty())
{
// Distributed it all
return;
}
} // for itr - m_SlotAreas[]
} // for Pass - repeat twice
}
示例4: SetHorseArmor
void cHorse::SetHorseArmor(cItem a_Armor)
{
if (ItemCategory::IsHorseArmor(a_Armor.m_ItemType))
{
m_World->BroadcastSoundEffect("entity.horse.armor", GetPosition(), 1.0f, 0.8f);
}
else if (!a_Armor.IsEmpty())
{
return; // Invalid item
}
m_Armor = std::move(a_Armor);
m_World->BroadcastEntityMetadata(*this);
}
示例5: SetHorseSaddle
void cHorse::SetHorseSaddle(cItem a_Saddle)
{
if (a_Saddle.m_ItemType == E_ITEM_SADDLE)
{
m_World->BroadcastSoundEffect("entity.horse.saddle", GetPosition(), 1.0f, 0.8f);
}
else if (!a_Saddle.IsEmpty())
{
return; // Invalid item
}
m_Saddle = std::move(a_Saddle);
m_World->BroadcastEntityMetadata(*this);
}
示例6: DistributeStackToAreas
void cWindow::DistributeStackToAreas(cItem & a_ItemStack, cPlayer & a_Player, cSlotAreas & a_AreasInOrder, bool a_ShouldApply, bool a_BackFill)
{
/* Ask each slot area to take as much of the stack as it can.
First ask only slots that already have the same kind of item
Then ask any remaining slots */
for (size_t Pass = 0; Pass < 2; Pass++)
{
for (auto SlotArea : a_AreasInOrder)
{
SlotArea->DistributeStack(a_ItemStack, a_Player, a_ShouldApply, (Pass == 0), a_BackFill);
if (a_ItemStack.IsEmpty())
{
// Distributed it all
return;
}
}
}
}
示例7:
void cProtocol132::WriteItem(const cItem & a_Item)
{
short ItemType = a_Item.m_ItemType;
ASSERT(ItemType >= -1); // Check validity of packets in debug runtime
if (ItemType <= 0)
{
// Fix, to make sure no invalid values are sent.
ItemType = -1;
}
if (a_Item.IsEmpty())
{
WriteShort(-1);
return;
}
WriteShort(ItemType);
WriteChar (a_Item.m_ItemCount);
WriteShort(a_Item.m_ItemDamage);
if (a_Item.m_Enchantments.IsEmpty())
{
WriteShort(-1);
return;
}
// Send the enchantments:
cFastNBTWriter Writer;
const char * TagName = (a_Item.m_ItemType == E_ITEM_BOOK) ? "StoredEnchantments" : "ench";
EnchantmentSerializer::WriteToNBTCompound(a_Item.m_Enchantments, Writer, TagName);
Writer.Finish();
AString Compressed;
CompressStringGZIP(Writer.GetResult().data(), Writer.GetResult().size(), Compressed);
WriteShort((short)Compressed.size());
SendData(Compressed.data(), Compressed.size());
}