コード例 #1
0
 public FarmTask(FarmTile farmToWork)
 {
     FarmToWork = farmToWork;
     Name       = "Work " + FarmToWork.Voxel.Coordinate;
     Priority   = PriorityType.Low;
     AutoRetry  = true;
 }
コード例 #2
0
        public void CreatePlant(FarmTile tile)
        {
            tile.Plant = CreatePlant(tile.Vox.Position + new Vector3(0.0f, 1.75f, 0.0f));
            Matrix original = tile.Plant.LocalTransform;

            original.Translation += Vector3.Down;
            tile.Plant.AnimationQueue.Add(new EaseMotion(0.5f, original, tile.Plant.LocalTransform.Translation));
            PlayState.ParticleManager.Trigger("puff", original.Translation, Color.White, 20);
            SoundManager.PlaySound(ContentPaths.Audio.pluck, tile.Vox.Position, true);
            AddBody(tile.Plant);
        }
コード例 #3
0
        public override void RemoveVoxel(Voxel voxel)
        {
            FarmTile toRemove = FarmTiles.FirstOrDefault(tile => tile.Vox.Equals(voxel));

            if (toRemove != null)
            {
                if (toRemove.Plant != null)
                {
                    toRemove.Plant.Die();
                }
                FarmTiles.Remove(toRemove);
            }
            base.RemoveVoxel(voxel);
        }
コード例 #4
0
        public override void OnVoxelsSelected(List <VoxelHandle> voxels, InputManager.MouseButton button)
        {
            List <CreatureAI> minions =
                Player.World.Master.Faction.Minions.Where(minion => minion.Stats.IsTaskAllowed(Task.TaskCategory.TillSoil)).ToList();
            List <FarmTask> goals = new List <FarmTask>();

            foreach (var voxel in voxels)
            {
                if (button == InputManager.MouseButton.Left)
                {
                    if (!ValidateTilling(voxel))
                    {
                        continue;
                    }

                    var newFarmTile = new FarmTile
                    {
                        Voxel = voxel
                    };

                    Player.Faction.Designations.AddVoxelDesignation(voxel, DesignationType.Till, newFarmTile);

                    goals.Add(new FarmTask(newFarmTile)
                    {
                        Mode = FarmAct.FarmMode.Till, Category = Task.TaskCategory.TillSoil
                    });
                }
                else
                {
                    var existingFarmTile = Player.Faction.Designations.GetVoxelDesignation(voxel, DesignationType._AllFarms)
                                           as FarmTile;
                    if (existingFarmTile != null && !existingFarmTile.PlantExists())
                    {
                        existingFarmTile.IsCanceled = true;
                        existingFarmTile.Farmer     = null;
                        Player.Faction.Designations.RemoveVoxelDesignation(existingFarmTile.Voxel, DesignationType._AllFarms);
                    }
                }
            }

            Player.TaskManager.AddTasks(goals);
            //TaskManager.AssignTasksGreedy(goals.Cast<Task>().ToList(), minions, 1);

            foreach (CreatureAI creature in minions)
            {
                creature.Creature.NoiseMaker.MakeNoise("Ok", creature.Position);
            }
        }
コード例 #5
0
        public FarmTile GetNearestFreeFarmTile(Vector3 position)
        {
            float    closestDist = float.MaxValue;
            FarmTile closest     = null;

            foreach (FarmTile tile in FarmTiles)
            {
                if (tile.IsFree())
                {
                    float dist = (tile.Vox.Position - position).LengthSquared();
                    if (dist < closestDist)
                    {
                        closest     = tile;
                        closestDist = dist;
                    }
                }
            }

            return(closest);
        }
コード例 #6
0
ファイル: FarmTool.cs プロジェクト: Solsund/dwarfcorp
        public override void OnVoxelsSelected(List <Voxel> voxels, InputManager.MouseButton button)
        {
            List <CreatureAI> minions = PlayState.Master.SelectedMinions.Where(minion => minion.Stats.CurrentClass.HasAction(GameMaster.ToolMode.Farm)).ToList();
            List <Task>       goals   = new List <Task>();

            switch (Mode)
            {
            case FarmMode.Tilling:
                foreach (Voxel voxel in voxels)
                {
                    if (button == InputManager.MouseButton.Left)
                    {
                        if (!voxel.Type.IsSoil)
                        {
                            PlayState.GUI.ToolTipManager.Popup("Can only till soil!");
                            continue;
                        }
                        if (voxel.TypeName == "TilledSoil")
                        {
                            PlayState.GUI.ToolTipManager.Popup("Soil already tilled!");
                            continue;
                        }
                        if (!HasTile(voxel))
                        {
                            FarmTile tile = new FarmTile()
                            {
                                Vox = voxel
                            };
                            goals.Add(new FarmTask(tile)
                            {
                                Mode = FarmAct.FarmMode.Till, Plant = PlantType
                            });
                            FarmTiles.Add(tile);
                        }
                        else
                        {
                            goals.Add(new FarmTask(FarmTiles.Find(tile => tile.Vox.Equals(voxel)))
                            {
                                Mode  = FarmAct.FarmMode.Till,
                                Plant = PlantType
                            });
                        }
                    }
                    else
                    {
                        if (HasTile(voxel) && !HasPlant(voxel))
                        {
                            FarmTiles.RemoveAll(tile => tile.Vox.Equals(voxel));
                        }
                    }
                }
                TaskManager.AssignTasksGreedy(goals, minions, 1);

                foreach (CreatureAI creature in minions)
                {
                    creature.Creature.NoiseMaker.MakeNoise("Ok", creature.Position);
                }

                break;

            case FarmMode.Planting:
                int currentAmount =
                    Player.Faction.ListResources()
                    .Sum(resource => resource.Key == PlantType && resource.Value.NumResources > 0 ? resource.Value.NumResources : 0);
                foreach (Voxel voxel in voxels)
                {
                    if (currentAmount == 0)
                    {
                        PlayState.GUI.ToolTipManager.Popup("Not enough " + PlantType + " in stocks!");
                        break;
                    }
                    if (voxel.TypeName != "TilledSoil")
                    {
                        PlayState.GUI.ToolTipManager.Popup("Can only plant on tilled soil!");
                        continue;
                    }

                    if (ResourceLibrary.Resources[PlantType].Tags.Contains(Resource.ResourceTags.AboveGroundPlant))
                    {
                        if (voxel.SunColor == 0)
                        {
                            PlayState.GUI.ToolTipManager.Popup("Can only plant " + PlantType + " above ground.");
                            continue;
                        }
                    }
                    else if (
                        ResourceLibrary.Resources[PlantType].Tags.Contains(
                            Resource.ResourceTags.BelowGroundPlant))
                    {
                        if (voxel.SunColor > 0)
                        {
                            PlayState.GUI.ToolTipManager.Popup("Can only plant " + PlantType + " below ground.");
                            continue;
                        }
                    }

                    if (!HasPlant(voxel))
                    {
                        FarmTile tile = new FarmTile()
                        {
                            Vox = voxel
                        };
                        goals.Add(new FarmTask(tile)
                        {
                            Mode = FarmAct.FarmMode.Plant, Plant = PlantType, RequiredResources = RequiredResources
                        });
                        FarmTiles.Add(tile);
                        currentAmount--;
                    }
                    else
                    {
                        PlayState.GUI.ToolTipManager.Popup("Something is already planted here!");
                        continue;
                    }
                }
                TaskManager.AssignTasksGreedy(goals, minions, 1);
                OnConfirm(minions);
                break;
            }
        }