コード例 #1
0
ファイル: PlayersController.php プロジェクト: kbiyo/ARTTv2
 public function playerDetail($id, $name)
 {
     $player = Player::find($id);
     if ($player == null) {
         abort(404);
     }
     $pname = strtolower(str_slug($player->prenom) . '-' . str_slug($player->nom));
     if (strtolower($name) != $pname) {
         abort(404);
     }
     $histo = array();
     foreach ($player->RankHistos()->orderBy('saison', 'asc')->orderBy('phase', 'asc')->get() as $rankHisto) {
         $saison = str_replace('Saison ', '', $rankHisto->saison);
         if ($rankHisto->phase == '1') {
             $saison = substr($saison, 0, 4);
             $saison = $saison . ' Q3';
         } else {
             $saison = substr($saison, 0, 4) + 1;
             $saison = $saison . ' Q1';
         }
         array_push($histo, array('saison' => $saison, 'point' => $rankHisto->point));
     }
     $adversaires = $player->Versuses()->orderBy('advclaof')->get();
     $advgrp = $adversaires->groupBy('advclaof');
     $vdgrp = $adversaires->groupBy('vd');
     $adv = array();
     foreach ($advgrp as $key => $versus) {
         array_push($adv, array('adv' => $key, 'nb' => count($versus)));
     }
     $vd = array();
     foreach ($vdgrp as $key => $versus) {
         array_push($vd, array('label' => $key == 'V' ? 'Victoires' : 'Defaites', 'value' => count($versus)));
     }
     return view('front.players.detail', array('player' => $player, 'histo' => $histo, 'adv' => $adv, 'vd' => $vd, 'rencontres' => $adversaires->sortByDesc('datef')->groupBy('date')));
 }
コード例 #2
0
ファイル: WonSet.php プロジェクト: stefanledin/mmpingis
 /**
  * Handle the event.
  *
  * @param  PlayerWonSet  $event
  * @return void
  */
 public function handle(PlayerWonSet $event)
 {
     $match = Match::find($event->player->match->id);
     $player = Player::find($event->player->id);
     $player->sets_won += 1;
     $player->save();
 }
コード例 #3
0
ファイル: BaseController.php プロジェクト: kakitsubun/wc-test
 /**
  * 构建
  * BaseController constructor.
  */
 public function __construct()
 {
     // 认证
     $objUser = Auth::user();
     $intPlayerId = $objUser->id;
     $this->_intPlayerId = $intPlayerId;
     $this->_strDeviceId = $intPlayerId;
     echo "====================================<br />";
     echo "[TOP INFO]PlayerId:" . $this->_intPlayerId . "DeviceId:" . $this->_strDeviceId . "<br />";
     echo "[TOP 菜单] ";
     echo "<a href='/game?player_id=" . $this->_intPlayerId . "&device_id=" . $this->_strDeviceId . "'>测试TOP</a> ";
     echo "<a href='/game/player?player_id=" . $this->_intPlayerId . "&device_id=" . $this->_strDeviceId . "'>玩家情报TOP</a> ";
     echo "<a href='/game/player/team?player_id=" . $this->_intPlayerId . "&device_id=" . $this->_strDeviceId . "'>玩家队伍编辑</a> ";
     echo "<a href='/game/player/card-box?player_id=" . $this->_intPlayerId . "&device_id=" . $this->_strDeviceId . "'>玩家卡片Box</a> ";
     echo "<a href='/game/player/equipment-box?player_id=" . $this->_intPlayerId . "&device_id=" . $this->_strDeviceId . "'>玩家装备Box</a>";
     echo "<br />";
     echo "====================================<br />";
     // 初始化玩家数据
     $objPlayer = Player::find($this->_intPlayerId);
     $objPlayerData = PlayerData::find($objPlayer->id);
     $this->_lstPlayer = array_merge($objPlayerData->toArray(), $objPlayer->toArray());
     echo "[TOP 玩家状态] <br />";
     echo "Lv." . $this->_lstPlayer["level"] . " 体力:" . $this->_lstPlayer["stamina"] . "/" . $this->_lstPlayer["max_stamina"];
     echo " 魔法石:" . $this->_lstPlayer["stone"];
     echo " 金币:" . $this->_lstPlayer["money"];
     echo "<br />";
     echo "====================================<br />";
 }
コード例 #4
0
ファイル: TestApi.php プロジェクト: stefanledin/mmpingis
 function test_first_point()
 {
     $this->dummyData();
     $this->assertEquals(0, Player::find($this->player1->id)->points);
     $response = $this->call('GET', '/player/1/addpoint');
     $this->assertEquals(200, $response->status());
     $this->assertEquals(1, Player::find($this->player1->id)->points);
 }
コード例 #5
0
 public function __construct()
 {
     // Always run csrf protection before the request when posting
     $playerId = Input::get('player_id');
     $player = Player::find($playerId);
     $this->_player = $player;
     $this->_playerData = PlayerData::find($player->id);
 }
コード例 #6
0
 public function appendEquipment()
 {
     $intPlayerId = Input::get('player_id');
     $intEquipmentId = Input::get('equipment_id');
     $strPlus = Input::get('plus', 0);
     $objPlayer = Player::find($intPlayerId);
     $objOwnedEquipment = $objPlayer->appendEquipment($intEquipmentId, $strPlus);
     return Response::json($objOwnedEquipment);
 }
コード例 #7
0
 function test_it_works()
 {
     $player = new Player(['nickname' => 'Stefan', 'points' => 10]);
     $opponent = new Player(['nickname' => 'Fredrik', 'points' => 9]);
     $match = Match::create(['set' => 2]);
     $match->players()->saveMany([$player, $opponent]);
     Event::fire(new App\Events\PlayerWonSet($player));
     $this->assertEquals(2, Match::find($match->id)->currentSet());
     $this->assertEquals(1, Player::find($player->id)->sets_won);
 }
