Esempio n. 1
0
 public function getUser()
 {
     //Check user authenticated
     if (Auth::user()) {
         //Set authenticated user instance
         $user = Auth::user();
         if (Matches::checkForActiveMatch($user->id)) {
             return redirect('/meme_slam/' . $user->id);
         } else {
             //If user instance has no mogs give it mogs
             if ($user->collection_rating == 0) {
                 ActivatedMogs::newAccountDrop($user->id);
             }
             //recalc user's collection rating and update
             $collection_rating = $user->recalcCollectionRating();
             //Get all the authenticated user's mogs
             $mogs = User::getUserMogs($user->id);
             //Get user's bet rating
             $bet_rating = ActivatedMogs::getBetRating($user->id);
             //Get count of users betted mogs
             $bet_count = count(User::getBettedMogs($user->id));
             //get top collection rating
             $top_collections = User::getTopCollections();
             //get list of ids for new mogs the player has seen
             $recent_mogs = ActivatedMogs::getRecentMogs($user->id);
             ActivatedMogs::resetUserRecentMogs($user->id);
             return view('home', ['user' => $user, 'mogs' => $mogs, 'bet_rating' => $bet_rating, 'collection_rating' => $collection_rating, 'bet_count' => $bet_count, 'top_collections' => $top_collections, 'recent_mogs' => $recent_mogs])->withEncryptedCsrfToken(Crypt::encrypt(csrf_token()));
         }
     } else {
         return "You are not authorized to view this page...";
     }
 }
 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 function updateBetStatus()
 {
     $mogs = [];
     $owner_id = Request::input('ownerID');
     $string_mogs = Request::input('mogs');
     //convert string data to int for sql query in next method
     if (!empty($string_mogs)) {
         foreach ($string_mogs as $s_mogs) {
             $mogs[] = (int) $s_mogs;
         }
     }
     ActivatedMogs::updateBetStatus($owner_id, $mogs);
     return "success";
 }
Esempio n. 4
0
    public static function toggleBetStatus($mog_id)
    {
        $mog = ActivatedMogs::getMog($mog_id);
        if ($mog->on_bet == 0) {
            $new_val = 1;
        } else {
            $new_val = 0;
        }
        DB::update('
				UPDATE ActivatedMogs
				SET on_bet = :new_val
				WHERE id = :mog_id
			', ['new_val' => $new_val, 'mog_id' => $mog_id]);
        return true;
    }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
 public function processGameOver()
 {
     //set match state, match complete, and in progress
     $this->in_progress = 0;
     $this->match_complete = 1;
     $this->match_state = 3;
     //update game count for players
     DB::table('User')->whereIn('id', array($this->p1_id, $this->p2_id))->increment('game_count');
     //determine who wins
     if ($this->p1_mog_count > $this->p2_mog_count) {
         //player 1 wins
         $winner = $this->p1_id;
         $loser = $this->p2_id;
     } else {
         if ($this->p1_mog_count < $this->p2_mog_count) {
             //player 2 wins
             $winner = $this->p2_id;
             $loser = $this->p1_id;
         } else {
             //tie
             $winner = false;
         }
     }
     //update winners game count
     DB::table('User')->where('id', '=', $winner)->increment('keeps_wins');
     DB::table('User')->where('id', '=', $winner)->increment('total_wins');
     //call new mog drops for winner/loser respectively
     if (!$winner) {
         //if tie users get low common drop
         ActivatedMogs::activateNew(5, 0, 0, $this->p1_id);
         ActivatedMogs::activateNew(5, 0, 0, $this->p2_id);
     } else {
         //values for drops
         $commonNum = 15;
         $rareNum = 0;
         $legendaryNum = 0;
         //rare roll...
         if (rand(0, 10) > 8) {
             $rareNum = rand(1, 4);
         }
         //legendary roll...
         if (rand(0, 10) >= 9) {
             $legendaryNum = 1;
         }
         $commonNum -= $rareNum + $legendaryNum;
         ActivatedMogs::activateNew($commonNum, $rareNum, $legendaryNum, $winner);
         ActivatedMogs::activateNew(5, 0, 0, $loser);
     }
     //reset players mog bet status
     ActivatedMogs::resetBetStatus($this->p1_id);
     ActivatedMogs::resetBetStatus($this->p2_id);
     $this->save();
 }