Skip to content

Commit

Permalink
Mtn: Fix many bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerkiz committed Oct 26, 2024
1 parent 32cb1f0 commit c74f3db
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 43 deletions.
4 changes: 1 addition & 3 deletions maps/mountain_fortress_v3/breached_wall.lua
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,6 @@ local function distance(player)
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 final_battle = Public.get('final_battle')


local p = player.physical_position

Expand Down Expand Up @@ -421,7 +419,7 @@ local function distance(player)
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()
Public.set('collapse_started', true)
Collapse.start_now(true)
Expand Down
13 changes: 11 additions & 2 deletions maps/mountain_fortress_v3/entities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ local reset_game =
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 total_weight = 0
item_index = item_index or 1
Expand Down Expand Up @@ -1507,7 +1516,7 @@ local function on_built_entity(event)
}

if valid_drills[entity.name] then
entity.force = 'bonus_drill'
Task.set_timeout_in_ticks(30, change_force_for_drills_token, { entity = entity })
return
end

Expand Down Expand Up @@ -1598,7 +1607,7 @@ local function on_robot_built_entity(event)
}

if valid_drills[entity.name] then
entity.force = 'bonus_drill'
Task.set_timeout_in_ticks(30, change_force_for_drills_token, { entity = entity })
return
end

Expand Down
5 changes: 1 addition & 4 deletions maps/mountain_fortress_v3/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1567,10 +1567,7 @@ function Public.is_creativity_mode_on()
end

function Public.disable_creative()
local creative_enabled = Misc.get('creative_enabled')
if creative_enabled then
Misc.set('creative_enabled', false)
end
Misc.set('creative_enabled', false)
end

function Public.on_player_respawned(event)
Expand Down
36 changes: 29 additions & 7 deletions maps/mountain_fortress_v3/ic/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ local function validate_entity(entity)
return true
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.
---@param unit_number any
---@return table|boolean
Expand Down Expand Up @@ -560,10 +572,11 @@ local function input_filtered(car_inv, chest, chest_inv, free_slots)
local request_stacks = {}

local prototypes = prototypes.item
for slot_index = 1, 30, 1 do
local stack = chest.get_request_slot(slot_index)
if stack then
request_stacks[stack.name] = 10 * prototypes[stack.name].stack_size
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
request_stacks[filter.value.name] = 10 * prototypes[filter.value.name].stack_size
end
end
for i = 1, #car_inv - 1, 1 do
Expand Down Expand Up @@ -606,7 +619,16 @@ local function input_cargo(car, chest)
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)
goto continue
end
Expand Down Expand Up @@ -811,7 +833,7 @@ function Public.save_car(event)
restore_surface(p, e)
elseif p.can_insert({ name = car.name, count = 1 }) then
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
Expand Down Expand Up @@ -1081,7 +1103,7 @@ function Public.validate_owner(player, entity)
player.driving = false
if not player.admin 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
return
end
Expand Down
5 changes: 5 additions & 0 deletions maps/mountain_fortress_v3/icw/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ function Public.use_cargo_wagon_door_with_entity(icw, player, door)
return
end


if not door then
return
end
Expand Down Expand Up @@ -1062,6 +1063,10 @@ function Public.toggle_minimap(icw, event)
return
end
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')
if is_spamming then
return
Expand Down
16 changes: 16 additions & 0 deletions maps/mountain_fortress_v3/icw/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ end
local function on_player_driving_changed_state(event)
local icw = ICW.get()
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)
end

local function on_player_changed_surface(event)
local player = game.players[event.player_index]
if player.controller_type == defines.controllers.remote then
return
end
Functions.kill_minimap(player)
end

Expand All @@ -37,6 +44,7 @@ local function on_gui_closed(event)
if not entity then
return
end

if not entity.valid then
return
end
Expand All @@ -52,6 +60,10 @@ local function on_gui_closed(event)
return
end

if player.controller_type == defines.controllers.remote then
return
end

Functions.kill_minimap(player)
end

Expand All @@ -77,6 +89,10 @@ local function on_gui_opened(event)
return
end

if player.controller_type == defines.controllers.remote then
return
end

