コード例 #1
0
ファイル: node.class.php プロジェクト: yunsite/devana-heroic
 public function move($x, $y)
 {
     global $db, $game;
     $this->getModules();
     $this->getResources();
     $this->getLocation();
     $moveCost = $game['factions'][$this->data['faction']]['costs']['move'];
     $distance = ceil(sqrt(pow($this->location['x'] - $x, 2) + pow($this->location['y'] - $y, 2)));
     $moveCostData = $this->checkCost($moveCost, 'move');
     if ($moveCostData['ok']) {
         $node = new node();
         if ($node->get('id', $this->data['id']) == 'done') {
             $sector = grid::getSector($x, $y);
             if ($sector['type'] == 1) {
                 $ok = 1;
                 $db->query('update grid set type="1", id=floor(1+rand()*9) where x="' . $this->location['x'] . '" and y="' . $this->location['y'] . '"');
                 if ($db->affected_rows() == -1) {
                     $ok = 0;
                 }
                 $this->location['x'] = $x;
                 $this->location['y'] = $y;
                 $db->query('update grid set type="2", id="' . $this->data['id'] . '" where x="' . $this->location['x'] . '" and y="' . $this->location['y'] . '"');
                 if ($db->affected_rows() == -1) {
                     $ok = 0;
                 }
                 foreach ($moveCost as $cost) {
                     $this->resources[$cost['resource']]['value'] -= $cost['value'] * $game['users']['cost']['move'];
                     $db->query('update resources set value="' . $this->resources[$cost['resource']]['value'] . '" where node="' . $this->data['id'] . '" and id="' . $cost['resource'] . '"');
                     if ($db->affected_rows() == -1) {
                         $ok = 0;
                     }
                 }
                 if ($ok) {
                     $status = 'done';
                 } else {
                     $status = 'error';
                 }
             } else {
                 $status = 'invalidGridSector';
             }
         } else {
             $status = 'noNode';
         }
     } else {
         $status = 'notEnoughResources';
     }
     return $status;
 }