Beispiel #1
0
        private static GameComponent __factory(ComponentManager Manager, Vector3 Position, Blackboard Data)
        {
            var resources = Data.GetData <List <ResourceAmount> >("Resources", null);
            var craftType = Data.GetData <string>("CraftType", null);

            if (resources == null && craftType != null)
            {
                resources = new List <ResourceAmount>();
                var craftItem = CraftLibrary.GetCraftable(craftType);
                foreach (var resource in craftItem.RequiredResources)
                {
                    var genericResource = ResourceLibrary.GetResourcesByTag(resource.ResourceType).FirstOrDefault();
                    resources.Add(new ResourceAmount(genericResource, resource.NumResources));
                }
            }
            else if (resources == null && craftType == null)
            {
                craftType = "Wooden Ladder";
                resources = new List <ResourceAmount>()
                {
                    new ResourceAmount(ResourceType.Wood)
                };
            }
            else if (craftType == null)
            {
                craftType = "Wooden Ladder";
            }

            return(new Ladder(
                       Manager,
                       Position,
                       resources, craftType));
        }
Beispiel #2
0
        public CraftItem ObjectAsCraftableResource()
        {
            string    resourceName = Name + "...";
            CraftItem toReturn     = CraftLibrary.GetCraftable(resourceName);

            if (toReturn == null)
            {
                toReturn                   = this.MemberwiseClone() as CraftItem;
                toReturn.Name              = resourceName;
                toReturn.Type              = CraftType.Resource;
                toReturn.CraftActBehavior  = CraftActBehaviors.Object;
                toReturn.ResourceCreated   = "Object";
                toReturn.CraftLocation     = String.IsNullOrEmpty(CraftLocation) ? "Anvil" : CraftLocation;
                toReturn.ObjectName        = Name;
                toReturn.AllowUserCrafting = false;
                CraftLibrary.Add(toReturn);
            }
            return(toReturn);
        }
Beispiel #3
0
        public CraftDetails(ComponentManager manager, string craftType, List <ResourceAmount> resources = null) :
            this(manager)
        {
            CraftType = craftType;

            if (resources != null)
            {
                Resources = resources;
            }
            else
            {
                Resources = new List <ResourceAmount>();
                var libraryType = CraftLibrary.GetCraftable(craftType);

                if (libraryType != null)
                {
                    foreach (var requirement in libraryType.RequiredResources)
                    {
                        Resources.Add(new ResourceAmount(ResourceLibrary.GetLeastValuableWithTag(requirement.ResourceType), requirement.NumResources));
                    }
                }
            }
        }
Beispiel #4
0
        public override void Die()
        {
            var body = Parent.GetRoot().GetComponent <Body>();

            if (body != null)
            {
                var bounds = body.GetBoundingBox();

                /*
                 * foreach(var resource in Resources)
                 * {
                 *  for (int i = 0; i < resource.NumResources; i++)
                 *  {
                 *      Vector3 pos = MathFunctions.RandVector3Box(bounds);
                 *      EntityFactory.CreateEntity<Body>(resource.ResourceType + " Resource", pos);
                 *  }
                 * }
                 */
                Resource resource = CraftLibrary.GetCraftable(this.CraftType).ToResource(World, Resources);
                Vector3  pos      = MathFunctions.RandVector3Box(bounds);
                EntityFactory.CreateEntity <Body>(resource.Name + " Resource", pos);
            }
            base.Die();
        }
