Example #1
0
 public function getSectorLink($x, $y, &$i)
 {
     if (isset($this->data[$i]) && $this->data[$i]['x'] == $x && $this->data[$i]['y'] == $y) {
         if ($this->data[$i]['type'] != 2) {
             $output = 'href="javascript: fetch(\'getGrid.php\', \'x=' . $x . '&y=' . $y . '\')" onMouseOver="setSectorData(labels[' . $this->data[$i]['type'] . '], \'-\', \'-\')" onMouseOut="setSectorData(\'-\', \'-\', \'-\')"';
         } else {
             $node = new node();
             $node->get('id', $this->data[$i]['id']);
             $user = new user();
             $user->get('id', $node->data['user']);
             $alliancename = '-';
             if ($user->data['alliance']) {
                 $alliance = new alliance();
                 $alliance->get('user', $user->data['id']);
                 $alliancename = $alliance->data['name'];
             }
             $output = 'href="javascript: fetch(\'getGrid.php\', \'x=' . $x . '&y=' . $y . '\')" onMouseOver="setSectorData(\'' . $node->data['name'] . '\', \'' . $user->data['name'] . '\', \'' . $alliancename . '\')" onMouseOut="setSectorData(\'-\', \'-\', \'-\')"';
         }
         if ($i < count($this->data) - 1) {
             $i++;
         }
     } else {
         $output = 'href="javascript: fetch(\'getGrid.php\', \'x=' . $x . '&y=' . $y . '\')"';
     }
     return $output;
 }
Example #2
0
 public function add($nodeId)
 {
     global $db, $game;
     $alliance = new alliance();
     if ($alliance->get('name', $this->data['name']) == 'noAlliance') {
         $node = new node();
         if ($node->get('id', $nodeId) == 'done') {
             $node->checkResources(time());
             $addCost = $game['factions'][$node->data['faction']]['costs']['alliance'];
             $addCostData = $node->checkCost($addCost, 'alliance');
             if ($addCostData['ok']) {
                 $ok = 1;
                 foreach ($addCost as $cost) {
                     $node->resources[$cost['resource']]['value'] -= $cost['value'] * $game['users']['cost']['alliance'];
                     $db->query('update resources set value="' . $node->resources[$cost['resource']]['value'] . '" where node="' . $node->data['id'] . '" and id="' . $cost['resource'] . '"');
                     if ($db->affected_rows() == -1) {
                         $ok = 0;
                     }
                 }
                 $this->data['id'] = misc::newId('alliances');
                 $db->query('insert into alliances (id, user, name) values ("' . $this->data['id'] . '", "' . $node->data['user'] . '", "' . $this->data['name'] . '")');
                 if ($db->affected_rows() == -1) {
                     $ok = 0;
                 }
                 $db->query('update users set alliance="' . $this->data['id'] . '" where id="' . $this->data['user'] . '"');
                 if ($db->affected_rows() == -1) {
                     $ok = 0;
                 }
                 if ($ok) {
                     $status = 'done';
                 } else {
                     $status = 'error';
                 }
             } else {
                 $status = 'notEnoughResources';
             }
         } else {
             $status = 'noNode';
         }
     } else {
         $status = 'nameTaken';
     }
     return $status;
 }
