// 第一章
int Rule = 1;
int RoundTime = 30;
int PlayerSpawn = 0;
int PlayerSpawnDir = 0;
int PlayerWeapon = 7;
int PlayerWeapon2 = 6;
int PlayerHP = 2500;

int q=0;
int qzr1=0;
int qzr2=0;
int qzr3=0;
int qth=0;
int qzx=0;
int qwg=0;
int t=0;
int tzr1=0;
int tzr2=0;
int tzr3=0;
int t1=0;
int t5=0;
int v= 0;

OnUpdate()
{
	int player = GetAnyChar("player");
	if (player < 0)
	{
		return 0;
	}
	
	int c = GetAnyChar("云尘道长");
	int c2 = GetAnyChar("汤 怀");
	int c3 = GetAnyChar("张 显");
	int c4 = GetAnyChar("王 贵");
	int now=GetGameTime();
	int gameover = 0;
	
	if (q== 0)
	{
		AddNPC("1-2");
	    AddNPC("1-3");
	    AddNPC("1-4");
		q=1;
	}
	if(q==1&&c2>=0&&c3>=0&&c4>=0)
	{
		PlayerPerform("say", "提示：【分别找到汤怀、张显、王贵三人】"); 
		PlayerPerform("say", "提示：【分别找到汤怀、张显、王贵三人】");
		PlayerPerform("say", "提示：【分别找到汤怀、张显、王贵三人】");
		PlayerPerform("pause", 2);
		PlayerPerform("block", 0);
		PlayerPerform("say", "（我也需尽全力，莫让师父与三位兄弟小瞧了。）");
		PlayerPerform("pause", 2);
		PlayerPerform("say", "（此番县中小考在即，大家都卯足了劲）");
		PlayerPerform("pause", 2);
		PlayerPerform("say", "（但这一次却不一样）");
		PlayerPerform("pause", 2);
		PlayerPerform("say", "（这些年我们之间虽时常切磋）");
		PlayerPerform("pause", 2);
		PlayerPerform("say", "（师父要我逐一击败三个兄弟）");
		PlayerPerform("pause", 1);
		PlayerPerform("block", 1);
		q=2;
		qth=1;
		qzx=1;
		qwg=1;
		qzr1=1;
		qzr2=1;
		qzr3=1;
		t=now+10;
		tzr1=now+30;
		tzr2=now+40;
		tzr3=now+50;
	}
	
	if (q==2&&now>t)
	{
		PlayerPerform("use",5);
		PlayerPerform("use",4);
		q=99;
	}	
	if(q==3&&c2<0&&c3<0&&c4<0&&now>t1)
	{
		AddNPC("1-1");
		q=4;
		t=now+1;
	}
	if(q==4&&c>=0&&now>t)
	{
		Perform(c, "say", "很好，鹏举，你过来。");
		
		PlayerPerform("say", "提示：【回到出生点】");
		PlayerPerform("say", "提示：【回到出生点】");
		PlayerPerform("pause", 3);
		PlayerPerform("block", 0);
		PlayerPerform("say", "是！师父。");
		PlayerPerform("pause", 3);
		PlayerPerform("block", 1);
		q=5;
	}
	if(q==5)
	{
		SetTarget(0, "waypoint", 69);
		SetTarget(1, "char", player);
		if (Distance(0, 1) <=500)
		{
			PlayerPerform("block", 0);
			PlayerPerform("say", "是！徒儿斗胆，冒犯师父了！");
			PlayerPerform("pause", 24);
			PlayerPerform("say", "师父！");
			PlayerPerform("block", 1);
			
			Perform(c, "say", "为师便赠你一件神兵。。");
			Perform(c,"pause",3);
			Perform(c, "say", "今日为师予你最后考较，你若能赢我手中羽扇，");
			Perform(c,"pause",3);
			Perform(c, "say", "此后上阵破敌建功立业，指日可待。");
			Perform(c,"pause",3);
			Perform(c, "say", "须知枪乃百兵之王，敌未有能至一丈内者。");
			Perform(c,"pause",3);
			Perform(c, "say", "为师所传枪法，你已悉得要领，且能融会贯通随心而变。");
			Perform(c,"pause", 3);
			Perform(c, "say", "鹏举，十余年来，你的苦功没有白费。");
			Perform(c,"pause", 3);
			Perform(c, "faceto", player);
			q=6;
			t=now+20;
		}
	}
	if(q==6&&now>t)
	{
		PlayerPerform("use",15);
		PlayerPerform("use",3);
		PlayerPerform("use",4);
		PlayerPerform("use",5);
		PlayerPerform("use",8);
		q=7;
	}
	if(q==7&& GetHP(c)<=1500 && GetHP(c)>0)
	{
		PlayerPerform("block", 1);
		
		Perform(c,"guard",10);
		Perform(c, "say", "不错不错！孺子可教！你随我来。");
		Perform(c, "faceto", player);
		q=8;
		t=now+3;
	}
	if(q==8&&now>t)
	{
		v=2;
	}
	if(qzr1==1&&now>tzr1)
	{
		Perform(c2, "say", "小弟在这里！");
		Perform(c2, "pause", 3);
		Perform(c2, "say", "岳大哥,你莫非迷路了？");
		qzr1=1;
		tzr1=now+30;
	}
	if(qzr2==1&&now>tzr2)
	{
		Perform(c3, "say", "莫非是怕输与我么？");
		Perform(c3, "pause", 3);
		Perform(c3, "say", "岳大哥,怎么还不来？");
		qzr2=1;
		tzr2=now+30;
	}
	if(qzr3==1&&now>tzr3)
	{
		Perform(c4, "say", "俺的板斧已经等不及了！");
		Perform(c4, "pause", 3);
		Perform(c4, "say", "岳大哥,快来会会俺。");
		qzr3=1;
		tzr3=now+30;
	}
	
	if(qth==1)
	{
		SetTarget(0, "waypoint", 40);
		SetTarget(1, "char", player);
		if (Distance(0, 1) <=300)
		{
			PlayerPerform("block", 0);
			PlayerPerform("say", "汤兄，请赐教。");
			PlayerPerform("pause", 3);
			PlayerPerform("block", 1);
			
			Perform(c2,"guard",4);
			Perform(c2, "say", "岳大哥，得罪了!");
			Perform(c2, "faceto", player);
			qth=2;	
			qzr1=9;
			t1=now+3;
		}	
	}	
	if(qth==2&&now>t1)
	{
		ChangeBehavior(c2, "follow", player);
		qth=3;
	}
	
	if(qth==3&& GetHP(c2)<=1500 && GetHP(c2)>0)
	{
		PlayerPerform("block", 0);
		PlayerPerform("say", "汤兄，承让了。");
		PlayerPerform("pause", 2);
		PlayerPerform("block", 1);
		
		Perform(c2,"guard",10);
		Perform(c2, "say", "岳大哥果然厉害!");
		Perform(c2, "faceto", player);
		qth=4;
		t1=now+3;
	}
	if(qth==4&&now>t1)
	{
		RemoveNPC(c2);
		t1=now+1;
		qth = 9;
		q=3;
	}
	
	if(qzx==1)
	{
		SetTarget(0, "waypoint", 22);
		SetTarget(1, "char", player);
		if (Distance(0, 1) <=300)
		{
			PlayerPerform("block", 0);
			PlayerPerform("say", "张兄，我不会手软的。");
			PlayerPerform("pause", 3);
			PlayerPerform("block", 1);
			
			Perform(c3,"guard",4);
			Perform(c3, "say", "岳大哥，请赐招吧!");
			Perform(c3, "faceto", player);
			qzx=2;
			qzr2=9;
			t1=now+3;
		}	
	}
	if(qzx==2&&now>t1)
	{
		ChangeBehavior(c3, "follow", player);
		qzx=3;
	}
	if(qzx==3&& GetHP(c3)<=1500 && GetHP(c3)>0)
	{
        PlayerPerform("block", 0);
		PlayerPerform("say", "张兄，承让了。");
		PlayerPerform("pause", 3);
		PlayerPerform("block", 1);
		
		Perform(c3,"guard",10);
		Perform(c3, "say", "看来我始终输你一招。");
		Perform(c3, "faceto", player);
		qzx=4;
		t1=now+3;
	}
    if(qzx==4&&now>t1)
	{
		RemoveNPC(c3);
		t1=now+1;
		qzx = 9;
		q=3;
	}
	
	if(qwg==1)
	{
		SetTarget(0, "waypoint", 66);
		SetTarget(1, "char", player);
		if (Distance(0, 1) <=300)
		{
			PlayerPerform("block", 0);
			PlayerPerform("say", "王兄，请赐教。");
			PlayerPerform("pause", 3);
			PlayerPerform("block", 1);
			
			Perform(c4,"guard",4);
			Perform(c4, "say", "岳兄弟，来试试俺的开山斧吧！");
			Perform(c4, "faceto", player);
			qwg=2;
			qzr3=9;
			t1=now+3;
		}	
	}
	if(qwg==2&&now>t1)
	{
		ChangeBehavior(c4, "follow", player);
		qwg=3;
	}
	if(qwg==3&& GetHP(c4)<=1500 && GetHP(c4)>0)
	{
		PlayerPerform("block", 0);
		PlayerPerform("say", "王兄过谦了。");
		PlayerPerform("pause", 2);
		PlayerPerform("block", 1);
		
		Perform(c4,"guard",10);
		Perform(c4, "say", "哈哈哈，俺始终不是你的对手。");
		Perform(c4, "faceto", player);
		qwg=4;
		t1=now+4;
	}
	
	if(qwg==4&&now>t1)
	{
		RemoveNPC(c4);
		t1=now+1;
		qwg = 9;
		q=3;
	}

	if(v==0&&GetHP(player)==0)
	{
		PlayerPerform("say", "师父……徒儿学艺不精……甘领责罚！");
		v=1;
		t5=now+4;
	}
    if(v==2&&now>=t5)
	{
		gameover = 1;
		
	}
	if(v==1&&now>=t5)
	{
		gameover = -1;
		
	}
	if ((gameover==1 || gameover==-1))
	{
		GameOver(gameover);
		gameover = 2;
	}
}


