/// <summary> /// Removes the realm from world. /// </summary> /// <param name="realm">The realm.</param> public void RemoveRealmFromWorld(DefaultRealm realm) { if (!this.Realms.Contains(realm)) { return; } this.realms.Remove(realm); }
/// <summary> /// Initializes the zone with the supplied realm. /// </summary> /// <param name="realm">The realm.</param> public virtual void Initialize(DefaultRealm realm) { this.realm = realm; if (this.weatherStates.Count > 0) { // Set up our weather clock and start performing weather changes. var weatherClock = new EngineTimer <IWeatherState>(this.CurrentWeather); // Convert the minutes specified with WeatherUpdateFrequency to in-game minutes using the GameTimeRatio. weatherClock.Start( 0, TimeSpan.FromMinutes(this.WeatherUpdateFrequency * this.realm.World.GameTimeAdjustmentFactor).TotalMilliseconds, 0, this.SetupWeather); } }
/// <summary> /// Adds the given realm to world and initializes it. /// </summary> /// <param name="realm">The realm.</param> /// <exception cref="System.NullReferenceException">Attempted to add a null Realm to the world. /// or /// Adding a Realm to a World with a null Zones collection is not allowed.</exception> public Task AddRealmToWorld(DefaultRealm realm) { if (realm == null) { throw new NullReferenceException("Attempted to add a null Realm to the world."); } if (realm.Zones == null) { throw new NullReferenceException("Adding a Realm to a World with a null Zones collection is not allowed."); } // We don't attempt to add duplicates. if (this.Realms.Contains(realm)) { return(Task.FromResult(0)); } this.realms.Add(realm); return(realm.Initialize()); }
/// <summary> /// Initializes the zone with the supplied realm. /// </summary> /// <param name="realm">The realm.</param> public virtual void Initialize(DefaultRealm realm) { this.realm = realm; if (this.weatherStates.Count > 0) { // Set up our weather clock and start performing weather changes. var weatherClock = new EngineTimer<IWeatherState>(this.CurrentWeather); // Convert the minutes specified with WeatherUpdateFrequency to in-game minutes using the GameTimeRatio. weatherClock.Start( 0, TimeSpan.FromMinutes(this.WeatherUpdateFrequency * this.realm.World.GameTimeAdjustmentFactor).TotalMilliseconds, 0, this.SetupWeather); } }
/// <summary> /// Constructs the world. /// </summary> /// <param name="game">The game.</param> private async Task ConstructWorld(IGame game) { // Set up the Room var bedroom = new DefaultRoom { IsEnabled = true }; var hallway = new DefaultRoom { IsEnabled = true }; // Set up the Zone var weatherStates = new List<IWeatherState> { new ClearWeather(), new RainyWeather(), new ThunderstormWeather() }; DefaultZone zone = new DefaultZone(); zone.Name = "Country Side"; zone.Rooms = new List<DefaultRoom>() { bedroom }; zone.WeatherStates = weatherStates; zone.WeatherUpdateFrequency = 6; zone.WeatherChanged += (sender, weatherArgs) => Console.WriteLine($"{zone.Name} zone weather has changed to {weatherArgs.CurrentState.Name}"); DefaultZone zone2 = new DefaultZone(); zone2.Name = "Castle Rock"; zone2.Rooms = new List<DefaultRoom> { hallway }; zone2.WeatherStates = weatherStates; zone2.WeatherUpdateFrequency = 2; zone2.WeatherChanged += (sender, weatherArgs) => Console.WriteLine($"{zone2.Name} zone weather has changed to {weatherArgs.CurrentState.Name}"); // Set up the World. IWorld world = new DefaultWorld(); world.GameDayToRealHourRatio = 0.4; world.HoursPerDay = 10; world.Name = "Sample World"; world.SetNotificationManager(game.NotificationCenter); var morningState = new TimeOfDayState { Name = "Morning", StateStartTime = new TimeOfDay { Hour = 2 } }; var afternoonState = new TimeOfDayState { Name = "Afternoon", StateStartTime = new TimeOfDay { Hour = 5 } }; var nightState = new TimeOfDayState { Name = "Night", StateStartTime = new TimeOfDay { Hour = 8 } }; world.AddTimeOfDayState(morningState); world.AddTimeOfDayState(afternoonState); world.AddTimeOfDayState(nightState); world.TimeOfDayChanged += World_TimeOfDayChanged; // Set up the Realm. DefaultRealm realm = new DefaultRealm(world, new TimeOfDay { Hour = 3, HoursPerDay = 10 }); realm.TimeZoneOffset = new TimeOfDay { Hour = 3, Minute = 10, HoursPerDay = world.HoursPerDay }; realm.Name = "Realm 1"; realm.SetNotificationManager(game.NotificationCenter); // Initialize the environment. Task task = world.Initialize(); task.Wait(); await world.AddRealmToWorld(realm); realm.AddZoneToRealm(zone); realm.AddZoneToRealm(zone2); await game.AddWorld(world); }
/// <summary> /// Removes the realm from world. /// </summary> /// <param name="realm">The realm.</param> public void RemoveRealmFromWorld(DefaultRealm realm) { if (!this.Realms.Contains(realm)) { return; } this.realms.Remove(realm); }
/// <summary> /// Adds the given realm to world and initializes it. /// </summary> /// <param name="realm">The realm.</param> /// <exception cref="System.NullReferenceException">Attempted to add a null Realm to the world. /// or /// Adding a Realm to a World with a null Zones collection is not allowed.</exception> public Task AddRealmToWorld(DefaultRealm realm) { if (realm == null) { throw new NullReferenceException("Attempted to add a null Realm to the world."); } if (realm.Zones == null) { throw new NullReferenceException("Adding a Realm to a World with a null Zones collection is not allowed."); } // We don't attempt to add duplicates. if (this.Realms.Contains(realm)) { return Task.FromResult(0); } this.realms.Add(realm); return realm.Initialize(); }