KevinM1 Posted July 7, 2008 Share Posted July 7, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/113593-yes-another-halp-me-w-my-rpg-plz-post/ Share on other sites More sharing options...
keeB Posted July 7, 2008 Share Posted July 7, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/113593-yes-another-halp-me-w-my-rpg-plz-post/#findComment-583750 Share on other sites More sharing options...
KevinM1 Posted July 7, 2008 Author Share Posted July 7, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/113593-yes-another-halp-me-w-my-rpg-plz-post/#findComment-583752 Share on other sites More sharing options...
keeB Posted July 7, 2008 Share Posted July 7, 2008 They weren't patterns per se, just a lot of math and each 'effect' having some multiplier for certain abilities. Quote Link to comment https://forums.phpfreaks.com/topic/113593-yes-another-halp-me-w-my-rpg-plz-post/#findComment-583762 Share on other sites More sharing options...
KevinM1 Posted July 7, 2008 Author Share Posted July 7, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/113593-yes-another-halp-me-w-my-rpg-plz-post/#findComment-583784 Share on other sites More sharing options...
keeB Posted July 7, 2008 Share Posted July 7, 2008 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.) Quote Link to comment https://forums.phpfreaks.com/topic/113593-yes-another-halp-me-w-my-rpg-plz-post/#findComment-583895 Share on other sites More sharing options...
KevinM1 Posted July 8, 2008 Author Share Posted July 8, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/113593-yes-another-halp-me-w-my-rpg-plz-post/#findComment-584537 Share on other sites More sharing options...
keeB Posted July 9, 2008 Share Posted July 9, 2008 Loot database is the way to go, imo. A'la Blizzard/World of Warcraft. Your decorators will do well. Let us know how it goes. Quote Link to comment https://forums.phpfreaks.com/topic/113593-yes-another-halp-me-w-my-rpg-plz-post/#findComment-585060 Share on other sites More sharing options...
cooldude832 Posted July 9, 2008 Share Posted July 9, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/113593-yes-another-halp-me-w-my-rpg-plz-post/#findComment-585065 Share on other sites More sharing options...
KevinM1 Posted July 9, 2008 Author Share Posted July 9, 2008 I would like to see it. You may want to send it via private message, though, depending on the size of things. Quote Link to comment https://forums.phpfreaks.com/topic/113593-yes-another-halp-me-w-my-rpg-plz-post/#findComment-585245 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.