コード例 #8
0
 public function test_player1_wins_match()
 {
     $player1 = new Player(['points' => 10, 'sets_won' => 1]);
     $player2 = new Player(['points' => 9, 'sets_won' => 1]);
     $match = Match::create();
     $match->players()->saveMany([$player1, $player2]);
     $match->addPointFor($player1);
     $this->assertEquals($player1->id, Match::find($match->id)->won_by);
     $this->assertEquals(2, Player::find($player1->id)->sets_won);
 }
コード例 #9
0
ファイル: BaseController.php プロジェクト: kakitsubun/wc-test
 public function __construct()
 {
     // Always run csrf protection before the request when posting
     $this->beforeFilter(function () {
         $deviceId = Input::get('device_id');
         $playerId = Input::get('player_id');
         $player = Player::find($playerId);
         if (!$player || $player->device_id != $deviceId) {
             return 'Login Error';
         }
         $this->_player = $player;
         $this->_playerData = PlayerData::find($player->id);
     });
     // Here's something that happens after the request
     $this->afterFilter(function () {
         // something
     });
 }
コード例 #10
0
ファイル: Game.php プロジェクト: VovikeMS/darts
 public function bestPlayer()
 {
     $sums = [];
     foreach ($this->Scores as $score) {
         if (!isset($sums[$score->player_id])) {
             $sums[$score->player_id] = 0;
         }
         $sums[$score->player_id] += $score->score;
     }
     $user_id = 0;
     $max = max($sums);
     foreach ($sums as $id => $sum) {
         if ($sum === $max) {
             $user_id = $id;
             break;
         }
     }
     return Player::find($user_id);
 }
コード例 #11
0
ファイル: PlayersController.php プロジェクト: kbiyo/ARTTv2
 public function PostPlayerEmail(Request $request, $id)
 {
     $player = Player::find($id);
     $iid = $request->input('id');
     $nom = $request->input('nom');
     $prenom = $request->input('prenom');
     $email = $request->input('email');
     $errors = array();
     if ($player->id != $iid) {
         array_push($errors, 'Une erreur est survenue lors de la mise à jour de l\'email.');
     }
     if ($player->nom != $nom || $player->prenom != $prenom) {
         array_push($errors, 'Une erreur est survenue lors de la mise à jour de l\'email.');
     }
     if (count($errors) == 0) {
         $player->email = $email;
         $player->save();
         Session::flash('success', 'L\'adresse email de ' . $prenom . ' ' . $nom . ' a bien été modifiée.');
         return redirect()->route('AdmBatchsPlayers');
     }
     Session::flash('errors', $errors);
     return redirect()->route('AdmBatchsPlayers');
 }
コード例 #12
0
 /**
  * Web测试首页
  */
 public function index()
 {
     $intPlayerId = $this->_intPlayerId;
     $strDeviceId = $this->_strDeviceId;
     $objPlayer = Player::find($intPlayerId);
     echo "Game Index<br />";
     if (!$intPlayerId || $intPlayerId == 0) {
         echo "无PlayerID<br />";
     } else {
         if (!$objPlayer) {
             echo "无用户数据<br />";
             echo "<a href='/game/player/create?device_id=" . $strDeviceId . "'>新建玩家</a><br />";
             //        } else if (!$strDeviceId || $strDeviceId == "") {
             //            echo "无终端ID<br />";
             //        } else if ($objPlayer->device_id != $strDeviceId) {
             //            echo "玩家DeviceId不正确<br />";
         } else {
             echo "<a href='/game/player?player_id=" . $intPlayerId . "&device_id=" . $strDeviceId . "'>玩家情报</a><br />";
             echo "<a href='/game/battle?player_id=" . $intPlayerId . "&device_id=" . $strDeviceId . "'>战斗情报</a><br />";
             echo "<a href='/game/dungeon?player_id=" . $intPlayerId . "&device_id=" . $strDeviceId . "'>地下城探险开始</a><br />";
         }
     }
 }
コード例 #13
0
 /**
  * 冒险中的事件发生处理 完成度20%
  * @param $objBattle
  * @return mixed
  */
 public function happen($objBattle)
 {
     // 取得事件的Master内容
     $objIncident = Incident::find($this->incident_id);
     if (empty($objIncident->target_category) || !$objIncident->target_category) {
         return $objBattle;
     }
     // 根据事件类型进行不同处理
     switch ($objIncident->target_category) {
         case 'hp':
             if ($objIncident->type == 'good') {
                 $objBattle->buff_hp = $objBattle->buff_hp + $this->power;
             } else {
                 $objBattle->buff_hp = $objBattle->buff_hp - $this->power;
             }
             break;
         case 'atk':
             if ($this->type == 'good') {
                 $objBattle->buff_atk = $objBattle->buff_atk + $this->power;
             } else {
                 $objBattle->buff_atk = $objBattle->buff_atk - $this->power;
             }
             break;
         case 'def':
             if ($objIncident->type == 'good') {
                 $objBattle->buff_def = $objBattle->buff_def + $this->power;
             } else {
                 $objBattle->buff_def = $objBattle->buff_def - $this->power;
             }
             break;
         case 'spd':
             if ($objIncident->type == 'good') {
                 $objBattle->buff_spd = $objBattle->buff_spd + $this->power;
             } else {
                 $objBattle->buff_spd = $objBattle->buff_spd - $this->power;
             }
             break;
         case 'spd':
             if ($objIncident->type == 'good') {
                 $objBattle->buff_spd = $objBattle->buff_spd + $this->power;
             } else {
                 $objBattle->buff_spd = $objBattle->buff_spd - $this->power;
             }
             break;
         case 'card':
             break;
         case 'item':
             break;
         case 'money':
             $player = Player::find($objBattle->player_id);
             if ($objIncident->type == 'good') {
                 $player->appendMoney($this->power);
             } else {
                 $player->appendMoney(0 - $this->power);
             }
             break;
         default:
             # code...
             break;
     }
     return $objBattle;
 }
