public override Feasibility IsFeasible(Creature agent) { if (!agent.Stats.IsTaskAllowed(Task.TaskCategory.TillSoil) && !agent.Stats.IsTaskAllowed(Task.TaskCategory.Plant)) { return(Feasibility.Infeasible); } if (agent.AI.Status.IsAsleep) { return(Feasibility.Infeasible); } bool farmValid = FarmToWork != null && !FarmToWork.IsCanceled; if (!farmValid) { return(Feasibility.Infeasible); } if (Mode == FarmAct.FarmMode.Till && FarmToWork.Voxel.Type.Name == "TilledSoil") { return(Feasibility.Infeasible); } if (Mode == FarmAct.FarmMode.Plant && FarmToWork.PlantExists()) { return(Feasibility.Infeasible); } return(Feasibility.Feasible); }
public IEnumerable <Status> FarmATile() { FarmTool.FarmTile tile = FarmToWork; if (tile == null) { yield return(Status.Fail); } else if (tile.PlantExists()) { tile.Farmer = null; yield return(Status.Success); } else { if (tile.Plant != null && tile.Plant.IsDead) { tile.Plant = null; } Creature.CurrentCharacterMode = Creature.CharacterMode.Attacking; Creature.Sprite.ResetAnimations(Creature.CharacterMode.Attacking); Creature.Sprite.PlayAnimations(Creature.CharacterMode.Attacking); while (tile.Progress < 100.0f && !Satisfied()) { Creature.Physics.Velocity *= 0.1f; tile.Progress += Creature.Stats.BaseFarmSpeed; Drawer2D.DrawLoadBar(Agent.Position + Vector3.Up, Color.White, Color.Black, 100, 16, tile.Progress / 100.0f); if (tile.Progress >= 100.0f && !Satisfied()) { tile.Progress = 0.0f; if (Mode == FarmAct.FarmMode.Plant) { FarmToWork.CreatePlant(PlantToCreate); DestroyResources(); } else { FarmToWork.Vox.Type = VoxelLibrary.GetVoxelType("TilledSoil"); FarmToWork.Vox.Chunk.NotifyTotalRebuild(true); } } if (MathFunctions.RandEvent(0.01f)) { PlayState.ParticleManager.Trigger("dirt_particle", Creature.AI.Position, Color.White, 1); } yield return(Status.Running); Creature.Sprite.ReloopAnimations(Creature.CharacterMode.Attacking); } Creature.CurrentCharacterMode = Creature.CharacterMode.Idle; Creature.AI.AddThought(Thought.ThoughtType.Farmed); Creature.AI.AddXP(1); tile.Farmer = null; Creature.Sprite.PauseAnimations(Creature.CharacterMode.Attacking); yield return(Status.Success); } }
bool Satisfied() { if (Mode == FarmMode.Plant) { return(FarmToWork.PlantExists()); } else { return(FarmToWork.IsTilled()); } }
public IEnumerable <Status> FarmATile() { FarmTool.FarmTile tile = FarmToWork; if (tile == null) { yield return(Status.Fail); } else if (tile.PlantExists()) { tile.Farmer = null; yield return(Status.Success); } else { if (tile.Plant != null && tile.Plant.IsDead) { tile.Plant = null; } while (tile.Progress < 100.0f && !Satisfied()) { Creature.CurrentCharacterMode = Creature.CharacterMode.Attacking; Creature.Physics.Velocity *= 0.1f; tile.Progress += Creature.Stats.BaseFarmSpeed; Drawer2D.DrawLoadBar(Agent.Position + Vector3.Up, Color.White, Color.Black, 100, 16, tile.Progress / 100.0f); if (tile.Progress >= 100.0f && !Satisfied()) { tile.Progress = 0.0f; if (Mode == FarmAct.FarmMode.Plant) { FarmToWork.CreatePlant(PlantToCreate); DestroyResources(); } else { FarmToWork.Vox.Type = VoxelLibrary.GetVoxelType("TilledSoil"); FarmToWork.Vox.Chunk.ShouldRebuild = true; } } yield return(Status.Running); } Creature.CurrentCharacterMode = Creature.CharacterMode.Idle; Creature.AI.AddThought(Thought.ThoughtType.Farmed); Creature.AI.AddXP(10); tile.Farmer = null; yield return(Status.Success); } }
private bool Validate() { bool tileValid = !FarmToWork.IsCanceled && FarmToWork.Farmer == Agent && FarmToWork.Voxel.IsValid && !FarmToWork.Voxel.IsEmpty; if (!tileValid) { return(false); } if (Mode == FarmMode.Plant && FarmToWork.PlantExists()) { return(false); } if (Mode == FarmMode.Till && FarmToWork.Voxel.Type.Name == "TilledSoil") { return(false); } return(true); }
public IEnumerable <Status> FarmATile() { if (FarmToWork == null) { yield return(Status.Fail); yield break; } if (FarmToWork.IsCanceled) { yield return(Status.Fail); yield break; } else if (FarmToWork.PlantExists()) { FarmToWork.Farmer = null; yield return(Status.Success); } else { if (FarmToWork.Plant != null && FarmToWork.Plant.IsDead) { FarmToWork.Plant = null; } Creature.CurrentCharacterMode = CharacterMode.Attacking; Creature.Sprite.ResetAnimations(CharacterMode.Attacking); Creature.Sprite.PlayAnimations(CharacterMode.Attacking); while (FarmToWork.Progress < 100.0f && !Satisfied()) { if (FarmToWork.IsCanceled) { yield return(Status.Fail); yield break; } Creature.Physics.Velocity *= 0.1f; FarmToWork.Progress += 3 * Creature.Stats.BaseFarmSpeed * DwarfTime.Dt; Drawer2D.DrawLoadBar(Agent.Manager.World.Camera, Agent.Position + Vector3.Up, Color.LightGreen, Color.Black, 64, 4, FarmToWork.Progress / 100.0f); if (FarmToWork.Progress >= 100.0f && !Satisfied()) { FarmToWork.Progress = 0.0f; if (Mode == FarmAct.FarmMode.Plant) { FarmToWork.CreatePlant(PlantToCreate, Creature.Manager.World); Creature.Faction.Designations.RemoveVoxelDesignation(FarmToWork.Voxel, DesignationType._AllFarms); Creature.Faction.Designations.AddVoxelDesignation(FarmToWork.Voxel, DesignationType._InactiveFarm, FarmToWork); DestroyResources(); } else { FarmToWork.Voxel.Type = VoxelLibrary.GetVoxelType("TilledSoil"); Creature.Faction.Designations.RemoveVoxelDesignation(FarmToWork.Voxel, DesignationType._AllFarms); Creature.Faction.Designations.AddVoxelDesignation(FarmToWork.Voxel, DesignationType._InactiveFarm, FarmToWork); } } if (MathFunctions.RandEvent(0.01f)) { Creature.Manager.World.ParticleManager.Trigger("dirt_particle", Creature.AI.Position, Color.White, 1); } yield return(Status.Running); Creature.Sprite.ReloopAnimations(CharacterMode.Attacking); } Creature.CurrentCharacterMode = CharacterMode.Idle; Creature.AI.AddThought(Thought.ThoughtType.Farmed); Creature.AI.AddXP(1); FarmToWork.Farmer = null; Creature.Sprite.PauseAnimations(CharacterMode.Attacking); yield return(Status.Success); } }