초기커밋
This commit is contained in:
132
GameServer/Ticker/ShopProductCheckTicker.cs
Normal file
132
GameServer/Ticker/ShopProductCheckTicker.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
|
||||
public class ShopProductCheckTicker : EntityTicker
|
||||
{
|
||||
private Dictionary<int, Timestamp?> m_shop { get; set; } = new();
|
||||
|
||||
public ShopProductCheckTicker(double onTickIntervalMilliseconds, CancellationTokenSource? cts)
|
||||
: base(EntityType.ShopProductCheckTicker, onTickIntervalMilliseconds, cts)
|
||||
{
|
||||
foreach (var shop in ShopHelper.getShopMetaData())
|
||||
{
|
||||
var end_time = ShopHelper.calculateSaleEndTime(shop.ResetTime);
|
||||
m_shop.Add(shop.Id, end_time);
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task onTaskTick()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
Stopwatch? stopwatch = null;
|
||||
var event_tid = string.Empty;
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
var server_config = server_logic.getServerConfig();
|
||||
|
||||
if (true == server_config.PerformanceCheckEnable)
|
||||
{
|
||||
event_tid = System.Guid.NewGuid().ToString("N");
|
||||
stopwatch = Stopwatch.StartNew();
|
||||
}
|
||||
|
||||
// 1. reset 상점 ids list 조회
|
||||
var reset_shop_ids = checkShopEndTime();
|
||||
if (!reset_shop_ids.Any()) return;
|
||||
|
||||
// 2. 유저의 상점 정보 체크
|
||||
foreach (var each in server_logic.getPlayerManager().getUsers())
|
||||
{
|
||||
var player = each.Value;
|
||||
|
||||
var user_create_or_load_action = player.getEntityAction<UserCreateOrLoadAction>();
|
||||
|
||||
if (false == user_create_or_load_action.isCompletedLoadUser())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
checkShopReset(player, reset_shop_ids.ToList());
|
||||
}
|
||||
|
||||
if (null != stopwatch)
|
||||
{
|
||||
var elapsed_msec = stopwatch.ElapsedMilliseconds;
|
||||
stopwatch.Stop();
|
||||
Log.getLogger().debug($"{GetType()} Ticker Stopwatch Stop : ETID:{event_tid}, ElapsedMSec:{elapsed_msec}, TickIntervalMSec:{getOnTickIntervalMilliseconds()}");
|
||||
}
|
||||
}
|
||||
|
||||
public override string toBasicString()
|
||||
{
|
||||
return $"{this.getTypeName()}";
|
||||
}
|
||||
|
||||
public override string toSummaryString()
|
||||
{
|
||||
return $"{this.getTypeName()}";
|
||||
}
|
||||
|
||||
private IEnumerable<int> checkShopEndTime()
|
||||
{
|
||||
var list = new List<int>(m_shop.Count);
|
||||
foreach (var shop in m_shop)
|
||||
{
|
||||
if (shop.Value == null) continue;
|
||||
if (shop.Value > DateTime.UtcNow.ToTimestamp()) continue;
|
||||
|
||||
var new_end_time = newEndTime(shop.Key);
|
||||
if (new_end_time == null) continue;
|
||||
|
||||
m_shop[shop.Key] = new_end_time;
|
||||
list.Add(shop.Key);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private static Timestamp? newEndTime(int shop_id)
|
||||
{
|
||||
var shop_table = ShopHelper.checkShopIdFromTableData(shop_id);
|
||||
if (shop_table.result.isFail() || shop_table.shop_data == null) return null;
|
||||
|
||||
return ShopHelper.calculateSaleEndTime(shop_table.shop_data.ResetTime);
|
||||
}
|
||||
|
||||
private static void checkShopReset(Player player, IReadOnlyList<int> shop_ids)
|
||||
{
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
var shop_action = player.getEntityAction<ShopAction>();
|
||||
|
||||
var message = new ClientToGame();
|
||||
message.Message = new();
|
||||
message.Message.NtfShopProductChange = new();
|
||||
|
||||
foreach (var shop in shop_action.getMyShopProducts())
|
||||
{
|
||||
var attribute = shop.getEntityAttribute<ShopProductTradingMeterAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(attribute, () => $"attribute is null !!!");
|
||||
|
||||
if (!shop_ids.Contains(attribute.ShopId)) continue;
|
||||
|
||||
message.Message.NtfShopProductChange.ShopId = attribute.ShopId;
|
||||
server_logic.onSendPacket(player, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user