Example #1
0
File: magic.cpp Project: 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 */
}
Example #2
0
int skill_pool_deactivate(dumb_ptr<map_session_data> sd, SkillID skill_id)
{
    if (bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED))
    {
        sd->status.skill[skill_id].flags &= ~SkillFlags::POOL_ACTIVATED;
        MAP_LOG_PC(sd, "SKILL-DEACTIVATE %d"_fmt, skill_id);
        pc_calcstatus(sd, 0);
        return 0;
    }

    return 1;
}
Example #3
0
int skill_pool_deactivate (struct map_session_data *sd, int skill_id)
{
    if (sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED)
    {
        sd->status.skill[skill_id].flags &= ~SKILL_POOL_ACTIVATED;
        MAP_LOG_PC (sd, "SKILL-DEACTIVATE %d", skill_id);
        pc_calcstatus (sd, 0);
        return 0;
    }

    return 1;
}
Example #4
0
int skill_pool_activate(dumb_ptr<map_session_data> sd, SkillID skill_id)
{
    if (bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED))
        return 0;               // Already there
    else if (sd->status.skill[skill_id].lv
             && (skill_pool_size(sd) < skill_pool_max(sd)))
    {
        sd->status.skill[skill_id].flags |= SkillFlags::POOL_ACTIVATED;
        pc_calcstatus(sd, 0);
        MAP_LOG_PC(sd, "SKILL-ACTIVATE %d %d %d"_fmt,
                skill_id, sd->status.skill[skill_id].lv,
                skill_power(sd, skill_id));
        return 0;
    }

    return 1;                   // failed
}
Example #5
0
int skill_pool_activate (struct map_session_data *sd, int skill_id)
{
    if (sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED)
        return 0;               // Already there
    else if (sd->status.skill[skill_id].id == skill_id  // knows the skill
             && (skill_pool_size (sd) < skill_pool_max (sd)))
    {
        sd->status.skill[skill_id].flags |= SKILL_POOL_ACTIVATED;
        pc_calcstatus (sd, 0);
        MAP_LOG_PC (sd, "SKILL-ACTIVATE %d %d %d", skill_id,
                    sd->status.skill[skill_id].lv, skill_power (sd,
                                                                skill_id));
        return 0;
    }

    return 1;                   // failed
}
Example #6
0
File: trade.cpp Project: mrktj/tmwa
/*==========================================
 * 取引許諾(trade押し)
 *------------------------------------------
 */
void trade_tradecommit(dumb_ptr<map_session_data> sd)
{
    dumb_ptr<map_session_data> target_sd;
    int trade_i;

    nullpo_retv(sd);

    if ((target_sd = map_id2sd(account_to_block(sd->trade_partner))) != nullptr)
    {
        MAP_LOG_PC(sd, " TRADECOMMIT WITH %d GIVE %d GET %d"_fmt,
                target_sd->status_key.char_id, sd->deal_zeny,
                target_sd->deal_zeny);
        if ((sd->deal_locked >= 1) && (target_sd->deal_locked >= 1))
        {                       // both have pressed 'ok'
            if (sd->deal_locked < 2)
            {
                sd->deal_locked = 2;
            }                   // set locked to 2
            if (target_sd->deal_locked == 2)
            {                   // the other one pressed 'trade' too
                if (sd->deal_zeny > sd->status.zeny)
                {
                    sd->deal_zeny = 0;
                    trade_tradecancel(sd);
                    MAP_LOG_PC(sd, " TRADECANCEL"_fmt);
                    return;
                }
                if (target_sd->deal_zeny > target_sd->status.zeny)
                {
                    target_sd->deal_zeny = 0;
                    trade_tradecancel(sd);
                    MAP_LOG_PC(sd, " TRADECANCEL"_fmt);
                    return;
                }
                sd->trade_partner = AccountId();
                target_sd->trade_partner = AccountId();
                for (trade_i = 0; trade_i < TRADE_MAX; trade_i++)
                {
                    if (sd->deal_item_amount[trade_i] != 0)
                    {
                        assert (sd->deal_item_index[trade_i].ok());
                        IOff0 n = sd->deal_item_index[trade_i].unshift();
                        PickupFail flag = pc_additem(target_sd,
                                &sd->status.inventory[n],
                                sd->deal_item_amount[trade_i]);
                        if (flag == PickupFail::OKAY)
                            pc_delitem(sd, n, sd->deal_item_amount[trade_i],
                                        1);
                        else
                            clif_additem(sd, n,
                                    sd->deal_item_amount[trade_i],
                                    PickupFail::OKAY);
                        sd->deal_item_index[trade_i] = IOff2::from(0);
                        sd->deal_item_amount[trade_i] = 0;
                    }
                    if (target_sd->deal_item_amount[trade_i] != 0)
                    {
                        assert (target_sd->deal_item_index[trade_i].ok());
                        IOff0 n = target_sd->deal_item_index[trade_i].unshift();
                        PickupFail flag = pc_additem(sd,
                                &target_sd->status.inventory[n],
                                target_sd->deal_item_amount[trade_i]);
                        if (flag == PickupFail::OKAY)
                            pc_delitem(target_sd, n,
                                        target_sd->deal_item_amount[trade_i],
                                        1);
                        else
                            clif_additem(target_sd, n,
                                    target_sd->deal_item_amount[trade_i],
                                    PickupFail::OKAY);
                        target_sd->deal_item_index[trade_i] = IOff2::from(0);
                        target_sd->deal_item_amount[trade_i] = 0;
                    }
                }
                if (sd->deal_zeny)
                {
                    int deal = sd->deal_zeny;
                    sd->deal_zeny = 0;
                    sd->status.zeny -= deal;
                    clif_updatestatus(sd, SP::ZENY);
                    target_sd->status.zeny += deal;
                    clif_updatestatus(target_sd, SP::ZENY);
                }
                if (target_sd->deal_zeny)
                {
                    int deal = target_sd->deal_zeny;
                    target_sd->deal_zeny = 0;
                    target_sd->status.zeny -= deal;
                    clif_updatestatus(target_sd, SP::ZENY);
                    sd->status.zeny += deal;
                    clif_updatestatus(sd, SP::ZENY);
                }
                sd->deal_locked = 0;
                target_sd->deal_locked = 0;
                clif_tradecompleted(sd, 0);
                clif_tradecompleted(target_sd, 0);
                MAP_LOG_PC(sd, " TRADEOK"_fmt);
            }
        }
    }
}
Example #7
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 */
}