Exemple #1
0
        public void Get_all_from_room()
        {
            var apple = new GameLogic.Item.Item();

            apple.Name        = "apple";
            apple.Description = new Description()
            {
                Room = "apple"
            };

            var room = new Room();

            room.Items.Add(apple);

            var player = new Player();

            player.ConnectionId = "1";
            player.Name         = "Gary";
            player.Inventory    = new ItemList();

            var objects = new GameLogic.Commands.Objects.Object(_IWriteToClient.Object, _IUpdateUI.Object, _IMobScripts.Object);

            objects.Get("all", "", room, player, "get all");


            Assert.True(room.Items.FirstOrDefault(x => x.Name == "apple") == null);
        }
Exemple #2
0
        public void Returns_correct_item_count()
        {
            var apple = new GameLogic.Item.Item();

            apple.Name        = "apple";
            apple.Description = new Description()
            {
                Room = "apple"
            };

            var sword = new GameLogic.Item.Item();

            sword.Name        = "sword";
            sword.Description = new Description()
            {
                Room = "sword"
            };

            this.items.Add(apple);
            this.items.Add(sword);
            this.items.Add(sword);

            var expected = new List <string> {
                "apple", "(2) sword"
            };

            Assert.Equal(items.List(), expected);
        }
Exemple #3
0
        public void show_error_if_char_not_found_to_give()
        {
            var apple = new GameLogic.Item.Item();

            apple.Name        = "apple";
            apple.Description = new Description()
            {
                Room = "apple"
            };

            var room = new Room();

            var player = new Player();

            player.ConnectionId = "1";
            player.Name         = "Gary";
            player.Inventory    = new ItemList();
            player.Inventory.Add(apple);

            var mob = new Player();

            mob.ConnectionId = "mob";
            mob.Name         = "Mob";
            mob.Inventory    = new ItemList();

            room.Players.Add(player);
            room.Players.Add(mob);

            var objects = new GameLogic.Commands.Objects.Object(_IWriteToClient.Object, _IUpdateUI.Object, _IMobScripts.Object);

            objects.Give("apple", "max", room, player, "");

            _IWriteToClient.Verify(w => w.WriteLine(It.Is <string>(s => s.Contains("They aren't here.")), "1"), Times.Once());
        }
Exemple #4
0
        public void Should_close_opened_Container()
        {
            var item = new GameLogic.Item.Item
            {
                Name        = "Chest",
                Description = new Description(),

                ItemType  = GameLogic.Item.Item.ItemTypes.Container,
                Container = new Container()
                {
                    CanOpen = true, IsOpen = true, Items = new ItemList()
                },
            };

            var room = new Room();

            room.Items.Add(item);

            var player = new Player();

            player.ConnectionId = "1";
            player.Name         = "Gary";
            player.Inventory    = new ItemList();


            var objects = new GameLogic.Commands.Objects.Object(_IWriteToClient.Object, _IUpdateUI.Object, _IMobScripts.Object);

            objects.Close("chest", room, player);

            _IWriteToClient.Verify(w => w.WriteLine(It.Is <string>(s => s.Contains("You close")), "1"), Times.Once());
            Assert.True(!item.Container.IsOpen);
        }
Exemple #5
0
        public void Add_Gold_to_player()
        {
            var item = new GameLogic.Item.Item
            {
                Name        = "gold",
                Description = new Description()
                {
                    Room = "gold"
                },
                Value    = 5,
                ItemType = GameLogic.Item.Item.ItemTypes.Money
            };

            var room = new Room();

            room.Items.Add(item);

            var player = new Player();

            player.ConnectionId = "1";
            player.Name         = "Gary";
            player.Inventory    = new ItemList();
            player.Money        = new GameLogic.Character.Model.Money();

            var objects = new GameLogic.Commands.Objects.Object(_IWriteToClient.Object, _IUpdateUI.Object, _IMobScripts.Object);

            objects.Get("gold", "", room, player, "get gold");


            Assert.True(player.Money.Gold.Equals(5));
        }
