From 6aab5c1022381a8486525085f3ea56f6368fd33b Mon Sep 17 00:00:00 2001 From: Schmoozerd Date: Tue, 31 Jan 2012 00:12:45 +0100 Subject: [PATCH] [11892] Really fix [11890]. This basicly reverts commit 11890 Remove the actually not required faction check in Player::GetNPCIfCanInteractWith - this is done by IsHostileTo a line before Improve the Player-login AtWar selection to also consider forced reactions Signed-off-by: Schmoozerd --- src/game/GameObject.cpp | 32 +++++++++++++--------- src/game/Level2.cpp | 2 +- src/game/ObjectMgr.cpp | 2 +- src/game/Player.cpp | 15 +++-------- src/game/ReputationMgr.cpp | 22 ++++++++-------- src/game/ReputationMgr.h | 2 +- src/game/Unit.cpp | 54 ++++++++++++++++++++++---------------- src/shared/revision_nr.h | 2 +- 8 files changed, 70 insertions(+), 61 deletions(-) diff --git a/src/game/GameObject.cpp b/src/game/GameObject.cpp index bf1716c57..286c97316 100644 --- a/src/game/GameObject.cpp +++ b/src/game/GameObject.cpp @@ -1728,7 +1728,7 @@ void GameObject::SetWorldRotationAngles(float z_rot, float y_rot, float x_rot) bool GameObject::IsHostileTo(Unit const* unit) const { // always non-hostile to GM in GM mode - if(unit->GetTypeId()==TYPEID_PLAYER && ((Player const*)unit)->isGameMaster()) + if (unit->GetTypeId()==TYPEID_PLAYER && ((Player const*)unit)->isGameMaster()) return false; // test owner instead if have @@ -1739,24 +1739,28 @@ bool GameObject::IsHostileTo(Unit const* unit) const return IsHostileTo(targetOwner); // for not set faction case (wild object) use hostile case - if(!GetGOInfo()->faction) + if (!GetGOInfo()->faction) return true; // faction base cases FactionTemplateEntry const*tester_faction = sFactionTemplateStore.LookupEntry(GetGOInfo()->faction); FactionTemplateEntry const*target_faction = unit->getFactionTemplateEntry(); - if(!tester_faction || !target_faction) + if (!tester_faction || !target_faction) return false; // GvP forced reaction and reputation case - if (unit->GetTypeId()==TYPEID_PLAYER) + if (unit->GetTypeId() == TYPEID_PLAYER) { if (tester_faction->faction) { + // forced reaction + if (ReputationRank const* force = ((Player*)unit)->GetReputationMgr().GetForcedRankIfAny(tester_faction)) + return *force <= REP_HOSTILE; + // apply reputation state FactionEntry const* raw_tester_faction = sFactionStore.LookupEntry(tester_faction->faction); - if (raw_tester_faction && raw_tester_faction->reputationListID >=0 ) - return ((Player const*)unit)->GetReputationMgr().GetRank(raw_tester_faction, true) <= REP_HOSTILE; + if (raw_tester_faction && raw_tester_faction->reputationListID >= 0) + return ((Player const*)unit)->GetReputationMgr().GetRank(raw_tester_faction) <= REP_HOSTILE; } } @@ -1767,7 +1771,7 @@ bool GameObject::IsHostileTo(Unit const* unit) const bool GameObject::IsFriendlyTo(Unit const* unit) const { // always friendly to GM in GM mode - if(unit->GetTypeId()==TYPEID_PLAYER && ((Player const*)unit)->isGameMaster()) + if (unit->GetTypeId()==TYPEID_PLAYER && ((Player const*)unit)->isGameMaster()) return true; // test owner instead if have @@ -1778,24 +1782,28 @@ bool GameObject::IsFriendlyTo(Unit const* unit) const return IsFriendlyTo(targetOwner); // for not set faction case (wild object) use hostile case - if(!GetGOInfo()->faction) + if (!GetGOInfo()->faction) return false; // faction base cases FactionTemplateEntry const*tester_faction = sFactionTemplateStore.LookupEntry(GetGOInfo()->faction); FactionTemplateEntry const*target_faction = unit->getFactionTemplateEntry(); - if(!tester_faction || !target_faction) + if (!tester_faction || !target_faction) return false; // GvP forced reaction and reputation case - if (unit->GetTypeId()==TYPEID_PLAYER) + if (unit->GetTypeId() == TYPEID_PLAYER) { if (tester_faction->faction) { + // forced reaction + if (ReputationRank const* force =((Player*)unit)->GetReputationMgr().GetForcedRankIfAny(tester_faction)) + return *force >= REP_FRIENDLY; + // apply reputation state if (FactionEntry const* raw_tester_faction = sFactionStore.LookupEntry(tester_faction->faction)) - if (raw_tester_faction->reputationListID >=0 ) - return ((Player const*)unit)->GetReputationMgr().GetRank(raw_tester_faction, true) >= REP_FRIENDLY; + if (raw_tester_faction->reputationListID >= 0) + return ((Player const*)unit)->GetReputationMgr().GetRank(raw_tester_faction) >= REP_FRIENDLY; } } diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp index 1eb0a64fc..4025e9595 100644 --- a/src/game/Level2.cpp +++ b/src/game/Level2.cpp @@ -1361,7 +1361,7 @@ void ChatHandler::ShowFactionListHelper( FactionEntry const * factionEntry, Loca if (repState) // and then target!=NULL also { - ReputationRank rank = target->GetReputationMgr().GetRank(factionEntry, false); + ReputationRank rank = target->GetReputationMgr().GetRank(factionEntry); std::string rankName = GetMangosString(ReputationRankStrIndex[rank]); ss << " " << rankName << "|h|r (" << target->GetReputationMgr().GetReputation(factionEntry) << ")"; diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 4391d709f..92827d388 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -7482,7 +7482,7 @@ bool PlayerCondition::Meets(Player const * player) const case CONDITION_REPUTATION_RANK: { FactionEntry const* faction = sFactionStore.LookupEntry(value1); - return faction && player->GetReputationMgr().GetRank(faction, false) >= ReputationRank(value2); + return faction && player->GetReputationMgr().GetRank(faction) >= ReputationRank(value2); } case CONDITION_TEAM: return uint32(player->GetTeam()) == value1; diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 0d09db754..aafc4e8a8 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -2180,15 +2180,8 @@ Creature* Player::GetNPCIfCanInteractWith(ObjectGuid guid, uint32 npcflagmask) if (unit->IsHostileTo(this)) return NULL; - // not unfriendly - if(FactionTemplateEntry const* factionTemplate = sFactionTemplateStore.LookupEntry(unit->getFaction())) - if(factionTemplate->faction) - if(FactionEntry const* faction = sFactionStore.LookupEntry(factionTemplate->faction)) - if(faction->reputationListID >= 0 && GetReputationMgr().GetRank(faction, true) <= REP_UNFRIENDLY) - return NULL; - // not too far - if(!unit->IsWithinDistInMap(this,INTERACTION_DISTANCE)) + if (!unit->IsWithinDistInMap(this, INTERACTION_DISTANCE)) return NULL; return unit; @@ -6229,7 +6222,7 @@ void Player::setFactionForRace(uint8 race) ReputationRank Player::GetReputationRank(uint32 faction) const { FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction); - return GetReputationMgr().GetRank(factionEntry, false); + return GetReputationMgr().GetRank(factionEntry); } //Calculate total reputation percent player gain with quest/creature level @@ -6310,7 +6303,7 @@ void Player::RewardReputation(Unit *pVictim, float rate) int32 donerep1 = CalculateReputationGain(REPUTATION_SOURCE_KILL, Rep->repvalue1, Rep->repfaction1, pVictim->getLevel()); donerep1 = int32(donerep1*rate); FactionEntry const *factionEntry1 = sFactionStore.LookupEntry(Rep->repfaction1); - uint32 current_reputation_rank1 = GetReputationMgr().GetRank(factionEntry1, false); + uint32 current_reputation_rank1 = GetReputationMgr().GetRank(factionEntry1); if (factionEntry1 && current_reputation_rank1 <= Rep->reputation_max_cap1) GetReputationMgr().ModifyReputation(factionEntry1, donerep1); @@ -6328,7 +6321,7 @@ void Player::RewardReputation(Unit *pVictim, float rate) int32 donerep2 = CalculateReputationGain(REPUTATION_SOURCE_KILL, Rep->repvalue2, Rep->repfaction2, pVictim->getLevel()); donerep2 = int32(donerep2*rate); FactionEntry const *factionEntry2 = sFactionStore.LookupEntry(Rep->repfaction2); - uint32 current_reputation_rank2 = GetReputationMgr().GetRank(factionEntry2, false); + uint32 current_reputation_rank2 = GetReputationMgr().GetRank(factionEntry2); if (factionEntry2 && current_reputation_rank2 <= Rep->reputation_max_cap2) GetReputationMgr().ModifyReputation(factionEntry2, donerep2); diff --git a/src/game/ReputationMgr.cpp b/src/game/ReputationMgr.cpp index 9813a5517..9b36bd20e 100644 --- a/src/game/ReputationMgr.cpp +++ b/src/game/ReputationMgr.cpp @@ -74,14 +74,8 @@ int32 ReputationMgr::GetReputation(FactionEntry const* factionEntry) const return 0; } -ReputationRank ReputationMgr::GetRank(FactionEntry const* factionEntry, bool withForcedReaction) const +ReputationRank ReputationMgr::GetRank(FactionEntry const* factionEntry) const { - if (withForcedReaction) - { - ForcedReactions::const_iterator find = m_forcedReactions.find(factionEntry->ID); - if (find != m_forcedReactions.end()) - return find->second; - } int32 reputation = GetReputation(factionEntry); return ReputationToRank(reputation); } @@ -286,7 +280,7 @@ bool ReputationMgr::SetReputation(FactionEntry const* factionEntry, int32 standi { if (FactionEntry const *factionEntryCalc = sFactionStore.LookupEntry(*itr)) { - if (factionEntryCalc == factionEntry || GetRank(factionEntryCalc, false) > ReputationRank(factionEntryCalc->spilloverMaxRankIn)) + if (factionEntryCalc == factionEntry || GetRank(factionEntryCalc) > ReputationRank(factionEntryCalc->spilloverMaxRankIn)) continue; int32 spilloverRep = int32(spillOverRepOut * factionEntryCalc->spilloverRateIn); if (spilloverRep != 0 || !incremental) @@ -492,11 +486,17 @@ void ReputationMgr::LoadFromDB(QueryResult *result) } // set atWar for hostile - if(GetRank(factionEntry, true) <= REP_HOSTILE) - SetAtWar(faction,true); + ForcedReactions::const_iterator forceItr = m_forcedReactions.find(factionEntry->ID); + if (forceItr != m_forcedReactions.end()) + { + if (forceItr->second <= REP_HOSTILE) + SetAtWar(faction, true); + } + else if (GetRank(factionEntry) <= REP_HOSTILE) + SetAtWar(faction, true); // reset changed flag if values similar to saved in DB - if(faction->Flags==dbFactionFlags) + if (faction->Flags == dbFactionFlags) { faction->needSend = false; faction->needSave = false; diff --git a/src/game/ReputationMgr.h b/src/game/ReputationMgr.h index 30fd6c8ae..303c371d8 100644 --- a/src/game/ReputationMgr.h +++ b/src/game/ReputationMgr.h @@ -93,7 +93,7 @@ class ReputationMgr int32 GetReputation(FactionEntry const* factionEntry) const; int32 GetBaseReputation(FactionEntry const* factionEntry) const; - ReputationRank GetRank(FactionEntry const* factionEntry, bool withForcedReaction) const; + ReputationRank GetRank(FactionEntry const* factionEntry) const; ReputationRank GetBaseRank(FactionEntry const* factionEntry) const; ReputationRank const* GetForcedRankIfAny(FactionTemplateEntry const* factionTemplateEntry) const diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 744d16bbe..949285a70 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -5419,38 +5419,42 @@ bool Unit::IsHostileTo(Unit const* unit) const } // faction base cases - FactionTemplateEntry const*tester_faction = tester->getFactionTemplateEntry(); - FactionTemplateEntry const*target_faction = target->getFactionTemplateEntry(); - if(!tester_faction || !target_faction) + FactionTemplateEntry const* tester_faction = tester->getFactionTemplateEntry(); + FactionTemplateEntry const* target_faction = target->getFactionTemplateEntry(); + if (!tester_faction || !target_faction) return false; - if(target->isAttackingPlayer() && tester->IsContestedGuard()) + if (target->isAttackingPlayer() && tester->IsContestedGuard()) return true; // PvC forced reaction and reputation case - if(tester->GetTypeId()==TYPEID_PLAYER) + if (tester->GetTypeId() == TYPEID_PLAYER) { - // forced reaction - if(target_faction->faction) + if (target_faction->faction) { - if(ReputationRank const* force =((Player*)tester)->GetReputationMgr().GetForcedRankIfAny(target_faction)) + // forced reaction + if (ReputationRank const* force =((Player*)tester)->GetReputationMgr().GetForcedRankIfAny(target_faction)) return *force <= REP_HOSTILE; // if faction have reputation then hostile state for tester at 100% dependent from at_war state - if(FactionEntry const* raw_target_faction = sFactionStore.LookupEntry(target_faction->faction)) - if(FactionState const* factionState = ((Player*)tester)->GetReputationMgr().GetState(raw_target_faction)) + if (FactionEntry const* raw_target_faction = sFactionStore.LookupEntry(target_faction->faction)) + if (FactionState const* factionState = ((Player*)tester)->GetReputationMgr().GetState(raw_target_faction)) return (factionState->Flags & FACTION_FLAG_AT_WAR); } } // CvP forced reaction and reputation case - else if (target->GetTypeId()==TYPEID_PLAYER) + else if (target->GetTypeId() == TYPEID_PLAYER) { if (tester_faction->faction) { + // forced reaction + if (ReputationRank const* force = ((Player*)unit)->GetReputationMgr().GetForcedRankIfAny(tester_faction)) + return *force <= REP_HOSTILE; + // apply reputation state FactionEntry const* raw_tester_faction = sFactionStore.LookupEntry(tester_faction->faction); - if (raw_tester_faction && raw_tester_faction->reputationListID >=0 ) - return ((Player const*)target)->GetReputationMgr().GetRank(raw_tester_faction, true) <= REP_HOSTILE; + if (raw_tester_faction && raw_tester_faction->reputationListID >= 0) + return ((Player const*)target)->GetReputationMgr().GetRank(raw_tester_faction) <= REP_HOSTILE; } } @@ -5529,36 +5533,40 @@ bool Unit::IsFriendlyTo(Unit const* unit) const // faction base cases FactionTemplateEntry const*tester_faction = tester->getFactionTemplateEntry(); FactionTemplateEntry const*target_faction = target->getFactionTemplateEntry(); - if(!tester_faction || !target_faction) + if (!tester_faction || !target_faction) return false; - if(target->isAttackingPlayer() && tester->IsContestedGuard()) + if (target->isAttackingPlayer() && tester->IsContestedGuard()) return false; // PvC forced reaction and reputation case - if(tester->GetTypeId()==TYPEID_PLAYER) + if (tester->GetTypeId() == TYPEID_PLAYER) { - // forced reaction - if(target_faction->faction) + if (target_faction->faction) { - if(ReputationRank const* force =((Player*)tester)->GetReputationMgr().GetForcedRankIfAny(target_faction)) + // forced reaction + if (ReputationRank const* force =((Player*)tester)->GetReputationMgr().GetForcedRankIfAny(target_faction)) return *force >= REP_FRIENDLY; // if faction have reputation then friendly state for tester at 100% dependent from at_war state - if(FactionEntry const* raw_target_faction = sFactionStore.LookupEntry(target_faction->faction)) - if(FactionState const* factionState = ((Player*)tester)->GetReputationMgr().GetState(raw_target_faction)) + if (FactionEntry const* raw_target_faction = sFactionStore.LookupEntry(target_faction->faction)) + if (FactionState const* factionState = ((Player*)tester)->GetReputationMgr().GetState(raw_target_faction)) return !(factionState->Flags & FACTION_FLAG_AT_WAR); } } // CvP forced reaction and reputation case - else if (target->GetTypeId()==TYPEID_PLAYER) + else if (target->GetTypeId() == TYPEID_PLAYER) { if (tester_faction->faction) { + // forced reaction + if (ReputationRank const* force =((Player*)unit)->GetReputationMgr().GetForcedRankIfAny(tester_faction)) + return *force >= REP_FRIENDLY; + // apply reputation state if (FactionEntry const* raw_tester_faction = sFactionStore.LookupEntry(tester_faction->faction)) if (raw_tester_faction->reputationListID >=0 ) - return ((Player const*)target)->GetReputationMgr().GetRank(raw_tester_faction, true) >= REP_FRIENDLY; + return ((Player const*)target)->GetReputationMgr().GetRank(raw_tester_faction) >= REP_FRIENDLY; } } diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index dc2f389f0..3b3f2a4b1 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "11891" + #define REVISION_NR "11892" #endif // __REVISION_NR_H__