コード例 #1
0
ファイル: Battle.php プロジェクト: kakitsubun/wc-test
 /**
  * 每层冒险的单独内部处理
  * @param $objBattleDetail
  */
 private function _doBattleTurn($objBattleDetail)
 {
     $intDungeonId = $this->dungeon_id;
     $intFloor = $objBattleDetail->floor;
     $intGrid = $objBattleDetail->grid;
     // 该地下城该行该列的特定敌人的列表取得 TODO Cache
     $objEnemy = DungeonEnemy::where('dungeon_id', $intDungeonId)->where('floor', $intFloor)->whereIn('grid', array($intGrid, 0))->get();
     // 该地下城该行该列的特定事件列表取得 TODO Cache
     $lstIncidents = DungeonIncident::where('dungeon_id', $intDungeonId)->where('floor', $intFloor)->whereIn('grid', array($intGrid, 0))->get();
     // 每层的冒险详细处理开始
     if (!$objEnemy->isEmpty()) {
         /** 特定敌人的场合 */
         Log::info("[BattleC][战斗模拟]:Fight");
         // 战斗相关处理
         $objFight = new Fight();
         // 战斗初始化
         $objFight->initFight($this, $objEnemy, $intFloor);
         // 战斗处理
         $strResult = $objFight->fight();
         if ($strResult == "win") {
             // 胜利
         } else {
             // 战败
             $this->status = self::BATTLE_FAIL_STATUS;
         }
         // 层详细记录
         $objBattleDetail->fight_id = $objFight->id;
         $objBattleDetail->action = 'fight';
     } elseif (!$lstIncidents->isEmpty()) {
         /** 特定事件的场合 */
         Log::info("[BattleC][事件模拟]:事件");
         $lstIncident = $this->_drawing($lstIncidents->toArray());
         $objIncident = DungeonIncident::find($lstIncident['id']);
         // 事件相关处理
         $objIncident->happen($this);
         // 层详细记录
         $objBattleDetail->incident_id = $objIncident->incident_id;
         $objBattleDetail->action = 'incident';
     } else {
         /** 无固定战斗或事件的情况下,依照地下城表中设定的各个项目的概率计算 */
         $boolDoneFlag = false;
         $objEnemy = DungeonEnemy::where('dungeon_id', $intDungeonId)->where('floor', 0)->whereIn('grid', array($intGrid, 0))->get();
         // 随机敌人抽选是否战斗
         if (!$objEnemy->isEmpty()) {
             $battleRate = mt_rand(0, 100);
             if ($battleRate < 50) {
                 // 假概率
                 // 本层玩家Flag
                 $boolDoneFlag = true;
                 // 战斗实例
                 $objFight = new Fight();
                 // 战斗初始化
                 $objFight->initFight($this, $objEnemy, $intFloor);
                 // 战斗流程
                 $strResult = $objFight->fight();
                 if ($strResult == "win") {
                     // 胜利
                 } else {
                     // 战败
                 }
                 // 记录战斗ID等到层详细记录
                 $objBattleDetail->fight_id = $objFight->id;
                 //仮
                 $objBattleDetail->action = 'fight';
             }
         }
         // 随机事件抽选
         $lstIncidents = DungeonIncident::where('dungeon_id', $intDungeonId)->where('floor', 0)->whereIn('grid', array($intGrid, 0))->get();
         if (!$lstIncidents->isEmpty()) {
             // 是否有随机事件发生
             $incidentRate = mt_rand(0, 100);
             if ($incidentRate < 50) {
                 // TODO 假概率
                 $boolDoneFlag = true;
                 $lstIncident = $this->_drawing($lstIncidents->toArray());
                 $objIncident = DungeonIncident::find($lstIncident['id']);
                 // 事件相关处理
                 $objIncident->happen($this);
                 // 层详细记录
                 $objBattleDetail->incident_id = $objIncident->incident_id;
                 $objBattleDetail->action = 'incident';
             }
         }
         // 既没战斗也没发生事件时
         if (!$boolDoneFlag) {
             $objBattleDetail->action = 'none';
         }
     }
     $objBattleDetail->save();
 }
コード例 #2
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);
 }
コード例 #3
0
 /**
  * 地下城事件保存
  * @return mixed
  */
 public function incidentStore()
 {
     // 新建地下城事件实例
     $objDungeonIncident = new DungeonIncident();
     $objDungeonIncident->dungeon_id = Input::get('dungeon_id');
     $objDungeonIncident->incident_id = Input::get('incident_id');
     $objDungeonIncident->floor = Input::get('floor');
     $objDungeonIncident->grid = Input::get('grid');
     $objDungeonIncident->rate = Input::get('rate');
     $objDungeonIncident->power = Input::get('power');
     if ($objDungeonIncident->save()) {
         return Redirect::to('admin/dungeon/incident/' . Input::get('dungeon_id'));
     } else {
         return Redirect::back()->withInput()->withErrors('保存失败!');
     }
 }