Exemple #6
0
        public void Sell_to_shop()
        {
            var item = new GameLogic.Item.Item()
            {
                Name     = "Sword",
                Value    = 10,
                ItemType = GameLogic.Item.Item.ItemTypes.Weapon
            };

            var itemB = new GameLogic.Item.Item()
            {
                Name     = "Axe",
                Value    = 10,
                ItemType = GameLogic.Item.Item.ItemTypes.Weapon
            };
            var shopkeeper = new Player
            {
                ConnectionId = "1",
                Name         = "Gary",
                Inventory    = new ItemList(),
                Shopkeeper   = true
            };

            shopkeeper.Inventory.Add(itemB);


            var player = new Player
            {
                ConnectionId = "1",
                Name         = "Player",
                Inventory    = new ItemList(),
                Shopkeeper   = false,
                Money        = new GameLogic.Character.Model.Money()
                {
                    Gold = 10
                }
            };

            player.Inventory.Add(item);

            var room = new Room();

            room.Mobs.Add(shopkeeper);
            room.Players.Add(player);


            var shop = new Shop(_IWriteToClient.Object, _IUpdateUI.Object, _passiveSkills.Object);

            shop.SellItem("sword", room, player);

            Assert.True(player.Inventory.FirstOrDefault(x => x.Name.Equals("Sword")) == null);
            Assert.True(player.Money.Gold == 15);

            _IWriteToClient.Verify(w => w.WriteLine(It.Is <string>(s => s.Contains("You sell sword for 5 gold.")), "1"), Times.Once());
        }
Exemple #7
0
        public void Should_return_view_of_next_room_from_portal()
        {
            _player      = new Player();
            _player.Name = "Liam";
            _player.Config.VerboseExits = false;
            _player.ConnectionId        = "1";


            var item = new GameLogic.Item.Item()
            {
                Name     = "A portal",
                ItemType = GameLogic.Item.Item.ItemTypes.Portal,
                Portal   = new Portal()
                {
                    Destination = "0000"
                }
            };
            var currentRoom = new GameLogic.World.Room.Room()
            {
                Items = new ItemList()
                {
                    item
                },
                AreaId = 1,
                Coords =
                {
                    X = 1,
                    Y = 0,
                    Z = 0
                },
                Players = new List <Player>()
                {
                    _player
                }
            };



            _room = new GameLogic.World.Room.Room()
            {
                Description = "Room description",
                AreaId      = 0,
                Coords      =
                {
                    X = 0,
                    Y = 0,
                    Z = 0
                }
            };

            _cache.Setup(x => x.GetRoom("0000")).Returns(_room);
            new RoomActions(_writer.Object, _time.Object, _cache.Object).LookInPortal(item, currentRoom, _player);

            _writer.Verify(w => w.WriteLine(It.Is <string>(s => s.Contains("Room description")), "1"), Times.Once());
        }
        public void Returns_list_of_recipes()
        {
            var item = new GameLogic.Item.Item()
            {
                Name     = "Wood",
                ItemType = GameLogic.Item.Item.ItemTypes.Material,
            };

            var player = new Player()
            {
                ConnectionId = "1",
                Name         = "Malleus",
                Status       = CharacterStatus.Status.Standing,
                Inventory    = new ItemList()
                {
                    item, item
                }
            };

            var recipe = new CraftingRecipes()
            {
                Description       = "",
                Title             = "Wooden sword",
                CraftingMaterials = new List <CraftingMaterials>()
                {
                    new CraftingMaterials()
                    {
                        Quantity = 2,
                        Material = "Wood"
                    }
                }
            };

            var listOfRecipes = new List <CraftingRecipes>();

            listOfRecipes.Add(recipe);
            _cache.Setup(x => x.GetCraftingRecipes()).Returns(listOfRecipes);

            new GameLogic.Crafting.Crafting(_writer.Object, _cache.Object, _gain.Object, _updateClientUi.Object, _skills.Object).ListCrafts(player);

            var sb = new StringBuilder();

            sb.Append("<p>You can craft the following items:</p>");
            sb.Append("<table class='simple'>");
            sb.Append($"<tr><td>Name</td><td>Materials</td></tr>");
            sb.Append($"<tr><td>Wooden sword</td><td>Wood x2, </td></tr>");
            sb.Append($"</table>");
            _writer.Verify(w => w.WriteLine(It.Is <string>(s => s.Contains(sb.ToString())), "1"), Times.Once());
        }
