tweet; if(!$tweet->team || !$tweet->mission) return; // Tweet out when missions are completed $newMissionStatus = $tweet->mission->complete($tweet->team); if($event->previousMissionStatus == false && $newMissionStatus == true) { $text = 'Team '.$tweet->team->name.' completed mission '.$tweet->mission_id.'! '.$tweet->mission->hashtag.' '.env('GAME_HASHTAG'); Log::info("Tweeting: $text"); $params = [ 'attachment_url' => 'https://twitter.com/'.$tweet->player->twitter.'/status/'.$tweet->tweet_id, 'status' => $text ]; try { Twitter::postTweet($params); } catch(\Exception $e) { Log::error($e->getMessage()); } } // Tweet about bonus points when a team visits a TC nobody else has been to if($tweet->mission_id == 2 && $tweet->transit_center) { $this_tc = $tweet->m2_transit_center_id; $other_teams = Tweet::where('team_id', '!=', $tweet->team_id) ->where('m2_complete', 1) ->where('m2_transit_center_id', $this_tc) ->count(); if($other_teams == 0) { $text = 'Team '.$tweet->team->name.' is currently the only team to have visited '.$tweet->transit_center->name.'! '.env('GAME_HASHTAG'); Log::info("Tweeting: $text"); $params = [ 'attachment_url' => 'https://twitter.com/'.$tweet->player->twitter.'/status/'.$tweet->tweet_id, 'status' => $text ]; try { Twitter::postTweet($params); } catch(\Exception $e) { Log::error($e->getMessage()); } } } // Broadcast this team's current score $score = $tweet->mission->score($tweet->team); $teamScore = $tweet->team->total_score(); event(new ScoreUpdatedEvent($tweet->team, $tweet->mission, $score, $newMissionStatus, $teamScore)); } }