88 lines
3.5 KiB
C#
88 lines
3.5 KiB
C#
using Cal.DataTable;
|
|
using NLog.Internal;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
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
|
|
{
|
|
Dictionary<long, (long, int)> dic = BossComponent.Instance.keyDic;
|
|
if (!dic.TryGetValue(unit.Id, out (long, int) key))
|
|
{
|
|
response.Message = "系统错误";
|
|
reply();
|
|
return;
|
|
}
|
|
dic.Remove(unit.Id);
|
|
|
|
byte[] bytes = BitConverter.GetBytes(request.Key);
|
|
//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);
|
|
LinkedList<Unit> teamList = team.GetUnits();
|
|
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;
|
|
}
|
|
BossComponent.BossState state = BossComponent.Instance.GetState(bossId);
|
|
if(state!= BossComponent.BossState.Idle)
|
|
{
|
|
response.Message = "boss正在挑战中";
|
|
reply();
|
|
return;
|
|
}
|
|
foreach (Unit u in teamList)
|
|
{
|
|
PlayerData data = u.GetComponent<PlayerData>();
|
|
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);
|
|
BossBattle battle = BattleMgrCompnent.Instance.CreateBattle<BossBattle>(team);
|
|
battle.Init(unitScene.MapId);
|
|
|
|
reply();
|
|
await ETTask.CompletedTask;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
}
|
|
}
|
|
} |