当前位置: 首页>>代码示例>>PHP>>正文


PHP Battle::battleFromDoc方法代码示例

本文整理汇总了PHP中Wargame\Battle::battleFromDoc方法的典型用法代码示例。如果您正苦于以下问题:PHP Battle::battleFromDoc方法的具体用法?PHP Battle::battleFromDoc怎么用?PHP Battle::battleFromDoc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Wargame\Battle的用法示例。


在下文中一共展示了Battle::battleFromDoc方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: postPoke

 public function postPoke(Request $req, CouchService $cs)
 {
     $user = Auth::user()['name'];
     $cs->setDb('games');
     $wargame = urldecode($req->session()->get("wargame"));
     $x = (int) Input::get('x', FALSE);
     $y = (int) Input::get('y', FALSE);
     $event = (int) Input::get('event', FALSE);
     $id = Input::get('id', FALSE);
     //        $this->load->model("wargame/wargame_model");
     /*  @var  Wargame_model */
     $cs->setDb('games');
     $doc = $cs->get(urldecode($wargame));
     $ter = false;
     if (!empty($doc->wargame->terrainName)) {
         try {
             $ter = $cs->get($doc->wargame->terrainName);
         } catch (\GuzzleHttp\Exception\BadResponseException $e) {
             var_dump($e->getMessage());
         }
         $doc->wargame->terrain = $ter->terrain;
     }
     //        $this->load->library("battle");
     $game = !empty($doc->gameName) ? $doc->gameName : '';
     $emsg = false;
     $click = $doc->_rev;
     $matches = array();
     preg_match("/^([0-9]+)-/", $click, $matches);
     $click = $matches[1];
     try {
         $battle = Battle::battleFromDoc($doc);
         $isGameOver = $battle->victory->gameOver;
         //            $battle = Battle::getBattle($game, $doc->wargame, $doc->wargame->arg, false, $doc->className);
         $doSave = $battle->poke($event, $id, $x, $y, $user, $click);
         $gameOver = $battle->victory->gameOver;
         if (!$isGameOver && $gameOver) {
             event(new \App\Events\Analytics\RecordGameEvent(['docId' => $doc->_id, 'winner' => $battle->victory->winner, 'type' => 'game-victory', 'className' => $doc->className, 'scenario' => $battle->scenario, 'arg' => $battle->arg, 'time' => time()]));
         }
         $success = false;
         if ($doSave) {
             $doc->wargame = $battle->save();
             $cs->put($doc->_id, $doc);
             $success = true;
         }
         if ($doSave === 0) {
             $success = true;
         }
     } catch (Exception $e) {
         $emsg = $e->getMessage() . " \nFile: " . $e->getFile() . " \nLine: " . $e->getLine() . " \nCode: " . $e->getCode();
         $success = false;
     }
     if (!$success) {
         header("HTTP/1.1 404 Not Found");
     }
     return compact('success', "emsg");
 }
开发者ID:daverodal,项目名称:game-dispatcher,代码行数:56,代码来源:WargameController.php

示例2: transformChanges

 static function transformChanges($doc, $last_seq, $user)
 {
     global $mode_name, $phase_name;
     $battle = Battle::battleFromDoc($doc);
     $val = print_r($doc->wargame->force, true);
     file_put_contents('/tmp/loggy', $val, FILE_APPEND);
     $val = print_r($doc->wargame->force, true);
     file_put_contents('/tmp/loggy', $val, FILE_APPEND);
     $chatsIndex = 0;
     /* remove me */
     $click = $doc->_rev;
     $matches = array();
     preg_match("/^([0-9]+)-/", $click, $matches);
     $click = $matches[1];
     //        $games = $doc->games;
     $chats = array_slice($doc->chats, $chatsIndex);
     $chatsIndex = count($doc->chats);
     //        $users = $doc->users;
     //        $clock = $doc->clock;
     $players = $doc->wargame->players;
     $player = array_search($user, $players);
     if ($player === false) {
         $player = 0;
     }
     $force = $doc->wargame->force;
     $wargame = $doc->wargame;
     $gameName = $doc->gameName;
     $gameRules = $wargame->gameRules;
     $gameRules->option = false;
     $fogDeploy = false;
     if (!empty($wargame->scenario->fogDeploy) && $doc->playerStatus == "multi") {
         $fogDeploy = true;
     }
     //        $revs = $doc->_revs_info;
     //        \Wargame\Battle::loadGame($gameName, $doc->wargame->arg);
     //Battle::getHeader();
     if (isset($doc->wargame->mapViewer)) {
         $playerData = $doc->wargame->mapViewer[$player];
     } else {
         $playerData = $doc->wargame->mapData[0];
     }
     $mapGrid = new MapGrid($playerData);
     $mapUnits = array();
     $moveRules = $doc->wargame->moveRules;
     $combatRules = $doc->wargame->combatRules;
     $combats = isset($combatRules->combats) ? $combatRules->combats : false;
     if (!$combats) {
         $combats = isset($combatRules->combatsToResolve) ? $combatRules->combatsToResolve : false;
     }
     if ($playerData->trueRows && $combats) {
         foreach ($combats as $combat) {
             foreach ($combat->thetas as $theta) {
                 foreach ($theta as $key => $val) {
                     $theta->{$key} += 90;
                 }
             }
         }
     }
     $combats = isset($combatRules->resolvedCombats) ? $combatRules->resolvedCombats : false;
     if ($playerData->trueRows && $combats) {
         foreach ($combats as $combat) {
             foreach ($combat->thetas as $theta) {
                 foreach ($theta as $key => $val) {
                     $theta->{$key} += 90;
                 }
             }
         }
     }
     $units = $battle->force->units;
     $attackingId = $doc->wargame->gameRules->attackingForceId;
     foreach ($units as $unit) {
         //            $unit = static::buildUnit($unit);
         if (is_object($unit->hexagon)) {
             //                $unit->hexagon->parent = $unit->parent;
         } else {
             $unit->hexagon = new Hexagon($unit->hexagon);
         }
         //            $unit->hexagon->parent = $unit->parent;
         $mapGrid->setHexagonXY($unit->hexagon->x, $unit->hexagon->y);
         $mapUnit = $unit->fetchData();
         $mapUnit->x = $mapGrid->getPixelX();
         $mapUnit->y = $mapGrid->getPixelY();
         if ($fogDeploy && ($gameRules->phase == RED_DEPLOY_PHASE || $gameRules->phase == BLUE_DEPLOY_PHASE) && $unit->forceId !== $player) {
             if ($unit->hexagon->parent == "gameImages") {
                 $mapUnit = new stdClass();
             }
         }
         $mapUnits[] = $mapUnit;
     }
     $turn = $doc->wargame->gameRules->turn;
     //        foreach ($units as $i => $unit) {
     //            $u = new StdClass();
     //            $u->status = $unit->status;
     //            $u->moveAmountUsed = $unit->moveAmountUsed;
     //            $u->maxMove = $unit->maxMove;
     //            $u->forceId = $unit->forceId;
     //            $u->forceMarch = $unit->forceMarch;
     //            $u->isDisrupted = $unit->isDisrupted;
     //            $u->disruptLen = $unit->disruptLen;
     //            $u->isImproved = $unit->isImproved;
//.........这里部分代码省略.........
开发者ID:daverodal,项目名称:wargaming,代码行数:101,代码来源:LandBattle.php


注:本文中的Wargame\Battle::battleFromDoc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。