X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=app%2FModels%2FChannel.php;h=738312dc3e82a60d6725a0289f2886a11b3dcc2e;hb=93f50820771a0333b169f76f74727239cf0cb286;hp=32ac875bb707c0760f9e75d2362a64416db7da61;hpb=7fc357a5943bf280ce2fa9aa97ec516af61efd69;p=alttp.git diff --git a/app/Models/Channel.php b/app/Models/Channel.php index 32ac875..738312d 100644 --- a/app/Models/Channel.php +++ b/app/Models/Channel.php @@ -35,6 +35,17 @@ class Channel extends Model $this->save(); } + public function getGuessingSetting($name, $default = null) { + if (empty($this->guessing_settings) || + empty($this->guessing_type) || + !array_key_exists($this->guessing_type, $this->guessing_settings) || + !array_key_exists($name, $this->guessing_settings[$this->guessing_type]) + ) { + return $default; + } + return $this->guessing_settings[$this->guessing_type][$name]; + } + public function solveGuessing($solution) { $start = $this->guessing_start; $end = is_null($this->guessing_end) ? now() : $this->guessing_end; @@ -96,7 +107,20 @@ class Channel extends Model } public function scoreGuessing($solution, $guess, $first) { - return 1; + if ($guess == $solution) { + if ($first) { + return $this->getGuessingSetting('points_exact_first', 1); + } + return $this->getGuessingSetting('points_exact_other', 1); + } + $distance = abs(intval($guess) - intval($solution)); + if ($distance <= $this->getGuessingSetting('points_close_max', 3)) { + if ($first) { + return $this->getGuessingSetting('points_close_first', 1); + } + return $this->getGuessingSetting('points_close_other', 1); + } + return 0; } public function isValidGuess($solution) { @@ -129,6 +153,7 @@ class Channel extends Model 'chat' => 'boolean', 'chat_commands' => 'array', 'chat_settings' => 'array', + 'guessing_settings' => 'array', 'guessing_start' => 'datetime', 'guessing_end' => 'datetime', 'languages' => 'array',