1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using System.Text.Json;
- namespace ET.Server
- {
- /// <summary>
- /// 抖音api http回调, 点赞10次增加等级
- /// </summary>
- [ActorMessageHandler(SceneType.Game)]
- public class R2G_AddLevelHandler : AMActorHandler<Scene, R2G_AddLevel>
- {
- protected override async ETTask Run(Scene scene, R2G_AddLevel request)
- {
- // 房间是否存在
- Map map = scene.GetComponent<GameMapComponent>().GetMapByRoomId(request.RoomId);
- if (map == null)
- {
- Log.Debug($"未找到房间...roomId={request.RoomId}");
- return;
- }
- // 数据是否存在
- Struct.UnitPlayerData unitPlayerData = map.GetUnitPlayerData(request.OpenId) ?? map.AddUnitPlayer(request.OpenId, 0, 0, request.Likes);
- // 累计增加点赞数
- unitPlayerData.Likes += request.Likes;
- map.TotalLikeNum += request.Likes;
- int initialLevel = 1; // 初始等级
- int maxLevel = 3; // 等级上限
- int configNum = 1000; //到达多少值后,总数量减去这个值,然后继续累加
- int level = initialLevel; // 玩家等级
- long levelUpCount = unitPlayerData.Likes / 10; // 计算升级次数
- // 根据升级次数更新等级
- for (long i = 0; i < levelUpCount; i++)
- {
- level++; // 等级加1
- // 如果等级超过上限,将等级设置为上限
- if (level > maxLevel)
- {
- level = maxLevel;
- break;
- }
- }
- // 模板id
- int oldTemplateId = unitPlayerData.TemplateId;
- int newTemplateId = ((oldTemplateId / 10) * 10) + level;
- if (oldTemplateId != newTemplateId)
- {
- // 当前战斗服objId
- int curObjId = unitPlayerData.ObjId;
- // 移除原单位
- await map.RemovePointUnit(curObjId);
- string[] pos = map.GetCurXY().Split(";");
- Struct.MonsterUnit unit = new Struct.MonsterUnit();
- unit.id = newTemplateId;
- unit.force = 1;
- unit.x = int.Parse(pos[0]);
- unit.y = int.Parse(pos[1]);
- unit.autoGuard = true;
- curObjId = await map.AddUnits(unit, true);
- map.AddUnitPlayer(request.OpenId, newTemplateId, curObjId, unitPlayerData.Likes);
- }
- // 推送客户端
- if (map.Player != null)
- {
- MessageHelper.SendToClient(map.Player, new G2C_LikeInfoPush{ TotalNum = map.TotalLikeNum, ConfigNum = configNum});
- }
- // 点赞>=ConfigNum时, 通知战斗服
- if (map.TotalLikeNum >= configNum)
- {
- 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;
- }
- }
- }
|