Example #1
0
/* true if the instance save is still valid */
bool InstanceSave::UnloadIfEmpty()
{
    if (m_playerList.empty() && m_groupList.empty())
    {
        if (!sInstanceSaveMgr->lock_instLists)
            sInstanceSaveMgr->RemoveInstanceSave(GetInstanceId());

        return false;
    }
    else
        return true;
}
// push Renderable nodes
//virtual
bool ControlPointGob::GetRenderables(RenderableNodeCollector* collector, RenderContext* context)
{
  
    Mesh* mesh = ShapeLibGetMesh(RenderShape::QuadLineStrip);
    m_localBounds = mesh->bounds;

    const float pointSize = 8; // control point size in pixels
    float upp = context->Cam().ComputeUnitPerPixel(float3(&m_world.M41),
        context->ViewPort().y);
    float scale = pointSize * upp;        
    Matrix scaleM = Matrix::CreateScale(scale);
    float3 objectPos = float3(m_world.M41,m_world.M42,m_world.M43);
    Matrix b = Matrix::CreateBillboard(objectPos,context->Cam().CamPos(),context->Cam().CamUp(),context->Cam().CamLook());
    Matrix billboard = scaleM * b;

    // calculate bounds for screen facing quad
    float3 transformed, min, max;
    transformed = mesh->pos[0];
    transformed.Transform(billboard);
    min = max = transformed;
    for (auto it = mesh->pos.begin(); it != mesh->pos.end(); ++it)
    {
        transformed = (*it);
        transformed.Transform(billboard);
        min = minimize(min, transformed);
        max = maximize(max, transformed);
    }
    m_bounds = AABB(min,max);

    // give it same color as curve
    int color = 0xFFFF0000;
    CurveGob* curve = (CurveGob*)m_parent;
    if(curve != NULL)
    {
        color = curve->GetColor();
    }

    // set renderable
    RenderableNode r;
    r.mesh = mesh;
    ConvertColor(color, &r.diffuse);
    r.objectId = GetInstanceId();
    r.bounds = m_bounds;
    r.WorldXform = billboard;
    r.SetFlag(RenderableNode::kTestAgainstBBoxOnly, true);
    r.SetFlag(RenderableNode::kShadowCaster, false);
    r.SetFlag(RenderableNode::kShadowReceiver, false);
    
    collector->Add(r, RenderFlags::None, Shaders::BasicShader);
    return true;
}
DungeonPersistentState::~DungeonPersistentState()
{
    DEBUG_LOG("Unloading DungeonPersistantState of map %u instance %u", GetMapId(), GetInstanceId());
    while (!m_playerList.empty())
    {
        Player* player = *(m_playerList.begin());
        player->UnbindInstance(GetMapId(), true);
    }
    while (!m_groupList.empty())
    {
        Group* group = *(m_groupList.begin());
        group->UnbindInstance(GetMapId(), true);
    }
}
Example #4
0
void Corpse::SaveToDB()
{
    // prevent DB data inconsistance 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();
}
Example #5
0
bool Renderer::AddTexture(const char * filename, TextureCategory category, TextureWrap wrapS, TextureWrap wrapT, bool invertY)
{
	assert(filename != nullptr);

	uint32_t width = 128;
	uint32_t height = 128;

	TextureManager::GetTiffImageSize(filename, width, height);

	uint16_t rendererId = (uint16_t)GetInstanceId();

	TextureInfo textureInfo(filename, rendererId, category, (GLsizei)width, (GLsizei)height, wrapS, wrapT, invertY);

	mTextureInfoList.push_back(textureInfo);

	return true;
}
Example #6
0
    void SkyDome::Render( RenderContext* context)
    {
        if(IsVisible() == false) 
            return;
       
        RenderableNode r;        
        r.mesh = ShapeLibGetMesh(RenderShape::Sphere);
        r.objectId = GetInstanceId();    
        r.textures[TextureType::Cubemap] = m_texture ? m_texture : TextureLib::Inst()->GetDefault(TextureType::Cubemap);       
        r.SetFlag( RenderableNode::kShadowCaster, false );
        r.SetFlag( RenderableNode::kShadowReceiver, false );

        SkyDomeShader* pShader =(SkyDomeShader*) ShaderLib::Inst()->GetShader(Shaders::SkyDomeShader); 
        pShader->Begin( context);
        pShader->SetRenderFlag( RenderFlags::None );   // call this *after* Begin()        
        pShader->Draw(r);
        
        pShader->End();
    }
