public override NET_RESULT_DEFINE.PACKET_EXE Execute(PacketBase packet, ref Peer pPlayer) { //当前流程是主流程 if (GameProcedure.GetActiveProcedure() == GameProcedure.s_ProcMain) { GCNewPet pPacket = (GCNewPet)packet; CObjectManager pObjectManager = CObjectManager.Instance; //检查位置是否合法 fVector2 pos = new fVector2(pPacket.getWorldPos().m_fX, pPacket.getWorldPos().m_fZ); if (!WorldManager.Instance.ActiveScene.IsValidPosition(ref pos)) { LogManager.LogError("Valid Position @GCNewPetHandler.Execute"); return(NET_RESULT_DEFINE.PACKET_EXE.PACKET_EXE_ERROR); } //创建宠物 CObject_PlayerNPC pNPC = (CObject_PlayerNPC)pObjectManager.FindServerObject((int)pPacket.getObjID()); float fFaceDir = pPacket.getDir(); if (pNPC == null) { pNPC = pObjectManager.NewPlayerNPC((int)pPacket.getObjID()); SObjectInit initPlayerNPC = new SObjectInit(); initPlayerNPC.m_fvPos = new Vector3(pos.x, 0, pos.y); initPlayerNPC.m_fvRot = new Vector3(0.0f, fFaceDir, 0.0f); pNPC.Initial(initPlayerNPC); } else { pNPC.SetMapPosition(pos.x, pos.y); pNPC.SetFaceDir(fFaceDir); pNPC.Enable((uint)ObjectStatusFlags.OSF_VISIABLE); pNPC.Disalbe((uint)ObjectStatusFlags.OSF_OUT_VISUAL_FIELD); } pNPC.SetNpcType(ENUM_NPC_TYPE.NPC_TYPE_PET); pNPC.GetCharacterData().Set_MoveSpeed(pPacket.getMoveSpeed()); SCommand_Object cmdTemp = new SCommand_Object(); cmdTemp.m_wID = (int)OBJECTCOMMANDDEF.OC_IDLE; cmdTemp.SetValue <float>(0, pos.x); cmdTemp.SetValue <float>(1, pos.y); cmdTemp.SetValue <bool>(2, false); pNPC.PushCommand(cmdTemp); //放入Ask队列 pObjectManager.LoadQueue.TryAddLoadTask(pNPC.ID); //同步渲染层 string szTemp = "GCNewPet(" + pos.x.ToString() + "," + pos.y.ToString() + ")"; pNPC.PushDebugString(szTemp); pNPC.SetMsgTime(GameProcedure.s_pTimeSystem.GetTimeNow()); } return(NET_RESULT_DEFINE.PACKET_EXE.PACKET_EXE_CONTINUE);; }
public CObject_PlayerNPC NewFakePlayerNPC() { CObject_PlayerNPC newFakePlayerNPC = new CObject_PlayerNPC(); newFakePlayerNPC.ServerID = -1; newFakePlayerNPC.SetFakeObjectFlag(true); newFakePlayerNPC.Initial(null); newFakePlayerNPC.SetPosition(new Vector3(0, 0, 0)); return(newFakePlayerNPC); }
public override NET_RESULT_DEFINE.PACKET_EXE Execute(PacketBase pPacket, ref Peer pPlayer) { //当前流程是主流程 if (GameProcedure.GetActiveProcedure() == (GameProcedure)GameProcedure.s_ProcMain) { GCNewMonster_Death newMonsterPacket = (GCNewMonster_Death)pPacket; CObjectManager pObjectManager = GameProcedure.s_pObjectManager; // //检查位置是否合法 // if(!CWorldManager::GetMe().GetActiveScene().IsValidPosition(fVector2(newMonsterPacket.getWorldPos().m_fX, newMonsterPacket.getWorldPos().m_fZ))) // { // TDThrow("ERROR POSITION @ GCNewMonsterHandler"); // } //创建玩家 CObject_PlayerNPC pNPC = (CObject_PlayerNPC)pObjectManager.FindServerObject((int)newMonsterPacket.ObjectID); if (pNPC == null) { pNPC = pObjectManager.NewPlayerNPC((int)newMonsterPacket.ObjectID); pNPC.Initial(null); } else { // pNPC.Enable( OSF_VISIABLE ); // pNPC.Disalbe( OSF_OUT_VISUAL_FIELD ); } //设置怪物位置和面向 pNPC.SetMapPosition(newMonsterPacket.Position.m_fX, newMonsterPacket.Position.m_fZ); pNPC.SetFaceDir(newMonsterPacket.Dir); if (newMonsterPacket.IsNpc != 0) { pNPC.SetNpcType(ENUM_NPC_TYPE.NPC_TYPE_NPC); } else { pNPC.SetNpcType(ENUM_NPC_TYPE.NPC_TYPE_MONSTER); } SCommand_Object cmdTemp = new SCommand_Object(); cmdTemp.m_wID = (int)OBJECTCOMMANDDEF.OC_DEATH; cmdTemp.SetValue <bool>(0, false); pNPC.PushCommand(cmdTemp); //清除界面选中NPC if (CObjectManager.Instance.GetMainTarget() != null && pNPC != null && (CObjectManager.Instance.GetMainTarget().ID == pNPC.ID)) { GameProcedure.s_pGameInterface.Object_SelectAsMainTarget(MacroDefine.INVALID_ID); } pNPC.GetCharacterData().Set_MoveSpeed(newMonsterPacket.MoveSpeed); //放入Ask队列 pObjectManager.LoadQueue.TryAddLoadTask(pNPC.ID); //此版不做服务器繁忙客户端延后发消息的处理 // CGCharAskBaseAttrib msgAskBaseAttrib = new CGCharAskBaseAttrib(); // msgAskBaseAttrib.setTargetID( (uint)newMonsterPacket.ObjectID); // GameProcedure.s_NetManager.SendPacket(msgAskBaseAttrib ); // char szTemp[MAX_PATH]; // _snprintf(szTemp, MAX_PATH, "GCNewMonster(%.1f,%.1f)", // newMonsterPacket.getWorldPos().m_fX, newMonsterPacket.getWorldPos().m_fZ); // pNPC.PushDebugString(szTemp); pNPC.SetMsgTime(GameProcedure.s_pTimeSystem.GetTimeNow()); } return(NET_RESULT_DEFINE.PACKET_EXE.PACKET_EXE_CONTINUE); }
public override NET_RESULT_DEFINE.PACKET_EXE Execute(PacketBase pPacket, ref Peer pPlayer) { //if(GameProcedure.GetActiveProcedure() == GameProcedure.s_ProcMain) // LogManager.Log("RECV GCNewMonster"); //当前流程是主流程 if (GameProcedure.GetActiveProcedure() == (GameProcedure)GameProcedure.s_ProcMain) { GCNewMonster newMonsterPacket = (GCNewMonster)pPacket; CObjectManager pObjectManager = GameProcedure.s_pObjectManager; // //检查位置是否合法 // if(!CWorldManager::GetMe().GetActiveScene().IsValidPosition(fVector2(newMonsterPacket.getWorldPos().m_fX, newMonsterPacket.getWorldPos().m_fZ))) // { // TDThrow("ERROR POSITION @ GCNewMonsterHandler"); // } //创建玩家 CObject_PlayerNPC pNPC = (CObject_PlayerNPC )pObjectManager.FindServerObject((int)newMonsterPacket.ObjectID); if (pNPC == null) { pNPC = pObjectManager.NewPlayerNPC((int)newMonsterPacket.ObjectID); pNPC.Initial(null); } else { // pNPC.Enable( OSF_VISIABLE ); // pNPC.Disalbe( OSF_OUT_VISUAL_FIELD ); } //设置怪物位置和面向 pNPC.SetMapPosition(newMonsterPacket.Position.m_fX, newMonsterPacket.Position.m_fZ); pNPC.SetFaceDir(newMonsterPacket.Dir); if (newMonsterPacket.IsNpc != 0) { pNPC.SetNpcType(ENUM_NPC_TYPE.NPC_TYPE_NPC); } else { pNPC.SetNpcType(ENUM_NPC_TYPE.NPC_TYPE_MONSTER); } pNPC.GetCharacterData().Set_MoveSpeed(newMonsterPacket.MoveSpeed); // SGWEB.SCommand_Object cmdTemp; // cmdTemp.m_wID = (SGWEB.AICommandDef)ObjectCommandDef.OC_IDLE; // cmdTemp.m_afParam[0] = newMonsterPacket.Position.m_fX; // cmdTemp.m_afParam[1] = newMonsterPacket.Position.m_fZ; // cmdTemp.m_abParam[2] = false; // pNPC.PushCommand(cmdTemp ); //放入Ask队列 pObjectManager.LoadQueue.TryAddLoadTask(pNPC.ID); //此版不做服务器繁忙客户端延后发消息的处理 // CGCharAskBaseAttrib msgAskBaseAttrib = new CGCharAskBaseAttrib(); // msgAskBaseAttrib.setTargetID( (uint)newMonsterPacket.ObjectID); // GameProcedure.s_NetManager.SendPacket(msgAskBaseAttrib ); // char szTemp[MAX_PATH]; // _snprintf(szTemp, MAX_PATH, "GCNewMonster(%.1f,%.1f)", // newMonsterPacket.getWorldPos().m_fX, newMonsterPacket.getWorldPos().m_fZ); // pNPC.PushDebugString(szTemp); pNPC.SetMsgTime(GameProcedure.s_pTimeSystem.GetTimeNow()); } return(NET_RESULT_DEFINE.PACKET_EXE.PACKET_EXE_CONTINUE); }
public override NET_RESULT_DEFINE.PACKET_EXE Execute(PacketBase pPacket, ref Peer pPlayer) { //当前流程是主流程 if (GameProcedure.GetActiveProcedure() == (GameProcedure)GameProcedure.s_ProcMain) { CObjectManager pObjectManager = CObjectManager.Instance; GCNewMonster_Move newMonsterMovPacket = (GCNewMonster_Move)pPacket; // //检查位置是否合法 // if(!CWorldManager::GetMe().GetActiveScene().IsValidPosition(fVector2(pPacket.getWorldPos().m_fX, pPacket.getWorldPos().m_fZ))) // { // TDThrow("ERROR POSITION @ GCNewMonster_MoveHandler"); // } // if(!CWorldManager::GetMe().GetActiveScene().IsValidPosition(fVector2(pPacket.getTargetPos().m_fX, pPacket.getTargetPos().m_fZ))) // { // TDThrow("ERROR POSITION @ GCNewMonster_MoveHandler target"); // } //创建玩家 CObject_PlayerNPC pNPC = (CObject_PlayerNPC)pObjectManager.FindServerObject((int)newMonsterMovPacket.getObjID()); if (pNPC == null) { pNPC = pObjectManager.NewPlayerNPC((int)newMonsterMovPacket.getObjID()); pNPC.Initial(null); } else { //pNPC.Enable( OSF_VISIABLE ); // pNPC.Disalbe( OSF_OUT_VISUAL_FIELD ); } //设置x z坐标 pNPC.SetMapPosition(newMonsterMovPacket.getWorldPos().m_fX, newMonsterMovPacket.getWorldPos().m_fZ); if (newMonsterMovPacket.getIsNPC()) { pNPC.SetNpcType(ENUM_NPC_TYPE.NPC_TYPE_NPC); } else { pNPC.SetNpcType(ENUM_NPC_TYPE.NPC_TYPE_MONSTER); } pNPC.GetCharacterData().Set_MoveSpeed(newMonsterMovPacket.getMoveSpeed()); // move to command { WORLD_POS[] posTarget = new WORLD_POS[1]; posTarget[0].m_fX = newMonsterMovPacket.getTargetPos().m_fX; posTarget[0].m_fZ = newMonsterMovPacket.getTargetPos().m_fZ; SCommand_Object cmdTemp = new SCommand_Object(); cmdTemp.m_wID = (int)OBJECTCOMMANDDEF.OC_MOVE; cmdTemp.SetValue <uint>(0, 0); cmdTemp.SetValue(1, newMonsterMovPacket.getHandleID()); cmdTemp.SetValue(2, 1); cmdTemp.SetValue <WORLD_POS[]>(3, posTarget); pNPC.PushCommand(cmdTemp); } //放入Ask队列 pObjectManager.LoadQueue.TryAddLoadTask(pNPC.ID); //tempcode // { // //此版不做服务器繁忙客户端延后发消息的处理 // CGCharAskBaseAttrib msgAskBaseAttrib = new CGCharAskBaseAttrib(); // msgAskBaseAttrib.setTargetID( (uint)(int)newMonsterMovPacket.getObjID()); // GameProcedure.s_NetManager.SendPacket(msgAskBaseAttrib ); // // } pNPC.SetMsgTime(GameProcedure.s_pTimeSystem.GetTimeNow()); } return(NET_RESULT_DEFINE.PACKET_EXE.PACKET_EXE_CONTINUE);; }