// Internal Method: Checks an inventory queue type bucket for a particular item sint16 Inventory::_HasItemByUse(ItemInstQueue& iqueue, uint8 use, 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 && inst->IsType(ItemClassCommon) && inst->GetItem()->ItemType == use) { quantity_found += (inst->GetCharges()<=0) ? 1 : inst->GetCharges(); if (quantity_found >= quantity) 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()->ItemType == use) { quantity_found += (baginst->GetCharges()<=0) ? 1 : baginst->GetCharges(); if (quantity_found >= quantity) return Inventory::CalcSlotId(SLOT_CURSOR, itb->first); } } } } // Not found return SLOT_INVALID; }
// Internal Method: Checks an inventory bucket for a particular item int16 Inventory::_HasItem(std::map<int16, ItemInst*>& bucket, uint32 item_id, uint8 quantity) { iter_inst it; iter_contents itb; ItemInst* inst = nullptr; uint8 quantity_found = 0; // Check item: After failed checks, check bag contents (if bag) for (it = bucket.begin(); it != bucket.end(); ++it) { inst = it->second; if (inst) { if (inst->GetID() == item_id) { quantity_found += (inst->GetCharges() <= 0) ? 1 : inst->GetCharges(); if (quantity_found >= quantity) return it->first; } } // 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(it->first, itb->first); } } } } // Not found return SLOT_INVALID; }
// Internal Method: Checks an inventory bucket for a particular item sint16 Inventory::_HasItemByUse(map<sint16, ItemInst*>& bucket, uint8 use, uint8 quantity) { iter_inst it; iter_contents itb; ItemInst* inst = NULL; uint8 quantity_found = 0; // Check item: After failed checks, check bag contents (if bag) for (it=bucket.begin(); it!=bucket.end(); it++) { inst = it->second; if (inst && inst->IsType(ItemClassCommon) && inst->GetItem()->ItemType == use) { quantity_found += (inst->GetCharges()<=0) ? 1 : inst->GetCharges(); if (quantity_found >= quantity) return it->first; } // 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()->ItemType == use) { quantity_found += (baginst->GetCharges()<=0) ? 1 : baginst->GetCharges(); if (quantity_found >= quantity) return Inventory::CalcSlotId(it->first, itb->first); } } } } // Not found return SLOT_INVALID; }
// 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; }
// Internal Method: Checks an inventory bucket for a particular item sint16 Inventory::_HasItem(map<sint16, ItemInst*>& bucket, uint32 item_id, uint8 quantity) { iter_inst it; iter_contents itb; ItemInst* inst = NULL; uint8 quantity_found = 0; // Check item: After failed checks, check bag contents (if bag) for (it=bucket.begin(); it!=bucket.end(); it++) { inst = it->second; if (inst) { if (inst->GetID() == item_id) { quantity_found += (inst->GetCharges()<=0) ? 1 : inst->GetCharges(); if (quantity_found >= quantity) return it->first; } 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(it->first, 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; }
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; } }
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); } }
void Corpse::LootItem(Client* client, const EQApplicationPacket* app) { /* This gets sent no matter what as a sort of ACK */ client->QueuePacket(app); if (!loot_cooldown_timer.Check()) { SendEndLootErrorPacket(client); //unlock corpse for others if (this->being_looted_by = client->GetID()) { being_looted_by = 0xFFFFFFFF; } return; } /* To prevent item loss for a player using 'Loot All' who doesn't have inventory space for all their items. */ if (RuleB(Character, CheckCursorEmptyWhenLooting) && !client->GetInv().CursorEmpty()) { client->Message(13, "You may not loot an item while you have an item on your cursor."); SendEndLootErrorPacket(client); /* Unlock corpse for others */ if (this->being_looted_by = client->GetID()) { being_looted_by = 0xFFFFFFFF; } return; } LootingItem_Struct* lootitem = (LootingItem_Struct*)app->pBuffer; if (this->being_looted_by != client->GetID()) { client->Message(13, "Error: Corpse::LootItem: BeingLootedBy != client"); SendEndLootErrorPacket(client); return; } if (IsPlayerCorpse() && !CanPlayerLoot(client->CharacterID()) && !become_npc && (char_id != client->CharacterID() && client->Admin() < 150)) { client->Message(13, "Error: This is a player corpse and you dont own it."); SendEndLootErrorPacket(client); return; } if (is_locked && client->Admin() < 100) { SendLootReqErrorPacket(client, 0); client->Message(13, "Error: Corpse locked by GM."); return; } if (IsPlayerCorpse() && (char_id != client->CharacterID()) && CanPlayerLoot(client->CharacterID()) && GetPlayerKillItem() == 0){ client->Message(13, "Error: You cannot loot any more items from this corpse."); SendEndLootErrorPacket(client); being_looted_by = 0xFFFFFFFF; return; } const Item_Struct* item = 0; ItemInst *inst = 0; ServerLootItem_Struct* item_data = nullptr, *bag_item_data[10]; memset(bag_item_data, 0, sizeof(bag_item_data)); if (GetPlayerKillItem() > 1){ item = database.GetItem(GetPlayerKillItem()); } else if (GetPlayerKillItem() == -1 || GetPlayerKillItem() == 1){ item_data = GetItem(lootitem->slot_id - EmuConstants::CORPSE_BEGIN); //dont allow them to loot entire bags of items as pvp reward } else{ item_data = GetItem(lootitem->slot_id - EmuConstants::CORPSE_BEGIN, bag_item_data); } if (GetPlayerKillItem()<=1 && item_data != 0) { item = database.GetItem(item_data->item_id); } if (item != 0) { if (item_data){ inst = database.CreateItem(item, item_data ? item_data->charges : 0, item_data->aug_1, item_data->aug_2, item_data->aug_3, item_data->aug_4, item_data->aug_5, item_data->aug_6, item_data->attuned); } else { inst = database.CreateItem(item); } } if (client && inst) { if (client->CheckLoreConflict(item)) { client->Message_StringID(0, LOOT_LORE_ERROR); SendEndLootErrorPacket(client); being_looted_by = 0; delete inst; return; } if (inst->IsAugmented()) { for (int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) { ItemInst *itm = inst->GetAugment(i); if (itm) { if (client->CheckLoreConflict(itm->GetItem())) { client->Message_StringID(0, LOOT_LORE_ERROR); SendEndLootErrorPacket(client); being_looted_by = 0; delete inst; return; } } } } char buf[88]; char corpse_name[64]; strcpy(corpse_name, corpse_name); snprintf(buf, 87, "%d %d %s", inst->GetItem()->ID, inst->GetCharges(), EntityList::RemoveNumbers(corpse_name)); buf[87] = '\0'; std::vector<EQEmu::Any> args; args.push_back(inst); args.push_back(this); parse->EventPlayer(EVENT_LOOT, client, buf, 0, &args); parse->EventItem(EVENT_LOOT, client, inst, this, buf, 0); if (!IsPlayerCorpse() && RuleB(Character, EnableDiscoveredItems)) { if (client && !client->GetGM() && !client->IsDiscovered(inst->GetItem()->ID)) client->DiscoverItem(inst->GetItem()->ID); } if (zone->adv_data) { ServerZoneAdventureDataReply_Struct *ad = (ServerZoneAdventureDataReply_Struct*)zone->adv_data; if (ad->type == Adventure_Collect && !IsPlayerCorpse()) { if (ad->data_id == inst->GetItem()->ID) { zone->DoAdventureCountIncrease(); } } } /* First add it to the looter - this will do the bag contents too */ if (lootitem->auto_loot) { if (!client->AutoPutLootInInventory(*inst, true, true, bag_item_data)) client->PutLootInInventory(MainCursor, *inst, bag_item_data); } else { client->PutLootInInventory(MainCursor, *inst, bag_item_data); } /* Update any tasks that have an activity to loot this item */ if (RuleB(TaskSystem, EnableTaskSystem)) client->UpdateTasksForItem(ActivityLoot, item->ID); /* Remove it from Corpse */ if (item_data){ /* Delete needs to be before RemoveItem because its deletes the pointer for item_data/bag_item_data */ database.DeleteItemOffCharacterCorpse(this->corpse_db_id, item_data->equip_slot, item_data->item_id); /* Delete Item Instance */ RemoveItem(item_data->lootslot); } /* Remove Bag Contents */ if (item->ItemClass == ItemClassContainer && (GetPlayerKillItem() != -1 || GetPlayerKillItem() != 1)) { for (int i = SUB_BEGIN; i < EmuConstants::ITEM_CONTAINER_SIZE; i++) { if (bag_item_data[i]) { /* Delete needs to be before RemoveItem because its deletes the pointer for item_data/bag_item_data */ database.DeleteItemOffCharacterCorpse(this->corpse_db_id, bag_item_data[i]->equip_slot, bag_item_data[i]->item_id); /* Delete Item Instance */ RemoveItem(bag_item_data[i]); } } } if (GetPlayerKillItem() != -1) { SetPlayerKillItemID(0); } /* Send message with item link to groups and such */ Client::TextLink linker; linker.SetLinkType(linker.linkItemInst); linker.SetItemInst(inst); auto item_link = linker.GenerateLink(); client->Message_StringID(MT_LootMessages, LOOTED_MESSAGE, item_link.c_str()); if (!IsPlayerCorpse()) { Group *g = client->GetGroup(); if(g != nullptr) { g->GroupMessage_StringID(client, MT_LootMessages, OTHER_LOOTED_MESSAGE, client->GetName(), item_link.c_str()); } else { Raid *r = client->GetRaid(); if(r != nullptr) { r->RaidMessage_StringID(client, MT_LootMessages, OTHER_LOOTED_MESSAGE, client->GetName(), item_link.c_str()); } } } } else { SendEndLootErrorPacket(client); safe_delete(inst); return; } if (IsPlayerCorpse()){ client->SendItemLink(inst); } else{ client->SendItemLink(inst, true); } safe_delete(inst); }
bool Inventory::HasSpaceForItem(const Item_Struct *ItemToTry, sint16 Quantity) { if(ItemToTry->Stackable) { for(sint16 i = 22; i <= 29; i++) { ItemInst* InvItem = GetItem(i); if(InvItem && (InvItem->GetItem()->ID == ItemToTry->ID) && (InvItem->GetCharges() < InvItem->GetItem()->StackSize)) { int ChargeSlotsLeft = InvItem->GetItem()->StackSize - InvItem->GetCharges(); if(Quantity <= ChargeSlotsLeft) return true; Quantity -= ChargeSlotsLeft; } if (InvItem && InvItem->IsType(ItemClassContainer)) { sint16 BaseSlotID = Inventory::CalcSlotId(i, 0); int8 BagSize=InvItem->GetItem()->BagSlots; for (uint8 BagSlot = 0; BagSlot < BagSize; BagSlot++) { InvItem = GetItem(BaseSlotID + BagSlot); if(InvItem && (InvItem->GetItem()->ID == ItemToTry->ID) && (InvItem->GetCharges() < InvItem->GetItem()->StackSize)) { int ChargeSlotsLeft = InvItem->GetItem()->StackSize - InvItem->GetCharges(); if(Quantity <= ChargeSlotsLeft) return true; Quantity -= ChargeSlotsLeft; } } } } } for (sint16 i = 22; i <= 29; i++) { ItemInst* InvItem = GetItem(i); if (!InvItem) { if(!ItemToTry->Stackable) { if(Quantity == 1) return true; else Quantity--; } else { if(Quantity <= ItemToTry->StackSize) return true; else Quantity -= ItemToTry->StackSize; } } else if(InvItem->IsType(ItemClassContainer) && CanItemFitInContainer(ItemToTry, InvItem->GetItem())) { sint16 BaseSlotID = Inventory::CalcSlotId(i, 0); int8 BagSize=InvItem->GetItem()->BagSlots; for (uint8 BagSlot=0; BagSlot<BagSize; BagSlot++) { InvItem = GetItem(BaseSlotID + BagSlot); if(!InvItem) { if(!ItemToTry->Stackable) { if(Quantity == 1) return true; else Quantity--; } else { if(Quantity <= ItemToTry->StackSize) return true; else Quantity -= ItemToTry->StackSize; } } } } } return false; }
void Inventory::dumpInventory() { iter_inst it; iter_contents itb; ItemInst* inst = NULL; // Check item: After failed checks, check bag contents (if bag) printf("Worn items:\n"); for (it=m_worn.begin(); it!=m_worn.end(); it++) { inst = it->second; it->first; if(!inst || !inst->GetItem()) continue; printf("Slot %d: %s (%d)\n", it->first, it->second->GetItem()->Name, (inst->GetCharges()<=0) ? 1 : inst->GetCharges()); // 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->GetItem()) continue; printf(" Slot %d: %s (%d)\n", Inventory::CalcSlotId(it->first, itb->first), baginst->GetItem()->Name, (baginst->GetCharges()<=0) ? 1 : baginst->GetCharges()); } } } printf("Inventory items:\n"); for (it=m_inv.begin(); it!=m_inv.end(); it++) { inst = it->second; it->first; if(!inst || !inst->GetItem()) continue; printf("Slot %d: %s (%d)\n", it->first, it->second->GetItem()->Name, (inst->GetCharges()<=0) ? 1 : inst->GetCharges()); // 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->GetItem()) continue; printf(" Slot %d: %s (%d)\n", Inventory::CalcSlotId(it->first, itb->first), baginst->GetItem()->Name, (baginst->GetCharges()<=0) ? 1 : baginst->GetCharges()); } } } printf("Bank items:\n"); for (it=m_bank.begin(); it!=m_bank.end(); it++) { inst = it->second; it->first; if(!inst || !inst->GetItem()) continue; printf("Slot %d: %s (%d)\n", it->first, it->second->GetItem()->Name, (inst->GetCharges()<=0) ? 1 : inst->GetCharges()); // 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->GetItem()) continue; printf(" Slot %d: %s (%d)\n", Inventory::CalcSlotId(it->first, itb->first), baginst->GetItem()->Name, (baginst->GetCharges()<=0) ? 1 : baginst->GetCharges()); } } } printf("Shared Bank items:\n"); for (it=m_shbank.begin(); it!=m_shbank.end(); it++) { inst = it->second; it->first; if(!inst || !inst->GetItem()) continue; printf("Slot %d: %s (%d)\n", it->first, it->second->GetItem()->Name, (inst->GetCharges()<=0) ? 1 : inst->GetCharges()); // 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->GetItem()) continue; printf(" Slot %d: %s (%d)\n", Inventory::CalcSlotId(it->first, itb->first), baginst->GetItem()->Name, (baginst->GetCharges()<=0) ? 1 : baginst->GetCharges()); } } } printf("\n"); fflush(stdout); }
void PerlembParser::ExportEventVariables(std::string &package_name, QuestEventID event, uint32 objid, const char * data, NPC* npcmob, ItemInst* iteminst, Mob* mob, uint32 extradata, std::vector<EQEmu::Any> *extra_pointers) { switch (event) { case EVENT_SAY: { if(npcmob && mob) { npcmob->DoQuestPause(mob); } ExportVar(package_name.c_str(), "data", objid); ExportVar(package_name.c_str(), "text", data); ExportVar(package_name.c_str(), "langid", extradata); break; } case EVENT_TRADE: { if(extra_pointers) { size_t sz = extra_pointers->size(); for(size_t i = 0; i < sz; ++i) { ItemInst *inst = EQEmu::any_cast<ItemInst*>(extra_pointers->at(i)); std::string var_name = "item"; var_name += std::to_string(i + 1); if(inst) { ExportVar(package_name.c_str(), var_name.c_str(), inst->GetItem()->ID); std::string temp_var_name = var_name; temp_var_name += "_charges"; ExportVar(package_name.c_str(), temp_var_name.c_str(), inst->GetCharges()); temp_var_name = var_name; temp_var_name += "_attuned"; ExportVar(package_name.c_str(), temp_var_name.c_str(), inst->IsAttuned()); } else { ExportVar(package_name.c_str(), var_name.c_str(), 0); std::string temp_var_name = var_name; temp_var_name += "_charges"; ExportVar(package_name.c_str(), temp_var_name.c_str(), 0); temp_var_name = var_name; temp_var_name += "_attuned"; ExportVar(package_name.c_str(), temp_var_name.c_str(), 0); } } } ExportVar(package_name.c_str(), "copper", GetVar("copper." + std::string(itoa(objid))).c_str()); ExportVar(package_name.c_str(), "silver", GetVar("silver." + std::string(itoa(objid))).c_str()); ExportVar(package_name.c_str(), "gold", GetVar("gold." + std::string(itoa(objid))).c_str()); ExportVar(package_name.c_str(), "platinum", GetVar("platinum." + std::string(itoa(objid))).c_str()); std::string hashname = package_name + std::string("::itemcount"); perl->eval(std::string("%").append(hashname).append(" = ();").c_str()); perl->eval(std::string("++$").append(hashname).append("{$").append(package_name).append("::item1};").c_str()); perl->eval(std::string("++$").append(hashname).append("{$").append(package_name).append("::item2};").c_str()); perl->eval(std::string("++$").append(hashname).append("{$").append(package_name).append("::item3};").c_str()); perl->eval(std::string("++$").append(hashname).append("{$").append(package_name).append("::item4};").c_str()); break; } case EVENT_WAYPOINT_ARRIVE: case EVENT_WAYPOINT_DEPART: { ExportVar(package_name.c_str(), "wp", data); break; } case EVENT_HP: { if (extradata == 1) { ExportVar(package_name.c_str(), "hpevent", "-1"); ExportVar(package_name.c_str(), "inchpevent", data); } else { ExportVar(package_name.c_str(), "hpevent", data); ExportVar(package_name.c_str(), "inchpevent", "-1"); } break; } case EVENT_TIMER: { ExportVar(package_name.c_str(), "timer", data); break; } case EVENT_SIGNAL: { ExportVar(package_name.c_str(), "signal", data); break; } case EVENT_NPC_SLAY: { ExportVar(package_name.c_str(), "killed", mob->GetNPCTypeID()); break; } case EVENT_COMBAT: { ExportVar(package_name.c_str(), "combat_state", data); break; } case EVENT_CLICK_DOOR: { ExportVar(package_name.c_str(), "doorid", data); ExportVar(package_name.c_str(), "version", zone->GetInstanceVersion()); break; } case EVENT_LOOT: { Seperator sep(data); ExportVar(package_name.c_str(), "looted_id", sep.arg[0]); ExportVar(package_name.c_str(), "looted_charges", sep.arg[1]); ExportVar(package_name.c_str(), "corpse", sep.arg[2]); break; } case EVENT_ZONE: { ExportVar(package_name.c_str(), "target_zone_id", data); break; } case EVENT_CAST_ON: case EVENT_CAST: case EVENT_CAST_BEGIN: { ExportVar(package_name.c_str(), "spell_id", data); break; } case EVENT_TASK_ACCEPTED: { ExportVar(package_name.c_str(), "task_id", data); break; } case EVENT_TASK_STAGE_COMPLETE: { Seperator sep(data); ExportVar(package_name.c_str(), "task_id", sep.arg[0]); ExportVar(package_name.c_str(), "activity_id", sep.arg[1]); break; } case EVENT_TASK_FAIL: { Seperator sep(data); ExportVar(package_name.c_str(), "task_id", sep.arg[0]); break; } case EVENT_TASK_COMPLETE: case EVENT_TASK_UPDATE: { Seperator sep(data); ExportVar(package_name.c_str(), "donecount", sep.arg[0]); ExportVar(package_name.c_str(), "activity_id", sep.arg[1]); ExportVar(package_name.c_str(), "task_id", sep.arg[2]); break; } case EVENT_PLAYER_PICKUP: { ExportVar(package_name.c_str(), "picked_up_id", data); ExportVar(package_name.c_str(), "picked_up_entity_id", extradata); break; } case EVENT_AGGRO_SAY: { ExportVar(package_name.c_str(), "data", objid); ExportVar(package_name.c_str(), "text", data); ExportVar(package_name.c_str(), "langid", extradata); break; } case EVENT_POPUP_RESPONSE: { ExportVar(package_name.c_str(), "popupid", data); break; } case EVENT_ENVIRONMENTAL_DAMAGE: { Seperator sep(data); ExportVar(package_name.c_str(), "env_damage", sep.arg[0]); ExportVar(package_name.c_str(), "env_damage_type", sep.arg[1]); ExportVar(package_name.c_str(), "env_final_damage", sep.arg[2]); break; } case EVENT_PROXIMITY_SAY: { ExportVar(package_name.c_str(), "data", objid); ExportVar(package_name.c_str(), "text", data); ExportVar(package_name.c_str(), "langid", extradata); break; } case EVENT_SCALE_CALC: case EVENT_ITEM_ENTER_ZONE: { // need a valid ItemInst pointer check here..unsure how to cancel this process ExportVar(package_name.c_str(), "itemid", objid); ExportVar(package_name.c_str(), "itemname", iteminst->GetItem()->Name); break; } case EVENT_ITEM_CLICK_CAST: case EVENT_ITEM_CLICK: { // need a valid ItemInst pointer check here..unsure how to cancel this process ExportVar(package_name.c_str(), "itemid", objid); ExportVar(package_name.c_str(), "itemname", iteminst->GetItem()->Name); ExportVar(package_name.c_str(), "slotid", extradata); ExportVar(package_name.c_str(), "spell_id", iteminst->GetItem()->Click.Effect); break; } case EVENT_GROUP_CHANGE: { if(mob && mob->IsClient()) { ExportVar(package_name.c_str(), "grouped", mob->IsGrouped()); ExportVar(package_name.c_str(), "raided", mob->IsRaidGrouped()); } break; } case EVENT_HATE_LIST: { ExportVar(package_name.c_str(), "hate_state", data); break; } case EVENT_SPELL_EFFECT_CLIENT: case EVENT_SPELL_EFFECT_NPC: case EVENT_SPELL_BUFF_TIC_CLIENT: case EVENT_SPELL_BUFF_TIC_NPC: { ExportVar(package_name.c_str(), "caster_id", extradata); break; } //tradeskill events case EVENT_COMBINE_SUCCESS: case EVENT_COMBINE_FAILURE: { ExportVar(package_name.c_str(), "recipe_id", extradata); ExportVar(package_name.c_str(), "recipe_name", data); break; } case EVENT_FORAGE_SUCCESS: { ExportVar(package_name.c_str(), "foraged_item", extradata); break; } case EVENT_FISH_SUCCESS: { ExportVar(package_name.c_str(), "fished_item", extradata); break; } case EVENT_CLICK_OBJECT: { ExportVar(package_name.c_str(), "objectid", data); ExportVar(package_name.c_str(), "clicker_id", extradata); break; } case EVENT_DISCOVER_ITEM: { ExportVar(package_name.c_str(), "itemid", extradata); break; } case EVENT_COMMAND: { ExportVar(package_name.c_str(), "text", data); ExportVar(package_name.c_str(), "data", "0"); ExportVar(package_name.c_str(), "langid", "0"); break; } case EVENT_RESPAWN: { ExportVar(package_name.c_str(), "option", data); ExportVar(package_name.c_str(), "resurrect", extradata); break; } case EVENT_DEATH: case EVENT_DEATH_COMPLETE: { Seperator sep(data); ExportVar(package_name.c_str(), "killer_id", sep.arg[0]); ExportVar(package_name.c_str(), "killer_damage", sep.arg[1]); ExportVar(package_name.c_str(), "killer_spell", sep.arg[2]); ExportVar(package_name.c_str(), "killer_skill", sep.arg[3]); break; } case EVENT_DROP_ITEM: { ExportVar(package_name.c_str(), "quantity", iteminst->IsStackable() ? iteminst->GetCharges() : 1); ExportVar(package_name.c_str(), "itemname", iteminst->GetItem()->Name); ExportVar(package_name.c_str(), "itemid", iteminst->GetItem()->ID); ExportVar(package_name.c_str(), "spell_id", iteminst->GetItem()->Click.Effect); ExportVar(package_name.c_str(), "slotid", extradata); break; } case EVENT_SPAWN_ZONE: { Seperator sep(data); ExportVar(package_name.c_str(), "spawned_entity_id", sep.arg[0]); ExportVar(package_name.c_str(), "spawned_npc_id", sep.arg[1]); break; } case EVENT_DEATH_ZONE: { Seperator sep(data); ExportVar(package_name.c_str(), "killer_id", sep.arg[0]); ExportVar(package_name.c_str(), "killer_damage", sep.arg[1]); ExportVar(package_name.c_str(), "killer_spell", sep.arg[2]); ExportVar(package_name.c_str(), "killer_skill", sep.arg[3]); ExportVar(package_name.c_str(), "killed_npc_id", sep.arg[4]); break; } default: { break; } } }
// Perform tradeskill combine void Object::HandleCombine(Client* user, const NewCombine_Struct* in_combine, Object *worldo) { if (!user || !in_combine) { Log.Out(Logs::General, Logs::Error, "Client or NewCombine_Struct not set in Object::HandleCombine"); return; } Inventory& user_inv = user->GetInv(); PlayerProfile_Struct& user_pp = user->GetPP(); ItemInst* container = nullptr; ItemInst* inst = nullptr; uint8 c_type = 0xE8; uint32 some_id = 0; bool worldcontainer=false; if (in_combine->container_slot == legacy::SLOT_TRADESKILL) { if(!worldo) { user->Message(13, "Error: Server is not aware of the tradeskill container you are attempting to use"); return; } c_type = worldo->m_type; inst = worldo->m_inst; worldcontainer=true; } else { inst = user_inv.GetItem(in_combine->container_slot); if (inst) { const Item_Struct* item = inst->GetItem(); if (item && inst->IsType(ItemClassContainer)) { c_type = item->BagType; some_id = item->ID; } } } if (!inst || !inst->IsType(ItemClassContainer)) { user->Message(13, "Error: Server does not recognize specified tradeskill container"); return; } container = inst; if (container->GetItem() && container->GetItem()->BagType == BagTypeTransformationmold) { const ItemInst* inst = container->GetItem(0); bool AllowAll = RuleB(Inventory, AllowAnyWeaponTransformation); if (inst && ItemInst::CanTransform(inst->GetItem(), container->GetItem(), AllowAll)) { const Item_Struct* new_weapon = inst->GetItem(); user->DeleteItemInInventory(Inventory::CalcSlotId(in_combine->container_slot, 0), 0, true); container->Clear(); user->SummonItem(new_weapon->ID, inst->GetCharges(), inst->GetAugmentItemID(0), inst->GetAugmentItemID(1), inst->GetAugmentItemID(2), inst->GetAugmentItemID(3), inst->GetAugmentItemID(4), inst->GetAugmentItemID(5), inst->IsAttuned(), MainCursor, container->GetItem()->Icon, atoi(container->GetItem()->IDFile + 2)); user->Message_StringID(4, TRANSFORM_COMPLETE, inst->GetItem()->Name); if (RuleB(Inventory, DeleteTransformationMold)) user->DeleteItemInInventory(in_combine->container_slot, 0, true); } else if (inst) { user->Message_StringID(4, TRANSFORM_FAILED, inst->GetItem()->Name); } EQApplicationPacket* outapp = new EQApplicationPacket(OP_TradeSkillCombine, 0); user->QueuePacket(outapp); safe_delete(outapp); return; } if (container->GetItem() && container->GetItem()->BagType == BagTypeDetransformationmold) { const ItemInst* inst = container->GetItem(0); if (inst && inst->GetOrnamentationIcon() && inst->GetOrnamentationIcon()) { const Item_Struct* new_weapon = inst->GetItem(); user->DeleteItemInInventory(Inventory::CalcSlotId(in_combine->container_slot, 0), 0, true); container->Clear(); user->SummonItem(new_weapon->ID, inst->GetCharges(), inst->GetAugmentItemID(0), inst->GetAugmentItemID(1), inst->GetAugmentItemID(2), inst->GetAugmentItemID(3), inst->GetAugmentItemID(4), inst->GetAugmentItemID(5), inst->IsAttuned(), MainCursor, 0, 0); user->Message_StringID(4, TRANSFORM_COMPLETE, inst->GetItem()->Name); } else if (inst) { user->Message_StringID(4, DETRANSFORM_FAILED, inst->GetItem()->Name); } EQApplicationPacket* outapp = new EQApplicationPacket(OP_TradeSkillCombine, 0); user->QueuePacket(outapp); safe_delete(outapp); return; } DBTradeskillRecipe_Struct spec; if (!database.GetTradeRecipe(container, c_type, some_id, user->CharacterID(), &spec)) { user->Message_StringID(MT_Emote,TRADESKILL_NOCOMBINE); EQApplicationPacket* outapp = new EQApplicationPacket(OP_TradeSkillCombine, 0); user->QueuePacket(outapp); safe_delete(outapp); return; } // Character hasn't learnt the recipe yet. // must_learn: // bit 1 (0x01): recipe can't be experimented // bit 2 (0x02): can try to experiment but not useable for auto-combine until learnt // bit 5 (0x10): no learn message, use unlisted flag to prevent it showing up on search // bit 6 (0x20): unlisted recipe flag if ((spec.must_learn&0xF) == 1 && !spec.has_learnt) { // Made up message for the client. Just giving a DNC is the other option. user->Message(4, "You need to learn how to combine these first."); EQApplicationPacket* outapp = new EQApplicationPacket(OP_TradeSkillCombine, 0); user->QueuePacket(outapp); safe_delete(outapp); return; } // Character does not have the required skill. if(spec.skill_needed > 0 && user->GetSkill(spec.tradeskill) < spec.skill_needed ) { // Notify client. user->Message(4, "You are not skilled enough."); EQApplicationPacket* outapp = new EQApplicationPacket(OP_TradeSkillCombine, 0); user->QueuePacket(outapp); safe_delete(outapp); return; } //changing from a switch to string of if's since we don't need to iterate through all of the skills in the SkillType enum if (spec.tradeskill == SkillAlchemy) { if (user_pp.class_ != SHAMAN) { user->Message(13, "This tradeskill can only be performed by a shaman."); return; } else if (user_pp.level < MIN_LEVEL_ALCHEMY) { user->Message(13, "You cannot perform alchemy until you reach level %i.", MIN_LEVEL_ALCHEMY); return; } } else if (spec.tradeskill == SkillTinkering) { if (user_pp.race != GNOME) { user->Message(13, "Only gnomes can tinker."); return; } } else if (spec.tradeskill == SkillMakePoison) { if (user_pp.class_ != ROGUE) { user->Message(13, "Only rogues can mix poisons."); return; } } // Send acknowledgement packets to client EQApplicationPacket* outapp = new EQApplicationPacket(OP_TradeSkillCombine, 0); user->QueuePacket(outapp); safe_delete(outapp); //now clean out the containers. if(worldcontainer){ container->Clear(); outapp = new EQApplicationPacket(OP_ClearObject, sizeof(ClearObject_Struct)); ClearObject_Struct *cos = (ClearObject_Struct *)outapp->pBuffer; cos->Clear = 1; user->QueuePacket(outapp); safe_delete(outapp); database.DeleteWorldContainer(worldo->m_id, zone->GetZoneID()); } else{ for (uint8 i = MAIN_BEGIN; i < EmuConstants::MAP_WORLD_SIZE; i++) { const ItemInst* inst = container->GetItem(i); if (inst) { user->DeleteItemInInventory(Inventory::CalcSlotId(in_combine->container_slot,i),0,true); } } container->Clear(); } //do the check and send results... bool success = user->TradeskillExecute(&spec); // Learn new recipe message // Update Made count if (success) { if (!spec.has_learnt && ((spec.must_learn&0x10) != 0x10)) { user->Message_StringID(4, TRADESKILL_LEARN_RECIPE, spec.name.c_str()); } database.UpdateRecipeMadecount(spec.recipe_id, user->CharacterID(), spec.madecount+1); } // Replace the container on success if required. // if(success && spec.replace_container) { if(worldcontainer){ //should report this error, but we dont have the recipe ID, so its not very useful Log.Out(Logs::General, Logs::Error, "Replace container combine executed in a world container."); } else user->DeleteItemInInventory(in_combine->container_slot, 0, true); } if (success) parse->EventPlayer(EVENT_COMBINE_SUCCESS, user, spec.name.c_str(), spec.recipe_id); else parse->EventPlayer(EVENT_COMBINE_FAILURE, user, spec.name.c_str(), spec.recipe_id); }