Beispiel #5
0
        public override void Update(DwarfGame game, DwarfTime time)
        {
            if (Player.IsCameraRotationModeActive())
            {
                return;
            }

            Player.VoxSelector.Enabled  = false;
            Player.BodySelector.Enabled = false;

            if (Player.World.IsMouseOverGui)
            {
                Player.World.SetMouse(Player.World.MousePointer);
            }
            else
            {
                Player.World.SetMouse(new Gui.MousePointer("mouse", 1, 9));
            }

            MouseState mouse = Mouse.GetState();


            if (State == ToolState.Selecting)
            {
                if (SelectedBody != null)
                {
                    foreach (var tinter in SelectedBody.GetRoot().EnumerateAll().OfType <Tinter>())
                    {
                        tinter.VertexColorTint = Color.White;
                        tinter.Stipple         = false;
                    }
                }

                SelectedBody = Player.World.ComponentManager.SelectRootBodiesOnScreen(new Rectangle(mouse.X, mouse.Y, 1, 1), Player.World.Camera)
                               .Where(body => body.Tags.Contains("Moveable"))
                               .FirstOrDefault();

                if (SelectedBody != null)
                {
                    if (SelectedBody.IsReserved)
                    {
                        Player.World.ShowTooltip("Can't move this " + SelectedBody.Name + "\nIt is being used.");
                    }
                    else
                    {
                        Player.World.ShowTooltip("Left click and drag to move this " + SelectedBody.Name);
                        foreach (var tinter in SelectedBody.GetRoot().EnumerateAll().OfType <Tinter>())
                        {
                            tinter.VertexColorTint = Color.Blue;
                            tinter.Stipple         = false;
                        }
                    }

                    if (mouse.LeftButton == ButtonState.Pressed)
                    {
                        StartDragging(SelectedBody);
                    }
                }
            }
            else if (State == ToolState.Dragging)
            {
                if (SelectedBody == null)
                {
                    throw new InvalidProgramException();
                }

                var craftDetails = SelectedBody.GetRoot().GetComponent <CraftDetails>();
                if (craftDetails != null && CraftLibrary.GetCraftable(craftDetails.CraftType).AllowRotation)
                {
                    HandleOrientation();
                    Player.World.ShowToolPopup(String.Format("Press {0}/{1} to rotate.", ControlSettings.Mappings.RotateObjectLeft, ControlSettings.Mappings.RotateObjectRight));
                }

                var voxelUnderMouse = Player.VoxSelector.VoxelUnderMouse;
                if (voxelUnderMouse.IsValid && voxelUnderMouse.IsEmpty)
                {
                    var       spawnOffset = Vector3.Zero;
                    CraftItem craftItem   = null;

                    if (craftDetails != null)
                    {
                        craftItem = CraftLibrary.GetCraftable(craftDetails.CraftType);
                        if (craftItem != null)
                        {
                            spawnOffset = craftItem.SpawnOffset;
                        }
                        else
                        {
                            Console.Error.WriteLine("{0} had no craft item.", craftDetails.CraftType);
                        }
                    }


                    if (craftItem == null)
                    {
                        return;
                    }

                    SelectedBody.LocalPosition = voxelUnderMouse.WorldPosition + new Vector3(0.5f, 0.0f, 0.5f) + spawnOffset;
                    SelectedBody.UpdateTransform();

                    if (OverrideOrientation)
                    {
                        SelectedBody.Orient(CurrentOrientation);
                    }
                    else
                    {
                        SelectedBody.OrientToWalls();
                    }

                    SelectedBody.PropogateTransforms();

                    var validPlacement = ObjectHelper.IsValidPlacement(voxelUnderMouse, craftItem, Player, SelectedBody, "move", "moved");

                    foreach (var tinter in SelectedBody.GetRoot().EnumerateAll().OfType <Tinter>())
                    {
                        tinter.VertexColorTint = validPlacement ? Color.Green : Color.Red;
                        tinter.Stipple         = true;
                    }

                    if (mouse.LeftButton == ButtonState.Released)
                    {
                        if (validPlacement)
                        {
                        }
                        else
                        {
                            SelectedBody.LocalTransform = OrigTransform;
                            SelectedBody.PropogateTransforms();
                        }

                        foreach (var tinter in SelectedBody.GetRoot().EnumerateAll().OfType <Tinter>())
                        {
                            tinter.VertexColorTint = Color.White;
                            tinter.Stipple         = false;
                        }

                        State = ToolState.Selecting;
                    }
                }
            }
        }
