public override IEnumerable <Status> Run() { InitializePath(); if (TrajectoryTimer == null) { yield break; } while (!TrajectoryTimer.HasTriggered) { TrajectoryTimer.Update(DwarfTime.LastTime); ValidPathTimer.Update(DwarfTime.LastTime); foreach (Status status in PerformCurrentAction()) { if (status == Status.Fail) { yield return(Status.Fail); } else if (status == Status.Success) { break; } yield return(Status.Running); } if (Agent.DrawPath) { List <Vector3> points = Path.Select( (v, i) => v.Voxel.Position + new Vector3(0.5f, 0.5f, 0.5f) + RandomPositionOffsets[i]) .ToList(); Drawer3D.DrawLineList(points, Color.Red, 0.1f); } // Check if the path has been made invalid if (ValidPathTimer.HasTriggered && !IsPathValid(Path)) { Creature.OverrideCharacterMode = false; Creature.DrawIndicator(IndicatorManager.StandardIndicators.Question); yield return(Status.Fail); } yield return(Status.Running); } Creature.OverrideCharacterMode = false; SetPath(null); yield return(Status.Success); }
public override IEnumerable <Status> Run() { InitializePath(); if (Path == null || Path.Count == 0) { yield return(Act.Status.Success); } if (TrajectoryTimer == null) { yield break; } while (!TrajectoryTimer.HasTriggered) { TrajectoryTimer.Update(DwarfTime.LastTime); ValidPathTimer.Update(DwarfTime.LastTime); foreach (Status status in PerformCurrentAction()) { if (status == Status.Fail) { yield return(Status.Fail); } else if (status == Status.Success) { break; } yield return(Status.Running); } if (Agent.DrawPath) { List <Vector3> points = Path.Select( (v, i) => v.SourceVoxel.WorldPosition + new Vector3(0.5f, 0.5f, 0.5f) + RandomPositionOffsets[i]) .ToList(); points.Add(Path[Path.Count - 1].DestinationVoxel.WorldPosition + new Vector3(0.5f, 0.5f, 0.5f)); List <Color> colors = Path.Select((v, i) => { switch (v.MoveType) { case MoveType.Climb: return(Color.Cyan); case MoveType.ClimbWalls: return(Color.DarkCyan); case MoveType.DestroyObject: return(Color.Orange); case MoveType.Fall: return(Color.LightBlue); case MoveType.Fly: return(Color.Green); case MoveType.Jump: return(Color.Yellow); case MoveType.Swim: return(Color.Blue); case MoveType.Walk: return(Color.Red); } return(Color.White); }) .ToList(); colors.Add(Color.White); Drawer3D.DrawLineList(points, colors, 0.1f); } // Check if the path has been made invalid if (ValidPathTimer.HasTriggered && !IsPathValid(Path)) { Creature.OverrideCharacterMode = false; Creature.DrawIndicator(IndicatorManager.StandardIndicators.Question); yield return(Status.Fail); } yield return(Status.Running); } Creature.OverrideCharacterMode = false; SetPath(null); yield return(Status.Success); }
public override IEnumerable <Status> Run() { InitializePath(); if (Path == null || Path.Count == 0) { yield return(Act.Status.Success); } if (TrajectoryTimer == null) { yield break; } while (!TrajectoryTimer.HasTriggered) { Agent.GetRoot().SetFlagRecursive(GameComponent.Flag.Visible, true); TrajectoryTimer.Update(DwarfTime.LastTime); ValidPathTimer.Update(DwarfTime.LastTime); foreach (Status status in PerformCurrentAction()) { if (status == Status.Fail) { CleanupMinecart(); yield return(Status.Fail); } else if (status == Status.Success) { break; } Creature.Physics.AnimationQueue.Clear(); yield return(Status.Running); } if (Debugger.Switches.DrawPaths) { List <Vector3> points = Path.Select( (v, i) => v.SourceVoxel.WorldPosition + new Vector3(0.5f, 0.5f, 0.5f) + RandomPositionOffsets[i]) .ToList(); points.Add(Path[Path.Count - 1].DestinationVoxel.WorldPosition + new Vector3(0.5f, 0.5f, 0.5f)); List <Color> colors = Path.Select((v, i) => { switch (v.MoveType) { case MoveType.Climb: return(Color.Cyan); case MoveType.ClimbWalls: return(Color.DarkCyan); case MoveType.DestroyObject: return(Color.Orange); case MoveType.Fall: return(Color.LightBlue); case MoveType.Fly: return(Color.Green); case MoveType.Jump: return(Color.Yellow); case MoveType.Swim: return(Color.Blue); case MoveType.Walk: return(Color.Red); } return(Color.White); }) .ToList(); colors.Add(Color.White); Drawer3D.DrawLineList(points, colors, 0.1f); } float t = 0; int currentIndex = 0; MoveAction action = new MoveAction(); if (GetCurrentAction(ref action, ref t, ref currentIndex)) { // Check if the path has been made invalid if (ValidPathTimer.HasTriggered && !IsPathValid(Path, currentIndex)) { Creature.OverrideCharacterMode = false; Creature.DrawIndicator(IndicatorManager.StandardIndicators.Question); CleanupMinecart(); Agent.GetRoot().SetFlagRecursive(GameComponent.Flag.Visible, true); yield return(Status.Fail); } } Creature.Physics.AnimationQueue.Clear(); yield return(Status.Running); } Creature.OverrideCharacterMode = false; SetPath(null); Agent.GetRoot().SetFlagRecursive(GameComponent.Flag.Visible, true); CleanupMinecart(); yield return(Status.Success); }
override public void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera) { base.Update(gameTime, chunks, camera); if (GameSettings.Current.DisableWeather) { Die(); return; } Storm.InitializeStatics(); BoundingBox box = chunks.Bounds; box.Expand(10.0f); if (GlobalTransform.Translation.X < box.Min.X || GlobalTransform.Translation.X > box.Max.X || GlobalTransform.Translation.Z < box.Min.Z || GlobalTransform.Translation.Z > box.Max.Z) { Die(); return; } bool generateRainDrop = MathFunctions.RandEvent(Raininess * 0.75f); if (generateRainDrop) { for (int i = 0; i < MaxRainDrops; i++) { if (!RainDrops[i].IsAlive) { RainDrops[i].IsAlive = true; if (RainDrops[i].Particle != null) { RainDrops[i].Particle.LifeRemaining = 60.0f; RainDrops[i].Particle.TimeAlive = 0.0f; } RainDrops[i].Pos = MathFunctions.RandVector3Box(BoundingBox.Expand(5)); RainDrops[i].Pos = new Vector3(RainDrops[i].Pos.X, BoundingBox.Min.Y - 1, RainDrops[i].Pos.Z); RainDrops[i].Vel = Vector3.Down * Storm.Properties[TypeofStorm].RainSpeed + Velocity; break; } } } bool generateLightning = LightningChance > 0.0f && MathFunctions.RandEvent((float)(LightningChance * 0.001f)); if (generateLightning) { var below = VoxelHelpers.FindFirstVoxelBelowIncludingWater(new VoxelHandle(World.ChunkManager, GlobalVoxelCoordinate.FromVector3(new Vector3(Position.X, Math.Min(World.WorldSizeInVoxels.Y - 1, Position.Y), Position.Z)))); if (below.IsValid && !below.IsEmpty) { var above = VoxelHelpers.GetVoxelAbove(below); if (above.IsValid) { EntityFactory.CreateEntity <Fire>("Fire", above.GetBoundingBox().Center()); List <Vector3> lightningStrikes = new List <Vector3>(); List <Color> colors = new List <Color>(); var c = above.GetBoundingBox().Center(); for (float t = 0; t < 1.0f; t += 0.25f) { var p = c * t + Position * (1.0f - t); lightningStrikes.Add(p + MathFunctions.RandVector3Box(-5, 5, 0, 0.1f, -5, 5)); colors.Add(Color.White); } lightningStrikes.Add(c); colors.Add(Color.White); Drawer3D.DrawLineList(lightningStrikes, colors, 0.3f); SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_rain_storm_alert, MathFunctions.Rand(0.001f, 0.05f), MathFunctions.Rand(0.5f, 1.0f)); SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_trap_destroyed, c, false, 1.0f, MathFunctions.Rand(-0.5f, 0.5f)); World.ParticleManager.Trigger("explode", c, Color.White, 10); } } } Storm.StormProperties stormProperties = Storm.Properties[TypeofStorm]; var rainEmitter = World.ParticleManager.Effects[stormProperties.RainEffect]; var hitEmitter = World.ParticleManager.Effects[stormProperties.HitEffect]; for (int i = 0; i < MaxRainDrops; i++) { if (!RainDrops[i].IsAlive) { continue; } RainDrops[i].Pos += RainDrops[i].Vel * DwarfTime.Dt; if (stormProperties.RainRandom > 0) { RainDrops[i].Vel.X += MathFunctions.Rand(-1, 1) * stormProperties.RainRandom * DwarfTime.Dt; RainDrops[i].Vel.Z += MathFunctions.Rand(-1, 1) * stormProperties.RainRandom * DwarfTime.Dt; } if (RainDrops[i].Pos.Y < 0) { RainDrops[i].IsAlive = false; } if (!RainDrops[i].IsAlive && RainDrops[i].Particle != null) { RainDrops[i].Particle.LifeRemaining = -1; } else if (RainDrops[i].IsAlive && RainDrops[i].Particle == null) { RainDrops[i].Particle = rainEmitter.Emitters[0].CreateParticle(RainDrops[i].Pos, RainDrops[i].Vel, Color.White); } else if (RainDrops[i].IsAlive && RainDrops[i].Particle != null) { RainDrops[i].Particle.Position = RainDrops[i].Pos; RainDrops[i].Particle.Velocity = RainDrops[i].Vel; } var test = new VoxelHandle(chunks, GlobalVoxelCoordinate.FromVector3(RainDrops[i].Pos)); if (!test.IsValid || (test.IsEmpty && test.LiquidLevel == 0)) { continue; } RainDrops[i].IsAlive = false; var hitBodies = World.EnumerateIntersectingObjects(new BoundingBox(RainDrops[i].Pos - Vector3.One, RainDrops[i].Pos + Vector3.One)); foreach (var body in hitBodies) { if (body.Parent != Manager.RootComponent) { continue; } if (body.GetRoot().GetComponent <Flammable>().HasValue(out var flames)) { flames.Heat *= 0.25f; } if (body.GetRoot().GetComponent <Seedling>().HasValue(out var seeds)) { if (TypeofStorm == StormType.RainStorm) { seeds.GrowthTime += MathFunctions.Rand(1.0f, 12.0f); } else if (MathFunctions.RandEvent(0.01f)) { seeds.GetRoot().Die(); } } } hitEmitter.Trigger(1, RainDrops[i].Pos + Vector3.UnitY * 0.5f, Color.White); //if (!MathFunctions.RandEvent(0.1f)) continue; var above = test.IsEmpty ? test : VoxelHelpers.GetVoxelAbove(test); if (!above.IsValid || !above.IsEmpty) { continue; } if (TypeofStorm == StormType.RainStorm && (above.LiquidLevel < WaterManager.maxWaterLevel && (above.LiquidType == LiquidType.Water))) { above.LiquidLevel = (byte)Math.Min(WaterManager.maxWaterLevel, above.LiquidLevel + WaterManager.rainFallAmount); above.LiquidType = stormProperties.LiquidToCreate; } else if (TypeofStorm == StormType.SnowStorm && above.IsEmpty && above.LiquidLevel == 0) { if (test.GrassType == 0) { test.GrassType = Library.GetGrassType("snow").ID; test.GrassDecay = Library.GetGrassType("snow").InitialDecayValue; } else { var existingGrass = Library.GetGrassType((byte)test.GrassType); if (!String.IsNullOrEmpty(existingGrass.BecomeWhenSnowedOn)) { var newGrass = Library.GetGrassType(existingGrass.BecomeWhenSnowedOn); test.GrassType = newGrass.ID; test.GrassDecay = newGrass.InitialDecayValue; } } } } Matrix tf = LocalTransform; tf.Translation += Velocity * DwarfTime.Dt; LocalTransform = tf; }