Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Bug Reports

Development::Bug Reports Post detailed bug reports and what you would like to see next in the emu here.

Reply
 
Thread Tools Display Modes
  #1  
Old 12-27-2006, 10:47 AM
Aerewen
Hill Giant
 
Join Date: Dec 2006
Posts: 110
Default

yes i have just tested it myself and exactly what i said is what is happening.

When the world boots up it clears the entire merchantlist_temp table. Then loads the merchantlists from the merchantlist table and sets them into an array in the zone.exe file.

When items are sold to the vendor they are inserted into the merchantlist_temp table, but not into the array.

I posted the sections of code where the problem comes from, now if someone else could do us all a favor and fix it... lol cuz i've about exhausted my knowledge of c++ in just finding the issue :p
Reply With Quote
  #2  
Old 12-28-2006, 08:30 PM
Aerewen
Hill Giant
 
Join Date: Dec 2006
Posts: 110
Default

After looking at this code i think we have a slightly larger problem on our hands...

The merchantlist information is being stored in an array... which means that presently, whenever a player accesses a merchant, that data comes out of the array and has nothing to do with the database. So we actually don't need to change anything with the way merchants handle items sold to them, instead what needs to happen is that the zone should only load the items in the merchantlist table at startup since they don't change. Then we need to modify the code for the function when a player accesses that merchant, and have it load the values from the merchantlist_temp table into the file...

where this causes a problem is what happens when 2 players access the same merchant at the same time. if a merchant had 1 discordant scoriae on it... and 2 players accessed the merchant at the same time, they could both buy that item since the temp list would only be loaded at the time of browsing... thus creating a method of item duplication.
Reply With Quote
  #3  
Old 12-29-2006, 02:03 AM
John Adams
Demi-God
 
Join Date: Jul 2006
Posts: 1,552
Default

I'm back at work! /argue on! j/k

If I can get on Live tonight, I will sell something to a vendor, and have 2 PCs open the same vendor and see what happens if they both try and buy the item. Something in the back of my mind tells me the merchant inventory list is dynamically updated live... but I could be dreaming.
Reply With Quote
  #4  
Old 12-29-2006, 09:57 AM
Aerewen
Hill Giant
 
Join Date: Dec 2006
Posts: 110
Default

good luck with that lol

remember... merchants won't resell items that you sell to them because of this bug :p

im just saying the code that needs changed is the code that actually executes when a player right clicks a merchant to browse, not the code i posted earlier in this thread
Reply With Quote
  #5  
Old 12-29-2006, 06:52 PM
John Adams
Demi-God
 
Join Date: Jul 2006
Posts: 1,552
Default

This all works on EQLive, right? Selling something, then buying it back?

Screw it. I'm testing this.

Ok, to end this senseless speculating... I am on Live right now, 2 chars, same merchant. I sold a Meat to the merchant, and without doing anything, it appeared magically on the second toons open merchant window - no closing, no reopening. That's what I expected to see.

The guy who sold it can buy it back immediately. And, it vanishes from the second guys merchant window - dynamically, like I said. Furthermore, the second guy could buy it if he wanted, and it also vanishes from the first guys window immediately. So, no risk of dupe items - on LIVE.

Now, Emu...
This does NOT work this way. If player 1 sells something, it does not appear on the merchant immediately. Hmm. Actually, ever. I left the zone, restarted it, the item is still in the temp table, but the merchant does not show the Meat - on EMU.

So, Aerewen, you are vindicated. Now, fix it. ~grin~

Last edited by John Adams; 12-30-2006 at 03:19 AM..
Reply With Quote
  #6  
Old 12-29-2006, 08:32 PM
Aerewen
Hill Giant
 
Join Date: Dec 2006
Posts: 110
Default

lol wish i knew how :p

