Jump to content

Yes, another "Halp me w/ my RPG plz" post


KevinM1

Recommended Posts

Okay, so like virtually every young wannabe PHP developer, I'm attempting to make my own web-based RPG.  Right now I'm still in the planning stage, so feel free to move this to the App Design forum if need be.

 

Right now, my biggest stumbling block is handling different weapon abilities.  Say I have a basic weapon type of Firearm:

abstract class Firearm
{
   private $ammoType; //obvious
   private $ammoAmount; //number of bullets/shells/whatever per reload
   private $shotType = "single"; //single shot, burst, or full-auto
   private $baseDmg = 5;
   private $maxRng = 50;

   abstract function getShotType();
   abstract function getBaseDmg();
   abstract function getMaxRng();
}

 

And a generic decorator setup:

abstract class FirearmDecorator extends Firearm
{
   protected $firearm;

   public function __construct($firearm)
   {
      $this->firearm = $firearm;
   }
}

class Glock extends FirearmDectorator
{
   public function getShotType()
   {
      return $this->firearm->shotType;
   }

   public function getBaseDmg()
   {
      return $this->firearm->baseDmg * 1.25;
   }

   public function getMaxRng()
   {
      return $this->firearm->maxRng * 0.75;
   }
}

 

What could/should I do if I wanted to add a special attack for each concrete weapon?  Or, even better, based on a character's skills?  So, say my Glock has an attack that increases accuracy, or my character has trained in something that causes splash damage to other enemies?  I'm thinking that some sort of strategy object (or objects, depending on the number of special attacks available) would be the way to go, but I'm having difficulty seeing how to implement it cleanly.

 

Any ideas?

Link to comment
Share on other sites

Normally RPG's user Modifiers, Multipliers, etc.

 

As for code layout, I'll think of something and post.

 

Quick Edit: You might want to look at the Quake 3 Source code or SDK. It has a lot of information on how their weapons are implemented. It's written in c++ but the syntax should be readable.

Link to comment
Share on other sites

Normally RPG's user Modifiers, Multipliers, etc.

 

As for code layout, I'll think of something and post.

 

Quick Edit: You might want to look at the Quake 3 Source code or SDK. It has a lot of information on how their weapons are implemented. It's written in c++ but the syntax should be readable.

 

Thanks, looks like a few google/wiki searches for those patterns and the code you mentioned are in order! :)

 

Ninja Edit: Unfortunately, neither Google nor Wikipedia have info on those two patterns you mentioned, at least, none that I can see.  I am downloading the Quake III source code now.

Link to comment
Share on other sites

They weren't patterns per se, just a lot of math and each 'effect' having some multiplier for certain abilities.

 

So, something along the lines of my decorators' functions?  Or something (and most likely) more complex than that?

Link to comment
Share on other sites

You'll see when you look at the source.

 

Basically there's a Weapon base class and each Weapon has special properties (damage, speed, knock back, splash radius, texture, etc) and you can get modifiers to globally increase damage/knockback (quad) speed (haste.)

 

 

Link to comment
Share on other sites

You'll see when you look at the source.

 

Basically there's a Weapon base class and each Weapon has special properties (damage, speed, knock back, splash radius, texture, etc) and you can get modifiers to globally increase damage/knockback (quad) speed (haste.)

 

Hmm...I don't see much difference between using a decorator and doing what ID did.  I mean, in Q3, each weapon has concrete properties which are modified by a power-up, or if the user is using the mission pack.  They have the benefit of hard-coding these attributes directly as they only had, what, 10 weapons and a few power-ups? 

 

Since I'm making an RPG, where loot is important, I think that item/weapon creation flexibility is paramount.  Modifyers/multipliers are still in play, but in order to come up with a loot algorithm, I think I'd want to be able to create new item combinations on the fly.

 

In other words, killing Generic Goblin #1 gives the player a 45% chance of obtaining a sword.  What kind of sword is calculated further...maybe a 70% chance of a short sword, and a 2% chance that it has some minor magical property.  So, after my calculations, I could simply write:

abstract class Sword {}

abstract class SwordDeco extends Sword
{
   protected $sword;

   public function __construct($sword)
   {
      $this->sword = $sword;
   }
}

class ShortSword extends Sword {}

$player->attack($goblin);

if(isDead($goblin))
{
   //calculate loot...in this case, $player receives a new short sword

   $player->obtain(new $loot());
}

 

Obviously, this isn't fleshed out at all, but the general idea is there.

 

Does this seem like the right way to go?  The other (and probably more efficient) way to go would probably be to have a loot database that my script can look-up once a monster is killed.  My only concern with that is having a ton of inflexible child objects that are referenced by the DB.  It just seems inelegant to do that.

Link to comment
Share on other sites

I've started writing a game also and I've came to the conclusion MySQL backing is critical.

 

I have over 20 tables so far for my game some are

 

Users (The user account data)

User characters (the users characters in game)

Character_Classes (generic character clas smodifiers)

Items (Generic list of all items ItemID ItemType ItemRarity etc.)

Char_Location (Character's position in map)

Map (X,Y Cords and their tiles)

Map_Tiles (Gives backing to map tiles)

 

There are a ton more.

 

Writing  an abstract for each weapon/armor/character is sorta over kill let the SQL handle all that and instead all the glock to load into the weapon class or even use an extension on to weapon class as "guns" which help guide the sql a bit more. 

 

Doing that gives you a ton more flexibility so on the fly you can add weapons and modifiers through a control panel without modifying active php documents.  When you have 10 thousand users playing your game you want to keep it stable as possible.

 

If u want to see a dump of my database let me know

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.