コード例 #14
0
ファイル: FfttAPIController.php プロジェクト: kbiyo/ARTTv2
 public function RunUpdatePlayer($id)
 {
     $licencie = Player::find($id);
     Artisan::call('FFTT:Player', ['licence' => $licencie->licence]);
     return redirect()->route('AdmBatchsPlayers');
 }
コード例 #15
0
 /**
  * Save a match to the provided event
  *
  * @return redirect
  **/
 public function saveMatch(CreateMatchRequest $request, Event $event)
 {
     $match = new Match();
     $match->match_type_id = MatchType::where('identifier', $event->type)->first()->id;
     $match->event_id = $event->id;
     $match->save();
     // if there is a team selected then we're going with teams.
     if ($request->teamBlack) {
         $match->teams()->save(Team::find($request->teamBlack));
         $match->teams()->save(Team::find($request->teamYellow));
     } elseif ($request->playersBlack) {
         $teamBlack = new Team();
         $teamBlack->save();
         $teamYellow = new Team();
         $teamYellow->save();
         foreach ($request->playersBlack as $key => $playerId) {
             $teamBlack->players()->save(Player::find($playerId));
             $teamYellow->players()->save(Player::find($request->playersYellow[$key]));
         }
         $match->teams()->save($teamBlack);
         $match->teams()->save($teamYellow);
     }
     return redirect()->route('dashboard.events.single', $event->id)->with('app-success', 'Match created successfully.');
 }
コード例 #16
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($player, $entry, $opponent_id)
 {
     $opponent = Player::find($opponent_id);
     $opplog = [];
     // OpponentLog::where('opponent_id' , '=', $opponent_id);
     //Match History
     $h2h = new Match();
     $head2head = $h2h->head2head($player->player_id, $opponent->player_id);
     //Evaluation
     $evaluation_id = 28;
     // get opponent evalution_id by table PlayerID -> entry_ID -> Opponent_id
     $categories = EvaluationCategory::all();
     $evaluation = PlayerEvaluation::find($evaluation_id);
     $scores = EvaluationScore::where('evaluation_id', '=', $evaluation_id);
     //Notes
     //
     //
     //
     return view('pages/players/journal/opponent/show', compact('player', 'entry', 'opponent', 'opplog', 'head2head', 'evaluation', 'categories', 'scores'));
 }
コード例 #17
0
ファイル: PlayerController.php プロジェクト: VovikeMS/darts
 /**
  * Delete player by id.
  *
  * @param  int  $id
  * @return Response
  */
 public function delete($id)
 {
     $player = NULL;
     if (is_numeric($id)) {
         $player = Player::find($id)->first();
     } else {
         $player = Player::where('nick', '=', $id)->first();
     }
     if ($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);
     }
     $player->delete();
     return \Redirect::route('players');
 }
コード例 #18
0
ファイル: routes.php プロジェクト: jenidarnold/racquetball
 $state = \DB::select(DB::raw($query));
 $arr_state = array();
 foreach ($state as $key => $n) {
     $row = array();
     $row['ranking_date'] = $n->ranking_date;
     $row["{$location->location}"] = intval($n->ranking);
     array_push($arr_state, $row);
 }
 /*Compare closest 3 rankings */
 /*get compare player ranking above*/
 $query_player1_id = "\n\t\tSELECT \n\t\t\tplayer_id\n\t\tFROM\n\t\t\trankings\n\t\tWHERE\n\t\t\tlocation_id = {$location_id}\n\t\t\tAND group_id = {$group_id}\n\t\t\tand ranking < {$player->state_rank}\n\t\tORDER BY \n\t\t\tranking_date DESC, ranking DESC\n\t\tLIMIT 1\n\t\t";
 $compare_player_1 = Player::find(\DB::select(DB::raw($query_player1_id))[0]->player_id);
 /*get compare2 id */
 /*get compare player ranking below*/
 $query_player2_id = "\n\t\tSELECT \n\t\t\tplayer_id\n\t\tFROM\n\t\t\trankings\n\t\tWHERE\n\t\t\tlocation_id = {$location_id}\n\t\t\tAND group_id = {$group_id}\n\t\t\tand ranking > {$player->state_rank}\n\t\tORDER BY \n\t\t\tranking_date DESC, ranking \n\t\tLIMIT 1\n\t\t";
 $compare_player_2 = Player::find(\DB::select(DB::raw($query_player2_id))[0]->player_id);
 /*get comare 1 player history */
 $query_compare = "\n\t\tSELECT \n\t\t\t*\n\t\tFROM\n\t\t\t(\n\t\t\t\tSELECT \n\t\t\t\t\tdate_format(ranking_date, '%m/%d/%Y') as ranking_date,\n\t\t\t\t\tranking as my_ranking\n\t\t\t\tFROM\n\t\t\t\t\trankings\n\t\t\t\tWHERE\n\t\t\t\t\tplayer_id = {$player_id}\n\t\t\t\t\tAND group_id = {$group_id}\n\t\t\t\t\tAND location_id = {$location_id}\n\t\t\t) as p1\n\t\tINNER JOIN\n\t\t\t(\n\t\t\t\tSELECT \n\t\t\t\t\tdate_format(ranking_date, '%m/%d/%Y') as ranking_date,\n\t\t\t\t\tranking as c1_ranking\n\t\t\t\tFROM\n\t\t\t\t\trankings\n\t\t\t\tWHERE\n\t\t\t\t\tplayer_id = {$compare_player_1->player_id}\n\t\t\t\t\tAND group_id = {$group_id}\n\t\t\t\t\tAND location_id = {$location_id}\n\t\t\t) as p2\n\t\tON p1.ranking_date = p2.ranking_date\n\t\tINNER JOIN\n\t\t\t(\n\t\t\t\tSELECT \n\t\t\t\t\tdate_format(ranking_date, '%m/%d/%Y') as ranking_date,\n\t\t\t\t\tranking as c2_ranking\n\t\t\t\tFROM\n\t\t\t\t\trankings\n\t\t\t\tWHERE\n\t\t\t\t\tplayer_id = {$compare_player_2->player_id}\n\t\t\t\t\tAND group_id = {$group_id}\n\t\t\t\t\tAND location_id = {$location_id}\n\t\t\t) as p3 \n\t\tON p2.ranking_date = p3.ranking_date\t\n\t\tORDER BY \n\t\t\tp1.ranking_date\n\t\t";
 $compare = \DB::select(DB::raw($query_compare));
 $arr_compare = array();
 /* Add players history*/
 foreach ($compare as $key => $n) {
     $row = array();
     $row['ranking_date'] = $n->ranking_date;
     $row["{$compare_player_1->first_name}"] = intval($n->c1_ranking);
     $row["{$player->first_name}"] = intval($n->my_ranking);
     $row["{$compare_player_2->first_name}"] = intval($n->c2_ranking);
     array_push($arr_compare, $row);
 }
 $rankings = ["National" => $arr_national, "State" => $arr_state, "Compare" => $arr_compare];
 return $rankings;
コード例 #19
0
ファイル: TestMatch.php プロジェクト: stefanledin/mmpingis
 public function test_player1_wins_set_and_player2_scores_first_in_second_set()
 {
     $player1 = new Player(['nickname' => 'Stefan', 'points' => 10]);
     $player2 = new Player(['nickname' => 'Fredrik', 'points' => 9]);
     $match = Match::create();
     $match->players()->saveMany([$player1, $player2]);
     $match->addPointFor($player1);
     $expected = (object) array('Stefan' => 11, 'Fredrik' => 9);
     $this->assertEquals($expected, $match->getScore());
     $this->assertEquals(1, Player::find($player1->id)->sets_won);
     $this->assertEquals(0, Player::find($player2->id)->sets_won);
     $match->startNewSet();
     $match->resetPlayerPoints();
     $expected = (object) array('Stefan' => 0, 'Fredrik' => 0);
     $this->assertEquals(2, Match::find($match->id)->currentSet());
     $this->assertEquals($expected, $match->getScore());
     $this->assertEquals(1, Player::find($player1->id)->sets_won);
     $this->assertEquals(0, Player::find($player2->id)->sets_won);
 }
コード例 #20
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function storePlayer(Request $request)
 {
     $player = new Player();
     $league_id = Input::get('league_id');
     $player_id = Input::get('player_id');
     // Player already exists?
     if (!is_null($player_id)) {
         $player = Player::find($player_id);
     } else {
         $user = new User();
         $user->first_name = Input::get('first_name');
         $user->last_name = Input::get('last_name');
         $user->email = Input::get('email');
         $user->save();
         $player = new Player();
         $player->first_name = Input::get('first_name');
         $player->last_name = Input::get('last_name');
         $player->player_id = $user->id;
         $player->save();
     }
     //Insert into league
     if ($player->player_id > 0) {
         $league_player = new LeaguePlayer();
         $league_player->player_id = $player->player_id;
         $league_player->league_id = $league_id;
         $league_player->save();
     }
     return \Redirect::route('tools.league.join', array($league_id));
 }