Beispiel #6
0
        public override void OnVoxelsSelected(List <VoxelHandle> refs, InputManager.MouseButton button)
        {
            if (Command.Contains("Build/"))
            {
                string         type = Command.Substring(6);
                BuildRoomOrder des  = new BuildRoomOrder(RoomLibrary.CreateRoom(Player.Faction, type, refs, false, Player.World), Player.Faction, Player.World);
                des.ToBuild.Designations = refs;
                Player.Faction.RoomBuilder.BuildDesignations.Add(des);
                Player.Faction.RoomBuilder.DesignatedRooms.Add(des.ToBuild);
                des.Build();
            }
            if (Command.Contains("Spawn/"))
            {
                string type = Command.Substring(6);
                foreach (var vox in refs.Where(vox => vox.IsValid))
                {
                    if (vox.IsEmpty)
                    {
                        var craftItem = CraftLibrary.GetCraftable(type);
                        var offset    = Vector3.Zero;

                        if (craftItem != null)
                        {
                            offset = craftItem.SpawnOffset;
                        }

                        var body = EntityFactory.CreateEntity <Body>(type, vox.WorldPosition + new Vector3(0.5f, 0.0f, 0.5f) + offset);
                        if (body != null)
                        {
                            body.PropogateTransforms();

                            if (craftItem != null)
                            {
                                if (craftItem.AddToOwnedPool)
                                {
                                    Player.Faction.OwnedObjects.Add(body);
                                }

                                if (craftItem.Moveable)
                                {
                                    body.Tags.Add("Moveable");
                                }

                                if (craftItem.Deconstructable)
                                {
                                    body.Tags.Add("Deconstructable");
                                }
                            }
                        }
                    }
                }
            }
            else if (Command.Contains("Rail/"))
            {
                string type     = Command.Substring("Rail/".Length);
                var    junction = new Rail.JunctionPiece
                {
                    RailPiece   = type,
                    Orientation = Rail.PieceOrientation.North,
                    Offset      = Point.Zero
                };

                foreach (var vox in refs.Where(vox => vox.IsValid))
                {
                    if (vox.IsEmpty)
                    {
                        var entity = new Rail.RailEntity(Player.World.ComponentManager, vox, junction);
                        Player.World.ComponentManager.RootComponent.AddChild(entity);
                    }
                }
            }
            else if (Command.Contains("Grass/"))
            {
                var type = GrassLibrary.GetGrassType(Command.Substring(6));
                foreach (var vox in refs.Where(v => v.IsValid))
                {
                    var v = vox;
                    if (!vox.IsEmpty)
                    {
                        v.GrassType = type.ID;
                    }
                }
            }
            else if (Command.Contains("Decal/"))
            {
                var type = DecalLibrary.GetGrassType(Command.Substring(6));
                foreach (var vox in refs.Where(v => v.IsValid))
                {
                    var v = vox;
                    if (!vox.IsEmpty)
                    {
                        v.Decal = DecalType.EncodeDecal(DecalOrientation, type.ID);
                    }
                }
            }
            else
            {
                foreach (var vox in refs.Where(vox => vox.IsValid))
                {
                    if (Command.Contains("Place/"))
                    {
                        string type = Command.Substring(6);
                        var    v    = vox;
                        v.Type = VoxelLibrary.GetVoxelType(type);
                        v.QuickSetLiquid(LiquidType.None, 0);

                        if (type == "Magic")
                        {
                            Player.World.ComponentManager.RootComponent.AddChild(
                                new DestroyOnTimer(Player.World.ComponentManager, Player.World.ChunkManager, vox)
                            {
                                DestroyTimer = new Timer(5.0f + MathFunctions.Rand(-0.5f, 0.5f), true)
                            });
                        }
                    }
                    else
                    {
                        switch (Command)
                        {
                        case "Delete Block":
                        {
                            var v = vox;
                            Player.World.Master.Faction.OnVoxelDestroyed(vox);
                            v.Type = VoxelLibrary.emptyType;
                            v.QuickSetLiquid(LiquidType.None, 0);
                        }
                        break;

                        case "Kill Block":
                            foreach (var selected in refs)
                            {
                                if (!selected.IsEmpty)
                                {
                                    Player.World.ChunkManager.KillVoxel(selected);
                                }
                            }
                            break;

                        case "Fill Water":
                        {
                            if (vox.IsEmpty)
                            {
                                var v = vox;
                                v.QuickSetLiquid(LiquidType.Water, WaterManager.maxWaterLevel);
                            }
                        }
                        break;

                        case "Fill Lava":
                        {
                            if (vox.IsEmpty)
                            {
                                var v = vox;
                                v.QuickSetLiquid(LiquidType.Lava, WaterManager.maxWaterLevel);
                            }
                        }
                        break;

                        case "Fire":
                        {
                            foreach (var flam2 in Player.World.EnumerateIntersectingObjects(vox.GetBoundingBox(), CollisionType.Both).OfType <Flammable>())
                            {
                                flam2.Heat = flam2.Flashpoint + 1;
                            }
                        }
                        break;

                        case "Kill Things":
                        {
                            foreach (var comp in Player.World.EnumerateIntersectingObjects(vox.GetBoundingBox(), CollisionType.Both))
                            {
                                comp.Die();
                            }
                        }
                        break;

                        case "Disease":
                        {
                            foreach (var creature in Player.World.EnumerateIntersectingObjects(vox.GetBoundingBox(), CollisionType.Both).OfType <Creature>())
                            {
                                var disease = Datastructures.SelectRandom(DiseaseLibrary.Diseases);
                                creature.AcquireDisease(disease.Name);
                            }
                            break;
                        }

                        default:
                            break;
                        }
                    }
                }
            }
        }