// 第四章
int Rule = 1;
int RoundTime = 50;
int PlayerSpawn = 0;
int PlayerSpawnDir = 0;
int PlayerWeapon = 43;
int PlayerWeapon2 = 6;
int PlayerHP = 4000;

int q=0;
int q1=0;
int qtx=0;
int qxh1=0;
int qxh2=0;
int qxh3=0;
int qxh4=0;
int qxh5=0;
int qxh6=0;
int qxh7=0;
int qth=0;
int qzx=0;
int qwg=0;
int qng=0;
int qxbh=0;
int t=0;
int txh1=0;
int txh2=0;
int t5=0;
int ttx=0;
int tdy=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 c5 = GetAnyChar("牛 皋");
	int c6 = GetAnyChar("喽啰·甲");
	int c7 = GetAnyChar("喽啰·乙");
	int c8 = GetAnyChar("喽啰·丙");
	int c9 = GetAnyChar("喽啰·丁");
	int c10= GetAnyChar("喽啰·戊");
	int c11= GetAnyChar("喽啰·己");
	int c12= GetAnyChar("喽啰·庚");
	int c13= GetAnyChar("洪先");
    int c15= GetAnyChar("萧别恨");
    int c16= GetAnyChar("强盗·甲");
	int c17= GetAnyChar("强盗·乙");
	int c18= GetAnyChar("强盗·丙");
	int c19= GetAnyChar("叛军·甲");
	int c20= GetAnyChar("叛军·乙");
	int c21= GetAnyChar("叛军·丙");
	int	c22= GetAnyChar("洪先");
	int now=GetGameTime();
	int gameover = 0;
	
	if(q==0)
	{
		AddNPC("4-1");
		q=1;
	}
	if(q==1&&c>=0)
	{
		PlayerPerform("block", 0);
		PlayerPerform("say", "正是如此，出招吧！");
		PlayerPerform("pause", 10);
		PlayerPerform("say", "兄台，我若赢了你，又当如何？");
		PlayerPerform("pause", 3);
	    PlayerPerform("block", 1);
		PlayerPerform("say", "【注意！对话中请勿偷袭！】");
			
		Perform(c,"guard",3);
		Perform(c,"aggress");
		Perform(c,"say", "你若赢过我，爷爷任你宰割！");
		Perform(c,"pause", 5);
		Perform(c,"say", "吃爷爷一矛！");
		Perform(c,"pause", 2);
		Perform(c,"faceto", player);
		q=2;
		qtx=1;
		t=now+8;
	}
	if(q==2&&now>t)
	{
		qtx=9;
		if(c>=0 && GetHP(c)<=1000 && GetHP(c)>0)
		{
			PlayerPerform("block", 0);
			PlayerPerform("say", "兄台言重了，在下有几句话说与你听，这边请。");
			PlayerPerform("pause", 7);
			PlayerPerform("say", "如何？还要再斗么？");
			PlayerPerform("pause", 3);
			
			Perform(c,"guard",10);
			Perform(c,"say", "俺牛皋说话算数，既败与你，便由你处置！");
			Perform(c,"pause", 4);
			Perform(c,"say", "好武艺！");
			Perform(c, "faceto", player);
			PlayerPerform("block", 1);
			q=3;
			t=now+10;
		}
	}
	if(q==3&&now>t)
	{
	    PlayerPerform("use",15);
	    RemoveNPC(c);
		q=4;
		t=now+1;
	}
	if(q==4&&now>t)
	{
		AddNPC("4-2");
		AddNPC("4-3");
		AddNPC("4-4");
		AddNPC("4-5");
		q=5;
	}
	if(q==5&&c2>=0&&c3>=0&&c4>=0&&c5>=0)
	{
		Perform(c3, "faceto", c5);
		Perform(c4, "faceto", c5);
		Perform(c2, "faceto", c5);
	    q=6;
	}
	if(q==6)
	{
		SetTarget(0, "char", player);
		SetTarget(1, "waypoint", 4);
		if (Distance(0, 1) <=50)
		{
			Perform(c5,"say", "啊哟！原来你便是岳飞、岳鹏举么！");
			Perform(c5,"pause", 9);
			Perform(c5,"say", "今日遇着你等，俺比拼不过，要打要杀悉听尊便。");
			Perform(c5,"pause", 4);
			Perform(c5,"say", "思来想去，便占了这破庙打草为生。");
			Perform(c5,"pause", 4);
			Perform(c5,"say", "俺将那强盗头子打杀了，把剩下的喽啰驱散，一时无处可去，");
			Perform(c5,"pause", 4);
			Perform(c5,"say", "俺在路上耗尽了盘缠，正没个去处，偏生在此遇上一伙毛贼剪径，");
			Perform(c5,"pause", 4);
			Perform(c5,"say", "又闻得县中乡试小考，去了才知已然结束。");
			Perform(c5,"pause", 4);
			Perform(c5,"say", "俺堪堪赶到汤阴，却未曾寻得云尘道长踪迹.");
			Perform(c5,"pause", 4);
			Perform(c5,"say", "要我前往汤阴寻一位【云尘道长】，跟他习武，将来也好讨个出身。");
			Perform(c5,"pause", 4);
			Perform(c5,"say", "此事说来话长，俺叫【牛皋】，只因家母临终之时嘱咐道：");
			Perform(c5,"pause", 4);
			Perform(c5, "faceto", player);
			
			Perform(c3,"say", "你眼前这人不正是云尘道长的关门弟子！");
			Perform(c3,"pause", 3);
			Perform(c3,"say", "这却不是奇了？该着你这黑炭头触霉，");
			Perform(c3,"pause", 42);
			
			PlayerPerform("say", "在下正是岳飞。");
			PlayerPerform("pause", 51);
			PlayerPerform("say", "兄台气宇非凡又一身好武艺，何苦却做那剪径的勾当？");
			PlayerPerform("block", 1);
			q=7;
			t=now+36;
		}
	}
	if(q==7&&now>t)
	{
		PlayerPerform("say", "此后我兄弟五人共同进退便是。");
		PlayerPerform("pause", 4);
		PlayerPerform("say", "正是如此，这三位是汤怀、张显、王贵，俱是好男儿。");
		PlayerPerform("pause", 16);
		PlayerPerform("say", "兄台何须如此，快快请起！");
		PlayerPerform("pause", 1);
		PlayerPerform("block", 1);
		
		Perform(c3,"say", "岳大哥，外面有动静。");
		Perform(c3,"pause", 27);
		
		Perform(c2,"say", "牛兄弟，俗话说不打不相识，你又何须见外？");
		Perform(c2,"pause", 12);
		
		Perform(c4,"say", "你是黑炭头，俺王贵也黑，咱俩倒像是一对儿夜叉。");
		Perform(c4,"pause", 8);
		
		Perform(c5,"say", "岳大哥若不收留俺，俺就不起！");
		Perform(c5,"pause", 4);
		Perform(c5,"say", "岳大哥！可叫俺寻着了！");
		Perform(c5,"crouch", 5);
		q=8;
		t=now+20;
	}
	if(q==8&&now>t)
	{
		
		PlayerPerform("say", "像是强盗，人数不少，诸位兄弟各守一门，不可贸然远去！");
		q=9;
		t=now+3;
	}
	if(q==9&&now>t)
	{
		PlayerPerform("say", "【提示：和四位兄弟共同御敌。】");
		PlayerPerform("say", "【提示：和四位兄弟共同御敌。】");
		PlayerPerform("say", "【提示：和四位兄弟共同御敌。】");
		PlayerPerform("block", 0);
		PlayerPerform("pause", 1);
		PlayerPerform("block", 1);
		
		Perform(c2,"say", "是！");
		Perform(c4,"say", "是！");
		Perform(c3,"say", "是！");
		Perform(c5,"say", "是！");
		q=10;
		qxh1=1;
		qxh2=1;
		qxh3=1;
		qxh4=1;
		qxh5=1;
		qxh6=1;
		qxh7=1;
		t=now+1;
	}
	if(q==10&&now>t)
	{
		ChangeBehavior(c5, "wait");
		SetTarget(3, "waypoint", 12);
		ChangeBehavior(c5, "attacktarget", 3);
		
		ChangeBehavior(c4, "wait");
		SetTarget(2, "waypoint", 9);
		ChangeBehavior(c4, "attacktarget", 2);
		
		ChangeBehavior(c3, "wait");
		SetTarget(1, "waypoint", 1);
		ChangeBehavior(c3, "attacktarget", 1);
		
		ChangeBehavior(c2, "wait");
		SetTarget(0, "waypoint", 8);
		ChangeBehavior(c2, "attacktarget", 0);
		q=11;
		qth=1;
		qwg=1;
		qzx=1;
		qng=1;
		txh2=now+180;
	}
	if(q==11&&now>txh2)
	{
		Perform(c5,"say", "岳大哥，这些鸟贼源源不断，杀也杀不尽！");
		q=12;
	}
	if(q==12)
	{
		AddNPC("4-13");
		t=now+3;
		q=13;
		
	}
	if(q==13&&c13>=0&&now>t)
	{
		PlayerPerform("use",16);
		PlayerPerform("use",5);
		PlayerPerform("use",4);
		PlayerPerform("use",3);
		PlayerPerform("say", "【提示：找到洪先，先击败他。】");
		PlayerPerform("say", "【提示：找到洪先，先击败他。】");
		PlayerPerform("pause", 1);
		PlayerPerform("say", "诸位兄弟再支撑片刻，待我去寻那洪先！");
		PlayerPerform("pause", 3);
			
		Perform(c13,"say", "岳飞！我看你还能撑到几时！");
		q=14;
	}
	if(q==14)
	{
		SetTarget(0, "waypoint", 14);
		SetTarget(1, "char", player);
		if (Distance(0, 1) <=80)
		{
		    Perform(c13,"say", "岳飞！今日便是你的死期！");
		    Perform(c13,"pause", 3);
			
			PlayerPerform("block", 0);
			PlayerPerform("pause", 3);
			PlayerPerform("say", "洪先！果然是你！");
			PlayerPerform("block", 1);
			q=99;
			q1=1;
			t=now+3;
		}
	}
	if(q1==1&&now>t)
	{
		ChangeBehavior(c13,"follow", player);
		q1=9;
		q=15;
	}
	
	if(q==15&&GetHP(c13)<=2000 && GetHP(c13)>0)
	{
		Perform(c13,"use", 45);
		Perform(c13,"guard", 2);
		Perform(c13, "say", "萧兄！快来助我！");
		PlayerPerform("block", 1);
		q=16;
		qxh1=99;
		qxh2=99;
		qxh3=99;
		qxh4=99;
		qxh5=99;
		qxh6=99;
		qxh7=99;
		qth=9;
		qzx=9;
		qwg=9;
		qng=9;
		t=now+3;
	}
	if(q==16&&now>t)
	{
		ChangeBehavior(c13, "idle");
		SetTarget(0, "waypoint", 15);
		ChangeBehavior(c13, "attacktarget", 0);
		q=17;
		t=now+1;
	}
	if(q==17&&now>t)
	{
		RemoveNPC(c6);
		RemoveNPC(c7);
		RemoveNPC(c8);
		RemoveNPC(c9);
		RemoveNPC(c10);
		RemoveNPC(c11);
		RemoveNPC(c12);
		q=18;
		t=now+1;
	}
	if(q==18&&now>t)
	{
		Perform(c2,"use", 15);
		Perform(c3,"use", 15);
		Perform(c4,"use", 15);
		Perform(c5,"use", 15);
		q=19;
	}
	if(q==19)
	{
		AddNPC("4-15");
		AddNPC("4-16");
		AddNPC("4-17");
		AddNPC("4-18");
		AddNPC("4-19");
		AddNPC("4-20");
		AddNPC("4-21");
		q=20;
	}
	if(q==20&&c15>=0&&c16>=0&&c17>=0&&c18>=0&&c19>=0&&c20>=0&&c21>=0)
	{
		ChangeBehavior(c5, "idle");
		SetTarget(3, "waypoint", 26);
		ChangeBehavior(c5, "attacktarget", 3);
		
		ChangeBehavior(c4, "idle");
		SetTarget(2, "waypoint", 25);
		ChangeBehavior(c4, "attacktarget", 2);
		
		ChangeBehavior(c3, "idle");
		SetTarget(1, "waypoint", 24);
		ChangeBehavior(c3, "attacktarget", 1);
		
		ChangeBehavior(c2, "idle");
		SetTarget(0, "waypoint", 23);
		ChangeBehavior(c2, "attacktarget", 0);
		q=21;
	}
	if(q==21)
	{
		PlayerPerform("block", 0);
		PlayerPerform("pause", 2);
		PlayerPerform("block", 1);
		PlayerPerform("use",16);
		PlayerPerform("use",16);
		q=22;
	}
	if(q==22)
	{
		SetTarget(0, "waypoint", 15);
		SetTarget(1, "char", player);
		if (Distance(0, 1) <=150)
		{
			
			Perform(c13, "say", "萧兄，这小子枪法入神，你先顶一下，我去提那娘们儿过来。");
			
			Perform(c2, "faceto", c15);
		    Perform(c3, "faceto", c15);
		    Perform(c4, "faceto", c15);
		    Perform(c5, "faceto", c15);
			Perform(c13, "faceto", c15);
			Perform(c15, "faceto", c13);
			Perform(c16, "faceto", c4);
			Perform(c17, "faceto", c4);
			Perform(c18, "faceto", c4);
			Perform(c19, "faceto", c3);
			Perform(c20, "faceto", c3);
			Perform(c21, "faceto", c3);
			PlayerPerform("block", 1);
			q=23;
			t=now+2;
		}
	}
	if(q==23&&now>t)
	{
		RemoveNPC(c13);
		q=24;
		t=now+1;
	}
	if(q==24&&now>t)
	{
		Perform(c5,"say", "休说废话！敢在爷爷的地头撒野，吃俺一矛！");
		Perform(c5,"pause", 3);
		
		Perform(c15,"say", "给我杀！");
		Perform(c15,"pause", 6);
		Perform(c15,"say", "小子，那日在神泣林放过你，不想你却在校场中坏我计划，今日留不得你！");
		Perform(c15, "faceto", player);
		
		Perform(c2,"use", 15);
		Perform(c3,"use", 15);
		Perform(c4,"use", 15);
		Perform(c5,"use", 15);
		
		PlayerPerform("block", 0);
		PlayerPerform("pause", 5);
		PlayerPerform("block", 1);
		q=25;
		t=now+5;
	}
	if(q==25&&now>t)
	{
		ChangeBehavior(c15,"wait");
		ChangeBehavior(c16,"wait");
		ChangeBehavior(c17,"wait");
		ChangeBehavior(c18,"wait");
		ChangeBehavior(c19,"wait");
		ChangeBehavior(c20,"wait");
		ChangeBehavior(c21,"wait");
		ChangeBehavior(c2,"wait");
		ChangeBehavior(c3,"wait");
		ChangeBehavior(c4,"wait");
		ChangeBehavior(c5,"wait");
		q=26;
		qxbh=1;
	}
	if(q==26&&GetHP(c20)<=0&&GetHP(c21)<=0&&GetHP(c16)<=0&&GetHP(c17)<=0&&GetHP(c18)<=0&&GetHP(c19)<=0)
	{
		AddNPC("4-22");
		q=27;
		t=now+2;
	}
	if(q==27&&c22>=0)
	{
		Perform(c15,"guard", 30);
		Perform(c2,"guard", 30);
		Perform(c3,"guard", 30);
		Perform(c4,"guard", 30);
	    Perform(c5,"guard", 30);
		PlayerPerform("block", 1);
		Perform(c22,"say", "住手！姓岳的小子，你来看看这是谁！");
		q=28;
		t=now+4;
	}
	if(q==28&&now>t)
	{
		v=2;
	}
	if(qxbh==1&&GetHP(c15)<=1500)
	{
		Perform(c15,"use", 15);
		qxbh=1;
	}
	if(qth==1&&now>tdy)
	{
		SetTarget(0, "waypoint", 8);
		SetTarget(1, "char", c2);
		if (Distance(0, 1) >=250)
		{
			ChangeBehavior(c2, "wait");
		    SetTarget(0, "waypoint", 8);
		    ChangeBehavior(c2, "attacktarget", 0);
			qth=1;
			tdy=now+1;
		}
	}
	if(qzx==1&&now>tdy)
	{
		SetTarget(3, "waypoint", 1);
		SetTarget(2, "char", c3);
		if (Distance(2, 3) >=250)
		{
			ChangeBehavior(c3, "wait");
		    SetTarget(1, "waypoint", 1);
		    ChangeBehavior(c3, "attacktarget", 1);
			qzx=1;
			tdy=now+1;
		}
	}
	if(qwg==1&&now>tdy)
	{
		SetTarget(4, "waypoint", 9);
		SetTarget(5, "char", c4);
		if (Distance(4, 5) >=250)
		{
			ChangeBehavior(c4, "wait");
		    SetTarget(2, "waypoint", 9);
		    ChangeBehavior(c4, "attacktarget", 2);
			qwg=1;
			tdy=now+1;
		}
	}
	if(qng==1&&now>tdy)
	{
		SetTarget(6, "waypoint", 12);
		SetTarget(7, "char", c5);
		if (Distance(6, 7) >=300)
		{
			ChangeBehavior(c5, "wait");
		    SetTarget(3, "waypoint", 12);
		    ChangeBehavior(c5, "attacktarget", 3);
			qng=1;
			tdy=now+1;
		}
	}
	if(qxh1==1&&now>txh1)
	{
		AddNPC("4-6");
		qxh1=2;
	}
	if(qxh1==2&&c6>=0)
	{
		qxh1=3;
	}
	if(qxh1==3&&GetHP(c6)<=0)
	{
		txh1=now+1;
		qxh1=4;
	}
	if(qxh1==4&&now>txh1)
	{
		Perform(c2,"use", 16);
		RemoveNPC(c6);
		qxh1=1;
        txh1=now+1;		
	}
	if(qxh2==1&&now>txh1)
	{
		AddNPC("4-7");
		qxh2=2;
	}
	if(qxh2==2&&c7>=0)
	{
		qxh2=3;
	}
	if(qxh2==3&&GetHP(c7)<=0)
	{
		txh1=now+1;
		qxh2=4;
	}
	if(qxh2==4&&now>txh1)
	{
		Perform(c2,"use", 16);
		RemoveNPC(c7);
		qxh2=1;
        txh1=now+1;		
	}
	if(qxh3==1&&now>txh1)
	{
		AddNPC("4-8");
		qxh3=2;
	}
	if(qxh3==2&&c8>=0)
	{
		qxh3=3;
	}
	if(qxh3==3&&GetHP(c8)<=0)
	{
		txh1=now+1;
		qxh3=4;
	}
	if(qxh3==4&&now>txh1)
	{
		Perform(c3,"use", 16);
		RemoveNPC(c8);
		qxh3=1;
        txh1=now+1;		
	}
	if(qxh4==1&&now>txh1)
	{
		AddNPC("4-9");
		qxh4=2;
	}
	if(qxh4==2&&c9>=0)
	{
		qxh4=3;
	}
	if(qxh4==3&&GetHP(c9)<=0)
	{
		txh1=now+1;
		qxh4=4;
	}
	if(qxh4==4&&now>txh1)
	{
		Perform(c3,"use", 16);
		RemoveNPC(c9);
		qxh4=1;
        txh1=now+1;		
	}
	if(qxh5==1&&now>txh1)
	{
		AddNPC("4-10");
		qxh5=2;
	}
	if(qxh5==2&&c10>=0)
	{
		qxh5=3;
	}
	if(qxh5==3&&GetHP(c10)<=0)
	{
		txh1=now+1;
		qxh5=4;
	}
	if(qxh5==4&&now>txh1)
	{
		Perform(c4,"use", 16);
		RemoveNPC(c10);
		qxh5=1;
        txh1=now+1;		
	}
	if(qxh6==1&&now>txh1)
	{
		AddNPC("4-11");
		qxh6=2;
	}
	if(qxh6==2&&c11>=0)
	{
		qxh6=3;
	}
	if(qxh6==3&&GetHP(c11)<=0)
	{
		txh1=now+1;
		qxh6=4;
	}
	if(qxh6==4&&now>txh1)
	{
		Perform(c4,"use", 16);
		RemoveNPC(c11);
		qxh6=1;
        txh1=now+1;		
	}
	if(qxh7==1&&now>txh1)
	{
		AddNPC("4-12");
		qxh7=2;
	}
	if(qxh7==2&&c12>=0)
	{
		qxh7=3;
	}
	if(qxh7==3&&GetHP(c12)<=0)
	{
		txh1=now+1;
		qxh7=4;
	}
	if(qxh7==4&&now>txh1)
	{
		Perform(c5,"use", 16);
		RemoveNPC(c12);
		qxh7=1;
        txh1=now+1;		
	}
	
	
	if(qtx==1&&GetHP(c)<5000)
	{
	    Perform(c,"say", "无耻匹夫！竟然偷袭！");
		qtx=2;
		ttx=now+2;	
	}
	if(qtx==2&&now>ttx)
	{
		v=1;
	}
	if(v==0&&GetHP(player)==0)
	{
		PlayerPerform("say", "师父……徒儿学艺不精……给您丢脸了！");
		v=1;t5=now+6;
		
	}
	if(v==0&&GetHP(c5)==0)
	{
		Say(c5, "岳大哥……俺牛皋……先走一步了……");
		v=1;t5=now+4;	
	}
	if(v==0&&GetHP(c2)==0)
	{
		Say(c2, "岳大哥……来生还做兄弟……");
		v=1;t5=now+4;	
	}
	if(v==0&&GetHP(c3)==0)
	{
		Say(c3, "岳大哥……替我报仇……");
		v=1;t5=now+4;	
	}
	if(v==0&&GetHP(c4)==0)
	{
		Say(c4, "岳兄弟……俺王贵不行了……");
		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;
	}
}


