public function destroy($id)
 {
     // delete
     $game = Game::find($id);
     $game->delete();
     return redirect('games');
 }
 /**
  * @param  int  $gameid
  * @return Response
  */
 public function joinagame(Request $request, $gameid)
 {
     Session::put('player', '2');
     Session::put('gameid', $gameid);
     $BS = new BSmodel();
     $BS->joinGame();
     $game = Game::find(Session::get('gameid'));
     PusherLaravel::trigger("{$game->player1id}", 'joined', ['id' => "{$game->player2id}", 'status' => 'joined']);
     return redirect()->route('battleship.game.index');
 }
Esempio n. 3
0
 public function startGame($id)
 {
     \Debugbar::info($id);
     $game = Game::find($id);
     //  $players = DB::select( DB::raw("SELECT game_id FROM game_player gp join games g on gp.game_id = g.game_id join players p on gp.player_id = p.player_id"));
     //   \Debugbar::info($players);
     if ($game != null) {
         /*   for($i=0; i<$players; $i++){
                  $players->status = "Playing";
                  $players->save();
              }*/
         $game->status = "Playing";
         $game->save();
     }
     return response()->json(['game' => $game]);
 }
Esempio n. 4
0
 public function middleScore()
 {
     $sums = [];
     foreach ($this->Scores as $score) {
         if (!isset($sums[$score->game_id])) {
             $sums[$score->game_id] = Game::find($score->game_id)->scoreOfPlayer($this->id);
         }
     }
     $length = count($sums);
     if ($length > 0) {
         $sum = 0;
         foreach ($sums as $item) {
             $sum += $item;
         }
         return $sum / $length;
     } else {
         return 0;
     }
 }
Esempio n. 5
0
 public function show($id)
 {
     $game = Game::find($id);
     return view('view', compact('game'));
 }
 function show($id)
 {
     $game = Game::find($id);
     return view('games.show')->with('game', $game);
 }
Esempio n. 7
0
 public static function deldup()
 {
     $last_moves = '';
     $games = Game::orderBy('moves')->get();
     foreach ($games as $game) {
         if ($last_moves == $game->moves) {
             Toastr::warning('Duplicate removed. ' . $last_moves);
             Game::find($game->id)->delete();
         }
         $last_moves = $game->moves;
     }
 }
 /**
  * Executes an action to given game
  */
 public function action($gameId)
 {
     $game = Game::find($gameId);
     if (is_null($game)) {
         session()->flash('error', sprintf(self::ERROR_NO_GAMES_FOUND, Auth::user()->name));
         return redirect()->route('welcome');
     }
     $action = Input::get('action');
     switch ($action) {
         case self::ACTION_ATTACK:
             return $this->actionAttack($game);
             break;
         case self::ACTION_END_OF_TURN:
             return $this->actionEOT($game);
             break;
         default:
             session()->flash('warning', sprintf(self::ERROR_UNKNOWN_ACTION));
             return redirect()->route(self::ROUTE_SHOW_GAME, $game->id);
     }
 }
Esempio n. 9
0
 public function PushAttack($pos, $status)
 {
     $game = Game::find(Session::get('gameid'));
     if (Session::get('player') == '1') {
         $channel = "{$game->player2id}";
         //canal envios al jugador 2
     } else {
         $channel = "{$game->player1id}";
         //canal envios al jugador 1
     }
     PusherLaravel::trigger($channel, 'attackme', ['position' => $pos, 'stat' => $status]);
     // ataque al oponente
 }
Esempio n. 10
0
 public function endGame()
 {
     $vars = Input::all();
     $game = Game::find($vars['id']);
     $game->status = "Finished";
     $game->winner = $vars['winner'];
     $game->save();
 }
