Пример #1
0
        public void UserCantShopWithoutReput()
        {
            _session.Character.Reput = 500000;
            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Etc, VNum = 1, IsSoldable = true, ReputPrice = 500000
                },
            };
            var itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());

            var list = new ConcurrentDictionary <int, ShopItem>();

            list.TryAdd(0, new ShopItem {
                Slot = 0, ItemInstance = itemBuilder.Create(1, -1), Type = 0
            });
            var shop = new Shop
            {
                ShopItems = list
            };

            _session.Character.Buy(shop, 0, 99);

            var packet = (SMemoPacket)_session.LastPacket;

            Assert.IsTrue(packet.Message == Language.Instance.GetMessageFromKey(LanguageKey.NOT_ENOUGH_REPUT, _session.Account.Language));
        }
Пример #2
0
        public void UserCantShopWithoutPlace()
        {
            _session.Character.Gold = 500000;

            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Etc, VNum = 1, IsSoldable = true, Price = 1
                },
            };
            var itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());

            _session.Character.ItemBuilderService = itemBuilder;
            var list = new ConcurrentDictionary <int, ShopItem>();

            list.TryAdd(0, new ShopItem {
                Slot = 0, ItemInstance = itemBuilder.Create(1, -1), Type = 0
            });
            var shop = new Shop
            {
                ShopItems = list
            };

            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 1, 999), PocketType.Etc, 0);
            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 2, 999), PocketType.Etc, 1);
            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 3, 999), PocketType.Etc, 2);

            _session.Character.Buy(shop, 0, 999);
            var packet = (MsgPacket)_session.LastPacket;

            Assert.IsTrue(packet.Message == Language.Instance.GetMessageFromKey(LanguageKey.NOT_ENOUGH_PLACE, _session.Account.Language));
        }
Пример #3
0
        public void Test_Wear_DestroyedSp()
        {
            _session.Character.HeroLevel = 1;
            var items = new List <Item>
            {
                new Item {
                    Type          = PocketType.Equipment, VNum = 1,
                    EquipmentSlot = EquipmentType.Sp
                },
            };

            _itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > > {
                new WearHandler()
            });
            _session.Character.Inventory.AddItemToPocket(_itemBuilder.Create(1, 1, 1, -2));
            _handler.Wear(new WearPacket {
                InventorySlot = 0, Type = PocketType.Equipment
            });

            Assert.IsTrue(_session.Character.Inventory.Any(s => s.Value.Type == PocketType.Equipment));
            var packet = (MsgPacket)_session.LastPacket;

            Assert.IsTrue(packet.Message == Language.Instance.GetMessageFromKey(LanguageKey.CANT_EQUIP_DESTROYED_SP,
                                                                                _session.Account.Language));
        }
Пример #4
0
        public void Test_Wear_BadHeroLevel()
        {
            _session.Character.HeroLevel = 1;
            var items = new List <Item>
            {
                new Item {
                    Type          = PocketType.Equipment, VNum = 1,
                    EquipmentSlot = EquipmentType.MainWeapon,
                    IsHeroic      = true,
                    LevelMinimum  = 3
                },
            };

            _itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > > {
                new WearHandler()
            });
            _session.Character.Inventory.AddItemToPocket(_itemBuilder.Create(1, 1));
            _handler.Wear(new WearPacket {
                InventorySlot = 0, Type = PocketType.Equipment
            });
            Assert.IsTrue(_session.Character.Inventory.All(s => s.Value.Type == PocketType.Equipment));
            var packet = (SayPacket)_session.LastPacket;

            Assert.IsTrue(packet.Message == Language.Instance.GetMessageFromKey(LanguageKey.BAD_EQUIPMENT,
                                                                                _session.Account.Language) && packet.Type == SayColorType.Yellow);
        }
