Esempio n. 1
0
        public Tile[,] tileArray = new Tile[GRIDW, GRIDH]; //X,Y; used for storing base tile information

        #endregion Fields

        #region Constructors

        public Level(int rCount, int cCount, String type, ContentEncyclopedia content, 
            int rngSeed, Vector3 mapPos)
        {
            seed = rngSeed;
            causeOfDeath = "unknown causes."; //If this never gets tripped, then wtf
            mannerOfDeath = "mysterious circumstances - will they never find a cure?"; //Ditto
            this.mapPos = mapPos;
            levelType = type;
            rng = new Random(rngSeed);
            rngDie = new Dice(rngSeed);
            this.content = content;
            int itemCount = rng.Next(5, 11); //5 to 10 items per level
            int creatureCount = rng.Next(5, 11); //5 to 10 initial creatures
            int x, y;

            switch(type)
            {
            case "dungeon":
                FillWithFreshTiles(false);
                MakeEmptyRooms();
                MakeCorridors();

                #region Place other fixtures
                bool doneFixtures = false; //Set up a stop condition for the next loop
                while (!doneFixtures) //A loop to place the down stairs randomly in an open space
                {
                    int r = rng.Next(0, rooms.Count); //Random major room
                    while (rooms[r].isIsolated) //Make sure we don't put stuff in isolated rooms
                        r = rng.Next(0, rooms.Count);

                    x = rng.Next(rooms[r].x + 1, rooms[r].x + rooms[r].width - 1);
                    y = rng.Next(rooms[r].y + 1, rooms[r].y + rooms[r].height - 1); //Pick a random spot in room

                    if (tileArray[x, y].isPassable && tileArray[x, y].fixtureLibrary.Count <= 0)
                    {
                        tileArray[x, y].fixtureLibrary.Add(new Stairs(true));

                        doneFixtures = true;
                    }
                }

                doneFixtures = false; //Reset
                for (int k = 0; k < 5; k++)
                {
                    x = rng.Next(3, GRIDW - 2);
                    y = rng.Next(3, GRIDH - 2); //Pick a random spot

                    if (tileArray[x, y].isPassable && tileArray[x, y].fixtureLibrary.Count <= 0) //If it's walkable
                    {
                        Trap thisTrap = new Trap(new Effect(rngDie.Roll(5), "tripwire"));
                        //thisTrap.visible = true; //For now, let's see where these things go
                        tileArray[x, y].fixtureLibrary.Add(thisTrap); //Place a tripwire here
                    }
                    else
                    {
                        k--;
                    }
                }
                #endregion

                PlacePlayer();

                rng = new Random((int)DateTime.Now.Ticks); //Reseed the level so the other things will change

                for (int i = 1; i <= creatureCount; i++)
                {
                    SpawnCreature(true, "monster");
                }

                #region Place the items
                for (int i = 1; i <= itemCount; i++)
                {
                    bool doneItems = false; //Set up a stop condition for the next loop
                    while (doneItems == false) //A loop to place the creature randomly in an open space
                    {
                        int r = rng.Next(0, rooms.Count); //Random major room
                        while (rooms[r].isIsolated)
                            r = rng.Next(0, rooms.Count);

                        x = rng.Next(rooms[r].x + 1, rooms[r].x + rooms[r].width - 1);
                        y = rng.Next(rooms[r].y + 1, rooms[r].y + rooms[r].height - 1); //Pick a random spot in room

                        if (tileArray[x, y].isPassable == true) //If it's passable
                        {
                            List<Armor> armorList = new List<Armor>();
                            List<Potion> potionList = new List<Potion>();
                            List<Weapon> weaponList = new List<Weapon>();
                            List<Item> plainList = new List<Item>();

                            foreach (Item t in content.items) //Organze the items for random drops TODO: Is this necessary? Linq?
                            {
                                if (t is Armor)
                                    armorList.Add((Armor)t);
                                else if (t is Potion)
                                    potionList.Add((Potion)t);
                                else if (t is Weapon)
                                    weaponList.Add((Weapon)t);
                                else
                                {
                                    if (ROOMTEMPERATURE > t.material.meltPoint) //Ugh, liquid
                                    {
                                        plainList.Add(t);
                                    }
                                }
                            }

                            Item thisItem;

                            if (rng.Next(0, 100) < 50) //50% chance
                            {
                                thisItem = plainList[(int)rng.Next(0, plainList.Count)]; //Random other item
                            }
                            else if (rng.Next(0, 100) < 30) //30% chance of 70%
                            {
                                thisItem = armorList[(int)rng.Next(0, armorList.Count)]; //Random armor
                            }
                            else if (rng.Next(0, 100) < 30) //30% chance of 70% of 70%
                            {
                                thisItem = weaponList[(int)rng.Next(0, weaponList.Count)]; //Random weapon
                            }
                            else
                            {
                                thisItem = potionList[(int)rng.Next(0, potionList.Count)]; //Random potion
                            }

                            tileArray[x, y].itemList.Add(thisItem); //Add a item to the Level's item list

                            armorList.Clear();
                            potionList.Clear();
                            weaponList.Clear();
                            doneItems = true;
                        }
                    }
                }
                #endregion
                break;

            case "forest":
                FillWithFreshTiles(true);
                FillWithTrees();
                PlacePlayer();

                rng = new Random((int)DateTime.Now.Ticks); //Reseed the level so the other things will change

                creatureCount = rng.Next(1, 5); //1 to 4 initial creatures

                for (int i = 1; i <= creatureCount; i++)
                {
                    SpawnCreature(false, "monster");
                }
                break;

            case "village":
                FillWithFreshTiles(true);
                FillWithTrees();
                MakeEmptyRooms();
                MakeShop();
                MakeCorridors();
                PlacePlayer();

                #region Place the villagers
                creatureCount = roomCount; //1 for every room

                for (int i = 1; i <= creatureCount; i++)
                {
                    SpawnCreature(true, "quest giver");
                }
                #endregion
                break;
            }
        }
