void Vehicle::InstallAccessory(uint32 entry, int8 seatId) { if(Unit *passenger = GetPassenger(seatId)) { // already installed if(passenger->GetEntry() == entry) return; passenger->ExitVehicle(); // this should not happen } const CreatureInfo *cInfo = objmgr.GetCreatureTemplate(entry); if(!cInfo) return; Creature *accessory; if(cInfo->VehicleId) accessory = SummonVehicle(entry, GetPositionX(), GetPositionY(), GetPositionZ()); else accessory = SummonCreature(entry, GetPositionX(), GetPositionY(), GetPositionZ()); if(!accessory) return; accessory->EnterVehicle(this, seatId); // This is not good, we have to send update twice accessory->SendMovementFlagUpdate(); }
void Transport::UpdateNPCPositions() { for(CreatureSet::iterator itr = m_NPCPassengerSet.begin(); itr != m_NPCPassengerSet.end(); ++itr) { Creature* npc = *itr; float x, y, z, o; o = GetOrientation() + npc->m_movementInfo.t_pos.m_orientation; MapManager::NormalizeOrientation(o); x = GetPositionX() + (npc->m_movementInfo.t_pos.m_positionX * cos(GetOrientation()) + npc->m_movementInfo.t_pos.m_positionY * sin(GetOrientation() + M_PI)); y = GetPositionY() + (npc->m_movementInfo.t_pos.m_positionY * cos(GetOrientation()) + npc->m_movementInfo.t_pos.m_positionX * sin(GetOrientation())); z = GetPositionZ() + npc->m_movementInfo.t_pos.m_positionZ; npc->SetHomePosition(x, y, z, o); GetMap()->CreatureRelocation(npc, x, y, z, o, false); } for(PlayerSet::iterator itr = m_passengers.begin(); itr != m_passengers.end(); ++itr) { Player* plr = *itr; float x, y, z, o; o = GetOrientation() + plr->m_movementInfo.t_pos.m_orientation; MapManager::NormalizeOrientation(o); x = GetPositionX() + (plr->m_movementInfo.t_pos.m_positionX * cos(GetOrientation()) + plr->m_movementInfo.t_pos.m_positionY * sin(GetOrientation() + M_PI)); y = GetPositionY() + (plr->m_movementInfo.t_pos.m_positionY * cos(GetOrientation()) + plr->m_movementInfo.t_pos.m_positionX * sin(GetOrientation())); z = GetPositionZ() + plr->m_movementInfo.t_pos.m_positionZ; plr->Relocate(x, y, z, o); UpdateData transData; WorldPacket packet; transData.BuildPacket(&packet); plr->SendDirectMessage(&packet); } }
void Enemy::Die() { Plane::Die(); Effect* boom = Effect::Create("boom1"); boom->SetPosition(GetPositionX(), GetPositionY(), GetPositionZ()); boom->SetOrder(LAYER_ENEMY_BOOM); GetScene()->Add(boom); Effect* cool = Effect::Create("cool"); cool->SetColorRGB(rand() % 128 + 128, rand() % 128 + 128, rand() % 128 + 128); cool->ResetVertex(); cool->SetPosition(GetPositionX() + rand() % 21 - 10, GetPositionY() + rand() % 21 - 10, GetPositionZ()); cool->RunAction(Frame2D::Move::Create(2.5, GetPositionX() + 50, GetPositionY())); cool->SetOrder(LAYER_UI_1); GetScene()->Add(cool); // 如果有道具那么掉落道具 if (_itemID != 0) { Item* item = Item::Create(_itemID); item->SetPosition(GetPositionX(), GetPositionY(), GetPositionZ()); item->SetOrder(LAYER_ITEM); GetScene()->Add(item); _itemID = 0; } }
void AreaTrigger::SearchUnitInBox(std::list<Unit*>& targetList) { float extentsX = GetTemplate()->BoxDatas.Extents[0]; float extentsY = GetTemplate()->BoxDatas.Extents[1]; float extentsZ = GetTemplate()->BoxDatas.Extents[2]; Trinity::AnyUnitInObjectRangeCheck check(this, GetTemplate()->MaxSearchRadius, false); Trinity::UnitListSearcher<Trinity::AnyUnitInObjectRangeCheck> searcher(this, targetList, check); Cell::VisitAllObjects(this, searcher, GetTemplate()->MaxSearchRadius); float halfExtentsX = extentsX / 2.0f; float halfExtentsY = extentsY / 2.0f; float halfExtentsZ = extentsZ / 2.0f; float minX = GetPositionX() - halfExtentsX; float maxX = GetPositionX() + halfExtentsX; float minY = GetPositionY() - halfExtentsY; float maxY = GetPositionY() + halfExtentsY; float minZ = GetPositionZ() - halfExtentsZ; float maxZ = GetPositionZ() + halfExtentsZ; G3D::AABox const box({ minX, minY, minZ }, { maxX, maxY, maxZ }); targetList.remove_if([&box](Unit* unit) -> bool { return !box.contains({ unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ() }); }); }
void GameObject::SaveToFile(std::stringstream & name) { std::stringstream ss; ss << "REPLACE INTO gameobject_spawns VALUES(" << ((m_spawn == NULL) ? 0 : m_spawn->id) << "," << GetEntry() << "," << GetMapId() << "," << GetPositionX() << "," << GetPositionY() << "," << GetPositionZ() << "," << GetOrientation() << "," << GetFloatValue(GAMEOBJECT_ROTATION) << "," << GetFloatValue(GAMEOBJECT_ROTATION_01) << "," << GetFloatValue(GAMEOBJECT_ROTATION_02) << "," << GetFloatValue(GAMEOBJECT_ROTATION_03) << "," << GetUInt32Value(GAMEOBJECT_STATE) << "," << GetUInt32Value(GAMEOBJECT_FLAGS) << "," << GetUInt32Value(GAMEOBJECT_FACTION) << "," << GetFloatValue(OBJECT_FIELD_SCALE_X) << "," << "0)"; FILE * OutFile; OutFile = fopen(name.str().c_str(), "wb"); if (!OutFile) return; fwrite(ss.str().c_str(),1,ss.str().size(),OutFile); fclose(OutFile); }
void Corpse::SaveToDB() { // prevent DB data inconsistence problems and duplicates SQLTransaction trans = CharacterDatabase.BeginTransaction(); DeleteFromDB(trans); uint16 index = 0; PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CORPSE); stmt->setUInt32(index++, GetGUIDLow()); // corpseGuid stmt->setUInt32(index++, GUID_LOPART(GetOwnerGUID())); // guid stmt->setFloat (index++, GetPositionX()); // posX stmt->setFloat (index++, GetPositionY()); // posY stmt->setFloat (index++, GetPositionZ()); // posZ stmt->setFloat (index++, GetOrientation()); // orientation stmt->setUInt16(index++, GetMapId()); // mapId stmt->setUInt32(index++, GetUInt32Value(CORPSE_FIELD_DISPLAY_ID)); // displayId stmt->setString(index++, _ConcatFields(CORPSE_FIELD_ITEMS, EQUIPMENT_SLOT_END)); // itemCache stmt->setUInt32(index++, GetUInt32Value(CORPSE_FIELD_SKIN_ID)); // bytes1 stmt->setUInt32(index++, GetUInt32Value(CORPSE_FIELD_FACIAL_HAIR_STYLE_ID)); // bytes2 stmt->setUInt8 (index++, GetUInt32Value(CORPSE_FIELD_FLAGS)); // flags stmt->setUInt8 (index++, GetUInt32Value(CORPSE_FIELD_DYNAMIC_FLAGS)); // dynFlags stmt->setUInt32(index++, uint32(m_time)); // time stmt->setUInt8 (index++, GetType()); // corpseType stmt->setUInt32(index++, GetInstanceId()); // instanceId stmt->setUInt32(index++, GetPhaseMask()); // phaseMask trans->Append(stmt); CharacterDatabase.CommitTransaction(trans); }
bool Corpse::Create(uint32 guidlow, Player *owner) { SetInstanceId(owner->GetInstanceId()); WorldObject::_Create(guidlow, HIGHGUID_CORPSE, owner->GetMapId()); Relocate(owner->GetPositionX(), owner->GetPositionY(), owner->GetPositionZ(), owner->GetOrientation()); if (!IsPositionValid()) { sLog.outLog(LOG_DEFAULT, "ERROR: Corpse (guidlow %d, owner %s) not created. Suggested coordinates isn't valid (X: %f Y: %f)", guidlow,owner->GetName(),owner->GetPositionX(), owner->GetPositionY()); return false; } SetFloatValue(OBJECT_FIELD_SCALE_X, 1); SetFloatValue(CORPSE_FIELD_POS_X, GetPositionX()); SetFloatValue(CORPSE_FIELD_POS_Y, GetPositionY()); SetFloatValue(CORPSE_FIELD_POS_Z, GetPositionZ()); SetFloatValue(CORPSE_FIELD_FACING, GetOrientation()); SetUInt64Value(CORPSE_FIELD_OWNER, owner->GetGUID()); m_grid = Hellground::ComputeGridPair(GetPositionX(), GetPositionY()); return true; }
void Corpse::SaveToDB() { // prevent DB data inconsistence problems and duplicates RealmDataDatabase.BeginTransaction(); DeleteFromDB(); static SqlStatementID saveCorpse; SqlStatement stmt = RealmDataDatabase.CreateStatement(saveCorpse, "INSERT INTO corpse (guid,player,position_x,position_y,position_z,orientation,zone,map,data,time,corpse_type,instance) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); stmt.addUInt64(GetGUIDLow()); stmt.addUInt64(GUID_LOPART(GetOwnerGUID())); stmt.addFloat(GetPositionX()); stmt.addFloat(GetPositionY()); stmt.addFloat(GetPositionZ()); stmt.addFloat(GetOrientation()); stmt.addUInt32(GetZoneId()); stmt.addUInt32(GetMapId()); stmt.addString(GetUInt32ValuesString()); stmt.addUInt64(m_time); stmt.addUInt32(GetType()); stmt.addInt32(GetInstanceId()); stmt.Execute(); RealmDataDatabase.CommitTransaction(); }
void Corpse::SaveToDB() { // bones should not be saved to DB (would be deleted on startup anyway) MANGOS_ASSERT(GetType() != CORPSE_BONES); // prevent DB data inconsistence problems and duplicates CharacterDatabase.BeginTransaction(); DeleteFromDB(); std::ostringstream ss; ss << "INSERT INTO corpse (guid,player,position_x,position_y,position_z,orientation,zone,map,data,time,corpse_type,instance) VALUES (" << GetGUIDLow() << ", " << GUID_LOPART(GetOwnerGUID()) << ", " << GetPositionX() << ", " << GetPositionY() << ", " << GetPositionZ() << ", " << GetOrientation() << ", " << GetZoneId() << ", " << GetMapId() << ", '"; for(uint16 i = 0; i < m_valuesCount; ++i) ss << GetUInt32Value(i) << " "; ss << "'," << uint64(m_time) <<", " << uint32(GetType()) << ", " << int(GetInstanceId()) << ")"; CharacterDatabase.Execute( ss.str().c_str() ); CharacterDatabase.CommitTransaction(); }
void Corpse::SaveToDB() { // prevent DB data inconsistence problems and duplicates CharacterDatabase.BeginTransaction(); DeleteFromDB(); std::ostringstream ss; ss << "INSERT INTO corpse (guid,player,position_x,position_y,position_z,orientation,zone,map,data,time,corpse_type,instance,phaseMask) VALUES (" << GetGUIDLow() << ", " << GUID_LOPART(GetOwnerGUID()) << ", " << GetPositionX() << ", " << GetPositionY() << ", " << GetPositionZ() << ", " << GetOrientation() << ", " << GetZoneId() << ", " << GetMapId() << ", '"; for (uint16 i = 0; i < m_valuesCount; ++i) ss << GetUInt32Value(i) << " "; ss << "'," << uint64(m_time) <<", " << uint32(GetType()) << ", " << int(GetInstanceId()) << ", " << uint16(GetPhaseMask()) << ")"; // prevent out of range error CharacterDatabase.Execute(ss.str().c_str()); CharacterDatabase.CommitTransaction(); }
void Position::RelocateOffset(const Position & offset) { m_positionX = GetPositionX() + (offset.GetPositionX() * std::cos(GetOrientation()) + offset.GetPositionY() * std::sin(GetOrientation() + float(M_PI))); m_positionY = GetPositionY() + (offset.GetPositionY() * std::cos(GetOrientation()) + offset.GetPositionX() * std::sin(GetOrientation())); m_positionZ = GetPositionZ() + offset.GetPositionZ(); SetOrientation(GetOrientation() + offset.GetOrientation()); }
bool Vehicle::Create(uint32 guidlow, Map *map, uint32 Entry, uint32 vehicleId, uint32 team) { SetMapId(map->GetId()); SetInstanceId(map->GetInstanceId()); Object::_Create(guidlow, Entry, HIGHGUID_VEHICLE); if(!InitEntry(Entry, team)) return false; m_defaultMovementType = IDLE_MOTION_TYPE; AIM_Initialize(); SetVehicleId(vehicleId); SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK); SetFloatValue(UNIT_FIELD_HOVERHEIGHT, 1.0f); CreatureInfo const *ci = GetCreatureInfo(); setFaction(team == ALLIANCE ? ci->faction_A : ci->faction_H); SetMaxHealth(ci->maxhealth); SelectLevel(ci); SetHealth(GetMaxHealth()); for( int i = 0; i < 4; ++i ) this->m_spells[i] = this->GetCreatureInfo()->spells[i]; // So our vehicles can have spells on bar GetMotionMaster()->MovePoint(0, GetPositionX(), GetPositionY(), GetPositionZ()+2 ); // So we can fly with Dragon Vehicles return true; }
bool Position::IsWithinBox(const Position& center, float xradius, float yradius, float zradius) const { // rotate the WorldObject position instead of rotating the whole cube, that way we can make a simplified // is-in-cube check and we have to calculate only one point instead of 4 // 2PI = 360*, keep in mind that ingame orientation is counter-clockwise double rotation = 2 * M_PI - center.GetOrientation(); double sinVal = std::sin(rotation); double cosVal = std::cos(rotation); float BoxDistX = GetPositionX() - center.GetPositionX(); float BoxDistY = GetPositionY() - center.GetPositionY(); float rotX = float(center.GetPositionX() + BoxDistX * cosVal - BoxDistY*sinVal); float rotY = float(center.GetPositionY() + BoxDistY * cosVal + BoxDistX*sinVal); // box edges are parallel to coordiante axis, so we can treat every dimension independently :D float dz = GetPositionZ() - center.GetPositionZ(); float dx = rotX - center.GetPositionX(); float dy = rotY - center.GetPositionY(); if ((std::fabs(dx) > xradius) || (std::fabs(dy) > yradius) || (std::fabs(dz) > zradius)) return false; return true; }
void Creature::GetRespawnPosition(float &x, float &y, float &z, float* ori, float* dist) const { if (m_DBTableGuid) { if (CreatureData const* data = sObjectMgr->GetCreatureData(GetDBTableGUIDLow())) { x = data->posX; y = data->posY; z = data->posZ; if (ori) *ori = data->orientation; if (dist) *dist = data->spawndist; return; } } x = GetPositionX(); y = GetPositionY(); z = GetPositionZ(); if (ori) *ori = GetOrientation(); if (dist) *dist = 0; }
void Transport::UpdatePassengerPositions() { for (UnitSet::iterator itr = _passengers.begin(); itr != _passengers.end(); ++itr) { Unit* passenger = *itr; // transport teleported but passenger not yet (can happen for players) if (passenger->GetMap() != GetMap()) continue; float x = GetPositionX() + (passenger->m_movementInfo.t_pos.m_positionX * cos(GetOrientation()) + passenger->m_movementInfo.t_pos.m_positionY * sin(GetOrientation() + M_PI)); float y = GetPositionY() + (passenger->m_movementInfo.t_pos.m_positionY * cos(GetOrientation()) + passenger->m_movementInfo.t_pos.m_positionX * sin(GetOrientation())); float z = GetPositionZ() + passenger->m_movementInfo.t_pos.m_positionZ; float o = GetOrientation() + passenger->m_movementInfo.t_pos.m_orientation; MapManager::NormalizeOrientation(o); switch (passenger->GetTypeId()) { case TYPEID_UNIT: passenger->ToCreature()->SetHomePosition(x, y, z, o); GetMap()->CreatureRelocation(passenger->ToCreature(), x, y, z, o, false); break; case TYPEID_PLAYER: GetMap()->PlayerRelocation(passenger->ToPlayer(), x, y, z, o); break; } if (passenger->IsVehicle()) passenger->GetVehicleKit()->RelocatePassengers(x, y, z, o); } }
void SpriteGroup::Render() { Element::Render(); for (int i = 0; i < m_sprite_list.size(); ++i) { Sprite* sprite = m_sprite_list.at(i); sprite->Render(); sprite->SetPosition( sprite->GetPositionX() - GetPositionX(), sprite->GetPositionY() - GetPositionY(), sprite->GetPositionZ() - GetPositionZ()); sprite->SetAngle( sprite->GetAngleX() - GetAngleX(), sprite->GetAngleY() - GetAngleY(), sprite->GetAngleZ() - GetAngleZ()); sprite->SetAnchor( sprite->GetAnchorX() * 2.0f - GetAnchorX(), sprite->GetAnchorY() * 2.0f - GetAnchorY()); if (GetScaleX() != 0) { sprite->SetScaleX(sprite->GetScaleX() / GetScaleX()); } if (GetScaleY() != 0) { sprite->SetScaleY(sprite->GetScaleY() / GetScaleY()); } } }
void SpriteGroup::Update(const float& delta) { Element::Update(delta); for (int i = 0; i < m_sprite_list.size(); ++i) { Sprite* sprite = m_sprite_list.at(i); sprite->SetPosition( sprite->GetPositionX() + GetPositionX(), sprite->GetPositionY() + GetPositionY(), sprite->GetPositionZ() + GetPositionZ()); sprite->SetAngle( sprite->GetAngleX() + GetAngleX(), sprite->GetAngleY() + GetAngleY(), sprite->GetAngleZ() + GetAngleZ()); sprite->SetAnchor( (sprite->GetAnchorX() + GetAnchorX()) / 2.0f, (sprite->GetAnchorY() + GetAnchorY()) / 2.0f); sprite->SetScale( sprite->GetScaleX() * GetScaleX(), sprite->GetScaleY() * GetScaleY()); sprite->Update(delta); } }
void Corpse::SaveToDB() { // prevent DB data inconsistence problems and duplicates SQLTransaction trans = CharacterDatabase.BeginTransaction(); DeleteFromDB(trans); PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CORPSE); stmt->setUInt32(0, GetGUIDLow()); // corpseGuid stmt->setUInt32(1, GUID_LOPART(GetOwnerGUID())); // guid stmt->setFloat (2, GetPositionX()); // posX stmt->setFloat (3, GetPositionY()); // posY stmt->setFloat (4, GetPositionZ()); // posZ stmt->setFloat (5, GetOrientation()); // orientation stmt->setUInt16(6, GetMapId()); // mapId stmt->setUInt32(7, GetUInt32Value(CORPSE_FIELD_DISPLAY_ID)); // displayId stmt->setString(8, _ConcatFields(CORPSE_FIELD_ITEM, EQUIPMENT_SLOT_END)); // itemCache stmt->setUInt32(9, GetUInt32Value(CORPSE_FIELD_BYTES_1)); // bytes1 stmt->setUInt32(10, GetUInt32Value(CORPSE_FIELD_BYTES_2)); // bytes2 stmt->setUInt32(11, GetUInt32Value(CORPSE_FIELD_GUILD)); // guildId stmt->setUInt8 (12, GetUInt32Value(CORPSE_FIELD_FLAGS)); // flags stmt->setUInt8 (13, GetUInt32Value(CORPSE_FIELD_DYNAMIC_FLAGS)); // dynFlags stmt->setUInt32(14, uint32(m_time)); // time stmt->setUInt8 (15, GetType()); // corpseType stmt->setUInt32(16, GetInstanceId()); // instanceId stmt->setUInt16(17, GetPhaseMask()); // phaseMask trans->Append(stmt); CharacterDatabase.CommitTransaction(trans); }
void Corpse::SaveToDB() { // bones should not be saved to DB (would be deleted on startup anyway) MANGOS_ASSERT(GetType() != CORPSE_BONES); // prevent DB data inconsistence problems and duplicates CharacterDatabase.BeginTransaction(); DeleteFromDB(); std::ostringstream ss; ss << "INSERT INTO corpse (guid,player,position_x,position_y,position_z,orientation,map,time,corpse_type,instance,phaseMask) VALUES (" << GetGUIDLow() << ", " << GetOwnerGuid().GetCounter() << ", " << GetPositionX() << ", " << GetPositionY() << ", " << GetPositionZ() << ", " << GetOrientation() << ", " << GetMapId() << ", " << uint64(m_time) << ", " << uint32(GetType()) << ", " << int(GetInstanceId()) << ", " << uint16(GetPhaseMask()) << ")"; // prevent out of range error CharacterDatabase.Execute(ss.str().c_str()); CharacterDatabase.CommitTransaction(); }
void AreaTrigger::SearchUnitInCylinder(std::list<Unit*>& targetList) { Trinity::AnyUnitInObjectRangeCheck check(this, GetTemplate()->MaxSearchRadius, false); Trinity::UnitListSearcher<Trinity::AnyUnitInObjectRangeCheck> searcher(this, targetList, check); Cell::VisitAllObjects(this, searcher, GetTemplate()->MaxSearchRadius); float height = GetTemplate()->CylinderDatas.Height; float minZ = GetPositionZ() - height; float maxZ = GetPositionZ() + height; targetList.remove_if([minZ, maxZ](Unit* unit) -> bool { return unit->GetPositionZ() < minZ || unit->GetPositionZ() > maxZ; }); }
void Corpse::SaveToDB() { // prevent DB data inconsistence problems and duplicates SQLTransaction trans = CharacterDatabase.BeginTransaction(); DeleteFromDB(trans); std::ostringstream ss; ss << "INSERT INTO corpse (guid,player,position_x,position_y,position_z,orientation,zone,map,displayId,itemCache,bytes1,bytes2,guild,flags,dynFlags,time,corpse_type,instance,phaseMask) VALUES (" << GetGUIDLow() << ", " << GUID_LOPART(GetOwnerGUID()) << ", " << GetPositionX() << ", " << GetPositionY() << ", " << GetPositionZ() << ", " << GetOrientation() << ", " << GetZoneId() << ", " << GetMapId() << ", " << GetUInt32Value(CORPSE_FIELD_DISPLAY_ID) << ", '"; for (uint16 i = 0; i < EQUIPMENT_SLOT_END; ++i) ss << GetUInt32Value(CORPSE_FIELD_ITEM+i) << " "; ss << "', " << GetUInt32Value(CORPSE_FIELD_BYTES_1) << ", " << GetUInt32Value(CORPSE_FIELD_BYTES_2) << ", " << GetUInt32Value(CORPSE_FIELD_GUILD) << ", " << GetUInt32Value(CORPSE_FIELD_FLAGS) << ", " << GetUInt32Value(CORPSE_FIELD_DYNAMIC_FLAGS) << ", " << uint64(m_time) << ", " << uint32(GetType()) << ", " << int(GetInstanceId()) << ", " << uint16(GetPhaseMask()) << ")"; // prevent out of range error trans->Append(ss.str().c_str()); CharacterDatabase.CommitTransaction(trans); }
bool Corpse::Create(uint32 guidlow, Player* owner) { MANGOS_ASSERT(owner); WorldObject::_Create(guidlow, HIGHGUID_CORPSE); Relocate(owner->GetPositionX(), owner->GetPositionY(), owner->GetPositionZ(), owner->GetOrientation()); // we need to assign owner's map for corpse // in other way we will get a crash in Corpse::SaveToDB() SetMap(owner->GetMap()); if (!IsPositionValid()) { sLog.outError("Corpse (guidlow %d, owner %s) not created. Suggested coordinates isn't valid (X: %f Y: %f)", guidlow, owner->GetName(), owner->GetPositionX(), owner->GetPositionY()); return false; } SetObjectScale(DEFAULT_OBJECT_SCALE); SetFloatValue(CORPSE_FIELD_POS_X, GetPositionX()); SetFloatValue(CORPSE_FIELD_POS_Y, GetPositionY()); SetFloatValue(CORPSE_FIELD_POS_Z, GetPositionZ()); SetFloatValue(CORPSE_FIELD_FACING, GetOrientation()); SetGuidValue(CORPSE_FIELD_OWNER, owner->GetObjectGuid()); m_grid = MaNGOS::ComputeGridPair(GetPositionX(), GetPositionY()); return true; }
void DynamicObject::DealWithSpellDamage(Player &caster) { uint32 runtimes=1; if(deleteThis) runtimes=m_DamageMaxTimes-m_DamageCurTimes; for(int i=0; i<runtimes; i++) { UnitList.clear(); MapManager::Instance().GetMap(m_mapId)->GetUnitList(GetPositionX(), GetPositionY(),UnitList); for(std::list<Unit*>::iterator iter=UnitList.begin(); iter!=UnitList.end(); iter++) { if((*iter)) { if( (*iter)->isAlive() ) { if(_CalcDistance(GetPositionX(),GetPositionY(),GetPositionZ(),(*iter)->GetPositionX(),(*iter)->GetPositionY(),(*iter)->GetPositionZ()) < m_PeriodicDamageRadius && (*iter)->GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE) != caster.GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE)) { caster.PeriodicAuraLog((*iter),m_spell->Id,m_PeriodicDamage,m_spell->School); } } } } m_DamageCurTimes++; } }
//! This method transforms supplied transport offsets into global coordinates void Transport::CalculatePassengerPosition(float& x, float& y, float& z, float& o) { float inx = x, iny = y, inz = z, ino = o; o = GetOrientation() + ino; x = GetPositionX() + (inx * cos(GetOrientation()) + iny * sin(GetOrientation() + M_PI)); y = GetPositionY() + (iny * cos(GetOrientation()) + inx * sin(GetOrientation())); z = GetPositionZ() + inz; }
void Transport::CalculatePassengerPosition(float& x, float& y, float& z, float& o) const { float inx = x, iny = y, inz = z, ino = o; o = GetOrientation() + ino; x = GetPositionX() + inx * std::cos(GetOrientation()) - iny * std::sin(GetOrientation()); y = GetPositionY() + iny * std::cos(GetOrientation()) + inx * std::sin(GetOrientation()); z = GetPositionZ() + inz; }
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); } }
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::RellocatePassengers(Map *map) { if (m_Seats.empty()) return; for(SeatMap::iterator itr = m_Seats.begin(); itr != m_Seats.end(); ++itr) { if(itr->second.flags & SEAT_FULL) { // passenger cant be NULL here Unit *passengers = itr->second.passenger; assert(passengers); float xx = GetPositionX() + passengers->m_movementInfo.GetTransportPos()->x; float yy = GetPositionY() + passengers->m_movementInfo.GetTransportPos()->y; float zz = GetPositionZ() + passengers->m_movementInfo.GetTransportPos()->z; //float oo = passengers->m_SeatData.Orientation; // this is not correct, we should recalculate // actual rotation depending on vehicle float oo = passengers->GetOrientation(); if(passengers->GetTypeId() == TYPEID_PLAYER) ((Player*)passengers)->SetPosition(xx, yy, zz, oo); else map->CreatureRelocation((Creature*)passengers, xx, yy, zz, oo); } else if(itr->second.flags & (SEAT_VEHICLE_FULL | SEAT_VEHICLE_FREE)) { // passenger cant be NULL here Unit *passengers = itr->second.passenger; assert(passengers); float xx = GetPositionX() + passengers->m_movementInfo.GetTransportPos()->x; float yy = GetPositionY() + passengers->m_movementInfo.GetTransportPos()->y; float zz = GetPositionZ() + passengers->m_movementInfo.GetTransportPos()->z; //float oo = passengers->m_SeatData.Orientation; // this is not correct, we should recalculate // actual rotation depending on vehicle float oo = passengers->GetOrientation(); map->CreatureRelocation((Creature*)passengers, xx, yy, zz, oo); } } }
//! This method transforms supplied global coordinates into local offsets void Transport::CalculatePassengerOffset(float& x, float& y, float& z, float& o) { o -= GetOrientation(); z -= GetPositionZ(); y -= GetPositionY(); // y = searchedY * cos(o) + searchedX * sin(o) x -= GetPositionX(); // x = searchedX * cos(o) + searchedY * sin(o + pi) float inx = x, iny = y; y = (iny - inx * tan(GetOrientation())) / (cos(GetOrientation()) - sin(GetOrientation() + M_PI) * tan(GetOrientation())); x = (inx - iny * sin(GetOrientation() + M_PI) / cos(GetOrientation())) / (cos(GetOrientation()) - tan(GetOrientation()) * sin(GetOrientation() + M_PI)); }
void Transport::CalculatePassengerPosition(float& x, float& y, float& z, float* o /*= NULL*/) const { float inx = x, iny = y, inz = z; if (o) *o = Position::NormalizeOrientation(GetOrientation() + *o); x = GetPositionX() + inx * std::cos(GetOrientation()) - iny * std::sin(GetOrientation()); y = GetPositionY() + iny * std::cos(GetOrientation()) + inx * std::sin(GetOrientation()); z = GetPositionZ() + inz; }