// 第二章
int Rule = 1;
int RoundTime = 30;
int PlayerSpawn = 0;
int PlayerSpawnDir = -135;
int PlayerWeapon = 7;
int PlayerWeapon2 = 6;
int PlayerHP = 3000;

int q=0;
int q1=0;
int t=0;
int t5=0;
int v= 0;

OnStart()
{
	AddNPC("2-2");
	AddNPC("2-3");
	AddNPC("2-4");
	AddNPC("2-5");
	AddNPC("2-6");
}

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;
	int c7;
	int c8;
	int c9;
	int c10;
	int c11;
	int now=GetGameTime();
	int gameover = 0;
	
	if (q==0&&c>=0&&c2>=0&&c3>=0&&c4>=0&&c5>=0)
	{
		Perform(c5,"guard",3);
		Perform(c4,"guard",3);
		Perform(c3,"guard",3);
		Perform(c2,"guard",3);
		Perform(c2,"say", "臭小子！找死！");
		Perform(c2,"pause", 4);
		Perform(c,"say", "多谢公子！");
		Perform(c,"pause", 2);
		PlayerPerform("say", "姑娘别怕，我来助你！");
		Perform(c5, "faceto", player);
		Perform(c4, "faceto", player);
		Perform(c3, "faceto", player);
		Perform(c2, "faceto", player);
		q=1;		
	}
	if(q==1&&c>=0&&GetHP(c2)<=0&&GetHP(c3)<=0&&GetHP(c4)<=0&&GetHP(c5)<=0)
	{
		ChangeBehavior(c, "idle");
		q=2;
		t=now+1;
	}
	if(q==2&&now>t)
	{
		PlayerPerform("block", 0);
		PlayerPerform("say", "既如此，李姑娘若不嫌弃，岳某愿随同前去查看，以免神器遭贼人玷污。");
		PlayerPerform("pause", 4);
		PlayerPerform("say", "原来沥泉神矛乃是有主之物，君子不夺人所好，是岳某冒昧了，");
		PlayerPerform("pause", 18);
		PlayerPerform("say", "姑娘也知此事？");
		PlayerPerform("pause", 8);
		PlayerPerform("say", "对了李姑娘，你可知此山中藏有某件神兵？");
		PlayerPerform("pause", 2);
		PlayerPerform("say", "李姑娘，岳某有礼了。");
		PlayerPerform("pause", 10);
		PlayerPerform("say", "在下姓岳，单名一个飞字。");
		PlayerPerform("pause", 12);
		PlayerPerform("say", "在下必将他们绳之以法，姑娘便先行下山去罢。");
		PlayerPerform("pause", 2);
		PlayerPerform("say", "不如由在下代为查探，若这伙强人当真意欲为祸乡里，");
		PlayerPerform("pause", 2);
		PlayerPerform("say", "山中多豺豹，又不知这伙强人底细，颇不太平，");
		PlayerPerform("pause", 7);
		PlayerPerform("say", "原来如此。敢问令尊是？");
		PlayerPerform("pause", 10);
		PlayerPerform("say", "姑娘无须多礼，你怎会独自来此深山？");
		PlayerPerform("pause", 4);
		PlayerPerform("block", 1);
		
		Perform(c,"say", "公子请随我来。");
		Perform(c,"pause", 2);
		Perform(c,"say", "太好了！岳公子侠肝义胆，知言再次谢过！");
		Perform(c,"pause", 12);
		Perform(c,"say", "本想亲自上山查看，无奈另有要事缠身，故此我才替爹爹前来。");
		Perform(c,"pause", 4);
		Perform(c,"say", "沥泉神矛历来由我家看护，这伙强人突然霸占神泣林，爹爹担忧他们是冲神矛而来，");
		Perform(c,"pause", 4);
		Perform(c,"say", "实不相瞒，知言此番上山，主要便是为保神矛安全而来，");
		Perform(c,"pause", 8);
		Perform(c,"say", "啊！你也是来找沥泉神矛……");
		Perform(c,"pause", 12);
		Perform(c,"say", "小女子姓李，名……名叫……李知言……（好一个英武的儿郎……)");
		Perform(c,"pause", 10);
		Perform(c,"say", "对了，还未请教公子尊姓大名。");
		Perform(c,"pause", 2);
		Perform(c,"say", "小女子谢过公子好意，不过……此事我不能置身事外……");
		Perform(c,"pause", 14);
		Perform(c,"say", "家父……只是一乡绅，唯恐这伙强人危及乡邻，因而担忧。");
		Perform(c,"pause", 6);
		Perform(c,"say", "小女子想替爹爹分忧，故此独身前来一探究竟。");
		Perform(c,"pause", 4);
		Perform(c,"say", "只因近日沥泉山来了一伙强人，令爹爹很是不快，");
		Perform(c,"pause", 6);
		Perform(c,"say", "多谢公子援手！");
		Perform(c, "faceto", player);
		q=3;
		q1=1;
		t=now+65;
		
	}
	if(q1==1&&c>=0&&GetHP(c2)<=0&&GetHP(c3)<=0&&GetHP(c4)<=0&&GetHP(c5)<=0&&now>t)
	{	
	    RemoveNPC(c2);
	    RemoveNPC(c3);
		RemoveNPC(c4);
		RemoveNPC(c5);
		q1=9;
	}
	if(q==3&&now>t)
	{
		ChangeBehavior(c,"patrol",82);
		q=4;
	}
	if(q==4)
	{
		SetTarget(0, "char", c);
		SetTarget(1, "waypoint", 82);
		if (c>=0&&Distance(0, 1) <=20)
		{
			Perform(c,"say", "不好！密室石门被破坏了！");
			q=6;
			t=now+1;
		}
	}
	if(q==6&&now>t)
	{
		ChangeBehavior(c,"patrol",91);
		q=7;
	}
	if(q==7)
	{
		SetTarget(0, "char", c);
		SetTarget(1, "waypoint", 91);
		if (c>=0&&Distance(0, 1) <=20)
		{
			ChangeBehavior(c, "idle");
			q=9;
		}
	}
	if(q==9)
	{
		Perform(c,"say", "神矛！沥泉神矛不见了！！");
		q=10;
	}
    if(q==10)
	{
		SetTarget(0, "waypoint", 91);
		SetTarget(1, "char", player);
		if (Distance(0, 1) <=50)
		{
			
		    PlayerPerform("say", "（又或是他们误打误撞发现了密室，因而带走了神矛？）");
		    PlayerPerform("pause", 3);
		    PlayerPerform("say", "（师父说这伙强人并非冲着沥泉神矛而来，莫非还另有歹徒？）");
		    PlayerPerform("pause", 3);
			PlayerPerform("say", "李姑娘莫急，先找找贼人可曾留下蛛丝马迹。");
			PlayerPerform("block", 1);
			q=11;
			t=now+6;
		}
	}
	if(q==11&&now>t)
	{
		AddNPC("2-1");
	    AddNPC("2-7");
	    AddNPC("2-8");
	    AddNPC("2-9");
	    AddNPC("2-10");
		q=12;
	}
	if(q==12)
	{
		c6 = GetAnyChar("萧别恨");
	    c7 = GetAnyChar("山贼·戊");
	    c8 = GetAnyChar("山贼·己");
	    c9 = GetAnyChar("山贼·庚");
	    c10 = GetAnyChar("山贼·辛");
		if(c6>=0&&c7>=0&&c8>=0&&c9>=0&&c10>=0)
		{
			Perform(c,"say", "适才你我都负了伤，我带有伤药，暂且治疗一下。");
		    Perform(c,"pause", 3);
	    	Perform(c,"say", "岳公子稍等，我和你同去。");
		    Perform(c,"pause", 9);
			
			PlayerPerform("block", 0);
			PlayerPerform("pause", 6);
			PlayerPerform("say", "果然还有强人，李姑娘，你在此稍候，待岳某出去交涉。");
			PlayerPerform("pause", 6);
			PlayerPerform("block", 1);
			
			Perform(c6,"say", "两个小贼，快快出来受死！");
			Perform(c6,"pause", 3);
			
			Perform(c7,"say", "大哥,我亲眼看见那两人跑了过来！");
			
			q=13;
			t=now+12;
		}
	}
	if(q==13&&now>t)
	{
		Perform(c,"use",15);
		PlayerPerform("use",15);
	    q=14;
	}
	if(q==14)
	{
		ChangeBehavior(c,"patrol",83);
		q=15;
	}
	if(q==15)
	{
		SetTarget(0, "waypoint", 83);
		SetTarget(1, "char", c);
		if (Distance(0, 1) <=50)
		{
			ChangeBehavior(c, "idle");
			q=16;
		}
	}
    if(q==16)
	{
		SetTarget(0, "waypoint", 82);
		SetTarget(1, "char", player);
		if (Distance(0, 1) <=200)
		{
			Perform(c7,"guard",30);
     	    Perform(c8,"guard",30);
		    Perform(c9,"guard",30);
    	    Perform(c10,"guard",30);
			Perform(c10,"faceto", player);
			Perform(c7, "faceto", player);
			Perform(c8, "faceto", player);
			Perform(c9, "faceto", player);
			
		    Perform(c,"say", "别想抵赖！");
		    Perform(c,"pause", 6);
		    Perform(c,"say", "不交出沥泉神矛，别想离开！");
		    Perform(c,"pause", 9);
		    Perform(c,"say", "好贼子！交出沥泉神矛！");
		    Perform(c,"pause", 3);
		
		    Perform(c6,"say", "臭小子！胆敢伤我弟兄，老子剁了你！");
		    Perform(c6,"pause",3);
		    Perform(c6,"say", "岂有此理！什么沥泉神矛，老子从未听说！");
		    Perform(c6,"pause", 6);
		    Perform(c6,"say", "疯婆子，你胡言乱语些什么！");
			Perform(c6,"pause", 9);
		    Perform(c6,"say", "小子，你无故伤我兄弟，是何道理！");
			Perform(c6,"faceto", player);
		
		    PlayerPerform("block", 0);
		    PlayerPerform("pause", 12);
			PlayerPerform("say", "李姑娘，切莫冲动！");
		    PlayerPerform("pause", 6);
			PlayerPerform("block", 1);
			q=18;
			t=now+18;
		}
	}	
    if(q==18&&now>t)
	{
		ChangeBehavior(c6,"follow",player);
		ChangeBehavior(c,"follow",player);
		q=21;
	}	
	if(q==21&&GetHP(c7)<=0&&GetHP(c8)<=0&&GetHP(c9)<=0&&GetHP(c10)<=0)
	{
		Perform(c6,"guard",30);
		Perform(c6, "say", "竟能伤了老子！两个小贼，咱们走着瞧！");
		Perform(c6, "faceto", player);
		q=22;
		t=now+1;
	
	}
	if(q==22&&now>t)
	{
		RemoveNPC(c6);
		q=24;
	}
	if(q==24)
	{
        PlayerPerform("say", "【提示：检查石碑】");
        PlayerPerform("say", "【提示：检查石碑】");
        PlayerPerform("pause", 1);
	 	PlayerPerform("say", "咱们去石碑周围仔细查一查。");
		PlayerPerform("pause", 3);
		PlayerPerform("say", "是以在下揣测，盗走神矛的恐怕另有其人。");
		PlayerPerform("pause", 3);
		PlayerPerform("say", "并且对你提出神矛一事茫然不知，");
		PlayerPerform("pause", 3);
		PlayerPerform("say", "然而这些人从头至尾并没亮出神矛，");
		PlayerPerform("pause", 3);
		PlayerPerform("say", "他若有神矛在手，必然用以对付我们，");
		PlayerPerform("pause", 6);
		PlayerPerform("say", "李姑娘且慢！在下觉得，沥泉神矛并非此人所取。");
	    PlayerPerform("pause", 3);
		
		Perform(c,"pause", 15);
		Perform(c,"say", "何以见得？");
	    Perform(c,"pause", 6);
	    Perform(c,"say", "别想跑！");
		q=26;
		t=now+18;
	}
	if(q==26&&now>t)
	{
		SetTarget(0, "waypoint", 105);
		SetTarget(1, "char", player);
		if (Distance(0, 1) <=50)
		{
			AddNPC("2-11");
			q=27;
		}
	}
	
    if(q==27)
	{
		c11 = GetAnyChar("盗贼");
	    
		if(c11>=0)
		{
			ChangeBehavior(c, "idle");
			q=28;
		}
	}
    if(q==28)
	{
		if(c11>=0)
		{
		    Perform(c,"say", "是沥泉神矛！");
		    Perform(c,"pause", 3);
		
   		    Perform(c11,"guard",3);
		    Perform(c11, "say", "哇呀呀！不好！");
		    PlayerPerform("block", 1);
		    q=29;
			t=now+3;
		}
	}
    if(q==29&&now>t)
	{
		ChangeBehavior(c11, "patrol", 120);
		q=30;
		t=now+1;
	}
	if(q==30&&now>t)
	{
		PlayerPerform("block", 0);
		PlayerPerform("say", "李姑娘你待在此处，谨防埋伏，我去追！");
		PlayerPerform("pause", 2);
		Perform(c,"say", "岳公子，他手上拿的便是沥泉神矛！");
		PlayerPerform("block", 1);
		q=31;
	}		
    if(q==31)
	{
		SetTarget(0, "waypoint", 120);
		SetTarget(1, "char", player);
		if (c11>=0 && Distance(0, 1) <=200)
		{
			Perform(c11,"guard",5);
		    Perform(c11, "say", "英雄别动手！我……我交出便是……");
			Perform(c11,"pause", 2);
			Perform(c11, "faceto", player);
			
			PlayerPerform("say", "小贼！还不交出神矛，讨打么！");
			PlayerPerform("block", 1);
			q=32;
			t=now+4;
		}
	}
	if(q==32&&now>t)
	{
		v=2;
	}

		
	//结算
	if(v==0&&GetHP(player)==0)
	{
		PlayerPerform("say", "师父……徒儿学艺不精……给您丢脸了！");
		v=1;t5=now+6;
		
	}
	if(v==0&&GetHP(c)==0)
	{
		Say(c, "啊~!爹……救女儿……");
		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;
	}
}