Esempio n. 11
0
 /**
  * Show player page by id.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     if (is_numeric($id)) {
         $this->tpl['player'] = Player::find($id)->first();
     } else {
         $this->tpl['player'] = Player::where('nick', '=', $id)->first();
     }
     if ($this->tpl['player'] === NULL) {
         $this->tpl['title'] = 'Not found';
         $this->tpl['error']['message'] = 'User not found';
         $this->tpl['error']['description'] = 'Sorry, but your user is not found.';
         return \Response::view('errors.404', $this->tpl);
     }
     $scores = Score::where('player_id', '=', $this->tpl['player']->id)->with('game')->get();
     $games = [];
     if ($scores !== NULL) {
         foreach ($scores as $score) {
             if (!isset($games[$score->game_id])) {
                 $games[$score->game_id] = Game::find($score->game_id);
             }
         }
     }
     $this->tpl['games'] = $games;
     return view('player.show', $this->tpl);
 }
Esempio n. 12
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(StoreProductRequest $request, $id)
 {
     $product = Product::find($id)->fill($request->all());
     $product->type = Product::find($id)->type;
     // validate request further according to type
     switch ($request->type) {
         case 'MOVIE':
         case 'SERIES':
         case 'ANIME':
         case 'VIDEO':
             $valRequest = new UpdateVideoRequest();
             $this->validate($request, $valRequest->rules());
             $info = Video::find($product->id)->fill($request->video);
             break;
         case 'GAME':
             $valRequest = new UpdateGameRequest();
             $this->validate($request, $valRequest->rules());
             $info = Game::find($product->id)->fill($request->video);
             break;
     }
     if (in_array($request->type, ['MOVIE', 'SERIES', 'ANIME', 'VIDEO'])) {
         $this->UpdateVideo($request, $product, $info);
     } else {
         if ($request->type == "GAME") {
             $this->UpdateGame($request, $product, $info);
         }
     }
     // flash message
     session()->flash('flash_message', 'Product updated successfully.');
     return redirect()->route('home');
 }
Esempio n. 13
0
    /**
     * ajax get link download.
     * @param $gameId
     * @return Response
     */
    public function downloadLink($gameId)
    {
        //return json to ajax.
        $link = session()->get($gameId . '_download');
        if (!$link) {
            $game = Game::find($gameId);
            $crawler = new MainCrawler();
            $link = $crawler->download($game);
            session()->put($gameId . '_download', $link);
        }

        return response()->json(['link' =>  $link]);
    }
