コード例 #1
0
ファイル: Creature.cs プロジェクト: Kalasen/Adventurer
        public void CloseDoor(Tile tile, Level currentLevel)
        {
            Door door = (Door)tile.fixtureLibrary[0];

            door.Close(tile, currentLevel);
        }
コード例 #2
0
        static void FileL_Level(Point3D pos)
        {
            #region Setup
            string levelPath = "Saves/" + sessionName.ToString() + "/(" + pos.X.ToString() + ", " + pos.Y.ToString() + ", " +
                               pos.Z.ToString() + ").txt"; //The path to the level
            Point2D tilePos = new Point2D();               //The tile position we're working with

            if (!File.Exists(levelPath))
            {
                GenLevel("Dungeon", false); //Fabricate one
                return;
            }
            #endregion

            #region Gen base level
            using (StreamReader read = new StreamReader(levelPath))
            {
                string line = read.ReadLine();                    //First entry should be the level type
                line = line.Remove(0, 7);                         //Clip off "[TYPE] "
                string levelType = line;                          // example: "Dungeon"

                line = read.ReadLine();                           //Next is the seed
                line = line.Remove(0, 7);                         //Clip off "[SEED] "

                levelSeed[pos.X, pos.Y, pos.Z] = int.Parse(line); //Fix the seed to its original

                GenLevel(levelType, false);                       //Recreate the originally genned level
                Creature tempCreature = new Creature(CurrentLevel.creatures[0]);
                CurrentLevel.creatures.Clear();                   //We'll fill this in from the load file
                for (int y = 0; y < Level.GRIDH; y++)
                {
                    for (int x = 0; x < Level.GRIDW; x++)                                    //For all tiles
                    {
                        CurrentLevel.tileArray[x, y].scentIdentifier.Add(tempCreature.name); //Keep track of this creature's scent now
                        CurrentLevel.tileArray[x, y].scentMagnitude.Add(0);                  //Start it at zero scent in the room
                        CurrentLevel.tileArray[x, y].itemList.Clear();                       //Clear out previous items
                        if (!CurrentLevel.tileArray[x, y].isPassable && CurrentLevel.tileArray[x, y].fixtureLibrary.Count > 0)
                        {
                            CurrentLevel.tileArray[x, y].isTransparent = true; //Remove influence of fixtures
                            CurrentLevel.tileArray[x, y].isPassable    = true;
                        }
                        CurrentLevel.tileArray[x, y].fixtureLibrary.Clear();
                    }
                }
                //currentLevel.creatureList.Add(tempCreature);
                #endregion

                line = read.ReadLine();
                while (line != "[END]")
                {
                    #region Work on individual tiles
                    if (line.StartsWith("(")) //If it's a tile position
                    {
                        #region Base Tile Data
                        string[] piece = line.Split(',');                                    //Split apart based on commas

                        piece[0]  = piece[0].Remove(0, 1);                                   //Remove "("
                        piece[1]  = piece[1].Substring(0, piece[1].Length - 1);              //Remove ")"
                        tilePos.X = short.Parse(piece[0]);                                   //Get the X digit
                        tilePos.Y = short.Parse(piece[1]);                                   //Get the Y digit
                        CurrentLevel.tileArray[tilePos.X, tilePos.Y].itemList.Clear();       //Empty the random gen items.
                        CurrentLevel.tileArray[tilePos.X, tilePos.Y].fixtureLibrary.Clear(); //Empty the random gen items.
                        #endregion
                    }
                    else if (line.StartsWith("[ARMOR]") || line.StartsWith("[ITEM]") || line.StartsWith("[POTION]") || line.StartsWith("[SCROLL]") ||
                             line.StartsWith("[WEAPON]")) //If an item of some sort
                    {
                        #region Item Data
                        string[] piece = line.Split(']'); //Split based on ]
                        piece[0] = piece[0].Remove(0, 1);
                        piece[1] = piece[1].Remove(0, 1);

                        if (piece[1] == "pinecone") //TODO: Bluh hackish improve later
                        {
                            CurrentLevel.tileArray[tilePos.X, tilePos.Y].itemList.Add(new Item(content.items.Find(item => item.name == "pinecone")));
                        }
                        else
                        {
                            foreach (Species c in content.bestiary)       //For gore
                            {
                                if (piece[1].StartsWith(c.name))          //If it's a creature part
                                {
                                    string[] split = piece[1].Split(' '); //Get creature name and part name

                                    Item gore;
                                    if (split[1] == "corpse")
                                    {
                                        gore = new Item(500f, 500f, $"{c.name} corpse", c.color, new List <Item>(), new List <string>());
                                    }
                                    else
                                    {
                                        gore = new Item(500f, 500f, $"{c.name} corpse", Color.Crimson, new List <Item>(), new List <string>());
                                    }
                                    gore.itemImage = 253; //"²"
                                    gore.edible    = true;
                                    CurrentLevel.tileArray[tilePos.X, tilePos.Y].itemList.Add(gore);
                                    break;
                                }
                            }

                            foreach (Item i in content.items)
                            {
                                if (i.name == piece[1])
                                {
                                    CurrentLevel.tileArray[tilePos.X, tilePos.Y].itemList.Add(i);
                                    break;
                                }
                            }
                        }
                        #endregion
                    }
                    else if (line.StartsWith("[CREATURE]") || line.StartsWith("[QUESTGIVER]") || line.StartsWith("[PLAYER]"))
                    {
                        #region Creature Data
                        bool isPlayer      = false;
                        int  creatureIndex = 0;

                        if (line.StartsWith("[CREATURE]"))
                        {
                            line = line.Remove(0, 11); // Clip off the "[CREATURE] " part
                        }
                        else if (line.StartsWith("[QUESTGIVER]"))
                        {
                            line = line.Remove(0, 13); // Clip off the "[QUESTGIVER] " part
                        }
                        else if (line.StartsWith("[PLAYER]"))
                        {
                            isPlayer = true;
                            line     = line.Remove(0, 9); //Clip off the "[PLAYER] " part
                        }

                        string[] piece = line.Split(':');       //Split it by ':'

                        foreach (Species c in content.bestiary) //Look for the creature to add
                        {
                            if (piece[0] == c.name)             //If the name matches the type of creature generator
                            {
                                if (isPlayer)
                                {
                                    Creature p = c.GenerateCreature("monster", content.items, int.Parse(piece[1]));
                                    p.hp    = int.Parse(piece[2]);
                                    p.hpMax = int.Parse(piece[3]);
                                    p.xp    = int.Parse(piece[4]);
                                    p.gold  = int.Parse(piece[5]);
                                    while (p.xp > p.xpBorder * 2)
                                    {
                                        p.xpBorder *= 2;
                                    }
                                    p.inventory.Clear();
                                    p.wornArmor.Clear();
                                    p.weapon      = null;
                                    p.pos         = tilePos;
                                    creatureIndex = 0;

                                    for (int y = 0; y < Level.GRIDH; y++)
                                    {
                                        for (int x = 0; x < Level.GRIDW; x++)
                                        {
                                            CurrentLevel.tileArray[x, y].scentIdentifier.Add(p.name); //Keep track of this creature's scent now
                                            CurrentLevel.tileArray[x, y].scentMagnitude.Add(0);       //Start it at zero scent in the room
                                        }
                                    }

                                    CurrentLevel.creatures.Insert(0, p); //Insert player at spot 0
                                }
                                else
                                {
                                    creatureIndex = CurrentLevel.creatures.Count;

                                    if (CurrentLevel.levelType == "village")
                                    {
                                        Creature p = c.GenerateCreature("quest giver", content.items, int.Parse(piece[1]));
                                        p.inventory.Clear();
                                        p.wornArmor.Clear();
                                        p.weapon = null;
                                        CurrentLevel.SpawnCreature(p, tilePos);
                                    }
                                    else
                                    {
                                        Creature p = c.GenerateCreature("monster", content.items, int.Parse(piece[1]));
                                        p.inventory.Clear();
                                        p.wornArmor.Clear();
                                        p.weapon = null;
                                        CurrentLevel.SpawnCreature(p, tilePos);
                                    }
                                }
                            }
                        }

                        for (int a = 2; a < piece.Length; a++) //Look for items in the inventory to add
                        {
                            if (piece[a] == "pinecone")        //Bluh hackish improve later
                            {
                                CurrentLevel.creatures[creatureIndex].inventory.Add(new Item(content.items.Find(item => item.name == "pinecone")));
                            }

                            foreach (Species c in content.bestiary)       //For gore
                            {
                                if (piece[a].StartsWith(c.name))          //If it's a creature part
                                {
                                    string[] split = piece[a].Split(' '); //Get creature name and part name
                                    Item     gore;
                                    if (split[1] == "corpse")
                                    {
                                        gore = new Item(500f, 500f, $"{c.name} corpse", c.color, new List <Item>(), new List <string>());
                                    }
                                    else
                                    {
                                        gore = new Item(500f, 500f, $"{c.name} corpse", Color.Crimson, new List <Item>(), new List <string>());
                                    }

                                    gore.itemImage = 253;
                                    gore.edible    = true;
                                    CurrentLevel.creatures[creatureIndex].inventory.Add(gore);
                                    break;
                                }
                            }

                            foreach (Item i in content.items)
                            {
                                if (i.name == piece[a])
                                {
                                    CurrentLevel.creatures[creatureIndex].inventory.Add(i);
                                }
                            }
                        }
                        #endregion
                    }
                    else if (line.StartsWith("[TRAP]"))
                    {
                        #region Trap Data
                        line = line.Remove(0, 7);                                                                                    //Remove the "[TRAP] " part
                        CurrentLevel.tileArray[tilePos.X, tilePos.Y].fixtureLibrary.Add(new Trap(new Effect(rngDie.Roll(5), line))); //Add trap
                        #endregion
                    }
                    else if (line.StartsWith("[TREE]"))
                    {
                        #region Tree Data
                        line = line.Remove(0, 7); //Remove the "[TREE] " part
                        string[] piece    = line.Split(':');
                        Tree     thisTree = new Tree(rng);
                        thisTree.species = piece[0];
                        thisTree.fruit   = piece[1];

                        CurrentLevel.tileArray[tilePos.X, tilePos.Y].isPassable    = false;        //Fix for tree
                        CurrentLevel.tileArray[tilePos.X, tilePos.Y].isTransparent = false;        //Fix for tree
                        CurrentLevel.tileArray[tilePos.X, tilePos.Y].fixtureLibrary.Add(thisTree); //Add tree
                        #endregion
                    }
                    else if (line.StartsWith("[DOOR]"))
                    {
                        #region Door Data
                        line = line.Remove(0, 7);
                        string[] dataSplit = line.Split(':');
                        Tile     thisTile  = CurrentLevel.tileArray[tilePos.X, tilePos.Y];
                        Door     thisDoor  = new Door(thisTile, bool.Parse(dataSplit[1]));
                        thisTile.fixtureLibrary.Add(thisDoor);

                        if (dataSplit[0] == "open")
                        {
                            thisDoor.Open(thisTile, CurrentLevel); //Open the door from default closed
                        }
                        else
                        {
                            thisDoor.Close(thisTile, CurrentLevel);
                        }
                        #endregion
                    }
                    else if (line.StartsWith("[STAIRS]"))
                    {
                        #region Stairs Data
                        line = line.Remove(0, 9);
                        if (line == "down")
                        {
                            CurrentLevel.tileArray[tilePos.X, tilePos.Y].fixtureLibrary.Add(new Stairs(true));
                        }
                        else
                        {
                            CurrentLevel.tileArray[tilePos.X, tilePos.Y].fixtureLibrary.Add(new Stairs(false));
                        }
                        #endregion
                    }
                    #endregion

                    line = read.ReadLine();
                }
            }
            //read.Dispose();
            //read.Close(); //Close this now that we're done with it
        } //PCLoadLevel
