/*
	PostNukeWasteland Equipment
	Author: NeoPhoenix
*/
#define equip:: equip_
#define MAX_EQUIP_SLOT	(10)

enum
{
	ITEM_ACTION_SLOT,
	WEAPON_SLOT_1,
	WEAPON_SLOT_2,
	BACKPACK_SLOT,
	BLEEDING_SLOT,
	EQUIPMENT_SLOT,
	COSMETIC_HAT,
	COSMETIC_MASK,
	COSMETIC_GLASSES,
	COSMETIC_BODY,
}

enum (+=1)
{
	None = 0,
	Spine,
	Head,
	LeftUpperArm,
	RightUpperArm,
	LeftHand,
	RightHand,
	LeftThigh,
	RightThigh,
	LeftFoot,
	RightFoot,
	RightCalf,
	LeftCalf,
	LeftForearm,
	RightForearm,
	LeftClavicle,
	RightClavicle,
	Neck,
	Jaw
}

enum enum_equip
{
	bool:eInUse,
	eModelID,
	eBoneID,
	eItemID,
}
new PlayerEquip[MAX_PLAYERS][MAX_EQUIP_SLOT][enum_equip];

equip::ResetEquipment(playerid)
{
	for(new i; i<MAX_EQUIP_SLOT; i++)
	{
		if(PlayerEquip[playerid][i][eInUse])
		{
			equip::RemoveSlot(playerid,i);
		}
	}
	return 1;
}

stock equip::RemoveSlot(playerid,slotid)
{
	if(!(slotid >= 0 && slotid < MAX_EQUIP_SLOT)) return 0;
	if(PlayerEquip[playerid][slotid][eInUse])
	{
		if(IsPlayerAttachedObjectSlotUsed(playerid,slotid))	RemovePlayerAttachedObject(playerid,slotid);
		PlayerEquip[playerid][slotid][eInUse]	= false;
		PlayerEquip[playerid][slotid][eModelID]	= 0;
		PlayerEquip[playerid][slotid][eBoneID]	= 0;
	}
	return 1;
}

stock equip::UseEquipment(playerid,modelid,bone,Float:fOffsetX=0.0,Float:fOffsetY=0.0,Float:fOffsetZ=0.0,Float:fRotX=0.0,Float:fRotY=0.0,Float:fRotZ=0.0,Float:fScaleX=1.0,Float:fScaleY=1.0,Float:fScaleZ=1.0,materialcolor1=0,materialcolor2=0,oslot=-1,itemID=0)
{
	if(oslot != -1)
	{
		if(IsPlayerAttachedObjectSlotUsed(playerid,oslot)) equip::RemoveSlot(playerid,oslot);
		SetPlayerAttachedObject(playerid,oslot,modelid,bone,fOffsetX,fOffsetY,fOffsetZ,fRotX,fRotY,fRotZ,fScaleX,fScaleY,fScaleZ,materialcolor1,materialcolor2);
		PlayerEquip[playerid][oslot][eInUse]	= true;
		PlayerEquip[playerid][oslot][eModelID]	= modelid;
		PlayerEquip[playerid][oslot][eBoneID]	= bone;
		PlayerEquip[playerid][oslot][eItemID]	= itemID;
		return oslot;
	}
	return -1;
}

stock equip::HasInUse(playerid,modelid=-1,boneid=-1,cosmetic_id=-1)
{
	for(new i; i<MAX_EQUIP_SLOT; i++) 
	{
		if(PlayerEquip[playerid][i][eInUse] && (cosmetic_id == -1 || cosmetic_id == i) && (modelid == -1 || (modelid == PlayerEquip[playerid][i][eModelID])) && (boneid == -1 || (boneid == PlayerEquip[playerid][i][eBoneID]))) return i;
	}
	return -1;
}

stock equip::CopyEquipment(playerid,str[],size=sizeof(str))
{
	format(str,size,"");
	for(new i; i<MAX_EQUIP_SLOT; i++)
	{
		if(i >= size) return 0;
        str[i] = PlayerEquip[playerid][i][eInUse]?PlayerEquip[playerid][i][eModelID]:0;
	}
	return 1;
}

stock equip::UpdateWeapons(playerid)
{
	equip::RemoveSlot(playerid,WEAPON_SLOT_1);
	equip::RemoveSlot(playerid,WEAPON_SLOT_2);
	if(PlayerWeapon[playerid][2][wWeaponID] > 0 && PlayerCurrentWeaponSlot[playerid] != 2) equip::UseEquipment(playerid,WeaponInfo[PlayerWeapon[playerid][2][wWeaponID]][wObjectID],RightThigh,0.0619,0.0088,0.1367,254.8748,0.3184,0.1764,.oslot=WEAPON_SLOT_1);
	if(PlayerWeapon[playerid][3][wWeaponID] > 0 && PlayerCurrentWeaponSlot[playerid] != 3) equip::UseEquipment(playerid,WeaponInfo[PlayerWeapon[playerid][3][wWeaponID]][wObjectID],RightThigh,0.0619,0.0088,0.1367,254.8748,0.3184,0.1764,.oslot=WEAPON_SLOT_2);
	return 1;
}