Ejemplo n.º 1
0
        public Creature GenerateCreature(string socialClass, List <Item> itemLibrary, int rngSeed)
        {
            rng = new Random(rngSeed); //Able to generate persistent creatures
            List <BodyPart> thisCreatureAnatomy = new List <BodyPart>();

            foreach (BodyPart b in anatomy)
            {
                thisCreatureAnatomy.Add(new BodyPart(b));
            }
            Creature genCreature;

            if (socialClass == "monster")
            {
                genCreature = new Creature(speed, damage, creatureImage, name, color, anatomy, mass, rng.Next());
            }
            else
            {
                genCreature = new QuestGiver(speed, damage, creatureImage, name, color, anatomy, mass, rng.Next(), itemLibrary);
            }
            genCreature.anatomy = new List <BodyPart>();            //Clear out whatever
            foreach (BodyPart b in thisCreatureAnatomy)
            {
                genCreature.anatomy.Add(new BodyPart(b));
            }

            if (rngDice.Roll(2) == 1)                    //1 in 2 chance
            {
                genCreature.gold = rngDice.Roll(10, 10); //10d10
            }
            genCreature.armorType    = armorType;
            genCreature.wornArmor    = armor;
            genCreature.weapon       = weapon;
            genCreature.strength     = (byte)rng.Next(7, 14); //7-13
            genCreature.dexterity    = (byte)rng.Next(7, 14); //7-13
            genCreature.constitution = (byte)rng.Next(7, 14); //7-13
            genCreature.hpMax        = 10;                    //TODO: Placeholder until calculating from body part health
            genCreature.intelligence = (byte)rng.Next(7, 14); //7-13
            genCreature.wisdom       = (byte)rng.Next(7, 14); //7-13
            genCreature.charisma     = (byte)rng.Next(7, 14); //7-13
            foreach (Item i in this.inventory)
            {
                genCreature.inventory.Add(i);
            }

            thisCreatureAnatomy.Clear();

            return(genCreature);
        }
