Example #1
0
/*
- adding instance into manager
- called from InstanceMap::Add, _LoadBoundInstances, LoadGroups
*/
InstanceSave* InstanceSaveManager::AddInstanceSave(uint32 mapId, uint32 instanceId, time_t resetTime, bool canReset, bool load)
{
    InstanceSave *save = GetInstanceSave(instanceId);
    if(save) return save;

    const MapEntry* entry = sMapStore.LookupEntry(mapId);
    if(!entry || instanceId == 0)
    {
        sLog.outError("InstanceSaveManager::AddInstanceSave: mapid = %d, instanceid = %d!", mapId, instanceId);
        return NULL;
    }

    if(!resetTime)
    {
        // initialize reset time
        // for normal instances if no creatures are killed the instance will reset in two hours
        if(entry->map_type == MAP_RAID)
            resetTime = GetResetTimeFor(mapId);
        else
        {
            resetTime = time(NULL) + 2 * HOUR;
            // normally this will be removed soon after in InstanceMap::Add, prevent error
            ScheduleReset(true, resetTime, InstResetEvent(0, mapId, instanceId));
        }
    }

    sLog.outDebug("InstanceSaveManager::AddInstanceSave: mapid = %d, instanceid = %d", mapId, instanceId);

    save = new InstanceSave(mapId, instanceId, resetTime, canReset);
    if(!load) save->SaveToDB();

    m_instanceSaveById[instanceId] = save;
    return save;
}
Example #2
0
/*
 - adding instance into manager
 - called from InstanceMap::Add, _LoadBoundInstances, LoadGroups
 */
InstanceSave* InstanceSaveManager::AddInstanceSave(uint32 mapId,
		uint32 instanceId, Difficulty difficulty, time_t resetTime,
		bool canReset, bool load) {
	if (InstanceSave *old_save = GetInstanceSave(instanceId))
		return old_save;

	const MapEntry* entry = sMapStore.LookupEntry(mapId);
	if (!entry) {
		sLog->outError(
				"InstanceSaveManager::AddInstanceSave: wrong mapid = %d, instanceid = %d!",
				mapId, instanceId);
		return NULL;
	}

	if (instanceId == 0) {
		sLog->outError(
				"InstanceSaveManager::AddInstanceSave: mapid = %d, wrong instanceid = %d!",
				mapId, instanceId);
		return NULL;
	}

	if (difficulty
			>= (entry->IsRaid() ? MAX_RAID_DIFFICULTY : MAX_DUNGEON_DIFFICULTY)) {
		sLog->outError(
				"InstanceSaveManager::AddInstanceSave: mapid = %d, instanceid = %d, wrong dificalty %u!",
				mapId, instanceId, difficulty);
		return NULL;
	}

	if (!resetTime) {
		// initialize reset time
		// for normal instances if no creatures are killed the instance will reset in two hours
		if (entry->map_type == MAP_RAID
				|| difficulty > DUNGEON_DIFFICULTY_NORMAL)
			resetTime = GetResetTimeFor(mapId, difficulty);
		else {
			resetTime = time(NULL) + 2 * HOUR;
			// normally this will be removed soon after in InstanceMap::Add, prevent error
			ScheduleReset(true, resetTime,
					InstResetEvent(0, mapId, difficulty, instanceId));
		}
	}

	sLog->outDebug(LOG_FILTER_MAPS,
			"InstanceSaveManager::AddInstanceSave: mapid = %d, instanceid = %d",
			mapId, instanceId);

	InstanceSave *save = new InstanceSave(mapId, instanceId, difficulty,
			resetTime, canReset);
	if (!load)
		save->SaveToDB();

	m_instanceSaveById[instanceId] = save;
	return save;
}
/*
- adding instance into manager
- called from InstanceMap::Add, _LoadBoundInstances, LoadGroups
*/
InstanceSave* InstanceSaveManager::AddInstanceSave(uint32 mapId, uint32 instanceId, Difficulty difficulty, time_t resetTime, uint32 entranceId, bool canReset, bool load)
{
    if (InstanceSave* old_save = GetInstanceSave(instanceId))
        return old_save;

    const MapEntry* entry = sMapStore.LookupEntry(mapId);
    if (!entry)
    {
        TC_LOG_ERROR("misc", "InstanceSaveManager::AddInstanceSave: wrong mapid = %d, instanceid = %d!", mapId, instanceId);
        return NULL;
    }

    if (instanceId == 0)
    {
        TC_LOG_ERROR("misc", "InstanceSaveManager::AddInstanceSave: mapid = %d, wrong instanceid = %d!", mapId, instanceId);
        return NULL;
    }

    DifficultyEntry const* difficultyEntry = sDifficultyStore.LookupEntry(difficulty);
    if (!difficultyEntry || difficultyEntry->InstanceType != entry->InstanceType)
    {
        TC_LOG_ERROR("misc", "InstanceSaveManager::AddInstanceSave: mapid = %d, instanceid = %d, wrong dificalty %u!", mapId, instanceId, difficulty);
        return NULL;
    }

    if (entranceId && !sWorldSafeLocsStore.LookupEntry(entranceId))
    {
        TC_LOG_WARN("misc", "InstanceSaveManager::AddInstanceSave: invalid entranceId = %d defined for instance save with mapid = %d, instanceid = %d!", entranceId, mapId, instanceId);
        entranceId = 0;
    }

    if (!resetTime)
    {
        // initialize reset time
        // for normal instances if no creatures are killed the instance will reset in two hours
        if (entry->IsRaid() || difficulty > DIFFICULTY_NORMAL)
            resetTime = GetResetTimeFor(mapId, difficulty);
        else
        {
            resetTime = time(NULL) + 2 * HOUR;
            // normally this will be removed soon after in InstanceMap::Add, prevent error
            ScheduleReset(true, resetTime, InstResetEvent(0, mapId, difficulty, instanceId));
        }
    }

    TC_LOG_DEBUG("maps", "InstanceSaveManager::AddInstanceSave: mapid = %d, instanceid = %d", mapId, instanceId);

    InstanceSave* save = new InstanceSave(mapId, instanceId, difficulty, entranceId, resetTime, canReset);
    if (!load)
        save->SaveToDB();

    m_instanceSaveById[instanceId] = save;
    return save;
}