zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Server/Hotfix/Game/Handler/Map/C2M_RequestEnterMapHandler.cs

208 lines
7.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using ET;
using Cal.DataTable;
using System;
using System.Net;
namespace ET
{
using System;
using Cal.DataTable;
using ET;
using ET.EventType;
using UnityEngine;
[ActorMessageHandler]
public class C2M_RequestEnterMapHandler : AMActorLocationRpcHandler<Unit, C2M_RequestEnterMap, M2C_RequestEnterMap>
{
protected override async ETTask Run(Unit unit, C2M_RequestEnterMap message, M2C_RequestEnterMap response, Action reply)
{
if (unit.isAI)
{
reply();
return;
}
if (!unit.IsTeamLeader)
{
response.Message = "您不是队长,不能切换地图!";
reply();
return;
}
UnitScene unitScene = unit.GetComponent<UnitScene>();
Sys_Scene currSceneInfo = MapSceneComponent.Instance.GetMapInfo(unitScene.MapId / 100);
int targetSceneId = message.MapId / 100;
int targetMapLayer = message.MapId % 100;
bool isPosWoring = true;
for (int j = 0; j < currSceneInfo.TransPosArr.Length; j++)
{
Sys_Scene.TransPos posInfo = currSceneInfo.TransPosArr[j];
if (posInfo != null)
{
Vector2 val = unitScene.Position - new Vector2(posInfo.TransPos_x, posInfo.TransPos_y);
if (val.sqrMagnitude <= MoveHelper.AtkDis)
{
isPosWoring = false;
}
}
}
if (isPosWoring)
{
Log.Error($"*【{UserComponent.Instance.Get(unit.Id)?.NickName} ({unit.Id})】传送时位置{unitScene.Position}错误");
response.Message = "系统错误";
reply();
return;
}
Sys_Scene targetSceneInfo = MapSceneComponent.Instance.GetMapInfo(targetSceneId);
if (targetSceneInfo.Layers < targetMapLayer)
{
response.Message = "进入层数不对!";
reply();
return;
}
if (unit.teamState == TeamState.Fight)
{
response.Message = "战斗状态!";
reply();
return;
}
PlayerData data = unit.GetComponent<PlayerData>();
if ((bool)data && data.IsBattleIdle)
{
response.Message = "挂机状态!";
reply();
return;
}
bool canEnter = false;
for (int i = 0; i < currSceneInfo.TargetMapArr.Length; i++)
{
Sys_Scene.TargetMap targetMap = currSceneInfo.TargetMapArr[i];
if (targetSceneId == unitScene.MapId / 100 && targetMapLayer - unitScene.MapId % 100 == 1)
{
canEnter = true;
break;
}
if (targetSceneId != targetMap.TargetMap_Id)
{
continue;
}
if (targetSceneId == Sys_SceneId.Scene_Boss && BossComponent.Instance.bossInfoDic.ContainsKey(targetMapLayer))
{
canEnter = true;
break;
}
else if (targetMapLayer == 1)
{
canEnter = true;
break;
}
}
if (!canEnter)
{
response.Message = "不能进入此地图";
reply();
return;
}
int targetMapId = message.MapId;
Team team = TeamComponent.Instance.Get(unit.TeamLeaderId);
if (team == null)
{
Log.Error(" team == null");
}
ChangeMap a;
switch (MapSceneComponent.Instance.GetUnitSceneType(targetMapId / 100))
{
case UnitSceneType.MainStory:
foreach (Unit item in team.GetUnits())
{
canEnter = canEnter && item.GetComponent<PlayerData>().CanEnterMianStory(targetMapId / 100);
}
if (!canEnter)
{
response.Message = "队伍中有人未通关上一关卡,不能进入!";
reply();
return;
}
break;
case UnitSceneType.Trial:
{
if (team.MemberCount > 1)
{
response.Message = "不能进入,试炼之地只能单人挑战!";
reply();
return;
}
int mapId;
string trialRet = PlayerDataSystem.GetTrialLayer( self: unit.GetComponent<PlayerData>(), sceneId: targetMapId/100,mapId: out mapId);
if (trialRet != null)
{
response.Message = trialRet;
reply();
return;
}
targetMapId = mapId;
break;
}
case UnitSceneType.Boss:
{
BossComponent.BossState state = BossComponent.Instance.GetState(targetMapLayer);
if (state == BossComponent.BossState.Idle)
{
SendBossRefresh(unit, targetMapLayer).Coroutine();
}
break;
}
case UnitSceneType.PersonalPvp:
if (team.MemberCount > 1)
{
response.Message = "此地图不能组队!";
reply();
return;
}
if (!PvpMap.inatance.CanEnterPvpMap(data, targetMapId))
{
response.Message = "积分不足,无法进入!";
reply();
return;
}
break;
case UnitSceneType.ManulEquip:
{
if (!ManulEquipMap.instance.CanEnterMap(data, targetMapId))
{
response.Message = "无法进入,请先击杀当前关卡boss";
reply();
return;
}
reply();
EventSystem eventSystem = Game.EventSystem;
a = new ChangeMap
{
unit = unit,
mapId = targetMapId
};
await eventSystem.Publish(a);
await ManulEquipMap.instance.EnterMap(data, targetMapId);
return;
}
}
reply();
EventSystem eventSystem2 = Game.EventSystem;
a = new ChangeMap
{
unit = unit,
mapId = targetMapId
};
eventSystem2.Publish(a).Coroutine();
}
private async ETVoid SendBossRefresh(Unit unit, int targetMapLayer)
{
await TimerComponent.Instance.WaitAsync(1000L);
MessageHelper.SendActor(unit, new M2C_BossRefresh
{
BossId = BossComponent.Instance.GetBossId(targetMapLayer)
});
}
}
}