/** * 玩家冒险详细 */ 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()); }
/** * 详细取得 */ public function detail() { $intPlayerId = $this->_intPlayerId; $intDungeonId = Input::get('dungeon_id', 0); $intBattleId = Input::get('battle_id', 0); if ($intPlayerId == 0 || $intDungeonId == 0 || $intBattleId == 0) { } $objBattle = Battle::find($intBattleId); $lstBattleInfo = $objBattle->doBattle(); echo "战斗ID:{$lstBattleInfo["info"]["id"]}<br />"; foreach ($lstBattleInfo["detail"] as $lstBattleInfoDetail) { echo "[Floor:{$lstBattleInfoDetail['floor']}][Grid:{$lstBattleInfoDetail['grid']}][{$lstBattleInfoDetail['action']}]<br />"; } }
/** * 取得冒险的最新信息 * 更新冒险信息 */ 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); }