[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 <schmoozerd@scriptdev2.com>
This commit is contained in:
Schmoozerd 2012-01-31 00:12:45 +01:00
parent 85309aa3c1
commit 6aab5c1022
8 changed files with 70 additions and 61 deletions

View file

@ -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;
}
}