Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Merc {
- //Shared stats
- protected static $i_hp = NULL;
- protected static $i_skill = NULL;
- protected static $i_strength = NULL;
- protected static $i_endurance = NULL;
- //Local
- protected $s_name = "Nemo";
- protected $s_race = "Unknown";
- protected $s_faction = "No allegiance";
- protected $i_level = 0;
- protected $i_xp = 0;
- protected $a_traits = [];
- protected $a_skills = [];
- protected $a_inventory = [];
- //Buff storage... May create a dedicated buff class to smoothen this process..
- protected $a_buffs = ["hp" => [],
- "skill" => [],
- "strength" => [],
- "endurance" => []];
- //Main accessor method to class properties (many of which will be faily dynamic)
- public function __get($_prop) {
- switch($_prop) {
- //Local
- case "Name":
- return $this->s_name;
- case "Race":
- return $this->s_race; //Will load proper race name from file, eventually..
- case "Faction":
- return $this->s_faction; //Pondering similar treatmeant for faction as race^
- case "Level":
- return $this->i_level;
- case "XP":
- return $this->i_xp;
- case "XPGoal": //--This algorithm doesn't really want to live here!--
- return 100 + (((($this->i_level / 2) + 0.5) * $this->i_level) * 10);
- //Ad-hoc (most probably very temporary) output for array data...
- case "Traits":
- $str = "";
- foreach($this->a_traits as $trait) {
- $str .= "$trait, ";
- }
- return rtrim($str, ", ");
- //case "":
- //case "":
- //Shared stats (at least until modifiers work)
- case "HP":
- return self::getStat("hp");
- case "Skill":
- return self::getStat("skill");
- case "Strength":
- return self::getStat("strength");
- case "Endurance":
- return self::getStat("endurance");
- //case "":
- default:
- throw new Exception("Unknown property: $_prop. (N.B. Need to fix exception type)");
- }
- }
- //--------------------------------[Main accessor END]--------------------------------
- //Constructor(s)...
- public function __construct($_file) {
- $json = file_get_contents($_file);
- $json = json_decode($json);
- $this->s_name = $json->merc->name;
- $this->s_race = $json->merc->race;
- $this->s_faction = $json->merc->faction;
- $this->i_level = $json->merc->level;
- $this->i_xp = $json->merc->xp;
- $this->a_traits = $json->merc->traits;
- //$this->a_ = $json->merc->;
- }
- //---------------------------------[Constructor END]---------------------------------
- //--Register buff method - protected or public..?
- public function registerBuff($_name, $_buff, $_stat = "hp"/*(/etc..?)*/) {
- //pending data structure..
- $this->a_buffs[$_stat] += [$_name => $_buff];
- print_r($this->a_buffs);
- }
- //--------------------------------[Buff Register END]---------------------------------
- //Access function for shared stats to make sure they're loaded when called for
- public static function getStat($_stat) {
- if(self::$i_hp === NULL || self::$i_skill === NULL ||
- self::$i_strength === NULL || self::$i_endurance === NULL) {
- //Load base stats here! =D
- $stats = json_decode(file_get_contents("BaseStatsMerc.json"));
- self::$i_hp = $stats->stats->hp;
- self::$i_skill = $stats->stats->skill;
- self::$i_strength = $stats->stats->strength;
- self::$i_endurance = $stats->stats->endurance;
- }
- switch($_stat) {
- case "hp":
- return self::$i_hp;
- case "skill":
- return self::$i_skill;
- case "strength":
- return self::$i_strength;
- case "endurance":
- return self::$i_endurance;
- default:
- throw new DomainException("Request for nonexistant stat: $_stat");
- }
- }
- //-----------------------------[Shared stat accessor END]----------------------------
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement