本文整理汇总了C++中ItemInst类的典型用法代码示例。如果您正苦于以下问题:C++ ItemInst类的具体用法?C++ ItemInst怎么用?C++ ItemInst使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ItemInst类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
// Remove item from bucket without memory delete
// Returns item pointer if full delete was successful
ItemInst* Inventory::PopItem(int16 slot_id)
{
ItemInst* p = nullptr;
if (slot_id == SLOT_CURSOR) { // Cursor
p = m_cursor.pop();
}
else if ((slot_id >= 1 && slot_id <= 21)) { // Worn slots
p = m_worn[slot_id];
m_worn.erase(slot_id);
}
else if ((slot_id >= 22 && slot_id <= 29)) {
p = m_inv[slot_id];
m_inv.erase(slot_id);
}
else if (slot_id >= 2000 && slot_id <= 2007) { // Bank slots
p = m_bank[slot_id];
m_bank.erase(slot_id);
}
else if (slot_id >= 3000 && slot_id <= 3007) { // Trade window slots
p = m_trade[slot_id];
m_trade.erase(slot_id);
}
else {
// Is slot inside bag?
ItemInst* baginst = GetItem(Inventory::CalcSlotId(slot_id));
if (baginst != nullptr && baginst->IsType(ItemClassContainer)) {
p = baginst->PopItem(Inventory::CalcBagIdx(slot_id));
}
}
// Return pointer that needs to be deleted (or otherwise managed)
return p;
}
示例2: respawn_timer
Object::Object(const char *model, float x, float y, float z, float heading, uint8 type, uint32 decay_time)
: respawn_timer(0), decay_timer(decay_time)
{
user = nullptr;
last_user = nullptr;
ItemInst* inst = nullptr;
inst = new ItemInst(ItemInstWorldContainer);
// Initialize members
m_id = 0;
m_inst = (inst) ? inst->Clone() : nullptr;
m_type = type;
m_icon = 0;
m_inuse = false;
m_ground_spawn = false;
// Set as much struct data as we can
memset(&m_data, 0, sizeof(Object_Struct));
m_data.heading = heading;
m_data.x = x;
m_data.y = y;
m_data.z = z;
m_data.zone_id = zone->GetZoneID();
if (decay_time)
decay_timer.Start();
respawn_timer.Disable();
if(model)
strcpy(m_data.object_name, model);
else
strcpy(m_data.object_name, "IT64_ACTORDEF"); //default object name if model isn't specified for some unknown reason
}
示例3: ClearByFlags
// Remove all items from container
void ItemInst::ClearByFlags(byFlagSetting is_nodrop, byFlagSetting is_norent)
{
// Destroy container contents
iter_contents cur, end, del;
cur = m_contents.begin();
end = m_contents.end();
for (; cur != end;) {
ItemInst* inst = cur->second;
const Item_Struct* item = inst->GetItem();
del = cur;
++cur;
switch (is_nodrop) {
case byFlagSet:
if (item->NoDrop == 0) {
safe_delete(inst);
m_contents.erase(del->first);
continue;
}
default:
break;
}
switch (is_norent) {
case byFlagSet:
if (item->NoRent == 0) {
safe_delete(inst);
m_contents.erase(del->first);
continue;
}
default:
break;
}
}
}
示例4: pickup_item
void PlayerInst::pickup_item(GameState* gs, const GameAction& action) {
const int PICKUP_RATE = 10;
GameInst* inst = gs->get_instance(action.use_id);
if (!inst) {
return;
}
ItemInst* iteminst = dynamic_cast<ItemInst*>(inst);
LANARTS_ASSERT(iteminst);
const Item& type = iteminst->item_type();
int amnt = iteminst->item_quantity();
bool inventory_full = false;
if (type.id == get_item_by_name("Gold")) {
gold() += amnt;
} else {
itemslot_t slot = inventory().add(type);
if (slot == -1) {
inventory_full = true;
} else if (projectile_should_autowield(equipment(), type,
this->last_chosen_weaponclass)) {
projectile_smart_equip(inventory(), slot);
}
}
if (!inventory_full) {
cooldowns().reset_pickup_cooldown(PICKUP_RATE);
gs->remove_instance(iteminst);
}
}
示例5: step
void ItemInst::step(GameState *gs) {
GameInst* other_item = NULL;
ItemEntry& ientry = item.item_entry();
if (ientry.stackable
&& gs->object_radius_test(this, &other_item, 1, same_item_colfilter)) {
ItemInst* oinst = (ItemInst*)other_item;
if (oinst->item == item && id < oinst->id) {
gs->remove_instance(oinst);
quantity += oinst->item_quantity();
}
}
}
示例6: PopItem
// Internal Method: "put" item into bucket, without regard for what is currently in bucket
// Assumes item has already been allocated
sint16 Inventory::_PutItem(sint16 slot_id, ItemInst* inst)
{
// If putting a NULL into slot, we need to remove slot without memory delete
if (inst == NULL) {
//Why do we not delete the poped item here????
PopItem(slot_id);
return slot_id;
}
sint16 result = SLOT_INVALID;
if (slot_id==SLOT_CURSOR) { // Cursor
// Replace current item on cursor, if exists
m_cursor.pop(); // no memory delete, clients of this function know what they are doing
m_cursor.push_front(inst);
result = slot_id;
}
else if ((slot_id>=0 && slot_id<=21) || (slot_id >= 400 && slot_id<=404) || (slot_id == 9999)) { // Worn slots
m_worn[slot_id] = inst;
result = slot_id;
}
else if ((slot_id>=22 && slot_id<=29)) {
m_inv[slot_id] = inst;
result = slot_id;
}
else if (slot_id>=2000 && slot_id<=2023) { // Bank slots
m_bank[slot_id] = inst;
result = slot_id;
}
else if (slot_id>=2500 && slot_id<=2501) { // Shared bank slots
m_shbank[slot_id] = inst;
result = slot_id;
}
else if (slot_id>=3000 && slot_id<=3007) { // Trade window slots
m_trade[slot_id] = inst;
result = slot_id;
}
else {
// Slot must be within a bag
ItemInst* baginst = GetItem(Inventory::CalcSlotId(slot_id)); // Get parent bag
if (baginst && baginst->IsType(ItemClassContainer)) {
baginst->_PutItem(Inventory::CalcBagIdx(slot_id), inst);
result = slot_id;
}
}
if (result == SLOT_INVALID) {
LogFile->write(EQEMuLog::Error, "Inventory::_PutItem: Invalid slot_id specified (%i)", slot_id);
safe_delete(inst); // Slot not found, clean up
}
return result;
}
示例7: GetItem
// Checks All items in a bag for No Drop
bool Inventory::CheckNoDrop(sint16 slot_id) {
ItemInst* inst = GetItem(slot_id);
if (!inst) return false;
if (!inst->GetItem()->NoDrop) return true;
if (inst->GetItem()->ItemClass == 1) {
for (int16 i=0; i<10; i++) {
ItemInst* bagitem = GetItem(Inventory::CalcSlotId(slot_id, i));
if (bagitem && !bagitem->GetItem()->NoDrop) return true;
}
}
return false;
}
示例8: _HasItemByLoreGroup
// Internal Method: Checks an inventory queue type bucket for a particular item
int16 Inventory::_HasItemByLoreGroup(ItemInstQueue& iqueue, uint32 loregroup)
{
iter_queue it;
iter_contents itb;
// Read-only iteration of queue
for (it = iqueue.begin(); it != iqueue.end(); ++it) {
ItemInst* inst = *it;
if (inst)
{
if (inst->GetItem()->LoreGroup == loregroup)
return SLOT_CURSOR;
}
// Go through bag, if bag
if (inst && inst->IsType(ItemClassContainer)) {
for (itb = inst->_begin(); itb != inst->_end(); ++itb) {
ItemInst* baginst = itb->second;
if (baginst && baginst->IsType(ItemClassCommon) && baginst->GetItem()->LoreGroup == loregroup)
return Inventory::CalcSlotId(SLOT_CURSOR, itb->first);
}
}
}
// Not found
return SLOT_INVALID;
}
示例9: GetGuildBank
ItemInst* GuildBankManager::GetItem(uint32 GuildID, uint16 Area, uint16 SlotID, uint32 Quantity)
{
std::list<GuildBank*>::iterator Iterator = GetGuildBank(GuildID);
if(Iterator == Banks.end())
return nullptr;
GuildBankItem* BankArea = nullptr;
ItemInst* inst = nullptr;
if(Area == GuildBankDepositArea)
{
if((SlotID > (GUILD_BANK_DEPOSIT_AREA_SIZE - 1)))
return nullptr;
inst = database.CreateItem((*Iterator)->Items.DepositArea[SlotID].ItemID);
if(!inst)
return nullptr;
BankArea = &(*Iterator)->Items.DepositArea[0];
}
else
{
if((SlotID > (GUILD_BANK_MAIN_AREA_SIZE - 1)))
return nullptr;
inst = database.CreateItem((*Iterator)->Items.MainArea[SlotID].ItemID);
if(!inst)
return nullptr;
BankArea = &(*Iterator)->Items.MainArea[0];
}
if(!inst->IsStackable())
inst->SetCharges(BankArea[SlotID].Quantity);
else
{
if(Quantity <= BankArea[SlotID].Quantity)
inst->SetCharges(Quantity);
else
inst->SetCharges(BankArea[SlotID].Quantity);
}
return inst;
}
示例10: dumpItemCollection
void Inventory::dumpItemCollection(const std::map<int16, ItemInst*> &collection) {
iter_inst it;
iter_contents itb;
ItemInst* inst = nullptr;
for (it=collection.begin(); it!=collection.end(); ++it) {
inst = it->second;
if(!inst || !inst->GetItem())
continue;
std::string slot;
StringFormat(slot, "Slot %d: %s (%d)",it->first, it->second->GetItem()->Name, (inst->GetCharges()<=0) ? 1 : inst->GetCharges());
std::cout << slot << std::endl;
dumpBagContents(inst, &it);
}
}
示例11: PutItem
void ItemInst::PutItem(uint8 index, const ItemInst& inst)
{
// Clean up item already in slot (if exists)
DeleteItem(index);
// Delegate to internal method
_PutItem(index, inst.Clone());
}
示例12: dumpBagContents
void Inventory::dumpBagContents(ItemInst *inst, iter_inst *it) {
iter_contents itb;
if (!inst || !inst->IsType(ItemClassContainer))
return;
// Go through bag, if bag
for (itb=inst->_begin(); itb!=inst->_end(); ++itb) {
ItemInst* baginst = itb->second;
if(!baginst || !baginst->GetItem())
continue;
std::string subSlot;
StringFormat(subSlot," Slot %d: %s (%d)", Inventory::CalcSlotId((*it)->first, itb->first),
baginst->GetItem()->Name, (baginst->GetCharges()<=0) ? 1 : baginst->GetCharges());
std::cout << subSlot << std::endl;
}
}
示例13: Close
void Object::Close() {
m_inuse = false;
if(user != nullptr)
{
last_user = user;
// put any remaining items from the world container back into the player's inventory to avoid item loss
// if they close the container without removing all items
ItemInst* container = this->m_inst;
if(container != nullptr)
{
for (uint8 i = SUB_BEGIN; i < EmuConstants::ITEM_CONTAINER_SIZE; i++)
{
ItemInst* inst = container->PopItem(i);
if(inst != nullptr)
{
user->MoveItemToInventory(inst, true);
}
}
}
user->SetTradeskillObject(nullptr);
}
user = nullptr;
}
示例14: Close
void Object::Close() {
m_inuse = false;
if(user != NULL)
{
last_user = user;
// put any remaining items from the world container back into the player's inventory to avoid item loss
// if they close the container without removing all items
ItemInst* container = this->m_inst;
if(container != NULL)
{
for (uint8 i = 0; i < MAX_ITEMS_PER_BAG; i++)
{
ItemInst* inst = container->PopItem(i);
if(inst != NULL)
{
user->MoveItemToInventory(inst, true);
}
}
}
user->SetTradeskillObject(NULL);
}
user = NULL;
}
示例15: _HasItem
// Internal Method: Checks an inventory queue type bucket for a particular item
sint16 Inventory::_HasItem(ItemInstQueue& iqueue, uint32 item_id, uint8 quantity)
{
iter_queue it;
iter_contents itb;
uint8 quantity_found = 0;
// Read-only iteration of queue
for (it=iqueue.begin(); it!=iqueue.end(); it++) {
ItemInst* inst = *it;
if (inst)
{
if (inst->GetID() == item_id) {
quantity_found += (inst->GetCharges()<=0) ? 1 : inst->GetCharges();
if (quantity_found >= quantity)
return SLOT_CURSOR;
}
for(int i = 0; i < MAX_AUGMENT_SLOTS; i++) {
if (inst->GetAugmentItemID(i) == item_id && quantity <= 1)
return SLOT_AUGMENT; // Only one augment per slot.
}
}
// Go through bag, if bag
if (inst && inst->IsType(ItemClassContainer)) {
for (itb=inst->_begin(); itb!=inst->_end(); itb++) {
ItemInst* baginst = itb->second;
if (baginst->GetID() == item_id) {
quantity_found += (baginst->GetCharges()<=0) ? 1 : baginst->GetCharges();
if (quantity_found >= quantity)
return Inventory::CalcSlotId(SLOT_CURSOR, itb->first);
}
for(int i = 0; i < MAX_AUGMENT_SLOTS; i++) {
if (baginst->GetAugmentItemID(i) == item_id && quantity <= 1)
return SLOT_AUGMENT; // Only one augment per slot.
}
}
}
}
// Not found
return SLOT_INVALID;
}