Пример #5
0
        public void Test_Wear_SpInLoading()
        {
            _session.Character.HeroLevel = 1;
            var items = new List <Item>
            {
                new Item {
                    Type          = PocketType.Equipment, VNum = 1,
                    EquipmentSlot = EquipmentType.Sp
                },
                new Item {
                    Type          = PocketType.Equipment, VNum = 2,
                    EquipmentSlot = EquipmentType.Sp
                },
            };

            _itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > > {
                new WearHandler()
            });
            _session.Character.Inventory.AddItemToPocket(_itemBuilder.Create(1, 1));
            _session.Character.Inventory.AddItemToPocket(_itemBuilder.Create(2, 1));
            _handler.Wear(new WearPacket {
                InventorySlot = 0, Type = PocketType.Equipment
            });
            _session.Character.SpCooldown = 30;
            _handler.Wear(new WearPacket {
                InventorySlot = 1, Type = PocketType.Equipment
            });
            Assert.IsTrue(_session.Character.Inventory.Any(s => s.Value.ItemVNum == 2 && s.Value.Type == PocketType.Equipment));
            var packet = (MsgPacket)_session.LastPacket;

            Assert.IsTrue(packet.Message == string.Format(Language.Instance.GetMessageFromKey(LanguageKey.SP_INLOADING,
                                                                                              _session.Account.Language), 30));
        }
Пример #6
0
        public void Test_Wear_SpInUse()
        {
            _session.Character.HeroLevel = 1;
            var items = new List <Item>
            {
                new Item {
                    Type          = PocketType.Equipment, VNum = 1,
                    EquipmentSlot = EquipmentType.Sp
                },
                new Item {
                    Type          = PocketType.Equipment, VNum = 2,
                    EquipmentSlot = EquipmentType.Sp
                },
            };

            _itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > > {
                new WearHandler()
            });
            _session.Character.Inventory.AddItemToPocket(_itemBuilder.Create(1, 1));
            _session.Character.Inventory.AddItemToPocket(_itemBuilder.Create(2, 1));
            _handler.Wear(new WearPacket {
                InventorySlot = 0, Type = PocketType.Equipment
            });
            _session.Character.UseSp = true;
            _handler.Wear(new WearPacket {
                InventorySlot = 1, Type = PocketType.Equipment
            });
            Assert.IsTrue(_session.Character.Inventory.Any(s => s.Value.ItemVNum == 2 && s.Value.Type == PocketType.Equipment));
            var packet = (SayPacket)_session.LastPacket;

            Assert.IsTrue(packet.Message == Language.Instance.GetMessageFromKey(LanguageKey.SP_BLOCKED,
                                                                                _session.Account.Language) && packet.Type == SayColorType.Yellow);
        }
Пример #7
0
        public void Test_Wear_WearFairy_SpUseBadElement()
        {
            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Equipment, VNum = 1, EquipmentSlot = EquipmentType.Fairy, Element = 3
                },
                new Item {
                    Type = PocketType.Equipment, VNum = 2, EquipmentSlot = EquipmentType.Sp, Element = 1, SecondaryElement = 2
                }
            };

            _itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > > {
                new WearHandler()
            });

            _session.Character.Inventory.AddItemToPocket(_itemBuilder.Create(1, 1));
            _session.Character.Inventory.AddItemToPocket(_itemBuilder.Create(2, 1));
            _handler.Wear(new WearPacket {
                InventorySlot = 1, Type = PocketType.Equipment
            });
            _session.Character.UseSp = true;
            _handler.Wear(new WearPacket {
                InventorySlot = 0, Type = PocketType.Equipment
            });
            Assert.IsTrue(_session.Character.Inventory.Any(s => s.Value.ItemVNum == 1 && s.Value.Type == PocketType.Equipment));
            var packet = (MsgPacket)_session.LastPacket;

            Assert.IsTrue(packet.Message == Language.Instance.GetMessageFromKey(LanguageKey.BAD_FAIRY,
                                                                                _session.Account.Language));
        }
Пример #8
0
        public void Test_Wear_WearFairy_SpUseGoodSecondElement()
        {
            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Equipment, VNum = 1, EquipmentSlot = EquipmentType.Fairy, Element = 2
                },
                new Item {
                    Type = PocketType.Equipment, VNum = 2, EquipmentSlot = EquipmentType.Sp, Element = 1, SecondaryElement = 2
                }
            };

            _itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > > {
                new WearHandler()
            });

            _session.Character.Inventory.AddItemToPocket(_itemBuilder.Create(1, 1));
            _session.Character.Inventory.AddItemToPocket(_itemBuilder.Create(2, 1));
            _handler.Wear(new WearPacket {
                InventorySlot = 1, Type = PocketType.Equipment
            });
            _session.Character.UseSp = true;
            _handler.Wear(new WearPacket {
                InventorySlot = 0, Type = PocketType.Equipment
            });
            Assert.IsTrue(_session.Character.Inventory.Any(s => s.Value.ItemVNum == 1 && s.Value.Type == PocketType.Wear));
        }
