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

88 lines
3.5 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using Cal.DataTable;
using NLog.Internal;
using System;
2021-04-11 19:50:39 +08:00
using System.Collections.Generic;
2021-04-08 20:09:59 +08:00
using System.Text;
namespace ET
{
[ActorMessageHandler]
public class C2M_StartBossFightHandler : AMActorLocationRpcHandler<Unit, C2M_StartBossFight, M2C_StartBossFight>
{
protected override async ETTask Run(Unit unit, C2M_StartBossFight request, M2C_StartBossFight response, Action reply)
{
try
{
2021-04-11 19:50:39 +08:00
Dictionary<long, (long, int)> dic = BossComponent.Instance.keyDic;
if (!dic.TryGetValue(unit.Id, out (long, int) key))
2021-04-08 20:09:59 +08:00
{
response.Message = "系统错误";
reply();
return;
}
dic.Remove(unit.Id);
2021-04-11 19:50:39 +08:00
byte[] bytes = BitConverter.GetBytes(request.Key);
2021-04-08 20:09:59 +08:00
//bytes = SecurityUtil.Xor(bytes);
Utility.Encryption.GetSelfXorBytes(bytes, CryptionHelper.GetXorKey());
long keyValue = BitConverter.ToInt64(bytes, 0);
keyValue -= DateTime.UtcNow.Year;
if (key.Item1 != keyValue)
{
Log.Error($"*【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】校验码{keyValue}错误{key}");
response.Message = "系统错误";
reply();
return;
}
int bossId = key.Item2;
Team team = TeamComponent.Instance.Get(unit.TeamLeaderId);
2021-04-11 19:50:39 +08:00
LinkedList<Unit> teamList = team.GetUnits();
2021-04-08 20:09:59 +08:00
if (team.TeamState == TeamState.Fight)
{
Log.Error($"*【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】多次进行Boss战斗");
response.Message = "多次进行战斗";
reply();
return;
}
UnitScene unitScene = unit.GetComponent<UnitScene>();
if (unitScene==null|| unitScene.MapId%100 != bossId)
{
Log.Error($"【{UserComponent.Instance.Get(unit.Id)?.NickName}({unit.Id})】mapid = {unitScene?.MapId} bossId = {bossId}");
response.Message = "系统错误";
reply();
return;
}
2021-04-11 19:50:39 +08:00
BossComponent.BossState state = BossComponent.Instance.GetState(bossId);
2021-04-08 20:09:59 +08:00
if(state!= BossComponent.BossState.Idle)
{
response.Message = "boss正在挑战中";
reply();
return;
}
2021-04-11 19:50:39 +08:00
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;
}
data.bossEnergy--;
UnitHelper.SaveComponenet(data).Coroutine();
}
BossComponent.Instance.ChangeState(bossId, BossComponent.BossState.Battle, false);
2021-04-11 19:50:39 +08:00
BossBattle battle = BattleMgrCompnent.Instance.CreateBattle<BossBattle>(team);
2021-04-08 20:09:59 +08:00
battle.Init(unitScene.MapId);
reply();
await ETTask.CompletedTask;
}
catch (Exception e)
{
Log.Error(e);
}
}
}
}