コード例 #1
0
 public CraftItemAct(CreatureAI creature, CraftDesignation type) :
     base(creature)
 {
     Item  = type;
     Voxel = type.Location;
     Name  = "Build craft item";
 }
コード例 #2
0
        public CraftResourceTask(CraftItem selectedResource, int NumRepeats, List <ResourceAmount> SelectedResources, int id = -1)
        {
            this.NumRepeats = NumRepeats;

            Category = TaskCategory.CraftItem;
            TaskID   = id < 0 ? MaxID : id;
            MaxID++;
            Item = new CraftDesignation()
            {
                ItemType          = selectedResource,
                Location          = VoxelHandle.InvalidHandle,
                Valid             = true,
                SelectedResources = SelectedResources
            };
            Name     = String.Format("Craft order {0}", TaskID);
            Priority = PriorityType.Low;

            noise = ResourceLibrary.GetResourceByName(Item.ItemType.ResourceCreated).Tags.Contains(Resource.ResourceTags.Edible)
                ? "Cook"
                : "Craft";
            AutoRetry       = true;
            BoredomIncrease = 0.2f;
            if (selectedResource.IsMagical)
            {
                Category = TaskCategory.Research;
            }
        }
コード例 #3
0
ファイル: CraftItemTask.cs プロジェクト: hhy5277/dwarfcorp
        public CraftItemTask(CraftDesignation CraftDesignation)
        {
            Category              = TaskCategory.BuildObject;
            MaxAssignable         = 3;
            Name                  = Library.GetString("craft-at", CraftDesignation.Entity.GlobalID, CraftDesignation.ItemType.DisplayName, CraftDesignation.Location);
            Priority              = TaskPriority.Medium;
            AutoRetry             = true;
            this.CraftDesignation = CraftDesignation;

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

            BoredomIncrease = GameSettings.Default.Boredom_NormalTask;
            EnergyDecrease  = GameSettings.Default.Energy_Tiring;

            if (CraftDesignation.ItemType.IsMagical)
            {
                Category = TaskCategory.Research;
            }

            if (CraftDesignation.ExistingResource != null)
            {
                MaxAssignable = 1;
            }
        }
コード例 #4
0
ファイル: CraftBuilder.cs プロジェクト: svifylabs/dwarfcorp
        public bool IsValid(CraftDesignation designation)
        {
            if (IsDesignation(designation.Location))
            {
                PlayState.GUI.ToolTipManager.Popup("Something is already being built there!");
                return(false);
            }

            if (Faction.GetNearestRoomOfType(WorkshopRoom.WorkshopName, designation.Location.Position) == null)
            {
                PlayState.GUI.ToolTipManager.Popup("Can't build, no workshops!");
                return(false);
            }

            if (!Faction.HasResources(designation.ItemType.RequiredResources))
            {
                string neededResources = "";

                foreach (Quantitiy <Resource.ResourceTags> amount in designation.ItemType.RequiredResources)
                {
                    neededResources += "" + amount.NumResources + " " + amount.ResourceType.ToString() + " ";
                }

                PlayState.GUI.ToolTipManager.Popup("Not enough resources! Need " + neededResources + ".");
                return(false);
            }

            return(true);
        }
コード例 #5
0
        public CraftResourceTask(CraftItem selectedResource, int CurrentRepeat, int NumRepeats, List <ResourceAmount> SelectedResources, int id = -1)
        {
            this.CurrentRepeat = CurrentRepeat;
            this.NumRepeats    = NumRepeats;

            TaskID = id < 0 ? MaxID : id;
            MaxID++;
            Item = new CraftDesignation()
            {
                ItemType          = selectedResource,
                Location          = VoxelHandle.InvalidHandle,
                Valid             = true,
                SelectedResources = SelectedResources
            };
            string verb = selectedResource.Verb;

            Name     = String.Format("{4} order {0}: {1}/{2} {3}", TaskID, CurrentRepeat, NumRepeats, selectedResource.PluralDisplayName, verb);
            Priority = TaskPriority.Medium;

            if (Library.GetResourceType(Item.ItemType.ResourceCreated).Tags.Contains(Resource.ResourceTags.Edible))
            {
                noise    = "Cook";
                Category = TaskCategory.Cook;
            }
            else
            {
                noise    = "Craft";
                Category = selectedResource.IsMagical ? TaskCategory.Research : TaskCategory.CraftItem;
            }

            AutoRetry       = true;
            BoredomIncrease = GameSettings.Default.Boredom_NormalTask;
            EnergyDecrease  = GameSettings.Default.Energy_Tiring;
        }