Пример #9
0
        public void Test_Binding_Required()
        {
            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Equipment, VNum = 1, RequireBinding = true
                },
            };

            _itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > > {
                new WearHandler()
            });

            _session.Character.Inventory.AddItemToPocket(_itemBuilder.Create(1, 1));
            _handler.Wear(new WearPacket {
                InventorySlot = 0, Type = PocketType.Equipment
            });

            var packet = (QnaPacket)_session.LastPacket;

            Assert.IsTrue(packet.YesPacket is UseItemPacket yespacket &&
                          yespacket.Slot == 0 &&
                          yespacket.Type == PocketType.Equipment &&
                          packet.Question == _session.GetMessageFromKey(LanguageKey.ASK_BIND));
            Assert.IsTrue(_session.Character.Inventory.Any(s => s.Value.ItemVNum == 1 && s.Value.Type == PocketType.Equipment));
        }
Пример #10
0
        public void UserCanShopReput()
        {
            _session.Character.Reput = 500000;

            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Etc, VNum = 1, IsSoldable = true, ReputPrice = 1
                },
            };
            var itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());

            _session.Character.ItemBuilderService = itemBuilder;
            var list = new ConcurrentDictionary <int, ShopItem>();

            list.TryAdd(0, new ShopItem {
                Slot = 0, ItemInstance = itemBuilder.Create(1, -1), Type = 0
            });
            var shop = new Shop
            {
                ShopItems = list
            };

            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 1, 999), PocketType.Etc, 0);
            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 2, 999), PocketType.Etc, 1);
            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 3, 1), PocketType.Etc, 2);

            _session.Character.Buy(shop, 0, 998);
            Assert.IsTrue(_session.Character.Inventory.All(s => s.Value.Amount == 999));
            Assert.IsTrue(_session.Character.Reput == 499002);
        }
Пример #11
0
        public void Setup()
        {
            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Main, VNum = 1012
                },
                new Item {
                    Type = PocketType.Main, VNum = 1013
                },
                new Item {
                    Type = PocketType.Equipment, VNum = 1, ItemType = ItemType.Weapon
                },
                new Item {
                    Type = PocketType.Equipment, VNum = 912, ItemType = ItemType.Specialist
                },
                new Item {
                    Type = PocketType.Equipment, VNum = 924, ItemType = ItemType.Fashion
                }
            };

            _itemBuilderService = new ItemBuilderService(items);
            Inventory           = new InventoryService(items, new WorldConfiguration {
                BackpackSize = 3, MaxItemAmount = 999
            });
        }
        public void Setup()
        {
            PacketFactory.Initialize <NoS0575Packet>();
            var contextBuilder =
                new DbContextOptionsBuilder <NosCoreContext>().UseInMemoryDatabase(
                    databaseName: Guid.NewGuid().ToString());

            DataAccessHelper.Instance.InitializeForTest(contextBuilder.Options);
            var _acc = new AccountDto {
                Name = "AccountTest", Password = EncryptionHelper.Sha512("test")
            };

            _chara = new CharacterDto
            {
                CharacterId = 1,
                Name        = "TestExistingCharacter",
                Slot        = 1,
                AccountId   = _acc.AccountId,
                MapId       = 1,
                State       = CharacterState.Active
            };
            _session.InitializeAccount(_acc);

            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Main, VNum = 1012, IsDroppable = true
                },
                new Item {
                    Type = PocketType.Main, VNum = 1013
                },
                new Item {
                    Type = PocketType.Equipment, VNum = 1, ItemType = ItemType.Weapon
                },
                new Item {
                    Type = PocketType.Equipment, VNum = 912, ItemType = ItemType.Specialist
                },
                new Item {
                    Type = PocketType.Equipment, VNum = 924, ItemType = ItemType.Fashion
                }
            };
            var conf = new WorldConfiguration {
                BackpackSize = 1, MaxItemAmount = 999
            };

            _itemBuilder = new ItemBuilderService(items);
            _handler     = new InventoryPacketController(conf);

            _handler.RegisterSession(_session);
            _session.SetCharacter(_chara.Adapt <Character>());
            _session.Character.MapInstance = _map;
            _session.Character.Inventory   = new InventoryService(items, conf);
        }