コード例 #21
0
 /**
  * 取得冒险的最新信息
  * 更新冒险信息
  */
 public function info()
 {
     // TODO 处理时间过长
     $intPlayerId = Input::get('player_id', 0);
     $intDungeonId = Input::get('dungeon_id', 0);
     $intBattleId = Input::get('battle_id', 0);
     if ($intPlayerId == 0 || $intDungeonId == 0 || $intBattleId == 0) {
         return "";
     }
     $objBattle = Battle::find($intBattleId);
     if (!$objBattle) {
         return "Battle is not exsit";
     }
     if ($objBattle->player_id != $intPlayerId) {
         // 不正PlayerID
     }
     if ($objBattle->dungeon_id != $intDungeonId) {
         // 不正地下城ID
     }
     $objPlayer = Player::find($intPlayerId);
     // Battle状态检查
     if ($objBattle->status >= 2) {
         // 冒险失败的场合
         $ojbBattleDetails = BattleDetail::where('battle_id', $intBattleId)->get();
         $lstBattleInfo = array('info' => $objBattle->toArray(), 'detail' => $ojbBattleDetails->toArray());
         return Response::json($lstBattleInfo);
     }
     // Dungeon进展&情报
     $dungeonInfo = Dungeon::getInfo($intDungeonId);
     $intCurrentFloor = $objBattle->current_floor;
     $objDungeon = Dungeon::find($intDungeonId);
     // 进展计算
     $now = Carbon::now();
     if ($objBattle->end_datetime >= $now) {
         // 未结束
         $startDate = new Carbon($objBattle->start_datetime);
         $intFloorDiff = $now->diffInMinutes($startDate) - $intCurrentFloor;
         $objBattle->current_floor = $intCurrentFloor + $intFloorDiff;
     } else {
         // 结束
         $intFloorDiff = $objBattle->floor - $intCurrentFloor;
         $objBattle->current_floor = $objDungeon->floor;
         $objBattle->status = 2;
     }
     // 副本的格数取得
     $intDungeonGrid = $objDungeon->grid;
     $floorDiffForUpdate = $intFloorDiff;
     // Transaction Start
     // 每层遍历循环
     // Battle Type #TODO
     // 起始层数初期化
     $intFloorCount = 0;
     // 战斗循环开始
     while ($intFloorCount < $intFloorDiff) {
         // TODO Debug用时间
         $debugStartDatetime = date("Y-m-d h:i:s");
         // 已模拟的层数自增
         $intFloorCount++;
         // 取得本次便利应该模拟的层数
         $intFloor = $intFloorCount + $intCurrentFloor;
         Log::info("[BattleC]冒险处理开始 第[" . $intFloor . "]层:" . $debugStartDatetime);
         // Grid随机取得 TODO Grid加成
         $grid = mt_rand(1, $intDungeonGrid);
         // 测试用Log
         Log::info("[BattleC][探险模拟]: ID:" . $intBattleId . " 层数:" . $intFloor . " 格数:" . $grid . "!!!");
         $objBattleDetail = new BattleDetail();
         $objBattleDetail->battle_id = $intBattleId;
         $objBattleDetail->floor = $intFloor;
         $objBattleDetail->grid = $grid;
         $objBattleDetail->fight_id = 0;
         //仮
         $objBattleDetail->incident_id = 0;
         //仮
         // 该地下城该行该列的特定敌人的列表取得 TODO Cache
         $objEnemy = DungeonEnemy::where('dungeon_id', $intDungeonId)->where('floor', $intFloor)->whereIn('grid', array($grid, 0))->get();
         // 该地下城该行该列的特定事件列表取得 TODO Cache
         $lstIncidents = DungeonIncident::where('dungeon_id', $intDungeonId)->where('floor', $intFloor)->whereIn('grid', array($grid, 0))->get();
         // TODO Fight 目前的过于复杂和难以表现
         // Insert Detail && Log
         /*
                     if ($result->first()) { }
                     if (!$result->isEmpty()) { }
                     if ($result->count()) { }
                     if (count($result)) { }
         */
         if (!$objEnemy->isEmpty()) {
             // 该层为特定敌人的场合
             Log::info("[BattleC][战斗模拟]:Fight");
             // 战斗相关处理
             $objFight = new Fight();
             // 战斗初始化
             $objFight->initFight($objBattle, $objEnemy, $intFloor);
             // 战斗处理
             $result = $objFight->fight();
             // $fight->fightBy($battle,$enemy,$floor);
             if ($result) {
                 // 胜利
             } else {
                 // 战败
             }
             // 层详细记录
             $objBattleDetail->fight_id = $objFight->id;
             //仮
             $objBattleDetail->action = 'fight';
         } elseif (!$lstIncidents->isEmpty()) {
             // 该层为特定事件的场合
             Log::info("[BattleC][事件模拟]:事件");
             $objIncidents = $this->_drawing($lstIncidents->toArray());
             $objIncidents = DungeonIncident::find($objIncidents['id']);
             // 事件相关处理
             $objBattle = $objIncidents->happen($objBattle);
             // 层详细记录
             $objBattleDetail->incident_id = $objIncidents['incident_id'];
             $objBattleDetail->action = 'incident';
         } else {
             // 该层为无固定战斗或事件的情况下,依照地下城表中设定的各个项目的概率计算
             $boolDoneFlag = false;
             $objEnemy = DungeonEnemy::where('dungeon_id', $intDungeonId)->where('floor', 0)->whereIn('grid', array($grid, 0))->get();
             if (!$objEnemy->isEmpty()) {
                 // 有随机敌人 抽选是否战斗
                 // TODO 抽选几率测试中
                 $battleRate = mt_rand(0, 100);
                 if ($battleRate < 50) {
                     // 本层玩家Flag
                     $boolDoneFlag = true;
                     // 战斗实例
                     $objFight = new Fight();
                     // 战斗初始化
                     $objFight->initFight($objBattle, $objEnemy, $intFloor);
                     // 战斗流程
                     $result = $objFight->fight();
                     // 记录战斗ID等到层详细记录
                     $objBattleDetail->fight_id = $objFight->id;
                     //仮
                     $objBattleDetail->action = 'fight';
                 }
             } else {
                 // 事件发生
                 $lstIncidents = DungeonIncident::where('dungeon_id', $intDungeonId)->where('floor', 0)->whereIn('grid', array($grid, 0))->get();
                 if (!$lstIncidents->isEmpty()) {
                     // 是否有随机事件发生
                     // TEST TODO
                     $incidentRate = mt_rand(0, 100);
                     if ($incidentRate < 50) {
                         $boolDoneFlag = true;
                         $objIncidents = $this->_drawing($lstIncidents->toArray());
                         $objIncidents = DungeonIncident::find($objIncidents['id']);
                         // 事件相关处理
                         $objBattle = $objIncidents->happen($objBattle);
                         $objBattleDetail->incident_id = $objIncidents['incident_id'];
                         $objBattleDetail->action = 'incident';
                     }
                 }
             }
             // 既没战斗也没发生事件时
             if (!$boolDoneFlag) {
                 $boolDoneFlag = true;
                 $objBattleDetail->action = 'none';
             }
         }
         $objBattleDetail->save();
         $debugEndDatetime = date("Y-m-d h:i:s");
         $timeDiff = strtotime($debugEndDatetime) - strtotime($debugStartDatetime);
         Log::info("[BattleC]处理结束[" . $intFloor . "]:" . $debugEndDatetime . "!!!!!");
         Log::info("[BattleC]处理时间[" . $intFloor . "]:" . $timeDiff . "!!!!!");
     }
     // 成功结束战斗 各种报酬赋予
     if ($objBattle->status == 2) {
         // 该副本报酬列表取得
         $lstDungeonRewards = $dungeonInfo['reward'];
         // 报酬列表遍历
         foreach ($lstDungeonRewards->toArray() as $lstReward) {
             // 报酬有金币的时候
             if ($lstReward['type'] == 'money') {
                 $objPlayer->appendMoney($lstReward['num']);
             }
             // 报酬有经验的时候
             if ($lstReward['type'] == 'exp') {
                 $isLevelUp = $objPlayer->appendExp($lstReward['num']);
             }
             // 报酬有装备的时候(TODO 装备素材)
             if ($lstReward['type'] == 'equipment') {
                 $isLevelUp = $objPlayer->appendEquipment($lstReward['equipment_id']);
             }
             // 报酬有卡片的时候
             if ($lstReward['type'] == 'card') {
                 $objPlayer->appendCard($lstReward['card_id']);
             }
             // TODO 报酬有卡片经验的时候
         }
         // TODO
         // 玩家地下城数据更新
         // 攻略情况
         // 完成度
     }
     // 失败的情况 给与卡片出场层数的奖励
     if ($objBattle->status == 3) {
         #TODO
     }
     // Update Battle
     $objBattle->save();
     // Transaction End
     // return $battleDetails;
     $ojbBattleDetails = BattleDetail::where('battle_id', $intBattleId)->get();
     // return Response::json($battleDetails->toArray());
     $battleInfo = array('info' => $objBattle->toArray(), 'detail' => $ojbBattleDetails->toArray());
     return Response::json($battleInfo);
 }
