コード例 #1
0
/**
 * MissionCaseRecycling.php
 *
 * @version 1.0
 * @copyright 2008 By Chlorel for XNova
 */
function flt_mission_recycle(&$mission_data)
{
    $fleet_row =& $mission_data['fleet'];
    $destination_planet =& $mission_data['dst_planet'];
    if (!$fleet_row) {
        return CACHE_NOTHING;
    }
    if (!isset($destination_planet['id'])) {
        // doquery("UPDATE {{fleets}} SET `fleet_mess` = 1 WHERE `fleet_id` = {$fleet_row['fleet_id']} LIMIT 1;");
        flt_send_back($mission_data['fleet']);
        return CACHE_FLEET;
    }
    global $lang;
    $RecyclerCapacity = 0;
    $OtherFleetCapacity = 0;
    $fleet_array = sys_unit_str2arr($fleet_row['fleet_array']);
    foreach ($fleet_array as $unit_id => $unit_count) {
        if (in_array($unit_id, sn_get_groups('fleet'))) {
            $capacity = get_unit_param($unit_id, P_CAPACITY) * $unit_count;
            if (in_array($unit_id, sn_get_groups('flt_recyclers'))) {
                $RecyclerCapacity += $capacity;
            } else {
                $OtherFleetCapacity += $capacity;
            }
        }
    }
    $IncomingFleetGoods = $fleet_row["fleet_resource_metal"] + $fleet_row["fleet_resource_crystal"] + $fleet_row["fleet_resource_deuterium"];
    if ($IncomingFleetGoods > $OtherFleetCapacity) {
        $RecyclerCapacity -= $IncomingFleetGoods - $OtherFleetCapacity;
    }
    if ($destination_planet["debris_metal"] + $destination_planet["debris_crystal"] <= $RecyclerCapacity) {
        $RecycledGoods["metal"] = $destination_planet["debris_metal"];
        $RecycledGoods["crystal"] = $destination_planet["debris_crystal"];
    } else {
        if ($destination_planet["debris_metal"] > $RecyclerCapacity / 2 and $destination_planet["debris_crystal"] > $RecyclerCapacity / 2) {
            $RecycledGoods["metal"] = $RecyclerCapacity / 2;
            $RecycledGoods["crystal"] = $RecyclerCapacity / 2;
        } else {
            if ($destination_planet["debris_metal"] > $destination_planet["debris_crystal"]) {
                $RecycledGoods["crystal"] = $destination_planet["debris_crystal"];
                if ($destination_planet["debris_metal"] > $RecyclerCapacity - $RecycledGoods["crystal"]) {
                    $RecycledGoods["metal"] = $RecyclerCapacity - $RecycledGoods["crystal"];
                } else {
                    $RecycledGoods["metal"] = $destination_planet["debris_metal"];
                }
            } else {
                $RecycledGoods["metal"] = $destination_planet["debris_metal"];
                if ($destination_planet["debris_crystal"] > $RecyclerCapacity - $RecycledGoods["metal"]) {
                    $RecycledGoods["crystal"] = $RecyclerCapacity - $RecycledGoods["metal"];
                } else {
                    $RecycledGoods["crystal"] = $destination_planet["debris_crystal"];
                }
            }
        }
    }
    $NewCargo['Metal'] = $fleet_row["fleet_resource_metal"] + $RecycledGoods["metal"];
    $NewCargo['Crystal'] = $fleet_row["fleet_resource_crystal"] + $RecycledGoods["crystal"];
    $NewCargo['Deuterium'] = $fleet_row["fleet_resource_deuterium"];
    db_planet_set_by_gspt($fleet_row['fleet_end_galaxy'], $fleet_row['fleet_end_system'], $fleet_row['fleet_end_planet'], PT_PLANET, "`debris_metal` = `debris_metal` - '{$RecycledGoods['metal']}', `debris_crystal` = `debris_crystal` - '{$RecycledGoods['crystal']}'");
    $Message = sprintf($lang['sys_recy_gotten'], pretty_number($RecycledGoods["metal"]), $lang['Metal'], pretty_number($RecycledGoods["crystal"]), $lang['Crystal']);
    msg_send_simple_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_start_time'], MSG_TYPE_RECYCLE, $lang['sys_mess_spy_control'], $lang['sys_recy_report'], $Message);
    $QryUpdateFleet = "UPDATE {{fleets}} SET `fleet_mess` = 1,`fleet_resource_metal` = '{$NewCargo['Metal']}',`fleet_resource_crystal` = '{$NewCargo['Crystal']}',`fleet_resource_deuterium` = '{$NewCargo['Deuterium']}' ";
    $QryUpdateFleet .= "WHERE `fleet_id` = '{$fleet_row['fleet_id']}' LIMIT 1;";
    doquery($QryUpdateFleet);
    return CACHE_FLEET | CACHE_PLANET_DST;
}
コード例 #2
0
ファイル: overview.php プロジェクト: hayalolsam/SuperNova
             throw new exception($lang['ov_teleport_err_wrong_coordinates'], ERR_ERROR);
         }
         sn_db_transaction_start();
         // При телепорте обновлять данные не надо - просто получить текущие данные и залочить их
         $user = db_user_by_id($user['id'], true, '*');
         $planetrow = db_planet_by_id($planetrow['id'], true, '*');
         //        $global_data = sys_o_get_updated($user, $planetrow['id'], SN_TIME_NOW);
         //        $user = $global_data['user'];
         //        $planetrow = $global_data['planet'];
         $can_teleport = uni_planet_teleport_check($user, $planetrow, $new_coordinates);
         if ($can_teleport['result'] != ERR_NONE) {
             throw new exception($can_teleport['message'], $can_teleport['result']);
         }
         rpg_points_change($user['id'], RPG_TELEPORT, -$config->planet_teleport_cost, array(&$lang['ov_teleport_log_record'], $planetrow['name'], $planetrow['id'], uni_render_coordinates($planetrow), uni_render_coordinates($new_coordinates)));
         $planet_teleport_next = SN_TIME_NOW + $config->planet_teleport_timeout;
         db_planet_set_by_gspt($planetrow['galaxy'], $planetrow['system'], $planetrow['planet'], PT_ALL, "galaxy = {$new_coordinates['galaxy']}, system = {$new_coordinates['system']}, planet = {$new_coordinates['planet']}, planet_teleport_next = {$planet_teleport_next}");
         if ($planetrow['id'] == $user['id_planet']) {
             db_user_set_by_id($user['id'], "galaxy = {$new_coordinates['galaxy']}, system = {$new_coordinates['system']}, planet = {$new_coordinates['planet']}");
         }
         // $global_data = sys_o_get_updated($user, $planetrow['id'], SN_TIME_NOW);
         sn_db_transaction_commit();
         $user = db_user_by_id($user['id'], true, '*');
         $planetrow = db_planet_by_id($planetrow['id'], true, '*');
         $result = array('STATUS' => ERR_NONE, 'MESSAGE' => $lang['ov_teleport_err_none']);
         sys_redirect('overview.php?mode=manage');
     } catch (exception $e) {
         sn_db_transaction_rollback();
         $result = array('STATUS' => $e->getCode(), 'MESSAGE' => $e->getMessage());
     }
 } elseif (sys_get_param_str('abandon')) {
     //if(sec_password_encode(sys_get_param('abandon_confirm'), $user['salt']) == $user['password']) {
コード例 #3
0
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};");
    }
}