2020-10-10 01:33:11 +02:00
|
|
|
local Event = require 'utils.event'
|
|
|
|
local Terrain = require 'maps.cave_miner_v2.terrain'
|
|
|
|
local Functions = require 'maps.cave_miner_v2.functions'
|
2020-10-10 03:43:49 +02:00
|
|
|
local Market = require 'maps.cave_miner_v2.market'
|
2020-10-10 01:33:11 +02:00
|
|
|
local Global = require 'utils.global'
|
|
|
|
local Server = require 'utils.server'
|
|
|
|
|
|
|
|
local math_floor = math.floor
|
|
|
|
|
|
|
|
local cave_miner = {}
|
|
|
|
Global.register(
|
|
|
|
cave_miner,
|
|
|
|
function(tbl)
|
|
|
|
cave_miner = tbl
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
local function on_player_joined_game(event)
|
|
|
|
local player = game.players[event.player_index]
|
|
|
|
local tick = game.ticks_played
|
|
|
|
if tick == 0 then
|
|
|
|
if player.character and player.character.valid then
|
|
|
|
player.character.destroy()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function on_player_changed_position(event)
|
|
|
|
local player = game.players[event.player_index]
|
|
|
|
if not player.character then return end
|
|
|
|
if not player.character.valid then return end
|
|
|
|
Terrain.reveal(game.surfaces.nauvis, game.surfaces.cave_miner_source, {x = math_floor(player.position.x), y = math_floor(player.position.y)}, 8)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function on_chunk_generated(event)
|
|
|
|
local surface = event.surface
|
|
|
|
if surface.index == 1 then
|
|
|
|
Terrain.out_of_map(event)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if surface.name == "cave_miner_source" then
|
|
|
|
Terrain.generate_cave(event)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-10 03:43:49 +02:00
|
|
|
local function on_market_item_purchased(event)
|
|
|
|
Market.offer_bought(event, cave_miner)
|
|
|
|
end
|
|
|
|
|
2020-10-10 01:33:11 +02:00
|
|
|
local function init(cave_miner)
|
|
|
|
local tick = game.ticks_played
|
|
|
|
if tick % 60 ~= 0 then return end
|
|
|
|
Terrain.roll_source_surface()
|
|
|
|
|
2020-10-10 03:43:49 +02:00
|
|
|
cave_miner.pickaxe_tier = 0
|
|
|
|
|
|
|
|
local force = game.forces.player
|
|
|
|
Functions.set_mining_speed(cave_miner, force)
|
|
|
|
|
|
|
|
force.technologies["steel-axe"].enabled = false
|
2020-10-10 01:33:11 +02:00
|
|
|
|
|
|
|
cave_miner.gamestate = "spawn_players"
|
|
|
|
end
|
|
|
|
|
|
|
|
local function spawn_players(cave_miner)
|
|
|
|
local tick = game.ticks_played
|
|
|
|
if tick % 60 ~= 0 then return end
|
|
|
|
Terrain.reveal(game.surfaces.nauvis, game.surfaces.cave_miner_source, {x = 0, y = 0}, 8)
|
2020-10-10 03:43:49 +02:00
|
|
|
Market.spawn(cave_miner)
|
2020-10-10 01:33:11 +02:00
|
|
|
for _, player in pairs(game.connected_players) do
|
|
|
|
Functions.spawn_player(player)
|
|
|
|
end
|
|
|
|
cave_miner.gamestate = "game_in_progress"
|
|
|
|
end
|
|
|
|
|
|
|
|
local function game_in_progress(cave_miner)
|
|
|
|
local tick = game.ticks_played
|
|
|
|
if tick % 60 ~= 0 then return end
|
|
|
|
end
|
|
|
|
|
|
|
|
local gamestates = {
|
|
|
|
["init"] = init,
|
|
|
|
["spawn_players"] = spawn_players,
|
|
|
|
["game_in_progress"] = game_in_progress,
|
|
|
|
}
|
|
|
|
|
|
|
|
local function on_tick()
|
|
|
|
gamestates[cave_miner.gamestate](cave_miner)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function on_init()
|
|
|
|
cave_miner.reset_counter = 0
|
2020-10-10 03:43:49 +02:00
|
|
|
cave_miner.pickaxe_boost_per_level = 0.25
|
2020-10-10 01:33:11 +02:00
|
|
|
cave_miner.gamestate = "init"
|
|
|
|
cave_miner.mining_speed_bonus = 100
|
2020-10-10 03:43:49 +02:00
|
|
|
|
|
|
|
global.rocks_yield_ore_maximum_amount = 256
|
|
|
|
global.rocks_yield_ore_base_amount = 32
|
|
|
|
global.rocks_yield_ore_distance_modifier = 0.01
|
2020-10-10 01:33:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
Event.on_init(on_init)
|
|
|
|
Event.add(defines.events.on_tick, on_tick)
|
|
|
|
Event.add(defines.events.on_chunk_generated, on_chunk_generated)
|
|
|
|
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
2020-10-10 03:43:49 +02:00
|
|
|
Event.add(defines.events.on_player_changed_position, on_player_changed_position)
|
|
|
|
Event.add(defines.events.on_market_item_purchased, on_market_item_purchased)
|
|
|
|
|
|
|
|
require "modules.rocks_yield_ore"
|