public function buildRulebook($owner = -1) { //Build rulebook or retrieve it from the cache. $out = Cache::remember('rulebook', 24 * 60, function () { $baseRulebook = []; $baseRulebook['sects'] = $this->expandSects(RulebookSect::get()); $baseRulebook['clans'] = $this->expandClans(RulebookClan::get()); $baseRulebook['rituals'] = $this->sortByGroups(RulebookRitual::whereNull('owner')->get(), "rituals"); $baseRulebook['backgrounds'] = $this->sortByGroups(RulebookBackground::orderBy('name')->get(), "backgrounds"); $baseRulebook['disciplines'] = $this->expandDisciplines(RulebookDiscipline::orderBy('name')->get()); $baseRulebook['natures'] = RulebookNature::get(); $baseRulebook['abilities'] = $this->sortByGroups(RulebookAbility::where('owner', null)->orderBy('name')->get(), "abilities"); $baseRulebook["paths"] = $this->expandPaths(RulebookPath::get()); $baseRulebook["derangements"] = RulebookDerangement::get(); $baseRulebook['merits'] = $this->sortByGroups(RulebookMerit::orderBy("cost")->get(), "merits"); $baseRulebook['flaws'] = $this->sortByGroups(RulebookFlaw::orderBy("cost")->get(), "flaws"); return $baseRulebook; }); if ($owner != -1) { $out['custom_abilities'] = RulebookAbility::where('owner', $owner)->get(); $out['elder_powers'] = RulebookElderPower::where('owner_id', $owner)->get(); $out['combo_disciplines'] = RulebookComboDiscipline::where('owner_id', $owner)->get(); $out['custom_rituals'] = RulebookRitual::where('owner', $owner)->get(); } return Response::json($out); }
} if ($key == "willpower") { echo "<h5>Willpower</h5>"; print_change("", @$value["dots"], ["Began with Dots.", "[change] Dots from -> .", "Removed all Dots."]); print_change("", @$value["traits"], ["Began with Traits.", "[change] Traits from -> .", "Removed all Traits."]); } if ($key == "attributes") { echo "<h5>Attributes</h5>"; print_change("", @$value["physicals"], ["Began with Physical Dots.", "[change] Physical Dots from -> .", "Removed all Physical Dots."]); print_change("", @$value["mentals"], ["Began with Mental Dots.", "[change] Mental Dots from -> .", "Removed all Mental Dots."]); print_change("", @$value["socials"], ["Began with Social Dots.", "[change] Social Dots from -> .", "Removed all Social Dots."]); } if ($key == "abilities") { echo "<h5>Abilities</h5>"; foreach ($value as $k => $v) { echo '<b>' . RulebookAbility::find($k)->name . '</b>'; if (isset($v['amount'])) { print_change("", @$v["amount"], ["Initial purchase of Dots.", "[change] Dots from -> .", "Removed all Dots."]); } if (isset($v['specialization']) && $v['specialization'][0] != $v['specialization'][1]) { print_change("", @$v["specialization"], ["Added specialization .", "Changed specialization from -> .", "Removed specialization ."]); } } } if ($key == "backgrounds") { echo "<h5>Backgrounds</h5>"; foreach ($value as $k => $v) { $name = RulebookBackground::find($k)->name; if (isset($v['description'][0])) { $name .= ": " . $v["description"][0]; } else {
public function addAbility($ability, $count, $name = null) { $abilityRecord = $this->findOneWhere("CharacterAbility", "ability_id", $ability ? $ability->id : null); if ($abilityRecord) { $rankDifference = $count - $abilityRecord->amount; if ($rankDifference < 0) { $abilityRecord->lost_points += abs($rankDifference); } else { if ($rankDifference > 0 && $this->editingAsStoryteller()) { $abilityRecord->free_points += $rankDifference; } } } else { $abilityRecord = $this->createNewRecord("CharacterAbility"); if (!$ability) { $ability = new RulebookAbility(); $ability->name = $name; $ability->isCustom = true; $ability->owner = $this->character_id; $ability->save(); if ($this->editingAsStoryteller()) { $abilityRecord->free_points += $count; } } $abilityRecord->ability_id = $ability->id; } $abilityRecord->amount = $count; $abilityRecord->save(); $this->touchedRecords["CharacterAbility"][] = $abilityRecord->id; return $abilityRecord; }
public function testStorytellerAddSpecialization() { self::$version->setEditingUser(self::$storyteller); $this->assertCostDifference(0, function () { self::$version->addAbilityWithSpecialization(RulebookAbility::skip(1)->first(), 1, "Test Specialization"); }); }
function getDataSet($val) { $all_backgrounds = RulebookBackground::all()->lists('name'); $all_abilities = RulebookAbility::where('isCustom', false)->get()->lists('name'); $extractor = null; $labelSet = []; switch ($val) { case "Generation": $labelSet = ["8th", "9th", "10th", "11th", "12th", "13th", "14th", "15th"]; $extractor = function ($character) { if ($character->hasFlaw("Fourteenth Generation")) { return 15; } elseif ($character->hasFlaw("Fifteenth Generation")) { return 14; } else { return 13 - $character->getBackgroundDots("Generation"); } }; break; case "Courage": $labelSet = [1, 2, 3, 4, 5]; $extractor = function ($character) { return @$character->path()->first()->virtue4; }; break; case "Morality": $labelSet = [1, 2, 3, 4, 5]; $extractor = function ($character) { return @$character->path()->first()->virtue3; }; break; case "Self-Control/Instinct": $labelSet = [1, 2, 3, 4, 5]; $extractor = function ($character) { return @$character->path()->first()->virtue2; }; break; case "Conscience/Conviction": $labelSet = [1, 2, 3, 4, 5]; $extractor = function ($character) { return @$character->path()->first()->virtue1; }; break; case "Physical Traits": $labelSet = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; $extractor = function ($character) { return $character->attributes()->first()->physicals; }; break; case "Mental Traits": $labelSet = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; $extractor = function ($character) { return $character->attributes()->first()->mentals; }; break; case "Social Traits": $labelSet = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; $extractor = function ($character) { return $character->attributes()->first()->socials; }; break; case "Current Experience": $labelSet = []; for ($i = 0; $i <= 100; $i++) { $labelSet[] = $i; } $extractor = function ($character) { return $character->cachedExperience(); }; break; case "Total Experience": $labelSet = []; for ($i = 0; $i <= 100; $i++) { $labelSet[] = $i; } $extractor = function ($character) { return $character->experience; }; break; case "Experience Spent": $labelSet = []; for ($i = 0; $i <= 100; $i++) { $labelSet[] = $i; } $extractor = function ($character) { return $character->getExperienceCost($character->activeVersion()); }; break; case "Total Influence": $labelSet = []; for ($i = 0; $i <= 14 * 5; $i++) { $labelSet[] = $i; } $extractor = function ($character) { $influences = ["Bureaucracy", "Church", "Finance", "Health", "High Society", "Industry", "Media", "Neighborhood", "Occult", "Police", "Politics", "Transportation", "Underworld", "University"]; $total = 0; foreach ($influences as $i) { $total += $character->getBackgroundDots($i); } return $total; }; break; default: if (in_array($val, $all_backgrounds)) { $labelSet = [0, 1, 2, 3, 4, 5]; $extractor = function ($character) use($val) { return $character->getBackgroundDots($val); }; } else { if (in_array($val, $all_abilities)) { $labelSet = [0, 1, 2, 3, 4, 5]; $extractor = function ($character) use($val) { return $character->getAbilityDots($val); }; } } break; } return ["labels" => $labelSet, "extractor" => $extractor]; /*$dataSet = []; foreach(Character::activeCharacters()->get() as $c) { $charData = call_user_func($extractor, $c); $dataSet[] = ["name" => $c->name, "value" => $charData]; } return ["labels" => $labelSet, "data" => $dataSet];*/ }
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; }