Пример #13
0
        public void UserCanNotCreateShopWithMissingItem()
        {
            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Etc, VNum = 1
                },
            };
            var itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());

            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 1));
            _session.Character.MapInstance = _instanceAccessService.GetBaseMapById(1);
            _handler.CreateShop(shopPacket);
            Assert.IsNull(_session.Character.Shop);
        }
Пример #14
0
        public void UserCanNotCreateShopInExchange()
        {
            _session.Character.InExchangeOrTrade = true;
            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Etc, VNum = 1, IsTradable = true
                },
            };
            var itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());

            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 1), PocketType.Etc, 0);
            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 2), PocketType.Etc, 1);
            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 3), PocketType.Etc, 2);

            _session.Character.MapInstance = _instanceAccessService.GetBaseMapById(1);
            _handler.CreateShop(shopPacket);
            Assert.IsNull(_session.Character.Shop);
        }
Пример #15
0
        public void Test_Wear_Put_Item_CorrectSlot(EquipmentType type)
        {
            var items = new List <Item>
            {
                new Item {
                    Type  = PocketType.Equipment, VNum = 1, EquipmentSlot = type,
                    Class = 31 //sum of all 2^class
                },
            };

            _itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > > {
                new WearHandler()
            });

            _session.Character.Inventory.AddItemToPocket(_itemBuilder.Create(1, 1));
            _handler.Wear(new WearPacket {
                InventorySlot = 0, Type = PocketType.Equipment
            });
            Assert.IsTrue(_session.Character.Inventory.All(s => s.Value.Slot == (short)type && s.Value.Type == PocketType.Wear));
        }
Пример #16
0
        public void Test_Binding()
        {
            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Equipment, VNum = 1, RequireBinding = true
                },
            };

            _itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > > {
                new WearHandler()
            });

            _session.Character.Inventory.AddItemToPocket(_itemBuilder.Create(1, 1));
            _handler.UseItem(new UseItemPacket {
                Slot = 0, Type = PocketType.Equipment, Mode = 1
            });

            Assert.IsTrue(_session.Character.Inventory.Any(s => s.Value.ItemVNum == 1 && s.Value.Type == PocketType.Wear && s.Value.BoundCharacterId == _session.Character.VisualId));
        }
Пример #17
0
        public void UserCanNotCreateShopWithMissingAmountItem()
        {
            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Etc, VNum = 1
                },
            };
            var itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());

            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 1), PocketType.Etc, 0);
            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 1), PocketType.Etc, 1);
            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 1), PocketType.Etc, 2);

            _session.Character.MapInstance = _instanceAccessService.GetBaseMapById(1);
            _handler.CreateShop(shopPacket);
            Assert.IsNull(_session.Character.Shop);
            var packet = (SayPacket)_session.LastPacket;

            Assert.IsTrue(packet.Message == Language.Instance.GetMessageFromKey(LanguageKey.SHOP_ONLY_TRADABLE_ITEMS, _session.Account.Language));
        }
Пример #18
0
        public void UserCanSell()
        {
            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Etc, VNum = 1, IsSoldable = true, Price = 500000
                },
            };
            var itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());

            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 1), PocketType.Etc, 0);
            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 2), PocketType.Etc, 1);
            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 3), PocketType.Etc, 2);

            _session.Character.MapInstance = _instanceAccessService.GetBaseMapById(1);
            _handler.SellShop(new SellPacket {
                Slot = 0, Amount = 1, Data = (short)PocketType.Etc
            });
            Assert.IsTrue(_session.Character.Gold > 0);
            Assert.IsNull(_session.Character.Inventory.LoadBySlotAndType <IItemInstance>(0, PocketType.Etc));
        }
Пример #19
0
        public void Test_Wear_GoodLevel()
        {
            _session.Character.Level = 3;
            var items = new List <Item>
            {
                new Item {
                    Type          = PocketType.Equipment, VNum = 1,
                    EquipmentSlot = EquipmentType.MainWeapon,
                    LevelMinimum  = 3
                },
            };

            _itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > > {
                new WearHandler()
            });
            _session.Character.Inventory.AddItemToPocket(_itemBuilder.Create(1, 1));
            _handler.Wear(new WearPacket {
                InventorySlot = 0, Type = PocketType.Equipment
            });
            Assert.IsTrue(_session.Character.Inventory.All(s => s.Value.Type == PocketType.Wear));
        }