Esempio n. 14
0
 public function viewGame($id)
 {
     $roundGame = Game::find($id);
     if (!count($roundGame)) {
         return redirect()->route('home');
     }
     $league = League::find($roundGame->league_id);
     $players = [User::find($roundGame->user_1_id), User::find($roundGame->user_2_id)];
     $round = $roundGame->round;
     $gameDate = [];
     $dayOffset = 0;
     for ($i = 0; $i < 20; $i++) {
         if (date("U", strtotime(date('d-m-Y'))) > date("U", strtotime('first monday of ' . $league->year . '-' . $league->month) + 86400 * $dayOffset)) {
             if ($round == $i + 1) {
                 $gameDate['day'] = date("j", strtotime('first monday of ' . $league->year . '-' . $league->month) + 86400 * $dayOffset);
                 $gameDate['month'] = date("n", strtotime('first monday of ' . $league->year . '-' . $league->month) + 86400 * $dayOffset);
                 $gameDate['year'] = date("Y", strtotime('first monday of ' . $league->year . '-' . $league->month) + 86400 * $dayOffset);
             }
         }
         if (($i + 1) % 5 == 0) {
             $dayOffset = $dayOffset + 3;
         } else {
             $dayOffset++;
         }
     }
     if (!count($gameDate)) {
         return redirect()->route('home');
     }
     $roundQuestions = Question::where('year', intval($gameDate['year']))->where('month', intval($gameDate['month']))->where('day', intval($gameDate['day']))->get();
     $roundAnswers = array(array());
     $filetype = [];
     foreach ($roundQuestions as $roundQuestion) {
         $filetype[$roundQuestion->id] = pathinfo($roundQuestion->filename, PATHINFO_EXTENSION);
         $roundAnswers[0][$roundQuestion->id] = Answer::where('submitted', 1)->where('user_id', $roundGame->user_1_id)->where('question_id', $roundQuestion->id)->first();
         $roundAnswers[1][$roundQuestion->id] = Answer::where('submitted', 1)->where('user_id', $roundGame->user_2_id)->where('question_id', $roundQuestion->id)->first();
         if (count($roundAnswers[0][$roundQuestion->id]) && count($roundAnswers[1][$roundQuestion->id])) {
             $roundAnswers[0][$roundQuestion->id]['pointsAttr'] = $roundAnswers[1][$roundQuestion->id]->points;
             $roundAnswers[1][$roundQuestion->id]['pointsAttr'] = $roundAnswers[0][$roundQuestion->id]->points;
             $roundAnswers[0][$roundQuestion->id]['pointsWon'] = $roundAnswers[0][$roundQuestion->id]->correct * $roundAnswers[1][$roundQuestion->id]->points;
             $roundAnswers[1][$roundQuestion->id]['pointsWon'] = $roundAnswers[1][$roundQuestion->id]->correct * $roundAnswers[0][$roundQuestion->id]->points;
             $players[0]['points'] += $roundAnswers[0][$roundQuestion->id]['pointsWon'];
             $players[1]['points'] += $roundAnswers[1][$roundQuestion->id]['pointsWon'];
             $players[0]['corrects'] += $roundAnswers[0][$roundQuestion->id]->correct;
             $players[1]['corrects'] += $roundAnswers[1][$roundQuestion->id]->correct;
         } else {
             if (count($roundAnswers[0][$roundQuestion->id])) {
                 $roundAnswers[1][$roundQuestion->id]['correct'] = 0;
                 $roundAnswers[0][$roundQuestion->id]['pointsWon'] = 'Correcta';
                 $roundAnswers[1][$roundQuestion->id]['pointsWon'] = 'Falta';
                 $roundAnswers[0][$roundQuestion->id]['pointsAttr'] = 'Errada';
                 $players[0]['corrects'] += $roundAnswers[0][$roundQuestion->id]->correct;
                 $players[1]['corrects'] = 'F';
                 $players[1]['points'] = 'F';
                 switch ($players[0]['corrects']) {
                     case 0:
                         $players[0]['points'] = 0;
                         break;
                     case 1:
                         $players[0]['points'] = 2;
                         break;
                     case 2:
                         $players[0]['points'] = 3;
                         break;
                     case 3:
                         $players[0]['points'] = 5;
                         break;
                     case 4:
                         $players[0]['points'] = 6;
                         break;
                     case 5:
                         $players[0]['points'] = 8;
                         break;
                     case 6:
                         $players[0]['points'] = 9;
                         break;
                     case 7:
                         $players[0]['points'] = 10;
                         break;
                     case 8:
                         $players[0]['points'] = 12;
                         break;
                 }
             } else {
                 if (count($roundAnswers[1][$roundQuestion->id])) {
                     $roundAnswers[0][$roundQuestion->id]['correct'] = 0;
                     $roundAnswers[0][$roundQuestion->id]['pointsWon'] = 'Falta';
                     $roundAnswers[1][$roundQuestion->id]['pointsWon'] = 'Correcta';
                     $roundAnswers[1][$roundQuestion->id]['pointsAttr'] = 'Errada';
                     $players[0]['corrects'] = 'F';
                     $players[1]['corrects'] += $roundAnswers[1][$roundQuestion->id]->correct;
                     $players[0]['points'] = 'F';
                     switch ($players[1]['corrects']) {
                         case 0:
                             $players[1]['points'] = 0;
                             break;
                         case 1:
                             $players[1]['points'] = 2;
                             break;
                         case 2:
                             $players[1]['points'] = 3;
                             break;
                         case 3:
                             $players[1]['points'] = 5;
                             break;
                         case 4:
                             $players[1]['points'] = 6;
                             break;
                         case 5:
                             $players[1]['points'] = 8;
                             break;
                         case 6:
                             $players[1]['points'] = 9;
                             break;
                         case 7:
                             $players[1]['points'] = 10;
                             break;
                         case 8:
                             $players[1]['points'] = 12;
                             break;
                     }
                 } else {
                     $roundAnswers[0][$roundQuestion->id]['correct'] = 0;
                     $roundAnswers[1][$roundQuestion->id]['correct'] = 0;
                     $roundAnswers[0][$roundQuestion->id]['pointsAttr'] = 'Falta';
                     $roundAnswers[1][$roundQuestion->id]['pointsAttr'] = 'Falta';
                     $players[0]['points'] = 'F';
                     $players[1]['points'] = 'F';
                 }
             }
         }
         $corrects = count(Answer::where('submitted', 1)->where('question_id', $roundQuestion->id)->where('correct', 1)->get());
         $total = count(Answer::where('submitted', 1)->where('question_id', $roundQuestion->id)->get());
         $roundAnswers['percentage'][$roundQuestion->id] = round($corrects / $total * 100, 2);
     }
     return view('game')->with(['date' => $gameDate, 'players' => $players, 'roundQuestions' => $roundQuestions, 'filetype' => $filetype, 'roundAnswers' => $roundAnswers]);
 }