コード例 #22
0
ファイル: Kernel.php プロジェクト: huludini/pw-web
 /**
  * Define the application's command schedule.
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     /*
      * Cubi Transferring
      */
     $schedule->call(function () {
         $transfers = Transfer::all();
         foreach ($transfers as $transfer) {
             if (!DB::table('usecashnow')->where('userid', $transfer->user_id)->where('zoneid', $transfer->zone_id)->take(1)->exists()) {
                 DB::table('usecashnow')->insert(['userid' => $transfer->user_id, 'zoneid' => $transfer->zone_id, 'sn' => 0, 'aid' => 1, 'point' => 0, 'cash' => $transfer->cash, 'status' => 1, 'creatime' => Carbon::now()]);
                 DB::table('pweb_transfer')->where('user_id', $transfer->user_id)->where('zone_id', $transfer->zone_id)->where('cash', $transfer->cash)->take(1)->delete();
             }
         }
     })->everyMinute();
     /*
      * Update Players
      */
     $schedule->call(function () {
         $api = new API();
         if ($api->online) {
             set_time_limit(0);
             $users = User::all();
             foreach ($users as $user) {
                 $roles = $api->getRoles($user->ID) ? $api->getRoles($user->ID)['roles'] : [];
                 foreach ($roles as $role) {
                     $role_data = $api->getRole($role['id']);
                     $var_data = settings('server_version') != '07' ? $api->parseOctet($role_data['status']['var_data'], 'var_data') : ['pk_count' => 0, 'dead_flag' => 0];
                     if (!empty($role_data['status']['faction_contrib'])) {
                         $faction_contrib = $api->parseOctet($role_data['status']['faction_contrib'], 'faction_contrib');
                     }
                     if (!empty($role_data['status']['force_data'])) {
                         $force_data = $api->parseOctet($role_data['status']['force_data'], 'force_data');
                     }
                     if (!empty($role_data['status']['title_data'])) {
                         $title_data = $api->parseOctet($role_data['status']['title_data'], 'title_data');
                     }
                     $user_faction = $api->getUserFaction($role['id']);
                     if (!empty($user_faction['fid'])) {
                         $faction_info = $api->getFactionInfo($user_faction['fid']);
                     }
                     $role_info = ['id' => $role_data['base']['id'], 'name' => $role_data['base']['name'], 'cls' => $role_data['base']['cls'], 'gender' => $role_data['base']['gender'], 'spouse' => $role_data['base']['spouse'], 'level' => $role_data['status']['level'], 'level2' => $role_data['status']['level2'], 'hp' => $role_data['status']['hp'], 'mp' => $role_data['status']['mp'], 'pariah_time' => $role_data['status']['pariah_time'], 'reputation' => $role_data['status']['reputation'], 'time_used' => $role_data['status']['time_used'], 'pk_count' => $var_data['pk_count'], 'dead_flag' => $var_data['dead_flag'], 'force_id' => !empty($force_data['cur_force_id']) ? $force_data['cur_force_id'] : 0, 'title_id' => !empty($title_data['cur_title_id']) ? $title_data['cur_title_id'] : 0, 'faction_id' => !empty($user_faction['fid']) ? $user_faction['fid'] : '', 'faction_name' => !empty($faction_info['name']) ? $faction_info['name'] : '', 'faction_role' => !empty($user_faction['role']) ? $user_faction['role'] : '', 'faction_contrib' => !empty($faction_contrib['consume_contrib']) ? $faction_contrib['consume_contrib'] : 0, 'faction_feat' => !empty($faction_contrib['cumulate_contrib']) ? $faction_contrib['cumulate_contrib'] : 0, 'equipment' => json_encode($role_data['equipment'])];
                     if ($player = Player::find($role_info['id'])) {
                         $player->update($role_info);
                     } else {
                         Player::create($role_info);
                     }
                     unset($role_data);
                     unset($var_data);
                     unset($force_data);
                     unset($faction_info);
                     unset($faction_contrib);
                     unset($user_faction);
                 }
             }
         }
     })->everyTenMinutes();
     /*
      * Update Factions
      */
     $schedule->call(function () {
         $gamed = new Gamed();
         $api = new API();
         $handler = NULL;
         if ($api->online) {
             set_time_limit(0);
             do {
                 $raw_info = $api->getRaw('factioninfo', $handler);
                 if (isset($raw_info['Raw']) || count($raw_info['Raw']) > 1) {
                     return true;
                 }
                 for ($i = 0; $i < count($raw_info['Raw']); $i++) {
                     if (empty($raw_info['Raw'][$i]['key']) || empty($raw_info['Raw'][$i]['value'])) {
                         unset($raw_info['Raw'][$i]);
                         continue;
                     }
                     $id = $gamed->getArrayValue(unpack("N", pack("H*", $raw_info['Raw'][$i]['key'])), 1);
                     $pack = pack("H*", $raw_info['Raw'][$i]['value']);
                     $faction = $gamed->unmarshal($pack, $api->data['FactionInfo']);
                     if (!empty($faction['master']['roleid']) && $faction['master']['roleid'] > 0) {
                         $user_faction = $api->getUserFaction($faction['master']['roleid']);
                         $faction_info = ['id' => $faction['fid'], 'name' => $faction['name'], 'level' => $faction['level'] + 1, 'master' => $faction['master']['roleid'], 'master_name' => $user_faction['name'], 'members' => count($faction['member']), 'reputation' => $this->getFactionStat($faction['fid'], 'reputation') > 0 ? $this->getFactionStat($faction['fid'], 'reputation') : 0, 'time_used' => $this->getFactionStat($faction['fid'], 'time_used') > 0 ? $this->getFactionStat($faction['fid'], 'time_used') : 0, 'pk_count' => $this->getFactionStat($faction['fid'], 'pk_count') > 0 ? $this->getFactionStat($faction['fid'], 'pk_count') : 0, 'announce' => $faction['announce'], 'territories' => Territory::where('owner', $faction['fid'])->count()];
                         if ($faction = Faction::find($faction_info['id'])) {
                             $faction->update($faction_info);
                         } else {
                             Faction::create($faction_info);
                         }
                     }
                     unset($id);
                     unset($faction);
                     unset($user_faction);
                     unset($raw_info['Raw'][$i]['value']);
                 }
                 $raw_count = count($raw_info['Raw']) - 1;
                 $last_raw = $raw_info['Raw'][$raw_count];
                 $last_key = $last_raw['key'];
                 $new_key = hexdec($last_key) + 1;
                 $handler = bin2hex(pack("N*", $new_key));
             } while (TRUE);
         }
     })->everyTenMinutes();
     /*
      * Update Territories
      */
     $schedule->call(function () {
         $api = new API();
         if ($api->online) {
             $territories = $api->getTerritories() ? $api->getTerritories()['Territory'] : [];
             foreach ($territories as $territory) {
                 if ($territory['owner'] > 0) {
                     $owner = $api->getFactionInfo($territory['owner']);
                 }
                 if ($territory['challenger'] > 0) {
                     $challenger = $api->getFactionInfo($territory['challenger']);
                 }
                 $territory_info = ['id' => $territory['id'], 'level' => $territory['level'], 'owner' => $territory['owner'], 'owner_name' => !empty($owner['name']) ? $owner['name'] : '', 'occupy_time' => $territory['occupy_time'], 'challenger' => $territory['challenger'], 'challenger_name' => !empty($challenger['name']) ? $challenger['name'] : '', 'deposit' => $territory['deposit'], 'cutoff_time' => $territory['cutoff_time'], 'battle_time' => $territory['battle_time'], 'bonus_time' => $territory['bonus_time'], 'color' => $territory['color'], 'status' => $territory['status'], 'timeout' => $territory['timeout'], 'maxbonus' => $territory['maxbonus'], 'challenge_time' => $territory['challenge_time'], 'challengerdetails' => $territory['challengerdetails']];
                 if ($territory = Territory::find($territory_info['id'])) {
                     $territory->update($territory_info);
                 } else {
                     Territory::create($territory_info);
                 }
                 unset($owner);
                 unset($challenger);
             }
         }
     })->everyTenMinutes();
 }
