Integrating Armor into our combat system (Perl)

Integrating Armor into our combat system (Perl)
We now have a way for our users to buy armor, but we haven’t made it so that the armor a user has equipped affects anything – at least, not yet. Today, we’ll be modifying our combat system so that a user’s armor affects the damage they take(just like we did with our weapons system earlier).

Because we’ve already written the stats retrieval code for our armor system, there isn’t much left to do but add the relevant code to forest.cgi:

 

use armorstats;
my @armor = qw(atorso ahead alegs aright aleft);
foreach my $key(@armor) {
	my $id = stats::getStat($key,$userID);
	my $defence = armorstats::getArmorStat('defence',$id);
	$player{defence} += $defence;
}

And that’s actually all there is to it! If you visit the forest page with some armor equipped now, you should notice the defence value of your equipped armor taking effect.

Extra Credit

Make the combat system display all of the modifiers in the fight(e.g. – “5 attack + 5 attack from sword, 2 defense + 3 defense from torso armor”).