Thread: Merchant fix
View Single Post
  #1  
Old 03-13-2002, 12:33 AM
Merkur
Sarnak
 
Join Date: Mar 2002
Posts: 53
Default Merchant fix

Code:
// Edited Merkur  03/12
case OP_ShopPlayerBuy: {								
	cout << name << " is attempting to purchase an item..  " << endl;
	Merchant_Purchase_Struct* mp=(Merchant_Purchase_Struct*)app->pBuffer;
	int merchantid;
	Mob* tmp = entity_list.GetMob(mp->npcid);
	if (tmp != 0)
		merchantid=tmp->CastToNPC()->MerchantType;
	else 
		break;
	uint16 item_nr = database.GetMerchantData(merchantid, mp->itemslot+1);
	if (item_nr == 0)
		break;
	Item_Struct* item = database.GetItem(item_nr);				
	APPLAYER* outapp = new APPLAYER(OP_ShopPlayerBuy, sizeof(Merchant_Purchase_Struct));
	Merchant_Purchase_Struct* mpo=(Merchant_Purchase_Struct*)outapp->pBuffer;							
	mpo->quantity = mp->quantity;
	mpo->playerid = mp->playerid;
	mpo->npcid = mp->npcid;
	mpo->itemslot = mp->itemslot;													
	mpo->IsSold = 0x00;
	mpo->unknown001 = 0x00;
	mpo->unknown002 = 0x00;
	mpo->unknown003 = 0x00;
	mpo->unknown004 = 0x00; 
	mpo->unknown005 = 0x00;
	// well i don't know how to calculate merchant prices exact, but *12 seems pretty near so it will do for now -Merkur
	mpo->itemcost = item->cost*mp->quantity*12;					
	cout << "taking " << item->cost*mp->quantity*12 << " copper from " << name << "." << endl;
	//	DumpPacketHex(app);
	QueuePacket(outapp);
	delete outapp;						
	PutItemInInventory(FindFreeInventorySlot(0, (item->type==0x01), false), item, mp->quantity);
	Save();
	break;
					   }
case OP_ShopPlayerSell: {
	cout << name << " is trying to sell an item." << endl;
	Merchant_Purchase_Struct* mp=(Merchant_Purchase_Struct*)app->pBuffer;														
	pp.inventory[mp->itemslot] = 0xFFFF;
	cout << " Inv Slot: " << int(mp->itemslot) << endl;
	QueuePacket(app); // Just send it back to accept the deal
	Save();
	cout << "response from sell action.." << endl;
	break;
						}
struct:
Code:
struct Merchant_Purchase_Struct {
/*000*/	int16	npcid;			// Merchant NPC's entity id
/*004*/	int16	playerid;		// Player's entity id
/*008*/	int8	itemslot;
		int8	IsSold;		// Already sold
/*009*/	int8	unknown001;	// always 0x0b, 0x7c, 0x00 ??
/*009*/	int8	unknown002;
/*013*/	int8	quantity;		// Qty - when used in Merchant_Purchase_Struct
		int8	unknown003;
		int8	unknown004;
		int8	unknown005;
		sint32  itemcost;
};
Reply With Quote