コード例 #1
0
        // CONSTRUCTORS

        public Player(Block[] map, Point position, Point worldIndex, int currentFloor, int sightDist, string name, string gender, DietType diet, string faction, Class uclass, byte graphic = 1,
                      bool solid = true, bool opaque = true) : base(map, position, worldIndex, currentFloor, sightDist, graphic, name, gender, diet, faction, solid, opaque)
        {
            ForeColor = Color.AntiqueWhite;

            BlueprintPouch bpPouch    = new BlueprintPouch(false);
            RecipePouch    craftPouch = new RecipePouch(false);

            Inventory.Add(bpPouch);
            Inventory.Add(craftPouch);
            Inventory.Add(new Axe(true)
            {
                WeaponName = "pickaxe", Material = Material.Copper
            });
            Inventory.Add(new Torch(false));
            foreach (Item i in Inventory)
            {
                i.DetermineDurability();
            }

            Gold  = 550;
            Class = uclass;
            DetermineStats();
            DetermineEquipment();
        }
コード例 #2
0
ファイル: Player.cs プロジェクト: ybottom/Landlord-Master
        // CONSTRUCTORS

        public Player(Block[] map, Point position, int sightDist, string name, string gender, bool friendly, Class uclass, byte graphic = 1,
                      bool solid = true, bool opaque = true) : base(map, position, sightDist, graphic, name, gender, friendly, solid, opaque)
        {
            ForeColor = Color.AntiqueWhite;

            BlueprintPouch bpPouch    = new BlueprintPouch(false);
            RecipePouch    craftPouch = new RecipePouch(false);

            Inventory.Add(bpPouch);
            Inventory.Add(craftPouch);
            Inventory.Add(new Axe(true)
            {
                WeaponName = "pickaxe", Material = Material.Copper
            });

            Gold  = 6000;
            Class = uclass;
            DetermineStats();
            DetermineEquipment();
        }
