// よ皚
int Rule = 10;
int RoundTime = 5;
int PlayerSpawn = 0;
int PlayerSpawnDir = 100;

int PlayerWeapon = 4+Rand(6);
int PlayerWeapon2 = 47+Rand(12);
int PlayerHP = 5000;

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 timer1 = 0;
int timer2 = 0;
int timer3 = 0;
int timer4 = 0;
int gameover = 0;
int reborn = -1;
string rebornName;


OnStart()
{
	AddNPC("npcX0601");
}

OnUpdate()
{
	int player = GetAnyChar("player");
	if (player < 0)
	{
		return 0;
	}
	if (gameover == 2)
	{
		return 0;
	}
	
	int c;
	int c2;
	int c3;
	int c4;
	int c5;
	int now = GetGameTime();

	if (trg0 == 0)
	{
		c = GetAnyChar("大掌柜");
		if (c>=0 && GetHP(player)>0)
		{
			Perform(c, "follow", player);
			Perform(c, "aggress");
			Perform(c, "pause", 4);
			Perform(c, "say", "你要打败我才能通关喔!");
			Perform(c, "use", 9);
			Perform(c, "kill", player);

			PlayerPerform("use", 9);
			PlayerPerform("block", 0);
			PlayerPerform("pause", 13);
			PlayerPerform("block", 1);

			trg0 = 1;
		}
	}

	if (trg1 == 0)
	{
		c = GetAnyChar("大掌柜");
		if (c>=0 && GetEnemy(c)==player && GetHP(player)>0)
		{
			Perform(c, "follow", player);
			Perform(c, "say", "让我看看你真正的实力吧!");
			Perform(c, "kill", player);

			trg1 = 1;
			timer3 = now + 10;
		}
	}
	
	if (trg1 == 2)
	{
		c = GetAnyChar("大掌柜");
		if (c>=0 && GetEnemy(c)==player && GetHP(player)>0)
		{
			Perform(c, "follow", player);
			Perform(c, "say", "认真些吧!");
			Perform(c, "faceto", player);

			trg1 = 3;
			timer4 = now + 10;
		}
	}

	

	if (trg3 == 0)
	{
		c = GetAnyChar("大掌柜");
		if (c>=0 && GetHP(c)>0  && GetHP(c)<=(GetMaxHP(c)/4)*3 && GetHP(player)>0)
		{
			Perform(c, "follow", player);
			Perform(c, "use", 5);
			Perform(c, "use", 8);
			Perform(c, "use", 19);
			Perform(c, "block", 0);
			Perform(c, "say", "我要认真战斗了!");
			Perform(c, "pause", 1);
			Perform(c, "block", 1);
			Perform(c, "faceto", player);
                        Perform(c, "kill", player);
			PlayerPerform("block", 0);
			PlayerPerform("pause", 7);
			PlayerPerform("block", 1);
			trg3 = 1;
		}
		c = GetAnyChar("大掌柜");
		if (c>=0 && GetHP(c)>0 && GetHP(c)<=GetMaxHP(c)/10 && GetHP(player)>0)
		{
			Perform(c, "aggress");
			Perform(c, "block", 0);
			Perform(c, "pause", 4);
			Perform(c, "say", "走，我们回去庆贺一下吧!");
			Perform(c, "pause", 12);
			Perform(c, "say", "担心你嘛，没想到你都练到这种成度，杀范旋指日可待了!");
			Perform(c, "pause", 8);
			Perform(c, "say", "好了，训练到此结束，你通过了，嘻嘻!");
			Perform(c, "block", 1);
			Perform(c, "faceto", player);

			PlayerPerform("block", 0);
			PlayerPerform("pause", 20);
			PlayerPerform("say", "你们啊，连我也信不过了么!");
			PlayerPerform("pause", 10);
			PlayerPerform("say", "真有你们的，用不着都来吧，呵呵呵!");
			PlayerPerform("pause", 6);
			PlayerPerform("block", 1);

			Perform(c5, "use", 9);
			Perform(c4, "use", 9);
			Perform(c3, "use", 9);
			Perform(c2, "use", 9);

			trg5 = 1;
			timer1 = now + 25;
		}
	}

	if (trg6==1)
	{
		trg6 = 0;
	}

	if (trg7 == 0)
	{
		c = GetAnyChar("叶翔");
		if (c>=0 && GetEnemy(c)==player && GetHP(player)>0)
		{
			Perform(c, "follow", player);

			trg7 = 1;
		}
	}
	if (trg7 == 1)
	{
		c = GetAnyChar("叶翔");
		if (c>=0 && GetEnemy(c)!=player && GetHP(player)>0)
		{
			ChangeBehavior(c, "patrol", 1,3,5,7,9,11,13,15,16,17);

			trg7 = 2;
		}
	}
	if (trg7 == 2)
	{
		c = GetAnyChar("叶翔");
		if (c>=0 && GetEnemy(c)==player && GetHP(player)>0)
		{
			Perform(c, "follow", player);

			trg7 = 3;
		}
	}
	if (trg7 == 3)
	{
		c = GetAnyChar("叶翔");
		if (c>=0 && GetEnemy(c)!=player && GetHP(player)>0)
		{
			ChangeBehavior(c, "patrol", 17,16,15,13,11,9,7,5,3,1);

			trg7 = 0;
		}
	}

	if (trg8 == 0)
	{
		c = GetAnyChar("小何");
		if (c>=0 && GetEnemy(c)==player && GetHP(player)>0)
		{
			Perform(c, "follow", player);

			trg8 = 1;
		}
	}
	if (trg8 == 1)
	{
		c = GetAnyChar("小何");
		if (c>=0 && GetEnemy(c)!=player && GetHP(player)>0)
		{
			ChangeBehavior(c, "patrol", 17,16,15,13,11,9,7,5,3,1);

			trg8 = 2;
		}
	}
	if (trg8 == 2)
	{
		c = GetAnyChar("小何");
		if (c>=0 && GetEnemy(c)==player && GetHP(player)>0)
		{
			Perform(c, "follow", player);

			trg8 = 3;
		}
	}
	if (trg8 == 3)
	{
		c = GetAnyChar("小何");
		if (c>=0 && GetEnemy(c)!=player && GetHP(player)>0)
		{
			ChangeBehavior(c, "patrol", 1,3,5,7,9,11,13,15,16,17);

			trg8 = 0;
		}
	}

	if (trg9 == 0)
	{
		c = GetAnyChar("凤凰");
		if (c>=0 && GetEnemy(c)==player && GetHP(player)>0)
		{
			Perform(c, "follow", player);

			trg9 = 1;
		}
	}
	if (trg9 == 1)
	{
		c = GetAnyChar("凤凰");
		if (c>=0 && GetEnemy(c)!=player && GetHP(player)>0)
		{
			ChangeBehavior(c, "patrol", 1,3,5,7,9,11,13,15,16,17);

			trg9 = 2;
		}
	}
	if (trg9 == 2)
	{
		c = GetAnyChar("凤凰");
		if (c>=0 && GetEnemy(c)==player && GetHP(player)>0)
		{
			Perform(c, "follow", player);

			trg9 = 3;
		}
	}
	if (trg9 == 3)
	{
		c = GetAnyChar("凤凰");
		if (c>=0 && GetEnemy(c)!=player && GetHP(player)>0)
		{
			ChangeBehavior(c, "patrol", 17,16,15,13,11,9,7,5,3,1);

			trg9 = 0;
		}
	}

	if (trg10 == 0)
	{
		c = GetAnyChar("石群");
		if (c>=0 && GetEnemy(c)==player && GetHP(player)>0)
		{
			Perform(c, "follow", player);

			trg10 = 1;
		}
	}
	if (trg10 == 1)
	{
		c = GetAnyChar("石群");
		if (c>=0 && GetEnemy(c)!=player && GetHP(player)>0)
		{
			ChangeBehavior(c, "patrol", 17,16,15,13,11,9,7,5,3,1);

			trg10 = 2;
		}
	}
	if (trg10 == 2)
	{
		c = GetAnyChar("石群");
		if (c>=0 && GetEnemy(c)==player && GetHP(player)>0)
		{
			Perform(c, "follow", player);

			trg10 = 3;
		}
	}
	if (trg10 == 3)
	{
		c = GetAnyChar("石群");
		if (c>=0 && GetEnemy(c)!=player && GetHP(player)>0)
		{
			ChangeBehavior(c, "patrol", 1,3,5,7,9,11,13,15,16,17);

			trg10 = 0;
		}
	}


	if (gameover!=-1 && GetHP(player)<=0)
	{
		gameover = -1;
		timer1 = now + 2; 
	}
	c = GetAnyChar("大掌柜");
	if (gameover!=-1 && c>=0 && GetHP(c)<=0)
	{			
		gameover = -1;
		timer1 = now + 2; 
	}	
	if ((gameover==1 || gameover==-1) && now>timer1)
	{
		GameOver(gameover);
		gameover = 2;
	}
}

