public function sendAllFleetsToShield() { $MOVEMENT = $this->Config['MOVEMENT']; //init $this->fleetInfo["id"] = -1; //應該要做synchronization //syn start //lock file echo iconv("UTF-8", "big5", "一個派船出航\n") . "\n"; $movement_page = GlobalFunc::synExecute("Sent fleet to shield", function () { echo "FleetCommander: This Planet[" . $this->coord[0] . ":" . $this->coord[1] . ":" . $this->coord[2] . "] "; //echo "-> Shield Planet[". $this->target_coord[0]. ":".$this->target_coord[1]. ":". $this->target_coord[2]."]\n"; //切換星球 call global function $page = GlobalFunc::changeFocusPlanet($this->href); $this->rUri = ""; //取得Fleet1頁面 ///game/index.php?page=fleet1&galaxy=1&system=104&position=13&type=1&mission=1 $f1_page = $this->getFleet1Page(); //取得所有的戰船數量 $fleets_uri = $this->getFleetsAmount($f1_page); $this->rUri .= "&speed=1" . $fleets_uri; //取得Fleet2頁面 //galaxy=1&system=104&position=13&type=1&mission=1&speed=10&am204=&am205=&am206=&am202=&am203=1&am209=&am210= $f2_page = $this->getFleet2Page(); //$f2 = GlobalFunc::loadHTML($f2_page); //取得Escape List echo iconv("UTF-8", "big5", "開始找尋適合的shield.\n"); $my_coord_text = GlobalFunc::getCoordTextWithType($this->coord); $ESList = EscapeFilter::getEscapeList(); if (isset($ESList[$my_coord_text])) { $shields = $ESList[$my_coord_text]["shields"]; $sh_count = sizeof($shields); $fcheck_page = 1; //儲存最終傳回的結果 來確定有沒有一個可行的座標 for ($sh_i = 0; $sh_i < $sh_count; $sh_i++) { $sh_coord = $shields[$sh_i]; $sh_text = GlobalFunc::getCoordTextWithType($sh_coord); //嘗試取得fleetcheck頁面 $fcheck_page = $this->getFleetCheck($sh_coord); echo "fcheck_page:" . $fcheck_page; if ($fcheck_page == "0") { echo iconv("UTF-8", "big5", "Check通過 決定Shield座標({$sh_text}).\n"); $this->target_coord = $sh_coord; break; } else { if ($fcheck_page == "1") { echo iconv("UTF-8", "big5", "此target座標({$sh_text})不存在.\n"); } else { if ($fcheck_page == "2") { echo iconv("UTF-8", "big5", "此target處於假期模式({$sh_text}) 無法派遣.\n"); } else { echo iconv("UTF-8", "big5", "fcheck_page:{$fcheck_page} 不等於任何已知結果\n"); } } } } } else { echo iconv("UTF-8", "big5", "沒有Escape List.\n"); $fcheck_page = $this->getFleetCheck($this->target_coord); } //加入目的地uri $type = 1; //出發星球的type if (isset($this->target_coord[3]) && $this->target_coord[3] != NULL) { $type = $this->target_coord[3]; } $posi_uri = "galaxy=" . $this->target_coord[0] . "&system=" . $this->target_coord[1] . "&position=" . $this->target_coord[2] . "&type=" . $type . "&mission=3"; $this->rUri = $posi_uri . $this->rUri; echo "this->uri: " . $this->rUri . "\n"; //file_put_contents($this->Config['FailInfo'], $f2_page); $f3_page = $this->getFleet3Page(); //派遣船隊 $movement_page = $this->sendFleetOut($f3_page); //echo "movement_page result strlen: ". strlen($movement_page) . "\n"; if (strlen($movement_page) < $this->Config['AskPageLeastStrLen']) { echo "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"; echo "Sent fleet failed, result strlen: " . strlen($movement_page); echo "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"; } return $movement_page; }); //syn end echo "FleetCommander: movement_page result strlen: " . strlen($movement_page) . "\n"; if (strlen($movement_page) == 0) { //echo "movement_page strlen: 0!\n"; echo "Error occur! No fleet info to return! return 0 instead.\n"; return 0; } //取得的duration是錯誤的 因為他的計算都在javascript 因此無法取得 date_default_timezone_set('Asia/Taipei'); $n_time = time(); $time_diff = $n_time - $this->time_before_sent; $predicted_start_time = $this->time_before_sent + $time_diff / 2; $mp = GlobalFunc::loadHTML($movement_page); //找尋船隊的detail資訊 $inhalt = $mp->getElementById("inhalt"); if (!is_object($inhalt)) { echo "Error occur, inhalt is not an object, no way to find fleet detail\n"; return 0; } $this->fleetInfo = $this->getfleetDetails($inhalt, $this->coord, $this->target_coord); //取得船隊的id //$this->fleetInfo['id']; //取得船隊召回的get url //get ?page=movement&return=id $this->fleetInfo["withdraw_link"] = $MOVEMENT . "&return=" . $this->fleetInfo["id"]; if (!isset($this->fleetInfo["id"])) { $this->fleetInfo["id"] = -1; } if ($this->fleetInfo["id"] == -1 || strlen(trim($this->fleetInfo["id"])) == 0) { echo "Can't get fleet id, return 0.\n"; echo iconv("UTF-8", "big5", '船隊撤退失敗, 請檢查 重氫是否不足\\n'); return 0; } //取得船隊的抵達時間 //$this->fleetInfo["arrivetime"]; //echo "My fleet info in the end of send: duration = ".$this->duration; //取得船隊的飛行時間 //$this->fleetInfo["flighttime"] = $this->duration; //取得船隊的出發時間 //$this->fleetInfo["starttime"] = $this->fleetInfo["arrivetime"] - $this->duration; //echo "arrivetime = ".$this->fleetInfo["arrivetime"]." duration = $this->duration | starttime = ".$this->fleetInfo["starttime"]."\n"; $this->fleetInfo["starttime"] = $predicted_start_time; //echo "My fleet info in the end of send: "; //var_dump($this->fleetInfo); return $this->fleetInfo; }
function buildResourceItem($blocks, $tCoor) { $PLANETS = $this->PLANETS; if (!isset($PLANETS)) { echo "No Planet list! return false.\n"; return false; } $page = $blocks[0]; for ($i = 0; $i < sizeof($PLANETS); $i++) { if (GlobalFunc::isCoordinateMatch($PLANETS[$i]->coord, $tCoor)) { echo "ResourceManager: Planet[" . $tCoor[0] . ":" . $tCoor[1] . ":" . $tCoor[2] . "](" . $tCoor[3] . ") isFound.\n"; //取得切換到該星球的 url $pos = strpos($PLANETS[$i]->href, "cp="); $cpText = substr($PLANETS[$i]->href, $pos); if ($page == "R") { //資源 $resourceUrl = $this->Config['RESOURCE_URL'] . "&" . $cpText; } else { if ($page == "S") { //設施 $resourceUrl = $this->Config['STATION_URL'] . "&" . $cpText; } else { if ($page == "T") { //科技 $resourceUrl = $this->Config['TECH_URL'] . "&" . $cpText; } else { echo "ResourceManager.buildResourceItem(): error, invalid page value: (" . $page . ") found. return 1 to skip.\n"; return 1; } } } //切換星球 順便取得resources page $this->resourceUrl = $resourceUrl; $resources_page = GlobalFunc::synExecute("Change focused planet and get resources page", function () { echo "resourceUrl: " . $this->resourceUrl; return GlobalFunc::changeFocusPlanet($this->resourceUrl); }); if (strlen($resources_page) < $this->Config['AskPageLeastStrLen']) { echo "ResourceManager: resources_page len " . strlen($resources_page) . " too few, return 0.\n"; return 0; //發送的請求可能失敗了 } $resources_dom = GlobalFunc::loadHtml($resources_page); //找金屬礦 //$resource_item_name = "button1"; //$but1 = $resources_dom->getElementById( $resource_item_name ); if ($page == "R" || $page == "S") { $item_id = $blocks[1]; $but1 = $this->getResourceStationBtn($resources_dom, $item_id); } else { if ($page == "T") { $item_id = $blocks[1]; $item_num = $blocks[2] - 1; $but1 = $this->getTechnologyBtn($resources_dom, $item_id, $item_num); } else { echo "Page is not R, S or T, invalid. return 1 to skip this request."; return 1; } } //發送 蓋資源 的請求 return $this->sendBuildRequest($but1, $item_id); } } //找不到該星球 return -1; }