Ejemplo n.º 1
0
 public ShopItem(ShopItemDto dto, ShopResources shopResources)
 {
     ItemNumber       = dto.Id;
     Gender           = (Gender)dto.RequiredGender;
     License          = (ItemLicense)dto.RequiredLicense;
     ColorGroup       = dto.Colors;
     UniqueColorGroup = dto.UniqueColors;
     MinLevel         = dto.RequiredLevel;
     MaxLevel         = dto.LevelLimit;
     MasterLevel      = dto.RequiredMasterLevel;
     //RepairCost = dto.repair_cost;
     IsOneTimeUse  = dto.IsOneTimeUse;
     IsDestroyable = dto.IsDestroyable;
     ItemInfos     = dto.ItemInfos.Select(i => new ShopItemInfo(this, i, shopResources)).ToList();
 }
        public IResult Handle(GetShopItemsQuery query)
        {
            var items = DatabaseQueryProcessor.GetProducts();

            var shopItemsDto = new ShopItemDto[items.Count];

            for (var i = 0; i < items.Count; i++)
            {
                shopItemsDto[i]             = new ShopItemDto();
                shopItemsDto[i].key         = items[i].productId;
                shopItemsDto[i].name        = items[i].name;
                shopItemsDto[i].price       = items[i].price;
                shopItemsDto[i].img         = items[i].imagePath;
                shopItemsDto[i].description = items[i].description;
                shopItemsDto[i].type        = items[i].productType;
            }

            return(new ShopItemsDto()
            {
                isSuccess = true,
                shopItems = shopItemsDto
            });
        }
Ejemplo n.º 3
0
 public ItemBuyItemAckMessage(ulong[] ids, ShopItemDto item)
 {
     Ids    = ids;
     Result = ItemBuyResult.OK;
     Item   = item;
 }
Ejemplo n.º 4
0
 public ItemBuyItemAckMessage()
 {
     Ids  = Array.Empty <ulong>();
     Item = new ShopItemDto();
 }
Ejemplo n.º 5
0
        public void InsertShopItems(List <string[]> packetList)
        {
            var  shopitems   = new List <ShopItemDto>();
            var  itemCounter = 0;
            byte type        = 0;
            var  shopItemdb  = _shopItemDao.LoadAll().ToList();
            var  shopdb      = _shopDao.LoadAll().ToList();

            foreach (var currentPacket in packetList.Where(o => o[0].Equals("n_inv") || o[0].Equals("shopping")))
            {
                if (currentPacket[0].Equals("n_inv"))
                {
                    var npcid = short.Parse(currentPacket[2]);
                    if (shopdb.FirstOrDefault(s => s.MapNpcId == npcid) == null)
                    {
                        continue;
                    }

                    for (var i = 5; i < currentPacket.Length; i++)
                    {
                        var item = currentPacket[i].Split('.');

                        if (item.Length < 5)
                        {
                            continue;
                        }

                        var sitem = new ShopItemDto
                        {
                            ShopId = shopdb.FirstOrDefault(s => s.MapNpcId == npcid)
                                     .ShopId,
                            Type     = type,
                            Slot     = byte.Parse(item[1]),
                            ItemVNum = short.Parse(item[2]),
                            Rare     = item.Length == 6 ? sbyte.Parse(item[3]) : (short)0,
                            Upgrade  = item.Length == 6 ? byte.Parse(item[4]) : (byte)0
                        };


                        if (shopitems.Any(s =>
                                          s.ItemVNum.Equals(sitem.ItemVNum) && s.ShopId.Equals(sitem.ShopId)) ||
                            shopItemdb.Where(s => s.ShopId == sitem.ShopId)
                            .Any(s => s.ItemVNum.Equals(sitem.ItemVNum)))
                        {
                            continue;
                        }

                        shopitems.Add(sitem);
                        itemCounter++;
                    }
                }
                else if (currentPacket.Length > 3)
                {
                    type = byte.Parse(currentPacket[1]);
                }
            }

            var groups           = shopitems.GroupBy(s => s.ShopId);
            var shopListItemDtos = new List <ShopItemDto>();

            foreach (var group in groups)
            {
                var shopItemDtos = group.OrderBy(s => s.Slot).ToList();
                for (byte i = 0; i < shopItemDtos.Count; i++)
                {
                    shopItemDtos.ElementAt(i).Slot = i;
                }

                shopListItemDtos.AddRange(shopItemDtos);
            }

            _shopItemDao.InsertOrUpdate(shopListItemDtos);
            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.SHOPITEMS_PARSED),
                                itemCounter);
        }
Ejemplo n.º 6
0
        public void InsertShopItems(List <string[]> packetList)
        {
            List <ShopItemDto> shopitems = new List <ShopItemDto>();
            int  itemCounter             = 0;
            byte type = 0;

            foreach (var currentPacket in packetList.Where(o => o[0].Equals("n_inv") || o[0].Equals("shopping")))
            {
                if (currentPacket[0].Equals("n_inv"))
                {
                    short npcid = short.Parse(currentPacket[2]);
                    if (_shopDao.FirstOrDefault(s => s.MapNpcId == npcid) == null)
                    {
                        continue;
                    }

                    for (int i = 5; i < currentPacket.Length; i++)
                    {
                        string[]    item  = currentPacket[i].Split('.');
                        ShopItemDto sitem = null;

                        if (item.Length == 5)
                        {
                            sitem = new ShopItemDto
                            {
                                ShopId = _shopDao.FirstOrDefault(s => s.MapNpcId == npcid)
                                         .ShopId,
                                Type     = type,
                                Slot     = byte.Parse(item[1]),
                                ItemVNum = short.Parse(item[2])
                            };
                        }

                        if (item.Length == 6)
                        {
                            sitem = new ShopItemDto
                            {
                                ShopId = _shopDao.FirstOrDefault(s => s.MapNpcId == npcid)
                                         .ShopId,
                                Type     = type,
                                Slot     = byte.Parse(item[1]),
                                ItemVNum = short.Parse(item[2]),
                                Rare     = sbyte.Parse(item[3]),
                                Upgrade  = byte.Parse(item[4])
                            };
                        }

                        if (sitem == null || shopitems.Any(s =>
                                                           s.ItemVNum.Equals(sitem.ItemVNum) && s.ShopId.Equals(sitem.ShopId)) ||
                            _shopItemDao.Where(s => s.ShopId == sitem.ShopId)
                            .Any(s => s.ItemVNum.Equals(sitem.ItemVNum)))
                        {
                            continue;
                        }

                        shopitems.Add(sitem);
                        itemCounter++;
                    }
                }
                else
                {
                    if (currentPacket.Length > 3)
                    {
                        type = byte.Parse(currentPacket[1]);
                    }
                }
            }

            IEnumerable <ShopItemDto> shopItemDtos = shopitems;

            _shopItemDao.InsertOrUpdate(shopItemDtos);
            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.SHOPITEMS_PARSED),
                                itemCounter);
        }
Ejemplo n.º 7
0
        public void Generate(string filePath)
        {
            var shopService     = ChickenContainer.Instance.Resolve <IShopService>();
            var shopItemService = ChickenContainer.Instance.Resolve <IShopItemService>();

            string[] lines   = File.ReadAllText(filePath, Encoding.Default).Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
            int      counter = 0;
            byte     type    = 0;

            foreach (string line in lines)
            {
                try
                {
                    string[] currentPacket = line.Split('\t', ' ');
                    switch (currentPacket[0])
                    {
                    case "n_inv":
                        short npcId = short.Parse(currentPacket[2]);
                        if (!shopService.GetByMapNpcId(npcId).Any())
                        {
                            continue;
                        }

                        for (int i = 5; i < currentPacket.Length; i++)
                        {
                            string[] item = currentPacket[i].Split('.');
                            if (item.Length != 5 && item.Length != 6)
                            {
                                continue;
                            }

                            var shopItem = new ShopItemDto
                            {
                                ShopId = shopService.GetByMapNpcId(npcId).FirstOrDefault()?.Id ?? 0,
                                Type   = type,
                                Slot   = byte.Parse(item[1]),
                                ItemId = long.Parse(item[2])
                            };
                            if (item.Length == 6)
                            {
                                shopItem.Rare    = sbyte.Parse(item[3]);
                                shopItem.Upgrade = byte.Parse(item[4]);
                            }

                            if (_shopItems.Any(s => s.ItemId.Equals(shopItem.ItemId) && s.ShopId.Equals(shopItem.ShopId)) ||
                                shopItemService.GetByShopId(shopItem.ShopId).Any(s => s.ItemId.Equals(shopItem.ItemId)))
                            {
                                continue;
                            }

                            _shopItems.Add(shopItem);
                            counter++;
                        }

                        break;

                    case "shopping":
                        type = byte.Parse(currentPacket[1]);
                        break;
                    }
                }
                catch (Exception e)
                {
                    Log.Error("[PARSE]", e);
                    Log.Warn(line);
                }
            }

            shopItemService.Save(_shopItems);
        }
Ejemplo n.º 8
0
 public SBuyItemAckMessage(ShopItemDto item, ItemBuyResult result)
     : this()
 {
     Item   = item;
     Result = result;
 }
