本文整理汇总了C++中Creature::AddToWorld方法的典型用法代码示例。如果您正苦于以下问题:C++ Creature::AddToWorld方法的具体用法?C++ Creature::AddToWorld怎么用?C++ Creature::AddToWorld使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Creature
的用法示例。
在下文中一共展示了Creature::AddToWorld方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleAddSpwCommand
bool ChatHandler::HandleAddSpwCommand(const char* args)
{
char* charID = strtok((char*)args, " ");
if (!charID)
return false;
uint32 id = atoi(charID);
Player *chr = m_session->GetPlayer();
float x = chr->GetPositionX();
float y = chr->GetPositionY();
float z = chr->GetPositionZ();
float o = chr->GetOrientation();
Creature* pCreature = new Creature(chr);
if (!pCreature->Create(objmgr.GenerateLowGuid(HIGHGUID_UNIT), chr->GetMapId(), x, y, z, o, id))
{
delete pCreature;
return false;
}
pCreature->SaveToDB();
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
pCreature->LoadFromDB(pCreature->GetGUIDLow(), NULL, chr->GetInstanceId());
pCreature->AddToWorld();
MapManager::Instance().GetMap(pCreature->GetMapId(), pCreature)->Add(pCreature);
sLog.outDebug(LANG_ADD_OBJ);
return true;
}
示例2: AddNPCPassenger
uint32 Transporter::AddNPCPassenger(uint32 tguid, uint32 entry, float x, float y, float z, float o, uint32 anim)
{
MapMgr* map = GetMapMgr();
CreatureProperties const* creature_properties = sMySQLStore.getCreatureProperties(entry);
if (creature_properties == nullptr || map == nullptr)
return 0;
#if VERSION_STRING != Cata
float transporter_x = obj_movement_info.transport_data.relativePosition.x + x;
float transporter_y = obj_movement_info.transport_data.relativePosition.y + y;
float transporter_z = obj_movement_info.transport_data.relativePosition.z + z;
#else
float transporter_x = obj_movement_info.getTransportPosition()->x + x;
float transporter_y = obj_movement_info.getTransportPosition()->y + y;
float transporter_z = obj_movement_info.getTransportPosition()->z + z;
#endif
Creature* pCreature = map->CreateCreature(entry);
pCreature->Create(map->GetMapId(), transporter_x, transporter_y, transporter_z, (std::atan2(transporter_x, transporter_y) + float(M_PI)) + o);
pCreature->Load(creature_properties, transporter_x, transporter_y, transporter_z, (std::atan2(transporter_x, transporter_y) + float(M_PI)) + o);
pCreature->AddToWorld(map);
pCreature->SetUnitMovementFlags(MOVEFLAG_TRANSPORT);
#if VERSION_STRING != Cata
pCreature->obj_movement_info.transport_data.relativePosition.x = x;
pCreature->obj_movement_info.transport_data.relativePosition.y = y;
pCreature->obj_movement_info.transport_data.relativePosition.z = z;
pCreature->obj_movement_info.transport_data.relativePosition.o = o;
pCreature->obj_movement_info.transport_data.transportGuid = getGuid();
#else
pCreature->obj_movement_info.setTransportData(getGuid(), x, y, z, o, 0, 0);
#endif
pCreature->m_transportData.transportGuid = this->getGuid();
pCreature->m_transportData.relativePosition.x = x;
pCreature->m_transportData.relativePosition.y = y;
pCreature->m_transportData.relativePosition.z = z;
pCreature->m_transportData.relativePosition.o = o;
if (anim)
pCreature->setUInt32Value(UNIT_NPC_EMOTESTATE, anim);
if (creature_properties->NPCFLags)
pCreature->setUInt32Value(UNIT_NPC_FLAGS, creature_properties->NPCFLags);
m_creatureSetMutex.Acquire();
m_NPCPassengerSet.insert(pCreature);
m_creatureSetMutex.Release();
if (tguid == 0)
{
++currenttguid;
tguid = currenttguid;
}
else
currenttguid = std::max(tguid, currenttguid);
return tguid;
}
示例3: AddNPCPassengerInInstance
Creature* Transporter::AddNPCPassengerInInstance(uint32 entry, float x, float y, float z, float o, uint32 /*anim*/)
{
MapMgr* map = GetMapMgr();
CreatureProperties const* creature_properties = sMySQLStore.getCreatureProperties(entry);
if (creature_properties == nullptr || map == nullptr)
return nullptr;
#if VERSION_STRING != Cata
float transporter_x = obj_movement_info.transport_data.relativePosition.x + x;
float transporter_y = obj_movement_info.transport_data.relativePosition.y + y;
float transporter_z = obj_movement_info.transport_data.relativePosition.z + z;
#else
float transporter_x = obj_movement_info.getTransportPosition()->x + x;
float transporter_y = obj_movement_info.getTransportPosition()->y + y;
float transporter_z = obj_movement_info.getTransportPosition()->z + z;
#endif
Creature* pCreature = map->CreateCreature(entry);
pCreature->Create(map->GetMapId(), transporter_x, transporter_y, transporter_z, (std::atan2(transporter_x, transporter_y) + float(M_PI)) + o);
pCreature->Load(creature_properties, transporter_x, transporter_y, transporter_z, (std::atan2(transporter_x, transporter_y) + float(M_PI)) + o);
pCreature->AddToWorld(map);
pCreature->SetUnitMovementFlags(MOVEFLAG_TRANSPORT);
#if VERSION_STRING != Cata
pCreature->obj_movement_info.transport_data.relativePosition.x = x;
pCreature->obj_movement_info.transport_data.relativePosition.y = y;
pCreature->obj_movement_info.transport_data.relativePosition.z = z;
pCreature->obj_movement_info.transport_data.relativePosition.o = o;
pCreature->obj_movement_info.transport_data.transportGuid = getGuid();
#else
pCreature->obj_movement_info.setTransportData(getGuid(), x, y, z, o, 0, 0);
#endif
pCreature->m_transportData.transportGuid = this->getGuid();
pCreature->m_transportData.relativePosition.x = x;
pCreature->m_transportData.relativePosition.y = y;
pCreature->m_transportData.relativePosition.z = z;
pCreature->m_transportData.relativePosition.o = o;
m_creatureSetMutex.Acquire();
m_NPCPassengerSet.insert(pCreature);
m_creatureSetMutex.Release();
return pCreature;
}
示例4: Creature
void
Spell::Effect_Summon_Pet(uint32 i)
{
WorldPacket data;
if(m_caster->GetUInt64Value(UNIT_FIELD_SUMMON) != 0)//If there is already a summon
{
Creature *OldSummon = objmgr.GetObject<Creature>(m_caster->GetUInt64Value(UNIT_FIELD_SUMMON));
if(!OldSummon)
{
m_caster->SetUInt64Value(UNIT_FIELD_SUMMON, 0);
sLog.outError("Warning!Old Summon could not be found!");
} else {
data.clear();
data.Initialize(SMSG_DESTROY_OBJECT);
data << OldSummon->GetGUID();
OldSummon->SendMessageToSet (&data, true);
if (OldSummon->GetMapCell())
OldSummon->GetMapCell()->RemoveObject (OldSummon);
OldSummon->RemoveFromMap();
OldSummon->RemoveFromWorld();
OldSummon->DeleteFromDB();
objmgr.RemoveObject_Free(OldSummon);
}
}
//Create new summon
Creature *NewSummon = new Creature();
CreatureTemplate *SummonInfo = objmgr.GetCreatureTemplate(m_spellInfo->EffectMiscValue[i]);
if(SummonInfo == NULL)
{
sLog.outError("No Minion found for CreatureTemplate %u", m_spellInfo->EffectMiscValue[i]);
return;
}
NewSummon->Create(objmgr.GenerateLowGuid(HIGHGUID_UNIT), SummonInfo->Name.c_str(), m_caster->GetMapId(), m_caster->GetPositionX(), m_caster->GetPositionY(), m_caster->GetPositionZ(), m_caster->GetOrientation());
NewSummon->SetLevel(m_caster->GetLevel());
NewSummon->SetUInt32Value(UNIT_FIELD_DISPLAYID, SummonInfo->Model);
NewSummon->SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, SummonInfo->Model);
NewSummon->SetUInt64Value(UNIT_FIELD_SUMMONEDBY, m_caster->GetGUID());
NewSummon->SetUInt32Value(UNIT_NPC_FLAGS , 0);
NewSummon->SetUInt32Value(UNIT_FIELD_HEALTH , 28 + 30 * m_caster->GetLevel());
NewSummon->SetUInt32Value(UNIT_FIELD_MAXHEALTH , 28 + 30 * m_caster->GetLevel());
NewSummon->SetFaction(m_caster->GetFaction());
NewSummon->SetScale( SummonInfo->Size );
NewSummon->SetUInt32Value(UNIT_FIELD_BYTES_0,2048);
NewSummon->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NONE);
NewSummon->SetUInt32Value(UNIT_FIELD_BASEATTACKTIME, SummonInfo->Attack[0]);
NewSummon->SetUInt32Value(UNIT_FIELD_BASEATTACKTIME+1, SummonInfo->Attack[1]);
NewSummon->SetUInt32Value(UNIT_FIELD_BOUNDINGRADIUS, SummonInfo->BoundingRadius);
NewSummon->SetUInt32Value(UNIT_FIELD_COMBATREACH, SummonInfo->CombatReach);
NewSummon->SetMinDamage((float)SummonInfo->Damage[0]);
NewSummon->SetMaxDamage((float)SummonInfo->Damage[1]);
NewSummon->SetUInt32Value(UNIT_FIELD_BYTES_1,0);
NewSummon->SetUInt32Value(UNIT_FIELD_PETNUMBER, NewSummon->GetGUIDLow());
NewSummon->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP,5);
NewSummon->SetUInt32Value(UNIT_FIELD_PETEXPERIENCE,0);
NewSummon->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP,1000);
NewSummon->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
NewSummon->SetUInt32Value(UNIT_FIELD_STAT0,22);
NewSummon->SetUInt32Value(UNIT_FIELD_STAT1,22); //////////TODO: GET THE RIGHT INFORMATIONS FOR THIS!!!
NewSummon->SetUInt32Value(UNIT_FIELD_STAT2,25);
NewSummon->SetUInt32Value(UNIT_FIELD_STAT3,28);
NewSummon->SetUInt32Value(UNIT_FIELD_STAT4,27);
NewSummon->SetUInt32Value(UNIT_FIELD_RESISTANCES+0,0);
NewSummon->SetUInt32Value(UNIT_FIELD_RESISTANCES+1,0);
NewSummon->SetUInt32Value(UNIT_FIELD_RESISTANCES+2,0);
NewSummon->SetUInt32Value(UNIT_FIELD_RESISTANCES+3,0);
NewSummon->SetUInt32Value(UNIT_FIELD_RESISTANCES+4,0);
NewSummon->SetUInt32Value(UNIT_FIELD_RESISTANCES+5,0);
NewSummon->SetUInt32Value(UNIT_FIELD_RESISTANCES+6,0);
NewSummon->SetUInt32Value(UNIT_FIELD_ATTACK_POWER,24);
NewSummon->SetUInt32Value(UNIT_FIELD_BASE_MANA, SummonInfo->MaxMana);
NewSummon->SetUInt32Value(OBJECT_FIELD_ENTRY, SummonInfo->Entry);
NewSummon->SetPosition(m_caster->GetPositionX(), m_caster->GetPositionY(), m_caster->GetPositionZ(), m_caster->GetOrientation());
NewSummon->SetZoneId(m_caster->GetZoneId());
NewSummon->SaveToDB();
objmgr.AddObject( NewSummon );
NewSummon->PlaceOnMap();
NewSummon->AddToWorld();
m_caster->SetUInt64Value(UNIT_FIELD_SUMMON, NewSummon->GetGUID());
sLog.outDebug("New Pet has guid %u", NewSummon->GetGUID());
if(objmgr.GetObject<Player>(m_caster->GetGUID()) )//if the caster is a player
{
data.clear();
data.Initialize(SMSG_PET_SPELLS);
data << (uint64)NewSummon->GetGUID() << uint32(0x00000101) << uint32(0x00000000) << uint32(0x07000001) << uint32(0x07000002);
data << uint32(0x02000000) << uint32(0x07000000) << uint32(0x04000000) << uint32(0x03000000) << uint32(0x06000002) << uint32(0x05000000);
data << uint32(0x06000000) << uint32(0x06000001) << uint8(0x02)/*Number of spells*/ << uint32(3110)/*SpellID1*/ << uint32(6307)/*SpellID2*/;
((Player*)m_caster)->GetSession()->SendPacket(&data);
}
}
示例5: ProcessObjectsAndScriptsProc
//.........这里部分代码省略.........
// get mapmgr for spawn
MapMgr * mgr = sInstanceMgr.GetMapMgr(mapid);
if(mgr == NULL)
{
// So this is a really interesting situation!
Log.Success("GameEvent","Failed to spawn creature spawn %u for event %u on nonexistant map %u", spawn.id, id, mapid);
continue;
}
// spawn the creature
//Creature * crt = mgr->GetInterface()->SpawnCreature(&spawn, true);
Creature * crt = mgr->CreateCreature(spawn.entry);
if(crt == NULL)
{
// we didnt succeed creating the creature! Print a warning and go on
Log.Success("GameEvent","Failed to spawn creature spawn %u for event %u", spawn.id, id);
continue;
}
crt->Load(&spawn, 0, mgr->GetMapInfo());
crt->spawnid = 0;
crt->m_spawn = NULL;
// add waypoints
crt->m_custom_waypoint_map = new WayPointMap();
for(std::list<WayPoint *>::iterator itr = waypoints[id][spawn_id].begin(); itr != waypoints[id][spawn_id].end(); itr++)
{
// use custom waypoint map, so we avoid saving it to database
crt->m_custom_waypoint_map->push_back(*itr);
}
crt->GetAIInterface()->SetWaypointMap(crt->m_custom_waypoint_map);
crt->AddToWorld(mgr);
m_creaturespawns[id][mapid].push_back(crt->GetUIdFromGUID());
}
while(query->NextRow());
}
// gameobject spawns
if(QueryResult *query = results[3].result)
{
do
{
Field * f = query->Fetch();
GOSpawn spawn;
//uint32 event = f[0].GetUInt32();
uint32 spawn_id = f[1].GetUInt32();
// generate new ingame sql id
spawn.id = /*objmgr.GenerateCreatureSpawnID()*/0;
spawn.entry = f[2].GetUInt32();
uint32 mapid = f[3].GetUInt32();
spawn.x = f[4].GetFloat();
spawn.y = f[5].GetFloat();
spawn.z = f[6].GetFloat();
spawn.facing = f[7].GetFloat();
spawn.o = f[8].GetFloat();
spawn.o1 = f[9].GetFloat();
spawn.o2 = f[10].GetFloat();
spawn.o3 = f[11].GetFloat();
spawn.state = f[12].GetUInt32();
spawn.flags = f[13].GetUInt32();
spawn.faction = f[14].GetUInt32();
spawn.scale = f[15].GetFloat();