void CUser::ItemWoreOut(int type, int damage)
{
static uint8 weaponsTypes[] = {RIGHTHAND, LEFTHAND};
static uint8 armourTypes[] = {HEAD, BREAST, LEG, GLOVE, FOOT};
static uint8 repairTypes[] = { RIGHTHAND, LEFTHAND, HEAD, BREAST, LEG, GLOVE, FOOT };
uint8 totalSlots;
int worerate;
if (type == ACID_ALL)
worerate = damage;
else
worerate = (int)sqrt(damage / 10.0f);
if (worerate == 0) return;
ASSERT(type == ATTACK || type == DEFENCE || type == REPAIR_ALL || type == ACID_ALL);
// Inflict damage on equipped weapons.
if (type == ATTACK)
totalSlots = sizeof(weaponsTypes) / sizeof(*weaponsTypes); // use all the slots.
// Inflict damage on equipped armour.
else if (type == DEFENCE)
totalSlots = sizeof(armourTypes) / sizeof(*armourTypes); // use all the slots.
// Item repair all slots.
else if (type == REPAIR_ALL)
totalSlots = sizeof(repairTypes) / sizeof(*repairTypes);
// Item acid all slots.
else if (type == ACID_ALL)
totalSlots = sizeof(armourTypes) / sizeof(*armourTypes);
for (uint8 i = 0; i < totalSlots; i++)
{
uint8 slot;
if (type == ATTACK)
slot = weaponsTypes;
else if (type == DEFENCE)
slot = armourTypes;
else if (type == REPAIR_ALL)
slot = repairTypes;
else
slot = armourTypes;
_ITEM_DATA * pItem = GetItem(slot);
_ITEM_TABLE * pTable = nullptr;
// Is a non-broken item equipped?
if (pItem == nullptr
|| (pItem->sDuration <= 0 && type != REPAIR_ALL)
// Does the item exist?
|| (pTable = g_pMain->GetItemPtr(pItem->nNum)) == nullptr
// If it's in the left or righthand slot, is it a shield? (this doesn't apply to weapons)
|| (type == ATTACK
&& ((slot == LEFTHAND || slot == RIGHTHAND) && pTable->m_bSlot == ItemSlot1HLeftHand)))
continue;
if (type == REPAIR_ALL)
{
pItem->sDuration = pTable->m_sDuration;
SendDurability(slot, pItem->sDuration);
UserLookChange(slot, pItem->nNum, pItem->sDuration);
SetUserAbility(true);
continue;
}
int beforepercent = (int)((pItem->sDuration / (double)pTable->m_sDuration) * 100);
int curpercent;
if (worerate > pItem->sDuration)
pItem->sDuration = 0;
else
pItem->sDuration -= worerate;
if (m_sItemArray[slot].sDuration == 0)
{
SendDurability(slot, 0);
SetUserAbility(false);
SendItemMove(1);
continue;
}
SendDurability(slot, pItem->sDuration);
curpercent = (int)((pItem->sDuration / (double)pTable->m_sDuration) * 100);
if ((curpercent / 5) != (beforepercent / 5))
{
if (curpercent >= 65 && curpercent < 70
|| curpercent >= 25 && curpercent < 30)
UserLookChange(slot, pItem->nNum, pItem->sDuration);
}
}
}