Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Server Code Submissions

Reply
 
Thread Tools Display Modes
  #1  
Old 03-04-2007, 04:52 AM
Darkonig
Hill Giant
 
Join Date: Dec 2006
Posts: 102
Default Tradeskill code fix

The current tradeskills code is not working like live code. The code is determining a tradeskill for the container type and as a result allows combines to be done in the wrong containers (ie, pottery has 2 combiners: Pottery Wheel (21) and Kiln (22). These are both used for pottery combines so current code lets either container do all pottery combines.) On live, some recipes require one and some the other.

Also on live, there are recipes that are done in a container that have nothing to do with the tradeskill that the container is normally used for. For example, the Toolbox is normally used by gnomes for Tinkering but can also be used by anybody to recharge tinkered items such as Anizok's Gauze Press. The current code prohibits other characters from doing this combine because of needing the Toolbox. With the new code, the recipes for recharging could be changed to tradeskill 75 and no fail and still use the toolbox.

The new code I am proposing does away with declaring combiners to only do certain tradeskills and eliminates being able to do all tradeskill combines in any container of that tradeskill type. (Example research or cultural recipes).

The following 5 posts show the changes made to the server code to support live like tradeskills. This code is working on my server.

Last edited by Darkonig; 03-04-2007 at 01:11 PM.. Reason: needed more room to fit the code
Reply With Quote
  #2  
Old 03-04-2007, 05:00 AM
Darkonig
Hill Giant
 
Join Date: Dec 2006
Posts: 102
Default

changes made for tradeskills

files changed:
common/item.h
zone/zonedb.h
zone/client.h
zone/client_packet.cpp
zone/tradeskills.cpp

common/item.h
Code:
<!	SLOT_TRADESKILL	= 1000,
!>	SLOT_WORLDCONTAINER = 1000,
This change is to make the purpose of the slot more clear. Although the object in the slot can be used for tradeskills, it is a worldcontainer object.

zone/zonedb.h
Code:
struct DBTradeskillRecipe_Struct {
!>	SkillType tradeskill;
	sint16 skill_needed;
	uint16 trivial;
	bool nofail;
	bool replace_container;
	vector< pair<uint32,uint8> > onsuccess;
	vector< pair<uint32,uint8> > onfail;
};
added SkillType tradeskill; to the structure because the tradeskill should actually be determined by the recipe, not by the type of container you are trying to perform the recipe in.
Code:
<!	bool	GetTradeRecipe(const ItemInst* container, uint8 c_type, uint8 tradeskill, DBTradeskillRecipe_Struct *spec);
!>	bool	GetTradeRecipe(const ItemInst* container, uint8 c_type, uint32 some_id, DBTradeskillRecipe_Struct *spec);
<!	bool	GetTradeRecipe(uint32 recipe_id, uint8 c_type, uint8 tradeskill, DBTradeskillRecipe_Struct *spec);
!>	bool	GetTradeRecipe(uint32 recipe_id, uint8 c_type, uint32 some_id, DBTradeskillRecipe_Struct *spec);
Changed signitures. These should be receiving the item qualifier instead of the tradeskill.

zone/client.h
Code:
<!	bool TradeskillExecute(DBTradeskillRecipe_Struct *spec, SkillType tradeskill);
!>	bool TradeskillExecute(DBTradeskillRecipe_Struct *spec);
Changed signitures. Since SkillType tradeskill is now included in DBTradeskillRecipe_Struct it does not need to be passed separately.

