Ejemplo n.º 1
0
        public void ActorDeserializationFromFile()
        {
            List <ActorTemplate> deserialized = Utils.JsonUtils.JsonDeseralize <List <ActorTemplate> >
                                                    (Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Entities", "Actors", "Humanoids.json"));
            Actor found = EntityFactory.ActorCreator(Point.None, deserialized.FirstOrDefault(i => i.Id == "test_troll"));

            Assert.Equal(found.Name, deserialized.FirstOrDefault(i => i.Id == "test_troll").Name);
        }
Ejemplo n.º 2
0
        // Create some random monsters with random attack and defense values
        // and drop them all over the map in
        // random places.
        private void CreateMonster()
        {
            // number of monsters to create
            int numMonster = 10;

            // Create several monsters and
            // pick a random position on the map to place them.
            // check if the placement spot is blocking (e.g. a wall)
            // and if it is, try a new position
            for (int i = 0; i < numMonster; i++)
            {
                int monsterPosition = 0;
                while (CurrentMap.Tiles[monsterPosition].IsBlockingMove)
                {
                    // pick a random spot on the map
                    monsterPosition = rndNum.Next(0, CurrentMap.Width * CurrentMap.Height);
                }

                // Set the monster's new position
                // Note: this fancy math will be replaced by a new helper method
                // in the next revision of SadConsole
                var pos = new Point(monsterPosition % CurrentMap.Width, monsterPosition / CurrentMap.Height);

                Stat monsterStat = new Stat()
                {
                    Defense       = rndNum.Next(0, 10),
                    DefenseChance = rndNum.Next(0, 50),
                    Attack        = rndNum.Next(0, 10),
                    AttackChance  = rndNum.Next(0, 50),
                    Speed         = 1,
                    ViewRadius    = 7,
                    Health        = 10,
                    MaxHealth     = 10
                };

                // Need to refactor this so that it's simpler to create a monster, propably gonna use the example
                // of moving castle to make a static class containing blueprints on how to create the actors and items.
                Anatomy monsterAnatomy = new Anatomy();
                monsterAnatomy.SetRace(new Race("Debug Race"));

                Actor debugMonster = EntityFactory.ActorCreator(
                    pos,
                    new ActorTemplate("Debug Monster", Color.Blue, Color.Transparent, 'M',
                                      (int)MapLayer.ACTORS, monsterStat, monsterAnatomy, "DebugTest", 150, 60, "flesh"));

                debugMonster.AddComponent(new MoveAndAttackAI(debugMonster.Stats.ViewRadius));
                debugMonster.Inventory.Add(EntityFactory.ItemCreator(debugMonster.Position,
                                                                     new ItemTemplate("Debug Remains", Color.Red, Color.Black, '%', 1.5f, 35, "DebugRotten")));
                debugMonster.Anatomy.Limbs = LimbTemplate.BasicHumanoidBody(debugMonster);

                CurrentMap.Add(debugMonster);
            }
        }