コード例 #6
0
        public CraftResourceTask(CraftItem selectedResource, int NumRepeats, List <ResourceAmount> SelectedResources, int id = -1)
        {
            this.NumRepeats = NumRepeats;

            TaskID = id < 0 ? MaxID : id;
            MaxID++;
            Item = new CraftDesignation()
            {
                ItemType          = selectedResource,
                Location          = VoxelHandle.InvalidHandle,
                Valid             = true,
                SelectedResources = SelectedResources
            };
            Name     = String.Format("Craft order {0}: {1} {2}s", TaskID, NumRepeats, selectedResource.DisplayName);
            Priority = PriorityType.Medium;

            if (ResourceLibrary.GetResourceByName(Item.ItemType.ResourceCreated).Tags.Contains(Resource.ResourceTags.Edible))
            {
                noise    = "Cook";
                Category = TaskCategory.Cook;
            }
            else
            {
                noise    = "Craft";
                Category = selectedResource.IsMagical ? TaskCategory.Research : TaskCategory.CraftItem;
            }

            AutoRetry       = true;
            BoredomIncrease = GameSettings.Default.Boredom_NormalTask;
        }
コード例 #7
0
 public CreateCraftItemAct(VoxelHandle voxel, CreatureAI agent, CraftDesignation itemType) :
     base(agent)
 {
     Agent = agent;
     Voxel = voxel;
     Name  = "Create craft item";
     Item  = itemType;
 }
コード例 #8
0
        public void RemoveDesignation(CraftDesignation des)
        {
            Designations.Remove(des);

            if (des.WorkPile != null)
            {
                des.WorkPile.Die();
            }
        }
コード例 #9
0
 public CraftItemTask(CraftDesignation type)
 {
     Category      = TaskCategory.BuildObject;
     MaxAssignable = 3;
     Name          = string.Format("Craft {0} at {1}", type.ItemType.Name, type.Location);
     Priority      = PriorityType.Low;
     AutoRetry     = true;
     Designation   = type;
 }
コード例 #10
0
        public void RemoveDesignation(Voxel v)
        {
            CraftDesignation des = GetDesignation(v);

            if (des != null)
            {
                RemoveDesignation(des);
            }
        }
コード例 #11
0
        public void RemoveDesignation(CraftDesignation des)
        {
            Faction.Designations.RemoveEntityDesignation(des.Entity, DesignationType.Craft);

            if (des.WorkPile != null)
            {
                des.WorkPile.Die();
            }
        }
コード例 #12
0
        public void AddDesignation(CraftDesignation des, Vector3 AdditionalOffset)
        {
            if (des.OverrideOrientation)
            {
                des.Entity.Orient(des.Orientation);
            }
            else
            {
                des.Entity.OrientToWalls();
            }

            Faction.Designations.AddEntityDesignation(des.Entity, DesignationType.Craft, des);
        }
コード例 #13
0
        public void Update(DwarfTime gameTime, GameMaster player)
        {
            if (!IsEnabled)
            {
                if (CurrentCraftBody != null)
                {
                    CurrentCraftBody.Delete();
                    CurrentCraftBody = null;
                }
                return;
            }

            if (Faction == null)
            {
                Faction = player.Faction;
            }

            if (CurrentCraftType != null && CurrentCraftBody == null)
            {
                CurrentCraftBody = EntityFactory.CreateEntity <Body>(CurrentCraftType.Name, player.VoxSelector.VoxelUnderMouse.Position);
                CurrentCraftBody.SetActiveRecursive(false);
                CurrentDesignation = new CraftDesignation()
                {
                    ItemType = CurrentCraftType,
                    Location = new Voxel(new Point3(0, 0, 0), null)
                };
                SetDisplayColor(Color.Green);
            }

            if (CurrentCraftBody == null || player.VoxSelector.VoxelUnderMouse == null)
            {
                return;
            }

            CurrentCraftBody.LocalPosition   = player.VoxSelector.VoxelUnderMouse.Position + Vector3.One * 0.5f;
            CurrentCraftBody.GlobalTransform = CurrentCraftBody.LocalTransform;
            CurrentCraftBody.OrientToWalls();

            if (CurrentDesignation.Location.IsSameAs(player.VoxSelector.VoxelUnderMouse))
            {
                return;
            }

            CurrentDesignation.Location = new Voxel(player.VoxSelector.VoxelUnderMouse);

            SetDisplayColor(IsValid(CurrentDesignation) ? Color.Green : Color.Red);
        }