Functions.draw_minimap(
icw,
player,
Expand Down
18 changes: 11 additions & 7 deletions maps/mountain_fortress_v3/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ local JailData = require 'utils.datastore.jail_data'
local RPG_Progression = require 'utils.datastore.rpg_data'
local OfflinePlayers = require 'modules.clear_vacant_players'
local Beam = require 'modules.render_beam'
local Commands = require 'utils.commands'

-- Use these settings for live
local send_ping_to_channel = Discord.channel_names.mtn_channel
Expand Down Expand Up @@ -142,6 +143,15 @@ partial_reset = function ()
Public.locomotive_spawn(surface, { x = -18, y = 25 }, this.adjusted_zones.reversed)
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_direction(surface, this.adjusted_zones.reversed)
end
Expand Down Expand Up @@ -185,7 +195,6 @@ function Public.reset_map()
Group.alphanumeric_only(false)

Public.disable_tech()
init_bonus_drill_force()

local surface = game.surfaces[this.active_surface_index]

Expand All @@ -204,19 +213,13 @@ function Public.reset_map()

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.acid_nova(true)
BiterHealthBooster.check_on_entity_died(true)
BiterHealthBooster.boss_spawns_projectiles(true)
BiterHealthBooster.enable_boss_loot(false)
BiterHealthBooster.enable_randomize_stun_and_slowdown_sticker(true)

Public.init_enemy_weapon_damage()

-- AntiGrief.whitelist_types('tree', true)
AntiGrief.enable_capsule_warning(false)
Expand Down Expand Up @@ -296,6 +299,7 @@ function Public.reset_map()
Public.set_difficulty()
Public.disable_creative()
Public.boost_difficulty()
Commands.restore_states()

if this.adjusted_zones.reversed then
if not surface.is_chunk_generated({ x = -20, y = -22 }) then
Expand Down
1 change: 1 addition & 0 deletions maps/mountain_fortress_v3/stateful/table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ local search_corpse_token =
Task.register(
function (event)
local player_index = event.player_index
if not player_index then return end
local player = game.get_player(player_index)

if not player or not player.valid then
Expand Down
21 changes: 11 additions & 10 deletions modules/rpg/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,19 @@ Commands.new('stats', 'Check what stats a user has!')
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
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
)

if _DEBUG then
Commands.new('rpg_debug_module', 'Toggle debug mode for RPG module!')
:require_admin()
:callback(
Expand Down
8 changes: 4 additions & 4 deletions modules/rpg/gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,18 @@ end

local function add_gui_increase_stat(element, name, player)
local rpg_t = Public.get_value_from_player(player.index)
local sprite = 'virtual-signal/signal-red'
local symbol = ''
local e = element.add({ type = 'sprite-button', name = name, caption = symbol })
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
local e = element.add({ type = 'sprite-button', name = name, caption = symbol, sprite = sprite })
e.style.maximal_height = 38
e.style.minimal_height = 38
e.style.maximal_width = 38
e.style.minimal_width = 38
e.style.font = 'default-large-semibold'
e.style.font_color = { 0, 0, 0 }
e.style.horizontal_align = 'center'
e.style.vertical_align = 'center'
e.style.padding = 0
Expand Down
3 changes: 0 additions & 3 deletions modules/rpg/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ local function on_gui_click(event)
if element.caption ~= '' then
return
end
if element.sprite ~= 'virtual-signal/signal-red' then
return
end

local rpg_t = Public.get_value_from_player(player.index)

Expand Down
4 changes: 2 additions & 2 deletions modules/rpg/spells.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ spells[#spells + 1] = {

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
player.teleport(pos, surface)
else
Expand Down Expand Up @@ -1145,7 +1145,7 @@ spells[#spells + 1] = {

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
player.teleport(pos, surface)
else
Expand Down
8 changes: 8 additions & 0 deletions utils/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,14 @@ function Public:set_default(defaults)
return self
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.
---@param func function
function Public:callback(func)
Expand Down
2 changes: 1 addition & 1 deletion utils/commands/misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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) } }

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
entity.destroy()
i = i + 1
Expand Down

0 comments on commit c74f3db

Please sign in to comment.