combatd.c

来自「C实现的MUD,对大家基本入门网络游戏很有帮助!」· C语言 代码 · 共 1,195 行 · 第 1/4 页

C
1,195
字号
				foo = weapon->hit_ob(me, victim, damage_bonus);				if( stringp(foo) ) result += foo;				else if(intp(foo) ) damage_bonus += foo;			} else 			{				foo = me->hit_ob(me, victim, damage_bonus);				if( stringp(foo) ) result += foo;				else if(intp(foo) ) damage_bonus += foo;			}			if( martial_skill = victim->query_skill_mapped("dodge") ) {				foo = SKILL_D(martial_skill)->ob_hit(me, victim, damage_bonus);				if( stringp(foo) ) result += foo;				else if(intp(foo) ) damage_bonus += foo;			}			if( martial_skill = victim->query_skill_mapped("parry") ) {				foo = SKILL_D(martial_skill)->ob_hit(me, victim, damage_bonus);			    if( stringp(foo) ) result += foo;				else if(intp(foo) ) damage_bonus += foo;			}                if( martial_skill = victim->query_skill_mapped("force") ) {				foo = SKILL_D(martial_skill)->ob_hit(me, victim, damage_bonus);				if( stringp(foo) ) result += foo;				else if(intp(foo) ) damage_bonus += foo;			}						if (foo = victim->query_temp("armor/cloth")) {				foo = foo->ob_hit(me, victim, damage_bonus);				if( stringp(foo) ) result += foo;				else if(intp(foo) ) damage_bonus += foo;			}						if( damage_bonus > 0 )			damage += (4*damage_bonus + random(damage_bonus))/5;			if( damage < 0 ) damage = 0;			// Let combat exp take effect		//	defense_factor = your["combat_exp"];		/*	while( random(defense_factor) > my["combat_exp"] ) 			{				damage -= damage / 4;				defense_factor /= 2;			}*/			//	(6) Inflict the damage.			//damage = damage * 20 / (victim->query_con() / 4 + 15);			damage = damage * 20 / ( victim->query_con() / 5 + 16);			damage = victim->receive_damage("qi", damage, me);			if( random(damage) > (int)victim->query_temp("apply/armor") && ( (me->is_killing(victim->query("id"))) 				&& ((!weapon) && !random(4) || weapon && !random(2) )			    || ((!weapon) && !random(7) || weapon && !random(4) ) )  )			{				// We are sure that damage is greater than victim's armor here.				victim->receive_wound("qi",damage - (int)victim->query_temp("apply/armor"), me);				wounded = 1;			}		result += damage_msg(damage, action["damage_type"]);		}	} 		result = replace_string( result, "$l", limb );	if( objectp(weapon) )		result = replace_string( result, "$w", weapon->name() );	else if( stringp(action["weapon"]) )		result = replace_string( result, "$w", action["weapon"] );	else if( attack_skill == "finger" ) 		result = replace_string( result, "$w", "手指" );	message_combatd(result, me, victim );    	if ( wizardp(me) && me->query("env/combat") )	{	if( damage > 0 )		{tell_object(me, sprintf( GRN "AP:%d,DP:%d,PP:%d,伤害力:%d\n" NOR,				ap/100, dp/100, pp/100, damage));			tell_object(victim, sprintf( GRN "AP:%d,DP:%d,PP:%d,伤害力:%d\n" NOR,				ap/100, dp/100, pp/100, damage));		}			else			{tell_object(me, sprintf( GRN "AP:%d,DP:%d,PP:%d\n" NOR,				ap/100, dp/100, pp/100));			tell_object(victim, sprintf( GRN "AP:%d,DP:%d,PP:%d\n" NOR,				ap/100, dp/100, pp/100));			}	}		if( damage > 0 ) {		report_status(victim, wounded);		if( victim->is_busy() ) victim->interrupt_me(me);		if( (!me->is_killing(your["id"])) && (!victim->is_killing(my["id"])) &&		victim->query("qi")*2 <= victim->query("max_qi")) 		{			me->remove_enemy(victim);			victim->remove_enemy(me);			fight_reward(me, victim);			fight_penalty(me, victim);					if (me->query("race") == "人类") {			message_vision( winner_msg[random(sizeof(winner_msg))], me, victim);			} else message_vision( winner_animal_msg[random(sizeof(winner_animal_msg))], me, victim);			/*// 比武现场转播 start			result = winner_msg[random(sizeof(winner_msg))];			result = replace_string(result,  "$P", me->name());			result = replace_string(result,  "$N", me->name());			result = replace_string(result,  "$n", victim->name());			result = replace_string(result,  "$p", victim->name());			if ((string)environment(me)->query("short") == "擂台")			for (userno=0; userno<sizeof(player); userno++)		    if ((player[userno])->query_temp("view_leitai"))			tell_object(player[userno], result);// 比武现场转播 end*/		}	}	if( functionp(action["post_action"]) )		evaluate( action["post_action"], me, victim, weapon, damage);}//	fight()//	This is called in the attack() defined in F_ATTACK, which handles fighting//	in the heart_beat() of all livings. Be sure to optimize it carefully.void fight(object me, object victim){	object ob;	string result;// 比武现场转播 start//	player=users();// 比武现场转播 end	if( !living(me) ) return;        if( me->query_temp("combat_yield") && userp(me)) return;	// If victim is busy or unconcious, always take the chance to make an attack.	if( victim->is_busy() || !living(victim) ) {		me->set_temp("guarding", 0);		if( !victim->is_fighting(me) ) victim->fight_ob(me);		do_attack(me, victim, me->query_temp("weapon"), TYPE_QUICK);		if( me->is_fighting(victim) && victim->is_fighting(me)) 		if( (!objectp(me->query_temp("weapon")) 		   && sizeof(me->query_skill_prepare()) > 1)		||  ( objectp(me->query_temp("weapon")) 		   &&(me->query_temp("weapon"))->query("skill_type") == "sword"		   && me->query_skill("pixie-jian", 1) >= 60		   && me->query_skill_mapped("sword") == "pixie-jian")                || (me->query("double_attack") && !objectp(me->query_temp("weapon")))                 || me->query_temp("double_attack"))		{		if (me->query("double_attack") && sizeof(me->query_skill_prepare()) < 2)			message_vision(CYN"\n$N双手分使,灵活异常,好象变成了两个人似的!"NOR,me);		   me->set_temp("action_flag",1);		   do_attack(me, victim, me->query_temp("weapon"), TYPE_QUICK);		   me->delete_temp("action_flag");	     	}	// Else, see if we are brave enough to make an aggressive action.		} else if( me->query_temp("guarding")||					random( (int)me->query_dex()  ) > random( (int)victim->query_dex() )) 		{	me->set_temp("guarding", 0);			if( !victim->is_fighting(me) ) victim->fight_ob(me);  			do_attack(me, victim, me->query_temp("weapon"), TYPE_REGULAR);		if( me->is_fighting(victim) && victim->is_fighting(me)) 		if( (!objectp(me->query_temp("weapon")) 		   && sizeof(me->query_skill_prepare()) > 1)		||  ( objectp(me->query_temp("weapon")) 		   &&(me->query_temp("weapon"))->query("skill_type") == "sword"		   && me->query_skill("pixie-jian", 1) >= 60		   && me->query_skill_mapped("sword") == "pixie-jian")                || (me->query("double_attack") && !objectp(me->query_temp("weapon")))                 || me->query_temp("double_attack"))		{		if (me->query("double_attack") && sizeof(me->query_skill_prepare()) < 2)			message_vision(CYN"\n$N双手分使,灵活异常,好象变成了两个人似的!"NOR,me);		   me->set_temp("action_flag",1);		   do_attack(me, victim, me->query_temp("weapon"), TYPE_QUICK);		   me->delete_temp("action_flag");	     	}	// Else, we just start guarding.	} else 	{		me->set_temp("guarding", 1);		message_vision( guard_msg[random(sizeof(guard_msg))], me, victim);// 比武现场转播 start/*		result = guard_msg[random(sizeof(guard_msg))];		result = replace_string(result,  "$P", me->name());		result = replace_string(result,  "$N", me->name());		result = replace_string(result,  "$n", victim->name());		result = replace_string(result,  "$p", victim->name());		if ((string)environment(me)->query("short") == "擂台")		for (userno=0; userno<sizeof(player); userno++)		    if ((player[userno])->query_temp("view_leitai"))			tell_object(player[userno], result);*/// 比武现场转播 end		return;	}	return;}//	auto_fight()//	This function is to start an automatically fight. Currently this is//	used in "aggressive", "vendetta", "hatred", "berserk" fight.void auto_fight(object me, object obj, string type){	// Don't let NPC autofight NPC.	if( !userp(me) && !userp(obj) ) return;	// Because most of the cases that we cannot start a fight cannot be checked	// before we really call the kill_ob(), so we just make sure we have no 	// aggressive callout wating here.	if( me->query_temp("looking_for_trouble") ) return;	me->set_temp("looking_for_trouble", 1);	// This call_out gives victim a chance to slip trough the fierce guys.	call_out( "start_" + type, 0, me, obj);}void start_berserk(object me, object obj){	int shen;	if( !me || !obj ) return;				// Are we still exist( not becoming a corpse )?	me->set_temp("looking_for_trouble", 0);	if(	me->is_fighting(obj)				// Are we busy fighting?	||	!living(me)							// Are we capable for a fight?	||	environment(me)!=environment(obj)	// Are we still in the same room?	||	environment(me)->query("no_fight") 	// Are we in a peace room?	)	return;	shen = 0 - (int)me->query("shen");	message_vision("$N用一种异样的眼神扫视著在场的每一个人。\n", me);	if( !userp(me) || (int)me->query("neili") > (random(shen) + shen)/10 ) return;	if( shen > (int)me->query("score") 	&&	!wizardp(obj) ) {		message_vision("$N对著$n喝道:" + RANK_D->query_self_rude(me)			+ "看你实在很不顺眼,去死吧。\n", me, obj);		me->kill_ob(obj);	} else {		message_vision("$N对著$n喝道:喂!" + RANK_D->query_rude(obj)			+ "," + RANK_D->query_self_rude(me) + "正想找人打架,陪我玩两手吧!\n",			me, obj);		me->fight_ob(obj);	}}void start_hatred(object me, object obj){	if( !me || !obj ) return;				// Are we still exist( not becoming a corpse )?	me->set_temp("looking_for_trouble", 0);	if(	me->is_fighting(obj)				// Are we busy fighting?	||	!living(me)							// Are we capable for a fight?	||	environment(me)!=environment(obj)	// Are we still in the same room?	||	environment(me)->query("no_fight") 	// Are we in a peace room?	)	return;	if(	me->query_temp("owner") == obj->query("id")	// be trained	||	obj->query_temp("owner") == me->query("id") 	// be trained	)	return;	// We found our hatred! Charge!	if (me->query("race") == "人类") {	message_vision( catch_hunt_msg[random(sizeof(catch_hunt_msg))], me, obj);	} else message_vision( catch_hunt_beast_msg[random(sizeof(catch_hunt_beast_msg))], me, obj);	me->kill_ob(obj);}void start_vendetta(object me, object obj){	if( !me || !obj ) return;				// Are we still exist( not becoming a corpse )?	me->set_temp("looking_for_trouble", 0);	if(	me->is_fighting(obj)				// Are we busy fighting?	||	!living(me)							// Are we capable for a fight?	||	environment(me)!=environment(obj)	// Are we still in the same room?	||	environment(me)->query("no_fight") 	// Are we in a peace room?	)	return;	// We found our vendetta opponent! Charge!	me->kill_ob(obj);}void start_aggressive(object me, object obj){	if( !me || !obj ) return;				// Are we still exist( not becoming a corpse )?	me->set_temp("looking_for_trouble", 0);	if(	me->is_fighting(obj)				// Are we busy fighting?	||	!living(me)							// Are we capable for a fight?	||	environment(me)!=environment(obj)	// Are we still in the same room?	||	environment(me)->query("no_fight") 	// Are we in a peace room?	)	return;	// We got a nice victim! Kill him/her/it!!!

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?