// douzhuan-xingyi 斗转星移
// 1997-2-14
#include <ansi.h>
inherit SKILL;
#include "/kungfu/skill/eff_msg.h";

string *parry_msg = ({
YEL"蓦地里一股力道飞来，将$N一引一带，$N身子轻轻越起，身行落在一旁"NOR,
BLU"$N当下一股内力冲向$L，$n击向$N的$L的招数莫名奇妙的溜滑向一旁"NOR,
HIW"$N双手前探，左臂搭上$n右臂，右臂使出$n的招数将$n此招化去"NOR,
HIY"$N星移斗转，$n这招莫名其妙的在中途转了方向，直奔自己袭来"NOR,
YEL"$N作壁上观，双手与对方相交数掌，谈笑间竟使出$n成名技艺，使得$n不知如何是好"NOR,
BLU"$N凝神运气向$n猛攻快打，使出的招数好似$n的成名绝技，把$n的招数化于无行"NOR,
HIW"只见$N身如飘风，恰似漫天星移，诡异地一式，双掌动向无定不可捉摸地拍向$n的$l"NOR,
HIY"$N身行飘忽不定，在星移斗转之间反用$n的招数击向$n，却令人$n百思不得其解"NOR,
});

int valid_enable(string usage)
{
	return usage == "parry";
}

string query_parry_msg(object weapon)
{
	
		return parry_msg[random(sizeof(parry_msg))] + "。\n";
}

int valid_learn(object me)
{
     return notify_fail("斗转星移只能通过领悟来提高。\n");
}

int practice_skill(object me)
{
	return notify_fail("斗转星移只能通过领悟来提高，无法通过练习来提高。\n");
}

string perform_action_file(string action)
{
	return __DIR__"douzhuan-xingyi/" + action;
}

