#include "../PScriptLib/AsHelper.as"

// 锺乳洞
int Rule = 10;
int RoundTime = 10;
int PlayerSpawn = 9;
int PlayerSpawnDir = 90;
int PlayerWeapon = 32;
int PlayerWeapon2 = 1;
int PlayerHP = 300;

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 timer0 = 0;
int timer1 = 0;
void OnStart()
{
	string voiceFolder = "UserData/Voice/sn01/";
	AsSoundCacheFolder(voiceFolder);
	AsSetChatVoiceFolder(voiceFolder);
	
	AddNPC("npc01_01");
	AddNPC("npc01_02");
	AddNPC("npc01_03");
	AddNPC("npc01_04");
	AddNPC("npc01_05");
	AddNPC("npc01_06");
	AddNPC("npc01_07");
	AddNPC("npc01_08");
}


int Report(int c1, int c2, int c3)
{
	if (c1>=0 && c3>=0)
	{
		SetTarget(0, "char", c1);
		SetTarget(1, "char", c3);
		
		if (Distance(0, 1) < 100)
		{
			if (c2 >= 0)
			{
				ChangeBehavior(c2, "follow", c3);
			}
	
			ChangeBehavior(c1, "follow", c3);
			AsPerform(c1, "pause", 4);
			AsPerform(c1, "say", "报告哨兵长！发现入侵者！！");
			AsPerform(c1, "faceto", c3);
		
			int player = GetChar("player");
			ChangeBehavior(c3, "follow", player);			
			AsPerform(c3, "say", "在那？所有人跟我来！");
			AsPerform(c3, "pause", 3);
			AsPerform(c3, "faceto", c1);			
		
			return 1;
		}
	}
	
	return 0;
}


void OnUpdate()
{
	int player = GetChar("player");	
	int c;
	int c2;
	int c3;
	int c4;
	int c5;
	int now = GetGameTime();

	if (trg0 == 0&&now>=1)
	{
		c = GetChar("无名"); 
		c2 = GetChar("屠城"); 
		c3 = GetChar("肖安");
		
    if (c>=0 && c2>=0 && c3>=0)
		{
			AsPerform(c, "say", "屠大鹏、萧银鹏......想不到......先走一步的我竟然会比那个家伙先暴露。");
			AsPerform(c, "crouch", 5);
			
			ChangeBehavior(c2, "patrol", 0, 2, 21, 23);
			ChangeBehavior(c2, "faceto",c3 );
			AsPerform(c2, "say", "哈哈哈，这话在理！不过怎么到现在还听不到炎硫岛的换防哨声呢？咦，那边好像有奇怪动静！");
			AsPerform(c2, "pause", 18);
			AsPerform(c2, "say", "肖兄，范璇这老家伙藏着不出来，让我们忙着筹备火器之物，可着实有点不厚道。");
			AsPerform(c2, "pause", 9);
			AsPerform(c2, "faceto", c3);
			
			ChangeBehavior(c3, "patrol", 0, 2, 21, 23);
			ChangeBehavior(c3, "faceto", c2);
			AsPerform(c3, "say", "（找到一处低地）全体都有，戒严！任何声响都要注意！你们几个在这里看着!屠老大，走，我们去那里看看！");
			AsPerform(c3, "pause", 12);
			AsPerform(c3, "say", "（或许...是我安排的杀手被发现了？这标记......败事有余的家伙！还要我来为你打掩护！）");
			AsPerform(c3, "pause", 22);
			AsPerform(c3, "say", "尊敬老人是你们中原的传统，让他得意几天又有何妨！");
			AsPerform(c3, "pause", 20);
			Perofrm(c3, "faceto", c2);
			

			PlayerPerform("pause", 5);
			PlayerPerform("say", "（那边好像有声音！如果那个神秘人暴露，若举棋不定，戒严之后......我恐怕也难以脱身。）");
			PlayerPerform("block", 0);
			PlayerPerform("pause", 10);
			PlayerPerform("say", "（这个位置......可以借助出口钟乳石塌方来造成混乱！引发动静之后便可趁机逃脱！");
			PlayerPerform("pause", 10);
			PlayerPerform("say", "（还是先想办法脱身为妙！）");
			PlayerPerform("pause", 4);
		    PlayerPerform("say", "（这一单任务......情况有点复杂。）");
		    PlayerPerform("pause", 4);
		    PlayerPerform("say", "（她会不会也藏在这里呢？）");
		    PlayerPerform("pause", 5);
		    PlayerPerform("say", "（那道神秘的声音......究竟会是谁？）");
			PlayerPerform("crouch", 1);
			PlayerPerform("block", 1);
			trg0 = 1;
			trg7 = 1;
			trg4 = 1;
			timer0 = now + 52;
			timer1 = now+5;
	if (trg4 == 1&&now>timer1)
	{
	
	c4 = GetAnyChar("player"); 	
	if (GetHP(c4)<=250&&now>=20)
    {
     PlayerPerform("say", "石倾危险......引发塌方之时我不可被波及太深......");
      trg4=2;
	  timer1=now+5;
    }
     }
		}
	}
	if (timer0<now && trg7 == 1)
	{
	c = GetChar("无名"); 
		c2 = GetChar("屠城"); 
		c3 = GetChar("肖安");
		
		if (c>=0 && c2>=0 && c3>=0)
		{
		RemoveNPC(c);
		RemoveNPC(c2);	
		RemoveNPC(c3);	
		trg7 =2;
		}
	}
	
	if (trg7 == 1)
	{
	c = GetChar("无名"); 
		c2 = GetChar("屠城"); 
		c3 = GetChar("肖安");
		
		if (c>=0 && GetEnemy(c)==player)
		{
        AsPerform(c, "say", "可恶，这下彻底暴露了！");
		trg7 =3;
		}
		if (c2>=0 && GetEnemy(c2)==player)
		{
        AsPerform(c2, "say", "什么人！！");
		trg7 =3;
		}
		if (c3>=0 && GetEnemy(c3)==player)
		{
        AsPerform(c3, "say", "哼，好一个蠢货！");
		trg7 =3;
		}
	}
	if (trg7 == 3)
	{
	timer0 = now + 5;
	PlayerPerform("say", "（不好！）");
	PlayerPerform("crouch", 1);
	PlayerPerform("block", 1);
	PlayerPerform("pause", 2);
	trg7 = 4;
	}
	
	if (trg7 == 4 && timer0<=now)
	{
	GameOver(-1);
	}
	
	if (trg0==1 && trg3==0)
	{
		c = GetChar("军枪哨兵长"); 	
		if (c>=0 && GetEnemy(c)==player)
		{			
			c2 = GetChar("铁枪哨兵﹒甲"); 
			c3 = GetChar("铁枪哨兵﹒乙");
			c4 = GetChar("铁枪哨兵﹒丙"); 
			c5 = GetChar("铁枪哨兵﹒丁");
			if (c2 >= 0)
			{
				ChangeBehavior(c2, "follow", c);
				AsPerform(c2, "pause", 2);
				AsPerform(c2, "faceto", c);
					timer0 = now + 5;
	PlayerPerform("say", "（不好！被发现了！）");
	PlayerPerform("crouch", 1);
	PlayerPerform("block", 1);
	PlayerPerform("pause", 2);
	trg7 = 4;
			}
			if (c3 >= 0)
			{
				ChangeBehavior(c3, "follow", c);
				AsPerform(c3, "pause", 2);
				AsPerform(c2, "faceto", c);
					timer0 = now + 5;
	PlayerPerform("say", "（不好！被发现了！）");
	PlayerPerform("crouch", 1);
	PlayerPerform("block", 1);
	PlayerPerform("pause", 2);
	trg7 = 4;
			}
				if (c4 >= 0)
			{
				ChangeBehavior(c3, "follow", c);
				AsPerform(c3, "pause", 2);
				AsPerform(c2, "faceto", c);
					timer0 = now + 5;
	PlayerPerform("say", "（不好！被发现了！）");
	PlayerPerform("crouch", 1);
	PlayerPerform("block", 1);
	PlayerPerform("pause", 2);
	trg7 = 4;
			}
				if (c5 >= 0)
			{
				ChangeBehavior(c3, "follow", c);
				AsPerform(c3, "pause", 2);
				AsPerform(c2, "faceto", c);
					timer0 = now + 5;
	PlayerPerform("say", "（不好！被发现了！）");
	PlayerPerform("crouch", 1);
	PlayerPerform("block", 1);
	PlayerPerform("pause", 2);
	trg7 = 4;
			}
			if (c2<0 && c3<0 &&c4<0&&c5<0)
			{
				AsPerform(c, "say", "人呢！？可恶！我就不信我一个人对付不了你！");
				AsPerform(c, "pause", 5);
			}
		
			Perform(c, "say", "来人呀！！");		
			AsPerform(c, "faceto", player);
		
			trg0 = 2;
		}
	}
		
	if (trg1==0 && trg0==1 && trg3==0)
	{
		c = GetChar("铁枪哨兵﹒甲");
		if (c>=0 && GetEnemy(c)==player)
		{
			AsPerform(c, "guard", 3);
			AsPerform(c, "faceto", player);
			trg1 = 1;
		}
		c = GetChar("铁枪哨兵﹒甲");
		if (c>=0 && GetEnemy(c)==player)
		{
			AsPerform(c, "guard", 3);
			AsPerform(c, "faceto", player);
			trg1 = 1;
		}
	}	
	if (trg6 == 3)
	{
		PlayerPerform("crouch", 1);
		PlayerPerform("block", 1);
		PlayerPerform("say", "可恶......死人同样也会说话！我暴露了行踪！");
		PlayerPerform("pause", 2);
		timer1 = now + 8;
		trg6 = 4;	
	}
	if (trg7 == 2&&trg5 <=0)
	{
		PlayerPerform("crouch", 1);
		PlayerPerform("block", 1);
		PlayerPerform("say", "可恶......出口被堵死了，那个神秘人必将把我供出来！");
		PlayerPerform("pause", 2);
		timer1 = now + 5;
		trg6 = 4;
        trg5 = 2;		
	}
	

		if (trg6 == 4 && now > timer1)
	{
    GameOver(-1);
	}
}


void OnCharacterKill(int killerId, int beKilledId){
	trg6 = 3;
}
// 处理角色死亡事件
void OnCharacterDeath(int charId, int reason){
    string reasonText = "未知";
    if (reason == 1){
    }
    else if (reason == 2) {
    }
    else if (reason == 3) {
        reasonText = "其它";
		trg5 = 1;
    }
}
