背景:
阅读文章

combatd中skill_power的溢出及解决办法

[日期:2010-05-01] 来源:  作者:52mudWIZ [字体: ]

to happypig
your email address不能接受email from sina, below are the error message:
The following message to <jfli@hitic.ia.ac.cn> was undeliverable.


The reason for the problem:
5.4.7 - Delivery expired (message too old) '[Errno 61] Connection refused'

1. 将一下代码替换combatd.c里的varargs int skill_power(object ob, string skill, int usage)方法:
        varargs int skill_level(object ob, string skill, int usage)
        {
                int level, tmp;

                if( !living(ob) )
                        return 0;

                // if enable parry as weapon but no weapon  then set no_parry skill
                if( skill == "no_parry")
                        level = ob->query_skill("parry",1)/2;
                else
                        level = ob->query_skill(skill);

                switch(usage) {
                                case SKILL_USAGE_ATTACK:
                                        tmp=ob->query_temp("apply/attack");
                                        if(tmp>APPLY_ATTACK_LIMIT) tmp=APPLY_ATTACK_LIMIT;
                                        level += tmp;

                                        // for action["attack"] cmy
                                        //                      CHANNEL_D->do_channel(ob,"sys",sprintf("origin:%d,add %d " , level,ob->query_temp("fighting/attack")));
                                        tmp=ob->query_temp("fighting/attack");
                                        if(tmp>FIGHT_ATTACK_LIMIT) tmp=FIGHT_ATTACK_LIMIT;
                                        level = level * (100 + tmp) / 100;

                                        //                      CHANNEL_D->do_channel(ob,"sys",skill+ sprintf(" after:%d " , level));

                                        break;
                                case SKILL_USAGE_DEFENSE:
                                        tmp=ob->query_temp("apply/defense");
                                        if(tmp>APPLY_DEFENSE_LIMIT) tmp=APPLY_DEFENSE_LIMIT;
                                        level += tmp;

                                        // for action["dodge"] cmy
                                        if (ob->is_fighting()) {
                                                //                      CHANNEL_D->do_channel(ob,"sys",sprintf("%s origin:%d,add %d ", skill,level,ob->query_temp("fighting/"+skill)));
                                                if( skill == "dodge") {
                                                        tmp = ob->query_temp("apply/dodge");
                                                        if( tmp > APPLY_DODGE_LIMIT ) tmp = APPLY_DODGE_LIMIT;
                                                        level += tmp;
                                                        if( stringp(map_skill= (ob->query_skill_mapped(skill))) && ( eff_level = SKILL_D(map_skill)->effective_level()) > 0)
                                                                level = level * eff_level / 10;      
                                                        //                      CHANNEL_D->do_channel(ob,"sys", sprintf(" dodge eff_level:%d " , eff_level));
                                                        tmp=ob->query_temp("fighting/dodge");
                                                        if(tmp>FIGHT_DODGE_LIMIT) tmp=FIGHT_DODGE_LIMIT;
                                                        level = level * (100 + tmp) / 100;
                                                }
                                                else /*if( skill == "parry")*/
                                                {
                                                        tmp = ob->query_temp("apply/parry");
                                                        if( tmp > APPLY_PARRY_LIMIT) tmp = APPLY_PARRY_LIMIT;
                                                        level += tmp;
                                                        if( stringp(map_skill= (ob->query_skill_mapped(skill))) && ( eff_level = SKILL_D(map_skill)->effective_level()) > 0)
                                                                level = level * eff_level / 10;      

                                                        tmp=ob->query_temp("fighting/parry");
                                                        if(tmp>FIGHT_PARRY_LIMIT) tmp=FIGHT_PARRY_LIMIT;
                                                        level = level * (100 + tmp) / 100;
                                                }
                                                //                      CHANNEL_D->do_channel(ob,"sys",skill+ sprintf(" after:%d " , level));
                                        }

                                        break;
                }

                return level;
        }

        varargs int skill_power(object ob, string skill, int usage)
        {
                int status, level, power, a_d_ratio,a_d_ratio_set, gin_ratio,sen_ratio;
                int eff_level,afford,tmp;
                string map_skill;

                if( !living(ob) )
                        return 0;

                //level
                level = skill_level(ob, skill, usage);
                if( !level ) return (int)ob->query("combat_exp") / 2;
                if(level>1500) level=1500; //防止溢出
                power = (level*level/25)*(level/25);
                tmp = ob->query("combat_exp");
                if( tmp < 0 )
                        tmp = 1;
                if( tmp > 10000000 )
                        tmp = 10000000;
                power = power + tmp/100;

                //神影响攻击,精影响防御
                gin_ratio = 100;
                sen_ratio = 100;
                if( (status = ob->query("max_sen")) > 0 && power > 1000 ) sen_ratio = 100 * ob->query("sen") / status;
                if( (status = ob->query("max_gin")) > 0 && power > 1000 ) gin_ratio = 100 * ob->query("gin") / status;
                if(gin_ratio < 50 )                gin_ratio = 50;
                if(sen_ratio < 50 )                sen_ratio = 50;
                if(gin_ratio > 120 )    gin_ratio = 120;        //允许部分超常发挥的情况
                if(sen_ratio > 120 )    sen_ratio = 120;

                //set attack
                a_d_ratio = 0;
                a_d_ratio_set = 0;
                if( objectp(ob) )
                {
                        if( intp(ob->query("env/attack")) )
                                a_d_ratio = (int)ob->query("env/attack");
                        else
                                a_d_ratio = 50;
                }
                if( a_d_ratio == 0)
                        a_d_ratio = 50;
                else if( a_d_ratio > 100)
                        a_d_ratio = 100;
                else if( a_d_ratio < 0)
                        a_d_ratio = 1;
                if( a_d_ratio != a_d_ratio_set )        //yisheng: only set again when set value is invalid
                        ob->set("env/attack",a_d_ratio);
               
                if( usage == SKILL_USAGE_ATTACK)       power = power*a_d_ratio/100*sen_ratio/25;                //yisheng: 1/4
                else if( usage == SKILL_USAGE_DEFENSE) power = power*(100-a_d_ratio)/100*gin_ratio/25;        //yisheng: 1/4

                //负重(>10%)影响攻击与躲闪
                afford = (int)ob->query_encumbrance() * 100 / (int)ob->query_max_encumbrance();
                if( afford > 10 && afford <= 100 && (skill == "dodge" || usage == SKILL_USAGE_ATTACK) ) power -= power/100*afford;

                if( power < 100 ) power = 100;

                return power;         
        }

        varargs int skill_candodgeorparray(object ob, object victim, string attack_skill, string defense_skill)
        {
                int level_ob, level_victim, n_ob, n_victim, ntrap;
                level_ob = skill_power(ob, attack_skill, SKILL_USAGE_ATTACK);
                level_victim = skill_power(victim, defense_skill, SKILL_USAGE_DEFENSE);
                n_ob = level_ob/1500;
                n_victim = level_victim/1500;
                if( n_ob == n_victim )
                {
                        return 0;        //如果等级相同,让随机数来决定吧
                }
                else
                {
                        ntrap = n_ob - n_victim;
                        if( ntrap > 0 )
                        {
                                ntrap = 10 - ntrap;
                                if( ntrap < 1 )
                                        ntrap = 1;
                                return skill_random(ntrap);        //如果攻击方的等级是防守方的n倍,那么防守方能躲避的几率就很小很小
                        }
                        else
                        {
                                ntrap = 90 + ntrap;
                                if( ntrap > 99 )
                                        ntrap = 99;
                                return skill_random(ntrap); //如果防守方的等级是攻击方的n倍,那么防守方能躲避的几率就很大很大
                        }
                }
        }

        int skill_random(int range)
        {
                //如果返回1,表示在范围内,否则返回0
                if(random(100)< range )
                        return 1;
        }

        varargs int skill_candodge(object ob, object victim, string attack_skill)
        {
                return skill_candodgeorparray(ob, victim, "dodge");
        }

        varargs int skill_canparry(object ob, object victim, string attack_skill)
        {
                return skill_candodgeorparray(ob, victim, "parry");
        }

2. 修改do_attack()方法里的判断是否dodge和是否parray的两句话为如下(Does the victim dodge this hit?和Does the victim dodge this hit?两句):
if( (me != victim) && ( skill_candodge(ob, victim, attack_skill) > 0 || (random(ap+dp)<dp) ) && random(action["undodgeable"])<10) {               // Does the victim dodge this hit?
if( (victim != me) && ( skill_canparry(ob, victim, attack_skill) > 0 || (random(ap+pp)<pp) ) && random(action["unparryable"])<10 ) {               // Does the victim dodge this hit?
这两句话的修改是通过skill_candodge和skill_canparry来判断攻击方和防守方的level是不是有差别,如果有差别,那么取random(100-差别)的几率能躲过去,返回值为1,无差别的时候,那么返回值为0,继续做random(ap+dp)<dp的判断。

收藏 推荐 打印 | 录入:sbso | 阅读:
相关内容       巫师  wiz 
本文评论   [发表评论]   全部评论 (0)
内容推送
52mud提供
一起回忆泥巴游戏QQ群68186072
52mud官方微信公众平台
热门评论