Esempio n. 2
0
        static void Inv_Main_UseItem()
        {
            if (!currentLevel.creatures[0].isDextrous) //Check to see if these can be used
            {
                currentLevel.creatures[0].message.Add("Your limbs are too clumsy to use this");
            }
            else if (currentLevel.creatures[0].inventory[inventorySelect - 1].use.Count > 1) //If it has multple uses
            {
                //inventoryMode = 2; //Switch to Use mode with item WIP
            }
            else if (currentLevel.creatures[0].inventory[inventorySelect - 1].use.Count == 1)
            {
                //Do the use for the item
                if (currentLevel.creatures[0].inventory[inventorySelect - 1].use[0] == "dig")
                {
                    #region Dig
                    Vector2 pos = currentLevel.creatures[0].pos;

                    if (currentLevel.tileArray[pos.X, pos.Y].hasBeenDug) //If it's been dug
                    {
                        Creature player = currentLevel.creatures[0];
                        player.message.Add("You break through the floor, and fall all the way to the next level down.");
                        player.TakeDamage(5);
                        player.message.Add("You land with a painful thud.");
                        mapPos.Z++;
                        GenLevel("dungeon", true);
                        while (!currentLevel.tileArray[player.pos.X, player.pos.Y].isPassable) //Keep going until we can move
                        {
                            player.pos.X = (short)rng.Next(1, Level.GRIDW);
                            player.pos.Y = (short)rng.Next(1, Level.GRIDH);
                        }
                        currentLevel.creatures[0] = player;
                        Item dirtChunk = new Item(100f, 100f, "dirt chunk", Color.FromArgb(157, 144, 118), new List<Item>(), new List<string>()); //Chunk of dirt
                        currentLevel.tileArray[player.pos.X, player.pos.Y].itemList.Add(new Item(dirtChunk)); //Put the dirt chunk there
                    }
                    else
                    {
                        Item dirtChunk = new Item(100f, 100f, "dirt chunk", Color.FromArgb(157, 144, 118), new List<Item>(), new List<string>()); //Chunk of dirt
                        currentLevel.tileArray[pos.X, pos.Y].itemList.Add(new Item(dirtChunk)); //Put the dirt chunk there
                        currentLevel.tileArray[pos.X, pos.Y].hasBeenDug = true; //We've dug a pit here.
                        currentLevel.creatures[0].message.Add("You dig a hole, unearthing some dirt.");
                    }
                    #endregion
                }
                else if (currentLevel.creatures[0].inventory[inventorySelect - 1].use[0] == "mine")
                {
                    #region Mine
                    currentLevel.creatures[0].message.Add("Choose a direction to dig.");
                    gameState = GameState.MainGame;
                    string input = Update_GetKey();

                    Vector2 playerPos = currentLevel.creatures[0].pos;
                    Vector2 radius = new Vector2(playerPos.X, playerPos.Y);

                    if (input == "1")
                        radius = new Vector2(playerPos.X - 1, playerPos.Y + 1);
                    else if (input == "2")
                        radius = new Vector2(playerPos.X - 0, playerPos.Y + 1);
                    else if (input == "3")
                        radius = new Vector2(playerPos.X + 1, playerPos.Y + 1);
                    else if (input == "4")
                        radius = new Vector2(playerPos.X - 1, playerPos.Y - 0);
                    else if (input == "6")
                        radius = new Vector2(playerPos.X + 1, playerPos.Y - 0);
                    else if (input == "7")
                        radius = new Vector2(playerPos.X - 1, playerPos.Y - 1);
                    else if (input == "8")
                        radius = new Vector2(playerPos.X - 0, playerPos.Y - 1);
                    else if (input == "9")
                        radius = new Vector2(playerPos.X + 1, playerPos.Y - 1);
                    else
                    {
                        currentLevel.creatures[0].message.Add("Dig cancelled");
                        return;
                    }

                    if (currentLevel.tileArray[radius.X, radius.Y].fixtureLibrary.Count > 0)
                    {
                        if (currentLevel.tileArray[radius.X, radius.Y].fixtureLibrary[0] is Door)
                        {
                            if (rngDie.Roll(2) == 1) // 1/2 chance
                            {
                                currentLevel.creatures[0].message.Add("Your swing bounces wildly off the door");
                            }
                            else
                            {
                                currentLevel.creatures[0].message.Add("You break right through the door");
                                currentLevel.tileArray[radius.X, radius.Y].MakeOpen(); //Clear out adjacent tile
                            }
                        }
                        else if (currentLevel.tileArray[radius.X, radius.Y].fixtureLibrary[0] is Tree)
                        {
                            if (rngDie.Roll(100) == 1) // 1% chance
                            {
                                currentLevel.creatures[0].message.Add("You somehow hit a weak point and topple the tree!");
                                Tree thisTree = (Tree)currentLevel.tileArray[radius.X, radius.Y].fixtureLibrary[0];
                                currentLevel.tileArray[radius.X, radius.Y].itemList.Add(new Item(500f, 500f, CapitalizeFirst(thisTree.species) + " log", Color.Brown, new List<Item>(), new List<string>()));
                                currentLevel.creatures[0].message.Add("You cut down the " + thisTree.species + " tree.");
                                currentLevel.tileArray[radius.X, radius.Y].fixtureLibrary.RemoveAt(0);
                            }
                            else // 99% chance
                            {
                                currentLevel.creatures[0].message.Add("You chip off only sawdust");
                                currentLevel.tileArray[radius.X, radius.Y].MakeOpen(); //Clear out adjacent tile
                            }
                        }
                        else
                        {
                            currentLevel.tileArray[radius.X, radius.Y].MakeOpen(); //Clear out adjacent tile
                        }
                    }
                    else
                    {
                        currentLevel.tileArray[radius.X, radius.Y].MakeOpen(); //Clear out the adjacent tile
                    }
                    #endregion
                }
                else if (currentLevel.creatures[0].inventory[inventorySelect - 1].use[0] == "tripwire")
                {
                    #region Tripwire
                    Vector2 playerPos = currentLevel.creatures[0].pos;
                    if (currentLevel.tileArray[playerPos.X, playerPos.Y].fixtureLibrary.Count <= 0)
                    {
                        Trap thisTrap = new Trap(new Effect(rngDie.Roll(5), "tripwire"));
                        thisTrap.visible = true; //The player made it, so they can see it
                        currentLevel.tileArray[playerPos.X, playerPos.Y].fixtureLibrary.Add(thisTrap);

                        currentLevel.creatures[0].inventory.RemoveAt(inventorySelect - 1); //Rope is now in trap
                        currentLevel.creatures[0].message.Add("You make a tripwire from the rope.");
                    }
                    else
                    {
                        currentLevel.creatures[0].message.Add("There is already a " +
                            currentLevel.tileArray[playerPos.X, playerPos.Y].fixtureLibrary[0].type + " here.");
                    }
                    #endregion
                }
                else if (currentLevel.creatures[0].inventory[inventorySelect - 1].use[0] == "chop")
                {
                    #region Chop
                    currentLevel.creatures[0].message.Add("Choose a direction to chop.");
                    gameState = GameState.MainGame;
                    string input = Update_GetKey();

                    Vector2 playerPos = currentLevel.creatures[0].pos;
                    Vector2 radius = new Vector2(playerPos.X, playerPos.Y);

                    if (input == "1")
                        radius = new Vector2(playerPos.X - 1, playerPos.Y + 1);
                    else if (input == "2")
                        radius = new Vector2(playerPos.X - 0, playerPos.Y + 1);
                    else if (input == "3")
                        radius = new Vector2(playerPos.X + 1, playerPos.Y + 1);
                    else if (input == "4")
                        radius = new Vector2(playerPos.X - 1, playerPos.Y - 0);
                    else if (input == "6")
                        radius = new Vector2(playerPos.X + 1, playerPos.Y - 0);
                    else if (input == "7")
                        radius = new Vector2(playerPos.X - 1, playerPos.Y - 1);
                    else if (input == "8")
                        radius = new Vector2(playerPos.X - 0, playerPos.Y - 1);
                    else if (input == "9")
                        radius = new Vector2(playerPos.X + 1, playerPos.Y - 1);
                    else
                    {
                        currentLevel.creatures[0].message.Add("Chop cancelled");
                        return;
                    }

                    bool creatureThere = false;
                    foreach (Creature c in currentLevel.creatures)
                    {
                        if (c.pos == radius) //If a creature is there.
                        {
                            creatureThere = true;
                        }
                    }

                    if (creatureThere) //Stupid foreach limitations
                        currentLevel.creatures[0].MeleeAttack(currentLevel, Direction.Parse(input));
                    else
                    {
                        if (currentLevel.tileArray[radius.X, radius.Y].fixtureLibrary.Count > 0)
                        {
                            if (currentLevel.tileArray[radius.X, radius.Y].fixtureLibrary[0] is Tree)
                            {
                                Tree thisTree = (Tree)currentLevel.tileArray[radius.X, radius.Y].fixtureLibrary[0];
                                currentLevel.tileArray[radius.X, radius.Y].itemList.Add(new Item(500f, 500f, CapitalizeFirst(thisTree.species) + " log", Color.Brown, new List<Item>(), new List<string>()));
                                currentLevel.creatures[0].message.Add("You cut down the " + thisTree.species + " tree.");
                                currentLevel.tileArray[radius.X, radius.Y].fixtureLibrary.RemoveAt(0);
                            }
                            else if (currentLevel.tileArray[radius.X, radius.Y].fixtureLibrary[0] is Door)
                            {
                                Item stick = new Item(100f, 100f, "stick", Color.Brown, new List<Item>(), new List<string>());

                                currentLevel.tileArray[radius.X, radius.Y].itemList.Add(new Item(stick));
                                currentLevel.tileArray[radius.X, radius.Y].itemList.Add(new Item(stick));
                                currentLevel.tileArray[radius.X, radius.Y].itemList.Add(new Item(stick));

                                currentLevel.tileArray[radius.X, radius.Y].fixtureLibrary.RemoveAt(0);
                                currentLevel.tileArray[radius.X, radius.Y].isPassable = true;
                                currentLevel.tileArray[radius.X, radius.Y].isTransparent = true;
                                currentLevel.tileArray[radius.X, radius.Y].isDoor = false;

                                currentLevel.creatures[0].message.Add("You chop the door to pieces");
                            }
                        }
                    }
                    #endregion
                }
            }
            else
            {
                currentLevel.creatures[0].message.Add("You can't think of an obvious use for it at the moment.");
            }
            gameState = GameState.MainGame;
            inventorySelect = 0;
            inventoryMode = 0;
        }