Skip to content

Commit

Permalink
[c12861] Implement condition CREATURE_IN_RANGE
Browse files Browse the repository at this point in the history
Will return TRUE if any alive creature of given entry in the selected range is found.
This is useful for gossip or quest conditions that must avoid double spawning a certain creature
Part of #409

(based on commit [12660] - 401d33d)

Signed-off-by: Xfurry <xfurry@scriptdev2.com>
  • Loading branch information
xfurry committed Aug 12, 2014
1 parent b2afcd7 commit 5936ff6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/game/ObjectMgr.cpp
Expand Up @@ -47,6 +47,9 @@
#include "InstanceData.h"
#include "DB2Structure.h"
#include "DB2Stores.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "CellImpl.h"

#include <limits>

Expand Down Expand Up @@ -8356,6 +8359,16 @@ bool PlayerCondition::Meets(Player const* player, Map const* map, WorldObject co
case 3: // Creature source is dead
return !source || source->GetTypeId() != TYPEID_UNIT || !((Unit*)source)->isAlive();
}
case CONDITION_CREATURE_IN_RANGE:
{
Creature* creature = NULL;

MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck creature_check(*player, m_value1, true, false, m_value2, true);
MaNGOS::CreatureLastSearcher<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck> searcher(creature, creature_check);
Cell::VisitGridObjects(player, searcher, m_value2);

return creature;
}
default:
return false;
}
Expand Down Expand Up @@ -8811,6 +8824,19 @@ bool PlayerCondition::IsValid(uint16 entry, ConditionType condition, uint32 valu
}
break;
}
case CONDITION_CREATURE_IN_RANGE:
{
if (!sCreatureStorage.LookupEntry<CreatureInfo> (value1))
{
sLog.outErrorDb("Creature in range condition (entry %u, type %u) has an invalid value in value1. (Creature %u does not exist in the database), skipping.", entry, condition, value1);
return false;
}
if (value2 <= 0)
{
sLog.outErrorDb("Creature in range condition (entry %u, type %u) has an invalid value in value2. (Range %u must be greater than 0), skipping.", entry, condition, value2);
return false;
}
}
case CONDITION_NONE:
break;
default:
Expand Down
1 change: 1 addition & 0 deletions src/game/ObjectMgr.h
Expand Up @@ -414,6 +414,7 @@ enum ConditionType
CONDITION_GENDER = 35, // 0=male, 1=female, 2=none (see enum Gender)
CONDITION_DEAD_OR_AWAY = 36, // value1: 0=player dead, 1=player is dead (with group dead), 2=player in instance are dead, 3=creature is dead
// value2: if != 0 only consider players in range of this value
CONDITION_CREATURE_IN_RANGE = 37, // value1: creature entry; value2: range; returns only alive creatures
};

enum ConditionSource // From where was the condition called?
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "12860"
#define REVISION_NR "12861"
#endif // __REVISION_NR_H__

0 comments on commit 5936ff6

Please sign in to comment.