Merge pull request 'Add cmd cache.' (#125) from feature/hp_swim into develop

Reviewed-on: https://git.brew.monster/Unity/perfect-world-unity/pulls/125
This commit is contained in:
tungdv
2026-01-16 12:19:03 +00:00
10 changed files with 2495 additions and 1574 deletions
@@ -0,0 +1,741 @@
using BrewMonster.Network;
using BrewMonster.Scripts.Managers;
using CSNetwork.C2SCommand;
using CSNetwork.Protocols;
using CSNetwork.S2CCommand;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace BrewMonster.Common
{
using CounterTable = Dictionary<int, CECCounter>;
public class CECC2SCmdCache
{
public struct presentInfo
{
public int roleid;
public int mailid;
public int itemid;
public int index;
public int slot;
};
int m_idLastPickUpItem; // ID of picked up item last time
int m_idLastSelTarget; // ID of selected item last time
bool m_bGetExpProps;
bool m_bEnterSanctuary;
CounterTable m_CounterMap = new CounterTable();
CounterTable m_CounterMap2 = new CounterTable();
List<cmd_use_item> m_UseItemCmdList = new List<cmd_use_item>();
List<getplayerbriefinfo> m_GetPlayerBriefInfoList = new List<getplayerbriefinfo>();
List<int> m_PlayerBaseInfoList = new List<int>();
List<int> m_EnterSanctuaryList = new List<int>();
List<presentInfo> m_PresentInfoList = new List<presentInfo>();
public CECC2SCmdCache()
{
m_idLastPickUpItem = 0;
m_idLastSelTarget = 0;
m_bGetExpProps = false;
m_bEnterSanctuary = false;
InitCounters();
}
// Initialize counters
bool InitCounters()
{
// 'Use item' command time counter
CECCounter pCnt = new CECCounter();
pCnt.SetPeriod(200);
pCnt.Reset(true);
if (m_CounterMap.ContainsKey((int)CommandID.USE_ITEM))
{
m_CounterMap[(int)CommandID.USE_ITEM] = pCnt;
}
else
{
m_CounterMap.Add((int)CommandID.USE_ITEM, pCnt);
}
// 'Pickup item' command time counter
pCnt = new CECCounter();
pCnt.SetPeriod(500);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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
public void RemoveAllCmds()
{
m_UseItemCmdList.Clear();
// 重置 C2S 命令计时器
m_CounterMap[(int)CommandID.USE_ITEM].Reset(true);
m_EnterSanctuaryList.Clear();
m_CounterMap[(int)CommandID.ENTER_SANCTUARY].Reset(true);
m_bEnterSanctuary = false;
m_PresentInfoList.Clear();
m_CounterMap[(int)CommandID.PLAYER_GIVE_PRESENT].Reset(true);
// 重置协议计时器
m_GetPlayerBriefInfoList.Clear();
m_CounterMap2[(int)ProtocolType.PROTOCOL_GETPLAYERBRIEFINFO].Reset(true);
m_PlayerBaseInfoList.Clear();
m_CounterMap2[(int)ProtocolType.PROTOCOL_PLAYERBASEINFO].Reset(true);
m_CounterMap2[(int)ProtocolType.PROTOCOL_FACTIONRESOURCEBATTLEGETMAP].Reset(true);
m_CounterMap2[(int)ProtocolType.PROTOCOL_FACTIONRESOURCEBATTLEGETRECORD].Reset(true);
}
// Tick routine
public bool Tick(float dwDeltaTime)
{
float dwRealTime = Time.realtimeSinceStartup;
foreach (var item in m_CounterMap)
{
item.Value.IncCounter(dwRealTime);
}
foreach (var item in m_CounterMap2)
{
item.Value.IncCounter(dwRealTime);
}
// Try to send 'use item' command in cache
SendCachedCmdUseItem();
// Try to send 'get extend properties' command
SendCachedCmdGetExtProp();
// Try to send 'GetPlayerBriefInfo'
SendCachedGetPlayerBriefInfo();
// Try to send 'PlayerBaseInfo'
SendCachedPlayerBaseInfo();
// Try to send 'PresentInfo'
SendCachedPresentInfo();
if (m_bEnterSanctuary)
{
CECCounter pCnt = m_CounterMap[(int)CommandID.ENTER_SANCTUARY];
if (pCnt.IsFull())
{
for (int i = 0; i < m_EnterSanctuaryList.Count; i++)
{
int id = m_EnterSanctuaryList[i];
UnityGameSession.Instance.GameSession.c2s_SendCmdEnterSanctuary(id);
}
m_EnterSanctuaryList.Clear();
m_bEnterSanctuary = false;
}
}
return true;
}
// Send 'use item' command
void SendCachedCmdUseItem()
{
CECCounter pCnt = m_CounterMap[(int)CommandID.USE_ITEM];
if (!pCnt.IsFull() || m_UseItemCmdList.Count == 0)
return;
pCnt.Reset();
// Send the first item
cmd_use_item Cmd = m_UseItemCmdList[0];
UnityGameSession.Instance.GameSession.c2s_SendCmdUseItem(Cmd.where, (byte)Cmd.index, Cmd.item_id, Cmd.byCount);
m_UseItemCmdList.Clear();
}
// Send cached 'get extend properties' command
void SendCachedCmdGetExtProp()
{
CECCounter pCnt = m_CounterMap[(int)CommandID.GET_EXT_PROP];
if (!m_bGetExpProps || !pCnt.IsFull())
return;
pCnt.Reset();
m_bGetExpProps = false;
UnityGameSession.Instance.GameSession.c2s_SendCmdGetExtProps();
}
// Send cached 'GetPlayerBriefInfo' command
void SendCachedGetPlayerBriefInfo()
{
CECCounter pCnt = m_CounterMap2[(int)ProtocolType.PROTOCOL_GETPLAYERBRIEFINFO];
if (!pCnt.IsFull() || m_GetPlayerBriefInfoList.Count == 0)
return;
pCnt.Reset();
getplayerbriefinfo p = m_GetPlayerBriefInfoList[0];
if (p.Playerlist.Count != 0)
{
// 获取第一个玩家id并向服务器发送协议
getplayerbriefinfo temp = p;
temp.Playerlist.Clear();
temp.Playerlist.Add(p.Playerlist[0]);
UnityGameSession.Instance.GameSession.SendProtocol(temp);
// 从列表中清除
p.Playerlist.Remove(p.Playerlist[0]);
}
if (p.Playerlist.Count == 0)
m_GetPlayerBriefInfoList.Remove(p);
}
// Remove the cached 'PlayerBaseInfo' request
public void RemovePlayerBaseInfo(int iRoleID)
{
int pos = m_PlayerBaseInfoList.Find(x => x == iRoleID);
if (pos != 0)
{
m_PlayerBaseInfoList.RemoveAt(pos);
}
}
// Send cached 'PlayerBaseInfo' protocol
void SendCachedPlayerBaseInfo()
{
CECCounter pCnt = m_CounterMap2[(int)ProtocolType.PROTOCOL_PLAYERBASEINFO];
if (!pCnt.IsFull() || m_PlayerBaseInfoList.Count == 0)
return;
pCnt.Reset();
List<int> aRoles = new List<int>();
for (int i = 0; i < m_PlayerBaseInfoList.Count; i++)
{
aRoles.Add(m_PlayerBaseInfoList[i]);
}
UnityGameSession.Instance.GameSession.GetRoleBaseInfo(aRoles.Count, aRoles);
}
void SendCachedPresentInfo()
{
CECCounter pCnt = m_CounterMap[(int)CommandID.PLAYER_GIVE_PRESENT];
if (!pCnt.IsFull() || m_PresentInfoList.Count == 0)
return;
pCnt.Reset();
presentInfo info = m_PresentInfoList[0];
UnityGameSession.Instance.GameSession.c2s_SendCmdGivePresent(info.roleid, info.mailid, info.itemid, info.index, info.slot);
m_PresentInfoList.Remove(info);
}
// Send commands ...
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.Instance.GameSession.c2s_SendCmdUseItem(byPackage, bySlot, tid, byCount);
return;
}
cmd_use_item Cmd = new cmd_use_item();
if (m_UseItemCmdList.Count == 0)
{
Cmd.where = byPackage;
Cmd.index = bySlot;
Cmd.item_id = tid;
Cmd.byCount = byCount;
m_UseItemCmdList.Add(Cmd);
return;
}
int idx = -1;
for (int i = 0; i < m_UseItemCmdList.Count; i++)
{
Cmd = m_UseItemCmdList[i];
if (Cmd.where == byPackage && Cmd.index == bySlot)
{
CECHostPlayer pHost = EC_Game.GetGameRun().GetHostPlayer();
EC_Inventory pPack = pHost.GetPack(byPackage);
if (pPack == null) return;
EC_IvtrItem pItem = pPack.GetItem(bySlot);
if (pItem == null || !pItem.CheckUseCondition())
return;
int iTotal = Cmd.byCount + byCount;
if (iTotal >= pItem.GetCount())
iTotal = pItem.GetCount();
AAssist.a_ClampRoof(ref iTotal, 255);
Cmd.byCount = (byte)iTotal;
break;
}
idx++;
}
if (idx < 0)
{
Cmd = new cmd_use_item();
Cmd.where = byPackage;
Cmd.index = bySlot;
Cmd.item_id = tid;
Cmd.byCount = byCount;
m_UseItemCmdList.Add(Cmd);
}
// Try to send command in cache
SendCachedCmdUseItem();
}
/* Send 'pick up item' command
The strategy to send 'pick up item' command:
1. if the item is just the one which was to be picked up, check whether
enough time has passed since last command was sent. If true, send
command again, otherwise just throw command
2. if the item isn't the one which was to be picked up, send command
directly.
*/
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.c2s_SendCmdReviveVillage(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.c2s_SendCmdReviveItem(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)
{
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);
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: a442b391d3e801346ac42d47da8c93b2
@@ -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<cmd_object_move>())
// {
// return default;
// }
// cmd_object_move result = new cmd_object_move();
// int preLenghtData = 0;
// int lenghtDataType = Marshal.SizeOf<int>();
// byte[] arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData);
// result.id = BitConverter.ToInt32(arrByteData);
// preLenghtData += lenghtDataType;
// lenghtDataType = Marshal.SizeOf<float>();
// arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData);
// result.dest_X = BitConverter.ToSingle(arrByteData);
// preLenghtData += lenghtDataType;
// lenghtDataType = Marshal.SizeOf<float>();
// arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData);
// result.dest_Y = BitConverter.ToSingle(arrByteData);
// preLenghtData += lenghtDataType;
// lenghtDataType = Marshal.SizeOf<float>();
// arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData);
// result.dest_Z = BitConverter.ToSingle(arrByteData);
// preLenghtData += lenghtDataType;
// lenghtDataType = Marshal.SizeOf<ushort>();
// arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData);
// result.use_time = BitConverter.ToUInt16(arrByteData);
// preLenghtData += lenghtDataType;
// lenghtDataType = Marshal.SizeOf<short>();
// 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ỏi cache
//g_pGame.GetGameSession().GetC2SCmdCache().RemovePlayerBaseInfo(cid);
UnityGameSession.Instance.GetC2SCmdCache().RemovePlayerBaseInfo(cid);
break;
/*case long value when value == EC_MsgDef.MSG_PM_PLAYERCUSTOM:
@@ -1501,6 +1501,75 @@ namespace CSNetwork.S2CCommand
public ushort index;
public int item_id;
};
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct cmd_player_give_present
{
public int roleid; //ÔùÓè¶ÔÏóµÄroleid
public int mail_id; //Ë÷È¡ÎïÆ·ÓʼþµÄË÷Òý£¬Ã»ÓеĻ°Îª-1
public int goods_id; //ÔùÓèÎïÆ·µÄid
public int goods_index; //ÔùÓèÎïÆ·ÔÚÉ̳ÇÖеÄË÷Òý
public int goods_slot; //ÔùÓèÎïÆ·µÄÏúÊÛÐÅÏ¢Ë÷Òý
};
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct cmd_enter_sanctuary
{
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 pets 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 skills 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 commands 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
@@ -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);
@@ -821,5 +824,55 @@ namespace CSNetwork.C2SCommand
pCmd.byCount = byCount;
return SerializeCommand(CommandID.USE_ITEM, pCmd);
}
public static Octets CreateGivePresentCmd(int roleid, int mail_id, int goods_id, int goods_index, int goods_slot)
{
cmd_player_give_present pCmd = new cmd_player_give_present();
pCmd.roleid = roleid;
pCmd.mail_id = mail_id;
pCmd.goods_id = goods_id;
pCmd.goods_index = goods_index;
pCmd.goods_slot = goods_slot;
return SerializeCommand(CommandID.PLAYER_GIVE_PRESENT, pCmd);
}
public static Octets CreateEnterSanctuaryCmd(int id)
{
cmd_enter_sanctuary pCmd = new cmd_enter_sanctuary();
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);
}
}
}
File diff suppressed because it is too large Load Diff
@@ -8,7 +8,7 @@ namespace CSNetwork.Protocols
public int Roleid { get; set; }
public int Localsid { get; set; }
public byte Reason { get; set; }
public List<int> Playerlist { get; set; }
public getplayerbriefinfo() : base(ProtocolType.PROTOCOL_GETPLAYERBRIEFINFO)
{
@@ -18,7 +18,8 @@ namespace CSNetwork.Protocols
{
Roleid = Roleid,
Localsid = Localsid,
Reason = Reason
Reason = Reason,
Playerlist = Playerlist
};
public override void Marshal(OctetsStream os)
@@ -26,6 +27,7 @@ namespace CSNetwork.Protocols
os.Write(Roleid);
os.Write(Localsid);
os.Write(Reason);
os.WriteListInt(Playerlist);
}
public override void Unmarshal(OctetsStream os)
@@ -33,6 +35,7 @@ namespace CSNetwork.Protocols
Roleid = os.ReadInt32();
Localsid = os.ReadInt32();
Reason = os.ReadByte();
os.ReadListInt(Playerlist);
}
public override int PriorPolicy() => 1;
@@ -33,13 +33,16 @@ 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)
if (_gameSession != null && isDebg != lastDebug)
{
_gameSession.IsDebug = isDebg;
lastDebug = isDebg;
@@ -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.c2s_SendCmdReviveVillage();
Instance._gameSession.CmdCache.SendCmdReviveVillage();
}
public static void RequestReviveItem()
public static void c2s_CmdReviveItem()
{
Instance._gameSession.c2s_SendCmdReviveItem();
Instance._gameSession.CmdCache.SendCmdReviveItem();
}
public static void RequestReviveByPlayer()
{
@@ -269,7 +272,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)
@@ -279,7 +282,7 @@ namespace BrewMonster.Network
public static void c2s_CmdCancelAction()
{
Instance._gameSession.c2s_CmdCancelAction();
Instance._gameSession.CmdCache.SendCmdCancelAction();
}
public static void c2s_CmdUnselect()
@@ -289,7 +292,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()
{
@@ -405,22 +408,38 @@ 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);
}
public static void c2s_CmdUseItem(byte byPackage, byte bySlot, int tid, byte byCount)
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.CmdCache.SendCmdExtProps();
}
public static void c2s_SendCmdGivePresent(int roleid, int mail_id, int goods_id, int goods_index, int goods_slot)
{
Instance._gameSession.c2s_SendCmdGivePresent(roleid, mail_id, goods_id, goods_index, goods_slot);
}
public void Update()
{
_gameSession?.CmdCache?.Tick(Time.deltaTime);
}
}
}
@@ -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()
+40 -10
View File
@@ -23,6 +23,7 @@ using System.Runtime.InteropServices;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
using static BrewMonster.Scripts.Managers.EC_Inventory;
using Host_work_ID = BrewMonster.Scripts.CECHPWork.Host_work_ID;
using Trace_reason = BrewMonster.CECHPWorkTrace.Trace_reason;
@@ -158,6 +159,8 @@ namespace BrewMonster
private UnityEngine.InputSystem.Mouse m_cachedMouse;
private UnityEngine.InputSystem.Keyboard m_cachedKeyboard;
int[] targetsCastSkill;
public bool IsChangingFace()
{
return m_bChangingFace;
@@ -3910,7 +3913,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 (瞬移技能)
@@ -4080,7 +4086,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;
@@ -5924,13 +5933,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;
}
@@ -6702,7 +6711,7 @@ namespace BrewMonster
return false;
}
UnityGameSession.c2s_CmdUseItem(InventoryConst.IVTRTYPE_EQUIPPACK, InventoryConst.EQUIPIVTR_FLYSWORD, pItem.GetTemplateID(), 1);
UnityGameSession.c2s_SendCmdUseItem(InventoryConst.IVTRTYPE_EQUIPPACK, InventoryConst.EQUIPIVTR_FLYSWORD, pItem.GetTemplateID(), 1);
return true;
}
@@ -6754,6 +6763,27 @@ namespace BrewMonster
m_bRushFly = pCmd.is_active != 0 ? true : false;
}
}
public EC_Inventory GetPack(int iPack)
{
EC_Inventory pInventory = null;
switch (iPack)
{
case Inventory_type.IVTRTYPE_PACK: pInventory = m_pPack; break;
case Inventory_type.IVTRTYPE_EQUIPPACK: pInventory = m_pEquipPack; break;
case Inventory_type.IVTRTYPE_TASKPACK: pInventory = m_pTaskPack; break;
//case Inventory_type.IVTRTYPE_TRASHBOX: pInventory = m_pTrashBoxPack; break;
//case Inventory_type.IVTRTYPE_TRASHBOX2: pInventory = m_pTrashBoxPack2; break;
//case Inventory_type.IVTRTYPE_TRASHBOX3: pInventory = m_pTrashBoxPack3; break;
//case Inventory_type.IVTRTYPE_ACCOUNT_BOX: pInventory = m_pAccountBoxPack; break;
//case Inventory_type.IVTRTYPE_GENERALCARD_BOX: pInventory = m_pGeneralCardPack; break;
//case IVTRTYPE_PACK_CLIENT_GENERALCAR.IVTRTYPE_CLIENT_GENERALCARD_PACK: pInventory = m_pClientGenCardPack; break;
default:
return null;
}
return pInventory;
}
public int GetEquippedSuiteItem(int idSuite, ref int[] aItems)
{
int i, iItemCnt = 0;