#include "../PScriptLib/AsHelper.as"
// 一线天
int Rule = 2;
int RoundTime = 15;
int PlayerSpawn = 125;
int PlayerSpawnDir = 140;
int PlayerWeapon = 14;
int PlayerWeapon2 = 0;
int PlayerHP = 800;

int trg0 = 0;
int trg1 = 0;
int trg2 = 0;
int trg3 = 0;
int trg4 = 0;
int trg5 = 0;
int trg6 = 0;
int trg7 = 0;
int trg8 = 0;
int trg9 = 0;
int trg10 = 0;
int trg11 = 0;
int trg12 = 0;
int timer0 = 0;
int timer1 = 0;
int timer2 = 0;
int timer3 = 0;
int timer4 = 0;
int timer5 = 0;
int gameover = 0;
int gameover1 = 0;
int gameover2 = 0;
int gameover3 = 0;
int gameover4 = 0;
int gameover5 = 0;
int now = 0;
int damn =0; 


void OnStart()
{
	string voiceFolder = "UserData/Voice/sn03/";
	AsSoundCacheFolder(voiceFolder);
	AsSetChatVoiceFolder(voiceFolder);
	
	AddNPC("npc03_01");
	AddNPC("npc03_02");
	AddNPC("npc03_03");
	AddNPC("npc03_04");
	AddNPC("npc03_05");
	AddNPC("npc03_06");
}

