function int_calc_storage_bar($resource_id) { global $lang, $template, $caps_real, $planetrow, $user; $totalProduction = $caps_real['total'][$resource_id]; $storage_fill = $caps_real['total_storage'][$resource_id] ? floor(mrc_get_level($user, $planetrow, $resource_id) / $caps_real['total_storage'][$resource_id] * 100) : 0; $template->assign_block_vars('resources', array('NAME' => $lang["sys_" . pname_resource_name($resource_id)], 'HOURLY' => pretty_number($totalProduction, true, true), 'WEEKLY' => pretty_number($totalProduction * 24 * 7, true, true), 'DAILY' => pretty_number($totalProduction * 24, true, true), 'MONTHLY' => pretty_number($totalProduction * 24 * 30, true, true), 'STORAGE' => intval($storage_fill), 'BAR' => min($storage_fill, 100))); }
function sn_admin_planet_edit_template(&$template, $edit_planet_row, $mode) { global $lang; $unit_list = sn_get_groups($mode); if (empty($unit_list)) { return; } $name_list = $lang['tech']; foreach ($unit_list as $unit_id) { $template->assign_block_vars('unit', array('ID' => $unit_id, 'NAME' => $name_list[$unit_id], 'TEXT' => pretty_number(mrc_get_level($user, $edit_planet_row, $unit_id, false, true)), 'VALUE' => '')); } }
function eco_bld_tech($que_type, &$user, &$planet) { global $config, $lang; lng_include('buildings'); lng_include('infos'); if (!mrc_get_level($user, $planet, STRUC_LABORATORY)) { message($lang['no_laboratory'], $lang['tech'][UNIT_TECHNOLOGIES]); } if (eco_unit_busy($user, $planet, UNIT_TECHNOLOGIES)) { message($lang['eco_bld_msg_err_laboratory_upgrading'], $lang['tech'][UNIT_TECHNOLOGIES]); } switch ($action = sys_get_param_escaped('action')) { case 'build': $operation_result = que_build($user, $planet); break; case 'trim': que_delete(QUE_RESEARCH, $user, $planet, false); break; case 'clear': que_delete(QUE_RESEARCH, $user, $planet, true); break; //case 'build':$operation_result = eco_bld_tech_research($user, $planet);break; } $template = gettemplate('buildings_research', true); if (!empty($operation_result)) { $template->assign_block_vars('result', $operation_result); } $fleet_list = flt_get_fleets_to_planet($planet); $ques = que_get($user['id'], QUE_RESEARCH); $que =& $ques['ques'][QUE_RESEARCH][$user['id']][0]; que_tpl_parse($template, QUE_RESEARCH, $user, null, $que); $in_que =& $ques['in_que'][QUE_RESEARCH][$user['id']][0]; foreach (sn_get_groups('tech') as $unit_id) { if (eco_can_build_unit($user, $planet, $unit_id) != BUILD_ALLOWED) { continue; } $level_base = mrc_get_level($user, '', $unit_id, false, true); $level_effective = mrc_get_level($user, '', $unit_id); $level_in_que = $in_que[$unit_id]; $level_bonus = max(0, $level_effective - $level_base); $level_base_and_que = $level_base + $level_in_que; $build_data = eco_get_build_data($user, $planet, $unit_id, $level_base_and_que); $temp[RES_METAL] = floor($planet['metal'] - $build_data[BUILD_CREATE][RES_METAL]); $temp[RES_CRYSTAL] = floor($planet['crystal'] - $build_data[BUILD_CREATE][RES_CRYSTAL]); $temp[RES_DEUTERIUM] = floor($planet['deuterium'] - $build_data[BUILD_CREATE][RES_DEUTERIUM]); $template->assign_block_vars('production', array('ID' => $unit_id, 'NAME' => $lang['tech'][$unit_id], 'DESCRIPTION' => $lang['info'][$unit_id]['description_short'], 'LEVEL_OLD' => $level_base, 'LEVEL_BONUS' => $level_bonus, 'LEVEL_NEXT' => $level_base + $level_in_que + 1, 'LEVEL_QUED' => $level_in_que, 'LEVEL' => $level_base_and_que, 'BUILD_CAN' => $build_data['CAN'][BUILD_CREATE], 'TIME' => pretty_time($build_data[RES_TIME][BUILD_CREATE]), 'METAL' => $build_data[BUILD_CREATE][RES_METAL], 'CRYSTAL' => $build_data[BUILD_CREATE][RES_CRYSTAL], 'DEUTERIUM' => $build_data[BUILD_CREATE][RES_DEUTERIUM], 'METAL_PRINT' => pretty_number($build_data[BUILD_CREATE][RES_METAL], true, $planet['metal']), 'CRYSTAL_PRINT' => pretty_number($build_data[BUILD_CREATE][RES_CRYSTAL], true, $planet['crystal']), 'DEUTERIUM_PRINT' => pretty_number($build_data[BUILD_CREATE][RES_DEUTERIUM], true, $planet['deuterium']), 'METAL_REST' => pretty_number($temp[RES_METAL], true, true), 'CRYSTAL_REST' => pretty_number($temp[RES_CRYSTAL], true, true), 'DEUTERIUM_REST' => pretty_number($temp[RES_DEUTERIUM], true, true), 'METAL_REST_NUM' => $temp[RES_METAL], 'CRYSTAL_REST_NUM' => $temp[RES_CRYSTAL], 'DEUTERIUM_REST_NUM' => $temp[RES_DEUTERIUM], 'METAL_FLEET' => pretty_number($temp[RES_METAL] + $fleet_list['own']['total'][RES_METAL], true, true), 'CRYSTAL_FLEET' => pretty_number($temp[RES_CRYSTAL] + $fleet_list['own']['total'][RES_CRYSTAL], true, true), 'DEUTERIUM_FLEET' => pretty_number($temp[RES_DEUTERIUM] + $fleet_list['own']['total'][RES_DEUTERIUM], true, true), 'BUILD_CAN2' => $build_data['CAN'][BUILD_CREATE])); } // if(count($que['ques'][$que_id][$user['id']][$planet_id]) >= que_get_max_que_length($user, $planet, $que_id, $que_data)) $template->assign_vars(array('QUE_ID' => QUE_RESEARCH, 'FLEET_OWN_COUNT' => $fleet_list['own']['count'], 'ARTIFACT_ID' => ART_HEURISTIC_CHIP, 'ARTIFACT_LEVEL' => mrc_get_level($user, array(), ART_HEURISTIC_CHIP), 'ARTIFACT_NAME' => $lang['tech'][ART_HEURISTIC_CHIP], 'REQUEST_URI' => $_SERVER['REQUEST_URI'], 'PAGE_HEADER' => $page_header = $lang['tech'][UNIT_TECHNOLOGIES] . ($user['user_as_ally'] ? " {$lang['sys_of_ally']} {$user['username']}" : ''), 'CONFIG_RESEARCH_QUE' => $config->server_que_length_research)); display(parsetemplate($template), $page_header); }
function sn_techtree_view($template = null) { global $lang, $user, $planetrow; $tech_tree = array(); foreach (get_unit_param('techtree') as $unit_group_id => $unit_list) { $tech_tree[] = array('NAME' => $lang['tech'][$unit_group_id]); foreach ($unit_list as $unit_id) { $sn_data_unit = get_unit_param($unit_id); $level_basic = $sn_data_unit[P_STACKABLE] ? 0 : mrc_get_level($user, $planetrow, $unit_id, false, true); $unit_level = $sn_data_unit[P_STACKABLE] ? 0 : mrc_get_level($user, $planetrow, $unit_id); $rendered_info = array('ID' => $unit_id, 'NAME' => $lang['tech'][$unit_id], 'LEVEL' => $unit_level, 'LEVEL_BASIC' => $level_basic, 'LEVEL_BONUS' => max(0, $unit_level - $level_basic), 'LEVEL_MAX' => $sn_data_unit['max']); $rendered_info['.']['require'] = unit_requirements_render($user, $planetrow, $unit_id); $tech_tree[] = $rendered_info; } } $template = gettemplate('techtree', $template); $template_result['.']['techtree'] = $tech_tree; $template->assign_recursive($template_result); return $template; }
function sn_techtree_view($template = null) { global $lang, $user, $planetrow; $tech_tree = array(); foreach (get_unit_param('techtree') as $unit_group_id => $unit_list) { $tech_tree[] = array('NAME' => $lang['tech'][$unit_group_id], 'GROUP_ID' => $unit_group_id); foreach ($unit_list as $unit_id) { $sn_data_unit = get_unit_param($unit_id); $level_basic = $sn_data_unit[P_STACKABLE] ? 0 : mrc_get_level($user, $planetrow, $unit_id, false, true); $unit_level = $sn_data_unit[P_STACKABLE] ? 0 : mrc_get_level($user, $planetrow, $unit_id); $rendered_info = array('ID' => $unit_id, 'NAME' => $lang['tech'][$unit_id], 'LEVEL' => $unit_level, 'LEVEL_BASIC' => $level_basic, 'LEVEL_BONUS' => max(0, $unit_level - $level_basic), 'LEVEL_MAX' => $sn_data_unit['max']); $rendered_info['.']['require'] = unit_requirements_render($user, $planetrow, $unit_id); $rendered_info['.']['grants'] = unit_requirements_render($user, $planetrow, $unit_id, P_UNIT_GRANTS); $tech_tree[] = $rendered_info; } } $template = gettemplate('techtree', $template); $template_result['.']['techtree'] = $tech_tree; $template->assign_recursive($template_result); $template->assign_vars(array('PAGE_HEADER' => $lang['tech'][UNIT_TECHNOLOGIES], 'PLAYER_OPTION_TECH_TREE_TABLE' => classSupernova::$user_options[PLAYER_OPTION_TECH_TREE_TABLE])); return $template; }
function sn_options_view($template = null) { global $lang, $template_result, $user, $planetrow, $user_option_list, $user_option_types, $sn_message_class_list, $config; sys_user_vacation($user); $FMT_DATE = preg_replace(array('/d/', '/m/', '/Y/'), array('DD', 'MM', 'YYYY'), FMT_DATE); $template = gettemplate('options', $template); // $template_result['.']['skin_list'][] = array( // 'NAME' => $lang['select_skin_path'], // 'VALUE' => '', // ); $dir = dir(SN_ROOT_PHYSICAL . 'skins'); while (($entry = $dir->read()) !== false) { if (is_dir("skins/{$entry}") && $entry[0] != '.') { $template_result['.']['skin_list'][] = array('VALUE' => $entry, 'NAME' => $entry, 'SELECTED' => $user['dpath'] == "skins/{$entry}/"); } } $dir->close(); foreach ($lang['opt_planet_sort_options'] as $key => &$value) { $template_result['.']['planet_sort_options'][] = array('VALUE' => $key, 'NAME' => $value, 'SELECTED' => classSupernova::$user_options[PLAYER_OPTION_PLANET_SORT] == $key); } /* foreach($lang['opt_planet_sort_ascending'] as $key => &$value) { $template_result['.']['planet_sort_ascending'][] = array( 'VALUE' => $key, 'NAME' => $value, 'SELECTED' => classSupernova::$user_options[PLAYER_OPTION_PLANET_SORT_INVERSE] == $key, ); } */ foreach ($lang['sys_gender_list'] as $key => $value) { $template_result['.']['gender_list'][] = array('VALUE' => $key, 'NAME' => $value, 'SELECTED' => $user['gender'] == $key); } $lang_list = lng_get_list(); foreach ($lang_list as $lang_id => $lang_data) { $template_result['.']['languages'][] = array('VALUE' => $lang_id, 'NAME' => $lang_data['LANG_NAME_NATIVE'], 'SELECTED' => $lang_id == $user['lang']); } if (isset($lang['menu_customize_show_hide_button_state'])) { foreach ($lang['menu_customize_show_hide_button_state'] as $key => $value) { $template->assign_block_vars('menu_customize_show_hide_button_state', array('ID' => $key, 'NAME' => $value)); } } $str_date_format = "%3\$02d %2\$0s %1\$04d {$lang['top_of_year']} %4\$02d:%5\$02d:%6\$02d"; $time_now_parsed = getdate($user['deltime']); $user_time_diff = playerTimeDiff::user_time_diff_get(); // $player_options = player_load_option($user); $template->assign_vars(array('USER_ID' => $user['id'], 'ACCOUNT_NAME' => sys_safe_output(classSupernova::$auth->account->account_name), 'USER_AUTHLEVEL' => $user['authlevel'], 'menu_customize_show_hide_button' => classSupernova::$user_options[PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON], 'PLAYER_OPTION_MENU_SHOW_ON_BUTTON' => classSupernova::$user_options[PLAYER_OPTION_MENU_SHOW_ON_BUTTON], 'PLAYER_OPTION_MENU_HIDE_ON_BUTTON' => classSupernova::$user_options[PLAYER_OPTION_MENU_HIDE_ON_BUTTON], 'PLAYER_OPTION_MENU_HIDE_ON_LEAVE' => classSupernova::$user_options[PLAYER_OPTION_MENU_HIDE_ON_LEAVE], 'PLAYER_OPTION_MENU_UNPIN_ABSOLUTE' => classSupernova::$user_options[PLAYER_OPTION_MENU_UNPIN_ABSOLUTE], 'PLAYER_OPTION_MENU_ITEMS_AS_BUTTONS' => classSupernova::$user_options[PLAYER_OPTION_MENU_ITEMS_AS_BUTTONS], 'PLAYER_OPTION_MENU_WHITE_TEXT' => classSupernova::$user_options[PLAYER_OPTION_MENU_WHITE_TEXT], 'PLAYER_OPTION_MENU_OLD' => classSupernova::$user_options[PLAYER_OPTION_MENU_OLD], 'PLAYER_OPTION_UNIVERSE_OLD' => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_OLD], 'PLAYER_OPTION_UNIVERSE_DISABLE_COLONIZE' => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_DISABLE_COLONIZE], 'PLAYER_OPTION_DESIGN_DISABLE_BORDERS' => classSupernova::$user_options[PLAYER_OPTION_DESIGN_DISABLE_BORDERS], 'PLAYER_OPTION_TECH_TREE_TABLE' => classSupernova::$user_options[PLAYER_OPTION_TECH_TREE_TABLE], 'sound_enabled' => classSupernova::$user_options[PLAYER_OPTION_SOUND_ENABLED], 'PLAYER_OPTION_ANIMATION_DISABLED' => classSupernova::$user_options[PLAYER_OPTION_ANIMATION_DISABLED], 'PLAYER_OPTION_PROGRESS_BARS_DISABLED' => classSupernova::$user_options[PLAYER_OPTION_PROGRESS_BARS_DISABLED], 'ADM_PROTECT_PLANETS' => $user['authlevel'] >= 3, 'opt_usern_data' => htmlspecialchars($user['username']), 'opt_mail1_data' => $user['email'], 'opt_mail2_data' => sys_safe_output(classSupernova::$auth->account->account_email), 'OPT_DPATH_DATA' => $user['dpath'], 'PLAYER_OPTION_PLANET_SORT_INVERSE' => classSupernova::$user_options[PLAYER_OPTION_PLANET_SORT_INVERSE], 'PLAYER_OPTION_FLEET_SPY_DEFAULT' => classSupernova::$user_options[PLAYER_OPTION_FLEET_SPY_DEFAULT], 'PLAYER_OPTION_TOOLTIP_DELAY' => classSupernova::$user_options[PLAYER_OPTION_TOOLTIP_DELAY], 'PLAYER_OPTION_BUILD_AUTOCONVERT_HIDE' => classSupernova::$user_options[PLAYER_OPTION_BUILD_AUTOCONVERT_HIDE], 'PLAYER_OPTION_NAVBAR_RESEARCH_WIDE' => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_RESEARCH_WIDE], 'PLAYER_OPTION_NAVBAR_DISABLE_EXPEDITIONS' => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_EXPEDITIONS], 'PLAYER_OPTION_NAVBAR_DISABLE_FLYING_FLEETS' => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_FLYING_FLEETS], 'PLAYER_OPTION_NAVBAR_DISABLE_RESEARCH' => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_RESEARCH], 'PLAYER_OPTION_NAVBAR_DISABLE_PLANET' => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_PLANET], 'PLAYER_OPTION_NAVBAR_DISABLE_HANGAR' => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_HANGAR], 'PLAYER_OPTION_NAVBAR_DISABLE_QUESTS' => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_QUESTS], 'PLAYER_OPTION_NAVBAR_DISABLE_META_MATTER' => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_META_MATTER], 'opt_sskin_data' => $user['design'] == 1 ? " checked='checked'" : '', 'opt_noipc_data' => $user['noipcheck'] == 1 ? " checked='checked'" : '', 'deltime' => $user['deltime'], 'deltime_text' => sprintf($str_date_format, $time_now_parsed['year'], $lang['months'][$time_now_parsed['mon']], $time_now_parsed['mday'], $time_now_parsed['hours'], $time_now_parsed['minutes'], $time_now_parsed['seconds']), 'opt_avatar' => $user['avatar'], 'config_game_email_pm' => $config->game_email_pm, 'user_settings_esp' => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_SPYING], 'user_settings_mis' => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_MISSILE], 'user_settings_wri' => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_PM], 'user_settings_statistics' => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_STATS], 'user_settings_info' => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_PROFILE], 'user_settings_bud' => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_BUDDY], 'user_time_diff_forced' => $user_time_diff[PLAYER_OPTION_TIME_DIFF_FORCED], 'adm_pl_prot' => $user['admin_protection'], 'user_birthday' => $user['user_birthday'], 'GENDER' => $user['gender'], 'GENDER_TEXT' => $lang['sys_gender_list'][$user['gender']], 'FMT_DATE' => $FMT_DATE, 'JS_FMT_DATE' => js_safe_string($FMT_DATE), 'USER_VACATION_DISABLE' => $config->user_vacation_disable, 'VACATION_NEXT' => $user['vacation_next'], 'VACATION_NEXT_TEXT' => date(FMT_DATE_TIME, $user['vacation_next']), 'VACATION_TIMEOUT' => $user['vacation_next'] - SN_TIME_NOW > 0 ? $user['vacation_next'] - SN_TIME_NOW : 0, 'SN_TIME_NOW' => SN_TIME_NOW, 'SERVER_SEND_EMAIL' => $config->game_email_pm, 'SERVER_NAME_CHANGE' => $config->game_user_changename != SERVER_PLAYER_NAME_CHANGE_NONE, 'SERVER_NAME_CHANGE_PAY' => $config->game_user_changename == SERVER_PLAYER_NAME_CHANGE_PAY, 'SERVER_NAME_CHANGE_ENABLED' => $config->game_user_changename == SERVER_PLAYER_NAME_CHANGE_FREE || $config->game_user_changename == SERVER_PLAYER_NAME_CHANGE_PAY && mrc_get_level($user, $planetrow, RES_DARK_MATTER) >= $config->game_user_changename_cost, 'DARK_MATTER' => pretty_number($config->game_user_changename_cost, true, mrc_get_level($user, $planetrow, RES_DARK_MATTER)), 'PAGE_HEADER' => $lang['opt_header'])); foreach ($user_option_list as $option_group_id => $option_group) { if ($option_group_id == OPT_MESSAGE) { foreach ($sn_message_class_list as $message_class_id => $message_class_data) { if ($message_class_data['switchable'] || $message_class_data['email'] && $config->game_email_pm) { $option_name = $message_class_data['name']; $template->assign_block_vars("options_{$option_group_id}", array('NAME' => $message_class_data['name'], 'TEXT' => $lang['msg_class'][$message_class_id], 'PM' => $message_class_data['switchable'] ? $user["opt_{$option_name}"] : -1, 'EMAIL' => $message_class_data['email'] && $config->game_email_pm ? $user["opt_email_{$option_name}"] : -1)); } } } else { foreach ($option_group as $option_name => $option_value) { if (array_key_exists($option_name, $user_option_types)) { $option_type = $user_option_types[$option_name]; } else { $option_type = 'switch'; } $template->assign_block_vars("options_{$option_group_id}", array('NAME' => $option_name, 'TYPE' => $option_type, 'TEXT' => $lang['opt_custom'][$option_name], 'HINT' => $lang['opt_custom']["{$option_name}_hint"], 'VALUE' => $user[$option_name])); } } } return parsetemplate($template); }
function get_player_max_colonies(&$user, $astrotech = -1) { global $config; if ($astrotech == -1) { if (!isset($user[UNIT_PLAYER_COLONIES_MAX])) { $expeditions = get_player_max_expeditons($user); $astrotech = mrc_get_level($user, false, TECH_ASTROTECH); $colonies = $astrotech - $expeditions; $user[UNIT_PLAYER_COLONIES_MAX] = $config->player_max_colonies < 0 ? $colonies : min($config->player_max_colonies, $colonies); } return $user[UNIT_PLAYER_COLONIES_MAX]; } else { $expeditions = get_player_max_expeditons($user, $astrotech); // $astrotech = mrc_get_level($user, false, TECH_ASTROTECH); $colonies = $astrotech - $expeditions; return $config->player_max_colonies < 0 ? $colonies : min($config->player_max_colonies, $colonies); } }
/** * Copyright (c) 2009-2010 by Gorlum for http://supernova.ws * OpenSource as long as you don't remove this Copyright * V3 2009-11-13 * V2 2009-10-10 */ function coe_o_missile_calculate() { sn_db_transaction_check(true); global $lang; $iraks = doquery("SELECT * FROM {{iraks}} WHERE `fleet_end_time` <= " . SN_TIME_NOW . " FOR UPDATE;"); while ($fleetRow = db_fetch($iraks)) { set_time_limit(15); $db_changeset = array(); $targetUser = db_user_by_id($fleetRow['fleet_target_owner'], true); $target_planet_row = sys_o_get_updated($targetUser, array('galaxy' => $fleetRow['fleet_end_galaxy'], 'system' => $fleetRow['fleet_end_system'], 'planet' => $fleetRow['fleet_end_planet'], 'planet_type' => PT_PLANET), SN_TIME_NOW); $target_planet_row = $target_planet_row['planet']; $rowAttacker = db_user_by_id($fleetRow['fleet_owner'], true); if ($target_planet_row['id']) { $planetDefense = array(); foreach (sn_get_groups('defense_active') as $unit_id) { $planetDefense[$unit_id] = array(mrc_get_level($targetUser, $target_planet_row, $unit_id, true, true)); } $message = ''; $interceptors = mrc_get_level($targetUser, $target_planet_row, UNIT_DEF_MISSILE_INTERCEPTOR, true, true); //$target_planet_row[$interceptor_db_name]; // Number of interceptors $missiles = $fleetRow['fleet_amount']; // Number of MIP if ($interceptors >= $missiles) { $message = $lang['mip_all_destroyed']; $db_changeset['unit'][] = sn_db_unit_changeset_prepare(UNIT_DEF_MISSILE_INTERCEPTOR, -$missiles, $targetUser, $target_planet_row['id']); } else { if ($interceptors) { $message = sprintf($lang['mip_destroyed'], $interceptors); $db_changeset['unit'][] = sn_db_unit_changeset_prepare(UNIT_DEF_MISSILE_INTERCEPTOR, -$interceptors, $targetUser, $target_planet_row['id']); } // $message .= $lang['mip_defense_destroyed']; $attackResult = COE_missileAttack($targetUser, $rowAttacker, $missiles - $interceptors, $planetDefense, $fleetRow['primaer']); foreach ($attackResult['structures'] as $key => $structure) { $destroyed = $planetDefense[$key][0] - $structure[0]; if ($destroyed) { $db_changeset['unit'][] = sn_db_unit_changeset_prepare($key, -$destroyed, $targetUser, $target_planet_row['id']); $message .= " {$lang['tech'][$key]} - {$destroyed} {$lang['quantity']}<br>"; } } if (!empty($message)) { $message = $lang['mip_defense_destroyed'] . $message . "{$lang['mip_recycled']}{$lang['Metal']}: {$attackResult['metal']}, {$lang['Crystal']}: {$attackResult['crystal']}<br>"; db_planet_set_by_id($target_planet_row['id'], "`metal` = `metal` + {$attackResult['metal']}, `crystal` = `crystal` + {$attackResult['crystal']}"); } // $message .= "{$lang['mip_recycled']}{$lang['Metal']}: {$attackResult['metal']}, {$lang['Crystal']}: {$attackResult['crystal']}<br>"; } db_changeset_apply($db_changeset); $fleetRow['fleet_start_type'] = PT_PLANET; $sourcePlanet = db_planet_by_vector($fleetRow, 'fleet_start_', false, 'name'); $message_vorlage = sprintf($lang['mip_body_attack'], $fleetRow['fleet_amount'], addslashes($sourcePlanet['name']), $fleetRow['fleet_start_galaxy'], $fleetRow['fleet_start_system'], $fleetRow['fleet_start_planet'], addslashes($target_planet_row['name']), $fleetRow['fleet_end_galaxy'], $fleetRow['fleet_end_system'], $fleetRow['fleet_end_planet']); empty($message) ? $message = $lang['mip_no_defense'] : false; // empty($message) && ($message = $lang['mip_no_defense']); msg_send_simple_message($fleetRow['fleet_owner'], '', SN_TIME_NOW, MSG_TYPE_SPY, $lang['mip_sender_amd'], $lang['mip_subject_amd'], $message_vorlage . $message); msg_send_simple_message($fleetRow['fleet_target_owner'], '', SN_TIME_NOW, MSG_TYPE_SPY, $lang['mip_sender_amd'], $lang['mip_subject_amd'], $message_vorlage . $message); } doquery("DELETE FROM {{iraks}} WHERE id = '{$fleetRow['id']}';"); } }
function uni_planet_teleport_check($user, $planetrow, $new_coordinates = null) { global $lang, $config; try { if ($planetrow['planet_teleport_next'] && $planetrow['planet_teleport_next'] > SN_TIME_NOW) { throw new exception($lang['ov_teleport_err_cooldown'], ERR_ERROR); } if (mrc_get_level($user, false, RES_DARK_MATTER) < $config->planet_teleport_cost) { throw new exception($lang['ov_teleport_err_no_dark_matter'], ERR_ERROR); } // TODO: Replace quick-check with using gathered flying fleet data $incoming = doquery("SELECT COUNT(*) AS incoming FROM {{fleets}} WHERE \n (fleet_start_galaxy = {$planetrow['galaxy']} and fleet_start_system = {$planetrow['system']} and fleet_start_planet = {$planetrow['planet']})\n or\n (fleet_end_galaxy = {$planetrow['galaxy']} and fleet_end_system = {$planetrow['system']} and fleet_end_planet = {$planetrow['planet']})", true); if (!empty($incoming['incoming'])) { throw new exception($lang['ov_teleport_err_fleet'], ERR_ERROR); } //$incoming = doquery("SELECT COUNT(*) AS incoming FROM {{iraks}} WHERE fleet_end_galaxy = {$planetrow['galaxy']} and fleet_end_system = {$planetrow['system']} and fleet_end_planet = {$planetrow['planet']}", true); //if($incoming['incoming']) { // throw new exception($lang['ov_teleport_err_fleet'], ERR_ERROR); //} if (is_array($new_coordinates)) { $new_coordinates['planet_type'] = PT_PLANET; $incoming = db_planet_by_vector($new_coordinates, '', true, 'id'); if ($incoming['id']) { throw new exception($lang['ov_teleport_err_destination_busy'], ERR_ERROR); } } $response = array('result' => ERR_NONE, 'message' => ''); } catch (exception $e) { $response = array('result' => $e->getCode(), 'message' => $e->getMessage()); } return $response; }
function sn_eco_can_build_unit($user, $planet, $unit_id, &$result) { global $config; $result = isset($result) ? $result : BUILD_ALLOWED; $result = $result == BUILD_ALLOWED && eco_unit_busy($user, $planet, $unit_id) ? BUILD_UNIT_BUSY : $result; $unit_param = get_unit_param($unit_id); if ($unit_param[P_UNIT_TYPE] != UNIT_MERCENARIES || !$config->empire_mercenary_temporary) { $requirement =& $unit_param[P_REQUIRE]; if ($result == BUILD_ALLOWED && $requirement) { foreach ($requirement as $require_id => $require_level) { if (mrc_get_level($user, $planet, $require_id) < $require_level) { $result = BUILD_REQUIRE_NOT_MEET; break; } } } } return $result; }
function ube_attack_prepare_planet(&$combat_data, &$planet) { global $ube_combat_bonus_list; $player_id = $planet['id_owner']; ube_attack_prepare_player($combat_data, $player_id, false); $player =& $combat_data[UBE_PLAYERS][$player_id][UBE_PLAYER_DATA]; $combat_data[UBE_FLEETS][0] = array(UBE_OWNER => $player_id); $fleet_info =& $combat_data[UBE_FLEETS][0]; foreach (sn_get_groups('combat') as $unit_id) { if ($unit_count = mrc_get_level($player, $planet, $unit_id)) { $fleet_info[UBE_COUNT][$unit_id] = $unit_count; } } foreach (sn_get_groups('resources_loot') as $resource_id) { $fleet_info[UBE_RESOURCES][$resource_id] = floor(mrc_get_level($player, $planet, $resource_id)); } if ($fortifier_level = mrc_get_level($player, $planet, MRC_FORTIFIER)) { $fortifier_bonus = $fortifier_level * get_unit_param(MRC_FORTIFIER, P_BONUS_VALUE) / 100; foreach ($ube_combat_bonus_list as $ube_id) { $fleet_info[UBE_BONUSES][$ube_id] += $fortifier_bonus; } } $combat_data[UBE_OUTCOME][UBE_PLANET] = $fleet_info[UBE_PLANET] = array(PLANET_ID => $planet['id'], PLANET_NAME => $planet['name'], PLANET_GALAXY => $planet['galaxy'], PLANET_SYSTEM => $planet['system'], PLANET_PLANET => $planet['planet'], PLANET_TYPE => $planet['planet_type'], PLANET_SIZE => $planet['diameter']); $combat_data[UBE_OPTIONS][UBE_DEFENDER_ACTIVE] = $player['onlinetime'] >= $combat_data[UBE_TIME] - 60 * 60 * 24 * 7; }
// die(); // } // // if(!$config->game_blitz_register) { // && $user['authlevel'] < AUTH_LEVEL_DEVELOPER // message($lang['sys_blitz_registration_disabled'], $lang['sys_error'], 'overview.php', 10); // die(); // } } $current_round = intval($config->db_loadItem('game_blitz_register_round')); $current_price = intval($config->db_loadItem('game_blitz_register_price')); if ($config->db_loadItem('game_blitz_register') == BLITZ_REGISTER_OPEN && (sys_get_param_str('register_me') || sys_get_param_str('register_me_not'))) { sn_db_transaction_start(); $user = db_user_by_id($user['id'], true); $is_registered = doquery("SELECT `id` FROM {{blitz_registrations}} WHERE `user_id` = {$user['id']} AND `round_number` = {$current_round} FOR UPDATE;", true); if (sys_get_param_str('register_me')) { if (empty($is_registered) && mrc_get_level($user, null, RES_METAMATTER) >= $current_price) { doquery("INSERT IGNORE INTO {{blitz_registrations}} SET `user_id` = {$user['id']}, `round_number` = {$current_round};"); //mm_points_change($user['id'], RPG_BLITZ_REGISTRATION, -$current_price, "Регистрация в раунде {$current_round} Блица"); classSupernova::$auth->account->metamatter_change(RPG_BLITZ_REGISTRATION, -$current_price, "Регистрация в раунде {$current_round} Блица"); } } elseif (sys_get_param_str('register_me_not') && !empty($is_registered)) { doquery("DELETE FROM {{blitz_registrations}} WHERE `user_id` = {$user['id']} AND `round_number` = {$current_round};"); // mm_points_change($user['id'], RPG_BLITZ_REGISTRATION_CANCEL, $current_price, "Отмена регистрации в раунде {$current_round} Блица"); classSupernova::$auth->account->metamatter_change(RPG_BLITZ_REGISTRATION_CANCEL, $current_price, "Отмена регистрации в раунде {$current_round} Блица"); } $registered_count = doquery("SELECT count(`id`) AS `count` FROM {{blitz_registrations}} WHERE `round_number` = {$current_round};", true); $config->db_saveItem('game_blitz_register_users', $registered_count['count']); sn_db_transaction_commit(); } $blitz_generated = array(); $blitz_result = array();
<?php /** * phalanx.php * * 2.0 copyright (c) 2009-2011 by Gorlum for http://supernova.ws [!] Full rewrote using SN functions * 1.2 - Security checks & tests by Gorlum for http://supernova.ws * @version 1.1 * @original made by ???? * @copyright 2008 by Pada for XNova.project.es */ include 'common.' . substr(strrchr(__FILE__, '.'), 1); lng_include('overview'); lng_include('universe'); $sensorLevel = mrc_get_level($user, $planetrow, STRUC_MOON_PHALANX); if (!intval($sensorLevel)) { message($lang['phalanx_nosensoravailable'], $lang['tech'][STRUC_MOON_PHALANX], '', 3); } if ($planetrow['planet_type'] != PT_MOON) { message($lang['phalanx_onlyformoons'], $lang['tech'][STRUC_MOON_PHALANX], '', 3); } $scan_galaxy = sys_get_param_int('galaxy'); $scan_system = sys_get_param_int('system'); $scan_planet = sys_get_param_int('planet'); $scan_planet_type = 1; // sys_get_param_int('planettype'); $id = sys_get_param_id('id'); $source_galaxy = $planetrow['galaxy']; $source_system = $planetrow['system']; $source_planet = $planetrow['planet'];
throw new exception($lang['uni_msg_error_wrong_system'], ERR_ERROR); } $uni_row = doquery("select * from `{{universe}}` where `universe_galaxy` = {$uni_galaxy} and `universe_system` = {$uni_system} limit 1;", '', true); $uni_row['universe_price'] += $uni_system ? $config->uni_price_system : $config->uni_price_galaxy; $uni_row['universe_name'] = strip_tags($uni_row['universe_name'] ? $uni_row['universe_name'] : ($uni_system ? "{$lang['sys_system']} [{$uni_galaxy}:{$uni_system}]" : "{$lang['sys_galaxy']} {$uni_galaxy}")); if (sys_get_param_str('uni_name_submit')) { $uni_row['universe_name'] = strip_tags(sys_get_param_str('uni_name')); $uni_price = sys_get_param_float('uni_price'); if ($uni_price < $uni_row['universe_price']) { throw new exception($lang['uni_msg_error_low_price'], ERR_ERROR); } $uni_row['universe_price'] = $uni_price; sn_db_transaction_start(); $user = db_user_by_id($user['id'], true); // if($user[get_unit_param(RES_DARK_MATTER, P_NAME)] < $uni_price) if (mrc_get_level($user, null, RES_DARK_MATTER) < $uni_price) { throw new exception($lang['uni_msg_error_no_dm'], ERR_ERROR); } if (!rpg_points_change($user['id'], RPG_RENAME, -$uni_price, "Renaming [{$uni_galaxy}:{$uni_system}] to " . sys_get_param_str_unsafe('uni_name'))) { throw new exception($lang['sys_msg_err_update_dm'], ERR_ERROR); } doquery("replace {{universe}} set `universe_galaxy` = {$uni_galaxy}, `universe_system` = {$uni_system}, `universe_name` = '{$uni_row['universe_name']}', `universe_price` = {$uni_row['universe_price']};"); $debug->warning(sprintf($lang['uni_msg_admin_rename'], $user['id'], $user['username'], $uni_price, $uni_system ? $lang['uni_system_of'] : $lang['uni_galaxy_of'], $uni_galaxy, $uni_system ? ":{$uni_system}" : '', strip_tags(sys_get_param_str_unsafe('uni_name'))), $lang['uni_naming'], LOG_INFO_UNI_RENAME); sn_db_transaction_commit(); sys_redirect("galaxy.php?mode=name&galaxy={$uni_galaxy}&system={$uni_system}"); } } catch (exception $e) { sn_db_transaction_rollback(); $template->assign_block_vars('result', array('STATUS' => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR, 'MESSAGE' => $e->getMessage())); } $template->assign_vars(array('GALAXY' => $uni_galaxy, 'SYSTEM' => $uni_system, 'NAME' => sys_safe_output($uni_row['universe_name']), 'PRICE' => $uni_row['universe_price'], 'PAGE_HINT' => $lang['uni_name_page_hint']));
$RetMessage = $lang['gate_wait_star'] . " - " . pretty_time($NextJumpTime); } sn_db_transaction_commit(); message($RetMessage, $lang['tech'][STRUC_MOON_GATE], "jumpgate.php", 10); } else { $template = gettemplate('jumpgate', true); if (mrc_get_level($user, $planetrow, STRUC_MOON_GATE) > 0) { $Combo = ''; $MoonList = db_planet_list_moon_other($user['id'], $planetrow['id']); // while($CurMoon = db_fetch($MoonList)) foreach ($MoonList as $CurMoon) { if (mrc_get_level($user, $CurMoon, STRUC_MOON_GATE) >= 1) { $NextJumpTime = uni_get_time_to_jump($CurMoon); $template->assign_block_vars('moon', array('ID' => $CurMoon['id'], 'GALAXY' => $CurMoon['galaxy'], 'SYSTEM' => $CurMoon['system'], 'PLANET' => $CurMoon['planet'], 'NAME' => $CurMoon['name'], 'NEXT_JUMP_TIME' => $NextJumpTime ? pretty_time($NextJumpTime) : '')); } } foreach (sn_get_groups('fleet') as $Ship) { if (($ship_count = mrc_get_level($user, $planetrow, $Ship)) <= 0) { continue; } $template->assign_block_vars('fleet', array('SHIP_ID' => $Ship, 'SHIP_NAME' => $lang['tech'][$Ship], 'SHIP_COUNT' => $ship_count, 'SHIP_COUNT_TEXT' => pretty_number($ship_count))); } $template->assign_vars(array('GATE_JUMP_REST_TIME' => uni_get_time_to_jump($planetrow), 'gate_start_name' => $planetrow['name'], 'gate_start_link' => uni_render_coordinates_href($planetrow, '', 3))); display($template, $lang['tech'][STRUC_MOON_GATE]); } else { message($lang['gate_no_src_ga'], $lang['tech'][STRUC_MOON_GATE], "overview.php", 10); } } // ----------------------------------------------------------------------------------------------------------- // History version // 1.0 - Version from scrap .. y avait pas ... bin maintenant y a !!
function flt_calculate_fleet_to_transport($ship_list, $resource_amount, $from, $to) { global $user; $ship_data = array(); $fleet_array = array(); foreach ($ship_list as $transport_id => $cork) { $ship_data[$transport_id] = flt_travel_data($user, $from, $to, array($transport_id => 1), 10); } uasort($ship_data, flt_calculate_ship_to_transport_sort); $fleet_hold = 0; $fleet_capacity = 0; $fuel_total = $fuel_left = mrc_get_level($user, $from, RES_DEUTERIUM); foreach ($ship_data as $transport_id => &$ship_info) { $ship_loaded = min($ship_list[$transport_id], ceil($resource_amount / $ship_info['hold']), floor($fuel_left / $ship_info['consumption'])); if ($ship_loaded) { $fleet_array[$transport_id] = $ship_loaded; $resource_amount -= min($resource_amount, $ship_info['hold'] * $ship_loaded); $fuel_left -= $ship_info['consumption'] * $ship_loaded; $fleet_capacity += $ship_info['capacity'] * $ship_loaded; } } return array('fleet' => $fleet_array, 'ship_data' => $ship_data, 'capacity' => $fleet_capacity, 'consumption' => $fuel_total - $fuel_left); }
$QryInsertFleet .= "`fleet_amount` = '{$fleet_ship_count}', "; $QryInsertFleet .= "`fleet_array` = '{$FleetDBArray}', "; $QryInsertFleet .= "`fleet_start_time` = '{$fleet_start_time}', "; if ($planetrow['id']) { $QryInsertFleet .= "`fleet_start_planet_id` = '{$planetrow['id']}', "; } $QryInsertFleet .= "`fleet_start_galaxy` = '{$planetrow['galaxy']}', `fleet_start_system` = '{$planetrow['system']}', `fleet_start_planet` = '{$planetrow['planet']}', `fleet_start_type` = '{$planetrow['planet_type']}', "; $QryInsertFleet .= "`fleet_end_time` = '{$fleet_end_time}', "; if ($target_row['id']) { $QryInsertFleet .= "`fleet_end_planet_id` = '{$target_row['id']}', "; } $QryInsertFleet .= "`fleet_end_galaxy` = '{$target_coord['galaxy']}', `fleet_end_system` = '{$target_coord['system']}', `fleet_end_planet` = '{$target_coord['planet']}', `fleet_end_type` = '{$target_planet_type}', "; $QryInsertFleet .= "`fleet_target_owner` = '{$target_row['id_owner']}', "; $QryInsertFleet .= "`start_time` = " . SN_TIME_NOW . ";"; doquery($QryInsertFleet); } db_planet_set_by_id($planetrow['id'], "`deuterium` = `deuterium` - {$travel_data['consumption']}"); db_changeset_apply($db_changeset); sn_db_transaction_commit(); $ships_sent = array(); //$ships_sent_js = array(); $ships_sent_js = 0; foreach ($fleet_array as $unit_id => $unit_count) { $ships_sent[] = "{$unit_count} {$lang['tech'][$unit_id]}"; $ships_sent_js += mrc_get_level($user, $planetrow, $unit_id, false, true); } $ships_sent = implode(', ', $ships_sent); //$ships_sent_js = implode(',', $ships_sent_js); $ships_sent_js = "{$unit_group}={$ships_sent_js}"; $ResultMessage = "{$lang['gs_sending']} {$ships_sent} {$lang['gs_to']} {$target_coord['galaxy']}:{$target_coord['system']}:{$target_coord['planet']}|{$ships_sent_js}"; die($ResultMessage);
function int_planet_pretemplate($planetrow, &$template) { global $lang, $user; $governor_id = $planetrow['PLANET_GOVERNOR_ID']; $governor_level_plain = mrc_get_level($user, $planetrow, $governor_id, false, true); $template->assign_vars(array('PLANET_ID' => $planetrow['id'], 'PLANET_NAME' => htmlentities($planetrow['name'], ENT_QUOTES, 'UTF-8'), 'PLANET_NAME_JS' => htmlentities(js_safe_string($planetrow['name']), ENT_QUOTES, 'UTF-8'), 'PLANET_GALAXY' => $planetrow['galaxy'], 'PLANET_SYSTEM' => $planetrow['system'], 'PLANET_PLANET' => $planetrow['planet'], 'PLANET_TYPE' => $planetrow['planet_type'], 'PLANET_TYPE_TEXT' => $lang['sys_planet_type'][$planetrow['planet_type']], 'PLANET_DEBRIS' => $planetrow['debris_metal'] + $planetrow['debris_crystal'], 'PLANET_GOVERNOR_ID' => $governor_id, 'PLANET_GOVERNOR_NAME' => $lang['tech'][$governor_id], 'PLANET_GOVERNOR_LEVEL' => $governor_level_plain, 'PLANET_GOVERNOR_LEVEL_PLUS' => mrc_get_level($user, $planetrow, $governor_id, false, false) - $governor_level_plain, 'PLANET_GOVERNOR_LEVEL_MAX' => get_unit_param($governor_id, P_MAX_STACK))); }
function sn_tpl_render_topnav(&$user, $planetrow) { if (!is_array($user)) { return ''; } global $lang, $config; $GET_mode = sys_get_param_str('mode'); $template = gettemplate('topnav', true); /* $planetrow = $planetrow ? $planetrow : $user['current_planet']; sn_db_transaction_start(); $planetrow = sys_o_get_updated($user, $planetrow, SN_TIME_NOW); sn_db_transaction_commit(); $planetrow = $planetrow['planet']; */ $ThisUsersPlanets = db_planet_list_sorted($user); // while ($CurPlanet = db_fetch($ThisUsersPlanets)) foreach ($ThisUsersPlanets as $CurPlanet) { if (!$CurPlanet['destruyed']) { $fleet_listx = flt_get_fleets_to_planet($CurPlanet); $template->assign_block_vars('topnav_planets', array('ID' => $CurPlanet['id'], 'NAME' => $CurPlanet['name'], 'PLIMAGE' => $CurPlanet['image'], 'FLEET_ENEMY' => $fleet_listx['enemy']['count'], 'COORDS' => uni_render_coordinates($CurPlanet), 'SELECTED' => $CurPlanet['id'] == $user['current_planet'] ? ' selected' : '')); } } $fleet_flying_list = tpl_get_fleets_flying($user); tpl_topnav_event_build($template, $fleet_flying_list[0]); tpl_topnav_event_build($template, $fleet_flying_list[MT_EXPLORE], 'expedition'); que_tpl_parse($template, QUE_RESEARCH, $user); $str_date_format = "%3\$02d %2\$0s %1\$04d {$lang['top_of_year']} %4\$02d:%5\$02d:%6\$02d"; $time_now_parsed = getdate(SN_TIME_NOW); $time_local_parsed = getdate(defined('SN_CLIENT_TIME_LOCAL') ? SN_CLIENT_TIME_LOCAL : SN_TIME_NOW); if ($config->game_news_overview) { nws_render($template, "WHERE UNIX_TIMESTAMP(`tsTimeStamp`) >= {$user['news_lastread']}", $config->game_news_overview); } $notes_query = doquery("SELECT * FROM {{notes}} WHERE `owner` = {$user['id']} AND `sticky` = 1 ORDER BY priority DESC, time DESC"); while ($note_row = db_fetch($notes_query)) { note_assign($template, $note_row); } $premium_lvl = mrc_get_level($user, false, UNIT_PREMIUM, true, true); $template->assign_vars(array('QUE_ID' => QUE_RESEARCH, 'QUE_HTML' => 'topnav', 'RESEARCH_ONGOING' => (bool) $user['que'], 'TIME_TEXT' => sprintf($str_date_format, $time_now_parsed['year'], $lang['months'][$time_now_parsed['mon']], $time_now_parsed['mday'], $time_now_parsed['hours'], $time_now_parsed['minutes'], $time_now_parsed['seconds']), 'TIME_TEXT_LOCAL' => sprintf($str_date_format, $time_local_parsed['year'], $lang['months'][$time_local_parsed['mon']], $time_local_parsed['mday'], $time_local_parsed['hours'], $time_local_parsed['minutes'], $time_local_parsed['seconds']), 'GAME_BLITZ_REGISTER' => $config->game_blitz_register, 'GAME_BLITZ_REGISTER_TEXT' => $lang['sys_blitz_registration_mode_list'][$config->game_blitz_register], 'BLITZ_REGISTER_OPEN' => $config->game_blitz_register == BLITZ_REGISTER_OPEN, 'BLITZ_REGISTER_CLOSED' => $config->game_blitz_register == BLITZ_REGISTER_CLOSED, 'BLITZ_REGISTER_SHOW_LOGIN' => $config->game_blitz_register == BLITZ_REGISTER_SHOW_LOGIN, 'BLITZ_REGISTER_DISCLOSURE_NAMES' => $config->game_blitz_register == BLITZ_REGISTER_DISCLOSURE_NAMES, 'GAME_BLITZ' => $config->game_mode == GAME_BLITZ, 'USERS_ONLINE' => $config->var_online_user_count, 'USERS_TOTAL' => $config->users_amount, 'USER_RANK' => $user['total_rank'], 'USER_NICK' => $user['username'], 'USER_AVATAR' => $user['avatar'], 'USER_AVATARID' => $user['id'], 'USER_PREMIUM' => $premium_lvl, 'USER_RACE' => $user['player_race'], 'TOPNAV_CURRENT_PLANET' => $user['current_planet'], 'TOPNAV_MODE' => $GET_mode, 'TOPNAV_DARK_MATTER' => mrc_get_level($user, '', RES_DARK_MATTER), 'TOPNAV_DARK_MATTER_TEXT' => pretty_number(mrc_get_level($user, '', RES_DARK_MATTER)), 'TOPNAV_METAMATTER' => mrc_get_level($user, '', RES_METAMATTER), 'TOPNAV_METAMATTER_TEXT' => pretty_number(mrc_get_level($user, '', RES_METAMATTER)), 'TOPNAV_PAYMENT' => sn_module_get_active_count('payment') && !defined('SN_GOOGLE'), 'TOPNAV_MESSAGES_ADMIN' => $user['msg_admin'], 'TOPNAV_MESSAGES_PLAYER' => $user['mnl_joueur'], 'TOPNAV_MESSAGES_ALLIANCE' => $user['mnl_alliance'], 'TOPNAV_MESSAGES_ATTACK' => $user['mnl_attaque'], 'TOPNAV_MESSAGES_ALL' => $user['new_message'], 'TOPNAV_FLEETS_FLYING' => count($fleet_flying_list[0]), 'TOPNAV_FLEETS_TOTAL' => GetMaxFleets($user), 'TOPNAV_EXPEDITIONS_FLYING' => count($fleet_flying_list[MT_EXPLORE]), 'TOPNAV_EXPEDITIONS_TOTAL' => get_player_max_expeditons($user), 'TOPNAV_QUEST_COMPLETE' => get_quest_amount_complete($user['id']), 'GAME_NEWS_OVERVIEW' => $config->game_news_overview)); if (defined('SN_RENDER_NAVBAR_PLANET') && SN_RENDER_NAVBAR_PLANET === true || $user['option_list'][OPT_INTERFACE]['opt_int_navbar_resource_force'] && SN_RENDER_NAVBAR_PLANET !== false) { tpl_set_resource_info($template, $planetrow); $template->assign_vars(array('SN_RENDER_NAVBAR_PLANET' => true, 'SN_NAVBAR_HIDE_FLEETS' => true)); } return $template; }
function sn_imperium_view($template = null) { global $user, $lang; $planets = array(); $ques = array(); $sn_group_factories = sn_get_groups('factories'); $planet_density = sn_get_groups('planet_density'); if (sys_get_param('save_production')) { $production = sys_get_param('percent'); if (is_array($production) && !empty($production)) { // sn_db_transaction_start(); $query = array(); $planet_row_list = db_planet_list_sorted($user, false, '*'); // while($planet = db_fetch($planet_row_list)) foreach ($planet_row_list as $planet) { foreach ($sn_group_factories as $factory_unit_id) { $unit_db_name_porcent = pname_factory_production_field_name($factory_unit_id); if (get_unit_param($factory_unit_id, P_MINING_IS_MANAGED) && isset($production[$factory_unit_id][$planet['id']]) && ($actual_porcent = intval($production[$factory_unit_id][$planet['id']] / 10)) >= 0 && $actual_porcent <= 10 && $actual_porcent != $planet[$unit_db_name_porcent]) { $query[$planet['id']][] = "{$unit_db_name_porcent} = {$actual_porcent}"; } } } foreach ($query as $planet_id => $query_data) { db_planet_set_by_id($planet_id, implode(',', $query_data)); } // sn_db_transaction_commit(); } } $planet_row_list = db_planet_list_sorted($user); // while ($planet = db_fetch($planet_row_list)) foreach ($planet_row_list as $planet) { sn_db_transaction_start(); $global_data = sys_o_get_updated($user, $planet['id'], SN_TIME_NOW, false, true); $planets[$planet['id']] = $global_data['planet']; // $ques[$planet['id']] = que_get($user['id'], $planet['id'], false); $ques[$planet['id']] = $global_data['que']; sn_db_transaction_commit(); } $template = gettemplate('imperium', $template); $template->assign_var('amount', count($planets) + 2); for ($i = 100; $i >= 0; $i -= 10) { $template->assign_block_vars('percent', array('PERCENT' => $i)); } $fleet_id = 1; $fleets = array(); $total['temp_min'] = 1000; $total['temp_max'] = -999; foreach ($planets as $planet_index => &$planet) { $list_planet_que = $ques[$planet_index]; $planet_template = tpl_parse_planet($planet); $planet_fleet_id = 0; $fleet_list = $planet_template['fleet_list']; //flt_get_fleets_to_planet($planet); if ($fleet_list['own']['count']) { $planet_fleet_id = "p{$fleet_id}"; $fleets[] = tpl_parse_fleet_sn($fleet_list['own']['total'], $planet_fleet_id); $fleet_id++; } $template->assign_block_vars('planet', array_merge($planet_template, array('PLANET_FLEET_ID' => $planet_fleet_id, 'METAL_CUR' => pretty_number($planet['metal'], true, $planet['caps']['total_storage'][RES_METAL]), 'METAL_PROD' => pretty_number($planet['caps']['total'][RES_METAL]), 'CRYSTAL_CUR' => pretty_number($planet['crystal'], true, $planet['caps']['total_storage'][RES_CRYSTAL]), 'CRYSTAL_PROD' => pretty_number($planet['caps']['total'][RES_CRYSTAL]), 'DEUTERIUM_CUR' => pretty_number($planet['deuterium'], true, $planet['caps']['total_storage'][RES_DEUTERIUM]), 'DEUTERIUM_PROD' => pretty_number($planet['caps']['total'][RES_DEUTERIUM]), 'ENERGY_CUR' => pretty_number($planet['caps'][RES_ENERGY][BUILD_CREATE] - $planet['caps'][RES_ENERGY][BUILD_DESTROY], true, true), 'ENERGY_MAX' => pretty_number($planet['caps'][RES_ENERGY][BUILD_CREATE]), 'TEMP_MIN' => $planet['temp_min'], 'TEMP_MAX' => $planet['temp_max'], 'DENSITY_CLASS' => $planet['density_index'], 'DENSITY_RICHNESS' => $planet_density[$planet['density_index']][UNIT_PLANET_DENSITY_RICHNESS], 'DENSITY_CLASS_TEXT' => $lang['uni_planet_density_types'][$planet['density_index']]))); $planet['fleet_list'] = $planet_template['fleet_list']; $planet['BUILDING_ID'] = $planet_template['BUILDING_ID']; $planet['hangar_que'] = $planet_template['hangar_que']; $planet['full_que'] = $list_planet_que; $total['fields'] += $planet['field_current']; $total['metal'] += $planet['metal']; $total['crystal'] += $planet['crystal']; $total['deuterium'] += $planet['deuterium']; $total['energy'] += $planet['energy_max'] - $planet['energy_used']; $total['fields_max'] += eco_planet_fields_max($planet); $total['metal_perhour'] += $planet['caps']['total'][RES_METAL]; $total['crystal_perhour'] += $planet['caps']['total'][RES_CRYSTAL]; $total['deuterium_perhour'] += $planet['caps']['total'][RES_DEUTERIUM]; $total['energy_max'] += $planet['caps'][RES_ENERGY][BUILD_CREATE]; $total['temp_min'] = min($planet['temp_min'], $total['temp_min']); $total['temp_max'] = max($planet['temp_max'], $total['temp_max']); } tpl_assign_fleet($template, $fleets); unset($planet); $show_groups = array(UNIT_STRUCTURES => 'structures', UNIT_STRUCTURES_SPECIAL => 'structures', UNIT_SHIPS => 'fleet', UNIT_DEFENCE => 'defense'); foreach ($show_groups as $unit_group_id => $mode) { $template->assign_block_vars('prods', array('NAME' => $lang['tech'][$unit_group_id])); $unit_group = get_unit_param('techtree', $unit_group_id); foreach ($unit_group as $unit_id) { $unit_count = $unit_count_abs = 0; $block_vars = array(); $unit_is_factory = in_array($unit_id, $sn_group_factories) && get_unit_param($unit_id, P_MINING_IS_MANAGED); // $unit_db_name = pname_resource_name($unit_id); foreach ($planets as $planet) { $unit_level_plain = mrc_get_level($user, $planet, $unit_id, false, true); $level_plus['FACTORY'] = $unit_is_factory; $level_plus['LEVEL_PLUS_YELLOW'] = 0; $level_plus['LEVEL_PLUS_GREEN'] = 0; $level_plus['PERCENT'] = $unit_is_factory ? $unit_level_plain ? $planet[pname_factory_production_field_name($unit_id)] * 10 : -1 : -1; switch ($mode) { /* case 'structures': $level_plus_build = $ques[$planet['id']]['in_que'][que_get_unit_que($unit_id)][$user['id']][$planet['id']][$unit_id]; if($level_plus_build) { $level_plus['LEVEL_PLUS_GREEN'] = $level_plus_build < 0 ? $level_plus_build : "+{$level_plus_build}"; $total['units'][$unit_id]['LEVEL_PLUS_GREEN'] += $level_plus['LEVEL_PLUS_GREEN']; } break; */ /** @noinspection PhpMissingBreakStatementInspection */ case 'fleet': $level_plus['LEVEL_PLUS_YELLOW'] = $planet['fleet_list']['own']['total'][$unit_id] <= 0 ? $planet['fleet_list']['own']['total'][$unit_id] : "+{$planet['fleet_list']['own']['total'][$unit_id]}"; $total['units'][$unit_id]['LEVEL_PLUS_YELLOW'] += $level_plus['LEVEL_PLUS_YELLOW']; case 'structures': case 'defense': $level_plus_build = $ques[$planet['id']]['in_que'][que_get_unit_que($unit_id)][$user['id']][$planet['id']][$unit_id]; if ($level_plus_build) { $level_plus['LEVEL_PLUS_GREEN'] = $level_plus_build < 0 ? $level_plus_build : "+{$level_plus_build}"; // $level_plus['LEVEL_PLUS_GREEN'] = "+{$level_plus_build}"; $total['units'][$unit_id]['LEVEL_PLUS_GREEN'] += $level_plus['LEVEL_PLUS_GREEN']; } break; default: break; } $block_vars[] = array_merge($level_plus, array('ID' => $planet['id'], 'TYPE' => $planet['planet_type'], 'LEVEL' => $unit_level_plain == 0 && !$level_plus['LEVEL_PLUS_YELLOW'] && !$level_plus['LEVEL_PLUS_GREEN'] ? '-' : $unit_level_plain)); $unit_count += $unit_level_plain; $unit_count_abs += $unit_level_plain + abs($level_plus['LEVEL_PLUS_YELLOW']) + abs($level_plus['LEVEL_PLUS_GREEN']); } if ($unit_count_abs) { $template->assign_block_vars('prods', array('ID' => $unit_id, 'FIELD' => 'unit_' . $unit_id, 'NAME' => $lang['tech'][$unit_id], 'MODE' => $mode)); foreach ($block_vars as $block_var) { $template->assign_block_vars('prods.planet', $block_var); } $unit_green = $total['units'][$unit_id]['LEVEL_PLUS_GREEN']; $unit_yellow = $total['units'][$unit_id]['LEVEL_PLUS_YELLOW']; $template->assign_block_vars('prods.planet', array('ID' => 0, 'LEVEL' => $unit_count, 'LEVEL_PLUS_GREEN' => $unit_green == 0 ? '' : ($unit_green > 0 ? "+{$unit_green}" : $unit_green), 'LEVEL_PLUS_YELLOW' => $unit_yellow == 0 ? '' : ($unit_yellow > 0 ? "+{$unit_yellow}" : $unit_yellow), 'PERCENT' => $unit_is_factory ? '' : -1, 'FACTORY' => $unit_is_factory)); } } } $template->assign_block_vars('planet', array_merge(array('ID' => 0, 'NAME' => $lang['sys_total'], 'FIELDS_CUR' => $total['fields'], 'FIELDS_MAX' => $total['fields_max'], 'METAL_CUR' => pretty_number($total['metal']), 'METAL_PROD' => pretty_number($total['metal_perhour']), 'CRYSTAL_CUR' => pretty_number($total['crystal']), 'CRYSTAL_PROD' => pretty_number($total['crystal_perhour']), 'DEUTERIUM_CUR' => pretty_number($total['deuterium']), 'DEUTERIUM_PROD' => pretty_number($total['deuterium_perhour']), 'ENERGY_CUR' => pretty_number($total['energy']), 'ENERGY_MAX' => pretty_number($total['energy_max']), 'TEMP_MIN' => $total['temp_min'], 'TEMP_MAX' => $total['temp_max']))); $template->assign_vars(array('COLONIES_CURRENT' => get_player_current_colonies($user), 'COLONIES_MAX' => get_player_max_colonies($user), 'EXPEDITIONS_CURRENT' => get_player_current_expeditions($user), 'EXPEDITIONS_MAX' => get_player_max_expeditons($user), 'PLANET_DENSITY_RICHNESS_NORMAL' => PLANET_DENSITY_RICHNESS_NORMAL, 'PLANET_DENSITY_RICHNESS_AVERAGE' => PLANET_DENSITY_RICHNESS_AVERAGE, 'PLANET_DENSITY_RICHNESS_GOOD' => PLANET_DENSITY_RICHNESS_GOOD, 'PLANET_DENSITY_RICHNESS_PERFECT' => PLANET_DENSITY_RICHNESS_PERFECT)); //$template->assign_recursive($template_result); return $template; }
function eco_get_planet_caps(&$user, &$planet_row, $production_time = 0) { // TODO Считать $production_time для термоядерной электростанции global $config; static $sn_group_modifiers, $config_resource_multiplier, $config_eco_scale_storage; if (!$sn_group_modifiers) { $sn_group_modifiers = sn_get_groups('modifiers'); // $config_resource_multiplier = $config->resource_multiplier; $config_resource_multiplier = game_resource_multiplier(); $config_eco_scale_storage = $config->eco_scale_storage ? $config_resource_multiplier : 1; } $caps = array(); foreach (sn_get_groups('storages') as $unit_id) { foreach (get_unit_param($unit_id, P_STORAGE) as $resource_id => $function) { $caps['storage'][$resource_id][$unit_id] = floor($config_eco_scale_storage * mrc_modify_value($user, $planet_row, $sn_group_modifiers[MODIFIER_RESOURCE_CAPACITY], $function(mrc_get_level($user, $planet_row, $unit_id)))); } } if ($planet_row['planet_type'] == PT_MOON) { return $caps; } $sn_group_planet_density = sn_get_groups('planet_density'); $planet_density = $sn_group_planet_density[$planet_row['density_index']][UNIT_RESOURCES]; $caps['production_full'][RES_METAL][0] = floor($config->metal_basic_income * $config_resource_multiplier * (isset($planet_density[RES_METAL]) ? $planet_density[RES_METAL] : 1)); $caps['production_full'][RES_CRYSTAL][0] = floor($config->crystal_basic_income * $config_resource_multiplier * (isset($planet_density[RES_CRYSTAL]) ? $planet_density[RES_CRYSTAL] : 1)); $caps['production_full'][RES_DEUTERIUM][0] = floor($config->deuterium_basic_income * $config_resource_multiplier * (isset($planet_density[RES_DEUTERIUM]) ? $planet_density[RES_DEUTERIUM] : 1)); $caps['production_full'][RES_ENERGY][0] = floor($config->energy_basic_income * $config_resource_multiplier * (isset($planet_density[RES_ENERGY]) ? $planet_density[RES_ENERGY] : 1)); foreach (sn_get_groups('factories') as $unit_id) { $unit_data = get_unit_param($unit_id); $unit_level = mrc_get_level($user, $planet_row, $unit_id); $unit_load = $planet_row[pname_factory_production_field_name($unit_id)]; foreach ($unit_data['production'] as $resource_id => $function) { $caps['production_full'][$resource_id][$unit_id] = $function($unit_level, $unit_load, $user, $planet_row) * $config_resource_multiplier * (isset($planet_density[$resource_id]) ? $planet_density[$resource_id] : 1); } } array_walk_recursive($caps['production_full'], 'eco_get_planet_caps_modify_production', array('user' => $user, 'planet' => $planet_row)); foreach ($caps['production_full'] as $resource_id => $resource_data) { $caps['total_production_full'][$resource_id] = array_sum($resource_data); } $caps['production'] = $caps['production_full']; if ($caps['production'][RES_ENERGY][STRUC_MINE_FUSION]) { $deuterium_balance = array_sum($caps['production'][RES_DEUTERIUM]); $energy_balance = array_sum($caps['production'][RES_ENERGY]); if ($deuterium_balance < 0 || $energy_balance < 0) { $caps['production'][RES_DEUTERIUM][STRUC_MINE_FUSION] = $caps['production'][RES_ENERGY][STRUC_MINE_FUSION] = 0; } } foreach ($caps['production'][RES_ENERGY] as $energy) { $caps[RES_ENERGY][$energy >= 0 ? BUILD_CREATE : BUILD_DESTROY] += $energy; } $caps[RES_ENERGY][BUILD_DESTROY] = -$caps[RES_ENERGY][BUILD_DESTROY]; $caps['efficiency'] = $caps[RES_ENERGY][BUILD_DESTROY] > $caps[RES_ENERGY][BUILD_CREATE] ? $caps[RES_ENERGY][BUILD_CREATE] / $caps[RES_ENERGY][BUILD_DESTROY] : 1; foreach ($caps['production'] as $resource_id => &$resource_data) { if ($caps['efficiency'] != 1) { foreach ($resource_data as $unit_id => &$resource_production) { if (!($unit_id == STRUC_MINE_FUSION && $resource_id == RES_DEUTERIUM) && $unit_id != 0 && !($resource_id == RES_ENERGY && $resource_production >= 0)) { $resource_production = $resource_production * $caps['efficiency']; } } } $caps['total'][$resource_id] = array_sum($resource_data); $caps['total'][$resource_id] = $caps['total'][$resource_id] >= 0 ? floor($caps['total'][$resource_id]) : ceil($caps['total'][$resource_id]); } foreach ($caps['storage'] as $resource_id => &$resource_data) { $caps['total_storage'][$resource_id] = array_sum($resource_data); } $planet_row['caps'] = $caps; $planet_row['metal_max'] = $caps['total_storage'][RES_METAL]; $planet_row['crystal_max'] = $caps['total_storage'][RES_CRYSTAL]; $planet_row['deuterium_max'] = $caps['total_storage'][RES_DEUTERIUM]; $planet_row['energy_max'] = $caps[RES_ENERGY][BUILD_CREATE]; $planet_row['energy_used'] = $caps[RES_ENERGY][BUILD_DESTROY]; return $caps; }
} if (sys_get_param_str('reload')) { $combat_data = sn_ube_report_load($combat_data[UBE_REPORT_CYPHER]); } //debug($combat_data); // Рендерим их в темплейт sn_ube_report_generate($combat_data, $template_result); $template_result['MICROTIME'] = $combat_data[UBE_TIME_SPENT]; $template = gettemplate('ube_combat_report', true); $template->assign_recursive($template_result); display($template, '', false, '', false, false, true); } else { $template = gettemplate('simulator', true); $techs_and_officers = array(TECH_WEAPON, TECH_SHIELD, TECH_ARMOR, MRC_ADMIRAL); foreach ($techs_and_officers as $tech_id) { if (!$sym_attacker[1][$tech_id]) { $sym_attacker[1][$tech_id] = mrc_get_level($user, false, $tech_id); } } $show_groups = array(UNIT_TECHNOLOGIES => array(TECH_WEAPON, TECH_SHIELD, TECH_ARMOR), UNIT_MERCENARIES => array(MRC_ADMIRAL), UNIT_SHIPS => sn_get_groups('fleet'), UNIT_RESOURCES => sn_get_groups('resources_loot'), UNIT_GOVERNORS => array(MRC_FORTIFIER), UNIT_DEFENCE => sn_get_groups('defense_active')); foreach ($show_groups as $unit_group_id => $unit_group) { $template->assign_block_vars('simulator', array('GROUP' => $unit_group_id, 'NAME' => $lang['tech'][$unit_group_id])); foreach ($unit_group as $unit_id) { $tab++; $value = mrc_get_level($user, $planetrow, $unit_id); $template->assign_block_vars('simulator', array('NUM' => $tab < 9 ? "0{$tab}" : $tab, 'ID' => $unit_id, 'GROUP' => $unit_group_id, 'NAME' => $lang['tech'][$unit_id], 'ATTACKER' => intval($sym_attacker[1][$unit_id]), 'DEFENDER' => intval($sym_defender[0][$unit_id]), 'VALUE' => $value)); } } $template->assign_vars(array('BE_DEBUG' => BE_DEBUG, 'UNIT_DEFENCE' => UNIT_DEFENCE, 'UNIT_GOVERNORS' => UNIT_GOVERNORS)); display($template, $lang['coe_combatSimulator'], false); }
function killer_add_planet($planet) { global $final_cost; $final_cost = array(); $sn_group_resources_loot = sn_get_groups('resources_loot'); /* foreach($sn_group_resources_loot as &$value) { $value = get_unit_param($value, P_NAME); } */ foreach (sn_get_groups('structures') as $unit_id) { $build_level = mrc_get_level($user, $planet, $unit_id, true, true); if ($build_level > 0) { $unit_cost = get_unit_param($unit_id, 'cost'); $build_factor = $unit_cost['factor'] != 1 ? (1 - pow($unit_cost['factor'], $build_level)) / (1 - $unit_cost['factor']) : $unit_cost['factor']; foreach ($sn_group_resources_loot as $resource_id) { $final_cost[$resource_id] += isset($unit_cost[$resource_id]) && $unit_cost[$resource_id] > 0 ? floor($unit_cost[$resource_id] * $build_factor) : 0; } } } foreach (sn_get_groups(array('defense', 'fleet')) as $unit_id) { $unit_count = mrc_get_level($user, $planet, $unit_id, true, true); if ($unit_count > 0) { $unit_cost = get_unit_param($unit_id, 'cost'); foreach ($sn_group_resources_loot as $resource_id) { $final_cost[$resource_id] += isset($unit_cost[$resource_id]) && $unit_cost[$resource_id] > 0 ? floor($unit_cost[$resource_id] * $unit_count) : 0; } } } foreach ($sn_group_resources_loot as $resource_id) { $final_cost[$resource_id] += floor(mrc_get_level($user, $planet, $resource_id, true, true)); } }
<?php !defined('INSIDE') ? die('Hack attempt!') : false; $sn_data += array(STRUC_MINE_METAL => array('name' => 'metal_mine', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'cost' => array(RES_METAL => 80, RES_CRYSTAL => 20, RES_DEUTERIUM => 0, RES_ENERGY => 0, 'factor' => 1.5), P_UNIT_PRODUCTION => array(RES_METAL => function ($level, $production_factor, $user, $planet_row) { return 40 * $level * pow(1.1, $level) * (0.1 * $production_factor); }, RES_ENERGY => function ($level, $production_factor, $user, $planet_row) { return -13 * $level * pow(1.1, $level) * (0.1 * $production_factor); }), P_MINING_IS_MANAGED => true), STRUC_MINE_CRYSTAL => array('name' => 'crystal_mine', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'cost' => array(RES_METAL => 48, RES_CRYSTAL => 24, RES_DEUTERIUM => 0, RES_ENERGY => 0, 'factor' => 1.6), P_UNIT_PRODUCTION => array(RES_CRYSTAL => function ($level, $production_factor, $user, $planet_row) { return 32 * $level * pow(1.1, $level) * (0.1 * $production_factor); }, RES_ENERGY => function ($level, $production_factor, $user, $planet_row) { return -16 * $level * pow(1.1, $level) * (0.1 * $production_factor); }), P_MINING_IS_MANAGED => true), STRUC_MINE_DEUTERIUM => array('name' => 'deuterium_sintetizer', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'cost' => array(RES_METAL => 225, RES_CRYSTAL => 75, RES_DEUTERIUM => 0, RES_ENERGY => 0, 'factor' => 1.5), P_UNIT_PRODUCTION => array(RES_DEUTERIUM => function ($level, $production_factor, $user, $planet_row) { return 10 * $level * pow(1.1, $level) * (0.1 * $production_factor) * (-0.002 * $planet_row["temp_max"] + 1.28); }, RES_ENERGY => function ($level, $production_factor, $user, $planet_row) { return -20 * $level * pow(1.1, $level) * (0.1 * $production_factor); }), P_MINING_IS_MANAGED => true), STRUC_MINE_SOLAR => array('name' => 'solar_plant', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'cost' => array(RES_METAL => 75, RES_CRYSTAL => 30, RES_DEUTERIUM => 0, RES_ENERGY => 0, 'factor' => 1.5), P_UNIT_PRODUCTION => array(RES_ENERGY => function ($level, $production_factor, $user, $planet_row) { return ($planet_row["temp_max"] / 5 + 15) * $level * pow(1.1, $level) * (0.1 * $production_factor); }), P_MINING_IS_MANAGED => true), STRUC_MINE_FUSION => array('name' => 'fusion_plant', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'require' => array(3 => 5, TECH_ENERGY => 3, UNIT_PLAN_STRUC_MINE_FUSION => 1), 'cost' => array(RES_METAL => 900, RES_CRYSTAL => 360, RES_DEUTERIUM => 180, RES_ENERGY => 0, 'factor' => 1.8), P_UNIT_PRODUCTION => array(RES_DEUTERIUM => function ($level, $production_factor, $user, $planet_row) { return -10 * $level * pow(1.1, $level) * (0.1 * $production_factor); }, RES_ENERGY => function ($level, $production_factor, $user, $planet_row) { return 30 * $level * pow(1.05 + 0.01 * mrc_get_level($user, "", TECH_ENERGY), $level) * (0.1 * $production_factor); }), P_MINING_IS_MANAGED => true), STRUC_STORE_METAL => array('name' => 'metal_store', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'cost' => array(RES_METAL => 2000, RES_CRYSTAL => 0, RES_DEUTERIUM => 0, RES_ENERGY => 0, 'factor' => 2), 'storage' => array(RES_METAL => function ($level) { return BASE_STORAGE_SIZE * pow(1.5, $level); })), STRUC_STORE_CRYSTAL => array('name' => 'crystal_store', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'cost' => array(RES_METAL => 2000, RES_CRYSTAL => 1000, RES_DEUTERIUM => 0, RES_ENERGY => 0, 'factor' => 2), 'storage' => array(RES_CRYSTAL => function ($level) { return BASE_STORAGE_SIZE * pow(1.5, $level); })), STRUC_STORE_DEUTERIUM => array('name' => 'deuterium_store', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'cost' => array(RES_METAL => 2000, RES_CRYSTAL => 2000, RES_DEUTERIUM => 0, RES_ENERGY => 0, 'factor' => 2), 'storage' => array(RES_DEUTERIUM => function ($level) { return BASE_STORAGE_SIZE * pow(1.5, $level); })), STRUC_FACTORY_ROBOT => array('name' => 'robot_factory', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'cost' => array(RES_METAL => 400, RES_CRYSTAL => 120, RES_DEUTERIUM => 200, RES_ENERGY => 0, 'factor' => 2)), STRUC_FACTORY_NANO => array('name' => 'nano_factory', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'require' => array(STRUC_FACTORY_ROBOT => 10, TECH_COMPUTER => 10), 'cost' => array(RES_METAL => 1000000, RES_CRYSTAL => 500000, RES_DEUTERIUM => 100000, RES_ENERGY => 0, 'factor' => 2)), STRUC_FACTORY_HANGAR => array('name' => 'hangar', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'require' => array(STRUC_FACTORY_ROBOT => 2), 'cost' => array(RES_METAL => 400, RES_CRYSTAL => 200, RES_DEUTERIUM => 100, RES_ENERGY => 0, 'factor' => 2)), STRUC_LABORATORY => array('name' => 'laboratory', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'cost' => array(RES_METAL => 200, RES_CRYSTAL => 400, RES_DEUTERIUM => 200, RES_ENERGY => 0, 'factor' => 2)), STRUC_TERRAFORMER => array('name' => 'terraformer', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'require' => array(STRUC_FACTORY_NANO => 1, TECH_ENERGY => 12), 'cost' => array(RES_METAL => 0, RES_CRYSTAL => 50000, RES_DEUTERIUM => 100000, RES_ENERGY => 0, 'factor' => 2)), STRUC_ALLY_DEPOSIT => array('name' => 'ally_deposit', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'cost' => array(RES_METAL => 20000, RES_CRYSTAL => 40000, RES_DEUTERIUM => 0, RES_ENERGY => 0, 'factor' => 2)), STRUC_LABORATORY_NANO => array('name' => 'nano', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'require' => array(STRUC_LABORATORY => 10, TECH_ENERGY => 10), 'cost' => array(RES_METAL => 1500000, RES_CRYSTAL => 750000, RES_DEUTERIUM => 150000, RES_ENERGY => 0, 'factor' => 2)), STRUC_MOON_STATION => array('name' => 'mondbasis', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'cost' => array(RES_METAL => 20000, RES_CRYSTAL => 40000, RES_DEUTERIUM => 20000, RES_ENERGY => 0, 'factor' => 2)), STRUC_MOON_PHALANX => array('name' => 'phalanx', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'require' => array(STRUC_MOON_STATION => 1), 'cost' => array(RES_METAL => 20000, RES_CRYSTAL => 40000, RES_DEUTERIUM => 20000, RES_ENERGY => 0, 'factor' => 2)), STRUC_MOON_GATE => array('name' => 'sprungtor', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'require' => array(STRUC_MOON_STATION => 1, TECH_HYPERSPACE => 7), 'cost' => array(RES_METAL => 2000000, RES_CRYSTAL => 4000000, RES_DEUTERIUM => 2000000, RES_ENERGY => 0, 'factor' => 2)), STRUC_SILO => array('name' => 'silo', 'type' => UNIT_STRUCTURES, 'location' => LOC_PLANET, 'require' => array(TECH_ENGINE_ION => 1), 'cost' => array(RES_METAL => 20000, RES_CRYSTAL => 20000, RES_DEUTERIUM => 1000, RES_ENERGY => 0, 'factor' => 2), 'capacity' => 12));
} } } } // Поддержка передачи данных для многошаговых платежных систем if (is_array($pay_link['DATA'])) { foreach ($pay_link['DATA'] as $key => $value) { $template->assign_block_vars('pay_link_data', array('FIELD' => $key, 'VALUE' => $value)); } } if (is_array($pay_link) && in_array($pay_link['PAY_LINK_METHOD'], array('POST', 'GET', 'LINK', 'STEP'))) { // TODO Переделать это под assign_vars_recursive и возвращать пустые строки если нет платежного метода - для унификации формы в темплейте $template->assign_vars(array('PAY_LINK_METHOD' => $pay_link['PAY_LINK_METHOD'], 'PAY_LINK_URL' => $pay_link['PAY_LINK_URL'])); } else { throw new exception($lang['pay_msg_request_paylink_unsupported'], ERR_ERROR); } } catch (exception $e) { $template->assign_block_vars('result', $response = array('STATUS' => $e->getCode(), 'MESSAGE' => $e->getMessage())); $debug->warning('Результат операции: код ' . $e->getCode() . ' сообщение "' . $e->getMessage() . '"', 'Ошибка платежа', LOG_INFO_PAYMENT); } } // Прегенерированные пакеты foreach ($unit_available_amount_list as $unit_amount => $discount) { $temp = sn_module_payment::currency_convert($unit_amount, 'MM_', $player_currency); $template->assign_block_vars('mm_amount', array('VALUE' => $unit_amount, 'PRICE_TEXT' => pretty_number($temp, 2), 'CURRENCY' => $player_currency, 'DISCOUNT' => $discount, 'DISCOUNT_PERCENT' => $discount * 100, 'DISCOUNTED' => $unit_amount * (1 + $discount), 'TEXT' => pretty_number($unit_amount), 'TEXT_DISCOUNTED' => pretty_number($unit_amount * (1 + $discount)))); } $currency = $payment_module ? sn_module_payment::$payment_methods[$payment_type_selected][$payment_method_selected]['currency'] : ''; $bonus_percent = round(sn_module_payment::bonus_calculate($request['metamatter'], true, true) * 100); $income_metamatter_text = pretty_number(sn_module_payment::bonus_calculate($request['metamatter']), true, true); $template->assign_vars(array('PAGE_HEADER' => $lang['sys_metamatter'], 'URL_PURCHASE' => $config->url_purchase_metamatter, 'PAYMENT_TYPE' => $payment_type_selected, 'PAYMENT_METHOD' => $payment_method_selected, 'PAYMENT_METHOD_NAME' => $lang['pay_methods'][$payment_method_selected], 'PAYMENT_MODULE' => $payment_module, 'PAYMENT_MODULE_NAME' => $lang["module_{$payment_module}_name"], 'PAYMENT_MODULE_DESCRIPTION' => $lang["module_{$payment_module}_description"], 'PLAYER_CURRENCY' => $player_currency, 'PLAYER_CURRENCY_PRICE_PER_MM' => sn_module_payment::currency_convert(1, $player_currency, 'MM_', 10), 'UNIT_AMOUNT' => (double) $request['metamatter'], 'UNIT_AMOUNT_TEXT' => pretty_number($request['metamatter']), 'UNIT_AMOUNT_BONUS_PERCENT' => $bonus_percent, 'UNIT_AMOUNT_TEXT_DISCOUNTED' => $income_metamatter_text, 'UNIT_AMOUNT_TEXT_COST_BASE' => pretty_number(sn_module_payment::currency_convert($request['metamatter'], 'MM_', $player_currency), 2), 'PAYMENT_CURRENCY_EXCHANGE_DEFAULT' => pretty_number(get_mm_cost(), true, true), 'PAYMENT_CURRENCY_DEFAULT_TEXT' => $lang['pay_currency_list'][$config->payment_currency_default], 'METAMATTER' => mrc_get_level($user, '', RES_METAMATTER), 'METAMATTER_COST_TEXT' => sprintf($lang['pay_mm_buy_conversion_cost'], pretty_number($request['metamatter'], true, true), pretty_number(sn_module_payment::currency_convert($request['metamatter'], 'MM_', $currency), 2, true), $currency), 'METAMATTER_COST_BONUS_TEXT' => $bonus_percent ? sprintf($lang['pay_mm_buy_real_income'], pretty_number($bonus_percent, true, true), $income_metamatter_text) : '', 'DARK_MATTER_DESCRIPTION' => $lang['info'][RES_DARK_MATTER]['description'], 'PAYMENT_AVAILABLE' => sn_module_get_active_count('payment') && !defined('SN_GOOGLE'))); display($template, $lang['sys_metamatter']);
function ShowProductionTable($CurrentUser, $CurrentPlanet, $BuildID, $Template) { $config_resource_multiplier = game_resource_multiplier(); $config_resource_multiplier_plain = game_resource_multiplier(true); $CurrentBuildtLvl = mrc_get_level($CurrentUser, $CurrentPlanet, $BuildID); $BuildLevel = $CurrentBuildtLvl > 0 ? $CurrentBuildtLvl : 1; $modifiers = sn_get_groups('modifiers'); $Prod[STRUC_MINE_METAL] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, $modifiers[MODIFIER_RESOURCE_PRODUCTION], $config_resource_multiplier * $unit_data[P_UNIT_PRODUCTION][RES_METAL]($BuildLevel, 100, $CurrentUser, $CurrentPlanet))); $Prod[STRUC_MINE_CRYSTAL] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, $modifiers[MODIFIER_RESOURCE_PRODUCTION], $config_resource_multiplier * $unit_data[P_UNIT_PRODUCTION][RES_CRYSTAL]($BuildLevel, 100, $CurrentUser, $CurrentPlanet))); $Prod[STRUC_MINE_DEUTERIUM] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, $modifiers[MODIFIER_RESOURCE_PRODUCTION], $config_resource_multiplier * $unit_data[P_UNIT_PRODUCTION][RES_DEUTERIUM]($BuildLevel, 100, $CurrentUser, $CurrentPlanet))); $Prod[STRUC_MINE_SOLAR] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, $modifiers[MODIFIER_RESOURCE_PRODUCTION], $config_resource_multiplier_plain * $unit_data[P_UNIT_PRODUCTION][RES_ENERGY]($BuildLevel, 100, $CurrentUser, $CurrentPlanet))); $ActualProd = floor($Prod[$BuildID]); if ($BuildID != STRUC_MINE_FUSION) { $ActualNeed = floor($Prod[STRUC_MINE_SOLAR]); } else { $ActualNeed = floor($Prod[STRUC_MINE_DEUTERIUM]); } $BuildStartLvl = $CurrentBuildtLvl - 2; if ($BuildStartLvl < 1) { $BuildStartLvl = 1; } $Table = ''; $ProdFirst = 0; for ($BuildLevel = $BuildStartLvl; $BuildLevel < $BuildStartLvl + 10; $BuildLevel++) { if ($BuildID != STRUC_MOON_PHALANX) { $Prod[STRUC_MINE_METAL] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, $modifiers[MODIFIER_RESOURCE_PRODUCTION], $config_resource_multiplier * $unit_data[P_UNIT_PRODUCTION][RES_METAL]($BuildLevel, 100, $CurrentUser, $CurrentPlanet))); $Prod[STRUC_MINE_CRYSTAL] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, $modifiers[MODIFIER_RESOURCE_PRODUCTION], $config_resource_multiplier * $unit_data[P_UNIT_PRODUCTION][RES_CRYSTAL]($BuildLevel, 100, $CurrentUser, $CurrentPlanet))); $Prod[STRUC_MINE_DEUTERIUM] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, $modifiers[MODIFIER_RESOURCE_PRODUCTION], $config_resource_multiplier * $unit_data[P_UNIT_PRODUCTION][RES_DEUTERIUM]($BuildLevel, 100, $CurrentUser, $CurrentPlanet))); $Prod[STRUC_MINE_SOLAR] = floor(mrc_modify_value($CurrentUser, $CurrentPlanet, $modifiers[MODIFIER_RESOURCE_PRODUCTION], $config_resource_multiplier_plain * $unit_data[P_UNIT_PRODUCTION][RES_ENERGY]($BuildLevel, 100, $CurrentUser, $CurrentPlanet))); $bloc['build_lvl'] = $CurrentBuildtLvl == $BuildLevel ? "<font color=\"#ff0000\">" . $BuildLevel . "</font>" : $BuildLevel; if ($ProdFirst > 0) { if ($BuildID != STRUC_MINE_FUSION) { $bloc['build_gain'] = "<font color=\"lime\">(" . pretty_number(floor($Prod[$BuildID] - $ProdFirst)) . ")</font>"; } else { $bloc['build_gain'] = "<font color=\"lime\">(" . pretty_number(floor($Prod[STRUC_MINE_SOLAR] - $ProdFirst)) . ")</font>"; } } else { $bloc['build_gain'] = ''; } if ($BuildID != STRUC_MINE_FUSION) { $bloc['build_prod'] = pretty_number(floor($Prod[$BuildID])); $bloc['build_prod_diff'] = pretty_number(floor($Prod[$BuildID] - $ActualProd), true, true); $bloc['build_need'] = pretty_number(floor($Prod[STRUC_MINE_SOLAR]), true, true); $bloc['build_need_diff'] = pretty_number(floor($Prod[STRUC_MINE_SOLAR] - $ActualNeed), true, true); } else { $bloc['build_prod'] = pretty_number(floor($Prod[STRUC_MINE_SOLAR])); $bloc['build_prod_diff'] = pretty_number(floor($Prod[STRUC_MINE_SOLAR] - $ActualProd), true, true); $bloc['build_need'] = pretty_number(floor($Prod[STRUC_MINE_DEUTERIUM]), true, true); $bloc['build_need_diff'] = pretty_number(floor($Prod[STRUC_MINE_DEUTERIUM] - $ActualNeed), true, true); } if ($ProdFirst == 0) { if ($BuildID != STRUC_MINE_FUSION) { $ProdFirst = floor($Prod[$BuildID]); } else { $ProdFirst = floor($Prod[STRUC_MINE_SOLAR]); } } } else { // Cas particulier de la phalange $bloc['build_lvl'] = $CurrentBuildtLvl == $BuildLevel ? "<font color=\"#ff0000\">" . $BuildLevel . "</font>" : $BuildLevel; $bloc['build_range'] = $BuildLevel * $BuildLevel - 1; } $Table .= parsetemplate($Template, $bloc); } return $Table; }
$sn_group_ques = sn_get_groups('ques'); foreach (array(QUE_STRUCTURES => $sn_group_ques[QUE_STRUCTURES]) as $que_id => $que_type_data) { $this_que = $que['ques'][$que_id][$user['id']][$planetrow['id']]; $template->assign_block_vars('ques', array('ID' => $que_id, 'NAME' => $lang['sys_ques'][$que_id], 'LENGTH' => empty($this_que) ? 0 : count($this_que))); if (!empty($this_que)) { foreach ($this_que as $que_item) { $template->assign_block_vars('que', que_tpl_parse_element($que_item)); } } } $que_hangar_length = tpl_assign_hangar($template, $planetrow, SUBQUE_FLEET); $template->assign_block_vars('ques', array('ID' => QUE_HANGAR, 'NAME' => $lang['sys_ques'][QUE_HANGAR], 'LENGTH' => $que_hangar_length)); $que_hangar_length = tpl_assign_hangar($template, $planetrow, SUBQUE_DEFENSE); $template->assign_block_vars('ques', array('ID' => SUBQUE_DEFENSE, 'NAME' => $lang['sys_ques'][SUBQUE_DEFENSE], 'LENGTH' => $que_hangar_length)); $overview_planet_rows = $user['opt_int_overview_planet_rows']; $overview_planet_columns = $user['opt_int_overview_planet_columns']; if ($overview_planet_rows <= 0 && $overview_planet_columns <= 0) { $overview_planet_rows = $user_option_list[OPT_INTERFACE]['opt_int_overview_planet_rows']; $overview_planet_columns = $user_option_list[OPT_INTERFACE]['opt_int_overview_planet_columns']; } if ($overview_planet_rows > 0 && $overview_planet_columns <= 0) { $overview_planet_columns = ceil($planet_count / $overview_planet_rows); } $sector_cost = eco_get_build_data($user, $planetrow, UNIT_SECTOR, mrc_get_level($user, $planetrow, UNIT_SECTOR), true); $sector_cost = $sector_cost[BUILD_CREATE][RES_DARK_MATTER]; $governor_level = $planetrow['PLANET_GOVERNOR_ID'] ? mrc_get_level($user, $planetrow, $planetrow['PLANET_GOVERNOR_ID'], false, true) : 0; $template->assign_vars(array('TIME_NOW' => SN_TIME_NOW, 'USER_ID' => $user['id'], 'user_username' => $user['username'], 'USER_AUTHLEVEL' => $user['authlevel'], 'NEW_MESSAGES' => $user['new_message'], 'NEW_LEVEL_MINER' => $level_miner, 'NEW_LEVEL_RAID' => $level_raid, 'planet_diameter' => pretty_number($planetrow['diameter']), 'planet_field_current' => $planetrow['field_current'], 'planet_field_max' => eco_planet_fields_max($planetrow), 'PLANET_FILL' => floor($planetrow['field_current'] / eco_planet_fields_max($planetrow) * 100), 'PLANET_FILL_BAR' => $planet_fill, 'metal_debris' => pretty_number($planetrow['debris_metal']), 'crystal_debris' => pretty_number($planetrow['debris_crystal']), 'PLANET_RECYCLERS' => $planet_recyclers_orbiting, 'planet_image' => $planetrow['image'], 'planet_temp_min' => $planetrow['temp_min'], 'planet_temp_avg' => round(($planetrow['temp_min'] + $planetrow['temp_max']) / 2), 'planet_temp_max' => $planetrow['temp_max'], 'planet_density' => $planetrow['density'], 'planet_density_index' => $planetrow['density_index'], 'planet_density_text' => $lang['uni_planet_density_types'][$planetrow['density_index']], 'GATE_LEVEL' => mrc_get_level($user, $planetrow, STRUC_MOON_GATE), 'GATE_JUMP_REST_TIME' => uni_get_time_to_jump($planetrow), 'ADMIN_EMAIL' => $config->game_adminEmail, 'PLANET_GOVERNOR_ID' => $planetrow['PLANET_GOVERNOR_ID'], 'PLANET_GOVERNOR_LEVEL' => $governor_level, 'PLANET_GOVERNOR_LEVEL_PLUS' => $governor_level ? mrc_get_level($user, $planetrow, $planetrow['PLANET_GOVERNOR_ID']) - $governor_level : 0, 'PLANET_GOVERNOR_NAME' => $lang['tech'][$planetrow['PLANET_GOVERNOR_ID']], 'LIST_ROW_COUNT' => $overview_planet_rows, 'LIST_COLUMN_COUNT' => $overview_planet_columns, 'SECTOR_CAN_BUY' => $sector_cost <= mrc_get_level($user, null, RES_DARK_MATTER), 'SECTOR_COST' => $sector_cost, 'SECTOR_COST_TEXT' => pretty_number($sector_cost))); tpl_set_resource_info($template, $planetrow, $fleets_to_planet, 2); display($template, "{$lang['ov_overview']} - {$lang['sys_planet_type'][$planetrow['planet_type']]} {$planetrow['name']} [{$planetrow['galaxy']}:{$planetrow['system']}:{$planetrow['planet']}]"); break; }
function que_process(&$user, $planet = null, $on_time = SN_TIME_NOW) { sn_db_transaction_check(true); $que = array(); // Блокируем пользователя. Собственно, запись о нём нам не нужна - будем использовать старую $user = db_user_by_id($user['id'], true); $time_left[$user['id']][0] = max(0, $on_time - $user['que_processed']); if ($planet === null && !$time_left[$user['id']][0]) { // TODO return $que; } // Определяем, какие очереди нам нужны и получаем их $que_type_id = $planet === null ? QUE_RESEARCH : false; $planet = intval(is_array($planet) ? $planet['id'] : $planet); // В $planet у нас теперь только её ID или шаблон null/0/false $que = que_get($user['id'], $planet, $que_type_id, true); //pdump($que); if (empty($que['items'])) { return $que; } $planet_list = array(); if ($planet !== null) { // Если нужно изменять данные на планетах - блокируем планеты и получаем данные о них // TODO - от них не надо ничего, кроме ID и que_processed // $planet_query = db_planet_list_by_user_or_planet($user['id'], $planet); // foreach($planet_query as $planet_row) $planet_row = db_planet_list_by_user_or_planet($user['id'], $planet); $planet_list[$planet_row['id']] = $planet_row; $time_left[$planet_row['id_owner']][$planet_row['id']] = max(0, $on_time - $planet_row['que_processed']); } // pdump($time_left); // Теперь в $time_left лежит время обсчета всех очередей по каждой из планеты if (array_sum($time_left[$user['id']]) == 0) { return $que; } // pdump($que); $db_changeset = array(); $unit_changes = array(); foreach ($que['items'] as &$que_item) { $que_player_id =& $que_item['que_player_id']; $que_planet_id = intval($que_item['que_planet_id']); // $que_type = &$que_item['que_type']; $que_time_left =& $que['time_left'][$que_player_id][$que_planet_id][$que_item['que_type']]; if (!isset($que_time_left)) { $que_time_left = $time_left[$que_player_id][$que_planet_id]; } if ($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) { continue; } // Дальше мы идем, если только осталось время в очереди И юниты к постройке // Вычисляем, сколько целых юнитов будет построено - от 0 до количества юнитов в очереди $unit_processed = min($que_item['que_unit_amount'] - 1, floor($que_time_left / $que_item['que_unit_time'])); // Вычитаем это время из остатков $que_time_left -= $unit_processed * $que_item['que_unit_time']; // Теперь работаем с остатком времени на юните. Оно не может быть равно или меньше нуля // Если времени в очереди осталось не меньше, чем время текущего юнита - значит мы достроили юнит if ($que_time_left >= $que_item['que_time_left']) { // Увеличиваем количество отстроенных юнитов $unit_processed++; // Вычитаем из времени очереди потраченное на постройку время $que_time_left -= $que_item['que_time_left']; // Полное время юнита равно времени нового юнита $que_item['que_time_left'] = $que_item['que_unit_time']; // Тут у нас может остатся время очереди - если постройка была не последняя } // Изменяем количество оставшихся юнитов $que_item['que_unit_amount'] -= $unit_processed; // Если еще остались юниты - значит ВСЁ оставшееся время приходится на достройку следующего юнита if ($que_item['que_unit_amount'] > 0) { $que_item['que_time_left'] = $que_item['que_time_left'] - $que_time_left; $que_time_left = 0; } if ($que_item['que_unit_amount'] <= 0) { $db_changeset['que'][] = array('action' => SQL_OP_DELETE, P_VERSION => 1, 'where' => array("que_id" => $que_item['que_id'])); } else { $db_changeset['que'][] = array('action' => SQL_OP_UPDATE, P_VERSION => 1, 'where' => array("que_id" => $que_item['que_id']), 'fields' => array('que_unit_amount' => array('delta' => -$unit_processed), 'que_time_left' => array('set' => $que_item['que_time_left']))); } if ($unit_processed) { $unit_processed_delta = $unit_processed * ($que_item['que_unit_mode'] == BUILD_CREATE ? 1 : -1); $unit_changes[$que_player_id][$que_planet_id][$que_item['que_unit_id']] += $unit_processed_delta; } } foreach ($time_left as $player_id => $planet_data) { foreach ($planet_data as $planet_id => $time_on_planet) { $table = $planet_id ? 'planets' : 'users'; $id = $planet_id ? $planet_id : $player_id; $db_changeset[$table][] = array('action' => SQL_OP_UPDATE, P_VERSION => 1, 'where' => array("id" => $id), 'fields' => array('que_processed' => array('set' => $on_time))); if (is_array($unit_changes[$player_id][$planet_id])) { foreach ($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) { $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, $unit_amount, $user, $planet_id ? $planet_id : null); } } } } //pdump($db_changeset, '$db_changeset'); $que = que_recalculate($que); //pdump($que, '$que'); // TODO: Re-enable quests for Alliances if (!empty($unit_changes) && !$user['user_as_ally']) { $quest_list = qst_get_quests($user['id']); $quest_triggers = qst_active_triggers($quest_list); $quest_rewards = array(); $xp_incoming = array(); foreach ($unit_changes as $user_id => $planet_changes) { foreach ($planet_changes as $planet_id => $changes) { $planet_this = $planet_id ? classSupernova::db_get_record_by_id(LOC_PLANET, $planet_id) : array(); foreach ($changes as $unit_id => $unit_value) { $que_id = que_get_unit_que($unit_id); $unit_level_new = mrc_get_level($user, $planet_this, $unit_id, false, true) + $unit_value; if ($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) { $build_data = eco_get_build_data($user, $planet_this, $unit_id, $unit_level_new - 1); $build_data = $build_data[BUILD_CREATE]; foreach (sn_get_groups('resources_loot') as $resource_id) { $xp_incoming[$que_id] += $build_data[$resource_id]; // TODO - добавить конверсию рейтов обмена } } if (is_array($quest_triggers)) { // TODO: Check mutiply condition quests $quest_trigger_list = array_keys($quest_triggers, $unit_id); if (is_array($quest_trigger_list)) { foreach ($quest_trigger_list as $quest_id) { if ($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $unit_level_new) { $quest_rewards[$quest_id][$user_id][$planet_id] = $quest_list[$quest_id]['quest_rewards_list']; $quest_list[$quest_id]['quest_status_status'] = QUEST_STATUS_COMPLETE; } } } } } } } // TODO: Изменить начисление награды за квесты на ту планету, на которой происходил ресеч qst_reward($user, $quest_rewards, $quest_list); foreach ($xp_incoming as $que_id => $xp) { rpg_level_up($user, $que_id == QUE_RESEARCH ? RPG_TECH : RPG_STRUCTURE, $xp / 1000); } } db_changeset_apply($db_changeset); // TODO Сообщения о постройке // $user = db_user_by_id($user['id'], true); return $que; /* // $local_que['time_left'][QUE_RESEARCH][0] = $time_left[QUE_RESEARCH][0]; //pdump($user_time_left, '$user_time_left'); print('1'); //foreach($local_que as $que_id => &$que_data) //{ // if(!intval($que_id))continue; foreach(sn_get_groups('que') as $que_id => $que_info) { if(!isset($que['ques'][$que_id]))continue; foreach($que_data as $owner_id => &$que_items) { foreach($que_items as &$que_item) { // Вычисляем, сколько целых юнитов будет построено - от 0 до количества юнитов в очереди $unit_processed = min($que_item['que_unit_amount'] - 1, floor($local_que['time_left'][$que_id][$owner_id] / $que_item['que_unit_time'])); // Вычитаем это время из остатков $local_que['time_left'][$que_id][$owner_id] -= $unit_processed * $que_item['que_unit_time']; // Теперь работаем с остатком времени на юните. Оно не может быть равно или меньше нуля // Вычитаем остаток времени работы очереди с времени постройки юнита if($que_item['que_time_left'] <= $local_que['time_left'][$que_id][$owner_id]) { // Если время постройки - неположительное, значит мы достроили юнит // Увеличиваем количество отстроенных юнитов $unit_processed++; // Вычитаем из времени очереди потраченное на постройку время $local_que['time_left'][$que_id][$owner_id] -= $que_item['que_time_left']; $que_item['que_time_left'] = $que_item['que_unit_time']; // Тут у нас может остатся время очереди - если постройка была не последняя } // Изменяем количество оставшихся юнитов $que_item['que_unit_amount'] -= $unit_processed; if($que_item['que_unit_amount']) { $que_item['que_time_left'] = $que_item['que_time_left'] - $local_que['time_left'][$que_id][$owner_id]; $local_que['time_left'][$que_id][$owner_id] = 0; } if(!$que_item['que_unit_amount']) { $db_changeset['que'][$que_item['que_id']] = array( 'action' => SQL_OP_DELETE, 'where' => array( "`que_id` = {$que_item['que_id']}", ), ); } else { $db_changeset['que'][$que_item['que_id']] = array( 'action' => SQL_OP_UPDATE, 'where' => array( "`que_id` = {$que_item['que_id']}", ), 'fields' => array( 'que_unit_amount' => array( 'delta' => -$unit_processed ), 'que_time_left' => array( 'set' => $que_item['que_time_left'] ), ), ); } if($unit_processed) { $unit_processed_delta = $unit_processed * ($que_item['que_unit_mode'] == BUILD_CREATE ? 1 : -1); $unit_changes[$owner_id][$que_item['que_unit_id']] += $unit_processed_delta; } // Если на очереди времени не осталось - выходим if(!$local_que['time_left'][$que_id][$owner_id]) { break; } } } } die(); // TODO: Re-enable quests for Alliances if(!empty($unit_changes) && !$user['user_as_ally'] && $user['id_planet']) { $planet = db_planet_by_id($user['id_planet'], true); $quest_list = qst_get_quests($user['id']); $quest_triggers = qst_active_triggers($quest_list); } else { $planet = array(); } $quest_rewards = array(); $xp_incoming = 0; foreach($unit_changes as $owner_id => $changes) { // $user_id_sql = $owner_id ? $owner_id : $user['id']; $planet_id_sql = $owner_id ? $owner_id : null; foreach($changes as $unit_id => $unit_value) { $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, $unit_value, $user, $planet_id_sql); // TODO: Изменить согласно типу очереди $unit_level_new = mrc_get_level($user, array(), $unit_id, false, true) + $unit_value; $build_data = eco_get_build_data($user, array(), $unit_id, $unit_level_new - 1); $build_data = $build_data[BUILD_CREATE]; foreach(sn_get_groups('resources_loot') as $resource_id) { $xp_incoming += $build_data[$resource_id]; } if($planet['id']) { // TODO: Check mutiply condition quests $quest_trigger_list = array_keys($quest_triggers, $unit_id); foreach($quest_trigger_list as $quest_id) { if($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $unit_level_new) { $quest_rewards[$quest_id] = $quest_list[$quest_id]['quest_rewards']; $quest_list[$quest_id]['quest_status_status'] = QUEST_STATUS_COMPLETE; } } } } } // TODO: Изменить согласно типу очереди rpg_level_up($user, RPG_TECH, $xp_incoming / 1000); // TODO: Изменить начисление награды за квесты на ту планету, на которой происходил ресеч qst_reward($user, $planet, $quest_rewards, $quest_list); db_changeset_apply($db_changeset); // Сообщения о постройке $user = db_user_by_id($user['id'], true); // TODO Так же пересчитывать планеты // sn_db_transaction_commit(); // TODO поменять que_processed у планеты и юзера return $local_que; */ }
/** * * This function changes rpg_points for user * You should ALWAYS use this function and NEVER directly change rpg_points by yourself * Otherwise refferal system wouldn't work and no logs would be made * "No logs" means you can never check if the user cheating with DM * * @package rpg * */ function rpg_points_change($user_id, $change_type, $dark_matter, $comment = false, $already_changed = false) { global $debug, $config, $dm_change_legit, $user; if (!$user_id) { return false; } $dm_change_legit = true; $sn_data_dark_matter_db_name = pname_resource_name(RES_DARK_MATTER); if ($already_changed) { $rows_affected = 1; } else { $changeset = array(); $a_user = db_user_by_id($user_id, true); if ($dark_matter < 0) { $dark_matter_exists = mrc_get_level($a_user, null, RES_DARK_MATTER, false, true); $dark_matter_exists < 0 ? $dark_matter_exists = 0 : false; $metamatter_to_reduce = -$dark_matter - $dark_matter_exists; if ($metamatter_to_reduce > 0) { $metamatter_exists = mrc_get_level($a_user, null, RES_METAMATTER); if ($metamatter_exists < $metamatter_to_reduce) { $debug->error('Ошибка снятия ТМ - ММ+ТМ меньше, чем сумма для снятия!', 'Ошибка снятия ТМ', LOG_ERR_INT_NOT_ENOUGH_DARK_MATTER); } if (is_array($comment)) { $comment = call_user_func_array('sprintf', $comment); } // mm_points_change($user_id, $change_type, -$metamatter_to_reduce, 'ММ в ТМ: ' . (-$dark_matter) . ' ТМ = ' . $dark_matter_exists . ' ТМ + ' . $metamatter_to_reduce . ' ММ. ' . $comment); classSupernova::$auth->account->metamatter_change($change_type, -$metamatter_to_reduce, 'ММ в ТМ: ' . -$dark_matter . ' ТМ = ' . $dark_matter_exists . ' ТМ + ' . $metamatter_to_reduce . ' ММ. ' . $comment); $dark_matter = -$dark_matter_exists; } } else { $changeset[] = "`dark_matter_total` = `dark_matter_total` + '{$dark_matter}'"; } $dark_matter ? $changeset[] = "`{$sn_data_dark_matter_db_name}` = `{$sn_data_dark_matter_db_name}` + '{$dark_matter}'" : false; !empty($changeset) ? db_user_set_by_id($user_id, implode(',', $changeset)) : false; $rows_affected = classSupernova::$db->db_affected_rows(); } if ($rows_affected || !$dark_matter) { $page_url = db_escape($_SERVER['SCRIPT_NAME']); if (is_array($comment)) { $comment = call_user_func_array('sprintf', $comment); } $comment = db_escape($comment); $row = db_user_by_id($user_id, false, 'username'); $row['username'] = db_escape($row['username']); doquery("INSERT INTO {{log_dark_matter}} (`log_dark_matter_username`, `log_dark_matter_reason`,\n `log_dark_matter_amount`, `log_dark_matter_comment`, `log_dark_matter_page`, `log_dark_matter_sender`)\n VALUES (\n '{$row['username']}', {$change_type},\n {$dark_matter}, '{$comment}', '{$page_url}', {$user_id}\n );"); if ($user['id'] == $user_id) { $user['dark_matter'] += $dark_matter; } if ($dark_matter > 0) { $old_referral = doquery("SELECT * FROM {{referrals}} WHERE `id` = {$user_id} LIMIT 1 FOR UPDATE;", '', true); if ($old_referral['id']) { doquery("UPDATE {{referrals}} SET dark_matter = dark_matter + '{$dark_matter}' WHERE `id` = {$user_id} LIMIT 1;"); $new_referral = doquery("SELECT * FROM {{referrals}} WHERE `id` = {$user_id} LIMIT 1;", '', true); $partner_bonus = floor($new_referral['dark_matter'] / $config->rpg_bonus_divisor) - ($old_referral['dark_matter'] >= $config->rpg_bonus_minimum ? floor($old_referral['dark_matter'] / $config->rpg_bonus_divisor) : 0); if ($partner_bonus > 0 && $new_referral['dark_matter'] >= $config->rpg_bonus_minimum) { rpg_points_change($new_referral['id_partner'], RPG_REFERRAL, $partner_bonus, "Incoming From Referral ID {$user_id}"); } } } } else { $debug->warning("Error adjusting Dark Matter for player ID {$user_id} (Player Not Found?) with {$dark_matter}. Reason: {$comment}", 'Dark Matter Change', 402); } $dm_change_legit = false; return $rows_affected; }
function sn_options_view($template = null) { global $lang, $template_result, $user, $planetrow, $user_option_list, $user_option_types, $sn_message_class_list, $config; sys_user_vacation($user); $FMT_DATE = preg_replace(array('/d/', '/m/', '/Y/'), array('DD', 'MM', 'YYYY'), FMT_DATE); $template = gettemplate('options', $template); // $template_result['.']['skin_list'][] = array( // 'NAME' => $lang['select_skin_path'], // 'VALUE' => '', // ); $dir = dir(SN_ROOT_PHYSICAL . 'skins'); while (($entry = $dir->read()) !== false) { if (is_dir("skins/{$entry}") && $entry[0] != '.') { $template_result['.']['skin_list'][] = array('VALUE' => $entry, 'NAME' => $entry, 'SELECTED' => $user['dpath'] == "skins/{$entry}/"); } } $dir->close(); for ($i = 0; $i < 2; $i++) { $template_result['.']['planet_order'][] = array('VALUE' => $i, 'NAME' => $lang['opt_lst_cla' . $i], 'SELECTED' => $user['planet_sort_order'] == $i); } for ($i = 0; $i < 4; $i++) { $template_result['.']['planet_order_type'][] = array('VALUE' => $i, 'NAME' => $lang['opt_lst_ord' . $i], 'SELECTED' => $user['planet_sort'] == $i); } foreach ($lang['sys_gender_list'] as $key => $value) { $template_result['.']['gender_list'][] = array('VALUE' => $key, 'NAME' => $value, 'SELECTED' => $user['gender'] == $key); } $lang_list = lng_get_list(); foreach ($lang_list as $lang_id => $lang_data) { $template_result['.']['languages'][] = array('VALUE' => $lang_id, 'NAME' => $lang_data['LANG_NAME_NATIVE'], 'SELECTED' => $lang_id == $user['lang']); } if (isset($lang['menu_customize_show_hide_button_state'])) { foreach ($lang['menu_customize_show_hide_button_state'] as $key => $value) { $template->assign_block_vars('menu_customize_show_hide_button_state', array('ID' => $key, 'NAME' => $value)); } } $str_date_format = "%3\$02d %2\$0s %1\$04d {$lang['top_of_year']} %4\$02d:%5\$02d:%6\$02d"; $time_now_parsed = getdate($user['deltime']); $user_time_diff = user_time_diff_get(); $player_options = player_load_option($user); $template->assign_vars(array('USER_ID' => $user['id'], 'USER_AUTHLEVEL' => $user['authlevel'], 'menu_customize_show_hide_button' => isset($player_options[PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON]) ? $player_options[PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON] : 0, 'menu_customize_show_button_enter' => isset($player_options[PLAYER_OPTION_MENU_SHOW_ON_BUTTON]) ? $player_options[PLAYER_OPTION_MENU_SHOW_ON_BUTTON] : 0, 'menu_customize_hide_button_enter' => isset($player_options[PLAYER_OPTION_MENU_HIDE_ON_BUTTON]) ? $player_options[PLAYER_OPTION_MENU_HIDE_ON_BUTTON] : 0, 'menu_customize_hide_unpinned_on_exit' => isset($player_options[PLAYER_OPTION_MENU_HIDE_ON_LEAVE]) ? $player_options[PLAYER_OPTION_MENU_HIDE_ON_LEAVE] : 0, 'menu_customize_show_absolute' => isset($player_options[PLAYER_OPTION_MENU_UNPIN_ABSOLUTE]) ? $player_options[PLAYER_OPTION_MENU_UNPIN_ABSOLUTE] : 0, 'menu_customize_items_as_buttons' => isset($player_options[PLAYER_OPTION_MENU_ITEMS_AS_BUTTONS]) ? $player_options[PLAYER_OPTION_MENU_ITEMS_AS_BUTTONS] : 0, 'sound_enabled' => isset($player_options[PLAYER_OPTION_SOUND_ENABLED]) ? $player_options[PLAYER_OPTION_SOUND_ENABLED] : 0, 'ADM_PROTECT_PLANETS' => $user['authlevel'] >= 3, 'opt_usern_data' => htmlspecialchars($user['username']), 'opt_mail1_data' => $user['email'], 'opt_mail2_data' => $user['email_2'], 'OPT_DPATH_DATA' => $user['dpath'], 'opt_probe_data' => $user['spio_anz'], 'opt_toolt_data' => $user['settings_tooltiptime'], 'opt_fleet_data' => $user['settings_fleetactions'], 'opt_sskin_data' => $user['design'] == 1 ? " checked='checked'" : '', 'opt_noipc_data' => $user['noipcheck'] == 1 ? " checked='checked'" : '', 'deltime' => $user['deltime'], 'deltime_text' => sprintf($str_date_format, $time_now_parsed['year'], $lang['months'][$time_now_parsed['mon']], $time_now_parsed['mday'], $time_now_parsed['hours'], $time_now_parsed['minutes'], $time_now_parsed['seconds']), 'opt_avatar' => $user['avatar'], 'config_game_email_pm' => $config->game_email_pm, 'user_settings_rep' => $user['settings_rep'] == 1 ? " checked='checked'/" : '', 'user_settings_esp' => $user['settings_esp'] == 1 ? " checked='checked'/" : '', 'user_settings_wri' => $user['settings_wri'] == 1 ? " checked='checked'/" : '', 'user_settings_mis' => $user['settings_mis'] == 1 ? " checked='checked'/" : '', 'user_settings_bud' => $user['settings_bud'] == 1 ? " checked='checked'/" : '', 'user_settings_statistics' => $user['settings_statistics'] == 1 ? " checked='checked'/" : '', 'user_settings_info' => $user['settings_info'] == 1 ? " checked='checked'/" : '', 'user_time_diff_forced' => $user_time_diff[PLAYER_OPTION_TIME_DIFF_FORCED], 'adm_pl_prot' => $user['admin_protection'], 'user_birthday' => $user['user_birthday'], 'GENDER' => $user['gender'], 'GENDER_TEXT' => $lang['sys_gender_list'][$user['gender']], 'FMT_DATE' => $FMT_DATE, 'JS_FMT_DATE' => js_safe_string($FMT_DATE), 'USER_VACATION_DISABLE' => $config->user_vacation_disable, 'VACATION_NEXT' => $user['vacation_next'], 'VACATION_NEXT_TEXT' => date(FMT_DATE_TIME, $user['vacation_next']), 'VACATION_TIMEOUT' => $user['vacation_next'] - SN_TIME_NOW > 0 ? $user['vacation_next'] - SN_TIME_NOW : 0, 'TIME_NOW' => SN_TIME_NOW, 'SERVER_SEND_EMAIL' => $config->game_email_pm, 'SERVER_NAME_CHANGE' => $config->game_user_changename != SERVER_PLAYER_NAME_CHANGE_NONE, 'SERVER_NAME_CHANGE_PAY' => $config->game_user_changename == SERVER_PLAYER_NAME_CHANGE_PAY, 'SERVER_NAME_CHANGE_ENABLED' => $config->game_user_changename == SERVER_PLAYER_NAME_CHANGE_FREE || $config->game_user_changename == SERVER_PLAYER_NAME_CHANGE_PAY && mrc_get_level($user, $planetrow, RES_DARK_MATTER) >= $config->game_user_changename_cost, 'DARK_MATTER' => pretty_number($config->game_user_changename_cost, true, mrc_get_level($user, $planetrow, RES_DARK_MATTER)), 'PAGE_HEADER' => $lang['opt_header'])); foreach ($user_option_list as $option_group_id => $option_group) { if ($option_group_id == OPT_MESSAGE) { foreach ($sn_message_class_list as $message_class_id => $message_class_data) { if ($message_class_data['switchable'] || $message_class_data['email'] && $config->game_email_pm) { $option_name = $message_class_data['name']; $template->assign_block_vars("options_{$option_group_id}", array('NAME' => $message_class_data['name'], 'TEXT' => $lang['msg_class'][$message_class_id], 'PM' => $message_class_data['switchable'] ? $user["opt_{$option_name}"] : -1, 'EMAIL' => $message_class_data['email'] && $config->game_email_pm ? $user["opt_email_{$option_name}"] : -1)); } } } else { foreach ($option_group as $option_name => $option_value) { if (array_key_exists($option_name, $user_option_types)) { $option_type = $user_option_types[$option_name]; } else { $option_type = 'switch'; } $template->assign_block_vars("options_{$option_group_id}", array('NAME' => $option_name, 'TYPE' => $option_type, 'TEXT' => $lang['opt_custom'][$option_name], 'HINT' => $lang['opt_custom']["{$option_name}_hint"], 'VALUE' => $user[$option_name])); } } } return parsetemplate($template); }