1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-09 13:37:02 +02:00
loots and biteys
This commit is contained in:
MewMew 2020-04-05 02:23:03 +02:00
parent 52e341947a
commit 905bd3f3f5
9 changed files with 139 additions and 33 deletions

View File

@ -216,11 +216,7 @@ local function get_raffle_keys()
return raffle_keys
end
local function roll_item(value)
end
local function roll_item_stack(remaining_budget)
function Public.roll_item_stack(remaining_budget)
if remaining_budget <= 0 then return end
local raffle_keys = get_raffle_keys()
local item_name = false
@ -243,19 +239,46 @@ local function roll_item_stack(remaining_budget)
break
end
end
remaining_budget = remaining_budget - item_count * item_worth
return {name = item_name, count = item_count}
end
function roll_item_stacks(value, max_slots)
if not value then return end
local function roll_item_stacks(remaining_budget, max_slots)
local item_stack_set = {}
local item_stack_set_worth = 0
for i = 1, max_slots, 1 do
if remaining_budget <= 0 then break end
local item_stack = Public.roll_item_stack(remaining_budget)
item_stack_set[i] = item_stack
remaining_budget = remaining_budget - item_stack.count * item_worths[item_stack.name]
item_stack_set_worth = item_stack_set_worth + item_stack.count * item_worths[item_stack.name]
end
return item_stack_set, item_stack_set_worth
end
function Public.roll(budget, max_slots)
if not budget then return end
if not max_slots then return end
local remaining_budget = value
local final_stack_set
local final_stack_set_worth = 0
local item_stack = roll_item_stack(remaining_budget)
game.print(item_stack.name .. "_" .. item_stack.count)
end
for attempt = 1, 5, 1 do
local item_stack_set, item_stack_set_worth = roll_item_stacks(budget, max_slots)
if item_stack_set_worth > final_stack_set_worth or item_stack_set_worth == budget then
final_stack_set = item_stack_set
final_stack_set_worth = item_stack_set_worth
end
end
--[[
for k, item_stack in pairs(final_stack_set) do
game.print(item_stack.count .. "x " .. item_stack.name)
end
game.print(final_stack_set_worth)
]]
return final_stack_set
end
return Public

View File

@ -51,6 +51,14 @@ local function desert(surface, room)
end
if math_random(1, 256) == 1 then
Functions.common_loot_crate(surface, tile.position)
else
if math_random(1, 512) == 1 then
Functions.uncommon_loot_crate(surface, tile.position)
else
if math_random(1, 2048) == 1 then
Functions.rare_loot_crate(surface, tile.position)
end
end
end
end

View File

@ -60,6 +60,10 @@ local function dirtlands(surface, room)
end
if math_random(1, 256) == 1 then
Functions.common_loot_crate(surface, tile.position)
else
if math_random(1, 512) == 1 then
Functions.uncommon_loot_crate(surface, tile.position)
end
end
end

View File

@ -23,7 +23,14 @@ local function doom(surface, room)
end
if math_random(1, 16) == 1 then
surface.create_entity({name = Functions.roll_worm_name(), position = tile.position})
end
end
if math_random(1, 512) == 1 then
Functions.rare_loot_crate(surface, tile.position)
else
if math_random(1, 1024) == 1 then
Functions.epic_loot_crate(surface, tile.position)
end
end
if key % 10 == 0 and math_random(1, 2) == 1 then
surface.create_entity({name = Functions.roll_spawner_name(), position = tile.position})
end

View File