void OnUpdate()
{
    int player = GetChar("player");
	if (player < 0)
	{
		player = 1;
	}
	int c;
	int c2;
	int flag;
	int c3;
	int c4;
	int c5;
	int c6;
	int c7;
	int c8;
	int c9;
	int c10;
	int c11;
	int c12;
	int c13;
	
		if (trg9 == 0)
	{
	    PlayerPerform("say", "（我该如何火中取栗呢？或许可以借助落石机关！）");
		PlayerPerform("pause", 20);
	    PlayerPerform("say", "（这个地形......仍然适合埋伏......或许可以黄雀在后！但是不能坐视一方获得优势......)");
	    PlayerPerform("pause", 5);
	    PlayerPerform("say", "孙剑这下要糟了......");
	    PlayerPerform("pause", 5);
	    PlayerPerform("block", 0);
		PlayerPerform("say", "（但高老大叮嘱我此行务必要小心谨慎，或许......这局面包含了许多势力的博弈？）");
		PlayerPerform("pause", 5);
	    PlayerPerform("say", "（目前刺杀范璇的现在任务暂时取消，若能趁机获取图纸和灵药，便可为高老大和叶翔赢得加入孙府的机会......）");
	    PlayerPerform("pause", 5);
	    PlayerPerform("say", "（瞄准目标，拉动火绳，就算是我这样的高手也要失去性命......长生灵药更是有解百的毒功效。）");
	    PlayerPerform("pause", 3);
		PlayerPerform("say", "（车中之物，想必就是弗朗机人所进贡的火器图纸和灵药了——官府、金人、倭寇、岛民都在争夺的宝贝......）");
		PlayerPerform("crouch", 1);
		PlayerPerform("block", 1);
		trg9 = 1;
	}
		if (trg0 == 0)
	{
		c = GetChar("夜猫子");
		if (c >= 0)
		{				
			SetTarget(0, "waypoint", 119);		// near flag position
			SetTarget(1, "char", player);
			SetTarget(2, "waypoint", 78);
			if (Distance(0, 1) < 500)
			{
				ChangeBehavior(c, "follow", "flag");
				ChangeBehavior(c, "attacktarget", 0, 3);
				SetTarget(0, "waypoint", 78);	// stone position
				ChangeBehavior(c, "attacktarget", 0, 3);
				SetTeam(c, 2);
				trg0 = 1;	
			}
			if (Distance(1, 2) < 400)
			{
				ChangeBehavior(c, "Kill", "player");
				ChangeBehavior(c, "follow", "player");
				ChangeBehavior(c, "attacktarget", 1,1);
				SetTarget(0, "waypoint", 78);	// stone position
				ChangeBehavior(c, "attacktarget", 1,1);
				SetTeam(c, 0);
				AsPerform(c, "say", "嘻嘻嘻，被你发现了,这里可不是你该纵横捭阖的地方。");
				trg0 = 2;	
			}
		}	
	}
	if (trg10 == 1)
	{AddNPC("npc03_07");
	trg10 = 2;
	}
	if (trg10 == 2)
	{
		c = GetChar("无名");
		if (c >= 0)
		{				
			SetTarget(0, "waypoint", 119);		// near flag position
			SetTarget(1, "char", player);
			SetTarget(2, "waypoint", 83);
			if (Distance(0, 1) < 700)
			{
				ChangeBehavior(c, "follow", "flag");
				ChangeBehavior(c, "attacktarget", 0, 3);
				SetTarget(0, "waypoint", 83);	// stone position
				ChangeBehavior(c, "attacktarget", 0, 3);
				SetTeam(c, 2);
				AsPerform(c, "say", "这里.....不是我们该徘徊的地方。");
				trg10 = 4;
				
				
			}
			if (Distance(1, 2) < 300)
			{
			    
				ChangeBehavior(c, "Kill", "player");
				ChangeBehavior(c, "follow", "player");
				SetTarget(0, "waypoint", 78);	// stone position
				ChangeBehavior(c, "attacktarget", 1,1);
				SetTeam(c, 2);
				AsPerform(c, "say", "这里.....不是我们该徘徊的地方。");
			    trg10 = 4;
				trg5 = 1;
			}
		}	
	}

	

		if (trg1 == 0)
	{
		c = GetChar("孙剑");
		c2 =GetChar("夜猫子");
		if (c >= 0)
		{		
			if (GetChar("flag") == c)
			{
				AsPerform(c, "say", "所有人警戒，有埋伏！");
				Perform (c, "use", 13);
				Perform(c, "pause", 4);
				AsPerform(c, "say", "眼前的镖物中冒出一道青烟！");
 				Perform(c, "pause", 8);
				AsPerform(c, "say", "镖车偏偏翻倒在这个地方......这恐怕......");
				Perform (c2, "use", 7);
				trg1 = 1;
				timer0 = now + 9;
			}
		}
	}
	if (trg1 == 1 && now > timer0)
	{
    AddNPC("npc03_08");
	AddNPC("npc03_09");
	AddNPC("npc03_10");
	trg1 = 2;
	timer0 = now +1;
	}

	
	if (trg1 == 2 && now >= timer0)
	{
    c = GetChar("孙剑");
	c2 = GetChar("孙府护卫.甲");
	c3 = GetChar("孙府护卫.乙");
	c4 = GetChar("孙府护卫.丙");
	c5 = GetChar("player");
	c6 = GetChar("原冲");
	c7 = GetChar("罗江");
	c8 = GetChar("方刚");
	player = GetChar("player");
	if (c >= 0)
	{
	AsPerform(c8, "say", "真是一条毒计啊！");
	Perform(c8, "pause", 15);
	AsPerform(c7, "say", "谁又能想到解百毒的灵药竟然会被下毒！");
	Perform(c7, "pause", 8);
 	Perform(c, "guard", 8);
	SetTeam(c, 0);
	SetTeam(player,0);
	Perform(c2, "guard", 8);
	Perform(c3, "guard", 8);
	Perform(c4, "guard", 8);
	Perform(c5, "guard", 8);
	Perform(c6, "guard", 8);
	Perform(c7, "guard", 8);
	Perform(c8, "guard", 8);
	AsPerform(c6, "say", "哈哈哈哈，孙剑，中了五毒洒之后，你还能看清楚眼前的事物吗？");
	AsPerform(c6, "faceto", c);
	AsPerform(c7, "faceto", c);
	AsPerform(c8, "faceto", c);
	trg1 = 3;
	timer0 = now + 8;
	trg4 = 1;
	}
	}
		if (trg1 == 3 && now >= timer0)
	{
    c = GetChar("孙剑");
	c2 = GetChar("孙府护卫.甲");
	c3 = GetChar("孙府护卫.乙");
	c4 = GetChar("孙府护卫.丙");
	c5 = GetChar("player");
	c6 = GetChar("原冲");
	c7 = GetChar("罗江");
	c8 = GetChar("方刚");
	if (c >= 0)
	{
 	ChangeBehavior(c, "wait");
	ChangeBehavior(c2, "Kill",c6);	
	ChangeBehavior(c3, "Kill",c7);
	ChangeBehavior(c4, "Kill",c8);
	ChangeBehavior(c3, "Kill",c8);
	ChangeBehavior(c6, "Kill",c);
	ChangeBehavior(c7, "Kill",c);
	ChangeBehavior(c8, "Kill",c);
	AsPerform(c, "say", "可恶......兄弟们...离我远点！我不能误伤你们！");
	trg1 = 4;
	timer0 = now + 5;
	trg4 = 1;
	}
	}
	if (trg4 == 1)
	{
    c = GetChar("孙剑");
	c2 = GetChar("flag");
	c3 = GetChar("夜猫子");
	c4 = GetChar("孙府护卫.丙");
	c5 = GetChar("player");
	c6 = GetChar("原冲");
	c7 = GetChar("罗江");
	c8 = GetChar("方刚");
	if (c6<0 && c7<0 && c8<0 &&c>0)
		{
			AsPerform(c, "say", "哼！就这种货色也想杀老子！");
			PlayerPerform("say", "（不好，孙剑要撤离，必须出手击杀孙剑！）");
		gameover5 = -1;
		timer1 = now + 10; 		
		trg10 = 1;
		trg4 = 4;
			}

		if (c < 0 && c2 < 0 && timer0 < now)
	{
	ChangeBehavior(c4, "patrol", 120,20.120);
	ChangeBehavior(c6, "patrol", 120,20);
	ChangeBehavior(c7, "patrol", 120,20);
	ChangeBehavior(c8, "patrol", 120,20);
	AsPerform(c8, "say", "快去夺镖!");
		SetTeam(c, 1);
		SetTeam(c3, 2);
	Perform (c3, "use", 41);
	Perform (c3, "use", 7);
	AsPerform(c3, "say", "啊哈哈，这镖物我要定了！");
	SetTeam(c5, 1);
	trg4 = 2;timer0 = now + 1;
	}
	}
	if (trg4 == 2&&timer0 < now)
	{
    c = GetChar("孙剑");
	c2 = GetChar("flag");
	c3 = GetChar("夜猫子");
	c4 = GetChar("孙府护卫.丙");
	c5 = GetChar("player");
	c6 = GetChar("原冲");
	c7 = GetChar("罗江");
	c8 = GetChar("方刚");
	c9 = GetChar("孙府护卫.甲");
	if (c <= 0 && c2 >= 0)//孙剑死亡，并且有人捡到标物，包括孟星魂和其他人。
	{
	ChangeBehavior(c4, "follow", "flag");
	ChangeBehavior(c3, "follow", "flag");
	ChangeBehavior(c6, "follow", "flag");
	ChangeBehavior(c7, "follow", "flag");
	ChangeBehavior(c8, "follow", "flag");
	AsPerform(c8, "say", "竟然还有人！");
	PlayerPerform("say", "（带着标物打碎障碍恐怕来不及了，或许可以施展轻功过关......）");
	PlayerPerform("pause", 5);
	PlayerPerform("say", "（心中总有不祥的预感，趁现在没人注意到我，赶紧撤离！！！）");
	SetTeam(c5, 1);
	SetTeam(c3, 2);
	SetTeam(c4, 0);
	trg10 = 1;
	trg4 = 3;timer0 = now + 999;
	}
	}
	
	if (trg4 == 3)
	{
    c = GetChar("孙剑");
	c2 = GetChar("flag");
	c3 = GetChar("夜猫子");
	c4 = GetChar("孙府护卫.丙");
	c5 = GetChar("player");
	c6 = GetChar("原冲");
	c7 = GetChar("罗江");
	c8 = GetChar("方刚");
	c9 = GetChar("孙府护卫.甲");

	if (c<1&&1<c2&&c5>=1)
	{
	if (c8 == c2)
	{
		gameover1 = -1;
		timer1 = now + 7; 
		AsPerform(c8, "say", "哈哈哈哈，夺到镖物了！撤！");
		trg4 = 4;	
	}

	}
		if (c7>0&&1<c2&&c5==1)
	{
	if (c7 == c2)
	{
			gameover2 = -1;
		timer1 = now + 5; 
		Perform(c7, "say", "孙剑已死，撤！");
		trg4 = 4;
	}
	}
			if (c6>0&&1<c2&&c5==1)
	{
	if (c6 == c2)
	{
		gameover3 = -1;
		timer1 = now + 10; 
		AsPerform(c6, "say", "哇哈哈哈哈，人没了东西还在！");
		trg4 = 4;
	}

	}
	if (c3>0&&1<c2&&c5==1)
		if (c3 == c2)
	{
	AsPerform(c3, "say", "嘻嘻，最终赢家属于我！");
		gameover4 = -1;
		timer1 = now + 10; 
		trg4 = 4;
	}
	}
		now = GetGameTime();	
		if (gameover==0 && GetHP(player)==0)
	{
		gameover = -1;
		timer1 = now + 2; 
		
	}
			if (gameover1==-1&&now>timer1)
			{
	c8 = GetChar("方刚");
	if(c8>0)
	{		gameover = -1;
		timer1 = now + 2; 
		gameover1 = 1;
		}	
	}
				if (gameover2==-1&&now>timer1)
			{
	c8 = GetChar("原冲");
	if(c8>0)
	{		gameover = -1;
		timer1 = now + 2; 
		gameover2 = 1;
		}	
	}
				if (gameover5==-1&&now>timer1)
			{
	c = GetChar("孙剑");
	c3 = GetAnyChar("夜猫子");
	c2 = GetChar("flag");
	if(c>0)
	{	gameover = -1;
		timer1 = now + 2; 
		gameover5 = 1;
		}
		if (c < 0&&c2<0)
	{
	ChangeBehavior(c4, "patrol", 120,20.120);
	ChangeBehavior(c6, "patrol", 120,20);
	ChangeBehavior(c7, "patrol", 120,20);
	ChangeBehavior(c8, "patrol", 120,20);
	SetTeam(c, 1);
	SetTeam(c3, 2);
	Perform (c3, "use", 41);
	Perform (c3, "use", 7);
	AsPerform(c3, "say", "啊哈哈，这镖物我要定了！");
	SetTeam(c5, 1);
	trg4 = 3;timer0 = now + 1;
	gameover5 = 99;
	}		
	}
					if (gameover3==-1&&now>timer1)
			{
	c8 = GetChar("罗江");
	if(c8>0)
	{		gameover = -1;
		timer1 = now + 2;
gameover3 = 1;		
		}	
	}
						if (gameover4==-1&&now>timer1)
			{
	c8 = GetChar("夜猫子");
	if(c8>0)
	{		gameover = -1;
		timer1 = now + 2; 
		gameover4 = 1;
		}	
	}
	if ((gameover==1 || gameover==-1) && now>timer1)
	{
		GameOver(gameover);
		gameover = 2;
	}
	if (trg11==0&&now>timer5)
	{SetTarget(4, "waypoint", 137);
	SetTarget(1, "char", player);	
	c2 = GetChar("flag");
	c5 = GetChar("player");
	if (Distance(4, 1) <= 500&&c2 == c5)
	{
	AddNPC("npc03_11");
	AddNPC("npc03_12");
	AddNPC("npc03_13");
	PlayerPerform ("use",14);
	PlayerPerform ("use",13);
	timer5 = now + 1;
	trg11 = 1;
	trg0 = 99;
	trg1 = 99;
	trg2 = 99;
	trg3 = 99;
	trg4 = 99;
	trg5 = 99;
	trg6 = 99;
	trg7 = 99;
	trg8 = 99;
	trg9 = 99;
	trg10 = 99;
	trg12 = 99;
	}
	}
if (trg11==0 && now==150)
{   c = GetChar("孙剑");
    c10 = GetChar("无名");
	AddNPC("npc03_11");
	AddNPC("npc03_12");
	AddNPC("npc03_13");
	PlayerPerform ("use",14);
	PlayerPerform ("use",13);
	trg11 = 1;
	timer5 = now + 3;
	trg0 = 99;
	trg1 = 99;
	trg2 = 99;
	trg3 = 99;
	trg4 = 99;
	trg5 = 99;
	trg6 = 99;
	trg7 = 99;
	trg8 = 99;
	trg9 = 99;
	trg10 = 99;
	trg12 = 99;

}
if (trg11==1&& now>timer5)
    {
	c13 = GetChar("律香川");
	c8 = GetChar("冯浩");
	c12 = GetChar("高寄萍");
	c5 = GetChar("player");
	c10 = GetChar("无名");
	c = GetChar("孙剑");
if (c13>=0 && now>timer5)
        {	    
	    ChangeBehavior(c8, "follow","flag");
		
		AsPlayerPerform("say", "（这剧毒......若是能撤离并及时服用灵药运功祛毒，或许我还有一线生机！）");
		PlayerPerform("pause", 8); 
		AsPlayerPerform("say", "（这个人是谁？高老大为什么会和他在一起？）");
		PlayerPerform("pause", 8); 
	    AsPlayerPerform("say", "（我是暴露了吗......还是被出卖了......）");
		SetTeam(c5, 1);
		SetTeam(c, 1);
		
	    Perform(c13, "pause", 8);  		
		Perform(c13, "say", "至于你...（原本你还可以成为孙府的一枚棋子），只配被剁碎喂狗！");
		Perform(c13, "pause", 8);   	
		Perform(c13, "say", "我若是你们的话，我肯定溜的比兔子还快！");	
		Perform(c13, "pause", 8);
        Perform(c13, "say", "到现在还赖着不走？武艺很不错，只可惜思绪不太缜密。");
		Perform(c8, "faceto", c5);
		timer3 = now + 25;		
        trg11 = 2;
		
        }
    }
	if (trg11==2)
    {
	c13 = GetChar("律香川");
	c7 = GetChar("冯浩");
	c12 = GetChar("高寄萍");
	c5 = GetChar("player");
	if (c13>=0&&now > timer3)
	   {
	PlayerPerform ("use",11);
	PlayerPerform ("use",12);
	PlayerPerform ("use",13);
	PlayerPerform ("use",14);
	AsPlayerPerform("say", "（不好，剧毒要发作了！）");
	Perform(c12, "say", "对不起，星魂，在快活林和武林盟主的利益面前，我不得不牺牲你。");
	trg11 = 3; timer3= now +5;

		}
	}
	if (trg11==3 && now > timer3)
	{
	 gameover = -1;
	 }
	 
	 if (trg11>=2)
	 {
	c2 = GetChar("flag");
	c5 = GetChar("player");
	 SetTarget(5, "waypoint", 138);
	 SetTarget(6, "waypoint", 139);
	 SetTarget(7, "waypoint", 140);
	SetTarget(1, "char", player);	
	 	if (Distance(6, 1) <= 100&&c2 == c5)
	{
	gameover =1;
	trg11=10;
	 }
	 	 	if (Distance(7, 1) <= 100&&c2 == c5)
	{
	gameover =1;
	trg11=10;
	 }
	 	 	 	if (Distance(5, 1) <= 100&&c2 == c5)
	{
	gameover =1;
	trg11=10;
	 }
    }	
		if (trg8==1)
    {
	c3 = GetChar("孙府护卫.甲");
    c = GetChar("夜猫子");
	c6 = GetChar("原冲");
	c7 = GetChar("罗江");
	c8 = GetChar("方刚");
	c4 = GetChar("孙剑");
	if (c>=0 && GetHP(c3)<=0&&now>timer2&&c4>=0&&c6>=0&&c7>=0&&c8>=0)
	   {	   AsPerform(c6, "say", "干得漂亮！孙剑，这下你不用顾忌你兄弟了！");
	   AsPerform(c6, "pause", 4);	
      AsPerform(c, "say", "哈哈！这下被压成肉酱了吧！");
		trg8 = 2;
		}
	}
			if (damn==1)
    {
	c = GetAnyChar("孙剑");
	c2 = GetAnyChar("孙府护卫.甲");
    c3 = GetAnyChar("孙府护卫.丙");
	c4 = GetAnyChar("孙府护卫.乙");
	c5 = GetAnyChar("孙府护卫.丁");
	c6 = GetAnyChar("原冲");
	c7 = GetAnyChar("罗江");
	c8 = GetAnyChar("方刚");
	c9 = GetAnyChar("夜猫子");
	
				if (GetHP(c6)<=0&&now>timer4)
	   {
	  RemoveNPC(c6);
	  damn = 0;
		}
						if (GetHP(c7)<=0&&now>timer4)
	   {
	  RemoveNPC(c7);
	  damn = 0;
		}
		if (GetHP(c8)<=0&&now>timer4)
	   {
	  RemoveNPC(c8);
	  damn = 0;
		}
	}
	if(trg7==1)
	{PlayerPerform("say", "（局势有所偏转，我得留心，想办法坐收渔翁之利。）");
	trg7 = 2;
	}
	if(trg6==0)
	{c2 = GetAnyChar("夜猫子");
	if (c2>=0 && GetHP(c2)<2000 &&GetHP(c2)>1200 )
	{
     PlayerPerform("say", "（我不能与这个人缠斗太久。）");		
			trg6 = 1;
		}			
		}
}
// 处理角色死亡事件
void OnCharacterDeath(int charId, int reason){
    string reasonText = "未知";
    if (reason == 1){
	reasonText = "被其他角色击杀";
	damn = 1;
	timer4 = now + 5;
	trg7 = 1;
    }
    else if (reason == 2) {
    }
    else if (reason == 3) {
        reasonText = "其它";
		trg8 = 1;
		timer2 = now +5;
		damn = 1;
		timer4 = now + 5;
	}	
   
}



