Exemple #1
0
        public override void OnVoxelsSelected(List <VoxelHandle> voxels, InputManager.MouseButton button)
        {
            if (Arguments == null)
            {
                return;
            }

            if (Selected == null)
            {
                Selected = new List <VoxelHandle>();
            }

            Selected.Clear();

            switch (button)
            {
            case (InputManager.MouseButton.Left):
            {
                if (Library.GetVoxelType(Arguments.VoxelType).HasValue(out VoxelType vType))
                {
                    List <Task> assignments = new List <Task>();

                    foreach (var r in voxels)
                    {
                        if (r.Type == vType)
                        {
                            continue;
                        }

                        var above = VoxelHelpers.GetVoxelAbove(r);
                        if (above.IsValid && above.LiquidType != LiquidType.None)
                        {
                            continue;
                        }

                        if (World.PersistentData.Designations.GetVoxelDesignation(r, DesignationType.Put).HasValue(out var existingDesignation))
                        {
                            World.TaskManager.CancelTask(existingDesignation.Task);
                        }

                        if (World.PersistentData.Designations.GetVoxelDesignation(r, DesignationType.Dig).HasValue(out var digDes))
                        {
                            World.TaskManager.CancelTask(digDes.Task);
                        }

                        if (r.IsEmpty)
                        {
                            assignments.Add(new BuildVoxelTask(r, vType.Name)
                                {
                                    Hidden = true
                                });
                        }
                        else
                        {
                            var sequentialTask = new SequentialTask("Put voxel", TaskCategory.Dig, TaskPriority.Medium)
                            {
                                Hidden = true
                            };
                            sequentialTask.AddSubTask(new KillVoxelTask(r)
                                {
                                    Hidden = true
                                });
                            sequentialTask.AddSubTask(new BuildVoxelTask(r, vType.Name)
                                {
                                    Hidden = true
                                });
                            assignments.Add(sequentialTask);
                        }
                    }

                    if (assignments.Count > 0)
                    {
                        World.TaskManager.AddTasks(assignments);

                        var compoundTask = new CompoundTask("Build Voxels", TaskCategory.BuildBlock, TaskPriority.Medium);
                        compoundTask.AddSubTasks(assignments);
                        World.TaskManager.AddTask(compoundTask);

                        var minions = Faction.FilterMinionsWithCapability(World.PersistentData.SelectedMinions, TaskCategory.BuildBlock);
                        OnConfirm(minions);
                    }
                }
                break;
            }

            case (InputManager.MouseButton.Right):
            {
                foreach (var r in voxels)
                {
                    if (World.PersistentData.Designations.GetVoxelDesignation(r, DesignationType.Put).HasValue(out var designation))
                    {
                        World.TaskManager.CancelTask(designation.Task);
                    }
                    if (World.PersistentData.Designations.GetVoxelDesignation(r, DesignationType.Dig).HasValue(out var digDesignation))
                    {
                        World.TaskManager.CancelTask(digDesignation.Task);
                    }
                }

                break;
            }
            }
        }
        public override void OnVoxelsSelected(List <VoxelHandle> voxels, InputManager.MouseButton button)
        {
            if (Arguments == null)
            {
                return;
            }

            if (Selected == null)
            {
                Selected = new List <VoxelHandle>();
            }

            Selected.Clear();

            switch (button)
            {
            case (InputManager.MouseButton.Left):
            {
                if (Library.GetVoxelType(Arguments.VoxelType).HasValue(out VoxelType vType))
                {
                    foreach (var r in voxels)
                    {
                        if (r.Type == vType)
                        {
                            continue;
                        }

                        var above = VoxelHelpers.GetVoxelAbove(r);
                        if (above.IsValid && above.LiquidType != LiquidType.None)
                        {
                            continue;
                        }

                        if (World.PersistentData.Designations.GetVoxelDesignation(r, DesignationType.Put).HasValue(out var existingDesignation))
                        {
                            World.TaskManager.CancelTask(existingDesignation.Task);
                        }

                        if (World.PersistentData.Designations.GetVoxelDesignation(r, DesignationType.Dig).HasValue(out var digDes))
                        {
                            World.TaskManager.CancelTask(digDes.Task);
                        }

                        if (r.IsEmpty)
                        {
                            World.TaskManager.AddTask(new BuildVoxelTask(r, vType.Name));
                        }
                        else
                        {
                            var sequentialTask = new SequentialTask("Put voxel", TaskCategory.Dig, TaskPriority.Medium);
                            sequentialTask.AddSubTask(new KillVoxelTask(r)
                                {
                                    Hidden = true
                                });
                            sequentialTask.AddSubTask(new BuildVoxelTask(r, vType.Name)
                                {
                                    Hidden = true
                                });
                            World.TaskManager.AddTask(sequentialTask);
                        }
                    }
                }
                break;
            }

            case (InputManager.MouseButton.Right):
            {
                foreach (var r in voxels)
                {
                    if (World.PersistentData.Designations.GetVoxelDesignation(r, DesignationType.Put).HasValue(out var designation))
                    {
                        World.TaskManager.CancelTask(designation.Task);
                    }
                    if (World.PersistentData.Designations.GetVoxelDesignation(r, DesignationType.Dig).HasValue(out var digDesignation))
                    {
                        World.TaskManager.CancelTask(digDesignation.Task);
                    }
                }

                break;
            }
            }
        }