

int regive_all(object who)
{
	int i;
	object *obs,me = this_object();
	
	if( !who ) return 0;
  	obs = all_inventory (who);
  	i = sizeof(obs);

  	message_vision ("满天的乌云渐渐散去。。。。\n",who);
  	while (i--)
  	{
    		object ob = obs[i];
    		if( !ob->query_temp("18break") )
    			continue;
		message_vision ("$N身上$n闪了一闪！\n",who,ob);
		ob->delete_temp("18break");
		ob->delete("breaked");
  	}  
    	return 1;
}

int get_all(object who)
{
	int i;
	object *obs,me = this_object();
	
	if( !who ) return 0;
  	obs = all_inventory (who);
  	i = sizeof(obs);

  	message_vision ("一阵狂风吹来，天地大变，冥冥中有紫雷夹带着狂风出现！\n",who);
  	while (i--)
  	{
    		object ob = obs[i];
    		if( ob->query("breaked") )
    			continue;
    		if( !ob->is_armor() && !ob->is_weapon() && !ob->is_fabao() )
    			continue;	
		message_vision ("一道惊雷闪过，$N身上的$n顿时灵气全无！\n",who,ob);
		ob->unequip();
		ob->set_temp("18break",1);
		ob->set("breaked",1);
  	} 
  	who->reset_action(); 
    	return 1;
}

int work_me()
{
        object who;
        who=this_player();

        if( (int)who->query("daoxing")<200000 )
        {
                message_vision("$N对$n一拱手，道：道行不够，强求亦是枉然。\n", this_object(),who);
                tell_object(who,CYN+name()+CYN"说道：道行都没到"+RANK_D->describe_dx(175000)+CYN"的境地，进去也是送死。\n"NOR);
                return 1;
        }
        if( who->query("mark/18diyu") && who->query("fangcun/panlong_hell_18")!="begin") 
        {
		message_vision("$N对$n一拱手，道：即是武功高强，我等佩服便是，这。。。便是免了吧！\n",this_object(),who);
		if( !who->is_titles("洗心革面") )
		{
			if( who->set_titles("洗心革面") )
			{
				tell_object(who,HIC"【系统】你获得了称号：「"HIC"洗心革面"NOR HIC"」。\n"NOR);
				CHANNEL_D->do_channel(this_object(),"chat",who->query("name")+"获得了称号：「"HIW"洗心革面" HIC"」。"NOR);
			}
		}
        	return 1;
        }
        if( this_object()->query_temp("SomeonePassing") ) 
        {
                tell_object(who,CYN+name()+CYN"说道：真时机缘不巧，改日再来吧。\n"NOR);
                return 1;
        }
        if( time()<who->query("mark/18diyu_fail")+3600 )
        {
                message_vision("$N对$n一拱手，道：修行不够，强求亦是枉然。\n", this_object(),who);
                tell_object(who,CYN+name()+CYN"说道：你刚刚失败过，还是先去练练！\n"NOR);
                return 1;
        }
	message_vision("$N对$n阴阴地笑了几声，说：天堂有路你不走，地狱无门你闯进来。\n",this_object(),who);
        this_object()->set_temp("SomeonePassing",1);
        CHANNEL_D->do_channel(this_object(),"chat",who->query("name")+"要闯俺地府十八层地狱，哼！等着收尸吧！");
        message_vision(HIC"$N"HIC"双手拍了一下，$n"HIC"脚下突然陷了下去。。。\n"NOR, this_object(),who);
        who->move("/d/death/emptyroom");
        EMOTE_D->do_emote(this_object(), "grin",0,CYN,0,0,0);
        this_object()->set_temp("no_ruturn",1);
        this_object()->move("/d/death/emptyroom");
	call_out("get_all",1,who);
        call_out("message",3,who);
        call_out("round_diyu",4, who,1);
        return 1;
}

int check_status(object who)
{
	if( !who )
		return 0;
	if( (int)who->query("kee") < 50 
         || (int)who->query("eff_kee") < 50
         || !present(who,environment()) )
        {
		remove_call_out("round_diyu");
		remove_call_out("message");
        	remove_call_out("winning");
        	remove_call_out("failed");
		who->set("eff_kee",50);
                call_out("failed",1,who);
                return 1;
        }
}

int failed(object who)
{       
	if( who )
	{
        	command("chat* 狂笑了几声。");
        	CHANNEL_D->do_channel(this_object(),"chat","果真有不怕死的，可惜还是逃不出俺的手掌心！");
        	this_object()->delete_temp("SomeonePassing");
        	who->set("mark/18diyu_fail",time());
        	regive_all(who);
        	who->move("obj/void");
        	who->unconcious();
        	this_object()->set_temp("no_ruturn",0);
        	this_object()->move("/d/death/zhengtang");
        }	
        remove_call_out("remove_all");
        call_out("remove_all", 3);
        return 1;
}

