1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-11-25 22:32:18 +02:00

Mtn: Fix many bugs

This commit is contained in:
Gerkiz
2024-10-26 13:05:31 +02:00
parent 32cb1f0ff9
commit c74f3db7c4
14 changed files with 101 additions and 43 deletions

View File

@@ -324,8 +324,6 @@ local function distance(player)
local breached_wall = Public.get('breached_wall') local breached_wall = Public.get('breached_wall')
local bonus_xp_on_join = Public.get('bonus_xp_on_join') local bonus_xp_on_join = Public.get('bonus_xp_on_join')
local enable_arties = Public.get('enable_arties') local enable_arties = Public.get('enable_arties')
local final_battle = Public.get('final_battle')
local p = player.physical_position local p = player.physical_position
@@ -421,7 +419,7 @@ local function distance(player)
end end
end end
if not Collapse.has_collapse_started() or not final_battle then if not Collapse.has_collapse_started() then
clear_breach_text_and_render() clear_breach_text_and_render()
Public.set('collapse_started', true) Public.set('collapse_started', true)
Collapse.start_now(true) Collapse.start_now(true)

View File

@@ -109,6 +109,15 @@ local reset_game =
end end
) )
local change_force_for_drills_token =
Task.register(
function (event)
local entity = event.entity
if not entity or not entity.valid then return end
entity.force = 'bonus_drill'
end
)
local function get_random_weighted(player, weighted_table, item_index, weight_index) local function get_random_weighted(player, weighted_table, item_index, weight_index)
local total_weight = 0 local total_weight = 0
item_index = item_index or 1 item_index = item_index or 1
@@ -1507,7 +1516,7 @@ local function on_built_entity(event)
} }
if valid_drills[entity.name] then if valid_drills[entity.name] then
entity.force = 'bonus_drill' Task.set_timeout_in_ticks(30, change_force_for_drills_token, { entity = entity })
return return
end end
@@ -1598,7 +1607,7 @@ local function on_robot_built_entity(event)
} }
if valid_drills[entity.name] then if valid_drills[entity.name] then
entity.force = 'bonus_drill' Task.set_timeout_in_ticks(30, change_force_for_drills_token, { entity = entity })
return return
end end

View File

@@ -1567,10 +1567,7 @@ function Public.is_creativity_mode_on()
end end
function Public.disable_creative() function Public.disable_creative()
local creative_enabled = Misc.get('creative_enabled') Misc.set('creative_enabled', false)
if creative_enabled then
Misc.set('creative_enabled', false)
end
end end
function Public.on_player_respawned(event) function Public.on_player_respawned(event)

View File

