コード例 #1
0
 /**
  * 玩家冒险详细
  */
 public function detail($id)
 {
     //
     $objBattle = Battle::find($id);
     $objDungeon = Dungeon::find($objBattle->dungeon_id);
     return view('admin.battle.detail')->withBattle($objBattle)->withDungeon($objDungeon)->withDetails(BattleDetail::where('battle_id', $id)->get());
 }
コード例 #2
0
 public function getDungeonInfo()
 {
     $dungeon = Dungeon::find(Input::get('dungeon_id'));
     $dungeonReward = DungeonReward::where('dungeon_id', Input::get('dungeon_id'))->get();
     $dungeonInfo = array('info' => $dungeon, 'reward' => $dungeonReward);
     // クリア状況 TODO
     // 地城打分系统 TODO
     return Response::json($dungeonInfo);
 }
コード例 #3
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);
 }
コード例 #4
0
 /**
  * 进入地下城处理
  */
 public function entryExec()
 {
     // 各项参数取得
     //        $intPlayerId = Input::get('player_id', 0);
     $intPlayerId = $this->_intPlayerId;
     $intDungeonId = Input::get('dungeon_id');
     $strType = Input::get('type', 'normal');
     $now = Carbon::now();
     // 有没有进行中的战斗
     $objBattle = Battle::where('player_id', $intPlayerId)->where('dungeon_id', $intDungeonId)->where('end_datetime', '>', $now)->orderBy('id', 'DESC')->first();
     // 存在进行中的战斗
     if (!empty($objBattle)) {
         return Response::json($objBattle->toArray());
     }
     Log::info("DungeonId" . $intDungeonId);
     // 取得地下城信息
     $lstDungeonInfo = Dungeon::getInfo($intDungeonId);
     // 没有找到该当地下城
     if (empty($lstDungeonInfo)) {
         return 'Dungeon not exist';
     }
     // 取得地下城对象
     $objDungeon = $lstDungeonInfo['info'];
     // Team TODO
     $intTeamId = Input::get('team_id');
     $objTeam = Team::find($intTeamId);
     if (!$objTeam) {
         return 'NG TeamId';
     }
     // 队伍的PlayerId不一致的情况
     if ($objTeam->player_id != $intPlayerId) {
         return 'Wrong PlayerId For Team';
     }
     // 冒险做成
     $objBattle = new Battle();
     // 冒险情报的各种设定
     $objBattle->player_id = $intPlayerId;
     $objBattle->dungeon_id = $intDungeonId;
     $objBattle->floor = $objDungeon->floor;
     $objBattle->current_floor = 0;
     $objBattle->type = $strType;
     $objBattle->start_datetime = $now->toDateTimeString();
     $objBattle->end_datetime = $now->addMinutes($objDungeon->floor)->toDateTimeString();
     // 出战队伍信息保存在冒险信息中
     if ($objTeam->position_1_owned_card_id != 0) {
         $ownedCard1 = OwnedCard::find($objTeam->position_1_owned_card_id);
         $objBattle->position_1 = $ownedCard1->id;
     }
     if ($objTeam->position_2_owned_card_id != 0) {
         $ownedCard2 = OwnedCard::find($objTeam->position_2_owned_card_id);
         $objBattle->position_2 = $ownedCard2->id;
     }
     if ($objTeam->position_3_owned_card_id != 0) {
         $ownedCard3 = OwnedCard::find($objTeam->position_3_owned_card_id);
         $objBattle->position_3 = $ownedCard3->id;
     }
     if ($objTeam->position_4_owned_card_id != 0) {
         $ownedCard4 = OwnedCard::find($objTeam->position_4_owned_card_id);
         $objBattle->position_4 = $ownedCard4->id;
     }
     if ($objTeam->position_5_owned_card_id != 0) {
         $ownedCard5 = OwnedCard::find($objTeam->position_5_owned_card_id);
         $objBattle->position_5 = $ownedCard5->id;
     }
     if ($objTeam->position_6_owned_card_id != 0) {
         $ownedCard6 = OwnedCard::find($objTeam->position_6_owned_card_id);
         $objBattle->position_6 = $ownedCard6->id;
     }
     if ($objBattle->save()) {
         // TODO Red
     }
 }
コード例 #5
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;
 }
コード例 #6
0
 /**
  * 地下城掉落详细
  * @param $intDungeonId
  * @return mixed
  */
 public function dropDetail($intDungeonId)
 {
     return view('admin.dungeon.drop-detail')->withDungeons(Dungeon::where('area_id', $intDungeonId)->get())->withArea(Area::find($intDungeonId));
 }