Example #7
0
void FastProjectile::StartBullet(float muzzle_velocity) {
	const bool is_synchronized = !GetManager()->IsLocalGameObjectId(GetInstanceId());
	const bool has_barrel = (GetOwnerInstanceId() != 0);
	ProjectileUtil::StartBullet(this, muzzle_velocity, !is_synchronized && has_barrel);

	if (is_synchronized && has_barrel) {
		// Move mesh to muzzle and let it lerp towards object.
		xform transform;
		vec3 velocity;
		ProjectileUtil::GetBarrel(this, transform, velocity);
		for (size_t x = 0; x < mesh_resource_array_.size(); ++x) {
			UiCure::UserGeometryReferenceResource* resource = mesh_resource_array_[x];
			tbc::GeometryBase* gfx_geometry = resource->GetRamData();
			gfx_geometry->SetTransformation(transform);
		}
		EnableMeshSlide(true);
		ActivateLerp();
	}
}
void DungeonPersistentState::UpdateEncounterState(EncounterCreditType type, uint32 creditEntry, Unit* source)
{
    DungeonEncounterList const* encounters = sObjectMgr.GetDungeonEncounterList(GetInstanceId(), GetDifficulty());
    if (!encounters)
        return;

    uint32 dungeonId = 0;
    for (DungeonEncounterList::const_iterator itr = encounters->begin(); itr != encounters->end(); ++itr)
    {
        DungeonEncounter const* encounter = *itr;
        if (encounter->creditType == type && encounter->creditEntry == creditEntry &&
            encounter->difficulty == -1 || (encounter->difficulty == GetDifficulty()))
        {
            m_completedEncountersMask |= 1 << encounter->dbcEntry->encounterIndex;
            if (encounter->lastEncounterDungeon)
            {
                dungeonId = encounter->lastEncounterDungeon;
                sLog.outDebug("UpdateEncounterState: Instance %s (instanceId %u) completed encounter %s. Credit Dungeon: %u", GetMap()->GetMapName(), GetInstanceId(), encounter->dbcEntry->encounterName[0], dungeonId);
                break;
            }
        }
    }

    if (dungeonId)
    {
        Map::PlayerList const& players = GetMap()->GetPlayers();
        for (Map::PlayerList::const_iterator i = players.begin(); i != players.end(); ++i)
        {
            if (Player* player = i->getSource())
            {
                if (Group* grp = player->GetGroup())
                {
                    if (grp->isLFGGroup())
                    {
                        sLFGMgr.FinishDungeon(grp->GetObjectGuid(), dungeonId);
                        return;
                    }
                }
            }
        }
    }
}
Example #9
0
    void Locator::BuildRenderables()
    {
        m_renderables.clear();
        Model* model = NULL;
        assert(m_resource);
        model = (Model*)m_resource->GetTarget();
        
        assert(model && model->IsReady());

        const NodeDict& nodes = model->Nodes();
        for(auto nodeIt = nodes.begin(); nodeIt != nodes.end(); ++nodeIt)
        {
            Node* node = nodeIt->second;
            assert(m_modelTransforms.size() >= node->index);
            const Matrix& world = m_modelTransforms[node->index]; // transform array holds world matricies already, not local
            for(auto geoIt = node->geometries.begin(); geoIt != node->geometries.end(); ++geoIt)
            {
                Geometry* geo = (*geoIt);
                Material * mat = geo->material;
                RenderableNode renderNode;
                renderNode.mesh = geo->mesh;
                renderNode.WorldXform = world;
                renderNode.bounds = geo->mesh->bounds;
                renderNode.bounds.Transform(renderNode.WorldXform);
                renderNode.objectId = GetInstanceId();
                renderNode.diffuse =  mat->diffuse;
                renderNode.specular = mat->specular.xyz();
                renderNode.specPower = mat->power;
                renderNode.SetFlag( RenderableNode::kShadowCaster, GetCastsShadows() );
                renderNode.SetFlag( RenderableNode::kShadowReceiver, GetReceivesShadows() );

                LightingState::Inst()->UpdateLightEnvironment(renderNode);

                for(unsigned int i = TextureType::MIN; i < TextureType::MAX; ++i)
                {
                    renderNode.textures[i] = geo->material->textures[i];
                }
                m_renderables.push_back(renderNode);
            }
        }
    }
