aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Handlers/ItemHandler.cpp
diff options
context:
space:
mode:
authorNay <dnpd.dd@gmail.com>2012-08-14 18:11:06 +0100
committerNay <dnpd.dd@gmail.com>2012-08-14 18:11:06 +0100
commitc0adf370e5ac3166bb74abb6d824556fbae54f6f (patch)
tree2b2b5aacb2e539acbbf58e92964fd6edc6529a88 /src/server/game/Handlers/ItemHandler.cpp
parente761458b249b8f2a128867ea0bd7adf5eaec4769 (diff)
Core/Vendors: Add currencies to vendors
npc_vendor table gets a new field, type (1 is item, 2 is currency) for type 1 fields still mean the same, for type 2 maxcount is buycount (without any "precision") changed structure of SMSG_UPDATE_CURRENCY(_WEEK_LIMIT) but not enabled, wrong values are being wrongly calculated
Diffstat (limited to 'src/server/game/Handlers/ItemHandler.cpp')
-rw-r--r--src/server/game/Handlers/ItemHandler.cpp125
1 files changed, 83 insertions, 42 deletions
diff --git a/src/server/game/Handlers/ItemHandler.cpp b/src/server/game/Handlers/ItemHandler.cpp
index 765adbda101..640d6996bdf 100644
--- a/src/server/game/Handlers/ItemHandler.cpp
+++ b/src/server/game/Handlers/ItemHandler.cpp
@@ -673,7 +673,7 @@ void WorldSession::HandleBuyItemOpcode(WorldPacket& recvData)
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_BUY_ITEM");
uint64 vendorguid, bagGuid;
uint32 item, slot, count;
- uint8 itemType; // 1 = item, 2 = currency (not implemented)
+ uint8 itemType; // 1 = item, 2 = currency
uint8 bagSlot;
recvData >> vendorguid >> itemType >> item >> slot >> count >> bagGuid >> bagSlot;
@@ -684,13 +684,20 @@ void WorldSession::HandleBuyItemOpcode(WorldPacket& recvData)
else
return; // cheating
- Item* bagItem = _player->GetItemByGuid(bagGuid);
+ if (itemType == ITEM_VENDOR_TYPE_ITEM)
+ {
+ Item* bagItem = _player->GetItemByGuid(bagGuid);
- uint8 bag = NULL_BAG;
- if (bagItem && bagItem->IsBag())
- bag = bagItem->GetSlot();
+ uint8 bag = NULL_BAG;
+ if (bagItem && bagItem->IsBag())
+ bag = bagItem->GetSlot();
- GetPlayer()->BuyItemFromVendorSlot(vendorguid, slot, item, count, bag, bagSlot);
+ GetPlayer()->BuyItemFromVendorSlot(vendorguid, slot, item, count, bag, bagSlot);
+ }
+ else if (itemType == ITEM_VENDOR_TYPE_CURRENCY)
+ GetPlayer()->BuyCurrencyFromVendorSlot(vendorguid, slot, item, count);
+ else
+ sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: received wrong itemType (%u) in HandleBuyItemOpcode", itemType);
}
void WorldSession::HandleListInventoryOpcode(WorldPacket & recvData)
@@ -744,52 +751,86 @@ void WorldSession::SendListInventory(uint64 vendorGuid)
VendorItem const* vendorItem = vendorItems->GetItem(slot);
if (!vendorItem) continue;
- ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(vendorItem->item);
- if (!itemTemplate) continue;
-
- if (!_player->isGameMaster()) // ignore conditions if GM on
+ if (vendorItem->Type == ITEM_VENDOR_TYPE_ITEM)
{
- // Respect allowed class
- if (!(itemTemplate->AllowableClass & _player->getClassMask()))
- continue;
+ ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(vendorItem->item);
+ if (!itemTemplate) continue;
+
+ if (!_player->isGameMaster()) // ignore conditions if GM on
+ {
+ // Respect allowed class
+ if (!(itemTemplate->AllowableClass & _player->getClassMask()))
+ continue;
- // Do not sell BOP items
- if (itemTemplate->Bonding == BIND_WHEN_PICKED_UP)
- continue;
+ // Do not sell BOP items
+ if (itemTemplate->Bonding == BIND_WHEN_PICKED_UP)
+ continue;
- // Only display items in vendor lists for the team the player is on
- if ((itemTemplate->Flags2 & ITEM_FLAGS_EXTRA_HORDE_ONLY && _player->GetTeam() == ALLIANCE) ||
- (itemTemplate->Flags2 & ITEM_FLAGS_EXTRA_ALLIANCE_ONLY && _player->GetTeam() == HORDE))
- continue;
+ // Only display items in vendor lists for the team the player is on
+ if ((itemTemplate->Flags2 & ITEM_FLAGS_EXTRA_HORDE_ONLY && _player->GetTeam() == ALLIANCE) ||
+ (itemTemplate->Flags2 & ITEM_FLAGS_EXTRA_ALLIANCE_ONLY && _player->GetTeam() == HORDE))
+ continue;
+
+ // Items sold out are not displayed in list
+ uint32 leftInStock = !vendorItem->maxcount ? 0xFFFFFFFF : vendor->GetVendorItemCurrentCount(vendorItem);
+ if (leftInStock == 0)
+ continue;
+ }
- // Items sold out are not displayed in list
+ int32 price = vendorItem->IsGoldRequired(itemTemplate) ? uint32(floor(itemTemplate->BuyPrice * discountMod)) : 0;
uint32 leftInStock = !vendorItem->maxcount ? 0xFFFFFFFF : vendor->GetVendorItemCurrentCount(vendorItem);
- if (leftInStock == 0)
- continue;
+
+ itemsData << uint32(count++ + 1); // client expects counting to start at 1
+ itemsData << uint32(itemTemplate->MaxDurability);
+
+ if (vendorItem->ExtendedCost != 0)
+ {
+ enablers.push_back(0);
+ itemsData << uint32(vendorItem->ExtendedCost);
+ }
+ else
+ enablers.push_back(1);
+ enablers.push_back(1); // unk bit
+
+ itemsData << uint32(vendorItem->item);
+ itemsData << uint32(vendorItem->Type); // 1 is items, 2 is currency
+ itemsData << uint32(price);
+ itemsData << uint32(itemTemplate->DisplayInfoID);
+ // if (!unk "enabler") data << uint32(something);
+ itemsData << int32(leftInStock);
+ itemsData << uint32(itemTemplate->BuyCount);
}
+ else if (vendorItem->Type == ITEM_VENDOR_TYPE_CURRENCY)
+ {
+ CurrencyTypesEntry const* currencyTemplate = sCurrencyTypesStore.LookupEntry(vendorItem->item);
- int32 price = vendorItem->IsGoldRequired(itemTemplate) ? uint32(floor(itemTemplate->BuyPrice * discountMod)) : 0;
- uint32 leftInStock = !vendorItem->maxcount ? 0xFFFFFFFF : vendor->GetVendorItemCurrentCount(vendorItem);
+ if (!currencyTemplate) continue;
- itemsData << uint32(count++ + 1); // client expects counting to start at 1
- itemsData << uint32(itemTemplate->MaxDurability);
+ if (vendorItem->ExtendedCost == 0) continue; // there's no price defined for currencies, only extendedcost is used
- if (vendorItem->ExtendedCost != 0)
- {
- enablers.push_back(0);
- itemsData << uint32(vendorItem->ExtendedCost);
+ uint32 precision = (currencyTemplate->Flags & CURRENCY_FLAG_HIGH_PRECISION) ? 100 : 1;
+
+ itemsData << uint32(count++ + 1); // client expects counting to start at 1
+ itemsData << uint32(0); // max durability
+
+ if (vendorItem->ExtendedCost != 0)
+ {
+ enablers.push_back(0);
+ itemsData << uint32(vendorItem->ExtendedCost);
+ }
+ else
+ enablers.push_back(1);
+ enablers.push_back(1); // unk bit
+
+ itemsData << uint32(vendorItem->item);
+ itemsData << uint32(vendorItem->Type); // 1 is items, 2 is currency
+ itemsData << uint32(0); // price, only seen currency types that have Extended cost
+ itemsData << uint32(0); // displayId
+ // if (!unk "enabler") data << uint32(something);
+ itemsData << int32(-1);
+ itemsData << uint32(vendorItem->maxcount * precision);
}
- else
- enablers.push_back(1);
- enablers.push_back(1); // unk bit
-
- itemsData << uint32(vendorItem->item);
- itemsData << uint32(1); // 1 is items, 2 is currency (FIXME: currency isn't implemented)
- itemsData << uint32(price);
- itemsData << uint32(itemTemplate->DisplayInfoID);
- // if (!unk "enabler") data << uint32(something);
- itemsData << int32(leftInStock);
- itemsData << uint32(itemTemplate->BuyCount);
+ // else error
}
uint8* guidBytes = (uint8*)&vendorGuid;