[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:
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:
return false;
}
@ -8147,6 +8178,31 @@ bool PlayerCondition::CheckParamRequirements(Player const* pPlayer, Map const* m
return false;
}
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:
if (!pPlayer)
{
@ -8521,6 +8577,15 @@ bool PlayerCondition::IsValid(uint16 entry, ConditionType condition, uint32 valu
}
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:
break;
default: