public static void RunItemDecay(NWPlayer player, NWItem item, float reduceAmount) { if (reduceAmount <= 0) { return; } if (player.IsPlot || item.IsPlot || item.GetLocalInt("UNBREAKABLE") == 1 || !item.IsValid || item.BaseItemType == BaseItem.CreatureItem || // Creature skin item.BaseItemType == BaseItem.CreatureBludgeWeapon || // Creature bludgeoning weapon item.BaseItemType == BaseItem.CreaturePierceWeapon || // Creature piercing weapon item.BaseItemType == BaseItem.CreatureSlashWeapon || // Creature slashing weapon item.BaseItemType == BaseItem.CreatureSlashPierceWeapon) // Creature slashing/piercing weapon { return; } float durability = GetDurability(item); string sItemName = item.Name; int apr = NWNXCreature.GetAttacksPerRound(player, true); // Reduce by 0.001 each time it's run. Player only receives notifications when it drops a full point. // I.E: Dropping from 29.001 to 29. // Note that players only see two decimal places in-game on purpose. durability -= reduceAmount / apr; bool displayMessage = Math.Abs(durability % 1) < 0.05f; if (displayMessage) { player.SendMessage(ColorTokenService.Red("Your " + sItemName + " has been damaged. (" + FormatDurability(durability) + " / " + GetMaxDurability(item))); } if (durability <= 0.00f) { item.Destroy(); player.SendMessage(ColorTokenService.Red("Your " + sItemName + " has broken!")); } else { SetDurability(item, durability); } }