diff --git a/endpoints/quest/quest.php b/endpoints/quest/quest.php index 69b1318c..289a2528 100644 --- a/endpoints/quest/quest.php +++ b/endpoints/quest/quest.php @@ -984,11 +984,29 @@ class QuestBaseResponse extends TemplateResponse implements ICache ->getByCondition(Type::QUEST, $this->typeId) ->prepare(); - if ($_ = $this->subject->getField('reqMinRepFaction')) - $cnd->addExternalCondition(Conditions::SRC_QUEST_AVAILABLE, '0:'.$this->typeId, [Conditions::REPUTATION_RANK, $_, 1 << Game::getReputationLevelForPoints($this->subject->getField('reqMinRepValue'))]); - if ($_ = $this->subject->getField('reqMaxRepFaction')) - $cnd->addExternalCondition(Conditions::SRC_QUEST_AVAILABLE, '0:'.$this->typeId, [-Conditions::REPUTATION_RANK, $_, 1 << Game::getReputationLevelForPoints($this->subject->getField('reqMaxRepValue'))]); + $minRepFac = $this->subject->getField('reqMinRepFaction'); + $maxRepFac = $this->subject->getField('reqMaxRepFaction'); + // add +/- 2 to contain edgecases. ie a reqMaxRepValue of 1 should not include the whole of REP_NEUTRAL + $minRepRank = $minRepFac ? Game::getReputationLevelForPoints($this->subject->getField('reqMinRepValue') + 2) : REP_HATED; + $maxRepRank = $maxRepFac ? Game::getReputationLevelForPoints($this->subject->getField('reqMaxRepValue') - 2) : REP_EXALTED; + + $convertRankBits = function (int $minRank, int $maxRank) : int + { + $bits = 0; + for ($i = $minRank; $i <= $maxRank; $i++) + $bits |= (1 << $i); + + return $bits; + }; + + if ($minRepFac && $maxRepFac && $minRepFac <> $maxRepFac) + { + $cnd->addExternalCondition(Conditions::SRC_QUEST_AVAILABLE, '0:'.$this->typeId, [Conditions::REPUTATION_RANK, $minRepFac, $convertRankBits($minRepRank, REP_EXALTED)]); + $cnd->addExternalCondition(Conditions::SRC_QUEST_AVAILABLE, '0:'.$this->typeId, [Conditions::REPUTATION_RANK, $maxRepFac, $convertRankBits(REP_HATED, $maxRepRank)]); + } + else if (($_ = $minRepFac) || ($_ = $maxRepFac)) + $cnd->addExternalCondition(Conditions::SRC_QUEST_AVAILABLE, '0:'.$this->typeId, [Conditions::REPUTATION_RANK, $_, $convertRankBits($minRepRank, $maxRepRank)]); if ($tab = $cnd->toListviewTab()) { diff --git a/includes/game/misc.php b/includes/game/misc.php index c9504eca..9ccbb91a 100644 --- a/includes/game/misc.php +++ b/includes/game/misc.php @@ -135,22 +135,16 @@ class Game public static function getReputationLevelForPoints(int $pts) : int { - if ($pts >= 41999) - return REP_EXALTED; - if ($pts >= 20999) - return REP_REVERED; - if ($pts >= 8999) - return REP_HONORED; - if ($pts >= 2999) - return REP_FRIENDLY; - if ($pts >= 0) - return REP_NEUTRAL; - if ($pts >= -3000) - return REP_UNFRIENDLY; - if ($pts >= -6000) - return REP_HOSTILE; - - return REP_HATED; + return match (true) { + $pts >= 42000 => REP_EXALTED, + $pts >= 21000 => REP_REVERED, + $pts >= 9000 => REP_HONORED, + $pts >= 3000 => REP_FRIENDLY, + $pts >= 0 => REP_NEUTRAL, + $pts >= -3000 => REP_UNFRIENDLY, + $pts >= -6000 => REP_HOSTILE, + default => REP_HATED, + }; } public static function getTaughtSpells(mixed &$spell) : array