//modify from douzhuan-xingyi
int ob_hit(object ob, object me, int damage)
{
	object wp,wp1, target;
	string msg;
	int p,j,skill, neili, neili1, exp, exp1;
       if(me->is_busy())  return 0;

	wp = me->query_temp("weapon");
	wp1 = ob->query_temp("weapon");
	skill = me->query_skill("douzhuan-xingyi", 1);
	neili = me->query("neili");
	neili1 = ob->query("neili");
	exp = me->query("combat_exp");
	exp1 = ob->query("combat_exp");
       if(wizardp(me)) tell_object(me,sprintf("damage = %O\n",damage));

	if(me->query_temp("qkdny/hua") && living(me)){
	  if (me->query("jing")< damage/10 || me->query("jingli")< damage/10){
    message_vision(HIC"$N正要把$n的攻势化解，心法却因精力不足运行有误！结果$N虚耗一招。\n"NOR,me, ob);
	  me->start_busy(1+random(2));
	  return random(damage/5);}
	    if ((random(me->query_int()) > ob->query_int()/4) && (random(skill)>ob->query_int()) && random(me->query("combat_exp"))>ob->query("combat_exp")/3){
     message_vision(HIC"$N使用四两播千斤之术，轻轻的化解了$n的攻势。\n"NOR,me,ob);
	  me->add("jing",-damage/10);
	  me->add("jingli",-damage/10);
	  return -damage;} else {
     message_vision(HIC"$N使用四两播千斤之术，化解了$n的大半攻势。\n"NOR,me,ob);
	  me->add("jing",-damage/20);
	  me->add("jingli",-damage/20);
	  return -damage/2;}
	}

	if(me->query_temp("qkdny/yin") && living(me)){
	  if (me->query("jing")< damage/10 || me->query("jingli")< damage/10
	    ||me->query("neili")< damage/10){
   message_vision(HIG"$N正要牵引$n的攻势，心法却因精神内力不足运行有误！结果$N虚耗一招。\n"NOR,me, ob);
	  me->start_busy(1+random(2));
	  return random(damage/5);}
	    if ((random(me->query_int()) > ob->query_int()/4) && (random(skill)>ob->query_int()) && random(me->query("combat_exp"))>ob->query("combat_exp")/3){
     message_vision(HIG"$N运起乾坤大挪移引字诀，$n的攻势不知如何攻向了$n自己！\n"NOR,me,ob);
	  me->add("jing",-damage/10);
	  me->add("jingli",-damage/10);
	  me->add("neili",-damage/5);
	  ob->receive_damage("qi",damage/2);
	  ob->receive_wound("qi",damage/6);
	  p = ob->query("qi")*100/ob->query("max_qi");
	  msg = "( $N"+eff_status_msg(p)+" )\n";
	  message_vision(msg,ob);
	  return -damage;} else {
     message_vision(HIG"$N运起乾坤大挪移引字诀，牵引开了$n的大半攻势。\n"NOR,me,ob);
	  me->add("jing",-damage/20);
	  me->add("jingli",-damage/20);
	  me->add("neili",-damage/10);
	  return -damage/2;}
	}

	if(me->query_temp("qkdny/yi") && living(me)){
		if(!objectp(target = me->query_temp("qkdny/yi"))
		|| environment(me) != environment(target)){
			me->delete_temp("qkdny/yi");
			tell_object(me, HIY"你发现你想挪移的目标对象已经不在这里了。\n"NOR);
			return 0;
			}
		me->delete_temp("qkdny/yi");

		if(!living(target)){
			tell_object(me, HIY"你发现你想挪移的目标对象已经昏迷不醒了。\n"NOR);
			return 0;
			}
		if(neili < 800){
			tell_object(me, HIY"你正要挪移，却发现自己的真气不够了！\n"NOR);
			return 0;
			}

		message_vision(WHT"$N突然双手晃动击出阵阵气流，左拔右带要把$n的招数向旁边众人牵引！\n"NOR,me, ob);
		if(exp < exp1/2 || random(neili) < neili1/2){
			me->add("jingli", -25);
			me->add("neili", -125);
			message_vision(HIY"结果$n并没有受到干扰，反而顺势来到$N的侧面，发出强力的一击！\n"NOR,me, ob);
			return random(damage);
			}
		me->add("neili", -250);
		me->add("jingli", -50);
		tell_room(environment(me), "结果引得"+ob->name()+"的力道直向"+target->name()+"冲击过去！\n",({ target,ob }));
		tell_object(target, HIR"结果你发现"+ob->name()+"的力道直向自己冲击过来！\n"NOR);
		tell_object(ob, HIR"结果你发现自己的力道直向"+target->name()+"冲击过去！\n"NOR);
		if(target->query_skill("dodge") >= damage)
			msg = HIY"结果$n没有受到任何伤害。\n"NOR;

		else{
			target->receive_damage("qi", damage, ob);
			p = target->query("qi")*100/target->query("max_qi");
			msg = damage_msg(damage, "伤害");
			msg += "( $n"+eff_status_msg(p)+" )\n";
			}
		if(target->query("shen") < -1000 && !target->is_killing(ob->query("id"))){
			if(random(target->query_int()) < 20)
				target->kill_ob(ob);
			else if(random(target->query_int()) > 30)
				target->fight_ob(me);
			}
		if(target->query("shen") > -1000 && !target->is_killing(ob->query("id"))){
			if(random(target->query_int()) < 20)
				target->fight_ob(ob);
			else if(random(target->query_int()) > 30)
				target->fight_ob(me);
			}
		message_vision(msg, me, target);
		return -8000;
		}


      if(me->query_temp("qkdny/xu") && !ob->query_temp("weapon")){
		if(me->query_temp("qkdny/xu") > 1200 || me->query_temp("qkdny/xu") > me->query("neili")/2)
			msg = "「蓄」字诀已在你体内蓄满了劲力！\n";
		else{
			msg = "「蓄」字诀自然而起，将这力量储存了下来。\n";
			me->add_temp("qkdny/xu", ob->query("jiali") + ob->query_skill("force")/10);
			}
		if(!me->query("env/brief"))
			tell_object(me, msg);

		if(wizardp(me) && me->query_temp("combat_yield"))
			tell_object(me, "Qkdny/xu = "+me->query_temp("qkdny/xu")+"\n");
		if(damage > me->query("neili")){
			tell_object(me, HIR"结果对方的力道太大，你一不小心被打散了积蓄的力量！\n"NOR);
			me->delete_temp("qkdny/xu");
			return damage/4;
			}
		ob->start_busy(random(2));
		if(!me->is_busy())
			me->start_busy(1);
		return -damage/3;
		}

      if(me->query_temp("fanzhen")){
		me->delete_temp("fanzhen");
		return 1;
		}

      if(me->query("jiali") && living(me) &&
	 random(skill)+20 > random(ob->query_skill("parry", 1)) &&
	 exp > exp1/2 && skill > 50 && neili > 500 && living(ob)
	 && !ob->query("env/invisibility")){
		if(random(2)==1) me->add_temp("fanzhen", 1);
		me->add("neili", -(random(10)));
		if(wp && wp1){
			msg = msg_weapon[random(sizeof(msg_weapon))];
			msg = replace_string(msg, "$W", wp->name());
			msg = replace_string(msg, "$w", wp1->name());
			if(neili >= neili1*2){
				if(random(me->query_str()) > ob->query_str()/2 && skill > 150){
                                        msg += HIC"结果$n一个抵挡不住，手中"+wp1->name()+HIC"差点脱手飞出！\n"NOR,

                                        me->add("neili", -50);
                                        ob->add_busy(1+random(3));
//                                        wp1->unequip();
//                                        wp1->move(environment(ob));
					j = -5000;
                                        }

				{
					ob->receive_damage("qi", damage/2?damage/2:10, me);
					ob->receive_wound("qi", damage/10 > 0?damage/10:2, me);
					p = ob->query("qi")*100/ob->query("max_qi");
					msg += damage_msg(damage/2, "伤害");
					msg += "( $n"+eff_status_msg(p)+" )\n";
					j = -5000;
					}
				}
			else if(neili >= random(neili1)*2){
				msg += "结果基本上卸掉了$n的力道。\n";
				j = -5000;
				}
			else{
				j = damage/2+random(damage/2);
				if(j<damage/2) msg += "结果卸掉了一些$n的力道。\n";
				else msg += "结果卸掉了$n大半的力道。\n";
				j = -j;
				}
			message_vision(msg, me, ob);
			return j;
			}
		else{
			msg = msg_unarmed[random(sizeof(msg_unarmed))];
			if(neili >= neili1*2){
				ob->receive_damage("qi", damage/2?damage/2:10, me);
				ob->receive_wound("qi", damage/10 > 0?damage/10:2, me);
				p = ob->query("qi")*100/ob->query("max_qi");
				msg += damage_msg(damage, "内伤") + "( $n"+eff_status_msg(p)+" )\n";
				j = -5000;
				}
		else if(neili >= random(neili1)*2){
			msg += "结果基本上卸掉了$n的力道。\n";
			j = -5000;
			}
		else{
			j = damage/2+random(damage/2);
			if(j<damage/2) msg += "结果卸掉了一些$n的力道。\n";
			else msg += "结果卸掉了$n一半的力道。\n";
			j = -j;
			}
		message_vision(msg, me, ob);
		return j;
		}
	}
}