Esempio n. 15
0
 /**
  * Update a match
  *
  * @param  int  $id
  * @return Response
  */
 public function updateMatch($league_id, $match_id)
 {
     $match_date = Input::get('match_date');
     $player1_id = Input::get('player1_id');
     $player2_id = Input::get('player2_id');
     $p1_score = Input::get('p1_score');
     $p2_score = Input::get('p2_score');
     $match_date = new \DateTime($match_date);
     $match_date = $match_date->format("Y-m-d h:m:s");
     if (!is_null($player1_id) && !is_null($player2_id)) {
         //update match
         $match = Match::find($match_id);
         if (!is_null($match)) {
             $match->player1_id = $player1_id;
             $match->player2_id = $player2_id;
             $match->match_date = $match_date;
             if ($p1_score > $p2_score) {
                 $match->winner_id = $player1_id;
             } else {
                 $match->winner_id = $player2_id;
             }
             $match->save();
             //Find the game
             $match_game = MatchGame::find($match_id);
             $game = new Game();
             if (!is_null($match_game)) {
                 $game = Game::find($match_game->game_id);
             } else {
                 //Game doesnt exist. create record in match games
                 $game->save();
                 $match_game = new MatchGame();
                 $match_game->match_id = $match_id;
                 $match_game->game_id = $game->id;
             }
             // update the game
             $game->score1 = $p1_score;
             $game->score2 = $p2_score;
             $game->save();
         }
     }
     //Redirect to add more matches; add Save Message
     return \Redirect::route('tools.league.match.edit', array($league_id, $match_id))->with('success', 'Match updated Successfully');
 }
 /**
  * Deletes old player_totals table and reload everything from
  * scratches into it.
  *
  * @return string
  */
 public function calculate()
 {
     \DB::table('player_totals')->truncate();
     $aliases = Alias::with('players')->whereNotIn('name', DeletedPlayer::lists('player_name'))->get();
     $totalServerScore = Player::sum('score');
     foreach ($aliases as $alias) {
         $playerTotal = new PlayerTotal();
         $playerTotal->name = $alias->name;
         $playerTotal->alias_id = $alias->id;
         $playerTotal->profile_id = $alias->profile_id;
         /*$playerTotal->last_loadout_id = $alias->profile->loadout_id;*/
         $playerTotal->last_team = $alias->profile->team;
         //$playerTotal->first_game_id = $alias->profile->game_first;
         //$playerTotal->last_game_id = $alias->profile->game_last;
         $playerTotal->country_id = $alias->players->last()->country_id;
         $playersCollection = $alias->players;
         //Permanent Solution
         if ($alias->profile->loadout->kyaKhali()) {
             foreach ($playersCollection->reverse() as $item) {
                 if (!$item->loadout->kyaKhali()) {
                     $playerTotal->last_loadout_id = $item->loadout_id;
                     break;
                 } else {
                     $playerTotal->last_loadout_id = $item->loadout_id;
                 }
             }
         } else {
             $playerTotal->last_loadout_id = $alias->profile->loadout_id;
         }
         $playerTotal->first_game_id = $playersCollection->min('game_id');
         $playerTotal->last_game_id = $playersCollection->max('game_id');
         $playerTotal->is_admin = $playersCollection->max('is_admin');
         $playerTotal->total_score = $playersCollection->sum('score');
         $playerTotal->highest_score = $playersCollection->max('score');
         $playerTotal->total_time_played = $playersCollection->sum('time_played');
         $playerTotal->total_kills = $playersCollection->sum('kills');
         $playerTotal->total_team_kills = $playersCollection->sum('team_kills');
         $playerTotal->total_deaths = $playersCollection->sum('deaths');
         $playerTotal->total_suicides = $playersCollection->sum('suicides');
         $playerTotal->total_arrests = $playersCollection->sum('arrests');
         $playerTotal->total_arrested = $playersCollection->sum('arrested');
         $playerTotal->best_killstreak = $playersCollection->max('kill_streak');
         $playerTotal->best_deathstreak = $playersCollection->max('death_streak');
         $playerTotal->best_arreststreak = $playersCollection->max('arrest_streak');
         $playerTotal->total_round_played = $playersCollection->unique('game_id')->count('game_id');
         $playerTotal->last_ip_address = $alias->ip_address;
         $playerTotal->killdeath_ratio = $playerTotal->total_deaths == 0 ? $playerTotal->total_kills : round($playerTotal->total_kills / $playerTotal->total_deaths, 2);
         $playerTotal->arr_ratio = $playerTotal->total_arrested == 0 ? $playerTotal->total_arrests : round($playerTotal->total_arrests / $playerTotal->total_arrested, 2);
         $playerTotal->score_per_min = $playerTotal->total_time_played == 0 ? $playerTotal->total_score : round($playerTotal->total_score / $playerTotal->total_time_played * 60, 2);
         $playerTotal->score_percentile = $playerTotal->total_score == 0 || $totalServerScore == 0 ? 0 : round($playerTotal->total_score / $totalServerScore * 100, 2);
         $won = 0;
         $lost = 0;
         $draw = 0;
         foreach ($playersCollection->unique('game_id') as $player) {
             switch ($player->game->isWinner($player->team)) {
                 case 0:
                     $lost++;
                     break;
                 case 1:
                     $won++;
                     break;
                 case -1:
                     $draw++;
                     break;
                 default:
                     break;
             }
         }
         $playerTotal->game_won = $won;
         $playerTotal->game_lost = $lost;
         $playerTotal->game_draw = $draw;
         $playerTotal->total_points = max($playerTotal->total_kills * 4 + $playerTotal->total_arrests * 13 - $playerTotal->total_deaths - $playerTotal->total_arrested * 3 - $playerTotal->total_team_kills * 2, 0);
         /**
          * This give extra points to the player from PlayerPoints Model
          */
         $playerPoints = PlayerPoint::where('name', $playerTotal->name)->get();
         if (!$playerPoints->isEmpty()) {
             $pointsToGive = $playerPoints->sum('points');
             $playerTotal->total_points += $pointsToGive;
         }
         /**
          * Calculation of player_rating
          *
          * Calculate only if player with this alias has played more than 10 hours in server
          * and also is active and seen in last 7 days
          */
         $last_seen_game = Game::find($playerTotal->last_game_id);
         if ($playerTotal->total_time_played > 60 * 60 * 10 && \Carbon\Carbon::now()->timestamp - $last_seen_game->updated_at->timestamp <= 60 * 60 * 24 * 7) {
             $playerTotal->player_rating = max($playerTotal->killdeath_ratio + $playerTotal->arr_ratio + $playerTotal->score_per_min * 1.25, 0);
             $playerTotal->player_rating = min($playerTotal->player_rating, 10);
         }
         /**
          * Calculation of rank_id using total_points and Rank table
          *
          * Add this if want time played(rank_seconds) also used to calculate ranks
          * ->where('rank_seconds', '<=' ,$playerTotal->total_time_played)
          *
          * Make sure that there are ranks in ranks table if not,
          * Run php artisan db:seed
          */
         $playerTotal->rank_id = Rank::where('rank_points', '>=', $playerTotal->total_points)->orderBy('rank_points')->first()->id;
         $playerTotal->save();
     }
     /**
      * Getting all PlayerTotal and updating its position one by one.
      */
     $pTs = PlayerTotal::orderBy('player_rating', 'DESC')->orderBy('total_points', 'DESC')->orderBy('total_score', 'DESC')->get();
     $position = 0;
     foreach ($pTs as $pT) {
         $pT->position = ++$position;
         $pT->save();
     }
     // Put to Top Player so that some bugs are fixed.
     $topPlayers = PlayerTotal::with(['country', 'rank'])->orderBy('position')->limit(10)->get();
     Cache::put('top_players', $topPlayers, 31);
     return "Players total has been logged into player_total table successfully!";
 }
Esempio n. 17
0
 public function setPrizeStatus(Request $request)
 {
     $game = Game::find($request->get('game'));
     $game->status_prize = $request->get('status');
     $game->save();
     return $game;
 }
Esempio n. 18
0
 public function editGame(Request $request)
 {
     if (Auth::check()) {
         if (Auth::user()->role == 'admin') {
             $request = json_decode($request->input, true);
             $game = \App\Game::find($request['game_id']);
             $game->game_background_img = $request['game_background_img'];
             $game->game_background_video = $request['game_background_video'];
             $game->custom_payment_link = $request['custom_payment_link'];
             $game->steam_payment_link = $request['steam_payment_link'];
             $game->ios_payment_link = $request['ios_payment_link'];
             $game->psn_payment_link = $request['psn_payment_link'];
             $game->android_payment_link = $request['android_payment_link'];
             $game->save();
             echo true;
         }
     } else {
         return view('errors.unauthorized');
     }
 }