[c12606] Implement CONDITION_DEAD_OR_AWAY

This commit is contained in:
Schmoozerd 2013-05-31 11:44:08 +01:00 committed by Antz
parent 12ee7b95ea
commit ad7d7dad1a
3 changed files with 68 additions and 1 deletions

View file

@ -8100,6 +8100,37 @@ bool PlayerCondition::Meets(Player const* player, Map const* map, WorldObject co
} }
case CONDITION_GENDER: case CONDITION_GENDER:
return player->getGender() == m_value1; return player->getGender() == m_value1;
case CONDITION_DEAD_OR_AWAY:
switch (m_value1)
{
case 0: // Player dead or out of range
return !player || !player->isAlive() || (m_value2 && source && !source->IsWithinDistInMap(player, m_value2));
case 1: // All players in Group dead or out of range
if (!player)
return true;
if (Group const* grp = player->GetGroup())
{
for (GroupReference const* itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
{
Player const* pl = itr->getSource();
if (pl && pl->isAlive() && !pl->isGameMaster() && (!m_value2 || !source || source->IsWithinDistInMap(pl, m_value2)))
return false;
}
return true;
}
else
return !player->isAlive() || (m_value2 && source && !source->IsWithinDistInMap(player, m_value2));
case 2: // All players in instance dead or out of range
for (Map::PlayerList::const_iterator itr = map->GetPlayers().begin(); itr != map->GetPlayers().end(); ++itr)
{
Player const* plr = itr->getSource();
if (plr && plr->isAlive() && !plr->isGameMaster() && (!m_value2 || !source || source->IsWithinDistInMap(plr, m_value2)))
return false;
}
return true;
case 3: // Creature source is dead
return !source || source->GetTypeId() != TYPEID_UNIT || !((Unit*)source)->isAlive();
}
default: default:
return false; return false;
} }
@ -8147,6 +8178,31 @@ bool PlayerCondition::CheckParamRequirements(Player const* pPlayer, Map const* m
return false; return false;
} }
break; break;
case CONDITION_DEAD_OR_AWAY:
switch (m_value1)
{
case 0: // Player dead or out of range
case 1: // All players in Group dead or out of range
case 2: // All players in instance dead or out of range
if (m_value2 && !source)
{
sLog.outErrorDb("CONDITION_DEAD_OR_AWAY %u - called from %s without source, but source expected for range check", m_entry, conditionSourceToStr[conditionSourceType]);
return false;
}
if (m_value1 != 2)
return true;
// Case 2 (Instance map only)
if (!map && (pPlayer || source))
map = source ? source->GetMap() : pPlayer->GetMap();
if (!map || !map->Instanceable())
{
sLog.outErrorDb("CONDITION_DEAD_OR_AWAY %u (Player in instance case) - called from %s without map param or from non-instanceable map %i", m_entry, conditionSourceToStr[conditionSourceType], map ? map->GetId() : -1);
return false;
}
case 3: // Creature source is dead
return true;
}
break;
default: default:
if (!pPlayer) if (!pPlayer)
{ {
@ -8521,6 +8577,15 @@ bool PlayerCondition::IsValid(uint16 entry, ConditionType condition, uint32 valu
} }
break; break;
} }
case CONDITION_DEAD_OR_AWAY:
{
if (value1 >= 4)
{
sLog.outErrorDb("Dead condition (entry %u, type %u) has an invalid value in value1. (Has %u, must be smaller than 4), skipping.", entry, condition, value1);
return false;
}
break;
}
case CONDITION_NONE: case CONDITION_NONE:
break; break;
default: default:

View file

@ -406,6 +406,8 @@ enum ConditionType
CONDITION_LAST_WAYPOINT = 33, // waypointId 0 = exact, 1: wp <= waypointId, 2: wp > waypointId Use to check what waypoint was last reached CONDITION_LAST_WAYPOINT = 33, // waypointId 0 = exact, 1: wp <= waypointId, 2: wp > waypointId Use to check what waypoint was last reached
CONDITION_XP_USER = 34, // 0, 1 (0: XP off, 1: XP on) for player 0 CONDITION_XP_USER = 34, // 0, 1 (0: XP off, 1: XP on) for player 0
CONDITION_GENDER = 35, // 0=male, 1=female, 2=none (see enum Gender) 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
}; };
enum ConditionSource // From where was the condition called? enum ConditionSource // From where was the condition called?

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "12605" #define REVISION_NR "12606"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__