12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using System.Text.Json;
- namespace ET.Server
- {
- /// <summary>
- /// 抖音推送回调, 点赞
- /// </summary>
- [ActorMessageHandler(SceneType.Game)]
- public class R2G_LiveLikeHandler : AMActorHandler<Scene, R2G_LiveLike>
- {
- protected override async ETTask Run(Scene scene, R2G_LiveLike request)
- {
- // 房间是否存在
- Map map = scene.GetComponent<GameMapComponent>().GetMapByRoomId(request.RoomId);
- if (map == null)
- {
- Log.Debug($"未找到房间...roomId={request.RoomId}");
- return;
- }
- // 数据是否存在
- Struct.UnitPlayerData unitPlayerData = map.GetUnitPlayerByOpenId(request.OpenId) ?? map.AddUnitPlayer(request.OpenId, 0, 0, request.Likes);
- // 累计增加点赞数
- unitPlayerData.Likes += request.Likes;
- map.TotalLikeNum += request.Likes;
- // 点赞增加贡献值
- unitPlayerData.ContributeValue += 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;
- }
- }
- }
|