1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-09-16 09:06:21 +02:00

Merge pull request #46 from M3wM3w/master

update from main
This commit is contained in:
hanakocz
2021-01-28 15:54:10 +01:00
committed by GitHub
16 changed files with 96 additions and 32 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
.vscode/ .vscode/
.history/ .history/
.git/ .git/
maps/biter_battles_v3/

View File

@@ -6,7 +6,6 @@ local Server = require 'utils.server'
local Tabs = require 'comfy_panel.main' local Tabs = require 'comfy_panel.main'
local session = require 'utils.datastore.session_data' local session = require 'utils.datastore.session_data'
local Class = {} local Class = {}
local insert = table.insert local insert = table.insert
@@ -946,6 +945,10 @@ Gui.on_click(
function(event) function(event)
local data = Gui.get_data(event.element) local data = Gui.get_data(event.element)
if not data then
return
end
insert(data.answers, {text = ''}) insert(data.answers, {text = ''})
redraw_create_poll_content(data) redraw_create_poll_content(data)
end end

View File

@@ -88,7 +88,7 @@ function Public.offer_bought(event, cave_miner)
local offers = market.get_market_items() local offers = market.get_market_items()
local bought_offer = offers[offer_index].offer local bought_offer = offers[offer_index].offer
if bought_offer.type ~= "nothing" then return end if bought_offer.type ~= "nothing" then return end
if offer_index == 1 then if offer_index == 1 and Constants.pickaxe_tiers[cave_miner.pickaxe_tier + 1] then
market.force.play_sound({path = 'utility/new_objective', volume_modifier = 0.75}) market.force.play_sound({path = 'utility/new_objective', volume_modifier = 0.75})
cave_miner.pickaxe_tier = cave_miner.pickaxe_tier + 1 cave_miner.pickaxe_tier = cave_miner.pickaxe_tier + 1
local speed = Functions.set_mining_speed(cave_miner, player.force) local speed = Functions.set_mining_speed(cave_miner, player.force)

View File

@@ -240,6 +240,7 @@ local function set_train_final_health(final_damage_amount)
locomotive_health = WPT.get('locomotive_health') locomotive_health = WPT.get('locomotive_health')
if locomotive_health <= 0 then if locomotive_health <= 0 then
WPT.set('game_lost', true)
Public.loco_died() Public.loco_died()
end end
@@ -1103,6 +1104,11 @@ function Public.unstuck_player(index)
end end
function Public.loco_died() function Public.loco_died()
local game_lost = WPT.get('game_lost')
if not game_lost then
return
end
local active_surface_index = WPT.get('active_surface_index') local active_surface_index = WPT.get('active_surface_index')
local locomotive = WPT.get('locomotive') local locomotive = WPT.get('locomotive')
local surface = game.surfaces[active_surface_index] local surface = game.surfaces[active_surface_index]
@@ -1169,14 +1175,12 @@ function Public.loco_died()
rendering.set_text(this.health_text, 'HP: ' .. this.locomotive_health .. ' / ' .. this.locomotive_max_health) rendering.set_text(this.health_text, 'HP: ' .. this.locomotive_health .. ' / ' .. this.locomotive_max_health)
wave_defense_table.game_lost = true wave_defense_table.game_lost = true
wave_defense_table.target = nil wave_defense_table.target = nil
this.game_lost = true
local msg = defeated_messages[random(1, #defeated_messages)] local msg = defeated_messages[random(1, #defeated_messages)]
local pos = { local pos = {
position = this.locomotive.position position = this.locomotive.position
} }
Alert.alert_all_players_location(pos, msg) Alert.alert_all_players_location(pos, msg)
Server.to_discord_bold(msg, true)
game.forces.enemy.set_friend('player', true) game.forces.enemy.set_friend('player', true)
game.forces.player.set_friend('enemy', true) game.forces.player.set_friend('enemy', true)

View File

@@ -1058,6 +1058,10 @@ function Public.set_spawn_position()
if spawn_near_collapse.active then if spawn_near_collapse.active then
local collapse_position = surface.find_non_colliding_position('small-biter', collapse_pos, 32, 2) local collapse_position = surface.find_non_colliding_position('small-biter', collapse_pos, 32, 2)
local sizeof = locomotive_positions.tbl[total_pos - total_pos + 1] local sizeof = locomotive_positions.tbl[total_pos - total_pos + 1]
if not sizeof then
goto continue
end
if check_tile(surface, sizeof, locomotive_positions.tbl, total_pos) then if check_tile(surface, sizeof, locomotive_positions.tbl, total_pos) then
retries = retries + 1 retries = retries + 1
if retries == 2 then if retries == 2 then

View File

@@ -11,6 +11,14 @@ local main_button_name = Gui.uid_name()
local main_frame_name = Gui.uid_name() local main_frame_name = Gui.uid_name()
local floor = math.floor local floor = math.floor
local function validate_entity(entity)
if not (entity and entity.valid) then
return false
end
return true
end
local function validate_player(player) local function validate_player(player)
if not player then if not player then
return false return false
@@ -159,6 +167,10 @@ local function on_gui_click(event)
end end
local locomotive = WPT.get('locomotive') local locomotive = WPT.get('locomotive')
if not validate_entity(locomotive) then
return
end
if not player or not player.valid then if not player or not player.valid then
return return
end end

View File

@@ -870,10 +870,12 @@ function Public.use_door_with_entity(ic, player, door)
end end
end end
if validate_entity(car.entity) then
player_data.fallback_surface = car.entity.surface.index player_data.fallback_surface = car.entity.surface.index
player_data.fallback_position = {car.entity.position.x, car.entity.position.y} player_data.fallback_position = {car.entity.position.x, car.entity.position.y}
end
if car.entity.surface.name == player.surface.name then if validate_entity(car.entity) and car.entity.surface.name == player.surface.name then
local surface = car.surface local surface = car.surface
if validate_entity(car.entity) and car.owner == player.index then if validate_entity(car.entity) and car.owner == player.index then
IC_Gui.add_toolbar(player) IC_Gui.add_toolbar(player)

View File

@@ -18,7 +18,6 @@ local function on_entity_died(event)
local ic = IC.get() local ic = IC.get()
if entity.type == 'car' or entity.name == 'spidertron' then if entity.type == 'car' or entity.name == 'spidertron' then
Minimap.kill_minimap(game.players[event.player_index])
Functions.kill_car(ic, entity) Functions.kill_car(ic, entity)
end end
end end

View File

@@ -86,6 +86,13 @@ local function on_train_created()
Functions.request_reconstruction(icw) Functions.request_reconstruction(icw)
end end
local function on_built_entity(event)
local icw = ICW.get()
local created_entity = event.created_entity
Functions.create_wagon(icw, created_entity)
Functions.add_wagon_entity_count(icw, created_entity)
end
local function on_gui_click(event) local function on_gui_click(event)
local icw = ICW.get() local icw = ICW.get()
Functions.toggle_minimap(icw, event) Functions.toggle_minimap(icw, event)
@@ -153,5 +160,6 @@ Event.add(defines.events.on_gui_opened, on_gui_opened)
Event.add(defines.events.on_player_built_tile, on_player_or_robot_built_tile) Event.add(defines.events.on_player_built_tile, on_player_or_robot_built_tile)
Event.add(defines.events.on_robot_built_tile, on_player_or_robot_built_tile) Event.add(defines.events.on_robot_built_tile, on_player_or_robot_built_tile)
Event.add(defines.events.on_gui_switch_state_changed, on_gui_switch_state_changed) Event.add(defines.events.on_gui_switch_state_changed, on_gui_switch_state_changed)
Event.add(defines.events.on_built_entity, on_built_entity)
return Public return Public

View File

@@ -35,7 +35,7 @@ local function compute_fullness(player)
local warn_player = is_player_warned(player) local warn_player = is_player_warned(player)
local free_slots = player.get_main_inventory().count_empty_stacks() local free_slots = player.get_main_inventory().count_empty_stacks()
if free_slots == 0 or free_slots == 1 then if free_slots == 0 or free_slots == 1 then
if player.character then if player.character and player.character.valid then
local damage = ceil((warn_player.count / 2) * warn_player.count) local damage = ceil((warn_player.count / 2) * warn_player.count)
if player.character.health >= damage then if player.character.health >= damage then
player.character.damage(damage, 'player', 'explosion') player.character.damage(damage, 'player', 'explosion')

View File

@@ -178,6 +178,9 @@ end
local function set_difficulty() local function set_difficulty()
local index = highest_count(this.difficulties) local index = highest_count(this.difficulties)
if not index then
return
end
if this.difficulty_vote_index ~= index then if this.difficulty_vote_index ~= index then
local message = table.concat({'>> Map difficulty has changed to ', this.difficulties[index].name, ' difficulty!'}) local message = table.concat({'>> Map difficulty has changed to ', this.difficulties[index].name, ' difficulty!'})

View File

@@ -159,6 +159,22 @@ local get_cause_player = {
end end
return players return players
end, end,
['spider-vehicle'] = function(cause)
local players = {}
local driver = cause.get_driver()
if driver then
if driver.player then
players[#players + 1] = driver.player
end
end
local passenger = cause.get_passenger()
if passenger then
if passenger.player then
players[#players + 1] = passenger.player
end
end
return players
end,
['locomotive'] = train_type_cause, ['locomotive'] = train_type_cause,
['cargo-wagon'] = train_type_cause, ['cargo-wagon'] = train_type_cause,
['artillery-wagon'] = train_type_cause, ['artillery-wagon'] = train_type_cause,

View File

@@ -45,6 +45,14 @@ Global.register(
local Public = {} local Public = {}
local validate_entity = function(entity)
if not (entity and entity.valid) then
return false
end
return true
end
local clear_gui = local clear_gui =
Token.register( Token.register(
function(data) function(data)
@@ -184,10 +192,7 @@ local teleport_player_to_gulag = function(player, action)
local gulag_tp = function(surface) local gulag_tp = function(surface)
get_player_data(player, true) get_player_data(player, true)
player.teleport( player.teleport(surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 128, 1), surface.name)
surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 128, 1),
surface.name
)
end end
if action == 'jail' then if action == 'jail' then
@@ -244,7 +249,19 @@ local validate_args = function(data)
local message = data.message local message = data.message
local cmd = data.cmd local cmd = data.cmd
if not griefer or not game.players[griefer] then if not type(griefer) == 'string' then
Utils.print_to(player, 'Invalid name.')
return false
end
local get_griefer_player = game.get_player(griefer)
if not validate_entity(get_griefer_player) then
Utils.print_to(player, 'Invalid name.')
return false
end
if not griefer or not get_griefer_player then
Utils.print_to(player, 'Invalid name.') Utils.print_to(player, 'Invalid name.')
return false return false
end end
@@ -269,7 +286,7 @@ local validate_args = function(data)
return false return false
end end
if game.players[griefer].admin and not player.admin then if get_griefer_player.admin and not player.admin then
Utils.print_to(player, 'You can´t select an admin.') Utils.print_to(player, 'You can´t select an admin.')
return false return false
end end
@@ -307,10 +324,7 @@ local vote_to_jail = function(player, griefer, msg)
votejail[griefer][player.name] = true votejail[griefer][player.name] = true
votejail[griefer].index = votejail[griefer].index + 1 votejail[griefer].index = votejail[griefer].index + 1
Utils.print_to(player, 'You have voted to jail player ' .. griefer .. '.') Utils.print_to(player, 'You have voted to jail player ' .. griefer .. '.')
if if votejail[griefer].index >= settings.votejail_count or (votejail[griefer].index == #game.connected_players - 1 and #game.connected_players > votejail[griefer].index) then
votejail[griefer].index >= settings.votejail_count or
(votejail[griefer].index == #game.connected_players - 1 and #game.connected_players > votejail[griefer].index)
then
Public.try_ul_data(griefer, true, votejail[griefer].actor, msg) Public.try_ul_data(griefer, true, votejail[griefer].actor, msg)
end end
else else
@@ -329,10 +343,7 @@ local vote_to_free = function(player, griefer)
votefree[griefer].index = votefree[griefer].index + 1 votefree[griefer].index = votefree[griefer].index + 1
Utils.print_to(player, 'You have voted to free player ' .. griefer .. '.') Utils.print_to(player, 'You have voted to free player ' .. griefer .. '.')
if if votefree[griefer].index >= settings.votejail_count or (votefree[griefer].index == #game.connected_players - 1 and #game.connected_players > votefree[griefer].index) then
votefree[griefer].index >= settings.votejail_count or
(votefree[griefer].index == #game.connected_players - 1 and #game.connected_players > votefree[griefer].index)
then
Public.try_ul_data(griefer, false, votefree[griefer].actor) Public.try_ul_data(griefer, false, votefree[griefer].actor)
votejail[griefer] = nil votejail[griefer] = nil
votefree[griefer] = nil votefree[griefer] = nil
@@ -573,10 +584,7 @@ Event.add(
if player.admin or playtime >= settings.playtime_for_instant_jail then if player.admin or playtime >= settings.playtime_for_instant_jail then
if cmd == 'jail' then if cmd == 'jail' then
if player.admin then if player.admin then
Utils.warning( Utils.warning(player, 'Abusing the jail command will lead to revoked permissions. Jailing someone in case of disagreement is not OK!')
player,
'Abusing the jail command will lead to revoked permissions. Jailing someone in case of disagreement is not OK!'
)
end end
Public.try_ul_data(griefer, true, player.name, message) Public.try_ul_data(griefer, true, player.name, message)
return return

View File

@@ -19,7 +19,8 @@ local fetch =
return return
end end
if type(value) == 'table' then if type(value) == 'table' then
game.print('>> ' .. player.name .. ' << ' .. value.msg, value.color) local message = string.gsub(value.msg, "{name}", player.name)
game.print(message, value.color)
end end
end end
) )
@@ -41,7 +42,7 @@ end
commands.add_command( commands.add_command(
'save-message', 'save-message',
'Sets your custom join message.', 'Sets your custom join message. "{name}" will be replaced with your username',
function(cmd) function(cmd)
local player = game.player local player = game.player
if not player or not player.valid then if not player or not player.valid then

View File

@@ -1,6 +1,5 @@
local Gui = require 'utils.gui' local Gui = require 'utils.gui'
local Color = require 'utils.color_presets' local Color = require 'utils.color_presets'
local Event = require 'utils.event'
local Public = {} local Public = {}

View File

@@ -40,8 +40,7 @@ function Public.show(container)
input_text_box_style.height = 32 input_text_box_style.height = 32
input_text_box_style.maximal_width = 1000 input_text_box_style.maximal_width = 1000
local refresh_button = local refresh_button = right_top_flow.add {type = 'sprite-button', name = refresh_name, sprite = 'utility/reset', tooltip = 'refresh'}
right_top_flow.add {type = 'sprite-button', name = refresh_name, sprite = 'utility/reset', tooltip = 'refresh'}
local refresh_button_style = refresh_button.style local refresh_button_style = refresh_button.style
refresh_button_style.width = 32 refresh_button_style.width = 32
refresh_button_style.height = 32 refresh_button_style.height = 32
@@ -75,6 +74,11 @@ Gui.on_click(
local left_panel = element.parent.parent local left_panel = element.parent.parent
local data = Gui.get_data(left_panel) local data = Gui.get_data(left_panel)
if not data then
return
end
local right_panel = data.right_panel local right_panel = data.right_panel
local selected_header = data.selected_header local selected_header = data.selected_header
local input_text_box = data.input_text_box local input_text_box = data.input_text_box