public function run() { $character = new Character(); $character->name = 'Ellerion'; $character->class = 'Mage'; $character->race = 'Human'; $character->realm = 'Darkspear'; $character->file = ''; $character->save(); }
public function storeCharacter() { $character = new Character(); $character->name = Input::get('name'); $character->class = Input::get('class'); $character->realm = Input::get('realm'); $character->file = Input::get('file'); $character->race = Input::get('race'); $character->save(); return Redirect::action('ItemsController@index'); }
function character_post() { if (!$this->post('name') || !$this->post('campaign')) { $this->response(NULL, 400); } // Only allow new/edit characters when a user is logged in if (!$this->user->exists()) { $this->response(NULL, 401); } if (!$this->post('id')) { // New character $character = new Character(); $character->player_id = $this->user->id; } else { // Edit character $character = new Character($this->post('id')); } $character->name = $this->post('name'); $character->number = $this->post('number'); $character->level = $this->post('level'); $character->faction = $this->post('faction'); $character->class = $this->post('class'); $character->campaign = $this->post('campaign'); $character->save(); $this->response(NULL, 200); }
if ($_FILES) { $uploads_directory = 'img/uploads/'; $filename = $uploads_directory . basename($_FILES['file']['name']); if (move_uploaded_file($_FILES['file']['tmp_name'], $filename)) { echo '<p> The file ' . basename($_FILES['file']['name']) . ' has been uploaded</p>'; } else { echo "Sorry, there was an error uploading your file."; } } $create_character = new Character(); $create_character->name = Input::get('name'); $create_character->realm = Input::get('realm'); $create_character->class = Input::get('class'); $create_character->race = Input::get('race'); $create_character->character_img = $filename; $create_character->save(); } ?> <!DOCTYPE html> <html> <head> <title>Character Creation</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> <link rel="stylesheet" href="/css/main.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <style> body {
public function transferExperience(Character $to) { $from = Character::find(Input::get("from")); if ($from != null && $to != null) { $to->experience += $from->availableExperience(); $from->experience -= $from->availableExperience(); $to->save(); $from->save(); Cache::forget("character-experience-" . $to->id); Cache::forget("character-experience-" . $from->id); return Redirect::to("dashboard/storyteller/characters"); } else { return Response::json(['success' => false, 'message' => 'Invalid data.']); } }
/** * Moves a character in a specific direction. * * @param string|int direction or area_id where character is heading * * @return redirects to /game/maps, even if the character isn't moved. */ function game_move($direction = null) { if (!isset($direction) && empty($direction)) { $this->redirect('/game/maps'); } $updateModels = array('Character'); $this->Area->contain(); $conditions = array('Area.id' => $this->characterInfo['area_id']); $currentArea = $this->Area->find('first', array('conditions' => $conditions)); $conditions = array(); $conditions['Area.access'] = 1; switch ($direction) { case "left": if ($currentArea['Area']['restriction'] == 'left') { $this->redirect('/game/maps'); exit; } $conditions['Area.map_id'] = $currentArea['Area']['map_id']; $conditions['Area.x'] = $currentArea['Area']['x'] - 1; $conditions['Area.y'] = $currentArea['Area']['y']; break; case "right": if ($currentArea['Area']['restriction'] == 'right') { $this->redirect('/game/maps'); exit; } $conditions['Area.map_id'] = $currentArea['Area']['map_id']; $conditions['Area.x'] = $currentArea['Area']['x'] + 1; $conditions['Area.y'] = $currentArea['Area']['y']; break; case "up": if ($currentArea['Area']['restriction'] == 'up') { $this->redirect('/game/maps'); exit; } $conditions['Area.map_id'] = $currentArea['Area']['map_id']; $conditions['Area.y'] = $currentArea['Area']['y'] - 1; $conditions['Area.x'] = $currentArea['Area']['x']; break; case "down": if ($currentArea['Area']['restriction'] == 'down') { $this->redirect('/game/maps'); exit; } $conditions['Area.map_id'] = $currentArea['Area']['map_id']; $conditions['Area.y'] = $currentArea['Area']['y'] + 1; $conditions['Area.x'] = $currentArea['Area']['x']; break; default: if ($direction == $currentArea['Area']['travel_to']) { $conditions['Area.id'] = $currentArea['Area']['travel_to']; $direction = $this->characterInfo['last_move']; $updateModels[] = 'Map'; } } $areaTo = $this->Area->find('first', array('conditions' => $conditions)); if (!empty($areaTo)) { $data['Character']['id'] = $this->characterInfo['id']; $data['Character']['area_id'] = $areaTo['Area']['id']; $data['Character']['last_move'] = $direction; App::import('Model', 'Character'); $Character = new Character(); $Character->save($data['Character'], array('validate' => false)); $this->updateGame($updateModels); } $this->redirect('/game/maps'); }
function testGetSkills() { //Arrange $description_id = 1; $race_id = 1; $stat_id = 1; $test_character = new Character($description_id, $race_id, $stat_id); $test_character->save(); $name = "Acrobatics"; $description = "stuff"; $id = 1; $test_skill = new Skill($name, $description, $id); $test_skill->save(); $name2 = "Athletics"; $description2 = "other stuff"; $id2 = 2; $test_skill2 = new Skill($name2, $description2, $id2); $test_skill2->save(); //Act $test_character->addSkill($test_skill); $test_character->addSkill($test_skill2); //Assert $this->assertEquals($test_character->getSkills(), [$test_skill, $test_skill2]); }
static function run() { // DESCRIPTION : $description = new Description($_SESSION['name'], $_SESSION['gender'], $_SESSION['age'], $_SESSION['alignment'], $_SESSION['height'], $_SESSION['eye_color'], $_SESSION['hair_color'], $_SESSION['skin_tone'], $_SESSION['other'], null); $description->save(); $description_id = $description->getId(); // STAT VARIABLES : $dex = $_SESSION['dex']; $dex_mod = Stat::getModifier($dex); $con = $_SESSION['con']; $con_mod = Stat::getModifier($con); $str = $_SESSION['str']; $str_mod = Stat::getModifier($str); $wis = $_SESSION['wis']; $wis_mod = Stat::getModifier($wis); $int = $_SESSION['int']; $int_mod = Stat::getModifier($int); $cha = $_SESSION['cha']; $cha_mod = Stat::getModifier($cha); $initiative = $dex_mod; // MAKES A CLASS VARIABLE, MAXHP, AC, BACKGROUND ID : if ($_SESSION['class'] == 1) { $class = "cleric"; $class_hp = 8; $class_id = 1; } elseif ($_SESSION['class'] == 2) { $class = "fighter"; $class_hp = 10; $class_id = 2; } elseif ($_SESSION['class'] == 3) { $class = "rogue"; $class_hp = 8; $class_id = 3; } elseif ($_SESSION['class'] == 4) { $class = "wizard"; $class_hp = 6; $class_id = 4; } $max_hp = $con_mod + $class_hp; $ac = 10 + $dex_mod; $proficiency_array = $_SESSION['skill']; $background_id = $_SESSION['background']; $proficiency_array = $_SESSION['skill']; $skill_ids = array(); foreach ($proficiency_array as $proficiency) { if ($proficiency == "Acrobatics") { $skill_id = 1; } elseif ($proficiency == "Animal Handling") { $skill_id = 2; } elseif ($proficiency == "Arcana") { $skill_id = 3; } elseif ($proficiency == "Athletics") { $skill_id = 4; } elseif ($proficiency == "Deception") { $skill_id = 5; } elseif ($proficiency == "History") { $skill_id = 6; } elseif ($proficiency == "Insight") { $skill_id = 7; } elseif ($proficiency == "Intimidation") { $skill_id = 8; } elseif ($proficiency == "Investigation") { $skill_id = 9; } elseif ($proficiency == "Medicine") { $skill_id = 10; } elseif ($proficiency == "Nature") { $skill_id = 11; } elseif ($proficiency == "Perception") { $skill_id = 12; } elseif ($proficiency == "Performance") { $skill_id = 13; } elseif ($proficiency == "Persuasion") { $skill_id = 14; } elseif ($proficiency == "Religion") { $skill_id = 15; } elseif ($proficiency == "Sleight of Hand") { $skill_id = 16; } elseif ($proficiency == "Stealth") { $skill_id = 17; } elseif ($proficiency == "Survival") { $skill_id = 18; } array_push($skill_ids, $skill_id); } // MAKES A RACE VARIABLE, SPEED : if ($_SESSION['race'] == 1) { $race = "human"; $speed = 30; $race_id = 1; } elseif ($_SESSION['race'] == 2) { $race = "hill dwarf"; $speed = 25; $race_id = 2; } elseif ($_SESSION['race'] == 3) { $race = "mountain dwarf"; $speed = 25; $race_id = 3; } elseif ($_SESSION['race'] == 4) { $race = "high elf"; $speed = 30; $race_id = 4; } elseif ($_SESSION['race'] == 5) { $race = "wood elf"; $speed = 35; $race_id = 5; } elseif ($_SESSION['race'] == 6) { $race = "lightfoot halfling"; $speed = 25; $race_id = 6; } elseif ($_SESSION['race'] == 7) { $race = "stout halfling"; $speed = 25; $race_id = 7; } // MAKE STAT CLASS : $stat = new Stat($ac, 1, 1, 1, 1, $cha, $con, 1, $dex, 1, $initiative, 1, $int, 1, 1, $max_hp, 1, 1, 1, 1, 1, 1, 1, $speed, 1, 1, $str, 1, $wis); $stat->save(); $stat->updateAcrobatics($proficiency_array); $stat->updateAnimalHandling($proficiency_array); $stat->updateArcana($proficiency_array); $stat->updateAthletics($proficiency_array); $stat->updateDeception($proficiency_array); $stat->updateHistory($proficiency_array); $stat->updateInsight($proficiency_array); $stat->updateIntimidation($proficiency_array); $stat->updateInvestigation($proficiency_array); $stat->updateMedicine($proficiency_array); $stat->updateNature($proficiency_array); $stat->updatePerception($proficiency_array); $stat->updatePerformance($proficiency_array); $stat->updatePersuasion($proficiency_array); $stat->updateReligion($proficiency_array); $stat->updateSleightOfHand($proficiency_array); $stat->updateStealth($proficiency_array); $stat->updateSurvival($proficiency_array); $stat_id = $stat->getId(); // CREATE CHARACTER, ADD JOINS : $character = new Character($description_id, $race_id, $stat_id); $character->save(); $character->addCharClass($class_id); $character->addBackground($background_id); foreach ($skill_ids as $id) { $character->addSkill($id); } return $character; }
public function save() { $user = Auth::user(); $character = Character::find(Input::get('characterId')); if (!$character) { $character = new Character(); $characterIsNew = true; } if (!isset($character->user_id)) { $character->user_id = $user->id; } $character->name = Input::get("sheet.name"); $character->save(); CharacterVersion::where('character_id', $character->id)->where('version', '>', $character->approved_version)->delete(); $version = CharacterVersion::createNewVersion($character, Input::has("comment") ? Input::get("comment") : null); if ($version->isNewCharacter()) { $version->setHasDroppedMorality(Input::get("sheet.hasDroppedMorality") == "true"); } try { $version->setEditingUser($user); if (Input::get("sheet.sect.selected")) { $version->setSect(RulebookSect::find(Input::get("sheet.sect.selected")), RulebookSect::find(Input::get("sheet.sect.displaying"))); } if (Input::get("sheet.clan.selected")) { $version->setClan(RulebookClan::find(Input::get("sheet.clan.selected")), RulebookClan::find(Input::get("sheet.clan.displaying"))); } $version->setClanOptions(Input::get("sheet.clanOptions.0"), Input::get("sheet.clanOptions.1"), Input::get("sheet.clanOptions.2")); if (Input::get("sheet.nature")) { $version->setNature(RulebookNature::find(Input::get("sheet.nature"))); } if (Input::get("sheet.willpower")) { $version->setWillpower(Input::get("sheet.willpower.dots"), Input::get("sheet.willpower.traits")); } if (Input::get("sheet.attributes")) { $version->setAttributes(Input::get("sheet.attributes.physicals"), Input::get("sheet.attributes.mentals"), Input::get("sheet.attributes.socials")); } foreach ((array) Input::get("sheet.abilities") as $ability) { if (array_key_exists("specialization", $ability)) { $version->addAbilityWithSpecialization(RulebookAbility::find($ability["id"]), $ability["count"], $ability["specialization"], $ability["name"]); } else { $version->addAbility(RulebookAbility::find($ability["id"]), $ability["count"], $ability["name"]); } } foreach ((array) Input::get("sheet.disciplines") as $discipline) { $version->updateDiscipline(RulebookDiscipline::find($discipline["id"]), $discipline["count"], array_key_exists("path", $discipline) ? $discipline["path"] : 0); } foreach ((array) Input::get("newRituals") as $newRitualData) { $version->addRitualToBook($newRitualData["name"], $newRitualData["description"], $newRitualData["type"]); } foreach ((array) Input::get("sheet.rituals") as $ritualId) { $version->addRitual($ritualId); } if (Input::get("sheet.path")) { $version->updatePath(RulebookPath::find(Input::get("sheet.path")), Input::get("sheet.virtues.0"), Input::get("sheet.virtues.1"), Input::get("sheet.virtues.2"), Input::get("sheet.virtues.3")); } foreach ((array) Input::get("sheet.merits") as $meritData) { $version->addMerit(RulebookMerit::find($meritData["id"]), array_key_exists("description", $meritData) ? $meritData["description"] : null); } foreach ((array) Input::get("sheet.flaws") as $flawData) { $version->addFlaw(RulebookFlaw::find($flawData["id"]), array_key_exists("description", $flawData) ? $flawData["description"] : null); } foreach ((array) Input::get("sheet.derangements") as $derangementData) { $version->addDerangement(RulebookDerangement::find($derangementData["id"]), array_key_exists("description", $derangementData) ? $derangementData["description"] : null); } foreach ((array) Input::get("sheet.backgrounds") as $backgroundData) { $version->addBackground(RulebookBackground::find($backgroundData["id"]), $backgroundData["count"], array_key_exists("description", $backgroundData) ? $backgroundData["description"] : null); } foreach ((array) Input::get("sheet.elderPowers") as $elderData) { $version->addElderPower($elderData); } foreach ((array) Input::get("sheet.comboDisciplines") as $comboData) { $version->addComboDiscipline($comboData); } $version->clearUntouchedRecords(); } catch (Exception $e) { throw $e; } return $version; }