using Cal.DataTable; using System; namespace ET { [ActorMessageHandler] public class C2M_StartPKFightHandler : AMActorLocationRpcHandler { protected override async ETTask Run(Unit unit, C2M_StartPKFight request, M2C_StartPKFight response, Action reply) { if (!unit.IsTeamLeader) { response.Message = "您不是队长!"; reply(); return; } Unit targetUnit = MapUnitComponent.Instance.Get(request.TargetId); if (targetUnit == null) { response.Message = "对方不在线!"; reply(); return; } if (unit.TeamLeaderId == targetUnit.TeamLeaderId) { response.Message = "不能跟队友PK"; reply(); return; } Team team = TeamComponent.Instance.Get(unit.TeamLeaderId); if (team.TeamState == TeamState.Fight) { Log.Error($"*【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】多次进行PK战斗"); response.Message = "系统错误"; reply(); return; } Team targetTeam = TeamComponent.Instance.Get(targetUnit.TeamLeaderId); if (targetTeam.TeamState == TeamState.Fight) { response.Message = "对方在战斗中"; reply(); return; } Unit targetLeader = targetTeam.GetLeader(); if (targetLeader.isAI) { response.Message = "对方跑图中,请勿打扰!"; reply(); return; } UnitScene unitScene = unit.GetComponent(); UnitSceneType unitSceneType = MapSceneComponent.Instance.GetUnitSceneType(unitScene.MapId / 100); if(unitSceneType == UnitSceneType.PersonalPvp) { response.Message = "竞技场禁止自由战斗!"; reply(); return; } if (unitScene.MapId / 100 == Sys_SceneId.Scene_MainCity) { response.Message = "城镇禁止斗殴!"; reply(); return; } if ((unitScene.Position - targetUnit.GetComponent().Position).sqrMagnitude > MoveHelper.AtkDis) { Log.Error($"*【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】位置{unit.GetComponent().Position}错误"); response.Message = "系统错误"; reply(); return; } PKBattle battle = BattleMgrCompnent.Instance.CreateBattle(team); battle.Init(targetTeam); reply(); await ETTask.CompletedTask; } } }