diff --git a/Assets/PerfectWorld/Scripts/Move/CECPlayer.cs b/Assets/PerfectWorld/Scripts/Move/CECPlayer.cs index e2f3e39cd4..ce500ffecd 100644 --- a/Assets/PerfectWorld/Scripts/Move/CECPlayer.cs +++ b/Assets/PerfectWorld/Scripts/Move/CECPlayer.cs @@ -1594,6 +1594,13 @@ public abstract partial class CECPlayer : CECObject return; } } + + #region Team + + // Get team to which this player belongs to + // public CECTeam GetTeam() { return m_pTeam; } + + #endregion } public struct PlayActionEvent diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommandFactory.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommandFactory.cs index efcdc4e9fb..d9aa8caad5 100644 --- a/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommandFactory.cs +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommandFactory.cs @@ -668,5 +668,38 @@ namespace CSNetwork.C2SCommand }; return SerializeCommand( CommandID.TASK_NOTIFY, cmd, false); } + + public static Octets CreateAutoTeamSetGoalCommand(int type, int goal_id, int op) + { + // int iSize = sizeof(cmd_header) + sizeof(cmd_auto_team_set_goal); + // uint itemSize = (uint)Marshal.SizeOf(); + // uint totalLen = contentSize + (uint)itemNum * itemSize; + // BYTE* pBuf = (BYTE*)a_malloctemp(iSize); + // if(!pBuf) return; + // + // ((cmd_header*)pBuf)->cmd = C2S::AUTO_TEAM_SET_GOAL; + // + // cmd_auto_team_set_goal pCmd = (cmd_auto_team_set_goal*)(pBuf + sizeof(cmd_header)); + cmd_auto_team_set_goal pCmd = new cmd_auto_team_set_goal() + { + goal_type = type, + goal_id = goal_id, + op = op + }; + + // + // g_pGame->GetGameSession()->SendGameData(pBuf, iSize); + // + // a_freetemp(pBuf); + // var cmd = new CMD_GetAllData + // { + // byPack = Convert.ToByte(byPack), + // byEquip = Convert.ToByte(byEquip), + // byTask = Convert.ToByte(byTask) + // }; + + // Serialize the command and return the serialized data + return SerializeCommand(CommandID.AUTO_TEAM_SET_GOAL, pCmd); + } } } diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GPDataType.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GPDataType.cs index ac2baea4cb..cc9791f03f 100644 --- a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GPDataType.cs +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GPDataType.cs @@ -1819,15 +1819,23 @@ namespace CSNetwork.GPDataType public ROLEEXTPROP prop; }; - [ StructLayout(LayoutKind.Sequential, Pack = 1)] + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct cmd_auto_team_set_goal + { + public int goal_type; // 0 unknown, 1 task, 2 Activity + public int op; + public int goal_id; + }; + + [StructLayout(LayoutKind.Sequential, Pack = 1)] struct cmd_task_deliver_item { - public int type; - public int expire_date; - public uint amount; - public uint slot_amount; - public byte where; //���ĸ���������0 ��׼��2 ����1 װ�� - public byte index; //��󲿷ַ����ĸ�λ�� - }; + public int type; + public int expire_date; + public uint amount; + public uint slot_amount; + public byte where; //���ĸ���������0 ��׼��2 ����1 װ�� + public byte index; //��󲿷ַ����ĸ�λ�� + } } diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs index c5548dce06..a7648fa8df 100644 --- a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs @@ -360,6 +360,13 @@ namespace CSNetwork OnPrtcPlayerBaseInfoRe(protocol); break; case ProtocolType.PROTOCOL_GETUICONFIG_RE: OnPrtcGetConfigRe(protocol); break; + case ProtocolType.PROTOCOL_AUTOTEAMSETGOAL_RE: + { + // CECAutoTeam pAutoTeam = CECGameRun.Instance.GetHostPlayer().GetAutoTeam(); + // if( pAutoTeam !=null) + // pAutoTeam.OnPrtcAutoTeamSetGoalRe((AutoTeamSetGoal_Re)protocol); + } + break; default: _logger.Log(LogType.Warning, $"Received unhandled protocol type: {protocol.GetPType()}"); break; @@ -1294,5 +1301,12 @@ namespace CSNetwork gamedatasend.Data = C2SCommandFactory.CreateNakeCmd(C2SCommand.CommandID.STAND_UP); SendProtocol(gamedatasend); } + + public void c2s_SendCmdAutoTeamSetGoal(int type, int goal_id, int op) + { + gamedatasend gamedatasend = new gamedatasend(); + gamedatasend.Data = C2SCommandFactory.CreateAutoTeamSetGoalCommand(type,goal_id, op); + SendProtocol(gamedatasend); + } } } \ No newline at end of file diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/Protocols/AutoTeamSetGoal_Re.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/Protocols/AutoTeamSetGoal_Re.cs new file mode 100644 index 0000000000..43eace2152 --- /dev/null +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/Protocols/AutoTeamSetGoal_Re.cs @@ -0,0 +1,56 @@ +namespace CSNetwork.Protocols +{ + namespace BrewMonster + { + public class AutoTeamSetGoal_Re : Protocol + { + public int roleid { get; set; } + public int goal_type { get; set; } + public int op { get; set; } + public int goal_id { get; set; } + public int retcode { get; set; } + public int localsid { get; set; } + + public AutoTeamSetGoal_Re() : base(ProtocolType.PROTOCOL_AUTOTEAMSETGOAL_RE) + { + + } + + public override Protocol Clone() => new AutoTeamSetGoal_Re + { + roleid = roleid, + goal_type = goal_type, + op = op, + goal_id = goal_id, + retcode = retcode, + localsid = localsid + }; + + public override void Marshal(OctetsStream os) + { + os.Write(roleid); + os.Write(goal_type); + os.Write(op); + os.Write(goal_id); + os.Write(retcode); + os.Write(localsid); + } + + public override void Unmarshal(OctetsStream os) + { + roleid = os.ReadInt32(); + goal_type = os.ReadInt32(); + op = os.ReadInt32(); + goal_id = os.ReadInt32(); + retcode = os.ReadInt32(); + localsid = os.ReadInt32(); + } + + public override int PriorPolicy() => 1; + + public override bool SizePolicy(int size) => size <= 32; + + public override string ToString => $" Type={Type}"; // - CMD_ID: {Enum.GetName(typeof(CommandID), BitConverter.ToUInt16(Data.ByteArray.Take(2).ToArray())) + } + } +} \ No newline at end of file diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/Protocols/AutoTeamSetGoal_Re.cs.meta b/Assets/PerfectWorld/Scripts/Network/CSNetwork/Protocols/AutoTeamSetGoal_Re.cs.meta new file mode 100644 index 0000000000..1a18b601e0 --- /dev/null +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/Protocols/AutoTeamSetGoal_Re.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 2e2c269d6707b37478238369cf01884f \ No newline at end of file diff --git a/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs b/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs index 5da25ae735..7891a9813d 100644 --- a/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs +++ b/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs @@ -334,6 +334,11 @@ namespace BrewMonster.Network Instance._gameSession.c2s_SendCmdTaskNotify( pBuf, sz); } + public static void c2s_CmdAutoTeamSetGoal(int type, int goal_id, int op) + { + Instance._gameSession.c2s_SendCmdAutoTeamSetGoal(type, goal_id, op);//{ ::c2s_SendCmdAutoTeamSetGoal(type, goal_id, op); } + } + #endregion public static void GetRoleBaseInfo(int iNumRole, List aRoleIDs) diff --git a/Assets/PerfectWorld/Scripts/Players/CECAutoTeam.cs b/Assets/PerfectWorld/Scripts/Players/CECAutoTeam.cs new file mode 100644 index 0000000000..0d0937daa3 --- /dev/null +++ b/Assets/PerfectWorld/Scripts/Players/CECAutoTeam.cs @@ -0,0 +1,185 @@ +using BrewMonster.Network; +using CSNetwork.GPDataType; + +namespace BrewMonster +{ + public class CECAutoTeam + { + public const float TASK_TEAM_DISTANCE = 300.0f; + public enum AutoTeamType + { + TYPE_UNKNOWN, + TYPE_TASK, + TYPE_ACTIVITY, + } + + protected int m_iType; // Auto team type + protected int m_iCurGoal; // For task-based teams: task ID; otherwise activity/event ID + protected A3DVECTOR3 m_vTaskPos; // In task teams: player position + protected CECCounter m_cntCancel; + +// CECAutoTeam::CECAutoTeam() +// { +// m_iType = TYPE_UNKNOWN; +// m_iCurGoal = 0; +// m_vTaskPos.Clear(); +// m_cntCancel.SetPeriod(500); +// m_cntCancel.Reset(); +// } + + public void Tick(float dwDeltaTime) + { + if (m_iType == (int)AutoTeamType.TYPE_TASK && m_iCurGoal>0 && m_cntCancel.IncCounter(dwDeltaTime)) + { + A3DVECTOR3 vPos = CECGameRun.Instance.GetHostPlayer().GetPos(); + var target = m_vTaskPos - vPos; + if (target.MagnitudeH() > TASK_TEAM_DISTANCE) + { + m_vTaskPos = vPos; + Cancel((int)AutoTeamType.TYPE_TASK); + } + m_cntCancel.Reset(); + } + } + + public bool DoAutoTeam(int type, int iGoalID) + { + // if(EC_Game.GetGameRun().GetHostPlayer().GetTeam()) + // return false; + //todo need to get bAutoTeamForTask + var bAutoTeamForTask = 1; + if( type == (int)AutoTeamType.TYPE_TASK && bAutoTeamForTask<=0)//&& !g_pGame->GetConfigs()->GetGameSettings().bAutoTeamForTask + return false; + + // Èç¹ûÕýÔÚ½øÐл×é¶ÓÇëÇó£¬ÔòºöÂÔÆäËûÇëÇó + //todo need to get m_iCurGoal + if( m_iType == (int)AutoTeamType.TYPE_TASK && m_iCurGoal>0)// && m_iCurGoal + return false; + + // ¼Ç¼´ËʱµÄλÖà + if( type == (int)AutoTeamType.TYPE_TASK ) + m_vTaskPos = EC_Game.GetGameRun().GetHostPlayer().GetPos(); + + if( m_iType == type && m_iCurGoal == iGoalID ) + return false; + + UnityGameSession.c2s_CmdAutoTeamSetGoal(type, iGoalID, 1); + return true; + } + + void Cancel(int type) + { + if (m_iType == type && m_iCurGoal>0) + UnityGameSession.c2s_CmdAutoTeamSetGoal(type, m_iCurGoal, 0); + } + + // public void OnPrtcAutoTeamSetGoalRe(Protocol p) + // { + // enum + // { + // ERR_INVALID_GOAL = -1, + // ERR_INVALID_ROLE_STATUS = -2, + // }; + // + // using namespace GNET; + // AutoTeamSetGoal_Re* pProto = (AutoTeamSetGoal_Re*)p; + // if( pProto->retcode == 0 ) + // { + // if( pProto->op == 1 ) + // { + // m_iType = (int)pProto->goal_type; + // m_iCurGoal = pProto->goal_id; + // + // if( pProto->goal_type == TYPE_ACTIVITY ) + // GetGameUIMan()->AddChatMessage(GetGameUIMan()->GetStringFromTable(10864), GP_CHAT_MISC); + // + // // ¸üнçÃæ + // CDlgActivity* pDlg = dynamic_cast(GetGameUIMan()->GetDialog("Win_Activity")); + // if( pDlg ) pDlg->UpdateActivityList(true); + // } + // } + // else + // { + // if( pProto->goal_type == TYPE_ACTIVITY ) + // { + // if( pProto->op == 1 && pProto->retcode == ERR_INVALID_GOAL ) + // GetGameUIMan()->MessageBox("", GetGameUIMan()->GetStringFromTable(10860), MB_OK, A3DCOLORRGBA(255, 255, 255, 160)); + // else if( pProto->op == 0 && pProto->retcode == ERR_INVALID_ROLE_STATUS ) + // GetGameUIMan()->MessageBox("", GetGameUIMan()->GetStringFromTable(10861), MB_OK, A3DCOLORRGBA(255, 255, 255, 160)); + // } + // } + // } + +// void CECAutoTeam::OnPrtcPlayerLeave(GNET::Protocol* p) +// { +// enum +// { +// REASON_COMPOSE_TEAM = 0, +// REASON_INVALID_STATUS, +// REASON_PLAYER_OP, +// REASON_JOIN_TEAM, +// REASON_TIMEOUT, +// }; +// +// using namespace GNET; +// AutoTeamPlayerLeave* pProto = (AutoTeamPlayerLeave*)p; +// if( m_iType == TYPE_ACTIVITY ) +// { +// switch(pProto->reason) +// { +// case REASON_INVALID_STATUS: +// GetGameUIMan()->MessageBox("", GetGameUIMan()->GetStringFromTable(10862), MB_OK, A3DCOLORRGBA(255, 255, 255, 160)); +// break; +// case REASON_TIMEOUT: +// GetGameUIMan()->AddChatMessage(GetGameUIMan()->GetStringFromTable(10863), GP_CHAT_MISC); +// break; +// } +// } +// +// m_iCurGoal = 0; +// m_iType = TYPE_UNKNOWN; +// +// // ¸üнçÃæ +// CDlgActivity* pDlg = dynamic_cast(GetGameUIMan()->GetDialog("Win_Activity")); +// if( pDlg ) pDlg->UpdateActivityList(true); +// } +// +// void CECAutoTeam::OnWorldChanged() +// { +// if( !IsMatchingForActivity() ) +// return; +// +// bool bFound = false; +// int world_id = g_pGame->GetGameRun()->GetWorld()->GetInstanceID(); +// for( size_t i=0;iMessageBox("", GetGameUIMan()->GetStringFromTable(10865), MB_OK, A3DCOLORRGBA(255, 255, 255, 160)); +// Cancel(TYPE_ACTIVITY); +// } +// } +// +// CECGameUIMan* CECAutoTeam::GetGameUIMan() +// { +// return g_pGame->GetGameRun()->GetUIManager()->GetInGameUIMan(); +// } +// +// CECGameSession* CECAutoTeam::GetGameSession() +// { +// return g_pGame->GetGameSession(); +// } +// +// CECHostPlayer* CECAutoTeam::GetHostPlayer() +// { +// return g_pGame->GetGameRun()->GetHostPlayer(); +// } + } +} diff --git a/Assets/PerfectWorld/Scripts/Players/CECAutoTeam.cs.meta b/Assets/PerfectWorld/Scripts/Players/CECAutoTeam.cs.meta new file mode 100644 index 0000000000..feead89096 --- /dev/null +++ b/Assets/PerfectWorld/Scripts/Players/CECAutoTeam.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 0c340e14ce1c73c409d397575cdf8029 \ No newline at end of file diff --git a/Assets/PerfectWorld/Scripts/Task/TaskClient.cs b/Assets/PerfectWorld/Scripts/Task/TaskClient.cs index b7b328db7f..bac843f5ec 100644 --- a/Assets/PerfectWorld/Scripts/Task/TaskClient.cs +++ b/Assets/PerfectWorld/Scripts/Task/TaskClient.cs @@ -462,16 +462,15 @@ namespace BrewMonster.Scripts.Task { // Monster kill count >= 2 triggers auto team // TODO: svr_monster_killed struct not defined; need to define or use alternative - // if (sz == Marshal.SizeOf()) - // { - // svr_monster_killed pKilled = Marshal.PtrToStructure(handle.AddrOfPinnedObject()); - // if (pKilled.monster_num >= 2) - // { - // // TODO: CECAutoTeam and DoAutoTeam not found; implement auto team if needed - // // CECAutoTeam pAutoTeam = g_pGame.GetGameRun().GetHostPlayer().GetAutoTeam(); - // // pAutoTeam.DoAutoTeam(CECAutoTeam.TYPE_TASK, pNotify.task); - // } - // } + if (sz == Marshal.SizeOf()) + { + svr_monster_killed pKilled = GPDataTypeHelper.FromBytes(pBuf) ;//Marshal.PtrToStructure(pNotify.AddrOfPinnedObject()); + if (pKilled.monster_num >= 2) + { + // CECAutoTeam pAutoTeam = EC_Game.GetGameRun().GetHostPlayer().GetAutoTeam(); + // pAutoTeam.DoAutoTeam((int)CECAutoTeam.AutoTeamType.TYPE_TASK, pNotify.task); + } + } // TODO: CECUIHelper.OnTaskProcessUpdated not found; implement UI update if needed // CECUIHelper.OnTaskProcessUpdated(pNotify.task); } diff --git a/Assets/Scripts/CECHostPlayer.cs b/Assets/Scripts/CECHostPlayer.cs index 0a5721e60c..9e554ec44d 100644 --- a/Assets/Scripts/CECHostPlayer.cs +++ b/Assets/Scripts/CECHostPlayer.cs @@ -91,6 +91,8 @@ namespace BrewMonster public uint m_dwMoveRelDir = 0; // Move relative direction flags public ON_AIR_CDR_INFO m_AirCDRInfo; + private CECAutoTeam m_pAutoTeam; // Player auto team / automatic team grouping + // ====== Ground cast config ====== [Header("Ground Cast")] [Tooltip("Khoảng thêm ngoài skinWidth để SphereCast xuống (m ngắn)")] @@ -138,6 +140,7 @@ namespace BrewMonster public EC_Inventory EquipInventory => m_equipInventory; public EC_Inventory TaskInventory => m_taskInventory; public bool IsMeleeing() { return m_bMelee; } + public CECAutoTeam GetAutoTeam() { return m_pAutoTeam; } public EC_Inventory GetInventory(byte byPackage) { @@ -271,6 +274,9 @@ namespace BrewMonster //m_dwMoveRelDir = 0; m_fVertSpeed = 0.0f; + + // Auto team / Automatic party grouping + // m_pAutoTeam.Tick(Time.deltaTime); } public void StopMovement()