function sn_ube_combat_result_apply(&$combat_data) { // TODO: Поменять все отладки на запросы $destination_user_id = $combat_data[UBE_FLEETS][0][UBE_OWNER]; $outcome =& $combat_data[UBE_OUTCOME]; $planet_info =& $outcome[UBE_PLANET]; $planet_id = $planet_info[PLANET_ID]; // Обновляем поле обломков на планете if (!$combat_data[UBE_OPTIONS][UBE_COMBAT_ADMIN] && !empty($outcome[UBE_DEBRIS])) { db_planet_set_by_gspt($planet_info[PLANET_GALAXY], $planet_info[PLANET_SYSTEM], $planet_info[PLANET_PLANET], PT_PLANET, "`debris_metal` = `debris_metal` + " . floor($outcome[UBE_DEBRIS][RES_METAL]) . ", `debris_crystal` = `debris_crystal` + " . floor($outcome[UBE_DEBRIS][RES_CRYSTAL])); } $db_save = array(UBE_FLEET_GROUP => array()); $fleets_outcome =& $outcome[UBE_FLEETS]; foreach ($combat_data[UBE_FLEETS] as $fleet_id => &$fleet_info) { if ($fleet_info[UBE_FLEET_GROUP]) { $db_save[UBE_FLEET_GROUP][$fleet_info[UBE_FLEET_GROUP]] = $fleet_info[UBE_FLEET_GROUP]; } $fleet_info[UBE_COUNT] = $fleet_info[UBE_COUNT] ? $fleet_info[UBE_COUNT] : array(); $fleets_outcome[$fleet_id][UBE_UNITS_LOST] = $fleets_outcome[$fleet_id][UBE_UNITS_LOST] ? $fleets_outcome[$fleet_id][UBE_UNITS_LOST] : array(); $fleet_query = array(); $db_changeset = array(); $old_fleet_count = array_sum($fleet_info[UBE_COUNT]); $new_fleet_count = $old_fleet_count - array_sum($fleets_outcome[$fleet_id][UBE_UNITS_LOST]); // Перебираем юниты если во время боя количество юнитов изменилось и при этом во флоту остались юниты или это планета if ($new_fleet_count != $old_fleet_count && (!$fleet_id || $new_fleet_count)) { // Просматриваем результаты изменения флотов foreach ($fleet_info[UBE_COUNT] as $unit_id => $unit_count) { // Перебираем аутком на случай восстановления юнитов $units_lost = (double) $fleets_outcome[$fleet_id][UBE_UNITS_LOST][$unit_id]; $units_left = $unit_count - $units_lost; if ($fleet_id) { // Не планета - всегда сразу записываем строку итогов флота $fleet_query[$unit_id] = "{$unit_id},{$units_left}"; } elseif ($units_lost) { // Планета - записываем в ИД юнита его потери только если есть потери // $unit_db_name = get_unit_param($unit_id, P_NAME); // $fleet_query[$unit_id] = "`{$unit_db_name}` = `{$unit_db_name}` - {$units_lost}"; // pdump($fleet_info); // die(); $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, -$units_lost, $combat_data[UBE_PLAYERS][$destination_user_id][UBE_PLAYER_DATA], $planet_id); } } if ($fleet_id) { // Для флотов перегенерируем массив как одно вхождение в SET SQL-запроса $fleet_query = implode(';', $fleet_query); $fleet_query = array("`fleet_array` = '{$fleet_query}'"); } } // Если во флоте остались юниты или это планета - генерируем изменение ресурсов if ($new_fleet_count || !$fleet_id) { foreach (sn_get_groups('resources_loot') as $resource_id) { $resource_change = (double) $fleets_outcome[$fleet_id][UBE_RESOURCES_LOOTED][$resource_id] + (double) $fleets_outcome[$fleet_id][UBE_CARGO_DROPPED][$resource_id]; if ($resource_change) { $resource_db_name = ($fleet_id ? 'fleet_resource_' : '') . pname_resource_name($resource_id); $fleet_query[] = "`{$resource_db_name}` = `{$resource_db_name}` - ({$resource_change})"; } } } /* if(empty($fleet_query)) { continue; } */ if ($fleet_id && $new_fleet_count) { // Если защитник и не РМФ - отправляем флот назад if ($fleet_info[UBE_FLEET_TYPE] == UBE_DEFENDERS && !$outcome[UBE_SFR] || $fleet_info[UBE_FLEET_TYPE] == UBE_ATTACKERS) { $fleet_query[] = '`fleet_mess` = 1'; } // Если флот в группе - помечаем нулем // if($fleet_info[UBE_FLEET_GROUP]) // { // $fleet_query[] = '`fleet_group` = 0'; // } } //global $debug; $fleet_query = implode(',', $fleet_query); if ($fleet_id) { if ($fleet_info[UBE_FLEET_TYPE] == UBE_ATTACKERS && $outcome[UBE_MOON_REAPERS] == UBE_MOON_REAPERS_DIED) { $new_fleet_count = 0; } if ($new_fleet_count) { if ($fleet_query) { doquery("UPDATE {{fleets}} SET {$fleet_query}, `fleet_amount` = '{$new_fleet_count}' WHERE `fleet_id` = {$fleet_id} LIMIT 1"); } } else { // Удаляем пустые флоты doquery("DELETE FROM {{fleets}} WHERE `fleet_id` = {$fleet_id} LIMIT 1"); db_unit_list_delete(0, LOC_FLEET, $fleet_id, 0); } } else { // Сохраняем изменения ресурсов - если они есть if ($fleet_query) { db_planet_set_by_id($planet_id, $fleet_query); } if (!empty($db_changeset)) { db_changeset_apply($db_changeset); } } } // TODO: Связать сабы с флотами констраинтами ON DELETE SET NULL // $db_save[UBE_FLEET_GROUP][$fleet_info[UBE_FLEET_GROUP]] = $fleet_info[UBE_FLEET_GROUP]; if (!empty($db_save[UBE_FLEET_GROUP])) { $db_save[UBE_FLEET_GROUP] = implode(',', $db_save[UBE_FLEET_GROUP]); doquery("DELETE FROM {{aks}} WHERE `id` IN ({$db_save[UBE_FLEET_GROUP]})"); } if ($outcome[UBE_MOON] == UBE_MOON_CREATE_SUCCESS) { $moon_row = uni_create_moon($planet_info[PLANET_GALAXY], $planet_info[PLANET_SYSTEM], $planet_info[PLANET_PLANET], $destination_user_id, $outcome[UBE_MOON_SIZE], '', false); $outcome[UBE_MOON_NAME] = $moon_row['name']; unset($moon_row); } elseif ($outcome[UBE_MOON] == UBE_MOON_DESTROY_SUCCESS) { db_planet_delete_by_id($planet_id); } $bashing_list = array(); foreach ($combat_data[UBE_PLAYERS] as $player_id => $player_info) { if ($player_info[UBE_ATTACKER]) { if ($outcome[UBE_MOON] != UBE_MOON_DESTROY_SUCCESS) { $bashing_list[] = "({$player_id}, {$planet_id}, {$combat_data[UBE_TIME]})"; } if ($combat_data[UBE_OPTIONS][UBE_MISSION_TYPE] == MT_ATTACK && $combat_data[UBE_OPTIONS][UBE_DEFENDER_ACTIVE]) { $str_loose_or_win = $outcome[UBE_COMBAT_RESULT] == UBE_COMBAT_RESULT_WIN ? 'raidswin' : 'raidsloose'; db_user_set_by_id($player_id, "`xpraid` = `xpraid` + 1, `raids` = `raids` + 1, `{$str_loose_or_win}` = `{$str_loose_or_win}` + 1"); } } } $bashing_list = implode(',', $bashing_list); if ($bashing_list) { doquery("INSERT INTO {{bashing}} (bashing_user_id, bashing_planet_id, bashing_time) VALUES {$bashing_list};"); } }
$moon = sys_o_get_updated($owner, $moon, SN_TIME_NOW); $moon = $moon['planet']; killer_add_planet($moon); } foreach (sn_get_groups('resources_loot') as $resource_id) { $resource_name = pname_resource_name($resource_id); $template->assign_var("{$resource_name}_cost", $final_cost[$resource_id]); $final_cost[$resource_id] = floor($final_cost[$resource_id] * $bonus); $template->assign_var("{$resource_name}_bonus", $final_cost[$resource_id]); } if ($_GET['btn_confirm']) { $time = SN_TIME_NOW + PERIOD_DAY; db_unit_list_delete($planet['id_owner'], LOC_PLANET, $planet['id']); db_planet_set_by_id($planet['id'], "id_owner = 0, destruyed = {$time}"); if ($moon) { db_unit_list_delete($planet['id_owner'], LOC_PLANET, $moon['id']); db_planet_set_by_id($moon['id'], "id_owner = 0, destruyed = {$time}"); } db_planet_set_by_id($destination['id'], "metal = metal + '{$final_cost[RES_METAL]}', crystal = crystal + '{$final_cost[RES_CRYSTAL]}', deuterium = deuterium + '{$final_cost[RES_DEUTERIUM]}'"); $template->assign_var('CHECK', 2); } } sn_db_transaction_commit(); } $template->assign_vars(array('galaxy_src' => $galaxy_src, 'system_src' => $system_src, 'planet_src' => $planet_src, 'galaxy_dst' => $galaxy_dst, 'system_dst' => $system_dst, 'planet_dst' => $planet_dst, 'bonus' => $bonus, 'username' => $username)); display(parsetemplate($template, $parse), $lang['adm_pl_comp_title'], false, '', true); function killer_add_planet($planet) { global $final_cost; $final_cost = array(); $sn_group_resources_loot = sn_get_groups('resources_loot');
function mrc_mercenary_hire($mode, $user, $mercenary_id) { global $config, $lang, $sn_powerup_buy_discounts; try { $is_permanent = $mode == UNIT_PLANS || !$config->empire_mercenary_temporary; $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; if (!in_array($mercenary_id, sn_get_groups($mode == UNIT_PLANS ? 'plans' : 'mercenaries'))) { throw new Exception($lang['mrc_msg_error_wrong_mercenary'], ERR_ERROR); } if (!mrc_officer_accessible($user, $mercenary_id)) { throw new Exception($lang['mrc_msg_error_requirements'], ERR_ERROR); } $mercenary_level = sys_get_param_int('mercenary_level'); if ($mercenary_level < 0 || $mercenary_level > get_unit_param($mercenary_id, P_MAX_STACK)) { throw new Exception($lang['mrc_msg_error_wrong_level'], ERR_ERROR); } if ($mercenary_level && !array_key_exists($mercenary_period = sys_get_param_int('mercenary_period'), $sn_powerup_buy_discounts)) { throw new Exception($lang['mrc_msg_error_wrong_period'], ERR_ERROR); } sn_db_transaction_start(); $mercenary_level_old = mrc_get_level($user, $planetrow, $mercenary_id, true, true); if ($config->empire_mercenary_temporary && $mercenary_level_old && $mercenary_level) { throw new Exception($lang['mrc_msg_error_already_hired'], ERR_ERROR); // Can't hire already hired temp mercenary - dismiss first } elseif ($config->empire_mercenary_temporary && !$mercenary_level_old && !$mercenary_level) { throw new Exception('', ERR_NONE); // Can't dismiss (!$mercenary_level) not hired (!$mercenary_level_old) temp mercenary. But no error } if ($mercenary_level) { $darkmater_cost = eco_get_total_cost($mercenary_id, $mercenary_level); if (!$config->empire_mercenary_temporary && $mercenary_level_old) { $darkmater_cost_old = eco_get_total_cost($mercenary_id, $mercenary_level_old); $darkmater_cost[BUILD_CREATE][RES_DARK_MATTER] -= $darkmater_cost_old[BUILD_CREATE][RES_DARK_MATTER]; } $darkmater_cost = ceil($darkmater_cost[BUILD_CREATE][RES_DARK_MATTER] * $mercenary_period * $sn_powerup_buy_discounts[$mercenary_period] / $config->empire_mercenary_base_period); } else { $darkmater_cost = 0; } $darkmater_cost *= $cost_alliance_multiplyer; if (mrc_get_level($user, null, RES_DARK_MATTER) < $darkmater_cost) { throw new Exception($lang['mrc_msg_error_no_resource'], ERR_ERROR); } if ($darkmater_cost && $mercenary_level || !$is_permanent) { $unit_row = db_unit_by_location($user['id'], LOC_USER, $user['id'], $mercenary_id); if (is_array($unit_row) && ($dismiss_left_days = floor((strtotime($unit_row['unit_time_finish']) - SN_TIME_NOW) / PERIOD_DAY))) { $dismiss_full_cost = eco_get_total_cost($mercenary_id, $unit_row['unit_level']); $dismiss_full_cost = $dismiss_full_cost[BUILD_CREATE][RES_DARK_MATTER]; $dismiss_full_days = round((strtotime($unit_row['unit_time_finish']) - strtotime($unit_row['unit_time_start'])) / PERIOD_DAY); /* print(sprintf($lang['mrc_mercenary_dismissed_log'], $lang['tech'][$mercenary_id], $mercenary_id, $dismiss_full_cost, $dismiss_full_days, $unit_row['unit_time_start'], $unit_row['unit_time_finish'], $dismiss_left_days, floor($dismiss_full_cost * $dismiss_left_days / $dismiss_full_days) )); */ rpg_points_change($user['id'], RPG_MERCENARY_DISMISSED, 0, sprintf($lang['mrc_mercenary_dismissed_log'], $lang['tech'][$mercenary_id], $mercenary_id, $dismiss_full_cost, $dismiss_full_days, $unit_row['unit_time_start'], $unit_row['unit_time_finish'], $dismiss_left_days, floor($dismiss_full_cost * $dismiss_left_days / $dismiss_full_days))); } db_unit_list_delete($user['id'], LOC_USER, $user['id'], $mercenary_id); } if ($darkmater_cost && $mercenary_level) { db_unit_set_insert("unit_player_id = {$user['id']},\n unit_location_type = " . LOC_USER . ",\n unit_location_id = {$user['id']},\n unit_type = {$mode},\n unit_snid = {$mercenary_id},\n unit_level = {$mercenary_level},\n unit_time_start = " . (!$is_permanent ? 'FROM_UNIXTIME(' . SN_TIME_NOW . ')' : 'null') . ",\n unit_time_finish = " . (!$is_permanent ? 'FROM_UNIXTIME(' . (SN_TIME_NOW + $mercenary_period) . ')' : 'null')); rpg_points_change($user['id'], $mode == UNIT_PLANS ? RPG_PLANS : RPG_MERCENARY, -$darkmater_cost, sprintf($lang[$mode == UNIT_PLANS ? 'mrc_plan_bought_log' : 'mrc_mercenary_hired_log'], $lang['tech'][$mercenary_id], $mercenary_id, $darkmater_cost, round($mercenary_period / PERIOD_DAY))); } sn_db_transaction_commit(); sys_redirect($_SERVER['REQUEST_URI']); } catch (Exception $e) { sn_db_transaction_rollback(); $operation_result = array('STATUS' => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR, 'MESSAGE' => $e->getMessage()); } return $operation_result; }