/*
	PScript file for desk Items of all scenes
		by Peter Pon 2002/09/26

	message handle for 20 desks
*/

int g_iNumDeskes = 20;
int g_iDeskHP[g_iNumDeskes];
int g_bDeskAlive[g_iNumDeskes];

InitDeskes(int num)
{
	int i;
	string name;
	
	for ( i=1; i<=num; i++ )
	{
		g_bDeskAlive[i-1] = 1;
		g_iDeskHP[i-1] = g_iDeskMaxHP;
		
		MakeString(name, "D_Desk", i);
		int id = GetSceneItem(name, "index");
		SetSceneItem(id, "name", "machine");
		SetSceneItem(id, "attribute", "collision", 1);
		SetSceneItem(id, "pose", 0, 0);

		MakeString(name, "D_itDesk", i);
		SetSceneItem(name, "attribute", "active", 0);
		SetSceneItem(name, "attribute", "interactive", 0);

		MakeString(name, "D_wpDesk", i);
		SetSceneItem(name, "attribute", "active", 0);
		SetSceneItem(name, "attribute", "interactive", 0);
	}
}

DeskOnAttack(int id, int index, int damage)
{
	g_iDeskHP[index-1] = g_iDeskHP[index-1] - damage;
	if ( g_iDeskHP[index-1]>0 )
	{
		NetEvent(1);
		CreateEffect(id, "BoxHIT");
		NetEvent(0);
	}
	
	if ( GetSceneItem(id, "pose")==1 )
	{
		return 0;
	}

	string itemname;
	string weaponname;
	MakeString(itemname, "D_itDesk", index);
	MakeString(weaponname, "D_wpDesk", index);

	NetEvent(1);
	CreateEffect(id, "BoxBRK");
	SetSceneItem(id, "pose", 1, 0);
	SetSceneItem(id, "attribute", "interactive", 0);
	SetSceneItem(id, "attribute", "collision", 0);
	SetSceneItem(itemname, "attribute", "active", 1);
	SetSceneItem(itemname, "attribute", "interactive", 1);
	SetSceneItem(weaponname, "attribute", "active", 1);
	SetSceneItem(weaponname, "attribute", "interactive", 1);
	NetEvent(0);
	
	return 1;
}

RemoveDesk(int id)
{
	int state;
	int pose;
	
	pose = GetSceneItem(id, "pose");
	if ( pose==0 )
	{
		return 0;
	}
	
	state = GetSceneItem(id, "state");
	if ( state!=3 )
	{
		return 0;
	}
	
	NetEvent(1);
	SetSceneItem(id, "attribute", "active", 0);
	NetEvent(0);
	Output("remove item", id);
	return 1;
}

DeskOnIdle(int id, int index)
{
	if ( g_bDeskAlive[index-1] )
	{
		if ( RemoveDesk(id) )
		{
			g_bDeskAlive[index-1]=0;
		}
	}
}

D_Desk01_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 1, damage);
}
D_Desk01_OnIdle(int id)
{
	DeskOnIdle(id, 1);
}

D_Desk02_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 2, damage);
}
D_Desk02_OnIdle(int id)
{
	DeskOnIdle(id, 2);
}

D_Desk03_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 3, damage);
}
D_Desk03_OnIdle(int id)
{
	DeskOnIdle(id, 3);
}

D_Desk04_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 4, damage);
}
D_Desk04_OnIdle(int id)
{
	DeskOnIdle(id, 4);
}

D_Desk05_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 5, damage);
}
D_Desk05_OnIdle(int id)
{
	DeskOnIdle(id, 5);
}

D_Desk06_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 6, damage);
}
D_Desk06_OnIdle(int id)
{
	DeskOnIdle(id, 6);
}

D_Desk07_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 7, damage);
}
D_Desk07_OnIdle(int id)
{
	DeskOnIdle(id, 7);
}

D_Desk08_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 8, damage);
}
D_Desk08_OnIdle(int id)
{
	DeskOnIdle(id, 8);
}

D_Desk09_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 9, damage);
}
D_Desk09_OnIdle(int id)
{
	DeskOnIdle(id, 9);
}

D_Desk10_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 10, damage);
}
D_Desk10_OnIdle(int id)
{
	DeskOnIdle(id, 10);
}

D_Desk11_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 11, damage);
}
D_Desk11_OnIdle(int id)
{
	DeskOnIdle(id, 11);
}

D_Desk12_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 12, damage);
}
D_Desk12_OnIdle(int id)
{
	DeskOnIdle(id, 12);
}

D_Desk13_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 13, damage);
}
D_Desk13_OnIdle(int id)
{
	DeskOnIdle(id, 13);
}

D_Desk14_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 14, damage);
}
D_Desk14_OnIdle(int id)
{
	DeskOnIdle(id, 14);
}

D_Desk15_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 15, damage);
}
D_Desk15_OnIdle(int id)
{
	DeskOnIdle(id, 15);
}

D_Desk16_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 16, damage);
}
D_Desk16_OnIdle(int id)
{
	DeskOnIdle(id, 16);
}

D_Desk17_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 17, damage);
}
D_Desk17_OnIdle(int id)
{
	DeskOnIdle(id, 17);
}

D_Desk18_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 18, damage);
}
D_Desk18_OnIdle(int id)
{
	DeskOnIdle(id, 18);
}

D_Desk19_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 19, damage);
}
D_Desk19_OnIdle(int id)
{
	DeskOnIdle(id, 19);
}

D_Desk20_OnAttack(int id, int character, int damage)
{
	DeskOnAttack(id, 20, damage);
}
D_Desk20_OnIdle(int id)
{
	DeskOnIdle(id, 20);
}
