Exemplo n.º 1
0
/*==========================================
 * NPC Spell
 *------------------------------------------
 */
int magic_message(dumb_ptr<map_session_data> caster, XString source_invocation)
{
    auto pair = magic_tokenise(source_invocation);
    // Spell Cast
    NpcEvent spell_event = spell_event2id(pair.first);

    RString spell_params = pair.second;

    if (spell_event.npc)
    {
        dumb_ptr<npc_data> nd = npc_name2id(spell_event.npc);

        if (nd)
        {
            argrec_t arg[1] =
            {
                {"@args$"_s, spell_params},
            };

            npc_event(caster, spell_event, 0, arg);
            return 1;
        }
    }
    return 0;
}
Exemplo n.º 2
0
Arquivo: magic.cpp Projeto: qiuhw/tmwa
int magic_message(dumb_ptr<map_session_data> caster, XString source_invocation)
{
    if (pc_isdead(caster))
        return 0;

    int power = caster->matk1;

    // This was the only thing worth saving from magic_preprocess_message.
    // May it rest only, and never rise again.
    // For more information on how this code worked, travel through time
    // and watch all the comments I wrote for myself while trying to figure
    // out if it was safe to delete.
    if (caster->state.shroud_active && caster->state.shroud_disappears_on_talk)
        magic_unshroud(caster);

    auto pair = magic_tokenise(source_invocation);
    XString spell_invocation = pair.first;
    XString parameter = pair.second;

    dumb_ptr<spell_t> spell = magic_find_spell(spell_invocation);

    if (spell)
    {
        int near_miss;
        dumb_ptr<env_t> env =
            spell_create_env(&magic_conf, spell, caster, power, parameter);
        effect_set_t *effects;

        if (bool(spell->flags & SPELL_FLAG::NONMAGIC) || (power >= 1))
            effects = spell_trigger(spell, caster, env, &near_miss);
        else
            effects = NULL;

#ifdef DEBUG
        FPRINTF(stderr, "Found spell `%s', triggered = %d\n", spell_,
                 effects != NULL);
#endif
        if (bool(caster->status.option & Option::HIDE))
            return 0;           // No spellcasting while hidden

        MAP_LOG_PC(caster, "CAST %s %s",
                    spell->name, effects ? "SUCCESS" : "FAILURE");

        if (effects)
        {
            dumb_ptr<invocation> invocation = spell_instantiate(effects, env);

            spell_bind(caster, invocation);
            spell_execute(invocation);

            return bool(spell->flags & SPELL_FLAG::SILENT) ? -1 : 1;
        }
        else
            magic_free_env(env);

        return 1;
    }

    return 0;                   /* Not a spell */
}
Exemplo n.º 3
0
int magic_message (character_t * caster, char *spell_, size_t spell_len)
{
    if (pc_isdead (caster))
        return 0;

    int  power = caster->matk1;
    char *invocation_base = spell_ + 8;
    char *source_invocation =
        1 + invocation_base + strlen (caster->status.name);
    spell_t *spell;
    char *parameter;
    char *spell_invocation;

    if (!source_invocation)
        return 0;

    /* Pre-message filter in case some spell alters output */
    source_invocation =
        magic_preprocess_message (caster, invocation_base, source_invocation);

    spell_invocation = magic_tokenise (source_invocation, &parameter);
    parameter = parameter ? strdup (parameter) : strdup ("");

    spell = magic_find_spell (spell_invocation);
    free (spell_invocation);

    if (spell)
    {
        int  near_miss;
        env_t *env =
            spell_create_env (&magic_conf, spell, caster, power, parameter);
        effect_set_t *effects;

        if ((spell->flags & SPELL_FLAG_NONMAGIC) || (power >= 1))
            effects = spell_trigger (spell, caster, env, &near_miss);
        else
            effects = NULL;

#ifdef DEBUG
        fprintf (stderr, "Found spell `%s', triggered = %d\n", spell_,
                 effects != NULL);
#endif
        if (caster->status.option & OPTION_HIDE)
            return 0;           // No spellcasting while hidden

        MAP_LOG_PC (caster, "CAST %s %s",
                    spell->name, effects ? "SUCCESS" : "FAILURE");

        if (effects)
        {
            invocation_t *invocation = spell_instantiate (effects, env);

            spell_bind (caster, invocation);
            spell_execute (invocation);

            return (spell->flags & SPELL_FLAG_SILENT) ? -1 : 1;
        }
        else
            magic_free_env (env);

        return 1;
    }
    else
        free (parameter);

    return 0;                   /* Not a spell */
}