コード例 #1
0
ファイル: SpellHandler.cpp プロジェクト: gc/mangos
void WorldSession::HandleSpellClick( WorldPacket & recv_data )
{
    ObjectGuid guid;
    recv_data >> guid;

    Creature *unit = _player->GetMap()->GetAnyTypeCreature(guid);
    if (!unit)
        return;

    if (_player->isInCombat() && !guid.IsVehicle())                              // client prevent click and set different icon at combat state
        return;

    if(guid.IsVehicle() && _player->GetVehicleKit())
        _player->RemoveVehicleKit();

    SpellClickInfoMapBounds clickPair = sObjectMgr.GetSpellClickInfoMapBounds(unit->GetEntry());
    for(SpellClickInfoMap::const_iterator itr = clickPair.first; itr != clickPair.second; ++itr)
    {
        if (itr->second.IsFitToRequirements(_player))
        {
            Unit *caster = (itr->second.castFlags & 0x1) ? (Unit*)_player : (Unit*)unit;
            Unit *target = (itr->second.castFlags & 0x2) ? (Unit*)_player : (Unit*)unit;

            if(itr->second.castFlags & 0x4)
            {
                unit->SetDeathState(JUST_DIED);
                unit->RemoveCorpse();
                unit->SetHealth(0);
            }

            caster->CastSpell(target, itr->second.spellId, true, NULL, NULL,caster->GetObjectGuid());
        }
    }

    if (unit->GetObjectGuid().IsVehicle())
    {
        _player->EnterVehicle(unit->GetVehicleKit());
    }
}
コード例 #2
0
ファイル: PetHandler.cpp プロジェクト: Tasssadar/catcore
void WorldSession::SendPetNameQuery( ObjectGuid petguid, uint32 petnumber)
{
    //Client asks for data before add to map (or we have wrong teleport sequence), so we cant use GetCreatureOrPetOrVehicle()
    Creature* pet = NULL;
    
    if(_player->IsBeingTeleported())
    {
        Map *map = sMapMgr.FindMap(_player->GetTeleportDest().mapid);
        if(map)
        {
            if (petguid.IsPet())
                pet = map->GetPet(petguid);
            else if(petguid.IsVehicle())
                pet = (Creature*)map->GetVehicle(petguid);
            else
                pet = map->GetCreature(petguid);
        }
    }
    else
        pet = ObjectAccessor::GetCreatureOrPetOrVehicle(*_player, petguid);

    if (!pet || !pet->GetCharmInfo() || pet->GetCharmInfo()->GetPetNumber() != petnumber)
    {
        std::string name = "NoPetName";

        WorldPacket data(SMSG_PET_NAME_QUERY_RESPONSE, (4+4+name.size()+1));
        data << uint32(petnumber);
        data << name.c_str();
        data << uint32(time(0));
        data << uint8(0);

        _player->GetSession()->SendPacket(&data);

        // looking for errors
     /*   if (!pet)
            sLog.outError("SendPetNameQuery:: Pet not found, not exist or not in world"); <-------
        else if (!pet->GetCharmInfo())
            sLog.outError("SendPetNameQuery:: Pet CharmInfo() not found");
        else if (pet->GetCharmInfo()->GetPetNumber() != petnumber)
            sLog.outError("SendPetNameQuery:: Pet number is not equal to requested petnumber"); */
        return;
    }

    std::string name = pet->GetName();

    WorldPacket data(SMSG_PET_NAME_QUERY_RESPONSE, (4+4+name.size()+1));
    data << uint32(petnumber);
    data << name.c_str();
    data << uint32(pet->GetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP));

    if ( pet->isPet() && ((Pet*)pet)->GetDeclinedNames() )
    {
        data << uint8(1);
        for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
            data << ((Pet*)pet)->GetDeclinedNames()->name[i];
    }
    else
        data << uint8(0);

    _player->GetSession()->SendPacket(&data);
}