매주 데일리 상점 세팅

This commit is contained in:
김판돌 2024-03-14 21:24:33 +09:00
parent 844cf559aa
commit 0363153f5a
3 changed files with 165 additions and 7 deletions

View File

@ -33,7 +33,7 @@ namespace Server.SQL
public override List<ResetShopItem> SelectUid(long user_id) public override List<ResetShopItem> 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();
} }
} }
} }

View File

@ -3,6 +3,7 @@ using Newtonsoft.Json;
using Server.SQL; using Server.SQL;
using Server.Manager; using Server.Manager;
using Microsoft.AspNetCore.DataProtection.KeyManagement; using Microsoft.AspNetCore.DataProtection.KeyManagement;
using System.Collections.Generic;
namespace Server.Service namespace Server.Service
{ {
@ -91,8 +92,160 @@ namespace Server.Service
#endregion #endregion
} }
#endregion #endregion
#region
List<ResetShopItem> resetShopItem = Statics.resetShopItemSQL.SelectUid(user.id);
List<ResetShopItem> addItem = new List<ResetShopItem>();
List<ResetShopItemData> 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<ResetShopItemData>();
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<ResetShopItemData> shopList = new List<ResetShopItemData>();
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<ResetShopItemData> shopList = new List<ResetShopItemData>();
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; public override Protocol ProtocolValue() => Protocol.Login;
@ -103,7 +256,7 @@ namespace Server.Service
return req; return req;
} }
private string makeResp(User user, List<DynamicData> dynamicData, List<DeckInfo> deckInfo, ItemManager itemManager, bool newUser) private string makeResp(User user, List<DynamicData> dynamicData, List<DeckInfo> deckInfo, ItemManager itemManager, bool newUser, List<ResetShopItem> resetShopItem)
{ {
LoginResp resp = new LoginResp(); LoginResp resp = new LoginResp();
resp.nickname = user.nickname; resp.nickname = user.nickname;
@ -115,8 +268,9 @@ namespace Server.Service
resp.deck_unit = itemManager.box.deckUnitInfo; resp.deck_unit = itemManager.box.deckUnitInfo;
resp.deck_info = deckInfo; resp.deck_info = deckInfo;
resp.equipment = itemManager.box.equipment; resp.equipment = itemManager.box.equipment;
resp.consumableItem = itemManager.box.consumableItem; resp.consumable_item = itemManager.box.consumableItem;
resp.etcItem = itemManager.box.etcItem; resp.etc_item = itemManager.box.etcItem;
resp.reset_shop_item = resetShopItem;
resp.status = 200; resp.status = 200;
return resp.ToJson(); return resp.ToJson();
} }
@ -147,7 +301,8 @@ namespace Server.Service
public List<DeckUnitInfo> deck_unit; public List<DeckUnitInfo> deck_unit;
public List<DeckInfo> deck_info; public List<DeckInfo> deck_info;
public List<Equipment> equipment; public List<Equipment> equipment;
public List<ConsumableItem> consumableItem; public List<ConsumableItem> consumable_item;
public List<EtcItem> etcItem; public List<EtcItem> etc_item;
public List<ResetShopItem> reset_shop_item;
} }
} }

View File

@ -19,6 +19,8 @@ namespace Server.System
public static readonly string PATTERN = "[^a-zA-Z0-9가-힣 ]"; public static readonly string PATTERN = "[^a-zA-Z0-9가-힣 ]";
public static readonly TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById("Korea Standard Time");
//SQL //SQL
public static DeckInfoSQL deckInfoSQL = new DeckInfoSQL(); public static DeckInfoSQL deckInfoSQL = new DeckInfoSQL();
public static DeckUnitInfoSQL deckUnitInfoSQL = new DeckUnitInfoSQL(); public static DeckUnitInfoSQL deckUnitInfoSQL = new DeckUnitInfoSQL();
@ -27,6 +29,7 @@ namespace Server.System
public static DynamicDataSQL dynamicDataSQL = new DynamicDataSQL(); public static DynamicDataSQL dynamicDataSQL = new DynamicDataSQL();
public static ConsumableItemSQL consumableItemSQL = new ConsumableItemSQL(); public static ConsumableItemSQL consumableItemSQL = new ConsumableItemSQL();
public static EtcItemSQL etcItemSQL = new EtcItemSQL(); public static EtcItemSQL etcItemSQL = new EtcItemSQL();
public static ResetShopItemSQL resetShopItemSQL = new ResetShopItemSQL();
//DATA //DATA
public static EquipmentDataExcel equipmentExcel = new EquipmentDataExcel(); public static EquipmentDataExcel equipmentExcel = new EquipmentDataExcel();