int remove_all()
{
	int i;
        object *list,empty;

        remove_call_out("remove_all");
        if( !(empty = find_object("/d/death/emptyroom")) )
                empty = load_object("/d/death/emptyroom");
        write("四周刮起一阵阴风。。。\n");
        if( empty = find_object("/d/death/emptyroom") ) {

                list=all_inventory(empty);
                i = sizeof(list);
                while (i--)
                {
                        object ob=list[i];
                        ob->move("/d/changan/fendui");
                }
        }
        return 1;
}

int winning(object who)
{
	if( who )
	{	
		regive_all(who);
     		if( who->query("fangcun/panlong_hell_18")=="begin" )
		{
			CHANNEL_D->do_channel(this_object(),"chat",who->query("name")+"，竟然闯过了我幽冥地府十八层地狱！");
			who->set("fangcun/panlong_hell_18","done");
			this_object()->set_temp("no_ruturn",0);
        		this_object()->move("/d/death/zhengtang");
        		this_object()->delete_temp("SomeonePassing");
	        	remove_call_out("remove_all");
        		call_out("remove_all", 3);
        		return 1;
		}
        	CHANNEL_D->do_channel(this_object(),"chat",who->query("name")+"，算你走运，下回可没这么便宜了！");
	        who->add("kar", 10);
        	who->add("potential", 5000);
        	who->add("daoxing", 5000);
        	tell_object(who,"你得到了五千点潜能和五年道行。\n");
        	who->set("mark/18diyu",1);
        	if( who->set_titles("洗心革面") )
        	{
	 		tell_object(who,HIC"【系统】你获得了称号：「"HIC"洗心革面"NOR HIC"」。\n"NOR);
	 		CHANNEL_D->do_channel(this_object(),"chat",who->query("name")+"获得了称号：「"HIW"洗心革面" HIC"」。"NOR);
	 	}
 		who->save();
        }
        this_object()->set_temp("no_ruturn",0);	
        this_object()->move("/d/death/zhengtang");
        this_object()->delete_temp("SomeonePassing");
        remove_call_out("remove_all");
        call_out("remove_all", 3);
        return 1;
}

int message(object who)
{
	string *msgs,msg;
        remove_call_out("message");
        if( !who )
        	return 0;
        msgs = ({
        	"\n你觉得自己不断下降，周围景物如彩蝶翻飞，不可注目。\n",
                "\n你觉得自己不断下降。\n",
                "\n你觉得自己不断下降，天地似乎没了界限。。。\n",
                "\n你觉得自己不断下降，周围一切都在旋转。。。\n",
                "\n你觉得自己不断下降，下降，似乎落向了无尽的深渊。\n",
	});
	msg = msgs[random(sizeof(msgs))];
	tell_object(who,msg);
        return 1;
}

string diyu_short(int lvl)
{
	string long,arg,color,*clr,*name = ({
		"吊筋","幽枉","火坊","酆都","拔舌","剥皮",
		"磨涯","锥捣","车崩","寒冰","脱壳","抽肠",
		"油锅","黑暗","刀山","血池","阿鼻","秤杆",
	});	
	if( lvl<1 || lvl>18 )
		return 0;
	arg = name[lvl-1]+"狱";
	long = @LONG
	                   ******
	                  ***%s***
			  ********
	                  ***%s***
			  ********
	                  ***%s***
			   ******
LONG;	
	clr = ({RED,YEL,BLU,HIB,MAG,CYN,HIR,HIG,HIY,HIB,HIM,HIC,HIW,});
	color = clr[random(sizeof(clr))];
	long = sprintf(long,HBRED+color+arg[0..1]+NOR,HBRED+color+arg[2..3]+NOR,HBRED+color+arg[4..5]+NOR);
	long = replace_string(long,"*",REV+color+" "NOR);
	return long;
}

int round_diyu(object who,int lvl)
{
	int num;
        object ghost;
 	seteuid(getuid());
 	if( who )
 	{
	        tell_room(environment(who),"\n突然间一道黑牌闪过：\n\n");
        	tell_room(environment(who),diyu_short(lvl));
	        ghost=new(__DIR__"gui");
        	ghost->set_level(ghost->query_level()+lvl);
        	ghost->move(environment(who));
        	ghost->invocation(who);
        }
        num = lvl/3;
        if( random(num)>0 )
        {
	        ghost=new(__DIR__"gui");
        	ghost->set_level(ghost->query_level()+lvl);
        	ghost->move(environment(who));
        	ghost->invocation(who);
        }	
        if( who )
        {
		if( lvl==18 )
		{
        		remove_call_out("winning");
			call_out("winning",4,who);
		}
        	else
        	{
        		remove_call_out("message");
        		remove_call_out("round_diyu");
        		call_out("message",3,who);
        		call_out("round_diyu", 4, who,lvl+1);
        	}	
	        remove_call_out("check_status");
		call_out("check_status",1,who);        
        }	
        return 1;
}
