R2G_LiveLikeHandler.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. int[] units = new int[] { 101, 121, 111, 131 };
  25. Vector2 pos = map.GetRandomPlayerPos();
  26. Struct.MonsterUnit unit = new Struct.MonsterUnit();
  27. unit.id = RandomGenerator.RandomArray(units);
  28. unit.force = 1;
  29. unit.x = pos.X;
  30. unit.y = pos.Y;
  31. unit.autoGuard = true;
  32. unit.name = request.NickName;
  33. unit.alias = request.Url;
  34. int objId = await map.AddUnits(unit, true);
  35. unitPlayerData = map.AddUnitPlayer(request.OpenId, unit.id, objId, 0, request.NickName, request.Url);
  36. }
  37. // 累计增加点赞数
  38. unitPlayerData.Likes += request.Likes;
  39. map.TotalLikeNum += request.Likes;
  40. // 点赞增加贡献值
  41. unitPlayerData.ContributeValue += request.Likes;
  42. const int configNum = 1000; //到达多少值后,总数量减去这个值,然后继续累加
  43. bool notifyBattleServer = false;
  44. // 点赞总数>=ConfigNum时, 通知战斗服
  45. if (map.TotalLikeNum >= configNum)
  46. {
  47. // 设置总数
  48. map.TotalLikeNum -= configNum;
  49. map.ConfigNum += 1;
  50. notifyBattleServer = true;
  51. }
  52. // 推送客户端
  53. if (map.Player != null)
  54. {
  55. long totalNum = map.ConfigNum * configNum + map.TotalLikeNum;
  56. MessageHelper.SendToClient(map.Player, new G2C_LikeInfoPush{ TotalNum = totalNum, ConfigNum = configNum});
  57. }
  58. if (notifyBattleServer)
  59. {
  60. Struct.TriggerEventNotify notify = new Struct.TriggerEventNotify();
  61. notify.message = BattleNotify.TiktokLike_energy.ToString();
  62. notify.TriggerUnits = unitPlayerData.ObjId.ToString();
  63. map.GetXmdsManager().notifyBattleServer(map.Id.ToString(), NotifyBSName.TriggerEvent, JsonSerializer.Serialize(notify));
  64. }
  65. await ETTask.CompletedTask;
  66. }
  67. }
  68. }