Пример #20
0
        public void Setup()
        {
            _worldConfiguration = new WorldConfiguration
            {
                MaxItemAmount     = 999,
                BackpackSize      = 48,
                MaxGoldAmount     = 1000000000,
                MaxBankGoldAmount = 100000000000
            };

            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Main, VNum = 1012
                },
                new Item {
                    Type = PocketType.Main, VNum = 1013
                },
            };

            _itemBuilderService = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());
            _exchangeService    = new ExchangeService(_itemBuilderService, _worldConfiguration);
        }
Пример #21
0
        public void Test_Wear_Put_Item_BadGender(GenderType genderToTest)
        {
            _session.Character.Gender = genderToTest;
            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Equipment, VNum = 1, EquipmentSlot = EquipmentType.MainWeapon,
                    Sex  = (byte)(3 - Math.Pow(2, (byte)genderToTest))
                },
            };

            _itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > > {
                new WearHandler()
            });

            _session.Character.Inventory.AddItemToPocket(_itemBuilder.Create(1, 1));
            _handler.Wear(new WearPacket {
                InventorySlot = 0, Type = PocketType.Equipment
            });
            Assert.IsTrue(_session.Character.Inventory.All(s => s.Value.Type == PocketType.Equipment));
            var packet = (SayPacket)_session.LastPacket;

            Assert.IsTrue(packet.Message == Language.Instance.GetMessageFromKey(LanguageKey.BAD_EQUIPMENT,
                                                                                _session.Account.Language) && packet.Type == SayColorType.Yellow);

            foreach (var validClass in Enum.GetValues(typeof(GenderType)).OfType <GenderType>().Where(s => s != genderToTest).ToList())
            {
                _session.Character.Gender = validClass;
                var item = _session.Character.Inventory.First();
                _handler.Wear(new WearPacket {
                    InventorySlot = 0, Type = PocketType.Equipment
                });
                Assert.IsTrue(item.Value.Type == PocketType.Wear);
                item.Value.Type = PocketType.Equipment;
                item.Value.Slot = 0;
            }
        }
Пример #22
0
        public void UserCanNotSellNotSoldable()
        {
            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Etc, VNum = 1, IsSoldable = false
                },
            };
            var itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());

            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 1), PocketType.Etc, 0);
            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 2), PocketType.Etc, 1);
            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 3), PocketType.Etc, 2);

            _session.Character.MapInstance = _instanceAccessService.GetBaseMapById(1);
            _handler.SellShop(new SellPacket {
                Slot = 0, Amount = 1, Data = (short)PocketType.Etc
            });
            var packet = (SMemoPacket)_session.LastPacket;

            Assert.IsTrue(packet.Message == Language.Instance.GetMessageFromKey(LanguageKey.ITEM_NOT_SOLDABLE, _session.Account.Language));
            Assert.IsTrue(_session.Character.Gold == 0);
            Assert.IsNotNull(_session.Character.Inventory.LoadBySlotAndType <IItemInstance>(0, PocketType.Etc));
        }
Пример #23
0
        public void UserCantShopMoreThanQuantityNonExistingSlot()
        {
            _session.Character.Gold = 9999999999;
            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Etc, VNum = 1, IsSoldable = true, Price = 500000
                },
            };
            var itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());

            var list = new ConcurrentDictionary <int, ShopItem>();

            list.TryAdd(0, new ShopItem {
                Slot = 0, ItemInstance = itemBuilder.Create(1, -1), Type = 0, Amount = 98
            });
            var shop = new Shop
            {
                ShopItems = list
            };

            _session.Character.Buy(shop, 0, 99);
            Assert.IsNull(_session.LastPacket);
        }
