Creature* BattleGround::AddCreature(uint32 entry, uint32 type, uint32 teamval, float x, float y, float z, float o) { // note: this should normally be FindMap // but it's a hack to allow the battlegrounds to initialize at server startup Map * map = MapManager::Instance().GetMap(GetMapId(), 0); if(!map) return NULL; Creature* pCreature = new Creature; if (!pCreature->Create(objmgr.GenerateLowGuid(HIGHGUID_UNIT), map, entry, teamval)) { sLog.outError("Can't create creature entry: %u",entry); delete pCreature; return NULL; } pCreature->Relocate(x, y, z, o); if(!pCreature->IsPositionValid()) { sLog.outError("ERROR: Creature (guidlow %d, entry %d) not added to battleground. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature->GetGUIDLow(),pCreature->GetEntry(),pCreature->GetPositionX(),pCreature->GetPositionY()); return NULL; } pCreature->AIM_Initialize(); //pCreature->SetDungeonDifficulty(0); map->Add(pCreature); m_BgCreatures[type] = pCreature->GetGUID(); return pCreature; }
bool HomeMovementGenerator<Creature>::Update(Creature &owner, const uint32& time_diff) { CreatureTraveller traveller( owner); if (i_destinationHolder.UpdateTraveller(traveller, time_diff, false)) { if (!IsActive(owner)) // force stop processing (movement can move out active zone with cleanup movegens list) return true; // not expire now, but already lost } if (time_diff > i_travel_time) { owner.AddSplineFlag(SPLINEFLAG_WALKMODE); // restore orientation of not moving creature at returning to home if (owner.GetDefaultMovementType() == IDLE_MOTION_TYPE) { // such a mob might need very exact spawning point, hence relocate to spawn-position if (CreatureData const* data = sObjectMgr.GetCreatureData(owner.GetGUIDLow())) { owner.Relocate(data->posX, data->posY, data->posZ, data->orientation); owner.SendHeartBeat(false); } } owner.LoadCreatureAddon(true); owner.AI()->JustReachedHome(); return false; } i_travel_time -= time_diff; return true; }
Creature* Transport::AddNPCPassengerInInstance (uint32 entry, float x, float y, float z, float o, uint32 anim) { Map* map = GetMap(); Creature* pCreature = new Creature; if (!pCreature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, GetPhaseMask(), entry, 0, GetGOInfo()->faction, 0, 0, 0, 0)) { delete pCreature; return NULL; } pCreature->SetTransport(this); pCreature->AddUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT); pCreature->m_movementInfo.guid = GetGUID(); pCreature->m_movementInfo.t_pos.Relocate(x, y, z, o); o += GetOrientation(); MapManager::NormalizeOrientation(o); pCreature->Relocate(GetPositionX() + (x * cos(GetOrientation()) + y * sin(GetOrientation() + float(M_PI))), GetPositionY() + (y * cos(GetOrientation()) + x * sin(GetOrientation())), z + GetPositionZ(), o); if (!pCreature->IsPositionValid()) { sLog->outError("Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)", pCreature->GetGUIDLow(), pCreature->GetEntry(), pCreature->GetPositionX(), pCreature->GetPositionY()); delete pCreature; return NULL; } map->Add(pCreature); m_NPCPassengerSet.insert(pCreature); pCreature->setActive(true); sScriptMgr->OnAddCreaturePassenger(this, pCreature); return pCreature; }
Creature* BattleGround::AddCreature(uint32 entry, uint32 type, uint32 teamval, float x, float y, float z, float o, uint32 respawntime) { Map * map = MapManager::Instance().FindMap(GetMapId(),GetInstanceID()); if(!map) return NULL; Creature* pCreature = new Creature; if (!pCreature->Create(objmgr.GenerateLowGuid(HIGHGUID_UNIT), map, entry, teamval)) { sLog.outError("Can't create creature entry: %u",entry); delete pCreature; return NULL; } pCreature->Relocate(x, y, z, o); if(!pCreature->IsPositionValid()) { sLog.outError("ERROR: Creature (guidlow %d, entry %d) not added to battleground. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature->GetGUIDLow(),pCreature->GetEntry(),pCreature->GetPositionX(),pCreature->GetPositionY()); return NULL; } pCreature->SetHomePosition(x, y, z, o); pCreature->AIM_Initialize(); map->Add(pCreature); m_BgCreatures[type] = pCreature->GetGUID(); return pCreature; }
bool OutdoorPvPObjective::AddCreature(uint32 type, uint32 entry, uint32 teamval, uint32 map, float x, float y, float z, float o, uint32 spawntimedelay) { Map * pMap = MapManager::Instance().FindMap(map); if (!pMap) return false; Creature* pCreature = new Creature; if (!pCreature->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT), pMap, PHASEMASK_NORMAL, entry, teamval)) { sLog.outError("OutdoorPvP: Can't create creature entry: %u",entry); delete pCreature; return false; } pCreature->Relocate(x, y, z, o); if (!pCreature->IsPositionValid()) { sLog.outError("OutdoorPvP: Creature (guidlow %d, entry %d) not added. Suggested coordinates isn't valid (X: %f Y: %f)", pCreature->GetGUIDLow(), pCreature->GetEntry(), pCreature->GetPositionX(), pCreature->GetPositionY()); delete pCreature; return false; } pCreature->AIM_Initialize(); if(spawntimedelay) pCreature->SetRespawnDelay(spawntimedelay); m_Creatures[type] = MAKE_NEW_GUID(pCreature->GetGUID(), entry, HIGHGUID_UNIT); m_CreatureTypes[m_Creatures[type]] = type; pMap->Add(pCreature); return true; }
uint32 Transport::AddNPCPassenger(uint32 tguid, uint32 entry, float x, float y, float z, float o, uint32 anim) { Map* map = GetMap(); CreatureInfo const *ci = sObjectMgr.GetCreatureTemplate(entry); if (!ci) return 0; Creature* pCreature = NULL; if(ci->ScriptID) pCreature = sScriptMgr.GetCreatureScriptedClass(ci->ScriptID); if(pCreature == NULL) pCreature = new Creature(); if (!pCreature->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT), map, GetPhaseMask(), entry, 0, GetGOInfo()->faction, 0, 0, 0, 0)) { delete pCreature; return 0; } pCreature->SetTransport(this); pCreature->AddUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT); pCreature->m_movementInfo.guid = GetGUID(); pCreature->m_movementInfo.t_pos.Relocate(x, y, z, o); if (anim) pCreature->SetUInt32Value(UNIT_NPC_EMOTESTATE, anim); pCreature->Relocate( GetPositionX() + (x * cos(GetOrientation()) + y * sin(GetOrientation() + float(M_PI))), GetPositionY() + (y * cos(GetOrientation()) + x * sin(GetOrientation())), z + GetPositionZ() , o + GetOrientation()); pCreature->SetHomePosition(pCreature->GetPositionX(), pCreature->GetPositionY(), pCreature->GetPositionZ(), pCreature->GetOrientation()); if(!pCreature->IsPositionValid()) { sLog.outError("Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature->GetGUIDLow(),pCreature->GetEntry(),pCreature->GetPositionX(),pCreature->GetPositionY()); delete pCreature; return 0; } map->Add(pCreature); m_NPCPassengerSet.insert(pCreature); if (tguid == 0) { ++currenttguid; tguid = currenttguid; } else currenttguid = std::max(tguid, currenttguid); pCreature->SetGUIDTransport(tguid); sScriptMgr.OnAddCreaturePassenger(this, pCreature); return tguid; }
void Vehicle::InstallAllAccessories() { if(!GetMap()) return; CreatureDataAddon const *cainfo = GetCreatureAddon(); if(!cainfo || !cainfo->passengers) return; for (CreatureDataAddonPassengers const* cPassanger = cainfo->passengers; cPassanger->seat_idx != -1; ++cPassanger) { // Continue if seat already taken if(GetPassenger(cPassanger->seat_idx)) continue; uint32 guid = 0; bool isVehicle = false; // Set guid and check whatever it is if(cPassanger->guid != 0) guid = cPassanger->guid; else { CreatureDataAddon const* passAddon; passAddon = ObjectMgr::GetCreatureTemplateAddon(cPassanger->entry); if(passAddon && passAddon->vehicle_id != 0) isVehicle = true; else guid = sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT); } // Create it Creature *pPassenger = new Creature; if(!isVehicle) { uint32 entry = cPassanger->entry; if(entry == 0) { CreatureData const* data = sObjectMgr.GetCreatureData(guid); if(!data) continue; entry = data->id; } if(!pPassenger->Create(guid, GetMap(), GetPhaseMask(), entry, 0)) continue; pPassenger->LoadFromDB(guid, GetMap()); pPassenger->Relocate(GetPositionX(), GetPositionY(), GetPositionZ()); GetMap()->Add(pPassenger); pPassenger->AIM_Initialize(); } else pPassenger = (Creature*)SummonVehicle(cPassanger->entry, GetPositionX(), GetPositionY(), GetPositionZ(), 0); // Enter vehicle... pPassenger->EnterVehicle(this, cPassanger->seat_idx, true); // ...and send update. Without this, client wont show this new creature/vehicle... WorldPacket data; pPassenger->BuildHeartBeatMsg(&data); pPassenger->SendMessageToSet(&data, false); } }
Creature* Transport::CreateNPCPassenger(uint32 guid, CreatureData const* data) { Map* map = GetMap(); Creature* creature = new Creature(); if (!creature->LoadCreatureFromDB(guid, map, false)) { delete creature; return NULL; } float x = data->posX; float y = data->posY; float z = data->posZ; float o = data->orientation; creature->SetTransport(this); creature->m_movementInfo.transport.guid = GetGUID(); creature->m_movementInfo.transport.pos.Relocate(x, y, z, o); // m_movementInfo.transport.pos.m_positionX x=offset CalculatePassengerPosition(x, y, z, &o); // This method transforms supplied transport offsets into global coordinates offset > worldpos creature->m_movementInfo.transport.seat = -1; GetMap()->CreatureRelocation(creature, x, y, z, o, false); creature->Relocate(x, y, z, o); // me->m_positionX x=worldpos creature->SetHomePosition(creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ(), creature->GetOrientation()); creature->SetTransportHomePosition(creature->m_movementInfo.transport.pos); /// @HACK - transport models are not added to map's dynamic LoS calculations /// because the current GameObjectModel cannot be moved without recreating creature->AddUnitState(UNIT_STATE_IGNORE_PATHFINDING); if (!creature->IsPositionValid()) { TC_LOG_ERROR("entities.transport", "Creature (guidlow %d, entry %d) not created. Suggested coordinates aren't valid (X: %f Y: %f)", creature->GetGUIDLow(), creature->GetEntry(), creature->GetPositionX(), creature->GetPositionY()); delete creature; return NULL; } if (!data->phaseIds.empty()) { for (uint16 ph : data->phaseIds) creature->SetInPhase(ph, false, true); } else creature->CopyPhaseFrom(this); if (!map->AddToMap(creature)) { delete creature; return NULL; } _staticPassengers.insert(creature); sScriptMgr->OnAddCreaturePassenger(this, creature); return creature; }
Creature* Transport::CreateNPCPassenger(ObjectGuid::LowType guid, CreatureData const* data) { Map* map = GetMap(); Creature* creature = new Creature(); if (!creature->LoadCreatureFromDB(guid, map, false)) { delete creature; return NULL; } ASSERT(data); float x = data->posX; float y = data->posY; float z = data->posZ; float o = data->orientation; creature->SetTransport(this); creature->m_movementInfo.transport.guid = GetGUID(); creature->m_movementInfo.transport.pos.Relocate(x, y, z, o); CalculatePassengerPosition(x, y, z, &o); creature->Relocate(x, y, z, o); creature->SetHomePosition(creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ(), creature->GetOrientation()); creature->SetTransportHomePosition(creature->m_movementInfo.transport.pos); /// @HACK - transport models are not added to map's dynamic LoS calculations /// because the current GameObjectModel cannot be moved without recreating creature->AddUnitState(UNIT_STATE_IGNORE_PATHFINDING); if (!creature->IsPositionValid()) { TC_LOG_ERROR("entities.transport", "Passenger %s not created. Suggested coordinates aren't valid (X: %f Y: %f)", creature->GetGUID().ToString().c_str(), creature->GetPositionX(), creature->GetPositionY()); delete creature; return NULL; } if (data->phaseid) creature->SetInPhase(data->phaseid, false, true); else if (data->phaseGroup) for (auto phase : sDB2Manager.GetPhasesForGroup(data->phaseGroup)) creature->SetInPhase(phase, false, true); else creature->CopyPhaseFrom(this); if (!map->AddToMap(creature)) { delete creature; return NULL; } _staticPassengers.insert(creature); sScriptMgr->OnAddCreaturePassenger(this, creature); return creature; }
uint32 Transport::AddNPCPassenger(uint32 tguid, uint32 entry, float x, float y, float z, float o, uint32 anim) { Map* map = GetMap(); //make it world object so it will not be unloaded with grid Creature* creature = new Creature(true); if (!creature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, GetPhaseMask(), entry, 0, GetGOInfo()->faction, 0, 0, 0, 0)) { delete creature; return 0; } creature->SetTransport(this); creature->AddUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT); creature->m_movementInfo.guid = GetGUID(); creature->m_movementInfo.t_pos.Relocate(x, y, z, o); if (anim) creature->SetUInt32Value(UNIT_NPC_EMOTESTATE, anim); creature->Relocate( GetPositionX() + (x * cos(GetOrientation()) + y * sin(GetOrientation() + float(M_PI))), GetPositionY() + (y * cos(GetOrientation()) + x * sin(GetOrientation())), z + GetPositionZ(), o + GetOrientation()); creature->SetHomePosition(creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ(), creature->GetOrientation()); creature->SetTransportHomePosition(creature->m_movementInfo.t_pos); if (!creature->IsPositionValid()) { sLog->outError(LOG_FILTER_TRANSPORTS, "Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)", creature->GetGUIDLow(), creature->GetEntry(), creature->GetPositionX(), creature->GetPositionY()); delete creature; return 0; } map->AddToMap(creature); m_NPCPassengerSet.insert(creature); if (tguid == 0) { ++currenttguid; tguid = currenttguid; } else currenttguid = std::max(tguid, currenttguid); creature->setActive(true); creature->SetGUIDTransport(tguid); sScriptMgr->OnAddCreaturePassenger(this, creature); return tguid; }
void Map::MoveAllCreaturesInMoveList() { while(!i_creaturesToMove.empty()) { // get data and remove element CreatureMoveList::iterator iter = i_creaturesToMove.begin(); Creature* c = iter->first; CreatureMover cm = iter->second; i_creaturesToMove.erase(iter); c->Relocate(cm.x, cm.y); } }
bool RandomCircleMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff) { if (creature.hasUnitState(UNIT_STAT_NOT_MOVE | UNIT_STAT_ON_VEHICLE)) { i_nextMoveTime.Update(i_nextMoveTime.GetExpiry()); // Expire the timer creature.clearUnitState(UNIT_STAT_ROAMING_MOVE); return true; } i_nextMoveTime.Update(diff); if (!creature.IsStopped() && !creature.canFly()) creature.clearUnitState(UNIT_STAT_ROAMING_MOVE); if (creature.IsStopped()) creature.addUnitState(UNIT_STAT_ROAMING_MOVE); if (!IsActive(creature)) // force stop processing (movement can move out active zone with cleanup movegens list) { Interrupt(creature); return true; } if (m_splineMap.empty()) { Reset(creature); return true; } if (i_nextMoveTime.Passed()) { if (m_splineMap.find(i_wpId) == m_splineMap.end()) { Reset(creature); return true; } SplineWayPointMap::iterator wp = m_splineMap.find(i_wpId); //rellocate but not send creature.Relocate(wp->second->x, wp->second->y, wp->second->z, wp->second->o); if (i_wpId == 29) // not last wp { Initialize(creature); return true; } i_wpId++; i_nextMoveTime.Reset(500); } return true; }
bool OutdoorPvPObjective::AddCapturePoint(uint32 entry, uint32 map, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3) { Map * pMap = MapManager::Instance().FindMap(map); if(!pMap) return false; GameObject* go = new GameObject; if (!go->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), entry, pMap, PHASEMASK_NORMAL, x, y, z, o, rotation0, rotation1, rotation2, rotation3, 100, GO_STATE_READY)) { sLog.outError("OutdoorPvP: Gameobject template %u not found in database.", entry); delete go; // TODO: Should we return here? //return false; } else go->AddToWorld(); Creature* pCreature = new Creature; if (!pCreature->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT), pMap,PHASEMASK_NORMAL, OPVP_TRIGGER_CREATURE_ENTRY, 0)) { sLog.outError("OutdoorPvP: Can't create creature entry: %u",entry); delete pCreature; return false; } pCreature->Relocate(x, y, z, o); if (!pCreature->IsPositionValid()) { sLog.outError("OutdoorPvP: Creature (guidlow %d, entry %d) not added to opvp. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature->GetGUIDLow(),pCreature->GetEntry(),pCreature->GetPositionX(),pCreature->GetPositionY()); delete pCreature; return false; } pCreature->AIM_Initialize(); pMap->Add(pCreature); m_CapturePointCreature = MAKE_NEW_GUID(pCreature->GetGUID(), OPVP_TRIGGER_CREATURE_ENTRY, HIGHGUID_UNIT); m_CapturePoint = MAKE_NEW_GUID(go->GetGUID(), entry, HIGHGUID_GAMEOBJECT); // TODO: Use proper outdoor PvP GO type. GameObjectInfo const* goinfo = go->GetGOInfo(); m_ShiftMaxPhase = goinfo->raw.data[17]; m_ShiftMaxCaptureSpeed = m_ShiftMaxPhase / float(goinfo->raw.data[16]); m_NeutralValue = goinfo->raw.data[12]; return true; }
Creature * Transport::AddNPCPassengerCreature(uint32 tguid, uint32 entry, float x, float y, float z, float o, uint32 anim) { Map* map = GetMap(); Creature * pCreature = new Creature; if (!pCreature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, GetPhaseMask(), entry, 0, GetGOInfo()->faction, 0, 0, 0, 0)) { delete pCreature; return NULL; } pCreature->SetTransport(this); pCreature->m_movementInfo.guid = GetGUID(); pCreature->m_movementInfo.t_pos.Relocate(x, y, z, o); if (anim) pCreature->SetUInt32Value(UNIT_NPC_EMOTESTATE, anim); pCreature->Relocate( GetPositionX() + (x * cos(GetOrientation()) + y * sin(GetOrientation() + float(M_PI))), GetPositionY() + (y * cos(GetOrientation()) + x * sin(GetOrientation())), z + GetPositionZ() , o + GetOrientation()); pCreature->SetHomePosition(pCreature->GetPositionX(), pCreature->GetPositionY(), pCreature->GetPositionZ(), pCreature->GetOrientation()); if(!pCreature->IsPositionValid()) { sLog->outError(LOG_FILTER_TRANSPORTS, "Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)", pCreature->GetGUIDLow(), pCreature->GetEntry(), pCreature->GetPositionX(), pCreature->GetPositionY()); delete pCreature; return NULL; } map->AddToMap(pCreature); m_NPCPassengerSet.insert(pCreature); if (tguid == 0) { ++currenttguid; tguid = currenttguid; } else currenttguid = std::max(tguid, currenttguid); pCreature->SetGUIDTransport(tguid); sScriptMgr->OnAddCreaturePassenger(this, pCreature); return pCreature; }
Creature* Transport::CreateNPCPassenger(ObjectGuid::LowType guid, CreatureData const* data) { Map* map = GetMap(); Creature* creature = Creature::CreateCreatureFromDB(guid, map, false); if (!creature) return nullptr; ASSERT(data); float x = data->posX; float y = data->posY; float z = data->posZ; float o = data->orientation; creature->SetTransport(this); creature->m_movementInfo.transport.guid = GetGUID(); creature->m_movementInfo.transport.pos.Relocate(x, y, z, o); creature->m_movementInfo.transport.seat = -1; CalculatePassengerPosition(x, y, z, &o); creature->Relocate(x, y, z, o); creature->SetHomePosition(creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ(), creature->GetOrientation()); creature->SetTransportHomePosition(creature->m_movementInfo.transport.pos); /// @HACK - transport models are not added to map's dynamic LoS calculations /// because the current GameObjectModel cannot be moved without recreating creature->AddUnitState(UNIT_STATE_IGNORE_PATHFINDING); if (!creature->IsPositionValid()) { TC_LOG_ERROR("entities.transport", "Passenger %s not created. Suggested coordinates aren't valid (X: %f Y: %f)", creature->GetGUID().ToString().c_str(), creature->GetPositionX(), creature->GetPositionY()); delete creature; return nullptr; } PhasingHandler::InitDbPhaseShift(creature->GetPhaseShift(), data->phaseUseFlags, data->phaseId, data->phaseGroup); PhasingHandler::InitDbVisibleMapId(creature->GetPhaseShift(), data->terrainSwapMap); if (!map->AddToMap(creature)) { delete creature; return nullptr; } _staticPassengers.insert(creature); sScriptMgr->OnAddCreaturePassenger(this, creature); return creature; }
Creature* Transport::CreateNPCPassenger(uint32 guid, CreatureData const* data) { Map* map = GetMap(); Creature* creature = new Creature(); if (!creature->LoadCreatureFromDB(guid, map, false)) { delete creature; return NULL; } float x = data->posX; float y = data->posY; float z = data->posZ; float o = data->orientation; creature->SetTransport(this); creature->AddUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT); creature->m_movementInfo.transport.guid = GetGUID(); creature->m_movementInfo.transport.pos.Relocate(x, y, z, o); CalculatePassengerPosition(x, y, z, &o); creature->Relocate(x, y, z, o); creature->SetHomePosition(creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ(), creature->GetOrientation()); creature->SetTransportHomePosition(creature->m_movementInfo.transport.pos); /// @HACK - transport models are not added to map's dynamic LoS calculations /// because the current GameObjectModel cannot be moved without recreating creature->AddUnitState(UNIT_STATE_IGNORE_PATHFINDING); if (!creature->IsPositionValid()) { TC_LOG_ERROR(LOG_FILTER_TRANSPORTS, "Creature (guidlow %d, entry %d) not created. Suggested coordinates aren't valid (X: %f Y: %f)",creature->GetGUIDLow(),creature->GetEntry(),creature->GetPositionX(),creature->GetPositionY()); delete creature; return NULL; } if (!map->AddToMap(creature)) { delete creature; return NULL; } _staticPassengers.insert(creature); sScriptMgr->OnAddCreaturePassenger(this, creature); return creature; }
Creature* Transport::CreateNPCPassenger(uint32 guid, CreatureData const* data) { Map* map = GetMap(); Creature* creature = new Creature(); if (!creature->LoadCreatureFromDB(guid, map, false)) { delete creature; return NULL; } float x = data->posX; float y = data->posY; float z = data->posZ; float o = data->orientation; creature->SetTransport(this); creature->AddUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT); creature->m_movementInfo.transport.guid = GetGUID(); creature->m_movementInfo.transport.pos.Relocate(x, y, z, o); CalculatePassengerPosition(x, y, z, &o); creature->Relocate(x, y, z, o); creature->SetHomePosition(creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ(), creature->GetOrientation()); creature->SetTransportHomePosition(creature->m_movementInfo.transport.pos); if (!creature->IsPositionValid()) { TC_LOG_ERROR(LOG_FILTER_TRANSPORTS, "Creature (guidlow %d, entry %d) not created. Suggested coordinates aren't valid (X: %f Y: %f)",creature->GetGUIDLow(),creature->GetEntry(),creature->GetPositionX(),creature->GetPositionY()); delete creature; return NULL; } if (!map->AddToMap(creature)) { delete creature; return NULL; } _staticPassengers.insert(creature); sScriptMgr->OnAddCreaturePassenger(this, creature); return creature; }
Creature* Transport::CreateNPCPassenger(uint32 entry, float x, float y, float z, float o, CreatureData const* data /*= NULL*/) { Map* map = GetMap(); Creature* creature = new Creature(); if (!creature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, GetPhaseMask(), entry, 0, GetGOInfo()->faction, 0.0f, 0.0f, 0.0f, 0.0f, data)) { delete creature; return NULL; } creature->SetTransport(this); creature->AddUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT); creature->m_movementInfo.guid = GetGUID(); creature->m_movementInfo.t_pos.Relocate(x, y, z, o); o += GetOrientation(); MapManager::NormalizeOrientation(o); creature->Relocate(GetPositionX() + (x * cos(GetOrientation()) + y * sin(GetOrientation() + float(M_PI))), GetPositionY() + (y * cos(GetOrientation()) + x * sin(GetOrientation())), z + GetPositionZ(), o); creature->SetHomePosition(creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ(), creature->GetOrientation()); if (!creature->IsPositionValid()) { sLog->outError("Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",creature->GetGUIDLow(),creature->GetEntry(),creature->GetPositionX(),creature->GetPositionY()); delete creature; return NULL; } map->AddToMap(creature); AddPassenger(creature); creature->SetWorldObject(true); //so it will not be unloaded with grid sScriptMgr->OnAddCreaturePassenger(this, creature); return creature; }
// gunship data Creature* Transport::AddNPCPassengerInInstance(uint32 entry, float x, float y, float z, float o, uint32 anim) { Map* map = GetMap(); Creature* creature = new Creature; if (!creature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, GetPhaseMask(), entry, 0, GetGOInfo()->faction, 0, 0, 0, 0)) { delete creature; return 0; } creature->SetTransport(this); creature->AddUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT); creature->m_movementInfo.guid = GetGUID(); creature->m_movementInfo.transport.pos.Relocate(x, y, z, o); creature->Relocate( GetPositionX() + (x * cos(GetOrientation()) + y * sin(GetOrientation() + float(M_PI))), GetPositionY() + (y * cos(GetOrientation()) + x * sin(GetOrientation())), z + GetPositionZ(), o + GetOrientation()); creature->SetHomePosition(creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ(), creature->GetOrientation()); if (!creature->IsPositionValid()) { delete creature; return 0; } map->AddToMap(creature); m_NPCPassengerSet.insert(creature); creature->setActive(true); sScriptMgr->OnAddCreaturePassenger(this, creature); return creature; }
void HomeMovementGenerator<Creature>::Finalize(Creature& owner) { if (i_travel_timer == 0) { owner.AddSplineFlag(SPLINEFLAG_WALKMODE); // restore orientation of not moving creature at returning to home if (owner.GetDefaultMovementType() == IDLE_MOTION_TYPE) { // such a mob might need very exact spawning point, hence relocate to spawn-position if (CreatureData const* data = sObjectMgr.GetCreatureData(owner.GetGUIDLow())) { owner.Relocate(data->posX, data->posY, data->posZ, data->orientation); owner.SendHeartBeat(false); } } if (owner.GetTemporaryFactionFlags() & TEMPFACTION_RESTORE_REACH_HOME) owner.ClearTemporaryFaction(); owner.LoadCreatureAddon(true); owner.AI()->JustReachedHome(); } }
bool OutdoorPvPObjective::AddCapturePoint(uint32 entry, uint32 map, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3) { sLog.outDebug("OutdoorPvPObjective: creating capture point %u and capture point creature",entry); // check info existence GameObjectInfo const* goinfo = objmgr.GetGameObjectInfo(entry); if (!goinfo) return false; CreatureInfo const *cinfo = objmgr.GetCreatureTemplate(OPVP_TRIGGER_CREATURE_ENTRY); if(!cinfo) return false; // create capture point creature uint32 displayId = objmgr.ChooseDisplayId(0, cinfo, NULL); uint32 creature_guid = objmgr.GenerateLowGuid(HIGHGUID_UNIT); CreatureData& cdata = objmgr.NewOrExistCreatureData(creature_guid); cdata.id = OPVP_TRIGGER_CREATURE_ENTRY; cdata.mapid = map; cdata.displayid = displayId; cdata.equipmentId = cinfo->equipmentId; cdata.posX = x; cdata.posY = y; cdata.posZ = z; cdata.orientation = o; cdata.spawntimesecs = 1; cdata.spawndist = 0; cdata.currentwaypoint = 0; cdata.curhealth = cinfo->maxhealth; cdata.curmana = cinfo->maxmana; cdata.is_dead = false; cdata.movementType = cinfo->MovementType; cdata.spawnMask = 1; cdata.phaseMask = PHASEMASK_NORMAL; objmgr.AddCreatureToGrid(creature_guid, &cdata); m_CapturePointCreature = MAKE_NEW_GUID(creature_guid, OPVP_TRIGGER_CREATURE_ENTRY, HIGHGUID_UNIT); // create capture point go uint32 guid = objmgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT); GameObjectData& data = objmgr.NewGOData(guid); data.id = entry; data.mapid = map; data.posX = x; data.posY = y; data.posZ = z; data.orientation = o; data.rotation0 = rotation0; data.rotation1 = rotation1; data.rotation2 = rotation2; data.rotation3 = rotation3; data.spawntimesecs = 1; data.animprogress = 100; data.spawnMask = 1; data.go_state = GO_STATE_READY; data.phaseMask = PHASEMASK_NORMAL; objmgr.AddGameobjectToGrid(guid, &data); m_CapturePoint = MAKE_NEW_GUID(guid, entry, HIGHGUID_GAMEOBJECT); // get the needed values from goinfo m_ShiftMaxPhase = goinfo->raw.data[17]; m_ShiftMaxCaptureSpeed = m_ShiftMaxPhase / float(goinfo->raw.data[16]); m_NeutralValue = goinfo->raw.data[12]; // add to map if map is already loaded Map * pMap = MapManager::Instance().FindMap(map); if(!pMap) return true; // add GO... GameObject * go = new GameObject; if(!go->Create(guid,entry, pMap, PHASEMASK_NORMAL, x,y,z,o,rotation0,rotation1,rotation2,rotation3,100, GO_STATE_READY)) { sLog.outError("OutdoorPvPObjective: Gameobject template %u not found in database.", entry); delete go; } else { go->SetRespawnTime(0); objmgr.SaveGORespawnTime(go->GetDBTableGUIDLow(), 0, 0); //this is useless this isn't spawned through db so it doesn't has dbtableguid (it's just 0) pMap->Add(go); } // add creature... Creature* pCreature = new Creature; if (!pCreature->Create(creature_guid, pMap,PHASEMASK_NORMAL, OPVP_TRIGGER_CREATURE_ENTRY, 0)) { sLog.outError("OutdoorPvPObjective: Can't create creature entry: %u",entry); delete pCreature; } else { pCreature->AIM_Initialize(); pCreature->Relocate(x, y, z, o); if(!pCreature->IsPositionValid()) { sLog.outError("OutdoorPvPObjective: Creature (guidlow %d, entry %d) not added to opvp. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature->GetGUIDLow(),pCreature->GetEntry(),pCreature->GetPositionX(),pCreature->GetPositionY()); return false; } pMap->Add(pCreature); } return true; }
bool OutdoorPvPObjective::AddCreature(uint32 type, uint32 entry, uint32 teamval, uint32 map, float x, float y, float z, float o, uint32 spawntimedelay) { CreatureInfo const *cinfo = objmgr.GetCreatureTemplate(entry); if(!cinfo) { return false; } uint32 displayId = objmgr.ChooseDisplayId(teamval, cinfo, NULL); CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(displayId); if (!minfo) { return false; } else displayId = minfo->modelid; // it can be different (for another gender) uint32 guid = objmgr.GenerateLowGuid(HIGHGUID_UNIT); CreatureData& data = objmgr.NewOrExistCreatureData(guid); data.id = entry; data.mapid = map; data.displayid = displayId; data.equipmentId = cinfo->equipmentId; data.posX = x; data.posY = y; data.posZ = z; data.orientation = o; data.spawntimesecs = spawntimedelay; data.spawndist = 0; data.currentwaypoint = 0; data.curhealth = cinfo->maxhealth; data.curmana = cinfo->maxmana; data.is_dead = false; data.movementType = cinfo->MovementType; data.spawnMask = 1; data.phaseMask = PHASEMASK_NORMAL; objmgr.AddCreatureToGrid(guid, &data); m_Creatures[type] = MAKE_NEW_GUID(guid, entry, HIGHGUID_UNIT); m_CreatureTypes[m_Creatures[type]] = type; Map * pMap = MapManager::Instance().FindMap(map); if(!pMap) return true; Creature* pCreature = new Creature; if (!pCreature->Create(guid, pMap, PHASEMASK_NORMAL, entry, teamval)) { sLog.outError("OutdoorPvPObjective: Can't create creature entry: %u",entry); delete pCreature; return true; } pCreature->AIM_Initialize(); pCreature->Relocate(x, y, z, o); if(!pCreature->IsPositionValid()) { sLog.outError("OutdoorPvPObjective: ERROR: Creature (guidlow %d, entry %d) not added to opvp. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature->GetGUIDLow(),pCreature->GetEntry(),pCreature->GetPositionX(),pCreature->GetPositionY()); return false; } if(spawntimedelay) pCreature->SetRespawnDelay(spawntimedelay); pMap->Add(pCreature); return true; }
void WorldSession::HandleTrainerBuySpellOpcode( WorldPacket & recv_data ) { uint64 guid; uint32 spellId = 0; TrainerSpell *proto=NULL; recv_data >> guid >> spellId; sLog.outDebug( "WORLD: Received CMSG_TRAINER_BUY_SPELL NpcGUID=%u, learn spell id is: %u",uint32(GUID_LOPART(guid)), spellId ); if(!GetPlayer()->isAlive()) return; Creature *unit = ObjectAccessor::Instance().GetCreature(*_player, guid); if(!unit) return; if( unit->IsHostileTo(_player)) // do not talk with enemies return; if(!unit->isCanTrainingOf(_player,true)) return; std::list<TrainerSpell*>::iterator titr; for (titr = unit->GetTspellsBegin(); titr != unit->GetTspellsEnd();titr++) { if((*titr)->spell->Id == spellId) { proto = *titr; break; } } if (proto == NULL) return; SpellEntry const *spellInfo = sSpellStore.LookupEntry(proto->spell->EffectTriggerSpell[0]); if(!spellInfo) return; if(_player->HasSpell(spellInfo->Id)) return; if(_player->getLevel() < (proto->reqlevel ? proto->reqlevel : spellInfo->spellLevel)) return; if(proto->reqskill && _player->GetSkillValue(proto->reqskill) < proto->reqskillvalue) return; uint32 prev_id = objmgr.GetPrevSpellInChain(spellInfo->Id); if(prev_id && !_player->HasSpell(prev_id)) return; if(proto->spell->Effect[1] == SPELL_EFFECT_SKILL_STEP) if(!_player->CanLearnProSpell(spellId)) return; if(!proto) { sLog.outErrorDb("TrainerBuySpell: Trainer(%u) has not the spell(%u).", uint32(GUID_LOPART(guid)), spellId); return; } if( _player->GetMoney() >= proto->spellcost ) { WorldPacket data( SMSG_TRAINER_BUY_SUCCEEDED, 12 ); data << guid << spellId; SendPacket( &data ); _player->ModifyMoney( -int32(proto->spellcost) ); if(spellInfo->powerType == 2) { _player->addSpell(spellId,4); // ative = 4 for spell book of hunter's pet return; } Spell *spell; if(proto->spell->SpellVisual == 222) spell = new Spell(_player, proto->spell, false, NULL); else spell = new Spell(unit, proto->spell, false, NULL); SpellCastTargets targets; targets.setUnitTarget( _player ); float u_oprientation = unit->GetOrientation(); // trainer always see at customer in time of training (part of client functionality) unit->SetInFront(_player); spell->prepare(&targets); // trainer always return to original orientation unit->Relocate(unit->GetPositionX(),unit->GetPositionY(),unit->GetPositionZ(),u_oprientation); } }
bool WaypointMovementGenerator<Creature>::Update(Creature &unit, const uint32 &diff) { if (!&unit) return true; if (!path_id) return false; // Waypoint movement can be switched on/off // This is quite handy for escort quests and other stuff if (unit.HasUnitState(UNIT_STAT_ROOT | UNIT_STAT_STUNNED | UNIT_STAT_DISTRACTED)) return true; // Clear the generator if the path doesn't exist if (!waypoints || !waypoints->size()) return false; Traveller<Creature> traveller(unit); i_nextMoveTime.Update(diff); i_destinationHolder.UpdateTraveller(traveller, diff, true); if (i_nextMoveTime.GetExpiry() < TIMEDIFF_NEXT_WP) { if (unit.IsStopped()) { if (StopedByPlayer) { ASSERT(node); InitTraveller(unit, *node); i_destinationHolder.SetDestination(traveller, node->x, node->y, node->z); i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime()); StopedByPlayer = false; return true; } if (i_currentNode == waypoints->size() - 1) // If that's our last waypoint { if (repeating) // If the movement is repeating i_currentNode = 0; // Start moving all over again else { unit.SetHomePosition(node->x, node->y, node->z, unit.GetOrientation()); unit.GetMotionMaster()->Initialize(); return false; // Clear the waypoint movement } } else ++i_currentNode; node = waypoints->at(i_currentNode); InitTraveller(unit, *node); i_destinationHolder.SetDestination(traveller, node->x, node->y, node->z); i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime()); //Call for creature group update if (unit.GetFormation() && unit.GetFormation()->getLeader() == &unit) unit.GetFormation()->LeaderMoveTo(node->x, node->y, node->z); } else { //Determine waittime if (node->delay) i_nextMoveTime.Reset(node->delay); //note: disable "start" for mtmap if (node->event_id && urand(0,99) < node->event_chance) unit.GetMap()->ScriptsStart(sWaypointScripts, node->event_id, &unit, NULL/*, false*/); i_destinationHolder.ResetTravelTime(); MovementInform(unit); unit.UpdateWaypointID(i_currentNode); unit.ClearUnitState(UNIT_STAT_ROAMING); unit.Relocate(node->x, node->y, node->z); } } else { if (unit.IsStopped() && !i_destinationHolder.HasArrived()) { if (!StopedByPlayer) { i_destinationHolder.IncreaseTravelTime(STOP_TIME_FOR_PLAYER); i_nextMoveTime.Reset(STOP_TIME_FOR_PLAYER); StopedByPlayer = true; } } } return true; }
void WorldSession::HandleTrainerBuySpellOpcode( WorldPacket & recv_data ) { CHECK_PACKET_SIZE(recv_data,8+4); uint64 guid; uint32 spellId = 0; recv_data >> guid >> spellId; sLog.outDebug( "WORLD: Received CMSG_TRAINER_BUY_SPELL NpcGUID=%u, learn spell id is: %u",uint32(GUID_LOPART(guid)), spellId ); Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid, UNIT_NPC_FLAG_TRAINER); if (!unit) { sLog.outDebug( "WORLD: HandleTrainerBuySpellOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); return; } // remove fake death if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); // Lazy loading at first access unit->LoadTrainerSpells(); if(!unit->isCanTrainingOf(_player,true)) return; TrainerSpell const* trainer_spell = NULL; // check present spell in trainer spell list Creature::SpellsList const& trainer_spells = unit->GetTrainerSpells(); for(Creature::SpellsList::const_iterator itr = trainer_spells.begin(); itr != trainer_spells.end(); ++itr) { if(itr->spell->Id == spellId) { trainer_spell = &*itr; break; } } // not found, cheat? if(!trainer_spell) return; // can't be learn, cheat? Or double learn with lags... if(_player->GetTrainerSpellState(trainer_spell) != TRAINER_SPELL_GREEN) return; // apply reputation discount uint32 nSpellCost = uint32(floor(trainer_spell->spellcost * _player->GetReputationPriceDiscount(unit))); // check money requirement if(_player->GetMoney() < nSpellCost ) return; SpellEntry const *spellInfo = sSpellStore.LookupEntry(trainer_spell->spell->EffectTriggerSpell[0]); WorldPacket data( SMSG_TRAINER_BUY_SUCCEEDED, 12 ); data << guid << spellId; SendPacket( &data ); _player->ModifyMoney( -int32(nSpellCost) ); if(spellInfo->powerType == 2) { _player->addSpell(spellId,4); // active = 4 for spell book of hunter's pet return; } // learn explicitly to prevent lost money at lags, learning spell will be only show spell anumation _player->learnSpell(spellInfo->Id); Unit* caster = (trainer_spell->spell->SpellVisual == 222) ? (Unit*)_player : (Unit*)unit; // trainer always see at customer in time of training (part of client functionality) float u_oprientation = unit->GetOrientation(); unit->SetInFront(_player); caster->CastSpell(_player,trainer_spell->spell,false); // trainer always return to original orientation unit->Relocate(unit->GetPositionX(),unit->GetPositionY(),unit->GetPositionZ(),u_oprientation); }