Here we have it!
Weapon durability and repairing.
Right now it’s only when you smash another object. All objects can be repaired using the standard tools.
It gives you a very slight chance to damage the weapon based on a number of factors.
This is the code:
[code] if (u.is_armed()) {
// Damage our weapon.
item* damage_weapon = &(u.weapon);
int damage = 10000 / ((u.weapon.weight() + 1) * (u.weapon.volume() / 2 + 1));
if (damage_weapon->made_of(“wood”)) {
damage *= 1.5;
} else if (damage_weapon->made_of(“plastic”)) {
damage *= 1.25;
} else if (damage_weapon->made_of(“glass”)) {
damage *= 2;
}
damage /= u.skillLevel(“melee”).level() / 10 + 1; // Reduce damage based on our skill.
damage *= u.str_cur / 8 + 1; // Change damage based on our strength.
damage /= damage_weapon->damage_bash() / 10 + 1; // Decrease damage based on bashing ability.
int targetweight = 5;
furn_t target = m.furn_at(smashx, smashy);
targetweight = target.move_str_req + 1;
damage *= targetweight;
// Do the roll.
if (rng(0, targetweight * 5) > damage) {
damage_weapon->damage++;
if (damage_weapon->damage > 4) {
add_msg(_("You destroy your%s!"), damage_weapon->tname().c_str());
u.remove_weapon();
}
else {
add_msg(_("You damage your %s!"), damage_weapon->tname().c_str());
}
}
}[/code]
The damage is based on:
Your strength (Higher = takes more. Determines how many times you need to hit to break the object anyway).
The weapon’s weight and volume. (Higher = takes less)
Your weapon’s bashing damage. (Higher = takes less)
The weapon’s material (Wood = 1.5 more likely, plastic = 1.25, glass = 2, everything else has no modifier)
Your melee skill. (Higher = takes less)
The smashable object’s weight (Higher = takes more)
The result is a chance for your weapon to get damaged. It can be repaired with the standard tools and materials just like armour, but not reinforced.
Big heavy metal objects will be better for bashing than small light ones or wood. The solution is to pick up a junk object when you want to smash something.
It also means you can now destroy objects without acid.
Wait.
If your weapon gets damaged, shouldn’t your fists get damaged too?
Why yes!
You’ll take some random damage when you smash an object with your fists, based on your strength and the volume of the object to smash.
Next will be damage from attacking mobs. Bashing weapons will follow the same principle as this but at a severely reduced rate. Cutting weapons will almost never get damaged, piercing weapons too. There will be a higher chance for damage if your weapon gets stuck.
After that, I’ll add firearm durability.