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; }