R2G_LiveLikeHandler.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.GetUnitPlayerByOpenId(request.OpenId) ?? map.AddUnitPlayer(request.OpenId, 0, 0, request.Likes);
  21. // 累计增加点赞数
  22. unitPlayerData.Likes += request.Likes;
  23. map.TotalLikeNum += request.Likes;
  24. // 点赞增加贡献值
  25. unitPlayerData.ContributeValue += request.Likes;
  26. const int configNum = 1000; //到达多少值后,总数量减去这个值,然后继续累加
  27. bool notifyBattleServer = false;
  28. // 点赞总数>=ConfigNum时, 通知战斗服
  29. if (map.TotalLikeNum >= configNum)
  30. {
  31. // 设置总数
  32. map.TotalLikeNum -= configNum;
  33. map.ConfigNum += 1;
  34. notifyBattleServer = true;
  35. }
  36. // 推送客户端
  37. if (map.Player != null)
  38. {
  39. long totalNum = map.ConfigNum * configNum + map.TotalLikeNum;
  40. MessageHelper.SendToClient(map.Player, new G2C_LikeInfoPush{ TotalNum = totalNum, ConfigNum = configNum});
  41. }
  42. if (notifyBattleServer)
  43. {
  44. Struct.TriggerEventNotify notify = new Struct.TriggerEventNotify();
  45. notify.message = BattleNotify.TiktokLike_energy.ToString();
  46. notify.TriggerUnits = unitPlayerData.ObjId.ToString();
  47. map.GetXmdsManager().notifyBattleServer(map.Id.ToString(), NotifyBSName.TriggerEvent, JsonSerializer.Serialize(notify));
  48. }
  49. await ETTask.CompletedTask;
  50. }
  51. }
  52. }