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:

37
38
39
40
41
42
43
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”).

Wish there was more?

I'm considering writing an ebook - click here.

.

Luke is the primary editor of Building Browsergames, and has written a large portion of the articles that you read here. He generally has no idea what to say when asked to write about himself in the third person.

Tags: , ,

Tuesday, September 30th, 2008 buildingbrowsergames, medieval
blog comments powered by Disqus

About

Building Browsergames is a blog about browsergames(also known as PBBG's). It's geared towards the beginner to intermediate developer who has an interest in building their own browsergame.

Sponsors

Got Something to Say?

Send an e-mail to luke@buildingbrowsergames.com, or get in touch through Twitter at http://twitter.com/bbrowsergames