combatd.c
来自「C实现的MUD,对大家基本入门网络游戏很有帮助!」· C语言 代码 · 共 1,195 行 · 第 1/4 页
C
1,195 行
if( ratio==100 ) return HIG "看起来充满活力,一点也不累。" NOR; if( ratio > 95 ) return HIG "似乎有些疲惫,但是仍然十分有活力。" NOR; if( ratio > 90 ) return HIY "看起来可能有些累了。" NOR; if( ratio > 80 ) return HIY "动作似乎开始有点不太灵光,但是仍然有条不紊。" NOR; if( ratio > 60 ) return HIY "气喘嘘嘘,看起来状况并不太好。" NOR; if( ratio > 40 ) return HIR "似乎十分疲惫,看来需要好好休息了。" NOR; if( ratio > 30 ) return HIR "已经一副头重脚轻的模样,正在勉力支撑著不倒下去。" NOR; if( ratio > 20 ) return HIR "看起来已经力不从心了。" NOR; if( ratio > 10 ) return RED "摇头晃脑、歪歪斜斜地站都站不稳,眼看就要倒在地上。" NOR; return RED "已经陷入半昏迷状态,随时都可能摔倒晕去。" NOR;}varargs void report_status(object ob, int effective){// 比武现场转播 start// player=users();// 比武现场转播 end if( effective ) {// if(!ob->query_temp("tjj_jie")) message_vision( "( $N" + eff_status_msg( (int)ob->query("eff_qi") * 100 / (int)ob->query("max_qi") ) + " )\n", ob);// 比武现场转播 start// if ((string)environment(ob)->query("short") == "擂台")// for (userno=0; userno<sizeof(player); userno++)// if ((player[userno])->query_temp("view_leitai"))// tell_object(player[userno], "( " + ob->name() + eff_status_msg(// (int)ob->query("eff_qi") * 100 / (int)ob->query("max_qi") ) // + " )\n");// 比武现场转播 end } else {// if(!ob->query_temp("tjj_jie")) message_vision( "( $N" + status_msg( (int)ob->query("qi") * 100 / (int)ob->query("max_qi") ) + " )\n", ob);// 比武现场转播 start// if ((string)environment(ob)->query("short") == "擂台")// for (userno=0; userno<sizeof(player); userno++)// if ((player[userno])->query_temp("view_leitai"))// tell_object(player[userno], "( " + ob->name() + status_msg(// (int)ob->query("qi") * 100 / (int)ob->query("max_qi") ) // + " )\n");// 比武现场转播 end }}void fight_reward(object winner, object loser){ object owner; if(owner=winner->query("possessed")) winner = owner; winner->win_enemy(loser);}void fight_penalty(object winner, object loser){ object owner; if(owner=loser->query("possessed")) loser = owner; loser->lose_enemy(winner);}// This function calculates the combined skill/combat_exp power of a certain// skill. This value is used for A/(A+B) probability use.varargs int skill_power(object ob, string skill, int usage){ int status, level, power,attack,def; int stra,dodgea,dexa; if( !living(ob) ) return 0; attack=ob->query_temp("apply/attack");if (ob->query_temp("apply/strength") > 800)ob->set_temp("apply/strength",800);if (ob->query_temp("apply/intelligence") > 800)ob->set_temp("apply/intelligence",800);if (ob->query_temp("apply/constitution") > 800)ob->set_temp("apply/constitution",800);if (ob->query_temp("apply/dexerity") > 800)ob->set_temp("apply/dexerity",800);if (ob->query_temp("apply/attack") > 2000)ob->set_temp("apply/attack",2000);if (ob->query_temp("apply/defense") > 2000)ob->set_temp("apply/defense",2000);if (ob->query_temp("apply/damage") >3000)ob->set_temp("apply/damage",3000);if (ob->query_temp("apply/armor") > 4000)ob->set_temp("apply/armor",4000);if (ob->query_temp("apply/dodge") > 1200)ob->set_temp("apply/dodge",1200);if (ob->query_temp("fight/dodge") > 1000)ob->set_temp("fight/dodge",1000); if (attack>200) attack = 200; def = ob->query_temp("apply/defense"); if (def>200) def = 200; level = ob->query_skill(skill)/2;dodgea=ob->query_temp("fight/dodge");if (dodgea> 250) dodgea=250; switch(usage) { case SKILL_USAGE_ATTACK: level += attack; break; case SKILL_USAGE_DEFENSE: level += def; if (ob->is_fighting() && skill="dodge" ) level = level + dodgea; else break; } if( !level ) return (int)ob->query("combat_exp") / 2; if (level > 600) level = 600;dexa=ob->query_dex();if (dexa > 250) dexa=250;stra=ob->query_str() + ob->query_temp("str")/2;if (stra > 250) stra=250; power = (level / 6)*level*level; if (usage == SKILL_USAGE_ATTACK) return (power + ob->query("combat_exp")) / 30 * dexa; return (power + ob->query("combat_exp")) /30 * (skill == "dodge"?dexa:stra); if (usage == SKILL_USAGE_ATTACK) return (power + ob->query("combat_exp")) / 30 * stra; else return (power + ob->query("combat_exp")) / 30 * stra; }// do_attack()// Perform an attack action. This function is called by fight() or as an// interface for some special utilize in quests.varargs int do_attack(object me, object victim, object weapon, int attack_type, string attack_msg, string damtype){ mapping my, your, prepare, action; string limb, *limbs, result; string attack_skill, force_skill, martial_skill, dodge_skill, parry_skill; mixed foo; int ap, dp, pp,n; int damage, damage_bonus, defense_factor,v_armor; int cost; int wounded = 0;int bounce = 0; int flag = 0; int absorb_vic; object vweapon;if (victim->query_temp("weapon")){ vweapon = victim->query_temp("weapon");}// 比武现场转播 start// player=users();// 比武现场转播 end if (me->query_skill_mapped("parry") == "douzhuan-xingyi" && ((!weapon && !vweapon) || ((weapon && vweapon) && weapon->query("skill_type") == vweapon->query("skill_type")))) flag = 1; if (!living(me)) return 0; my = me->query_entire_dbase(); your = victim->query_entire_dbase();// (0) Choose skills. if (flag) { foo = me; me = victim; } prepare = me->query_skill_prepare(); if (!prepare) prepare = ([]); if ( sizeof(prepare) == 0) attack_skill = "unarmed"; if ( sizeof(prepare) == 1) attack_skill = (keys(prepare))[0]; if ( sizeof(prepare) == 2) attack_skill = (keys(prepare))[me->query_temp("action_flag")]; if ( weapon ) attack_skill = weapon->query("skill_type"); if (flag && !me->query_skill_mapped(attack_skill)) { me = foo; flag = 0; prepare = me->query_skill_prepare(); if (!prepare) prepare = ([]); if ( sizeof(prepare) == 0) attack_skill = "unarmed"; if ( sizeof(prepare) == 1) attack_skill = (keys(prepare))[0]; if ( sizeof(prepare) == 2) attack_skill = (keys(prepare))[me->query_temp("action_flag")]; if ( weapon ) attack_skill = weapon->query("skill_type"); } // (1) Find out what action the offenser will take. me->prepare_skill("sword"); me->prepare_skill("blade"); me->reset_action(); action = me->query("actions"); if( !mapp(action) ) { me->reset_action(); action = me->query("actions"); if( !mapp(action) ) { CHANNEL_D->do_channel( this_object(), "sys", sprintf("%s(%s): bad action = %O", me->name(1), me->query("id"), me->query("actions", 1)));// return combat_action[random(sizeof(combat_action))]; return 0; } } if (me->query_temp("action_flag") == 0) result = "\n" + action["action"] + "!\n"; else result = "\n" + "紧跟着"+action["action"] + "!\n"; if(stringp(attack_msg)) result = "\n" + attack_msg + "\n"; // (2) Prepare AP, DP for checking if hit. limbs = victim->query("limbs"); if (! arrayp(limbs)) { limbs = ({ "身体" }); victim->set("limbs", limbs); } limb = limbs[random(sizeof(limbs))]; ap = skill_power(me, attack_skill, SKILL_USAGE_ATTACK); if( ap < 1) ap = 1; if (userp(me) && intp(action["dodge"])) me->set_temp("fight/dodge", action["dodge"]); dp = skill_power(victim, "dodge", SKILL_USAGE_DEFENSE); if( dp < 1 ) dp = 1; if( victim->is_busy() ) dp /= 3; // (3) Fight! if( random(ap + dp) < dp ) { // Does the victim dodge this hit? dodge_skill = victim->query_skill_mapped("dodge"); if( !dodge_skill ) dodge_skill = "dodge"; result += SKILL_D(dodge_skill)->query_dodge_msg(limb); damage = RESULT_DODGE; } else { // (4) Check if the victim can parry this attack. pp = skill_power(victim, "parry", SKILL_USAGE_DEFENSE); if( victim->query_temp("weapon") ) { if( !weapon ) pp *= 2; } else { if( weapon ) pp /= 2; } if( victim->is_busy() ) pp /= 3; if( pp < 1 ) pp = 1; if( random(ap + pp)< pp ) { parry_skill = victim->query_skill_mapped("parry"); if( !parry_skill ) parry_skill = "parry"; // change to SKILL_D(parry_skill) after added parry msg to those // martial arts that can parry. result += SKILL_D("parry")->query_parry_msg(weapon); damage = RESULT_PARRY; } else {// (5) We hit the victim and the victim failed to parry damage = me->query_temp("apply/damage");if (me->query_temp("apply/strength") > 800)me->set_temp("apply/strength",800);if (me->query_temp("apply/intelligence") > 800)me->set_temp("apply/intelligence",800);if (me->query_temp("apply/constitution") > 800)me->set_temp("apply/constitution",800);if (me->query_temp("apply/dexerity") > 800)me->set_temp("apply/dexerity",800);if (me->query_temp("apply/attack") > 2000)me->set_temp("apply/attack", 2000);if (me->query_temp("apply/defense") > 2000)me->set_temp("apply/defense", 2000);if (me->query_temp("apply/damage") > 3000)me->set_temp("apply/damage", 3000);if (me->query_temp("apply/armor") > 4000)me->set_temp("apply/armor", 4000);if (me->query_temp("apply/dodge") > 1200)me->set_temp("apply/dodge",1200);if (me->query_temp("fight/dodge") > 1000)me->set_temp("fight/dodge",1000); if ( damage > 200 ) damage = 200; damage = (4*damage + random(damage)) / 5; // if( action["damage"] ) // damage += action["damage"] * damage / 500;//暂时关闭 if (weapon) damage += me->query_skill(attack_skill) * damage / 500; damage_bonus = me->query_str() * 2; // Let force skill take effect. if( my["jiali"] && (my["neili"] > my["jiali"]) ) { if( force_skill = me->query_skill_mapped("force") ) { foo = SKILL_D(force_skill)->hit_ob(me, victim, damage_bonus, my["jiali"]); if( stringp(foo) ) result += foo; else if( intp(foo) ) damage_bonus += foo; } } // if( action["force"] ) // damage_bonus += action["force"] * damage_bonus / 1000;//暂时关闭 damage_bonus += me->query_skill(attack_skill) * damage_bonus / 1000; if( weapon ) damage_bonus -= damage_bonus/3 ; if( martial_skill = me->query_skill_mapped(attack_skill) ) { foo = SKILL_D(martial_skill)->hit_ob(me, victim, damage_bonus); if( stringp(foo) ) result += foo; else if(intp(foo) ) damage_bonus += foo; } // Let weapon or monster have their special damage. if( weapon ) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?