R2G_LiveLikeHandler.cs 2.2 KB

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