本文整理汇总了C++中ItemInst::GetItem方法的典型用法代码示例。如果您正苦于以下问题:C++ ItemInst::GetItem方法的具体用法?C++ ItemInst::GetItem怎么用?C++ ItemInst::GetItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ItemInst
的用法示例。
在下文中一共展示了ItemInst::GetItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _HasItemByUse
// 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;
}
示例2: GetItem
// Retrieve item at specified slot; returns false if item not found
ItemInst* Inventory::GetItem(int16 slot_id) const
{
ItemInst* result = nullptr;
// Cursor
if (slot_id == SLOT_CURSOR) {
// Cursor slot
result = m_cursor.peek_front();
}
// Non bag slots
else if (slot_id >= 3000 && slot_id <= 3007) {
// Trade slots
result = _GetItem(m_trade, slot_id);
}
else if (slot_id >= 2000 && slot_id <= 2007) {
// Bank slots
result = _GetItem(m_bank, slot_id);
}
else if ((slot_id >= 22 && slot_id <= 29)) {
// Personal inventory slots
result = _GetItem(m_inv, slot_id);
}
else if ((slot_id >= 1 && slot_id <= 21)) {
// Equippable slots (on body)
result = _GetItem(m_worn, slot_id);
}
// Trade bag slots
else if (slot_id >= 3030 && slot_id <= 3109) {
// Trade bag slots
ItemInst* inst = _GetItem(m_trade, Inventory::CalcSlotId(slot_id));
if (inst && inst->IsType(ItemClassContainer)) {
result = inst->GetItem(Inventory::CalcBagIdx(slot_id));
}
}
else if (slot_id >= 2030 && slot_id <= 2109) {
// Bank bag slots
ItemInst* inst = _GetItem(m_bank, Inventory::CalcSlotId(slot_id));
if (inst && inst->IsType(ItemClassContainer)) {
result = inst->GetItem(Inventory::CalcBagIdx(slot_id));
}
}
else if (slot_id >= 330 && slot_id <= 339) {
// Cursor bag slots
ItemInst* inst = m_cursor.peek_front();
if (inst && inst->IsType(ItemClassContainer)) {
result = inst->GetItem(Inventory::CalcBagIdx(slot_id));
}
}
else if (slot_id >= 250 && slot_id <= 329) {
// Personal inventory bag slots
ItemInst* inst = _GetItem(m_inv, Inventory::CalcSlotId(slot_id));
if (inst && inst->IsType(ItemClassContainer)) {
result = inst->GetItem(Inventory::CalcBagIdx(slot_id));
}
}
return result;
}
示例3: _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;
}
示例4: CheckNoDrop
// 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;
}
示例5: 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;
}
}
}
示例6: 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;
}
}
示例7: _HasItemByLoreGroup
// Internal Method: Checks an inventory queue type bucket for a particular item
sint16 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;
ItemInst* Aug;
for(int i = 0; i < MAX_AUGMENT_SLOTS; i++) {
Aug = inst->GetAugment(i);
if (Aug && Aug->GetItem()->LoreGroup == loregroup)
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 && baginst->IsType(ItemClassCommon)&& baginst->GetItem()->LoreGroup == loregroup)
return Inventory::CalcSlotId(SLOT_CURSOR, itb->first);
ItemInst* Aug2;
for(int i = 0; i < MAX_AUGMENT_SLOTS; i++) {
Aug2 = baginst->GetAugment(i);
if (Aug2 && Aug2->GetItem()->LoreGroup == loregroup)
return SLOT_AUGMENT; // Only one augment per slot.
}
}
}
}
// Not found
return SLOT_INVALID;
}
示例8: 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);
}
}
示例9: dumpInventory
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);
}
示例10: CalcCurrentWeight
uint32 Client::CalcCurrentWeight() {
const Item_Struct* TempItem = 0;
ItemInst* ins;
uint32 Total = 0;
int x;
for (x = MainCursor; x <= EmuConstants::GENERAL_END; x++)
{
TempItem = 0;
ins = GetInv().GetItem(x);
if (ins)
TempItem = ins->GetItem();
if (TempItem)
Total += TempItem->Weight;
ItemInst* baginst = ins;
ItemInst* inst;
const Item_Struct* Item = 0;
if (baginst && baginst->GetItem() && baginst->IsType(ItemClassContainer))
{
uint32 bag_weight = 0;
int i;
for (i = 0; i < baginst->GetItem()->BagSlots; i++)
{
inst = GetInv().GetItem(m_inv.CalcSlotId(x, i));
if (inst)
Item = inst->GetItem();
if (Item)
{
bag_weight += Item->Weight;
}
}
int reduction = baginst->GetItem()->BagWR;
if (reduction > 0 && bag_weight > 0)
bag_weight -= bag_weight*reduction/100;
Total += bag_weight;
}
}
uint32 coin_weight = (m_pp.platinum + m_pp.gold + m_pp.silver + m_pp.copper) / 4;
// Coin purses only work when in a main inventory slot
const Item_Struct* CoinItem = 0;
ItemInst* cins;
uint32 coin_reduction = 0;
for (x = EmuConstants::GENERAL_BEGIN; x <= EmuConstants::GENERAL_END; x++)
{
CoinItem = 0;
cins = GetInv().GetItem(x);
if (cins && cins->GetID() >= 17201 && cins->GetID() <= 17230)
{
CoinItem = cins->GetItem();
if(CoinItem)
coin_reduction = CoinItem->BagWR > coin_reduction ? CoinItem->BagWR : coin_reduction;
}
}
coin_weight -= coin_weight*coin_reduction/100;
Total += coin_weight;
float Packrat = (float)spellbonuses.Packrat + (float)aabonuses.Packrat + (float)itembonuses.Packrat;
if (Packrat > 0)
Total = (uint32)((float)Total * (1.0f - ((Packrat * 1.0f) / 100.0f))); //AndMetal: 1% per level, up to 5% (calculated from Titanium client). verified thru client that it reduces coin weight by the same %
//without casting to float & back to uint32, this didn't work right
return Total;
}
示例11: LootItem
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];
//.........这里部分代码省略.........
示例12: GetItem
// Retrieve item at specified slot; returns false if item not found
ItemInst* Inventory::GetItem(sint16 slot_id) const
{
_CP(Inventory_GetItem);
ItemInst* result = NULL;
// Cursor
if (slot_id == SLOT_CURSOR) {
// Cursor slot
result = m_cursor.peek_front();
}
// Non bag slots
else if (slot_id>=3000 && slot_id<=3007) {
// Trade slots
result = _GetItem(m_trade, slot_id);
}
else if (slot_id>=2500 && slot_id<=2501) {
// Shared Bank slots
result = _GetItem(m_shbank, slot_id);
}
else if (slot_id>=2000 && slot_id<=2023) {
// Bank slots
result = _GetItem(m_bank, slot_id);
}
else if ((slot_id>=22 && slot_id<=29)) {
// Personal inventory slots
result = _GetItem(m_inv, slot_id);
}
else if ((slot_id>=0 && slot_id<=21) || (slot_id >= 400 && slot_id<=404) || (slot_id == 9999)) {
// Equippable slots (on body)
result = _GetItem(m_worn, slot_id);
}
// Inner bag slots
else if (slot_id>=3031 && slot_id<=3110) {
// Trade bag slots
ItemInst* inst = _GetItem(m_trade, Inventory::CalcSlotId(slot_id));
if (inst && inst->IsType(ItemClassContainer)) {
result = inst->GetItem(Inventory::CalcBagIdx(slot_id));
}
}
else if (slot_id>=2531 && slot_id<=2550) {
// Shared Bank bag slots
ItemInst* inst = _GetItem(m_shbank, Inventory::CalcSlotId(slot_id));
if (inst && inst->IsType(ItemClassContainer)) {
result = inst->GetItem(Inventory::CalcBagIdx(slot_id));
}
}
else if (slot_id>=2031 && slot_id<=2270) {
// Bank bag slots
ItemInst* inst = _GetItem(m_bank, Inventory::CalcSlotId(slot_id));
if (inst && inst->IsType(ItemClassContainer)) {
result = inst->GetItem(Inventory::CalcBagIdx(slot_id));
}
}
else if (slot_id>=331 && slot_id<=340) {
// Cursor bag slots
ItemInst* inst = m_cursor.peek_front();
if (inst && inst->IsType(ItemClassContainer)) {
result = inst->GetItem(Inventory::CalcBagIdx(slot_id));
}
}
else if (slot_id>=251 && slot_id<=330) {
// Personal inventory bag slots
ItemInst* inst = _GetItem(m_inv, Inventory::CalcSlotId(slot_id));
if (inst && inst->IsType(ItemClassContainer)) {
result = inst->GetItem(Inventory::CalcBagIdx(slot_id));
}
}
return result;
}
示例13: GoFish
void Client::GoFish()
{
//TODO: generate a message if we're already fishing
/*if (!fishing_timer.Check()) { //this isn't the right check, may need to add something to the Client class like 'bool is_fishing'
Message_StringID(0, ALREADY_FISHING); //You are already fishing!
return;
}*/
fishing_timer.Disable();
//we're doing this a second time (1st in Client::Handle_OP_Fishing) to make sure that, between when we started fishing & now, we're still able to fish (in case we move, change equip, etc)
if (!CanFish()) //if we can't fish here, we don't need to bother with the rest
return;
//multiple entries yeilds higher probability of dropping...
uint32 common_fish_ids[MAX_COMMON_FISH_IDS] = {
1038, // Tattered Cloth Sandals
1038, // Tattered Cloth Sandals
1038, // Tattered Cloth Sandals
13019, // Fresh Fish
13076, // Fish Scales
13076, // Fish Scales
7007, // Rusty Dagger
7007, // Rusty Dagger
7007 // Rusty Dagger
};
//success formula is not researched at all
int fishing_skill = GetSkill(SkillFishing); //will take into account skill bonuses on pole & bait
//make sure we still have a fishing pole on:
int32 bslot = m_inv.HasItemByUse(ItemTypeFishingBait, 1, invWhereWorn|invWherePersonal);
const ItemInst* Bait = nullptr;
if (bslot != INVALID_INDEX)
Bait = m_inv.GetItem(bslot);
//if the bait isnt equipped, need to add its skill bonus
if(bslot >= EmuConstants::GENERAL_BEGIN && Bait->GetItem()->SkillModType == SkillFishing) {
fishing_skill += Bait->GetItem()->SkillModValue;
}
if (fishing_skill > 100)
{
fishing_skill = 100+((fishing_skill-100)/2);
}
if (zone->random.Int(0,175) < fishing_skill) {
uint32 food_id = 0;
//25% chance to fish an item.
if (zone->random.Int(0, 399) <= fishing_skill ) {
uint32 npc_id = 0;
uint8 npc_chance = 0;
food_id = database.GetZoneFishing(m_pp.zone_id, fishing_skill, npc_id, npc_chance);
//check for add NPC
if(npc_chance > 0 && npc_id) {
if(npc_chance < zone->random.Int(0, 99)) {
const NPCType* tmp = database.GetNPCType(npc_id);
if(tmp != nullptr) {
NPC* npc = new NPC(tmp, nullptr, GetX()+3, GetY(), GetZ(), GetHeading(), FlyMode3);
npc->AddLootTable();
npc->AddToHateList(this, 1, 0, false); //no help yelling
entity_list.AddNPC(npc);
Message(MT_Emote, "You fish up a little more than you bargained for...");
}
}
}
}
//consume bait, should we always consume bait on success?
DeleteItemInInventory(bslot, 1, true); //do we need client update?
if(food_id == 0) {
int index = zone->random.Int(0, MAX_COMMON_FISH_IDS-1);
food_id = common_fish_ids[index];
}
const Item_Struct* food_item = database.GetItem(food_id);
Message_StringID(MT_Skills, FISHING_SUCCESS);
ItemInst* inst = database.CreateItem(food_item, 1);
if(inst != nullptr) {
if(CheckLoreConflict(inst->GetItem()))
{
Message_StringID(0, DUP_LORE);
safe_delete(inst);
}
else
{
PushItemOnCursor(*inst);
SendItemPacket(MainCursor, inst, ItemPacketSummonItem);
if(RuleB(TaskSystem, EnableTaskSystem))
UpdateTasksForItem(ActivityFish, food_id);
//.........这里部分代码省略.........
示例14: ForageItem
void Client::ForageItem(bool guarantee) {
int skill_level = GetSkill(SkillForage);
//be wary of the string ids in switch below when changing this.
uint32 common_food_ids[MAX_COMMON_FOOD_IDS] = {
13046, // Fruit
13045, // Berries
13419, // Vegetables
13048, // Rabbit Meat
13047, // Roots
13044, // Pod Of Water
14905, // mushroom
13106 // Fishing Grubs
};
// these may need to be fine tuned, I am just guessing here
if (guarantee || zone->random.Int(0,199) < skill_level) {
uint32 foragedfood = 0;
uint32 stringid = FORAGE_NOEAT;
if (zone->random.Roll(25)) {
foragedfood = database.GetZoneForage(m_pp.zone_id, skill_level);
}
//not an else in case theres no DB food
if(foragedfood == 0) {
uint8 index = 0;
index = zone->random.Int(0, MAX_COMMON_FOOD_IDS-1);
foragedfood = common_food_ids[index];
}
const Item_Struct* food_item = database.GetItem(foragedfood);
if(!food_item) {
LogFile->write(EQEMuLog::Error, "nullptr returned from database.GetItem in ClientForageItem");
return;
}
if(foragedfood == 13106)
stringid = FORAGE_GRUBS;
else
switch(food_item->ItemType) {
case ItemTypeFood:
stringid = FORAGE_FOOD;
break;
case ItemTypeDrink:
if(strstr(food_item->Name, "ater"))
stringid = FORAGE_WATER;
else
stringid = FORAGE_DRINK;
break;
default:
break;
}
Message_StringID(MT_Skills, stringid);
ItemInst* inst = database.CreateItem(food_item, 1);
if(inst != nullptr) {
// check to make sure it isn't a foraged lore item
if(CheckLoreConflict(inst->GetItem()))
{
Message_StringID(0, DUP_LORE);
safe_delete(inst);
}
else {
PushItemOnCursor(*inst);
SendItemPacket(MainCursor, inst, ItemPacketSummonItem);
if(RuleB(TaskSystem, EnableTaskSystem))
UpdateTasksForItem(ActivityForage, foragedfood);
safe_delete(inst);
inst = m_inv.GetItem(MainCursor);
}
if(inst) {
std::vector<EQEmu::Any> args;
args.push_back(inst);
parse->EventPlayer(EVENT_FORAGE_SUCCESS, this, "", inst->GetID(), &args);
}
}
int ChanceSecondForage = aabonuses.ForageAdditionalItems + itembonuses.ForageAdditionalItems + spellbonuses.ForageAdditionalItems;
if(!guarantee && zone->random.Roll(ChanceSecondForage)) {
Message_StringID(MT_Skills, FORAGE_MASTERY);
ForageItem(true);
}
} else {
Message_StringID(MT_Skills, FORAGE_FAILED);
parse->EventPlayer(EVENT_FORAGE_FAILURE, this, "", 0);
}
CheckIncreaseSkill(SkillForage, nullptr, 5);
}
示例15: ExportEventVariables
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;
}
//.........这里部分代码省略.........