Example #10
0
std::string ResourceUIScriptRuntime::AddCallbackRef(ResUIResultCallback resultCallback)
{
	std::unique_lock<std::recursive_mutex> lock(m_refMutex);

	// add the ref to the list
	int32_t idx = m_refIdx;
	m_refs[idx] = resultCallback;

	m_refIdx++;

	// canonicalize the ref
	char* refString;
	m_scriptHost->CanonicalizeRef(idx, GetInstanceId(), &refString);

	// turn into a std::string and free
	std::string retval = refString;
	fwFree(refString);

	// return the value
	return retval;
}
Example #11
0
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->setUInt64(index++, GetGUID().GetCounter());                                 // corpseGuid
    stmt->setUInt64(index++, GetOwnerGUID().GetCounter());                            // 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_ITEM, EQUIPMENT_SLOT_END));   // itemCache
    stmt->setUInt32(index++, GetUInt32Value(CORPSE_FIELD_BYTES_1));                   // bytes1
    stmt->setUInt32(index++, GetUInt32Value(CORPSE_FIELD_BYTES_2));                   // 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
    trans->Append(stmt);

    for (uint32 phaseId : GetPhases())
    {
        index = 0;
        stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CORPSE_PHASES);
        stmt->setUInt32(index++, GetGUID().GetCounter());                                       // Guid (corpse's)
        stmt->setUInt32(index++, phaseId);                                            // PhaseId
        stmt->setUInt32(index++, GetOwnerGUID().GetCounter());                        // OwnerGuid
        stmt->setUInt32(index++, uint32(m_time));                                     // Time
        stmt->setUInt8(index++, GetType());                                           // CorpseType
        trans->Append(stmt);
    }

    CharacterDatabase.CommitTransaction(trans);
}
Example #12
0
//-----------------------------------------------------------------------------------------------------------------------------------
// push Renderable nodes
//virtual
void CurveGob::GetRenderables(RenderableNodeCollector* collector, RenderContext* context)
{
	if (!IsVisible(context->Cam().GetFrustum()) || m_points.size() < 2)
		return;
    
	super::GetRenderables(collector, context);
    
    RenderableNode r;
    r.mesh = &m_mesh;
    ConvertColor(m_color, &r.diffuse);
    r.objectId = GetInstanceId();
    r.SetFlag( RenderableNode::kShadowCaster, false );
    r.SetFlag( RenderableNode::kShadowReceiver, false );
    r.bounds = m_bounds;
    r.WorldXform = m_world;       
    collector->Add( r, RenderFlags::None, Shaders::BasicShader );

    // draw control points.
    for( auto it = m_points.begin(); it != m_points.end(); ++it)
    {
        (*it)->GetRenderables(collector,context);
    }
}
Example #13
0
// Release the DHCP addresses of all virtual LAN cards
void Win32ReleaseAllDhcp9x(bool wait)
{
	TOKEN_LIST *t;
	UINT i;

	t = MsEnumNetworkAdapters(VLAN_ADAPTER_NAME, VLAN_ADAPTER_NAME_OLD);
	if (t == NULL)
	{
		return;
	}

	for (i = 0;i < t->NumTokens;i++)
	{
		char *name = t->Token[i];
		UINT id = GetInstanceId(name);
		if (id != 0)
		{
			Win32ReleaseDhcp9x(id, wait);
		}
	}

	FreeToken(t);
}
Example #14
0
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) VALUES ("
        << GetGUIDLow() << ", "
        << GetOwnerGuid().GetCounter() << ", "
        << GetPositionX() << ", "
        << GetPositionY() << ", "
        << GetPositionZ() << ", "
        << GetOrientation() << ", "
        << GetMapId() << ", "
        << uint64(m_time) << ", "
        << uint32(GetType()) << ", "
        << int(GetInstanceId()) << ")";
    CharacterDatabase.Execute(ss.str().c_str());
    CharacterDatabase.CommitTransaction();
}
/*
    Called from AddPersistentState
*/
void DungeonPersistentState::SaveToDB()
{
    // state instance data too
    std::string data;

    if (Map* map = GetMap())
    {
        InstanceData* iData = map->GetInstanceData();
        if (iData && iData->Save())
        {
            data = iData->Save();
            CharacterDatabase.escape_string(data);
        }
    }

    CharacterDatabase.PExecute("INSERT INTO instance VALUES ('%u', '%u', '" UI64FMTD "', '%u', '%u', '%s')", GetInstanceId(), GetMapId(), (uint64)GetResetTimeForDB(), GetDifficulty(), GetCompletedEncountersMask(), data.c_str());
}
DungeonPersistentState::~DungeonPersistentState()
{
    DEBUG_LOG("Unloading DungeonPersistantState of map %u instance %u", GetMapId(), GetInstanceId());
    UnbindThisState();
}
void DungeonPersistentState::UpdateEncounterState(EncounterCreditType type, uint32 creditEntry, Player* player)
{
    DungeonEncounterList const* encounterList = sObjectMgr.GetDungeonEncounterList(GetMapId(), GetDifficulty());

    if (!encounterList)
        return;

    for (DungeonEncounterList::const_iterator itr = encounterList->begin(); itr != encounterList->end(); ++itr)
    {
        if ((*itr)->creditType == type && (*itr)->creditEntry == creditEntry)
        {
            uint32 oldMask = m_completedEncountersMask;
            m_completedEncountersMask |= 1 << (*itr)->dbcEntry->encounterIndex;
            if ( m_completedEncountersMask != oldMask)
            {
                CharacterDatabase.PExecute("UPDATE instance SET encountersMask = '%u' WHERE id = '%u'", m_completedEncountersMask, GetInstanceId());

                DEBUG_LOG("DungeonPersistentState: Dungeon %s (Id %u) completed encounter %s", GetMap()->GetMapName(), GetInstanceId(), (*itr)->dbcEntry->encounterName[sWorld.GetDefaultDbcLocale()]);

                if (uint32 dungeonId = (*itr)->lastEncounterDungeon)
                {
                    DEBUG_LOG("DungeonPersistentState:: Dungeon %s (Id %u) completed last encounter %s", GetMap()->GetMapName(), GetInstanceId(), (*itr)->dbcEntry->encounterName[sWorld.GetDefaultDbcLocale()]);
                    // Place LFG reward there!
                }

                DungeonMap* dungeon = (DungeonMap*)GetMap();

                if (dungeon && player)
                    dungeon->PermBindAllPlayers(player, dungeon->IsRaidOrHeroicDungeon());
                SaveToDB();
            }
            return;
        }
    }
}
Example #18
0
void GameObject::SaveRespawnTime()
{
    if(m_respawnTime > time(NULL) && m_spawnedByDefault)
        objmgr.SaveGORespawnTime(m_DBTableGuid,GetInstanceId(),m_respawnTime);
}
Example #19
0
void Mine::OnDie() {
	Parent::OnDie();
	GetManager()->PostKillObject(GetInstanceId());
}
Example #20
0
// Start tracking of the routing table
void RouteTrackingStart(SESSION *s)
{
	VLAN *v;
	ROUTE_TRACKING *t;
	UINT if_id = 0;
	ROUTE_ENTRY *e;
	ROUTE_ENTRY *dns = NULL;
	ROUTE_ENTRY *route_to_real_server_global = NULL;
	char tmp[64];
	UINT exclude_if_id = 0;
	bool already_exists = false;
	bool already_exists_by_other_account = false;
	IP eight;
	// Validate arguments
	if (s == NULL)
	{
		return;
	}

	v = (VLAN *)s->PacketAdapter->Param;
	if (v->RouteState != NULL)
	{
		return;
	}

	// Get the interface ID of the virtual LAN card
	if_id = GetInstanceId(v->InstanceName);
	Debug("[InstanceId of %s] = 0x%x\n", v->InstanceName, if_id);

	if (MsIsVista())
	{
		// The routing table by the virtual LAN card body should be
		// excluded explicitly in Windows Vista
		exclude_if_id = if_id;
	}

	// Get the route to the server
	e = GetBestRouteEntryEx(&s->ServerIP, exclude_if_id);
	if (e == NULL)
	{
		// Acquisition failure
		Debug("Failed to get GetBestRouteEntry().\n");
		return;
	}
	IPToStr(tmp, sizeof(tmp), &e->GatewayIP);
	Debug("GetBestRouteEntry() Succeed. [Gateway: %s]\n", tmp);

	// Add a route
	if (MsIsVista())
	{
		e->Metric = e->OldIfMetric;
	}
	if (AddRouteEntryEx(e, &already_exists) == false)
	{
		FreeRouteEntry(e);
		e = NULL;
	}
	Debug("already_exists: %u\n", already_exists);

	if (already_exists)
	{
		if (s->Cedar->Client != NULL && s->Account != NULL)
		{
			UINT i;
			ACCOUNT *a;
			for (i = 0;i < LIST_NUM(s->Cedar->Client->AccountList);i++)
			{
				a = LIST_DATA(s->Cedar->Client->AccountList, i);
				Lock(a->lock);
				{
					SESSION *sess = a->ClientSession;
					if (sess != NULL && sess != s)
					{
						VLAN *v = sess->PacketAdapter->Param;
						if (v != NULL)
						{
							ROUTE_TRACKING *tr = v->RouteState;
							if (tr != NULL && e != NULL)
							{
								if (Cmp(tr->RouteToServer, e, sizeof(ROUTE_ENTRY)) == 0)
								{
									already_exists_by_other_account = true;
								}
							}
						}
					}
				}
				Unlock(a->lock);
			}
		}

		if (already_exists_by_other_account)
		{
			Debug("already_exists_by_other_account = %u\n", already_exists_by_other_account);
			already_exists = false;
		}
	}

	// Get the routing table to the DNS server
	// (If the DNS server is this PC itself, there's no need to get)
	if (IsZeroIP(&s->DefaultDns) == false)
	{
		if (IsMyIPAddress(&s->DefaultDns) == false)
		{
			dns = GetBestRouteEntryEx(&s->DefaultDns, exclude_if_id);
			if (dns == NULL)
			{
				// Getting failure
				Debug("Failed to get GetBestRouteEntry DNS.\n");
			}
			else
			{
				// Add a route
				if (MsIsVista())
				{
					dns->Metric = dns->OldIfMetric;

					if (AddRouteEntry(dns) == false)
					{
						FreeRouteEntry(dns);
						dns = NULL;
					}
				}
			}
		}
	}

	if (s->IsAzureSession && IsZeroIP(&s->AzureRealServerGlobalIp) == false)
	{
		// Add also a static route to the real server in the case of via VPN Azure
		if (IsMyIPAddress(&s->AzureRealServerGlobalIp) == false)
		{
			route_to_real_server_global = GetBestRouteEntryEx(&s->AzureRealServerGlobalIp, exclude_if_id);

			if (route_to_real_server_global != NULL)
			{
				if (MsIsVista())
				{
					route_to_real_server_global->Metric = route_to_real_server_global->OldIfMetric;
				}

				if (AddRouteEntry(route_to_real_server_global) == false)
				{
					FreeRouteEntry(route_to_real_server_global);
					route_to_real_server_global = NULL;
				}
			}
		}
	}

	// Initialize
	if (s->Cedar->Client != NULL && s->Account != NULL)
	{
		Lock(s->Account->lock);
	}

	t = ZeroMalloc(sizeof(ROUTE_TRACKING));
	v->RouteState = t;

	t->RouteToServerAlreadyExists = already_exists;
	t->RouteToServer = e;
	t->RouteToDefaultDns = dns;
	t->RouteToRealServerGlobal = route_to_real_server_global;
	t->VLanInterfaceId = if_id;
	t->NextTrackingTime = 0;
	t->DeletedDefaultGateway = NewQueue();
	t->OldDefaultGatewayMetric = 0x7fffffff;

	if (s->Cedar->Client != NULL && s->Account != NULL)
	{
		Unlock(s->Account->lock);
	}

	// Get the route to 8.8.8.8
	SetIP(&eight, 8, 8, 8, 8);
	t->RouteToEight = GetBestRouteEntryEx(&eight, exclude_if_id);

	// Get the current default DNS server to detect network changes
	GetDefaultDns(&t->OldDnsServer);

	// Get as soon as releasing the IP address in the case of using DHCP
	if (IsNt())
	{
		char tmp[MAX_SIZE];
		MS_ADAPTER *a;

		Format(tmp, sizeof(tmp), VLAN_ADAPTER_NAME_TAG, v->InstanceName);
		a = MsGetAdapter(tmp);

		if (a != NULL)
		{
			if (a->UseDhcp)
			{
				bool ret = Win32ReleaseAddressByGuidEx(a->Guid, 100);
				Debug("*** Win32ReleaseAddressByGuidEx = %u\n", ret);

				ret = Win32RenewAddressByGuidEx(a->Guid, 100);
				Debug("*** Win32RenewAddressByGuidEx = %u\n", ret);
			}

			MsFreeAdapter(a);
		}
	}
	else
	{
		// For Win9x
		Win32RenewDhcp9x(if_id);
	}

	// Clear the DNS cache
	Win32FlushDnsCache();

	// Detect a change in the routing table (for only supported OS)
	t->RouteChange = NewRouteChange();
	Debug("t->RouteChange = 0x%p\n", t->RouteChange);
}
Example #21
0
void GameObject::DeleteFromDB()
{
    objmgr.SaveGORespawnTime(m_DBTableGuid,GetInstanceId(),0);
    objmgr.DeleteGOData(m_DBTableGuid);
    WorldDatabase.PExecute("DELETE FROM `gameobject` WHERE `guid` = '%u'", m_DBTableGuid);
}
Example #22
0
bool GameObject::LoadFromDB(uint32 guid, QueryResult *result, uint32 InstanceId)
{
    bool external = (result != NULL);
    if (!external)
        //                                0    1     2            3            4            5             6           7           8           9           10     11              12             13         14            15
        result = sDatabase.PQuery("SELECT `id`,`map`,`position_x`,`position_y`,`position_z`,`orientation`,`rotation0`,`rotation1`,`rotation2`,`rotation3`,`loot`,`spawntimesecs`,`animprogress`,`dynflags`,`respawntime`,`guid` "
            "FROM `gameobject` LEFT JOIN `gameobject_respawn` ON ((`gameobject`.`guid`=`gameobject_respawn`.`guid`) AND (`gameobject_respawn`.`instance` = '%u')) WHERE `gameobject`.`guid` = '%u'", InstanceId, guid);

    if( !result )
    {
        sLog.outErrorDb("ERROR: Gameobject (GUID: %u) not found in table `gameobject`, can't load. ",guid);
        return false;
    }

    Field *fields = result->Fetch();
    uint32 entry = fields[0].GetUInt32();
    uint32 map_id=fields[1].GetUInt32();
    float x = fields[2].GetFloat();
    float y = fields[3].GetFloat();
    float z = fields[4].GetFloat();
    float ang = fields[5].GetFloat();

    float rotation0 = fields[6].GetFloat();
    float rotation1 = fields[7].GetFloat();
    float rotation2 = fields[8].GetFloat();
    float rotation3 = fields[9].GetFloat();

    uint32 animprogress = fields[12].GetUInt32();
    uint32 dynflags = fields[13].GetUInt32();

    uint32 stored_guid = guid;
    if (InstanceId != 0) guid = objmgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT);
    SetInstanceId(InstanceId);

    if (!Create(guid,entry, map_id, x, y, z, ang, rotation0, rotation1, rotation2, rotation3, animprogress, dynflags) )
    {
        if (!external) delete result;
        return false;
    }

    m_DBTableGuid = stored_guid;

    lootid=fields[10].GetUInt32();
    m_respawnDelayTime=fields[11].GetUInt32();
    m_respawnTime=fields[14].GetUInt64();
    if(m_respawnTime && m_respawnTime <= time(NULL))        // ready to respawn
    {
        m_respawnTime = 0;
        sDatabase.PExecute("DELETE FROM `gameobject_respawn` WHERE `guid` = '%u' AND `instance` = '%u'", m_DBTableGuid, GetInstanceId());
    }

    if (!external) delete result;

    _LoadQuests();
    return true;
}
Example #23
0
void GameObject::DeleteFromDB()
{
    sDatabase.PExecute("DELETE FROM `gameobject` WHERE `guid` = '%u'", m_DBTableGuid);
    sDatabase.PExecute("DELETE FROM `gameobject_respawn` WHERE `guid` = '%u' AND `instance` = '%u'", m_DBTableGuid, GetInstanceId());
}
void DungeonPersistentState::DeleteFromDB() const
{
    MapPersistentStateManager::DeleteInstanceFromDB(GetInstanceId());
}
void DungeonPersistentState::UpdateEncounterState(EncounterCreditType type, uint32 creditEntry)
{
    DungeonEncounterMapBounds bounds = sObjectMgr.GetDungeonEncounterBounds(creditEntry);

    for (DungeonEncounterMap::const_iterator iter = bounds.first; iter != bounds.second; ++iter)
    {
        DungeonEncounterEntry const* dbcEntry = iter->second->dbcEntry;

        if (iter->second->creditType == type && Difficulty(dbcEntry->Difficulty) == GetDifficulty() && dbcEntry->mapId == GetMapId())
        {
            m_completedEncountersMask |= 1 << dbcEntry->encounterIndex;

            CharacterDatabase.PExecute("UPDATE instance SET encountersMask = '%u' WHERE id = '%u'", m_completedEncountersMask, GetInstanceId());

            DEBUG_LOG("DungeonPersistentState: Dungeon %s (Id %u) completed encounter %s", GetMap()->GetMapName(), GetInstanceId(), dbcEntry->encounterName[sWorld.GetDefaultDbcLocale()]);
            if (/*uint32 dungeonId =*/ iter->second->lastEncounterDungeon)
            {
                DEBUG_LOG("DungeonPersistentState:: Dungeon %s (Instance-Id %u) completed last encounter %s", GetMap()->GetMapName(), GetInstanceId(), dbcEntry->encounterName[sWorld.GetDefaultDbcLocale()]);
                // Place LFG reward here
            }
            return;
        }
    }
}
void DungeonPersistentState::UpdateEncounterState(EncounterCreditType type, uint32 creditEntry)
{
    DungeonEncounterMapBounds bounds = sObjectMgr.GetDungeonEncounterBounds(creditEntry);

    for (DungeonEncounterMap::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
    {
        DungeonEncounterEntry const* dbcEntry = itr->second->dbcEntry;

        if (itr->second->creditType == type && Difficulty(dbcEntry->Difficulty) == GetDifficulty() && dbcEntry->mapId == GetMapId())
        {
            uint32 oldMask = m_completedEncountersMask;
            m_completedEncountersMask |= 1 << dbcEntry->encounterIndex;

            DungeonMap* dungeon = (DungeonMap*)GetMap();

            if (!dungeon || dungeon->GetPlayers().isEmpty())
                return;

            Player* player = dungeon->GetPlayers().begin()->getSource();

            if ( m_completedEncountersMask != oldMask)
            {
                if (dungeon && player)
                    dungeon->PermBindAllPlayers(player, dungeon->IsRaidOrHeroicDungeon());

                CharacterDatabase.PExecute("UPDATE instance SET encountersMask = '%u' WHERE id = '%u'", m_completedEncountersMask, GetInstanceId());

                uint32 dungeonId = itr->second->lastEncounterDungeon;

                DEBUG_LOG("DungeonPersistentState: Dungeon %s (Id %u) completed encounter %s %s", GetMap()->GetMapName(), GetInstanceId(), dbcEntry->encounterName[sWorld.GetDefaultDbcLocale()], dungeonId ? "(last)" : "");

                if (dungeon && player && player->GetGroup() && player->GetGroup()->isLFGGroup())
                {
                    sLFGMgr.DungeonEncounterReached(player->GetGroup());

                    if ((sWorld.getConfig(CONFIG_BOOL_LFG_ONLYLASTENCOUNTER) && dungeonId)
                        || IsCompleted())
                        sLFGMgr.SendLFGRewards(player->GetGroup());
                }
            }
            return;
        }
    }
}
Example #27
0
float WorldLocation::GetDistance(WorldLocation const& loc) const
{
    return (!HasMap() || !loc.HasMap() || ((GetMapId() == loc.GetMapId()) && (GetInstanceId() == loc.GetInstanceId()))) ?
        ((Position)*this).GetDistance((Position)loc) :
        MAX_VISIBILITY_DISTANCE + 1.0f;
};
Example #28
0
bool GameObject::LoadFromDB(uint32 guid, Map *map)
{
    GameObjectData const* data = objmgr.GetGOData(guid);

    if( !data )
    {
        sLog.outErrorDb("ERROR: Gameobject (GUID: %u) not found in table `gameobject`, can't load. ",guid);
        return false;
    }

    uint32 entry = data->id;
    //uint32 map_id = data->mapid;                          // already used before call
    float x = data->posX;
    float y = data->posY;
    float z = data->posZ;
    float ang = data->orientation;

    float rotation0 = data->rotation0;
    float rotation1 = data->rotation1;
    float rotation2 = data->rotation2;
    float rotation3 = data->rotation3;

    uint32 animprogress = data->animprogress;
    uint32 go_state = data->go_state;

    m_DBTableGuid = guid;
    if (map->GetInstanceId() != 0) guid = objmgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT);

    if (!Create(guid,entry, map, x, y, z, ang, rotation0, rotation1, rotation2, rotation3, animprogress, go_state) )
        return false;

    switch(GetGOInfo()->type)
    {
        case GAMEOBJECT_TYPE_DOOR:
        case GAMEOBJECT_TYPE_BUTTON:
            /* this code (in comment) isn't correct because in battlegrounds we need despawnable doors and buttons, pls remove
            SetFlag(GAMEOBJECT_FLAGS, GO_FLAG_NODESPAWN);
            m_spawnedByDefault = true;
            m_respawnDelayTime = 0;
            m_respawnTime = 0;
            break;*/
        default:
            if(data->spawntimesecs >= 0)
            {
                m_spawnedByDefault = true;
                m_respawnDelayTime = data->spawntimesecs;
                m_respawnTime = objmgr.GetGORespawnTime(m_DBTableGuid, map->GetInstanceId());

                                                            // ready to respawn
                if(m_respawnTime && m_respawnTime <= time(NULL))
                {
                    m_respawnTime = 0;
                    objmgr.SaveGORespawnTime(m_DBTableGuid,GetInstanceId(),0);
                }
            }
            else
            {
                m_spawnedByDefault = false;
                m_respawnDelayTime = -data->spawntimesecs;
                m_respawnTime = 0;
            }
            break;
    }

    return true;
}
void InstanceSave::DeleteFromDB()
{
    InstanceSaveManager::DeleteInstanceFromDB(GetInstanceId());
}
Example #30
0
void GameObject::SaveRespawnTime()
{
    if(m_respawnTime > time(NULL) && !GetOwnerGUID())
    {
        sDatabase.PExecute("DELETE FROM `gameobject_respawn` WHERE `guid` = '%u' AND `instance` = '%u'", m_DBTableGuid, GetInstanceId());
        sDatabase.PExecute("INSERT INTO `gameobject_respawn` VALUES ( '%u', '" I64FMTD "', '%u' )", m_DBTableGuid, uint64(m_respawnTime), GetInstanceId());
    }
}