bool NFPatrolState::RandomPatrol(const NFGUID& self, NFIStateMachine* pStateMachine) { //首先,得看有没路径 //没有的话,随机找个地址走吧(以出生点为中心开始找,种子地址)NPCConfigID const std::string& strConfigID = m_pKernelModule->GetPropertyString(self, "NPCConfigID"); const std::string& strNPCID = m_pKernelModule->GetPropertyString(self, "ConfigID"); if (!strConfigID.empty()) { NF_SHARE_PTR<NFIPropertyManager> xPropertyManager = m_pElementModule->GetPropertyManager(strConfigID); if (xPropertyManager) { NF_SHARE_PTR<NFIProperty> xPropertyX = xPropertyManager->GetElement("SeedX"); NF_SHARE_PTR<NFIProperty> xPropertyY = xPropertyManager->GetElement("SeedY"); NF_SHARE_PTR<NFIProperty> xPropertyZ = xPropertyManager->GetElement("SeedZ"); double fCurX = xPropertyX->GetFloat(); double fCurY = xPropertyY->GetFloat(); double fCurZ = xPropertyZ->GetFloat(); double fPosOffestX = (double)(rand() / double(RAND_MAX) - 0.5); double fPosOffestZ = (double)(rand() / double(RAND_MAX) - 0.5); fPosOffestX *= 10; fPosOffestZ *= 10; fCurX += fPosOffestX; fCurZ += fPosOffestZ; //if (fCurX > 0.0f && fCurZ > 0.0f) { //看能否寻路,不能寻路则重来 NFAI_STATE eStateType = NFAI_STATE::ChaseState; double fRand = (double)(rand() / double(RAND_MAX)); if (fRand < 0.5f) { eStateType = NFAI_STATE::ChaseState; } NFDataList valueList; valueList.AddFloat(fCurX); valueList.AddFloat(fCurY); valueList.AddFloat(fCurZ); //m_pKernelModule->DoEvent(self, NFED_ON_CLIENT_REQUIRE_MOVE, valueList); m_pKernelModule->SetPropertyFloat(self, "X", fCurX); m_pKernelModule->SetPropertyFloat(self, "Y", fCurY); m_pKernelModule->SetPropertyFloat(self, "Z", fCurZ); return true; } } } return false; }
void NFCPlayerLogic::OnObjectEntry(const NFSOCK nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen) { NFGUID nPlayerID; NFMsg::AckPlayerEntryList xMsg; if (!NFINetModule::ReceivePB(nMsgID, msg, nLen, xMsg, nPlayerID)) { return; } for(int i = 0; i < xMsg.object_list_size(); i++) { const NFMsg::PlayerEntryInfo info = xMsg.object_list(i); NFDataList var; var.Add("X"); var.AddFloat(info.x()); var.Add("Y"); var.AddFloat(info.y()); var.Add("Z"); var.AddFloat(info.z()); g_pKernelModule->CreateObject(NFINetModule::PBToNF(info.object_guid()), info.scene_id(), 0, info.class_id(), info.config_id(), var); } }
// 移动 void NFCPlayerLogic::OnObjectMove(const NFSOCK nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen) { NFGUID nPlayerID; NFMsg::ReqAckPlayerMove xMsg; if (!NFINetModule::ReceivePB(nMsgID, msg, nLen, xMsg, nPlayerID)) { return; } float fMove = g_pKernelModule->GetPropertyInt(NFINetModule::PBToNF(xMsg.mover()), "MOVE_SPEED")/10000.0f; NFDataList var; var.AddObject(NFINetModule::PBToNF(xMsg.mover())); var.AddFloat(fMove); const NFMsg::Vector3 &pos = xMsg.target_pos(0); var.AddVector3(NFVector3(pos.x(), pos.y(), pos.z())); DoEvent(E_PlayerEvent_PlayerMove, var); }