コード例 #1
0
 public function handleWarrior()
 {
     $itemId = $this->buildings[$this->buildingIndex]['item_id'];
     $this->troopsUpgrade = array();
     $_arr = explode(",", $this->data['troops_training']);
     foreach ($_arr as $troopStr) {
         $attack_level = explode(" ", $troopStr);
         $defense_level = explode(" ", $troopStr);
         $researches_done = explode(" ", $troopStr);
         $troopId = explode(" ", $troopStr);
         list($troopId, $researches_done, $defense_level, $attack_level) = $troopId;
         if ($researches_done == 1 && 0 < $this->gameMetadata['troops'][$troopId]['gold_needed']) {
             $this->troopsUpgrade[$troopId] = $troopId;
         }
     }
     $this->warriorMessage = "";
     if ($this->isPost() && isset($_POST['tf']) && !$this->isGameTransientStopped() && !$this->isGameOver()) {
         $cropConsume = 0;
         $totalGoldsNeeded = 0;
         foreach ($_POST['tf'] as $troopId => $num) {
             $num = intval($num);
             if ($num <= 0 || !isset($this->troopsUpgrade[$troopId])) {
                 continue;
             }
             $totalGoldsNeeded += $this->gameMetadata['troops'][$troopId]['gold_needed'] * $num;
             $cropConsume += $this->gameMetadata['troops'][$troopId]['crop_consumption'] * $num;
         }
         if ($totalGoldsNeeded <= 0) {
         } else {
             $canProcess = $totalGoldsNeeded <= $this->data['gold_num'];
             $this->warriorMessage = $canProcess ? 1 : 2;
             if ($canProcess) {
                 $troopsString = "";
                 foreach ($this->troops as $tid => $num) {
                     if ($tid == 99) {
                         continue;
                     }
                     $neededNum = isset($this->troopsUpgrade[$tid], $_POST['tf'][$tid]) ? $_POST['tf'][$tid] : 0;
                     if ($troopsString != "") {
                         $troopsString .= ",";
                     }
                     $troopsString .= $tid . " " . $neededNum;
                 }
                 $m = new BuildModel();
                 $m->decreaseGoldNum($this->player->playerId, $totalGoldsNeeded);
                 $m->dispose();
                 $this->data -= "gold_num";
                 $procParams = $troopsString . "|0||||||1";
                 $buildingMetadata = $this->gameMetadata['items'][$this->buildProperties['building']['item_id']];
                 $bLevel = $this->buildings[$this->buildingIndex]['level'];
                 $needed_time = $buildingMetadata['levels'][$bLevel - 1]['value'] * 3600;
                 $newTask = new QueueTask(QS_WAR_REINFORCE, 0, $needed_time);
                 $newTask->villageId = 0;
                 $newTask->toPlayerId = $this->player->playerId;
                 $newTask->toVillageId = $this->data['selected_village_id'];
                 $newTask->procParams = $procParams;
                 $newTask->tag = array("troops" => NULL, "hasHero" => FALSE, "resources" => NULL, "troopsCropConsume" => $cropConsume);
                 $this->queueModel->addTask($newTask);
             }
         }
     }
 }