using System.Text.Json;
namespace ET.Server
{
///
/// 抖音推送回调, 点赞
///
[ActorMessageHandler(SceneType.Game)]
public class R2G_LiveLikeHandler : AMActorHandler
{
protected override async ETTask Run(Scene scene, R2G_LiveLike request)
{
// 房间是否存在
Map map = scene.GetComponent().GetMapByRoomId(request.RoomId);
if (map == null)
{
Log.Debug($"未找到房间...roomId={request.RoomId}");
return;
}
// 数据是否存在
Struct.UnitPlayerData unitPlayerData = map.GetUnitPlayerData(request.OpenId) ?? map.AddUnitPlayer(request.OpenId, 0, 0, request.Likes);
// 累计增加点赞数
unitPlayerData.Likes += request.Likes;
map.TotalLikeNum += request.Likes;
const int configNum = 1000; //到达多少值后,总数量减去这个值,然后继续累加
bool notifyBattleServer = false;
// 点赞总数>=ConfigNum时, 通知战斗服
if (map.TotalLikeNum >= configNum)
{
// 设置总数
map.TotalLikeNum -= configNum;
map.ConfigNum += 1;
notifyBattleServer = true;
}
// 推送客户端
if (map.Player != null)
{
long totalNum = map.ConfigNum * configNum + map.TotalLikeNum;
MessageHelper.SendToClient(map.Player, new G2C_LikeInfoPush{ TotalNum = totalNum, ConfigNum = configNum});
}
if (notifyBattleServer)
{
Struct.TriggerEventNotify notify = new Struct.TriggerEventNotify();
notify.message = BattleNotify.TiktokLike_energy.ToString();
notify.TriggerUnits = unitPlayerData.ObjId.ToString();
map.GetXmdsManager().notifyBattleServer(map.Id.ToString(), NotifyBSName.TriggerEvent, JsonSerializer.Serialize(notify));
}
await ETTask.CompletedTask;
}
}
}