From 22de30bab3713f30ef6d6281a6464bfd75379b39 Mon Sep 17 00:00:00 2001 From: Paul Coene Date: Sun, 25 Jan 2015 09:46:00 -0500 Subject: [PATCH 1/3] Repair faction messaging code. The messages were being based on total faction rather than personal faction. The personal faction range is all that is needed to detremine which message. There were several bugs as well. Fixed several edge conditions --- zone/client.cpp | 159 +++++++++++++++++++++++++++++------------------- zone/client.h | 3 +- 2 files changed, 98 insertions(+), 64 deletions(-) diff --git a/zone/client.cpp b/zone/client.cpp index 5094328b0..43e88c45e 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -7564,73 +7564,30 @@ void Client::SetFactionLevel(uint32 char_id, uint32 npc_id, uint8 char_class, ui int32 faction_id[MAX_NPC_FACTIONS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int32 npc_value[MAX_NPC_FACTIONS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; uint8 temp[MAX_NPC_FACTIONS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - int32 mod; - int32 tmpValue; int32 current_value; - FactionMods fm; bool change = false; - bool repair = false; // Get the npc faction list if (!database.GetNPCFactionList(npc_id, faction_id, npc_value, temp)) return; for (int i = 0; i < MAX_NPC_FACTIONS; i++) { + int32 faction_before_hit; + int32 faction_to_use_for_messaging; + if (faction_id[i] <= 0) continue; - // Get the faction modifiers - if (database.GetFactionData(&fm, char_class, char_race, char_deity, faction_id[i])) - { - // Get the characters current value with that faction - current_value = GetCharacterFactionLevel(faction_id[i]); + // Get the characters current value with that faction + current_value = GetCharacterFactionLevel(faction_id[i]); + faction_before_hit = current_value; - if (this->itembonuses.HeroicCHA) + change = UpdatePersonalFaction(char_id, npc_value[i], faction_id[i], ¤t_value, temp[i]); + + if (change) { - int faction_mod = itembonuses.HeroicCHA / 5; - // If our result isn't truncated, then just do that - if (npc_value[i] * faction_mod / 100 != 0) - npc_value[i] += npc_value[i] * faction_mod / 100; - // If our result is truncated, then double a mob's value every once and a while to equal what they would have got - else - { - if (zone->random.Int(0, 100) < faction_mod) - npc_value[i] *= 2; - } + SendFactionMessage(npc_value[i], faction_id[i], faction_before_hit, current_value, temp[i]); } - // Set flag when to update db - if (current_value > MAX_PERSONAL_FACTION) - { - current_value = MAX_PERSONAL_FACTION; - repair = true; - } - else if (current_value < MIN_PERSONAL_FACTION) - { - current_value = MIN_PERSONAL_FACTION; - repair = true; - } - else if ((m_pp.gm != 1) && (npc_value[i] != 0) && ((current_value != MAX_PERSONAL_FACTION) || (current_value != MIN_PERSONAL_FACTION))) - change = true; - - current_value += npc_value[i]; - - if (current_value > MAX_PERSONAL_FACTION) - current_value = MAX_PERSONAL_FACTION; - else if (current_value < MIN_PERSONAL_FACTION) - current_value = MIN_PERSONAL_FACTION; - - if (change || repair) - { - database.SetCharacterFactionLevel(char_id, faction_id[i], current_value, temp[i], factionvalues); - - if (change) - { - mod = fm.base + fm.class_mod + fm.race_mod + fm.deity_mod; - tmpValue = current_value + mod + npc_value[i]; - SendFactionMessage(npc_value[i], faction_id[i], tmpValue, temp[i]); - } - } - } } return; } @@ -7638,15 +7595,24 @@ void Client::SetFactionLevel(uint32 char_id, uint32 npc_id, uint8 char_class, ui void Client::SetFactionLevel2(uint32 char_id, int32 faction_id, uint8 char_class, uint8 char_race, uint8 char_deity, int32 value, uint8 temp) { int32 current_value; + bool change=false; + //Get the npc faction list if(faction_id > 0 && value != 0) { - //Get the faction modifiers - current_value = GetCharacterFactionLevel(faction_id) + value; - if(!(database.SetCharacterFactionLevel(char_id, faction_id, current_value, temp, factionvalues))) - return; + int32 faction_before_hit; - SendFactionMessage(value, faction_id, current_value, temp); + //Get the faction modifiers + current_value = GetCharacterFactionLevel(faction_id); + faction_before_hit = current_value; + + change = UpdatePersonalFaction(char_id, value, faction_id, ¤t_value, temp); + + if (change) + { + SendFactionMessage(value, faction_id, faction_before_hit, current_value, temp); + } } + return; } @@ -7661,6 +7627,58 @@ int32 Client::GetCharacterFactionLevel(int32 faction_id) return res->second; } +// Common code to set faction level. +// Applies HeroicCHA is it applies +// Checks for bottom out and max faction and old faction db entries +// Updates the faction if we are not minned, maxed or we need to repair + +bool Client::UpdatePersonalFaction(int32 char_id, int32 npc_value, int32 faction_id, int32 *current_value, int32 temp) +{ + bool repair = false; + bool change = false; + + if (this->itembonuses.HeroicCHA) + { + int faction_mod = itembonuses.HeroicCHA / 5; + // If our result isn't truncated, then just do that + if (npc_value * faction_mod / 100 != 0) + npc_value += npc_value * faction_mod / 100; + // If our result is truncated, then double a mob's value every once and a while to equal what they would have got + else + { + if (zone->random.Int(0, 100) < faction_mod) + npc_value *= 2; + } + } + // Set flag when to update db + if (*current_value > MAX_PERSONAL_FACTION) + { + *current_value = MAX_PERSONAL_FACTION; + repair = true; + } + else if (*current_value < MIN_PERSONAL_FACTION) + { + *current_value = MIN_PERSONAL_FACTION; + repair = true; + } + else if ((m_pp.gm != 1) && (npc_value != 0) && ((*current_value != MAX_PERSONAL_FACTION) || (*current_value != MIN_PERSONAL_FACTION))) + change = true; + + *current_value += npc_value; + + if (*current_value > MAX_PERSONAL_FACTION) + *current_value = MAX_PERSONAL_FACTION; + else if (*current_value < MIN_PERSONAL_FACTION) + *current_value = MIN_PERSONAL_FACTION; + + if (change || repair) + { + database.SetCharacterFactionLevel(char_id, faction_id, *current_value, temp, factionvalues); + } + +return change; +} + // returns the character's faction level, adjusted for racial, class, and deity modifiers int32 Client::GetModCharacterFactionLevel(int32 faction_id) { int32 Modded = GetCharacterFactionLevel(faction_id); @@ -7739,9 +7757,24 @@ void Client::MerchantRejectMessage(Mob *merchant, int primaryfaction) //o-------------------------------------------------------------- //| Purpose: Send faction change message to client //o-------------------------------------------------------------- -void Client::SendFactionMessage(int32 tmpvalue, int32 faction_id, int32 totalvalue, uint8 temp) +void Client::SendFactionMessage(int32 tmpvalue, int32 faction_id, int32 faction_before_hit, int32 totalvalue, uint8 temp) { char name[50]; + int32 faction_value; + + // If we're dropping from MAX or raising from MIN, we should + // base the message on the new updated value so we don't show + // a min MAX message + // + // If we're changing any other place, we use the value before the + // hit. For example, if we go from 1199 to 1200 which is the MAX + // we still want to say faction got better this time around. + + if ( (faction_before_hit == MAX_PERSONAL_FACTION) || + (faction_before_hit == MIN_PERSONAL_FACTION)) + faction_value = totalvalue; + else + faction_value = faction_before_hit; // default to Faction# if we couldn't get the name from the ID if (database.GetFactionName(faction_id, name, sizeof(name)) == false) @@ -7749,13 +7782,13 @@ void Client::SendFactionMessage(int32 tmpvalue, int32 faction_id, int32 totalval if (tmpvalue == 0 || temp == 1 || temp == 2) return; - else if (totalvalue >= MAX_PERSONAL_FACTION) + else if (faction_value >= MAX_PERSONAL_FACTION) Message_StringID(15, FACTION_BEST, name); - else if (totalvalue <= MIN_PERSONAL_FACTION) + else if (faction_value <= MIN_PERSONAL_FACTION) Message_StringID(15, FACTION_WORST, name); - else if (tmpvalue > 0 && totalvalue < MAX_PERSONAL_FACTION && !RuleB(Client, UseLiveFactionMessage)) + else if (tmpvalue > 0 && faction_value < MAX_PERSONAL_FACTION && !RuleB(Client, UseLiveFactionMessage)) Message_StringID(15, FACTION_BETTER, name); - else if (tmpvalue < 0 && totalvalue > MIN_PERSONAL_FACTION && !RuleB(Client, UseLiveFactionMessage)) + else if (tmpvalue < 0 && faction_value > MIN_PERSONAL_FACTION && !RuleB(Client, UseLiveFactionMessage)) Message_StringID(15, FACTION_WORSE, name); else if (RuleB(Client, UseLiveFactionMessage)) Message(15, "Your faction standing with %s has been adjusted by %i.", name, tmpvalue); //New Live faction message (14261) diff --git a/zone/client.h b/zone/client.h index c89dc017c..9f17dee9d 100644 --- a/zone/client.h +++ b/zone/client.h @@ -606,8 +606,9 @@ public: int32 GetCharacterFactionLevel(int32 faction_id); int32 GetModCharacterFactionLevel(int32 faction_id); void MerchantRejectMessage(Mob *merchant, int primaryfaction); - void SendFactionMessage(int32 tmpvalue, int32 faction_id, int32 totalvalue, uint8 temp); + void SendFactionMessage(int32 tmpvalue, int32 faction_id, int32 faction_before_hit, int32 totalvalue, uint8 temp); + bool UpdatePersonalFaction(int32 char_id, int32 npc_value, int32 faction_id, int32 *current_value, int32 temp); 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); int32 GetRawItemAC(); From 60412276da42959c4631ced13a3aa83d63d73bd8 Mon Sep 17 00:00:00 2001 From: Paul Coene Date: Sun, 25 Jan 2015 09:55:41 -0500 Subject: [PATCH 2/3] Report repair as well as change from Update Personal Faction. --- zone/client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zone/client.cpp b/zone/client.cpp index 43e88c45e..431f3662b 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -7676,7 +7676,7 @@ bool Client::UpdatePersonalFaction(int32 char_id, int32 npc_value, int32 faction database.SetCharacterFactionLevel(char_id, faction_id, *current_value, temp, factionvalues); } -return change; +return (repair || change); } // returns the character's faction level, adjusted for racial, class, and deity modifiers From cad4ebc6f3f85c7811e20d4ff85c07c9c39b931d Mon Sep 17 00:00:00 2001 From: Paul Coene Date: Sun, 25 Jan 2015 12:42:19 -0500 Subject: [PATCH 3/3] Procedure for peqdb users to see all faction information for their character. --- .../2015_01_25_MyFaction_Stored_Procedure.sql | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 utils/sql/git/optional/2015_01_25_MyFaction_Stored_Procedure.sql diff --git a/utils/sql/git/optional/2015_01_25_MyFaction_Stored_Procedure.sql b/utils/sql/git/optional/2015_01_25_MyFaction_Stored_Procedure.sql new file mode 100644 index 000000000..91d386289 --- /dev/null +++ b/utils/sql/git/optional/2015_01_25_MyFaction_Stored_Procedure.sql @@ -0,0 +1,30 @@ +DELIMITER $$ + +use peqdb + +CREATE DEFINER=`eqemu`@`%` PROCEDURE `MyFaction`(charname text) +BEGIN +declare class_mod text default ""; +declare race_mod text default ""; +declare deity_mod text default ""; + +select class into class_mod from character_data where name = charname; +select race into race_mod from character_data where name = charname; +select deity into deity_mod from character_data where name = charname; +select concat("c", class_mod) into class_mod; +select concat("r", race_mod) into race_mod; +select concat("d", deity_mod) into deity_mod; + +set @class_bump := 0; +set @race_bump := 0; +set @deity_bump := 0; + +SELECT race_mod as R, class_mod as C, deity_mod as D, f.name as faction, f.id, v.current_value, f.base as "START", +@class_bump := IFNULL((select m.mod from faction_list_mod m where faction_id = f.id && class_mod != "" && mod_name = class_mod),0) as class_bump, +@race_bump := IFNULL((select m.mod from faction_list_mod m where faction_id = f.id && race_mod != "" && mod_name = race_mod),0) as race_bump, +@deity_bump := IFNULL((select m.mod from faction_list_mod m where faction_id = f.id && race_mod != "" && mod_name = deity_mod),0) as deity_bump, +v.current_value + f.base + @class_bump + @race_bump + @deity_bump as TOTAL +FROM peqdb.faction_values v +inner join faction_list f on f.id = v.faction_id +where v.char_id = (select id from character_data where name=charname) ; +END