コード例 #1
0
//-----------------------------------------------------------------------------
bool psNPCLoader::SaveToFile(int id, csString &filename)
{
    filename.Insert(0,"/this/");

    psCharacterLoader loader;
    npc = loader.LoadCharacterData(id,false);

    if(!npc)
    {
        CPrintf(CON_ERROR, "Error: Couldn't load NPC with id: %i\n",id);
        return false;
    }

    //*npc = *character;  // removed



    npcID = id;
    area  = npc->GetCharName();

    csRef<iDocumentSystem> xml;
    xml.AttachNew(new csTinyDocumentSystem);
    csRef<iDocument> doc = xml->CreateDocument();
    csRef<iDocumentNode> root = doc->CreateRoot();
    npcRoot = root->CreateNodeBefore(CS_NODE_ELEMENT);
    npcRoot->SetValue("npc");


    WriteBasicInfo();
    WriteDescription();
    WriteLocation();
    WriteStats();
    WriteMoney();
    WriteEquipment();
    WriteFactions();
    WriteSkills();
    WriteMerchantInfo();
    WriteTrainerInfo();
    WriteKnowledgeAreas();
    WriteSpecificKnowledge();

    csRef<iVFS> vfs =  csQueryRegistry<iVFS> (psserver->GetObjectReg());

    if(!vfs)
        return false;

    csString error = doc->Write(vfs, filename);
    if(!error.IsEmpty())
    {
        CPrintf(CON_ERROR, "Error writing to file %s: %s\n",filename.GetData(), error.GetData());
        return false;
    }

    return true;
}
コード例 #2
0
bool psNPCLoader::SaveDialogsToFile(csString &area, csString &filename, int questid, bool quest)
{
    filename.Insert(0,"/this/");

    csRef<iDocumentSystem> xml;
    xml.AttachNew(new csTinyDocumentSystem);
    csRef<iDocument> doc = xml->CreateDocument();
    csRef<iDocumentNode> root = doc->CreateRoot();

    if(quest)
    {
        this->area.Clear();

        csRef<iDocumentNode> questNode = root->CreateNodeBefore(CS_NODE_ELEMENT);
        questNode->SetValue("quest");

        Result questInfo(db->Select("SELECT name, task, player_lockout_time, quest_lockout_time FROM quests WHERE id = '%i'", questid));
        questNode->SetAttribute("name", questInfo[0][0]);
        questNode->SetAttribute("task", questInfo[0][1]);
        questNode->SetAttributeAsInt("player_lockout_time", questInfo[0].GetInt(2));
        questNode->SetAttributeAsInt("quest_lockout_time", questInfo[0].GetInt(3));

        npcRoot = questNode->CreateNodeBefore(CS_NODE_ELEMENT);
        npcRoot->SetValue("npcdialogs");
        if(!WriteSpecificKnowledge(questid))
        {
            CPrintf(CON_ERROR,"Error writing specific knowledge.\n");
            return false;
        }

        Result questSteps(db->Select("SELECT id, name, task, minor_step_number, player_lockout_time, quest_lockout_time FROM quests WHERE master_quest_id = '%i' ORDER BY minor_step_number", questid));
        for(unsigned int i = 0; i<questSteps.Count(); i++)
        {
            csRef<iDocumentNode> questStepNode = questNode->CreateNodeBefore(CS_NODE_ELEMENT);
            questStepNode->SetValue("queststep");
            questStepNode->SetAttribute("name", questInfo[i][1]);
            questStepNode->SetAttribute("task", questInfo[i][2]);
            if(questSteps[i].GetInt(3))
                questStepNode->SetAttributeAsInt("minor_step_number", questSteps[i].GetInt(3));
            if(questSteps[i].GetInt(4))
                questStepNode->SetAttributeAsInt("player_lockout_time", questInfo[i].GetInt(4));
            if(questSteps[i].GetInt(5))
                questStepNode->SetAttributeAsInt("quest_lockout_time", questInfo[i].GetInt(5));

            npcRoot = questStepNode->CreateNodeBefore(CS_NODE_ELEMENT);
            npcRoot->SetValue("npcdialogs");
            if(!WriteSpecificKnowledge(questSteps[i].GetInt(0)))
            {
                CPrintf(CON_ERROR,"Error writing specific knowledge.\n");
                return false;
            }
        }
    }
    else            // This is when exporting areas or queststeps
    {
        npcRoot = root->CreateNodeBefore(CS_NODE_ELEMENT);
        npcRoot->SetValue("npcdialogs");

        csString temp;
        if(questid == -1)
        {
            npcRoot->SetAttribute("area", area);
            this->area = area;
        }
        else
            this->area.Clear();

        if(!WriteSpecificKnowledge(questid))
        {
            CPrintf(CON_ERROR,"Error writing specific knowledge.\n");
            return false;
        }
    }

    csRef<iVFS> vfs =  csQueryRegistry<iVFS> (psserver->GetObjectReg());

    if(!vfs)
        return false;

    csString error = doc->Write(vfs, filename);
    if(!error.IsEmpty())
    {
        CPrintf(CON_ERROR, "Error writing to file %s: %s\n",filename.GetData(), error.GetData());
        return false;
    }

    return true;
}