コード例 #14
0
        public CraftItemTask(CraftDesignation CraftDesignation)
        {
            Category              = TaskCategory.BuildObject;
            MaxAssignable         = 3;
            Name                  = string.Format("{2} Craft {0} at {1}", CraftDesignation.ItemType.Name, CraftDesignation.Location, CraftDesignation.Entity.GlobalID);
            Priority              = PriorityType.Low;
            AutoRetry             = true;
            this.CraftDesignation = CraftDesignation;

            foreach (var tinter in CraftDesignation.Entity.EnumerateAll().OfType <Tinter>())
            {
                tinter.Stipple = true;
            }
            BoredomIncrease = 0.2f;
            if (CraftDesignation.ItemType.IsMagical)
            {
                Category = TaskCategory.Research;
            }
        }
コード例 #15
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.SpawnOffset;
                    Vector3 startPos = pos + new Vector3(0.0f, -0.1f, 0.0f);

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

                    if (Mode == PlacementMode.PlaceExisting)
                    {
                        newDesignation.ExistingResource = ExistingPlacement;
                    }

                    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 CraftItemTask(newDesignation));


                    if (Mode == PlacementMode.PlaceExisting && !HandlePlaceExistingUpdate())
                    {
                        World.UserInterface.ShowToolPopup("Unable to place any more.");
                        Mode = PlacementMode.BuildNew;
                    }

                    PreviewBody = CreatePreviewBody();
                }

                break;
            }

            case (InputManager.MouseButton.Right):
            {
                var designation = World.PersistentData.Designations.EnumerateEntityDesignations(DesignationType.Craft).Select(d => d.Tag as CraftDesignation).FirstOrDefault(d => d.Location == World.UserInterface.VoxSelector.VoxelUnderMouse);
                if (designation != null)
                {
                    if (World.PersistentData.Designations.GetEntityDesignation(designation.Entity, DesignationType.Craft).HasValue(out var realDesignation))
                    {
                        World.TaskManager.CancelTask(realDesignation.Task);
                    }
                }
                break;
            }
            }
        }
コード例 #16
0
        public void VoxelsSelected(List <Voxel> refs, InputManager.MouseButton button)
        {
            if (!IsEnabled)
            {
                return;
            }
            switch (button)
            {
            case (InputManager.MouseButton.Left):
            {
                if (Faction.FilterMinionsWithCapability(Faction.SelectedMinions, GameMaster.ToolMode.Craft).Count == 0)
                {
                    World.ShowToolPopup("None of the selected units can craft items.");
                    return;
                }
                List <Task> assignments = new List <Task>();
                foreach (Voxel r in refs)
                {
                    if (IsDesignation(r) || r == null || !r.IsEmpty)
                    {
                        continue;
                    }
                    else
                    {
                        Vector3          pos            = r.Position + Vector3.One * 0.5f;
                        Vector3          startPos       = pos + new Vector3(0.0f, -0.1f, 0.0f);
                        Vector3          endPos         = pos;
                        CraftDesignation newDesignation = new CraftDesignation()
                        {
                            ItemType = CurrentCraftType,
                            Location = r,
                            WorkPile = new WorkPile(World.ComponentManager, startPos)
                        };

                        newDesignation.WorkPile.AnimationQueue.Add(new EaseMotion(1.1f, Matrix.CreateTranslation(startPos), endPos));
                        World.ParticleManager.Trigger("puff", pos, Color.White, 10);
                        if (IsValid(newDesignation))
                        {
                            AddDesignation(newDesignation);
                            assignments.Add(new CraftItemTask(new Voxel(new Point3(r.GridPosition), r.Chunk),
                                                              CurrentCraftType));
                        }
                        else
                        {
                            newDesignation.WorkPile.Die();
                        }
                    }
                }

                if (assignments.Count > 0)
                {
                    TaskManager.AssignTasks(assignments, Faction.FilterMinionsWithCapability(World.Master.SelectedMinions, GameMaster.ToolMode.Craft));
                }

                break;
            }

            case (InputManager.MouseButton.Right):
            {
                foreach (Voxel r in refs)
                {
                    if (!IsDesignation(r))
                    {
                        continue;
                    }
                    RemoveDesignation(r);
                }
                break;
            }
            }
        }
