public function initialize($user_id) { $required_bet_count = 20; $in_active_match = Matches::checkForActiveMatch($user_id); if (count(User::getBettedMogs($user_id)) == $required_bet_count || $in_active_match) { //get the user $user = Auth::user(); //Get the user's bet rating $bet_rating = ActivatedMogs::getBetRating($user_id); //Check if the user is already in a match $active_match_id = $user->getActiveMatch(); if ($active_match_id) { //user is in a match //get the match record to know the current state of the match $match_detail = Matches::find($active_match_id); //get the mogs that are in the play field $bet_mogs = PlayField::getUsersBettedMogs($active_match_id, $user->id); $captured_mogs = PlayField::getUsersCapturedMogs($active_match_id, $user->id); } else { //user is not in a match $match_detail = null; //Get user's betted mogs $bet_mogs = User::getBettedMogs($user_id); $captured_mogs = []; } return view('memeslam', ['user' => $user, 'bet_rating' => $bet_rating, 'match_detail', 'bet_mogs' => $bet_mogs, 'captured_mogs' => $captured_mogs])->withEncryptedCsrfToken(Crypt::encrypt(csrf_token())); } else { return redirect('/'); } }
public static function getPlayerState($match_id, $player_id) { //get player username $name = User::getUserName($player_id); //get player's playing mogs $playing_mogs = PlayField::getUsersBettedMogs($match_id, $player_id); //get player's captured mogs $captured_mogs = PlayField::getUsersCapturedMogs($match_id, $player_id); $player = new Player($name, $playing_mogs, $captured_mogs); return $player; }