;'HS - Repair Item'

;Human Soldier, class only skill. Repairs armor and weapons.
;Takes item number 30, "Repair Supplies", to repair something.

RepairSupplies = 30

If GetUserAccess(#USERID) < 5
	;Only Human Soldiers can use this skill
	If GetUserClass(#USERID) <> 0
		Goto END
	EndIf
EndIf

If HasItem(#USERID,RepairSupplies) = 0
	SendMessageToUser(#USERID,"You need some Repair Supplies to repair a item.",#MSG_SAY)
	GoTo END
EndIf

MSG=Lower(GetUserMessage(#USERID))

ItemID=0
InvItemID=0

If MSG="armor"
	InvItemID = GetUserEquippedArmor(#USERID)
	If InvItemID > -1
		ItemID = GetUserInvItem(#USERID,InvItemID)
	Else
		SendMessageToUser(#USERID,"You don't have any armor equipped.",#MSG_SAY)
		GoTo END
	EndIf
ElseIf MSG="weapon"
	InvItemID = GetUserEquippedWeapon(#USERID)
	If InvItemID > -1
		ItemID = GetUserInvItem(#USERID,InvItemID)
	Else
		SendMessageToUser(#USERID,"You don't have a weapon equipped.",#MSG_SAY)
		GoTo END
	EndIf
Else
	SendMessageToUser(#USERID,"Repair your equipped [weapon], or equipped [armor]?",#MSG_SAY)
	GoTo END
EndIf

ItemDur=GetItemDurability(#USERID,InvItemID)
ItemMaxDur=GetItemFlag2(ItemID)

If ItemDur = -1
	SendMessageToUser(#USERID,"This item is unbreakable, you can't repair it.",#MSG_SAY)
	GoTo END
EndIf
If ItemDur > ItemMaxDur-1
	Ratio=ItemDur/ItemMaxDur
	Ratio=Ratio*100
	Percentage=Floor(Ratio+0.5)
	SendMessageToUser(#USERID,GetItemName(ItemID)+" is at "+Percentage+"% durability.",#MSG_SAY)
	SendMessageToUser(#USERID,"This item is in perfect condition, you can't repair it.",#MSG_SAY)
	GoTo END
EndIf

TakeItem(#USERID,RepairSupplies)

ItemDur = ItemDur + 100
If ItemDur > ItemMaxDur
	ItemDur = ItemMaxDur
EndIf

SetItemDurability(#USERID,InvItemID,ItemDur)
Ratio=ItemDur/ItemMaxDur
Ratio=Ratio*100
Percentage=Floor(Ratio+0.5)
SendMessageToUser(#USERID,GetItemName(ItemID)+" is at "+Percentage+"% durability.",#MSG_SAY)
SendMessageToUser(#USERID,"You repair the "+GetItemName(ItemID)+".",#MSG_EMOTE)

Label END

Continue = 1