mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-02-03 13:12:11 +02:00
minor changes
added Collapse.start_now(true/false)
This commit is contained in:
parent
fe1601bc57
commit
17eec0b6b2
@ -1,5 +1,5 @@
|
||||
--Hunger games balance things by Gerkiz --
|
||||
local Event = require 'utils.event'
|
||||
local Public = {}
|
||||
|
||||
local function player_ammo_starting_modifiers()
|
||||
local data = {
|
||||
@ -89,7 +89,7 @@ local function enemy_ammo_starting_modifiers()
|
||||
['grenade'] = 0,
|
||||
['landmine'] = 0,
|
||||
['laser-turret'] = 0,
|
||||
['melee'] = 0.5,
|
||||
['melee'] = 0,
|
||||
['railgun'] = 0,
|
||||
['rocket'] = 0,
|
||||
['shotgun-shell'] = 0
|
||||
@ -100,18 +100,18 @@ end
|
||||
local function enemy_ammo_evolution_modifiers()
|
||||
local data = {
|
||||
['artillery-shell'] = 1,
|
||||
['biological'] = 2,
|
||||
['biological'] = 1,
|
||||
['bullet'] = 1,
|
||||
--['cannon-shell'] = 1,
|
||||
['capsule'] = 1,
|
||||
['combat-robot-beam'] = 1,
|
||||
['combat-robot-laser'] = 1,
|
||||
['electric'] = 1,
|
||||
['flamethrower'] = 2,
|
||||
['flamethrower'] = 1,
|
||||
--['grenade'] = 1,
|
||||
--['landmine'] = 1,
|
||||
['laser-turret'] = 2,
|
||||
['melee'] = 2
|
||||
['laser-turret'] = 1,
|
||||
['melee'] = 1
|
||||
--['railgun'] = 1,
|
||||
--['rocket'] = 1,
|
||||
--['shotgun-shell'] = 1
|
||||
@ -129,7 +129,7 @@ local function init_player_weapon_damage(force)
|
||||
end
|
||||
end
|
||||
|
||||
local function init_enemy_weapon_damage()
|
||||
function Public.init_enemy_weapon_damage()
|
||||
local e, s, sd = game.forces['enemy'], game.forces['scrap'], game.forces['scrap_defense']
|
||||
|
||||
for k, v in pairs(enemy_ammo_starting_modifiers()) do
|
||||
@ -196,6 +196,7 @@ local function research_finished(event)
|
||||
end
|
||||
end
|
||||
|
||||
Event.on_init(init_enemy_weapon_damage)
|
||||
Event.on_nth_tick(18000, enemy_weapon_damage)
|
||||
--Event.add(defines.events.on_research_finished, research_finished)
|
||||
|
||||
return Public
|
||||
|
@ -1,66 +0,0 @@
|
||||
local Event = require 'utils.event'
|
||||
local Modifier = require 'player_modifiers'
|
||||
local Color = require 'utils.color_presets'
|
||||
|
||||
local function validate_player(player)
|
||||
if not player then
|
||||
return false
|
||||
end
|
||||
if not player.valid then
|
||||
return false
|
||||
end
|
||||
if not player.character then
|
||||
return false
|
||||
end
|
||||
if not player.connected then
|
||||
return false
|
||||
end
|
||||
if not game.players[player.name] then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function compute_fullness(player)
|
||||
local inv = player.get_inventory(defines.inventory.character_main)
|
||||
local max_stacks = #inv
|
||||
local num_stacks = 0
|
||||
|
||||
local contents = inv.get_contents()
|
||||
for item, count in pairs(contents) do
|
||||
local stack_size = 1
|
||||
if game.item_prototypes[item].stackable then
|
||||
stack_size = game.item_prototypes[item].stack_size
|
||||
end
|
||||
|
||||
num_stacks = num_stacks + count / stack_size
|
||||
end
|
||||
|
||||
return num_stacks / max_stacks
|
||||
end
|
||||
|
||||
local function check_burden(event)
|
||||
local player_modifiers = Modifier.get_table()
|
||||
local player = game.players[event.player_index]
|
||||
validate_player(player)
|
||||
local fullness = compute_fullness(player)
|
||||
player_modifiers[player.index].character_running_speed_modifier['scrapyard'] = 0.3 - fullness
|
||||
player_modifiers[player.index].character_mining_speed_modifier['scrapyard'] = 0.3 - fullness
|
||||
Modifier.update_player_modifiers(player)
|
||||
if fullness >= 0.3 and fullness <= 0.301 then
|
||||
player.print('You feel all of a sudden burden.', Color.yellow)
|
||||
elseif fullness >= 0.5 and fullness <= 0.501 then
|
||||
player.print('Maybe you should drop some of that inventory to lessen the burden.', Color.red)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_init(event)
|
||||
script.on_event(defines.events.on_player_main_inventory_changed, check_burden)
|
||||
end
|
||||
|
||||
local function on_load(event)
|
||||
script.on_event(defines.events.on_player_main_inventory_changed, check_burden)
|
||||
end
|
||||
|
||||
Event.on_init(on_init)
|
||||
Event.on_load(on_load)
|
@ -1,248 +0,0 @@
|
||||
local Global = require 'utils.global'
|
||||
local Public = {}
|
||||
|
||||
local math_floor = math.floor
|
||||
local table_shuffle_table = table.shuffle_table
|
||||
|
||||
local collapse = {}
|
||||
Global.register(
|
||||
collapse,
|
||||
function(tbl)
|
||||
collapse = tbl
|
||||
end
|
||||
)
|
||||
|
||||
local directions = {
|
||||
['north'] = function(position)
|
||||
local width = collapse.surface.map_gen_settings.width
|
||||
if width > collapse.max_line_size then
|
||||
width = collapse.max_line_size
|
||||
end
|
||||
local a = width * 0.5 + 1
|
||||
collapse.vector = {0, -1}
|
||||
collapse.area = {{position.x - a, position.y - 1}, {position.x + a, position.y}}
|
||||
end,
|
||||
['south'] = function(position)
|
||||
local width = collapse.surface.map_gen_settings.width
|
||||
if width > collapse.max_line_size then
|
||||
width = collapse.max_line_size
|
||||
end
|
||||
local a = width * 0.5 + 1
|
||||
collapse.vector = {0, 1}
|
||||
collapse.area = {{position.x - a, position.y}, {position.x + a, position.y + 1}}
|
||||
end,
|
||||
['west'] = function(position)
|
||||
local width = collapse.surface.map_gen_settings.height
|
||||
if width > collapse.max_line_size then
|
||||
width = collapse.max_line_size
|
||||
end
|
||||
local a = width * 0.5 + 1
|
||||
collapse.vector = {-1, 0}
|
||||
collapse.area = {{position.x - 1, position.y - a}, {position.x, position.y + a}}
|
||||
end,
|
||||
['east'] = function(position)
|
||||
local width = collapse.surface.map_gen_settings.height
|
||||
if width > collapse.max_line_size then
|
||||
width = collapse.max_line_size
|
||||
end
|
||||
local a = width * 0.5 + 1
|
||||
collapse.vector = {1, 0}
|
||||
collapse.area = {{position.x, position.y - a}, {position.x + 1, position.y + a}}
|
||||
end
|
||||
}
|
||||
|
||||
local function print_debug(a)
|
||||
print('Collapse error #' .. a)
|
||||
end
|
||||
|
||||
local function set_collapse_tiles(surface)
|
||||
game.forces.player.chart(surface, collapse.area)
|
||||
collapse.tiles = surface.find_tiles_filtered({area = collapse.area})
|
||||
if not collapse.tiles then
|
||||
return
|
||||
end
|
||||
collapse.size_of_tiles = #collapse.tiles
|
||||
if collapse.size_of_tiles > 0 then
|
||||
table_shuffle_table(collapse.tiles)
|
||||
end
|
||||
collapse.position = {x = collapse.position.x + collapse.vector[1], y = collapse.position.y + collapse.vector[2]}
|
||||
local v = collapse.vector
|
||||
local area = collapse.area
|
||||
collapse.area = {{area[1][1] + v[1], area[1][2] + v[2]}, {area[2][1] + v[1], area[2][2] + v[2]}}
|
||||
game.forces.player.chart(surface, collapse.area)
|
||||
end
|
||||
|
||||
local function progress()
|
||||
local surface = collapse.surface
|
||||
|
||||
if not collapse.start_now then
|
||||
return
|
||||
end
|
||||
|
||||
local tiles = collapse.tiles
|
||||
if not tiles then
|
||||
set_collapse_tiles(surface)
|
||||
tiles = collapse.tiles
|
||||
end
|
||||
if not tiles then
|
||||
return
|
||||
end
|
||||
|
||||
for _ = 1, collapse.amount, 1 do
|
||||
local tile = tiles[collapse.size_of_tiles]
|
||||
if not tile then
|
||||
collapse.tiles = nil
|
||||
return
|
||||
end
|
||||
collapse.size_of_tiles = collapse.size_of_tiles - 1
|
||||
if not tile.valid then
|
||||
return
|
||||
end
|
||||
if collapse.kill then
|
||||
local position = {tile.position.x + 0.5, tile.position.y + 0.5}
|
||||
for _, e in pairs(
|
||||
surface.find_entities_filtered(
|
||||
{area = {{position[1] - 2, position[2] - 2}, {position[1] + 2, position[2] + 2}}}
|
||||
)
|
||||
) do
|
||||
if e.valid and e.health then
|
||||
e.die()
|
||||
end
|
||||
end
|
||||
end
|
||||
surface.set_tiles({{name = 'out-of-map', position = tile.position}}, true)
|
||||
end
|
||||
end
|
||||
|
||||
function Public.set_surface(surface)
|
||||
if not surface then
|
||||
print_debug(1)
|
||||
return
|
||||
end
|
||||
if not surface.valid then
|
||||
print_debug(2)
|
||||
return
|
||||
end
|
||||
if not game.surfaces[surface.index] then
|
||||
print_debug(3)
|
||||
return
|
||||
end
|
||||
collapse.surface = surface
|
||||
end
|
||||
|
||||
function Public.set_direction(direction)
|
||||
if not directions[direction] then
|
||||
print_debug(11)
|
||||
return
|
||||
end
|
||||
directions[direction](collapse.position)
|
||||
end
|
||||
|
||||
function Public.set_speed(speed)
|
||||
if not speed then
|
||||
print_debug(8)
|
||||
return
|
||||
end
|
||||
speed = math_floor(speed)
|
||||
if speed < 1 then
|
||||
speed = 1
|
||||
end
|
||||
collapse.speed = speed
|
||||
end
|
||||
|
||||
function Public.set_amount(amount)
|
||||
if not amount then
|
||||
print_debug(9)
|
||||
return
|
||||
end
|
||||
amount = math_floor(amount)
|
||||
if amount < 0 then
|
||||
amount = 0
|
||||
end
|
||||
collapse.amount = amount
|
||||
end
|
||||
|
||||
function Public.set_position(position)
|
||||
if not position then
|
||||
print_debug(4)
|
||||
return
|
||||
end
|
||||
if not position.x and not position[1] then
|
||||
print_debug(5)
|
||||
return
|
||||
end
|
||||
if not position.y and not position[2] then
|
||||
print_debug(6)
|
||||
return
|
||||
end
|
||||
local x = 0
|
||||
local y = 0
|
||||
if position[1] then
|
||||
x = position[1]
|
||||
end
|
||||
if position[2] then
|
||||
y = position[2]
|
||||
end
|
||||
if position.x then
|
||||
x = position.x
|
||||
end
|
||||
if position.y then
|
||||
y = position.y
|
||||
end
|
||||
collapse.position = {x = x, y = y}
|
||||
end
|
||||
|
||||
function Public.get_position()
|
||||
return collapse.position
|
||||
end
|
||||
|
||||
function Public.start_now(status)
|
||||
if status == true then
|
||||
collapse.start_now = true
|
||||
elseif status == false then
|
||||
collapse.start_now = false
|
||||
end
|
||||
return collapse.start_now
|
||||
end
|
||||
|
||||
function Public.set_max_line_size(size)
|
||||
if not size then
|
||||
print_debug(22)
|
||||
return
|
||||
end
|
||||
size = math_floor(size)
|
||||
if size <= 0 then
|
||||
print_debug(21)
|
||||
return
|
||||
end
|
||||
collapse.max_line_size = size
|
||||
end
|
||||
|
||||
function Public.set_kill_entities(a)
|
||||
collapse.kill = a
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
Public.set_surface(game.surfaces.nauvis)
|
||||
Public.set_position({0, 32})
|
||||
Public.set_max_line_size(256)
|
||||
Public.set_direction('north')
|
||||
Public.set_kill_entities(true)
|
||||
collapse.tiles = nil
|
||||
collapse.speed = 1
|
||||
collapse.amount = 8
|
||||
collapse.start_now = false
|
||||
end
|
||||
|
||||
local function on_tick()
|
||||
if game.tick % collapse.speed ~= 0 then
|
||||
return
|
||||
end
|
||||
progress()
|
||||
end
|
||||
|
||||
local Event = require 'utils.event'
|
||||
Event.on_init(on_init)
|
||||
Event.add(defines.events.on_tick, on_tick)
|
||||
|
||||
return Public
|
@ -106,11 +106,11 @@ local function set_comfy_speech_bubble(text)
|
||||
this.comfybubble.destroy()
|
||||
end
|
||||
this.comfybubble =
|
||||
this.comfylatron.surface.create_entity(
|
||||
this.grandmaster.surface.create_entity(
|
||||
{
|
||||
name = 'compi-speech-bubble',
|
||||
position = this.comfylatron.position,
|
||||
source = this.comfylatron,
|
||||
position = this.grandmaster.position,
|
||||
source = this.grandmaster,
|
||||
text = text
|
||||
}
|
||||
)
|
||||
@ -118,16 +118,16 @@ end
|
||||
|
||||
local function is_target_inside_habitat(pos, surface)
|
||||
local this = Scrap_table.get_table()
|
||||
if pos.x < this.comfylatron_habitat.left_top.x then
|
||||
if pos.x < this.grandmaster_habitat.left_top.x then
|
||||
return false
|
||||
end
|
||||
if pos.x > this.comfylatron_habitat.right_bottom.x then
|
||||
if pos.x > this.grandmaster_habitat.right_bottom.x then
|
||||
return false
|
||||
end
|
||||
if pos.y < this.comfylatron_habitat.left_top.y then
|
||||
if pos.y < this.grandmaster_habitat.left_top.y then
|
||||
return false
|
||||
end
|
||||
if pos.y > this.comfylatron_habitat.right_bottom.y then
|
||||
if pos.y > this.grandmaster_habitat.right_bottom.y then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
@ -136,12 +136,12 @@ end
|
||||
local function get_nearby_players()
|
||||
local this = Scrap_table.get_table()
|
||||
local players =
|
||||
this.comfylatron.surface.find_entities_filtered(
|
||||
this.grandmaster.surface.find_entities_filtered(
|
||||
{
|
||||
name = 'character',
|
||||
area = {
|
||||
{this.comfylatron.position.x - 9, this.comfylatron.position.y - 9},
|
||||
{this.comfylatron.position.x + 9, this.comfylatron.position.y + 9}
|
||||
{this.grandmaster.position.x - 9, this.grandmaster.position.y - 9},
|
||||
{this.grandmaster.position.x + 9, this.grandmaster.position.y + 9}
|
||||
}
|
||||
}
|
||||
)
|
||||
@ -154,10 +154,10 @@ end
|
||||
local function visit_player()
|
||||
local this = Scrap_table.get_table()
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
if this.comfylatron_last_player_visit > game.tick then
|
||||
if this.grandmaster_last_player_visit > game.tick then
|
||||
return false
|
||||
end
|
||||
this.comfylatron_last_player_visit = game.tick + math_random(7200, 10800)
|
||||
this.grandmaster_last_player_visit = game.tick + math_random(7200, 10800)
|
||||
|
||||
local players = {}
|
||||
for _, p in pairs(game.connected_players) do
|
||||
@ -176,7 +176,7 @@ local function visit_player()
|
||||
return
|
||||
end
|
||||
|
||||
this.comfylatron.set_command(
|
||||
this.grandmaster.set_command(
|
||||
{
|
||||
type = defines.command.go_to_location,
|
||||
destination_entity = player.character,
|
||||
@ -194,7 +194,7 @@ local function visit_player()
|
||||
str = str .. symbols[math_random(1, #symbols)]
|
||||
set_comfy_speech_bubble(str)
|
||||
|
||||
this.comfylatron_greet_player_index = player.index
|
||||
this.grandmaster_greet_player_index = player.index
|
||||
|
||||
return true
|
||||
end
|
||||
@ -204,17 +204,17 @@ local function greet_player(nearby_characters)
|
||||
if not nearby_characters then
|
||||
return false
|
||||
end
|
||||
if not this.comfylatron_greet_player_index then
|
||||
if not this.grandmaster_greet_player_index then
|
||||
return false
|
||||
end
|
||||
for _, c in pairs(nearby_characters) do
|
||||
if c.player.index == this.comfylatron_greet_player_index then
|
||||
if c.player.index == this.grandmaster_greet_player_index then
|
||||
local str = texts['greetings'][math_random(1, #texts['greetings'])] .. ' '
|
||||
str = str .. c.player.name
|
||||
local symbols = {'. ', '! ', '. ', '! ', '? ', '... '}
|
||||
str = str .. symbols[math_random(1, 6)]
|
||||
set_comfy_speech_bubble(str)
|
||||
this.comfylatron_greet_player_index = false
|
||||
this.grandmaster_greet_player_index = false
|
||||
return true
|
||||
end
|
||||
end
|
||||
@ -258,10 +258,10 @@ local function desync(event)
|
||||
local m = 12
|
||||
local m2 = m * 0.005
|
||||
for i = 1, 32, 1 do
|
||||
this.comfylatron.surface.create_particle(
|
||||
this.grandmaster.surface.create_particle(
|
||||
{
|
||||
name = 'iron-ore-particle',
|
||||
position = this.comfylatron.position,
|
||||
position = this.grandmaster.position,
|
||||
frame_speed = 0.1,
|
||||
vertical_speed = 0.1,
|
||||
height = 0.1,
|
||||
@ -270,26 +270,36 @@ local function desync(event)
|
||||
)
|
||||
end
|
||||
if not event or math_random(1, 4) == 1 then
|
||||
this.comfylatron.surface.create_entity({name = 'medium-explosion', position = this.comfylatron.position})
|
||||
this.comfylatron.surface.create_entity(
|
||||
this.grandmaster.surface.create_entity({name = 'medium-explosion', position = this.grandmaster.position})
|
||||
this.grandmaster.surface.create_entity(
|
||||
{
|
||||
name = 'flying-text',
|
||||
position = this.comfylatron.position,
|
||||
position = this.grandmaster.position,
|
||||
text = 'desync',
|
||||
color = {r = 150, g = 0, b = 0}
|
||||
}
|
||||
)
|
||||
this.comfylatron.destroy()
|
||||
this.comfylatron = nil
|
||||
this.grandmaster.destroy()
|
||||
this.grandmaster = nil
|
||||
else
|
||||
this.comfylatron.surface.create_entity(
|
||||
this.grandmaster.surface.create_entity(
|
||||
{
|
||||
name = 'flying-text',
|
||||
position = this.comfylatron.position,
|
||||
position = this.grandmaster.position,
|
||||
text = 'desync evaded',
|
||||
color = {r = 0, g = 150, b = 0}
|
||||
}
|
||||
)
|
||||
if event.cause then
|
||||
if event.cause.valid and event.cause.player then
|
||||
game.print(
|
||||
'[color=blue]Grandmaster:[/color]: I got you this time! Back to work, ' ..
|
||||
event.cause.player.name .. '!',
|
||||
{r = 200, g = 0, b = 0}
|
||||
)
|
||||
event.cause.die('player', this.grandmaster)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -310,11 +320,11 @@ local function analyze_random_nearby_entity()
|
||||
end
|
||||
|
||||
local entities =
|
||||
this.comfylatron.surface.find_entities_filtered(
|
||||
this.grandmaster.surface.find_entities_filtered(
|
||||
{
|
||||
area = {
|
||||
{this.comfylatron.position.x - 4, this.comfylatron.position.y - 4},
|
||||
{this.comfylatron.position.x + 4, this.comfylatron.position.y + 4}
|
||||
{this.grandmaster.position.x - 4, this.grandmaster.position.y - 4},
|
||||
{this.grandmaster.position.x + 4, this.grandmaster.position.y + 4}
|
||||
}
|
||||
}
|
||||
)
|
||||
@ -348,8 +358,8 @@ local function analyze_random_nearby_entity()
|
||||
end
|
||||
set_comfy_speech_bubble(str)
|
||||
|
||||
if not this.comfylatron_greet_player_index then
|
||||
this.comfylatron.set_command(
|
||||
if not this.grandmaster_greet_player_index then
|
||||
this.grandmaster.set_command(
|
||||
{
|
||||
type = defines.command.go_to_location,
|
||||
destination_entity = entity,
|
||||
@ -372,24 +382,24 @@ local function go_to_some_location()
|
||||
return false
|
||||
end
|
||||
|
||||
if this.comfylatron_greet_player_index then
|
||||
local player = game.players[this.comfylatron_greet_player_index]
|
||||
if player.surface ~= this.comfylatron.surface then
|
||||
if this.grandmaster_greet_player_index then
|
||||
local player = game.players[this.grandmaster_greet_player_index]
|
||||
if player.surface ~= this.grandmaster.surface then
|
||||
return
|
||||
end
|
||||
if not player.character then
|
||||
this.comfylatron_greet_player_index = nil
|
||||
this.grandmaster_greet_player_index = nil
|
||||
return false
|
||||
end
|
||||
if not player.character.valid then
|
||||
this.comfylatron_greet_player_index = nil
|
||||
this.grandmaster_greet_player_index = nil
|
||||
return false
|
||||
end
|
||||
if not is_target_inside_habitat(player.position, player.surface) then
|
||||
this.comfylatron_greet_player_index = nil
|
||||
this.grandmaster_greet_player_index = nil
|
||||
return false
|
||||
end
|
||||
this.comfylatron.set_command(
|
||||
this.grandmaster.set_command(
|
||||
{
|
||||
type = defines.command.go_to_location,
|
||||
destination_entity = player.character,
|
||||
@ -404,17 +414,17 @@ local function go_to_some_location()
|
||||
)
|
||||
else
|
||||
local p = {
|
||||
x = this.comfylatron.position.x + (-96 + math_random(0, 192)),
|
||||
y = this.comfylatron.position.y + (-96 + math_random(0, 192))
|
||||
x = this.grandmaster.position.x + (-96 + math_random(0, 192)),
|
||||
y = this.grandmaster.position.y + (-96 + math_random(0, 192))
|
||||
}
|
||||
local target = this.comfylatron.surface.find_non_colliding_position('compilatron', p, 8, 1)
|
||||
local target = this.grandmaster.surface.find_non_colliding_position('compilatron', p, 8, 1)
|
||||
if not target then
|
||||
return false
|
||||
end
|
||||
if not is_target_inside_habitat(target, this.comfylatron.surface) then
|
||||
if not is_target_inside_habitat(target, this.grandmaster.surface) then
|
||||
return false
|
||||
end
|
||||
this.comfylatron.set_command(
|
||||
this.grandmaster.set_command(
|
||||
{
|
||||
type = defines.command.go_to_location,
|
||||
destination = target,
|
||||
@ -437,7 +447,7 @@ local function go_to_some_location()
|
||||
return true
|
||||
end
|
||||
|
||||
local function spawn_comfylatron(surface)
|
||||
local function spawn_grandmaster(surface)
|
||||
local this = Scrap_table.get_table()
|
||||
if surface == nil then
|
||||
return
|
||||
@ -448,12 +458,12 @@ local function spawn_comfylatron(surface)
|
||||
if not this.locomotive.valid then
|
||||
return
|
||||
end
|
||||
if not this.comfylatron_last_player_visit then
|
||||
this.comfylatron_last_player_visit = 0
|
||||
if not this.grandmaster_last_player_visit then
|
||||
this.grandmaster_last_player_visit = 0
|
||||
end
|
||||
if not this.comfylatron_habitat then
|
||||
if not this.grandmaster_habitat then
|
||||
local pos = this.locomotive.position
|
||||
this.comfylatron_habitat = {
|
||||
this.grandmaster_habitat = {
|
||||
left_top = {x = pos.x - 256, y = pos.y - 256},
|
||||
right_bottom = {x = pos.x + 256, y = pos.y + 256}
|
||||
}
|
||||
@ -475,7 +485,7 @@ local function spawn_comfylatron(surface)
|
||||
if not position then
|
||||
return false
|
||||
end
|
||||
this.comfylatron =
|
||||
this.grandmaster =
|
||||
surface.create_entity(
|
||||
{
|
||||
name = 'compilatron',
|
||||
@ -511,14 +521,14 @@ local function heartbeat()
|
||||
if surface == nil then
|
||||
return
|
||||
end
|
||||
if not this.comfylatron then
|
||||
if not this.grandmaster then
|
||||
if math_random(1, 4) == 1 then
|
||||
spawn_comfylatron(surface)
|
||||
spawn_grandmaster(surface)
|
||||
end
|
||||
return
|
||||
end
|
||||
if not this.comfylatron.valid then
|
||||
this.comfylatron = nil
|
||||
if not this.grandmaster.valid then
|
||||
this.grandmaster = nil
|
||||
return
|
||||
end
|
||||
if visit_player() then
|
||||
@ -541,13 +551,13 @@ end
|
||||
|
||||
local function on_entity_damaged(event)
|
||||
local this = Scrap_table.get_table()
|
||||
if not this.comfylatron then
|
||||
if not this.grandmaster then
|
||||
return
|
||||
end
|
||||
if not event.entity.valid then
|
||||
return
|
||||
end
|
||||
if event.entity ~= this.comfylatron then
|
||||
if event.entity ~= this.grandmaster then
|
||||
return
|
||||
end
|
||||
desync(event)
|
||||
@ -555,25 +565,25 @@ end
|
||||
|
||||
local function on_entity_died(event)
|
||||
local this = Scrap_table.get_table()
|
||||
if not this.comfylatron then
|
||||
if not this.grandmaster then
|
||||
return
|
||||
end
|
||||
if not event.entity.valid then
|
||||
return
|
||||
end
|
||||
if event.entity ~= this.comfylatron then
|
||||
if event.entity ~= this.grandmaster then
|
||||
return
|
||||
end
|
||||
if this.comfybubble then
|
||||
this.comfybubble.destroy()
|
||||
end
|
||||
if this.comfylatron then
|
||||
this.comfylatron.die()
|
||||
if this.grandmaster then
|
||||
this.grandmaster.die()
|
||||
end
|
||||
this.comfybubble = nil
|
||||
this.comfylatron = nil
|
||||
this.comfylatron_habitat = nil
|
||||
this.comfylatron_last_player_visit = nil
|
||||
this.grandmaster = nil
|
||||
this.grandmaster_habitat = nil
|
||||
this.grandmaster_last_player_visit = nil
|
||||
end
|
||||
|
||||
local function on_tick()
|
||||
|
@ -1,19 +1,13 @@
|
||||
local Event = require 'utils.event'
|
||||
local Power = require 'maps.scrapyard.power'
|
||||
local ICW = require 'maps.scrapyard.icw.main'
|
||||
local WD = require 'modules.wave_defense.table'
|
||||
local Scrap_table = require 'maps.scrapyard.table'
|
||||
local RPG = require 'maps.scrapyard.rpg'
|
||||
local Terrain = require 'maps.scrapyard.terrain'
|
||||
require 'maps.scrapyard.locomotive_market'
|
||||
|
||||
local Public = {}
|
||||
|
||||
local desc = {
|
||||
['clear_threat_level'] = '[Wave Defense]:\nClears the current threat to 0\nUsable if threat level is too high.\nCan be purchased multiple times.',
|
||||
['energy_upgrade'] = '[Linked Power]:\nUpgrades the buffer size of the energy interface\nUsable if the power dies easily.\nCan be purchased multiple times.',
|
||||
['locomotive_max_health'] = '[Locomotive Health]:\nUpgrades the train health.\nCan be purchased multiple times.'
|
||||
}
|
||||
|
||||
local energy_upgrade = 50000000
|
||||
|
||||
local function rebuild_energy_overworld(data)
|
||||
@ -36,7 +30,7 @@ local function rebuild_energy_overworld(data)
|
||||
end
|
||||
this.ow_energy =
|
||||
surface.create_entity {
|
||||
name = 'electric-energy-interface',
|
||||
name = 'hidden-electric-energy-interface',
|
||||
position = {
|
||||
x = this.locomotive.position.x,
|
||||
y = this.locomotive.position.y + 2
|
||||
@ -45,19 +39,8 @@ local function rebuild_energy_overworld(data)
|
||||
force = game.forces.neutral
|
||||
}
|
||||
|
||||
rendering.draw_text {
|
||||
text = 'Power to locomotive',
|
||||
surface = surface,
|
||||
target = this.ow_energy,
|
||||
target_offset = {0, -1.5},
|
||||
color = {r = 0, g = 1, b = 0},
|
||||
alignment = 'center'
|
||||
}
|
||||
|
||||
this.ow_energy.minable = false
|
||||
this.ow_energy.destructible = false
|
||||
this.ow_energy.operable = false
|
||||
this.ow_energy.power_production = 0
|
||||
this.ow_energy.power_production = 5
|
||||
if this.energy_purchased then
|
||||
this.ow_energy.electric_buffer_size = energy_upgrade
|
||||
else
|
||||
@ -111,238 +94,33 @@ local function rebuild_energy_loco(data, rebuild)
|
||||
end
|
||||
end
|
||||
|
||||
local function refresh_market(data)
|
||||
local this = data.this
|
||||
|
||||
if this.market then
|
||||
for i = 1, 100, 1 do
|
||||
local a = this.market.remove_market_item(1)
|
||||
if a == false then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local items = {
|
||||
{
|
||||
price = {
|
||||
{'coin', 5000 * (1 + this.train_upgrades)},
|
||||
{'chemical-science-pack', 200 * (1 + this.train_upgrades)},
|
||||
{'advanced-circuit', 150 * (1 + this.train_upgrades)}
|
||||
},
|
||||
offer = {type = 'nothing', effect_description = desc['clear_threat_level']}
|
||||
},
|
||||
{
|
||||
price = {
|
||||
{'coin', 5000 * (1 + this.train_upgrades)},
|
||||
{'solar-panel', 500 * (1 + this.train_upgrades)},
|
||||
{'accumulator', 100 * (1 + this.train_upgrades)}
|
||||
},
|
||||
offer = {type = 'nothing', effect_description = desc['energy_upgrade']}
|
||||
},
|
||||
{
|
||||
price = {
|
||||
{'coin', 5000 * (1 + this.train_upgrades)},
|
||||
{'copper-plate', 1500 * (1 + this.train_upgrades)},
|
||||
{'iron-plate', 500 * (1 + this.train_upgrades)}
|
||||
},
|
||||
offer = {type = 'nothing', effect_description = desc['locomotive_max_health']}
|
||||
},
|
||||
{price = {{'coin', 5}}, offer = {type = 'give-item', item = 'small-lamp'}},
|
||||
{price = {{'coin', 5}}, offer = {type = 'give-item', item = 'firearm-magazine'}},
|
||||
{price = {{'wood', 25}}, offer = {type = 'give-item', item = 'raw-fish', count = 2}},
|
||||
{price = {{'coin', 25}}, offer = {type = 'give-item', item = 'land-mine', count = 1}}
|
||||
}
|
||||
|
||||
for _, item in pairs(items) do
|
||||
this.market.add_market_item(item)
|
||||
end
|
||||
return items
|
||||
end
|
||||
|
||||
local function create_market(data, rebuild)
|
||||
local surface = data.surface
|
||||
local this = data.this
|
||||
local pos = {x = 18, y = 3}
|
||||
|
||||
if rebuild then
|
||||
local radius = 1024
|
||||
local area = {{x = -radius, y = -radius}, {x = radius, y = radius}}
|
||||
for _, entity in pairs(surface.find_entities_filtered {area = area, name = 'market'}) do
|
||||
entity.destroy()
|
||||
end
|
||||
this.market = nil
|
||||
end
|
||||
if this.market then
|
||||
for i = 1, 100, 1 do
|
||||
local a = this.market.remove_market_item(1)
|
||||
if a == false then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
this.market = surface.create_entity {name = 'market', position = pos, force = 'player'}
|
||||
|
||||
rendering.draw_text {
|
||||
text = 'Market',
|
||||
surface = surface,
|
||||
target = this.market,
|
||||
target_offset = {0, 2},
|
||||
color = {r = 0.98, g = 0.66, b = 0.22},
|
||||
alignment = 'center'
|
||||
}
|
||||
|
||||
this.market.destructible = false
|
||||
|
||||
local items = refresh_market(data)
|
||||
|
||||
for _, item in pairs(items) do
|
||||
this.market.add_market_item(item)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_market_item_purchased(event)
|
||||
local player = game.players[event.player_index]
|
||||
local market = event.market
|
||||
local offer_index = event.offer_index
|
||||
local offers = market.get_market_items()
|
||||
local bought_offer = offers[offer_index].offer
|
||||
if bought_offer.type ~= 'nothing' then
|
||||
return
|
||||
end
|
||||
local this = Scrap_table.get_table()
|
||||
local wdt = WD.get_table()
|
||||
local icw_table = ICW.get_table()
|
||||
if not this.locomotive then
|
||||
return
|
||||
end
|
||||
if not this.locomotive.valid then
|
||||
return
|
||||
end
|
||||
local unit_surface = this.locomotive.unit_number
|
||||
local surface = game.surfaces[icw_table.wagons[unit_surface].surface.index]
|
||||
|
||||
local data = {
|
||||
this = this,
|
||||
surface = surface,
|
||||
wave = wdt
|
||||
}
|
||||
|
||||
if bought_offer.effect_description == desc['clear_threat_level'] then
|
||||
game.print(
|
||||
'[color=blue]Grandmaster:[/color] ' ..
|
||||
player.name .. ' has bought the group some extra time. Threat level is no more!',
|
||||
{r = 0.22, g = 0.77, b = 0.44}
|
||||
)
|
||||
this.train_upgrades = this.train_upgrades + 1
|
||||
wdt.threat = 0
|
||||
|
||||
refresh_market(data)
|
||||
return
|
||||
end
|
||||
if bought_offer.effect_description == desc['energy_upgrade'] then
|
||||
game.print(
|
||||
'[color=blue]Grandmaster:[/color] ' ..
|
||||
player.name .. ' has bought the group a power upgrade The energy interface is now buffed!',
|
||||
{r = 0.22, g = 0.77, b = 0.44}
|
||||
)
|
||||
this.train_upgrades = this.train_upgrades + 1
|
||||
this.energy_purchased = true
|
||||
this.lo_energy.electric_buffer_size = this.lo_energy.electric_buffer_size + energy_upgrade
|
||||
this.ow_energy.electric_buffer_size = this.ow_energy.electric_buffer_size + energy_upgrade
|
||||
|
||||
refresh_market(data)
|
||||
return
|
||||
end
|
||||
if bought_offer.effect_description == desc['locomotive_max_health'] then
|
||||
game.print(
|
||||
'[color=blue]Grandmaster:[/color] ' ..
|
||||
player.name .. ' has bought the group a train health modifier! The train health is now buffed!',
|
||||
{r = 0.22, g = 0.77, b = 0.44}
|
||||
)
|
||||
this.locomotive_max_health = this.locomotive_max_health + 2500
|
||||
this.train_upgrades = this.train_upgrades + 1
|
||||
rendering.set_text(this.health_text, 'HP: ' .. this.locomotive_health .. ' / ' .. this.locomotive_max_health)
|
||||
|
||||
refresh_market(data)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local function on_gui_opened(event)
|
||||
if not event.entity then
|
||||
return
|
||||
end
|
||||
if not event.entity.valid then
|
||||
return
|
||||
end
|
||||
local this = Scrap_table.get_table()
|
||||
local icw_table = ICW.get_table()
|
||||
if not this.locomotive then
|
||||
return
|
||||
end
|
||||
if not this.locomotive.valid then
|
||||
return
|
||||
end
|
||||
local unit_surface = this.locomotive.unit_number
|
||||
local surface = game.surfaces[icw_table.wagons[unit_surface].surface.index]
|
||||
|
||||
local data = {
|
||||
this = this,
|
||||
surface = surface
|
||||
}
|
||||
if event.entity.name == 'market' then
|
||||
refresh_market(data)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
--local function distance(data)
|
||||
-- local sqrt = math.sqrt
|
||||
-- local floor = math.floor
|
||||
-- local player = data.player
|
||||
-- local rpg = data.rpg
|
||||
-- local distance_to_center = floor(sqrt(player.position.x ^ 2 + player.position.y ^ 2))
|
||||
-- local location = distance_to_center
|
||||
-- if location < 950 then return end
|
||||
-- local min = 960 * rpg[player.index].bonus
|
||||
-- local max = 965 * rpg[player.index].bonus
|
||||
-- local min_times = location >= min
|
||||
-- local max_times = location <= max
|
||||
-- if min_times and max_times then
|
||||
-- rpg[player.index].bonus = rpg[player.index].bonus + 1
|
||||
-- player.print("[color=blue]Grandmaster:[/color] Survivor! Well done.")
|
||||
-- Public.gain_xp(player, 300 * rpg[player.index].bonus)
|
||||
-- return
|
||||
-- end
|
||||
--end
|
||||
|
||||
local function property_boost(data)
|
||||
local surface = data.surface
|
||||
local rng = math.random
|
||||
local xp_floating_text_color = {r = rng(0, 128), g = 128, b = 0}
|
||||
local visuals_delay = 1800
|
||||
local this = data.this
|
||||
local aura = this.locomotive_xp_aura
|
||||
local rpg = data.rpg
|
||||
local loco = this.locomotive.position
|
||||
local area = {
|
||||
left_top = {x = loco.x - 40, y = loco.y - 40},
|
||||
right_bottom = {x = loco.x + 40, y = loco.y + 40}
|
||||
left_top = {x = loco.x - aura, y = loco.y - aura},
|
||||
right_bottom = {x = loco.x + aura, y = loco.y + aura}
|
||||
}
|
||||
if this.beam then
|
||||
this.beam.destroy()
|
||||
end
|
||||
|
||||
for _, player in pairs(game.connected_players) do
|
||||
--if player.surface ~= surface then
|
||||
-- return -- players get xp inside train
|
||||
--end
|
||||
if Public.contains_positions(player.position, area) then
|
||||
local pos = player.position
|
||||
RPG.gain_xp(player, 0.2 * rpg[player.index].bonus)
|
||||
|
||||
player.create_local_flying_text {
|
||||
text = '+' .. '',
|
||||
position = {x = pos.x, y = pos.y - 2},
|
||||
color = xp_floating_text_color,
|
||||
time_to_live = 120,
|
||||
speed = 2
|
||||
time_to_live = 60,
|
||||
speed = 3
|
||||
}
|
||||
rpg[player.index].xp_since_last_floaty_text = 0
|
||||
rpg[player.index].last_floaty_text = game.tick + visuals_delay
|
||||
@ -365,7 +143,19 @@ local function train_rainbow()
|
||||
g = math.sin((game.tick + 1200 + 770) / 1900) * 127 + 127
|
||||
}
|
||||
this.locomotive.color = color
|
||||
Public.render_train_hp()
|
||||
rendering.set_text(this.health_text, 'HP: ' .. this.locomotive_health .. ' / ' .. this.locomotive_max_health)
|
||||
if this.circle then
|
||||
rendering.destroy(this.circle)
|
||||
end
|
||||
this.circle =
|
||||
rendering.draw_circle {
|
||||
surface = game.surfaces[this.active_surface_index],
|
||||
target = this.locomotive,
|
||||
color = this.locomotive.color,
|
||||
filled = false,
|
||||
radius = this.locomotive_xp_aura,
|
||||
only_in_alt_mode = true
|
||||
}
|
||||
end
|
||||
|
||||
local function reveal_train_area()
|
||||
@ -469,15 +259,16 @@ end
|
||||
|
||||
local function tick()
|
||||
local this = Scrap_table.get_table()
|
||||
Public.power_source_overworld()
|
||||
Public.power_source_locomotive()
|
||||
Public.place_market()
|
||||
if this.energy_shared then
|
||||
Public.power_source_overworld()
|
||||
Public.power_source_locomotive()
|
||||
end
|
||||
if game.tick % 120 == 0 then
|
||||
Public.boost_players_around_train()
|
||||
end
|
||||
--if game.tick % 80 == 0 then
|
||||
-- train_rainbow()
|
||||
--end
|
||||
if game.tick % 80 == 0 then
|
||||
train_rainbow()
|
||||
end
|
||||
if this.train_reveal then
|
||||
if game.tick % 10 == 0 then
|
||||
reveal_train_area()
|
||||
@ -514,6 +305,7 @@ end
|
||||
function Public.render_train_hp()
|
||||
local this = Scrap_table.get_table()
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
|
||||
this.health_text =
|
||||
rendering.draw_text {
|
||||
text = 'HP: ' .. this.locomotive_health .. ' / ' .. this.locomotive_max_health,
|
||||
@ -526,6 +318,7 @@ function Public.render_train_hp()
|
||||
alignment = 'center',
|
||||
scale_with_zoom = false
|
||||
}
|
||||
|
||||
this.caption =
|
||||
rendering.draw_text {
|
||||
text = 'Grandmasters Train',
|
||||
@ -541,11 +334,12 @@ function Public.render_train_hp()
|
||||
|
||||
this.circle =
|
||||
rendering.draw_circle {
|
||||
surface = surface,
|
||||
surface = surface,
|
||||
target = this.locomotive,
|
||||
color = this.locomotive.color,
|
||||
filled = false,
|
||||
radius = 40
|
||||
radius = this.locomotive_xp_aura,
|
||||
only_in_alt_mode = true
|
||||
}
|
||||
end
|
||||
|
||||
@ -620,29 +414,6 @@ function Public.contains_positions(pos, area)
|
||||
return false
|
||||
end
|
||||
|
||||
function Public.place_market()
|
||||
local this = Scrap_table.get_table()
|
||||
local icw_table = ICW.get_table()
|
||||
if not this.locomotive then
|
||||
return
|
||||
end
|
||||
if not this.locomotive.valid then
|
||||
return
|
||||
end
|
||||
local unit_surface = this.locomotive.unit_number
|
||||
local surface = game.surfaces[icw_table.wagons[unit_surface].surface.index]
|
||||
|
||||
local data = {
|
||||
this = this,
|
||||
surface = surface
|
||||
}
|
||||
if not this.market then
|
||||
create_market(data)
|
||||
elseif not this.market.valid then
|
||||
create_market(data, true)
|
||||
end
|
||||
end
|
||||
|
||||
function Public.power_source_overworld()
|
||||
local this = Scrap_table.get_table()
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
@ -687,7 +458,5 @@ function Public.power_source_locomotive()
|
||||
end
|
||||
|
||||
Event.on_nth_tick(5, tick)
|
||||
Event.add(defines.events.on_market_item_purchased, on_market_item_purchased)
|
||||
Event.add(defines.events.on_gui_opened, on_gui_opened)
|
||||
|
||||
return Public
|
||||
|
649
maps/scrapyard/locomotive_market.lua
Normal file
649
maps/scrapyard/locomotive_market.lua
Normal file
@ -0,0 +1,649 @@
|
||||
local Event = require 'utils.event'
|
||||
local Scrap_table = require 'maps.scrapyard.table'
|
||||
local WD = require 'modules.wave_defense.table'
|
||||
local ICW = require 'maps.scrapyard.icw.main'
|
||||
local format_number = require 'util'.format_number
|
||||
|
||||
local grandmaster = '[color=blue]Grandmaster:[/color]'
|
||||
local duration_per_charge = 2700
|
||||
|
||||
local energy_upgrade = 50000000
|
||||
local random = math.random
|
||||
|
||||
local function shuffle(tbl)
|
||||
local size = #tbl
|
||||
for i = size, 1, -1 do
|
||||
local rand = random(size)
|
||||
tbl[i], tbl[rand] = tbl[rand], tbl[i]
|
||||
end
|
||||
return tbl
|
||||
end
|
||||
|
||||
local items = {
|
||||
['clear_threat_level'] = {
|
||||
stack = 1,
|
||||
value = 'coin',
|
||||
price = 50000,
|
||||
tooltip = '[Wave Defense]:\nClears the current threat to 0\nUsable if threat level is too high.\nCan be purchased multiple times.',
|
||||
sprite = 'item/computer',
|
||||
enabled = true
|
||||
},
|
||||
['energy_upgrade'] = {
|
||||
stack = 1,
|
||||
value = 'coin',
|
||||
price = 50000,
|
||||
tooltip = '[Linked Power]:\nUpgrades the buffer size of the energy interface\nUsable if the power dies easily.\nCan be purchased multiple times.',
|
||||
sprite = 'item/computer',
|
||||
enabled = true
|
||||
},
|
||||
['locomotive_max_health'] = {
|
||||
stack = 1,
|
||||
value = 'coin',
|
||||
price = 50000,
|
||||
tooltip = '[Locomotive Health]:\nUpgrades the train health.\nCan be purchased multiple times.',
|
||||
sprite = 'item/computer',
|
||||
enabled = true
|
||||
},
|
||||
['locomotive_xp_aura'] = {
|
||||
stack = 1,
|
||||
value = 'coin',
|
||||
price = 50000,
|
||||
tooltip = '[XP Aura]:\nUpgrades the aura that is around the train.\nNote! Reaching breach walls gives more XP.',
|
||||
sprite = 'item/computer',
|
||||
enabled = true
|
||||
},
|
||||
['player_terrain_reveal'] = {
|
||||
stack = 1,
|
||||
value = 'coin',
|
||||
price = 5000,
|
||||
tooltip = '[Terrain Reveal]:\nAllows the player to reveal terrain for a short amount of time.',
|
||||
sprite = 'item/computer',
|
||||
enabled = true
|
||||
},
|
||||
['small-lamp'] = {stack = 1, value = 'coin', price = 5, tooltip = 'Small Lamp'},
|
||||
['land-mine'] = {stack = 1, value = 'coin', price = 25, tooltip = 'Land Mine'},
|
||||
['raw-fish'] = {stack = 2, value = 'coin', price = 25, tooltip = 'Raw Fish'},
|
||||
['firearm-magazine'] = {stack = 1, value = 'coin', price = 5, tooltip = 'Firearm Magazine'},
|
||||
['loader'] = {stack = 1, value = 'coin', price = 150, tooltip = 'Loader'},
|
||||
['fast-loader'] = {stack = 1, value = 'coin', price = 300, tooltip = 'Fast Loader'}
|
||||
}
|
||||
|
||||
local space = {
|
||||
minimal_height = 10,
|
||||
top_padding = 0,
|
||||
bottom_padding = 0
|
||||
}
|
||||
|
||||
local function addStyle(guiIn, styleIn)
|
||||
for k, v in pairs(styleIn) do
|
||||
guiIn.style[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
local function adjustSpace(guiIn)
|
||||
addStyle(guiIn.add {type = 'line', direction = 'horizontal'}, space)
|
||||
end
|
||||
|
||||
local function validate_player(player)
|
||||
if not player then
|
||||
return false
|
||||
end
|
||||
if not player.valid then
|
||||
return false
|
||||
end
|
||||
if not player.character then
|
||||
return false
|
||||
end
|
||||
if not player.connected then
|
||||
return false
|
||||
end
|
||||
if not game.players[player.index] then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function close_market_gui(player)
|
||||
local this = Scrap_table.get_table()
|
||||
|
||||
local element = player.gui.center
|
||||
local data = this.players[player.index].data
|
||||
if not data then
|
||||
return
|
||||
end
|
||||
|
||||
if element and element.valid then
|
||||
element = element['market_gui']
|
||||
if element and element.valid then
|
||||
element.destroy()
|
||||
end
|
||||
if data.frame and data.frame.valid then
|
||||
data.frame.destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function redraw_market_items(gui, player, search_text)
|
||||
if not validate_player(player) then
|
||||
return
|
||||
end
|
||||
local this = Scrap_table.get_table()
|
||||
|
||||
gui.clear()
|
||||
shuffle(items)
|
||||
|
||||
local inventory = player.get_main_inventory()
|
||||
local player_item_count = inventory.get_item_count('coin')
|
||||
|
||||
local items_table = gui.add({type = 'table', column_count = 6})
|
||||
|
||||
local slider_value = math.ceil(this.players[player.index].data.slider.slider_value)
|
||||
for name, opts in pairs(items) do
|
||||
if not search_text then
|
||||
goto continue
|
||||
end
|
||||
if not search_text.text then
|
||||
goto continue
|
||||
end
|
||||
if not string.lower(name:gsub('-', ' ')):find(search_text.text) then
|
||||
goto continue
|
||||
end
|
||||
local item_count = opts.stack * slider_value
|
||||
local item_cost = opts.price * slider_value
|
||||
local flow = items_table.add({type = 'flow'})
|
||||
flow.style.vertical_align = 'bottom'
|
||||
|
||||
local button =
|
||||
flow.add(
|
||||
{
|
||||
type = 'sprite-button',
|
||||
sprite = opts.sprite or 'item/' .. name,
|
||||
number = item_count,
|
||||
name = name,
|
||||
tooltip = opts.tooltip,
|
||||
style = 'slot_button',
|
||||
enabled = opts.enabled
|
||||
}
|
||||
)
|
||||
flow.add(
|
||||
{
|
||||
type = 'label',
|
||||
caption = format_number(item_cost, true) .. ' coin'
|
||||
}
|
||||
)
|
||||
|
||||
if player_item_count < item_cost then
|
||||
button.enabled = false
|
||||
end
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
|
||||
local function redraw_coins_left(gui, player)
|
||||
if not validate_player(player) then
|
||||
return
|
||||
end
|
||||
|
||||
gui.clear()
|
||||
local inventory = player.get_main_inventory()
|
||||
local player_item_count = inventory.get_item_count('coin')
|
||||
|
||||
local coinsleft =
|
||||
gui.add(
|
||||
{
|
||||
type = 'label',
|
||||
caption = 'Coins left: ' .. format_number(player_item_count, true)
|
||||
}
|
||||
)
|
||||
|
||||
adjustSpace(coinsleft)
|
||||
end
|
||||
|
||||
local function slider_changed(event)
|
||||
local player = game.players[event.player_index]
|
||||
local this = Scrap_table.get_table()
|
||||
local slider_value
|
||||
|
||||
slider_value = this.players
|
||||
if not slider_value then
|
||||
return
|
||||
end
|
||||
slider_value = slider_value[player.index].data
|
||||
if not slider_value then
|
||||
return
|
||||
end
|
||||
slider_value = slider_value.slider
|
||||
if not slider_value then
|
||||
return
|
||||
end
|
||||
slider_value = slider_value.slider_value
|
||||
if not slider_value then
|
||||
return
|
||||
end
|
||||
slider_value = math.ceil(slider_value)
|
||||
this.players[player.index].data.text_input.text = slider_value
|
||||
redraw_market_items(this.players[player.index].data.item_frame, player, this.players[player.index].data.search_text)
|
||||
end
|
||||
|
||||
local function text_changed(event)
|
||||
local this = Scrap_table.get_table()
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
local data = this.players[player.index].data
|
||||
if not data then
|
||||
return
|
||||
end
|
||||
|
||||
local value = 0
|
||||
tonumber(data.text_input.text)
|
||||
if not value then
|
||||
return
|
||||
end
|
||||
data.slider.slider_value = value
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
end
|
||||
|
||||
local function gui_opened(event)
|
||||
local this = Scrap_table.get_table()
|
||||
|
||||
if not event.gui_type == defines.gui_type.entity then
|
||||
return
|
||||
end
|
||||
|
||||
local entity = event.entity
|
||||
if not entity then
|
||||
return
|
||||
end
|
||||
|
||||
if entity ~= this.market then
|
||||
return
|
||||
end
|
||||
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
if not validate_player(player) then
|
||||
return
|
||||
end
|
||||
|
||||
local inventory = player.get_main_inventory()
|
||||
local player_item_count = inventory.get_item_count('coin')
|
||||
|
||||
local data = this.players[player.index].data
|
||||
|
||||
if data.frame then
|
||||
data.frame = nil
|
||||
end
|
||||
local frame =
|
||||
player.gui.screen.add(
|
||||
{
|
||||
type = 'frame',
|
||||
caption = 'Market',
|
||||
direction = 'vertical',
|
||||
name = 'market_gui'
|
||||
}
|
||||
)
|
||||
|
||||
frame.auto_center = true
|
||||
|
||||
player.opened = frame
|
||||
frame.style.minimal_width = 500
|
||||
frame.style.minimal_height = 250
|
||||
|
||||
local search_table = frame.add({type = 'table', column_count = 2})
|
||||
search_table.add({type = 'label', caption = 'Search: '})
|
||||
local search_text = search_table.add({type = 'textfield'})
|
||||
|
||||
adjustSpace(frame)
|
||||
|
||||
local pane =
|
||||
frame.add {
|
||||
type = 'scroll-pane',
|
||||
direction = 'vertical',
|
||||
vertical_scroll_policy = 'always',
|
||||
horizontal_scroll_policy = 'never'
|
||||
}
|
||||
pane.style.maximal_height = 200
|
||||
pane.style.horizontally_stretchable = true
|
||||
pane.style.minimal_height = 200
|
||||
pane.style.right_padding = 0
|
||||
|
||||
local flow = frame.add({type = 'flow'})
|
||||
|
||||
adjustSpace(flow)
|
||||
|
||||
local slider_frame = frame.add({type = 'table', column_count = 5})
|
||||
|
||||
local left_button = slider_frame.add({type = 'button', caption = '-1', name = 'less'})
|
||||
local slider =
|
||||
slider_frame.add(
|
||||
{
|
||||
type = 'slider',
|
||||
minimum_value = 1,
|
||||
maximum_value = 1e3,
|
||||
value = 1
|
||||
}
|
||||
)
|
||||
|
||||
local right_button = slider_frame.add({type = 'button', caption = '+1', name = 'more'})
|
||||
|
||||
left_button.style.width = 0
|
||||
left_button.style.height = 0
|
||||
right_button.style.width = 0
|
||||
right_button.style.height = 0
|
||||
|
||||
slider_frame.add(
|
||||
{
|
||||
type = 'label',
|
||||
caption = 'Qty:'
|
||||
}
|
||||
)
|
||||
|
||||
local text_input =
|
||||
slider_frame.add(
|
||||
{
|
||||
type = 'textfield',
|
||||
text = 1
|
||||
}
|
||||
)
|
||||
|
||||
local coinsleft = frame.add({type = 'flow'})
|
||||
|
||||
coinsleft.add(
|
||||
{
|
||||
type = 'label',
|
||||
caption = 'Coins left: ' .. format_number(player_item_count, true)
|
||||
}
|
||||
)
|
||||
|
||||
this.players[player.index].data.search_text = search_text
|
||||
this.players[player.index].data.text_input = text_input
|
||||
this.players[player.index].data.slider = slider
|
||||
this.players[player.index].data.frame = frame
|
||||
this.players[player.index].data.item_frame = pane
|
||||
this.players[player.index].data.coins_left = coinsleft
|
||||
|
||||
redraw_market_items(pane, player, search_text)
|
||||
end
|
||||
|
||||
local function gui_click(event)
|
||||
local this = Scrap_table.get_table()
|
||||
local wdt = WD.get_table()
|
||||
|
||||
local element = event.element
|
||||
local player = game.players[event.player_index]
|
||||
if not validate_player(player) then
|
||||
return
|
||||
end
|
||||
|
||||
local data = this.players[player.index].data
|
||||
if not data then
|
||||
return
|
||||
end
|
||||
|
||||
if not element.valid then
|
||||
return
|
||||
end
|
||||
local name = element.name
|
||||
|
||||
if name == 'less' then
|
||||
local slider_value = this.players[player.index].data.slider.slider_value
|
||||
if slider_value > 1 then
|
||||
data.slider.slider_value = slider_value - 1
|
||||
data.text_input.text = data.slider.slider_value
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
end
|
||||
return
|
||||
elseif name == 'more' then
|
||||
local slider_value = data.slider.slider_value
|
||||
if slider_value <= 1e3 then
|
||||
data.slider.slider_value = slider_value + 1
|
||||
data.text_input.text = data.slider.slider_value
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if not player.opened then
|
||||
return
|
||||
end
|
||||
if not player.opened.name == 'market' then
|
||||
return
|
||||
end
|
||||
if not data then
|
||||
return
|
||||
end
|
||||
local item = items[name]
|
||||
if not item then
|
||||
return
|
||||
end
|
||||
|
||||
local inventory = player.get_main_inventory()
|
||||
local player_item_count = inventory.get_item_count(item.value)
|
||||
local slider_value = math.ceil(data.slider.slider_value)
|
||||
local cost = (item.price * slider_value)
|
||||
local item_count = item.stack * slider_value
|
||||
|
||||
if name == 'clear_threat_level' then
|
||||
player.remove_item({name = item.value, count = cost})
|
||||
|
||||
game.print(
|
||||
grandmaster .. ' ' .. player.name .. ' has bought the group some extra time. Threat level is no more!',
|
||||
{r = 0.98, g = 0.66, b = 0.22}
|
||||
)
|
||||
this.train_upgrades = this.train_upgrades + 1
|
||||
wdt.threat = 0
|
||||
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
redraw_coins_left(data.coins_left, player)
|
||||
|
||||
return
|
||||
end
|
||||
if name == 'energy_upgrade' then
|
||||
player.remove_item({name = item.value, count = cost})
|
||||
|
||||
game.print(
|
||||
grandmaster ..
|
||||
' ' .. player.name .. ' has bought the group a power upgrade! The energy interface is now buffed!',
|
||||
{r = 0.98, g = 0.66, b = 0.22}
|
||||
)
|
||||
this.train_upgrades = this.train_upgrades + 1
|
||||
this.energy_purchased = true
|
||||
this.lo_energy.electric_buffer_size = this.lo_energy.electric_buffer_size + energy_upgrade
|
||||
this.ow_energy.electric_buffer_size = this.ow_energy.electric_buffer_size + energy_upgrade
|
||||
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
redraw_coins_left(data.coins_left, player)
|
||||
|
||||
return
|
||||
end
|
||||
if name == 'locomotive_max_health' then
|
||||
player.remove_item({name = item.value, count = cost})
|
||||
|
||||
game.print(
|
||||
grandmaster ..
|
||||
' ' .. player.name .. ' has bought the group a train health modifier! The train health is now buffed!',
|
||||
{r = 0.98, g = 0.66, b = 0.22}
|
||||
)
|
||||
this.locomotive_max_health = this.locomotive_max_health + 2500
|
||||
this.train_upgrades = this.train_upgrades + 1
|
||||
rendering.set_text(this.health_text, 'HP: ' .. this.locomotive_health .. ' / ' .. this.locomotive_max_health)
|
||||
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
redraw_coins_left(data.coins_left, player)
|
||||
|
||||
return
|
||||
end
|
||||
if name == 'locomotive_xp_aura' then
|
||||
player.remove_item({name = item.value, count = cost})
|
||||
|
||||
game.print(
|
||||
grandmaster .. ' ' .. player.name .. ' has bought the group a XP aura modifier! The XP aura is now buffed!',
|
||||
{r = 0.98, g = 0.66, b = 0.22}
|
||||
)
|
||||
this.locomotive_xp_aura = this.locomotive_xp_aura + 5
|
||||
this.train_upgrades = this.train_upgrades + 1
|
||||
|
||||
if this.circle then
|
||||
rendering.destroy(this.circle)
|
||||
end
|
||||
this.circle =
|
||||
rendering.draw_circle {
|
||||
surface = game.surfaces[this.active_surface_index],
|
||||
target = this.locomotive,
|
||||
color = this.locomotive.color,
|
||||
filled = false,
|
||||
radius = this.locomotive_xp_aura,
|
||||
only_in_alt_mode = true
|
||||
}
|
||||
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
redraw_coins_left(data.coins_left, player)
|
||||
|
||||
return
|
||||
end
|
||||
if name == 'player_terrain_reveal' then
|
||||
player.remove_item({name = item.value, count = cost})
|
||||
|
||||
this.players[player.index].reveal = this.players[player.index].reveal + duration_per_charge
|
||||
|
||||
this.players[player.index].reveal = duration_per_charge
|
||||
player.print(
|
||||
grandmaster ..
|
||||
' ' .. player.name .. ' a fine choice! You can now reveal terrain when going through the black mist!',
|
||||
{r = 0.98, g = 0.66, b = 0.22}
|
||||
)
|
||||
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
redraw_coins_left(data.coins_left, player)
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
if player_item_count >= cost then
|
||||
if player.can_insert({name = name, count = item_count}) then
|
||||
player.play_sound({path = 'entity-close/stone-furnace', volume_modifier = 0.65})
|
||||
player.remove_item({name = item.value, count = cost})
|
||||
local inserted_count = player.insert({name = name, count = item_count})
|
||||
if inserted_count < item_count then
|
||||
player.play_sound({path = 'utility/cannot_build', volume_modifier = 0.65})
|
||||
player.insert({name = item.value, count = cost})
|
||||
player.remove_item({name = name, count = inserted_count})
|
||||
end
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
redraw_coins_left(data.coins_left, player)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function gui_closed(event)
|
||||
local player = game.players[event.player_index]
|
||||
local this = Scrap_table.get_table()
|
||||
|
||||
local type = event.gui_type
|
||||
|
||||
if type == defines.gui_type.custom then
|
||||
local data = this.players[player.index].data
|
||||
if not data then
|
||||
return
|
||||
end
|
||||
close_market_gui(player)
|
||||
end
|
||||
end
|
||||
|
||||
local function inside(pos, area)
|
||||
local lt = area.left_top
|
||||
local rb = area.right_bottom
|
||||
|
||||
return pos.x >= lt.x and pos.y >= lt.y and pos.x <= rb.x and pos.y <= rb.y
|
||||
end
|
||||
|
||||
local function contains_positions(pos, area)
|
||||
if inside(pos, area) then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function on_player_changed_position(event)
|
||||
local this = Scrap_table.get_table()
|
||||
local player = game.players[event.player_index]
|
||||
local data = this.players[player.index].data
|
||||
|
||||
if data and data.frame and data.frame.valid then
|
||||
local position = this.market.position
|
||||
local area = {
|
||||
left_top = {x = position.x - 10, y = position.y - 10},
|
||||
right_bottom = {x = position.x + 10, y = position.y + 10}
|
||||
}
|
||||
if contains_positions(player.position, area) then
|
||||
return
|
||||
end
|
||||
if not data then
|
||||
return
|
||||
end
|
||||
close_market_gui(player)
|
||||
end
|
||||
end
|
||||
|
||||
local function create_market(data, rebuild)
|
||||
local surface = data.surface
|
||||
local this = data.this
|
||||
local pos = {x = 18, y = 3}
|
||||
|
||||
if rebuild then
|
||||
local radius = 1024
|
||||
local area = {{x = -radius, y = -radius}, {x = radius, y = radius}}
|
||||
for _, entity in pairs(surface.find_entities_filtered {area = area, name = 'market'}) do
|
||||
entity.destroy()
|
||||
end
|
||||
this.market = nil
|
||||
end
|
||||
|
||||
this.market = surface.create_entity {name = 'market', position = pos, force = 'player'}
|
||||
|
||||
rendering.draw_text {
|
||||
text = 'Market',
|
||||
surface = surface,
|
||||
target = this.market,
|
||||
target_offset = {0, 2},
|
||||
color = {r = 0.98, g = 0.66, b = 0.22},
|
||||
alignment = 'center'
|
||||
}
|
||||
|
||||
this.market.destructible = false
|
||||
end
|
||||
|
||||
local function place_market()
|
||||
local this = Scrap_table.get_table()
|
||||
local icw_table = ICW.get_table()
|
||||
if not this.locomotive then
|
||||
return
|
||||
end
|
||||
if not this.locomotive.valid then
|
||||
return
|
||||
end
|
||||
local unit_surface = this.locomotive.unit_number
|
||||
local surface = game.surfaces[icw_table.wagons[unit_surface].surface.index]
|
||||
|
||||
local data = {
|
||||
this = this,
|
||||
surface = surface
|
||||
}
|
||||
if not this.market then
|
||||
create_market(data)
|
||||
elseif not this.market.valid then
|
||||
create_market(data, true)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_tick()
|
||||
place_market()
|
||||
end
|
||||
|
||||
Event.on_nth_tick(5, on_tick)
|
||||
Event.add(defines.events.on_gui_click, gui_click)
|
||||
Event.add(defines.events.on_gui_opened, gui_opened)
|
||||
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_gui_closed, gui_closed)
|
||||
Event.add(defines.events.on_player_changed_position, on_player_changed_position)
|
@ -6,10 +6,10 @@ require 'on_tick_schedule'
|
||||
require 'modules.dynamic_landfill'
|
||||
require 'modules.difficulty_vote'
|
||||
require 'modules.shotgun_buff'
|
||||
require 'maps.scrapyard.burden'
|
||||
require 'modules.burden'
|
||||
require 'modules.rocks_heal_over_time'
|
||||
require 'modules.no_deconstruction_of_neutral_entities'
|
||||
require 'maps.scrapyard.flamethrower_nerf'
|
||||
require 'modules.flamethrower_nerf'
|
||||
require 'modules.rocks_yield_ore_veins'
|
||||
require 'modules.spawners_contain_biters'
|
||||
require 'modules.biters_yield_coins'
|
||||
@ -41,13 +41,14 @@ local Locomotive = require 'maps.scrapyard.locomotive'.locomotive_spawn
|
||||
local render_train_hp = require 'maps.scrapyard.locomotive'.render_train_hp
|
||||
local Score = require 'comfy_panel.score'
|
||||
local Poll = require 'comfy_panel.poll'
|
||||
local Collapse = require 'maps.scrapyard.collapse'
|
||||
local Collapse = require 'modules.collapse'
|
||||
local Balance = require 'maps.scrapyard.balance'
|
||||
|
||||
local Public = {}
|
||||
local math_random = math.random
|
||||
local math_floor = math.floor
|
||||
|
||||
Scrap_table.init({train_reveal = true})
|
||||
Scrap_table.init({train_reveal = true, energy_shared = true})
|
||||
|
||||
local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['wood'] = 4, ['rail'] = 16, ['raw-fish'] = 2}
|
||||
local disabled_entities = {'gun-turret', 'laser-turret', 'flamethrower-turret', 'land-mine'}
|
||||
@ -56,6 +57,14 @@ local colors = {
|
||||
'red-refined-concrete',
|
||||
'blue-refined-concrete'
|
||||
}
|
||||
local disabled_tiles = {
|
||||
['water-shallow'] = true,
|
||||
['deepwater-green'] = true,
|
||||
['out-of-map'] = true,
|
||||
['green-refined-concrete'] = true,
|
||||
['red-refined-concrete'] = true,
|
||||
['blue-refined-concrete'] = true
|
||||
}
|
||||
local treasure_chest_messages = {
|
||||
"You notice an old crate within the rubble. It's filled with treasure!",
|
||||
"You find a chest underneath the broken rocks. It's filled with goodies!",
|
||||
@ -141,8 +150,8 @@ local function set_difficulty()
|
||||
|
||||
--20 Players for fastest wave_interval
|
||||
wave_defense_table.wave_interval = 3600 - player_count * 90
|
||||
if wave_defense_table.wave_interval < 1800 then
|
||||
wave_defense_table.wave_interval = 1800
|
||||
if wave_defense_table.wave_interval < 2000 then
|
||||
wave_defense_table.wave_interval = 2000
|
||||
end
|
||||
end
|
||||
|
||||
@ -152,6 +161,7 @@ function Public.reset_map()
|
||||
local get_score = Score.get_table()
|
||||
Poll.reset()
|
||||
ICW.reset()
|
||||
Balance.init_enemy_weapon_damage()
|
||||
game.reset_time_played()
|
||||
Scrap_table.reset_table()
|
||||
wave_defense_table.math = 8
|
||||
@ -178,6 +188,7 @@ function Public.reset_map()
|
||||
game.forces.player.set_spawn_position({0, 25}, game.surfaces[this.active_surface_index])
|
||||
this.active_surface_index =
|
||||
Reset.soft_reset_map(game.surfaces[this.active_surface_index], map_gen_settings, starting_items).index
|
||||
this.active_surface = game.surfaces[this.active_surface_index]
|
||||
end
|
||||
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
@ -217,8 +228,7 @@ function Public.reset_map()
|
||||
Collapse.start_now(false)
|
||||
|
||||
surface.ticks_per_day = surface.ticks_per_day * 2
|
||||
surface.min_brightness = 0.08
|
||||
surface.daytime = 0.7
|
||||
surface.daytime = 1
|
||||
surface.brightness_visual_weights = {1, 0, 0, 0}
|
||||
surface.freeze_daytime = true
|
||||
surface.solar_power_multiplier = 1
|
||||
@ -395,7 +405,7 @@ local function protect_train(event)
|
||||
end
|
||||
|
||||
local function change_tile(surface, pos, steps)
|
||||
return surface.set_tiles {{name = colors[math_floor(steps * 0.5) % 3 + 1], position = {x = pos.x, y = pos.y + 1}}}
|
||||
return surface.set_tiles {{name = colors[math_floor(steps * 0.5) % 3 + 1], position = {x = pos.x, y = pos.y}}}
|
||||
end
|
||||
|
||||
local function on_player_changed_position(event)
|
||||
@ -420,11 +430,9 @@ local function on_player_changed_position(event)
|
||||
--for y = -1,1 do
|
||||
--local _pos = {position.x+x,position.y+y}
|
||||
local steps = this.players[player.index].steps
|
||||
local shallow, deepwater, oom =
|
||||
surface.get_tile(position).name == 'water-shallow',
|
||||
surface.get_tile(position).name == 'deepwater-green',
|
||||
surface.get_tile(position).name == 'out-of-map'
|
||||
if shallow or deepwater or oom then
|
||||
local tile = surface.get_tile(position).name
|
||||
local disabled = disabled_tiles[tile]
|
||||
if disabled then
|
||||
goto continue
|
||||
end
|
||||
change_tile(surface, position, steps)
|
||||
@ -436,7 +444,7 @@ local function on_player_changed_position(event)
|
||||
--end
|
||||
end
|
||||
::continue::
|
||||
if not this.train_reveal then
|
||||
if not this.train_reveal or this.players[player.index].reveal - game.tick > 0 then
|
||||
if position.y < 5 then
|
||||
Terrain.reveal(player)
|
||||
end
|
||||
@ -473,7 +481,9 @@ local function on_player_joined_game(event)
|
||||
this.players[player.index] = {
|
||||
tiles_enabled = true,
|
||||
steps = 0,
|
||||
first_join = false
|
||||
first_join = false,
|
||||
reveal = 0,
|
||||
data = {}
|
||||
}
|
||||
end
|
||||
|
||||
@ -938,23 +948,7 @@ local on_init = function()
|
||||
'Good luck, over and out!',
|
||||
'\n',
|
||||
'\n',
|
||||
'\n',
|
||||
'Fixes:\n',
|
||||
'Collapse activates after reaching first breach wall\n',
|
||||
'Crafting grants more xp\n',
|
||||
'Magic is tweaked\n',
|
||||
'Loot chests are affected by magic\n',
|
||||
'Scrap turrets are boosted in dmg\n',
|
||||
'Disable out-of-map tile placing\n',
|
||||
'RPG levels are now visible in the player list\n',
|
||||
"Moved comfylatron to overworld, 'lil bugger was causing issues\n",
|
||||
'RPG now has a global XP pool\n',
|
||||
'Locomotive has now market upgrades\n',
|
||||
'XP is granted after each breached wall\n',
|
||||
'Train now has a XP aura, stay near it!\n',
|
||||
'Aura increases after each breach wall\n',
|
||||
'Players cannot reveal path, only the train can.\n',
|
||||
'Follow the train and defend it.'
|
||||
'\n'
|
||||
}
|
||||
)
|
||||
T.main_caption_color = {r = 150, g = 150, b = 0}
|
||||
@ -985,7 +979,7 @@ local function darkness(data)
|
||||
game.print(grandmaster .. ' Sunlight, finally!', {r = 1, g = 0.5, b = 0.1})
|
||||
surface.min_brightness = 1
|
||||
surface.brightness_visual_weights = {1, 0, 0, 0}
|
||||
surface.daytime = 0.7
|
||||
surface.daytime = 1
|
||||
surface.freeze_daytime = true
|
||||
surface.solar_power_multiplier = 1
|
||||
this.freeze_daytime = false
|
||||
|
@ -1,51 +0,0 @@
|
||||
local Public = {}
|
||||
local math_random = math.random
|
||||
|
||||
local function shuffle(tbl)
|
||||
local size = #tbl
|
||||
for i = size, 1, -1 do
|
||||
local rand = math_random(size)
|
||||
tbl[i], tbl[rand] = tbl[rand], tbl[i]
|
||||
end
|
||||
return tbl
|
||||
end
|
||||
|
||||
function Public.add(pos, surface)
|
||||
local secret_market_items = {
|
||||
{price = {{'coin', math_random(30, 60)}}, offer = {type = 'give-item', item = 'construction-robot'}},
|
||||
{price = {{'coin', math_random(100, 200)}}, offer = {type = 'give-item', item = 'loader'}},
|
||||
{price = {{'coin', math_random(200, 300)}}, offer = {type = 'give-item', item = 'fast-loader'}},
|
||||
{price = {{'coin', math_random(300, 500)}}, offer = {type = 'give-item', item = 'express-loader'}},
|
||||
{price = {{'coin', math_random(100, 200)}}, offer = {type = 'give-item', item = 'locomotive'}},
|
||||
{price = {{'coin', math_random(75, 150)}}, offer = {type = 'give-item', item = 'cargo-wagon'}},
|
||||
{price = {{'coin', math_random(2, 3)}}, offer = {type = 'give-item', item = 'rail'}},
|
||||
{price = {{'coin', math_random(4, 12)}}, offer = {type = 'give-item', item = 'small-lamp'}},
|
||||
{price = {{'coin', math_random(80, 160)}}, offer = {type = 'give-item', item = 'car'}},
|
||||
{price = {{'coin', math_random(300, 600)}}, offer = {type = 'give-item', item = 'electric-furnace'}},
|
||||
{price = {{'coin', math_random(80, 160)}}, offer = {type = 'give-item', item = 'effectivity-module'}},
|
||||
{price = {{'coin', math_random(80, 160)}}, offer = {type = 'give-item', item = 'productivity-module'}},
|
||||
{price = {{'coin', math_random(80, 160)}}, offer = {type = 'give-item', item = 'speed-module'}},
|
||||
{price = {{'coin', math_random(5, 10)}}, offer = {type = 'give-item', item = 'wood', count = 50}},
|
||||
{price = {{'coin', math_random(5, 10)}}, offer = {type = 'give-item', item = 'iron-ore', count = 50}},
|
||||
{price = {{'coin', math_random(5, 10)}}, offer = {type = 'give-item', item = 'copper-ore', count = 50}},
|
||||
{price = {{'coin', math_random(5, 10)}}, offer = {type = 'give-item', item = 'stone', count = 50}},
|
||||
{price = {{'coin', math_random(5, 10)}}, offer = {type = 'give-item', item = 'coal', count = 50}},
|
||||
{price = {{'coin', math_random(8, 16)}}, offer = {type = 'give-item', item = 'uranium-ore', count = 50}},
|
||||
{price = {{'wood', math_random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}},
|
||||
{price = {{'iron-ore', math_random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}},
|
||||
{price = {{'copper-ore', math_random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}},
|
||||
{price = {{'stone', math_random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}},
|
||||
{price = {{'coal', math_random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}},
|
||||
{price = {{'uranium-ore', math_random(8, 10)}}, offer = {type = 'give-item', item = 'coin'}}
|
||||
}
|
||||
secret_market_items = shuffle(secret_market_items)
|
||||
|
||||
local market = surface.create_entity {name = 'market', position = pos, force = 'scrap'}
|
||||
market.destructible = false
|
||||
|
||||
for i = 1, math_random(6, 8), 1 do
|
||||
market.add_market_item(secret_market_items[i])
|
||||
end
|
||||
end
|
||||
|
||||
return Public
|
@ -208,7 +208,7 @@ local function get_amount(data)
|
||||
if this.scrap_enabled then
|
||||
local amount_bonus =
|
||||
(game.forces.enemy.evolution_factor * 2) + (game.forces.player.mining_drill_productivity_bonus * 2)
|
||||
local r1 = math.ceil(scrap_amount[scrap] * (0.3 + (amount_bonus * 0.3)))
|
||||
local r1 = math.ceil(scrap_amount[scrap] * (1.3 + (amount_bonus * 1.3)))
|
||||
local r2 = math.ceil(scrap_amount[scrap] * (1.7 + (amount_bonus * 1.7)))
|
||||
if not r1 or not r2 then
|
||||
return
|
||||
@ -230,12 +230,6 @@ local function scrap_randomness(data)
|
||||
local player = data.player
|
||||
local scrap
|
||||
|
||||
--if this.scrap_enabled[player.index] then
|
||||
-- scrap = scrap_raffle_scrap[math.random(1, size_of_scrap_raffle)]
|
||||
--else
|
||||
-- scrap = scrap_raffle_ores[math.random(1, size_of_ore_raffle)]
|
||||
--end
|
||||
|
||||
if this.scrap_enabled then
|
||||
scrap = scrap_raffle_scrap[math.random(1, size_of_scrap_raffle)]
|
||||
else
|
||||
|
@ -530,7 +530,7 @@ function Public.gain_xp(player, amount)
|
||||
else
|
||||
fee = 0
|
||||
end
|
||||
amount = math_round(amount, 2) - fee
|
||||
amount = math_floor(amount, 2) - fee
|
||||
rpg_t.global_pool = rpg_t.global_pool + fee
|
||||
rpg_t[player.index].xp = rpg_t[player.index].xp + amount
|
||||
rpg_t[player.index].xp_since_last_floaty_text = rpg_t[player.index].xp_since_last_floaty_text + amount
|
||||
@ -548,7 +548,7 @@ function Public.gain_xp(player, amount)
|
||||
return
|
||||
end
|
||||
player.create_local_flying_text {
|
||||
text = '+' .. math_round(rpg_t[player.index].xp_since_last_floaty_text) .. ' xp',
|
||||
text = '+' .. math_floor(rpg_t[player.index].xp_since_last_floaty_text) .. ' xp',
|
||||
position = player.position,
|
||||
color = xp_floating_text_color,
|
||||
time_to_live = 120,
|
||||
@ -573,7 +573,7 @@ local function global_pool()
|
||||
if rpg_t[p.index].level < 10 and p.online_time < 50000 then
|
||||
local s = share * 2
|
||||
p.create_local_flying_text {
|
||||
text = '+' .. s .. ' xp',
|
||||
text = '+' .. math_floor(s) .. ' xp',
|
||||
position = p.position,
|
||||
color = xp_floating_text_color,
|
||||
time_to_live = 240,
|
||||
@ -582,7 +582,7 @@ local function global_pool()
|
||||
Public.gain_xp(p, s * 2)
|
||||
else
|
||||
p.create_local_flying_text {
|
||||
text = '+' .. share .. ' xp',
|
||||
text = '+' .. math_floor(share) .. ' xp',
|
||||
position = p.position,
|
||||
color = xp_floating_text_color,
|
||||
time_to_live = 240,
|
||||
|
@ -3,7 +3,8 @@ local Global = require 'utils.global'
|
||||
local Event = require 'utils.event'
|
||||
|
||||
local this = {
|
||||
train_reveal = true
|
||||
train_reveal = true,
|
||||
energy_shared = true
|
||||
}
|
||||
local Public = {}
|
||||
|
||||
@ -20,6 +21,7 @@ function Public.reset_table()
|
||||
--end
|
||||
this.lo_energy = nil
|
||||
this.ow_energy = nil
|
||||
this.dummy = nil
|
||||
this.game_lost = false
|
||||
this.game_won = false
|
||||
this.energy = {}
|
||||
@ -40,6 +42,7 @@ function Public.reset_table()
|
||||
this.offline_players = {}
|
||||
this.mined_scrap = 0
|
||||
this.biters_killed = 0
|
||||
this.locomotive_xp_aura = 40
|
||||
end
|
||||
|
||||
function Public.get_table()
|
||||
@ -49,6 +52,9 @@ end
|
||||
function Public.init(args)
|
||||
if args then
|
||||
this.train_reveal = args.train_reveal
|
||||
this.energy_shared = args.energy_shared
|
||||
else
|
||||
return error('Not a valid init argument', 2)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,14 +1,24 @@
|
||||
local Event = require 'utils.event'
|
||||
local Modifier = require "player_modifiers"
|
||||
local Modifier = require 'player_modifiers'
|
||||
local Color = require 'utils.color_presets'
|
||||
|
||||
local function validate_player(player)
|
||||
if not player then return false end
|
||||
if not player.valid then return false end
|
||||
if not player.character then return false end
|
||||
if not player.connected then return false end
|
||||
if not game.players[player.name] then return false end
|
||||
return true
|
||||
if not player then
|
||||
return false
|
||||
end
|
||||
if not player.valid then
|
||||
return false
|
||||
end
|
||||
if not player.character then
|
||||
return false
|
||||
end
|
||||
if not player.connected then
|
||||
return false
|
||||
end
|
||||
if not game.players[player.name] then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function compute_fullness(player)
|
||||
@ -34,17 +44,16 @@ local function check_burden(event)
|
||||
local player = game.players[event.player_index]
|
||||
validate_player(player)
|
||||
local fullness = compute_fullness(player)
|
||||
player_modifiers[player.index].character_running_speed_modifier["overworld"] = 0.5 - fullness
|
||||
player_modifiers[player.index].character_mining_speed_modifier["overworld"] = 0.5 - fullness
|
||||
player_modifiers[player.index].character_running_speed_modifier['randomness'] = 0.3 - fullness
|
||||
player_modifiers[player.index].character_mining_speed_modifier['randomess'] = 0.3 - fullness
|
||||
Modifier.update_player_modifiers(player)
|
||||
if fullness >= 0.5 and fullness <= 0.51 then
|
||||
player.print("You feel all of a sudden burden.", Color.yellow)
|
||||
elseif fullness >= 0.9 and fullness <= 0.91 then
|
||||
player.print("Maybe you should drop some of that inventory to lessen the burden.", Color.red)
|
||||
if fullness >= 0.3 and fullness <= 0.305 then
|
||||
player.print('You feel all of a sudden burden.', Color.yellow)
|
||||
elseif fullness >= 0.5 and fullness <= 0.505 then
|
||||
player.print('Maybe you should drop some of that inventory to lessen the burden.', Color.red)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function on_init(event)
|
||||
script.on_event(defines.events.on_player_main_inventory_changed, check_burden)
|
||||
end
|
||||
|
@ -13,150 +13,236 @@ Global.register(
|
||||
)
|
||||
|
||||
local directions = {
|
||||
["north"] = function(position)
|
||||
local width = collapse.surface.map_gen_settings.width
|
||||
if width > collapse.max_line_size then width = collapse.max_line_size end
|
||||
local a = width * 0.5 + 1
|
||||
collapse.vector = {0, -1}
|
||||
collapse.area = {{position.x - a, position.y - 1}, {position.x + a, position.y}}
|
||||
end,
|
||||
["south"] = function(position)
|
||||
local width = collapse.surface.map_gen_settings.width
|
||||
if width > collapse.max_line_size then width = collapse.max_line_size end
|
||||
local a = width * 0.5 + 1
|
||||
collapse.vector = {0, 1}
|
||||
collapse.area = {{position.x - a, position.y}, {position.x + a, position.y + 1}}
|
||||
end,
|
||||
["west"] = function(position)
|
||||
local width = collapse.surface.map_gen_settings.height
|
||||
if width > collapse.max_line_size then width = collapse.max_line_size end
|
||||
local a = width * 0.5 + 1
|
||||
collapse.vector = {-1, 0}
|
||||
collapse.area = {{position.x - 1, position.y - a}, {position.x, position.y + a}}
|
||||
end,
|
||||
["east"] = function(position)
|
||||
local width = collapse.surface.map_gen_settings.height
|
||||
if width > collapse.max_line_size then width = collapse.max_line_size end
|
||||
local a = width * 0.5 + 1
|
||||
collapse.vector = {1, 0}
|
||||
collapse.area = {{position.x, position.y - a}, {position.x + 1, position.y + a}}
|
||||
end,
|
||||
['north'] = function(position)
|
||||
local width = collapse.surface.map_gen_settings.width
|
||||
if width > collapse.max_line_size then
|
||||
width = collapse.max_line_size
|
||||
end
|
||||
local a = width * 0.5 + 1
|
||||
collapse.vector = {0, -1}
|
||||
collapse.area = {{position.x - a, position.y - 1}, {position.x + a, position.y}}
|
||||
end,
|
||||
['south'] = function(position)
|
||||
local width = collapse.surface.map_gen_settings.width
|
||||
if width > collapse.max_line_size then
|
||||
width = collapse.max_line_size
|
||||
end
|
||||
local a = width * 0.5 + 1
|
||||
collapse.vector = {0, 1}
|
||||
collapse.area = {{position.x - a, position.y}, {position.x + a, position.y + 1}}
|
||||
end,
|
||||
['west'] = function(position)
|
||||
local width = collapse.surface.map_gen_settings.height
|
||||
if width > collapse.max_line_size then
|
||||
width = collapse.max_line_size
|
||||
end
|
||||
local a = width * 0.5 + 1
|
||||
collapse.vector = {-1, 0}
|
||||
collapse.area = {{position.x - 1, position.y - a}, {position.x, position.y + a}}
|
||||
end,
|
||||
['east'] = function(position)
|
||||
local width = collapse.surface.map_gen_settings.height
|
||||
if width > collapse.max_line_size then
|
||||
width = collapse.max_line_size
|
||||
end
|
||||
local a = width * 0.5 + 1
|
||||
collapse.vector = {1, 0}
|
||||
collapse.area = {{position.x, position.y - a}, {position.x + 1, position.y + a}}
|
||||
end
|
||||
}
|
||||
|
||||
local function print_debug(a)
|
||||
print("Collapse error #" .. a)
|
||||
print('Collapse error #' .. a)
|
||||
end
|
||||
|
||||
local function set_collapse_tiles(surface)
|
||||
game.forces.player.chart(surface, collapse.area)
|
||||
collapse.tiles = surface.find_tiles_filtered({area = collapse.area})
|
||||
if not collapse.tiles then return end
|
||||
collapse.size_of_tiles = #collapse.tiles
|
||||
if collapse.size_of_tiles > 0 then table_shuffle_table(collapse.tiles) end
|
||||
collapse.position = {x = collapse.position.x + collapse.vector[1], y = collapse.position.y + collapse.vector[2]}
|
||||
local v = collapse.vector
|
||||
local area = collapse.area
|
||||
collapse.area = {{area[1][1] + v[1], area[1][2] + v[2]}, {area[2][1] + v[1], area[2][2] + v[2]}}
|
||||
game.forces.player.chart(surface, collapse.area)
|
||||
game.forces.player.chart(surface, collapse.area)
|
||||
collapse.tiles = surface.find_tiles_filtered({area = collapse.area})
|
||||
if not collapse.tiles then
|
||||
return
|
||||
end
|
||||
collapse.size_of_tiles = #collapse.tiles
|
||||
if collapse.size_of_tiles > 0 then
|
||||
table_shuffle_table(collapse.tiles)
|
||||
end
|
||||
collapse.position = {x = collapse.position.x + collapse.vector[1], y = collapse.position.y + collapse.vector[2]}
|
||||
local v = collapse.vector
|
||||
local area = collapse.area
|
||||
collapse.area = {{area[1][1] + v[1], area[1][2] + v[2]}, {area[2][1] + v[1], area[2][2] + v[2]}}
|
||||
game.forces.player.chart(surface, collapse.area)
|
||||
end
|
||||
|
||||
local function progress()
|
||||
local surface = collapse.surface
|
||||
|
||||
local tiles = collapse.tiles
|
||||
if not tiles then
|
||||
set_collapse_tiles(surface)
|
||||
tiles = collapse.tiles
|
||||
end
|
||||
if not tiles then return end
|
||||
|
||||
for _ = 1, collapse.amount, 1 do
|
||||
local tile = tiles[collapse.size_of_tiles]
|
||||
if not tile then collapse.tiles = nil return end
|
||||
collapse.size_of_tiles = collapse.size_of_tiles - 1
|
||||
if not tile.valid then return end
|
||||
if collapse.kill then
|
||||
local position = {tile.position.x + 0.5, tile.position.y + 0.5}
|
||||
for _, e in pairs(surface.find_entities_filtered({area = {{position[1] - 2, position[2] - 2}, {position[1] + 2, position[2] + 2}}})) do
|
||||
if e.valid and e.health then e.die() end
|
||||
end
|
||||
end
|
||||
surface.set_tiles({{name = "out-of-map", position = tile.position}}, true)
|
||||
end
|
||||
local surface = collapse.surface
|
||||
|
||||
if not collapse.start_now then
|
||||
return
|
||||
end
|
||||
|
||||
local tiles = collapse.tiles
|
||||
if not tiles then
|
||||
set_collapse_tiles(surface)
|
||||
tiles = collapse.tiles
|
||||
end
|
||||
if not tiles then
|
||||
return
|
||||
end
|
||||
|
||||
for _ = 1, collapse.amount, 1 do
|
||||
local tile = tiles[collapse.size_of_tiles]
|
||||
if not tile then
|
||||
collapse.tiles = nil
|
||||
return
|
||||
end
|
||||
collapse.size_of_tiles = collapse.size_of_tiles - 1
|
||||
if not tile.valid then
|
||||
return
|
||||
end
|
||||
if collapse.kill then
|
||||
local position = {tile.position.x + 0.5, tile.position.y + 0.5}
|
||||
for _, e in pairs(
|
||||
surface.find_entities_filtered(
|
||||
{area = {{position[1] - 2, position[2] - 2}, {position[1] + 2, position[2] + 2}}}
|
||||
)
|
||||
) do
|
||||
if e.valid and e.health then
|
||||
e.die()
|
||||
end
|
||||
end
|
||||
end
|
||||
surface.set_tiles({{name = 'out-of-map', position = tile.position}}, true)
|
||||
end
|
||||
end
|
||||
|
||||
function Public.set_surface(surface)
|
||||
if not surface then print_debug(1) return end
|
||||
if not surface.valid then print_debug(2) return end
|
||||
if not game.surfaces[surface.index] then print_debug(3) return end
|
||||
collapse.surface = surface
|
||||
if not surface then
|
||||
print_debug(1)
|
||||
return
|
||||
end
|
||||
if not surface.valid then
|
||||
print_debug(2)
|
||||
return
|
||||
end
|
||||
if not game.surfaces[surface.index] then
|
||||
print_debug(3)
|
||||
return
|
||||
end
|
||||
collapse.surface = surface
|
||||
end
|
||||
|
||||
function Public.set_direction(direction)
|
||||
if not directions[direction] then print_debug(11) return end
|
||||
directions[direction](collapse.position)
|
||||
if not directions[direction] then
|
||||
print_debug(11)
|
||||
return
|
||||
end
|
||||
directions[direction](collapse.position)
|
||||
end
|
||||
|
||||
function Public.set_speed(speed)
|
||||
if not speed then print_debug(8) return end
|
||||
speed = math_floor(speed)
|
||||
if speed < 1 then speed = 1 end
|
||||
collapse.speed = speed
|
||||
if not speed then
|
||||
print_debug(8)
|
||||
return
|
||||
end
|
||||
speed = math_floor(speed)
|
||||
if speed < 1 then
|
||||
speed = 1
|
||||
end
|
||||
collapse.speed = speed
|
||||
end
|
||||
|
||||
function Public.set_amount(amount)
|
||||
if not amount then print_debug(9) return end
|
||||
amount = math_floor(amount)
|
||||
if amount < 0 then amount = 0 end
|
||||
collapse.amount = amount
|
||||
if not amount then
|
||||
print_debug(9)
|
||||
return
|
||||
end
|
||||
amount = math_floor(amount)
|
||||
if amount < 0 then
|
||||
amount = 0
|
||||
end
|
||||
collapse.amount = amount
|
||||
end
|
||||
|
||||
function Public.set_position(position)
|
||||
if not position then print_debug(4) return end
|
||||
if not position.x and not position[1] then print_debug(5) return end
|
||||
if not position.y and not position[2] then print_debug(6) return end
|
||||
local x = 0
|
||||
local y = 0
|
||||
if position[1] then x = position[1] end
|
||||
if position[2] then y = position[2] end
|
||||
if position.x then x = position.x end
|
||||
if position.y then y = position.y end
|
||||
collapse.position = {x = x, y = y}
|
||||
if not position then
|
||||
print_debug(4)
|
||||
return
|
||||
end
|
||||
if not position.x and not position[1] then
|
||||
print_debug(5)
|
||||
return
|
||||
end
|
||||
if not position.y and not position[2] then
|
||||
print_debug(6)
|
||||
return
|
||||
end
|
||||
local x = 0
|
||||
local y = 0
|
||||
if position[1] then
|
||||
x = position[1]
|
||||
end
|
||||
if position[2] then
|
||||
y = position[2]
|
||||
end
|
||||
if position.x then
|
||||
x = position.x
|
||||
end
|
||||
if position.y then
|
||||
y = position.y
|
||||
end
|
||||
collapse.position = {x = x, y = y}
|
||||
end
|
||||
|
||||
function Public.get_position()
|
||||
return collapse.position
|
||||
return collapse.position
|
||||
end
|
||||
|
||||
function Public.start_now(status)
|
||||
if status == true then
|
||||
collapse.start_now = true
|
||||
elseif status == false then
|
||||
collapse.start_now = false
|
||||
end
|
||||
return collapse.start_now
|
||||
end
|
||||
|
||||
function Public.set_max_line_size(size)
|
||||
if not size then print_debug(22) return end
|
||||
size = math_floor(size)
|
||||
if size <= 0 then print_debug(21) return end
|
||||
collapse.max_line_size = size
|
||||
if not size then
|
||||
print_debug(22)
|
||||
return
|
||||
end
|
||||
size = math_floor(size)
|
||||
if size <= 0 then
|
||||
print_debug(21)
|
||||
return
|
||||
end
|
||||
collapse.max_line_size = size
|
||||
end
|
||||
|
||||
function Public.set_kill_entities(a)
|
||||
collapse.kill = a
|
||||
collapse.kill = a
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
Public.set_surface(game.surfaces.nauvis)
|
||||
Public.set_position({0, 32})
|
||||
Public.set_max_line_size(256)
|
||||
Public.set_direction("north")
|
||||
Public.set_kill_entities(true)
|
||||
collapse.tiles = nil
|
||||
collapse.speed = 1
|
||||
collapse.amount = 8
|
||||
Public.set_surface(game.surfaces.nauvis)
|
||||
Public.set_position({0, 32})
|
||||
Public.set_max_line_size(256)
|
||||
Public.set_direction('north')
|
||||
Public.set_kill_entities(true)
|
||||
collapse.tiles = nil
|
||||
collapse.speed = 1
|
||||
collapse.amount = 8
|
||||
collapse.start_now = true
|
||||
end
|
||||
|
||||
local function on_tick()
|
||||
if game.tick % collapse.speed ~= 0 then return end
|
||||
progress()
|
||||
if game.tick % collapse.speed ~= 0 then
|
||||
return
|
||||
end
|
||||
progress()
|
||||
end
|
||||
|
||||
local Event = require 'utils.event'
|
||||
Event.on_init(on_init)
|
||||
Event.add(defines.events.on_tick, on_tick)
|
||||
|
||||
return Public
|
||||
return Public
|
||||
|
@ -1,57 +1,62 @@
|
||||
--Central to add all player modifiers together.
|
||||
--Will overwrite character stats from other mods.
|
||||
|
||||
local Global = require "utils.global"
|
||||
local Global = require 'utils.global'
|
||||
|
||||
local this = {}
|
||||
|
||||
Global.register(this, function(t) this = t end)
|
||||
Global.register(
|
||||
this,
|
||||
function(t)
|
||||
this = t
|
||||
end
|
||||
)
|
||||
|
||||
local Public = {}
|
||||
|
||||
function Public.get_table()
|
||||
return this
|
||||
return this
|
||||
end
|
||||
|
||||
local modifiers = {
|
||||
"character_build_distance_bonus",
|
||||
"character_crafting_speed_modifier",
|
||||
"character_health_bonus",
|
||||
"character_inventory_slots_bonus",
|
||||
"character_item_drop_distance_bonus",
|
||||
"character_item_pickup_distance_bonus",
|
||||
"character_loot_pickup_distance_bonus",
|
||||
"character_mining_speed_modifier",
|
||||
"character_reach_distance_bonus",
|
||||
"character_resource_reach_distance_bonus",
|
||||
"character_running_speed_modifier",
|
||||
'character_build_distance_bonus',
|
||||
'character_crafting_speed_modifier',
|
||||
'character_health_bonus',
|
||||
'character_inventory_slots_bonus',
|
||||
'character_item_drop_distance_bonus',
|
||||
'character_item_pickup_distance_bonus',
|
||||
'character_loot_pickup_distance_bonus',
|
||||
'character_mining_speed_modifier',
|
||||
'character_reach_distance_bonus',
|
||||
'character_resource_reach_distance_bonus',
|
||||
'character_running_speed_modifier'
|
||||
}
|
||||
|
||||
function Public.update_player_modifiers(player)
|
||||
for _, modifier in pairs(modifiers) do
|
||||
local sum_value = 0
|
||||
for _, value in pairs(this[player.index][modifier]) do
|
||||
sum_value = sum_value + value
|
||||
end
|
||||
if player.character then
|
||||
player[modifier] = sum_value
|
||||
end
|
||||
end
|
||||
for _, modifier in pairs(modifiers) do
|
||||
local sum_value = 0
|
||||
for _, value in pairs(this[player.index][modifier]) do
|
||||
sum_value = sum_value + value
|
||||
end
|
||||
if player.character then
|
||||
player[modifier] = sum_value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
if this[event.player_index] then
|
||||
Public.update_player_modifiers(game.players[event.player_index])
|
||||
return
|
||||
end
|
||||
this[event.player_index] = {}
|
||||
for _, modifier in pairs(modifiers) do
|
||||
this[event.player_index][modifier] = {}
|
||||
end
|
||||
if this[event.player_index] then
|
||||
Public.update_player_modifiers(game.players[event.player_index])
|
||||
return
|
||||
end
|
||||
this[event.player_index] = {}
|
||||
for _, modifier in pairs(modifiers) do
|
||||
this[event.player_index][modifier] = {}
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_respawned(event)
|
||||
Public.update_player_modifiers(game.players[event.player_index])
|
||||
local function on_player_respawned(event)
|
||||
Public.update_player_modifiers(game.players[event.player_index])
|
||||
end
|
||||
|
||||
local Event = require 'utils.event'
|
||||
@ -59,4 +64,3 @@ Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
Event.add(defines.events.on_player_respawned, on_player_respawned)
|
||||
|
||||
return Public
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user