Rest of the OpCodes , the structs, and the SQL..
Yes, code is a little sloppy, can be cleaned up a bit when databse stuff is implemented
Code:
case OP_ShopPlayerBuy:
{
cout << name << " is attempting to purchase an item.. " << endl;
Merchant_Purchase_Struct* mp=(Merchant_Purchase_Struct*)app->pBuffer;
// this item number needs to bounce back to the merchant table, since the client
// only tells us what slot the client is wanting to purchase.
// slot value is in mp->itemslot.
uint16 item_nr = 16592; // hardcoded to always sell you grapes :)
Item_Struct* item = database.GetItem(item_nr);
// Give Item
APPLAYER* outapp = new APPLAYER;
outapp->opcode = OP_ShopGiveItem;
outapp->size = sizeof(Item_Struct);
outapp->pBuffer = new uchar[outapp->size];
item->common.number = mp->merchant.quantity; // number purchased from merchant.
// copied this code from loot code - but doesn't seem to work right.
item->equipSlot = 0xFF;
for (int i=22; i<31; i++)
{
if (pp.inventory[i] == 0xFFFF || pp.inventory[i] == item->item_nr)
{
item->equipSlot = i;
break;
}
}
if (item->equipSlot == 0xFF)
{
Message(14,"There is no more room in your inventory. Item cannot be purchased.");
delete outapp;
}
else
{
//item->equipSlot = 0x1d;
memcpy(outapp->pBuffer, item, sizeof(Item_Struct));
QueuePacket(outapp);
delete outapp;
// Take Players Money
outapp = new APPLAYER;
outapp->opcode = OP_ShopTakeMoney;
outapp->size = sizeof(Merchant_Purchase_Struct);
outapp->pBuffer = new uchar[outapp->size];
Merchant_Purchase_Struct* mps = (Merchant_Purchase_Struct*)outapp->pBuffer;
mps->merchant.mcs_unknown001 = mp->merchant.mcs_unknown001;
mps->merchant.merchantid = mp->merchant.merchantid;
mps->merchant.itemslot = mp->merchant.itemslot;
mps->merchant.mcs_unknown002[0] = 0x00;
mps->merchant.mcs_unknown002[1] = 0x00;
mps->merchant.mcs_unknown002[2] = 0x00;
mps->merchant.quantity = mp->merchant.quantity;
mps->merchant.mcs_unknown003[0] = 0x00;
mps->merchant.mcs_unknown003[1] = 0x00;
mps->merchant.mcs_unknown003[2] = 0x00;
mps->mps_unknown001 = item->cost; // amount in copper.
cout << "taking " << item->cost << " copper from " << name << "." << endl;
DumpPacketHex(outapp);
QueuePacket(outapp);
delete outapp;
}
break;
}
case OP_ShopPlayerSell:
{
cout << name << " is trying to sell an item." << endl;
DumpPacketHex(app);
Merchant_Purchase_Struct* mp=(Merchant_Purchase_Struct*)app->pBuffer;
APPLAYER* outapp = new APPLAYER;
outapp->opcode = OP_ShopPlayerSell;
outapp->size = sizeof(Merchant_Purchase_Struct);
outapp->pBuffer = new uchar[outapp->size];
Merchant_Purchase_Struct* mps = (Merchant_Purchase_Struct*)outapp->pBuffer;
mps->merchant.mcs_unknown001 = mp->merchant.mcs_unknown001;
mps->merchant.merchantid = mp->merchant.merchantid;
mps->merchant.itemslot = mp->merchant.itemslot;
mps->merchant.mcs_unknown002[0] = 0x00;
mps->merchant.mcs_unknown002[1] = 0x46;
mps->merchant.mcs_unknown002[2] = 0x00;
mps->merchant.quantity = 0x00;
mps->merchant.mcs_unknown003[0] = 0x00;
mps->merchant.mcs_unknown003[1] = 0x00;
mps->merchant.mcs_unknown003[2] = 0x00;
mps->mps_unknown001 = 0x00;
cout << "response from sell action.." << endl;
DumpPacketHex(outapp);
QueuePacket(outapp);
delete outapp;
break;
}
case OP_ShopEnd:
{
cout << name << " is ending merchant interaction." << endl;
APPLAYER* outapp = new APPLAYER;
outapp->opcode = OP_ShopEndConfirm;
outapp->pBuffer = new uchar[2];
outapp->size = 2;
outapp->pBuffer[0] = 0x0a;
outapp->pBuffer[1] = 0x66;
QueuePacket(outapp);
delete outapp;
break;
}
code for eq_packet_structs.h
Code:
// Darvik: shopkeeper structs
struct Merchant_Click_Struct {
uint32 mcs_unknown001; // unknown - first byte has different value by zone??
uint32 merchantid; // unique identifier for merchantID
int8 itemslot; // always 0x40 FROM client, 0x01 TO client. itemslot when used in purchase.
int8 mcs_unknown002[3]; // always 0x0b, 0x7c, 0x00 ??
int8 quantity; // Qty - when used in Merchant_Purchase_Struct
int8 mcs_unknown003[3]; // always 0xa5, 0x3f ??
};
struct Merchant_Purchase_Struct {
Merchant_Click_Struct merchant;
int32 mps_unknown001; // Cost in copper
};
struct Item_Shop_Struct {
uint32 merchantid;
int8 itemtype;
Item_Struct item;
int32 iss_unknown001;
};
SQL stuff:
Code:
#
# Table structure for table 'shopkeepers'
#
CREATE TABLE shopkeepers (
id int(11) NOT NULL,
npc_id int(11) NOT NULL,
items_table int(11) NOT NULL,
price_markup tinyint(2) unsigned NOT NULL default '0',
PRIMARY KEY (id, npc_id)
) TYPE=MyISAM;
#
# Table structure for table 'shopkeeper_items'
#
CREATE TABLE shopkeeper_items (
id int(11) NOT NULL,
seq tinyint(2) unsigned NOT NULL,
item_id int(11) NOT NULL,
qty int(11) NOT NULL,
PRIMARY KEY (id,seq)
) TYPE=MyISAM;
#
# Dumping data for table 'shopkeepers'
#
INSERT INTO shopkeepers VALUES (1,2,1,0);
#
# Dumping data for table 'shopkeeper_items'
#
INSERT INTO shopkeeper_items VALUES (1,0,1001,99);
INSERT INTO shopkeeper_items VALUES (1,1,1002,99);
INSERT INTO shopkeeper_items VALUES (1,2,1003,99);
INSERT INTO shopkeeper_items VALUES (1,3,1004,99);
INSERT INTO shopkeeper_items VALUES (1,4,1005,99);
INSERT INTO shopkeeper_items VALUES (1,5,1006,99);
INSERT INTO shopkeeper_items VALUES (1,6,1007,99);
INSERT INTO shopkeeper_items VALUES (1,7,1008,99);
INSERT INTO shopkeeper_items VALUES (1,8,1009,99);
INSERT INTO shopkeeper_items VALUES (1,9,1010,99);
INSERT INTO shopkeeper_items VALUES (1,10,1011,99);
INSERT INTO shopkeeper_items VALUES (1,11,1012,99);