I'm making a text-based role playing game written in PHP.
I have a hard time figuring out how to handle items in game - there will be a few types of objects (weapon, machine, tool, building etc) each of these types will have its own stats, attributes etc, and items itself.
My initial plan was to make a interface and abstract class called Object
interface IObject
{
public function takeObject() {};
public function dropObject() {};
public function examineObject() {};
// etc
}
abstract class WeaponObject implements IObject
{
// Some generic properties valid for this type of objects
public $name = "";
public $weight = 0;
public $damage = 0;
// etc
}
and then make another class for each item that extends the base Object
e.g
class HuntingBow extends WeaponObject
{
//
}
But there's a problem I think. There's going to be a lot of objects in the game - and that means a lot of classes, and composer need to load them all. So I think that performance may decrease significantly?
My second idea was to make a generic table called objects
In which I would store every item. But setting up object attributes, handling stats, etc, would be a nightmare.
Is the first idea the best way to approach the problem? Is there a better way of doing thins that I don't about?