Ejemplo n.º 9
0
        private static void FillShop()
        {
            if (!Config.Instance.NoobMode)
            {
                return;
            }

            using (var db = GameDatabase.Open())
            {
                if (!db.Find <ShopVersionDto>().Any())
                {
                    var version = new ShopVersionDto
                    {
                        Version = DateTimeOffset.UtcNow.ToString("yyyyMMddHHmmss")
                    };
                    db.Insert(version);
                }

                if (db.Find <ShopEffectGroupDto>().Any() || db.Find <ShopEffectDto>().Any() ||
                    db.Find <ShopPriceGroupDto>().Any() || db.Find <ShopPriceDto>().Any() ||
                    db.Find <ShopItemDto>().Any() || db.Find <ShopItemInfoDto>().Any())
                {
                    return;
                }

                Log.Information("NoobMode: Filling the shop with items");

                using (var transaction = db.BeginTransaction())
                {
                    var effects = new Dictionary <string, Tuple <uint[], int> >
                    {
                        { "None", Tuple.Create(Array.Empty <uint>(), 0) },
                        { "HP+30", Tuple.Create(new uint[] { 1030 }, 0) },
                        { "HP+15", Tuple.Create(new uint[] { 1015 }, 0) },
                        { "SP+40", Tuple.Create(new uint[] { 2040 }, 0) },
                        { "HP+20 & SP+20", Tuple.Create(new uint[] { 4001 }, 0) },
                        { "SP+3", Tuple.Create(new uint[] { 2003 }, 0) },
                        { "Defense+7", Tuple.Create(new uint[] { 19907 }, 0) },
                        { "HP+3", Tuple.Create(new uint[] { 1003 }, 0) }
                    };

                    #region Effects

                    foreach (var pair in effects.ToArray())
                    {
                        var effectGroup = new ShopEffectGroupDto {
                            Name = pair.Key
                        };
                        db.Insert(effectGroup, statement => statement.AttachToTransaction(transaction));
                        effects[pair.Key] = Tuple.Create(pair.Value.Item1, effectGroup.Id);

                        foreach (var effect in pair.Value.Item1)
                        {
                            db.Insert(new ShopEffectDto {
                                EffectGroupId = effectGroup.Id, Effect = effect
                            },
                                      statement => statement.AttachToTransaction(transaction));
                        }
                    }

                    #endregion

                    #region Price

                    var priceGroup = new ShopPriceGroupDto
                    {
                        Name      = "PEN",
                        PriceType = (byte)ItemPriceType.PEN
                    };
                    db.Insert(priceGroup, statement => statement.AttachToTransaction(transaction));

                    var price = new ShopPriceDto
                    {
                        PriceGroupId = priceGroup.Id,
                        PeriodType   = (byte)ItemPeriodType.None,
                        IsRefundable = false,
                        Durability   = 1000000,
                        IsEnabled    = true,
                        Price        = 1
                    };
                    db.Insert(price, statement => statement.AttachToTransaction(transaction));

                    #endregion

                    #region Items

                    var items = GameServer.Instance.ResourceCache.GetItems().Values.ToArray();
                    for (var i = 0; i < items.Length; ++i)
                    {
                        var item        = items[i];
                        var effectToUse = effects["None"];

                        switch (item.ItemNumber.Category)
                        {
                        case ItemCategory.Weapon:
                            break;

                        case ItemCategory.Skill:
                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 0)     // half hp mastery
                            {
                                effectToUse = effects["HP+15"];
                            }

                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 1)     // hp mastery
                            {
                                effectToUse = effects["HP+30"];
                            }

                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 2)     // sp mastery
                            {
                                effectToUse = effects["SP+40"];
                            }

                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 3)     // dual mastery
                            {
                                effectToUse = effects["HP+20 & SP+20"];
                            }

                            break;

                        case ItemCategory.Costume:
                            if (item.ItemNumber.SubCategory == (int)CostumeSlot.Hair)
                            {
                                effectToUse = effects["Defense+7"];
                            }

                            if (item.ItemNumber.SubCategory == (int)CostumeSlot.Face)
                            {
                                effectToUse = effects["SP+3"];
                            }

                            if (item.ItemNumber.SubCategory == (int)CostumeSlot.Pants)
                            {
                                effectToUse = effects["Defense+7"];
                            }

                            if (item.ItemNumber.SubCategory == (int)CostumeSlot.Gloves)
                            {
                                effectToUse = effects["HP+3"];
                            }

                            if (item.ItemNumber.SubCategory == (int)CostumeSlot.Shoes)
                            {
                                effectToUse = effects["HP+3"];
                            }

                            if (item.ItemNumber.SubCategory == (int)CostumeSlot.Accessory)
                            {
                                effectToUse = effects["SP+3"];
                            }
                            break;

                        default:
                            continue;
                        }

                        var shopItem = new ShopItemDto
                        {
                            Id              = item.ItemNumber,
                            RequiredGender  = (byte)item.Gender,
                            RequiredLicense = (byte)item.License,
                            IsDestroyable   = true
                        };
                        db.Insert(shopItem, statement => statement.AttachToTransaction(transaction));

                        var shopItemInfo = new ShopItemInfoDto
                        {
                            ShopItemId    = shopItem.Id,
                            PriceGroupId  = priceGroup.Id,
                            EffectGroupId = effectToUse.Item2,
                            IsEnabled     = true
                        };
                        db.Insert(shopItemInfo, statement => statement.AttachToTransaction(transaction));

                        Log.Information($"[{i}/{items.Length}] {item.ItemNumber}: {item.Name}");
                    }

                    #endregion

                    try
                    {
                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 10
0
        private static void FillShop()
        {
            if (!Config.Instance.NoobMode)
            {
                return;
            }

            using (var db = GameDatabase.Open())
            {
                if (!db.Find <ShopVersionDto>().Any())
                {
                    var version = new ShopVersionDto
                    {
                        Version = DateTimeOffset.UtcNow.ToString("yyyyMMddHHmmss")
                    };
                    db.Insert(version);
                }

                if (db.Find <ShopEffectGroupDto>().Any() || db.Find <ShopEffectDto>().Any() ||
                    db.Find <ShopPriceGroupDto>().Any() || db.Find <ShopPriceDto>().Any() ||
                    db.Find <ShopItemDto>().Any() || db.Find <ShopItemInfoDto>().Any())
                {
                    return;
                }

                Log.Information("NoobMode: Filling the shop with items");

                using (var transaction = db.BeginTransaction())
                {
                    var effects = new Dictionary <string, Tuple <uint[], uint> > // effectids, groupid/effect
                    {
                        { "None", Tuple.Create(Array.Empty <uint>(), (uint)0) },
                        {
                            "Shooting Weapon Defense (Head) +5%",
                            Tuple.Create(new uint[] { 1100313003, 1100315003, 1100317003 }, (uint)1100315002)
                        },
                        { "SP+6", Tuple.Create(new uint[] { 1101301006 }, (uint)1101301006) },
                        { "Attack+1%", Tuple.Create(new uint[] { 1102303001 }, (uint)1102303001) },
                        { "Attack+5%", Tuple.Create(new uint[] { 1102303003 }, (uint)1102303003) },
                        { "Attack+10%", Tuple.Create(new uint[] { 1299600006 }, (uint)1299600006) },
                        { "Defense+5%", Tuple.Create(new uint[] { 1103302004 }, (uint)1103302004) },
                        { "HP+4", Tuple.Create(new uint[] { 1105300004 }, (uint)1105300004) },
                        { "HP+30", Tuple.Create(new uint[] { 1999300011 }, (uint)1999300011) },
                        { "HP+15", Tuple.Create(new uint[] { 1999300009 }, (uint)1999300009) },
                        { "SP+40", Tuple.Create(new uint[] { 1300301012 }, (uint)1300301012) },
                        { "HP+20 & SP+20", Tuple.Create(new uint[] { 1999300010, 1999301011 }, (uint)30001) },
                        { "HP+25 & SP+25", Tuple.Create(new uint[] { 1999300012, 1999301013 }, (uint)30003) }
                    };

                    #region Effects

                    foreach (var pair in effects.ToArray())
                    {
                        var effectGroup = new ShopEffectGroupDto {
                            Name = pair.Key, Effect = pair.Value.Item2
                        };
                        db.Insert(effectGroup, statement => statement.AttachToTransaction(transaction));
                        effects[pair.Key] = Tuple.Create(pair.Value.Item1, (uint)effectGroup.Id);

                        foreach (var effect in pair.Value.Item1)
                        {
                            db.Insert(new ShopEffectDto {
                                EffectGroupId = effectGroup.Id, Effect = effect
                            },
                                      statement => statement.AttachToTransaction(transaction));
                        }
                    }

                    #endregion

                    #region Price

                    var priceGroup = new ShopPriceGroupDto
                    {
                        Name      = "PEN",
                        PriceType = (byte)ItemPriceType.PEN
                    };
                    var priceGroup2 = new ShopPriceGroupDto
                    {
                        Name      = "Item",
                        PriceType = (byte)ItemPriceType.Premium
                    };

                    db.Insert(priceGroup);
                    db.Insert(priceGroup2);
                    var price_none_perm = new ShopPriceDto
                    {
                        PriceGroupId = priceGroup.Id,
                        PeriodType   = (byte)ItemPeriodType.None,
                        IsRefundable = true,
                        Durability   = 2400,
                        IsEnabled    = true,
                        Price        = 1
                    };

                    var price_unit_one = new ShopPriceDto
                    {
                        PriceGroupId = priceGroup2.Id,
                        Durability   = 1,
                        PeriodType   = (byte)ItemPeriodType.Units,
                        IsRefundable = true,
                        Period       = 1,
                        IsEnabled    = true,
                        Price        = 1000
                    };

                    var price_unit_two = new ShopPriceDto
                    {
                        PriceGroupId = priceGroup2.Id,
                        Durability   = 1,
                        PeriodType   = (byte)ItemPeriodType.Units,
                        IsRefundable = true,
                        Period       = 2,
                        IsEnabled    = true,
                        Price        = 2000
                    };

                    var price_unit_five = new ShopPriceDto
                    {
                        PriceGroupId = priceGroup2.Id,
                        Durability   = 1,
                        PeriodType   = (byte)ItemPeriodType.Units,
                        IsRefundable = true,
                        Period       = 5,
                        IsEnabled    = true,
                        Price        = 4500
                    };

                    var price_unit_ten = new ShopPriceDto
                    {
                        PriceGroupId = priceGroup2.Id,
                        Durability   = 1,
                        PeriodType   = (byte)ItemPeriodType.Units,
                        IsRefundable = true,
                        Period       = 10,
                        IsEnabled    = true,
                        Price        = 8000
                    };

                    db.Insert(price_none_perm);
                    db.Insert(price_unit_one);
                    db.Insert(price_unit_two);
                    db.Insert(price_unit_five);
                    db.Insert(price_unit_ten);

                    #endregion

                    #region Items

                    var items = GameServer.Instance.ResourceCache.GetItems().Values.ToArray();
                    Log.Information("{count} items cargados", items.Count());

                    for (var i = 0; i < items.Length; ++i)
                    {
                        var  item        = items[i];
                        var  effectToUse = effects["None"];
                        byte mainTab     = 0;
                        byte subTab      = 0;

                        switch (item.ItemNumber.Category)
                        {
                        case ItemCategory.Card:
                        case ItemCategory.Coupon:
                            mainTab = 4;
                            subTab  = 6;
                            break;

                        case ItemCategory.EsperChip:
                            mainTab = 4;
                            subTab  = 2;
                            break;

                        case ItemCategory.Boost:
                            switch ((BoostCategory)item.ItemNumber.SubCategory)
                            {
                            case BoostCategory.Pen:
                                mainTab = 4;
                                subTab  = 4;
                                break;

                            case BoostCategory.Exp:
                                mainTab = 4;
                                subTab  = 5;
                                break;

                            case BoostCategory.Mp:
                                mainTab = 4;
                                subTab  = 3;
                                break;

                            case BoostCategory.Unique:
                                mainTab = 4;
                                subTab  = 5;
                                break;
                            }

                            break;

                        case ItemCategory.OneTimeUse:
                            switch ((OneTimeUseCategory)item.ItemNumber.SubCategory)
                            {
                            case OneTimeUseCategory.Namechange:
                                mainTab = 4;
                                subTab  = 0;
                                break;

                            case OneTimeUseCategory.Stat:
                                mainTab = 4;
                                subTab  = 0;
                                break;

                            case OneTimeUseCategory.Capsule:         //clothes+weps
                                mainTab = 1;
                                subTab  = 0;
                                break;

                            case OneTimeUseCategory.FumbiCapsule:
                                mainTab = 1;
                                subTab  = 4;
                                break;

                            case OneTimeUseCategory.Event:
                                mainTab = 4;
                                subTab  = 0;
                                break;

                            default:
                                continue;
                            }

                            break;

                        case ItemCategory.Weapon:
                            effectToUse = effects["Attack+1%"];
                            mainTab     = 2;

                            switch ((WeaponCategory)item.ItemNumber.SubCategory)
                            {
                            case WeaponCategory.Melee:
                                subTab = 1;
                                break;

                            case WeaponCategory.RifleGun:
                                subTab = 2;
                                break;

                            case WeaponCategory.HeavyGun:
                                subTab = 4;
                                break;

                            case WeaponCategory.Sniper:
                                subTab = 5;
                                break;

                            case WeaponCategory.Sentry:
                                subTab = 6;
                                break;

                            case WeaponCategory.Bomb:
                                subTab = 7;
                                break;

                            case WeaponCategory.Mind:
                                subTab = 6;
                                break;
                            }

                            break;

                        case ItemCategory.Skill:
                            mainTab = 2;
                            subTab  = 8;
                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 0)     // half hp mastery
                            {
                                effectToUse = effects["HP+15"];
                            }

                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 1)     // hp mastery
                            {
                                effectToUse = effects["HP+30"];
                            }

                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 2)     // sp mastery
                            {
                                effectToUse = effects["SP+40"];
                            }

                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 3)     // dual mastery
                            {
                                effectToUse = effects["HP+20 & SP+20"];
                            }

                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 5
                                ) // dual mastery - returner
                            {
                                effectToUse = effects["HP+20 & SP+20"];
                            }

                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 7
                                ) // unique dual mastery - balanced!
                            {
                                effectToUse = effects["HP+25 & SP+25"];
                            }

                            break;

                        case ItemCategory.Costume:
                            mainTab = 3;
                            subTab  = (byte)(item.ItemNumber.SubCategory + 2);
                            switch ((CostumeSlot)item.ItemNumber.SubCategory)
                            {
                            case CostumeSlot.Hair:
                                effectToUse = effects["Shooting Weapon Defense (Head) +5%"];
                                break;

                            case CostumeSlot.Face:
                                effectToUse = effects["SP+6"];
                                break;

                            case CostumeSlot.Shirt:
                                effectToUse = effects["Attack+5%"];
                                break;

                            case CostumeSlot.Pants:
                                effectToUse = effects["Defense+5%"];
                                break;

                            case CostumeSlot.Gloves:
                                effectToUse = effects["HP+4"];
                                break;

                            case CostumeSlot.Shoes:
                                effectToUse = effects["HP+4"];
                                break;

                            case CostumeSlot.Accessory:
                                effectToUse = effects["SP+6"];
                                break;

                            case CostumeSlot.Pet:
                                effectToUse = effects["SP+6"];
                                break;
                            }

                            break;

                        default:
                            effectToUse = effects["None"];
                            mainTab     = 4;
                            subTab      = 6;
                            break;
                        }

                        var shopItem = new ShopItemDto
                        {
                            Id              = item.ItemNumber,
                            RequiredGender  = (byte)item.Gender,
                            RequiredLicense = (byte)item.License,
                            IsDestroyable   = true,
                            MainTab         = mainTab,
                            SubTab          = subTab,
                            Colors          = (byte)item.Colors
                        };
                        db.Insert(shopItem, statement => statement.AttachToTransaction(transaction));

                        var shopItemInfo = new ShopItemInfoDto
                        {
                            ShopItemId    = shopItem.Id,
                            PriceGroupId  = priceGroup.Id,
                            EffectGroupId = (int)effectToUse.Item2,
                            IsEnabled     = true
                        };
                        var shopItemInfo_onetimeuse = new ShopItemInfoDto
                        {
                            ShopItemId    = shopItem.Id,
                            PriceGroupId  = priceGroup2.Id,
                            EffectGroupId = (int)effectToUse.Item2,
                            IsEnabled     = true
                        };
                        if (item.ItemNumber.Category == ItemCategory.Costume || item.ItemNumber.Category ==
                            ItemCategory.Weapon ||
                            item.ItemNumber.Category ==
                            ItemCategory.Skill ||
                            item.ItemNumber.Category ==
                            ItemCategory.EsperChip)
                        {
                            db.Insert(shopItemInfo, statement => statement.AttachToTransaction(transaction));
                        }
                        else
                        {
                            db.Insert(shopItemInfo_onetimeuse, statement => statement.AttachToTransaction(transaction));
                        }

                        Log.Information($"[{i}/{items.Length}] {item.ItemNumber}: {item.Name} | Colors: {item.Colors}");
                    }

                    #endregion

                    try
                    {
                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 11
0
 public UniqueShopItem(ShopItemDto dto, ShopResources shopResources)
 {
 }
Ejemplo n.º 12
0
        public async Task <ActionResult <RewardContentDto> > Buy([FromBody] ShopItemDto dto, [FromServices] IEquipmentGenerator equipmentGenerator)
        {
            var userId = User.Claims.GetUserId();

            if (userId == null)
            {
                return(Forbid());
            }

            var item = ShopInventory.Items.FirstOrDefault(o => o.ItemId == dto.ItemId && o.Rarity == dto.Rarity);

            if (item == null)
            {
                return(BadRequest());
            }

            foreach (var price in item.Prices)
            {
                var currencies = await Context.Items
                                 .Where(o => o.UserId == userId)
                                 .Where(o => o.ItemId == price.CurrencyItemId)
                                 .Take(price.Quantity)
                                 .ToListAsync();

                if (currencies.Count != price.Quantity)
                {
                    return(BadRequest());
                }

                Context.RemoveRange(currencies);
            }

            var content = new RewardContentDto();

            if (EquipmentConstants.IsEquipmentConstant(item.ItemId))
            {
                var fighterLevel = await Context.Fighters
                                   .Where(o => o.UserId == userId)
                                   .MaxAsync(o => o.Level);

                var itemLevel = fighterLevel.NearestBase(8);
                if (itemLevel < 1)
                {
                    itemLevel = 1;
                }

                var equipment = equipmentGenerator.GenerateEquipment(item.ItemId, itemLevel, item.Rarity, userId.Value);
                Context.Add(equipment);
                content.Equipment.Add(Mapper.Map <EquipmentDto>(equipment));
            }
            else
            {
                var boughtItem = new Item()
                {
                    ItemId = item.ItemId,
                    UserId = userId.Value,
                };

                Context.Items.Add(boughtItem);
                content.Items.Add(Mapper.Map <ItemDto>(boughtItem));
            }

            await Context.SaveChangesAsync();

            return(Ok(content));
        }
Ejemplo n.º 13
0
        private async Task HandleNpcItemBuyRequest(IPlayerEntity player, ShopBuyEvent shopBuy, Shop shop)
        {
            ShopItemDto item   = shop.Items.FirstOrDefault(s => s.Slot == shopBuy.Slot);
            short       amount = shopBuy.Amount;

            if (item == null || amount <= 0)
            {
                return;
            }

            // check diginity
            double percent = 1.0;

            switch (player.GetDignityIcon())
            {
            case CharacterDignity.BluffedNameOnly:
                percent = 1.10;
                break;

            case CharacterDignity.NotQualifiedFor:
                percent = 1.20;
                break;

            case CharacterDignity.Useless:
            case CharacterDignity.StupidMinded:
                percent = 1.5;
                break;
            }

            bool isReputBuy = item.Item.ReputPrice > 0;
            long price      = isReputBuy ? item.Item.ReputPrice : item.Item.Price;

            price *= amount;
            sbyte rare = item.Rare;

            if (item.Item.Type == 0)
            {
                amount = 1;
            }

            if (!isReputBuy && price < 0 && price * percent > player.Character.Gold)
            {
                await player.SendPacketAsync(player.GenerateShopMemoPacket(SMemoPacketType.FailNpc, player.GetLanguage(PlayerMessages.YOU_DONT_HAVE_ENOUGH_GOLD)));

                return;
            }

            if (isReputBuy)
            {
                if (price > player.Character.Reput)
                {
                    await player.SendPacketAsync(player.GenerateShopMemoPacket(SMemoPacketType.FailNpc, player.GetLanguage(PlayerMessages.YOU_DONT_HAVE_ENOUGH_REPUTATION)));

                    return;
                }

                // generate a random rarity
                byte ra = (byte)_randomGenerator.Next(100);

                int[] rareprob = { 100, 100, 70, 50, 30, 15, 5, 1 };
                if (item.Item.ReputPrice == 0)
                {
                    return;
                }

                for (int i = 0; i < rareprob.Length; i++)
                {
                    if (ra <= rareprob[i])
                    {
                        rare = (sbyte)i;
                    }
                }
            }

            bool canAddItem = player.Inventory.CanAddItem(item.Item, amount);

            if (!canAddItem)
            {
                await player.SendPacketAsync(player.GenerateShopMemoPacket(SMemoPacketType.FailNpc, player.GetLanguage(PlayerMessages.YOU_DONT_HAVE_ENOUGH_SPACE_IN_INVENTORY)));

                return;
            }

            // add item to inventory
            var             itemFactory = ChickenContainer.Instance.Resolve <IItemInstanceDtoFactory>();
            ItemInstanceDto newitem     = itemFactory.CreateItem(item.ItemId, amount, (sbyte)rare);

            if (isReputBuy)
            {
                player.Character.Reput -= price;
                await player.ActualizeUiReputation();

                // player.SendPacket "reput decreased"
            }
            else
            {
                player.Character.Gold -= (long)(price * percent);
                await player.ActualizeUiGold();
            }

            await player.EmitEventAsync(new InventoryAddItemEvent
            {
                ItemInstance = newitem
            });
        }
        private static void FillShop()
        {
            if (!Config.Instance.NoobMode)
            {
                return;
            }

            using (var db = GameDatabase.Open())
            {
                if (!db.Find <ShopVersionDto>().Any())
                {
                    var version = new ShopVersionDto
                    {
                        Version = DateTimeOffset.UtcNow.ToString("yyyyMMddHHmmss")
                    };
                    db.Insert(version);
                }

                if (db.Find <ShopEffectGroupDto>().Any() || db.Find <ShopEffectDto>().Any() ||
                    db.Find <ShopPriceGroupDto>().Any() || db.Find <ShopPriceDto>().Any() ||
                    db.Find <ShopItemDto>().Any() || db.Find <ShopItemInfoDto>().Any())
                {
                    return;
                }

                Log.Information("NoobMode: Filling the shop with items");

                using (var transaction = db.BeginTransaction())
                {
                    var effects = new Dictionary <string, Tuple <uint[], int> >
                    {
                        { "None", Tuple.Create(Array.Empty <uint>(), 0) },
                        { "Shooting Weapon Defense (Head) +5%", Tuple.Create(new uint[] { 1100313003, 1100315003, 1100317003 }, 0) },
                        { "SP+6", Tuple.Create(new uint[] { 1101301006 }, 0) },
                        { "Attack+1%", Tuple.Create(new uint[] { 1102303001 }, 0) },
                        { "Attack+5%", Tuple.Create(new uint[] { 1102303003 }, 0) },
                        { "Defense+5%", Tuple.Create(new uint[] { 1103302004 }, 0) },
                        { "HP+4", Tuple.Create(new uint[] { 1105300004 }, 0) },
                        { "HP+30", Tuple.Create(new uint[] { 1999300011 }, 0) },
                        { "HP+15", Tuple.Create(new uint[] { 1999300009 }, 0) },
                        { "SP+40", Tuple.Create(new uint[] { 1300301012 }, 0) },
                        { "HP+20 & SP+20", Tuple.Create(new uint[] { 1999300010, 1999301011 }, 0) }
                    };

                    #region Effects

                    foreach (var pair in effects.ToArray())
                    {
                        var effectGroup = new ShopEffectGroupDto {
                            Name = pair.Key
                        };
                        db.Insert(effectGroup, statement => statement.AttachToTransaction(transaction));
                        effects[pair.Key] = Tuple.Create(pair.Value.Item1, effectGroup.Id);

                        foreach (var effect in pair.Value.Item1)
                        {
                            db.Insert(new ShopEffectDto {
                                EffectGroupId = effectGroup.Id, Effect = effect
                            },
                                      statement => statement.AttachToTransaction(transaction));
                        }
                    }

                    #endregion

                    #region Price

                    var priceGroup = new ShopPriceGroupDto
                    {
                        Name      = "PEN",
                        PriceType = (byte)ItemPriceType.PEN
                    };
                    db.Insert(priceGroup, statement => statement.AttachToTransaction(transaction));

                    var price = new ShopPriceDto
                    {
                        PriceGroupId = priceGroup.Id,
                        PeriodType   = (byte)ItemPeriodType.None,
                        IsRefundable = false,
                        Durability   = 1000000,
                        IsEnabled    = true,
                        Price        = 1
                    };
                    db.Insert(price, statement => statement.AttachToTransaction(transaction));

                    #endregion

                    #region Items

                    var items = GameServer.Instance.ResourceCache.GetItems().Values.ToArray();
                    for (var i = 0; i < items.Length; ++i)
                    {
                        var  item        = items[i];
                        var  effectToUse = effects["None"];
                        byte mainTab     = 4;
                        byte subTab      = 1;

                        switch (item.ItemNumber.Category)
                        {
                        case ItemCategory.Weapon:
                            effectToUse = effects["Attack+1%"];
                            mainTab     = 2;

                            switch ((WeaponCategory)item.ItemNumber.SubCategory)
                            {
                            case WeaponCategory.Melee:
                                subTab = 1;
                                break;

                            case WeaponCategory.RifleGun:
                                subTab = 2;
                                break;

                            case WeaponCategory.HeavyGun:
                                subTab = 4;
                                break;

                            case WeaponCategory.Sniper:
                                subTab = 5;
                                break;

                            case WeaponCategory.Sentry:
                                subTab = 6;
                                break;

                            case WeaponCategory.Bomb:
                                subTab = 7;
                                break;

                            case WeaponCategory.Mind:
                                subTab = 6;
                                break;
                            }
                            break;

                        case ItemCategory.Skill:
                            mainTab = 2;
                            subTab  = 8;
                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 0)     // half hp mastery
                            {
                                effectToUse = effects["HP+15"];
                            }

                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 1)     // hp mastery
                            {
                                effectToUse = effects["HP+30"];
                            }

                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 2)     // sp mastery
                            {
                                effectToUse = effects["SP+40"];
                            }

                            if (item.ItemNumber.SubCategory == 0 && item.ItemNumber.Number == 3)     // dual mastery
                            {
                                effectToUse = effects["HP+20 & SP+20"];
                            }

                            break;

                        case ItemCategory.Costume:
                            mainTab = 3;
                            subTab  = (byte)(item.ItemNumber.SubCategory + 2);
                            switch ((CostumeSlot)item.ItemNumber.SubCategory)
                            {
                            case CostumeSlot.Hair:
                                effectToUse = effects["Shooting Weapon Defense (Head) +5%"];
                                break;

                            case CostumeSlot.Face:
                                effectToUse = effects["SP+6"];
                                break;

                            case CostumeSlot.Shirt:
                                effectToUse = effects["Attack+5%"];
                                break;

                            case CostumeSlot.Pants:
                                effectToUse = effects["Defense+5%"];
                                break;

                            case CostumeSlot.Gloves:
                                effectToUse = effects["HP+4"];
                                break;

                            case CostumeSlot.Shoes:
                                effectToUse = effects["HP+4"];
                                break;

                            case CostumeSlot.Accessory:
                                effectToUse = effects["SP+6"];
                                break;

                            case CostumeSlot.Pet:
                                effectToUse = effects["SP+6"];
                                break;
                            }

                            break;

                        default:
                            continue;
                        }

                        var shopItem = new ShopItemDto
                        {
                            Id              = item.ItemNumber,
                            RequiredGender  = (byte)item.Gender,
                            RequiredLicense = (byte)item.License,
                            IsDestroyable   = true,
                            MainTab         = mainTab,
                            SubTab          = subTab
                        };
                        db.Insert(shopItem, statement => statement.AttachToTransaction(transaction));

                        var shopItemInfo = new ShopItemInfoDto
                        {
                            ShopItemId    = shopItem.Id,
                            PriceGroupId  = priceGroup.Id,
                            EffectGroupId = effectToUse.Item2,
                            IsEnabled     = true
                        };
                        db.Insert(shopItemInfo, statement => statement.AttachToTransaction(transaction));

                        Log.Information($"[{i}/{items.Length}] {item.ItemNumber}: {item.Name}");
                    }

                    #endregion

                    try
                    {
                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }