// Roc House
int Rule = 4;
int RoundTime = 25;
int PlayerSpawn = 30;
int PlayerSpawnDir = 80;
int PlayerWeapon = 13;
int PlayerWeapon2 = 10;
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 timer0 = 0;
int timer1 = 0;
int timer2 = 0;
int timer3 = 0;
int gameover = 0;

OnStart()
{
	AddNPC("npc15_01");
	AddNPC("npc15_02");
	AddNPC("npc15_03");
	AddNPC("npc15_04");
	AddNPC("npc15_05");
	AddNPC("npc15_06");
	AddNPC("npc15_07");
}

Report(int c)
{
	int c2 = GetChar("Andy Xiao");
	int c3;
	int c4;
	int player;
	
	if (c>=0 && c2>=0)
	{
		SetTarget(0, "char", c);
		SetTarget(1, "char", c2);
		if (Distance(0, 1) < 100)
		{
			player = GetChar("player");
			c3 = GetChar("Guard A");
			ChangeBehavior(c3, "follow", player);
			c3 = GetChar("Guard B");
			ChangeBehavior(c3, "follow", player);
			c3 = GetChar("Guard C");
			ChangeBehavior(c3, "follow", player);
			c3 = GetChar("Guard D");
			ChangeBehavior(c3, "follow", player);
			
			Perform(c, "say", "Yes£¡£¡");
			Perform(c, "pause", 10);
			Perform(c, "say", "Sir, I find a stranger©q©q");
			Perform(c, "faceto", c2);
				
			c3 = GetChar("Bodyguard A");
			if (c3 >= 0)
			{
				ChangeBehavior(c3, "follow", c2);
				Perform(c3, "say", "Yes£¡");
				Perform(c3, "pause", 5);
				Perform(c3, "say", "Yes£¡");
				Perform(c3, "pause", 15);
			}
			c4 = GetChar("Bodyguard B");
			if (c4 >= 0)
			{
				ChangeBehavior(c4, "follow", c2);
				Perform(c4, "say", "Yes£¡");
				Perform(c4, "pause", 5);
				Perform(c4, "say", "Yes£¡");
				Perform(c4, "pause", 15);
			}				
				
			if (c3>=0 || c4>=0)
			{				
				Perform(c2, "say", "You stay here, let see what he can do£¡£¡");
				Perform(c2, "pause", 5);
				Perform(c2, "say", "Bodyguards£¡");
			}
			Perform(c2, "pause", 5);
			Perform(c2, "say", "Go get him£¡");
			Perform(c2, "say", "Killer, right, he is still coming£¡");
			Perform(c2, "pause", 5);					
			Perform(c2, "faceto", c);	
					
			return 1;
		}
	}	
	
	return 0;
}

Report2(int c)
{
	int c2 = GetChar("Andy Xiao");
	int c3;
	int c4;
	int player;
	if (c>=0 && c2>=0)
	{
		SetTarget(0, "char", c);
		SetTarget(1, "char", c2);
		if (Distance(0, 1) < 100)
		{
			player = GetChar("player");
			c3 = GetChar("Guard A");
			ChangeBehavior(c3, "follow", c2);
			c3 = GetChar("Guard B");
			ChangeBehavior(c3, "follow", c2);
			c3 = GetChar("Guard C");
			ChangeBehavior(c3, "follow", c2);
			c3 = GetChar("Guard D");
			ChangeBehavior(c3, "follow", c2);
			c3 = GetChar("Bodyguard B");
			ChangeBehavior(c3, "follow", c2);
			c3 = GetChar("Bodyguard A");
			ChangeBehavior(c3, "follow", c2);
			
			Perform(c, "say", "Yes£¡£¡");
			Perform(c, "pause", 8);
			Perform(c, "say", "Sir, I find a stranger, he should be the guy who caused trouble in Snow Town£¡");
			Perform(c, "faceto", c2);

			ChangeBehavior(c2, "follow", player);			
			Perform(c2, "say", "He wants to die. Let's move£¡£¡");
			Perform(c2, "pause", 5);					
			Perform(c2, "faceto", c);		
			return 1;		
		}
	}	
	
	return 0;
}

