87 lines
3.3 KiB
C#
87 lines
3.3 KiB
C#
|
using Cal.DataTable;
|
|||
|
using NLog.Internal;
|
|||
|
using System;
|
|||
|
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
|
|||
|
{
|
|||
|
var dic = BossComponent.Instance.keyDic;
|
|||
|
if (!dic.TryGetValue(unit.Id, out var key))
|
|||
|
{
|
|||
|
response.Message = "系统错误";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
dic.Remove(unit.Id);
|
|||
|
|
|||
|
var 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);
|
|||
|
var 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;
|
|||
|
}
|
|||
|
var state = BossComponent.Instance.GetState(bossId);
|
|||
|
if(state!= BossComponent.BossState.Idle)
|
|||
|
{
|
|||
|
response.Message = "boss正在挑战中";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
foreach (var u in teamList)
|
|||
|
{
|
|||
|
var 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);
|
|||
|
var battle = BattleMgrCompnent.Instance.CreateBattle<BossBattle>(team);
|
|||
|
battle.Init(unitScene.MapId);
|
|||
|
|
|||
|
reply();
|
|||
|
await ETTask.CompletedTask;
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
Log.Error(e);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|