I have a question about the internal system that organizes all the predefined items within a RPG game.
For example, where do developers store all their predefined items such as "Potions", "Antidotes", "Buster Sword", "Cursed Ring". Or are they all hard coded into the game along with all the game code?
RPG Items
almost certainly in some external data file. hard coding any values or data into the actual code and therefore the compiled executable is the bane of my existence
Instances of an item should all be external.
You might have hard coded types like ring or potion. But then have a DB or data file that contains all the instance of those like healing potion, mana potion, etc..
There is also an argument for making even you types configurable outside of code, using a scripting language.
You might have hard coded types like ring or potion. But then have a DB or data file that contains all the instance of those like healing potion, mana potion, etc..
There is also an argument for making even you types configurable outside of code, using a scripting language.
Writing Blog: The Aspiring Writer
Novels:
Legacy - Black Prince Saga Book One - By Alexander Ballard (Free this week)
It really depends on the setup. If you have a lot of items, the best method would probably be to store the raw data of the item inside a database, then have a class (such as potion, sword, whatever) that takes in a row from that database and modifies the fighter the class.
For example:
Table Items would have:
ID | Name | HP Recover | MP Recover | AtkUp | DefUp | Cost
You could then have a class like:
class item{
function __constructor($ItemID)
{
$A = get_from_database_where_id=$ID;
$this->Name = $A['Name'];
$this->HPR = $A['HP Recover'];
... etc
}
function heal_hp($Fighter)
{
$Fighter['HP'] += $this->HPR;
}
etc...
function use_item($Fighter))
{
$this->heal_hp($Fighter);
$this->heal_mp($Fighter);
$this->atk_up($Fighter);
etc...
}
}
in your code, you'd call:
$Item = new item($ID);
$Item->use_item($FighterClass);
This way, if you 'use an item' on the fighter, it will update his stats with the abilities from the databse.
Sorry in advance if this code is sloppy. I'm on my way out the door and had about 3 minutes to write it.
For example:
Table Items would have:
ID | Name | HP Recover | MP Recover | AtkUp | DefUp | Cost
You could then have a class like:
class item{
function __constructor($ItemID)
{
$A = get_from_database_where_id=$ID;
$this->Name = $A['Name'];
$this->HPR = $A['HP Recover'];
... etc
}
function heal_hp($Fighter)
{
$Fighter['HP'] += $this->HPR;
}
etc...
function use_item($Fighter))
{
$this->heal_hp($Fighter);
$this->heal_mp($Fighter);
$this->atk_up($Fighter);
etc...
}
}
in your code, you'd call:
$Item = new item($ID);
$Item->use_item($FighterClass);
This way, if you 'use an item' on the fighter, it will update his stats with the abilities from the databse.
Sorry in advance if this code is sloppy. I'm on my way out the door and had about 3 minutes to write it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement