View Single Post
  #1  
Old 08-27-2014, 04:19 PM
noudess
Discordant
 
Join Date: Sep 2012
Location: Upstate NY
Posts: 274
Default COMMITTED: More detailed merchant rejection code

The code (at least the version I have from eqemu) that tells a PC to go pound salt, isn't good enough to avoid situations where a half elf is told by a half elf that his race should go elsewhere.

This patch changes it so the merchant decides what to say based on the worst contributor vs primary faction be it class, race, deity or nasty deeds.

Use it if you like, seems to be working as intended on my server.

Code:
=== modified file 'zone/client.h'
--- zone/client.h	2014-07-25 14:55:13 +0000
+++ zone/client.h	2014-08-27 19:58:49 +0000
@@ -577,7 +577,7 @@
     FACTION_VALUE   GetFactionLevel(uint32 char_id, uint32 npc_id, uint32 p_race, uint32 p_class, uint32 p_deity, int32 pFaction, Mob* tnpc);
 	int32	GetCharacterFactionLevel(int32 faction_id);
 	int32  GetModCharacterFactionLevel(int32 faction_id);
-	bool	HatedByClass(uint32 p_race, uint32 p_class, uint32 p_deity, int32 pFaction);
+	string	WhyHated(uint32 p_race, uint32 p_class, uint32 p_deity, int32 pFaction);
 
 	void	SetFactionLevel(uint32 char_id, uint32 npc_id, uint8 char_class, uint8 char_race, uint8 char_deity);
 	void    SetFactionLevel2(uint32 char_id, int32 faction_id, uint8 char_class, uint8 char_race, uint8 char_deity, int32 value, uint8 temp);

=== modified file 'zone/client_packet.cpp'
--- zone/client_packet.cpp	2014-08-15 18:12:09 +0000
+++ zone/client_packet.cpp	2014-08-27 20:02:52 +0000
@@ -5465,25 +5465,21 @@
 	int factionlvl = GetFactionLevel(CharacterID(), tmp->CastToNPC()->GetNPCTypeID(), GetRace(), GetClass(), GetDeity(), tmp->CastToNPC()->GetPrimaryFaction(), tmp);
 	if(factionlvl >= 7)
 	{
-		char playerp[16] = "players";
-		if(HatedByClass(GetRace(), GetClass(), GetDeity(), tmp->CastToNPC()->GetPrimaryFaction()))
-			strcpy(playerp,GetClassPlural(this));
-		else
-			strcpy(playerp,GetRacePlural(this));
+		string playerp = WhyHated(GetRace(), GetClass(), GetDeity(), tmp->CastToNPC()->GetPrimaryFaction());
 
 		uint8 rand_ = rand() % 4;
 		switch(rand_){
 			case 1:
-				Message(0,"%s says 'It's not enough that you %s have ruined your own lands. Now get lost!'", tmp->GetCleanName(), playerp);
+				Message(0,"%s says 'It's not enough that you %s have ruined your own lands. Now get lost!'", tmp->GetCleanName(), playerp.data());
 				break;
 			case 2:
-				Message(0,"%s says 'I have something here that %s use... let me see... it's the EXIT, now get LOST!'", tmp->GetCleanName(), playerp);
+				Message(0,"%s says 'I have something here that %s use... let me see... it's the EXIT, now get LOST!'", tmp->GetCleanName(), playerp.data());
 				break;
 			case 3:
-				Message(0,"%s says 'Don't you %s have your own merchants? Whatever, I'm not selling anything to you!'", tmp->GetCleanName(), playerp);
+				Message(0,"%s says 'Don't you %s have your own merchants? Whatever, I'm not selling anything to you!'", tmp->GetCleanName(), playerp.data());
 				break;
 			default:
-				Message(0,"%s says 'I don't like to speak to %s much less sell to them!'", tmp->GetCleanName(), playerp);
+				Message(0,"%s says 'I don't like to speak to %s much less sell to them!'", tmp->GetCleanName(), playerp.data());
 				break;
 		}
 		action = 0;

=== modified file 'zone/faction.cpp'
--- zone/faction.cpp	2013-07-09 15:28:09 +0000
+++ zone/faction.cpp	2014-08-27 20:09:18 +0000
@@ -1037,28 +1037,38 @@
 	return true;
 }
 
