private IDictionary <IItem, int> GetItemsAndOccuranceChance(ShopTypes shopType)
 {
     return(shopType switch
     {
         ShopTypes.Tavern => new Dictionary <IItem, int>()
         {
             { ConsumableItem.GetConsumableItem(ConsumableItemTypes.Beer), 1 }
         },
         ShopTypes.Inn => new Dictionary <IItem, int>()
         {
             { ConsumableItem.GetConsumableItem(ConsumableItemTypes.Beer), 1 }
         },
         ShopTypes.ArmorShop => new Dictionary <IItem, int>()
         {
             { Armor.GetArmor(ArmorTypes.CopperArmor), 10 },
             { Armor.GetArmor(ArmorTypes.IronArmor), 3 },
         },
         ShopTypes.WeaponShop => new Dictionary <IItem, int>()
         {
             { Weapon.GetWeapon(WeaponTypes.Axe), 10 },
             { Weapon.GetWeapon(WeaponTypes.Spear), 15 },
             { Weapon.GetWeapon(WeaponTypes.Sword), 13 },
         },
         ShopTypes.ItemShop => new Dictionary <IItem, int>()
         {
             { ConsumableItem.GetConsumableItem(ConsumableItemTypes.HealingPotion), 1 }
         },
         ShopTypes.BitOfEverythingShopType => new Dictionary <IItem, int>()
         {
             { ConsumableItem.GetConsumableItem(ConsumableItemTypes.HealingPotion), 50 },
             { Armor.GetArmor(ArmorTypes.CopperArmor), 1 },
             { Weapon.GetWeapon(WeaponTypes.Axe), 4 },
         },
         _ => null
     });
Beispiel #2
0
        public async Task <IActionResult> PutShopTypes(int id, ShopTypes shopTypes)
        {
            if (id != shopTypes.Id)
            {
                return(BadRequest());
            }

            _context.Entry(shopTypes).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ShopTypesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #3
0
        private DBAccessor()
        {
            //var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            //SafeCreateDirectory(documents + @"\HardwareLedger\Database\");
            //Directory = documents + @"\HardwareLedger\Database\{0}.json";
            Directory = @"Database\{0}.json";

            //SafeCreateDirectory(documents + @"\HardwareLedger\Database\");
            SafeCreateDirectory(@"Database\");

            data = new Dictionary <Type, List <IPgmRow> >();

            Reserves         = ReadJson <Reserve, DBObject.Reserve>();
            ShopTypes        = ReadJson <ShopType, DBObject.ShopType>();
            ItemTypes        = ReadJson <ItemType, DBObject.ItemType>();
            ItemStates       = ReadJson <ItemState, DBObject.ItemState>();
            Malfunctions     = ReadJson <Malfunction, DBObject.Malfunction>();
            Relations        = ReadJson <Relation, DBObject.Relation>();
            CollectSchedules = ReadJson <CollectSchedule, DBObject.CollectSchedule>();
            ReserveShippings = ReadJson <ReserveShipping, DBObject.ReserveShipping>();



            data.Add(typeof(Reserve), Reserves.Cast <IPgmRow>().ToList());
            data.Add(typeof(ShopType), ShopTypes.Cast <IPgmRow>().ToList());
            data.Add(typeof(ItemType), ItemTypes.Cast <IPgmRow>().ToList());
            data.Add(typeof(ItemState), ItemStates.Cast <IPgmRow>().ToList());
            data.Add(typeof(Malfunction), Malfunctions.Cast <IPgmRow>().ToList());
            data.Add(typeof(Relation), Relations.Cast <IPgmRow>().ToList());
            data.Add(typeof(CollectSchedule), CollectSchedules.Cast <IPgmRow>().ToList());
            data.Add(typeof(ReserveShipping), ReserveShippings.Cast <IPgmRow>().ToList());
        }
Beispiel #4
0
        public async Task <ActionResult <ShopTypes> > PostShopTypes(ShopTypes shopTypes)
        {
            _context.ShopTypes.Add(shopTypes);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetShopTypes", new { id = shopTypes.Id }, shopTypes));
        }
        public IShop GenerateRandomShop(ShopTypes shopType)
        {
            ShopItemGenerator itemGenerator = new ShopItemGenerator();

            IShopItem[] shopItems = itemGenerator.RandomGenerateShopItems(shopType, 10, 50);

            return(new Shop(shopType, shopItems));
        }
Beispiel #6
0
        public static IShop GetShop(ShopTypes type, string address, string tokenId)
        {
            switch (type)
            {
            case ShopTypes.NeblioTokenShop:
                var shop = new NeblioTokenShop(address, tokenId);
                return(shop);
            }

            return(null);
        }
        private void AssertShopItemsAreGenerated(ShopTypes shopType)
        {
            ShopItemGenerator itemGenerator = new ShopItemGenerator();

            for (int i = 0; i < TotalRuns; ++i)
            {
                IShopItem[] shopItems = itemGenerator.RandomGenerateShopItems(shopType, MinItems, MaxItems);

                foreach (IShopItem item in shopItems)
                {
                    Assert.IsNotNull(item);
                }

                int totalStockedItems = shopItems.Sum(x => x.StockQuantity);
                Assert.IsTrue(totalStockedItems >= MinItems &&
                              totalStockedItems <= MaxItems);
            }
        }
        private IItem[] GenerateItemPool(ShopTypes shopType)
        {
            IDictionary <IItem, int> itemsAndOccuranceChances = GetItemsAndOccuranceChance(shopType);

            IItem[] itemPool = new IItem[itemsAndOccuranceChances.Sum(x => x.Value)];

            int indexCounter = 0;

            foreach (KeyValuePair <IItem, int> itemAndOccuranceChance in itemsAndOccuranceChances)
            {
                for (int i = 0; i < itemAndOccuranceChance.Value; ++i)
                {
                    itemPool[indexCounter] = itemAndOccuranceChance.Key;
                    ++indexCounter;
                }
            }

            return(itemPool);
        }
        public IShopItem[] RandomGenerateShopItems(ShopTypes shopType, int minItems, int maxItems)
        {
            IItem[] itemPool = GenerateItemPool(shopType);

            int totalItemsGenerated = rand.Next(minItems, maxItems);

            IDictionary <IItem, int> itemsAndStockQuantity = GetItemAndStockOfItemPool(itemPool, totalItemsGenerated);

            IShopItem[] shopItems = new IShopItem[itemsAndStockQuantity.Count];
            int         counter   = 0;

            foreach (KeyValuePair <IItem, int> itemAndStockQuantity in itemsAndStockQuantity)
            {
                int itemPrice = GetItemPrice(itemAndStockQuantity.Key);
                shopItems[counter] = new ShopItem(itemAndStockQuantity.Key, itemPrice, itemAndStockQuantity.Value);
                ++counter;
            }

            return(shopItems);
        }
Beispiel #10
0
        public IBuilding RandomGenerateBuilding(BuildingTypes buildingType)
        {
            Building building = new Building(buildingType);

            ShopTypes shopType = buildingType switch
            {
                BuildingTypes.Tavern => ShopTypes.Tavern,
                BuildingTypes.Inn => ShopTypes.Inn,
                BuildingTypes.WeaponShop => ShopTypes.WeaponShop,
                BuildingTypes.ArmorShop => ShopTypes.ArmorShop,
                BuildingTypes.ItemShop => ShopTypes.ItemShop,
                BuildingTypes.BitOfEverythingStore => ShopTypes.BitOfEverythingShopType,
                _ => ShopTypes.UndefinedShopType,
            };

            ShopCreator shopCreator = new ShopCreator();

            building.SetShop(
                shopCreator.GenerateRandomShop(shopType));

            return(building);
        }
        public void CreateShopTest()
        {
            const ShopTypes ShopType = ShopTypes.ItemShop;

            IShopItem[] shopItems = new IShopItem[]
            {
                new ShopItem(
                    new Armor(ArmorTypes.CopperArmor, 10),
                    10, 15),
                new ShopItem(
                    new Weapon(WeaponTypes.Axe, 15),
                    18, 10),
                new ShopItem(
                    new Weapon(WeaponTypes.Sword, 12),
                    6, 3),
            };

            ShopCreator creator = new ShopCreator();
            IShop       shop    = creator.CreateShop(ShopType, shopItems);

            Assert.AreEqual(ShopType, shop.ShopType);
            Assert.AreEqual(shopItems.Length, shop.ShopInventory.ShopItems.Length);

            foreach (IShopItem item in shop.ShopInventory.ShopItems)
            {
                IShopItem localShopItem = Array.Find(shopItems, x
                                                     => x.Item.ItemType == item.Item.ItemType &&
                                                     x.Price == item.Price &&
                                                     x.StockQuantity == item.StockQuantity);

                Assert.IsNotNull(localShopItem);
                Assert.IsTrue(item.Item is Armor || item.Item is Weapon);

                if (item.Item is Armor shopArmor && localShopItem.Item is Armor localArmor)
                {
                    Assert.AreEqual(localArmor.ArmorType, shopArmor.ArmorType);
                    Assert.AreEqual(localArmor.DefenseValue, shopArmor.DefenseValue);
                }
Beispiel #12
0
        /// <summary>
        /// Tworzy nowy sklep.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="position"></param>
        /// <param name="shopType"></param>
        /// <returns></returns>
        public static Shop CreateShop(string name, Vector3 position, ShopTypes shopType)
        {
            using (Database.Database db = new Database.Database())
            {
                Shop newShop = new Shop
                {
                    Name     = name,
                    X        = position.X,
                    Y        = position.Y,
                    Z        = position.Z,
                    ShopType = shopType
                };

                newShop.ShopMarker = NAPI.Marker.CreateMarker(1, newShop.Position,
                                                              new Vector3(), new Vector3(), 0.5f, 255, 255, 255, false, 0);

                db.Shops.Add(newShop);
                db.SaveChanges();
                ShopsList.Add(newShop.Id, newShop);

                return(newShop);
            }
        }
 public IShop CreateShop(ShopTypes shopType, IShopItem[] shopItems)
 {
     return(new Shop(shopType, shopItems));
 }
 public Shop(ShopTypes shopType, IShopItem[] shopItems)
 {
     ShopType      = shopType;
     ShopInventory = new ShopInventory(shopItems);
 }
        public void RandomGenerateShopItemsTest_ItemShop()
        {
            const ShopTypes Type = ShopTypes.ItemShop;

            AssertShopItemsAreGenerated(Type);
        }
        public void RandomGenerateShopItemsTest_Tavern()
        {
            const ShopTypes Type = ShopTypes.Tavern;

            AssertShopItemsAreGenerated(Type);
        }
        public void RandomGenerateShopItemsTest_BitOfEverythingShop()
        {
            const ShopTypes Type = ShopTypes.BitOfEverythingShopType;

            AssertShopItemsAreGenerated(Type);
        }