1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2024-12-30 23:17:53 +02:00
This commit is contained in:
Gerkiz 2020-06-07 13:33:24 +02:00
parent ee1f80fb82
commit 57c81f024b
15 changed files with 784 additions and 500 deletions

View File

@ -126,6 +126,7 @@ require 'modules.autostash'
-----------------------------
---- more modules here ----
--require 'modules.hidden_dimension.main'
--require 'modules.towny.main'
--require 'modules.rpg'
--require 'modules.trees_grow'

View File

@ -3,7 +3,7 @@ local Terrain = require 'maps.mountain_fortress_v3.terrain'
local Balance = require 'maps.mountain_fortress_v3.balance'
local RPG = require 'maps.mountain_fortress_v3.rpg'
local WPT = require 'maps.mountain_fortress_v3.table'
local Alert = require 'maps.mountain_fortress_v3.alert'
local Alert = require 'utils.alert'
local Event = require 'utils.event'
local Task = require 'utils.task'
local Token = require 'utils.token'
@ -33,7 +33,7 @@ local zone_complete =
local bonus = data.bonus
local player = data.player
local message = keeper .. 'Survivor! Well done. You have completed zone: ' .. bonus
Alert.alert_player(player, 10, message)
Alert.alert_player_warning(player, 10, message)
end
)

View File