Exemple #9
0
        public void Buy_from_shop()
        {
            var item = new GameLogic.Item.Item()
            {
                Name  = "Sword",
                Value = 10
            };
            var shopkeeper = new Player
            {
                ConnectionId = "1",
                Name         = "Gary",
                Inventory    = new ItemList(),
                Shopkeeper   = true
            };

            shopkeeper.Inventory.Add(item);

            var player = new Player
            {
                ConnectionId = "1",
                Name         = "Player",
                Inventory    = new ItemList(),
                Shopkeeper   = false,
                Money        = new GameLogic.Character.Model.Money()
                {
                    Gold = 20
                }
            };

            var room = new Room();

            room.Mobs.Add(shopkeeper);
            room.Players.Add(player);


            var shop = new Shop(_IWriteToClient.Object, _IUpdateUI.Object);

            shop.BuyItem("sword", room, player);

            Assert.True(player.Inventory.FirstOrDefault(x => x.Name.Equals("Sword")) != null);
            Assert.True(player.Money.Gold < 20);

            _IWriteToClient.Verify(w => w.WriteLine(It.Is <string>(s => s.Contains("You buy sword for 15 gold.")), "1"), Times.Once());
        }
        public void Returns_error_if_not_enough_quantity_of_materials()
        {
            var item = new GameLogic.Item.Item()
            {
                Name     = "Wood",
                ItemType = GameLogic.Item.Item.ItemTypes.Material,
            };

            var player = new Player()
            {
                ConnectionId = "1",
                Name         = "Malleus",
                Status       = CharacterStatus.Status.Standing,
                Inventory    = new ItemList()
                {
                    item
                }
            };

            var recipe = new CraftingRecipes()
            {
                Description       = "",
                Title             = "Wooden sword",
                CraftingMaterials = new List <CraftingMaterials>()
                {
                    new CraftingMaterials()
                    {
                        Quantity = 2,
                        Material = "Wood"
                    }
                }
            };

            var listOfRecipes = new List <CraftingRecipes>();

            listOfRecipes.Add(recipe);
            _cache.Setup(x => x.GetCraftingRecipes()).Returns(listOfRecipes);

            new GameLogic.Crafting.Crafting(_writer.Object, _cache.Object, _gain.Object, _updateClientUi.Object, _skills.Object).ListCrafts(player);

            _writer.Verify(w => w.WriteLine(It.Is <string>(s => s.Contains("<p>No crafting recipes found with the current materials you have.</p>")), "1"), Times.Once());
        }
Exemple #11
0
        public void Get_item_container_weight_of_item_should_not_be_that_of_the_container()
        {
            var apple = new GameLogic.Item.Item();

            apple.Name        = "apple";
            apple.Description = new Description()
            {
                Room = "apple"
            };
            apple.Weight = 0.5F;

            var chest = new GameLogic.Item.Item
            {
                Name      = "chest",
                Container = new Container()
                {
                    Items = new ItemList {
                        apple
                    }, IsOpen = true
                },
                Weight = 5
            };

            var room = new Room();

            room.Items.Add(chest);

            var player = new Player();

            player.ConnectionId = "1";
            player.Name         = "Gary";
            player.Inventory    = new ItemList();

            var objects = new GameLogic.Commands.Objects.Object(_IWriteToClient.Object, _IUpdateUI.Object, _IMobScripts.Object);

            objects.Get("apple", "chest", room, player, "get apple chest");


            Assert.True(player.Inventory.FirstOrDefault(x => x.Name == "apple").Weight == 0.5);
        }