コード例 #23
0
 /**
  * [测试用] 赋予玩家一张卡片
  */
 public function appendCard()
 {
     echo "AppendCard<br />";
     // 取得卡片ID
     $intCardId = Input::get("card_id");
     if (!$intCardId || $intCardId == 0) {
         echo "不正的卡片ID";
     } else {
         $objPlayer = Player::find($this->_intPlayerId);
         $objPlayer->appendCard($intCardId);
         echo "赋予成功";
     }
 }
コード例 #24
0
ファイル: Match.php プロジェクト: stefanledin/mmpingis
 /**
  * Checks if the player won the match
  *
  * @return bool
  */
 protected function playerWonMatch(Player $player)
 {
     $sets_won = Player::find($player->id)->sets_won;
     if ($sets_won == 2) {
         return true;
     }
     return false;
 }
コード例 #25
0
ファイル: Battle.php プロジェクト: kakitsubun/wc-test
 /**
  * 冒险过程处理
  */
 public function doBattle()
 {
     if (!$this) {
         echo "Battle is not exsit";
     }
     // 各种常用数据整合
     $intPlayerId = $this->player_id;
     $intBattleId = $this->id;
     $intDungeonId = $this->dungeon_id;
     $objPlayer = Player::find($intPlayerId);
     // Battle状态检查
     if ($this->status >= self::BATTLE_WIN_STATUS) {
         // 冒险已经结束的情况下,不再进行计算
         $ojbBattleDetails = BattleDetail::where('battle_id', $intBattleId)->get();
         $lstBattleInfo = array('info' => $this->toArray(), 'detail' => $ojbBattleDetails->toArray());
         return $lstBattleInfo;
     }
     // Dungeon进展&情报
     $objDungeonInfo = Dungeon::getInfo($intDungeonId);
     $objDungeon = Dungeon::find($intDungeonId);
     $intCurrentFloor = $this->current_floor;
     // 进展计算
     $objNow = Carbon::now();
     if ($this->end_datetime >= $objNow) {
         /** 本次冒险未结束 */
         $startDate = new Carbon($this->start_datetime);
         // 计算需要处理的层数
         $intFloorDiff = $objNow->diffInMinutes($startDate) - $intCurrentFloor;
     } else {
         /** 本次冒险结束 */
         // 计算需要处理的层数
         $intFloorDiff = $this->floor - $intCurrentFloor;
         // 冒险结束状态码
         $this->status = self::BATTLE_WIN_STATUS;
     }
     // 副本的格数取得
     $intDungeonGrid = $objDungeon->grid;
     Log::info("[BattleC]冒险处理开始");
     // TODO Fight 目前的过于复杂和难以表现
     // Truncate
     DB::beginTransaction();
     // 需要计算的起始层数数量初期化
     $intFloorCount = 0;
     // 战斗循环开始
     while ($intFloorCount < $intFloorDiff) {
         if ($this->status > self::BATTLE_WIN_STATUS) {
             // 循环结束
             break;
         }
         // 每层遍历循环
         // Battle Type #TODO
         // Debug用时间
         $debugStartDatetime = date("Y-m-d h:i:s");
         // 已模拟的层数自增
         $intFloorCount++;
         // 取得本次遍历应该模拟的层数
         $intFloor = $intFloorCount + $intCurrentFloor;
         Log::info("[BattleC]冒险处理开始 第[" . $intFloor . "]层:" . $debugStartDatetime);
         // Grid随机取得 TODO Grid加成
         $intGrid = mt_rand(1, $intDungeonGrid);
         // 测试用Log
         Log::info("[BattleC][探险模拟]: ID:" . $intBattleId . " 层数:" . $intFloor . " 格数:" . $intGrid . "!!!");
         // 每层冒险详细对象初始化
         $objBattleDetail = new BattleDetail();
         $objBattleDetail->battle_id = $intBattleId;
         $objBattleDetail->floor = $intFloor;
         $objBattleDetail->grid = $intGrid;
         $objBattleDetail->fight_id = 0;
         //仮
         $objBattleDetail->incident_id = 0;
         //仮
         // 层冒险的战斗细节处理
         $this->_doBattleTurn($objBattleDetail);
         // Debug时间和Log
         $debugEndDatetime = date("Y-m-d h:i:s");
         $timeDiff = strtotime($debugEndDatetime) - strtotime($debugStartDatetime);
         Log::info("[BattleC]处理结束[" . $intFloor . "]:" . $debugEndDatetime . "!!!!!");
         Log::info("[BattleC]处理时间[" . $intFloor . "]:" . $timeDiff . "!!!!!");
     }
     $this->current_floor = $intFloor;
     // 成功结束战斗 各种报酬赋予
     if ($this->status == self::BATTLE_WIN_STATUS) {
         // 该副本报酬列表取得
         $lstDungeonRewards = $objDungeonInfo['reward'];
         // 报酬列表遍历
         foreach ($lstDungeonRewards->toArray() as $lstReward) {
             // 报酬有金币的时候
             if ($lstReward['type'] == 'money') {
                 $objPlayer->appendMoney($lstReward['num']);
             }
             // 报酬有经验的时候
             if ($lstReward['type'] == 'exp') {
                 $isLevelUp = $objPlayer->appendExp($lstReward['num']);
             }
             // 报酬有装备的时候(TODO 装备素材)
             if ($lstReward['type'] == 'equipment') {
                 $objOwnedEquipment = $objPlayer->appendEquipment($lstReward['equipment_id']);
             }
             // 报酬有卡片的时候
             if ($lstReward['type'] == 'card') {
                 $objOwnedCard = $objPlayer->appendCard($lstReward['card_id']);
             }
             // TODO 报酬有卡片经验的时候
         }
         // TODO // 玩家地下城数据更新 // 攻略情况 // 完成度
     }
     // 失败的情况 给与卡片出场层数的奖励
     if ($this->status == self::BATTLE_FAIL_STATUS) {
         // TODO
     }
     // Transaction结束
     if ($this->save()) {
         DB::commit();
     } else {
         DB::rollback();
     }
     // 结果返回
     $ojbBattleDetails = BattleDetail::where('battle_id', $intBattleId)->get();
     $lstBattleInfo = array('info' => $this->toArray(), 'detail' => $ojbBattleDetails->toArray());
     return $lstBattleInfo;
 }
コード例 #26
0
 protected function delete(Request $request)
 {
     $user = Player::find($request->player);
     $user->delete();
     return redirect()->action('TeamsController@edit', $request->team_name);
 }
コード例 #27
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $player = Player::find($id);
     $file = $player->photo;
     if (\File::isFile($file)) {
         \File::delete($file);
     }
     $player->delete();
     flash()->success('', 'Žaidėjas panaikintas!');
     return redirect()->back();
 }