Пример #24
0
        public void Setup()
        {
            PacketFactory.Initialize <NoS0575Packet>();
            Broadcaster.Reset();
            var contextBuilder = new DbContextOptionsBuilder <NosCoreContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());

            DataAccessHelper.Instance.InitializeForTest(contextBuilder.Options);
            var map = new MapDto {
                MapId = 1
            };

            DaoFactory.MapDao.InsertOrUpdate(ref map);
            var account = new AccountDto {
                Name = "AccountTest", Password = "******".ToSha512()
            };

            DaoFactory.AccountDao.InsertOrUpdate(ref account);
            WebApiAccess.RegisterBaseAdress();
            WebApiAccess.Instance.MockValues =
                new Dictionary <WebApiRoute, object>
            {
                { WebApiRoute.Channel, new List <ChannelInfo> {
                      new ChannelInfo()
                  } },
                { WebApiRoute.ConnectedAccount, new List <ConnectedAccount>() }
            };

            var _chara = new CharacterDto
            {
                CharacterId = 1,
                Name        = "TestExistingCharacter",
                Slot        = 1,
                AccountId   = account.AccountId,
                MapId       = 1,
                State       = CharacterState.Active
            };

            DaoFactory.CharacterDao.InsertOrUpdate(ref _chara);

            _itemBuilderService = new ItemBuilderService(new List <Item>(),
                                                         new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());
            _instanceAccessService = new MapInstanceAccessService(new List <NpcMonsterDto>(), new List <Map> {
                _map, _mapShop
            },
                                                                  new MapItemBuilderService(new List <IHandler <MapItem, Tuple <MapItem, GetPacket> > >()),
                                                                  new MapNpcBuilderService(_itemBuilderService, new List <ShopDto>(), new List <ShopItemDto>(), new List <NpcMonsterDto>(), new List <MapNpcDto>()),
                                                                  new MapMonsterBuilderService(new List <Item>(), new List <ShopDto>(), new List <ShopItemDto>(), new List <NpcMonsterDto>(), new List <MapMonsterDto>()));

            var channelMock = new Mock <IChannel>();

            _session = new ClientSession(null, new List <PacketController> {
                new DefaultPacketController(null, _instanceAccessService, null)
            }, _instanceAccessService, null);
            _session.RegisterChannel(channelMock.Object);
            _session.InitializeAccount(account);
            _session.SessionId = 1;
            var conf = new WorldConfiguration()
            {
                BackpackSize = 3, MaxItemAmount = 999, MaxGoldAmount = 999_999_999
            };

            _handler = new NpcPacketController(conf, new NrunAccessService(new List <IHandler <Tuple <IAliveEntity, NrunPacket>, Tuple <IAliveEntity, NrunPacket> > >()));
            _handler.RegisterSession(_session);
            _session.SetCharacter(_chara.Adapt <Character>());
            var mapinstance = _instanceAccessService.GetBaseMapById(0);

            _session.Character.Account             = account;
            _session.Character.MapInstance         = _instanceAccessService.GetBaseMapById(0);
            _session.Character.MapInstance         = mapinstance;
            _session.Character.MapInstance.Portals = new List <Portal> {
                new Portal
                {
                    DestinationMapId         = _map.MapId,
                    Type                     = PortalType.Open,
                    SourceMapInstanceId      = mapinstance.MapInstanceId,
                    DestinationMapInstanceId = _instanceAccessService.GetBaseMapById(0).MapInstanceId,
                    DestinationX             = 5,
                    DestinationY             = 5,
                    PortalId                 = 1,
                    SourceMapId              = _map.MapId,
                    SourceX                  = 0,
                    SourceY                  = 0,
                }
            };

            _session.Character.Inventory = new InventoryService(new List <Item>(), conf);
            Broadcaster.Instance.RegisterSession(_session);
        }