コード例 #17
0
        public void Update(DwarfTime gameTime, GameMaster player)
        {
            if (!IsEnabled)
            {
                if (CurrentCraftBody != null)
                {
                    CurrentCraftBody.Delete();
                    CurrentCraftBody = null;
                }

                return;
            }

            if (Faction == null)
            {
                Faction = player.Faction;
            }

            if (CurrentCraftType != null && CurrentCraftBody == null)
            {
                CurrentCraftBody = EntityFactory.CreateEntity <Body>(CurrentCraftType.Name,
                                                                     player.VoxSelector.VoxelUnderMouse.WorldPosition,
                                                                     Blackboard.Create <List <ResourceAmount> >("Resources", SelectedResources));
                EntityFactory.GhostEntity(CurrentCraftBody, Color.White);

                CurrentDesignation = new CraftDesignation()
                {
                    ItemType = CurrentCraftType,
                    Location = VoxelHandle.InvalidHandle,
                    Valid    = true
                };

                OverrideOrientation = false;
                CurrentCraftBody.SetTintRecursive(Color.Green);
            }

            if (CurrentCraftBody == null || !player.VoxSelector.VoxelUnderMouse.IsValid)
            {
                return;
            }

            CurrentCraftBody.LocalPosition = player.VoxSelector.VoxelUnderMouse.WorldPosition + new Vector3(0.5f, 0.0f, 0.5f) + CurrentCraftType.SpawnOffset;

            CurrentCraftBody.GlobalTransform = CurrentCraftBody.LocalTransform;
            CurrentCraftBody.UpdateTransform();
            CurrentCraftBody.PropogateTransforms();
            if (OverrideOrientation)
            {
                CurrentCraftBody.Orient(CurrentOrientation);
            }
            else
            {
                CurrentCraftBody.OrientToWalls();
            }

            HandleOrientation();

            if (CurrentDesignation != null)
            {
                if (CurrentDesignation.Location.Equals(player.VoxSelector.VoxelUnderMouse))
                {
                    return;
                }

                CurrentDesignation.Location = player.VoxSelector.VoxelUnderMouse;

                World.ShowTooltip("Click to build. Press R/T to rotate.");
                CurrentCraftBody.SetTintRecursive(IsValid(CurrentDesignation) ? Color.Green : Color.Red);
            }
        }
コード例 #18
0
        public bool IsValid(CraftDesignation designation)
        {
            if (IsDesignation(designation.Location))
            {
                World.ShowToolPopup("Something is already being built there!");
                return(false);
            }

            if (Faction.GetNearestRoomOfType(WorkshopRoom.WorkshopName, designation.Location.Position) == null)
            {
                World.ShowToolPopup("Can't build, no workshops!");
                return(false);
            }

            if (!Faction.HasResources(designation.ItemType.RequiredResources))
            {
                string neededResources = "";

                foreach (Quantitiy <Resource.ResourceTags> amount in designation.ItemType.RequiredResources)
                {
                    neededResources += "" + amount.NumResources + " " + amount.ResourceType.ToString() + " ";
                }

                World.ShowToolPopup("Not enough resources! Need " + neededResources + ".");
                return(false);
            }

            Voxel[] neighbors = new Voxel[4];
            foreach (CraftItem.CraftPrereq req in designation.ItemType.Prerequisites)
            {
                switch (req)
                {
                case CraftItem.CraftPrereq.NearWall:
                {
                    designation.Location.Chunk.Get2DManhattanNeighbors(neighbors,
                                                                       (int)designation.Location.GridPosition.X,
                                                                       (int)designation.Location.GridPosition.Y, (int)designation.Location.GridPosition.Z);

                    bool neighborFound = neighbors.Any(voxel => voxel != null && !voxel.IsEmpty);

                    if (!neighborFound)
                    {
                        World.ShowToolPopup("Must be built next to wall!");
                        return(false);
                    }

                    break;
                }

                case CraftItem.CraftPrereq.OnGround:
                {
                    Voxel below = new Voxel();
                    designation.Location.GetNeighbor(Vector3.Down, ref below);

                    if (below.IsEmpty)
                    {
                        World.ShowToolPopup("Must be built on solid ground!");
                        return(false);
                    }
                    break;
                }
                }
            }

            return(true);
        }
