diff --git a/Assets/PerfectWorld/Scripts/Common/EC_C2SCmdCache.cs b/Assets/PerfectWorld/Scripts/Common/EC_C2SCmdCache.cs index 07c73965d5..cf06359f56 100644 --- a/Assets/PerfectWorld/Scripts/Common/EC_C2SCmdCache.cs +++ b/Assets/PerfectWorld/Scripts/Common/EC_C2SCmdCache.cs @@ -63,98 +63,210 @@ namespace BrewMonster.Common // 'Pickup item' command time counter pCnt = new CECCounter(); pCnt.SetPeriod(500); - m_CounterMap[(int)CommandID.PICKUP] = pCnt; + if (m_CounterMap.ContainsKey((int)CommandID.PICKUP)) + { + m_CounterMap[(int)CommandID.PICKUP] = pCnt; + } + else + { + m_CounterMap.Add((int)CommandID.PICKUP, pCnt); + } // 'Select target' command time counter pCnt = new CECCounter(); pCnt.SetPeriod(250); - m_CounterMap[(int)CommandID.SELECT_TARGET] = pCnt; + if (m_CounterMap.ContainsKey((int)CommandID.SELECT_TARGET)) + { + m_CounterMap[(int)CommandID.SELECT_TARGET] = pCnt; + } + else + { + m_CounterMap.Add((int)CommandID.SELECT_TARGET, pCnt); + } // 'Get extend properties' command time counter pCnt = new CECCounter(); pCnt.SetPeriod(2000); pCnt.Reset(true); - m_CounterMap[(int)CommandID.GET_EXT_PROP] = pCnt; + if (m_CounterMap.ContainsKey((int)CommandID.GET_EXT_PROP)) + { + m_CounterMap[(int)CommandID.GET_EXT_PROP] = pCnt; + } + else + { + m_CounterMap.Add((int)CommandID.GET_EXT_PROP, pCnt); + } // 'Cast skill' command time counter pCnt = new CECCounter(); pCnt.SetPeriod(200); pCnt.Reset(true); - m_CounterMap[(int)CommandID.CAST_SKILL] = pCnt; + if (m_CounterMap.ContainsKey((int)CommandID.CAST_SKILL)) + { + m_CounterMap[(int)CommandID.CAST_SKILL] = pCnt; + } + else + { + m_CounterMap.Add((int)CommandID.CAST_SKILL, pCnt); + } // 'Revive ask' command time counter pCnt = new CECCounter(); pCnt.SetPeriod(500); pCnt.Reset(true); - m_CounterMap[(int)CommandID.REVIVE_VILLAGE] = pCnt; + if (m_CounterMap.ContainsKey((int)CommandID.REVIVE_VILLAGE)) + { + m_CounterMap[(int)CommandID.REVIVE_VILLAGE] = pCnt; + } + else + { + m_CounterMap.Add((int)CommandID.REVIVE_VILLAGE, pCnt); + } // 'Enter sanctuary' command time counter pCnt = new CECCounter(); pCnt.SetPeriod(2000); - m_CounterMap[(int)CommandID.ENTER_SANCTUARY] = pCnt; + if (m_CounterMap.ContainsKey((int)CommandID.ENTER_SANCTUARY)) + { + m_CounterMap[(int)CommandID.ENTER_SANCTUARY] = pCnt; + } + else + { + m_CounterMap.Add((int)CommandID.ENTER_SANCTUARY, pCnt); + } // 'Enter instance' command time counter pCnt = new CECCounter(); pCnt.SetPeriod(2000); pCnt.Reset(true); - m_CounterMap[(int)CommandID.ENTER_INSTANCE] = pCnt; + if (m_CounterMap.ContainsKey((int)CommandID.ENTER_INSTANCE)) + { + m_CounterMap[(int)CommandID.ENTER_INSTANCE] = pCnt; + } + else + { + m_CounterMap.Add((int)CommandID.ENTER_INSTANCE, pCnt); + } // 'Rush fly' command time counter pCnt = new CECCounter(); pCnt.SetPeriod(500); pCnt.Reset(true); - m_CounterMap[(int)CommandID.ACTIVE_RUSH_FLY] = pCnt; + if (m_CounterMap.ContainsKey((int)CommandID.ACTIVE_RUSH_FLY)) + { + m_CounterMap[(int)CommandID.ACTIVE_RUSH_FLY] = pCnt; + } + else + { + m_CounterMap.Add((int)CommandID.ACTIVE_RUSH_FLY, pCnt); + } // 'Cancel action' command time counter pCnt = new CECCounter(); pCnt.SetPeriod(200); pCnt.Reset(true); - m_CounterMap[(int)CommandID.CANCEL_ACTION] = pCnt; + if (m_CounterMap.ContainsKey((int)CommandID.CANCEL_ACTION)) + { + m_CounterMap[(int)CommandID.CANCEL_ACTION] = pCnt; + } + else + { + m_CounterMap.Add((int)CommandID.CANCEL_ACTION, pCnt); + } // 'Control pet' command time counter pCnt = new CECCounter(); pCnt.SetPeriod(400); pCnt.Reset(true); - m_CounterMap[(int)CommandID.PET_CTRL] = pCnt; + if (m_CounterMap.ContainsKey((int)CommandID.PET_CTRL)) + { + m_CounterMap[(int)CommandID.PET_CTRL] = pCnt; + } + else + { + m_CounterMap.Add((int)CommandID.PET_CTRL, pCnt); + } // 'Hello' command time counter pCnt = new CECCounter(); pCnt.SetPeriod(2000); pCnt.Reset(true); - m_CounterMap[(int)CommandID.SEVNPC_HELLO] = pCnt; + if (m_CounterMap.ContainsKey((int)CommandID.SEVNPC_HELLO)) + { + m_CounterMap[(int)CommandID.SEVNPC_HELLO] = pCnt; + } + else + { + m_CounterMap.Add((int)CommandID.SEVNPC_HELLO, pCnt); + } // 'Present' command time counter pCnt = new CECCounter(); pCnt.SetPeriod(1000); pCnt.Reset(true); - m_CounterMap[(int)CommandID.PLAYER_GIVE_PRESENT] = pCnt; + if (m_CounterMap.ContainsKey((int)CommandID.PLAYER_GIVE_PRESENT)) + { + m_CounterMap[(int)CommandID.PLAYER_GIVE_PRESENT] = pCnt; + } + else + { + m_CounterMap.Add((int)CommandID.PLAYER_GIVE_PRESENT, pCnt); + } // 'GetPlayerBriefInfo' time counter pCnt = new CECCounter(); pCnt.SetPeriod(2000); pCnt.Reset(true); - m_CounterMap2[(int)ProtocolType.PROTOCOL_GETPLAYERBRIEFINFO] = pCnt; + if (m_CounterMap2.ContainsKey((int)ProtocolType.PROTOCOL_GETPLAYERBRIEFINFO)) + { + m_CounterMap2[(int)ProtocolType.PROTOCOL_GETPLAYERBRIEFINFO] = pCnt; + } + else + { + m_CounterMap2.Add((int)ProtocolType.PROTOCOL_GETPLAYERBRIEFINFO, pCnt); + } // 'PlayerBaseInfo' time counter pCnt = new CECCounter(); pCnt.SetPeriod(2000); pCnt.Reset(true); - m_CounterMap2[(int)ProtocolType.PROTOCOL_PLAYERBASEINFO] = pCnt; + if (m_CounterMap2.ContainsKey((int)ProtocolType.PROTOCOL_PLAYERBASEINFO)) + { + m_CounterMap2[(int)ProtocolType.PROTOCOL_PLAYERBASEINFO] = pCnt; + } + else + { + m_CounterMap2.Add((int)ProtocolType.PROTOCOL_PLAYERBASEINFO, pCnt); + } pCnt = new CECCounter(); pCnt.SetPeriod(10 * 1000); pCnt.Reset(true); - m_CounterMap2[(int)ProtocolType.PROTOCOL_FACTIONRESOURCEBATTLEGETMAP] = pCnt; + if (m_CounterMap2.ContainsKey((int)ProtocolType.PROTOCOL_FACTIONRESOURCEBATTLEGETMAP)) + { + m_CounterMap2[(int)ProtocolType.PROTOCOL_FACTIONRESOURCEBATTLEGETMAP] = pCnt; + } + else + { + m_CounterMap2.Add((int)ProtocolType.PROTOCOL_FACTIONRESOURCEBATTLEGETMAP, pCnt); + } pCnt = new CECCounter(); pCnt.SetPeriod(10 * 1000); pCnt.Reset(true); - m_CounterMap2[(int)ProtocolType.PROTOCOL_FACTIONRESOURCEBATTLEGETRECORD] = pCnt; + if (m_CounterMap2.ContainsKey((int)ProtocolType.PROTOCOL_FACTIONRESOURCEBATTLEGETRECORD)) + { + m_CounterMap2[(int)ProtocolType.PROTOCOL_FACTIONRESOURCEBATTLEGETRECORD] = pCnt; + } + else + { + m_CounterMap2.Add((int)ProtocolType.PROTOCOL_FACTIONRESOURCEBATTLEGETRECORD, pCnt); + } return true; } // Remove all un-sent commands in cache - void RemoveAllCmds() + public void RemoveAllCmds() { m_UseItemCmdList.Clear(); @@ -180,33 +292,17 @@ namespace BrewMonster.Common } // Tick routine - bool Tick(float dwDeltaTime) + public bool Tick(float dwDeltaTime) { float dwRealTime = Time.realtimeSinceStartup; - //{ - // CounterTable::iterator it = m_CounterMap.begin(); - // for (; it != m_CounterMap.end(); ++it) - // ((CECCounter*)it.second).IncCounter(dwRealTime); - // for(int i = 0; i < m_CounterMap.Count; i++) - // { - // m_CounterMap[i].IncCounter(dwRealTime); - // } - //} - //{ - // CounterTable::iterator it = m_CounterMap2.begin(); - // for (; it != m_CounterMap2.end(); ++it) - // ((CECCounter*)it.second).IncCounter(dwRealTime); - - //} - - for (int i = 0; i < m_CounterMap.Count; i++) + foreach (var item in m_CounterMap) { - m_CounterMap[i].IncCounter(dwRealTime); + item.Value.IncCounter(dwRealTime); } - for (int i = 0; i < m_CounterMap2.Count; i++) + foreach (var item in m_CounterMap2) { - m_CounterMap2[i].IncCounter(dwRealTime); + item.Value.IncCounter(dwRealTime); } // Try to send 'use item' command in cache @@ -227,10 +323,10 @@ namespace BrewMonster.Common CECCounter pCnt = m_CounterMap[(int)CommandID.ENTER_SANCTUARY]; if (pCnt.IsFull()) { - for(int i = 0; i < m_EnterSanctuaryList.Count; i++) + for (int i = 0; i < m_EnterSanctuaryList.Count; i++) { int id = m_EnterSanctuaryList[i]; - UnityGameSession.c2s_SendCmdEnterSanctuary(id); + UnityGameSession.Instance.GameSession.c2s_SendCmdEnterSanctuary(id); } m_EnterSanctuaryList.Clear(); @@ -252,7 +348,7 @@ namespace BrewMonster.Common // Send the first item cmd_use_item Cmd = m_UseItemCmdList[0]; - UnityGameSession.c2s_SendCmdUseItem(Cmd.where, (byte)Cmd.index, Cmd.item_id, Cmd.byCount); + UnityGameSession.Instance.GameSession.c2s_SendCmdUseItem(Cmd.where, (byte)Cmd.index, Cmd.item_id, Cmd.byCount); m_UseItemCmdList.Clear(); } @@ -266,7 +362,7 @@ namespace BrewMonster.Common pCnt.Reset(); m_bGetExpProps = false; - UnityGameSession.c2s_SendCmdGetExtProps(); + UnityGameSession.Instance.GameSession.c2s_SendCmdGetExtProps(); } // Send cached 'GetPlayerBriefInfo' command @@ -285,7 +381,7 @@ namespace BrewMonster.Common getplayerbriefinfo temp = p; temp.Playerlist.Clear(); temp.Playerlist.Add(p.Playerlist[0]); - UnityGameSession.SendNetData(temp); + UnityGameSession.Instance.GameSession.SendProtocol(temp); // 从列表中清除 p.Playerlist.Remove(p.Playerlist[0]); @@ -296,7 +392,7 @@ namespace BrewMonster.Common } // Remove the cached 'PlayerBaseInfo' request - void RemovePlayerBaseInfo(int iRoleID) + public void RemovePlayerBaseInfo(int iRoleID) { int pos = m_PlayerBaseInfoList.Find(x => x == iRoleID); if (pos != 0) @@ -315,12 +411,12 @@ namespace BrewMonster.Common pCnt.Reset(); List aRoles = new List(); - for(int i = 0; i < m_PlayerBaseInfoList.Count; i++) + for (int i = 0; i < m_PlayerBaseInfoList.Count; i++) { aRoles.Add(m_PlayerBaseInfoList[i]); } - UnityGameSession.GetRoleBaseInfo(aRoles.Count, aRoles); + UnityGameSession.Instance.GameSession.GetRoleBaseInfo(aRoles.Count, aRoles); } void SendCachedPresentInfo() @@ -332,18 +428,18 @@ namespace BrewMonster.Common pCnt.Reset(); presentInfo info = m_PresentInfoList[0]; - UnityGameSession.c2s_SendCmdGivePresent(info.roleid, info.mailid, info.itemid, info.index, info.slot); + UnityGameSession.Instance.GameSession.c2s_SendCmdGivePresent(info.roleid, info.mailid, info.itemid, info.index, info.slot); m_PresentInfoList.Remove(info); } // Send commands ... - void SendCmdUseItem(byte byPackage, byte bySlot, int tid, byte byCount) + public void SendCmdUseItem(byte byPackage, byte bySlot, int tid, byte byCount) { CECCounter pCnt = m_CounterMap[(int)CommandID.USE_ITEM]; if (m_UseItemCmdList.Count == 0 && pCnt.IsFull()) { pCnt.Reset(); - UnityGameSession.c2s_SendCmdUseItem(byPackage, bySlot, tid, byCount); + UnityGameSession.Instance.GameSession.c2s_SendCmdUseItem(byPackage, bySlot, tid, byCount); return; } @@ -358,7 +454,7 @@ namespace BrewMonster.Common return; } int idx = -1; - for(int i = 0; i< m_UseItemCmdList.Count; i++) + for (int i = 0; i < m_UseItemCmdList.Count; i++) { Cmd = m_UseItemCmdList[i]; @@ -382,7 +478,7 @@ namespace BrewMonster.Common } idx++; } - if(idx < 0) + if (idx < 0) { Cmd = new cmd_use_item(); Cmd.where = byPackage; @@ -405,26 +501,241 @@ namespace BrewMonster.Common 2. if the item isn't the one which was to be picked up, send command directly. */ - void SendCmdPickUp(int idItem, int tid); - void SendCmdSelectTarget(int id); - void SendCmdExtProps(); - void SendCmdReviveVillage(int param = 0); - void SendCmdReviveItem(int param = 0); - void SendCmdCastSkill(int idSkill, byte byPVPMask, int iNumTarget, int* aTargets); - void SendCmdCastInstantSkill(int idSkill, byte byPVPMask, int iNumTarget, int* aTargets); - void SendCmdEnterSanctuary(int id); - void SendCmdEnterInstance(int iTransIdx, int idInst); - void SendCmdActiveRushFly(bool bActive); - void SendCmdCancelAction(); - void SendCmdPetCtrl(int idTarget, int cmd, void* pParamBuf, int iParamLen); - void SendCmdNPCSevHello(int nid); - void SendCmdFactionPVPQueryInfo(int idFaction); + public void SendCmdPickUp(int idItem, int tid) + { + //StackChecker::ACTrace(5); + + CECCounter pCnt = m_CounterMap[(int)CommandID.PICKUP]; + if (m_idLastPickUpItem != idItem || pCnt.IsFull()) + { + pCnt.Reset(); + UnityGameSession.Instance.GameSession.RequestPickupItem(idItem, tid); + m_idLastPickUpItem = idItem; + } + } + + // Send 'select target' command + // The strategy to send 'select target' command is like as SendCmdPickUp() + public void SendCmdSelectTarget(int id) + { + // Set selection first before server returns, so as to reduce the player waiting time. + CECHostPlayer pHost = EC_Game.GetGameRun().GetHostPlayer(); + pHost.SetSelectedTarget(id); + + CECCounter pCnt = m_CounterMap[(int)CommandID.SELECT_TARGET]; + if (m_idLastSelTarget != id || pCnt.IsFull()) + { + pCnt.Reset(); + UnityGameSession.Instance.GameSession.c2s_SendCmdSelectTarget(id); + m_idLastSelTarget = id; + } + } + + // Send 'get extend properties' command + public void SendCmdExtProps() + { + // If there is already a request waiting, return directly + if (m_bGetExpProps) + return; + + CECCounter pCnt = m_CounterMap[(int)CommandID.GET_EXT_PROP]; + if (pCnt.IsFull()) + { + pCnt.Reset(); + UnityGameSession.Instance.GameSession.c2s_SendCmdGetExtProps(); + return; + } + + m_bGetExpProps = true; + } + + // Send 'revive ask' command + public void SendCmdReviveVillage(int param = 0) + { + CECCounter pCnt = m_CounterMap[(int)CommandID.REVIVE_VILLAGE]; + if (pCnt.IsFull()) + { + pCnt.Reset(); + UnityGameSession.Instance.GameSession.RequestReviveBase(param); + } + } + + // Send 'revive ask' command + public void SendCmdReviveItem(int param = 0) + { + // This command merge time counter with REVIVE_VILLAGE + CECCounter pCnt = m_CounterMap[(int)CommandID.REVIVE_VILLAGE]; + if (pCnt.IsFull()) + { + pCnt.Reset(); + UnityGameSession.Instance.GameSession.RequestReviveItem(param); + } + } + + // Send 'cast skill' command + public void SendCmdCastSkill(int idSkill, byte byPVPMask, int iNumTarget, int[] aTargets) + { + CECCounter pCnt = m_CounterMap[(int)CommandID.CAST_SKILL]; + if (pCnt.IsFull()) + { + pCnt.Reset(); + UnityGameSession.Instance.GameSession.c2s_SendCmdCastSkill(idSkill, byPVPMask, iNumTarget, aTargets); + } + } + + // Send 'cast instant skill' command + public void SendCmdCastInstantSkill(int idSkill, byte byPVPMask, int iNumTarget, int[] aTargets) + { + CECCounter pCnt = m_CounterMap[(int)CommandID.CAST_SKILL]; + if (pCnt.IsFull()) + { + pCnt.Reset(); + UnityGameSession.Instance.GameSession.c2s_SendCmdCastInstantSkill(idSkill, byPVPMask, iNumTarget, aTargets); + } + } + + // Send 'enter sanctuary' command + void SendCmdEnterSanctuary(int id) + { + for (int i = 0; i < m_EnterSanctuaryList.Count; i++) + { + if (m_EnterSanctuaryList[i] == id) return; + } + + // Delay this command some time + m_bEnterSanctuary = true; + CECCounter pCnt = m_CounterMap[(int)CommandID.ENTER_SANCTUARY]; + pCnt.Reset(); + m_EnterSanctuaryList.Add(id); + } + + // Send 'enter instance' commnad + void SendCmdEnterInstance(int iTransIdx, int idInst) + { + CECCounter pCnt = m_CounterMap[(int)CommandID.ENTER_INSTANCE]; + if (pCnt.IsFull()) + { + pCnt.Reset(); + UnityGameSession.Instance.GameSession.c2s_SendCmdEnterInstance(iTransIdx, idInst); + } + } + + void SendCmdActiveRushFly(bool bActive) + { + CECCounter pCnt = m_CounterMap[(int)CommandID.ACTIVE_RUSH_FLY]; + if (pCnt.IsFull()) + { + pCnt.Reset(); + UnityGameSession.Instance.GameSession.c2s_SendCmdActiveRushFly(bActive); + } + } + + public void SendCmdCancelAction() + { + CECCounter pCnt = m_CounterMap[(int)CommandID.CANCEL_ACTION]; + if (pCnt.IsFull()) + { + pCnt.Reset(); + UnityGameSession.Instance.GameSession.c2s_SendCmdCancelAction(); + } + } + void SendCmdPetCtrl(int idTarget, int cmd, byte[] pParamBuf, int iParamLen) + { + CECCounter pCnt = m_CounterMap[(int)CommandID.PET_CTRL]; + if (pCnt.IsFull()) + { + pCnt.Reset(); + UnityGameSession.Instance.GameSession.c2s_SendCmdPetCtrl(idTarget, cmd, pParamBuf, iParamLen); + } + } + + public void SendCmdNPCSevHello(int nid) + { + CECCounter pCnt = m_CounterMap[(int)CommandID.SEVNPC_HELLO]; + if (pCnt.IsFull()) + { + pCnt.Reset(); + UnityGameSession.Instance.GameSession.c2s_SendCmdNPCSevHello(nid); + } + } + + void SendCmdFactionPVPQueryInfo(int idFaction) + { + int piMax = -1; + CECHostPlayer pHost = EC_Game.GetGameRun().GetHostPlayer(); + if (pHost.GetCoolTime((int)CSNetwork.GPDataType.CoolTimeIndex.GP_CT_QUERY_MAFIA_PVP_INFO, ref piMax) == 0) + { + UnityGameSession.Instance.GameSession.c2s_SendCmdQueryFactionPVPInfo(idFaction); + } + } // Send protocols ... - void SendGetPlayerBriefInfo(int iNumPlayer, int* aIDs, int iReason); - void SendGetPlayerBaseInfo(int iNumRole, const int* aRoleIDs); - void SendGivePresentProtocol(int roleid, int mailid, int itemid, int index, int slot); - void SendFactionPVPGetMap(); - void SendFactionPVPGetRank(); + void SendGetPlayerBriefInfo(int iNumPlayer, int[] aIDs, int iReason) + { + if (iNumPlayer == 0 || aIDs == null || aIDs.Length == 0) + return; + + // 1.合并添加到列表 + getplayerbriefinfo p = new getplayerbriefinfo(); + p.Roleid = EC_Game.GetGameRun().GetHostPlayer().GetCharacterID(); + p.Reason = (byte)iReason; + for (int i = 0; i < iNumPlayer; ++i) + { + if (aIDs[i] != 0) + p.Playerlist.Add(aIDs[i]); + } + if (p.Playerlist.Count > 0) + m_GetPlayerBriefInfoList.Add(p); + + // 2.检查并发送 + SendCachedGetPlayerBriefInfo(); + } + + void SendGetPlayerBaseInfo(int iNumRole, int[] aRoleIDs) + { + if (iNumRole == 0 || aRoleIDs == null || aRoleIDs.Length == 0) + return; + + for (int i = 0; i < iNumRole; i++) + { + if (aRoleIDs[i] != 0) + m_PlayerBaseInfoList.Add(aRoleIDs[i]); + } + + SendCachedPlayerBaseInfo(); + } + + void SendGivePresentProtocol(int roleid, int mailid, int itemid, int index, int slot) + { + presentInfo info = new presentInfo(); + info.roleid = roleid; + info.mailid = mailid; + info.itemid = itemid; + info.index = index; + info.slot = slot; + m_PresentInfoList.Add(info); + } + void SendFactionPVPGetMap() + { + CECCounter pCnt = m_CounterMap2[(int)ProtocolType.PROTOCOL_FACTIONRESOURCEBATTLEGETMAP]; + if (pCnt.IsFull()) + { + pCnt.Reset(); + factionresourcebattlegetmap p = new factionresourcebattlegetmap(); + p.Roleid = EC_Game.GetGameRun().GetHostPlayer().GetCharacterID(); + UnityGameSession.Instance.GameSession.SendProtocol(p); + } + } + void SendFactionPVPGetRank() + { + CECCounter pCnt = m_CounterMap2[(int)ProtocolType.PROTOCOL_FACTIONRESOURCEBATTLEGETRECORD]; + if (pCnt.IsFull()) + { + pCnt.Reset(); + factionresourcebattlegetrecord p = new factionresourcebattlegetrecord(); + p.Roleid = EC_Game.GetGameRun().GetHostPlayer().GetCharacterID(); + UnityGameSession.Instance.GameSession.SendProtocol(p); + } + } } } diff --git a/Assets/PerfectWorld/Scripts/Managers/EC_ManPlayer.cs b/Assets/PerfectWorld/Scripts/Managers/EC_ManPlayer.cs index eb87632482..8324928321 100644 --- a/Assets/PerfectWorld/Scripts/Managers/EC_ManPlayer.cs +++ b/Assets/PerfectWorld/Scripts/Managers/EC_ManPlayer.cs @@ -509,6 +509,7 @@ namespace PerfectWorld.Scripts.Managers if (pHost != null && pHost.GetSelectedTarget() == cid) pHost.SelectTarget(0); + UnityGameSession.Instance.GetC2SCmdCache().RemovePlayerBaseInfo(cid); // Release player resource if (pPlayer != null) { @@ -522,49 +523,6 @@ namespace PerfectWorld.Scripts.Managers } } - //private cmd_object_move ConvertToStruct(byte[] bytes) - //{ - // if (bytes.Length < Marshal.SizeOf()) - // { - // return default; - // } - - // cmd_object_move result = new cmd_object_move(); - // int preLenghtData = 0; - // int lenghtDataType = Marshal.SizeOf(); - // byte[] arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData); - // result.id = BitConverter.ToInt32(arrByteData); - - // preLenghtData += lenghtDataType; - // lenghtDataType = Marshal.SizeOf(); - // arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData); - // result.dest_X = BitConverter.ToSingle(arrByteData); - - // preLenghtData += lenghtDataType; - // lenghtDataType = Marshal.SizeOf(); - // arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData); - // result.dest_Y = BitConverter.ToSingle(arrByteData); - - // preLenghtData += lenghtDataType; - // lenghtDataType = Marshal.SizeOf(); - // arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData); - // result.dest_Z = BitConverter.ToSingle(arrByteData); - - // preLenghtData += lenghtDataType; - // lenghtDataType = Marshal.SizeOf(); - // arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData); - // result.use_time = BitConverter.ToUInt16(arrByteData); - - // preLenghtData += lenghtDataType; - // lenghtDataType = Marshal.SizeOf(); - // arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData); - // result.sSpeed = BitConverter.ToInt16(arrByteData); - - // preLenghtData += lenghtDataType; - // result.move_mode = bytes[preLenghtData + 1]; - // return result; - //} - private byte[] GetBytes(byte[] bytes, int length, int index) { byte[] arrByteData = new byte[length]; @@ -596,7 +554,7 @@ namespace PerfectWorld.Scripts.Managers case long value when value == EC_MsgDef.MSG_PM_PLAYERBASEINFO: cid = (int)((playerbaseinfo_re)Msg.dwParam1).Player.id; // Xo谩 kh峄廼 cache - //g_pGame.GetGameSession().GetC2SCmdCache().RemovePlayerBaseInfo(cid); + UnityGameSession.Instance.GetC2SCmdCache().RemovePlayerBaseInfo(cid); break; /*case long value when value == EC_MsgDef.MSG_PM_PLAYERCUSTOM: diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommand.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommand.cs index 3e0fa94a01..5b979939c9 100644 --- a/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommand.cs +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommand.cs @@ -1497,6 +1497,59 @@ namespace CSNetwork.S2CCommand { public int id; // self id or pet id. }; + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct cmd_enter_instance + { + public int iTransIndex; + public int idInst; + }; + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct cmd_active_rush_fly + { + public int is_active; + }; + + /* Categories of pet_cmd: + pet_cmd = 1 Attack the specified target, requires a valid target. + Parameter: char, pvp mask for attack protection status. + + pet_cmd = 2 Change pet follow behavior, target is ignored. + Parameter: int + 0 = follow the player (default) + 1 = stay at current position + When this command is issued, it attempts to interrupt the pet鈥檚 current action + and perform the newly assigned follow behavior. + + pet_cmd = 3 Change pet combat behavior, target is ignored. + Parameter: int + 0 = Defensive mode 鈥 counterattack when hit, and counterattack when the owner is hit + (currently not implemented) + 1 = Aggressive mode 鈥 automatically attacks enemies within range + 2 = Passive mode 鈥 will not react unless commanded by the player + + pet_cmd = 4 Request pet to use a skill; target represents the skill鈥檚 target. + Parameter: int 鈥 ID of the skill to use + Parameter: char 鈥 pvp mask for attack protection status + + pet_cmd = 5 Request pet to auto-cast a skill, target ignored. + Parameter: int 鈥 ID of the skill to auto-cast + if the skill ID is 0, auto-casting is disabled. + */ + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct cmd_pet_ctrl + { + public int target; // The target of the operation. If no target is required, set the command鈥檚 target to 0. + public int pet_cmd; // Control commands for the pet + //char buf[]; // Parameters of the pet control commands + }; + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct cmd_query_faction_pvp_info + { + public int faction_id; + }; } // Player and NPC state \ No newline at end of file diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommandFactory.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommandFactory.cs index 4c2d34352c..5a93d1fb43 100644 --- a/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommandFactory.cs +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommandFactory.cs @@ -268,29 +268,7 @@ namespace CSNetwork.C2SCommand }; return SerializeCommand(CommandID.STOP_MOVE, cmd); } - public static Octets CreatePlayerCastSkill(int idSkill, byte byPVPMask, int iNumTarget, int aTargets) - { - var cmd = new CMD_CastSkill - { - skillId = idSkill, - pvpMask = byPVPMask, - targetCount = (byte)iNumTarget, - targets = null - }; - if (iNumTarget > 0) - { - if (iNumTarget > 0) - { - cmd.targets = new int[iNumTarget]; - cmd.targets[0] = aTargets; - } - } - - var cmdBuf = SerializeCommand(CommandID.CAST_SKILL, cmd); - return cmdBuf; - } - - public static Octets CreatePlayerCastInstantSkill(int idSkill, byte byPVPMask, int iNumTarget, int aTargets) + public static Octets CreatePlayerCastSkill(int idSkill, byte byPVPMask, int iNumTarget, int[] aTargets) { var cmd = new CMD_CastSkill { @@ -302,7 +280,32 @@ namespace CSNetwork.C2SCommand if (iNumTarget > 0) { cmd.targets = new int[iNumTarget]; - cmd.targets[0] = aTargets; + for (int i = 0; i < iNumTarget; i++) + { + cmd.targets[i] = aTargets[i]; + } + } + + var cmdBuf = SerializeCommand(CommandID.CAST_SKILL, cmd); + return cmdBuf; + } + + public static Octets CreatePlayerCastInstantSkill(int idSkill, byte byPVPMask, int iNumTarget, int[] aTargets) + { + var cmd = new CMD_CastSkill + { + skillId = idSkill, + pvpMask = byPVPMask, + targetCount = (byte)iNumTarget, + targets = null + }; + if (iNumTarget > 0) + { + cmd.targets = new int[iNumTarget]; + for(int i = 0; i < iNumTarget; i++) + { + cmd.targets[i] = aTargets[i]; + } } var cmdBuf = SerializeCommand(CommandID.CAST_INSTANT_SKILL, cmd); @@ -806,5 +809,37 @@ namespace CSNetwork.C2SCommand pCmd.id = id; return SerializeCommand(CommandID.ENTER_SANCTUARY, pCmd); } + + public static Octets CreateEnterInstanceCmd(int iTransIdx, int idInst) + { + cmd_enter_instance pCmd = new cmd_enter_instance(); + pCmd.iTransIndex = iTransIdx; + pCmd.idInst = idInst; + return SerializeCommand(CommandID.ENTER_INSTANCE, pCmd); + } + + public static Octets CreateActiveRushFlyCmd(bool bActive) + { + cmd_active_rush_fly pCmd = new cmd_active_rush_fly(); + pCmd.is_active = bActive ? 1 : 0; + return SerializeCommand(CommandID.ACTIVE_RUSH_FLY, pCmd); + } + + public static Octets CreatePetCtrlCmd(int idTarget, int cmd, byte[] pParamBuf, int iParamLen) + { + cmd_pet_ctrl pCmd = new cmd_pet_ctrl(); + pCmd.target = idTarget; + pCmd.pet_cmd = cmd; + var tempOctets = SerializeCommand(CommandID.PET_CTRL, pCmd); + tempOctets.Insert(tempOctets.Size + 1, pParamBuf); + return tempOctets; + } + + public static Octets CreateQueryFactionPVPInfo(int faction_id) + { + cmd_query_faction_pvp_info pCmd = new cmd_query_faction_pvp_info(); + pCmd.faction_id = faction_id; + return SerializeCommand(CommandID.QUERY_MAFIA_PVP_INFO, pCmd); + } } } diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs index 4d32b1ad55..f49163892e 100644 --- a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs @@ -1,4 +1,5 @@ 锘縰sing BrewMonster; +using BrewMonster.Common; using BrewMonster.Managers; using BrewMonster.Network; using BrewMonster.Scripts.Skills; @@ -42,7 +43,7 @@ namespace CSNetwork private RoleInfo _selectedRole; public bool IsConnected => _networkManager?.IsConnected ?? false; public static SynchronizationContext Context; - + private CECC2SCmdCache m_CmdCache; // C2S command cache #if UNITY_EDITOR public bool isDebug; public bool IsDebug @@ -51,11 +52,13 @@ namespace CSNetwork set => isDebug = value; } #endif + public CECC2SCmdCache CmdCache { get => m_CmdCache; } public GameSession() { _networkManager = new NetworkManager(); + m_CmdCache = new CECC2SCmdCache(); _networkManager.ProtocolReceived += OnProtocolReceived; _networkManager.ErrorOccurred += OnErrorOccurred; _networkManager.Disconnected += OnDisconnected; @@ -831,6 +834,8 @@ namespace CSNetwork _currentUserId = -1; FailLoginInProgress("Disconnected"); FailRoleListInProgress("Disconnected"); + // Clear command cache + m_CmdCache.RemoveAllCmds(); } // --- Protocol Handling Logic --- @@ -1044,7 +1049,7 @@ namespace CSNetwork C2SCommandFactory.CreatePlayerMove(vCurPos, vDest, (ushort)iTime, fSpeed, (byte)iMoveMode, wStamp); SendProtocol(gamedatasend); } - public void c2s_CmdCastSkill(int idSkill, byte byPVPMask, int iNumTarget, int aTargets) + public void c2s_SendCmdCastSkill(int idSkill, byte byPVPMask, int iNumTarget, int[] aTargets) { gamedatasend gamedatasend = new gamedatasend(); @@ -1054,7 +1059,7 @@ namespace CSNetwork SendProtocol(gamedatasend); } - public void c2s_CmdCastInstantSkill(int idSkill, byte byPVPMask, int iNumTarget, int aTargets) + public void c2s_SendCmdCastInstantSkill(int idSkill, byte byPVPMask, int iNumTarget, int[] aTargets) { gamedatasend gamedatasend = new gamedatasend(); @@ -1219,7 +1224,7 @@ namespace CSNetwork SendProtocol(gamedatasend); } - public void c2s_CmdCancelAction() + public void c2s_SendCmdCancelAction() { gamedatasend gamedatasend = new gamedatasend(); gamedatasend.Data = C2SCommandFactory.CreateNakeCmd(CSNetwork.C2SCommand.CommandID.CANCEL_ACTION); @@ -1233,19 +1238,11 @@ namespace CSNetwork SendProtocol(gamedatasend); } - public void c2s_CmdSelectTarget(int idTarget) + public void c2s_SendCmdSelectTarget(int idTarget) { - // Set selection first before server returns, so as to reduce the player waiting time. - CECHostPlayer pHost = EC_ManMessageMono.Instance.GetECManPlayer.GetHostPlayer(); - pHost.SetSelectedTarget(idTarget); - - if (m_idLastSelTarget != idTarget) - { - gamedatasend gamedatasend = new gamedatasend(); - gamedatasend.Data = C2SCommandFactory.CreateSelectTarget(idTarget); - SendProtocol(gamedatasend); - m_idLastSelTarget = idTarget; - } + gamedatasend gamedatasend = new gamedatasend(); + gamedatasend.Data = C2SCommandFactory.CreateSelectTarget(idTarget); + SendProtocol(gamedatasend); } public void c2s_SendCmdNPCSevWaypoint() @@ -1438,5 +1435,33 @@ namespace CSNetwork gamedatasend.Data = C2SCommandFactory.CreateEnterSanctuaryCmd(id); SendProtocol(gamedatasend); } + + public void c2s_SendCmdEnterInstance(int iTransIdx, int idInst) + { + gamedatasend gamedatasend = new gamedatasend(); + gamedatasend.Data = C2SCommandFactory.CreateEnterInstanceCmd(iTransIdx, idInst); + SendProtocol(gamedatasend); + } + + public void c2s_SendCmdActiveRushFly(bool bActive) + { + gamedatasend gamedatasend = new gamedatasend(); + gamedatasend.Data = C2SCommandFactory.CreateActiveRushFlyCmd(bActive); + SendProtocol(gamedatasend); + } + + public void c2s_SendCmdPetCtrl(int idTarget, int cmd, byte[] pParamBuf, int iParamLen) + { + gamedatasend gamedatasend = new gamedatasend(); + gamedatasend.Data = C2SCommandFactory.CreatePetCtrlCmd(idTarget, cmd, pParamBuf, iParamLen); + SendProtocol(gamedatasend); + } + + public void c2s_SendCmdQueryFactionPVPInfo(int faction_id) + { + gamedatasend gamedatasend = new gamedatasend(); + gamedatasend.Data = C2SCommandFactory.CreateQueryFactionPVPInfo(faction_id); + SendProtocol(gamedatasend); + } } } \ No newline at end of file diff --git a/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs b/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs index 03592dcb54..5c6bbb11c3 100644 --- a/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs +++ b/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs @@ -33,10 +33,13 @@ namespace BrewMonster.Network private string _password = ""; CECStubbornFactionInfoSender m_stubbornFactionInfoSender; - + public GameSession GameSession { get => _gameSession; } + public CECC2SCmdCache GetC2SCmdCache() { return _gameSession.CmdCache; } #if UNITY_EDITOR public bool isDebg; private bool lastDebug; + + public void OnValidate() { if (isDebg != lastDebug) @@ -79,14 +82,14 @@ namespace BrewMonster.Network Instance._ip = ip; Instance._port = port; } - public static void c2s_CmdCastSkill(int idSkill, byte byPVPMask, int iNumTarget, int aTargets) + public static void c2s_CmdCastSkill(int idSkill, byte byPVPMask, int iNumTarget, int[] aTargets) { - Instance._gameSession.c2s_CmdCastSkill(idSkill, byPVPMask, iNumTarget, aTargets); + Instance._gameSession.CmdCache.SendCmdCastSkill(idSkill, byPVPMask, iNumTarget, aTargets); } - public static void c2s_CmdCastInstantSkill(int idSkill, byte byPVPMask, int iNumTarget, int aTargets) + public static void c2s_CmdCastInstantSkill(int idSkill, byte byPVPMask, int iNumTarget, int[] aTargets) { - Instance._gameSession.c2s_CmdCastInstantSkill(idSkill, byPVPMask, iNumTarget, aTargets); + Instance._gameSession.CmdCache.SendCmdCastInstantSkill(idSkill, byPVPMask, iNumTarget, aTargets); } public static void c2s_CmdCastPosSkill(int idSkill, Vector3 vDest, byte byPVPMask, int iNumTarget, int aTargets) @@ -196,7 +199,7 @@ namespace BrewMonster.Network } public static void RequestPickupItem(int idItem, int tid) { - Instance._gameSession.RequestPickupItem(idItem, tid); + Instance._gameSession.CmdCache.SendCmdPickUp(idItem, tid); } public static void RequestDropIvrtItem(byte index, int amount) { @@ -214,13 +217,13 @@ namespace BrewMonster.Network { Instance._gameSession.c2s_SendCmdContinueAction(); } - public static void RequestReviveBase() + public static void c2s_CmdReviveVillage() { - Instance._gameSession.RequestReviveBase(); + Instance._gameSession.CmdCache.SendCmdReviveVillage(); } - public static void RequestReviveItem() + public static void c2s_CmdReviveItem() { - Instance._gameSession.RequestReviveItem(); + Instance._gameSession.CmdCache.SendCmdReviveItem(); } public static void RequestReviveByPlayer() { @@ -265,7 +268,7 @@ namespace BrewMonster.Network public static void c2s_CmdNPCSevHello(int nid) { - Instance._gameSession.c2s_SendCmdNPCSevHello(nid); + Instance._gameSession.CmdCache.SendCmdNPCSevHello(nid); } public static void c2s_CmdNormalAttack(byte byPVPMask) @@ -275,7 +278,7 @@ namespace BrewMonster.Network public static void c2s_CmdCancelAction() { - Instance._gameSession.c2s_CmdCancelAction(); + Instance._gameSession.CmdCache.SendCmdCancelAction(); } public static void c2s_CmdUnselect() @@ -285,7 +288,7 @@ namespace BrewMonster.Network public static void c2s_CmdSelectTarget(int idTarget) { - Instance._gameSession.c2s_CmdSelectTarget(idTarget); + Instance._gameSession.CmdCache.SendCmdSelectTarget(idTarget); } public static void c2s_CmdNPCSevWaypoint() { @@ -397,14 +400,14 @@ namespace BrewMonster.Network } actDone?.Invoke(true); } + void OnDestroy() { _gameSession.Disconnect(); _gameSession.Dispose(); CECNPC.ReleaseStaticRes(); } - - + public static void c2s_CmdGoto(float x, float y, float z) { Instance._gameSession.c2s_CmdGoto(x, y, z); @@ -412,18 +415,13 @@ namespace BrewMonster.Network public static void c2s_SendCmdUseItem(byte byPackage, byte bySlot, int tid, byte byCount) { - Instance._gameSession.c2s_SendCmdUseItem(byPackage, bySlot, tid, byCount); + Instance._gameSession.CmdCache.SendCmdUseItem(byPackage, bySlot, tid, byCount); } // Send C2S::GET_EXT_PROP commadn data public static void c2s_SendCmdGetExtProps() { - Instance._gameSession.c2s_SendCmdGetExtProps(); - } - - public static void SendNetData(getplayerbriefinfo temp) - { - Instance._gameSession.SendProtocol(temp); + Instance._gameSession.CmdCache.SendCmdExtProps(); } public static void c2s_SendCmdGivePresent(int roleid, int mail_id, int goods_id, int goods_index, int goods_slot) @@ -431,9 +429,9 @@ namespace BrewMonster.Network Instance._gameSession.c2s_SendCmdGivePresent(roleid, mail_id, goods_id, goods_index, goods_slot); } - public static void c2s_SendCmdEnterSanctuary(int id) + public void Update() { - Instance._gameSession.c2s_SendCmdEnterSanctuary(id); + _gameSession?.CmdCache?.Tick(Time.deltaTime); } } } \ No newline at end of file diff --git a/Assets/PerfectWorld/Scripts/UI/Popup/RevivePopup.cs b/Assets/PerfectWorld/Scripts/UI/Popup/RevivePopup.cs index 438494e8c3..7fe7124e7c 100644 --- a/Assets/PerfectWorld/Scripts/UI/Popup/RevivePopup.cs +++ b/Assets/PerfectWorld/Scripts/UI/Popup/RevivePopup.cs @@ -27,12 +27,12 @@ namespace BrewMonster private void ReviveInBase() { - UnityGameSession.RequestReviveBase(); + UnityGameSession.c2s_CmdReviveVillage(); } private void ReviveByItem() { - UnityGameSession.RequestReviveItem(); + UnityGameSession.c2s_CmdReviveItem(); } private void ReviveByPlayer() diff --git a/Assets/Scripts/CECHostPlayer.cs b/Assets/Scripts/CECHostPlayer.cs index ae9b672a34..39120b81bb 100644 --- a/Assets/Scripts/CECHostPlayer.cs +++ b/Assets/Scripts/CECHostPlayer.cs @@ -156,6 +156,8 @@ namespace BrewMonster private UnityEngine.InputSystem.Mouse m_cachedMouse; private UnityEngine.InputSystem.Keyboard m_cachedKeyboard; + int[] targetsCastSkill; + public bool IsChangingFace() { return m_bChangingFace; @@ -3771,7 +3773,10 @@ namespace BrewMonster // Handle instant skills if (m_pPrepSkill.IsInstant()) { - UnityGameSession.c2s_CmdCastInstantSkill(m_pPrepSkill.GetSkillID(), byPVPMask, 1, idTarget); + int countTarget = 1; + targetsCastSkill = new int[countTarget]; + targetsCastSkill[0] = idTarget; + UnityGameSession.c2s_CmdCastInstantSkill(m_pPrepSkill.GetSkillID(), byPVPMask, countTarget, targetsCastSkill); m_pPrepSkill = null; } // Handle flash move skills (鐬Щ鎶鑳) @@ -3941,7 +3946,10 @@ namespace BrewMonster { // Regular skill casting byte byPVPMask2 = glb_BuildPVPMask(bForceAttack); - UnityGameSession.c2s_CmdCastSkill(m_pPrepSkill.GetSkillID(), byPVPMask2, 1, idTarget); + int targets = 1; + targetsCastSkill = new int[targets]; + targetsCastSkill[0] = idTarget; + UnityGameSession.c2s_CmdCastSkill(m_pPrepSkill.GetSkillID(), byPVPMask2, targets, targetsCastSkill); } return true; @@ -5783,13 +5791,13 @@ namespace BrewMonster // Get cool time public int GetCoolTime(int iIndex, ref int piMax /* NULL */) { - // if (iIndex >= 0 && iIndex < GP_CT_MAX) - // { - // if (piMax>0) - // piMax = m_aCoolTimes[iIndex].iMaxTime; - // - // return m_aCoolTimes[iIndex].iCurTime; - // } + if (iIndex >= 0 && iIndex < (int)CoolTimeIndex.GP_CT_MAX) + { + if (piMax > 0) + piMax = m_aCoolTimes[iIndex].iMaxTime; + + return m_aCoolTimes[iIndex].iCurTime; + } return 0; }