Exemple #1
0
bool ChatHandler::HandleDeleteCommand(const char* args, WorldSession *m_session)
{
    Creature* unit = getSelectedCreature(m_session, false);
    if(!unit)
    {
        SystemMessage(m_session, "You should select a creature.");
        return true;
    }
    else if(unit->IsPet() || unit->IsSummon())
    {
        SystemMessage(m_session, "You can't delete playerpets.");
        return true;
    }

    if( unit->m_spawn != NULL && !m_session->CanUseCommand('z') )
    {
        SystemMessage(m_session, "You do not have permission to do that. Please contact higher staff for removing of saved spawns.");
        return true;
    }

    if(unit->IsVehicle())
    {
        Vehicle* veh = TO_VEHICLE(unit);
        for(int i = 0; i < 8; i++)
        {
            if(!veh->GetPassenger(i))
                continue;

            // Remove any players
            if(veh->GetPassenger(i)->IsPlayer())
                veh->RemovePassenger(veh->GetPassenger(i));
            else // Remove any units.
                veh->GetPassenger(i)->RemoveFromWorld(true);
        }
    }

    sWorld.LogGM(m_session, "used npc delete, sqlid %u, creature %s, pos %f %f %f",
                 unit->m_spawn ? unit->m_spawn->id : 0, unit->GetCreatureInfo() ? unit->GetCreatureInfo()->Name : "wtfbbqhax", unit->GetPositionX(), unit->GetPositionY(),
                 unit->GetPositionZ());

    BlueSystemMessage(m_session, "Deleted creature ID %u", unit->spawnid);

    unit->DeleteFromDB();

    if(!unit->IsInWorld())
        return true;

    MapMgr* unitMgr = unit->GetMapMgr();
    if(unit->m_spawn)
    {
        uint32 cellx = unitMgr->GetPosX(unit->m_spawn->x);
        uint32 celly = unitMgr->GetPosX(unit->m_spawn->y);
        if(cellx <= _sizeX && celly <= _sizeY )
        {
            CellSpawns *c = unitMgr->GetBaseMap()->GetSpawnsList(cellx, celly);
            if( c != NULL )
            {
                CreatureSpawnList::iterator itr, itr2;
                for(itr = c->CreatureSpawns.begin(); itr != c->CreatureSpawns.end();)
                {
                    itr2 = itr++;
                    if((*itr2) == unit->m_spawn)
                    {
                        c->CreatureSpawns.erase(itr2);
                        delete unit->m_spawn;
                        break;
                    }
                }
            }
        }
    }
    unit->RemoveFromWorld(false, true);

    if(unit->IsVehicle())
        TO_VEHICLE(unit)->Destruct();
    else
        unit->Destruct();

    m_session->GetPlayer()->SetSelection(NULL);
    return true;
}