コード例 #19
0
        public bool IsValid(CraftDesignation designation)
        {
            if (!designation.Valid)
            {
                return(false);
            }

            if (IsDesignation(designation.Location))
            {
                World.ShowToolPopup("Something is already being built there!");
                return(false);
            }

            if (!String.IsNullOrEmpty(designation.ItemType.CraftLocation) &&
                Faction.FindNearestItemWithTags(designation.ItemType.CraftLocation, designation.Location.WorldPosition, false) ==
                null)
            {
                World.ShowToolPopup("Can't build, need " + designation.ItemType.CraftLocation);
                return(false);
            }

            if (!Faction.HasResources(designation.ItemType.RequiredResources))
            {
                string neededResources = "";

                foreach (Quantitiy <Resource.ResourceTags> amount in designation.ItemType.RequiredResources)
                {
                    neededResources += "" + amount.NumResources + " " + amount.ResourceType.ToString() + " ";
                }

                World.ShowToolPopup("Not enough resources! Need " + neededResources + ".");
                return(false);
            }

            foreach (var req in designation.ItemType.Prerequisites)
            {
                switch (req)
                {
                case CraftItem.CraftPrereq.NearWall:
                {
                    var neighborFound = VoxelHelpers.EnumerateManhattanNeighbors2D(designation.Location.Coordinate)
                                        .Select(c => new VoxelHandle(World.ChunkManager.ChunkData, c))
                                        .Any(v => v.IsValid && !v.IsEmpty);

                    if (!neighborFound)
                    {
                        World.ShowToolPopup("Must be built next to wall!");
                        return(false);
                    }

                    break;
                }

                case CraftItem.CraftPrereq.OnGround:
                {
                    var below = VoxelHelpers.GetNeighbor(designation.Location, new GlobalVoxelOffset(0, -1, 0));

                    if (!below.IsValid || below.IsEmpty)
                    {
                        World.ShowToolPopup("Must be built on solid ground!");
                        return(false);
                    }
                    break;
                }
                }
            }

            if (CurrentCraftBody != null)
            {
                var intersectsAnyOther = Faction.OwnedObjects.FirstOrDefault(
                    o => o != null &&
                    o != CurrentCraftBody &&
                    o.GetRotatedBoundingBox().Intersects(CurrentCraftBody.GetRotatedBoundingBox().Expand(-0.1f)));

                var intersectsBuildObjects = Faction.Designations.EnumerateEntityDesignations(DesignationType.Craft)
                                             .Any(d => d.Body != CurrentCraftBody && d.Body.GetRotatedBoundingBox().Intersects(
                                                      CurrentCraftBody.GetRotatedBoundingBox().Expand(-0.1f)));

                bool intersectsWall = VoxelHelpers.EnumerateCoordinatesInBoundingBox
                                          (CurrentCraftBody.GetRotatedBoundingBox().Expand(-0.1f)).Any(
                    v =>
                {
                    var tvh = new VoxelHandle(World.ChunkManager.ChunkData, v);
                    return(tvh.IsValid && !tvh.IsEmpty);
                });

                if (intersectsAnyOther != null)
                {
                    World.ShowToolPopup("Can't build here: intersects " + intersectsAnyOther.Name);
                }
                else if (intersectsBuildObjects)
                {
                    World.ShowToolPopup("Can't build here: intersects something else being built");
                }
                else if (intersectsWall && !designation.ItemType.Prerequisites.Contains(CraftItem.CraftPrereq.NearWall))
                {
                    World.ShowToolPopup("Can't build here: intersects wall.");
                }

                return(intersectsAnyOther == null && !intersectsBuildObjects &&
                       (!intersectsWall || designation.ItemType.Prerequisites.Contains(CraftItem.CraftPrereq.NearWall)));
            }
            return(true);
        }
