void InstanceSaveManager::LoadInstanceSaves()
{
    QueryResult result = CharacterDatabase.Query("SELECT id, map, resettime, difficulty, completedEncounters, data FROM instance ORDER BY id ASC");
    if (result)
    {
        do
        {
            Field* fields = result->Fetch();

            uint32 instanceId = fields[0].GetUInt32();
            uint32 mapId = fields[1].GetUInt16();
            time_t resettime = time_t(fields[2].GetUInt32());
            uint8 difficulty = fields[3].GetUInt8();
            uint32 completedEncounters = fields[4].GetUInt32();
            std::string instanceData = fields[5].GetString();

            // Mark instance id as being used
            sMapMgr->RegisterInstanceId(instanceId);

            InstanceSave* save = AddInstanceSave(mapId, instanceId, Difficulty(difficulty), true);
            if (save)
            {
                save->SetCompletedEncounterMask(completedEncounters);
                save->SetInstanceData(instanceData);
                if (resettime > 0)
                    save->SetResetTime(resettime);
            }
        }
        while (result->NextRow());
    }
}
Example #2
0
void InstanceScript::SetCompletedEncountersMask(uint32 newMask, bool save)
{
	if (completedEncounters == newMask)
		return;
	completedEncounters = newMask;
	// pussywizard:
	if (save)
	{
		InstanceSave* iSave = sInstanceSaveMgr->GetInstanceSave(instance->GetInstanceId());
		if (iSave)
			iSave->SetCompletedEncounterMask(completedEncounters);

		PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_INSTANCE_SAVE_ENCOUNTERMASK);
		stmt->setUInt32(0, completedEncounters);
		stmt->setUInt32(1, instance->GetInstanceId());
		CharacterDatabase.Execute(stmt);
	}
}