void SetDest(SpellDestination& dest) { Creature* creature = GetCaster()->ToCreature(); if (creature) return; // Side of the room: WEST > 366.781f (middle of the room) > EAST float ori = creature->GetPositionY() > 366.781f ? DegToRad(270) : DegToRad(90); // DB dest has no orientation field (always 0.0f). dest.RelocateOffset({ 0.0f, 0.0f, 0.0f, ori }); creature->SetHomePosition(dest._position.GetPosition()); }
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()); 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 0; } map->AddToMap(creature); m_NPCPassengerSet.insert(creature); if (tguid == 0) { ++currenttguid; tguid = currenttguid; } else currenttguid = std::max(tguid, currenttguid); creature->SetGUIDTransport(tguid); sScriptMgr->OnAddCreaturePassenger(this, creature); return tguid; }
void RandomMovementGenerator<Creature>::Initialize(Creature &creature) { if (!creature.isAlive()) return; if (creature.canFly() && !(creature.canWalk() && creature.IsAtGroundLevel(creature.GetPositionX(), creature.GetPositionY(), creature.GetPositionZ()))) creature.AddSplineFlag(SPLINEFLAG_UNKNOWN7); else creature.AddSplineFlag(SPLINEFLAG_WALKMODE); creature.addUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE); _setRandomLocation(creature); }
void AIUpdate() { if(!scene && spells.size() > 0) { for(uint8 i = 0; i < spells.size(); i++) { if(spells[i]->time < getMSTime()) { if(Rand(spells[i]->chance)) { CastScriptSpell(spells[i]); spells[i]->time = getMSTime() + spells[i]->timer; } } } } else { //this is ugly, better ideas? scene = false; Creature* citizen = NULL; uint32 entry = 0; for(uint32 i = 0; i != _unit->GetMapMgr()->m_CreatureHighGuid; ++i) { if(_unit->GetMapMgr()->CreatureStorage[i] != NULL) { entry = _unit->GetMapMgr()->CreatureStorage[i]->GetEntry(); if(entry == 31126 || entry == 31127 || entry == 28167 || entry == 28169) { citizen = _unit->GetMapMgr()->CreatureStorage[i]; CreatureProto* cp = CreatureProtoStorage.LookupEntry(27737);//risen zombie CreatureInfo* ci = CreatureNameStorage.LookupEntry(27737); Creature* c = NULL; if(cp && ci) { c = _unit->GetMapMgr()->CreateCreature(27737); if(c) { //position is guessed c->Load(cp, citizen->GetPositionX(), citizen->GetPositionY(), citizen->GetPositionZ(), citizen->GetOrientation()); c->PushToWorld(_unit->GetMapMgr()); } } citizen->Despawn(0, 0); } } } } }
// Emote Ardonis and Pathaleon void Turn_to_Pathaleons_Image() { Creature* ardonis = Unit::GetCreature(*me, ardonisGUID); Creature* pathaleon = Unit::GetCreature(*me, pathaleonGUID); Player* player = Unit::GetPlayer(*me, PlayerGUID); if (!ardonis || !pathaleon || !player) return; //Calculate the angle to Pathaleon angle_dawnforge = me->GetAngle(pathaleon->GetPositionX(), pathaleon->GetPositionY()); angle_ardonis = ardonis->GetAngle(pathaleon->GetPositionX(), pathaleon->GetPositionY()); //Turn Dawnforge and update me->SetOrientation(angle_dawnforge); me->SendUpdateToPlayer(player); //Turn Ardonis and update ardonis->SetOrientation(angle_ardonis); ardonis->SendUpdateToPlayer(player); //Set them to kneel me->SetStandState(UNIT_STAND_STATE_KNEEL); ardonis->SetStandState(UNIT_STAND_STATE_KNEEL); }
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::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; }
void ConfusedMovementGenerator::Initialize(Creature &creature) { const float wander_distance=11; float x,y,z,z2; x = creature.GetPositionX(); y = creature.GetPositionY(); z = creature.GetPositionZ(); uint32 mapid=creature.GetMapId(); Map* map = MapManager::Instance().GetMap(mapid); z2 = map->GetHeight(x,y); if( abs( z2 - z ) < 5 ) z = z2; i_nextMove = 1; bool is_water_ok = creature.isCanSwimOrFly(); bool is_land_ok = creature.isCanWalkOrFly(); for(unsigned int idx=0; idx < MAX_CONF_WAYPOINTS+1; ++idx) { const float wanderX=((wander_distance*rand())/RAND_MAX)-wander_distance/2; const float wanderY=((wander_distance*rand())/RAND_MAX)-wander_distance/2; i_waypoints[idx][0] = x + wanderX; i_waypoints[idx][1] = y + wanderY; // prevent invalid coordinates generation MaNGOS::NormalizeMapCoord(i_waypoints[idx][0]); MaNGOS::NormalizeMapCoord(i_waypoints[idx][1]); bool is_water = map->IsInWater(i_waypoints[idx][0],i_waypoints[idx][1]); // if generated wrong path just ignore if( is_water && !is_water_ok || !is_water && !is_land_ok ) { i_waypoints[idx][0] = idx > 0 ? i_waypoints[idx-1][0] : x; i_waypoints[idx][1] = idx > 0 ? i_waypoints[idx-1][1] : y; } z2 = map->GetHeight(i_waypoints[idx][0],i_waypoints[idx][1]); if( abs( z2 - z ) < 5 ) z = z2; i_waypoints[idx][2] = z; } creature.StopMoving(); }
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; }
void RandomCircleMovementGenerator<Creature>::Initialize(Creature &creature) { if (!creature.isAlive()) return; if (creature.canFly() && !(creature.canWalk() && creature.IsAtGroundLevel(creature.GetPositionX(), creature.GetPositionY(), creature.GetPositionZ()))) creature.AddSplineFlag(SPLINEFLAG_UNKNOWN7); else creature.AddSplineFlag(SPLINEFLAG_WALKMODE); creature.addUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE); m_bClockWise = urand(0, 1) ? true : false; i_wpId = 0; fillSplineWayPoints(creature); SplineFlags flags = SplineFlags(SPLINEFLAG_FORWARD | SPLINEFLAG_UNKNOWN7 | SPLINEFLAG_FLYING | creature.GetSplineFlags()); creature.SendSplineMove(&m_splineMap, SPLINETYPE_NORMAL, flags, 500, NULL); }
void HandleScriptEffect(SpellEffIndex /*effIndex*/) { Unit* caster = GetCaster(); Creature* target = GetHitCreature(); if (!target || caster == target) return; target->CastSpell(target->GetPositionX()+irand(-10, 10), target->GetPositionY()+irand(-10, 10), target->GetPositionZ() , SPELL_RACER_DEATH_VISUAL, true); target->DespawnOrUnsummon(3000); target->CastSpell(target, SPELL_RACER_FLAMES, true); caster->CastSpell(caster, SPELL_RACER_KILL_COUNTER, true); if (Player* targetSummoner = target->GetCharmerOrOwnerPlayerOrPlayerItself()) { //targetSummoner->RemoveCriteriaProgress(sAchievementCriteriaStore.LookupEntry(RACER_ACHI_CRITERIA)); !ZOMG, ADD ACCESSOR targetSummoner->RemoveAurasDueToSpell(SPELL_RACER_KILL_COUNTER); } }
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; }
bool EffectAuraDummy_npc_scourged_flamespitter(const Aura* pAura, bool bApply) { if (pAura->GetId() == SPELL_REINFORCED_NET && pAura->GetEffIndex() == EFFECT_INDEX_0 && bApply) { Creature* pCreature = (Creature*)pAura->GetTarget(); Unit* pCaster = pAura->GetCaster(); if (!pCreature || !pCaster || pCaster->GetTypeId() != TYPEID_PLAYER || pCreature->GetEntry() != NPC_FLAMESPITTER) return false; // move the flamespitter to the ground level pCreature->GetMotionMaster()->Clear(); pCreature->SetWalk(false); float fGroundZ = pCreature->GetMap()->GetHeight(pCreature->GetPhaseMask(), pCreature->GetPositionX(), pCreature->GetPositionY(), pCreature->GetPositionZ()); pCreature->GetMotionMaster()->MovePoint(1, pCreature->GetPositionX(), pCreature->GetPositionY(), fGroundZ); return true; } return false; }
void WorldSession::SendTaxiStatus(uint64 guid) { // cheating checks Creature* unit = GetPlayer()->GetMap()->GetCreature(guid); if (!unit) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WorldSession::SendTaxiStatus - Unit (GUID: %u) not found.", uint32(GUID_LOPART(guid))); return; } uint32 curloc = sObjectMgr->GetNearestTaxiNode(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ(), unit->GetMapId(), GetPlayer()->GetTeam()); if (curloc == 0) // Nearest location not found. return; sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: current location %u ", curloc); ObjectGuid npcGuid = guid; WorldPacket data(SMSG_TAXI_NODE_STATUS, 9); data.WriteBit(npcGuid[0]); data.WriteBit(npcGuid[7]); data.WriteBits(GetPlayer()->m_taxi.IsTaximaskNodeKnown(curloc) ? 1 : 0, 2); data.WriteBit(npcGuid[2]); data.WriteBit(npcGuid[3]); data.WriteBit(npcGuid[6]); data.WriteBit(npcGuid[5]); data.WriteBit(npcGuid[4]); data.WriteBit(npcGuid[1]); data.FlushBits(); uint8 bytesOrder[8] = { 3, 2, 6, 4, 7, 1, 0, 5 }; data.WriteBytesSeq(npcGuid, bytesOrder); SendPacket(&data); sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_TAXI_NODE_STATUS"); }
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); 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 NULL; } map->Add(pCreature); m_NPCPassengerSet.insert(pCreature); pCreature->setActive(true); sScriptMgr->OnAddCreaturePassenger(this, pCreature); return pCreature; }
bool ChatHandler::HandleDeleteCommand(const char* args, WorldSession *m_session) { uint64 guid = m_session->GetPlayer()->GetSelection(); if (guid == 0) { SystemMessage(m_session, "No selection."); return true; } Creature *unit = m_session->GetPlayer()->GetMapMgr()->GetCreature(guid); if(!unit) { SystemMessage(m_session, "You should select a creature."); return true; } sGMLog.writefromsession(m_session, "used npc delete, sqlid %u, creature %s, pos %f %f %f", unit->GetSQL_id(), unit->GetCreatureName()->Name, unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ()); if(unit->m_spawn == 0) return false; BlueSystemMessage(m_session, "Deleted creature ID %u", unit->spawnid); if(unit->IsInWorld()) { if(unit->m_spawn) { uint32 cellx=float2int32(((_maxX-unit->m_spawn->x)/_cellSize)); uint32 celly=float2int32(((_maxY-unit->m_spawn->y)/_cellSize)); unit->GetMapMgr()->GetBaseMap()->GetSpawnsListAndCreate(cellx, celly)->CreatureSpawns.erase(unit->m_spawn); } unit->RemoveFromWorld(false); } unit->DeleteFromDB(); delete unit; return true; }
bool OrbOfMurlocControl(uint32 i, Spell* pSpell) { if(pSpell->m_caster->IsPlayer() == false) return true; Player* pPlayer = TO_PLAYER( pSpell->u_caster ); QuestLogEntry *pQuest = pPlayer->GetQuestLogForEntry(11541); if(pQuest == NULL) return true; Creature* pTarget; for(ObjectSet::iterator itr = pSpell->m_caster->GetInRangeSetBegin(); itr != pSpell->m_caster->GetInRangeSetEnd(); ++itr) { if( (*itr)->IsUnit() && TO_UNIT(*itr)->IsCreature() ) pTarget = TO_CREATURE(*itr); else continue; if( pSpell->m_caster->CalcDistance(pTarget) > 5 ) continue; if( pTarget->GetEntry() == 25084) { if(pQuest->GetMobCount(0) < pQuest->GetQuest()->required_mobcount[0]) { pQuest->SetMobCount(0, pQuest->GetMobCount(0) + 1); pQuest->SendUpdateAddKill(0); Creature* FreedGreengill = sEAS.SpawnCreature(pPlayer, 25085, pTarget->GetPositionX(), pTarget->GetPositionY(), pTarget->GetPositionZ(), pTarget->GetOrientation(), 0); FreedGreengill->Despawn(6*60*1000, 0); pTarget->Despawn(0, 6*60*1000); pQuest->UpdatePlayerFields(); return true; } } } return true; }
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; }
bool MagnetoCollector(uint32 i, Spell* pSpell) { Player *pPlayer = (Player*)pSpell->u_caster; if(!pPlayer) return true; if(!pSpell->u_caster->IsPlayer()) return true; QuestLogEntry *qle = pPlayer->GetQuestLogForEntry(10584); if(qle == NULL) return true; Creature *magneto = static_cast<Creature*>(pSpell->GetUnitTarget()); if(!magneto) return true; Creature *auramagneto = sEAS.SpawnCreature(pPlayer, 21731, magneto->GetPositionX(), magneto->GetPositionY(), magneto->GetPositionZ(), magneto->GetOrientation(), 0); magneto->Despawn(1, 0); auramagneto->Despawn(4*60*1000, 0); return true; }
// 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 Transform() { if (Player* pPlayer = m_creature->GetMap()->GetPlayer(m_playerGuid)) { Creature* pPreciousDevourer = NULL; Creature* pDemon = m_creature->SummonCreature(NPC_SIMONE_THE_SEDUCTRESS, m_creature->GetPositionX(), m_creature->GetPositionY(), m_creature->GetPositionZ(), m_creature->GetAngle(m_creature), TEMPSUMMON_DEAD_DESPAWN, 0); Creature* pPrecious = GetClosestCreatureWithEntry(m_creature, NPC_PRECIOUS, 100.0f); if (pDemon) { if (npc_simone_seductressAI * pSimone = dynamic_cast<npc_simone_seductressAI*> (pDemon->AI())) pSimone->m_simoneGuid = m_creature->GetObjectGuid(); m_creature->SetVisibility(VISIBILITY_OFF); m_creature->ForcedDespawn(); } if (pDemon && pPrecious) { pPreciousDevourer = m_creature->SummonCreature(NPC_PRECIOUS_THE_DEVOURER, pPrecious->GetPositionX(), pPrecious->GetPositionY(), pPrecious->GetPositionZ(), pPrecious->GetAngle(pPrecious), TEMPSUMMON_DEAD_DESPAWN, 0, true); if (pPreciousDevourer) { if (npc_simone_seductressAI * pSimone = dynamic_cast<npc_simone_seductressAI*> (pDemon->AI())) pSimone->m_preciousGuid = pPreciousDevourer->GetObjectGuid(); if (npc_precious_the_devourerAI * pDevourer = dynamic_cast<npc_precious_the_devourerAI*> (pPreciousDevourer->AI())) pDevourer->m_simoneGuid = pDemon->GetObjectGuid(); } pPrecious->SetVisibility(VISIBILITY_OFF); pPrecious->ForcedDespawn(); } } }
dtQueryFilter PathInfo::createFilter() { dtQueryFilter filter; if(m_sourceObject->GetTypeId() != TYPEID_UNIT) return filter; Creature* creature = (Creature*)m_sourceObject; filter.includeFlags = 0; filter.excludeFlags = 0; if(creature->canWalk()) { filter.includeFlags |= NAV_GROUND; // walk filter.includeFlags |= NAV_SHALLOW_WATER; // any creature can walk through shallow water } if(creature->canSwim()) filter.includeFlags |= NAV_WATER; // swim else { // TODO: check size of creature to determine NAV_AVERAGE_WATER and NAV_DEEP_WATER } // TODO: check for NAV_MAGMA //if(creature->IsImmunedToDamage(SPELL_SCHOOL_MASK_FIRE)) // immune to fire damage - valid? // TODO: check for NAV_SLIME // allow creatures to cheat and use different movement types if they are moved // forcefully into terrain they can't normally move in if(creature->IsInWater() || creature->IsUnderWater()) filter.includeFlags |= getNavTerrain(creature->GetPositionX(),creature->GetPositionY(),creature->GetPositionZ()); return filter; }
void WorldSession::SendTaxiStatus(ObjectGuid guid) { // cheating checks Creature* unit = GetPlayer()->GetMap()->GetCreature(guid); if (!unit) { TC_LOG_DEBUG("network", "WorldSession::SendTaxiStatus - %s not found.", guid.ToString().c_str()); return; } uint32 curloc = sObjectMgr->GetNearestTaxiNode(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ(), unit->GetMapId(), GetPlayer()->GetTeam()); WorldPackets::Taxi::TaxiNodeStatus data; data.Unit = guid; if (!curloc) data.Status = TAXISTATUS_NONE; else if (unit->GetReactionTo(GetPlayer()) >= REP_NEUTRAL) data.Status = GetPlayer()->m_taxi.IsTaximaskNodeKnown(curloc) ? TAXISTATUS_LEARNED : TAXISTATUS_UNLEARNED; else data.Status = TAXISTATUS_NOT_ELIGIBLE; SendPacket(data.Write()); }
bool OrbOfMurlocControl(uint32 i, Spell* pSpell) { if(pSpell->u_caster->IsPlayer() == false) return true; Player *plr = (Player*)pSpell->u_caster; Unit *unit_target = (Unit*)plr->GetMapMgr()->GetCreature(GET_LOWGUID_PART(plr->GetSelection())); if(unit_target == NULL) return true; if(!unit_target->IsCreature()) return true; Creature *target = (Creature*)unit_target; QuestLogEntry *qle = plr->GetQuestLogForEntry(11541); if(qle == NULL) return true; if(target->GetEntry() == 25084) { if(qle->GetMobCount(0) < qle->GetQuest()->required_mobcount[0]) { uint32 newcount = qle->GetMobCount(0) + 1; qle->SetMobCount(0, newcount); qle->SendUpdateAddKill(0); Creature *FreedGreengill = sEAS.SpawnCreature(plr, 25085, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), target->GetOrientation(), 0); FreedGreengill->Despawn(6*60*1000, 0); target->Despawn(0, 6*60*1000); qle->UpdatePlayerFields(); return true; } } return true; }
void WorldSession::HandleActivateTaxiOpcode(WorldPackets::Taxi::ActivateTaxi& activateTaxi) { Creature* unit = GetPlayer()->GetNPCIfCanInteractWith(activateTaxi.Vendor, UNIT_NPC_FLAG_FLIGHTMASTER); if (!unit) { TC_LOG_DEBUG("network", "WORLD: HandleActivateTaxiOpcode - %s not found or you can't interact with it.", activateTaxi.Vendor.ToString().c_str()); return; } uint32 curloc = sObjectMgr->GetNearestTaxiNode(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ(), unit->GetMapId(), GetPlayer()->GetTeam()); if (!curloc) return; TaxiNodesEntry const* from = sTaxiNodesStore.LookupEntry(curloc); TaxiNodesEntry const* to = sTaxiNodesStore.LookupEntry(activateTaxi.Node); if (!to) return; if (!GetPlayer()->isTaxiCheater()) { if (!GetPlayer()->m_taxi.IsTaximaskNodeKnown(curloc) || !GetPlayer()->m_taxi.IsTaximaskNodeKnown(activateTaxi.Node)) { SendActivateTaxiReply(ERR_TAXINOTVISITED); return; } } uint32 preferredMountDisplay = 0; if (MountEntry const* mount = sMountStore.LookupEntry(activateTaxi.FlyingMountID)) if (GetPlayer()->HasSpell(mount->SpellId)) preferredMountDisplay = mount->DisplayId; std::vector<uint32> nodes; sTaxiPathGraph.GetCompleteNodeRoute(from, to, GetPlayer(), nodes); GetPlayer()->ActivateTaxiPathTo(nodes, unit, 0, preferredMountDisplay); }
void WorldSession::SendTaxiStatus(ObjectGuid guid) { // cheating checks Creature* unit = GetPlayer()->GetMap()->GetCreature(guid); if (!unit) { TC_LOG_DEBUG("network", "WorldSession::SendTaxiStatus - %s not found.", guid.ToString().c_str()); return; } uint32 curloc = sObjectMgr->GetNearestTaxiNode(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ(), unit->GetMapId(), GetPlayer()->GetTeam()); // not found nearest if (curloc == 0) return; TC_LOG_DEBUG("network", "WORLD: current location %u ", curloc); WorldPacket data(SMSG_TAXI_NODE_STATUS, 9); data << guid; data << uint8(GetPlayer()->m_taxi.IsTaximaskNodeKnown(curloc) ? 1 : 0); SendPacket(&data); TC_LOG_DEBUG("network", "WORLD: Sent SMSG_TAXINODE_STATUS"); }
void WorldSession::SendTaxiStatus(uint64 guid) { // cheating checks Creature* unit = GetPlayer()->GetMap()->GetCreature(guid); if (!unit) { sLog.outDebug("WorldSession::SendTaxiStatus - Unit (GUID: %u) not found.", uint32(GUID_LOPART(guid))); return; } uint32 curloc = objmgr.GetNearestTaxiNode(unit->GetPositionX(),unit->GetPositionY(),unit->GetPositionZ(),unit->GetMapId()); // not found nearest if (curloc == 0) return; DEBUG_LOG("WORLD: current location %u ",curloc); WorldPacket data(SMSG_TAXINODE_STATUS, 9); data << guid; data << uint8(GetPlayer()->m_taxi.IsTaximaskNodeKnown(curloc) ? 1 : 0); SendPacket(&data); DEBUG_LOG("WORLD: Sent SMSG_TAXINODE_STATUS"); }
void SetData(uint32 type, uint32 data) { switch (type) { case DATA_RAGEWINTERCHILLEVENT: m_auiEncounter[0] = data; break; case DATA_ANETHERONEVENT: m_auiEncounter[1] = data; break; case DATA_KAZROGALEVENT: m_auiEncounter[2] = data; break; case DATA_AZGALOREVENT: { m_auiEncounter[3] = data; if (data == DONE) { if (ArchiYell) break; ArchiYell = true; Creature* creature = instance->GetCreature(Azgalor); if (creature) { Creature* unit = creature->SummonCreature(21987, creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN, 10000); Map* map = creature->GetMap(); if (map->IsDungeon() && unit) { unit->SetVisible(false); Map::PlayerList const &PlayerList = map->GetPlayers(); if (PlayerList.isEmpty()) return; for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i) { if (i->getSource()) { WorldPacket packet(SMSG_MESSAGECHAT, 200); unit->BuildMonsterChat(&packet, CHAT_MSG_MONSTER_YELL, YELL_EFFORTS, 0, YELL_EFFORTS_NAME, i->getSource()->GetGUID()); i->getSource()->GetSession()->SendPacket(&packet); WorldPacket data2(SMSG_PLAY_SOUND, 4); data2 << uint32(10986); data2 << uint64(unit->GetGUID()); i->getSource()->GetSession()->SendPacket(&data2); } } } } } } break; case DATA_ARCHIMONDEEVENT: m_auiEncounter[4] = data; break; case DATA_RESET_TRASH_COUNT: Trash = 0; break; case DATA_TRASH: if (data) Trash = data; else Trash--; DoUpdateWorldState(WORLD_STATE_ENEMYCOUNT, Trash); break; case TYPE_RETREAT: if (data == SPECIAL) { if (!m_uiAncientGemGUID.empty()) { for (std::list<uint64>::const_iterator itr = m_uiAncientGemGUID.begin(); itr != m_uiAncientGemGUID.end(); ++itr) { //don't know how long it expected DoRespawnGameObject(*itr, DAY); } } } break; case DATA_ALLIANCE_RETREAT: allianceRetreat = data; HandleGameObject(HordeGate, true); SaveToDB(); break; case DATA_HORDE_RETREAT: hordeRetreat = data; HandleGameObject(ElfGate, true); SaveToDB(); break; case DATA_RAIDDAMAGE: RaidDamage += data; if (RaidDamage >= MINRAIDDAMAGE) RaidDamage = MINRAIDDAMAGE; break; case DATA_RESET_RAIDDAMAGE: RaidDamage = 0; break; } TC_LOG_DEBUG(LOG_FILTER_TSCR, "Instance Hyjal: Instance data updated for event %u (Data=%u)", type, data); if (data == DONE) { OUT_SAVE_INST_DATA; std::ostringstream saveStream; saveStream << m_auiEncounter[0] << ' ' << m_auiEncounter[1] << ' ' << m_auiEncounter[2] << ' ' << m_auiEncounter[3] << ' ' << m_auiEncounter[4] << ' ' << allianceRetreat << ' ' << hordeRetreat << ' ' << RaidDamage; str_data = saveStream.str(); SaveToDB(); OUT_SAVE_INST_DATA_COMPLETE; } }
bool ChatHandler::HandleDeleteCommand(const char* args, WorldSession *m_session) { uint64 guid = m_session->GetPlayer()->GetSelection(); if (guid == 0) { SystemMessage(m_session, "No selection."); return true; } Creature *unit = m_session->GetPlayer()->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(!unit) { SystemMessage(m_session, "You should select a creature."); return true; } if ( unit->IsPet() ) { SystemMessage(m_session, "You can't delete a pet." ); return true; } sGMLog.writefromsession(m_session, "used npc delete, sqlid %u, creature %s, pos %f %f %f", unit->GetSQL_id(), unit->GetCreatureInfo() ? unit->GetCreatureInfo()->Name : "wtfbbqhax", unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ()); if( unit->m_spawn == NULL ) return false; BlueSystemMessage(m_session, "Deleted creature ID %u", unit->spawnid); if(unit->IsInWorld()) { if(unit->m_spawn) { uint32 cellx=float2int32(((_maxX-unit->m_spawn->x)/_cellSize)); uint32 celly=float2int32(((_maxY-unit->m_spawn->y)/_cellSize)); if(cellx <= _sizeX && celly <= _sizeY) { CellSpawns * c = unit->GetMapMgr()->GetBaseMap()->GetSpawnsListAndCreate(cellx, celly); for(CreatureSpawnList::iterator itr = c->CreatureSpawns.begin(); itr != c->CreatureSpawns.end(); ++itr) if((*itr) == unit->m_spawn) { c->CreatureSpawns.erase(itr); break; } delete unit->m_spawn; } } unit->RemoveFromWorld(false,true); } unit->DeleteFromDB(); delete unit; return true; }
static bool HandleWpModifyCommand(ChatHandler* handler, const char* args) { if (!*args) return false; // first arg: add del text emote spell waittime move char* show_str = strtok((char*)args, " "); if (!show_str) { return false; } std::string show = show_str; // Check // Remember: "show" must also be the name of a column! if ((show != "delay") && (show != "action") && (show != "action_chance") && (show != "move_flag") && (show != "del") && (show != "move") && (show != "wpadd") ) { return false; } // Next arg is: <PATHID> <WPNUM> <ARGUMENT> char* arg_str = NULL; // Did user provide a GUID // or did the user select a creature? // -> variable lowguid is filled with the GUID of the NPC uint32 pathid = 0; uint32 point = 0; uint32 wpGuid = 0; Creature* target = handler->getSelectedCreature(); if (!target || target->GetEntry() != VISUAL_WAYPOINT) { handler->SendSysMessage("|cffff33ffERROR: You must select a waypoint.|r"); return false; } // The visual waypoint wpGuid = target->GetGUIDLow(); // User did select a visual waypoint? // Check the creature QueryResult result = WorldDatabase.PQuery("SELECT id, point FROM waypoint_data WHERE wpguid = %u", wpGuid); if (!result) { handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDSEARCH, target->GetGUIDLow()); // Select waypoint number from database // Since we compare float values, we have to deal with // some difficulties. // Here we search for all waypoints that only differ in one from 1 thousand // (0.001) - There is no other way to compare C++ floats with mySQL floats // See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html const char* maxDIFF = "0.01"; result = WorldDatabase.PQuery("SELECT id, point FROM waypoint_data WHERE (abs(position_x - %f) <= %s) and (abs(position_y - %f) <= %s) and (abs(position_z - %f) <= %s)", target->GetPositionX(), maxDIFF, target->GetPositionY(), maxDIFF, target->GetPositionZ(), maxDIFF); if (!result) { handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM, wpGuid); return true; } } do { Field* fields = result->Fetch(); pathid = fields[0].GetUInt32(); point = fields[1].GetUInt32(); } while (result->NextRow()); // We have the waypoint number and the GUID of the "master npc" // Text is enclosed in "<>", all other arguments not arg_str = strtok((char*)NULL, " "); // Check for argument if (show != "del" && show != "move" && arg_str == NULL) { handler->PSendSysMessage(LANG_WAYPOINT_ARGUMENTREQ, show_str); return false; } if (show == "del" && target) { handler->PSendSysMessage("|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff%u|r", pathid); // wpCreature Creature* wpCreature = NULL; if (wpGuid != 0) { wpCreature = handler->GetSession()->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT)); wpCreature->CombatStop(); wpCreature->DeleteFromDB(); wpCreature->AddObjectToRemoveList(); } PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_WAYPOINT_DATA); stmt->setUInt32(0, pathid); stmt->setUInt32(1, point); WorldDatabase.Execute(stmt); stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_DATA_POINT); stmt->setUInt32(0, pathid); stmt->setUInt32(1, point); WorldDatabase.Execute(stmt); handler->PSendSysMessage(LANG_WAYPOINT_REMOVED); return true; } // del if (show == "move" && target) { handler->PSendSysMessage("|cff00ff00DEBUG: wp move, PathID: |r|cff00ffff%u|r", pathid); Player* chr = handler->GetSession()->GetPlayer(); Map* map = chr->GetMap(); { // wpCreature Creature* wpCreature = NULL; // What to do: // Move the visual spawnpoint // Respawn the owner of the waypoints if (wpGuid != 0) { wpCreature = handler->GetSession()->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT)); wpCreature->CombatStop(); wpCreature->DeleteFromDB(); wpCreature->AddObjectToRemoveList(); // re-create Creature* wpCreature2 = new Creature; if (!wpCreature2->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), VISUAL_WAYPOINT, 0, 0, chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(), chr->GetOrientation())) { handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT); delete wpCreature2; return false; } wpCreature2->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn()); // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells(); //TODO: Should we first use "Create" then use "LoadFromDB"? if (!wpCreature2->LoadCreatureFromDB(wpCreature2->GetDBTableGUIDLow(), map)) { handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT); delete wpCreature2; return false; } //sMapMgr->GetMap(npcCreature->GetMapId())->Add(wpCreature2); } PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_DATA_POSITION); stmt->setFloat(0, chr->GetPositionX()); stmt->setFloat(1, chr->GetPositionY()); stmt->setFloat(2, chr->GetPositionZ()); stmt->setUInt32(3, pathid); stmt->setUInt32(4, point); WorldDatabase.Execute(stmt); handler->PSendSysMessage(LANG_WAYPOINT_CHANGED); } return true; } // move const char *text = arg_str; if (text == 0) { // show_str check for present in list of correct values, no sql injection possible WorldDatabase.PExecute("UPDATE waypoint_data SET %s=NULL WHERE id='%u' AND point='%u'", show_str, pathid, point); // Query can't be a prepared statement } else { // show_str check for present in list of correct values, no sql injection possible std::string text2 = text; WorldDatabase.EscapeString(text2); WorldDatabase.PExecute("UPDATE waypoint_data SET %s='%s' WHERE id='%u' AND point='%u'", show_str, text2.c_str(), pathid, point); // Query can't be a prepared statement } handler->PSendSysMessage(LANG_WAYPOINT_CHANGED_NO, show_str); return true; }