R2G_LiveLikeHandler.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Text.Json;
  2. namespace ET.Server
  3. {
  4. /// <summary>
  5. /// 抖音推送回调, 点赞
  6. /// </summary>
  7. [ActorMessageHandler(SceneType.Game)]
  8. public class R2G_LiveLikeHandler : AMActorHandler<Scene, R2G_LiveLike>
  9. {
  10. protected override async ETTask Run(Scene scene, R2G_LiveLike request)
  11. {
  12. // 房间是否存在
  13. Map map = scene.GetComponent<GameMapComponent>().GetMapByRoomId(request.RoomId);
  14. if (map == null)
  15. {
  16. Log.Debug($"未找到房间...roomId={request.RoomId}");
  17. return;
  18. }
  19. // 数据是否存在
  20. Struct.UnitPlayerData unitPlayerData = map.GetUnitPlayerData(request.OpenId) ?? map.AddUnitPlayer(request.OpenId, 0, 0, request.Likes);
  21. // 累计增加点赞数
  22. unitPlayerData.Likes += request.Likes;
  23. map.TotalLikeNum += request.Likes;
  24. const int configNum = 1000; //到达多少值后,总数量减去这个值,然后继续累加
  25. bool notifyBattleServer = false;
  26. // 点赞总数>=ConfigNum时, 通知战斗服
  27. if (map.TotalLikeNum >= configNum)
  28. {
  29. // 设置总数
  30. map.TotalLikeNum -= configNum;
  31. map.ConfigNum += 1;
  32. notifyBattleServer = true;
  33. }
  34. // 推送客户端
  35. if (map.Player != null)
  36. {
  37. long totalNum = map.ConfigNum * configNum + map.TotalLikeNum;
  38. MessageHelper.SendToClient(map.Player, new G2C_LikeInfoPush{ TotalNum = totalNum, ConfigNum = configNum});
  39. }
  40. if (notifyBattleServer)
  41. {
  42. Struct.TriggerEventNotify notify = new Struct.TriggerEventNotify();
  43. notify.message = BattleNotify.TiktokLike_energy.ToString();
  44. notify.TriggerUnits = unitPlayerData.ObjId.ToString();
  45. map.GetXmdsManager().notifyBattleServer(map.Id.ToString(), NotifyBSName.TriggerEvent, JsonSerializer.Serialize(notify));
  46. }
  47. await ETTask.CompletedTask;
  48. }
  49. }
  50. }