zone/client_packet.cpp
Code:
void Client::Handle_OP_RecipesFavorite(const EQApplicationPacket *app)
{
	if (app->size != sizeof(TradeskillFavorites_Struct)) {
		LogFile->write(EQEMuLog::Error, "Invalid size for TradeskillFavorites_Struct: Expected: %i, Got: %i",
			sizeof(TradeskillFavorites_Struct), app->size);
		return;
	}
	
	TradeskillFavorites_Struct* tsf = (TradeskillFavorites_Struct*)app->pBuffer;
	
<!	uint32 tskill = Object::TypeToSkill(tsf->object_type);
<!	if(tskill == 0) {
<!		LogFile->write(EQEMuLog::Error, "Unknown container type for OP_RecipesFavorite: %d\n", tsf->object_type);
<!		return;
<!	}

!>	LogFile->write(EQEMuLog::Debug, "Requested Favorites for: %d - %d\n", tsf->object_type, tsf->some_id);

!>	// make where clause segment for container(s)
!>	char containers[30];
!>	if (tsf->some_id == 0) {
!>		// world combiner so no item number
!>		snprintf(containers,29, "= %u", tsf->object_type);
!>	} else {
!>		// container in inventory
!>		snprintf(containers,29, "in (%u,%u)", tsf->object_type, tsf->some_id);
!>	}

char *query = 0;
	char buf[1100];	//gotta be big enough for 100 IDs
	
	bool first = true;
	uint8 r;
	char *pos = buf;
	
	//Assumes item IDs are <10 characters long
	for(r = 0; r < 100; r++) {
		if(tsf->favorite_recipes[r] == 0)
			break;	//assume the first 0 is the end...
		
		if(first) {
			pos += snprintf(pos, 10, "%u", tsf->favorite_recipes[r]);
			first = false;
		} else {
			pos += snprintf(pos, 10, ",%u", tsf->favorite_recipes[r]);
		}
	}
	
	if(first)	//no favorites....
		return;
	
	//To be a good kid, I should move this SQL somewhere else...
	//but im lazy right now, so it stays here
	uint32 qlen = 0;
	qlen = MakeAnyLenString(&query, "SELECT tr.id,tr.name,tr.trivial,SUM(tre.componentcount) "
		" FROM tradeskill_recipe AS tr "
		" LEFT JOIN tradeskill_recipe_entries AS tre ON tr.id=tre.recipe_id "
<!		" WHERE tr.id IN (%s) AND tradeskill=%lu "
<!		" GROUP BY tr.id LIMIT 100 ", buf, tskill);
!>		" WHERE tr.id IN (%s) "
!>		" GROUP BY tr.id "
!>		" HAVING sum(if(tre.item_id %s AND tre.iscontainer > 0,1,0)) > 0 "
!>		" LIMIT 100 ", buf, containers);
	
	TradeskillSearchResults(query, qlen, tsf->object_type, tsf->some_id);
	
	safe_delete_array(query);
	return;
}
Removed type to skill lookup because results should be determined by container, not by what tradeskill container is normally used in.
Added code to use containers in the lookup. If either the type or some_id is listed as a container in the recipe we want it.
Code:
void Client::Handle_OP_RecipesSearch(const EQApplicationPacket *app)
{
	if (app->size != sizeof(RecipesSearch_Struct)) {
		LogFile->write(EQEMuLog::Error, "Invalid size for RecipesSearch_Struct: Expected: %i, Got: %i",
			sizeof(RecipesSearch_Struct), app->size);
		return;
	}
	
	RecipesSearch_Struct* rss = (RecipesSearch_Struct*)app->pBuffer;
	rss->query[55] = '\0';	//just to be sure.

<!	uint32 tskill = Object::TypeToSkill(rss->object_type);
<!	if(tskill == 0) {
<!		LogFile->write(EQEMuLog::Error, "Unknown container type for OP_RecipesSearch: %d\n", rss->object_type);
<!		return;
<!	}

!>	// make where clause segment for container(s)
!>	char containers[30];
!>	if (rss->some_id == 0) {
!>		// world combiner so no item number
!>		snprintf(containers,29, "= %u", rss->object_type);
!>	} else {
!>		// container in inventory
!>		snprintf(containers,29, "in (%u,%u)", rss->object_type, rss->some_id);
!>	}

	char *query = 0;
	char searchclause[140];	//2X rss->query + SQL crap
	
	//omit the rlike clause if query is empty
	if(rss->query[0] != 0) {
		char buf[120];	//larger than 2X rss->query
		database.DoEscapeString(buf, rss->query, strlen(rss->query));
		
		snprintf(searchclause, 139, "name rlike '%s' AND", buf);
	} else {
		searchclause[0] = '\0';
	}
	uint32 qlen = 0;
	
	//arbitrary limit of 200 recipes, makes sense to me.
	qlen = MakeAnyLenString(&query, "SELECT tr.id,tr.name,tr.trivial,SUM(tre.componentcount) "
		" FROM tradeskill_recipe AS tr "
		" LEFT JOIN tradeskill_recipe_entries AS tre ON tr.id=tre.recipe_id "
<!		" WHERE %s tr.trivial >= %u AND tr.trivial <= %u AND tradeskill=%lu "
!>		" WHERE %s tr.trivial >= %u AND tr.trivial <= %u "
<!		" GROUP BY tr.id LIMIT 200 ", searchclause, rss->mintrivial, rss->maxtrivial, tskill);
!>		" GROUP BY tr.id "
!>		" HAVING sum(if(tre.item_id %s AND tre.iscontainer > 0,1,0)) > 0 "
!>		" LIMIT 200 "
!>		, searchclause, rss->mintrivial, rss->maxtrivial, containers);
	
	TradeskillSearchResults(query, qlen, rss->object_type, rss->some_id);
	
	safe_delete_array(query);
	return;
}
Removed type to skill lookup because results should be determined by container, not by what tradeskill container is normally used in.
Added code to use containers in the lookup. If either the type or some_id is listed as a container in the recipe we want it.
Reply With Quote
  #3  
Old 03-04-2007, 05:03 AM
Darkonig
Hill Giant
 
Join Date: Dec 2006
Posts: 102
Default

zone/tradeskills.cpp

