本文整理汇总了PHP中sn_get_groups函数的典型用法代码示例。如果您正苦于以下问题:PHP sn_get_groups函数的具体用法?PHP sn_get_groups怎么用?PHP sn_get_groups使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sn_get_groups函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: db_change_units
function db_change_units(&$user, &$planet, $unit_list = array(), $query = null)
{
$query = is_array($query) ? $query : array(LOC_USER => array(), LOC_PLANET => array());
$group = sn_get_groups('resources_loot');
foreach ($unit_list as $unit_id => $unit_amount) {
if (!in_array($unit_id, $group)) {
// TODO - remove later
print '<h1>СООБЩИТЕ ЭТО АДМИНУ: db_change_units() вызван для не-ресурсов!</h1>';
pdump(debug_backtrace());
die('db_change_units() вызван для не-ресурсов!');
}
if (!$unit_amount) {
continue;
}
$unit_db_name = pname_resource_name($unit_id);
$unit_location = sys_get_unit_location($user, $planet, $unit_id);
// Changing value in object
switch ($unit_location) {
case LOC_USER:
$user[$unit_db_name] += $unit_amount;
break;
case LOC_PLANET:
$planet[$unit_db_name] += $unit_amount;
break;
}
$unit_amount = $unit_amount < 0 ? $unit_amount : "+{$unit_amount}";
// Converting positive unit_amount to string '+unit_amount'
$query[$unit_location][$unit_id] = "`{$unit_db_name}`=`{$unit_db_name}`{$unit_amount}";
}
db_change_units_perform($query[LOC_USER], 'users', $user['id']);
db_change_units_perform($query[LOC_PLANET], 'planets', $planet['id']);
}
示例2: uni_create_planet
/**
* @param int $Galaxy
* @param int $System
* @param int $Position
* @param int $PlanetOwnerID
* @param string $planet_name_unsafe
* @param bool|false $HomeWorld
* @param array $options
*
* @return bool
*/
function uni_create_planet($Galaxy, $System, $Position, $PlanetOwnerID, $planet_name_unsafe = '', $HomeWorld = false, $options = array())
{
global $lang, $config;
$Position = intval($Position);
if (!isset($options['skip_check']) && db_planet_by_gspt($Galaxy, $System, $Position, PT_PLANET, true, '`id`')) {
return false;
}
$user_row = !empty($options['user_row']) && is_array($options['user_row']) ? $options['user_row'] : db_user_by_id($PlanetOwnerID);
$planet_generator = sn_get_groups('planet_generator');
if ($HomeWorld) {
$position_data = $planet_generator[0];
} else {
$position_data = $planet_generator[$Position >= UNIVERSE_RANDOM_PLANET_START || $Position < 1 ? UNIVERSE_RANDOM_PLANET_START : $Position];
if ($Position >= UNIVERSE_RANDOM_PLANET_START) {
// Корректируем температуру для планеты-странника
$position_data['t_max_max'] -= UNIVERSE_RANDOM_PLANET_TEMPERATURE_DECREASE * ($Position - UNIVERSE_RANDOM_PLANET_START);
}
}
$planet_images = sn_get_groups('planet_images');
$planet_image = $position_data['planet_images'][mt_rand(0, count($position_data['planet_images']) - 1)];
$planet_image .= 'planet' . $planet_images[$planet_image][mt_rand(0, count($planet_images[$planet_image]) - 1)];
$t_max = sn_rand_gauss_range($position_data['t_max_min'], $position_data['t_max_max'], true, 1.3, true);
$t_min = $t_max - sn_rand_gauss_range($position_data['t_delta_min'], $position_data['t_delta_max'], true, 1.3, true);
$planet_sectors = sn_rand_gauss_range($position_data['size_min'], $position_data['size_max'], true, 1.7, true);
// $planet_diameter = round(pow($planet_sectors, 2) * 1000);
$planet_diameter = round(sqrt($planet_sectors) * 1000);
$core_info = uni_create_planet_get_density($position_data, $user_row, $planet_sectors);
$planet_name_unsafe = $user_row['username'] . ' ' . ($planet_name_unsafe ? $planet_name_unsafe : $lang['sys_colo_defaultname']);
$planet['name'] = db_escape(strip_tags(trim($planet_name_unsafe)));
$planet['id_owner'] = $PlanetOwnerID;
$planet['last_update'] = SN_TIME_NOW;
$planet['image'] = $planet_image;
$planet['galaxy'] = $Galaxy;
$planet['system'] = $System;
$planet['planet'] = $planet['position_original'] = $Position;
$planet['planet_type'] = PT_PLANET;
$planet['diameter'] = $planet_diameter;
$planet['field_max'] = $planet['field_max_original'] = $planet_sectors;
$planet['density'] = $core_info[UNIT_PLANET_DENSITY];
$planet['density_index'] = $core_info[UNIT_PLANET_DENSITY_INDEX];
$planet['temp_min'] = $planet['temp_min_original'] = $t_min;
$planet['temp_max'] = $planet['temp_max_original'] = $t_max;
$planet['metal'] = $config->eco_planet_starting_metal;
$planet['crystal'] = $config->eco_planet_starting_crystal;
$planet['deuterium'] = $config->eco_planet_starting_deuterium;
$planet['metal_max'] = $config->eco_planet_storage_metal;
$planet['crystal_max'] = $config->eco_planet_storage_crystal;
$planet['deuterium_max'] = $config->eco_planet_storage_deuterium;
$density_info_resources =& $density_list[$core_info[UNIT_PLANET_DENSITY_INDEX]][UNIT_RESOURCES];
$planet['metal_perhour'] = $config->metal_basic_income * $density_info_resources[RES_METAL];
$planet['crystal_perhour'] = $config->crystal_basic_income * $density_info_resources[RES_CRYSTAL];
$planet['deuterium_perhour'] = $config->deuterium_basic_income * $density_info_resources[RES_DEUTERIUM];
$RetValue = classSupernova::db_ins_record(LOC_PLANET, "`name` = '{$planet['name']}', `id_owner` = '{$planet['id_owner']}', `last_update` = '{$planet['last_update']}', `image` = '{$planet['image']}',\n `galaxy` = '{$planet['galaxy']}', `system` = '{$planet['system']}', `planet` = '{$planet['planet']}', `planet_type` = '{$planet['planet_type']}', `position_original` = '{$planet['position_original']}',\n `diameter` = '{$planet['diameter']}', `field_max` = '{$planet['field_max']}', `field_max_original` = '{$planet['field_max_original']}',\n `density` = '{$planet['density']}', `density_index` = '{$planet['density_index']}',\n `temp_min` = '{$planet['temp_min']}', `temp_max` = '{$planet['temp_max']}', `temp_min_original` = '{$planet['temp_min_original']}', `temp_max_original` = '{$planet['temp_max_original']}',\n `metal` = '{$planet['metal']}', `metal_perhour` = '{$planet['metal_perhour']}', `metal_max` = '{$planet['metal_max']}',\n `crystal` = '{$planet['crystal']}', `crystal_perhour` = '{$planet['crystal_perhour']}', `crystal_max` = '{$planet['crystal_max']}',\n `deuterium` = '{$planet['deuterium']}', `deuterium_perhour` = '{$planet['deuterium_perhour']}', `deuterium_max` = '{$planet['deuterium_max']}'");
return is_array($RetValue) ? $RetValue['id'] : false;
// OK
}
示例3: sn_admin_planet_edit_query_string
function sn_admin_planet_edit_query_string($unit_id, $unit_amount, $mode)
{
if ($unit_amount && in_array($unit_id, sn_get_groups($mode))) {
$unit_amount = round($unit_amount);
$unit_name = get_unit_param($unit_id, P_NAME);
$result = "{$unit_name} = GREATEST(0, {$unit_name} + ({$unit_amount}))";
} else {
$result = '';
}
return $result;
}
示例4: eco_bld_tech
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);
}
示例5: que_process
//.........这里部分代码省略.........
$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;
/*
示例6: eco_render_rapid_fire
function eco_render_rapid_fire($unit_id)
{
global $lang;
$unit_data = get_unit_param($unit_id);
$unit_durability = $unit_data['shield'] + $unit_data['armor'];
$str_rapid_from = '';
$str_rapid_to = '';
foreach (sn_get_groups(array('fleet', 'defense_active')) as $enemy_id) {
$enemy_data = get_unit_param($enemy_id);
$enemy_durability = $enemy_data['shield'] + $enemy_data['armor'];
$rapid = floor($unit_data['attack'] * (isset($unit_data['amplify'][$enemy_id]) ? $unit_data['amplify'][$enemy_id] : 1) / $enemy_durability);
if ($rapid >= 1) {
$str_rapid_to .= "{$lang['nfo_rf_again']} {$lang['tech'][$enemy_id]} <font color=\"#00ff00\">{$rapid}</font><br>";
}
$rapid = floor($enemy_data['attack'] * (isset($enemy_data['amplify'][$unit_id]) ? $enemy_data['amplify'][$unit_id] : 1) / $unit_durability);
if ($rapid >= 1) {
$str_rapid_from .= "{$lang['tech'][$enemy_id]} {$lang['nfo_rf_from']} <font color=\"#ff0000\">{$rapid}</font><br>";
}
}
if ($str_rapid_to && $str_rapid_from) {
$str_rapid_to .= '<hr>';
}
return array('to' => $str_rapid_to, 'from' => $str_rapid_from);
}
示例7: sn_eco_build
function sn_eco_build($que_type, &$auser, &$planet)
{
global $lang, $config;
if ($ally_id = sys_get_param_id('ally_id')) {
define('SN_IN_ALLY', true);
$ranks = ally_get_ranks($auser['ally']);
if ($ranks[$auser['ally_rank_id']]['admin'] || $auser['ally']['ally_owner'] == $auser['id']) {
$user =& $auser['ally']['player'];
$planet = array('metal' => $user['metal'], 'crystal' => $user['crystal'], 'deuterium' => $user['deuterium']);
}
}
if (!$user) {
$user =& $auser;
}
switch ($action = sys_get_param_escaped('action')) {
case 'create':
// Add unit to que for build
// Add unit to que for build
case 'destroy':
// Add unit to que for remove
$operation_result = que_build($user, $planet, $action == 'destroy' ? BUILD_DESTROY : BUILD_CREATE);
break;
case 'trim':
que_delete($que_type, $user, $planet, false);
break;
case 'clear':
que_delete($que_type, $user, $planet, true);
break;
}
$group_missile = sn_get_groups('missile');
$silo_capacity_free = 0;
if ($que_type == QUE_STRUCTURES) {
$build_unit_list = sn_get_groups('build_allow');
$build_unit_list = $build_unit_list[$planet['planet_type']];
$artifact_id = ART_NANO_BUILDER;
$page_header = $lang['tech'][UNIT_STRUCTURES];
} elseif ($que_type == QUE_RESEARCH) {
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]);
}
$build_unit_list = sn_get_groups('tech');
$artifact_id = ART_HEURISTIC_CHIP;
$page_header = $lang['tech'][UNIT_TECHNOLOGIES] . ($user['user_as_ally'] ? " {$lang['sys_of_ally']} {$user['username']}" : '');
} elseif ($que_type == QUE_MERCENARY) {
// 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]);
// }
$build_unit_list = sn_get_groups('mercenaries');
$artifact_id = 0;
$page_header = $lang['tech'][UNIT_MERCENARIES] . ($user['user_as_ally'] ? " {$lang['sys_of_ally']} {$user['username']}" : '');
} else {
if (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) == 0) {
message($lang['need_hangar'], $lang['tech'][STRUC_FACTORY_HANGAR]);
}
$build_unit_list = sn_get_groups($page_mode = $que_type == SUBQUE_FLEET ? 'fleet' : 'defense');
$page_header = $lang[$page_mode];
$artifact_id = 0;
$silo_capacity_free = mrc_get_level($user, $planet, STRUC_SILO) * get_unit_param(STRUC_SILO, P_CAPACITY);
foreach ($group_missile as $unit_id) {
$silo_capacity_free -= (mrc_get_level($user, $planet, $unit_id, false, true) + (isset($in_que[$unit_id]) && $in_que[$unit_id] ? $in_que[$unit_id] : 0)) * get_unit_param($unit_id, P_UNIT_SIZE);
}
$silo_capacity_free = max(0, $silo_capacity_free);
}
// Caching values that used more then one time into local variables
// $config_resource_multiplier = $config->resource_multiplier;
$config_resource_multiplier = game_resource_multiplier();
/*
// Code for fully working new que system
$hangar_busy = count($que['que'][QUE_HANGAR]);
$lab_busy = count($que['que'][QUE_RESEARCH]) && !$config->BuildLabWhileRun;
*/
$template = gettemplate('buildings_builds', true);
if (!empty($operation_result)) {
$template->assign_block_vars('result', $operation_result);
}
$planet_id = $que_type == QUE_RESEARCH || $que_type == QUE_MERCENARY ? 0 : $planet['id'];
$ques = que_get($user['id'], $planet_id, $que_type);
$in_que =& $ques['in_que'][$que_type][$user['id']][$planet_id];
$que =& $ques['ques'][$que_type][$user['id']][$planet_id];
que_tpl_parse($template, $que_type, $user, $planet, $que);
$que_length = count($que);
$can_que_element = $que_length < que_get_max_que_length($user, $planet, $que_type);
$fleet_list = flt_get_fleets_to_planet($planet);
$planet_fields_max = eco_planet_fields_max($planet);
$planet_fields_current = $planet['field_current'];
$planet_fields_que = is_array($in_que) ? -array_sum($in_que) : 0;
$planet_fields_free = max(0, $planet_fields_max - $planet_fields_current + $planet_fields_que);
$planet_fields_queable = $que_type != QUE_STRUCTURES || $planet_fields_free > 0;
//$planet_temp_max = $planet['temp_max'];
$sn_modifiers_resource = sn_get_groups('modifiers');
$sn_modifiers_resource = $sn_modifiers_resource[MODIFIER_RESOURCE_PRODUCTION];
$sn_groups_density = sn_get_groups('planet_density');
$density_info = $sn_groups_density[$planet['density_index']][UNIT_RESOURCES];
$user_dark_matter = mrc_get_level($user, null, RES_DARK_MATTER);
//.........这里部分代码省略.........
示例8: sn_ube_report_load
}
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);
}
示例9: sn_imperium_view
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}";
//.........这里部分代码省略.........
示例10: killer_add_planet
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));
}
}
示例11: eco_get_planet_caps
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;
}
示例12: flt_flying_fleet_handler
function flt_flying_fleet_handler($skip_fleet_update = false)
{
/*
[*] Нужно ли заворачивать ВСЕ в одну транзакцию?
С одной стороны - да, что бы данные были гарантированно на момент снапшота
С другой стороны - нет, потому что при большой активности это все будет блокировать слишком много рядов, да и таймаут будет большой для ожидания всего разлоченного
Стоит завернуть каждую миссию отдельно? Это сильно увеличит количество запросов, зато так же сильно снизит количество блокировок.
Resume: НЕТ! Надо оставить все в одной транзакции! Так можно будет поддерживать consistency кэша. Там буквально сантисекунды блокировки
[*] Убрать кэшированние данных о пользователях и планета. Офигенно освободит память - проследить!
НЕТ! Считать, скольким флотам нужна будет инфа и кэшировать только то, что используется больше раза!
Заодно можно будет исключить перересчет очередей/ресурсов - сильно ускорит дело!
Особенно будет актуально, когда все бонусы будут в одной таблице
Ну и никто не заставляет как сейчас брать ВСЕ из таблицы - только по полям. Гемор, но не сильный - сделать запрос по группам sn_data
И писать в БД только один раз результат
[*] Нужно ли на этом этапе знать полную информацию о флотах?
Заблокировать флоты можно и неполным запросом. Блокировка флотов - это не страшно. Ну, не пройдет одна-две отмены - так никто и не гарантировал реалтайма!
С одной стороны - да, уменьшит количество запросов
С другой стооны - расход памяти
Все равно надо будет знать полную инфу о флоте в момент обработки
[*] Сделать тестовую БД для расчетов
[*] Но не раньше, чем переписать все миссии
*/
global $config, $debug;
if ($config->game_disable != GAME_DISABLE_NONE || $skip_fleet_update) {
return;
}
sn_db_transaction_start();
if ($config->db_loadItem('game_disable') != GAME_DISABLE_NONE || SN_TIME_NOW - strtotime($config->db_loadItem('fleet_update_last')) <= $config->fleet_update_interval) {
sn_db_transaction_rollback();
return;
}
// Watchdog timer
if ($config->db_loadItem('fleet_update_lock')) {
if (SN_TIME_NOW - strtotime($config->fleet_update_lock) <= mt_rand(240, 300)) {
sn_db_transaction_rollback();
return;
} else {
$debug->warning('Flying fleet handler was locked too long - watchdog unlocked', 'FFH Error', 504);
}
}
$config->db_saveItem('fleet_update_lock', SN_TIME_SQL);
$config->db_saveItem('fleet_update_last', SN_TIME_SQL);
sn_db_transaction_commit();
//log_file('Начинаем обсчёт флотов');
//log_file('Обсчёт ракет');
sn_db_transaction_start();
coe_o_missile_calculate();
sn_db_transaction_commit();
$fleet_list = array();
$fleet_event_list = array();
$missions_used = array();
sn_db_transaction_start();
//log_file('Запрос на флоты');
$_fleets = doquery("SELECT * FROM `{{fleets}}` WHERE\n (`fleet_start_time` <= " . SN_TIME_NOW . " AND `fleet_mess` = 0)\n OR (`fleet_end_stay` <= " . SN_TIME_NOW . " AND fleet_end_stay > 0 AND `fleet_mess` = 0)\n OR (`fleet_end_time` <= " . SN_TIME_NOW . ")\n FOR UPDATE;");
//log_file('Выборка флотов');
while ($fleet_row = db_fetch($_fleets)) {
set_time_limit(15);
// Унифицировать код с темплейтным разбором эвентов на планете!
$fleet_list[$fleet_row['fleet_id']] = $fleet_row;
$missions_used[$fleet_row['fleet_mission']] = 1;
if ($fleet_row['fleet_start_time'] <= SN_TIME_NOW && $fleet_row['fleet_mess'] == 0) {
$fleet_event_list[] = array('fleet_row' => &$fleet_list[$fleet_row['fleet_id']], 'fleet_time' => $fleet_list[$fleet_row['fleet_id']]['fleet_start_time'], 'fleet_event' => EVENT_FLT_ARRIVE);
}
if ($fleet_row['fleet_end_stay'] > 0 && $fleet_row['fleet_end_stay'] <= SN_TIME_NOW && $fleet_row['fleet_mess'] == 0) {
$fleet_event_list[] = array('fleet_row' => &$fleet_list[$fleet_row['fleet_id']], 'fleet_time' => $fleet_list[$fleet_row['fleet_id']]['fleet_end_stay'], 'fleet_event' => EVENT_FLT_ACOMPLISH);
}
if ($fleet_row['fleet_end_time'] <= SN_TIME_NOW) {
$fleet_event_list[] = array('fleet_row' => &$fleet_list[$fleet_row['fleet_id']], 'fleet_time' => $fleet_list[$fleet_row['fleet_id']]['fleet_end_time'], 'fleet_event' => EVENT_FLT_RETURN);
}
}
sn_db_transaction_commit();
//log_file('Сортировка и подгрузка модулей');
uasort($fleet_event_list, 'flt_flyingFleetsSort');
unset($_fleets);
// TODO: Грузить только используемые модули из $missions_used
$mission_files = array(MT_ATTACK => 'flt_mission_attack', MT_AKS => 'flt_mission_attack', MT_DESTROY => 'flt_mission_attack', MT_TRANSPORT => 'flt_mission_transport', MT_RELOCATE => 'flt_mission_relocate', MT_HOLD => 'flt_mission_hold', MT_SPY => 'flt_mission_spy', MT_COLONIZE => 'flt_mission_colonize', MT_RECYCLE => 'flt_mission_recycle', MT_EXPLORE => 'flt_mission_explore');
foreach ($missions_used as $mission_id => $cork) {
require_once SN_ROOT_PHYSICAL . "includes/includes/{$mission_files[$mission_id]}" . DOT_PHP_EX;
}
//log_file('Обработка миссий');
$sn_groups_mission = sn_get_groups('missions');
foreach ($fleet_event_list as $fleet_event) {
// TODO: Указатель тут потом сделать
// TODO: СЕЙЧАС НАДО ПРОВЕРЯТЬ ПО БАЗЕ - А ЖИВОЙ ЛИ ФЛОТ?!
$fleet_row = $fleet_event['fleet_row'];
if (!$fleet_row) {
// Fleet was destroyed in course of previous actions
continue;
}
//log_file('Миссия');
// TODO Обернуть всё в транзакции. Начинать надо заранее, блокируя все таблицы внутренним локом SELECT 1 FROM {{users}}
sn_db_transaction_start();
$config->db_saveItem('fleet_update_last', SN_TIME_SQL);
$mission_data = $sn_groups_mission[$fleet_row['fleet_mission']];
// Формируем запрос, блокирующий сразу все нужные записи
db_flying_fleet_lock($mission_data, $fleet_row);
$fleet_row = doquery("SELECT * FROM {{fleets}} WHERE fleet_id = {$fleet_row['fleet_id']} FOR UPDATE", true);
if (!$fleet_row || empty($fleet_row)) {
// Fleet was destroyed in course of previous actions
sn_db_transaction_commit();
//.........这里部分代码省略.........
示例13: mrc_mercenary_render
function mrc_mercenary_render($user)
{
global $config, $lang, $sn_powerup_buy_discounts;
$mode = sys_get_param_int('mode', UNIT_MERCENARIES);
$mode = in_array($mode, array(UNIT_MERCENARIES, UNIT_PLANS)) ? $mode : UNIT_MERCENARIES;
$is_permanent = $mode == UNIT_PLANS || !$config->empire_mercenary_temporary;
if ($mercenary_id = sys_get_param_int('mercenary_id')) {
$operation_result = mrc_mercenary_hire($mode, $user, $mercenary_id);
}
lng_include('infos');
$template = gettemplate('mrc_mercenary_hire', true);
if (!empty($operation_result)) {
$template->assign_block_vars('result', $operation_result);
}
foreach ($sn_powerup_buy_discounts as $hire_period => $hire_discount) {
$template->assign_block_vars('period', array('LENGTH' => $hire_period, 'TEXT' => $lang['mrc_period_list'][$hire_period], 'DISCOUNT' => $hire_period / $config->empire_mercenary_base_period * $hire_discount, 'SELECTED' => $hire_period == $config->empire_mercenary_base_period));
}
$user_dark_matter = mrc_get_level($user, '', RES_DARK_MATTER);
$cost_alliance_multiplyer = SN_IN_ALLY === true && $mode == UNIT_PLANS ? $config->ali_bonus_members : 1;
$cost_alliance_multiplyer = $cost_alliance_multiplyer >= 1 ? $cost_alliance_multiplyer : 1;
foreach (sn_get_groups($mode == UNIT_PLANS ? 'plans' : 'mercenaries') as $mercenary_id) {
$mercenary = get_unit_param($mercenary_id);
$mercenary_bonus = $mercenary['bonus'];
$mercenary_bonus = $mercenary_bonus >= 0 ? "+{$mercenary_bonus}" : "{$mercenary_bonus}";
switch ($mercenary['bonus_type']) {
case BONUS_PERCENT:
$mercenary_bonus = "{$mercenary_bonus}% ";
break;
case BONUS_ABILITY:
$mercenary_bonus = '';
break;
case BONUS_ADD:
default:
break;
}
$mercenary_level = mrc_get_level($user, null, $mercenary_id, false, true);
$mercenary_level_bonus = max(0, mrc_get_level($user, null, $mercenary_id) - $mercenary_level);
$total_cost_old = 0;
if ($is_permanent) {
$total_cost_old = eco_get_total_cost($mercenary_id, $mercenary_level);
$total_cost_old = $total_cost_old[BUILD_CREATE][RES_DARK_MATTER] * $cost_alliance_multiplyer;
}
$total_cost = eco_get_total_cost($mercenary_id, $mercenary_level + 1);
$total_cost[BUILD_CREATE][RES_DARK_MATTER] *= $cost_alliance_multiplyer;
$mercenary_unit = classSupernova::db_get_unit_by_location($user['id'], LOC_USER, $user['id'], $mercenary_id);
$mercenary_time_finish = strtotime($mercenary_unit['unit_time_finish']);
$template->assign_block_vars('officer', array('ID' => $mercenary_id, 'NAME' => $lang['tech'][$mercenary_id], 'DESCRIPTION' => $lang['info'][$mercenary_id]['description'], 'EFFECT' => $lang['info'][$mercenary_id]['effect'], 'COST' => $total_cost[BUILD_CREATE][RES_DARK_MATTER] - $total_cost_old, 'COST_TEXT' => pretty_number($total_cost[BUILD_CREATE][RES_DARK_MATTER] - $total_cost_old, 0, $user_dark_matter), 'LEVEL' => $mercenary_level, 'LEVEL_BONUS' => $mercenary_level_bonus, 'LEVEL_MAX' => $mercenary['max'], 'BONUS' => $mercenary_bonus, 'BONUS_TYPE' => $mercenary['bonus_type'], 'HIRE_END' => $mercenary_time_finish && $mercenary_time_finish >= SN_TIME_NOW ? date(FMT_DATE_TIME, $mercenary_time_finish) : '', 'CAN_BUY' => mrc_officer_accessible($user, $mercenary_id)));
$upgrade_cost = 1;
for ($i = $config->empire_mercenary_temporary ? 1 : $mercenary_level + 1; $mercenary['max'] ? $i <= $mercenary['max'] : $upgrade_cost <= $user_dark_matter; $i++) {
$total_cost = eco_get_total_cost($mercenary_id, $i);
$total_cost[BUILD_CREATE][RES_DARK_MATTER] *= $cost_alliance_multiplyer;
$upgrade_cost = $total_cost[BUILD_CREATE][RES_DARK_MATTER] - $total_cost_old;
$template->assign_block_vars('officer.level', array('VALUE' => $i, 'PRICE' => $upgrade_cost));
}
}
$template->assign_vars(array('PAGE_HEADER' => $lang['tech'][$mode], 'MODE' => $mode, 'IS_PERMANENT' => intval($is_permanent), 'EMPIRE_MERCENARY_TEMPORARY' => $config->empire_mercenary_temporary, 'DARK_MATTER' => $user_dark_matter));
display(parsetemplate($template), $lang['tech'][$mode]);
}
示例14: db_planet_by_id
$planetrow = db_planet_by_id($user['current_planet'], true);
$target_planet_type = sys_get_param_int('planet_type');
$target_planet_check = $target_planet_type == PT_DEBRIS ? PT_PLANET : $target_planet_type;
$target_coord['planet_type'] = $target_planet_check;
$target_row = db_planet_by_vector($target_coord);
if (empty($target_row)) {
$target_row = array('galaxy' => $target_coord['galaxy'], 'system' => $target_coord['system'], 'planet' => $target_coord['planet'], 'planet_type' => $target_planet_check, 'id_owner' => 0);
}
$fleet_array = array();
switch ($target_mission) {
case MT_SPY:
$fleet_array[SHIP_SPY] = min(mrc_get_level($user, $planetrow, SHIP_SPY), abs($user['spio_anz']));
$unit_group = 'flt_spies';
break;
case MT_RECYCLE:
foreach (sn_get_groups('flt_recyclers') as $unit_id) {
if ($unit_count = mrc_get_level($user, $planetrow, $unit_id)) {
$fleet_array[$unit_id] = $unit_count;
}
}
$transport_data = flt_calculate_fleet_to_transport($fleet_array, $target_row['debris_metal'] + $target_row['debris_crystal'], $planetrow, $target_row);
$fleet_array = $transport_data['fleet'];
$unit_group = 'flt_recyclers';
break;
case MT_MISSILE:
$fleet_array[UNIT_DEF_MISSILE_INTERPLANET] = min(mrc_get_level($user, $planetrow, UNIT_DEF_MISSILE_INTERPLANET), abs(sys_get_param_float('missiles')));
$unit_group = 'missile';
break;
}
$options = array('target_structure' => $target_structure = sys_get_param_int('structures'));
$cant_attack = flt_can_attack($planetrow, $target_row, $fleet_array, $target_mission, $options);
示例15: qst_reward
function qst_reward(&$user, &$rewards, &$quest_list)
{
if (empty($rewards)) {
return;
}
global $lang;
$db_changeset = array();
$total_rewards = array();
$comment_dm = '';
foreach ($rewards as $quest_id => $user_data) {
foreach ($user_data as $user_id => $planet_data) {
foreach ($planet_data as $planet_id => $reward_list) {
$comment = sprintf($lang['qst_msg_complete_body'], $quest_list[$quest_id]['quest_name']);
$comment_dm .= isset($reward_list[RES_DARK_MATTER]) ? $comment : '';
$comment_reward = array();
foreach ($reward_list as $unit_id => $unit_amount) {
$comment_reward[] = $unit_amount . ' ' . $lang['tech'][$unit_id];
$total_rewards[$user_id][$planet_id][$unit_id] += $unit_amount;
}
$comment .= " {$lang['qst_msg_your_reward']} " . implode(',', $comment_reward);
msg_send_simple_message($user['id'], 0, SN_TIME_NOW, MSG_TYPE_ADMIN, $lang['msg_from_admin'], $lang['qst_msg_complete_subject'], $comment);
sn_db_perform('{{quest_status}}', array('quest_status_quest_id' => $quest_id, 'quest_status_user_id' => $user_id, 'quest_status_status' => QUEST_STATUS_COMPLETE));
}
}
}
$group_resources = sn_get_groups('resources_loot');
$quest_rewards_allowed = sn_get_groups('quest_rewards');
if (!empty($total_rewards)) {
foreach ($total_rewards as $user_id => $planet_data) {
$user_row = classSupernova::db_get_record_by_id(LOC_USER, $user_id);
foreach ($planet_data as $planet_id => $unit_data) {
$local_changeset = array();
foreach ($unit_data as $unit_id => $unit_amount) {
if (!isset($quest_rewards_allowed[$unit_id])) {
continue;
}
if ($unit_id == RES_DARK_MATTER) {
rpg_points_change($user['id'], RPG_QUEST, $unit_amount, $comment_dm);
} elseif (isset($group_resources[$unit_id])) {
$local_changeset[pname_resource_name($unit_id)] = array('delta' => $unit_amount);
} else {
$db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, $unit_amount, $user_row, $planet_id);
}
// unit
}
if (!empty($local_changeset)) {
$planet_id = $planet_id == 0 && isset($user_row['id_planet']) ? $user_row['id_planet'] : $planet_id;
$db_changeset[$planet_id ? 'planets' : 'users'][] = array('action' => SQL_OP_UPDATE, P_VERSION => 1, 'where' => array("id" => $planet_id ? $planet_id : $user_id), 'fields' => $local_changeset);
}
}
}
classSupernova::db_changeset_apply($db_changeset);
}
}