public function testStorytellerPurchaseInClanDiscipline() { self::$version->setEditingUser(self::$storyteller); CharacterDiscipline::character(self::$character->id)->version(self::$version->version)->delete(); $this->assertCostDifference(0, function () { self::$version->updateDiscipline(RulebookDiscipline::find(1), 1); }); CharacterDiscipline::character(self::$character->id)->version(self::$version->version)->delete(); $this->assertCostDifference(0, function () { self::$version->updateDiscipline(RulebookDiscipline::find(1), 2); }); CharacterDiscipline::character(self::$character->id)->version(self::$version->version)->delete(); $this->assertCostDifference(0, function () { self::$version->updateDiscipline(RulebookDiscipline::find(1), 3); }); CharacterDiscipline::character(self::$character->id)->version(self::$version->version)->delete(); $this->assertCostDifference(0, function () { self::$version->updateDiscipline(RulebookDiscipline::find(1), 4); }); CharacterDiscipline::character(self::$character->id)->version(self::$version->version)->delete(); $this->assertCostDifference(0, function () { self::$version->updateDiscipline(RulebookDiscipline::find(1), 5); }); }
public function updateDiscipline(RulebookDiscipline $discipline, $amount, $path = 0) { $disciplineRecord = CharacterDiscipline::character($this->character_id)->version($this->version)->where('discipline_id', $discipline->id)->where('path_id', $path)->where('ranks', '!=', 0)->first(); $inClanBasicCount = $this->character->countInClanBasics($this->version); if ($disciplineRecord) { $rankDifference = $amount - $disciplineRecord->ranks; if ($rankDifference < 0) { //Burn points if we have lost a rank. $disciplineRecord->lost_points += $this->character->getDisciplinePathCost($disciplineRecord->definition, $path, $disciplineRecord->ranks, $this->version) - $this->character->getDisciplinePathCost($disciplineRecord->definition, $path, $amount, $this->version); } else { if ($rankDifference > 0 && $this->editingAsStoryteller()) { //Storytellers receive free points. $disciplineRecord->free_points += $this->character->getDisciplinePathCost($disciplineRecord->definition, $path, $amount, $this->version) - $this->character->getDisciplinePathCost($disciplineRecord->definition, $path, $disciplineRecord->ranks, $this->version); } } } else { $disciplineRecord = $this->createNewRecord("CharacterDiscipline"); $disciplineRecord->discipline_id = $discipline->id; $disciplineRecord->path_id = $path; if ($this->editingAsStoryteller()) { $disciplineRecord->free_points += $this->character->getDisciplinePathCost($disciplineRecord->definition, $path, $amount, $this->version) - ($this->character->isDisciplineInClan($discipline, $this->version) ? min(3 - $inClanBasicCount, min($amount, 2)) * 3 : 0); } } $disciplineRecord->ranks = $amount; $disciplineRecord->save(); $this->touchedRecords["CharacterDiscipline"][] = $disciplineRecord->id; }
public function disciplines($version = -1, $ignoreRankZeros = false) { if ($version == -1) { $version = $this->activeVersion(); } if ($ignoreRankZeros) { return CharacterDiscipline::character($this->id)->version($version); } return CharacterDiscipline::character($this->id)->where('ranks', '>', 0)->version($version); }