@@ -39,6 +39,18 @@ local function validate_entity(entity)
return true return true
end end
local get_filters = function (points)
local filters = {}
for _, section in pairs(points.sections) do
for _, filter in pairs(section.filters) do
if filter and filter.value and filter.value.name then
filters[#filters + 1] = filter
end
end
end
return filters
end
---Returns the car from the unit_number. ---Returns the car from the unit_number.
---@param unit_number any ---@param unit_number any
---@return table|boolean ---@return table|boolean
@@ -560,10 +572,11 @@ local function input_filtered(car_inv, chest, chest_inv, free_slots)
local request_stacks = {} local request_stacks = {}
local prototypes = prototypes.item local prototypes = prototypes.item
for slot_index = 1, 30, 1 do local logistics = chest.get_logistic_point(defines.logistic_member_index.logistic_container)
local stack = chest.get_request_slot(slot_index) local filters = get_filters(logistics)
if stack then for _, filter in pairs(filters) do
request_stacks[stack.name] = 10 * prototypes[stack.name].stack_size if filter.value.name then
request_stacks[filter.value.name] = 10 * prototypes[filter.value.name].stack_size
end end
end end
for i = 1, #car_inv - 1, 1 do for i = 1, #car_inv - 1, 1 do
@@ -606,7 +619,16 @@ local function input_cargo(car, chest)
end end
end end
if chest.get_request_slot(1) then local has_request_slot = false
local logistics = chest.get_logistic_point(defines.logistic_member_index.logistic_container)
local filters = get_filters(logistics)
for _, filter in pairs(filters) do
if filter.value.name then
has_request_slot = true
end
end
if has_request_slot then
input_filtered(car_inventory, chest, chest_inventory, free_slots) input_filtered(car_inventory, chest, chest_inventory, free_slots)
goto continue goto continue
end end
@@ -811,7 +833,7 @@ function Public.save_car(event)
restore_surface(p, e) restore_surface(p, e)
elseif p.can_insert({ name = car.name, count = 1 }) then elseif p.can_insert({ name = car.name, count = 1 }) then
p.insert({ name = car.name, count = 1, health = health }) p.insert({ name = car.name, count = 1, health = health })
p.print(module_tag .. 'Your car was stolen from you - the gods foresaw this and granted you a new one.', {color = Color.info}) p.print(module_tag .. 'Your car was stolen from you - the gods foresaw this and granted you a new one.', { color = Color.info })
end end
end end
end end
@@ -1081,7 +1103,7 @@ function Public.validate_owner(player, entity)
player.driving = false player.driving = false
if not player.admin then if not player.admin then
if list.notify_on_driver_change == 'left' then if list.notify_on_driver_change == 'left' then
p.print(player.name .. ' tried to drive your car.', {color = Color.warning}) p.print(player.name .. ' tried to drive your car.', { color = Color.warning })
end end
return return
end end

View File

@@ -761,6 +761,7 @@ function Public.use_cargo_wagon_door_with_entity(icw, player, door)
return return
end end
if not door then if not door then
return return
end end
@@ -1062,6 +1063,10 @@ function Public.toggle_minimap(icw, event)
return return
end end
local player = game.players[event.player_index] local player = game.players[event.player_index]
if player.controller_type == defines.controllers.remote then
return
end
local is_spamming = SpamProtection.is_spamming(player, 5, 'ICW Toggle Minimap') local is_spamming = SpamProtection.is_spamming(player, 5, 'ICW Toggle Minimap')
if is_spamming then if is_spamming then
return return

View File

@@ -24,11 +24,18 @@ end
local function on_player_driving_changed_state(event) local function on_player_driving_changed_state(event)
local icw = ICW.get() local icw = ICW.get()
local player = game.players[event.player_index] local player = game.players[event.player_index]
if player.controller_type == defines.controllers.remote then
return
end
Functions.use_cargo_wagon_door_with_entity(icw, player, event.entity) Functions.use_cargo_wagon_door_with_entity(icw, player, event.entity)
end end
local function on_player_changed_surface(event) local function on_player_changed_surface(event)
local player = game.players[event.player_index] local player = game.players[event.player_index]
if player.controller_type == defines.controllers.remote then
return
end
Functions.kill_minimap(player) Functions.kill_minimap(player)
end end
@@ -37,6 +44,7 @@ local function on_gui_closed(event)
if not entity then if not entity then
return return
end end
if not entity.valid then if not entity.valid then
return return
end end
@@ -52,6 +60,10 @@ local function on_gui_closed(event)
return return
end end
if player.controller_type == defines.controllers.remote then
return
end
Functions.kill_minimap(player) Functions.kill_minimap(player)
end end
@@ -77,6 +89,10 @@ local function on_gui_opened(event)
return return
end end
if player.controller_type == defines.controllers.remote then
return
end
Functions.draw_minimap( Functions.draw_minimap(
icw, icw,
player, player,

View File

@@ -42,6 +42,7 @@ local JailData = require 'utils.datastore.jail_data'
local RPG_Progression = require 'utils.datastore.rpg_data' local RPG_Progression = require 'utils.datastore.rpg_data'
local OfflinePlayers = require 'modules.clear_vacant_players' local OfflinePlayers = require 'modules.clear_vacant_players'
local Beam = require 'modules.render_beam' local Beam = require 'modules.render_beam'
local Commands = require 'utils.commands'
-- Use these settings for live -- Use these settings for live
local send_ping_to_channel = Discord.channel_names.mtn_channel local send_ping_to_channel = Discord.channel_names.mtn_channel
@@ -142,6 +143,15 @@ partial_reset = function ()
Public.locomotive_spawn(surface, { x = -18, y = 25 }, this.adjusted_zones.reversed) Public.locomotive_spawn(surface, { x = -18, y = 25 }, this.adjusted_zones.reversed)
end end
init_bonus_drill_force()
Public.init_enemy_weapon_damage()
game.forces.player.manual_mining_speed_modifier = 0
game.forces.player.set_ammo_damage_modifier('artillery-shell', -0.95)
game.forces.player.worker_robots_battery_modifier = 4
game.forces.player.worker_robots_storage_bonus = 15
Public.render_train_hp() Public.render_train_hp()
Public.render_direction(surface, this.adjusted_zones.reversed) Public.render_direction(surface, this.adjusted_zones.reversed)
end end
@@ -185,7 +195,6 @@ function Public.reset_map()
Group.alphanumeric_only(false) Group.alphanumeric_only(false)
Public.disable_tech() Public.disable_tech()
init_bonus_drill_force()
local surface = game.surfaces[this.active_surface_index] local surface = game.surfaces[this.active_surface_index]
@@ -204,11 +213,6 @@ function Public.reset_map()
Beam.reset_valid_targets() Beam.reset_valid_targets()
game.forces.player.manual_mining_speed_modifier = 0
game.forces.player.set_ammo_damage_modifier('artillery-shell', -0.95)
game.forces.player.worker_robots_battery_modifier = 4
game.forces.player.worker_robots_storage_bonus = 15
BiterHealthBooster.set_active_surface(tostring(surface.name)) BiterHealthBooster.set_active_surface(tostring(surface.name))
BiterHealthBooster.acid_nova(true) BiterHealthBooster.acid_nova(true)
BiterHealthBooster.check_on_entity_died(true) BiterHealthBooster.check_on_entity_died(true)
@@ -216,7 +220,6 @@ function Public.reset_map()
BiterHealthBooster.enable_boss_loot(false) BiterHealthBooster.enable_boss_loot(false)
BiterHealthBooster.enable_randomize_stun_and_slowdown_sticker(true) BiterHealthBooster.enable_randomize_stun_and_slowdown_sticker(true)
Public.init_enemy_weapon_damage()
-- AntiGrief.whitelist_types('tree', true) -- AntiGrief.whitelist_types('tree', true)
AntiGrief.enable_capsule_warning(false) AntiGrief.enable_capsule_warning(false)
@@ -296,6 +299,7 @@ function Public.reset_map()
Public.set_difficulty() Public.set_difficulty()
Public.disable_creative() Public.disable_creative()
Public.boost_difficulty() Public.boost_difficulty()
Commands.restore_states()
if this.adjusted_zones.reversed then if this.adjusted_zones.reversed then
if not surface.is_chunk_generated({ x = -20, y = -22 }) then if not surface.is_chunk_generated({ x = -20, y = -22 }) then

View File

@@ -519,6 +519,7 @@ local search_corpse_token =
Task.register( Task.register(
function (event) function (event)
local player_index = event.player_index local player_index = event.player_index
if not player_index then return end
local player = game.get_player(player_index) local player = game.get_player(player_index)
if not player or not player.valid then if not player or not player.valid then

View File

@@ -109,18 +109,19 @@ Commands.new('stats', 'Check what stats a user has!')
end end
) )
Commands.new('rpg_give_xp', 'Give players XP!')
:require_admin()
:require_validation("Running this again will grant EVERY player XP. Are you sure you want to continue?")
:add_parameter('amount', false, 'number')
:callback(
function (_, amount)
Public.give_xp(amount)
game.print('Distributed ' .. amount .. ' of xp.')
end
)
if _DEBUG then if _DEBUG then
Commands.new('give_xp', 'Give a player XP!')
:require_admin()
:add_parameter('amount', false, 'number')
:callback(
function (_, amount)
Public.give_xp(amount)
game.print('Distributed ' .. amount .. ' of xp.')
end
)
Commands.new('rpg_debug_module', 'Toggle debug mode for RPG module!') Commands.new('rpg_debug_module', 'Toggle debug mode for RPG module!')
:require_admin() :require_admin()
:callback( :callback(

View File

@@ -157,18 +157,18 @@ end
local function add_gui_increase_stat(element, name, player) local function add_gui_increase_stat(element, name, player)
local rpg_t = Public.get_value_from_player(player.index) local rpg_t = Public.get_value_from_player(player.index)
local sprite = 'virtual-signal/signal-red'
local symbol = '' local symbol = ''
local e = element.add({ type = 'sprite-button', name = name, caption = symbol })
if rpg_t.points_left <= 0 then if rpg_t.points_left <= 0 then
sprite = 'virtual-signal/signal-black' e.style.font_color = { 0, 0, 0 }
else
e.style.font_color = { 195, 0, 0 }
end end
local e = element.add({ type = 'sprite-button', name = name, caption = symbol, sprite = sprite })
e.style.maximal_height = 38 e.style.maximal_height = 38
e.style.minimal_height = 38 e.style.minimal_height = 38
e.style.maximal_width = 38 e.style.maximal_width = 38
e.style.minimal_width = 38 e.style.minimal_width = 38
e.style.font = 'default-large-semibold' e.style.font = 'default-large-semibold'
e.style.font_color = { 0, 0, 0 }
e.style.horizontal_align = 'center' e.style.horizontal_align = 'center'
e.style.vertical_align = 'center' e.style.vertical_align = 'center'
e.style.padding = 0 e.style.padding = 0

View File

@@ -64,9 +64,6 @@ local function on_gui_click(event)
if element.caption ~= '' then if element.caption ~= '' then
return return
end end
if element.sprite ~= 'virtual-signal/signal-red' then
return
end
local rpg_t = Public.get_value_from_player(player.index) local rpg_t = Public.get_value_from_player(player.index)

View File

@@ -1109,7 +1109,7 @@ spells[#spells + 1] = {
local surface = data.surface local surface = data.surface
local pos = surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5) local pos = surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0)
if pos then if pos then
player.teleport(pos, surface) player.teleport(pos, surface)
else else
@@ -1145,7 +1145,7 @@ spells[#spells + 1] = {
Public.register_cooldown_for_spell(player) Public.register_cooldown_for_spell(player)
local pos = surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5) local pos = surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0)
if pos then if pos then
player.teleport(pos, surface) player.teleport(pos, surface)
else else

View File

@@ -523,6 +523,14 @@ function Public:set_default(defaults)
return self return self
end end
--- Restores the command_activated state for each command
function Public.restore_states()
for _, command in pairs(this.commands) do
command.validated_command = false
command.command_activated = false
end
end
--- Registers the command to the game. Will return the player/server and the args as separate arguments. --- Registers the command to the game. Will return the player/server and the args as separate arguments.
---@param func function ---@param func function
function Public:callback(func) function Public:callback(func)

View File

@@ -318,7 +318,7 @@ local function clear_corpses(cmd)
local radius = { { x = (pos.x + -param), y = (pos.y + -param) }, { x = (pos.x + param), y = (pos.y + param) } } local radius = { { x = (pos.x + -param), y = (pos.y + -param) }, { x = (pos.x + param), y = (pos.y + param) } }
for _, entity in pairs(player.surface.find_entities_filtered { area = radius, type = 'corpse' }) do for _, entity in pairs(player.surface.find_entities_filtered { area = radius, type = { 'corpse' } }) do
if entity.corpse_expires then if entity.corpse_expires then
entity.destroy() entity.destroy()
i = i + 1 i = i + 1