I am building a game based on PHP and MySQL. There is a player-vs-player mode but I figured I should add a player-vs-computer mode as well, since players may not be online at all times, especially in the beginning.
It is a combat type of game where players have up to two characters and can fight each other, taking turns.
I decided to save the computer's units on the filesystem instead of in a database. There are different monster camps which players may attack. If multiple players attack the same camp, separate instances are being created.
However what I'm having my doubts about is whether I should save the full unit information in the instance or just the properties that can change in the course of battle. Let me give an example.
Here's the unit class
class Unit {
// Generic
protected $id = null;
public function getID(){ return $this->id; }
public $owner = null;
public $name;
// Vitality
public $HP = 100;
public $HPmax = 100;
public $energy = 100;
public $NRGmax = 100;
// Physical
public $strength = 0;
public $endurance = 0;
// Psychical
public $knowledge = 0;
public $wisdom = 0;
// ...
}
And here's how the file structure looks like
/PvC/prototypes/
/PvC/clones/
in prototypes are saved the preset settings of individual units, while in clones are saved the instances that the players are fighting against currently. How it works at the moment is in clones I save serialize($computer->units)
which inserts the complete full information of the unit. My concern is that some properties, such as name, owner and others, will never change during the battle, so rewriting those each time is pretty pointless. And the instance file is getting rewritten pretty often I'd say, with almost every single request during battle.
In order to avoid that continuous overwriting I could serialize only the properties that can change during battle and then load the unit from the prototype as is, then overwrite that with the properties from the clone. However the problem with that is that I'm loading two files instead of one, then loading a bunch of data from the first file that I won't use, and is going to get overwritten.
I know this is not really something that would matter, as file size will rarely exceed 10kb. What are your thoughts on this?