UnknownHelp(int c, int p)
{			
	if (c>=0 && GetEnemy(c)==p && GetHP(p)<GetMaxHP(p)/3)
	{
		AddNPC("npc15_08");
		return 1;
	}	
	
	return 0;
}

StopChat()
{
	int c;
	c = GetChar("Guard A");
	if (c >= 0)
	{
		StopPerform(c);
	}
	c = GetChar("Guard B");
	if (c >= 0)
	{
		StopPerform(c);
	}			
	c = GetChar("player");
	if (c >= 0)
	{
		StopPerform(c);
	}
}

OnUpdate()
{
	int player = GetChar("player");
	if (player < 0)
	{
		return 0;
	}
	
	int c;
	int c2;
	int c3;	
	int c4;	
	int now = GetGameTime();
	
	if (trg0 == 0)
	{
		c = GetChar("Guard A");
		c2 = GetChar("Guard B");
		c3 = GetChar("Guard C");
		c4 = GetChar("Guard D");
		if (c>=0 && c2>=0 && c3>=0 && c4>=0)
		{
			ChangeBehavior(c, "patrol", 0, 1, 2, 3, 4, 5);
			Perform(c, "say", "All right, keep going©q©q©q");
			Perform(c, "pause", 8);
			Perform(c, "say", "But that girl was so pretty, if I can©q©q");
			Perform(c, "pause", 8);
			Perform(c, "say", "I don't think I have vacations any more©q©q");
			Perform(c, "pause", 8);
			Perform(c, "say", "I heard a guy caused a big troublr in Snow Town, then everybody got nervous£¡");
			Perform(c, "faceto", c2);
			
			ChangeBehavior(c2, "patrol", 0, 20, 24, 10, 11, 13, 17, 16);
			Perform(c2, "say", "Ok, see you later¡«");
			Perform(c2, "pause", 4);
			Perform(c2, "say", "If somebody rush in, you don't even have your life £¡");
			Perform(c2, "say", "You don't have a vacation for too long, right©q©q");
			Perform(c2, "pause", 8);
			Perform(c2, "say", "When the thief was caught, we had to guard every day and night©q");
			Perform(c2, "pause", 8);
			Perform(c2, "say", "Hey, I just came back from my vacation");
			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", "£¨©q©q©qI don't need to care about this©q©q©q©q£©");
			PlayerPerform("pause", 2);
			PlayerPerform("say", "£¨That girl, she is caught in this house©q©q£©");
			PlayerPerform("pause", 15);
			PlayerPerform("say", "£¨Thief£¡©q©q©qThat girl 'Ivy'£¿©q©q£©");
			PlayerPerform("pause", 15);
			PlayerPerform("block", 1);
			
			trg0 = 1;
		}
	}
	
	if (trg0 == 1)
	{
		if (trg1 == 0)
		{
			c = GetChar("Guard A");
			if (c>=0 && GetEnemy(c)==player)
			{
				StopChat();
				Perform(c, "guard", 3);
				Perform(c, "say", "Who are you£¡");
				Perform(c, "faceto", player);
				trg1 = 1;
			}
		}
		if (trg2 == 0)
		{
			c = GetChar("Guard B");
			if (c>=0 && GetEnemy(c)==player)
			{
				StopChat();
				Perform(c, "guard", 3);
				Perform(c, "say", "You dare rush in! Prepare yourself£¡");
				Perform(c, "faceto", player);
				trg2 = 1;
			}
		}	
		if (trg3 == 0)
		{
			c = GetChar("Guard C");
			if (c>=0 && GetEnemy(c)==player)
			{
				c2 = GetChar("Guard D");
				if (c2 >= 0)
				{
					ChangeBehavior(c2, "follow", c);
				}
				
				Perform(c, "guard", 3);
				Perform(c, "say", "Come on! Somebody rushes in£¡£¡");
				Perform(c, "faceto", player);
				trg3 = 1;
				trg4 = 1;
			}
		}
		if (trg4 == 0)
		{
			c = GetChar("Guard D");
			if (c>=0 && GetEnemy(c)==player)
			{
				c2 = GetChar("Guard C");
				if (c2 >= 0)
				{
					ChangeBehavior(c2, "follow", c);
				}
				
				Perform(c, "guard", 3);
				Perform(c, "say", "Come on! Somebody rushes in£¡£¡");
				Perform(c, "faceto", player);
				trg4 = 1;
				trg3 = 1;
			}
		}		
	}
	
	if (trg1 == 1)
	{
		c = GetChar("Guard A");
		if (c>=0 && GetHP(c)<GetMaxHP(c)/2)
		{
			c2 = GetChar("Guard C");
			if (c2 >= 0)
			{
				ChangeBehavior(c, "follow", c2);
				Perform(c, "say", "Come on! Somebody rushes in£¡");				
				ChangeBehavior(c2, "follow", player);
				trg1 = 2;
				trg3 = 1;
			}
		}		
	}
	if (trg2 == 1)
	{
		c = GetChar("Guard B");
		if (c>=0 && GetHP(c)<GetMaxHP(c)/2)
		{
			c2 = GetChar("Guard D");
			if (c2 >= 0)
			{
				ChangeBehavior(c, "follow", c2);
				Perform(c, "say", "Come on! Somebody rushes in£¡");				
				ChangeBehavior(c2, "follow", player);
				trg2 = 2;
				trg4 = 1;
			}
		}		
	}	
	
	if (trg3 == 1)
	{
		c = GetChar("Guard C");
		if (c>=0 && GetHP(c)<GetMaxHP(c)/2)
		{
			ChangeBehavior(c, "follow", "vip");
			trg3 = 2;
		}
	}
	if (trg4 == 1)
	{
		c = GetChar("Guard D");
		if (c>=0 && GetHP(c)<GetMaxHP(c)/2)
		{
			ChangeBehavior(c, "follow", "vip");
			trg4 = 2;
		}
	}	
	
	if (trg3 == 2)
	{
		c = GetChar("Guard C");
		if (Report(c))
		{
			trg1 = 3;
			trg2 = 3;
			trg3 = 3;
			trg4 = 3;
			trg5 = 4;
			trg6 = 4;
		}
	}
	if (trg4 == 2)
	{
		c = GetChar("Guard D");
		if (Report(c))
		{
			trg1 = 3;
			trg2 = 3;
			trg3 = 3;
			trg4 = 3;
			trg5 = 4;
			trg6 = 4;
		}
	}	
	
	if (trg5 == 0)
	{
		c = GetChar("Bodyguard A");
		if (c>=0 && GetEnemy(c)==player)
		{
			SetTarget(0, "char", c);
			SetTarget(1, "char", player);
			if (Distance(0, 1) < 200)
			{
				Perform(c, "aggress");
				Perform(c, "say", "Let's play£¡");
				Perform(c, "pause", 4);
				Perform(c, "say", "That should be you who got trouble in Snow Town£¡");
				Perform(c, "faceto", player);				
				trg5 = 1;
			}
		}
	}
	if (trg5 == 1)
	{
		c = GetChar("Bodyguard A");
		if (c>=0 && GetHP(c)<GetMaxHP(c)/2)
		{
			Perform(c, "say", "©q©q©qYou are not that easy©q©q©q");
			Perform(c, "faceto", player);				
			trg5 = 2;
		}	
	}
	if (trg5 == 2)
	{
		c = GetChar("Bodyguard A");
		if (c>=0 && GetHP(c)<GetMaxHP(c)/4)
		{
			ChangeBehavior(c, "follow", "vip");
			Perform(c, "say", "©q©qRun first¡«");
			Perform(c, "faceto", player);				
			trg5 = 3;
		}				
	}
	if (trg5 == 3)
	{
		c = GetChar("Bodyguard A");
		if (c>=0 && Report2(c))
		{
			trg1 = 3;
			trg2 = 3;
			trg3 = 3;
			trg4 = 3;
			trg5 = 4;
			trg6 = 4;
		}
	}
	if (trg5==3 || trg5==4)
	{
		c = GetAnyChar("Bodyguard A");
		if (c>=0 && GetHP(c)<=0)
		{
			Say(c, "Boss Xiao, I will go first©q©q©q");
			trg5 = 5;
		}
	}
	
	if (trg6 == 0)
	{
		c = GetChar("Bodyguard B");
		if (c>=0 && GetEnemy(c)==player)
		{
			SetTarget(0, "char", c);
			SetTarget(1, "char", player);
			if (Distance(0, 1) < 200)
			{
				Perform(c, "aggress");
				Perform(c, "say", "Let me play with you£¡");
				Perform(c, "pause", 4);
				Perform(c, "say", "You are not that easy£¡");
				Perform(c, "faceto", player);				
				trg6 = 1;
			}
		}
	}
	if (trg6 == 1)
	{
		c = GetChar("Bodyguard B");
		if (c>=0 && GetHP(c)<GetMaxHP(c)/2)
		{
			Perform(c, "say", "Shit! you make me mad£¡£¡");
			Perform(c, "faceto", player);				
			trg6 = 2;
		}	
	}
	if (trg6 == 2)
	{
		c = GetChar("Bodyguard B");
		if (c>=0 && GetHP(c)<GetMaxHP(c)/4)
		{
			ChangeBehavior(c, "follow", "vip");
			Perform(c, "say", "I can't beat you, but I will find some people to deal with you£¡");
			Perform(c, "faceto", player);				
			trg6 = 3;
		}				
	}
	if (trg6 == 3)
	{
		c = GetChar("Bodyguard B");
		if (c>=0 && Report2(c))
		{
			trg1 = 3;
			trg2 = 3;
			trg3 = 3;
			trg4 = 3;
			trg5 = 4;
			trg6 = 4;
		}
	}
	if (trg6==3 || trg6==4)
	{
		c = GetAnyChar("Bodyguard B");
		if (c>=0 && GetHP(c)<=0)
		{
			Say(c, "I,I can't©q©q©q");
			trg6 = 5;
		}
	}
	
	if (trg7 == 0)
	{
		c = GetChar("Andy Xiao");
		SetTarget(0, "char", c);
		SetTarget(1, "char", player);
		if (c>=0 && GetEnemy(c)==player && Distance(0, 1)<200)
		{
			Perform(c, "guard", 3);
			Perform(c, "say", "Just go hell then you will know why£¡£¡");
			Perform(c, "faceto", player);
			Perform(c, "say", "It seems like you know nothing");
			Perform(c, "pause", 3);
			Perform(c, "say", "In my opinion, you are just a pitiful dog follows others£¡");
			Perform(c, "aggress");
			Perform(c, "say", "You are so pitiful that you  never know how you die£¡");
			Perform(c, "pause", 3);
			Perform(c, "say", "I wait here for so long, but finally you come£¡");
			Perform(c, "faceto", player);
								
												
			c2 = GetChar("Bodyguard A");
			if (c2 >= 0)
			{
				ChangeBehavior(c2, "follow", c);
				Perform(c2, "guard", 10);
				Perform(c2, "faceto", player);
			}
			c2 = GetChar("Bodyguard B");
			if (c2 >= 0)
			{
				ChangeBehavior(c2, "follow", c);
				Perform(c2, "guard", 10);
				Perform(c2, "faceto", player);
			}		

			StopChat();					
			c2 = GetChar("Guard A");
			if (c2 >= 0)
			{
				Perform(c2, "guard", 10);
				Perform(c2, "faceto", player);
			}			
			c2 = GetChar("Guard B");
			if (c2 >= 0)
			{
				Perform(c2, "guard", 10);
				Perform(c2, "faceto", player);
			}			
			c2 = GetChar("Guard C");
			if (c2 >= 0)
			{
				Perform(c2, "guard", 10);
				Perform(c2, "faceto", player);
			}			
			c2 = GetChar("Guard D");
			if (c2 >= 0)
			{
				Perform(c2, "guard", 10);
				Perform(c2, "faceto", player);
			}			
								
			PlayerPerform("block", 0);
			PlayerPerform("pause", 15);
			PlayerPerform("block", 1);
			
			trg1 = 3;
			trg2 = 3;
			trg3 = 3;
			trg4 = 3;
			trg5 = 4;
			trg6 = 4;			
			trg7 = 1;
		}
		
		if (trg7==0)	
		{
			if (trg8 == 0)
			{
				c2 = GetChar("Bodyguard A");			
				if (UnknownHelp(c2, player))
				{
					trg8 = 1;
				}
			}
			if (trg8 == 0)
			{
				c2 = GetChar("Bodyguard B");
				if (UnknownHelp(c2, player))
				{
					trg8 = 1;
				}
			}
		}		
	}

	if (trg7 == 1)
	{
		c = GetChar("Andy Xiao");
		if (c>=0 && GetHP(c)<GetMaxHP(c)/2)
		{
			Perform(c, "say", "But you are too young to get through here£¡£¡");
			Perform(c, "guard", 5);
			Perform(c, "say", "Yeah! He got the right man£¡");
			Perform(c, "faceto", player);
			
			PlayerPerform("say", "£¨©q©qRight man£¿£¿£¿£©");
			PlayerPerform("pause", 3);
			
			trg7 = 2;
		}		
	}
	if (trg7 == 2)
	{
		c = GetChar("Andy Xiao");
		if (c>=0 && GetHP(c)<GetMaxHP(c)/4)
		{				
			ChangeBehavior(c, "wait");
			SetTarget(0, "waypoint", 79);
			ChangeBehavior(c, "attacktarget", 0);
						
			Perform(c, "say", "©q©q©qJust wait here, I will show you something©q©q©q");
			Perform(c, "say", "Hold him for a while, then I come up with a plan to get out here£¡£¡");
			Perform(c, "say", "Shit! Boy£¡");
			Perform(c, "faceto", player);
		
			c2 = GetChar("Bodyguard B");
			ChangeBehavior(c2, "follow", player);
			c2 = GetChar("Bodyguard A");
			ChangeBehavior(c2, "follow", player);
			
			trg7 = 3;	
			timer1 = now + 20;
		}
	}
	if (trg7==3 && now>timer1)
	{
		c = GetChar("Andy Xiao");
		if (c >= 0)
		{
			SetTarget(0, "waypoint", 107);
			ChangeBehavior(c, "attacktarget", 0);						
			trg7 = 4;
			timer1 = now + 15;
		}
	}
	if (trg7==4 && now>timer1)
	{
		c = GetChar("Andy Xiao");
		if (c >= 0)
		{
			SetTarget(0, "waypoint", 115);
			ChangeBehavior(c, "attacktarget", 0);						
			trg7 = 5;
			timer1 = now + 15;
		}
	}
	if (trg7==5 && now>timer1)
	{
		c = GetChar("Andy Xiao");
		if (c >= 0)
		{
			SetTarget(0, "waypoint", 53);
			ChangeBehavior(c, "attacktarget", 0);						
			trg7 = 6;
			timer1 = now + 10;
		}
	}		
	if (trg7==6 && now>timer1)
	{
		c = GetChar("Andy Xiao");
		if (c >= 0)
		{
			SetTarget(0, "waypoint", 116);
			ChangeBehavior(c, "attacktarget", 0);						
			Perform(c, "aggress");
			Perform(c, "faceto", player);
			trg7 = 7;
		}
	}				
	if (trg7 == 7)
	{
		c = GetChar("Andy Xiao");
		if (c >= 0)
		{
			SetTarget(0, "char", c);
			SetTarget(1, "waypoint", 116);
			if (Distance(0, 1) < 80)
			{
				RemoveNPC(c);
				gameover = -1;
				timer0 = now + 3;
				trg7 = 8;
			}
		}		
	}
	
	if (trg8 == 1)
	{
		c = GetChar("Unname");
		if (c >= 0)
		{
			SetTarget(0, "char", c);
			SetTarget(1, "char", player);
			if (Distance(0, 1) < 150)
			{
				PlayerPerform("say", "You are©q©q©q");
				
				c3 = -1;
				c2 = GetChar("Bodyguard A");
				if (c2 >= 0)
				{
					Perform(c2, "say", "Who the hell are you! Move£¡£¡");
					Perform(c2, "pause", 6);		
					Perform(c2, "faceto", c);
					
					c3 = c2;
				}
				c2 = GetChar("Bodyguard B");
				if (c2 >= 0)
				{
					Perform(c2, "say", "Who the hell are you! Move£¡£¡");
					Perform(c2, "pause", 6);		
					Perform(c2, "faceto", c);
					c3 = c2;
				}
				
				if (c3 >= 0)
				{							
					Perform(c, "aggress");
					Perform(c, "say", "©q©q©q©q©q");
					Perform(c, "pause", 3);
					Perform(c, "faceto", c3);					
				}
				trg8 = 2;
			}
		}
	}
	
	if (trg8 == 2)
	{
		c = GetChar("Unname");
		
		if (trg9 == 0)
		{
			c2 = GetAnyChar("Bodyguard A");
			if (c2>=0 && GetHP(c2)<=0)
			{
				Say(c2, "You get a hand©q©q©q©q©q");
				
				Perform(c, "aggress");
				Perform(c, "say", "Dawn£¡");
				Perform(c, "faceto", c2);
				trg9 = 1;
				timer2 = now + 5;
			}
		}
		if (trg10 == 0)
		{
			c2 = GetAnyChar("Bodyguard B");
			if (c2>=0 && GetHP(c2)<=0)
			{
				Say(c2, "Shit! Getting a hand©q©q©q");
				
				Perform(c, "aggress");
				Perform(c, "say", "Dawn£¡");
				Perform(c, "faceto", c2);
				trg10 = 1;
				timer2 = now + 5;
			}
		}		
	}
	
	if (trg8 != 0)
	{
		c = GetChar("Unname");
		if (c>=0 && now>timer3)
		{
			Perform(c, "use", 4);
			timer3 = now + 180;			
		}
	}
	
	if (trg9==1 && trg10==1 && now>timer2)
	{
		c = GetChar("Unname");
		if (c >= 0)
		{
			SetTarget(0, "waypoint", 53);
			ChangeBehavior(c, "attacktarget", 0);
			
			Perform(c, "©q©q©qUnname©q©q©q");
			Perform(c, "pause", 5);
			Perform(c, "©q©q©q©q©q©q");
			Perform(c, "pause", 5);
			Perform(c, "faceto", player);
			
			trg9 = 2;
		}				
	}
	
	if (trg9 == 2)
	{
		c = GetChar("Unname");
		if (c >= 0)
		{
			SetTarget(0, "waypoint", 53);
			SetTarget(1, "char", c);
			if (Distance(0, 1) < 80)
			{
				RemoveNPC(c);
				trg9 = 3;
			}			
		}		
	}
	
	
	if ((gameover==1 || gameover==-1) && now>timer0)
	{
		GameOver(gameover);
		gameover = 2;
	}		
}