Пример #1
0
 public PlaceObjectAct(CreatureAI creature, PlacementDesignation type) :
     base(creature)
 {
     Item  = type;
     Voxel = type.Location;
     Name  = "Build craft item";
 }
Пример #2
0
        public override void OnVoxelsSelected(List <VoxelHandle> voxels, InputManager.MouseButton button)
        {
            switch (button)
            {
            case (InputManager.MouseButton.Left):
            {
                if (ObjectHelper.IsValidPlacement(World.UserInterface.VoxSelector.VoxelUnderMouse, CraftType, World, PreviewBody, "build", "built"))
                {
                    PreviewBody.SetFlag(GameComponent.Flag.ShouldSerialize, true);

                    Vector3 pos      = World.UserInterface.VoxSelector.VoxelUnderMouse.WorldPosition + new Vector3(0.5f, 0.0f, 0.5f) + CraftType.Placement_SpawnOffset;
                    Vector3 startPos = pos + new Vector3(0.0f, -0.1f, 0.0f);

                    var newDesignation = new PlacementDesignation()
                    {
                        ItemType            = CraftType,
                        Location            = World.UserInterface.VoxSelector.VoxelUnderMouse,
                        Orientation         = Orientation,
                        OverrideOrientation = OverrideOrientation,
                        Entity   = PreviewBody,
                        WorkPile = new WorkPile(World.ComponentManager, startPos)
                    };

                    World.ComponentManager.RootComponent.AddChild(newDesignation.WorkPile);
                    newDesignation.WorkPile.AnimationQueue.Add(new EaseMotion(1.1f, Matrix.CreateTranslation(startPos), pos));
                    World.ParticleManager.Trigger("puff", pos, Color.White, 10);

                    World.TaskManager.AddTask(new PlaceObjectTask(newDesignation));

                    if (!HandlePlaceExistingUpdate())
                    {
                        PreviewBody = null;
                        World.UserInterface.ShowToolPopup("Unable to place any more.");
                        World.UserInterface.ChangeTool("SelectUnits");
                    }
                    else
                    {
                        PreviewBody = CreatePreviewBody();
                    }
                }

                break;
            }

            case (InputManager.MouseButton.Right):
            {
                var designation = World.PersistentData.Designations.EnumerateEntityDesignations(DesignationType.PlaceObject).Select(d => d.Tag as PlacementDesignation).FirstOrDefault(d => d.Location == World.UserInterface.VoxSelector.VoxelUnderMouse);
                if (designation != null && World.PersistentData.Designations.GetEntityDesignation(designation.Entity, DesignationType.PlaceObject).HasValue(out var realDesignation))
                {
                    World.TaskManager.CancelTask(realDesignation.Task);
                }
                break;
            }
            }
        }
Пример #3
0
        public PlaceObjectTask(PlacementDesignation PlacementDesignation)
        {
            this.PlacementDesignation = PlacementDesignation;

            Category      = TaskCategory.BuildObject;
            MaxAssignable = 1;
            Name          = Library.GetString("craft-at", PlacementDesignation.Entity.GlobalID, PlacementDesignation.ItemType.DisplayName, PlacementDesignation.Location);
            Priority      = TaskPriority.Medium;
            AutoRetry     = true;

            foreach (var tinter in PlacementDesignation.Entity.EnumerateAll().OfType <Tinter>())
            {
                tinter.Stipple = true;
            }

            BoredomIncrease = GameSettings.Current.Boredom_NormalTask;
            EnergyDecrease  = GameSettings.Current.Energy_Tiring;
        }