コード例 #20
0
        public void VoxelsSelected(List <VoxelHandle> refs, InputManager.MouseButton button)
        {
            if (!IsEnabled)
            {
                return;
            }
            switch (button)
            {
            case (InputManager.MouseButton.Left):
            {
                List <Task> assignments = new List <Task>();
                // Creating multiples doesn't work anyway - kill it.
                foreach (var r in refs)
                {
                    if (IsDesignation(r) || !r.IsValid || !r.IsEmpty)
                    {
                        continue;
                    }
                    else
                    {
                        Vector3 pos = r.WorldPosition + new Vector3(0.5f, 0.0f, 0.5f) + CurrentCraftType.SpawnOffset;

                        Vector3 startPos = pos + new Vector3(0.0f, -0.1f, 0.0f);
                        Vector3 endPos   = pos;
                        // TODO: Why are we creating a new designation?
                        CraftDesignation newDesignation = new CraftDesignation()
                        {
                            ItemType            = CurrentCraftType,
                            Location            = r,
                            Orientation         = CurrentDesignation.Orientation,
                            OverrideOrientation = CurrentDesignation.OverrideOrientation,
                            Valid             = true,
                            Entity            = CurrentCraftBody,
                            SelectedResources = SelectedResources
                        };

                        if (IsValid(newDesignation))
                        {
                            AddDesignation(newDesignation, CurrentCraftType.SpawnOffset);
                            assignments.Add(new CraftItemTask(newDesignation));

                            // Todo: Maybe don't support create huge numbers of entities at once?
                            CurrentCraftBody = EntityFactory.CreateEntity <Body>(CurrentCraftType.Name, r.WorldPosition,
                                                                                 Blackboard.Create <List <ResourceAmount> >("Resources", SelectedResources));
                            EntityFactory.GhostEntity(CurrentCraftBody, Color.White);

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

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

                break;
            }

            case (InputManager.MouseButton.Right):
            {
                foreach (var r in refs)
                {
                    if (!IsDesignation(r))
                    {
                        continue;
                    }
                    RemoveDesignation(r);
                }
                break;
            }
            }
        }
コード例 #21
0
ファイル: BuildRailTool.cs プロジェクト: jeason1997/dwarfcorp
        private void Place(VoxelHandle Location)
        {
            var assignments = new List <Task>();

            for (var i = 0; i < PreviewBodies.Count; ++i)
            {
                var body              = PreviewBodies[i];
                var piece             = Pattern.Pieces[i];
                var actualPosition    = new VoxelHandle(Location.Chunk.Manager.ChunkData, Location.Coordinate + new GlobalVoxelOffset(piece.Offset.X, 0, piece.Offset.Y));
                var addNewDesignation = true;

                foreach (var entity in Player.World.CollisionManager.EnumerateIntersectingObjects(actualPosition.GetBoundingBox().Expand(-0.2f), CollisionManager.CollisionType.Static))
                {
                    if (!addNewDesignation)
                    {
                        break;
                    }
                    if (Object.ReferenceEquals(entity, body))
                    {
                        continue;
                    }

                    var possibleCombination = FindPossibleCombination(piece, entity);
                    if (possibleCombination != null)
                    {
                        var combinedPiece = new Rail.JunctionPiece
                        {
                            RailPiece   = possibleCombination.Result,
                            Orientation = Rail.OrientationHelper.Rotate((entity as RailPiece).Piece.Orientation, (int)possibleCombination.ResultRelativeOrientation),
                        };

                        var existingDesignation = Player.Faction.Designations.EnumerateEntityDesignations(DesignationType.Craft).FirstOrDefault(d => Object.ReferenceEquals(d.Body, entity));
                        if (existingDesignation != null)
                        {
                            (entity as RailPiece).UpdatePiece(combinedPiece, actualPosition);
                            (existingDesignation.Tag as CraftDesignation).Progress = 0.0f;
                            body.Delete();
                            addNewDesignation = false;
                        }
                        else
                        {
                            (entity as RailPiece).Die();
                            body.UpdatePiece(combinedPiece, actualPosition);
                        }
                    }
                }

                if (addNewDesignation)
                {
                    var startPos = body.Position + new Vector3(0.0f, -0.3f, 0.0f);
                    var endPos   = body.Position;

                    var designation = new CraftDesignation
                    {
                        Entity              = body,
                        WorkPile            = new WorkPile(Player.World.ComponentManager, startPos),
                        OverrideOrientation = false,
                        Valid                = true,
                        ItemType             = RailCraftItem,
                        SelectedResources    = SelectedResources,
                        Location             = new VoxelHandle(Player.World.ChunkManager.ChunkData, GlobalVoxelCoordinate.FromVector3(body.Position)),
                        HasResources         = false,
                        ResourcesReservedFor = null,
                        Orientation          = 0.0f,
                        Progress             = 0.0f,
                    };

                    Player.World.ComponentManager.RootComponent.AddChild(designation.WorkPile);
                    designation.WorkPile.AnimationQueue.Add(new EaseMotion(1.1f, Matrix.CreateTranslation(startPos), endPos));
                    Player.World.ParticleManager.Trigger("puff", endPos, Color.White, 10);
                    Player.Faction.Designations.AddEntityDesignation(body, DesignationType.Craft, designation);
                    assignments.Add(new CraftItemTask(designation));
                }
            }

            if (assignments.Count > 0)
            {
                Player.World.Master.TaskManager.AddTasks(assignments);
            }
        }
コード例 #22
0
 public void AddDesignation(CraftDesignation des)
 {
     Designations.Add(des);
 }