public function set($nodeId) { global $db, $game; $alliance = new alliance(); if ($alliance->get('id', $this->data['id']) == 'done') { if ($alliance->get('name', $this->data['name']) == 'noAlliance') { $node = new node(); if ($node->get('id', $nodeId) == 'done') { $node->getResources(); $setCost = $game['factions'][$node->data['faction']]['costs']['alliance']; $setCostData = $node->checkCost($setCost, 'alliance'); if ($setCostData['ok']) { $ok = 1; foreach ($setCost 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; } } $db->query('update alliances set name="' . $this->data['name'] . '" where id="' . $this->data['id'] . '"'); if ($db->affected_rows() == -1) { $ok = 0; } if ($ok) { $status = 'done'; } else { $status = 'error'; } } else { $status = 'notEnoughResources'; } } else { $status = 'noNode'; } } else { $status = 'nameTaken'; } } else { $status = 'noAlliance'; } return $status; }