Ejemplo n.º 2
0
        static void FileS_Level(Level currentLevel)
        {
            string folderPath = "Saves/" + sessionName.ToString(); //Folder name based on seed
            string filePath   = folderPath + "/(" + currentLevel.mapPos.X + ", " + currentLevel.mapPos.Y + ", " +
                                currentLevel.mapPos.Z + ").txt";   //File path

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);          //Create the folder if it doesn't exist
            }
            List <string> data = new List <string>();           //The level data as it will be written to the file.

            data.Add("[TYPE] " + currentLevel.levelType);       //Track the level's type
            data.Add("[SEED] " + currentLevel.seed.ToString()); //Store the base seed

            #region Write tile data
            for (int y = 0; y < Level.GRIDH; y++)
            {
                for (int x = 0; x < Level.GRIDW; x++)
                {
                    Tile currentTile = currentLevel.tileArray[x, y]; //Working with current tile

                    bool creatureHere = false;
                    foreach (Creature c in currentLevel.creatures)
                    {
                        if (c.pos == new Point2D(x, y))
                        {
                            creatureHere = true; //There's a creature at this tile
                        }
                    }
                    if (currentTile.itemList.Count > 0 || currentTile.fixtureLibrary.Count > 0 || creatureHere)
                    {
                        data.Add("(" + x + ", " + y + ")"); //Mark the tile if there's something notable here
                    }

                    foreach (Item i in currentTile.itemList)
                    {
                        #region Write item data
                        if (i is Armor)
                        {
                            data.Add("[ARMOR] " + i.name);
                        }
                        else if (i is Potion)
                        {
                            data.Add("[POTION] " + i.name);
                        }
                        else if (i is Scroll)
                        {
                            data.Add("[SCROLL] " + i.name);
                        }
                        else if (i is Weapon)
                        {
                            data.Add("[WEAPON] " + i.name);
                        }
                        else if (i != null)
                        {
                            data.Add("[ITEM] " + i.name);
                        }
                        #endregion
                    }

                    foreach (Fixture f in currentTile.fixtureLibrary)
                    {
                        #region Save Fixture Data
                        if (f is Door)
                        {
                            Door d = (Door)f;
                            if (d.isOpen)
                            {
                                if (d.isVertical)
                                {
                                    data.Add("[DOOR] open:true");
                                }
                                else
                                {
                                    data.Add("[DOOR] open:false");
                                }
                            }
                            else
                            {
                                if (d.isVertical)
                                {
                                    data.Add("[DOOR] closed:true");
                                }
                                else
                                {
                                    data.Add("[DOOR] closed:false");
                                }
                            }
                        }
                        else if (f is Stairs)
                        {
                            Stairs s = (Stairs)f;
                            if (s.isDown)
                            {
                                data.Add("[STAIRS] down");
                            }
                            else
                            {
                                data.Add("[STAIRS] up");
                            }
                        }
                        else if (f is Tree)
                        {
                            Tree t = (Tree)f;
                            data.Add("[TREE] " + t.species + ":" + t.fruit);
                        }
                        else if (f is Trap)
                        {
                            Trap t = (Trap)f;
                            data.Add("[TRAP] " + t.effect.type);
                        }
                        else if (f is Trap)
                        {
                            data.Add("[FIXTURE] ");
                        }
                        #endregion
                    }

                    foreach (Creature c in currentLevel.creatures)
                    {
                        #region Save Creatures
                        if (c.pos.X == x && c.pos.Y == y)
                        {
                            if (c is QuestGiver)
                            {
                                QuestGiver q = (QuestGiver)c;
                                data.Add("[QUESTGIVER] " + q.name + ":" + q.seed + ":" + q.wantObject + ":" + q.giveObject);

                                foreach (Item i in q.inventory)
                                {
                                    data[data.Count - 1] += ":" + i.name;
                                }

                                if (q.wornArmor.Count > 0)
                                {
                                    data[data.Count - 1] += ":ARMOR";
                                }

                                foreach (Armor a in q.wornArmor)
                                {
                                    data[data.Count - 1] += ":" + a.name;
                                }

                                if (q.weapon != null)
                                {
                                    data[data.Count - 1] += ":WEAPON" + q.weapon.name;
                                }
                            }
                            else if (currentLevel.creatures[0].pos == c.pos) //If it's the player
                            {
                                data.Add("[PLAYER] " + c.name);
                                data[data.Count - 1] += ":" + c.seed;
                                data[data.Count - 1] += ":" + c.hp;
                                data[data.Count - 1] += ":" + c.hpMax;
                                data[data.Count - 1] += ":" + c.xp;
                                data[data.Count - 1] += ":" + c.gold;

                                foreach (Item i in c.inventory)
                                {
                                    data[data.Count - 1] += ":" + i.name;
                                }

                                if (c.wornArmor.Count > 0)
                                {
                                    data[data.Count - 1] += ":ARMOR:";
                                }

                                foreach (Armor a in c.wornArmor)
                                {
                                    data[data.Count - 1] += ":" + a.name;
                                }

                                if (c.weapon != null)
                                {
                                    data[data.Count - 1] += ":WEAPON:" + c.weapon.name;
                                }
                            }
                            else
                            {
                                data.Add("[CREATURE] " + c.name);
                                data[data.Count - 1] += ":" + c.seed; //Store how to generate base creature

                                foreach (Item i in c.inventory)
                                {
                                    data[data.Count - 1] += ":" + i.name;
                                }

                                if (c.wornArmor.Count > 0)
                                {
                                    data[data.Count - 1] += ":ARMOR:";
                                }

                                foreach (Armor a in c.wornArmor)
                                {
                                    data[data.Count - 1] += ":" + a.name;
                                }

                                if (c.weapon != null)
                                {
                                    data[data.Count - 1] += ":WEAPON:" + c.weapon.name;
                                }
                            }
                        }
                        #endregion
                    }
                }
            }
            #endregion

            data.Add("[END]");
            string[] dataArray = data.ToArray();     //Convert to a fixed array for next part.

            File.WriteAllLines(filePath, dataArray); //Write the data
        }
Ejemplo n.º 3
0
 public QuestGiver(QuestGiver c)
     : base(c)
 {
     this.wantObject = c.wantObject;
     this.giveObject = c.giveObject;
 }
Ejemplo n.º 4
0
 public QuestGiver(QuestGiver c)
     : base(c)
 {
     this.wantObject = c.wantObject;
     this.giveObject = c.giveObject;
 }