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
-1
View File
@@ -1082,7 +1082,6 @@ class Player : public Unit, public GridObject<Player>
void SendInstanceResetWarning(uint32 mapid, Difficulty difficulty, uint32 time);
Creature* GetNPCIfCanInteractWith(uint64 guid, uint32 npcflagmask);
bool CanInteractWithNPCs(bool alive = true) const;
GameObject* GetGameObjectIfCanInteractWith(uint64 guid, GameobjectTypes type) const;
bool ToggleAFK();
@@ -2154,7 +2154,7 @@ enum CreatureTypeFlags
CREATURE_TYPEFLAGS_UNK5 = 0x000010,
CREATURE_TYPEFLAGS_UNK6 = 0x000020,
CREATURE_TYPEFLAGS_UNK7 = 0x000040,
CREATURE_TYPEFLAGS_UNK8 = 0x000080,
CREATURE_TYPEFLAGS_DEAD_INTERACT = 0x000080, // Player can interact with the creature if its dead (not player dead)
CREATURE_TYPEFLAGS_HERBLOOT = 0x000100, // Can be looted by herbalist
CREATURE_TYPEFLAGS_MININGLOOT = 0x000200, // Can be looted by miner
CREATURE_TYPEFLAGS_UNK11 = 0x000400,