コード例 #3
0
        private static void HandleGetMaterial(Creature c, RecipeComponent nextComponent, bool forCrafting = false)
        {
            Point nextPos = GetClosestMaterialPos(c, nextComponent, true); // returns new Point() if item is in player's inventory, returns null if the object can't be found

            // if the material is not on the map or in your inventory
            if (nextPos == null)
            {
                if (nextComponent == RecipeComponent.Log)
                {
                    HandleChopTree(c);
                }
                else if (nextComponent == RecipeComponent.Stone)
                {
                    HandleMineRock(c);
                }
                else
                {
                    // if there is no crafting recipe stored and the player has a recipe pouch
                    if (currentCraftingRecipe == null && c.Inventory.Exists(i => i is RecipePouch))
                    {
                        RecipePouch rp = (RecipePouch)c.Inventory.Find(i => i is RecipePouch);
                        foreach (CraftingRecipe r in rp.Recipes)
                        {
                            if (r.CraftingTarget.Exists(e => e.ToComponent() == nextComponent))
                            {
                                currentCraftingRecipe = r;
                                break;
                            }
                        }
                    }
                    else if (currentCraftingRecipe != null)
                    {
                        if (!currentCraftingRecipe.CraftingTarget.Exists(e => e.ToComponent() == nextComponent))
                        {
                            currentCraftingRecipe = null;
                        }
                        if (c.Inventory.Exists(i => i.ToComponent() == currentCraftingRecipe.Recipe[0]))
                        {
                            HandleCraftComponent(c);
                        }
                        else
                        {
                            HandleGetMaterial(c, currentCraftingRecipe.Recipe[0], true);
                        }
                    }
                }
                return;
            }

            if (nextPos.Equals(new Point()))
            {
                nextPos = GetClosestMaterialPos(c, nextComponent, false);
            }


            if (nextPos == null)
            {
                creatureStates[c.ID] = CreatureState.PlaceMaterials;
                return;
            }

            if (!nextPos.Equals(new Point()) || c.CheckCanCarryItem(nextComponent.ToItem()) == true)
            {
                bool    nextToItem = c.Position.NextToPoint(nextPos);
                int     currentFloor = c.CurrentFloor;
                Point   worldIndex = c.WorldIndex;
                Block[] blocks = currentFloor >= 0 ? Program.WorldMap[worldIndex.X, worldIndex.Y].Dungeon.Floors[currentFloor].Blocks : Program.WorldMap[worldIndex.X, worldIndex.Y].Blocks;
                int     width = Program.WorldMap.TileWidth, height = Program.WorldMap.TileHeight;

                if (nextToItem)
                {
                    if (blocks[nextPos.X * width + nextPos.Y] is Chest chest)
                    {
                        for (int i = chest.Inventory.Count - 1; i >= 0; i--)
                        {
                            if (chest.Inventory[i].ToComponent() == nextComponent)
                            {
                                bool itemAdded = c.AddItem(chest.Inventory[i]);
                                if (itemAdded)
                                {
                                    chest.Inventory.RemoveAt(i);
                                }
                                else if (DropUnnecessaryItems(c, nextComponent))
                                {
                                    itemAdded = c.AddItem(chest.Inventory[i]);
                                    if (itemAdded)
                                    {
                                        chest.Inventory.RemoveAt(i);
                                    }
                                    else
                                    {
                                        creatureStates[c.ID] = CreatureState.PlaceMaterials;
                                    }
                                }
                                else
                                {
                                    creatureStates[c.ID] = CreatureState.PlaceMaterials;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (c.CheckCanCarryItem((Item)blocks[nextPos.X * width + nextPos.Y]))
                        {
                            c.GetItem(nextPos);
                            getIndex++;
                        }
                        else
                        {
                            bool droppedItems = DropUnnecessaryItems(c, nextComponent);
                            if (droppedItems == false)
                            {
                                creatureStates[c.ID] = CreatureState.PlaceMaterials;
                            }
                        }
                    }
                }
                else if (c.Path == null)
                {
                    c.SetPath(nextPos);
                }
            }
            else
            {
                c.Path = null;
                creatureStates[c.ID] = CreatureState.PlaceMaterials;
            }
        }
コード例 #4
0
        private static void HandleGetMaterial(RecipeComponent nextComponent, bool forCrafting = false)
        {
            Point nextPos = GetClosestMaterialPos(nextComponent, true); // returns new Point() if item is in player's inventory, returns null if the object can't be found

            if (nextPos == null)
            {
                if (nextComponent == RecipeComponent.Log)
                {
                    HandleChopTree();
                }
                else if (nextComponent == RecipeComponent.Stone)
                {
                }
                else
                {
                    if (currentCraftingRecipe == null && Program.Player.Inventory.Exists(i => i is RecipePouch))
                    {
                        RecipePouch rp = (RecipePouch)Program.Player.Inventory.Find(i => i is RecipePouch);
                        foreach (CraftingRecipe r in rp.Recipes)
                        {
                            if (r.CraftingTarget.Exists(e => e.ToComponent() == nextComponent))
                            {
                                currentCraftingRecipe = r;
                                break;
                            }
                        }
                    }
                    if (currentCraftingRecipe != null)
                    {
                        if (Program.Player.Inventory.Exists(i => i.ToComponent() == currentCraftingRecipe.Recipe[0]))
                        {
                            HandleCraftComponent();
                        }
                        else
                        {
                            HandleGetMaterial(currentCraftingRecipe.Recipe[0], true);
                        }
                    }
                }

                return;
            }

            bool hasItem = nextPos.Equals(new Point());

            if (hasItem == true)
            {
                nextPos = GetClosestMaterialPos(nextComponent, false);
            }


            if (nextPos == null)
            {
                playerState = PlayerState.PlaceMaterials;
                return;
            }

            if (hasItem == false || Program.Player.CanCarryItem(nextComponent.ToItem()) == true)
            {
                bool nextToItem = Program.Player.PointNextToSelf(nextPos);
                if (nextToItem)
                {
                    if (Program.WorldMap.LocalTile[nextPos.X, nextPos.Y] is Chest chest)
                    {
                        for (int i = chest.Inventory.Count - 1; i >= 0; i--)
                        {
                            if (chest.Inventory[i].ToComponent() == nextComponent)
                            {
                                bool itemAdded = Program.Player.AddItem(chest.Inventory[i]);
                                if (itemAdded)
                                {
                                    chest.Inventory.RemoveAt(i);
                                }
                                else if (DropUnnecessaryItems(nextComponent))
                                {
                                    itemAdded = Program.Player.AddItem(chest.Inventory[i]);
                                    if (itemAdded)
                                    {
                                        chest.Inventory.RemoveAt(i);
                                    }
                                    else
                                    {
                                        playerState = PlayerState.PlaceMaterials;
                                    }
                                }
                                else
                                {
                                    playerState = PlayerState.PlaceMaterials;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (Program.Player.CanCarryItem((Item)Program.WorldMap.LocalTile[nextPos.X, nextPos.Y]))
                        {
                            Program.Player.GetItem(nextPos);
                            getIndex++;
                        }
                        else
                        {
                            bool droppedItems = DropUnnecessaryItems(nextComponent);
                            if (droppedItems == false)
                            {
                                playerState = PlayerState.PlaceMaterials;
                            }
                        }
                    }
                }
                else if (Program.Player.Path == null)
                {
                    Program.Player.SetPath(nextPos);
                }
            }
            else
            {
                Program.Player.Path = null;
                playerState         = PlayerState.PlaceMaterials;
            }
        }