Example #1
0
void DFSpells::SaveSchool(std::ofstream &fout, School *school)
{
	char buffer[256];
	std::vector <std::string> lines;

	fout << "\n\n#---------------------------------------------\n";

	sprintf(buffer, "S:%s,%s,%s,%s,%s,%s,%s,%s", school->name.c_str(),school->deity.c_str(),school->skill.c_str(),school->resistSkill.c_str(),
			school->r.c_str(),school->g.c_str(),school->b.c_str(),school->symbol.c_str());
	fout << buffer;

	SplitLine( school->deityDescription, lines);
	for ( unsigned int i = 0; i < lines.size(); i++ )
		fout << "\nG:" << lines[i];

	// donations
	for ( unsigned int i = 0; i < school->lowDonation.size(); i++ )
		fout << "\nL:" << school->lowDonation[i];
	for ( unsigned int i = 0; i < school->neutralDonation.size(); i++ )
		fout << "\nN:" << school->neutralDonation[i];
	for ( unsigned int i = 0; i < school->highDonation.size(); i++ )
		fout << "\nH:" << school->highDonation[i];

	fout << "\n#---------------------------------------------\n\n";

	std::vector<Spell*>::iterator itr;
	for ( itr = school->spells.begin(); itr != school->spells.end(); itr++ )
	{
		SaveSpell(fout, *itr);
	}
}
Example #2
0
void SpellManager::HandleAssembler(MsgEntry* me, Client* client)
{
    psGlyphAssembleMessage mesg;
    mesg.FromClient(me);

    csArray<psItemStats*> assembler;
    for(size_t i = 0; i < GLYPH_ASSEMBLER_SLOTS; i++)
    {
        if(mesg.glyphs[i] != 0)
        {
            psItemStats* stats = cacheManager->GetBasicItemStatsByID(mesg.glyphs[i]);
            if(stats)
                assembler.Push(stats);
        }
    }

    if(assembler.GetSize() == 0)
    {
        psserver->SendSystemError(client->GetClientNum(), "There are no glyphs in the research slots.");
        return;
    }

    if(!client->GetCharacterData()->Inventory().HasPurifiedGlyphs(assembler))
    {
        Error2("Client %i tried to research spell with glyphs he actually doesn't have", client->GetClientNum());
        SendGlyphs(NULL,client);
        return;
    }

    // Is the Glyph Sequence a Valid one?
    psSpell* spell = FindSpell(client, assembler);

    csString description("Your research didn't result in a valid spell.");
    if(spell)
    {
        // Is this spell already in our spellbook?
        psSpell* knownSpell = client->GetCharacterData()->GetSpellByName(spell->GetName());
        if(knownSpell)
        {
            if(mesg.info)
            {
                psGlyphAssembleMessage newmsginfo(client->GetClientNum(), knownSpell->GetName(), knownSpell->GetImage(), knownSpell->GetDescription());
                newmsginfo.SendMessage();
            }
            else
            {
                psserver->SendSystemInfo(client->GetClientNum(), "You know this spell already.");
            }
            return;
        }
        description = "A spell materializes for a second, but you then lose focus. Try again or increase your magic knowledge.";
    }
    if(mesg.info)
        return;

    csString name(" ");
    csString image(" ");

    const bool success = spell && psserver->GetRandom() * 100.0 < spell->ChanceOfResearchSuccess(client->GetCharacterData());
    ProgressionScript* outcome = psserver->GetProgressionManager()->FindScript(success ? "ResearchSpellSuccess" : "ResearchSpellFailure");
    if(outcome)
    {
        MathEnvironment env;
        env.Define("Actor", client->GetActor());
        outcome->Run(&env);
    }

    if(success)
    {
        description = spell->GetDescription();
        name = spell->GetName();
        image = spell->GetImage();
        SaveSpell(client, name);
    }

    // Clear the description, if this is not valid glyph sequence for our player:
    psGlyphAssembleMessage newmsg(client->GetClientNum(), name, image, description);
    newmsg.SendMessage();
}