Code:
// Perform tradeskill combine
// complete tradeskill rewrite by father nitwit, 8/2004
void Object::HandleCombine(Client* user, const NewCombine_Struct* in_combine, Object *worldo)
{
	if (!user || !in_combine) {
		LogFile->write(EQEMuLog::Error, "Client or NewCombine_Struct not set in Object::HandleCombine");
		return;
	}
	
	Inventory& user_inv = user->GetInv();
	PlayerProfile_Struct& user_pp = user->GetPP();
	ItemInst* container = NULL;
	ItemInst* inst = NULL;
<!	int8 tstype = 0xE8;
!>	uint8 c_type = 0xE8;
<!	uint8 passtype = 0;
!>	uint32 some_id = 0;
	bool worldcontainer=false;
	
<!	if (in_combine->container_slot == SLOT_TRADESKILL) {
!>	if (in_combine->container_slot == SLOT_WORLDCONTAINER) {
		if(!worldo) {
			user->Message(13, "Error: Server is not aware of the tradeskill container you are attempting to use");
			return;
		}
		inst = worldo->m_inst;
!>		c_type = worldo->m_type;
		worldcontainer=true;
	}
	else {
		inst = user_inv.GetItem(in_combine->container_slot);
		if (inst) {
			const Item_Struct* item = inst->GetItem();
			if (item && inst->IsType(ItemClassContainer)) {
				c_type = item->BagType;
!>				some_id = item->ID;
			}
		}
	}
	
	if (!inst || !inst->IsType(ItemClassContainer)) {
		user->Message(13, "Error: Server does not recognize specified tradeskill container");
		return;
	}
	
	container = inst;
	
<!	// Convert container type to tradeskill type
<!	SkillType tradeskill = TradeskillUnknown;
<!	switch (tstype)
<!	{
<!	case 16:
<!		tradeskill = TAILORING;
<!		break;
<!	case 0xE8: //Generic World Container
<!		if(!worldcontainer)	//just to garuntee that worldo is valid
<!			return;
<!		passtype = worldo->m_type;
<!		
<!		if(worldo->m_type == OT_MEDICINEBAG) {
<!			if ((user_pp.class_ == SHAMAN) & (user_pp.level >= MIN_LEVEL_ALCHEMY))
<!				tradeskill = ALCHEMY;
<!			else if (user_pp.class_ != SHAMAN)
<!				user->Message(13, "This tradeskill can only be performed by a shaman.");
<!			else if (user_pp.level < MIN_LEVEL_ALCHEMY)
<!				user->Message(13, "You cannot perform alchemy until you reach level %i.", MIN_LEVEL_ALCHEMY);
<!			break;
<!		} else {
<!			tradeskill = TypeToSkill(worldo->m_type);
<!		}
<!		break;
<!	case 18:
<!		tradeskill = FLETCHING;
<!		break;
<!	case 20:
<!		tradeskill = JEWELRY_MAKING;
<!		break;
<!	case 30: //Pottery Still needs completion
<!		tradeskill = POTTERY;
<!		break;
<!	case 14: // Baking 
<!	case 15:
<!		tradeskill = BAKING;
<!		break;
<!	case 9: //Alchemy Still needs completion
<!		if ((user_pp.class_ == SHAMAN) & (user_pp.level >= MIN_LEVEL_ALCHEMY))
<!			tradeskill = ALCHEMY;
<!		else if (user_pp.class_ != SHAMAN)
<!			user->Message(13, "This tradeskill can only be performed by a shaman.");
<!		else if (user_pp.level < MIN_LEVEL_ALCHEMY)
<!			user->Message(13, "You cannot perform alchemy until you reach level %i.", MIN_LEVEL_ALCHEMY);
<!		return;
<!		break;
<!	case 10: //Tinkering Still needs completion
<!		if (user_pp.race == GNOME)
<!			tradeskill = TINKERING;
<!		else
<!			user->Message(13, "Only gnomes can tinker.");
<!		break; 
<!	case 24: //Research Still needs completion
<!	case 25:
<!	case 26:
<!	case 27:
<!		tradeskill = RESEARCH;
<!		return;
<!		break; 
<!	case 12:
<!		if (user_pp.class_ == ROGUE)
<!			tradeskill = MAKE_POISON;
<!		else
<!			user->Message(13, "Only rogues can mix poisons.");
<!		break;
<!	case 13: //Quest Containers
<!		tradeskill = GENERIC_TRADESKILL;
<!		break;
<!	case 46: //Fishing Still needs completion
<!		tradeskill = FISHING;
<!		return;
<!		break;
<!	}
<!	
<!		break;
<!	default:
<!		user->Message(13, "This tradeskill has not been implemented yet, if you get this message send a "
<!			"petition and let them know what tradeskill you were trying to use. and give them the following code: 0x%02X", tradeskill);
<!	}
<!	
<!	if (tradeskill == TradeskillUnknown) {
<!		return;
<!	}
	
	DBTradeskillRecipe_Struct spec;
<!	if (!database.GetTradeRecipe(container, passtype, tradeskill, &spec)) {
!>	if (!database.GetTradeRecipe(container, c_type, some_id, &spec)) {
		user->Message_StringID(4,TRADESKILL_NOCOMBINE);
		EQApplicationPacket* outapp = new EQApplicationPacket(OP_TradeSkillCombine, 0);
		user->QueuePacket(outapp);
		safe_delete(outapp);
		return;
	}
	
!>	switch (spec.tradeskill)
!>	{
!>	case ALCHEMY:
!>		if (user_pp.class_ != SHAMAN)
!>			user->Message(13, "This tradeskill can only be performed by a shaman.");
!>		else if (user_pp.level < MIN_LEVEL_ALCHEMY)
!>			user->Message(13, "You cannot perform alchemy until you reach level %i.", MIN_LEVEL_ALCHEMY);
!>		return;
!>		break;
!>	case TINKERING:
!>		if (user_pp.race != GNOME)
!>			user->Message(13, "Only gnomes can tinker.");
!>		return;
!>		break; 
!>	case MAKE_POISON:
!>		if (user_pp.class_ != ROGUE)
!>			user->Message(13, "Only rogues can mix poisons.");
!>		return;
!>		break;
!>	}
	
	//do the check and send results...
<!	bool success = user->TradeskillExecute(&spec, tradeskill);
!>	bool success = user->TradeskillExecute(&spec);
	
	// Send acknowledgement packets to client
	EQApplicationPacket* outapp = new EQApplicationPacket(OP_TradeSkillCombine, 0);
	user->QueuePacket(outapp);
	safe_delete(outapp);
	
	//now clean out the containers.
	if(worldcontainer){
		container->Clear();
		outapp = new EQApplicationPacket(OP_ClearObject,0);
		user->QueuePacket(outapp);
		safe_delete(outapp);
		database.DeleteWorldContainer(worldo->m_id, zone->GetZoneID());
		if(success && spec.replace_container) {
			//should report this error, but we dont have the recipe ID, so its not very useful
			LogFile->write(EQEMuLog::Error, "Replace container combine executed in a world container.");
		}
	} else{
		for (uint8 i=0; i<10; i++){
			const ItemInst* inst = container->GetItem(i);
			if (inst) {
				user->DeleteItemInInventory(Inventory::CalcSlotId(in_combine->container_slot,i),0,true);
			}
		}
		container->Clear();
		if(success && spec.replace_container) {
			user->DeleteItemInInventory(in_combine->container_slot, 0, true);
		}
	}
}
Removed references to tstype and passtype as tradeskill info is no longer relevant
Added references to c_type and some_id to be consistent with naming on client_packet.cpp
Removed code to assign tradeskill based on combiner type
Changed function call to pass combiner type and some_id instead of combiner type and tradeskill
After return from getting recipe (which now identifies tradeskill it wants to use) added code to check classes against tradeskill
changed function call to TradeskillExecute to remove tradeskill from parameter list as it is now included in spec.
Reply With Quote
  #4  
Old 03-04-2007, 05:05 AM
Darkonig
Hill Giant
 
Join Date: Dec 2006
Posts: 102
Default

Tradeskills.cpp
Code:
void Object::HandleAutoCombine(Client* user, const RecipeAutoCombine_Struct* rac) {
	
	//get our packet ready, gotta send one no matter what...
	EQApplicationPacket* outapp = new EQApplicationPacket(OP_RecipeAutoCombine, sizeof(RecipeAutoCombine_Struct));
	RecipeAutoCombine_Struct *outp = (RecipeAutoCombine_Struct *)outapp->pBuffer;
	outp->object_type = rac->object_type;
	outp->some_id = rac->some_id;
	outp->unknown1 = rac->unknown1;
	outp->recipe_id = rac->recipe_id;
	outp->reply_code = 0xFFFFFFF5;	//default fail.
	
	
<!	SkillType tskill = Object::TypeToSkill(rac->object_type);
<!	if(tskill == TradeskillUnknown) {
<!		LogFile->write(EQEMuLog::Error, "Unknown container type for HandleAutoCombine: %d\n", rac->object_type);
<!		user->QueuePacket(outapp);
<!		safe_delete(outapp);
<!		return;
<!	}
<!	
	//ask the database for the recipe to make sure it exists...
	DBTradeskillRecipe_Struct spec;
<!	if (!database.GetTradeRecipe(rac->recipe_id, rac->object_type, tskill, &spec)) {
>!	if (!database.GetTradeRecipe(rac->recipe_id, rac->object_type, rac->some_id, &spec)) {
		LogFile->write(EQEMuLog::Error, "Unknown recipe for HandleAutoCombine: %u\n", rac->recipe_id);
		user->QueuePacket(outapp);
		safe_delete(outapp);
		return;
	}
	
	char errbuf[MYSQL_ERRMSG_SIZE];
    MYSQL_RES *result;
    MYSQL_ROW row;
    char *query = 0;
	
	uint32 qlen = 0;
	uint8 qcount = 0;

	//pull the list of components
	qlen = MakeAnyLenString(&query, "SELECT tre.item_id,tre.componentcount "
	 " FROM tradeskill_recipe_entries AS tre "
	 " WHERE tre.componentcount > 0 AND tre.recipe_id=%u", rac->recipe_id);

	if (!database.RunQuery(query, qlen, errbuf, &result)) {
		LogFile->write(EQEMuLog::Error, "Error in HandleAutoCombine query '%s': %s", query, errbuf);
		safe_delete_array(query);
		user->QueuePacket(outapp);
		safe_delete(outapp);
		return;
	}
	safe_delete_array(query);
	
	qcount = mysql_num_rows(result);
	if(qcount < 1) {
		LogFile->write(EQEMuLog::Error, "Error in HandleAutoCombine: no components returned");
		user->QueuePacket(outapp);
		safe_delete(outapp);
		return;
	}
	if(qcount > 10) {
		LogFile->write(EQEMuLog::Error, "Error in HandleAutoCombine: too many components returned (%u)", qcount);
		user->QueuePacket(outapp);
		safe_delete(outapp);
		return;
	}
	
	uint32 items[10];
	memset(items, 0, sizeof(items));
	uint8 counts[10];
	memset(counts, 0, sizeof(counts));
	
	
	//search for all the crap in their inventory
	Inventory& user_inv = user->GetInv();
	uint8 count = 0;
	uint8 needcount = 0;
	uint8 r,k;
	for(r = 0; r < qcount; r++) {
		row = mysql_fetch_row(result);
		uint32 item = (uint32)atoi(row[0]);
		uint8 num = (uint8) atoi(row[1]);
		
		needcount += num;
		
		//because a HasItem on items with num > 1 only returns the
		//last-most slot... the results of this are useless to us
		//when we go to delete them because we cannot assume it is in a single stack.
		if(user_inv.HasItem(item, num, invWherePersonal) != SLOT_INVALID)
			count += num;
		//dont start deleting anything until we have found it all.
		items[r] = item;
		counts[r] = num;
	}
	mysql_free_result(result);
	
	//make sure we found it all...
	if(count != needcount) {
		user->QueuePacket(outapp);
		safe_delete(outapp);
		return;
	}
	
	//now we know they have everything...
	
	//remove all the items from the players inventory, with updates...
	sint16 slot;
	for(r = 0; r < qcount; r++) {
		if(items[r] == 0 || counts[r] == 0)
			continue;	//skip empties, could prolly break here
		
		//we have to loop here to delete 1 at a time in case its in multiple stacks.
		for(k = 0; k < counts[r]; k++) {
			slot = user_inv.HasItem(items[r], 1, invWherePersonal);
			if(slot == SLOT_INVALID) {
				//WTF... I just checked this above, but just to be sure...
				//we cant undo the previous deletes without a lot of work.
				//so just call it quits, this shouldent ever happen anyways.
				user->QueuePacket(outapp);
				safe_delete(outapp);
				return;
			}
			
			user->DeleteItemInInventory(slot, 1, true);
		}
	}
	
	//otherwise, we found it all...
	outp->reply_code = 0x00000000;	//success for finding it...
	
	user->QueuePacket(outapp);
	//DumpPacket(outapp);
	safe_delete(outapp);
	
	//now actually try to make something...
	
<!	bool success = user->TradeskillExecute(&spec, tskill);
!>	bool success = user->TradeskillExecute(&spec);
	
	//TODO: find in-pack containers in inventory, make sure they are really
	//there, and then use that slot to handle replace_container too.
	if(success && spec.replace_container) {
//		user->DeleteItemInInventory(in_combine->container_slot, 0, true);
	}
	
}
Removed code that determines tradeskill from combiner type as it is no longer relevant
changed function call to GetTradeRecipe to pass some_id instead of tradeskill
changed function call to TradeskillExecute to remove tradeskill from parameter list as it is now included in spec

Last edited by Darkonig; 03-04-2007 at 01:10 PM..
Reply With Quote
  #5  
Old 03-04-2007, 05:07 AM
Darkonig
Hill Giant
 
Join Date: Dec 2006
Posts: 102
Default

Tradeskills.cpp
Code:
//returns true on success
<!bool Client::TradeskillExecute(DBTradeskillRecipe_Struct *spec, SkillType tradeskill) {
>!bool Client::TradeskillExecute(DBTradeskillRecipe_Struct *spec) {
<!	if(spec == NULL || tradeskill == 0)
!>	if(spec == NULL)
		return(false);
	
<!	int16 user_skill = GetSkill(tradeskill);
!>	int16 user_skill = GetSkill(spec->tradeskill);
	float chance = 0;
	float skillup_modifier;
	sint16 thirdstat = 0;
	sint16 stat_modifier = 15;
	uint16 success_modifier;

	// Rework based on the info on eqtraders.com
	// http://mboards.eqtraders.com/eq/showthread.php?t=22246
	// 09/10/2006 v0.1 (eq4me)
	// 09/11/2006 v0.2 (eq4me)
	// Todo:
	//     Implementing AAs
	//     Success modifiers based on recipes
	//     Skillup modifiers based on the rarity of the ingredients

	// Some tradeskills are more eqal then others. ;-)
	// If you want to customize the stage1 success rate do it here.
    // Remember: skillup_modifier is (float). Lower is better
<!	switch(tradeskill) {
!>	switch(spec->tradeskill) {
	case FLETCHING:
	case ALCHEMY:
	case JEWELRY_MAKING:
	case POTTERY:
		skillup_modifier = 4;
		break;
	case BAKING:
	case BREWING:
		skillup_modifier = 3;
		break;
	case RESEARCH:
		skillup_modifier = 1;
		break;
	default:
		skillup_modifier = 2;
		break;
	}

	// Some tradeskills take the higher of one additional stat beside INT and WIS
	// to determine the skillup rate. Additionally these tradeskills do not have an
	// -15 modifier on their statbonus.
<!	if (tradeskill ==  FLETCHING || tradeskill == MAKE_POISON) {
!>	switch(spec->tradeskill) {
!>	case FLETCHING:
!>	case MAKE_POISON:
		thirdstat = GetDEX();
		stat_modifier = 0;
		break;
<!	} else if (tradeskill == BLACKSMITHING) {
!>	case BLACKSMITHING:
		thirdstat = GetSTR();
		stat_modifier = 0;
!>		break;
!>	default:
!>		break;
	}
	
	sint16 higher_from_int_wis = (GetINT() > GetWIS()) ? GetINT() : GetWIS();
	sint16 bonusstat = (higher_from_int_wis > thirdstat) ? higher_from_int_wis : thirdstat;
	
	vector< pair<uint32,uint8> >::iterator itr;


    //calculate the base success chance
	// For trivials over 68 the chance is (skill - 0.75*trivial) +51.5
    // For trivial up to 68 the chance is (skill - trivial) + 66
	if (spec->trivial >= 68) {
		chance = (user_skill - (0.75*spec->trivial)) + 51.5;
	} else {
		chance = (user_skill - spec->trivial) + 66;
	}
	
	sint16 over_trivial = (sint16)user_skill - (sint16)spec->trivial;

	//handle caps
	if(spec->nofail) {
		chance = 100;	//cannot fail.
		_log(TRADESKILLS__TRACE, "...This combine cannot fail.");
	} else if(over_trivial > 0) {
		// At reaching trivial the chance goes to 95% going up an additional
		// percent for every 40 skillpoints above the trivial.
		// The success rate is not modified through stats.
		// Mastery AAs are unaccounted for so far.
		// chance_AA = chance + ((100 - chance) * mastery_modifier)
		// But the 95% limit with an additional 1% for every 40 skill points
		// above critical still stands.
		// Mastery modifier is: 10%/25%/50% for rank one/two/three
		chance = 95.0f + (float(user_skill - spec->trivial) / 40.0f);
		Message_StringID(4, TRADESKILL_TRIVIAL);
	} else if(chance < 5) {
		// Minimum chance is always 5
		chance = 5;
	} else if(chance > 95) {
		//cap is 95, shouldent reach this before trivial, but just in case.
		chance = 95;
	}
	
	_log(TRADESKILLS__TRACE, "...Current skill: %d , Trivial: %d , Success chance: %f percent", user_skill , spec->trivial , chance);
	_log(TRADESKILLS__TRACE, "...Bonusstat: %d , INT: %d , WIS: %d , DEX: %d , STR: %d", bonusstat , GetINT() , GetWIS() , GetDEX() , GetSTR());
	
	float res = MakeRandomFloat(0, 99);
<!	if ((tradeskill==75) || GetGM() || (chance > res)){
>!	if ((spec->tradeskill==75) || GetGM() || (chance > res)){
		success_modifier = 1;
		
		if(over_trivial < 0)
<!			CheckIncreaseTradeskill(bonusstat, stat_modifier, skillup_modifier, success_modifier, tradeskill);
!>			CheckIncreaseTradeskill(bonusstat, stat_modifier, skillup_modifier, success_modifier, spec->tradeskill);
		
		Message_StringID(4,TRADESKILL_SUCCEED);

		_log(TRADESKILLS__TRACE, "Tradeskill success");

		itr = spec->onsuccess.begin();
		while(itr != spec->onsuccess.end()) {
			//should we check this crap?
			SummonItem(itr->first, itr->second);
			itr++;
		}
		return(true);
	} else {
		success_modifier = 2; // Halves the chance
		
		if(over_trivial < 0)
<!			CheckIncreaseTradeskill(bonusstat, stat_modifier, skillup_modifier, success_modifier, tradeskill);
!>			CheckIncreaseTradeskill(bonusstat, stat_modifier, skillup_modifier, success_modifier, spec->tradeskill);
		
		Message_StringID(4,TRADESKILL_FAILED);

		_log(TRADESKILLS__TRACE, "Tradeskill failed");
		
		itr = spec->onfail.begin();
		while(itr != spec->onfail.end()) {
			//should we check these arguments?
			SummonItem(itr->first, itr->second);
			itr++;
		}
	}
	return(false);
}
changed signature to remove tradeskill as it is now part of spec
changed references to tradeskill to spec->tradeskill
changed compound if statement to switch to facilitate changes in evaluation (not needed for code to work)
Reply With Quote
  #6  
Old 03-04-2007, 05:09 AM
Darkonig
Hill Giant
 
Join Date: Dec 2006
Posts: 102
Default

Tradeskills.cpp
Code:
<!bool ZoneDatabase::GetTradeRecipe(const ItemInst* container, uint8 c_type, uint8 tradeskill, 
!>bool ZoneDatabase::GetTradeRecipe(const ItemInst* container, uint8 c_type, uint32 some_id, 
	DBTradeskillRecipe_Struct *spec)
{
	char errbuf[MYSQL_ERRMSG_SIZE];
    MYSQL_RES *result;
    MYSQL_ROW row;
    char *query = 0;
	char buf2[2048];
	
	uint32 sum = 0;
	uint32 count = 0;
	uint32 qcount = 0;
	uint32 qlen = 0;

<!	//use the world item type as type if we have a world item
<!	//otherwise use the item's ID... this make the assumption that
<!	//no tradeskill containers will have an item ID which is
<!	//below the highest ID of objects, which is currently 0x30
<!	uint32 type = c_type;
<!	
<!	//dunno why I have to cast this up to call GetItem
<!	const Item_Struct *istruct = ((const ItemInst *) container)->GetItem();
<!	if(c_type == 0 && istruct) {
<!		type = istruct->ID;
<!	}
<!
!>	// make where clause segment for container(s)
!>	char containers[30];
!>	if (some_id == 0) {
!>		// world combiner so no item number
!>		snprintf(containers,29, "= %u", c_type);
!>	} else {
!>		// container in inventory
!>		snprintf(containers,29, "in (%u,%u)", c_type, some_id);
!>	}

	buf2[0] = '\0';
	
	//Could prolly watch for stacks in this loop and handle them properly...
	//just increment sum and count accordingly
	bool first = true;
	uint8 i;
	char *pos = buf2;
	for (i=0; i<10; i++) {
		const ItemInst* inst = container->GetItem(i);
		if (inst) {
			const Item_Struct* item = GetItem(inst->GetItem()->ID);
			if (item) {
				if(first) {
					pos += snprintf(pos, 19, "%d", item->ID);
					first = false;
				} else {
					pos += snprintf(pos, 19, ",%d", item->ID);
				}
				sum += item->ID;
				count++;
			}
		}
	}
	*pos = '\0';
	
	if(count < 1) {
		return(false);	//no items == no recipe
	}
	
	qlen = MakeAnyLenString(&query, "SELECT tre.recipe_id "
	" FROM tradeskill_recipe_entries AS tre"
	" WHERE ( tre.item_id IN(%s) AND tre.componentcount>0 )"
<!	"  OR ( tre.item_id=%u AND tre.iscontainer=1 )"
!>	"  OR ( tre.item_id %s AND tre.iscontainer=1 )"
	" GROUP BY tre.recipe_id HAVING sum(tre.componentcount) = %u"
<!	"  AND sum(tre.item_id * tre.componentcount) = %u", buf2, type, count, sum);
!>	"  AND sum(tre.item_id * tre.componentcount) = %u", buf2, containers, count, sum);
	
	if (!RunQuery(query, qlen, errbuf, &result)) {
<!		LogFile->write(EQEMuLog::Error, "Error in GetTradeRecept search, query: %s", query);
!>		LogFile->write(EQEMuLog::Error, "Error in GetTradeRecipe search, query: %s", query);
		safe_delete_array(query);
<!		LogFile->write(EQEMuLog::Error, "Error in GetTradeRecept search, error: %s", errbuf);
!>		LogFile->write(EQEMuLog::Error, "Error in GetTradeRecipe search, error: %s", errbuf);
		return(false);
	}
	safe_delete_array(query);
	
	qcount = mysql_num_rows(result);
	if(qcount > 1) {
		//multiple recipes, partial match... do an extra query to get it exact.
		//this happens when combining components for a smaller recipe
		//which is completely contained within another recipe
		
		first = true;
		pos = buf2;
		for (i = 0; i < qcount; i++) {
			row = mysql_fetch_row(result);
			uint32 recipeid = (uint32) atoi(row[0]);
			if(first) {
				pos += snprintf(pos, 19, "%u", recipeid);
				first = false;
			} else {
				pos += snprintf(pos, 19, ",%u", recipeid);
			}
			//length sanity check on buf2
			if(pos > (buf2 + 2020))
				break;
		}
		
		qlen = MakeAnyLenString(&query, "SELECT tre.recipe_id"
		" FROM tradeskill_recipe_entries AS tre"
		" WHERE tre.recipe_id IN (%s)"
		" GROUP BY tre.recipe_id HAVING sum(tre.componentcount) = %u"
		"  AND sum(tre.item_id * tre.componentcount) = %u", buf2, count, sum);
		
		if (!RunQuery(query, qlen, errbuf, &result)) {
<!			LogFile->write(EQEMuLog::Error, "Error in GetTradeRecept, re-query: %s", query);
!>			LogFile->write(EQEMuLog::Error, "Error in GetTradeRecipe, re-query: %s", query);
			safe_delete_array(query);
<!			LogFile->write(EQEMuLog::Error, "Error in GetTradeRecept, error: %s", errbuf);
!>			LogFile->write(EQEMuLog::Error, "Error in GetTradeRecipe, error: %s", errbuf);
			return(false);
		}
		safe_delete_array(query);
	
		qcount = mysql_num_rows(result);
	}
	if (qcount != 1) {
		if(qcount > 1) {
			LogFile->write(EQEMuLog::Error, "Combine error: Recipe is not unique!");
		}
		//else, just not found i guess..
		return(false);
	}
	
	row = mysql_fetch_row(result);
	uint32 recipe_id = (uint32)atoi(row[0]);
	mysql_free_result(result);
	
<!	return(GetTradeRecipe(recipe_id, c_type, tradeskill, spec));
!>	return(GetTradeRecipe(recipe_id, c_type, some_id, spec));
}
Changed signature to use some_id instead of tradeskill
Changed error logging to use actual function name
Changed query to use containers (type and some_id) instead of just one or the other - this helps simplify recipes

Code:
<!bool ZoneDatabase::GetTradeRecipe(uint32 recipe_id, uint8 c_type, uint8 tradeskill, 
!>bool ZoneDatabase::GetTradeRecipe(uint32 recipe_id, uint8 c_type, uint32 some_id, 
	DBTradeskillRecipe_Struct *spec)
{	
	char errbuf[MYSQL_ERRMSG_SIZE];
    MYSQL_RES *result;
    MYSQL_ROW row;
    char *query = 0;
	
	uint32 qcount = 0;
	uint32 qlen;

<!	qlen = MakeAnyLenString(&query, "SELECT tr.skillneeded, tr.trivial, tr.nofail, tr.replace_container"
<!	" FROM tradeskill_recipe AS tr"
<!	" WHERE tr.id = %lu AND tr.tradeskill = %u", recipe_id, tradeskill);
!>	// make where clause segment for container(s)
!>	char containers[30];
!>	if (some_id == 0) {
!>		// world combiner so no item number
!>		snprintf(containers,29, "= %u", c_type);
!>	} else {
!>		// container in inventory
!>		snprintf(containers,29, "in (%u,%u)", c_type, some_id);
!>	}
!>	
!>	qlen = MakeAnyLenString(&query, "SELECT tr.id, tr.tradeskill, tr.skillneeded,"
!>	" tr.trivial, tr.nofail, tr.replace_container"
!>	" FROM tradeskill_recipe AS tr inner join tradeskill_recipe_entries as tre"
!>	" ON tr.id = tre.recipe_id"
!>	" WHERE tr.id = %lu AND tre.item_id %s"
!>	" GROUP BY tr.id", recipe_id, containers);
		
	if (!RunQuery(query, qlen, errbuf, &result)) {
<!		LogFile->write(EQEMuLog::Error, "Error in GetTradeRecept, query: %s", query);
!>		LogFile->write(EQEMuLog::Error, "Error in GetTradeRecipe, query: %s", query);
		safe_delete_array(query);
<!		LogFile->write(EQEMuLog::Error, "Error in GetTradeRecept, error: %s", errbuf);
!>		LogFile->write(EQEMuLog::Error, "Error in GetTradeRecipe, error: %s", errbuf);
		return(false);
	}
	safe_delete_array(query);
	
	qcount = mysql_num_rows(result);
	if(qcount != 1) {
		//just not found i guess..
		return(false);
	}
	
	row = mysql_fetch_row(result);
<!	spec->skill_needed		= (sint16)atoi(row[0]);
<!	spec->trivial			= (uint16)atoi(row[1]);
<!	spec->nofail			= atoi(row[2]) ? true : false;
<!	spec->replace_container	= atoi(row[3]) ? true : false;
!>	spec->tradeskill			= (SkillType)atoi(row[1]);
!>	spec->skill_needed		= (sint16)atoi(row[2]);
!>	spec->trivial			= (uint16)atoi(row[3]);
!>	spec->nofail			= atoi(row[4]) ? true : false;
!>	spec->replace_container	= atoi(row[5]) ? true : false;
	mysql_free_result(result);
	
	//Pull the on-success items...
	qlen = MakeAnyLenString(&query, "SELECT item_id,successcount FROM tradeskill_recipe_entries"
	 " WHERE successcount>0 AND componentcount=0 AND recipe_id=%u", recipe_id);
	 
	if (!RunQuery(query, qlen, errbuf, &result)) {
		LogFile->write(EQEMuLog::Error, "Error in GetTradeRecept success query '%s': %s", query, errbuf);
		safe_delete_array(query);
		return(false);
	}
	safe_delete_array(query);
	
	qcount = mysql_num_rows(result);
	if(qcount < 1) {
		LogFile->write(EQEMuLog::Error, "Error in GetTradeRecept success: no success items returned");
		return(false);
	}
	uint8 r;
	spec->onsuccess.clear();
	for(r = 0; r < qcount; r++) {
		row = mysql_fetch_row(result);
		/*if(r == 0) {
			*product1_id	= (uint32)atoi(row[0]);
			*productcount	= (uint32)atoi(row[1]);
		} else if(r == 1) {
			*product2_id	= (uint32)atoi(row[0]);
		} else {
			LogFile->write(EQEMuLog::Warning, "Warning: recipe returned more than 2 products, not yet supported.");
		}*/
		uint32 item = (uint32)atoi(row[0]);
		uint8 num = (uint8) atoi(row[1]);
		spec->onsuccess.push_back(pair<uint32,uint8>::pair(item, num));
	}
	mysql_free_result(result);
	
	
	//Pull the on-fail items...
	qlen = MakeAnyLenString(&query, "SELECT item_id,failcount FROM tradeskill_recipe_entries"
	 " WHERE failcount>0 AND componentcount=0 AND recipe_id=%u", recipe_id);

	spec->onfail.clear();
	if (RunQuery(query, qlen, errbuf, &result)) {
		
		qcount = mysql_num_rows(result);
		uint8 r;
		for(r = 0; r < qcount; r++) {
			row = mysql_fetch_row(result);
			/*if(r == 0) {
				*failproduct_id	= (uint32)atoi(row[0]);
			} else {
				LogFile->write(EQEMuLog::Warning, "Warning: recipe returned more than 1 fail product, not yet supported.");
			}*/
			uint32 item = (uint32)atoi(row[0]);
			uint8 num = (uint8) atoi(row[1]);
			spec->onfail.push_back(pair<uint32,uint8>::pair(item, num));
		}
		mysql_free_result(result);
	}
	safe_delete_array(query);
	
	return(true);
}
Changed signature from using tradeskill to using some_id
Changed query to use containers instead of tradeskill
Changed error message posting to use actual name of function
Changed fetch results to include tradeskill from recipe in spec
Reply With Quote
  #7  
Old 03-04-2007, 05:21 AM
Angelox
AX Classic Developer
 
Join Date: May 2006
Location: filler
Posts: 2,049
Default

KLS is revamping the tradeskills , you need to get in touch - try a PM and link your thread. Tell me if you don't get reply, I'll try and find
Reply With Quote
  #8  
Old 03-04-2007, 02:40 PM
KLS
Administrator
 
Join Date: Sep 2006
Posts: 1,348
Default

While I'm not revamping tradeskills =P I will take a look when I get a chance, thanks.
Reply With Quote
  #9  
Old 10-18-2007, 01:01 PM
Angelox
AX Classic Developer
 
Join Date: May 2006
Location: filler
Posts: 2,049
Default

This looks like a real good fix for tradeskills - I wonder if it ever got into the source?
Reply With Quote
  #10  
Old 10-18-2007, 01:15 PM
cavedude's Avatar
cavedude
The PEQ Dude
 
Join Date: Apr 2003
Location: -
Posts: 1,988
Default

Yes, it did. Or, at least something did. Tradeskill combines work much better now in that items will only combine in containers that the db tells them to, not any container that is related to it like in the past. Also, there is no longer a need to specify the container type in the code, which means no more broken combines due to the server not knowing what the container is.
Reply With Quote
Reply


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 12:50 PM.


 

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 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3