even if i did find a way to fix it... i dont have a clue how to make those little add/subtract files that i see people posting... im not a cbase programmer... i do php/mysql/perl etc all the web based crap but never learned any actual programming :(
Reply With Quote
  #7  
Old 12-29-2006, 09:35 PM
Aerewen
Hill Giant
 
Join Date: Dec 2006
Posts: 110
Default

GRRRRRRR i wish i learned c++ lol

i've been staring at the code now for like well... since i made the last post on here so an hour?

as far as i can tell it should work

from client_process.cpp... looks like it is pulling the items from the tmpmerchanttable[] array properly and sending them to the client when the merchant is browsed...
Code:
void Client::BulkSendMerchantInventory(int merchant_id, int16 npcid) {
	const Item_Struct* handyitem = NULL;
	int32 numItemSlots=80;  //The max number of items passed in the transaction.
	const Item_Struct *item;
	std::list<MerchantList> merlist = zone->merchanttable[merchant_id];
	std::list<MerchantList>::const_iterator itr;
	if(merlist.size()==0){ //Attempt to load the data, it might have been missed if someone spawned the merchant after the zone was loaded
		zone->LoadNewMerchantData(merchant_id);
		merlist = zone->merchanttable[merchant_id];
		if(merlist.size()==0)
			return;
	}
	std::list<TempMerchantList> tmp_merlist = zone->tmpmerchanttable[npcid];
	std::list<TempMerchantList>::iterator tmp_itr;

	int32 i=1;
	int8 handychance = 0;
	for(itr = merlist.begin();itr != merlist.end() && i<numItemSlots;itr++){
		MerchantList ml = *itr;
		handychance = MakeRandomInt(0, merlist.size() + tmp_merlist.size() - 1 );
		
		item = database.GetItem(ml.item);
		if(item) {
			if(handychance==0)
				handyitem=item;
			else
				handychance--;
			int charges=1;
			if(item->ItemClass==ItemClassCommon)
				charges=item->MaxCharges;
			ItemInst* inst = database.CreateItem(item, charges);
			if (inst) {
				inst->SetPrice(item->Price*127/100);
				inst->SetMerchantSlot(ml.slot);
				inst->SetMerchantCount(-1);		//unlimited
				if(charges > 0)
					inst->SetCharges(charges);
				else
					inst->SetCharges(1);
				SendItemPacket(ml.slot-1, inst, ItemPacketMerchant);
				safe_delete(inst);
			}
		}
		i++;
	}
	std::list<TempMerchantList> origtmp_merlist = zone->tmpmerchanttable[npcid];
	tmp_merlist.clear();
	for(tmp_itr = origtmp_merlist.begin();tmp_itr != origtmp_merlist.end() && i<numItemSlots;tmp_itr++){
		TempMerchantList ml = *tmp_itr;
		item=database.GetItem(ml.item);
		ml.slot=i;
		if (item) {
			if(handychance==0)
				handyitem=item;
			else
				handychance--;
			int charges=1;
			if(item->ItemClass==ItemClassCommon && (sint16)ml.charges <= item->MaxCharges)
				charges=ml.charges;
			else
				charges = item->MaxCharges;
			ItemInst* inst = database.CreateItem(item, charges);
			if (inst) {
				inst->SetPrice(item->Price*127/100);
				inst->SetMerchantSlot(ml.slot);
				inst->SetMerchantCount(1);
				if(charges > 0)
					inst->SetCharges(charges);
				else
					inst->SetCharges(1);
				SendItemPacket(ml.slot-1, inst, ItemPacketMerchant);
				safe_delete(inst);
			}
		}
		tmp_merlist.push_back(ml);
		i++;
	}
	//this resets the slot
	zone->tmpmerchanttable[npcid] = tmp_merlist;
	Mob* merch = entity_list.GetMobByNpcTypeID(npcid);
	if(merch != NULL && handyitem){
		char handy_id[8]={0};
		int greeting=rand()%5;
		int greet_id=0;
		switch(greeting){
			case 1:
				greet_id=MERCHANT_GREETING;
				break;
			case 2:
				greet_id=MERCHANT_HANDY_ITEM1;
				break;
			case 3:
				greet_id=MERCHANT_HANDY_ITEM2;
				break;
			case 4:
				greet_id=MERCHANT_HANDY_ITEM3;
				break;
			default:
				greet_id=MERCHANT_HANDY_ITEM4;
        }
		sprintf(handy_id,"%i",greet_id);
		char merchantname[64]={0};
		strncpy(merchantname,merch->GetName(),strlen(merch->GetName())-2);
		if(greet_id!=MERCHANT_GREETING){
			Message_StringID(10,GENERIC_STRINGID_SAY,merchantname,handy_id,this->GetName(),handyitem->Name);
		
        }
        else
			Message_StringID(10,GENERIC_STRINGID_SAY,merchantname,handy_id,this->GetName());
		
		merch->CastToNPC()->FaceTarget(this->CastToMob());
    }
		
//		safe_delete_array(cpi);
}
and the code for when a player sells an item to the npc... is below... and it also looks as if it is adding the item to both the database and the tmpmerchanttable[] array properly...

from zone.cpp

Code:
int Zone::SaveTempItem(int32 merchantid, int32 npcid, int32 item, sint32 charges, bool sold){
	int freeslot = 0;
	
	std::list<MerchantList> merlist = merchanttable[merchantid];
	std::list<MerchantList>::const_iterator itr;
	int32 i = 1;
	for(itr = merlist.begin();itr != merlist.end();itr++){
		MerchantList ml = *itr;
		if(ml.item == item)
			return 0;
		else
			i++;
	}
	std::list<TempMerchantList> tmp_merlist = tmpmerchanttable[npcid];
	std::list<TempMerchantList>::const_iterator tmp_itr;
	bool update_charges = false;
	TempMerchantList ml;
	while(freeslot == 0 && !update_charges){
		freeslot = i;
		for(tmp_itr = tmp_merlist.begin();tmp_itr != tmp_merlist.end();tmp_itr++){
			ml = *tmp_itr;
			if(ml.item == item){
				update_charges = true;
				freeslot = 0;
				break;
			}
			if(ml.origslot==i)
				freeslot=0;
		}
		i++;
	}
	if(update_charges){
		tmp_merlist.clear();
		std::list<TempMerchantList> oldtmp_merlist = tmpmerchanttable[npcid];
		for(tmp_itr = oldtmp_merlist.begin();tmp_itr != oldtmp_merlist.end();tmp_itr++){
			TempMerchantList ml2 = *tmp_itr;
			if(ml2.item != item)
				tmp_merlist.push_back(ml2);
		}
		if(sold)
			ml.charges = ml.charges + charges;
		else
			ml.charges = charges;
		if(!ml.origslot)
			ml.origslot = ml.slot;
		if(charges>0){
			database.SaveMerchantTemp(npcid, ml.origslot, item, ml.charges);
			tmp_merlist.push_back(ml);
		}
		else{
			database.DeleteMerchantTemp(npcid,ml.origslot);
		}
		tmpmerchanttable[npcid] = tmp_merlist;
		
	}
	if(freeslot){
		if(charges<0) //sanity check only, shouldnt happen
			charges = 255;
		database.SaveMerchantTemp(npcid, freeslot, item, charges);
		tmp_merlist = tmpmerchanttable[npcid];
		TempMerchantList ml2;
		ml2.charges = charges;
		ml2.item = item;
		ml2.npcid = npcid;
		ml2.slot = freeslot;
		ml2.origslot = ml2.slot;
		tmp_merlist.push_back(ml2);
		tmpmerchanttable[npcid] = tmp_merlist;
	}
	return freeslot;
}
so as far as i can tell it should be displaying the items that were sold to the merchant unless im missing something somewhere...
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 01:43 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3