Пример #25
0
        public void Setup()
        {
            SystemTime.Freeze();
            PacketFactory.Initialize <NoS0575Packet>();
            var contextBuilder =
                new DbContextOptionsBuilder <NosCoreContext>().UseInMemoryDatabase(
                    databaseName: Guid.NewGuid().ToString());

            DataAccessHelper.Instance.InitializeForTest(contextBuilder.Options);
            var _acc = new AccountDto {
                Name = "AccountTest", Password = "******".ToSha512()
            };

            _chara = new CharacterDto
            {
                CharacterId = 1,
                Name        = "TestExistingCharacter",
                Slot        = 1,
                AccountId   = _acc.AccountId,
                MapId       = 1,
                State       = CharacterState.Active
            };
            _session.InitializeAccount(_acc);

            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Main, VNum = 1012, IsDroppable = true
                },
                new Item {
                    Type = PocketType.Main, VNum = 1013
                },
                new Item {
                    Type = PocketType.Equipment, VNum = 1, ItemType = ItemType.Weapon
                },
                new Item {
                    Type = PocketType.Equipment, VNum = 2, EquipmentSlot = EquipmentType.Fairy, Element = 2
                },
                new Item {
                    Type = PocketType.Equipment, VNum = 912, ItemType = ItemType.Specialist, ReputationMinimum = 2, Element = 1
                },
                new Item {
                    Type = PocketType.Equipment, VNum = 924, ItemType = ItemType.Fashion
                }
            };
            var conf = new WorldConfiguration {
                BackpackSize = 2, MaxItemAmount = 999
            };

            _itemBuilder           = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());
            _handler               = new InventoryPacketController(conf);
            _mapItemBuilderService = new MapItemBuilderService(new List <IHandler <MapItem, Tuple <MapItem, GetPacket> > > {
                new DropHandler(), new SpChargerHandler(), new GoldDropHandler()
            });
            _map = new MapInstance(new Map
            {
                Name = "testMap",
                Data = new byte[]
                {
                    8, 0, 8, 0,
                    0, 0, 0, 0, 0, 0, 0, 0,
                    0, 1, 1, 1, 0, 0, 0, 0,
                    0, 1, 1, 1, 0, 0, 0, 0,
                    0, 1, 1, 1, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0
                }
            }
                                   , Guid.NewGuid(), false, MapInstanceType.BaseMapInstance, new List <NpcMonsterDto>(),
                                   _mapItemBuilderService, new MapNpcBuilderService(_itemBuilder, new List <ShopDto>(), new List <ShopItemDto>(), new List <NpcMonsterDto>(), new List <MapNpcDto>()),
                                   new MapMonsterBuilderService(new List <Item>(), new List <ShopDto>(), new List <ShopItemDto>(), new List <NpcMonsterDto>(), new List <MapMonsterDto>()));
            _handler.RegisterSession(_session);
            _session.SetCharacter(_chara.Adapt <Character>());
            _session.Character.MapInstance     = _map;
            _session.Character.Account         = _acc;
            _session.Character.Inventory       = new InventoryService(items, conf);
            _session.Character.ExchangeService = new ExchangeService(null, null);
        }
Пример #26
0
        private ClientSession prepareSessionShop()
        {
            var conf = new WorldConfiguration()
            {
                BackpackSize = 3, MaxItemAmount = 999, MaxGoldAmount = 999_999_999
            };
            var session2 = new ClientSession(conf, new List <PacketController> {
                new DefaultPacketController(null, _instanceAccessService, null)
            }, _instanceAccessService, null);
            var channelMock = new Mock <IChannel>();

            session2.RegisterChannel(channelMock.Object);
            var account = new AccountDto {
                Name = "AccountTest", Password = "******".ToSha512()
            };

            session2.InitializeAccount(account);
            session2.SessionId = 1;

            _handler = new NpcPacketController(conf,
                                               new NrunAccessService(new List <IHandler <Tuple <IAliveEntity, NrunPacket>, Tuple <IAliveEntity, NrunPacket> > >()));
            _handler.RegisterSession(session2);
            session2.SetCharacter(new CharacterDto
            {
                CharacterId = 1,
                Name        = "chara2",
                Slot        = 1,
                AccountId   = 1,
                MapId       = 1,
                State       = CharacterState.Active
            }.Adapt <Character>());
            var mapinstance = _instanceAccessService.GetBaseMapById(0);

            session2.Character.Account     = account;
            session2.Character.MapInstance = _instanceAccessService.GetBaseMapById(0);
            session2.Character.MapInstance = mapinstance;
            session2.Character.Inventory   = new InventoryService(new List <Item>(), conf);

            _session.Character.Gold = 500000;
            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Etc, VNum = 1, IsSoldable = true, Price = 1
                },
            };
            var itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());

            _session.Character.ItemBuilderService = itemBuilder;
            var list = new ConcurrentDictionary <int, ShopItem>();
            var it   = itemBuilder.Create(1, 1, 999);

            session2.Character.Inventory.AddItemToPocket(it, PocketType.Etc, 0);
            list.TryAdd(0, new ShopItem {
                Slot = 0, ItemInstance = it, Type = 0, Price = 1, Amount = 999
            });
            list.TryAdd(1, new ShopItem {
                Slot = 1, ItemInstance = it, Type = 0, Price = 1, Amount = 500
            });
            session2.Character.Shop = new Shop
            {
                Session   = session2,
                ShopItems = list
            };
            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 1, 999), PocketType.Etc, 0);
            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 2, 999), PocketType.Etc, 1);
            return(session2);
        }