using Cal.DataTable; using System; using System.Collections.Generic; namespace ET { [ActorMessageHandler] public class C2M_StartBossFightRequestHandler : AMActorLocationRpcHandler { private const int moveTimeToStartBoss = 3 * 1000; protected override async ETTask Run(Unit unit, C2M_StartBossFightRequest request, M2C_StartBossFightRequest response, Action reply) { try { if (!unit.IsTeamLeader) { response.Message = "您不是队长!"; reply(); return; } UnitScene unitScene = unit.GetComponent(); if (TimeHelper.ClientNow() - unitScene.enterTime < moveTimeToStartBoss) { Log.Error($"*【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】挑战Boss时间错误,进入了{TimeHelper.ClientNow() - unitScene.enterTime}"); response.Message = "系统错误"; reply(); return; } if (unitScene.Position.x < -1) { Log.Error($"*【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】挑战Boss位置{unitScene.Position}错误"); response.Message = "系统错误"; reply(); return; } int sceneId = unitScene.MapId / 100; int mapLayer = unitScene.MapId % 100; if (sceneId != Sys_SceneId.Scene_Boss) { Log.Error($"*【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】挑战Boss场景{sceneId}错误"); response.Message = "系统错误"; reply(); return; } BossComponent.BossState state = BossComponent.Instance.GetState(mapLayer); if (state == default) { Log.Error($"*【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】挑战Boss层数{mapLayer}错误"); response.Message = "系统错误"; reply(); return; } if (state == BossComponent.BossState.Dead) { response.Message = "Boss已被击败"; reply(); return; } else if (state == BossComponent.BossState.Battle) { response.Message = "Boss正在挑战中"; reply(); return; } Team team = TeamComponent.Instance.Get(unit.TeamLeaderId); LinkedList teamList = team.GetUnits(); foreach (Unit u in teamList) { PlayerData data = u.GetComponent(); if (data == null) { Log.Error($"data == null where id = {u?.Id}"); continue; } if (data.bossEnergy <= 0) { response.Message = "您的或者队友的Boss行动值不够"; reply(); return; } } response.Key = Game.IdGenerater.GenerateId(); BossComponent.Instance.keyDic[unit.Id] = (response.Key,mapLayer); reply(); } catch (Exception e) { Log.Error(e); } await ETTask.CompletedTask; } } }