#include "../PScriptLib/AsHelper.as"
// 飞鹏堡
int Rule = 4;
int RoundTime = 12;
int PlayerSpawn = 30;
int PlayerSpawnDir = 80;
int PlayerWeapon = 14;
int PlayerWeapon2 = 1;
int PlayerHP = 2500;

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;
int damn1 =0;
int damn2 =0; 

void OnStart()
{
AddNPC("npc15_01");
AddNPC("npc15_02");
AddNPC("npc15_03");
AddNPC("npc15_08");
AddNPC("npc15_05");
AddNPC("npc15_04");
AddNPC("npc15_06");
AddNPC("npc15_07");
	string voiceFolder = "UserData/Voice/sn15/";
	AsSoundCacheFolder(voiceFolder);
	AsSetChatVoiceFolder(voiceFolder);
}


void OnUpdate()
{
	int player = GetChar("player");
	if (player < 0)
	{
		player = 0;
	}
	
	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;
	int now = GetGameTime();
	

		if (trg0 == 0)
	{
		c = GetChar("金枪侍卫﹒甲");
		c2 = GetChar("金枪侍卫﹒乙");
		c3 = GetChar("金枪侍卫﹒丙");
		c4 = GetChar("金枪侍卫﹒丁");
		c5 = GetChar("player");
        c6 = GetChar("范璇");
		if (c>=0 && c2>=0 && c3>=0 && c4>=0)
		{
			ChangeBehavior(c, "patrol", 0, 1, 2, 3, 4, 5);
			AsPerform(c, "say", "好呗～还是巡一下好了﹒﹒﹒");
			Perform(c, "pause", 18);
			AsPerform(c, "say", "不过，那姑娘的姿色很不错耶，要是能够﹒﹒嘻嘻嘻嘻﹒﹒");
			Perform(c, "pause", 10);
			AsPerform(c, "say", "我看我接下来的假期也没得休了﹒﹒");
			Perform(c, "pause", 8);
			AsPerform(c, "say", "听说孙玉伯要与我们飞鹏帮开战了！");
			Perform(c, "faceto", c2);
			
			ChangeBehavior(c2, "patrol", 0, 20, 24, 10, 11, 13, 17, 16);
			AsPerform(c2, "say", "嗯﹒﹒再聊～");
			Perform(c2, "pause", 8);
			AsPerform(c2, "say", "小心要是等会儿有人闯进来，假也别放了，被砍头还比较快！");
			Perform(c2, "pause", 4);
			AsPerform(c2, "say", "你是太久没放假去解放一下了是吧﹒﹒");
			Perform(c2, "pause", 14);
			AsPerform(c2, "say", "唉，自从那个女飞贼捉回来之後，我们就得不眠不休地守卫﹒");
			Perform(c2, "pause", 8);
			AsPerform(c2, "say", "嘿呀﹒﹒害我的假休到一半又被招回来");
			Perform(c2, "pause", 4);
			Perform(c2, "faceto", c);
			
			Perform(c3, "pause", 10);
			Perform(c3, "faceto", c);
			Perform(c4, "pause", 15);
			Perform(c4, "faceto", c2);
			
			PlayerPerform("block", 0);
			PlayerPerform("say", "（﹒﹒﹒算了﹒﹒﹒不该理会这种事﹒﹒﹒﹒）");
			PlayerPerform("pause", 2);
			PlayerPerform("say", "（那女子﹒﹒难道她被禁闭在这个座城中？﹒﹒﹒这﹒﹒）");
			PlayerPerform("pause", 15);
			PlayerPerform("say", "（女飞贼！﹒﹒﹒那个女子？﹒﹒）");
			PlayerPerform("pause", 15);
			PlayerPerform("block", 1);
			
			trg0 = 1;
			timer2 = now + 30;//合适的数值
		}
	}

		
	if (trg0 <= 3)
	{
		if (trg1 == 0)
		{
			c = GetChar("金枪侍卫﹒甲");
			if (c>=0 && GetEnemy(c)==player)
			{
				Perform(c, "guard", 3);
				AsPerform(c, "say", "你是谁！胆敢闯进来！拿命来！");
				Perform(c, "faceto", player);
				trg1 = 1;
			}
		}
		if (trg2 == 0)
		{
			c = GetChar("金枪侍卫﹒乙");
			if (c>=0 && GetEnemy(c)==player)
			{
				Perform(c, "guard", 3);
				AsPerform(c, "say", "好大的胆子，竟敢闯入！看我怎麽取你狗命！");
				Perform(c, "faceto", player);
				trg2 = 1;
			}
		}	
		if (trg3 == 0)
		{
			c = GetChar("金枪侍卫﹒丙");
			if (c>=0 && GetEnemy(c)==player)
			{
				c2 = GetChar("金枪侍卫﹒丁");
				if (c2 >= 0)
				{
					ChangeBehavior(c2, "follow", c);
				}
				
				Perform(c, "guard", 3);
				AsPerform(c, "say", "快来呀！！有人闯入了！！");
				Perform(c, "faceto", player);
				trg3 = 1;
				trg4 = 1;
			}
		}
		}
if (trg1 == 1)
{
gameover = -1;
PlayerPerform("say", "可恶，被发现了！");
timer0 = now+3;
trg1 =2;
trg2 =2;
trg3 =2;
}
if (trg2 == 1)
{
gameover = -1;
PlayerPerform("say", "可恶，被发现了！");
timer0 = now+3;
trg1 =2;
trg2 =2;
trg3 =2;
}
if (trg3 == 1)
{
gameover = -1;
PlayerPerform("say", "可恶，被发现了！");
timer0 = now+3;
trg1 =2;
trg2 =2;
trg3 =2;
}
if (trg4 == 0)
			{
c4 = GetChar("金枪侍卫﹒丁");
c = GetChar("player");
			if (c4>=0 && GetEnemy(c4)==player)
			{
ChangeBehavior(c4, "follow", c);
AsPerform(c4, "say", "你是谁？拿命来！");
trg4= 1;
			}
			}
	
	
if (trg5 == 0)
	{
		c = GetChar("左护法");
		if (c>=0 && GetEnemy(c)==player)
		{
			SetTarget(0, "char", c);
			SetTarget(1, "char", player);
			if (Distance(0, 1) < 200)
			{
				Perform(c, "aggress");
				AsPerform(c, "say", "哼！老子就先来陪你玩玩！");
				Perform(c, "pause", 4);
				Perform(c, "faceto", player);				
				trg5 = 1;
			}
		}
	}
	if (trg5 == 1)
	{
		c = GetChar("左护法");
		if (c>=0 && GetHP(c)<GetMaxHP(c)/2)
		{
			AsPerform(c, "say", "﹒﹒﹒你﹒﹒﹒你这小子真有两下子﹒﹒﹒");
			Perform(c, "faceto", player);				
			trg5 = 2;
		}	
	}
	if (trg5 == 2)
	{
		c = GetChar("左护法");
		if (c>=0 && GetHP(c)<GetMaxHP(c)/6)
		{
			ChangeBehavior(c, "follow", "vip");
			AsPerform(c, "say", "﹒﹒识时务者为俊杰﹒溜～");
			Perform(c, "faceto", player);				
			trg5 = 3;
		}				
	}
	if (trg5==3 || trg5==4)
	{
		c = GetAnyChar("左护法");
		if (c>=0 && GetHP(c)<=0)
		{
			Say(c, "老大﹒﹒﹒小的先离开了﹒﹒﹒");
			trg5 = 5;
		}
	}
				if (trg5>=1&&trg9==0&&trg0>=4)
	{
		c = GetAnyChar("左护法");
		c10 = GetAnyChar("无名");
		if (c>=0 && GetHP(c)<=0)
		{
			Say(c, "可恶......要不是你人多......");
			AsPerform(c10,"say", "嫩！");
			Perform(c10, "pause", 4);
			trg5 = 2;
			trg9= 1;
			timer3 = now +5;
		}
	}
	
		if (trg6 == 0)
	{
		c = GetChar("右护法");
		if (c>=0 && GetEnemy(c)==player)
		{
			SetTarget(0, "char", c);
			SetTarget(1, "char", player);
			if (Distance(0, 1) < 200)
			{
				Perform(c, "aggress");
				AsPerform(c, "say", "就让我来试试你的身手吧！");
				Perform(c, "pause", 4);
				AsPerform(c, "say", "唷！你这小子还真有本事能够闯进来咧！");
				Perform(c, "faceto", player);				
				trg6 = 1;
			}
		}
	}
	if (trg6 == 1)
	{
		c = GetChar("右护法");
		if (c>=0 && GetHP(c)<GetMaxHP(c)/2)
		{
			AsPerform(c, "say", "可﹒﹒恶﹒﹒﹒你这小子惹脑了我了！！");
			Perform(c, "faceto", player);				
			trg6 = 2;
		}	
	}
	if (trg6 == 2)
	{
		c = GetChar("右护法");
		if (c>=0 && GetHP(c)<GetMaxHP(c)/6.5)
		{
			ChangeBehavior(c, "follow", "vip");
			AsPerform(c, "say", "哼！老子就算斗不了你！我这就找人来治你！");
			Perform(c, "faceto", player);				
			trg6 = 3;
		}				
	}
		if (trg6==3 || trg6==4)
	{
		c = GetAnyChar("右护法");
		if (c>=0 && GetHP(c)<=0)
		{
			Say(c, "我﹒﹒我﹒﹒不行了﹒﹒﹒");
			trg6 = 5;
		}
	}
			if (trg5>=1&&trg8==0&&trg0>=4)
	{
		c = GetAnyChar("右护法");
		c10 = GetChar("无名");
		if (c>=0 && GetHP(c)<=0)
		{
			Say(c, "竟然......有帮手");
			AsPerform(c10,"say", "嫩！");
			Perform(c, "pause", 4);
			trg5 = 2;
			trg8= 1;
			timer3 = now +5;
		}
	}
	if(trg5>=1&&trg10==0)
	{
	c = GetChar("player");
c2 = GetChar("范璇");
c3 = GetChar("金枪侍卫﹒甲");
c4 = GetChar("金枪侍卫﹒乙");
c5 = GetChar("金枪侍卫﹒丙");
c6 = GetChar("金枪侍卫﹒丁");
c7 = GetChar("肖安");
c8 = GetChar("左护法");
c9 = GetChar("右护法");
c10 = GetChar("无名");
	if(!IsAlive(c8)&&!IsAlive(c9)&&now>timer3&&trg3==4)
	{
	RemoveNPC(c10);
	trg10=1;
	}
	if(!IsAlive(c8)&&!IsAlive(c9)&&now>timer3&&trg3==3&&!IsAlive(c3)&&!IsAlive(c4)&&!IsAlive(c5))
	{
	RemoveNPC(c10);
	trg10=1;
	}
	}
if (trg0==1&&now>timer2)
	{
c = GetChar("player");
c2 = GetChar("范璇");
c3 = GetChar("金枪侍卫﹒甲");
c4 = GetChar("金枪侍卫﹒乙");
c5 = GetChar("金枪侍卫﹒丙");
c6 = GetChar("金枪侍卫﹒丁");
c7 = GetChar("肖安");
c8 = GetChar("左护法");
c9 = GetChar("右护法");
c10 = GetChar("无名");
SetTarget(0, "char", c2);
SetTarget(1, "char", c8);
SetTarget(2, "char", c9);
SetTarget(3, "char", c);
if (Distance(0, 3) < 200)
{
Perform(c2, "say", "什么人？来人！！！");
PlayerPerform("say", "（不好，暴露了！）");
trg0 = 10;
timer0 = now +2;
}
if (c2>=0)
{
Perform(c7, "say", "是！");
Perform(c7, "pause", 8);
AsPerform(c2, "say", "不过......最大的敌人就在自己身边！肖安，你去拷问那个女飞贼！为什么要来偷我的传国玉玺！！");
Perform(c2, "pause", 7);
AsPerform(c2, "say", "孙玉伯！！！！胆敢与我飞鹏帮开战！我要将你碎尸万段！");
trg0 =2;
timer2 = now+5;

}

	}
	
				if (trg0==2&&now>timer2)
	{
c = GetChar("player");
c2 = GetChar("范璇");
c3 = GetChar("金枪侍卫﹒甲");
c4 = GetChar("金枪侍卫﹒乙");
c5 = GetChar("金枪侍卫﹒丙");
c6 = GetChar("金枪侍卫﹒丁");
c7 = GetChar("肖安");
c8 = GetChar("左护法");
c9 = GetChar("右护法");
c10 = GetChar("无名");
if (c2>=0)
{
RemoveNPC(c7);
trg0 =3;
timer2 =now+5;	
}

	}
if (trg0==3&&now>timer2)
	{
c = GetChar("player");
c2 = GetChar("范璇");
c3 = GetChar("金枪侍卫﹒甲");
c4 = GetChar("金枪侍卫﹒乙");
c5 = GetChar("金枪侍卫﹒丙");
c6 = GetChar("金枪侍卫﹒丁");
c7 = GetChar("肖安");
c8 = GetChar("左护法");
c9 = GetChar("右护法");
c10 = GetChar("无名");
if (GetHP(c)<GetMaxHP(c)/1.5 &&IsAlive(c8)&&IsAlive(c9))
{
AddNPC("npc15_09");
trg5 =1;
trg0 =4;
timer2 =now+5;	
}
}
if (trg0==4&&now>timer2)
	{
c = GetChar("player");
c2 = GetChar("范璇");
c3 = GetChar("金枪侍卫﹒甲");
c4 = GetChar("金枪侍卫﹒乙");
c5 = GetChar("金枪侍卫﹒丙");
c6 = GetChar("金枪侍卫﹒丁");
c7 = GetChar("肖安");
c8 = GetChar("左护法");
c9 = GetChar("右护法");
c10 = GetChar("无名");
if (c10>=0)
{
AsPerform(c8, "say", "哪来的东西！");
ChangeBehavior(c10, "follow", "vip");
trg0 =5;
timer2 =now+5;	
}
}
if (trg7==0&&now>timer2)
	{
c = GetChar("player");
c2 = GetChar("范璇");
c3 = GetChar("金枪侍卫﹒甲");
c4 = GetChar("金枪侍卫﹒乙");
c5 = GetChar("金枪侍卫﹒丙");
c6 = GetChar("金枪侍卫﹒丁");
c7 = GetChar("肖安");
c8 = GetChar("左护法");
c9 = GetChar("右护法");
c10 = GetChar("无名");
SetTarget(0, "char", c2);
SetTarget(1, "char", c8);
SetTarget(2, "char", c9);
SetTarget(3, "char", c);
		if (Distance(0, 1) < 50)
		{
			ChangeBehavior(c3, "follow", c2);
			ChangeBehavior(c4, "follow", c2);
			ChangeBehavior(c5, "follow", c2);
			ChangeBehavior(c6, "follow", c2);
			ChangeBehavior(c8, "follow", c2);
			ChangeBehavior(c9, "follow", c2);
			
			Perform(c8, "say", "是！！");
			Perform(c8, "pause", 8);
			AsPerform(c8, "say", "禀报老大！有外人侵入！");
			Perform(c8, "faceto", c2);

			ChangeBehavior(c2, "follow", player);			
			AsPerform(c2, "say", "哼，还胆敢行刺我，所有人跟我走！！");
			Perform(c2, "pause", 5);					
			Perform(c2, "faceto", c);
CharSetBaseAttrib(2, CharAttrib_Defense, 55);
CharSetBaseAttrib(2, CharAttrib_Attack, 45);
CharSetBaseAttrib(3, CharAttrib_Defense, 85);
CharSetBaseAttrib(3, CharAttrib_Attack, 45);
CharSetBaseAttrib(4, CharAttrib_Defense, 85);
CharSetBaseAttrib(4, CharAttrib_Attack, 45);
CharSetBaseAttrib(5, CharAttrib_Defense, 100);
CharSetBaseAttrib(6, CharAttrib_Defense, 30);
CharSetBaseAttrib(6, CharAttrib_Attack, 25);
CharSetBaseAttrib(7, CharAttrib_Defense, 30);
CharSetBaseAttrib(7, CharAttrib_Attack, 25);
CharSetBaseAttrib(8, CharAttrib_Defense, 30);
CharSetBaseAttrib(8, CharAttrib_Attack, 25);
CharSetBaseAttrib(9, CharAttrib_Defense, 60);
CharSetBaseAttrib(9, CharAttrib_Attack, 25);			
trg7=1;			
trg1= 3;
trg2= 3;
trg3= 3;
}
		if (Distance(0, 3) < 100&&IsAlive(c8)&&IsAlive(c9))
		{
			ChangeBehavior(c3, "follow", c2);
			ChangeBehavior(c4, "follow", c2);
			ChangeBehavior(c5, "follow", c2);
			ChangeBehavior(c6, "follow", c2);
			ChangeBehavior(c8, "follow", c2);
			ChangeBehavior(c9, "follow", c2);		
			ChangeBehavior(c2, "follow", player);
CharSetBaseAttrib(2, CharAttrib_Defense, 55);
CharSetBaseAttrib(2, CharAttrib_Attack, 45);
CharSetBaseAttrib(3, CharAttrib_Defense, 85);
CharSetBaseAttrib(3, CharAttrib_Attack, 45);
CharSetBaseAttrib(4, CharAttrib_Defense, 85);
CharSetBaseAttrib(4, CharAttrib_Attack, 45);
CharSetBaseAttrib(5, CharAttrib_Defense, 100);
CharSetBaseAttrib(6, CharAttrib_Defense, 30);
CharSetBaseAttrib(6, CharAttrib_Attack, 25);
CharSetBaseAttrib(7, CharAttrib_Defense, 30);
CharSetBaseAttrib(7, CharAttrib_Attack, 25);
CharSetBaseAttrib(8, CharAttrib_Defense, 30);
CharSetBaseAttrib(8, CharAttrib_Attack, 25);
CharSetBaseAttrib(9, CharAttrib_Defense, 60);
CharSetBaseAttrib(9, CharAttrib_Attack, 25);			
			Perform(c2, "say", "左右护法！");
			Perform(c2, "pause", 5);		
			AsPerform(c2, "say", "哼，还胆敢行刺我，所有人跟我走！！");
			Perform(c2, "pause", 5);					
			Perform(c2, "faceto", c);	
trg7=1;			
trg1= 3;
trg2= 3;
trg3= 3;
}
		if (Distance(0, 3) < 100&&!IsAlive(c8)&&!IsAlive(c9))
		{	
			ChangeBehavior(c2, "follow", player);	
			Perform(c2, "say", "左右护法......人呢？");
			Perform(c2, "pause", 3);		
			AsPerform(c2, "say", "哼，还胆敢行刺我，所有人跟我走！！");
			Perform(c2, "pause", 1);					
			Perform(c2, "faceto", c);	
trg7=1;			
trg1= 3;
trg2= 3;
trg3= 4;
}
}
			
	if (trg7==0&&now>timer2)
	{
c = GetChar("player");
c2 = GetChar("范璇");
c3 = GetChar("金枪侍卫﹒甲");
c4 = GetChar("金枪侍卫﹒乙");
c5 = GetChar("金枪侍卫﹒丙");
c6 = GetChar("金枪侍卫﹒丁");
c7 = GetChar("肖安");
c8 = GetChar("左护法");
c9 = GetChar("右护法");
c10 = GetChar("无名");
SetTarget(0, "char", c2);
SetTarget(1, "char", c8);
SetTarget(2, "char", c9);
if (Distance(0, 2) < 100)
		{
			ChangeBehavior(c3, "follow", c2);
			ChangeBehavior(c4, "follow", c2);
			ChangeBehavior(c5, "follow", c2);
			ChangeBehavior(c6, "follow", c2);
			ChangeBehavior(c8, "follow", c2);
			ChangeBehavior(c9, "follow", c2);
CharSetBaseAttrib(2, CharAttrib_Defense, 55);
CharSetBaseAttrib(2, CharAttrib_Attack, 45);
CharSetBaseAttrib(3, CharAttrib_Defense, 85);
CharSetBaseAttrib(3, CharAttrib_Attack, 45);
CharSetBaseAttrib(4, CharAttrib_Defense, 85);
CharSetBaseAttrib(4, CharAttrib_Attack, 45);
CharSetBaseAttrib(5, CharAttrib_Defense, 100);
CharSetBaseAttrib(6, CharAttrib_Defense, 30);
CharSetBaseAttrib(6, CharAttrib_Attack, 25);
CharSetBaseAttrib(7, CharAttrib_Defense, 30);
CharSetBaseAttrib(7, CharAttrib_Attack, 25);
CharSetBaseAttrib(8, CharAttrib_Defense, 30);
CharSetBaseAttrib(8, CharAttrib_Attack, 25);
CharSetBaseAttrib(9, CharAttrib_Defense, 60);
CharSetBaseAttrib(9, CharAttrib_Attack, 25);
			Perform(c9, "say", "是！！");
			Perform(c9, "pause", 8);
			AsPerform(c9, "say", "禀报老大！有外人侵入！");
			Perform(c9, "faceto", c2);

			ChangeBehavior(c2, "follow", player);			
			AsPerform(c2, "say", "所有人跟我走！！");
			Perform(c2, "pause", 5);					
			Perform(c2, "faceto", c);
trg7=1;			
trg1= 3;
trg2= 3;
trg3= 3;
}
}		
	if (trg7 == 1)
	{
c = GetChar("player");
c2 = GetChar("范璇");
c3 = GetChar("金枪侍卫﹒甲");
c4 = GetChar("金枪侍卫﹒乙");
c5 = GetChar("金枪侍卫﹒丙");
c6 = GetChar("金枪侍卫﹒丁");
c7 = GetChar("肖安");
c8 = GetChar("左护法");
c9 = GetChar("右护法");
c10 = GetChar("无名");
		if (c>=0 && GetHP(c2)<GetMaxHP(c2)/6)
		{
			ChangeBehavior(c2, "patrol", 73);
			AsPerform(c2, "say", "可恶！想杀我还嫩了些！");	
CharSetBaseAttrib(2, CharAttrib_Speed, 200);			
			trg7 = 3;
			timer4= now+2;
		}				
	}
		if (trg7 == 3)
	{
c = GetChar("player");
c2 = GetChar("范璇");
c3 = GetChar("金枪侍卫﹒甲");
c4 = GetChar("金枪侍卫﹒乙");
c5 = GetChar("金枪侍卫﹒丙");
c6 = GetChar("金枪侍卫﹒丁");
c7 = GetChar("肖安");
c8 = GetChar("左护法");
c9 = GetChar("右护法");
c10 = GetChar("无名");
SetTarget(4, "waypoint", 73);
SetTarget(0, "char", c2);
		if (Distance(0, 4) < 100)
		{
				Perform(c2, "say", "（从画后面的密道开溜）");		
			trg7 = 4;
			timer4= now+2;
			
		}				
	}
			if (trg7 == 4&& now>timer4)
	{
c = GetChar("player");
c2 = GetChar("范璇");
c3 = GetChar("金枪侍卫﹒甲");
c4 = GetChar("金枪侍卫﹒乙");
c5 = GetChar("金枪侍卫﹒丙");
c6 = GetChar("金枪侍卫﹒丁");
c7 = GetChar("肖安");
c8 = GetChar("左护法");
c9 = GetChar("右护法");
c10 = GetChar("无名");
SetTarget(4, "waypoint", 73);
SetTarget(0, "char", c2);

			
RemoveNPC(c2);			
trg7 = 5;
gameover =1;
timer0 = now+2;			
	}
	
	if (trg0 == 10&&now > timer0)
	{
	gameover = -1;
	}
	
	if ((gameover==1 || gameover==-1) && now>timer0)
	{
		GameOver(gameover);
		gameover = 2;
	}		
}