NFGUID NFCHeroModule::AddHero(const NFGUID& self, const std::string& strID) { NF_SHARE_PTR<NFIRecord> pHeroRecord = m_pKernelModule->FindRecord(self, NFrame::Player::PlayerHero::ThisName()); if (nullptr == pHeroRecord) { return NFGUID(); } int nRow = pHeroRecord->FindString(NFrame::Player::PlayerHero::ConfigID, strID); if (nRow >= 0) { return NFGUID(); } NF_SHARE_PTR<NFDataList> xRowData = pHeroRecord->GetInitData(); NFGUID xHeroID = m_pKernelModule->CreateGUID(); xRowData->SetObject(NFrame::Player::PlayerHero::GUID, xHeroID); xRowData->SetString(NFrame::Player::PlayerHero::ConfigID, strID); xRowData->SetInt(NFrame::Player::PlayerHero::Activated, 0); if (pHeroRecord->AddRow(-1, *xRowData) < 0) { return NFGUID(); } AddToFightList(self, xHeroID); return xHeroID; }
bool NFCPackModule::CreateItemInTempBag(const NFGUID & self, const std::string & strConfigName, const int nCount) { NF_SHARE_PTR<NFIRecord> pRecord = m_pKernelModule->FindRecord(self, NFrame::Player::TempItemList::ThisName()); if (nullptr == pRecord) { return false; } NFDataList varFindResult; int nFindRowCount = pRecord->FindString(NFrame::Player::TempItemList::ConfigID, strConfigName, varFindResult); if (nFindRowCount <= 0) { NF_SHARE_PTR<NFDataList> xRowData = pRecord->GetInitData(); xRowData->SetString(NFrame::Player::TempItemList::ConfigID, strConfigName); xRowData->SetInt(NFrame::Player::TempItemList::ItemCount, nCount); pRecord->AddRow(-1, *xRowData); } else { int nFindRow = varFindResult.Int32(0); int nOldCount = pRecord->GetInt32(nFindRow, NFrame::Player::TempItemList::ItemCount); int nNewCount = nOldCount + nCount; pRecord->SetInt(nFindRow, NFrame::Player::TempItemList::ItemCount, nNewCount); } return true; }
NF_SHARE_PTR<NFIRecordManager> NFCCommonRedisModule::NewRecordManager(const std::string& strClassName) { NF_SHARE_PTR<NFIRecordManager> pStaticClassRecordManager = m_pLogicClassModule->GetClassRecordManager(strClassName); if (pStaticClassRecordManager) { NFGUID ident; NF_SHARE_PTR<NFIRecordManager> pRecordManager(NF_NEW NFCRecordManager(ident)); NF_SHARE_PTR<NFIRecord> pConfigRecordInfo = pStaticClassRecordManager->First(); while (pConfigRecordInfo) { if (pConfigRecordInfo->GetSave() || pConfigRecordInfo->GetCache()) { NF_SHARE_PTR<NFIRecord> xRecord = pRecordManager->AddRecord(ident, pConfigRecordInfo->GetName(), pConfigRecordInfo->GetInitData(), pConfigRecordInfo->GetTag(), pConfigRecordInfo->GetRows()); xRecord->SetPublic(pConfigRecordInfo->GetPublic()); xRecord->SetPrivate(pConfigRecordInfo->GetPrivate()); xRecord->SetSave(pConfigRecordInfo->GetSave()); xRecord->SetCache(pConfigRecordInfo->GetCache()); } pConfigRecordInfo = pStaticClassRecordManager->Next(); } return pRecordManager; } return NF_SHARE_PTR<NFIRecordManager>(NULL); }
bool NFCPackModule::CreateItem( const NFGUID& self, const std::string& strConfigName, const int nCount ) { if (nCount <= 0) { return 0; } NF_SHARE_PTR<NFIObject> pObject = m_pKernelModule->GetObject( self ); if ( NULL == pObject ) { return 0; } //还得确定有这个装备 bool bExist = m_pElementModule->ExistElement(NFrame::Item::ThisName(), strConfigName ); if ( !bExist ) { return 0; } NF_SHARE_PTR<NFIRecord> pRecord = pObject->GetRecordManager()->GetElement( NFrame::Player::R_BagItemList() ); if (!pRecord) { return 0; } NFCDataList varFindResult; int nFindRowCount = pRecord->FindString(NFrame::Player::BagItemList_ConfigID, strConfigName, varFindResult); if (nFindRowCount <= 0) { NF_SHARE_PTR<NFIDataList> xRowData = pRecord->GetInitData(); xRowData->SetString(NFrame::Player::BagItemList_ConfigID, strConfigName); xRowData->SetInt(NFrame::Player::BagItemList_ItemCount, nCount); xRowData->SetInt(NFrame::Player::BagItemList_Date, NFTime::GetNowTime()); } else { int nFindRow = varFindResult.Int(0); int nOldCount = pRecord->GetInt(nFindRow, NFrame::Player::BagItemList_ItemCount); int nNewCount = nOldCount + nCount; pRecord->SetInt(nFindRow, NFrame::Player::BagItemList_ItemCount, nNewCount); } return 0; }
const NFGUID& NFCPackModule::CreateEquip( const NFGUID& self, const std::string& strConfigName ) { NF_SHARE_PTR<NFIObject> pObject = m_pKernelModule->GetObject( self ); if ( NULL == pObject ) { return NULL_OBJECT; } //还得确定有这个装备 bool bExist = m_pElementModule->ExistElement( strConfigName ); if ( !bExist ) { return NULL_OBJECT; } int nItemType = m_pElementModule->GetPropertyInt(strConfigName, NFrame::Item::ItemType()); if ( NFMsg::EItemType::EIT_EQUIP != nItemType ) { return NULL_OBJECT; } NF_SHARE_PTR<NFIRecord> pRecord = pObject->GetRecordManager()->GetElement( NFrame::Player::R_BagEquipList() ); if (!pRecord) { return NULL_OBJECT; } NFGUID ident = m_pUUIDModule->CreateGUID(); NF_SHARE_PTR<NFIDataList> var = pRecord->GetInitData(); var->SetObject(NFrame::Player::BagEquipList_GUID, ident); var->SetString(NFrame::Player::BagEquipList_ConfigID, strConfigName.c_str()); var->SetInt(NFrame::Player::BagEquipList_Date, NFTime::GetNowTime()); int nAddRow = pRecord->AddRow(-1, *var); if (nAddRow > 0) { return pRecord->GetObject(nAddRow, NFrame::Player::BagEquipList_GUID); } return NULL_OBJECT; }
void NFGamePVPModule::RecordPVPData(const NFGUID & self, const int nStar, const int nGold, const int nDiamond) { //how to record this war for these two people NFGUID xWarID = m_pKernelModule->GetPropertyObject(self, NFrame::Player::WarID()); NF_SHARE_PTR<NFIRecord> xAttackWarRecord = m_pKernelModule->FindRecord(self, NFrame::Player::WarList::ThisName()); NF_SHARE_PTR<NFDataList> xDataList = xAttackWarRecord->GetInitData(); xDataList->SetObject(NFrame::Player::WarList::WarID, xWarID); //record the war information /* //the fields below need to be setted run-time static const std::string& BuildingCount() { static std::string x = "BuildingCOunt"; return x; };// int static const std::string& DestroiedBuilding() { static std::string x = "DestroiedBuilding"; return x; };// int static const std::string& DeadHero1() { static std::string x = "DeadHero1"; return x; };// int static const std::string& DeadHero2() { static std::string x = "DeadHero2"; return x; };// int static const std::string& DeadHero3() { static std::string x = "DeadHero3"; return x; };// int static const std::string& KilledHero1() { static std::string x = "KilledHero1"; return x; };// int static const std::string& KilledHero2() { static std::string x = "KilledHero2"; return x; };// int static const std::string& KilledHero3() { static std::string x = "KilledHero3"; return x; };// int static const std::string& KilledMasterCount() { static std::string x = "KilledMasterCount"; return x; };// int static const std::string& MasterCount() { static std::string x = "MasterCount"; return x; };// int */ xDataList->SetString(NFrame::Player::WarList::AttackerName, m_pKernelModule->GetPropertyString(self, NFrame::Player::Name())); xDataList->SetInt(NFrame::Player::WarList::AttackerCup, m_pKernelModule->GetPropertyInt(self, NFrame::Player::Cup())); //xDataList->SetString(NFrame::Player::WarList::AttackerHero1, m_pKernelModule->GetPropertyString(self, NFrame::Player::HeroPos1CnfID())); //xDataList->SetInt(NFrame::Player::WarList::AttackerHero1Star, m_pKernelModule->GetPropertyInt(self, NFrame::Player::HeroPos1Star())); //xDataList->SetString(NFrame::Player::WarList::AttackerHero2, m_pKernelModule->GetPropertyString(self, NFrame::Player::HeroPos2CnfID())); //xDataList->SetInt(NFrame::Player::WarList::AttackerHero2Star, m_pKernelModule->GetPropertyInt(self, NFrame::Player::HeroPos2Star())); //xDataList->SetString(NFrame::Player::WarList::AttackerHero3, m_pKernelModule->GetPropertyString(self, NFrame::Player::HeroPos3CnfID())); //xDataList->SetInt(NFrame::Player::WarList::AttackerHero3Star, m_pKernelModule->GetPropertyInt(self, NFrame::Player::HeroPos3Star())); xDataList->SetObject(NFrame::Player::WarList::AttackerID, self); xDataList->SetInt(NFrame::Player::WarList::AttackerLevel, m_pKernelModule->GetPropertyInt(self, NFrame::Player::Level())); xDataList->SetString(NFrame::Player::WarList::BeAttackerName, m_pKernelModule->GetPropertyString(self, NFrame::Player::OpponentName())); xDataList->SetInt(NFrame::Player::WarList::BeAttackerCup, m_pKernelModule->GetPropertyInt(self, NFrame::Player::OpponentCup())); //xDataList->SetString(NFrame::Player::WarList::BeAttackerHero1, m_pKernelModule->GetPropertyString(self, NFrame::Player::OpponentHero1())); //xDataList->SetInt(NFrame::Player::WarList::BeAttackerHero1Star, m_pKernelModule->GetPropertyInt(self, NFrame::Player::OpponentHero1Star())); //xDataList->SetString(NFrame::Player::WarList::BeAttackerHero2, m_pKernelModule->GetPropertyString(self, NFrame::Player::OpponentHero2())); //xDataList->SetInt(NFrame::Player::WarList::BeAttackerHero2Star, m_pKernelModule->GetPropertyInt(self, NFrame::Player::OpponentHero2Star())); //xDataList->SetString(NFrame::Player::WarList::BeAttackerHero3, m_pKernelModule->GetPropertyString(self, NFrame::Player::OpponentHero3())); //xDataList->SetInt(NFrame::Player::WarList::BeAttackerHero3Star, m_pKernelModule->GetPropertyInt(self, NFrame::Player::OpponentHero3Star())); xDataList->SetObject(NFrame::Player::WarList::BeAttackerID, m_pKernelModule->GetPropertyObject(self, NFrame::Player::OpponentFighting())); xDataList->SetInt(NFrame::Player::WarList::BeAttackerLevel, m_pKernelModule->GetPropertyInt(self, NFrame::Player::Level())); //xDataList->SetString(NFrame::Player::WarList::Item1, m_pKernelModule->GetPropertyString(self, NFrame::Player::Item1())); //xDataList->SetInt(NFrame::Player::WarList::Item1Count, m_pKernelModule->GetPropertyInt(self, NFrame::Player::Item1UsedCount())); //xDataList->SetString(NFrame::Player::WarList::Item2, m_pKernelModule->GetPropertyString(self, NFrame::Player::Item2())); //xDataList->SetInt(NFrame::Player::WarList::Item2Count, m_pKernelModule->GetPropertyInt(self, NFrame::Player::Item2UsedCount())); //xDataList->SetString(NFrame::Player::WarList::Item3, m_pKernelModule->GetPropertyString(self, NFrame::Player::Item3())); //xDataList->SetInt(NFrame::Player::WarList::Item3Count, m_pKernelModule->GetPropertyInt(self, NFrame::Player::Item3UsedCount())); int64_t nEventTime = m_pKernelModule->GetPropertyInt(self, NFrame::Player::WarEventTime()); int64_t nCostTime = NFGetTimeMS() - nEventTime; xDataList->SetInt(NFrame::Player::WarList::EventTime, nEventTime); xDataList->SetInt(NFrame::Player::WarList::WarStar, nStar); xDataList->SetInt(NFrame::Player::WarList::CostTime, nCostTime); xDataList->SetInt(NFrame::Player::WarList::Gold, nGold); xDataList->SetInt(NFrame::Player::WarList::Diamond, nDiamond); if (nStar >= 2) { xDataList->SetObject(NFrame::Player::WarList::Winner, self); } else { xDataList->SetObject(NFrame::Player::WarList::Winner, m_pKernelModule->GetPropertyObject(self, NFrame::Player::OpponentFighting())); } xAttackWarRecord->AddRow(-1, *xDataList); ////////for beattacker//////////////////////////////////// }
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; }