diff --git a/Server/SQL/ResetShopItem.cs b/Server/SQL/ResetShopItem.cs index 69b5093..9f17ab3 100644 --- a/Server/SQL/ResetShopItem.cs +++ b/Server/SQL/ResetShopItem.cs @@ -33,7 +33,7 @@ namespace Server.SQL public override List SelectUid(long user_id) { //현재 시간도 비교해서 이전날자가 들어가지 않게 하기 - return table.Where(data => data.user_id == user_id).ToList(); + return table.Where(data => data.user_id == user_id && data.end_date > DateTime.UtcNow).ToList(); } } } diff --git a/Server/Service/Login.cs b/Server/Service/Login.cs index f9a0a45..1787102 100644 --- a/Server/Service/Login.cs +++ b/Server/Service/Login.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json; using Server.SQL; using Server.Manager; using Microsoft.AspNetCore.DataProtection.KeyManagement; +using System.Collections.Generic; namespace Server.Service { @@ -91,8 +92,160 @@ namespace Server.Service #endregion } #endregion + #region 리셋 상점 세팅 + List resetShopItem = Statics.resetShopItemSQL.SelectUid(user.id); + List addItem = new List(); + List shopItemData = null; + Random rand = new Random(); + if (resetShopItem.FindIndex(data => data.shop_index == 10001) == -1) + { + //일일 상품 추가 + if (shopItemData == null) + shopItemData = Statics.resetShopItemExcel.getResetShopItemData(); + List < ResetShopItemData > shopList = new List(); + foreach(var item in shopItemData) + { + if(item.shop_index == 10001) + { + shopList.Add(item); + } + } + int count = shopList[0].buy_count; + DateTime saveDate = DateTime.UtcNow.AddDays(1); - return makeResp(user, dynamicDataList, deckInfoList, itemManager, newUser); + for (int n = 0; n < count; n++) + { + int select = rand.Next(0, shopList.Count); + int index = addItem.FindIndex(data => data.reset_shop_item_data_id == shopList[select].index); + if (index != -1) + { + addItem[index].count++; + } + else + { + ResetShopItem newShopItem = new ResetShopItem(); + newShopItem.user_id = user.id; + newShopItem.reset_shop_item_data_id = shopList[select].index; + newShopItem.name = shopList[select].name; + newShopItem.shop_index = shopList[select].shop_index; + newShopItem.buy_type = shopList[select].buy_type; + newShopItem.buy = shopList[select].buy; + newShopItem.reward = shopList[select].reward; + newShopItem.buy_count = shopList[select].buy_count; + newShopItem.count = 1; + newShopItem.end_date = saveDate; + addItem.Add(newShopItem); + } + } + } + if (resetShopItem.FindIndex(data => data.shop_index == 10002) == -1) + { + //주간 상품 추가 + if (shopItemData == null) + shopItemData = Statics.resetShopItemExcel.getResetShopItemData(); + List shopList = new List(); + foreach (var item in shopItemData) + { + if (item.shop_index == 10002) + { + shopList.Add(item); + } + } + int count = shopList[0].buy_count; + + DateTime today = DateTime.UtcNow;//Saturday + int daysUntilNext = ((int)DayOfWeek.Wednesday - (int)today.DayOfWeek + 7) % 7; + DateTime saveDate = today.AddDays(daysUntilNext); + + for (int n = 0; n < count; n++) + { + int select = rand.Next(0, shopList.Count); + int index = addItem.FindIndex(data => data.reset_shop_item_data_id == shopList[select].index); + if (index != -1) + { + addItem[index].count++; + } + else + { + ResetShopItem newShopItem = new ResetShopItem(); + newShopItem.user_id = user.id; + newShopItem.reset_shop_item_data_id = shopList[select].index; + newShopItem.name = shopList[select].name; + newShopItem.shop_index = shopList[select].shop_index; + newShopItem.buy_type = shopList[select].buy_type; + newShopItem.buy = shopList[select].buy; + newShopItem.reward = shopList[select].reward; + newShopItem.buy_count = shopList[select].buy_count; + newShopItem.count = 1; + newShopItem.end_date = saveDate; + addItem.Add(newShopItem); + } + } + + } + if (resetShopItem.FindIndex(data => data.shop_index == 10003) == -1) + { + //월간 상품 추가 + if (shopItemData == null) + shopItemData = Statics.resetShopItemExcel.getResetShopItemData(); + List shopList = new List(); + foreach (var item in shopItemData) + { + if (item.shop_index == 10003) + { + shopList.Add(item); + } + } + int count = shopList[0].buy_count; + + DateTime today = DateTime.UtcNow; + int year = today.Year; + int month = today.Month; + if (month == 12) + { + year++; + month = 1; + } + else + { + month++; + } + DateTime saveDate = new DateTime(year, month, 1, 0, 0, 0, DateTimeKind.Utc); + + for (int n = 0; n < count; n++) + { + int select = rand.Next(0, shopList.Count); + int index = addItem.FindIndex(data => data.reset_shop_item_data_id == shopList[select].index); + if (index != -1) + { + addItem[index].count++; + } + else + { + ResetShopItem newShopItem = new ResetShopItem(); + newShopItem.user_id = user.id; + newShopItem.reset_shop_item_data_id = shopList[select].index; + newShopItem.name = shopList[select].name; + newShopItem.shop_index = shopList[select].shop_index; + newShopItem.buy_type = shopList[select].buy_type; + newShopItem.buy = shopList[select].buy; + newShopItem.reward = shopList[select].reward; + newShopItem.buy_count = shopList[select].buy_count; + newShopItem.count = 1; + newShopItem.end_date = saveDate; + addItem.Add(newShopItem); + } + } + } + if(addItem.Count != 0) + { + Statics.resetShopItemSQL.Insert(addItem); + Statics.resetShopItemSQL.SaveChanges(); + resetShopItem.AddRange(addItem); + } + #endregion + + return makeResp(user, dynamicDataList, deckInfoList, itemManager, newUser, resetShopItem); } public override Protocol ProtocolValue() => Protocol.Login; @@ -103,7 +256,7 @@ namespace Server.Service return req; } - private string makeResp(User user, List dynamicData, List deckInfo, ItemManager itemManager, bool newUser) + private string makeResp(User user, List dynamicData, List deckInfo, ItemManager itemManager, bool newUser, List resetShopItem) { LoginResp resp = new LoginResp(); resp.nickname = user.nickname; @@ -115,8 +268,9 @@ namespace Server.Service resp.deck_unit = itemManager.box.deckUnitInfo; resp.deck_info = deckInfo; resp.equipment = itemManager.box.equipment; - resp.consumableItem = itemManager.box.consumableItem; - resp.etcItem = itemManager.box.etcItem; + resp.consumable_item = itemManager.box.consumableItem; + resp.etc_item = itemManager.box.etcItem; + resp.reset_shop_item = resetShopItem; resp.status = 200; return resp.ToJson(); } @@ -147,7 +301,8 @@ namespace Server.Service public List deck_unit; public List deck_info; public List equipment; - public List consumableItem; - public List etcItem; + public List consumable_item; + public List etc_item; + public List reset_shop_item; } } diff --git a/Server/System/Statics.cs b/Server/System/Statics.cs index 43fa693..6f9c128 100644 --- a/Server/System/Statics.cs +++ b/Server/System/Statics.cs @@ -19,6 +19,8 @@ namespace Server.System public static readonly string PATTERN = "[^a-zA-Z0-9가-힣 ]"; + public static readonly TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById("Korea Standard Time"); + //SQL public static DeckInfoSQL deckInfoSQL = new DeckInfoSQL(); public static DeckUnitInfoSQL deckUnitInfoSQL = new DeckUnitInfoSQL(); @@ -27,6 +29,7 @@ namespace Server.System public static DynamicDataSQL dynamicDataSQL = new DynamicDataSQL(); public static ConsumableItemSQL consumableItemSQL = new ConsumableItemSQL(); public static EtcItemSQL etcItemSQL = new EtcItemSQL(); + public static ResetShopItemSQL resetShopItemSQL = new ResetShopItemSQL(); //DATA public static EquipmentDataExcel equipmentExcel = new EquipmentDataExcel();