public void CheckGrowing() { var entityGrowingManager = new EntityGrowingManager(null); var random = new Random(1); var entity = new PlantGrowingEntity(); entity.GrowLevels.Add(new GrowLevel { GrowTime = UtopiaTimeSpan.FromHours(1) }); entity.GrowLevels.Add(new GrowLevel { GrowTime = UtopiaTimeSpan.FromHours(1) }); entity.GrowLevels.Add(new GrowLevel { GrowTime = UtopiaTimeSpan.FromHours(1) }); entity.GrowLevels.Add(new GrowLevel { GrowTime = UtopiaTimeSpan.FromHours(1) }); entity.LastGrowUpdate = new UtopiaTime() + UtopiaTimeSpan.FromMinutes(1); var now = new UtopiaTime() + UtopiaTimeSpan.FromHours(2.5); entityGrowingManager.EntityGrowCheck(now, entity, null, random); Assert.AreEqual(2, entity.CurrentGrowLevelIndex); entity = new PlantGrowingEntity(); entity.GrowingSeasons.Add(UtopiaTime.TimeConfiguration.Seasons[0].Name); entity.GrowingSeasons.Add(UtopiaTime.TimeConfiguration.Seasons[2].Name); entity.GrowLevels.Add(new GrowLevel { GrowTime = UtopiaTimeSpan.FromDays(10) }); entity.GrowLevels.Add(new GrowLevel { GrowTime = UtopiaTimeSpan.FromDays(10) }); entity.GrowLevels.Add(new GrowLevel { GrowTime = UtopiaTimeSpan.FromDays(10) }); entity.GrowLevels.Add(new GrowLevel { GrowTime = UtopiaTimeSpan.FromDays(10) }); entity.LastGrowUpdate = new UtopiaTime() + UtopiaTimeSpan.FromMinutes(1); now = new UtopiaTime() + UtopiaTimeSpan.FromMinutes(50); entityGrowingManager.EntityGrowCheck(now, entity, null, random); entity.LastGrowUpdate = now; Assert.AreEqual(0, entity.CurrentGrowLevelIndex); now = new UtopiaTime() + UtopiaTimeSpan.FromYears(1); entityGrowingManager.EntityGrowCheck(now, entity, null, random); entity.LastGrowUpdate = now; Assert.AreEqual(1, entity.CurrentGrowLevelIndex); now = new UtopiaTime() + UtopiaTimeSpan.FromYears(1) + UtopiaTimeSpan.FromMinutes(1); entityGrowingManager.EntityGrowCheck(now, entity, null, random); entity.LastGrowUpdate = now; Assert.AreEqual(2, entity.CurrentGrowLevelIndex); }
public override void Initialize(ServerCore server) { _server = server; _server.LoginManager.PlayerAuthorized += LoginManager_PlayerAuthorized; server.Clock.CreateNewTimer(new Clock.GameClockTimer(UtopiaTimeSpan.FromDays(1), server.Clock, PerDayTrigger)); _lastMessage = UpdateWeather(); }
private void TreeIntegrity(ServerChunk chunk, TreeSoul soul) { if (!soul.IsDamaged) { return; } // the tree will regenerate or die after one day if ((_server.Clock.Now - soul.LastUpdate) < UtopiaTimeSpan.FromDays(1)) { return; } var config = _server.EntityFactory.Config; var treeBp = config.TreeBluePrintsDico[soul.TreeTypeId]; var treeBlocks = _treeLSystem.Generate(soul.TreeRndSeed, new Vector3I(), treeBp); var cursor = _server.LandscapeManager.GetCursor(soul.Position); if (soul.IsDying) { // remove the tree using (cursor.TransactionScope()) { foreach (var blockWithPosition in treeBlocks) { cursor.GlobalPosition = (Vector3I)soul.Position + blockWithPosition.WorldPosition; if (cursor.Read() == blockWithPosition.BlockId) { cursor.Write(WorldConfiguration.CubeId.Air); } } } chunk.Entities.Remove(soul); } else { // restore the tree using (cursor.TransactionScope()) { foreach (var blockWithPosition in treeBlocks) { cursor.GlobalPosition = (Vector3I)soul.Position + blockWithPosition.WorldPosition; if (cursor.Read() == WorldConfiguration.CubeId.Air) { cursor.Write(blockWithPosition.BlockId); } } } soul.IsDamaged = false; } }