function sn_mrc_get_level(&$user, $planet = array(), $unit_id, $for_update = false, $plain = false, &$result) { $mercenary_level = 0; $unit_db_name = pname_resource_name($unit_id); if (in_array($unit_id, sn_get_groups(array('plans', 'mercenaries', 'tech', 'artifacts')))) { /* $context = array( 'location' => LOC_USER, 'user' => &$user, ); $mercenary_level = unit_get_level($unit_id, $context, array('for_update' => $for_update)); */ $unit = classSupernova::db_get_unit_by_location($user['id'], LOC_USER, $user['id'], $unit_id); $mercenary_level = is_array($unit) && $unit['unit_level'] ? $unit['unit_level'] : 0; } elseif (in_array($unit_id, sn_get_groups(array('structures', 'fleet', 'defense')))) { /* $context = array( 'location' => LOC_PLANET, 'planet' => &$planet, ); $mercenary_level = unit_get_level($unit_id, $context, array('for_update' => $for_update)); */ $unit = classSupernova::db_get_unit_by_location(is_array($user) ? $user['id'] : $planet['id_owner'], LOC_PLANET, $planet['id'], $unit_id); $mercenary_level = is_array($unit) && $unit['unit_level'] ? $unit['unit_level'] : 0; } elseif (in_array($unit_id, sn_get_groups('governors'))) { $mercenary_level = $unit_id == $planet['PLANET_GOVERNOR_ID'] ? $planet['PLANET_GOVERNOR_LEVEL'] : 0; } elseif ($unit_id == RES_DARK_MATTER || $unit_id == RES_METAMATTER) { $mercenary_level = $user[$unit_db_name]; } elseif (in_array($unit_id, sn_get_groups(array('resources_loot'))) || $unit_id == UNIT_SECTOR) { $mercenary_level = !empty($planet) ? $planet[$unit_db_name] : $user[$unit_db_name]; } return $result = $mercenary_level; }
function db_unit_by_location($user_id = 0, $location_type, $location_id, $unit_snid = 0, $for_update = false, $fields = '*') { // apply time restrictions ???? return classSupernova::db_get_unit_by_location($user_id, $location_type, $location_id, $unit_snid, $for_update, $fields); }
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]); }