Exemple #12
0
        public void Get_item_container()
        {
            var apple = new GameLogic.Item.Item();

            apple.Name        = "apple";
            apple.Description = new Description()
            {
                Room = "apple"
            };

            var chest = new GameLogic.Item.Item
            {
                Name      = "chest",
                Container = new Container()
                {
                    Items = new ItemList {
                        apple
                    }, IsOpen = true
                }
            };

            var room = new Room();

            room.Items.Add(chest);

            var player = new Player();

            player.ConnectionId = "1";
            player.Name         = "Gary";
            player.Inventory    = new ItemList();

            var objects = new GameLogic.Commands.Objects.Object(_IWriteToClient.Object, _IUpdateUI.Object);

            objects.Get("apple", "chest", room, player);


            Assert.True(chest.Container.Items.FirstOrDefault(x => x.Name == "apple") == null);
        }
Exemple #13
0
        public void Display_Inventory()
        {
            var item = new GameLogic.Item.Item()
            {
                Name = "Sword",
            };
            var shopkeeper = new Player
            {
                ConnectionId = "1",
                Name         = "Gary",
                Inventory    = new ItemList(),
                Shopkeeper   = true
            };

            shopkeeper.Inventory.Add(item);

            var player = new Player
            {
                ConnectionId = "1",
                Name         = "Player",
                Inventory    = new ItemList(),
                Shopkeeper   = false
            };

            var room = new Room();

            room.Mobs.Add(shopkeeper);


            var shop = new Shop(_IWriteToClient.Object, _IUpdateUI.Object, _passiveSkills.Object);

            shop.DisplayInventory(shopkeeper, player);


            _IWriteToClient.Verify(w => w.WriteLine(It.Is <string>(s => s.Contains("Gary says 'Here's what I have for sale.'")), "1"), Times.Once());

            _IWriteToClient.Verify(w => w.WriteLine(It.Is <string>(s => s.Contains("<table class='data'><tr><td style='width: 30px; text-align: center;'>#</td><td style='width: 30px; text-align: center;'>Level</td><td  style='width: 65px;'>Price</td><td>Item</td></tr><tr><td style='width: 30px; text-align: center;'>1</td><td style='width: 30px; text-align: center;'>0</td><td  style='width: 65px;'>0</td><td>Sword</td></tr></table>")), "1"), Times.Once());
        }
        public void Returns_error_if_no_recipes_configured()
        {
            var item = new GameLogic.Item.Item()
            {
                Name     = "Wood",
                ItemType = GameLogic.Item.Item.ItemTypes.Material,
            };

            var player = new Player()
            {
                ConnectionId = "1",
                Name         = "Malleus",
                Status       = CharacterStatus.Status.Standing,
                Inventory    = new ItemList()
                {
                    item
                }
            };

            new GameLogic.Crafting.Crafting(_writer.Object, _cache.Object, _gain.Object, _updateClientUi.Object, _skills.Object).ListCrafts(player);

            _writer.Verify(w => w.WriteLine(It.Is <string>(s => s.Contains("<p>No crafting recipes have been set up.</p>")), "1"), Times.Once());
        }
        public void Returns_correct_item_count()
        {
            var apple = new GameLogic.Item.Item();

            apple.Id          = 0;
            apple.Name        = "apple";
            apple.Description = new Description()
            {
                Room = "apple"
            };

            var sword = new GameLogic.Item.Item();

            sword.Id          = 1;
            sword.Name        = "sword";
            sword.Description = new Description()
            {
                Room = "sword"
            };

            this.items.Add(apple);
            this.items.Add(sword);
            this.items.Add(sword);

            var expected = new List <ItemObj> {
                new ItemObj()
                {
                    Id = 0, Name = "apple"
                }, new ItemObj()
                {
                    Id = 1, Name = "(2) sword"
                }
            };

            Assert.Equal(items.List(true).ToList()[0].Name, expected[0].Name);
            Assert.Equal(items.List(true).ToList()[1].Name, expected[1].Name);
        }
