NF_SHARE_PTR<NFIPropertyManager> NFCCommonRedisModule::NewPropertyManager(const std::string& strClassName) { NF_SHARE_PTR<NFIPropertyManager> pStaticClassPropertyManager = m_pLogicClassModule->GetClassPropertyManager(strClassName); if (pStaticClassPropertyManager) { NFGUID ident; NF_SHARE_PTR<NFIPropertyManager> pPropertyManager(NF_NEW NFCPropertyManager(ident)); NF_SHARE_PTR<NFIProperty> pStaticConfigPropertyInfo = pStaticClassPropertyManager->First(); while (pStaticConfigPropertyInfo) { if (pStaticConfigPropertyInfo->GetSave() || pStaticConfigPropertyInfo->GetCache()) { NF_SHARE_PTR<NFIProperty> xProperty = pPropertyManager->AddProperty(ident, pStaticConfigPropertyInfo->GetKey(), pStaticConfigPropertyInfo->GetType()); xProperty->SetPublic(pStaticConfigPropertyInfo->GetPublic()); xProperty->SetPrivate(pStaticConfigPropertyInfo->GetPrivate()); xProperty->SetSave(pStaticConfigPropertyInfo->GetSave()); xProperty->SetCache(pStaticConfigPropertyInfo->GetCache()); xProperty->SetRef(pStaticConfigPropertyInfo->GetRef()); } pStaticConfigPropertyInfo = pStaticClassPropertyManager->Next(); } return pPropertyManager; } return NF_SHARE_PTR<NFIPropertyManager>(NULL); }
int NFCPropertyTrailModule::TrailObjectData(const NFGUID& self) { NF_SHARE_PTR<NFIObject> xObject = m_pKernelModule->GetObject(self); if (nullptr == xObject) { return -1; } NF_SHARE_PTR<NFIPropertyManager> xPropertyManager = xObject->GetPropertyManager(); if (nullptr != xPropertyManager) { NF_SHARE_PTR<NFIProperty> xProperty = xPropertyManager->First(); while (nullptr != xProperty) { m_pKernelModule->AddPropertyCallBack(self, xProperty->GetKey(), this, &NFCPropertyTrailModule::OnObjectPropertyEvent); xProperty = xPropertyManager->Next(); } } NF_SHARE_PTR<NFIRecordManager> xRecordManager = xObject->GetRecordManager(); if (nullptr != xRecordManager) { NF_SHARE_PTR<NFIRecord> xRecord = xRecordManager->First(); while (nullptr != xRecord) { m_pKernelModule->AddRecordCallBack(self, xRecord->GetName(), this, &NFCPropertyTrailModule::OnObjectRecordEvent); xRecord = xRecordManager->Next(); } } return 0; }
int NFCItemModule::AddItemEffectDataProperty(const NFGUID& self, const NFGUID& xTarget, const std::string& strItemID) { if (strItemID.empty()) { return 1; } ////////////////////////////////////////////////////////////////////////// NF_SHARE_PTR<NFIObject> pObject = m_pKernelModule->GetObject(xTarget); if (NULL == pObject) { //m_pLogModule->LogObject(NFILogModule::NLL_ERROR_NORMAL, self, "There is no object", __FUNCTION__, __LINE__); return 1; } ////////////////////////////////////////////////////////////////////////// NF_SHARE_PTR<NFIPropertyManager> pPropertyManager = m_pElementModule->GetPropertyManager(strItemID); if (!pPropertyManager) { return 1; } NF_SHARE_PTR<NFIProperty> pEffectDataProperty = pPropertyManager->GetElement("EffectData"); if (!pEffectDataProperty) { return 1; } NF_SHARE_PTR<NFIPropertyManager> pEffectDataPropertyManager = m_pElementModule->GetPropertyManager(pEffectDataProperty->GetString()); if (!pEffectDataPropertyManager) { return 1; } NF_SHARE_PTR<NFIProperty> pProperty = pEffectDataPropertyManager->First(); while (pProperty) { if (pProperty->GetInt() != 0) { m_pPropertyModule->AddPropertyValue(xTarget, pProperty->GetKey(), NFIPropertyModule::NPG_EQUIP, pProperty->GetInt()); } pProperty = pEffectDataPropertyManager->Next(); } return 0; }
NF_SHARE_PTR<NFIProperty> NFCPropertyManager::AddProperty(const NFIDENTID& self, NF_SHARE_PTR<NFIProperty> pProperty) { const std::string& strProperty = pProperty->GetKey(); NF_SHARE_PTR<NFIProperty> pOldProperty = this->GetElement(strProperty); if (!pOldProperty.get()) { NF_SHARE_PTR<NFIProperty> pNewProperty(NF_NEW NFCProperty(self, strProperty, pProperty->GetType(), pProperty->GetPublic(), pProperty->GetPrivate(), pProperty->GetSave(), pProperty->GetView(), pProperty->GetIndex(), pProperty->GetRelationValue())); this->AddElement(strProperty, pNewProperty); if (pProperty->GetIndex() > 0) { mxPropertyIndexMap.insert(std::map<std::string, int>::value_type(strProperty, pProperty->GetIndex())); } } return pOldProperty; }
NF_SHARE_PTR<NFIPropertyManager> NFCCommonRedisModule::GetPropertyInfo(const NFGUID& self, const std::string& strClassName, std::vector<std::string>& vKeyCacheList, std::vector<std::string>& vValueCacheList) { //TODO optimize NF_SHARE_PTR<NFIPropertyManager> pPropertyManager = NewPropertyManager(strClassName); if (!pPropertyManager) { return nullptr; } NF_SHARE_PTR<NFIRedisClient> pDriver = m_pNoSqlModule->GetDriverBySuit(self.ToString()); if (!pDriver) { return nullptr; } //TODO //just run this function one time NF_SHARE_PTR<NFIProperty> xProperty = pPropertyManager->First(); while (xProperty) { if (xProperty->GetCache() || xProperty->GetSave()) { vKeyCacheList.push_back(xProperty->GetKey()); } xProperty = pPropertyManager->Next(); } //cache std::string strCacheKey = GetPropertyCacheKey(self); if (!pDriver->HMGET(strCacheKey, vKeyCacheList, vValueCacheList)) { return nullptr; } if (vKeyCacheList.size() == vValueCacheList.size()) { ConvertVectorToPropertyManager(vKeyCacheList, vValueCacheList, pPropertyManager); return pPropertyManager; } return nullptr; }
NF_SHARE_PTR<NFIProperty> NFCPropertyManager::AddProperty(const NFGUID& self, NF_SHARE_PTR<NFIProperty> pProperty) { const std::string& strProperty = pProperty->GetKey(); NF_SHARE_PTR<NFIProperty> pOldProperty = this->GetElement(strProperty); if (!pOldProperty.get()) { NF_SHARE_PTR<NFIProperty> pNewProperty(NF_NEW NFCProperty(self, strProperty, pProperty->GetType())); pNewProperty->SetPublic(pProperty->GetPublic()); pNewProperty->SetPrivate(pProperty->GetPrivate()); pNewProperty->SetSave(pProperty->GetSave()); pNewProperty->SetCache(pProperty->GetCache()); pNewProperty->SetRelationValue(pProperty->GetRelationValue()); this->AddElement(strProperty, pNewProperty); } return pOldProperty; }
bool NFCCommonRedisModule::ConvertPropertyManagerToVector(NF_SHARE_PTR<NFIPropertyManager> pPropertyManager, std::vector<std::string>& vKeyList, std::vector<std::string>& vValueList) { for (NF_SHARE_PTR<NFIProperty> pProperty = pPropertyManager->First(); pProperty != NULL; pProperty = pPropertyManager->Next()) { const int nType = pProperty->GetType(); if (!pProperty->GetCache() && !pProperty->GetSave()) { continue; } const std::string& strPropertyName = pProperty->GetKey(); const std::string& strPropertyValue = pProperty->ToString(); vKeyList.push_back(strPropertyName); vValueList.push_back(strPropertyValue); } return true; }
bool NFCElementModule::CheckRef() { NF_SHARE_PTR<NFIClass> pLogicClass = m_pClassModule->First(); while (pLogicClass) { NF_SHARE_PTR<NFIPropertyManager> pClassPropertyManager = pLogicClass->GetPropertyManager(); if (pClassPropertyManager) { NF_SHARE_PTR<NFIProperty> pProperty = pClassPropertyManager->First(); while (pProperty) { //if one property is ref,check every config if (pProperty->GetRef()) { NFList<std::string>& strIdList = pLogicClass->GetIdList(); std::string strId; for (bool bRet = strIdList.First(strId); bRet; bRet = strIdList.Next(strId)) { const std::string& strRefValue= this->GetPropertyString(strId, pProperty->GetKey()); if (!this->GetElement(strRefValue)) { std::string msg; msg.append("check ref failed id: ").append(strRefValue).append(" in ").append(pLogicClass->GetClassName()); NFASSERT(nRet, msg.c_str(), __FILE__, __FUNCTION__); exit(0); } } } pProperty = pClassPropertyManager->Next(); } } ////////////////////////////////////////////////////////////////////////// pLogicClass = m_pClassModule->Next(); } return false; }
bool NFCElementInfoModule::Load(rapidxml::xml_node<>* attrNode, NF_SHARE_PTR<NFILogicClass> pLogicClass) { //attrNode is the node of a object std::string strConfigID = attrNode->first_attribute("ID")->value(); if (strConfigID.empty()) { NFASSERT(0, strConfigID, __FILE__, __FUNCTION__); return false; } if (ExistElement(strConfigID)) { NFASSERT(0, strConfigID, __FILE__, __FUNCTION__); return false; } NF_SHARE_PTR<ElementConfigInfo> pElementInfo(NF_NEW ElementConfigInfo()); AddElement(strConfigID, pElementInfo); //can find all configid by class name pLogicClass->AddConfigName(strConfigID); //ElementConfigInfo* pElementInfo = CreateElement( strConfigID, pElementInfo ); NF_SHARE_PTR<NFIPropertyManager> pElementPropertyManager = pElementInfo->GetPropertyManager(); NF_SHARE_PTR<NFIRecordManager> pElementRecordManager = pElementInfo->GetRecordManager(); //1.add property //2.set the default value of them NF_SHARE_PTR<NFIPropertyManager> pClassPropertyManager = pLogicClass->GetPropertyManager(); NF_SHARE_PTR<NFIRecordManager> pClassRecordManager = pLogicClass->GetRecordManager(); if (pClassPropertyManager.get() && pClassRecordManager.get()) { NF_SHARE_PTR<NFIProperty> pProperty = pClassPropertyManager->First(); while (pProperty.get()) { pElementPropertyManager->AddProperty(NFGUID(), pProperty); pProperty = pClassPropertyManager->Next(); } NF_SHARE_PTR<NFIRecord> pRecord = pClassRecordManager->First(); while (pRecord.get()) { pElementRecordManager->AddRecord(NFGUID(), pRecord->GetName(), pRecord->GetInitData(), pRecord->GetKeyState(), pRecord->GetInitDesc(), pRecord->GetTag(), pRecord->GetRelatedRecord(), pRecord->GetRows(), pRecord->GetPublic(), pRecord->GetPrivate(), pRecord->GetSave(), pRecord->GetView(), pRecord->GetIndex()); pRecord = pClassRecordManager->Next(); } } //3.set the config value to them //const char* pstrConfigID = attrNode->first_attribute( "ID" ); for (rapidxml::xml_attribute<>* pAttribute = attrNode->first_attribute(); pAttribute; pAttribute = pAttribute->next_attribute()) { const char* pstrConfigName = pAttribute->name(); const char* pstrConfigValue = pAttribute->value(); //printf( "%s : %s\n", pstrConfigName, pstrConfigValue ); NF_SHARE_PTR<NFIProperty> temProperty = pElementPropertyManager->GetElement(pstrConfigName); if (!temProperty) { continue; } NFIDataList::TData var; TDATA_TYPE eType = temProperty->GetType(); switch (eType) { case TDATA_INT: { if (!LegalNumber(pstrConfigValue)) { NFASSERT(0, temProperty->GetKey(), __FILE__, __FUNCTION__); } var.SetInt(lexical_cast<NFINT64>(pstrConfigValue)); } break; case TDATA_FLOAT: { if (strlen(pstrConfigValue) <= 0) { NFASSERT(0, temProperty->GetKey(), __FILE__, __FUNCTION__); } var.SetFloat((double)atof(pstrConfigValue)); } break; case TDATA_STRING: var.SetString(pstrConfigValue); break; case TDATA_OBJECT: { if (strlen(pstrConfigValue) <= 0) { NFASSERT(0, temProperty->GetKey(), __FILE__, __FUNCTION__); } var.SetObject(NFGUID()); } break; default: NFASSERT(0, temProperty->GetKey(), __FILE__, __FUNCTION__); break; } pElementPropertyManager->SetProperty(pstrConfigName, var); } NFIDataList::TData xData; xData.SetString(pLogicClass->GetClassName()); pElementPropertyManager->SetProperty("ClassName", xData); return true; }
int NFCPropertyTrailModule::LogObjectData(const NFGUID& self) { NF_SHARE_PTR<NFIObject> xObject = m_pKernelModule->GetObject(self); if (nullptr == xObject) { return -1; } NF_SHARE_PTR<NFIPropertyManager> xPropertyManager = xObject->GetPropertyManager(); if (nullptr != xPropertyManager) { NF_SHARE_PTR<NFIProperty> xProperty = xPropertyManager->First(); while (nullptr != xProperty) { std::ostringstream stream; stream << " Start trail "; stream << xProperty->ToString(); m_pLogModule->LogProperty(NFILogModule::NF_LOG_LEVEL::NLL_INFO_NORMAL, self, xProperty->GetKey(), stream.str(), __FUNCTION__, __LINE__); xProperty = xPropertyManager->Next(); } } NF_SHARE_PTR<NFIRecordManager> xRecordManager = xObject->GetRecordManager(); if (nullptr != xRecordManager) { NF_SHARE_PTR<NFIRecord> xRecord = xRecordManager->First(); while (nullptr != xRecord) { for (int i = 0; i < xRecord->GetRows(); ++i) { NFCDataList xDataList; bool bRet = xRecord->QueryRow(i, xDataList); if (bRet) { std::ostringstream stream; stream << " Start trail Row[" << i << "]"; for (int j = 0; j < xDataList.GetCount(); ++j) { stream << " [" << j << "] " << xDataList.StringValEx(j); } m_pLogModule->LogRecord(NFILogModule::NF_LOG_LEVEL::NLL_INFO_NORMAL, self, xRecord->GetName(), stream.str(), __FUNCTION__, __LINE__); } } xRecord = xRecordManager->Next(); } } return 0; }
bool NFCCreateRoleModule::ConvertPropertyManagerToPB(const NF_SHARE_PTR<NFIPropertyManager>& pProps, NFMsg::ObjectPropertyList * pPropertyData) { if (pProps) { NF_SHARE_PTR<NFIProperty> xPropert = pProps->First(); while (xPropert) { if (xPropert->GetCache() || xPropert->GetSave()) { switch (xPropert->GetType()) { case NFDATA_TYPE::TDATA_INT: { NFMsg::PropertyInt* pData = pPropertyData->add_property_int_list(); pData->set_property_name(xPropert->GetKey()); pData->set_data(xPropert->GetInt()); } break; case NFDATA_TYPE::TDATA_FLOAT: { NFMsg::PropertyFloat* pData = pPropertyData->add_property_float_list(); pData->set_property_name(xPropert->GetKey()); pData->set_data(xPropert->GetFloat()); } break; case NFDATA_TYPE::TDATA_OBJECT: { NFMsg::PropertyObject* pData = pPropertyData->add_property_object_list(); pData->set_property_name(xPropert->GetKey()); *(pData->mutable_data()) = NFINetModule::NFToPB(xPropert->GetObject()); } break; case NFDATA_TYPE::TDATA_STRING: { NFMsg::PropertyString* pData = pPropertyData->add_property_string_list(); pData->set_property_name(xPropert->GetKey()); pData->set_data(xPropert->GetString()); std::cout << xPropert->GetKey() << " " << xPropert->GetString() << std::endl; } break; case NFDATA_TYPE::TDATA_VECTOR2: { NFMsg::PropertyVector2* pData = pPropertyData->add_property_vector2_list(); pData->set_property_name(xPropert->GetKey()); *(pData->mutable_data()) = NFINetModule::NFToPB(xPropert->GetVector2()); } break; case NFDATA_TYPE::TDATA_VECTOR3: { NFMsg::PropertyVector3* pData = pPropertyData->add_property_vector3_list(); pData->set_property_name(xPropert->GetKey()); *(pData->mutable_data()) = NFINetModule::NFToPB(xPropert->GetVector3()); } break; default: break; } } xPropert = pProps->Next(); } } return false; }