Example #3
0
 foreach ($_POST as $key => $value) {
     if (!in_array($key, array('name', 'attackerGroupUnitIds', 'attackerGroups', 'attackerFocus'))) {
         $_POST[$key] = misc::clean($value, 'numeric');
     } else {
         if (!in_array($key, array('name', 'attackerFocus'))) {
             $nr = count($_POST[$key]);
             for ($i = 0; $i < $nr; $i++) {
                 $_POST[$key][$i] = misc::clean($_POST[$key][$i], 'numeric');
             }
         } else {
             $_POST[$key] = misc::clean($value);
         }
     }
 }
 $target = new node();
 if ($target->get('name', $_POST['name']) == 'done') {
     $targetUser = new user();
     if ($targetUser->get('id', $target->data['user']) == 'done') {
         $alliance = new alliance();
         $targetAlliance = new alliance();
         if ($targetAlliance->get('id', $targetUser->data['alliance']) == 'done' && $alliance->get('id', $_SESSION[$shortTitle . 'User']['alliance']) == 'done') {
             $war = $alliance->getWar($targetAlliance->data['id']);
             if (isset($war['type'])) {
                 $gotStatic = false;
                 $data = array();
                 $data['input']['attacker']['focus'] = $_POST['attackerFocus'];
                 $data['input']['attacker']['faction'] = $node->data['faction'];
                 foreach ($_POST['attackerGroupUnitIds'] as $key => $unitId) {
                     $data['input']['attacker']['groups'][$key] = array('unitId' => $unitId, 'quantity' => $_POST['attackerGroups'][$key]);
                     if (!$game['units'][$node->data['faction']][$unitId]['speed']) {
                         $gotStatic = true;
Example #4
0
         }
     }
     break;
 case 'add':
     if ($status == 'noAlliance') {
         $nodes = node::getList($_SESSION[$shortTitle . 'User']['id']);
         if ($nodes) {
             $nodeList = '';
             foreach ($nodes as $node) {
                 $nodeList .= '<option value="' . $node->data['id'] . '">' . $node->data['name'] . '</option>';
             }
             if (isset($_POST['nodeId'], $_POST['name'])) {
                 if ($_POST['name'] != '') {
                     $alliance = new alliance();
                     $node = new node();
                     $status = $node->get('id', $_POST['nodeId']);
                     if ($status == 'done') {
                         if ($node->data['user'] == $_SESSION[$shortTitle . 'User']['id']) {
                             $alliance->data['name'] = $_POST['name'];
                             $alliance->data['user'] = $_SESSION[$shortTitle . 'User']['id'];
                             $status = $alliance->add($node->data['id']);
                             if ($status == 'done') {
                                 $status = $alliance->get('name', $_POST['name']);
                                 if ($status == 'done') {
                                     $_SESSION[$shortTitle . 'User']['alliance'] = $alliance->data['id'];
                                 }
                             }
                             $message = $ui[$status];
                         } else {
                             $message = $ui['accessDenied'];
                         }
Example #5
0
                 if (!$item['stage']) {
                     if ($item['sender'] == $node->data['id']) {
                         $action = 'outgoing';
                         $cancel = '<div class="cell"> | <a class="link" href="combat.php?action=cancel&nodeId=' . $node->data['id'] . '&combatId=' . $item['id'] . '">x</a></div>';
                     } else {
                         $action = 'incoming';
                     }
                 } else {
                     if ($item['sender'] == $node->data['id']) {
                         $action = 'returning';
                     }
                 }
                 $remaining = $item['start'] + $item['duration'] * 60 - time();
                 $otherNode = new node();
                 if ($item['sender'] == $node->data['id']) {
                     $status = $otherNode->get('id', $item['recipient']);
                 } else {
                     $status = $otherNode->get('id', $item['sender']);
                 }
                 if ($status == 'done') {
                     echo '<div><div class="cell">' . $ui[$action] . ' ' . $ui['combat'] . '</div><div class="cell">"' . $otherNode->data['name'] . '"</div><div class="cell"><span id="combat_' . $item['id'] . '">' . implode(':', misc::sToHMS($remaining)) . '</span><script type="text/javascript">timedJump("combat_' . $item['id'] . '", "node.php?action=get&nodeId=' . $node->data['id'] . '");</script></div>' . $cancel . '</div>';
                 }
             }
             echo '</div>';
         }
     }
     break;
 case 'set':
     if (isset($node->data['id'])) {
         $costData = '';
         foreach ($game['factions'][$node->data['faction']]['costs']['set'] as $key => $cost) {
Example #6
0
 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;
 }
Example #7
0
                     }
                 } else {
                     $message = $ui['accessDenied'];
                 }
             }
         } else {
             $message = $ui[$status];
         }
     } else {
         $message = $ui['insufficientData'];
     }
     break;
 case 'move':
     if (isset($_GET['nodeId'])) {
         $node = new node();
         $status = $node->get('id', $_GET['nodeId']);
         if ($status == 'done') {
             if (isset($_POST['x'], $_POST['y'])) {
                 if ($node->data['user'] == $_SESSION[$shortTitle . 'User']['id']) {
                     if ($game['factions'][$node->data['faction']]['costs']['move'][0]['resource'] > -1) {
                         $message = $ui[$node->move($_POST['x'], $_POST['y'])];
                     } else {
                         $message = $ui['nodeMoveDisabled'];
                     }
                 } else {
                     $message = $ui['accessDenied'];
                 }
             }
         } else {
             $message = $ui[$status];
         }