Exemple #16
0
        public void give_item_to_mob()
        {
            var apple = new GameLogic.Item.Item();

            apple.Name        = "apple";
            apple.Description = new Description()
            {
                Room = "apple"
            };

            var room = new Room();

            var player = new Player();

            player.ConnectionId = "1";
            player.Name         = "Gary";
            player.Inventory    = new ItemList();
            player.Inventory.Add(apple);

            var mob = new Player();

            mob.ConnectionId = "mob";
            mob.Name         = "Mob";
            mob.Inventory    = new ItemList();

            room.Players.Add(player);
            room.Players.Add(mob);

            var objects = new GameLogic.Commands.Objects.Object(_IWriteToClient.Object, _IUpdateUI.Object, _IMobScripts.Object);

            objects.Give("apple", "mob", room, player, "");


            Assert.True(player.Inventory.FirstOrDefault(x => x.Name == "apple") == null);
            Assert.True(mob.Inventory.FirstOrDefault(x => x.Name == "apple") != null);
        }
Exemple #17
0
        public void List_Command_Only_Fires_If_Shopkeeper()
        {
            var item = new GameLogic.Item.Item()
            {
                Name = "Sword",
            };
            var shopkeeper = new Player
            {
                ConnectionId = "1",
                Name         = "Gary",
                Inventory    = new ItemList(),
                Shopkeeper   = false
            };

            shopkeeper.Inventory.Add(item);

            var player = new Player
            {
                ConnectionId = "1",
                Name         = "Player",
                Inventory    = new ItemList(),
                Shopkeeper   = false
            };

            var room = new Room();

            room.Mobs.Add(shopkeeper);


            var shop = new Shop(_IWriteToClient.Object, _IUpdateUI.Object, _passiveSkills.Object);

            shop.List(room, player);


            _IWriteToClient.Verify(w => w.WriteLine(It.Is <string>(s => s.Contains("<p>There is no one selling here.</p>")), "1"), Times.Once());
        }
        public void Returns_food_item()
        {
            var player = new Player()
            {
                ConnectionId = "1",
                Name         = "Malleus",
                Status       = CharacterStatus.Status.Sleeping,
                Inventory    = new ItemList()
            };

            var room = new Room();


            var pot = new GameLogic.Item.Item()
            {
                Name      = "cook pot",
                Container = new Container()
                {
                    IsOpen = true,
                    Items  = new ItemList()
                    {
                        new GameLogic.Item.Item()
                        {
                            Name     = "Carrot",
                            ItemType = GameLogic.Item.Item.ItemTypes.Material,
                            Modifier = new Modifier()
                            {
                                HP = 5
                            }
                        },
                        new GameLogic.Item.Item()
                        {
                            Name     = "Mango",
                            ItemType = GameLogic.Item.Item.ItemTypes.Material,
                            Modifier = new Modifier()
                            {
                                Mana = 10
                            }
                        },
                        new GameLogic.Item.Item()
                        {
                            Name     = "Melon",
                            ItemType = GameLogic.Item.Item.ItemTypes.Material,
                            Modifier = new Modifier()
                            {
                                HP = 5
                            }
                        }
                    }
                },
                ItemType = GameLogic.Item.Item.ItemTypes.Cooking
            };

            _dice.Setup(x => x.Roll(1, It.IsAny <int>(), It.IsAny <int>()))
            .Returns(1);

            var ingredient = new Tuple <GameLogic.Item.Item, int>(new GameLogic.Item.Item()
            {
                Name     = "Mango",
                ItemType = GameLogic.Item.Item.ItemTypes.Material,
                Modifier = new Modifier()
                {
                    Mana = 10
                }
            }, 3);



            var ingredients = new List <Tuple <GameLogic.Item.Item, int> >()
            {
                ingredient
            };


            var food = new GameLogic.Crafting.Cooking(_writer.Object, _dice.Object, _updateClientUi.Object, _skills.Object).GenerateCookedItem(player, room, ingredients);

            Assert.NotNull(food);
        }