public function Setup() { $data = MorpheusPetsData::getInstance(); if ($this->setup != 1) { //session_start(); $_SESSION['enemy'] = 2; $_SESSION['user'] = 1; if (isset($_SESSION['user'])) { $this->user = $_SESSION['user']; } if (isset($_SESSION['enemy'])) { $this->enemy = $_SESSION['enemy']; } $this->enemy_team = $data->getActivePetsForUser($this->enemy); $this->user_team = $data->getActivePetsForUser($this->user); $this->activePet = 0; $this->activeEnemyPet = 0; $this->user_health = []; $this->enemy_health = []; for ($x = 0; $x < 3; $x++) { $user_pet = $this->user_team[$x]; $pet_health = $this->createHealth($user_pet); $this->user_health[$x] = array($pet_health, $pet_health); $enemy_pet = $this->enemy_team[$x]; $e_pet_health = $this->createHealth($enemy_pet); $this->enemy_health[$x] = array($e_pet_health, $e_pet_health); } //echo "Setting up"; $this->setup = 1; } }
/** * Profile_ViewModel constructor. */ public function __construct($user, $profileUser) { parent::__construct(); $this->logged_in_user = $user; $this->profile_user = $profileUser; $this->data = MorpheusPetsData::getInstance(); }
/** * Battle_ViewModel constructor. */ public function __construct($user) { parent::__construct(); $this->logged_in_user = $user; $this->data = MorpheusPetsData::getInstance(); $this->battle = new Battle(); }
public function checkLevelUp($exp_gain) { $orig_exp = 0; $ret = ""; for ($x = 0; $x < 3; $x++) { $orig_exp = $this->user_team[$x]->getExperience(); //get the old exp value $orig_level = floor($orig_exp / 100) + 1; //get the old level $new_exp = $orig_exp + $exp_gain; //add the gained exp to get the new exp value $new_level = floor($new_exp / 100) + 1; //get the new level if ($new_level > $orig_level) { //if the pet leveled up $ret = $ret . "<br /><br />" . $this->user_team[$x]->getName() . " leveled up, and is now level " . strval(floor($new_exp / 100) + 1) . "!"; //level up procedure $statincrease = [0, 0, 0, 0, 0, 0]; //one per stat $points = 21; //6 + 5 + ... + 1. $species = $this->user_team[$x]->getSpecies(); //gets the species of the pet leveling up $priority = $species->getStats(); //gets the species' stat priority for ($i = 0; $i < 6; $i++) { //for all six stats $spent = rand(1, 6 - $i); //pick a number between 1 and a decreasing max $statincrease[$i] = $spent; //this number is how much the stat will increase $points -= $spent; //take it off of the lvlup points total } while ($points > 0) { //If there are (maybe still) points left over for ($i = 5; $i >= 0; $i--) { //Counts down, we're increasing the stats in reverse order to make it slightly more even if ($points > 0) { //just in case we run out during the loop $statincrease[$i]++; $points--; } } } for ($curstat = 0; $curstat < 6; $curstat++) { //echo $priority[$curstat]; switch ($priority[$curstat]) { case 'b': $this->user_team[$x]->setBrawn($this->user_team[$x]->getBrawn() + $statincrease[$curstat]); break; case 'g': $this->user_team[$x]->setGuts($this->user_team[$x]->getGuts() + $statincrease[$curstat]); break; case 'e': $this->user_team[$x]->setEssence($this->user_team[$x]->getEssence() + $statincrease[$curstat]); break; case 's': $this->user_team[$x]->setSpeed($this->user_team[$x]->getSpeed() + $statincrease[$curstat]); break; case 'f': $this->user_team[$x]->setFocus($this->user_team[$x]->getFocus() + $statincrease[$curstat]); break; case 'r': $this->user_team[$x]->setGrit($this->user_team[$x]->getGrit() + $statincrease[$curstat]); break; } } } //regardless of level up or not $this->user_team[$x]->setExperience($new_exp); //set the new exp value //update pet $data = MorpheusPetsData::getInstance(); $data->updatepet($this->user_team[$x]); } return $ret; }
<?php require_once 'viewmodels/PetViewer_ViewModel.php'; require_once 'viewmodels/Error_ViewModel.php'; require_once 'data/UserSession.php'; require_once 'data/data.php'; // GET keys $pet_id_key = "pet_id"; $session = UserSession::getInstance(); $data = MorpheusPetsData::getInstance(); $pet_id = null; $pet_to_show = null; // Get a pet if a pet id was specified if (isset($_GET[$pet_id_key])) { $pet_id = intval($_GET[$pet_id_key]); $pet_to_show = $data->getPet($pet_id); } if ($pet_to_show !== null) { // Create view model $view_model = new PetViewer_ViewModel($pet_to_show); // Add logged in user if such exists if ($session->isUserLoggedIn()) { $logged_in_user = $session->getLoggedInUser(); $view_model->setLoggedInUser($logged_in_user); } $view_model->renderPet(); } else { // Pet does not exist $view_model = new Error_ViewModel(); $view_model->renderPetNotExist($pet_id); }
/** * UserSession constructor. * Starts a PHP session */ private function __construct() { $this->data = MorpheusPetsData::getInstance(); $this->startSession(); }
/** * @return MorpheusPetsData The single shared instance */ public static function getInstance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
/** * User_ViewModel constructor. */ public function __construct() { parent::__construct(); $this->data = MorpheusPetsData::getInstance(); }