private static void FillShop() { if (!Config.Instance.NoobMode) { return; } using (var db = GameDatabase.Open()) { if (!DbUtil.Find <ShopVersionDto>(db).Any()) { var version = new ShopVersionDto { Version = DateTimeOffset.UtcNow.ToString("yyyyMMddHHmmss") }; DbUtil.Insert(db, version); } if (DbUtil.Find <ShopEffectGroupDto>(db).Any() || DbUtil.Find <ShopEffectDto>(db).Any() || DbUtil.Find <ShopPriceGroupDto>(db).Any() || DbUtil.Find <ShopPriceDto>(db).Any() || DbUtil.Find <ShopItemDto>(db).Any() || DbUtil.Find <ShopItemInfoDto>(db).Any()) { return; } Log.Information("NoobMode: Filling the shop with items"); using (var transaction = DbUtil.BeginTransaction(db)) { 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[] { 1299600001 }, (uint)1299600001) }, { "Attack+3%", Tuple.Create(new uint[] { 1299600002 }, (uint)1299600002) }, { "Attack+5%", Tuple.Create(new uint[] { 1299600003 }, (uint)1299600003) }, { "Attack+8%", Tuple.Create(new uint[] { 1299600005 }, (uint)1299600005) }, { "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 }; DbUtil.Insert(db, effectGroup, statement => statement.AttachToTransaction(transaction)); effects[pair.Key] = Tuple.Create(pair.Value.Item1, (uint)effectGroup.Id); foreach (var effect in pair.Value.Item1) { DbUtil.Insert(db, 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 }; var priceGroup3 = new ShopPriceGroupDto { Name = "AP", PriceType = (byte)ItemPriceType.AP }; DbUtil.Insert(db, priceGroup); DbUtil.Insert(db, priceGroup2); DbUtil.Insert(db, priceGroup3); 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 }; var price_ap_perm = new ShopPriceDto { PriceGroupId = priceGroup3.Id, PeriodType = (byte)ItemPeriodType.None, IsRefundable = true, Durability = 2400, IsEnabled = true, Price = 1 }; DbUtil.Insert(db, price_none_perm); DbUtil.Insert(db, price_unit_one); DbUtil.Insert(db, price_unit_two); DbUtil.Insert(db, price_unit_five); DbUtil.Insert(db, price_unit_ten); DbUtil.Insert(db, price_ap_perm); #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 = 0; byte subTab = 0; bool enabled = true; 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; case OneTimeUseCategory.Set: mainTab = 1; subTab = 7; 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 { 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 }; DbUtil.Insert(db, shopItem, statement => statement.AttachToTransaction(transaction)); var shopItemInfo = new ShopItemInfoDto { ShopItemId = shopItem.Id, PriceGroupId = priceGroup.Id, EffectGroupId = (int)effectToUse.Item2, ShopInfoType = enabled ? (byte)1 : (byte)0, }; var shopItemInfo_onetimeuse = new ShopItemInfoDto { ShopItemId = shopItem.Id, PriceGroupId = priceGroup2.Id, EffectGroupId = (int)effectToUse.Item2, ShopInfoType = enabled ? (byte)1 : (byte)0, }; if (item.ItemNumber.Category == ItemCategory.Costume || item.ItemNumber.Category == ItemCategory.Weapon || item.ItemNumber.Category == ItemCategory.Skill || item.ItemNumber.Category == ItemCategory.EsperChip) { DbUtil.Insert(db, shopItemInfo, statement => statement.AttachToTransaction(transaction)); } else { DbUtil.Insert(db, shopItemInfo_onetimeuse, statement => statement.AttachToTransaction(transaction)); } Log.Information($"[{i}/{items.Length}] {item.ItemNumber}: {item.Name} | Colors: {item.Colors}"); } #endregion var itemInfos = DbUtil.Find <ShopItemInfoDto>(db, statement => statement .Include <ShopItemDto>(join => join.LeftOuterJoin()) .AttachToTransaction(transaction)); var caps = GameServer.Instance.ResourceCache._loader.GetWorkingCapsules(); foreach (var item in items.Where(x => x.ItemNumber.Category == ItemCategory.OneTimeUse)) { var itemInfo = itemInfos.FirstOrDefault(x => x.ShopItemId == item.ItemNumber); if (itemInfo != null) { if (!caps.Contains(item.ItemNumber)) { itemInfo.ShopInfoType = 0; DbUtil.Update(db, itemInfo, statement => statement.AttachToTransaction(transaction)); } } } try { transaction.Commit(); } catch { transaction.Rollback(); throw; } } } }
internal void Save(IDbConnection db) { var deleteMapping = OrmConfiguration .GetDefaultEntityMapping <PlayerMailDto>() .Clone() .UpdatePropertiesExcluding(prop => prop.IsExcludedFromUpdates = true, nameof(PlayerMailDto.IsMailDeleted)); if (!_mailsToDelete.IsEmpty) { var idsToRemove = new StringBuilder(); var firstRun = true; while (_mailsToDelete.TryPop(out var mailToDelete)) { if (firstRun) { firstRun = false; } else { idsToRemove.Append(','); } idsToRemove.Append(mailToDelete.Id); } DbUtil.BulkUpdate(db, new PlayerMailDto { IsMailDeleted = true }, statement => statement .Where($"{nameof(PlayerMailDto.Id):C} IN ({idsToRemove})") .WithEntityMappingOverride(deleteMapping)); } var isNewMapping = OrmConfiguration .GetDefaultEntityMapping <PlayerMailDto>() .Clone() .UpdatePropertiesExcluding(prop => prop.IsExcludedFromUpdates = true, nameof(PlayerMailDto.IsMailNew)); var needsSave = _mails.Values.Where(mail => mail.NeedsToSave).ToArray(); var isNew = needsSave.Where(mail => mail.IsNew); var isNotNew = needsSave.Where(mail => !mail.IsNew); var enumerable = isNew as Mail[] ?? isNew.ToArray(); if (enumerable.Any()) { DbUtil.BulkUpdate(db, new PlayerMailDto { IsMailNew = true }, statement => statement .Where($"{nameof(PlayerMailDto.Id):C} IN ({string.Join(",", enumerable.Select(x => x.Id))})") .WithEntityMappingOverride(isNewMapping)); foreach (var mail in enumerable) { mail.NeedsToSave = false; } } var notNew = isNotNew as Mail[] ?? isNotNew.ToArray(); if (notNew.Any()) { DbUtil.BulkUpdate(db, new PlayerMailDto { IsMailNew = false }, statement => statement .Where($"{nameof(PlayerMailDto.Id):C} IN ({string.Join(",", notNew.Select(x => x.Id))})") .WithEntityMappingOverride(isNewMapping)); foreach (var mail in notNew) { mail.NeedsToSave = false; } } }