private void GameDifficultyCheck()
{
bool ChangeEffected = false;
int TargetGameDifficulty;
int CurrentDifficulty;
//
// If the current difficulty doesn't match the target difficulty,
// then attempt to increase or decrease the difficulty to match.
// If a change was made, re-check quickly so that adjustments can
// converge rapidly on the target value (as only a single up/down
// adjustment is being made at any given time).
//
try
{
TargetGameDifficulty = GetLocalInt(GetModule(), "ACR_GAME_DIFFICULTY_LEVEL");
CurrentDifficulty = GetGameDifficulty();
if ((TargetGameDifficulty != 0) && (CurrentDifficulty != TargetGameDifficulty))
{
if (CurrentDifficulty < TargetGameDifficulty)
{
WriteTimestampedLogEntry(String.Format(
"ACR_ServerCommunicator.GameDifficultyCheck(): Difficulty level {0} is lower than target {1}, attempting to increase.",
CurrentDifficulty,
TargetGameDifficulty));
ALFA.SystemInfo.AdjustGameDifficultyLevel(true);
GetDatabase().ACR_IncrementStatistic("GAME_DIFFICULTY_INCREMENT");
}
else
{
WriteTimestampedLogEntry(String.Format(
"ACR_ServerCommunicator.GameDifficultyCheck(): Difficulty level {0} is above than target {1}, attempting to decrease.",
CurrentDifficulty,
TargetGameDifficulty));
ALFA.SystemInfo.AdjustGameDifficultyLevel(false);
GetDatabase().ACR_IncrementStatistic("GAME_DIFFICULTY_DECREMENT");
}
ChangeEffected = true;
}
}
catch (Exception e)
{
WriteTimestampedLogEntry(String.Format(
"ACR_ServerCommunicator.GameDifficultyCheck(): Exception: {0}", e));
}
//
// Start a new check cycle going.
//
DelayCommand(ChangeEffected ? 6.0f : GAME_DIFFICULTY_CHECK_INTERVAL,
delegate() { GameDifficultyCheck(); });
}