-bool Client::HatedByClass(uint32 p_race, uint32 p_class, uint32 p_deity, int32 pFaction)
+string Client::WhyHated(uint32 p_race, uint32 p_class, uint32 p_deity, int32 pFaction)
 {
-	
-	bool Result = false;
+	string result="defilers of our beliefs"
 	_ZP(Client_GetFactionLevel);
 
 	int32 tmpFactionValue;
 	FactionMods fmods;
+	int32 lowestvalue;
 
-    //First get the NPC's Primary faction
+	//First get the NPC's Primary faction
 	if(pFaction > 0)
-	{
+		{
 		//Get the faction data from the database
 		if(database.GetFactionData(&fmods, p_class, p_race, p_deity, pFaction))
-		{
+			{
 			tmpFactionValue = GetCharacterFactionLevel(pFaction);
-			tmpFactionValue += GetFactionBonus(pFaction);
-			tmpFactionValue += GetItemFactionBonus(pFaction);
-			CalculateFaction(&fmods, tmpFactionValue);
-			if(fmods.class_mod < fmods.race_mod)
-				Result = true;
+			lowestvalue=min(tmpFactionValue, min(fmods.class_mod, 
+								min(fmods.race_mod, fmods.deity_mod)));
+			if (lowestvalue == fmods.class_mod)
+				{
+				result=GetClassPlural(this);
+				}
+			else if (lowestvalue == fmods.race_mod)
+				{
+				result=GetRacePlural(this);;
+				}
+			else if (lowestvalue == fmods.deity_mod)
+				{
+				result="worshippers of " + GetDeityName(p_deity);
+				}
+			}
 		}
-	}
-	return Result;
+
+	return result;
 }

=== modified file 'zone/mob.cpp'
--- zone/mob.cpp	2014-07-22 19:15:11 +0000
+++ zone/mob.cpp	2014-08-27 20:13:08 +0000
@@ -30,6 +30,7 @@
 #include "../common/rulesys.h"
 #include "../common/emu_opcodes.h"
 #include "../common/eq_packet_structs.h"
+#include "../common/deity.h"
 #include "zonedb.h"
 #include "../common/packet_dump.h"
 #include "../common/packet_functions.h"
@@ -4598,3 +4599,31 @@
 }
 
 
+string Mob::GetDeityName(uint8 deity)
+
+{
+	string name;
+
+	switch (deity)
+		{
+		case DEITY_AGNOSTIC:	name="AGNOSTIC"; break;
+		case DEITY_BRELL:		name="BRELL"; break;
+		case DEITY_CAZIC:		name="CAZIC"; break;
+		case DEITY_EROLLSI:		name="EROLLSI"; break;
+		case DEITY_BRISTLE:		name="BRISTLE"; break;
+		case DEITY_INNY:		name="INNY"; break;
+		case DEITY_KARANA:		name="KARANA"; break;
+		case DEITY_MITH:		name="MITH"; break;
+		case DEITY_PREXUS:		name="PREXUS"; break;
+		case DEITY_QUELLIOUS:	name="QUELLIOUS"; break;
+		case DEITY_RALLOS:		name="RALLOS"; break;
+		case DEITY_SOLUSEK:		name="SOLUSEK"; break;
+		case DEITY_TRIBUNAL:	name="TRIBUNAL"; break;
+		case DEITY_TUNARE:		name="TUNARE"; break;
+		case DEITY_BERTOX:		name="BERTOX"; break;
+		case DEITY_RODCET:		name="RODCET"; break;
+		case DEITY_VEESHAN:		name="VEESHAN"; break;
+		} 
+	
+	return name;
+}

=== modified file 'zone/mob.h'
--- zone/mob.h	2014-07-22 19:15:11 +0000
+++ zone/mob.h	2014-08-27 19:53:40 +0000
@@ -732,6 +732,7 @@
 	virtual void SetTarget(Mob* mob);
 	virtual inline float		GetHPRatio() const { return max_hp == 0 ? 0 : ((float)cur_hp/max_hp*100); }
 
+	string GetDeityName(uint8 deity);
 	bool IsLoggingEnabled() const { return(logging_enabled); }
 	void EnableLogging() { logging_enabled = true; }
 	void DisableLogging() { logging_enabled = false; }
Reply With Quote