Esempio n. 1
0
 /**
  * 敌方卡片的战斗单元构造方法(AI)
  * @param $intDungeonEnemyId
  * @param $intPosition
  */
 public function initWithEnemy($intDungeonEnemyId, $intPosition)
 {
     $this->position = $intPosition;
     $objDungeonEnemy = DungeonEnemy::find($intDungeonEnemyId);
     $this->hp = $objDungeonEnemy->hp;
     $this->atk = $objDungeonEnemy->atk;
     $this->def = $objDungeonEnemy->def;
     $this->spd = $objDungeonEnemy->spd;
     $this->int = $objDungeonEnemy->int;
     $this->card_id = $objDungeonEnemy->card_id;
     $this->alive = true;
 }
Esempio n. 2
0
 /**
  * 每层冒险的单独内部处理
  * @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();
 }