コード例 #3
0
ファイル: Adventurer_Load.cs プロジェクト: Kalasen/Adventurer
        static void FileL_Level(Vector3 pos)
        {
            #region Setup
            string levelPath = "Saves/" + sessionName.ToString() + "/(" + pos.X.ToString() + ", " + pos.Y.ToString() + ", " +
                pos.Z.ToString() + ").txt"; //The path to the level
            Vector2 tilePos = new Vector2(); //The tile position we're working with

            if (!File.Exists(levelPath))
            {
                GenLevel("Dungeon", false); //Fabricate one
                return;
            }
            #endregion

            #region Gen base level
            using (StreamReader read = new StreamReader(levelPath))
            {
                string line = read.ReadLine(); //First entry should be the level type
                line = line.Remove(0, 7); //Clip off "[TYPE] "
                string levelType = line; // example: "Dungeon"

                line = read.ReadLine(); //Next is the seed
                line = line.Remove(0, 7); //Clip off "[SEED] "

                levelSeed[pos.X, pos.Y, pos.Z] = int.Parse(line); //Fix the seed to its original

                GenLevel(levelType, false); //Recreate the originally genned level
                Creature tempCreature = new Creature(currentLevel.creatures[0]);
                currentLevel.creatures.Clear(); //We'll fill this in from the load file
                for (int y = 0; y < Level.GRIDH; y++)
                    for (int x = 0; x < Level.GRIDW; x++) //For all tiles
                    {
                        currentLevel.tileArray[x, y].scentIdentifier.Add(tempCreature.name); //Keep track of this creature's scent now
                        currentLevel.tileArray[x, y].scentMagnitude.Add(0); //Start it at zero scent in the room
                        currentLevel.tileArray[x, y].itemList.Clear(); //Clear out previous items
                        if (!currentLevel.tileArray[x, y].isPassable && currentLevel.tileArray[x, y].fixtureLibrary.Count > 0)
                        {
                            currentLevel.tileArray[x, y].isTransparent = true; //Remove influence of fixtures
                            currentLevel.tileArray[x, y].isPassable = true;
                        }
                        currentLevel.tileArray[x, y].fixtureLibrary.Clear();
                    }
                //currentLevel.creatureList.Add(tempCreature);
            #endregion

                line = read.ReadLine();
                while (line != "[END]")
                {
                    #region Work on individual tiles
                    if (line.StartsWith("(")) //If it's a tile position
                    {
                        #region Base Tile Data
                        string[] piece = line.Split(','); //Split apart based on commas

                        piece[0] = piece[0].Remove(0, 1); //Remove "("
                        piece[1] = piece[1].Substring(0, piece[1].Length - 1); //Remove ")"
                        tilePos.X = short.Parse(piece[0]); //Get the X digit
                        tilePos.Y = short.Parse(piece[1]); //Get the Y digit
                        currentLevel.tileArray[tilePos.X, tilePos.Y].itemList.Clear(); //Empty the random gen items.
                        currentLevel.tileArray[tilePos.X, tilePos.Y].fixtureLibrary.Clear(); //Empty the random gen items.
                        #endregion
                    }
                    else if (line.StartsWith("[ARMOR]") || line.StartsWith("[ITEM]") || line.StartsWith("[POTION]") || line.StartsWith("[SCROLL]")
                        || line.StartsWith("[WEAPON]")) //If an item of some sort
                    {
                        #region Item Data
                        string[] piece = line.Split(']'); //Split based on ]
                        piece[0] = piece[0].Remove(0, 1);
                        piece[1] = piece[1].Remove(0, 1);

                        if (piece[1] == "pinecone") //TODO: Bluh hackish improve later
                        {
                            currentLevel.tileArray[tilePos.X, tilePos.Y].itemList.Add(new Item(content.items.Find(item => item.name == "pinecone")));
                        }
                        else
                        {
                            foreach (Species c in content.bestiary) //For gore
                            {
                                if (piece[1].StartsWith(c.name)) //If it's a creature part
                                {
                                    string[] split = piece[1].Split(' '); //Get creature name and part name

                                    Item gore;
                                    if (split[1] == "corpse")
                                        gore = new Item(500f, 500f, $"{c.name} corpse", c.color, new List<Item>(), new List<string>());
                                    else
                                        gore = new Item(500f, 500f, $"{c.name} corpse", Color.Crimson, new List<Item>(), new List<string>());
                                    gore.itemImage = 253; //"²"
                                    gore.edible = true;
                                    currentLevel.tileArray[tilePos.X, tilePos.Y].itemList.Add(gore);
                                    break;
                                }
                            }

                            foreach (Item i in content.items)
                            {
                                if (i.name == piece[1])
                                {
                                    currentLevel.tileArray[tilePos.X, tilePos.Y].itemList.Add(i);
                                    break;
                                }
                            }
                        }
                        #endregion
                    }
                    else if (line.StartsWith("[CREATURE]") || line.StartsWith("[QUESTGIVER]") || line.StartsWith("[PLAYER]"))
                    {
                        #region Creature Data
                        bool isPlayer = false;
                        int creatureIndex = 0;

                        if (line.StartsWith("[CREATURE]"))
                            line = line.Remove(0, 11); // Clip off the "[CREATURE] " part
                        else if (line.StartsWith("[QUESTGIVER]"))
                            line = line.Remove(0, 13); // Clip off the "[QUESTGIVER] " part
                        else if (line.StartsWith("[PLAYER]"))
                        {
                            isPlayer = true;
                            line = line.Remove(0, 9); //Clip off the "[PLAYER] " part
                        }

                        string[] piece = line.Split(':'); //Split it by ':'

                        foreach (Species c in content.bestiary) //Look for the creature to add
                        {
                            if (piece[0] == c.name) //If the name matches the type of creature generator
                            {
                                if (isPlayer)
                                {
                                    Creature p = c.GenerateCreature("monster", content.items, int.Parse(piece[1]));
                                    p.hp = int.Parse(piece[2]);
                                    p.hpMax = int.Parse(piece[3]);
                                    p.xp = int.Parse(piece[4]);
                                    p.gold = int.Parse(piece[5]);
                                    while (p.xp > p.xpBorder*2)
                                        p.xpBorder *= 2;
                                    p.inventory.Clear();
                                    p.wornArmor.Clear();
                                    p.weapon = null;
                                    p.pos = tilePos;
                                    creatureIndex = 0;

                                    for (int y = 0; y < Level.GRIDH; y++)
                                        for (int x = 0; x < Level.GRIDW; x++)
                                        {
                                            currentLevel.tileArray[x, y].scentIdentifier.Add(p.name); //Keep track of this creature's scent now
                                            currentLevel.tileArray[x, y].scentMagnitude.Add(0); //Start it at zero scent in the room
                                        }

                                    currentLevel.creatures.Insert(0, p); //Insert player at spot 0
                                }
                                else
                                {
                                    creatureIndex = currentLevel.creatures.Count;

                                    if (currentLevel.levelType == "village")
                                    {
                                        Creature p = c.GenerateCreature("quest giver", content.items, int.Parse(piece[1]));
                                        p.inventory.Clear();
                                        p.wornArmor.Clear();
                                        p.weapon = null;
                                        currentLevel.SpawnCreature(p, tilePos);
                                    }
                                    else
                                    {
                                        Creature p = c.GenerateCreature("monster", content.items, int.Parse(piece[1]));
                                        p.inventory.Clear();
                                        p.wornArmor.Clear();
                                        p.weapon = null;
                                        currentLevel.SpawnCreature(p, tilePos);
                                    }
                                }
                            }
                        }

                        for (int a = 2; a < piece.Length; a++) //Look for items in the inventory to add
                        {
                            if (piece[a] == "pinecone") //Bluh hackish improve later
                            {
                                currentLevel.creatures[creatureIndex].inventory.Add(new Item(content.items.Find(item => item.name == "pinecone")));
                            }

                            foreach (Species c in content.bestiary) //For gore
                            {
                                if (piece[a].StartsWith(c.name)) //If it's a creature part
                                {
                                    string[] split = piece[a].Split(' '); //Get creature name and part name
                                    Item gore;
                                    if (split[1] == "corpse")
                                        gore = new Item(500f, 500f, $"{c.name} corpse", c.color, new List<Item>(), new List<string>());
                                    else
                                        gore = new Item(500f, 500f, $"{c.name} corpse", Color.Crimson, new List<Item>(), new List<string>());

                                    gore.itemImage = 253;
                                    gore.edible = true;
                                    currentLevel.creatures[creatureIndex].inventory.Add(gore);
                                    break;
                                }
                            }

                            foreach (Item i in content.items)
                            {
                                if (i.name == piece[a])
                                {
                                    currentLevel.creatures[creatureIndex].inventory.Add(i);
                                }
                            }
                        }
                        #endregion
                    }
                    else if (line.StartsWith("[TRAP]"))
                    {
                        #region Trap Data
                        line = line.Remove(0, 7); //Remove the "[TRAP] " part
                        currentLevel.tileArray[tilePos.X, tilePos.Y].fixtureLibrary.Add(new Trap(new Effect(rngDie.Roll(5), line))); //Add trap
                        #endregion
                    }
                    else if (line.StartsWith("[TREE]"))
                    {
                        #region Tree Data
                        line = line.Remove(0, 7); //Remove the "[TREE] " part
                        string[] piece = line.Split(':');
                        Tree thisTree = new Tree(rng);
                        thisTree.species = piece[0];
                        thisTree.fruit = piece[1];

                        currentLevel.tileArray[tilePos.X, tilePos.Y].isPassable = false; //Fix for tree
                        currentLevel.tileArray[tilePos.X, tilePos.Y].isTransparent = false; //Fix for tree
                        currentLevel.tileArray[tilePos.X, tilePos.Y].fixtureLibrary.Add(thisTree); //Add tree
                        #endregion
                    }
                    else if (line.StartsWith("[DOOR]"))
                    {
                        #region Door Data
                        line = line.Remove(0, 7);
                        string[] dataSplit = line.Split(':');
                        Tile thisTile = currentLevel.tileArray[tilePos.X, tilePos.Y];
                        Door thisDoor = new Door(thisTile, bool.Parse(dataSplit[1]));
                        thisTile.fixtureLibrary.Add(thisDoor);

                        if (dataSplit[0] == "open")
                        {
                            thisDoor.Open(thisTile, currentLevel); //Open the door from default closed
                        }
                        else
                        {
                            thisDoor.Close(thisTile, currentLevel);
                        }
                        #endregion
                    }
                    else if (line.StartsWith("[STAIRS]"))
                    {
                        #region Stairs Data
                        line = line.Remove(0, 9);
                        if (line == "down")
                            currentLevel.tileArray[tilePos.X, tilePos.Y].fixtureLibrary.Add(new Stairs(true));
                        else
                            currentLevel.tileArray[tilePos.X, tilePos.Y].fixtureLibrary.Add(new Stairs(false));
                        #endregion
                    }
                    #endregion

                    line = read.ReadLine();
                }
            }
            //read.Dispose();
            //read.Close(); //Close this now that we're done with it
        }