Void GameplayManager::_LoadGameDatabase( const GChar * strPath )
{
    // List everything in current path
    Bool bIsDirectory = false;
    GChar strFileName[FILENAME_LENGTH + 1];

    Bool bContinue = SystemFn->ListDirectoryFirst( strPath, &bIsDirectory, strFileName, FILENAME_LENGTH );

    while( bContinue ) {
        // Build sub path
        GChar strSubPath[PATHNAME_LENGTH + 1];
        StringFn->Format( strSubPath, TEXT("%s/%s"), strPath, strFileName );

        // Sub-directory case
        if ( bIsDirectory ) {
            // Recurse
            _LoadGameDatabase( strSubPath );

            // Next file
            bContinue = SystemFn->ListDirectoryNext( &bIsDirectory, strFileName, FILENAME_LENGTH );
            continue;
        }

        // File case, load XML
        XMLDocument * pMonsterFile = XMLDocument::CreateDocument( strSubPath );

        Assert( pMonsterFile != NULL );
        Assert( StringFn->Cmp(pMonsterFile->GetTagName(), TEXT("MonsterFile")) == 0 );

            // Load skills
        const XMLNode * pSkillListNode = pMonsterFile->GetChildByTag( TEXT("SkillList"), 0 );
        Assert( pSkillListNode != NULL );

        UInt iCount = pSkillListNode->GetChildCount();
        for ( UInt i = 0; i < iCount; ++i ) {
            const XMLNode * pSkillNode = pSkillListNode->GetChildByTag( TEXT("Skill"), i );
            Assert( pSkillNode != NULL );

            Skill * pSkill = Skill::StaticLoad( pSkillNode );

            Bool bInserted = m_mapSkills.Insert( pSkill->GetID(), pSkill );
            Assert( bInserted );
        }

            // Load monsters
        const XMLNode * pMonsterListNode = pMonsterFile->GetChildByTag( TEXT("MonsterList"), 0 );
        Assert( pMonsterListNode != NULL );

        iCount = pMonsterListNode->GetChildCount();
        for( UInt i = 0; i < iCount;  ++i ) {
            XMLNode * pMonsterNode = pMonsterListNode->GetChildByTag( TEXT("Monster"), i );
            Assert( pMonsterNode != NULL );

            Monster hMonster;
            hMonster.Load( pMonsterNode );

            Bool bInserted = m_mapMonsters.Insert( hMonster.GetID(), hMonster );
            Assert( bInserted );
        }

        // Done with this one
        XMLDocument::DestroyDocument( pMonsterFile );
        pMonsterFile = NULL;

        // Next file
        bContinue = SystemFn->ListDirectoryNext( &bIsDirectory, strFileName, FILENAME_LENGTH );
    }
}
示例#2
0
bool MonsterManager::LoadMonster(UINT mapId)
{
	char xmlfile[260] = {0};
	sprintf(xmlfile, "moninfo%u.xml", mapId);


	m_mapId = mapId;

	m_pListCtrl->DeleteAllItems();
	Release();

	char szFile[260] = {0};
	sprintf(szFile, "%s/%s", EditorConfig::Instance()->makeServerResPath(MONINFO_PATH), xmlfile);

	xml_document doc;  
	File file;
	if (!file.open(szFile))
		return false;

	doc.load_buffer(file.getBufferPtr(), file.getLength());

	ushort count = 0;
	ushort index = 0;
	for (pugi::xml_node node1=doc.child("moninfo").child("mon"); node1; node1=node1.next_sibling()) {
		MONINFO info;
		info.mapId = mapId;
		int baseId = node1.attribute("BaseId").as_int();
		int num = node1.attribute("Num").as_int();
		index++;

		info.race = baseId;
		info.num = num;

		info.ai = node1.attribute("AI").as_int();
		info.speed = node1.attribute("Speed").as_int();
		info.view = node1.attribute("View").as_int();

		info.dropInfo[0].dropId = node1.attribute("DropId").as_int();
		info.dropInfo[0].dropProb = node1.attribute("DropProb").as_int();
		info.dropInfo[0].dropType = node1.attribute("DropType").as_int();

		info.dropInfo[1].dropId = node1.attribute("DropId2").as_int();
		info.dropInfo[1].dropProb = node1.attribute("DropProb2").as_int();
		info.dropInfo[1].dropType = node1.attribute("DropType2").as_int();

		info.dropInfo[2].dropId = node1.attribute("DropId3").as_int();
		info.dropInfo[2].dropProb = node1.attribute("DropProb3").as_int();
		info.dropInfo[2].dropType = node1.attribute("DropType3").as_int();

		info.reviveTime = node1.attribute("ReviveTime").as_int();
		info.isSiegeWar = node1.attribute("SiegeWar").as_int();
		info.isEventMon = node1.attribute("EventMon").as_int();
		info.birthRect.x = node1.attribute("BirthX").as_int();
		info.birthRect.y = node1.attribute("BirthY").as_int();
		info.birthRect.cx = node1.attribute("BirthWidth").as_int();
		info.birthRect.cy = node1.attribute("BirthHeight").as_int();

		const stMonBase* base = GameTable::getMonBase(baseId);
		if (!base) {
			LOGE("¶ÁÈ¡¹ÖÎï·Ö²¼³ö´í£¬²»´æÔڵĹÖÎïÀàÐÍ, file=%s, race=%u", szFile, baseId);
			continue;
		}

		Monster* pMon = new Monster;
		pMon->SetName(base->name);
		pMon->SetNum(num);
		pMon->FillInfo(info);
		pMon->Load(base->id);
		pMon->SetGridPos(info.birthRect.x, info.birthRect.y);

		if (!this->AddMonster(pMon)) {
			SAFE_DELETE(pMon);
			TRACE("²åÈë¹ÖÎïʧ°Ü, file=%s, race=%u", szFile, info.race);
			continue;
		}
	}


	return true;
}