zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Server/Hotfix/Game/Handler/Battle/Common/C2M_StartBossFightRequestHa...

94 lines
3.8 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using Cal.DataTable;
using System;
2021-04-11 19:50:39 +08:00
using System.Collections.Generic;
2021-04-08 20:09:59 +08:00
namespace ET
{
[ActorMessageHandler]
public class C2M_StartBossFightRequestHandler : AMActorLocationRpcHandler<Unit, C2M_StartBossFightRequest, M2C_StartBossFightRequest>
{
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<UnitScene>();
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;
}
2021-04-11 19:50:39 +08:00
BossComponent.BossState state = BossComponent.Instance.GetState(mapLayer);
2021-04-08 20:09:59 +08:00
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);
2021-04-11 19:50:39 +08:00
LinkedList<Unit> teamList = team.GetUnits();
foreach (Unit u in teamList)
2021-04-08 20:09:59 +08:00
{
2021-04-11 19:50:39 +08:00
PlayerData data = u.GetComponent<PlayerData>();
2021-04-08 20:09:59 +08:00
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;
}
}
}