Exemplo n.º 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;
            }
            }
        }
Exemplo n.º 2
0
        public override void OnVoxelsSelected(List <VoxelHandle> refs, InputManager.MouseButton button)
        {
            if (button == InputManager.MouseButton.Left)
            {
                int count = World.PersistentData.Designations.EnumerateDesignations(DesignationType.Dig).Count();

                World.Tutorial("slice");
                List <Task> assignments = new List <Task>();
                foreach (var v in refs)
                {
                    if (!v.IsValid || (v.IsEmpty && v.IsExplored) || v.Type.IsInvincible)
                    {
                        continue;
                    }

                    var boundingBox = v.GetBoundingBox().Expand(-0.1f);
                    var entities    = World.EnumerateIntersectingObjects(boundingBox, CollisionType.Static);
                    if (entities.OfType <IVoxelListener>().Any())
                    {
                        continue;
                    }

                    if (count >= GameSettings.Current.MaxVoxelDesignations)
                    {
                        World.UserInterface.ShowToolPopup("Too many dig designations!");
                        break;
                    }

                    // Todo: Should this be removed from the existing compound task and put in the new one?
                    if (!World.PersistentData.Designations.IsVoxelDesignation(v, DesignationType.Dig) && !(World.IsInZone(v) || World.IsBuildDesignation(v)))
                    {
                        var task = new KillVoxelTask(v);
                        task.Hidden = true;
                        assignments.Add(task);
                        count++;
                    }
                }

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

                    var compoundTask = new CompoundTask("DIG A HOLE", TaskCategory.Dig, TaskPriority.Medium);
                    compoundTask.AddSubTasks(assignments);
                    World.TaskManager.AddTask(compoundTask);

                    var minions = Faction.FilterMinionsWithCapability(World.PersistentData.SelectedMinions, TaskCategory.Dig);
                    OnConfirm(minions);
                }
            }
            else
            {
                foreach (var r in refs)
                {
                    if (r.IsValid)
                    {
                        if (World.PersistentData.Designations.GetVoxelDesignation(r, DesignationType.Dig).HasValue(out var designation) && designation.Task != null) // Todo: Is this necessary?
                        {
                            World.TaskManager.CancelTask(designation.Task);
                        }
                    }
                }
            }
        }