123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using System.Numerics;
- 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);
- if (unitPlayerData == null)
- {
- int[] units = new int[] { 101, 121, 111, 131 };
- Vector2 pos = map.GetRandomPlayerPos();
- Struct.MonsterUnit unit = new Struct.MonsterUnit();
- unit.id = RandomGenerator.RandomArray(units);
- unit.force = 1;
- unit.x = pos.X;
- unit.y = pos.Y;
- unit.autoGuard = true;
- unit.name = request.NickName;
- unit.alias = request.Url;
- int objId = await map.AddUnits(unit, true);
- unitPlayerData = map.AddUnitPlayer(request.OpenId, unit.id, objId, 0, request.NickName, request.Url);
- }
- // 累计增加点赞数
- 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;
- }
- }
- }
|