You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
196 lines
7.8 KiB
196 lines
7.8 KiB
using System.Collections.Generic;
|
|
using ProtoCSClass;
|
|
using Proto;
|
|
using UnityEngine;
|
|
using xFrame;
|
|
|
|
namespace CoreGame.Render
|
|
{
|
|
public static class CallFromRPC
|
|
{
|
|
private static readonly Dictionary<int, BaseHandle> m_HandleMap = new();
|
|
private static bool m_IsInit;
|
|
|
|
public static void Init()
|
|
{
|
|
if (m_IsInit)
|
|
return;
|
|
m_IsInit = true;
|
|
InitHandleMap();
|
|
InitNetMsgReceiver();
|
|
}
|
|
|
|
private static void InitHandleMap()
|
|
{
|
|
if (m_HandleMap.Count > 0)
|
|
return;
|
|
m_HandleMap.Add((int)RpcType.ChangeProp, new Handle_ChangeProp());
|
|
m_HandleMap.Add((int)RpcType.LevelUp, new Handle_LevelUp());
|
|
m_HandleMap.Add((int)RpcType.KilledMonster, new Handle_OnKillEntity());
|
|
m_HandleMap.Add((int)RpcType.OnBronEntity, new Handle_OnCreateEntity());
|
|
m_HandleMap.Add((int)RpcType.OnDropExtBox, new Handle_DropExtBox());
|
|
m_HandleMap.Add((int)RpcType.BossContinueBattleFinishLayer, new Handle_BossContinueBattleFinishLayer());
|
|
m_HandleMap.Add((int)RpcType.BossContinueBattleIntruder, new Handle_BossContinueBattleIntruder());
|
|
m_HandleMap.Add((int)RpcType.BossContinueBattleLeave, new Handle_BossContinueBattleLeave());
|
|
}
|
|
|
|
private static void InitNetMsgReceiver()
|
|
{
|
|
NetMsgGateway.Instance.AddReceiverFromBattle((int)ClientMsgId.CS_MULT_FRAP_BOOT_INFO_SYNC,
|
|
(msg) =>
|
|
{
|
|
if (msg is CSMultFrapBootInfo data)
|
|
{
|
|
// var windowComponent = Contexts.sharedInstance.logic.GlobalEntHandle.value.frameWindow;
|
|
// if (windowComponent != null)
|
|
// {
|
|
// windowComponent.rawMsgQueue.Enqueue(data);
|
|
// }
|
|
}
|
|
});
|
|
|
|
// NetMsgGateway.Instance.AddReceiverFromBattle((int)ClientMsgId.CS_GAMEMSGID_JOIN_ROOM_RES,
|
|
// (msg) =>
|
|
// {
|
|
// if (msg is CSJoinRoomRes data)
|
|
// {
|
|
// // 创建本地玩家
|
|
// EntityCreateSrv2.CreateHeroEntity2(Contexts.Combat, 5010, data.Eid, true);
|
|
// }
|
|
// });
|
|
|
|
NetMsgGateway.Instance.AddReceiverFromBattle((int)ClientMsgId.CS_GAMEMSGID_ROOM_INFO_SYNC,
|
|
(msg) =>
|
|
{
|
|
if (msg is CSRoomInfoSync data)
|
|
{
|
|
for (int i = 0; i < data.Eids.Count; i++)
|
|
{
|
|
if (Contexts.Combat.GetEntity(data.Eids[i]) == false)
|
|
{
|
|
// 创建其它玩家
|
|
EntityCreateSrv2.CreateHeroEntity2(Contexts.Combat, 5010, data.Eids[i]);
|
|
}
|
|
}
|
|
|
|
// Contexts.sharedInstance.logic.GlobalEntHandle.value.synchr.bActive = true;
|
|
}
|
|
});
|
|
|
|
if (RPCConfig.UseLocalRPC)
|
|
return;
|
|
// 注册
|
|
NetMsgGateway.Instance.AddReceiverFromBattle(
|
|
(int)ClientMsgId.CS_GAMEMSGID_KILLED_MONSTER_RES, (msg) =>
|
|
{
|
|
if (msg is OnKilledMonsterRes data)
|
|
{
|
|
if (data.DropInfo == null)
|
|
{
|
|
XLog.LogWarning("wtf...");
|
|
return;
|
|
}
|
|
|
|
if (Contexts.IsValid && Contexts.Combat.hasRPCRetry &&
|
|
Contexts.Combat.rPCRetry.RemoveCache(data.MsgSeq))
|
|
Call(data.DropInfo.Seq, RpcType.KilledMonster, msg);
|
|
}
|
|
});
|
|
|
|
NetMsgGateway.Instance.AddReceiverFromBattle((int)ClientMsgId.CS_GAMEMSGID_CB_FINISH_RES,
|
|
(msg) =>
|
|
{
|
|
if (msg is CSCBFinishLayerRes data)
|
|
{
|
|
if (Contexts.IsValid && Contexts.Combat.hasRPCRetry &&
|
|
Contexts.Combat.rPCRetry.RemoveCache(data.MsgSeq))
|
|
Call(Contexts.Combat.leveWaveEid, RpcType.BossContinueBattleFinishLayer, msg);
|
|
}
|
|
});
|
|
NetMsgGateway.Instance.AddReceiverFromBattle(
|
|
(int)ClientMsgId.CS_GAMEMSGID_CBC_PLAYER_SYNC, msg =>
|
|
{
|
|
if (msg is CSCBCPlayerQuerySync data)
|
|
{
|
|
Call(Contexts.Combat.leveWaveEid, RpcType.BossContinueBattleIntruder, msg);
|
|
}
|
|
});
|
|
NetMsgGateway.Instance.AddReceiverFromBattle((int)ClientMsgId.CS_GAMEMSGID_CB_LEAVE_RES,
|
|
msg =>
|
|
{
|
|
if (msg is CSCBLeaveRes data)
|
|
{
|
|
if (Contexts.IsValid && Contexts.Combat.hasRPCRetry &&
|
|
Contexts.Combat.rPCRetry.RemoveCache(data.MsgSeq))
|
|
Call(Contexts.Combat.leveWaveEid, RpcType.BossContinueBattleLeave, msg);
|
|
}
|
|
});
|
|
|
|
NetMsgGateway.Instance.AddReceiverFromBattle(
|
|
(int)ClientMsgId.CS_GAMEMSGID_ONTICK_BATTLE_ENTITY_RES, (msg) =>
|
|
{
|
|
if (msg is OnTickBattleEntityRes data)
|
|
{
|
|
if (Contexts.IsValid && Contexts.Combat.hasRPCRetry &&
|
|
Contexts.Combat.rPCRetry.RemoveCache(data.MsgSeq))
|
|
Call(data.Seq, RpcType.OnBronEntity, msg);
|
|
}
|
|
});
|
|
|
|
|
|
NetMsgGateway.Instance.AddReceiverFromBattle((int)ClientMsgId.CS_GAMEMSGID_ON_SYNC_EXT_DROP_REWARD_DATA,
|
|
(msg) =>
|
|
{
|
|
if (msg is SyncExtDropRewardData data)
|
|
{
|
|
Call(BattleModule.s_LocalPlayerEid, RpcType.OnDropExtBox, msg);
|
|
}
|
|
});
|
|
}
|
|
|
|
public static void UnInit()
|
|
{
|
|
if (m_IsInit == false)
|
|
return;
|
|
|
|
m_IsInit = false;
|
|
if (RPCConfig.UseLocalRPC == false)
|
|
{
|
|
NetMsgGateway.Instance?.RemoveReceiverFromBattle((int)ClientMsgId.CS_GAMEMSGID_KILLED_MONSTER_RES);
|
|
NetMsgGateway.Instance?.RemoveReceiverFromBattle((int)ClientMsgId.CS_GAMEMSGID_CB_FINISH_RES);
|
|
NetMsgGateway.Instance?.RemoveReceiverFromBattle((int)ClientMsgId.CS_GAMEMSGID_CBC_PLAYER_SYNC);
|
|
NetMsgGateway.Instance?.RemoveReceiverFromBattle((int)ClientMsgId.CS_GAMEMSGID_CB_LEAVE_RES);
|
|
NetMsgGateway.Instance?.RemoveReceiverFromBattle((int)ClientMsgId
|
|
.CS_GAMEMSGID_ONTICK_BATTLE_ENTITY_RES);
|
|
NetMsgGateway.Instance?.RemoveReceiverFromBattle((int)ClientMsgId
|
|
.CS_GAMEMSGID_ON_SYNC_EXT_DROP_REWARD_DATA);
|
|
}
|
|
|
|
m_HandleMap.Clear();
|
|
}
|
|
|
|
public static void Call(int eid, RpcType msgId, object msg)
|
|
{
|
|
if (Contexts.IsValid == false)
|
|
return;
|
|
|
|
if (m_HandleMap.TryGetValue((int)msgId, out var handle))
|
|
{
|
|
handle.DoHandle(eid, msg);
|
|
}
|
|
}
|
|
|
|
public static void InitForGuideMonsterBattle()
|
|
{
|
|
if (m_IsInit) return;
|
|
InitHandleMap();
|
|
}
|
|
|
|
public static void InitForGuideFreeBattle()
|
|
{
|
|
if (m_IsInit) return;
|
|
m_IsInit = true;
|
|
InitNetMsgReceiver();
|
|
}
|
|
}
|
|
}
|