bool TalkAction::ghost(Creature* creature, const std::string& cmd, const std::string& param)
{
Player* player = creature->getPlayer();
if(!player)
return false;
if(player->hasFlag(PlayerFlag_CannotBeSeen))
{
player->sendTextMessage(MSG_INFO_DESCR, "Command disabled for players with special, invisibility flag.");
return true;
}
SpectatorVec::iterator it;
SpectatorVec list = g_game.getSpectators(player->getPosition());
Player* tmpPlayer = NULL;
Condition* condition = NULL;
if((condition = player->getCondition(CONDITION_GAMEMASTER, CONDITIONID_DEFAULT, GAMEMASTER_INVISIBLE)))
{
player->sendTextMessage(MSG_INFO_DESCR, "You are visible again.");
IOLoginData::getInstance()->updateOnlineStatus(player->getGUID(), true);
Status::getInstance()->addPlayer();
for(AutoList<Player>::listiterator pit = Player::listPlayer.list.begin(); pit != Player::listPlayer.list.end(); ++pit)
{
if(!pit->second->canSeeCreature(player))
pit->second->notifyLogIn(player);
}
for(it = list.begin(); it != list.end(); ++it)
{
if((tmpPlayer = (*it)->getPlayer()) && !tmpPlayer->canSeeCreature(player))
tmpPlayer->sendMagicEffect(player->getPosition(), NM_ME_TELEPORT);
}
player->removeCondition(condition);
g_game.internalCreatureChangeVisible(creature, VISIBLE_GHOST_APPEAR);
}
else if((condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_GAMEMASTER, -1, 0, false, GAMEMASTER_INVISIBLE)))
{
player->addCondition(condition);
g_game.internalCreatureChangeVisible(creature, VISIBLE_GHOST_DISAPPEAR);
for(it = list.begin(); it != list.end(); ++it)
{
if((tmpPlayer = (*it)->getPlayer()) && !tmpPlayer->canSeeCreature(player))
tmpPlayer->sendMagicEffect(player->getPosition(), NM_ME_POFF);
}
for(AutoList<Player>::listiterator pit = Player::listPlayer.list.begin(); pit != Player::listPlayer.list.end(); ++pit)
{
if(!pit->second->canSeeCreature(player))
pit->second->notifyLogOut(player);
}
Status::getInstance()->removePlayer();
IOLoginData::getInstance()->updateOnlineStatus(player->getGUID(), false);
player->sendTextMessage(MSG_INFO_DESCR, "You are now invisible.");
}
return true;
}