@ -21,12 +21,16 @@ local function glitch(surface, room)
if math_random(1, 3) == 1 then
surface.create_entity({name = ores[math_random(1, #ores)], position = tile.position, amount = math_random(250, 500) + global.dungeons.depth * 10})
end
if math_random(1, 16) == 1 then
if math_random(1, 12) == 1 then
surface.create_entity({name = Functions.roll_worm_name(), position = tile.position})
end
if math_random(1, 2048) == 1 then
surface.create_entity({name = "rock-huge", position = tile.position})
end
if math_random(1, 32) == 1 then
Functions.common_loot_crate(surface, tile.position)
else
if math_random(1, 32) == 1 then
Functions.uncommon_loot_crate(surface, tile.position)
end
end
end
if room.center then

View File

@ -57,7 +57,11 @@ local function grasslands(surface, room)
end
if math_random(1, 256) == 1 then
Functions.common_loot_crate(surface, tile.position)
end
else
if math_random(1, 512) == 1 then
Functions.uncommon_loot_crate(surface, tile.position)
end
end
end
if room.center then

View File

@ -38,6 +38,14 @@ local function red_desert(surface, room)
end
if math_random(1, 256) == 1 then
Functions.common_loot_crate(surface, tile.position)
else
if math_random(1, 512) == 1 then
Functions.uncommon_loot_crate(surface, tile.position)
else
if math_random(1, 2048) == 1 then
Functions.rare_loot_crate(surface, tile.position)
end
end
end
end

View File

@ -25,11 +25,40 @@ function Public.get_crude_oil_amount()
end
function Public.common_loot_crate(surface, position)
local item_stacks = LootRaffle.roll(global.dungeons.depth * 2 + 8, 16)
local item_stacks = LootRaffle.roll(global.dungeons.depth * 2 + math_random(8, 16), 16)
local container = surface.create_entity({name = "wooden-chest", position = position, force = "neutral"})
for _, item_stack in pairs(item_stacks) do
container.insert(item_stack)
end
end
function Public.uncommon_loot_crate(surface, position)
local item_stacks = LootRaffle.roll(global.dungeons.depth * 4 + math_random(32, 64), 16)
local container = surface.create_entity({name = "wooden-chest", position = position, force = "neutral"})
for _, item_stack in pairs(item_stacks) do
container.insert(item_stack)
end
end
function Public.rare_loot_crate(surface, position)
local item_stacks = LootRaffle.roll(global.dungeons.depth * 8 + math_random(128, 256), 24)
local container = surface.create_entity({name = "iron-chest", position = position, force = "neutral"})
for _, item_stack in pairs(item_stacks) do
container.insert(item_stack)
end
end
function Public.epic_loot_crate(surface, position)
local item_stacks = LootRaffle.roll(global.dungeons.depth * 16 + math_random(512, 1024), 24)
local container = surface.create_entity({name = "steel-chest", position = position, force = "neutral"})
for _, item_stack in pairs(item_stacks) do
container.insert(item_stack)
end
end
function Public.spawn_random_biter(surface, position)
local name = BiterRaffle.roll("mixed", global.dungeons.depth * 0.001)
local unit = surface.create_entity({name = name, position = position, force = "enemy"})
end
return Public

View File

@ -8,6 +8,7 @@ local MapInfo = require "modules.map_info"
local Room_generator = require "functions.room_generator"
local RPG = require "modules.rpg"
local BiterHealthBooster = require "modules.biter_health_booster"
local Functions = require "maps.dungeons.functions"
local Biomes = {}
Biomes.dirtlands = require "maps.dungeons.biome_dirtlands"
@ -40,8 +41,8 @@ local function get_biome(position)
local seed_addition = 100000
if Get_noise("dungeons", position, seed + seed_addition * 1) > 0.59 then return "glitch" end
if Get_noise("dungeons", position, seed + seed_addition * 2) > 0.48 then return "doom" end
if Get_noise("dungeons", position, seed + seed_addition * 3) > 0.20 then return "grasslands" end
if Get_noise("dungeons", position, seed + seed_addition * 2) > 0.50 then return "doom" end
if Get_noise("dungeons", position, seed + seed_addition * 3) > 0.24 then return "grasslands" end
if Get_noise("dungeons", position, seed + seed_addition * 4) > 0.35 then return "red_desert" end
if Get_noise("dungeons", position, seed + seed_addition * 5) > 0.25 then return "desert" end
if Get_noise("dungeons", position, seed + seed_addition * 6) > 0.75 then return "concrete" end
@ -52,7 +53,7 @@ end
local function draw_depth_gui()
for _, player in pairs(game.connected_players) do
if player.gui.top.dungeon_depth then player.gui.top.dungeon_depth.destroy() end
local element = player.gui.top.add({type = "sprite-button", name = "dungeon_depth", caption = "Depth: " .. global.dungeons.depth, tooltip = "Delve deep and face increased dangers.\nIncreases whenever a new room is discovered."})
local element = player.gui.top.add({type = "sprite-button", name = "dungeon_depth", caption = "Depth: " .. global.dungeons.depth, tooltip = "Increases whenever a new room is discovered."})
local style = element.style
style.minimal_height = 38
style.maximal_height = 38
@ -111,15 +112,15 @@ local function on_chunk_generated(event)
end
local function on_entity_spawned(event)
game.forces.enemy.evolution_factor = global.dungeons.depth * 0.0005
global.biter_health_boost = 1 + global.dungeons.depth * 0.0005
local spawner = event.spawner
local unit = event.entity
local unit_2 = spawner.surface.create_entity({name = unit.name, position = unit.position, force = "enemy"})
unit_2.ai_settings.allow_try_return_to_spawner = true
unit_2.ai_settings.allow_destroy_when_commands_fail = false
local spawner_tier = global.dungeons.spawner_tier
if not spawner_tier[spawner.unit_number] then
local tier = math_floor(global.dungeons.depth * 0.05 - math_random(1, 4))
local tier = math_floor(global.dungeons.depth * 0.015 - math_random(0, 15))
if tier < 1 then tier = 1 end
spawner_tier[spawner.unit_number] = tier
@ -136,14 +137,21 @@ local function on_entity_spawned(event)
}
end
local health_multiplier = (spawner_tier[spawner.unit_number] + 4) * 0.25
local health_multiplier = (spawner_tier[spawner.unit_number] + 4) * 0.20
if math_random(1, 32) == 1 then
BiterHealthBooster.add_boss_unit(unit, health_multiplier * 8, 0.25)
else
BiterHealthBooster.add_unit(unit, health_multiplier)
end
BiterHealthBooster.add_unit(unit_2, health_multiplier)
local r = math_floor(spawner_tier[spawner.unit_number] * 0.1) + 2
for _ = 1, math_random(1, r), 1 do
local unit_2 = spawner.surface.create_entity({name = unit.name, position = unit.position, force = "enemy"})
unit_2.ai_settings.allow_try_return_to_spawner = true
unit_2.ai_settings.allow_destroy_when_commands_fail = false
BiterHealthBooster.add_unit(unit_2, health_multiplier)
end
end
local function on_player_joined_game(event)
@ -158,7 +166,14 @@ end
local function on_player_mined_entity(event)
local entity = event.entity
if not entity.valid then return end
if not entity.valid then return end
if entity.type == "simple-entity" then
if math_random(1, 8) == 1 then Functions.spawn_random_biter(entity.surface, entity.position) return end
if math_random(1, 16) == 1 then Functions.common_loot_crate(entity.surface, entity.position) return end
if math_random(1, 64) == 1 then Functions.uncommon_loot_crate(entity.surface, entity.position) return end
if math_random(1, 256) == 1 then Functions.rare_loot_crate(entity.surface, entity.position) return end
if math_random(1, 1024) == 1 then Functions.epic_loot_crate(entity.surface, entity.position) return end
end
if entity.name ~= "rock-big" then return end
expand(entity.surface, entity.position)
end
@ -209,6 +224,10 @@ local function on_init()
game.forces.player.manual_mining_speed_modifier = 0
game.map_settings.enemy_evolution.destroy_factor = 0
game.map_settings.enemy_evolution.pollution_factor = 0
game.map_settings.enemy_evolution.time_factor = 0
global.dungeons = {}
global.dungeons.depth = 0
global.dungeons.spawner_tier = {}