コード例 #1
0
 public function addTeam()
 {
     $lstTeams = Team::where("player_id", $this->_intPlayerId)->get()->toArray();
     $intTeamCount = count($lstTeams);
     // TODO Team数量限定
     $intNewTeamNo = $intTeamCount + 1;
     $objNewTeam = new Team();
     $objNewTeam->team_name = "Team" . $intNewTeamNo;
     $objNewTeam->team_no = $intNewTeamNo;
     $objNewTeam->player_id = $this->_intPlayerId;
     $objNewTeam->save();
     $objTeamBk = Team::find($objNewTeam->id);
     // 20151012 TeamMember Table 初始化
     for ($intPosition = 1; $intPosition <= 6; $intPosition++) {
         $objTeamMember = new TeamMember();
         $objTeamMember->team_id = $objTeamBk->id;
         $objTeamMember->position = $intPosition;
         $objTeamMember->player_id = $objTeamBk->player_id;
         $objTeamMember->save();
         switch ($intPosition) {
             case 1:
                 $objTeamBk->position_1_member_id = $objTeamMember->id;
                 break;
             case 2:
                 $objTeamBk->position_2_member_id = $objTeamMember->id;
                 break;
             case 3:
                 $objTeamBk->position_3_member_id = $objTeamMember->id;
                 break;
             case 4:
                 $objTeamBk->position_4_member_id = $objTeamMember->id;
                 break;
             case 5:
                 $objTeamBk->position_5_member_id = $objTeamMember->id;
                 break;
             case 6:
                 $objTeamBk->position_6_member_id = $objTeamMember->id;
                 break;
             default:
                 # code...
                 break;
         }
     }
     $objTeamBk->save();
 }
コード例 #2
0
ファイル: TeamController.php プロジェクト: kakitsubun/wc-test
 public function initTeam()
 {
     $intPlayerId = Input::get('player_id', 0);
     // 目前已经生成Team数量确认
     /* 玩家可用Team数量确认
      * Lv.1 ~ Lv.10   1Team
      * Lv.11 ~ Lv.20  2Team
      * Lv.21 ~ Lv.50  3Team
      * Lv.51 ~ Lv.100 4Team
      * 氪金玩家        +1Team
      */
     $objTeam = new Team();
     $objTeam->player_id = $intPlayerId;
     $objTeam->team_no = 1;
     // 该用户的第一个队伍
     $objTeam->team_name = "Team01";
     $firstCard = OwnedCard::where('player_id', $intPlayerId)->orderBy('id', 'ASC')->first();
     $objTeam->position_1_owned_card_id = $firstCard->id;
     $objTeam->total_cost = $firstCard->getCost();
     $objTeam->save();
     $objTeamBk = Team::find($objTeam->id);
     // 20151012 TeamMember Table 初始化
     for ($intPosition = 1; $intPosition <= 6; $intPosition++) {
         $objTeamMember = new TeamMember();
         $objTeamMember->team_id = $objTeamBk->id;
         $objTeamMember->position = $intPosition;
         $objTeamMember->player_id = $objTeamBk->player_id;
         if ($intPosition == 1) {
             $objTeamMember->card_id = $firstCard->card_id;
             $objTeamMember->owned_card_id = $firstCard->id;
         }
         $objTeamMember->save();
         switch ($intPosition) {
             case 1:
                 $objTeamBk->position_1_member_id = $objTeamMember->id;
                 break;
             case 2:
                 $objTeamBk->position_2_member_id = $objTeamMember->id;
                 break;
             case 3:
                 $objTeamBk->position_3_member_id = $objTeamMember->id;
                 break;
             case 4:
                 $objTeamBk->position_4_member_id = $objTeamMember->id;
                 break;
             case 5:
                 $objTeamBk->position_5_member_id = $objTeamMember->id;
                 break;
             case 6:
                 $objTeamBk->position_6_member_id = $objTeamMember->id;
                 break;
             default:
                 # code...
                 break;
         }
         // 20151103 追加
         $firstCard->team_id = $objTeam->id;
         $firstCard->save();
     }
     $objTeamBk->save();
     return Response::json($objTeamBk->toArray());
 }
コード例 #3
0
ファイル: Player.php プロジェクト: kakitsubun/wc-test
 /**
  * 玩家创建时初始化第一套队伍
  */
 public function firstTeam()
 {
     // Transaction
     DB::beginTransaction();
     try {
         $objTeam = new Team();
         $intPlayerId = $this->id;
         $objTeam->player_id = $intPlayerId;
         $objFirstCard = OwnedCard::where('player_id', $intPlayerId)->orderBy('id', 'ASC')->first();
         $objTeam->position_1_owned_card_id = $objFirstCard->id;
         $objTeam->total_cost = $objFirstCard->getCost();
         $objTeam->save();
         // TODO 是否需要
         $objTeamBk = Team::find($objTeam->id);
         // 20151012 TeamMember Table 初始化
         for ($intPosition = 1; $intPosition <= 6; $intPosition++) {
             $objTeamMember = new TeamMember();
             $objTeamMember->team_id = $objTeamBk->id;
             $objTeamMember->position = $intPosition;
             $objTeamMember->player_id = $objTeamBk->player_id;
             if ($intPosition == 1) {
                 $objTeamMember->card_id = $objFirstCard->card_id;
                 $objTeamMember->owned_card_id = $objFirstCard->id;
             }
             if (!$objTeamMember->save()) {
                 throw new Exception('Save Failed');
             }
             switch ($intPosition) {
                 case 1:
                     $objTeamBk->position_1_member_id = $objTeamMember->id;
                     break;
                 case 2:
                     $objTeamBk->position_2_member_id = $objTeamMember->id;
                     break;
                 case 3:
                     $objTeamBk->position_3_member_id = $objTeamMember->id;
                     break;
                 case 4:
                     $objTeamBk->position_4_member_id = $objTeamMember->id;
                     break;
                 case 5:
                     $objTeamBk->position_5_member_id = $objTeamMember->id;
                     break;
                 case 6:
                     $objTeamBk->position_6_member_id = $objTeamMember->id;
                     break;
             }
             // 更新玩家卡片的队伍信息
             $objFirstCard->team_id = $objTeam->id;
             if (!$objFirstCard->save()) {
                 throw new Exception('Save Failed');
             }
         }
         if (!$objTeamBk->save()) {
             throw new Exception('Save Failed');
         }
         DB::commit();
     } catch (Exception $e) {
         // TODO Dev Log
         DB::rollback();
     }
 }