@ -10,6 +10,8 @@ local Mining = require 'maps.mountain_fortress_v3.mining'
local Terrain = require 'maps.mountain_fortress_v3.terrain'
local BiterHealthBooster = require 'modules.biter_health_booster'
local Traps = require 'maps.mountain_fortress_v3.traps'
local Locomotive = require 'maps.mountain_fortress_v3.locomotive'
local Alert = require 'utils.alert'
--local HD = require 'modules.hidden_dimension.main'
-- tables
@ -24,7 +26,7 @@ local math_floor = math.floor
local math_abs = math.abs
--local raise_event = script.raise_event
local mapkeeper = '[color=blue]Mapkeeper:[/color]'
local mapkeeper = '[color=blue]Mapkeeper:[/color]\n'
local treasure_chest_messages = {
"You notice an old crate within the rubble. It's filled with treasure!",
@ -70,6 +72,15 @@ local function set_objective_health(final_damage_amount)
return
end
if this.locomotive_health <= 2000 then
if not this.poison_deployed then
Locomotive.enable_poison_defense()
this.poison_deployed = true
end
elseif this.locomotive_health >= this.locomotive_max_health then
this.poison_deployed = false
end
if this.locomotive_health <= 0 then
this.locomotive.health = this.locomotive.health + final_damage_amount
return
@ -190,14 +201,13 @@ local function hidden_treasure(event)
return
end
if magic > 50 then
player.print(
rare_treasure_chest_messages[math.random(1, #rare_treasure_chest_messages)],
{r = 0.98, g = 0.66, b = 0.22}
)
local msg = rare_treasure_chest_messages[math.random(1, #rare_treasure_chest_messages)]
Alert.alert_player(player, 5, msg)
Loot.add_rare(event.entity.surface, event.entity.position, 'wooden-chest', magic)
return
end
player.print(treasure_chest_messages[math.random(1, #treasure_chest_messages)], {r = 0.98, g = 0.66, b = 0.22})
local msg = treasure_chest_messages[math.random(1, #treasure_chest_messages)]
Alert.alert_player(player, 5, msg)
Loot.add(event.entity.surface, event.entity.position, 'wooden-chest')
end
@ -509,7 +519,15 @@ local function on_player_repaired_entity(event)
end
local entity = event.entity
if entity == this.locomotive then
set_objective_health(-1)
local player = game.players[event.player_index]
local repair_speed = RPG.get_magicka(player)
if repair_speed <= 0 then
set_objective_health(-1)
return
else
set_objective_health(-repair_speed)
return
end
end
end
@ -618,8 +636,11 @@ function Public.loco_died()
local Reset_map = require 'maps.mountain_fortress_v3.main'.reset_map
wave_defense_table.game_lost = true
wave_defense_table.target = nil
game.print(mapkeeper .. ' ' .. defeated_messages[math.random(1, #defeated_messages)], {r = 1, g = 0.5, b = 0.1})
game.print(mapkeeper .. ' Better luck next time.', {r = 1, g = 0.5, b = 0.1})
local pos = {
position = this.locomotive.position
}
local msg = mapkeeper .. defeated_messages[math.random(1, #defeated_messages)] .. '\nBetter luck next time.'
Alert.alert_all_players_location(pos, msg)
Reset_map()
return
end
@ -634,13 +655,22 @@ function Public.loco_died()
rendering.set_text(this.health_text, 'HP: ' .. this.locomotive_health .. ' / ' .. this.locomotive_max_health)
wave_defense_table.game_lost = true
wave_defense_table.target = nil
game.print(mapkeeper .. ' ' .. defeated_messages[math.random(1, #defeated_messages)], {r = 1, g = 0.5, b = 0.1})
game.print(mapkeeper .. ' Better luck next time.', {r = 1, g = 0.5, b = 0.1})
local msg
if not this.disable_reset then
game.print(mapkeeper .. ' Game will soft-reset shortly.', {r = 1, g = 0.5, b = 0.1})
msg =
mapkeeper ..
defeated_messages[math.random(1, #defeated_messages)] ..
'\nBetter luck next time.\nGame will soft-reset shortly.'
else
game.print(mapkeeper .. ' Game will not soft-reset. Soft-reset is disabled.', {r = 1, g = 0.5, b = 0.1})
msg =
mapkeeper ..
defeated_messages[math.random(1, #defeated_messages)] ..
'\nBetter luck next time.\nGame will not soft-reset. Soft-reset is disabled.'
end
local pos = {
position = this.locomotive.position
}
Alert.alert_all_players_location(pos, msg)
game.forces.enemy.set_friend('player', true)
game.forces.player.set_friend('enemy', true)

View File

@ -5,9 +5,7 @@ local Token = require 'utils.token'
local Event = require 'utils.event'
local Terrain = require 'maps.mountain_fortress_v3.terrain'.heavy_functions
local insert = table.insert
local tiles_per_call = 32
local tiles_per_call = 8
local total_calls = math.ceil(1024 / tiles_per_call)
local regen_decoratives = false
local force_chunk = false
@ -19,7 +17,7 @@ Public.enable_register_events = true
local function do_tile_inner(tiles, tile, pos)
if type(tile) == 'string' then
insert(tiles, {name = tile, position = pos})
tiles[#tiles + 1] = {name = tile, position = pos}
end
end
@ -36,45 +34,40 @@ local function do_tile(y, x, data, shape)
if type(tile) == 'table' then
do_tile_inner(data.tiles, tile.tile, pos)
local hidden_tile = tile.hidden_tile
if hidden_tile then
insert(data.hidden_tiles, {tile = hidden_tile, position = pos})
end
local entities = tile.entities
if entities then
for _, entity in ipairs(entities) do
for _, entity in pairs(entities) do
if not entity.position then
entity.position = pos
end
insert(data.entities, entity)
data.entities[#data.entities + 1] = entity
end
end
local decoratives = tile.decoratives
if decoratives then
for _, decorative in ipairs(decoratives) do
insert(data.decoratives, decorative)
for _, decorative in pairs(decoratives) do
data.decoratives[#data.decoratives + 1] = decorative
end
end
local markets = tile.markets
if markets then
for _, t in ipairs(markets) do
for _, t in pairs(markets) do
if not t.position then
t.position = pos
end
insert(data.markets, t)
data.markets[#data.markets + 1] = t
end
end
local treasure = tile.treasure
if treasure then
for _, t in ipairs(treasure) do
for _, t in pairs(treasure) do
if not t.position then
t.position = pos
end
insert(data.treasure, t)
data.treasure[#data.treasure + 1] = t
end
end
else
@ -103,48 +96,43 @@ local function do_row(row, data, shape)
if type(tile) == 'table' then
do_tile_inner(tiles, tile.tile, pos)
local hidden_tile = tile.hidden_tile
if hidden_tile then
insert(data.hidden_tiles, {tile = hidden_tile, position = pos})
end
local entities = tile.entities
if entities then
for _, entity in ipairs(entities) do
for _, entity in pairs(entities) do
if not entity.position then
entity.position = pos
end
insert(data.entities, entity)
data.entities[#data.entities + 1] = entity
end
end
local decoratives = tile.decoratives
if decoratives then
for _, decorative in ipairs(decoratives) do
for _, decorative in pairs(decoratives) do
if not decorative.position then
decorative.position = pos
end
insert(data.decoratives, decorative)
data.decoratives[#data.decoratives + 1] = decorative
end
end
local markets = tile.markets
if markets then
for _, t in ipairs(markets) do
for _, t in pairs(markets) do
if not t.position then
t.position = pos
end
insert(data.markets, t)
data.markets[#data.markets + 1] = t
end
end
local treasure = tile.treasure
if treasure then
for _, t in ipairs(treasure) do
for _, t in pairs(treasure) do
if not t.position then
t.position = pos
end
insert(data.treasure, t)
data.treasure[#data.treasure + 1] = t
end
end
else
@ -166,7 +154,7 @@ local function do_place_treasure(data)
return
end
for _, e in ipairs(data.treasure) do
for _, e in pairs(data.treasure) do
if rnd(1, 6) == 1 then
e.chest = 'iron-chest'
end
@ -209,17 +197,6 @@ local function do_place_tiles(data)
data.surface.set_tiles(data.tiles, true)
end
local function do_place_hidden_tiles(data)
if not data.surface.valid then
return
end
local surface = data.surface
for _, t in ipairs(data.hidden_tiles) do
surface.set_hidden_tile(t.position, t.tile)
end
end
local function do_place_decoratives(data)
if not data.surface.valid then
return
@ -244,7 +221,7 @@ local function do_place_entities(data)
local entity
local callback
for _, e in ipairs(data.entities) do
for _, e in pairs(data.entities) do
if e.collision then
if surface.can_place_entity(e) then
entity = surface.create_entity(e)
@ -318,16 +295,16 @@ local function map_gen_action(data)
local state = data.y
if state < 32 then
if not data.surface.valid then
return
end
local shape = Terrain
if shape == nil then
return false
end
local count = total_calls
if not data.surface.valid then
return
end
local count = tiles_per_call
local y = state + data.top_y
local x = data.x
@ -338,7 +315,6 @@ local function map_gen_action(data)
repeat
count = count - 1
do_tile(y, x, data, shape)
x = x + 1
@ -362,26 +338,22 @@ local function map_gen_action(data)
data.y = 33
return true
elseif state == 33 then
do_place_hidden_tiles(data)
do_place_entities(data)
data.y = 34
return true
elseif state == 34 then
do_place_entities(data)
do_place_markets(data)
data.y = 35
return true
elseif state == 35 then
do_place_markets(data)
do_place_treasure(data)
data.y = 36
return true
elseif state == 36 then
do_place_treasure(data)
do_place_decoratives(data)
data.y = 37
return true
elseif state == 37 then
do_place_decoratives(data)
data.y = 38
return true
elseif state == 38 then
run_chart_update(data)
return false
end
@ -395,6 +367,10 @@ function Public.schedule_chunk(event)
local surface = event.surface
local shape = Terrain
if event.tick < 1 then
return
end
if not surface.valid then
return
end
@ -415,7 +391,6 @@ function Public.schedule_chunk(event)
top_y = area.left_top.y,
surface = surface,
tiles = {},
hidden_tiles = {},
entities = {},
decoratives = {},
markets = {},
@ -453,7 +428,6 @@ function Public.do_chunk(event)
top_y = area.left_top.y,
surface = surface,
tiles = {},
hidden_tiles = {},
entities = {},
decoratives = {},
markets = {},
@ -469,7 +443,6 @@ function Public.do_chunk(event)
end
do_place_tiles(data)
do_place_hidden_tiles(data)
do_place_entities(data)
do_place_decoratives(data)
do_place_markets(data)

View File

@ -133,38 +133,51 @@ local function on_gui_click(event)
if name == main_button_name then
if player.surface ~= locomotive.surface then
local s = player.gui.left.icw_map
if s and s.visible then
player.gui.left.icw_map.visible = false
local minimap = player.gui.left.icw_map
if minimap and minimap.visible then
minimap.visible = false
return
elseif s and not s.visible then
player.gui.left.icw_map.visible = true
elseif minimap and not minimap.visible then
minimap.visible = true
return
end
return
end
if player.gui.top[main_frame_name] then
local s = player.gui.top[main_frame_name]
if s and s.visible then
if player.gui.top['wave_defense'] then
player.gui.top['wave_defense'].visible = false
local info = player.gui.top[main_frame_name]
local wd = player.gui.top['wave_defense']
local diff = player.gui.top['difficulty_gui']
if info and info.visible then
if wd then
wd.visible = false
end
if player.gui.top['difficulty_gui'] then
player.gui.top['difficulty_gui'].visible = false
if diff then
diff.visible = false
end
player.gui.top[main_frame_name].visible = false
info.visible = false
return
elseif s and not s.visible then
elseif wd and not wd.visible then
for _, child in pairs(player.gui.left.children) do
child.destroy()
end
if player.gui.top['wave_defense'] then
player.gui.top['wave_defense'].visible = true
if wd then
wd.visible = true
end
if player.gui.top['difficulty_gui'] then
player.gui.top['difficulty_gui'].visible = true
if diff then
diff.visible = true
end
player.gui.top[main_frame_name].visible = true
return
elseif info and not info.visible then
for _, child in pairs(player.gui.left.children) do
child.destroy()
end
if wd then
wd.visible = true
end
if diff then
diff.visible = true
end
info.visible = true
return
end
else
@ -173,14 +186,6 @@ local function on_gui_click(event)
end
create_main_frame(player)
end
elseif name ~= main_button_name then
if player.gui.top[main_frame_name] then
local s = player.gui.top[main_frame_name]
if s and s.visible then
player.gui.top[main_frame_name].visible = false
return
end
end
end
end
local function on_player_changed_surface(event)
@ -189,51 +194,54 @@ local function on_player_changed_surface(event)
return
end
local locomotive = WPT.get('locomotive')
local main = WPT.get('locomotive')
local icw_locomotive = WPT.get('icw_locomotive')
local loco_surface = icw_locomotive.surface
local wagon_surface = icw_locomotive.surface
local info = player.gui.top[main_button_name]
local wd = player.gui.top['wave_defense']
local diff = player.gui.top['difficulty_gui']
local frame = player.gui.top[main_frame_name]
if player.gui.top[main_button_name] then
player.gui.top[main_button_name].tooltip = 'Shows statistics!'
player.gui.top[main_button_name].sprite = 'item/dummy-steel-axe'
if info then
info.tooltip = 'Shows statistics!'
info.sprite = 'item/dummy-steel-axe'
end
if not locomotive then
if not main then
return
end
if not locomotive.valid then
if not main.valid then
return
end
if not loco_surface then
if not wagon_surface then
return
end
if not loco_surface.valid then
if not wagon_surface.valid then
return
end
if player.surface == locomotive.surface then
local s = player.gui.left.icw_map
if s and s.visible then
player.gui.left.icw_map.visible = false
if player.surface == main.surface then
local minimap = player.gui.left.icw_map
if minimap and minimap.visible then
minimap.visible = false
end
player.gui.top[main_button_name].tooltip = 'Shows statistics!'
player.gui.top[main_button_name].sprite = 'item/dummy-steel-axe'
elseif player.surface == loco_surface then
if player.gui.top['wave_defense'] then
player.gui.top['wave_defense'].visible = false
info.tooltip = 'Shows statistics!'
info.sprite = 'item/dummy-steel-axe'
elseif player.surface == wagon_surface then
if wd then
wd.visible = false
end
if player.gui.top['difficulty_gui'] then
player.gui.top['difficulty_gui'].visible = false
if diff then
diff.visible = false
end
if player.gui.top[main_button_name] then
player.gui.top[main_button_name].tooltip = 'Hide locomotive minimap!'
player.gui.top[main_button_name].sprite = 'utility/map'
if info then
info.tooltip = 'Hide locomotive minimap!'
info.sprite = 'utility/map'
end
if player.gui.top[main_frame_name] then
local vis = player.gui.top[main_frame_name].visible
if vis then
player.gui.top[main_frame_name].visible = false
if frame then
frame.visible = false
return
end
end
@ -241,7 +249,7 @@ local function on_player_changed_surface(event)
end
function Public.update_gui(player)
local rpg = RPG.get_table()
local rpg_extra = RPG.get_extra_table()
local this = WPT.get()
if not player.gui.top[main_frame_name] then
@ -253,12 +261,13 @@ function Public.update_gui(player)
end
local gui = player.gui.top[main_frame_name]
if rpg.global_pool == 0 then
if rpg_extra.global_pool == 0 then
gui.global_pool.caption = 'XP: 0'
gui.global_pool.tooltip = 'Dig, handcraft or run to increase the pool!'
elseif rpg.global_pool > 0 then
gui.global_pool.caption = 'XP: ' .. format_number(floor(rpg.global_pool), true)
gui.global_pool.tooltip = 'Amount of XP that is stored inside the global xp pool.'
elseif rpg_extra.global_pool >= 0 then
gui.global_pool.caption = 'XP: ' .. format_number(floor(rpg_extra.global_pool), true)
gui.global_pool.tooltip =
'Amount of XP that is stored inside the global xp pool.\nRaw Value: ' .. floor(rpg_extra.global_pool)
end
gui.scrap_mined.caption = ' [img=entity.tree-01][img=entity.rock-huge]: ' .. format_number(this.mined_scrap, true)

View File

@ -274,7 +274,7 @@ function Public.kill_wagon(icw, entity)
kick_players_out_of_vehicles(wagon)
kill_wagon_doors(icw, wagon)
for _, e in pairs(surface.find_entities_filtered({area = wagon.area})) do
if e.name == 'character' and e.player then
if e and e.valid and e.name == 'character' and e.player then
local p = wagon.entity.surface.find_non_colliding_position('character', wagon.entity.position, 128, 0.5)
if p then
e.player.teleport(p, wagon.entity.surface)
@ -315,7 +315,7 @@ function Public.create_room_surface(icw, unit_number)
local surface = game.create_surface(tostring(unit_number), map_gen_settings)
surface.freeze_daytime = true
surface.daytime = 0.1
surface.request_to_generate_chunks({16, 16}, 2)
surface.request_to_generate_chunks({16, 16}, 1)
surface.force_generate_chunk_requests()
for _, tile in pairs(surface.find_tiles_filtered({area = {{-2, -2}, {2, 2}}})) do
surface.set_tiles({{name = 'out-of-map', position = tile.position}}, true)

View File

@ -2,17 +2,21 @@ local Event = require 'utils.event'
--local Power = require 'maps.mountain_fortress_v3.power'
local ICW = require 'maps.mountain_fortress_v3.icw.main'
local WPT = require 'maps.mountain_fortress_v3.table'
local Difficulty = require 'modules.difficulty_vote'
local RPG = require 'maps.mountain_fortress_v3.rpg'
local Server = require 'utils.server'
local Alert = require 'maps.mountain_fortress_v3.alert'
local WD = require 'modules.wave_defense.table'
local Alert = require 'utils.alert'
local format_number = require 'util'.format_number
local Public = {}
local random = math.random
local rad = math.rad
local concat = table.concat
local cos = math.cos
local sin = math.sin
local shopkeeper = '[color=blue]Shopkeeper:[/color]'
local shopkeeper = '[color=blue]Shopkeeper:[/color]\n'
local comfylatron = '[color=blue]Comfylatron:[/color]\n'
local space = {
minimal_height = 10,
@ -181,6 +185,56 @@ local function validate_index()
end
end
local function create_poison_cloud(position)
local active_surface_index = WPT.get('active_surface_index')
local surface = game.surfaces[active_surface_index]
local random_angles = {
rad(random(359)),
rad(random(359)),
rad(random(359)),
rad(random(359))
}
surface.create_entity({name = 'poison-cloud', position = {x = position.x, y = position.y}})
surface.create_entity(
{
name = 'poison-cloud',
position = {
x = position.x + 12 * cos(random_angles[1]),
y = position.y + 12 * sin(random_angles[1])
}
}
)
surface.create_entity(
{
name = 'poison-cloud',
position = {
x = position.x + 12 * cos(random_angles[2]),
y = position.y + 12 * sin(random_angles[2])
}
}
)
surface.create_entity(
{
name = 'poison-cloud',
position = {
x = position.x + 12 * cos(random_angles[3]),
y = position.y + 12 * sin(random_angles[3])
}
}
)
surface.create_entity(
{
name = 'poison-cloud',
position = {
x = position.x + 12 * cos(random_angles[4]),
y = position.y + 12 * sin(random_angles[4])
}
}
)
end
local function close_market_gui(player)
local this = WPT.get()
@ -439,7 +493,6 @@ end
local function gui_click(event)
local this = WPT.get()
local wdt = WD.get_table()
local element = event.element
local player = game.players[event.player_index]
@ -505,50 +558,17 @@ local function gui_click(event)
local cost = (item.price * slider_value)
local item_count = item.stack * slider_value
if name == 'clear_threat_level' then
if wdt.threat <= 10000 then
return player.print(
shopkeeper .. ' ' .. player.name .. ', threat is already low!',
{r = 0.98, g = 0.66, b = 0.22}
)
end
player.remove_item({name = item.value, count = cost})
local message =
shopkeeper ..
' ' ..
player.name ..
' has bought the clear threat modifier for ' .. cost .. ' coins.\nThreat level is reduced by 50%!'
Alert.alert_all_players(5, message)
Server.to_discord_bold(
table.concat {
player.name ..
' has bought the clear threat modifier for ' .. cost .. ' coins.\nThreat level is reduced by 50%!'
}
)
this.threat_upgrades = this.threat_upgrades + item_count
wdt.threat = wdt.threat / 2 * item_count
redraw_market_items(data.item_frame, player)
redraw_coins_left(data.coins_left, player)
return
end
if name == 'locomotive_max_health' then
player.remove_item({name = item.value, count = cost})
local message =
shopkeeper ..
' ' ..
player.name ..
' has bought the locomotive health modifier for ' ..
cost .. ' coins.\nThe train health is now buffed.'
player.name .. ' has bought the locomotive health modifier for ' .. format_number(cost, true) .. ' coins.'
Alert.alert_all_players(5, message)
Server.to_discord_bold(
table.concat {
player.name ..
' has bought the locomotive health modifier for ' ..
cost .. ' coins.\nThe train health is now buffed.'
' has bought the locomotive health modifier for ' .. format_number(cost, true) .. ' coins.'
}
)
this.locomotive_max_health = this.locomotive_max_health + 2500 * item_count
@ -569,14 +589,12 @@ local function gui_click(event)
local message =
shopkeeper ..
' ' ..
player.name ..
' has bought the locomotive xp aura modifier for ' .. cost .. ' coins.\nThe XP aura is now buffed.'
player.name .. ' has bought the locomotive xp aura modifier for ' .. format_number(cost, true) .. ' coins.'
Alert.alert_all_players(5, message)
Server.to_discord_bold(
table.concat {
player.name ..
' has bought the locomotive xp aura modifier for ' .. cost .. ' coins.\nThe XP aura is now buffed.'
' has bought the locomotive xp aura modifier for ' .. format_number(cost, true) .. ' coins.'
}
)
this.locomotive_xp_aura = this.locomotive_xp_aura + 5
@ -607,14 +625,11 @@ local function gui_click(event)
local message =
shopkeeper ..
' ' ..
player.name ..
' has bought the xp point modifier for ' .. cost .. ' coins.\nYou now gain more XP points.'
player.name .. ' has bought the XP points modifier for ' .. format_number(cost, true) .. ' coins.'
Alert.alert_all_players(5, message)
Server.to_discord_bold(
table.concat {
player.name ..
' has bought the xp point modifier for ' .. cost .. ' coins.\nYou now gain more XP points.'
player.name .. ' has bought the XP points modifier for ' .. format_number(cost) .. ' coins.'
}
)
this.xp_points = this.xp_points + 0.5
@ -631,24 +646,27 @@ local function gui_click(event)
player.remove_item({name = item.value, count = cost})
if item_count >= 1 then
local message =
shopkeeper .. ' ' .. player.name .. ' has bought a flamethrower-turret slot for ' .. cost .. ' coins.'
shopkeeper ..
player.name .. ' has bought a flamethrower-turret slot for ' .. format_number(cost, true) .. ' coins.'
Alert.alert_all_players(5, message)
Server.to_discord_bold(
table.concat {
player.name .. ' has bought a flamethrower-turret slot for ' .. cost .. ' coins.'
player.name ..
' has bought a flamethrower-turret slot for ' .. format_number(cost, true) .. ' coins.'
}
)
else
local message =
shopkeeper ..
' ' ..
player.name ..
' has bought ' .. item_count .. ' flamethrower-turret slots for ' .. cost .. ' coins.'
player.name ..
' has bought ' ..
item_count .. ' flamethrower-turret slots for ' .. format_number(cost, true) .. ' coins.'
Alert.alert_all_players(5, message)
Server.to_discord_bold(
table.concat {
player.name ..
' has bought ' .. item_count .. ' flamethrower-turret slots for ' .. cost .. ' coins.'
' has bought ' ..
item_count .. ' flamethrower-turret slots for ' .. format_number(cost, true) .. ' coins.'
}
)
end
@ -663,18 +681,18 @@ local function gui_click(event)
if name == 'land_mine' then
player.remove_item({name = item.value, count = cost})
if item_count >= 1 then
local message = shopkeeper .. ' ' .. player.name .. ' has bought a landmine slot for ' .. cost .. ' coins.'
Alert.alert_all_players(3, message)
else
if item_count >= 1 and this.upgrades.landmine.bought % 10 == 0 then
local message =
shopkeeper ..
' ' .. player.name .. ' has bought ' .. item_count .. ' landmine slots for ' .. cost .. ' coins.'
player.name .. ' has bought a landmine slot for ' .. format_number(cost, true) .. ' coins.'
Alert.alert_all_players(3, message)
if cost >= 5000 then
if cost >= 1000 then
Server.to_discord_bold(
table.concat {
player.name .. ' has bought ' .. item_count .. ' landmine slots for ' .. cost .. ' coins.'
player.name ..
' has bought ' ..
item_count .. ' landmine slots for ' .. format_number(cost, true) .. ' coins.'
}
)
end
@ -687,6 +705,21 @@ local function gui_click(event)
redraw_coins_left(data.coins_left, player)
return
end
if name == 'skill_reset' then
player.remove_item({name = item.value, count = cost})
local message =
shopkeeper ..
player.name ..
' decided to recycle their RPG skills and start over for ' .. format_number(cost, true) .. ' coins.'
Alert.alert_all_players(10, message)
RPG.rpg_reset_player(player, true)
redraw_market_items(data.item_frame, player)
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
@ -883,19 +916,26 @@ local function place_market()
end
local function tick()
if game.tick % 120 == 0 then
Public.boost_players_around_train()
end
local ticker = game.tick
if game.tick % 30 == 0 then
if ticker % 30 == 0 then
place_market()
validate_index()
set_locomotive_health()
fish_tag()
if game.tick % 1800 == 0 then
set_player_spawn()
refill_fish()
end
end
if ticker % 120 == 0 then
Public.boost_players_around_train()
end
if ticker % 600 == 0 then
Public.transfer_pollution()
end
if ticker % 1800 == 0 then
set_player_spawn()
refill_fish()
end
end
@ -1025,9 +1065,6 @@ function Public.locomotive_spawn(surface, position)
this.icw_locomotive = locomotive
locomotive.surface.request_to_generate_chunks({0, 19}, 1)
locomotive.surface.force_generate_chunk_requests()
game.forces.player.set_spawn_position({0, 19}, locomotive.surface)
end
@ -1047,44 +1084,36 @@ end
function Public.get_items()
local this = WPT.get()
local threat_cost = 150000
local health_cost = 10000 * (1 + this.health_upgrades)
local aura_cost = 10000 * (1 + this.aura_upgrades)
local xp_point_boost_cost = 10000 * (1 + this.xp_points_upgrade)
local flamethrower_turrets_cost = 3500 * (1 + this.upgrades.flame_turret.bought)
local land_mine_cost = 2 * (1 + this.upgrades.landmine.bought)
local skill_reset_cost = 100000
local items = {}
items['clear_threat_level'] = {
stack = 1,
value = 'coin',
price = threat_cost,
tooltip = '[Wave Defense]:\nReduces the threat level by 50%\nUsable if threat level is too high.\nCan be purchased multiple times.',
sprite = 'item/computer',
enabled = true
}
items['locomotive_max_health'] = {
stack = 1,
value = 'coin',
price = health_cost,
tooltip = '[Locomotive Health]:\nUpgrades the train health.\nCan be purchased multiple times.',
sprite = 'item/computer',
tooltip = 'Upgrades the train health.\nCan be purchased multiple times.',
sprite = 'achievement/getting-on-track',
enabled = true
}
items['locomotive_xp_aura'] = {
stack = 1,
value = 'coin',
price = aura_cost,
tooltip = '[XP Aura]:\nUpgrades the aura that is around the train.\nNote! Reaching breach walls gives more XP.',
sprite = 'item/computer',
tooltip = 'Upgrades the XP aura that is around the train.',
sprite = 'achievement/tech-maniac',
enabled = true
}
items['xp_points_boost'] = {
stack = 1,
value = 'coin',
price = xp_point_boost_cost,
tooltip = '[XP Points]:\nUpgrades the amount of xp points you get inside the XP aura',
sprite = 'item/computer',
tooltip = 'Upgrades the amount of XP points you get inside the XP aura',
sprite = 'achievement/trans-factorio-express',
enabled = true
}
items['flamethrower_turrets'] = {
@ -1092,7 +1121,7 @@ function Public.get_items()
value = 'coin',
price = flamethrower_turrets_cost,
tooltip = 'Upgrades the amount of flamethrowers that can be placed.',
sprite = 'item/computer',
sprite = 'achievement/pyromaniac',
enabled = true
}
items['land_mine'] = {
@ -1100,7 +1129,15 @@ function Public.get_items()
value = 'coin',
price = land_mine_cost,
tooltip = 'Upgrades the amount of landmines that can be placed.',
sprite = 'item/computer',
sprite = 'achievement/watch-your-step',
enabled = true
}
items['skill_reset'] = {
stack = 1,
value = 'coin',
price = skill_reset_cost,
tooltip = 'For when you have picked the wrong RPG path and want to start over.\nPoints will be kept.',
sprite = 'achievement/golem',
enabled = true
}
@ -1118,6 +1155,46 @@ function Public.get_items()
return items
end
function Public.transfer_pollution()
local locomotive = WPT.get('locomotive')
local active_surface_index = WPT.get('active_surface_index')
local icw_locomotive = WPT.get('icw_locomotive')
local surface = icw_locomotive.surface
local Diff = Difficulty.get()
if not surface then
return
end
local total_interior_pollution = surface.get_total_pollution()
local pollution = surface.get_total_pollution() * (3 / (4 / 3 + 1)) * Diff.difficulty_vote_value
game.surfaces[active_surface_index].pollute(locomotive.position, pollution)
game.pollution_statistics.on_flow('locomotive', pollution - total_interior_pollution)
surface.clear_pollution()
end
function Public.enable_poison_defense()
local locomotive = WPT.get('locomotive')
if not locomotive then
return
end
if not locomotive.valid then
return
end
local pos = locomotive.position
create_poison_cloud({x = pos.x, y = pos.y})
if random(1, 3) == 1 then
local random_angles = {rad(random(359))}
create_poison_cloud({x = pos.x + 24 * cos(random_angles[1]), y = pos.y + -24 * sin(random_angles[1])})
end
local p = {
position = pos
}
local msg = comfylatron .. 'Train is taking heavy damage.\nDeploying defense mechanisms.'
Alert.alert_all_players_location(p, msg)
end
Public.place_market = place_market
Event.on_nth_tick(5, tick)

View File

@ -1,3 +1,17 @@
require 'maps.mountain_fortress_v3.generate'
require 'maps.mountain_fortress_v3.commands'
require 'maps.mountain_fortress_v3.breached_wall'
require 'modules.dynamic_landfill'
require 'modules.shotgun_buff'
require 'modules.rocks_heal_over_time'
require 'modules.no_deconstruction_of_neutral_entities'
require 'modules.rocks_yield_ore_veins'
require 'modules.spawners_contain_biters'
require 'modules.biters_yield_coins'
require 'modules.wave_defense.main'
require 'modules.mineable_wreckage_yields_scrap'
local CS = require 'maps.mountain_fortress_v3.surface'
local Map_score = require 'comfy_panel.map_score'
local Server = require 'utils.server'
@ -19,29 +33,15 @@ local Poll = require 'comfy_panel.poll'
local Collapse = require 'modules.collapse'
local Difficulty = require 'modules.difficulty_vote'
local Task = require 'utils.task'
local Alert = require 'maps.mountain_fortress_v3.alert'
local Alert = require 'utils.alert'
--local HD = require 'modules.hidden_dimension.main'
require 'maps.mountain_fortress_v3.generate'
require 'maps.mountain_fortress_v3.commands'
require 'maps.mountain_fortress_v3.breached_wall'
require 'modules.dynamic_landfill'
require 'modules.shotgun_buff'
require 'modules.rocks_heal_over_time'
require 'modules.no_deconstruction_of_neutral_entities'
require 'modules.rocks_yield_ore_veins'
require 'modules.spawners_contain_biters'
require 'modules.biters_yield_coins'
require 'modules.wave_defense.main'
require 'modules.mineable_wreckage_yields_scrap'
local Public = {}
-- local raise_event = script.raise_event
local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['rail'] = 16, ['wood'] = 16, ['explosives'] = 32}
local function disable_recipes()
local disable_recipes = function()
local force = game.forces.player
force.recipes['cargo-wagon'].enabled = false
force.recipes['fluid-wagon'].enabled = false
@ -63,7 +63,7 @@ local collapse_kill = {
enabled = true
}
local function disable_tech()
local disable_tech = function()
game.forces.player.technologies['landfill'].enabled = false
game.forces.player.technologies['optics'].researched = true
game.forces.player.technologies['railway'].researched = true
@ -71,7 +71,7 @@ local function disable_tech()
disable_recipes()
end
local function set_difficulty()
local set_difficulty = function()
local Diff = Difficulty.get()
local wave_defense_table = WD.get_table()
local player_count = #game.connected_players
@ -97,7 +97,7 @@ local function set_difficulty()
end
end
local function render_direction(surface)
local render_direction = function(surface)
local counter = WPT.get('soft_reset_counter')
if counter then
rendering.draw_text {
@ -193,7 +193,6 @@ local function render_direction(surface)
end
function Public.reset_map()
local Settings = CS.get()
local Diff = Difficulty.get()
local this = WPT.get()
local wave_defense_table = WD.get_table()
@ -205,11 +204,7 @@ function Public.reset_map()
end
end
if not this.active_surface_index then
this.active_surface_index = Settings.active_surface_index
else
this.active_surface_index = CS.create_surface()
end
this.active_surface_index = CS.create_surface()
Poll.reset()
ICW.reset()
@ -265,21 +260,22 @@ function Public.reset_map()
wave_defense_table.nest_building_density = 32
wave_defense_table.game_lost = false
wave_defense_table.spawn_position = {x = 0, y = 100}
WD.alert_boss_wave(true)
WD.clear_corpses(true)
set_difficulty()
if not surface.is_chunk_generated({-20, 22}) then
surface.request_to_generate_chunks({-20, 22}, 0.1)
surface.force_generate_chunk_requests()
surface.set_chunk_generated_status({-20, 22}, defines.chunk_generated_status.custom_tiles)
end
game.forces.player.set_spawn_position({-27, 25}, surface)
Task.start_queue()
Task.set_queue_speed(4)
Task.set_queue_speed(32)
this.chunk_load_tick = game.tick + 800
this.chunk_load_tick = game.tick + 1200
--HD.enable_auto_init = false
@ -290,7 +286,7 @@ function Public.reset_map()
--raise_event(HD.events.reset_game, {})
end
local function on_player_changed_position(event)
local on_player_changed_position = function(event)
local this = WPT.get()
local player = game.players[event.player_index]
local map_name = 'mountain_fortress_v3'
@ -315,10 +311,11 @@ local function on_player_changed_position(event)
end
end
local function on_player_joined_game(event)
local on_player_joined_game = function(event)
local this = WPT.get()
local player = game.players[event.player_index]
local surface = game.surfaces[this.active_surface_index]
local comfy = '[color=blue]Comfylatron:[/color] \n'
set_difficulty()
@ -326,7 +323,7 @@ local function on_player_joined_game(event)
this.players[player.index] = {
data = {}
}
local message = 'Greetings, ' .. player.name .. '!\nPlease read the map info.'
local message = comfy .. 'Greetings, ' .. player.name .. '!\nPlease read the map info.'
Alert.alert_player(player, 10, message)
for item, amount in pairs(starting_items) do
player.insert({name = item, count = amount})
@ -357,11 +354,11 @@ local function on_player_joined_game(event)
end
end
local function on_player_left_game()
local on_player_left_game = function()
set_difficulty()
end
local function on_pre_player_left_game(event)
local on_pre_player_left_game = function(event)
local this = WPT.get()
local player = game.players[event.player_index]
local tick
@ -379,7 +376,7 @@ local function on_pre_player_left_game(event)
end
end
local function remove_offline_players()
local remove_offline_players = function()
local this = WPT.get()
if not this.offline_players_enabled then
if game.tick < 500 then
@ -474,7 +471,7 @@ local function remove_offline_players()
end
end
local function on_research_finished(event)
local on_research_finished = function(event)
disable_recipes()
local research = event.research
local this = WPT.get()
@ -503,14 +500,14 @@ local function on_research_finished(event)
end
end
local function is_locomotive_valid()
local is_locomotive_valid = function()
local locomotive = WPT.get('locomotive')
if not locomotive.valid then
Entities.loco_died()
end
end
local function has_the_game_ended()
local has_the_game_ended = function()
local this = WPT.get()
if this.game_reset_tick then
if this.game_reset_tick < game.tick then
@ -531,12 +528,12 @@ local function has_the_game_ended()
end
end
local function chunk_load()
local chunk_load = function()
local chunk_load_tick = WPT.get('chunk_load_tick')
if chunk_load_tick then
if chunk_load_tick < game.tick then
WPT.get().chunk_load_tick = nil
Task.set_queue_speed(0.5)
Task.set_queue_speed(1)
end
end
end

View File

@ -15,6 +15,7 @@ Modified by Gerkiz *-*
require 'player_modifiers'
local Global = require 'utils.global'
local Alert = require 'utils.alert'
local Tabs = require 'comfy_panel.main'
local P = require 'player_modifiers'
local WD = require 'modules.wave_defense.table'
@ -38,14 +39,18 @@ local reset_tooltip = 'ONE-TIME reset if you picked the wrong path (this will ke
local reset_not_available =
'ONE-TIME reset if you picked the wrong path (this will keep your points)\nAvailable after level 50.'
local teller = '[color=blue]Global Pool Reward:[/color]'
local teller_global_pool = '[color=blue]Global Pool Reward:[/color] \n'
local teller_level_limit = '[color=blue]Level Limit:[/color] \n'
local rpg_t = {}
local rpg_extra = {
debug = false,
breached_walls = 1,
reward_new_players = 0,
level_limit_enabled = true
level_limit_enabled = false,
global_pool = 0,
leftover_pool = 0,
turret_kills_to_global_pool = true
}
local rpg_frame_icons = {
'entity/small-worm-turret',
@ -98,29 +103,6 @@ Global.register(
local Public = {}
function Public.get_table()
return rpg_t
end
function Public.get_extra_table()
return rpg_extra
end
function Public.toggle_debug()
if rpg_extra.debug then
rpg_extra.debug = false
else
rpg_extra.debug = true
end
end
function Public.debug_log(str)
if not rpg_extra.debug then
return
end
print(str)
end
local classes = {
['engineer'] = 'ENGINEER',
['strength'] = 'MINER',
@ -180,6 +162,7 @@ local function level_limit_exceeded(player, value)
if value then
return limits[zone]
end
if level >= limits[zone] then
return true
end
@ -406,13 +389,12 @@ local function draw_gui(player, forced)
t = frame.add({type = 'table', column_count = 4})
t.style.cell_padding = 1
local level_tooltip =
'Current max level limit for this zone is: ' ..
level_limit_exceeded(player, true) .. '\nIncreases by breaching walls/zones.'
add_gui_description(t, 'LEVEL', 80)
e = add_gui_stat(t, rpg_t[player.index].level, 80)
if rpg_extra.level_limit_enabled then
local level_tooltip =
'Current max level limit for this zone is: ' ..
level_limit_exceeded(player, true) .. '\nIncreases by breaching walls/zones.'
e.tooltip = level_tooltip
else
e.tooltip = gain_info_tooltip
@ -454,7 +436,7 @@ local function draw_gui(player, forced)
e.tooltip = tip
add_gui_increase_stat(tt, 'strength', player)
local tip = 'Increases reach distance.'
local tip = 'Increases reach distance.\nIncreases repair speed.'
e = add_gui_description(tt, 'MAGIC', w1)
e.tooltip = tip
e = add_gui_stat(tt, rpg_t[player.index].magicka, w2)
@ -547,6 +529,7 @@ local function draw_gui(player, forced)
tooltip = tooltip .. '\nLoot pickup distance bonus: ' .. player.character_loot_pickup_distance_bonus
tooltip = tooltip .. '\nItem pickup distance bonus: ' .. player.character_item_pickup_distance_bonus
tooltip = tooltip .. '\nResource reach distance bonus: ' .. player.character_resource_reach_distance_bonus
tooltip = tooltip .. '\nRepair speed: ' .. Public.get_magicka(player)
add_gui_description(tt, ' ', w0)
e = add_gui_description(tt, 'REACH\nDISTANCE', w1)
e.tooltip = tooltip
@ -663,142 +646,70 @@ local function level_up(player)
level_up_effects(player)
end
function Public.gain_xp(player, amount)
if level_limit_exceeded(player) then
local function add_to_global_pool(amount)
if not rpg_extra.global_pool then
return
end
Public.debug_log('RPG - ' .. player.name .. ' got org xp: ' .. amount)
local fee = amount * 0.3
Public.debug_log('RPG - ' .. player.name .. ' got fee: ' .. fee)
rpg_t.global_pool = rpg_t.global_pool + fee
amount = math_round(amount, 3) - fee
Public.debug_log('RPG - ' .. player.name .. ' got after fee: ' .. amount)
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
if player.gui.left.rpg then
draw_gui(player, false)
end
if not experience_levels[rpg_t[player.index].level + 1] then
return
end
if rpg_t[player.index].xp >= experience_levels[rpg_t[player.index].level + 1] then
level_up(player)
return
end
if rpg_t[player.index].last_floaty_text > game.tick then
return
end
player.create_local_flying_text {
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,
speed = 2
}
rpg_t[player.index].xp_since_last_floaty_text = 0
rpg_t[player.index].last_floaty_text = game.tick + visuals_delay
Public.debug_log('RPG - global_pool got : ' .. fee)
rpg_extra.global_pool = rpg_extra.global_pool + fee
return fee
end
local function global_pool()
if not rpg_t.global_pool then
if not rpg_extra.global_pool then
return
end
local pool = math_floor(rpg_t.global_pool)
local pool = math_floor(rpg_extra.global_pool)
local random_amount = math_random(5000, 10000)
if pool <= random_amount then
return
end
local player_count = #game.connected_players
local share = pool / player_count
if pool >= 20000 then
pool = 20000
end
local players_count = #game.connected_players
local players = game.connected_players
local share = pool / players_count
Public.debug_log('RPG - Share per player:' .. share)
for _, p in pairs(game.connected_players) do
for i = 1, #players do
local p = players[i]
if p.afk_time < 5000 then
p.create_local_flying_text {
text = '+' .. math_floor(share) .. ' xp',
position = p.position,
color = xp_floating_text_color,
time_to_live = 240,
speed = 1
}
rpg_t[p.index].xp_since_last_floaty_text = 0
Public.gain_xp(p, share)
xp_effects(p)
if not level_limit_exceeded(p) then
p.create_local_flying_text {
text = '+' .. math_floor(share) .. ' xp',
position = p.position,
color = xp_floating_text_color,
time_to_live = 240,
speed = 1
}
rpg_t[p.index].xp_since_last_floaty_text = 0
Public.gain_xp(p, share)
xp_effects(p)
else
if p.afk_time < 5000 then
share = share / 10
rpg_extra.leftover_pool = rpg_extra.leftover_pool + share
Public.debug_log('RPG - player level capped:' .. share)
end
end
else
p.print(teller .. ' ' .. p.name .. ' received nothing. Reason: AFK')
local message = teller_global_pool .. p.name .. ' received nothing. Reason: AFK'
Alert.alert_player_warning(p, 10, message)
end
end
rpg_t.global_pool = 0
return
end
function Public.rpg_reset_player(player, one_time_reset)
if player.gui.left.rpg then
player.gui.left.rpg.destroy()
end
if not player.character then
player.set_controller({type = defines.controllers.god})
player.create_character()
end
if one_time_reset then
local total = rpg_t[player.index].total
local old_level = rpg_t[player.index].level
local old_points_to_distribute = rpg_t[player.index].points_to_distribute
local old_xp = rpg_t[player.index].xp
rpg_t[player.index] = {
level = 1,
xp = 0,
strength = 10,
magicka = 10,
dexterity = 10,
vitality = 10,
points_to_distribute = 0,
last_floaty_text = visuals_delay,
xp_since_last_floaty_text = 0,
reset = true,
bonus = rpg_extra.breached_walls or 1,
rotated_entity_delay = 0,
gui_refresh_delay = 0,
last_mined_entity_position = {x = 0, y = 0}
}
rpg_t[player.index].points_to_distribute = old_points_to_distribute + total
rpg_t[player.index].xp = old_xp
rpg_t[player.index].level = old_level
if rpg_extra.leftover_pool >= 0 then
add_to_global_pool(rpg_extra.leftover_pool)
else
rpg_t[player.index] = {
level = 1,
xp = 0,
strength = 10,
magicka = 10,
dexterity = 10,
vitality = 10,
points_to_distribute = 0,
last_floaty_text = visuals_delay,
xp_since_last_floaty_text = 0,
reset = false,
total = 0,
bonus = 1,
rotated_entity_delay = 0,
gui_refresh_delay = 0,
last_mined_entity_position = {x = 0, y = 0}
}
rpg_extra.global_pool = 0
end
draw_gui_char_button(player)
draw_level_text(player)
update_char_button(player)
update_player_stats(player)
end
function Public.rpg_reset_all_players()
for k, _ in pairs(rpg_t) do
rpg_t[k] = nil
end
for _, p in pairs(game.connected_players) do
Public.rpg_reset_player(p)
end
rpg_extra.breached_walls = 1
rpg_extra.reward_new_players = 0
rpg_t.global_pool = 0
return
end
local function on_gui_click(event)
@ -996,7 +907,12 @@ local function on_entity_died(event)
if enemy_types[event.entity.type] then
for _, player in pairs(players) do
if rpg_xp_yield[event.entity.name] then
Public.gain_xp(player, rpg_xp_yield[event.entity.name] * global.biter_health_boost)
local amount = rpg_xp_yield[event.entity.name] * global.biter_health_boost
if rpg_extra.turret_kills_to_global_pool then
add_to_global_pool(amount)
else
Public.gain_xp(player, amount)
end
else
Public.gain_xp(player, 0.5 * global.biter_health_boost)
end
@ -1008,7 +924,12 @@ local function on_entity_died(event)
--Grant normal XP
for _, player in pairs(players) do
if rpg_xp_yield[event.entity.name] then
Public.gain_xp(player, rpg_xp_yield[event.entity.name])
local amount = rpg_xp_yield[event.entity.name]
if rpg_extra.turret_kills_to_global_pool then
add_to_global_pool(amount)
else
Public.gain_xp(player, amount)
end
else
Public.gain_xp(player, 0.5)
end
@ -1086,18 +1007,6 @@ local function one_punch(character, target, damage)
end
end
--- Gives connected player some bonus xp if the map was preemptively shut down.
-- amount (integer) -- 10 levels
-- local Public = require 'maps.mountain_fortress_v3.rpg' Public.give_xp(512)
function Public.give_xp(amount)
for _, player in pairs(game.connected_players) do
if not validate_player(player) then
return
end
Public.gain_xp(player, amount)
end
end
local function on_entity_damaged(event)
if not event.cause then
return
@ -1207,11 +1116,33 @@ local function on_player_repaired_entity(event)
if math_random(1, 4) ~= 1 then
return
end
local entity = event.entity
if not entity then
return
end
if not entity.valid then
return
end
if not entity.health then
return
end
local player = game.players[event.player_index]
if not player.character then
return
end
Public.gain_xp(player, 0.05)
local repair_speed = Public.get_magicka(player)
if repair_speed <= 0 then
return
end
entity.health = entity.health + repair_speed
end
local function on_player_rotated_entity(event)
@ -1327,19 +1258,168 @@ local function on_player_joined_game(event)
update_player_stats(player)
end
local function on_init()
if not rpg_t.global_pool then
rpg_t.global_pool = 0
end
table.shuffle_table(rpg_frame_icons)
end
local function tick()
global_pool()
end
--- Gives connected player some bonus xp if the map was preemptively shut down.
-- amount (integer) -- 10 levels
-- local Public = require 'maps.mountain_fortress_v3.rpg' Public.give_xp(512)
function Public.give_xp(amount)
for _, player in pairs(game.connected_players) do
if not validate_player(player) then
return
end
Public.gain_xp(player, amount)
end
end
function Public.rpg_reset_player(player, one_time_reset)
if player.gui.left.rpg then
player.gui.left.rpg.destroy()
end
if not player.character then
player.set_controller({type = defines.controllers.god})
player.create_character()
end
if one_time_reset then
local total = rpg_t[player.index].total
if not total then
total = 0
end
local old_level = rpg_t[player.index].level
local old_points_to_distribute = rpg_t[player.index].points_to_distribute
local old_xp = rpg_t[player.index].xp
rpg_t[player.index] = {
level = 1,
xp = 0,
strength = 10,
magicka = 10,
dexterity = 10,
vitality = 10,
points_to_distribute = 0,
last_floaty_text = visuals_delay,
xp_since_last_floaty_text = 0,
reset = true,
capped = false,
bonus = rpg_extra.breached_walls or 1,
rotated_entity_delay = 0,
gui_refresh_delay = 0,
last_mined_entity_position = {x = 0, y = 0}
}
rpg_t[player.index].points_to_distribute = old_points_to_distribute + total
rpg_t[player.index].xp = old_xp
rpg_t[player.index].level = old_level
else
rpg_t[player.index] = {
level = 1,
xp = 0,
strength = 10,
magicka = 10,
dexterity = 10,
vitality = 10,
points_to_distribute = 0,
last_floaty_text = visuals_delay,
xp_since_last_floaty_text = 0,
reset = false,
capped = false,
total = 0,
bonus = 1,
rotated_entity_delay = 0,
gui_refresh_delay = 0,
last_mined_entity_position = {x = 0, y = 0}
}
end
draw_gui_char_button(player)
draw_level_text(player)
update_char_button(player)
update_player_stats(player)
end
function Public.rpg_reset_all_players()
for k, _ in pairs(rpg_t) do
rpg_t[k] = nil
end
for _, p in pairs(game.connected_players) do
Public.rpg_reset_player(p)
end
rpg_extra.breached_walls = 1
rpg_extra.reward_new_players = 0
rpg_extra.global_pool = 0
end
function Public.get_magicka(player)
return (rpg_t[player.index].magicka - 10) * 0.10
end
function Public.gain_xp(player, amount)
if level_limit_exceeded(player) then
add_to_global_pool(amount)
if not rpg_t[player.index].capped then
rpg_t[player.index].capped = true
local message = teller_level_limit .. 'You have hit the max level for the current zone.'
Alert.alert_player_warning(player, 10, message)
end
return
end
if rpg_t[player.index].capped then
rpg_t[player.index].capped = false
end
Public.debug_log('RPG - ' .. player.name .. ' got org xp: ' .. amount)
local fee = add_to_global_pool(amount)
Public.debug_log('RPG - ' .. player.name .. ' got fee: ' .. fee)
amount = math_round(amount, 3) - fee
Public.debug_log('RPG - ' .. player.name .. ' got after fee: ' .. amount)
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
if player.gui.left.rpg then
draw_gui(player, false)
end
if not experience_levels[rpg_t[player.index].level + 1] then
return
end
if rpg_t[player.index].xp >= experience_levels[rpg_t[player.index].level + 1] then
level_up(player)
return
end
if rpg_t[player.index].last_floaty_text > game.tick then
return
end
player.create_local_flying_text {
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,
speed = 2
}
rpg_t[player.index].xp_since_last_floaty_text = 0
rpg_t[player.index].last_floaty_text = game.tick + visuals_delay
end
function Public.get_table()
return rpg_t
end
function Public.get_extra_table()
return rpg_extra
end
function Public.toggle_debug()
if rpg_extra.debug then
rpg_extra.debug = false
else
rpg_extra.debug = true
end
end
function Public.debug_log(str)
if not rpg_extra.debug then
return
end
print(str)
end
local event = require 'utils.event'
event.on_init(on_init)
event.add(defines.events.on_entity_damaged, on_entity_damaged)
event.add(defines.events.on_entity_died, on_entity_died)
event.add(defines.events.on_gui_click, on_gui_click)

View File

@ -1,4 +1,4 @@
-- on table to rule them all!
-- one table to rule them all!
local Global = require 'utils.global'
local Event = require 'utils.event'
@ -51,6 +51,7 @@ function Public.reset_table()
this.locomotive_xp_aura = 40
this.xp_points = 0
this.xp_points_upgrade = 0
this.poison_deployed = false
this.upgrades = {
showed_text = false,
landmine = {
@ -73,7 +74,6 @@ function Public.reset_table()
this.hidden_dimension.logistic_research_level = 0
end
this.health_upgrades = 0
this.threat_upgrades = 0
this.breached_wall = 1
this.entity_limits = {}
this.offline_players_enabled = false

View File

@ -78,15 +78,14 @@ local turret_list = {
}
local function place_wagon(data)
if math_random(1, 5048) ~= 1 then
return false
end
local surface = data.surface
local tiles = data.tiles
local entities = data.entities
local top_x = data.top_x
local top_y = data.top_y
if math_random(1, 1548) ~= 1 then
return
end
local position = {x = top_x + math_random(4, 12) * 2, y = top_y + math_random(4, 12) * 2}
local wagon_mineable = {
callback = Functions.disable_minable_and_ICW_callback
@ -133,6 +132,7 @@ local function place_wagon(data)
callback = wagon_mineable
}
)
return true
end
local function get_oil_amount(p)
@ -346,6 +346,9 @@ local function process_level_13_position(x, y, data)
if math_random(1, 256) == 1 then
spawn_turret(entities, p, 4)
end
if place_wagon(data) then
return
end
return
end
@ -433,6 +436,9 @@ local function process_level_12_position(x, y, data)
elseif math_random(1, 32) == 1 then
entities[#entities + 1] = {name = 'coal', position = p, amount = math_abs(p.y) + 1}
end
if place_wagon(data) then
return
end
end
if math_random(1, 8192) == 1 then
markets[#markets + 1] = p
@ -470,6 +476,9 @@ local function process_level_11_position(x, y, data)
if noise_1 < -0.72 then
tiles[#tiles + 1] = {name = 'lab-dark-1', position = p}
entities[#entities + 1] = {name = 'uranium-ore', position = p, amount = math_abs(p.y) + 1 * 3}
if place_wagon(data) then
return
end
return
end
@ -532,6 +541,9 @@ local function process_level_10_position(x, y, data)
entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'}
end
tiles[#tiles + 1] = {name = 'water-mud', position = p}
if place_wagon(data) then
return
end
return
end
if math_abs(scrapyard) > 0.25 and math_abs(scrapyard) < 0.40 then
@ -582,6 +594,9 @@ local function process_level_9_position(x, y, data)
if math_random(1, 256) == 1 then
Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier)
entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'}
if place_wagon(data) then
return
end
end
return
end
@ -630,10 +645,15 @@ local function process_level_8_position(x, y, data)
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
return
end
if small_caves < -0.35 then
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
return
end
if place_wagon(data) then
return
end
end
if scrapyard < -0.25 or scrapyard > 0.25 then
@ -790,8 +810,14 @@ local function process_level_7_position(x, y, data)
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
return
end
if small_caves < -0.55 then
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
return
end
if place_wagon(data) then
return
end
end
@ -824,10 +850,15 @@ local function process_level_6_position(x, y, data)
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
return
end
if small_caves < -0.45 then
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
return
end
if place_wagon(data) then
return
end
end
if large_caves > -0.03 and large_caves < 0.03 and cave_rivers < 0.25 then
@ -895,6 +926,9 @@ local function process_level_5_position(x, y, data)
if math_random(1, 128) == 1 then
Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier)
entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'}
if place_wagon(data) then
return
end
end
if math_random(1, 256) == 1 then
spawn_turret(entities, p, 4)
@ -921,7 +955,6 @@ local function process_level_5_position(x, y, data)
if math_random(1, 2) == 1 then
entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p}
end
return
end
end
@ -986,10 +1019,15 @@ local function process_level_4_position(x, y, data)
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
return
end
if small_caves < -0.75 then
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
return
end
if place_wagon(data) then
return
end
end
if small_caves > -0.15 and small_caves < 0.15 then
@ -1071,10 +1109,17 @@ local function process_level_3_position(x, y, data)
if noise_cave_ponds < 0.12 and noise_cave_ponds > -0.12 then
if small_caves > 0.85 then
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
return
end
if small_caves < -0.85 then
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
return
end
if place_wagon(data) then
return
end
end
@ -1176,12 +1221,17 @@ local function process_level_2_position(x, y, data)
if noise_cave_ponds < 0.15 and noise_cave_ponds > -0.15 then
if small_caves > 0.32 then
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
return
end
if small_caves < -0.32 then
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
return
end
if place_wagon(data) then
return
end
end
--Green Water Ponds
@ -1296,6 +1346,10 @@ local function process_level_1_position(x, y, data)
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
return
end
if place_wagon(data) then
return
end
end
--Water Ponds
@ -1551,10 +1605,6 @@ function Public.heavy_functions(x, y, data)
return
end
if top_y > 32 then
game.forces.player.chart(surface, {{top_x, top_y}, {top_x + 31, top_y + 31}})
end
if top_y == -128 and top_x == -128 then
local pl = WPT.get().locomotive.position
for _, entity in pairs(
@ -1568,9 +1618,6 @@ function Public.heavy_functions(x, y, data)
if top_y < 0 then
process_bits(x, y, data)
if math_random(1, chance_for_wagon_spawn) == 1 then
place_wagon(data)
end
return
end
@ -1590,4 +1637,29 @@ function Public.heavy_functions(x, y, data)
end
end
Event.add(
defines.events.on_chunk_generated,
function(e)
local surface = e.surface
local map_name = 'mountain_fortress_v3'
if string.sub(surface.name, 0, #map_name) ~= map_name then
return
end
local area = e.area
local left_top = area.left_top
if not surface then
return
end
if not surface.valid then
return
end
if left_top.y > 32 then
game.forces.player.chart(surface, {{left_top.x, left_top.y}, {left_top.x + 31, left_top.y + 31}})
end
end
)
return Public

View File

@ -26,17 +26,6 @@ local function addStyle(guiIn, styleIn)
end
end
local function build_prototype_data(item_name)
local localised_name
for name, prototype in pairs(game.item_prototypes) do
if item_name == name then
localised_name = prototype.localised_name
end
end
return localised_name
end
local function adjustSpace(guiIn)
addStyle(guiIn.add {type = 'line', direction = 'horizontal'}, space)
end
@ -83,7 +72,7 @@ local function redraw_inventory(gui, source, target, caption, panel_type)
gui.clear()
local items_table = gui.add({type = 'table', column_count = 11})
local prototype
local types = game.item_prototypes
local mod_gui = this.gui[source.index].inventory_gui
mod_gui.caption = 'Inventory of ' .. target.name
@ -92,8 +81,6 @@ local function redraw_inventory(gui, source, target, caption, panel_type)
local flow = items_table.add({type = 'flow'})
flow.style.vertical_align = 'bottom'
prototype = build_prototype_data(name)
local button =
flow.add(
{
@ -101,35 +88,31 @@ local function redraw_inventory(gui, source, target, caption, panel_type)
sprite = 'item/' .. name,
number = opts,
name = name,
tooltip = prototype,
tooltip = types[name].localised_name,
style = 'slot_button'
}
)
button.enabled = false
if caption == 'Armor' then
if not target.get_inventory(5)[1].grid then
return
end
local p_armor = target.get_inventory(5)[1].grid.get_contents()
for k, v in pairs(p_armor) do
prototype = build_prototype_data(k)
local armor_gui =
flow.add(
{
type = 'sprite-button',
sprite = 'item/' .. k,
number = v,
name = k,
tooltip = prototype,
style = 'slot_button'
}
)
armor_gui.enabled = false
if target.get_inventory(5)[1].grid then
local p_armor = target.get_inventory(5)[1].grid.get_contents()
for k, v in pairs(p_armor) do
local armor_gui =
flow.add(
{
type = 'sprite-button',
sprite = 'item/' .. k,
number = v,
name = k,
tooltip = types[name].localised_name,
style = 'slot_button'
}
)
armor_gui.enabled = false
end
end
end
::continue::
end
end
@ -170,6 +153,7 @@ local function open_inventory(source, target)
local menu_frame = mod_gui.inventory_gui
if menu_frame then
menu_frame.destroy()
return
end
local frame =
@ -194,16 +178,24 @@ local function open_inventory(source, target)
this.data[source.index].frame = frame
this.data[source.index].player_opened = target
local main = target.get_main_inventory().get_contents()
local armor = target.get_inventory(defines.inventory.character_armor).get_contents()
local guns = target.get_inventory(defines.inventory.character_guns).get_contents()
local ammo = target.get_inventory(defines.inventory.character_ammo).get_contents()
local trash = target.get_inventory(defines.inventory.character_trash).get_contents()
local types = {
['Main'] = target.get_main_inventory().get_contents(),
['Armor'] = target.get_inventory(defines.inventory.character_armor).get_contents(),
['Guns'] = target.get_inventory(defines.inventory.character_guns).get_contents(),
['Ammo'] = target.get_inventory(defines.inventory.character_ammo).get_contents(),
['Trash'] = target.get_inventory(defines.inventory.character_trash).get_contents()
['Main'] = main,
['Armor'] = armor,
['Guns'] = guns,
['Ammo'] = ammo,
['Trash'] = trash
}
for k, v in pairs(types) do
add_inventory(panel, source, target, k, v)
if v ~= nil then
add_inventory(panel, source, target, k, v)
end
end
end

View File

@ -5,6 +5,7 @@ local ThreatEvent = require "modules.wave_defense.threat_events"
local update_gui = require "modules.wave_defense.gui"
local threat_values = require "modules.wave_defense.threat_values"
local WD = require "modules.wave_defense.table"
local Alert = require 'utils.alert'
local math_random = math.random
local math_floor = math.floor
local table_insert = table.insert
@ -229,7 +230,13 @@ local function set_next_wave()
if wave_defense_table.wave_number % 25 == 0 then
wave_defense_table.boss_wave = true
wave_defense_table.boss_wave_warning = true
game.print('Boss Wave: ' .. wave_defense_table.wave_number, {r = 0.8, g = 0.1, b = 0.1})
if wave_defense_table.alert_boss_wave then
local msg = 'Boss Wave: ' .. wave_defense_table.wave_number
local pos = {
position = wave_defense_table.spawn_position
}
Alert.alert_all_players_location(pos, msg, {r = 0.8, g = 0.1, b = 0.1})
end
threat_gain = threat_gain * 2
else
if wave_defense_table.boss_wave_warning then

View File

@ -12,9 +12,9 @@ Global.register(
)
function Public.reset_wave_defense()
wave_defense.boss_wave = false
wave_defense.boss_wave_warning = false
wave_defense.side_target_count = 0
wave_defense.boss_wave = false
wave_defense.boss_wave_warning = false
wave_defense.side_target_count = 0
wave_defense.active_biters = {}
wave_defense.active_biter_count = 0
wave_defense.active_biter_threat = 0
@ -49,14 +49,27 @@ function Public.reset_wave_defense()
wave_defense.worm_building_chance = 3
wave_defense.worm_building_density = 16
wave_defense.worm_raffle = {}
wave_defense.clear_corpses = true
wave_defense.clear_corpses = false
wave_defense.alert_boss_wave = false
end
function Public.get_table()
return wave_defense
end
local on_init = function ()
function Public.clear_corpses(value)
if value then
wave_defense.clear_corpses = value
end
end
function Public.alert_boss_wave(value)
if value then
wave_defense.alert_boss_wave = value
end
end
local on_init = function()
Public.reset_wave_defense()
end

View File

@ -256,6 +256,33 @@ function Public.alert_player(player, duration, message, color)
player,
duration,
function(container)
container.add {
type = 'sprite-button',
sprite = 'achievement/you-are-doing-it-right',
style = 'slot_button'
}
local label = container.add({type = 'label', name = close_alert_name, caption = message})
label.style.single_line = false
label.style.font_color = color or Color.comfy
end
)
end
---Message to a specific player as warning
---@param player LuaPlayer
---@param duration number
---@param message string
---@param color string
function Public.alert_player_warning(player, duration, message, color)
Public.alert_player_template(
player,
duration,
function(container)
container.add {
type = 'sprite-button',
sprite = 'achievement/golem',
style = 'slot_button'
}
local label = container.add({type = 'label', name = close_alert_name, caption = message})
label.style.single_line = false
label.style.font_color = color or Color.comfy
@ -305,14 +332,19 @@ commands.add_command(
if not param then
return p('Valid arguments are: message_to_print')
end
Public.alert_all_players_location(player, param)
else
p = log
if not param then
return p('Valid arguments are: message_to_print')
end
Public.alert_all_players(15, param)
local comfy = '[color=blue]' .. player.name .. ':[/color] \n'
local message = comfy .. param
Public.alert_all_players_location(player, message)
end
else
p = log
if not param then
return p('Valid arguments are: message_to_print')
end
local comfy = '[color=blue]Server:[/color] \n'
local message = comfy .. param
p(param)
Public.alert_all_players(15, message)
end
end
)
@ -361,8 +393,9 @@ commands.add_command(
end
if t_message then
local message = t_message
Public.alert_player(target_player, 15, message)
local comfy = '[color=blue]' .. player.name .. ':[/color] \n'
local message = comfy .. t_message
Public.alert_player_warning(target_player, 15, message)
else
p('No message was provided', Color.fail)
end