示例#1
0
        public override void Die()
        {
            if (Farm != null && !(this is Seedling))
            {
                if (Farm.Voxel.IsValid && Farm.Voxel.Type.Name == "TilledSoil" && !String.IsNullOrEmpty(Farm.SeedResourceType))
                {
                    var farmTile = new Farm
                    {
                        Voxel             = Farm.Voxel,
                        SeedResourceType  = Farm.SeedResourceType,
                        RequiredResources = Farm.RequiredResources
                    };

                    if (GameSettings.Default.AllowAutoFarming)
                    {
                        var task = new PlantTask(farmTile)
                        {
                            Plant             = Farm.SeedResourceType,
                            RequiredResources = Farm.RequiredResources
                        };
                        World.Master.TaskManager.AddTask(task);
                    }
                }
            }
            base.Die();
        }
示例#2
0
        public override void OnVoxelsSelected(List <VoxelHandle> voxels, InputManager.MouseButton button)
        {
            if (button == InputManager.MouseButton.Left)
            {
                var goals = new List <PlantTask>();
                int count = Player.Faction.Designations.EnumerateDesignations(DesignationType.Plant).Count();

                foreach (var voxel in voxels)
                {
                    if (count >= 1024)
                    {
                        Player.World.ShowToolPopup("Too many planting tasks.");
                        break;
                    }
                    if (ValidatePlanting(voxel))
                    {
                        count++;
                        var farmTile = new Farm
                        {
                            Voxel             = voxel,
                            RequiredResources = RequiredResources,
                            SeedResourceType  = PlantType
                        };

                        var task = new PlantTask(farmTile)
                        {
                            Plant             = PlantType,
                            RequiredResources = RequiredResources
                        };

                        if (voxel.Type.Name != "TilledSoil")
                        {
                            farmTile.TargetProgress = 200.0f; // Planting on untilled soil takes longer.
                        }
                        goals.Add(task);
                    }
                }

                Player.TaskManager.AddTasks(goals);

                OnConfirm(Player.World.Master.Faction.Minions.Where(minion => minion.Stats.IsTaskAllowed(Task.TaskCategory.Plant)).ToList());
            }
            else if (button == InputManager.MouseButton.Right)
            {
                foreach (var voxel in voxels)
                {
                    var designation = Player.Faction.Designations.GetVoxelDesignation(voxel, DesignationType.Plant);

                    if (designation != null)
                    {
                        Player.TaskManager.CancelTask(designation.Task);
                    }
                }
            }
        }