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; }
public static function getGameState($match_id, $player_id) { //get match $match = Matches::find($match_id); //get player's opponent id $opponent_id = Matches::getOpponentID($match_id, $player_id); //get the player's state $player = Player::getPlayerState($match_id, $player_id); //get the opponent player's state $opponent = Player::getPlayerState($match_id, $opponent_id); //get the game's current state $match_state = $match->match_state; //get the current active player $active_player = $match->active_player_id; //get mogs for results animation screen $round_result_mogs = PlayField::getResultsAnimationMogs($match_id); //get last update timestamp $last_update = $match->updated_at; $last_update = substr($last_update, 0, 19); //create new game_state object $game_state = new GameState($player, $opponent, $match_state, $active_player, $round_result_mogs, $last_update); return $game_state; }
public static function flipMogs($match_id, $active_player_id, $count) { //arrays for id's to be flipped and active ids for owner update $flip_ids = []; $active_ids = []; //Get the mogs $mogs = PlayField::getActiveMogs($match_id); //Build array of random indexes for flip for ($i = 0; $i < $count; $i++) { $flipIdx = rand(0, count((array) $mogs) - 1); $flip_ids[] = $mogs[$flipIdx]->id; array_splice($mogs, $flipIdx, 1); } //flip them DB::table('PlayField')->where('match_id', '=', $match_id)->where('flipped', '=', 0)->whereIn('id', $flip_ids)->update(['flipped' => 1, 'new_owner_id' => $active_player_id, 'show_animation' => 1]); //Get flipped Mogs active id for update $flipped_mogs = DB::table('PlayField')->whereIn('id', $flip_ids)->get(); //build array of active ids from flipped mogs foreach ($flipped_mogs as $mog) { $active_ids[] = $mog->mog_id; } //update Activated Mog's owner ActivatedMogs::updateOwner($active_ids, $active_player_id); }
public function calcRoundOutcome($slam_time) { //determine round_bias from given slam time if ($slam_time == 0) { $round_bias = 0; } else { if ($slam_time > 1 && $slam_time <= 200) { $round_bias = 1; } else { if ($slam_time > 200 && $slam_time <= 300) { $round_bias = 0.9; } else { if ($slam_time > 300 && $slam_time <= 600) { $round_bias = 0.8; } else { if ($slam_time > 600 && $slam_time <= 700) { $round_bias = 0.7; } else { if ($slam_time > 700 && $slam_time <= 900) { $round_bias = 0.6; } else { if ($slam_time > 900 && $slam_time <= 1200) { $round_bias = 0.5; } else { if ($slam_time > 1200 && $slam_time <= 1600) { $round_bias = 0.4; } else { if ($slam_time > 1600 && $slam_time <= 2100) { $round_bias = 0.3; } else { if ($slam_time > 2100 && $slam_time <= 4000) { $round_bias = 0.2; } else { $round_bias = 0.1; } } } } } } } } } } //get count of available mogs for this match $available_mog_count = PlayField::getActiveMogs($this->id); $available_mog_count = count((array) $available_mog_count); //get number to be flipped $flip_count = 40 * $round_bias; //make sure number to be flipped doesn't exceed available if ($flip_count > $available_mog_count) { $flip_count = $available_mog_count; } //Flip the mogs PlayField::flipMogs($this->id, $this->active_player_id, $flip_count); //update count of mogs for player if ($this->active_player_id == $this->p1_id) { $this->p1_mog_count += $flip_count; } else { $this->p2_mog_count += $flip_count; } $this->save(); }