Exemplo n.º 1
0
function db_que_set_insert($set)
{
    return classSupernova::db_ins_record(LOC_QUE, $set);
    // return ($set = trim($set)) ? doquery("INSERT INTO {{que}} SET {$set}") : false;
}
Exemplo n.º 2
0
/**
 * @param        $pos_galaxy
 * @param        $pos_system
 * @param        $pos_planet
 * @param        $user_id
 * @param int    $moon_chance
 * <p><b>0</b> случайный размер луны</p>
 * <p>1..100 Шанс выпадения луны</p>
 * <p>> 100 Размер луны</p>
 * @param string $moon_name
 * @param bool   $update_debris
 * @param array  $options
 *
 * @return array|false|resource
 */
function uni_create_moon($pos_galaxy, $pos_system, $pos_planet, $user_id, $moon_chance = 0, $moon_name = '', $update_debris = true, $options = array())
{
    global $lang;
    $moon_name = '';
    $moon_row = array();
    $moon = db_planet_by_gspt($pos_galaxy, $pos_system, $pos_planet, PT_MOON, false, 'id');
    if (!$moon['id']) {
        $moon_planet = db_planet_by_gspt($pos_galaxy, $pos_system, $pos_planet, PT_PLANET, true, '`id`, `temp_min`, `temp_max`, `name`, `debris_metal`, `debris_crystal`');
        if ($moon_planet['id']) {
            $base_storage_size = BASE_STORAGE_SIZE;
            if (!$moon_chance) {
                $size = mt_rand(1100, 8999);
            } elseif ($moon_chance <= 100) {
                $size = mt_rand($moon_chance * 100 + 1000, $moon_chance * 200 + 2999);
            } else {
                $size = $moon_chance;
            }
            $moon_chance = min(30, ceil($size / 1000));
            $temp_min = $moon_planet['temp_min'] - rand(10, 45);
            $temp_max = $temp_min + 40;
            $moon_name = $moon_name ? $moon_name : "{$moon_planet['name']} {$lang['sys_moon']}";
            $moon_name_safe = db_escape($moon_name);
            $field_max = ceil($size / 1000);
            if (isset($options['image']) && $options['image']) {
                $moon_image = $options['image'];
            } else {
                $moon_image = 'mond';
            }
            $moon_row = classSupernova::db_ins_record(LOC_PLANET, "`id_owner` = '{$user_id}', `parent_planet` = '{$moon_planet['id']}', `name` = '{$moon_name_safe}', `last_update` = " . SN_TIME_NOW . ", `image` = '{$moon_image}',\n          `galaxy` = '{$pos_galaxy}', `system` = '{$pos_system}', `planet` = '{$pos_planet}', `planet_type` = " . PT_MOON . ",\n          `diameter` = '{$size}', `field_max` = '{$field_max}', `density` = 2500, `density_index` = 2, `temp_min` = '{$temp_min}', `temp_max` = '{$temp_max}',\n          `metal` = '0', `metal_perhour` = '0', `metal_max` = '{$base_storage_size}',\n          `crystal` = '0', `crystal_perhour` = '0', `crystal_max` = '{$base_storage_size}',\n          `deuterium` = '0', `deuterium_perhour` = '0', `deuterium_max` = '{$base_storage_size}'");
            if ($update_debris) {
                $debris_spent = $moon_chance * 1000000;
                $metal_spent = round(min($moon_planet['debris_metal'], $debris_spent * mt_rand(50, 75) / 100));
                $crystal_spent = min($moon_planet['debris_crystal'], $debris_spent - $metal_spent);
                $metal_spent = min($moon_planet['debris_metal'], $debris_spent - $crystal_spent);
                // Need if crystal less then their part
                db_planet_set_by_id($moon_planet['id'], "`debris_metal` = GREATEST(0, `debris_metal` - {$metal_spent}), `debris_crystal` = GREATEST(0, `debris_crystal` - {$crystal_spent})");
            }
        }
    }
    return $moon_row;
}
Exemplo n.º 3
0
 public static function db_changeset_apply($db_changeset, $flush_delayed = false)
 {
     $result = true;
     if (!is_array($db_changeset) || empty($db_changeset)) {
         return $result;
     }
     foreach ($db_changeset as $table_name => &$table_data) {
         // TODO - delayed changeset
         /*
         if(static::db_transaction_check(false) && !$flush_delayed && ($table_name == 'users' || $table_name == 'planets' || $table_name == 'unit'))
         {
           static::db_changeset_delay($table_name, $table_data);
           continue;
         }
         */
         foreach ($table_data as $record_id => &$conditions) {
             static::db_changeset_condition_compile($conditions, $table_name);
             if ($conditions['action'] != SQL_OP_DELETE && !$conditions[P_FIELDS_STR]) {
                 continue;
             }
             if ($conditions['action'] == SQL_OP_DELETE && !$conditions[P_WHERE_STR]) {
                 continue;
             }
             // Защита от случайного удаления всех данных в таблице
             if ($conditions[P_LOCATION] != LOC_NONE) {
                 //die('spec ops supernova.php line 928 Добавить работу с кэшем юнитов итд');
                 switch ($conditions['action']) {
                     case SQL_OP_DELETE:
                         $result = classSupernova::db_del_record_list($conditions[P_LOCATION], $conditions[P_WHERE_STR]) && $result;
                         break;
                     case SQL_OP_UPDATE:
                         $result = classSupernova::db_upd_record_list($conditions[P_LOCATION], $conditions[P_WHERE_STR], $conditions[P_FIELDS_STR]) && $result;
                         break;
                     case SQL_OP_INSERT:
                         $result = classSupernova::db_ins_record($conditions[P_LOCATION], $conditions[P_FIELDS_STR]) && $result;
                         break;
                     default:
                         die('Неподдерживаемая операция в classSupernova::db_changeset_apply');
                         // case SQL_OP_REPLACE: $result = $result && doquery("REPLACE INTO {{{$table_name}}} SET {$fields}"); break;
                 }
             } else {
                 $result = doquery($conditions[P_QUERY_STR]) && $result;
             }
         }
     }
     return $result;
 }
Exemplo n.º 4
0
function db_unit_set_insert($set)
{
    return classSupernova::db_ins_record(LOC_UNIT, $set);
}
Exemplo n.º 5
0
function db_unit_set_insert($set)
{
    return classSupernova::db_ins_record(LOC_UNIT, $set);
    return doquery("INSERT INTO {{unit}} SET {$set}");
}