1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-13 13:49:33 +02:00

scrapyard changes

Fixes:
Collapse activates after reaching first breach wall
Crafting grants more xp
Magic is tweaked
Loot chests are affected by magic
Scrap turrets are boosted in dmg
Disable out-of-map tile placing
RPG levels are now visible in the player list
Moved comfylatron to overworld, 'lil bugger was causing issues	
RPG now has a global XP pool
Locomotive has now market upgrades
XP is granted after each breached wall
This commit is contained in:
Gerkiz 2020-05-01 13:06:00 +02:00
parent f08f46d253
commit 2c8a3df495
5 changed files with 242 additions and 43 deletions

View File

@ -356,7 +356,7 @@ local function go_to_some_location()
return true
end
local function spawn_comfylatron(surface, x, y)
local function spawn_comfylatron(surface)
local this = Scrap_table.get_table()
if surface == nil then return end
if not this.comfylatron_last_player_visit then this.comfylatron_last_player_visit = 0 end
@ -375,9 +375,9 @@ local function spawn_comfylatron(surface, x, y)
if #players == 0 then return false end
local player = players[math_random(1, #players)]
local position = player.surface.find_non_colliding_position("compilatron", player.position, 16, 1)
local position = surface.find_non_colliding_position("compilatron", player.position, 16, 1)
if not position then return false end
this.comfylatron = player.surface.create_entity({
this.comfylatron = surface.create_entity({
name = "compilatron",
position = position,
force = "neutral"
@ -400,7 +400,7 @@ local function heartbeat()
local surface = game.surfaces[this.active_surface_index]
if not surface then return end
if surface == nil then return end
if not this.comfylatron then if math_random(1,4) == 1 then spawn_comfylatron(surface, 0, 26) end return end
if not this.comfylatron then if math_random(1,4) == 1 then spawn_comfylatron(surface) end return end
if not this.comfylatron.valid then this.comfylatron = nil return end
if visit_player() then return end
local nearby_players = get_nearby_players()

View File

@ -1,10 +1,19 @@
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 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
function Public.render_train_hp()
local this = Scrap_table.get_table()
local surface = game.surfaces[this.active_surface_index]
@ -74,10 +83,6 @@ end
local function rebuild_energy_overworld(data)
local this = data.this
local surface = data.surface
if not this.locomotive then return end
if not this.locomotive.valid then return end
if not this.locomotive.surface then return end
if not this.locomotive.surface.valid then return end
if this.ow_energy then
if this.ow_energy.valid then
local position = this.ow_energy.position
@ -95,7 +100,7 @@ local function rebuild_energy_overworld(data)
name = "electric-energy-interface",
position = {
x=this.locomotive.position.x,
y=this.locomotive.position.y+1
y=this.locomotive.position.y+2
},
create_build_effect_smoke = false,
force = game.forces.neutral
@ -114,31 +119,32 @@ local function rebuild_energy_overworld(data)
this.ow_energy.destructible = false
this.ow_energy.operable = false
this.ow_energy.power_production = 0
this.ow_energy.electric_buffer_size = 10000000
if this.energy_purchased then
this.ow_energy.electric_buffer_size = energy_upgrade
else
this.ow_energy.electric_buffer_size = 10000000
end
if this.old_ow_energy then
this.ow_energy.energy = this.old_ow_energy
end
end
local function rebuild_energy_loco(data, destroy)
local function rebuild_energy_loco(data, rebuild)
local this = data.this
local icw_table = data.icw_table
if not this.locomotive.valid then return end
local unit_surface = this.locomotive.unit_number
local loco_surface = game.surfaces[icw_table.wagons[unit_surface].surface.index]
local surface = data.surface
local pos = {x=-19, y=3}
if destroy then
if rebuild then
local radius = 1024
local area = {{x = -radius, y = -radius}, {x = radius, y = radius}}
for _, entity in pairs(loco_surface.find_entities_filtered{area = area, name = "electric-energy-interface"}) do
for _, entity in pairs(surface.find_entities_filtered{area = area, name = "electric-energy-interface"}) do
entity.destroy()
end
this.energy.loco = nil
this.lo_energy = nil
end
this.lo_energy = loco_surface.create_entity{
this.lo_energy = surface.create_entity{
name = "electric-energy-interface",
position = pos,
create_build_effect_smoke = false,
@ -147,7 +153,7 @@ local function rebuild_energy_loco(data, destroy)
rendering.draw_text{
text = "Power to overworld",
surface = loco_surface,
surface = surface,
target = this.lo_energy,
target_offset = {0, -1.5},
color = { r = 0, g = 1, b = 0},
@ -158,12 +164,178 @@ local function rebuild_energy_loco(data, destroy)
this.lo_energy.destructible = false
this.lo_energy.operable = false
this.lo_energy.power_production = 0
this.lo_energy.electric_buffer_size = 10000000
if this.energy_purchased then
this.lo_energy.electric_buffer_size = energy_upgrade
else
this.lo_energy.electric_buffer_size = 10000000
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}}
}
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
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]
if not this.locomotive then return end
if not this.locomotive.valid then return end
local data = {
this = this,
@ -176,10 +348,15 @@ end
function Public.power_source_locomotive()
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,
icw_table = icw_table
icw_table = icw_table,
surface = surface
}
if not this.lo_energy then
@ -223,6 +400,7 @@ end
local function tick()
Public.power_source_overworld()
Public.power_source_locomotive()
Public.place_market()
if game.tick % 30 == 0 then
if game.tick % 1800 == 0 then
set_player_spawn_and_refill_fish()
@ -232,5 +410,7 @@ local function tick()
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

View File

@ -784,7 +784,7 @@ local function transfer_pollution(data)
end
local tick_minute_functions = {
[300 * 2] = scrap_randomness,
[300 * 2 + 30 * 2] = scrap_randomness,
[300 * 3 + 30 * 0] = darkness,
[300 * 3 + 30 * 1] = transfer_pollution,
}
@ -805,7 +805,6 @@ local on_tick = function()
if Collapse.start_now() == true then goto continue end
if this.left_top.y % Terrain.level_depth == 0 and this.left_top.y < 0 and this.left_top.y > Terrain.level_depth * -10 then
if not Collapse.start_now() then
this.o_left_top = this.left_top
Collapse.start_now(true)
end
end

View File

@ -15,11 +15,14 @@ Modified by Gerkiz *-*
require "player_modifiers"
local math_random = math.random
local Global = require 'utils.global'
local Tabs = require "comfy_panel.main"
local Color = require 'utils.color_presets'
local P = require "player_modifiers"
local math_floor = math.floor
local math_random = math.random
local math_sqrt = math.sqrt
local nth_tick = 18001
local visuals_delay = 1800
local level_up_floating_text_color = {0, 205, 0}
local xp_floating_text_color = {157, 157, 157}
@ -39,9 +42,7 @@ local rpg_frame_icons = {
"entity/behemoth-spitter"
}
local math_sqrt = math.sqrt
local math_floor = math.floor
local math_random = math.random
Global.register(
{rpg_t=rpg_t, rpg_frame_icons=rpg_frame_icons},
@ -480,8 +481,9 @@ local function gain_xp(player, amount)
rpg_t[player.index].last_floaty_text = game.tick + visuals_delay
end
function global_pool()
local function global_pool()
local pool = rpg_t.global_pool
if pool <= 5000 then return end
local player_count = #game.connected_players
local share = pool / player_count
rpg_t.global_pool = 0
@ -489,11 +491,11 @@ 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", position=p.position, color=xp_floating_text_color, time_to_live=240, speed=1}
gain_xp(p, s * 2)
gain_xp(p, s * 2)
else
p.create_local_flying_text{text="+" .. 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
gain_xp(p, share)
gain_xp(p, share)
end
end
return
@ -511,7 +513,7 @@ function Public.rpg_reset_player(player, one_time_reset)
local old_xp = rpg_t[player.index].xp
rpg_t[player.index] = {
level = 1, xp = 0, strength = 10, magic = 10, dexterity = 10, vitality = 10, points_to_distribute = 0,
last_floaty_text = visuals_delay, xp_since_last_floaty_text = 0, reset = true,
last_floaty_text = visuals_delay, xp_since_last_floaty_text = 0, reset = true, bonus = 1,
rotated_entity_delay = 0, gui_refresh_delay = 0, last_mined_entity_position = {x = 0, y = 0},
}
rpg_t[player.index].points_to_distribute = total
@ -520,7 +522,7 @@ function Public.rpg_reset_player(player, one_time_reset)
else
rpg_t[player.index] = {
level = 1, xp = 0, strength = 10, magic = 10, dexterity = 10, vitality = 10, points_to_distribute = 0,
last_floaty_text = visuals_delay, xp_since_last_floaty_text = 0, reset = false, total = 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},
}
end
@ -838,12 +840,30 @@ local function on_player_rotated_entity(event)
gain_xp(player, 0.20)
end
local function distance(player)
local distance_to_center = math_floor(math_sqrt(player.position.x ^ 2 + player.position.y ^ 2))
local location = distance_to_center
if location < 950 then return end
local min = 960 * rpg_t[player.index].bonus
local max = 965 * rpg_t[player.index].bonus
local min_times = location >= min
local max_times = location <= max
if min_times and max_times then
rpg_t[player.index].bonus = rpg_t[player.index].bonus + 1
player.print("[color=blue]Grandmaster:[/color] Survivor! Well done.")
gain_xp(player, 300 * rpg_t[player.index].bonus)
return
end
end
local function on_player_changed_position(event)
if math_random(1, 64) ~= 1 then return end
local player = game.players[event.player_index]
if string.sub(player.surface.name, 0, 9) ~= "scrapyard" then return end
distance(player)
if math_random(1, 64) ~= 1 then return end
if not player.character then return end
if player.character.driving then return end
gain_xp(player, 1.0)
gain_xp(player, 1.0)
end
local building_and_mining_blacklist = {
@ -902,6 +922,10 @@ local function on_init(event)
table.shuffle_table(rpg_frame_icons)
end
local function tick()
global_pool()
end
local event = require 'utils.event'
event.on_init(on_init)
event.add(defines.events.on_entity_damaged, on_entity_damaged)
@ -914,5 +938,6 @@ event.add(defines.events.on_player_repaired_entity, on_player_repaired_entity)
event.add(defines.events.on_player_respawned, on_player_respawned)
event.add(defines.events.on_player_rotated_entity, on_player_rotated_entity)
event.add(defines.events.on_pre_player_mined_item, on_pre_player_mined_item)
event.on_nth_tick(nth_tick, tick)
return Public

View File

@ -21,10 +21,7 @@ local this = {
x = 0,
y = 0
},
o_left_top = {
x = 0,
y = 0
}
vendor = {}
}
local Public = {}
@ -55,10 +52,8 @@ function Public.reset_table()
x = 0,
y = 0
}
this.o_left_top = {
x = 0,
y = 0
}
this.train_upgrades = 0
this.energy_purchased = false
end
function Public.get_table()