Core/Player: Fixed interaction rules with dead creatures

This commit is contained in:
Shauren
2011-04-18 12:17:45 +02:00
parent 0d477ab132
commit 542bc3008d
3 changed files with 19 additions and 28 deletions
+18 -26
View File
@@ -2649,18 +2649,7 @@ void Player::ResetAllPowers()
}
}
bool Player::CanInteractWithNPCs(bool alive) const
{
if (alive && !isAlive())
return false;
if (isInFlight())
return false;
return true;
}
Creature*
Player::GetNPCIfCanInteractWith(uint64 guid, uint32 npcflagmask)
Creature* Player::GetNPCIfCanInteractWith(uint64 guid, uint32 npcflagmask)
{
// unit checks
if (!guid)
@@ -2669,43 +2658,46 @@ Player::GetNPCIfCanInteractWith(uint64 guid, uint32 npcflagmask)
if (!IsInWorld())
return NULL;
if (isInFlight())
return NULL;
// exist (we need look pets also for some interaction (quest/etc)
Creature *unit = ObjectAccessor::GetCreatureOrPetOrVehicle(*this,guid);
if (!unit)
Creature* creature = ObjectAccessor::GetCreatureOrPetOrVehicle(*this, guid);
if (!creature)
return NULL;
// player check
if (!CanInteractWithNPCs(!unit->isSpiritService()))
return NULL;
// appropriate npc type
if (npcflagmask && !unit->HasFlag(UNIT_NPC_FLAGS, npcflagmask))
// Deathstate checks
if (!isAlive() && !(creature->GetCreatureInfo()->type_flags & CREATURE_TYPEFLAGS_GHOST))
return NULL;
// alive or spirit healer
if (!unit->isAlive() && (!unit->isSpiritService() || isAlive()))
if (!creature->isAlive() && !(creature->GetCreatureInfo()->type_flags & CREATURE_TYPEFLAGS_DEAD_INTERACT))
return NULL;
// appropriate npc type
if (npcflagmask && !creature->HasFlag(UNIT_NPC_FLAGS, npcflagmask))
return NULL;
// not allow interaction under control, but allow with own pets
if (unit->GetCharmerGUID())
if (creature->GetCharmerGUID())
return NULL;
// not enemy
if (unit->IsHostileTo(this))
if (creature->IsHostileTo(this))
return NULL;
// not unfriendly
if (FactionTemplateEntry const* factionTemplate = sFactionTemplateStore.LookupEntry(unit->getFaction()))
if (FactionTemplateEntry const* factionTemplate = sFactionTemplateStore.LookupEntry(creature->getFaction()))
if (factionTemplate->faction)
if (FactionEntry const* faction = sFactionStore.LookupEntry(factionTemplate->faction))
if (faction->reputationListID >= 0 && GetReputationMgr().GetRank(faction) <= REP_UNFRIENDLY)
return NULL;
// not too far
if (!unit->IsWithinDistInMap(this,INTERACTION_DISTANCE))
if (!creature->IsWithinDistInMap(this, INTERACTION_DISTANCE))
return NULL;
return unit;
return creature;
}
GameObject* Player::GetGameObjectIfCanInteractWith(uint64 guid, GameobjectTypes type) const