mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-14 02:34:09 +02:00
Mtn: fix and port for 2.0
This commit is contained in:
parent
635faf6edf
commit
488fe67504
@ -206,6 +206,9 @@ local function get_market_item_list(rarity)
|
||||
if rarity > 10 then
|
||||
rarity = 10
|
||||
end
|
||||
local quality_list = Public.get('quality_list')
|
||||
local quality_level = random(1, #quality_list)
|
||||
local quality = quality_list[quality_level]
|
||||
local types = get_types()
|
||||
local list = {}
|
||||
for i = 1, 9 do
|
||||
@ -220,7 +223,7 @@ local function get_market_item_list(rarity)
|
||||
if price > 64000 then
|
||||
price = 64000
|
||||
end
|
||||
list[#list + 1] = { price = { { name = 'coin', count = price } }, offer = { type = 'give-item', item = k } }
|
||||
list[#list + 1] = { price = { { name = 'coin', count = price * quality_level, quality = quality } }, offer = { type = 'give-item', item = k, quality = quality } }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -31,36 +31,44 @@ local entities_that_earn_coins = {
|
||||
['flamethrower-turret'] = true
|
||||
}
|
||||
|
||||
local function check_quality()
|
||||
local quality_list = Public.get('quality_list')
|
||||
local quality_level = random(1, #quality_list)
|
||||
local quality = quality_list[quality_level]
|
||||
return quality
|
||||
end
|
||||
|
||||
--extra coins for "boss" biters from biter_health_booster.lua
|
||||
local function get_coin_count(entity)
|
||||
local coin_count = coin_yield[entity.name]
|
||||
if not coin_count then
|
||||
return
|
||||
end
|
||||
local quality = check_quality()
|
||||
local biter_health_boost_units = BiterHealthBooster.get('biter_health_boost_units')
|
||||
|
||||
if not biter_health_boost_units then
|
||||
return coin_count
|
||||
return coin_count, quality
|
||||
end
|
||||
local unit_number = entity.unit_number
|
||||
if not unit_number then
|
||||
return coin_count
|
||||
return coin_count, quality
|
||||
end
|
||||
if not biter_health_boost_units[unit_number] then
|
||||
return coin_count
|
||||
return coin_count, quality
|
||||
end
|
||||
if not biter_health_boost_units[unit_number][3] then
|
||||
return coin_count
|
||||
return coin_count, quality
|
||||
end
|
||||
if not biter_health_boost_units[unit_number][3].healthbar_id then -- only bosses
|
||||
return coin_count
|
||||
return coin_count, quality
|
||||
end
|
||||
local m = 1 / biter_health_boost_units[unit_number][2]
|
||||
coin_count = floor(coin_count * m)
|
||||
if coin_count < 1 then
|
||||
return 1
|
||||
end
|
||||
return coin_count
|
||||
return coin_count, quality
|
||||
end
|
||||
|
||||
---comment
|
||||
@ -78,7 +86,7 @@ local function on_entity_died(event)
|
||||
|
||||
local cause = event.cause
|
||||
|
||||
local coin_count = get_coin_count(entity)
|
||||
local coin_count, quality = get_coin_count(entity)
|
||||
if not coin_count then
|
||||
return
|
||||
end
|
||||
@ -124,13 +132,13 @@ local function on_entity_died(event)
|
||||
end
|
||||
if forest_zone then
|
||||
if random(1, 12) == 1 then
|
||||
player.insert({ name = 'coin', count = coin_count })
|
||||
player.insert({ name = 'coin', count = coin_count, quality = quality })
|
||||
if p then
|
||||
StatData.get_data(p.index):increase('coins', coin_count)
|
||||
end
|
||||
end
|
||||
else
|
||||
player.insert({ name = 'coin', count = coin_count })
|
||||
player.insert({ name = 'coin', count = coin_count, quality = quality })
|
||||
if p then
|
||||
StatData.get_data(p.index):increase('coins', coin_count)
|
||||
end
|
||||
@ -139,7 +147,7 @@ local function on_entity_died(event)
|
||||
end
|
||||
if not Public.get('final_battle') then
|
||||
if entities_that_earn_coins[cause.name] then
|
||||
event.entity.surface.spill_item_stack({ position = cause.position, stack = { name = 'coin', count = coin_count }, enable_looted = true })
|
||||
event.entity.surface.spill_item_stack({ position = cause.position, stack = { name = 'coin', count = coin_count, quality = quality }, enable_looted = true })
|
||||
reward_has_been_given = true
|
||||
end
|
||||
end
|
||||
@ -150,7 +158,7 @@ local function on_entity_died(event)
|
||||
end
|
||||
|
||||
if reward_has_been_given == false then
|
||||
event.entity.surface.spill_item_stack({ position = event.entity.position, stack = { name = 'coin', count = coin_count }, enable_looted = true })
|
||||
event.entity.surface.spill_item_stack({ position = event.entity.position, stack = { name = 'coin', count = coin_count, quality = quality }, enable_looted = true })
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -158,7 +158,7 @@ local spidertron_too_far =
|
||||
|
||||
local check_distance_between_player_and_locomotive = function (player)
|
||||
local surface = player.surface
|
||||
local position = player.position
|
||||
local position = player.physical_position
|
||||
local locomotive = Public.get('locomotive')
|
||||
if not locomotive or not locomotive.valid then
|
||||
return
|
||||
@ -221,7 +221,7 @@ local check_distance_between_player_and_locomotive = function (player)
|
||||
end
|
||||
|
||||
local compare_player_pos = function (player)
|
||||
local p = player.position
|
||||
local p = player.physical_position
|
||||
local index = player.index
|
||||
local adjusted_zones = Public.get('adjusted_zones')
|
||||
if not adjusted_zones.size then
|
||||
@ -263,7 +263,7 @@ local compare_player_and_train = function (player, entity)
|
||||
|
||||
local car = ICF.get_car(entity.unit_number)
|
||||
|
||||
local position = player.position
|
||||
local position = player.physical_position
|
||||
local locomotive = Public.get('locomotive')
|
||||
if not locomotive or not locomotive.valid then
|
||||
return
|
||||
@ -323,13 +323,13 @@ end
|
||||
|
||||
local function distance(player)
|
||||
local index = player.index
|
||||
local bonus = RPG.get_value_from_player(index, 'bonus')
|
||||
local bonus = RPG.get_value_from_player(index, 'bonus') or 1
|
||||
local rpg_extra = RPG.get('rpg_extra')
|
||||
local breached_wall = Public.get('breached_wall')
|
||||
local bonus_xp_on_join = Public.get('bonus_xp_on_join')
|
||||
local enable_arties = Public.get('enable_arties')
|
||||
|
||||
local p = player.position
|
||||
local p = player.physical_position
|
||||
|
||||
local validate_spider = Public.get('validate_spider')
|
||||
if validate_spider[index] then
|
||||
@ -386,6 +386,7 @@ local function distance(player)
|
||||
Public.enemy_weapon_damage()
|
||||
local spidertron_unlocked_enabled = Public.get('spidertron_unlocked_enabled')
|
||||
if Public.get('breached_wall') >= Public.get('spidertron_unlocked_at_zone') and not spidertron_unlocked_enabled then
|
||||
local get_player_data = Public.get_player_data(player)
|
||||
Public.set('spidertron_unlocked_enabled', true)
|
||||
local main_market_items = Public.get('main_market_items')
|
||||
if not main_market_items['spidertron'] then
|
||||
@ -401,7 +402,7 @@ local function distance(player)
|
||||
main_market_items['spidertron'] = {
|
||||
stack = 1,
|
||||
value = 'coin',
|
||||
price = rng,
|
||||
price = rng * (get_player_data and get_player_data.quality or 1),
|
||||
tooltip = spider_tooltip,
|
||||
upgrade = false,
|
||||
static = true
|
||||
@ -462,11 +463,11 @@ local function on_player_changed_position(event)
|
||||
return
|
||||
end
|
||||
|
||||
if player.position.y > -100 and player.position.y < -100 then
|
||||
if player.physical_position.y > -100 and player.physical_position.y < -100 then
|
||||
return
|
||||
end
|
||||
|
||||
if player.position.y > 100 and player.position.y < 100 then
|
||||
if player.physical_position.y > 100 and player.physical_position.y < 100 then
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -36,7 +36,7 @@ local function draw_charging_gui(player, activate_custom_buttons)
|
||||
end
|
||||
|
||||
local function discharge_accumulators(surface, position, force, power_needs)
|
||||
local accumulators = surface.find_entities_filtered {name = 'accumulator', force = force, position = position, radius = 13}
|
||||
local accumulators = surface.find_entities_filtered { name = 'accumulator', force = force, position = position, radius = 13 }
|
||||
local power_drained = 0
|
||||
power_needs = power_needs * 1
|
||||
for _, accu in pairs(accumulators) do
|
||||
@ -75,7 +75,7 @@ local function charge(player)
|
||||
return player.print(module_name .. 'No valid armor to charge was found.', Color.warning)
|
||||
end
|
||||
|
||||
local ents = player.surface.find_entities_filtered {name = 'accumulator', force = player.force, position = player.position, radius = 13}
|
||||
local ents = player.surface.find_entities_filtered { name = 'accumulator', force = player.force, position = player.physical_position, radius = 13 }
|
||||
if not ents or not next(ents) then
|
||||
return player.print(module_name .. 'No accumulators nearby.', Color.warning)
|
||||
end
|
||||
@ -85,7 +85,7 @@ local function charge(player)
|
||||
if piece.valid and piece.generator_power == 0 then
|
||||
local energy_needs = piece.max_energy - piece.energy
|
||||
if energy_needs > 0 then
|
||||
local energy = discharge_accumulators(player.surface, player.position, player.force, energy_needs)
|
||||
local energy = discharge_accumulators(player.surface, player.physical_position, player.force, energy_needs)
|
||||
if energy > 0 then
|
||||
if piece.energy + energy >= piece.max_energy then
|
||||
piece.energy = piece.max_energy
|
||||
@ -123,7 +123,7 @@ end
|
||||
|
||||
Gui.on_click(
|
||||
charging_station_name,
|
||||
function(event)
|
||||
function (event)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
@ -142,7 +142,7 @@ Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
|
||||
Event.add(
|
||||
BottomFrame.events.bottom_quickbar_location_changed,
|
||||
function(event)
|
||||
function (event)
|
||||
local player_index = event.player_index
|
||||
if not player_index then
|
||||
return
|
||||
|
@ -498,7 +498,7 @@ local unstuck_player_token =
|
||||
end
|
||||
|
||||
local surface = player.surface
|
||||
local position = surface.find_non_colliding_position('character', player.position, 32, 1)
|
||||
local position = surface.find_non_colliding_position('character', player.physical_position, 32, 1)
|
||||
if not position then
|
||||
return
|
||||
end
|
||||
@ -734,6 +734,7 @@ local function on_player_mined_entity(event)
|
||||
return
|
||||
end
|
||||
local rpg_char = RPG.get_value_from_player(player.index)
|
||||
if not rpg_char then return end
|
||||
|
||||
if string.sub(entity.surface.name, 0, #scenario_name) ~= scenario_name then
|
||||
return
|
||||
@ -1318,7 +1319,7 @@ function Public.unstuck_player(index)
|
||||
end
|
||||
|
||||
local surface = player.surface
|
||||
local position = surface.find_non_colliding_position('character', player.position, 32, 1)
|
||||
local position = surface.find_non_colliding_position('character', player.physical_position, 32, 1)
|
||||
if not position then
|
||||
return
|
||||
end
|
||||
@ -1513,8 +1514,6 @@ local function on_built_entity(event)
|
||||
local upgrades = Public.get('upgrades')
|
||||
|
||||
local upg = upgrades
|
||||
local surface = entity.surface
|
||||
|
||||
local built = {
|
||||
['land-mine'] = upg.landmine.built,
|
||||
['flamethrower-turret'] = upg.flame_turret.built
|
||||
|
@ -1026,16 +1026,16 @@ function Public.find_void_tiles_and_replace()
|
||||
local rp = Collapse.get_reverse_position()
|
||||
|
||||
local area = {
|
||||
left_top = { x = (-zone_settings.zone_width / 2) + 10, y = cp.y },
|
||||
right_bottom = { x = (zone_settings.zone_width / 2) - 10, y = rp.y }
|
||||
left_top = { x = (-zone_settings.zone_width / 2) + 10, y = -rp.y - 1000 },
|
||||
right_bottom = { x = (zone_settings.zone_width / 2) - 10, y = cp.y }
|
||||
}
|
||||
|
||||
local adjusted_zones = Public.get('adjusted_zones')
|
||||
|
||||
if adjusted_zones.reversed then
|
||||
area = {
|
||||
left_top = { x = ((zone_settings.zone_width / 2) + 10) * -1, y = rp.y },
|
||||
right_bottom = { x = math.abs((-zone_settings.zone_width / 2) - 10), y = cp.y },
|
||||
left_top = { x = ((zone_settings.zone_width / 2) + 10) * -1, y = cp.y },
|
||||
right_bottom = { x = math.abs((-zone_settings.zone_width / 2) - 10), y = rp.y },
|
||||
}
|
||||
end
|
||||
|
||||
@ -1487,7 +1487,7 @@ function Public.on_player_joined_game(event)
|
||||
end
|
||||
end
|
||||
|
||||
if player.surface.index ~= active_surface_index then
|
||||
if player.online_time < 1 then
|
||||
local pos = surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0)
|
||||
if pos then
|
||||
player.teleport(pos, surface)
|
||||
@ -1496,7 +1496,7 @@ function Public.on_player_joined_game(event)
|
||||
player.teleport(pos, surface)
|
||||
end
|
||||
else
|
||||
local p = { x = player.position.x, y = player.position.y }
|
||||
local p = { x = player.physical_position.x, y = player.physical_position.y }
|
||||
local get_tile = surface.get_tile(p.x, p.y)
|
||||
if get_tile.valid and get_tile.name == 'out-of-map' then
|
||||
local pos = surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0)
|
||||
@ -1518,9 +1518,9 @@ function Public.on_player_joined_game(event)
|
||||
local adjusted_zones = Public.get('adjusted_zones')
|
||||
local distance_from_train
|
||||
if adjusted_zones.reversed then
|
||||
distance_from_train = player.position.y < locomotive.position.y
|
||||
distance_from_train = player.physical_position.y < locomotive.position.y
|
||||
else
|
||||
distance_from_train = player.position.y > locomotive.position.y
|
||||
distance_from_train = player.physical_position.y > locomotive.position.y
|
||||
end
|
||||
|
||||
if distance_from_train then
|
||||
@ -1633,11 +1633,11 @@ function Public.on_player_changed_position(event)
|
||||
return
|
||||
end
|
||||
|
||||
local position = player.position
|
||||
local position = player.physical_position
|
||||
local surface = game.surfaces[active_surface_index]
|
||||
local adjusted_zones = Public.get('adjusted_zones')
|
||||
|
||||
local p = { x = player.position.x, y = player.position.y }
|
||||
local p = { x = player.physical_position.x, y = player.physical_position.y }
|
||||
local config_tile = Public.get('void_or_tile')
|
||||
if config_tile == 'lab-dark-2' then
|
||||
local get_tile = surface.get_tile(p.x, p.y)
|
||||
@ -1646,7 +1646,7 @@ function Public.on_player_changed_position(event)
|
||||
if random(1, 2) == 1 then
|
||||
show_text('This path is not for players!', p, surface, player)
|
||||
end
|
||||
player.surface.create_entity({ name = 'fire-flame', position = player.position })
|
||||
player.surface.create_entity({ name = 'fire-flame', position = player.physical_position })
|
||||
player.character.health = player.character.health - tile_damage
|
||||
if player.character.health == 0 then
|
||||
player.character.die()
|
||||
@ -1746,6 +1746,22 @@ function Public.on_research_finished(event)
|
||||
Public.set('toolbelt_researched_count', 10)
|
||||
end
|
||||
|
||||
if script.feature_flags.quality then
|
||||
local quality_list = Public.get('quality_list')
|
||||
if research.name == 'quality-module' then
|
||||
quality_list[#quality_list + 1] = 'uncommon'
|
||||
end
|
||||
if research.name == 'quality-module-2' then
|
||||
quality_list[#quality_list + 1] = 'rare'
|
||||
end
|
||||
if research.name == 'epic-quality' then
|
||||
quality_list[#quality_list + 1] = 'epic'
|
||||
end
|
||||
if research.name == 'legendary-quality' then
|
||||
quality_list[#quality_list + 1] = 'legendary'
|
||||
end
|
||||
end
|
||||
|
||||
research.force.character_inventory_slots_bonus = (player.mining_drill_productivity_bonus * 50) + (Public.get('toolbelt_researched_count') or 0)
|
||||
if bonus_drill then
|
||||
bonus_drill.mining_drill_productivity_bonus = bonus_drill.mining_drill_productivity_bonus + 0.03
|
||||
|
@ -230,6 +230,7 @@ local function do_place_buildings(data)
|
||||
then
|
||||
e.create_build_effect_smoke = false
|
||||
entity = surface.create_entity(e)
|
||||
entity.custom_status = { diode = defines.entity_status_diode.green, label = 'Custom building that generates free resources.' }
|
||||
if entity and entity.valid then
|
||||
if e.direction then
|
||||
entity.direction = e.direction
|
||||
|
@ -411,22 +411,6 @@ local function kick_players_out_of_vehicles(car)
|
||||
end
|
||||
end
|
||||
|
||||
local function check_if_players_are_in_nauvis()
|
||||
local allowed_surface = IC.get('allowed_surface')
|
||||
for _, player in pairs(game.connected_players) do
|
||||
local main_surface = game.surfaces[allowed_surface]
|
||||
if player.surface.name == 'nauvis' then
|
||||
local pos = main_surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(main_surface), 3, 0)
|
||||
if pos then
|
||||
player.teleport(pos, main_surface)
|
||||
else
|
||||
pos = game.forces.player.get_spawn_position(main_surface)
|
||||
player.teleport(pos, main_surface)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function exclude_surface(surface)
|
||||
for _, force in pairs(game.forces) do
|
||||
force.set_surface_hidden(surface, true)
|
||||
@ -442,7 +426,6 @@ local function kick_players_from_surface(car, owner_id)
|
||||
local surface = game.surfaces[surface_index]
|
||||
local allowed_surface = IC.get('allowed_surface')
|
||||
if not validate_entity(surface) then
|
||||
check_if_players_are_in_nauvis()
|
||||
return log_err('Car surface was not valid.')
|
||||
end
|
||||
if not car.entity or not car.entity.valid then
|
||||
@ -460,7 +443,6 @@ local function kick_players_from_surface(car, owner_id)
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
check_if_players_are_in_nauvis()
|
||||
return log_err('Car entity was not valid.')
|
||||
end
|
||||
end
|
||||
@ -479,7 +461,6 @@ local function kick_players_from_surface(car, owner_id)
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
check_if_players_are_in_nauvis()
|
||||
end
|
||||
|
||||
---Kicks players out of the car surface.
|
||||
@ -808,7 +789,7 @@ function Public.save_car(event)
|
||||
local find_remove_car_args = {
|
||||
index = p.surface.index,
|
||||
types = types,
|
||||
position = p.position
|
||||
position = p.physical_position
|
||||
}
|
||||
|
||||
Task.set_timeout_in_ticks(1, find_remove_car, find_remove_car_args)
|
||||
@ -1446,7 +1427,7 @@ function Public.use_door_with_entity(player, door)
|
||||
end
|
||||
|
||||
local area = car.area
|
||||
local x_vector = door.position.x - player.position.x
|
||||
local x_vector = door.position.x - player.physical_position.x
|
||||
local position
|
||||
if x_vector > 0 then
|
||||
position = { area.left_top.x + 0.5, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5) }
|
||||
|
@ -209,8 +209,8 @@ local function teleport_char(position, destination_area, wagon)
|
||||
local player = e.player
|
||||
if player then
|
||||
position[player.index] = {
|
||||
player.position.x,
|
||||
player.position.y + (destination_area.left_top.y - wagon.area.left_top.y)
|
||||
player.physical_position.x,
|
||||
player.physical_position.y + (destination_area.left_top.y - wagon.area.left_top.y)
|
||||
}
|
||||
player.teleport({ 0, 0 }, game.surfaces.nauvis)
|
||||
end
|
||||
@ -671,7 +671,7 @@ function Public.create_wagon_room(icw, wagon)
|
||||
end
|
||||
|
||||
if wagon.entity.type == 'cargo-wagon' then
|
||||
Task.set_timeout_in_ticks(5, add_chests_to_wagon_token, { wagon = wagon, surface = surface })
|
||||
Task.set_timeout_in_ticks(15, add_chests_to_wagon_token, { wagon = wagon, surface = surface })
|
||||
end
|
||||
end
|
||||
|
||||
@ -819,7 +819,7 @@ function Public.use_cargo_wagon_door_with_entity(icw, player, door)
|
||||
return
|
||||
end
|
||||
local area = wagon.area
|
||||
local x_vector = door.position.x - player.position.x
|
||||
local x_vector = door.position.x - player.physical_position.x
|
||||
local position
|
||||
if x_vector > 0 then
|
||||
position = { area.left_top.x + 0.5, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5) }
|
||||
|
@ -1412,7 +1412,7 @@ local function on_player_changed_position(event)
|
||||
left_top = { x = position.x - 8, y = position.y - 8 },
|
||||
right_bottom = { x = position.x + 8, y = position.y + 8 }
|
||||
}
|
||||
if Math2D.bounding_box.contains_point(area, player.position) then
|
||||
if Math2D.bounding_box.contains_point(area, player.physical_position) then
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -77,14 +77,14 @@ local function add_random_loot_to_main_market(rarity)
|
||||
end
|
||||
|
||||
for _, v in pairs(items) do
|
||||
local price = v.price[1][2] + random(1, 15) * rarity
|
||||
local value = v.price[1][1]
|
||||
local price = v.price[1].count + random(1, 15) * rarity
|
||||
local value = v.price[1].name
|
||||
local stack = 1
|
||||
if v.offer.item == 'coin' then
|
||||
price = v.price[1][2]
|
||||
price = v.price[1].count
|
||||
stack = v.offer.count
|
||||
if not stack then
|
||||
stack = v.price[1][2]
|
||||
stack = v.price[1].count
|
||||
end
|
||||
end
|
||||
|
||||
@ -101,7 +101,7 @@ local function add_random_loot_to_main_market(rarity)
|
||||
end
|
||||
|
||||
local function death_effects(player)
|
||||
local position = { x = player.position.x - 0.75, y = player.position.y - 1 }
|
||||
local position = { x = player.physical_position.x - 0.75, y = player.physical_position.y - 1 }
|
||||
local b = 0.75
|
||||
for _ = 1, 5, 1 do
|
||||
local p = {
|
||||
@ -187,7 +187,7 @@ local function hurt_players_outside_of_aura()
|
||||
Core.iter_connected_players(
|
||||
function (player)
|
||||
if sub(player.surface.name, 0, #scenario_name) == scenario_name then
|
||||
local position = player.position
|
||||
local position = player.physical_position
|
||||
local inside = ((position.x - loco.x) ^ 2 + (position.y - loco.y) ^ 2) < upgrades.locomotive_aura_radius ^ 2
|
||||
if not inside then
|
||||
local entity = player.character
|
||||
@ -262,7 +262,7 @@ local function give_passive_xp(data)
|
||||
|
||||
Core.iter_connected_players(
|
||||
function (player)
|
||||
local position = player.position
|
||||
local position = player.physical_position
|
||||
local inside = ((position.x - loco.x) ^ 2 + (position.y - loco.y) ^ 2) < upgrades.locomotive_aura_radius ^ 2
|
||||
if player.afk_time < 200 and not RPG.get_last_spell_cast(player) then
|
||||
if inside or player.surface.index == loco_surface.index then
|
||||
@ -279,7 +279,7 @@ local function give_passive_xp(data)
|
||||
Modifiers.update_single_modifier(player, 'character_crafting_speed_modifier', 'aura', 1)
|
||||
Modifiers.update_player_modifiers(player)
|
||||
|
||||
local pos = player.position
|
||||
local pos = player.physical_position
|
||||
RPG.gain_xp(player, 0.5 * (rpg[player.index].bonus + upgrades.xp_points))
|
||||
|
||||
player.create_local_flying_text {
|
||||
@ -291,7 +291,7 @@ local function give_passive_xp(data)
|
||||
}
|
||||
rpg[player.index].xp_since_last_floaty_text = 0
|
||||
rpg[player.index].last_floaty_text = game.tick + visuals_delay
|
||||
RPG.set_last_spell_cast(player, player.position)
|
||||
RPG.set_last_spell_cast(player, player.physical_position)
|
||||
if player.gui.screen[rpg_main_frame] then
|
||||
local f = player.gui.screen[rpg_main_frame]
|
||||
local d = Gui.get_data(f)
|
||||
@ -568,16 +568,6 @@ local function on_player_changed_surface(event)
|
||||
end
|
||||
end
|
||||
|
||||
if player.surface.name == 'nauvis' then
|
||||
local pos = surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0)
|
||||
if pos then
|
||||
player.teleport(pos, surface)
|
||||
else
|
||||
pos = game.forces.player.get_spawn_position(surface)
|
||||
player.teleport(pos, surface)
|
||||
end
|
||||
end
|
||||
|
||||
local locomotive_surface = Public.get('loco_surface')
|
||||
|
||||
if locomotive_surface and locomotive_surface.valid and player.surface.index == locomotive_surface.index then
|
||||
@ -589,32 +579,6 @@ local function on_player_changed_surface(event)
|
||||
end
|
||||
end
|
||||
|
||||
local function check_on_player_changed_surface()
|
||||
local active_surface = Public.get('active_surface_index')
|
||||
if not active_surface then
|
||||
return
|
||||
end
|
||||
|
||||
local surface = game.get_surface(active_surface)
|
||||
if not surface or not surface.valid then
|
||||
return
|
||||
end
|
||||
|
||||
Core.iter_players(
|
||||
function (player)
|
||||
if player.surface.name == 'nauvis' then
|
||||
local pos = surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0)
|
||||
if pos then
|
||||
player.teleport(pos, surface)
|
||||
else
|
||||
pos = game.forces.player.get_spawn_position(surface)
|
||||
player.teleport(pos, surface)
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
local function on_player_driving_changed_state(event)
|
||||
local player = game.players[event.player_index]
|
||||
if not player or not player.valid then
|
||||
@ -863,7 +827,7 @@ local function tick()
|
||||
local ticker = game.tick
|
||||
|
||||
if ticker % 30 == 0 then
|
||||
check_on_player_changed_surface()
|
||||
-- check_on_player_changed_surface()
|
||||
set_locomotive_health()
|
||||
validate_index()
|
||||
fish_tag()
|
||||
|
@ -41,8 +41,72 @@ local function add_space(frame)
|
||||
add_style(frame.add { type = 'line', direction = 'horizontal' }, space)
|
||||
end
|
||||
|
||||
function get_player_data(player, remove)
|
||||
local storage_data = Public.get('player_market_settings')
|
||||
if not storage_data then
|
||||
Public.set('player_market_settings', {})
|
||||
storage_data = Public.get('player_market_settings')
|
||||
end
|
||||
|
||||
local function get_items()
|
||||
local data = storage_data[player.name]
|
||||
if remove and data then
|
||||
storage_data[player.name] = nil
|
||||
return
|
||||
end
|
||||
|
||||
if not storage_data[player.name] then
|
||||
storage_data[player.name] = {
|
||||
quality = 1,
|
||||
}
|
||||
end
|
||||
|
||||
return storage_data[player.name]
|
||||
end
|
||||
|
||||
local function get_player_quality(player)
|
||||
if not player or not player.valid then
|
||||
return 'normal'
|
||||
end
|
||||
|
||||
local quality_list = Public.get('quality_list')
|
||||
|
||||
local player_data = get_player_data(player)
|
||||
local quality = quality_list[player_data.quality]
|
||||
return string.lower(quality)
|
||||
end
|
||||
|
||||
local function get_player_quality_int(player)
|
||||
if not player or not player.valid then
|
||||
return 'normal'
|
||||
end
|
||||
|
||||
local player_data = get_player_data(player)
|
||||
return player_data.quality
|
||||
end
|
||||
|
||||
local function get_item_count(player, name)
|
||||
if not player or not player.valid then
|
||||
return 0
|
||||
end
|
||||
|
||||
local player_data = get_player_data(player)
|
||||
local quality_list = Public.get('quality_list')
|
||||
local quality = quality_list[player_data.quality]
|
||||
local inventory = player.get_main_inventory()
|
||||
return inventory.get_item_count({ name = name, quality = quality })
|
||||
end
|
||||
|
||||
local function remove_item_count(player, name, count)
|
||||
if not player or not player.valid then
|
||||
return 0
|
||||
end
|
||||
local player_data = get_player_data(player)
|
||||
local quality_list = Public.get('quality_list')
|
||||
local quality = quality_list[player_data.quality]
|
||||
player.remove_item({ name = name, count = count, quality = quality })
|
||||
end
|
||||
|
||||
local function get_items(player)
|
||||
local market_limits = Public.get('market_limits')
|
||||
local main_market_items = Public.get('main_market_items')
|
||||
local flame_turret = Public.get('upgrades').flame_turret.bought
|
||||
@ -62,6 +126,8 @@ local function get_items()
|
||||
|
||||
local pickaxe_upgrades = Public.pickaxe_upgrades
|
||||
|
||||
local quality_price = get_player_quality_int(player)
|
||||
|
||||
local offer = pickaxe_upgrades[upgrades.pickaxe_tier]
|
||||
|
||||
if upgrades.pickaxe_tier >= market_limits.pickaxe_tier_limit then
|
||||
@ -539,6 +605,12 @@ local function get_items()
|
||||
static = true
|
||||
}
|
||||
|
||||
for _, item in pairs(main_market_items) do
|
||||
if item.static then
|
||||
item.price = item.price * quality_price
|
||||
end
|
||||
end
|
||||
|
||||
return main_market_items
|
||||
end
|
||||
|
||||
@ -590,8 +662,7 @@ local function redraw_market_items(gui, player, search_text)
|
||||
gui.clear()
|
||||
end
|
||||
|
||||
local inventory = player.get_main_inventory()
|
||||
local player_item_count
|
||||
local player_item_count = 0
|
||||
|
||||
if not (gui and gui.valid) then
|
||||
return
|
||||
@ -608,7 +679,9 @@ local function redraw_market_items(gui, player, search_text)
|
||||
|
||||
local upgrade_table = gui.add({ type = 'table', column_count = 6 })
|
||||
|
||||
for item, data in pairs(get_items()) do
|
||||
local quality = get_player_quality(player)
|
||||
|
||||
for item, data in pairs(get_items(player)) do
|
||||
if data.upgrade then
|
||||
if not search_text then
|
||||
goto continue
|
||||
@ -625,7 +698,7 @@ local function redraw_market_items(gui, player, search_text)
|
||||
local frame = upgrade_table.add({ type = 'flow' })
|
||||
frame.style.vertical_align = 'bottom'
|
||||
|
||||
player_item_count = inventory.get_item_count(data.value)
|
||||
player_item_count = get_item_count(player, data.value)
|
||||
|
||||
local button =
|
||||
frame.add(
|
||||
@ -644,7 +717,7 @@ local function redraw_market_items(gui, player, search_text)
|
||||
frame.add(
|
||||
{
|
||||
type = 'label',
|
||||
caption = concat { '[item=', data.value, ']: ' } .. format_number(item_cost, true)
|
||||
caption = concat { '[item=', data.value, ',quality=' .. quality .. ']: ' } .. format_number(item_cost, true)
|
||||
}
|
||||
)
|
||||
label.style.font = 'default-bold'
|
||||
@ -667,7 +740,7 @@ local function redraw_market_items(gui, player, search_text)
|
||||
local slider_value = ceil(players[player.index].data.slider.slider_value)
|
||||
local items_table = gui.add({ type = 'table', column_count = 6 })
|
||||
|
||||
for item, data in pairs(get_items()) do
|
||||
for item, data in pairs(get_items(player)) do
|
||||
if not data.upgrade then
|
||||
if not search_text then
|
||||
goto continue
|
||||
@ -684,7 +757,7 @@ local function redraw_market_items(gui, player, search_text)
|
||||
local frame = items_table.add({ type = 'flow' })
|
||||
frame.style.vertical_align = 'bottom'
|
||||
|
||||
player_item_count = inventory.get_item_count(data.value)
|
||||
player_item_count = get_item_count(player, data.value)
|
||||
|
||||
local button =
|
||||
frame.add(
|
||||
@ -717,7 +790,7 @@ local function redraw_market_items(gui, player, search_text)
|
||||
frame.add(
|
||||
{
|
||||
type = 'label',
|
||||
caption = concat { '[item=', data.value, ']: ' } .. format_number(item_cost, true)
|
||||
caption = concat { '[item=', data.value, ',quality=' .. quality .. ']: ' } .. format_number(item_cost, true)
|
||||
}
|
||||
)
|
||||
label.style.font = 'default-bold'
|
||||
@ -736,8 +809,7 @@ local function redraw_coins_left(gui, player)
|
||||
end
|
||||
|
||||
gui.clear()
|
||||
local inventory = player.get_main_inventory()
|
||||
local player_item_count = inventory.get_item_count('coin')
|
||||
local player_item_count = get_item_count(player, 'coin')
|
||||
|
||||
local coinsleft =
|
||||
gui.add(
|
||||
@ -867,8 +939,7 @@ local function gui_opened(event)
|
||||
return
|
||||
end
|
||||
|
||||
local inventory = player.get_main_inventory()
|
||||
local player_item_count = inventory.get_item_count('coin')
|
||||
local player_item_count = get_item_count(player, 'coin')
|
||||
|
||||
local players = Public.get('players')
|
||||
if not players then
|
||||
@ -953,6 +1024,32 @@ local function gui_opened(event)
|
||||
}
|
||||
)
|
||||
|
||||
if script.feature_flags.quality then
|
||||
if game.forces.player.technologies['quality-module'].researched then
|
||||
local quality_list = Public.get('quality_list')
|
||||
local bg_right = bottom_grid.add({ type = 'label', caption = ({ 'locomotive.quality_text' }) })
|
||||
bg_right.style.font = 'default-bold'
|
||||
|
||||
local player_data = get_player_data(player)
|
||||
|
||||
local qual = {}
|
||||
for _, quality in pairs(quality_list) do
|
||||
qual[#qual + 1] = quality:gsub("^%l", string.upper)
|
||||
end
|
||||
|
||||
local text_input_right =
|
||||
bottom_grid.add(
|
||||
{
|
||||
name = 'quality',
|
||||
type = 'drop-down',
|
||||
items = qual,
|
||||
selected_index = player_data and player_data.quality or 1,
|
||||
}
|
||||
)
|
||||
text_input_right.style.maximal_height = 28
|
||||
end
|
||||
end
|
||||
|
||||
players[player.index].data.search_text = search_text
|
||||
players[player.index].data.text_input = text_input
|
||||
players[player.index].data.slider = slider
|
||||
@ -1005,13 +1102,12 @@ local function gui_click(event)
|
||||
if not data then
|
||||
return
|
||||
end
|
||||
local item = get_items()[name]
|
||||
local item = get_items(player)[name]
|
||||
if not item then
|
||||
return
|
||||
end
|
||||
|
||||
local inventory = player.get_main_inventory()
|
||||
local player_item_count = inventory.get_item_count(item.value)
|
||||
local player_item_count = get_item_count(player, item.value)
|
||||
local slider_value = ceil(data.slider.slider_value)
|
||||
local cost = (item.price * slider_value)
|
||||
local item_count = item.stack * slider_value
|
||||
@ -1029,7 +1125,7 @@ local function gui_click(event)
|
||||
player.print(({ 'locomotive.limit_reached' }), { r = 0.98, g = 0.66, b = 0.22 })
|
||||
return
|
||||
end
|
||||
player.remove_item({ name = item.value, count = item.price })
|
||||
remove_item_count(player, item.value, item.price)
|
||||
|
||||
player.insert({ name = name, count = item.stack })
|
||||
|
||||
@ -1049,7 +1145,7 @@ local function gui_click(event)
|
||||
end
|
||||
|
||||
if name == 'upgrade_pickaxe' then
|
||||
player.remove_item({ name = item.value, count = item.price })
|
||||
remove_item_count(player, item.value, item.price)
|
||||
|
||||
Event.raise(Public.events.on_market_item_purchased, { cost = item.price })
|
||||
|
||||
@ -1083,7 +1179,7 @@ local function gui_click(event)
|
||||
return
|
||||
end
|
||||
if name == 'locomotive_max_health' then
|
||||
player.remove_item({ name = item.value, count = item.price })
|
||||
remove_item_count(player, item.value, item.price)
|
||||
local message = ({ 'locomotive.health_bought_info', shopkeeper, player.name, format_number(item.price, true) })
|
||||
|
||||
Event.raise(Public.events.on_market_item_purchased, { cost = item.price })
|
||||
@ -1140,7 +1236,8 @@ local function gui_click(event)
|
||||
player.print(({ 'locomotive.limit_reached' }), { r = 0.98, g = 0.66, b = 0.22 })
|
||||
return
|
||||
end
|
||||
player.remove_item({ name = item.value, count = item.price })
|
||||
remove_item_count(player, item.value, item.price)
|
||||
|
||||
|
||||
Event.raise(Public.events.on_market_item_purchased, { cost = item.price })
|
||||
|
||||
@ -1183,7 +1280,7 @@ local function gui_click(event)
|
||||
end
|
||||
|
||||
if name == 'xp_points_boost' then
|
||||
player.remove_item({ name = item.value, count = item.price })
|
||||
remove_item_count(player, item.value, item.price)
|
||||
local message = ({ 'locomotive.xp_bought_info', shopkeeper, player.name, format_number(item.price, true) })
|
||||
|
||||
Event.raise(Public.events.on_market_item_purchased, { cost = item.price })
|
||||
@ -1205,7 +1302,7 @@ local function gui_click(event)
|
||||
end
|
||||
|
||||
if name == 'redraw_mystical_chest' then
|
||||
player.remove_item({ name = item.value, count = item.price })
|
||||
remove_item_count(player, item.value, item.price)
|
||||
local message = ({ 'locomotive.mystical_bought_info', shopkeeper, player.name, format_number(item.price, true) })
|
||||
|
||||
Event.raise(Public.events.on_market_item_purchased, { cost = item.price })
|
||||
@ -1226,7 +1323,7 @@ local function gui_click(event)
|
||||
end
|
||||
|
||||
if name == 'explosive_bullets' then
|
||||
player.remove_item({ name = item.value, count = item.price })
|
||||
remove_item_count(player, item.value, item.price)
|
||||
local message = ({
|
||||
'locomotive.explosive_bullet_bought_info',
|
||||
shopkeeper,
|
||||
@ -1252,7 +1349,7 @@ local function gui_click(event)
|
||||
end
|
||||
|
||||
if name == 'car_health_upgrade_pool' then
|
||||
player.remove_item({ name = item.value, count = item.price })
|
||||
remove_item_count(player, item.value, item.price)
|
||||
local message = ({
|
||||
'locomotive.car_health_upgrade_pool_bought_info',
|
||||
shopkeeper,
|
||||
@ -1277,7 +1374,7 @@ local function gui_click(event)
|
||||
end
|
||||
|
||||
if name == 'upgraded_tile_when_mining_cost' then
|
||||
player.remove_item({ name = item.value, count = item.price })
|
||||
remove_item_count(player, item.value, item.price)
|
||||
local message = ({
|
||||
'locomotive.tile_upgrade_bought_info',
|
||||
shopkeeper,
|
||||
@ -1302,7 +1399,7 @@ local function gui_click(event)
|
||||
end
|
||||
|
||||
if name == 'flamethrower_turrets' then
|
||||
player.remove_item({ name = item.value, count = item.price })
|
||||
remove_item_count(player, item.value, item.price)
|
||||
Event.raise(Public.events.on_market_item_purchased, { cost = item.price })
|
||||
|
||||
if item.stack >= 1 then
|
||||
@ -1342,7 +1439,8 @@ local function gui_click(event)
|
||||
return
|
||||
end
|
||||
if name == 'land_mine' then
|
||||
player.remove_item({ name = item.value, count = item.price })
|
||||
remove_item_count(player, item.value, item.price)
|
||||
|
||||
|
||||
Event.raise(Public.events.on_market_item_purchased, { cost = item.price })
|
||||
|
||||
@ -1373,19 +1471,22 @@ local function gui_click(event)
|
||||
return
|
||||
end
|
||||
|
||||
local quality = get_player_quality(player)
|
||||
|
||||
if player_item_count >= cost then
|
||||
if player.can_insert({ name = name, count = item_count }) then
|
||||
if player.can_insert({ name = name, count = item_count, quality = quality }) then
|
||||
player.play_sound({ path = 'entity-close/stone-furnace', volume_modifier = 0.65 })
|
||||
local inserted_count = player.insert({ name = name, count = item_count })
|
||||
local inserted_count = player.insert({ name = name, count = item_count, quality = quality })
|
||||
if inserted_count < item_count then
|
||||
player.play_sound({ path = 'utility/cannot_build', volume_modifier = 0.65 })
|
||||
player.print(({ 'locomotive.full_inventory', inserted_count, name }), { r = 0.98, g = 0.66, b = 0.22 })
|
||||
player.print(({ 'locomotive.change_returned' }), { r = 0.98, g = 0.66, b = 0.22 })
|
||||
player.insert({ name = name, count = inserted_count })
|
||||
player.remove_item({ name = item.value, count = ceil(item.price * (inserted_count / item.stack)) })
|
||||
player.insert({ name = name, count = inserted_count, quality = quality })
|
||||
remove_item_count(player, item.value, ceil(item.price * (inserted_count / item.stack)))
|
||||
|
||||
Event.raise(Public.events.on_market_item_purchased, { cost = ceil(item.price * (inserted_count / item.stack)) })
|
||||
else
|
||||
player.remove_item({ name = item.value, count = cost })
|
||||
remove_item_count(player, item.value, cost)
|
||||
Event.raise(Public.events.on_market_item_purchased, { cost = cost })
|
||||
end
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
@ -1420,6 +1521,26 @@ local function gui_closed(event)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_gui_selection_state_changed(event)
|
||||
local name = event.element.name
|
||||
local player = game.get_player(event.player_index)
|
||||
local selected_index = event.element.selected_index
|
||||
if name == 'quality' then
|
||||
local player_data = get_player_data(player)
|
||||
player_data.quality = selected_index
|
||||
end
|
||||
|
||||
local players = Public.get('players')
|
||||
if not players then
|
||||
return
|
||||
end
|
||||
local data = players[player.index].data
|
||||
if not data then
|
||||
return
|
||||
end
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
end
|
||||
|
||||
local function on_player_changed_position(event)
|
||||
local players = Public.get('players')
|
||||
if not players then
|
||||
@ -1443,7 +1564,7 @@ local function on_player_changed_position(event)
|
||||
left_top = { x = position.x - 10, y = position.y - 10 },
|
||||
right_bottom = { x = position.x + 10, y = position.y + 10 }
|
||||
}
|
||||
if Math2D.bounding_box.contains_point(area, player.position) then
|
||||
if Math2D.bounding_box.contains_point(area, player.physical_position) then
|
||||
return
|
||||
end
|
||||
if not data then
|
||||
@ -1587,6 +1708,9 @@ local function place_market()
|
||||
|
||||
local icw_table = ICW.get_table()
|
||||
local unit_surface = locomotive.unit_number
|
||||
if not icw_table.wagons[unit_surface] then
|
||||
return
|
||||
end
|
||||
local surface = game.surfaces[icw_table.wagons[unit_surface].surface.index]
|
||||
local market = Public.get('market')
|
||||
|
||||
@ -1654,7 +1778,10 @@ Event.add(defines.events.on_gui_click, gui_click)
|
||||
Event.add(defines.events.on_gui_value_changed, slider_changed)
|
||||
Event.add(defines.events.on_gui_text_changed, text_changed)
|
||||
Event.add(defines.events.on_player_changed_position, on_player_changed_position)
|
||||
Event.add(defines.events.on_gui_selection_state_changed, on_gui_selection_state_changed)
|
||||
Event.add(defines.events.on_gui_opened, gui_opened)
|
||||
Event.add(defines.events.on_gui_closed, gui_closed)
|
||||
|
||||
Public.get_player_data = get_player_data
|
||||
|
||||
return Public
|
||||
|
@ -145,23 +145,31 @@ function Public.locomotive_spawn(surface, position, reversed)
|
||||
surface.create_entity({ name = 'straight-rail', position = { position.x, position.y + y }, force = 'player', direction = 0 })
|
||||
end
|
||||
this.locomotive = surface.create_entity({ name = 'locomotive', position = { position.x, position.y + -3 }, force = 'player', direction = defines.direction.south, quality = quality })
|
||||
this.locomotive.get_inventory(defines.inventory.fuel).insert({ name = 'wood', count = 100 })
|
||||
if this.locomotive and this.locomotive.valid then
|
||||
this.locomotive.get_inventory(defines.inventory.fuel).insert({ name = 'wood', count = 100 })
|
||||
end
|
||||
|
||||
this.locomotive_cargo = surface.create_entity({ name = 'cargo-wagon', position = { position.x, position.y + 3 }, force = 'player', direction = defines.direction.south, quality = quality })
|
||||
this.locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert({ name = 'raw-fish', count = 8 })
|
||||
if this.locomotive_cargo and this.locomotive_cargo.valid then
|
||||
this.locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert({ name = 'raw-fish', count = 8 })
|
||||
end
|
||||
else
|
||||
for y = -6, 6, 2 do
|
||||
surface.create_entity({ name = 'straight-rail', position = { position.x, position.y + y }, force = 'player', direction = 0 })
|
||||
end
|
||||
this.locomotive = surface.create_entity({ name = 'locomotive', position = { position.x, position.y + -3 }, force = 'player', quality = quality })
|
||||
this.locomotive.get_inventory(defines.inventory.fuel).insert({ name = 'wood', count = 100 })
|
||||
if this.locomotive and this.locomotive.valid then
|
||||
this.locomotive.get_inventory(defines.inventory.fuel).insert({ name = 'wood', count = 100 })
|
||||
end
|
||||
|
||||
this.locomotive_cargo = surface.create_entity({ name = 'cargo-wagon', position = { position.x, position.y + 3 }, force = 'player', quality = quality })
|
||||
this.locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert({ name = 'raw-fish', count = 8 })
|
||||
if this.locomotive_cargo and this.locomotive_cargo.valid then
|
||||
this.locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert({ name = 'raw-fish', count = 8 })
|
||||
end
|
||||
end
|
||||
|
||||
local winter_mode_locomotive = Public.wintery(this.locomotive, 5.5)
|
||||
if not winter_mode_locomotive then
|
||||
if not winter_mode_locomotive and this.locomotive and this.locomotive.valid then
|
||||
rendering.draw_light(
|
||||
{
|
||||
sprite = 'utility/light_medium',
|
||||
@ -180,7 +188,7 @@ function Public.locomotive_spawn(surface, position, reversed)
|
||||
|
||||
local winter_mode_cargo = Public.wintery(this.locomotive_cargo, 5.5)
|
||||
|
||||
if not winter_mode_cargo then
|
||||
if not winter_mode_cargo and this.locomotive_cargo and this.locomotive_cargo.valid then
|
||||
rendering.draw_light(
|
||||
{
|
||||
sprite = 'utility/light_medium',
|
||||
|
@ -55,12 +55,20 @@ local scenario_name = Public.scenario_name
|
||||
local floor = math.floor
|
||||
local remove = table.remove
|
||||
local abs = math.abs
|
||||
local partial_reset
|
||||
RPG.disable_cooldowns_on_spells()
|
||||
Gui.mod_gui_button_enabled = true
|
||||
Gui.button_style = 'mod_gui_button'
|
||||
Gui.set_toggle_button(true)
|
||||
Gui.set_mod_gui_top_frame(true)
|
||||
|
||||
local partial_reset_token =
|
||||
Task.register(
|
||||
function ()
|
||||
partial_reset()
|
||||
end
|
||||
)
|
||||
|
||||
local collapse_kill = {
|
||||
entities = {
|
||||
['laser-turret'] = true,
|
||||
@ -116,22 +124,45 @@ local announce_new_map =
|
||||
end
|
||||
)
|
||||
|
||||
|
||||
partial_reset = function ()
|
||||
local this = Public.get()
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
|
||||
if this.adjusted_zones.reversed then
|
||||
Explosives.check_growth_below_void(false)
|
||||
this.spawn_near_collapse.compare = abs(this.spawn_near_collapse.compare)
|
||||
Collapse.set_position({ 0, -130 })
|
||||
Collapse.set_direction('south')
|
||||
Public.locomotive_spawn(surface, { x = -18, y = -25 }, this.adjusted_zones.reversed)
|
||||
else
|
||||
Explosives.check_growth_below_void(true)
|
||||
this.spawn_near_collapse.compare = abs(this.spawn_near_collapse.compare) * -1
|
||||
Collapse.set_position({ 0, 130 })
|
||||
Collapse.set_direction('north')
|
||||
Public.locomotive_spawn(surface, { x = -18, y = 25 }, this.adjusted_zones.reversed)
|
||||
end
|
||||
|
||||
Public.render_train_hp()
|
||||
Public.render_direction(surface, this.adjusted_zones.reversed)
|
||||
end
|
||||
|
||||
function Public.reset_map()
|
||||
rendering.clear()
|
||||
local this = Public.get()
|
||||
this.active_surface_index = Public.create_surface()
|
||||
|
||||
game.forces.player.reset()
|
||||
Public.reset_main_table()
|
||||
|
||||
Difficulty.show_gui(false)
|
||||
|
||||
local this = Public.get()
|
||||
local wave_defense_table = WD.get_table()
|
||||
Misc.reset()
|
||||
Misc.bottom_button(true)
|
||||
|
||||
LinkedChests.reset()
|
||||
|
||||
this.active_surface_index = Public.create_surface()
|
||||
this.old_surface_index = this.active_surface_index
|
||||
|
||||
Public.stateful.clear_all_frames()
|
||||
|
||||
Autostash.insert_into_furnace(true)
|
||||
@ -239,22 +270,6 @@ function Public.reset_map()
|
||||
this.locomotive_health = 10000
|
||||
this.locomotive_max_health = 10000
|
||||
|
||||
if this.adjusted_zones.reversed then
|
||||
Explosives.check_growth_below_void(false)
|
||||
this.spawn_near_collapse.compare = abs(this.spawn_near_collapse.compare)
|
||||
Collapse.set_position({ 0, -130 })
|
||||
Collapse.set_direction('south')
|
||||
Public.locomotive_spawn(surface, { x = -18, y = -25 }, this.adjusted_zones.reversed)
|
||||
else
|
||||
Explosives.check_growth_below_void(true)
|
||||
this.spawn_near_collapse.compare = abs(this.spawn_near_collapse.compare) * -1
|
||||
Collapse.set_position({ 0, 130 })
|
||||
Collapse.set_direction('north')
|
||||
Public.locomotive_spawn(surface, { x = -18, y = 25 }, this.adjusted_zones.reversed)
|
||||
end
|
||||
Public.render_train_hp()
|
||||
Public.render_direction(surface, this.adjusted_zones.reversed)
|
||||
|
||||
WD.reset_wave_defense()
|
||||
wave_defense_table.surface_index = this.active_surface_index
|
||||
wave_defense_table.target = this.locomotive
|
||||
@ -285,7 +300,7 @@ function Public.reset_map()
|
||||
|
||||
if this.adjusted_zones.reversed then
|
||||
if not surface.is_chunk_generated({ x = -20, y = -22 }) then
|
||||
surface.request_to_generate_chunks({ x = -20, y = -22 }, 0.1)
|
||||
surface.request_to_generate_chunks({ x = -20, y = -22 }, 1)
|
||||
surface.force_generate_chunk_requests()
|
||||
end
|
||||
game.forces.player.set_spawn_position({ x = -27, y = -25 }, surface)
|
||||
@ -293,7 +308,7 @@ function Public.reset_map()
|
||||
WD.enable_inverted(true)
|
||||
else
|
||||
if not surface.is_chunk_generated({ x = -20, y = 22 }) then
|
||||
surface.request_to_generate_chunks({ x = -20, y = 22 }, 0.1)
|
||||
surface.request_to_generate_chunks({ x = -20, y = 22 }, 1)
|
||||
surface.force_generate_chunk_requests()
|
||||
end
|
||||
game.forces.player.set_spawn_position({ x = -27, y = 25 }, surface)
|
||||
@ -301,6 +316,9 @@ function Public.reset_map()
|
||||
WD.enable_inverted(false)
|
||||
end
|
||||
|
||||
Public.sr_reset_forces()
|
||||
Public.sr_teleport_players()
|
||||
|
||||
game.speed = 1
|
||||
if this.space_age then
|
||||
surface.destroy_decoratives({ name = "brown-cup", invert = true })
|
||||
@ -344,10 +362,15 @@ function Public.reset_map()
|
||||
if not this.disable_startup_notification then
|
||||
Task.set_timeout_in_ticks(25, announce_new_map)
|
||||
end
|
||||
|
||||
Public.equip_players(nil, false)
|
||||
|
||||
Task.set_timeout_in_ticks(100, partial_reset_token, {})
|
||||
end
|
||||
|
||||
local is_locomotive_valid = function ()
|
||||
local locomotive = Public.get('locomotive')
|
||||
if game.ticks_played < 1000 then return end
|
||||
if not locomotive or not locomotive.valid then
|
||||
Public.set('game_lost', true)
|
||||
Public.loco_died(true)
|
||||
@ -558,6 +581,7 @@ local handle_changes = function ()
|
||||
end
|
||||
|
||||
local nth_40_tick = function ()
|
||||
if game.tick < 30 then return end
|
||||
local update_gui = Public.update_gui
|
||||
local players = game.connected_players
|
||||
|
||||
@ -573,12 +597,14 @@ local nth_40_tick = function ()
|
||||
end
|
||||
|
||||
local nth_250_tick = function ()
|
||||
if game.tick < 500 then return end
|
||||
compare_collapse_and_train()
|
||||
collapse_after_wave_200()
|
||||
Public.set_spawn_position()
|
||||
end
|
||||
|
||||
local nth_1000_tick = function ()
|
||||
if game.tick < 500 then return end
|
||||
Public.set_difficulty()
|
||||
Public.is_creativity_mode_on()
|
||||
end
|
||||
@ -640,4 +666,11 @@ Event.add(
|
||||
end
|
||||
)
|
||||
|
||||
Event.on_init(function ()
|
||||
local nauvis = game.surfaces.nauvis
|
||||
nauvis.clear(true)
|
||||
nauvis.request_to_generate_chunks({ 0, 0 }, 3)
|
||||
nauvis.force_generate_chunk_requests()
|
||||
end)
|
||||
|
||||
return Public
|
||||
|
@ -344,7 +344,7 @@ local function randomness(data)
|
||||
if data.script_character then
|
||||
create_particles(player.surface, particle, position, 16, { x = data.script_character.position.x, y = data.script_character.position.y })
|
||||
else
|
||||
create_particles(player.surface, particle, position, 16, { x = player.position.x, y = player.position.y })
|
||||
create_particles(player.surface, particle, position, 16, { x = player.physical_position.x, y = player.physical_position.y })
|
||||
end
|
||||
end
|
||||
|
||||
@ -401,7 +401,7 @@ local function randomness_scrap(data)
|
||||
if data.script_character then
|
||||
create_particles(player.surface, particle, position, 64, { x = data.script_character.position.x, y = data.script_character.position.y })
|
||||
else
|
||||
create_particles(player.surface, particle, position, 64, { x = player.position.x, y = player.position.y })
|
||||
create_particles(player.surface, particle, position, 64, { x = player.physical_position.x, y = player.physical_position.y })
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -4,15 +4,10 @@ local Event = require 'utils.event'
|
||||
|
||||
local mapkeeper = '[color=blue]Mapkeeper:[/color]'
|
||||
|
||||
local function reset_forces(new_surface, old_surface)
|
||||
local function reset_forces()
|
||||
for _, f in pairs(game.forces) do
|
||||
local spawn = {
|
||||
x = game.forces.player.get_spawn_position(old_surface).x,
|
||||
y = game.forces.player.get_spawn_position(old_surface).y
|
||||
}
|
||||
f.reset()
|
||||
f.reset_evolution()
|
||||
f.set_spawn_position(spawn, new_surface)
|
||||
end
|
||||
for _, tech in pairs(game.forces.player.technologies) do
|
||||
tech.researched = false
|
||||
@ -20,8 +15,11 @@ local function reset_forces(new_surface, old_surface)
|
||||
end
|
||||
end
|
||||
|
||||
---@param surface LuaSurface
|
||||
local function teleport_players(surface)
|
||||
local function teleport_players()
|
||||
local surface = game.get_surface('nauvis')
|
||||
if not surface or not surface.valid then
|
||||
return
|
||||
end
|
||||
local adjusted_zones = Public.get('adjusted_zones')
|
||||
local position
|
||||
|
||||
@ -115,21 +113,15 @@ local function scheduled_surface_clearing()
|
||||
|
||||
game.print(mapkeeper .. ' Deleting old surface.')
|
||||
|
||||
game.delete_surface(surface)
|
||||
scheduler.operation = 'done'
|
||||
scheduler.start_after = tick + 100
|
||||
elseif operation == 'done' then
|
||||
game.print(mapkeeper .. ' Done clearing old surface.')
|
||||
local new_surface_index = Public.get('active_surface_index')
|
||||
local new_surface = game.get_surface(new_surface_index)
|
||||
if new_surface and new_surface.valid then
|
||||
new_surface.name = scheduler.old_surface_name
|
||||
end
|
||||
clear_scheduler(scheduler)
|
||||
end
|
||||
end
|
||||
|
||||
function Public.soft_reset_map(old_surface, map_gen_settings)
|
||||
function Public.soft_reset_map(old_surface)
|
||||
local this = Public.get()
|
||||
|
||||
if not this.soft_reset_counter then
|
||||
@ -140,28 +132,23 @@ function Public.soft_reset_map(old_surface, map_gen_settings)
|
||||
end
|
||||
this.soft_reset_counter = this.soft_reset_counter + 1
|
||||
|
||||
local new_surface = game.create_surface(this.original_surface_name .. '_' .. tostring(this.soft_reset_counter), map_gen_settings)
|
||||
new_surface.request_to_generate_chunks({ 0, 0 }, 0.1)
|
||||
new_surface.force_generate_chunk_requests()
|
||||
|
||||
reset_forces(new_surface, old_surface)
|
||||
teleport_players(new_surface)
|
||||
Public.equip_players(nil, true)
|
||||
|
||||
Public.add_schedule_to_delete_surface(true)
|
||||
local nauvis = game.surfaces.nauvis
|
||||
nauvis.clear(true)
|
||||
nauvis.request_to_generate_chunks({ 0, 0 }, 1)
|
||||
nauvis.force_generate_chunk_requests()
|
||||
|
||||
local radius = 512
|
||||
local area = { { x = -radius, y = -radius }, { x = radius, y = radius } }
|
||||
for _, entity in pairs(new_surface.find_entities_filtered { area = area, type = 'logistic-robot' }) do
|
||||
for _, entity in pairs(nauvis.find_entities_filtered { area = area, type = 'logistic-robot' }) do
|
||||
entity.destroy()
|
||||
end
|
||||
|
||||
for _, entity in pairs(new_surface.find_entities_filtered { area = area, type = 'construction-robot' }) do
|
||||
for _, entity in pairs(nauvis.find_entities_filtered { area = area, type = 'construction-robot' }) do
|
||||
entity.destroy()
|
||||
end
|
||||
|
||||
local message = table.concat({ mapkeeper .. ' Welcome to ', this.original_surface_name, '!' })
|
||||
local message_to_discord = table.concat({ '** Welcome to ', this.original_surface_name, '! **' })
|
||||
local message = table.concat({ mapkeeper .. ' Welcome to Mtn Fortress!' })
|
||||
local message_to_discord = table.concat({ '** Welcome to Mtn Fortress! **' })
|
||||
|
||||
if this.soft_reset_counter > 1 then
|
||||
message =
|
||||
@ -177,26 +164,12 @@ function Public.soft_reset_map(old_surface, map_gen_settings)
|
||||
game.print(message, { r = 0.98, g = 0.66, b = 0.22 })
|
||||
Server.to_discord_embed(message_to_discord)
|
||||
|
||||
return new_surface
|
||||
end
|
||||
|
||||
function Public.add_schedule_to_delete_surface(remove_surface)
|
||||
local old_surface_index = Public.get('old_surface_index')
|
||||
local surface = game.get_surface(old_surface_index)
|
||||
if not surface or not surface.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local tick = game.tick
|
||||
|
||||
local scheduler = Public.get('scheduler')
|
||||
scheduler.operation = 'warn'
|
||||
scheduler.surface = surface
|
||||
scheduler.old_surface_name = surface.name
|
||||
scheduler.remove_surface = remove_surface or false
|
||||
scheduler.start_after = tick + 500
|
||||
return nauvis
|
||||
end
|
||||
|
||||
Event.on_nth_tick(10, scheduled_surface_clearing)
|
||||
|
||||
Public.sr_teleport_players = teleport_players
|
||||
Public.sr_reset_forces = reset_forces
|
||||
|
||||
return Public
|
||||
|
@ -69,7 +69,7 @@ local spread_particles_token =
|
||||
end
|
||||
local particle = event.particle
|
||||
|
||||
create_particles(player.surface, particle, player.position, 128)
|
||||
create_particles(player.surface, particle, player.physical_position, 128)
|
||||
end
|
||||
)
|
||||
|
||||
@ -194,7 +194,7 @@ local warn_player_sound_token =
|
||||
|
||||
player.play_sound { path = 'utility/new_objective', volume_modifier = 0.75 }
|
||||
|
||||
create_particles(player.surface, particle, player.position, 128)
|
||||
create_particles(player.surface, particle, player.physical_position, 128)
|
||||
end
|
||||
)
|
||||
|
||||
|
@ -184,13 +184,12 @@ Event.add(
|
||||
)
|
||||
|
||||
Event.add(
|
||||
defines.events.on_rocket_launched,
|
||||
defines.events.on_rocket_launch_ordered,
|
||||
function (event)
|
||||
local rocket_inventory = event.rocket.get_inventory(defines.inventory.rocket)
|
||||
local rocket_inventory = event.rocket.cargo_pod.get_inventory(defines.inventory.cargo_unit)
|
||||
local slot = rocket_inventory[1]
|
||||
if slot and slot.valid and slot.valid_for_read then
|
||||
local objectives = Public.get_stateful('objectives')
|
||||
|
||||
local launch_item = objectives.launch_item
|
||||
if launch_item then
|
||||
if slot.name ~= launch_item.name then
|
||||
|
@ -512,7 +512,7 @@ local search_corpse_token =
|
||||
return
|
||||
end
|
||||
|
||||
local pos = player.position
|
||||
local pos = player.physical_position
|
||||
local entities =
|
||||
player.surface.find_entities_filtered {
|
||||
area = { { pos.x - 0.5, pos.y - 0.5 }, { pos.x + 0.5, pos.y + 0.5 } },
|
||||
|
@ -22,7 +22,7 @@ function Public.create_surface()
|
||||
['water'] = 0.001,
|
||||
['starting_area'] = 1,
|
||||
['cliff_settings'] = { cliff_elevation_interval = 0, cliff_elevation_0 = 0 },
|
||||
['default_enable_all_autoplace_controls'] = true,
|
||||
['default_enable_all_autoplace_controls'] = false,
|
||||
['autoplace_settings'] = {
|
||||
['entity'] = { treat_missing_as_default = false },
|
||||
['tile'] = {
|
||||
@ -52,23 +52,18 @@ function Public.create_surface()
|
||||
map_gen_settings.property_expression_names = mine
|
||||
map_gen_settings.default_enable_all_autoplace_controls = false
|
||||
|
||||
|
||||
if not this.active_surface_index then
|
||||
this.active_surface_index = game.create_surface(surface_name, map_gen_settings).index
|
||||
this.active_surface_index = game.surfaces.nauvis.index
|
||||
-- this.active_surface_index = game.planets['fulgora'].create_surface(surface_name, map_gen_settings).index
|
||||
else
|
||||
this.active_surface_index = Public.soft_reset_map(game.surfaces[this.active_surface_index], map_gen_settings).index
|
||||
end
|
||||
|
||||
-- this.soft_reset_counter = Public.get_reset_counter()
|
||||
game.surfaces.nauvis.map_gen_settings = map_gen_settings
|
||||
|
||||
if not this.cleared_nauvis then
|
||||
local mgs = game.surfaces['nauvis'].map_gen_settings
|
||||
mgs.width = 16
|
||||
mgs.height = 16
|
||||
game.surfaces['nauvis'].map_gen_settings = mgs
|
||||
game.surfaces['nauvis'].clear()
|
||||
this.cleared_nauvis = true
|
||||
end
|
||||
|
||||
-- this.soft_reset_counter = Public.get_reset_counter()
|
||||
|
||||
return this.active_surface_index
|
||||
end
|
||||
|
@ -4,6 +4,10 @@ local Server = require 'utils.server'
|
||||
local Event = require 'utils.event'
|
||||
local Task = require 'utils.task_token'
|
||||
|
||||
local stateful_settings = {
|
||||
reversed = false
|
||||
}
|
||||
|
||||
local this = {
|
||||
players = {},
|
||||
traps = {},
|
||||
@ -12,12 +16,19 @@ local this = {
|
||||
surface = nil,
|
||||
operation = nil,
|
||||
next_operation = nil
|
||||
},
|
||||
adjusted_zones = {
|
||||
scrap = {},
|
||||
forest = {},
|
||||
size = nil,
|
||||
shuffled_zones = nil,
|
||||
starting_zone = true,
|
||||
reversed = stateful_settings.reversed,
|
||||
disable_terrain = false
|
||||
}
|
||||
}
|
||||
|
||||
local stateful_settings = {
|
||||
reversed = false
|
||||
}
|
||||
|
||||
local Public = {}
|
||||
local random = math.random
|
||||
local dataset = 'scenario_settings'
|
||||
@ -30,7 +41,7 @@ Public.events = {
|
||||
on_market_item_purchased = Event.generate_event_name('on_market_item_purchased')
|
||||
}
|
||||
|
||||
local scenario_name = 'Mtn Fortress'
|
||||
local scenario_name = 'nauvis'
|
||||
Public.scenario_name = scenario_name
|
||||
|
||||
Global.register(
|
||||
@ -335,6 +346,11 @@ function Public.reset_main_table()
|
||||
}
|
||||
|
||||
this.wagons_in_the_wild = {}
|
||||
this.player_market_settings = {}
|
||||
|
||||
this.quality_list = {
|
||||
'normal',
|
||||
}
|
||||
|
||||
for k, _ in pairs(this.players) do
|
||||
this.players[k] = {}
|
||||
|
@ -3036,7 +3036,7 @@ Event.add(
|
||||
end
|
||||
|
||||
local adjusted_zones = Public.get('adjusted_zones')
|
||||
if adjusted_zones.disable_terrain then
|
||||
if adjusted_zones and adjusted_zones.disable_terrain then
|
||||
return
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user