예제 #1
0
 static function transformChanges($doc, $last_seq, $user)
 {
     global $mode_name, $phase_name;
     $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;
     $fogDeploy = false;
     if ($wargame->scenario->fogDeploy && $doc->playerStatus == "multi") {
         $fogDeploy = true;
     }
     //        $revs = $doc->_revs_info;
     Battle::loadGame($gameName, $doc->wargame->arg);
     //Battle::getHeader();
     if (isset($doc->wargame->mapViewer)) {
         $playerData = $doc->wargame->mapViewer[0];
     } else {
         $playerData = $doc->wargame->mapData[0];
     }
     $mapUnits = array();
     $moveRules = $doc->wargame->moveRules;
     $combatRules = $doc->wargame->combatRules;
     //        $display = $doc->wargame->display;
     $units = $force->units;
     $attackingId = $doc->wargame->gameRules->attackingForceId;
     foreach ($units as $unit) {
         $unit = UnitFactory::build($unit);
         $mapUnit = $unit->fetchData();
         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;
         if ($unit->reinforceTurn > $turn) {
             $u->reinforceTurn = $unit->reinforceTurn;
         }
         $units[$i] = $u;
     }
     if ($fogDeploy) {
         if ($gameRules->phase == BLUE_DEPLOY_PHASE && $player === RED_FORCE) {
             $moveRules->moves = new stdClass();
         }
         if ($gameRules->phase == RED_DEPLOY_PHASE && $player === BLUE_FORCE) {
             $moveRules->moves = new stdClass();
         }
     }
     if ($moveRules->moves) {
         foreach ($moveRules->moves as $k => $move) {
             unset($moveRules->moves->{$k}->isValid);
         }
         if ($moveRules->path) {
             foreach ($moveRules->path as $hexName) {
                 $moveRules->hexPath[] = $path;
             }
         }
     }
     $force->units = $units;
     $gameRules = $wargame->gameRules;
     //        $gameRules->display = $display;
     $gameRules->phase_name = $phase_name;
     $gameRules->mode_name = $mode_name;
     $gameRules->exchangeAmount = $force->exchangeAmount;
     $newSpecialHexes = new stdClass();
     $phaseClicks = $gameRules->phaseClicks;
     if ($doc->wargame->mapData->specialHexes) {
         $specialHexes = $doc->wargame->mapData->specialHexes;
         foreach ($specialHexes as $k => $v) {
             $hex = new Hexagon($k);
             $mapGrid->setHexagonXY($hex->x, $hex->y);
             $path = new stdClass();
             $newSpecialHexes->{"x" . intval($mapGrid->getPixelX()) . "y" . intval($mapGrid->getPixelY())} = $v;
         }
     }
     $sentBreadcrumbs = new stdClass();
     if ($doc->wargame->mapData->breadcrumbs) {
         $breadcrumbs = $doc->wargame->mapData->breadcrumbs;
         $breadcrumbKey = "/{$turn}" . "t" . $attackingId . "a/";
         foreach ($breadcrumbs as $key => $crumbs) {
             if (!preg_match($breadcrumbKey, $key)) {
                 continue;
             }
             $matches = array();
             preg_match("/m(\\d*)\$/", $key, $matches);
             if (strlen($matches[1]) < 1) {
                 continue;
             }
             $unitId = $matches[1];
             if (!isset($sentBreadcrumbs->{$unitId})) {
                 $sentBreadcrumbs->{$unitId} = [];
             }
             $sentMoves = $sentBreadcrumbs->{$unitId};
             foreach ($crumbs as $crumb) {
                 if (!isset($crumb->type)) {
                     $type = "move";
                 } else {
                     $type = $crumb->type;
                 }
                 switch ($type) {
                     case "move":
                         if ($crumb->fromHex === "0000") {
                             continue;
                         }
                         $fromHex = new Hexagon($crumb->fromHex);
                         $mapGrid->setHexagonXY($fromHex->x, $fromHex->y);
                         $crumb->fromX = intval($mapGrid->getPixelX());
                         $crumb->fromY = intval($mapGrid->getPixelY());
                         $toHex = new Hexagon($crumb->toHex);
                         $mapGrid->setHexagonXY($toHex->x, $toHex->y);
                         $crumb->toX = intval($mapGrid->getPixelX());
                         $crumb->toY = intval($mapGrid->getPixelY());
                         break;
                     case "combatResult":
                         if ($crumb->hex) {
                             $hex = new Hexagon($crumb->hex);
                             $mapGrid->setHexagonXY($hex->x, $hex->y);
                             $crumb->hexX = intval($mapGrid->getPixelX());
                             $crumb->hexY = intval($mapGrid->getPixelY());
                         }
                         break;
                 }
                 $sentMoves[] = $crumb;
             }
             $sentBreadcrumbs->{$unitId} = $sentMoves;
         }
     }
     $specialHexes = $newSpecialHexes;
     $newSpecialHexesChanges = new stdClass();
     if ($doc->wargame->mapData->specialHexesChanges) {
         $specialHexesChanges = $doc->wargame->mapData->specialHexesChanges;
         foreach ($specialHexesChanges as $k => $v) {
             $hex = new Hexagon($k);
             $mapGrid->setHexagonXY($hex->x, $hex->y);
             $path = new stdClass();
             $newSpecialHexesChanges->{"x" . intval($mapGrid->getPixelX()) . "y" . intval($mapGrid->getPixelY())} = $v;
         }
     }
     $newSpecialHexesVictory = new stdClass();
     if ($doc->wargame->mapData->specialHexesVictory) {
         $specialHexesVictory = $doc->wargame->mapData->specialHexesVictory;
         foreach ($specialHexesVictory as $k => $v) {
             $hex = new Hexagon($k);
             $mapGrid->setHexagonXY($hex->x, $hex->y);
             $path = new stdClass();
             $newSpecialHexesVictory->{"x" . intval($mapGrid->getPixelX()) . "y" . intval($mapGrid->getPixelY())} = $v;
         }
     }
     $vp = $doc->wargame->victory->victoryPoints;
     $flashMessages = $gameRules->flashMessages;
     if (count($flashMessages)) {
     }
     //        $flashMessages = array("Victory","Is","Mine");
     $specialHexesChanges = $newSpecialHexesChanges;
     $specialHexesVictory = $newSpecialHexesVictory;
     $gameRules->playerStatus = $doc->playerStatus;
     $clock = "The turn is " . $gameRules->turn . ". The Phase is " . $phase_name[$gameRules->phase] . ". The mode is " . $mode_name[$gameRules->mode];
     return compact("sentBreadcrumbs", "phaseClicks", "click", "revs", "vp", "flashMessages", "specialHexesVictory", "specialHexes", "specialHexesChanges", "combatRules", 'force', 'seq', 'chats', 'chatsIndex', 'last_seq', 'users', 'games', 'clock', 'mapUnits', 'moveRules', 'gameRules');
 }