|
|
@ -13,12 +13,14 @@ class Mission extends Model |
|
|
|
return $this->hasMany('App\Tweet'); |
|
|
|
} |
|
|
|
|
|
|
|
private function unique_transit_lines(Team $team) { |
|
|
|
private function unique_trimet_transit_lines(Team $team) { |
|
|
|
static $cache = []; |
|
|
|
if(array_key_exists($team->id, $cache)) |
|
|
|
return $cache[$team->id]; |
|
|
|
|
|
|
|
$tweets = Tweet::where('team_id', $team->id)->where('m1_complete', 1)->get(); |
|
|
|
$tweets = Tweet::where('team_id', $team->id) |
|
|
|
->where('m1_complete', 1)->whereNotNull('m1_transit_line_id')->get(); |
|
|
|
|
|
|
|
$lines = []; |
|
|
|
foreach($tweets as $tweet) { |
|
|
|
if($tweet->m1_transit_line_id && !in_array($tweet->m1_transit_line_id, $lines)) { |
|
|
@ -37,6 +39,7 @@ class Mission extends Model |
|
|
|
|
|
|
|
$tweets = Tweet::where('team_id', $team->id)->where('m2_complete', 1)->get(); |
|
|
|
$centers = []; |
|
|
|
|
|
|
|
foreach($tweets as $tweet) { |
|
|
|
if($tweet->m2_transit_center_id && !in_array($tweet->m2_transit_center_id, $centers)) { |
|
|
|
$centers[] = $tweet->m2_transit_center_id; |
|
|
@ -77,8 +80,8 @@ class Mission extends Model |
|
|
|
public function complete(Team $team) { |
|
|
|
switch($this->id) { |
|
|
|
case 1: |
|
|
|
// 5 unique transit lines
|
|
|
|
return $this->unique_transit_lines($team) >= 5; |
|
|
|
// 5 unique trimet transit lines
|
|
|
|
return $this->unique_trimet_transit_lines($team) >= 5; |
|
|
|
case 2: |
|
|
|
// 3 unique transit centers
|
|
|
|
return $this->unique_transit_centers($team) >= 3; |
|
|
@ -95,9 +98,9 @@ class Mission extends Model |
|
|
|
public function progress(Team $team) { |
|
|
|
switch($this->id) { |
|
|
|
case 1: |
|
|
|
return [$this->unique_transit_lines($team), 5]; |
|
|
|
return [$this->unique_trimet_transit_lines($team), 5]; |
|
|
|
case 2: |
|
|
|
return [$this->unique_transit_lines($team), 3]; |
|
|
|
return [$this->unique_transit_centers($team), 3]; |
|
|
|
case 3: |
|
|
|
case 4: |
|
|
|
case 5: |
|
|
@ -112,13 +115,65 @@ class Mission extends Model |
|
|
|
public function score(Team $team) { |
|
|
|
switch($this->id) { |
|
|
|
case 1: |
|
|
|
|
|
|
|
|
|
|
|
// No points unless they hit 5 trimet transit lines
|
|
|
|
if($this->complete($team)) { |
|
|
|
$score = 50; |
|
|
|
// 20 bonus for each line that is not trimet
|
|
|
|
$tweet = Tweet::where('team_id', $team->id)->where('m1_complete', 1)->whereNotNull('m1_non_trimet')->get(); |
|
|
|
$lines = []; |
|
|
|
foreach($tweet as $tweet) { |
|
|
|
if(!in_array($tweet->m1_non_trimet, $lines)) { |
|
|
|
$lines[] = $tweet->m1_non_trimet; |
|
|
|
} |
|
|
|
} |
|
|
|
$score += count($lines) * 20; |
|
|
|
return $score; |
|
|
|
} else { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
// No points unless they hit 3 transit centers
|
|
|
|
if($this->complete($team)) { |
|
|
|
$score = 50; |
|
|
|
// 20 bonus points for any TC with another team
|
|
|
|
|
|
|
|
// ?? Increasing bonus points for additional transit centers
|
|
|
|
|
|
|
|
// Triple points for each? transit center that no other team goes to
|
|
|
|
|
|
|
|
} else { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
case 4: |
|
|
|
case 6: |
|
|
|
if($this->complete($team)) { |
|
|
|
return 50; |
|
|
|
} else { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
case 5: |
|
|
|
if($this->complete($team)) { |
|
|
|
$score = 50; |
|
|
|
|
|
|
|
return $score; |
|
|
|
} else { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
case 7: |
|
|
|
if($this->complete($team)) { |
|
|
|
$score = 50; |
|
|
|
// +5 for each additional photo
|
|
|
|
$extra_docs = $this->unique_documents($team) - 3; |
|
|
|
if($extra_docs > 0) { |
|
|
|
$score += $extra_docs * 5; |
|
|
|
} |
|
|
|
return $score; |
|
|
|
} else { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |