1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00

Merge pull request #21 from M3wM3w/master

update from main
This commit is contained in:
hanakocz 2020-07-24 02:50:10 +02:00 committed by GitHub
commit 594c850839
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 735 additions and 178 deletions

View File

@ -614,13 +614,22 @@ end
local function on_player_cancelled_crafting(event) local function on_player_cancelled_crafting(event)
local player = game.players[event.player_index] local player = game.players[event.player_index]
local count = #event.items local crafting_queue_item_count = event.items.get_item_count()
local player_inventory_free_slot_count = player.get_main_inventory().count_empty_stacks()
local crafting_queue_canceled_item_slot_count = #event.items
if crafting_queue_canceled_item_slot_count > player_inventory_free_slot_count then
player.character.character_inventory_slots_bonus = crafting_queue_canceled_item_slot_count + #player.get_main_inventory()
for i = 1, crafting_queue_canceled_item_slot_count do
player.character.get_main_inventory().insert(event.items[i])
end
player.character.die('player')
if count > 40 then
Utils.action_warning( Utils.action_warning(
'{Crafting}', '{Crafting}',
player.name .. ' canceled their craft of item ' .. event.recipe.name .. ' of total count ' .. count .. '.' player.name .. ' canceled their craft of item ' .. event.recipe.name .. ' of total count ' .. crafting_queue_item_count .. ' in raw items (' .. crafting_queue_canceled_item_slot_count .. ' slots) and was punished.'
) )
if not this.cancel_crafting_history[player.index] then if not this.cancel_crafting_history[player.index] then
this.cancel_crafting_history[player.index] = {} this.cancel_crafting_history[player.index] = {}
end end
@ -632,7 +641,7 @@ local function on_player_cancelled_crafting(event)
local str = '[' .. t .. '] ' local str = '[' .. t .. '] '
str = str .. player.name .. ' canceled ' str = str .. player.name .. ' canceled '
str = str .. ' item ' .. event.recipe.name str = str .. ' item ' .. event.recipe.name
str = str .. ' count was a total of: ' .. count str = str .. ' count was a total of: ' .. crafting_queue_item_count
str = str .. ' at X:' str = str .. ' at X:'
str = str .. math.floor(player.position.x) str = str .. math.floor(player.position.x)
str = str .. ' Y:' str = str .. ' Y:'

View File

@ -8,6 +8,11 @@ map_info_main_caption=--Desert Oasis--
map_info_sub_caption=Survival in the dry sands. map_info_sub_caption=Survival in the dry sands.
map_info_text=This is a harsh world, the heat is unbearable and the sand is sharp like diamonds.\nMake sure to stay properly hydrated.\nDrink some water from a pond, or sip it out of a barrel to stay refreshed.\n\nWe shall not attempt to travel without a proper vehicle.\nMany building foundations are not possible to be set up outside of the oasis.\nRailways between them however should be possible.\n\nLuckily the ship's moisture meter module did survive the crash.\nIt may come in handy! map_info_text=This is a harsh world, the heat is unbearable and the sand is sharp like diamonds.\nMake sure to stay properly hydrated.\nDrink some water from a pond, or sip it out of a barrel to stay refreshed.\n\nWe shall not attempt to travel without a proper vehicle.\nMany building foundations are not possible to be set up outside of the oasis.\nRailways between them however should be possible.\n\nLuckily the ship's moisture meter module did survive the crash.\nIt may come in handy!
[expanse]
map_info_main_caption=-- E x p a n s e --
map_info_sub_caption=
map_info_text=The blue chests are hungry.\nFeed them and they will reward you with more land.\n\nThe friendly infini tree will provide you with all the wood you ever wanted.\nThe everlasting rock with be happy to provide resources for you.\n\nIf you find yourself stuck, put a reroll token, the small plane toy, in the chest to get a new offer.\nUnlocking chests may drop additional tokens.
[fish_defender] [fish_defender]
map_info_main_caption=--Fish Defender-- map_info_main_caption=--Fish Defender--
map_info_sub_caption= *blb blubby blub* map_info_sub_caption= *blb blubby blub*

View File

@ -2,20 +2,37 @@ local Price_raffle = require 'maps.expanse.price_raffle'
local Public = {} local Public = {}
local price_modifiers = { local price_modifiers = {
["unit-spawner"] = -128, ["unit-spawner"] = -256,
["unit"] = -16, ["unit"] = -16,
["turret"] = -128, ["turret"] = -128,
["tree"] = -8, ["tree"] = -8,
["simple-entity"] = -12, ["simple-entity"] = 2,
["cliff"] = -32, ["cliff"] = -128,
["water"] = -4, ["water"] = -5,
["water-green"] = -4, ["water-green"] = -5,
["deepwater"] = -4, ["deepwater"] = -5,
["deepwater-green"] = -4, ["deepwater-green"] = -5,
["water-mud"] = -6, ["water-mud"] = -6,
["water-shallow"] = -6, ["water-shallow"] = -6,
} }
local function reward_tokens(expanse, entity)
local chance = expanse.token_chance % 1
local count = math.floor(expanse.token_chance)
if chance > 0 then
chance = math.floor(chance * 1000)
if math.random(1, 1000) <= chance then
entity.surface.spill_item_stack(entity.position, {name = "small-plane", count = 1}, true, nil, false)
end
end
if count > 0 then
for _ = 1, count, 1 do
entity.surface.spill_item_stack(entity.position, {name = "small-plane", count = 1}, true, nil, false)
end
end
end
local function get_cell_value(expanse, left_top) local function get_cell_value(expanse, left_top)
local square_size = expanse.square_size local square_size = expanse.square_size
local value = square_size ^ 2 local value = square_size ^ 2
@ -31,19 +48,20 @@ local function get_cell_value(expanse, left_top)
value = value + price_modifiers[tile.name] value = value + price_modifiers[tile.name]
end end
end end
local distance = math.sqrt(left_top.x ^ 2 + left_top.y ^ 2)
local value = value * (distance * 0.005)
local ore_modifier = distance * 0.00025
if ore_modifier > 0.5 then ore_modifier = 0.5 end
for _, entity in pairs(entities) do for _, entity in pairs(entities) do
if price_modifiers[entity.type] then if price_modifiers[entity.type] then
value = value + price_modifiers[entity.type] value = value + price_modifiers[entity.type]
end end
end
local distance = math.sqrt(left_top.x ^ 2 + left_top.y ^ 2)
local value = value * (distance * expanse.price_distance_modifier)
local ore_modifier = distance * 0.00025
if ore_modifier > expanse.max_ore_price_modifier then ore_modifier = expanse.max_ore_price_modifier end
for _, entity in pairs(entities) do
if entity.type == "resource" then if entity.type == "resource" then
if entity.name == "crude-oil" then if entity.prototype.resource_category == "basic-fluid" then
value = value + (entity.amount * ore_modifier * 0.01) value = value + (entity.amount * ore_modifier * 0.01)
else else
value = value + (entity.amount * ore_modifier) value = value + (entity.amount * ore_modifier)
@ -96,7 +114,7 @@ end
function Public.expand(expanse, left_top) function Public.expand(expanse, left_top)
local source_surface = game.surfaces[expanse.source_surface] local source_surface = game.surfaces[expanse.source_surface]
if not source_surface then return end if not source_surface then return end
source_surface.request_to_generate_chunks({x = 0, y = 0}, 3) source_surface.request_to_generate_chunks(left_top, 3)
source_surface.force_generate_chunk_requests() source_surface.force_generate_chunk_requests()
local square_size = expanse.square_size local square_size = expanse.square_size
@ -134,12 +152,17 @@ function Public.expand(expanse, left_top)
if game.tick == 0 then if game.tick == 0 then
local a = math.floor(expanse.square_size * 0.5) local a = math.floor(expanse.square_size * 0.5)
surface.create_entity({name = "crude-oil", position = {a - 3, a}, amount = 300000}) for x = 1, 3, 1 do
local e = surface.create_entity({name = "offshore-pump", force = "player", position = {a + 1, a}}) for y = 1, 3, 1 do
e.destructible = false surface.set_tiles({{name = "water", position = {a + x, a + y - 2}}}, true)
e.minable = false end
end
surface.create_entity({name = "crude-oil", position = {a - 3, a}, amount = 1500000})
surface.create_entity({name = "rock-big", position = {a, a}}) surface.create_entity({name = "rock-big", position = {a, a}})
surface.create_entity({name = "tree-0" .. math.random(1,9), position = {a, a - 1}}) surface.create_entity({name = "tree-0" .. math.random(1,9), position = {a, a - 1}})
surface.spill_item_stack({a, a + 2}, {name = "small-plane", count = 1}, false, nil, false)
surface.spill_item_stack({a + 0.5, a + 2.5}, {name = "small-plane", count = 1}, false, nil, false)
surface.spill_item_stack({a - 0.5, a + 2.5}, {name = "small-plane", count = 1}, false, nil, false)
end end
end end
@ -176,6 +199,18 @@ function Public.set_container(expanse, entity)
local inventory = container.entity.get_inventory(defines.inventory.chest) local inventory = container.entity.get_inventory(defines.inventory.chest)
if not inventory.is_empty() then
local contents = inventory.get_contents()
if contents["small-plane"] then
local count_removed = inventory.remove({name = "small-plane", count = 1})
if count_removed > 0 then
init_container(expanse, entity)
container = expanse.containers[entity.unit_number]
game.print("The hungry chest has renewed it's offer! [gps=" .. math.floor(entity.position.x) .. "," .. math.floor(entity.position.y) .. ",expanse]")
end
end
end
for key, item_stack in pairs(container.price) do for key, item_stack in pairs(container.price) do
local count_removed = inventory.remove(item_stack) local count_removed = inventory.remove(item_stack)
container.price[key].count = container.price[key].count - count_removed container.price[key].count = container.price[key].count - count_removed
@ -186,15 +221,18 @@ function Public.set_container(expanse, entity)
if #container.price == 0 then if #container.price == 0 then
Public.expand(expanse, container.left_top) Public.expand(expanse, container.left_top)
local a = math.floor(expanse.square_size * 0.5)
local expansion_position = {x = expanse.containers[entity.unit_number].left_top.x + a, y = expanse.containers[entity.unit_number].left_top.y + a}
expanse.containers[entity.unit_number] = nil expanse.containers[entity.unit_number] = nil
if not inventory.is_empty() then if not inventory.is_empty() then
for name, count in pairs(inventory.get_contents()) do for name, count in pairs(inventory.get_contents()) do
entity.surface.spill_item_stack(entity.position, {name = name, count = count}, true, nil, false) entity.surface.spill_item_stack(entity.position, {name = name, count = count}, true, nil, false)
end end
end end
reward_tokens(expanse, entity)
entity.destructible = true entity.destructible = true
entity.die() entity.die()
return return expansion_position
end end
for slot = 1, 30, 1 do for slot = 1, 30, 1 do

View File

@ -3,8 +3,7 @@ require 'modules.satellite_score'
local Event = require 'utils.event' local Event = require 'utils.event'
local Functions = require 'maps.expanse.functions' local Functions = require 'maps.expanse.functions'
local Global = require 'utils.global' local Global = require 'utils.global'
local Map_info = require "modules.map_info"
local math_round = math.round
local expanse = {} local expanse = {}
Global.register( Global.register(
@ -14,10 +13,28 @@ Global.register(
end end
) )
local function set_nauvis()
local surface = game.surfaces[1]
local map_gen_settings = surface.map_gen_settings
map_gen_settings.autoplace_controls = {
["coal"] = {frequency = 10, size = 0.7, richness = 0.5,},
["stone"] = {frequency = 10, size = 0.7, richness = 0.5,},
["copper-ore"] = {frequency = 10, size = 0.7, richness = 0.75,},
["iron-ore"] = {frequency = 10, size = 0.7, richness = 1,},
["uranium-ore"] = {frequency = 10, size = 0.5, richness = 1,},
["crude-oil"] = {frequency = 25, size = 1.5, richness = 1.5,},
["trees"] = {frequency = 1.5, size = 1, richness = 1},
["enemy-base"] = {frequency = 10, size = 2, richness = 1},
}
map_gen_settings.starting_area = 0.25
surface.map_gen_settings = map_gen_settings
for chunk in surface.get_chunks() do
surface.delete_chunk({chunk.x, chunk.y})
end
end
local function reset() local function reset()
expanse.containers = {} expanse.containers = {}
expanse.source_surface = 1
expanse.square_size = 15
local map_gen_settings = { local map_gen_settings = {
["water"] = 0, ["water"] = 0,
@ -42,6 +59,8 @@ local function reset()
} }
game.create_surface("expanse", map_gen_settings) game.create_surface("expanse", map_gen_settings)
--set_nauvis()
local source_surface = game.surfaces[expanse.source_surface] local source_surface = game.surfaces[expanse.source_surface]
source_surface.request_to_generate_chunks({x = 0, y = 0}, 4) source_surface.request_to_generate_chunks({x = 0, y = 0}, 4)
source_surface.force_generate_chunk_requests() source_surface.force_generate_chunk_requests()
@ -87,22 +106,26 @@ local function on_chunk_generated(event)
event.surface.set_tiles(tiles, true) event.surface.set_tiles(tiles, true)
end end
local function on_gui_opened(event) local function container_opened(event)
local entity = event.entity local entity = event.entity
if not entity then return end if not entity then return end
if not entity.valid then return end if not entity.valid then return end
if not entity.unit_number then return end if not entity.unit_number then return end
if entity.force.index ~= 3 then return end if entity.force.index ~= 3 then return end
Functions.set_container(expanse, entity) local expansion_position = Functions.set_container(expanse, entity)
if expansion_position then
local player = game.players[event.player_index]
local colored_player_name = table.concat({"[color=", player.color.r * 0.6 + 0.35, ",", player.color.g * 0.6 + 0.35, ",", player.color.b * 0.6 + 0.35, "]", player.name, "[/color]"})
game.print(colored_player_name .. " unlocked new grounds! [gps=" .. math.floor(expansion_position.x) .. "," .. math.floor(expansion_position.y) .. ",expanse]")
end
end
local function on_gui_opened(event)
container_opened(event)
end end
local function on_gui_closed(event) local function on_gui_closed(event)
local entity = event.entity container_opened(event)
if not entity then return end
if not entity.valid then return end
if not entity.unit_number then return end
if entity.force.index ~= 3 then return end
Functions.set_container(expanse, entity)
end end
local ores = {"iron-ore", "iron-ore", "copper-ore", "coal"} local ores = {"iron-ore", "iron-ore", "copper-ore", "coal"}
@ -111,7 +134,8 @@ local function infini_rock(entity)
local a = math.floor(expanse.square_size * 0.5) local a = math.floor(expanse.square_size * 0.5)
if entity.position.x == a and entity.position.y == a then if entity.position.x == a and entity.position.y == a then
entity.surface.create_entity({name = "rock-big", position = {a, a}}) entity.surface.create_entity({name = "rock-big", position = {a, a}})
entity.surface.spill_item_stack(entity.position, {name = ores[math.random(1,4)], count = math.random(125, 250)}, true, nil, true) entity.surface.spill_item_stack(entity.position, {name = ores[math.random(1,4)], count = math.random(100, 200)}, true, nil, true)
entity.surface.spill_item_stack(entity.position, {name = "stone", count = math.random(25, 50)}, true, nil, true)
end end
end end
@ -138,15 +162,47 @@ local function on_player_joined_game(event)
end end
end end
local function on_player_left_game(event)
local player = game.players[event.player_index]
if not player.character then return end
if not player.character.valid then return end
local inventory = player.get_main_inventory()
if not inventory then return end
local removed_count = inventory.remove({name = "small-plane", count = 999})
if removed_count > 0 then
for _ = 1, removed_count, 1 do
player.surface.spill_item_stack(player.position, {name = "small-plane", count = 1}, false, nil, false)
end
game.print(player.name .. " dropped their tokens! [gps=" .. math.floor(player.position.x) .. "," .. math.floor(player.position.y) .. "," .. player.surface.name .. "]")
end
end
local function on_init(event) local function on_init(event)
local T = Map_info.Pop_info()
T.localised_category = "expanse"
T.main_caption_color = {r = 170, g = 170, b = 0}
T.sub_caption_color = {r = 120, g = 120, b = 0}
if not expanse.source_surface then expanse.source_surface = "nauvis" end
if not expanse.token_chance then expanse.token_chance = 0.33 end
if not expanse.price_distance_modifier then expanse.price_distance_modifier = 0.004 end
if not expanse.max_ore_price_modifier then expanse.max_ore_price_modifier = 0.33 end
if not expanse.square_size then expanse.square_size = 16 end
--[[
expanse.token_chance = 2.5
expanse.price_distance_modifier = 0.001
expanse.max_ore_price_modifier = 0.01
]]
reset() reset()
end end
Event.on_init(on_init) Event.on_init(on_init)
Event.add(defines.events.on_gui_opened, on_gui_opened)
Event.add(defines.events.on_gui_closed, on_gui_closed)
Event.add(defines.events.on_chunk_generated, on_chunk_generated) Event.add(defines.events.on_chunk_generated, on_chunk_generated)
Event.add(defines.events.on_entity_died, infini_resource) Event.add(defines.events.on_entity_died, infini_resource)
Event.add(defines.events.on_robot_mined_entity, infini_resource) Event.add(defines.events.on_gui_closed, on_gui_closed)
Event.add(defines.events.on_player_mined_entity, infini_resource) Event.add(defines.events.on_gui_opened, on_gui_opened)
Event.add(defines.events.on_player_joined_game, on_player_joined_game) Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_player_left_game, on_player_left_game)
Event.add(defines.events.on_player_mined_entity, infini_resource)
Event.add(defines.events.on_robot_mined_entity, infini_resource)

View File

@ -227,7 +227,7 @@ function Public.roll_item_stack(remaining_budget, blacklist)
if not blacklist[item_name] and item_worth <= remaining_budget then break end if not blacklist[item_name] and item_worth <= remaining_budget then break end
end end
local stack_size = game.item_prototypes[item_name].stack_size * 16 local stack_size = game.item_prototypes[item_name].stack_size * 32
local item_count = 1 local item_count = 1

View File

@ -78,6 +78,7 @@ local function distance(player)
rpg_extra.reward_new_players = bonus_xp_on_join * rpg_extra.breached_walls rpg_extra.reward_new_players = bonus_xp_on_join * rpg_extra.breached_walls
WPT.set().breached_wall = breached_wall + 1 WPT.set().breached_wall = breached_wall + 1
WPT.set().placed_trains_in_zone.placed = 0 WPT.set().placed_trains_in_zone.placed = 0
WPT.set().placed_trains_in_zone.randomized = false
WPT.set().placed_trains_in_zone.positions = {} WPT.set().placed_trains_in_zone.positions = {}
raise_event(Balance.events.breached_wall, {}) raise_event(Balance.events.breached_wall, {})

View File

@ -233,8 +233,9 @@ function Public.reset_map()
RPG.set_surface_name('mountain_fortress_v3') RPG.set_surface_name('mountain_fortress_v3')
RPG.enable_health_and_mana_bars(true) RPG.enable_health_and_mana_bars(true)
RPG.enable_wave_defense(true) RPG.enable_wave_defense(true)
RPG.enable_mana(false) RPG.enable_mana(true)
RPG.enable_flame_boots(false) RPG.enable_flame_boots(true)
RPG.personal_tax_rate(1)
disable_tech() disable_tech()

View File

@ -87,14 +87,126 @@ local resource_loot = {
recipe = 'stone-wall', recipe = 'stone-wall',
output = {item = 'stone-wall', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 512} output = {item = 'stone-wall', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 512}
}, },
weight = 2 weight = 10
}, },
{ {
stack = { stack = {
recipe = 'iron-gear-wheel', recipe = 'iron-gear-wheel',
output = {item = 'iron-gear-wheel', min_rate = 1 / 4 / 60, distance_factor = 1 / 6 / 60 / 512} output = {item = 'iron-gear-wheel', min_rate = 1 / 4 / 60, distance_factor = 1 / 6 / 60 / 512}
}, },
weight = 12
},
{
stack = {
recipe = 'inserter',
output = {item = 'inserter', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 512}
},
weight = 12
},
{
stack = {
recipe = 'transport-belt',
output = {item = 'transport-belt', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 512}
},
weight = 8
},
{
stack = {
recipe = 'underground-belt',
output = {item = 'underground-belt', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 512}
},
weight = 8
},
{
stack = {
recipe = 'small-electric-pole',
output = {item = 'small-electric-pole', min_rate = 1 / 4 / 60, distance_factor = 1 / 6 / 60 / 512}
},
weight = 8
},
{
stack = {
recipe = 'fast-transport-belt',
output = {item = 'fast-transport-belt', min_rate = 1 / 4 / 60, distance_factor = 1 / 12 / 60 / 512}
},
weight = 5
},
{
stack = {
recipe = 'fast-underground-belt',
output = {item = 'fast-underground-belt', min_rate = 1 / 4 / 60, distance_factor = 1 / 12 / 60 / 512}
},
weight = 5
},
{
stack = {
recipe = 'solar-panel',
output = {item = 'solar-panel', min_rate = 1 / 4 / 60, distance_factor = 1 / 12 / 60 / 512}
},
weight = 3 weight = 3
},
{
stack = {
recipe = 'productivity-module',
output = {item = 'productivity-module', min_rate = 1 / 4 / 60, distance_factor = 1 / 20 / 60 / 512}
},
weight = 0.9
},
{
stack = {
recipe = 'effectivity-module',
output = {item = 'effectivity-module', min_rate = 1 / 4 / 60, distance_factor = 1 / 20 / 60 / 512}
},
weight = 0.9
},
{
stack = {
recipe = 'speed-module',
output = {item = 'speed-module', min_rate = 1 / 4 / 60, distance_factor = 1 / 20 / 60 / 512}
},
weight = 0.8
},
{
stack = {
recipe = 'productivity-module-2',
output = {item = 'productivity-module-2', min_rate = 1 / 4 / 60, distance_factor = 1 / 20 / 60 / 512}
},
weight = 0.5
},
{
stack = {
recipe = 'effectivity-module-2',
output = {item = 'effectivity-module-2', min_rate = 1 / 4 / 60, distance_factor = 1 / 20 / 60 / 512}
},
weight = 0.5
},
{
stack = {
recipe = 'speed-module-2',
output = {item = 'speed-module-2', min_rate = 1 / 4 / 60, distance_factor = 1 / 20 / 60 / 512}
},
weight = 0.5
},
{
stack = {
recipe = 'productivity-module-3',
output = {item = 'productivity-module-3', min_rate = 1 / 4 / 60, distance_factor = 1 / 30 / 60 / 512}
},
weight = 0.25
},
{
stack = {
recipe = 'effectivity-module-3',
output = {item = 'effectivity-module-3', min_rate = 1 / 4 / 60, distance_factor = 1 / 30 / 60 / 512}
},
weight = 0.25
},
{
stack = {
recipe = 'speed-module-3',
output = {item = 'speed-module-3', min_rate = 1 / 4 / 60, distance_factor = 1 / 30 / 60 / 512}
},
weight = 0.10
} }
} }
@ -116,7 +228,7 @@ local furnace_loot = {
{ {
stack = { stack = {
furance_item = 'steel-plate', furance_item = 'steel-plate',
output = {item = 'steel-plate', min_rate = 0.5 / 8 / 60, distance_factor = 1 / 25 / 60 / 512} output = {item = 'steel-plate', min_rate = 0.5 / 8 / 60, distance_factor = 1 / 15 / 60 / 512}
}, },
weight = 1 weight = 1
} }

View File

@ -89,7 +89,8 @@ function Public.reset_table()
this.placed_trains_in_zone = { this.placed_trains_in_zone = {
placed = 0, placed = 0,
positions = {}, positions = {},
limit = 5 limit = 5,
randomized = false
} }
end end

View File

@ -114,6 +114,12 @@ local function place_wagon(data)
local placed_trains_in_zone = WPT.get('placed_trains_in_zone') local placed_trains_in_zone = WPT.get('placed_trains_in_zone')
if not placed_trains_in_zone.randomized then
placed_trains_in_zone.limit = math.random(1, 5)
placed_trains_in_zone.randomized = true
placed_trains_in_zone = WPT.get('placed_trains_in_zone')
end
if placed_trains_in_zone.placed >= placed_trains_in_zone.limit then if placed_trains_in_zone.placed >= placed_trains_in_zone.limit then
return return
end end
@ -1416,7 +1422,7 @@ local function process_level_2_position(x, y, data)
--Main Rock Terrain --Main Rock Terrain
local no_rocks_2 = get_noise('no_rocks_2', p, seed + 75000) local no_rocks_2 = get_noise('no_rocks_2', p, seed + 75000)
if no_rocks_2 > 0.80 or no_rocks_2 < -0.80 then if no_rocks_2 > 0.80 or no_rocks_2 < -0.80 then
tiles[#tiles + 1] = {name = 'dirt-' .. math.floor(no_rocks_2 * 8) % 2 + 5, position = p} tiles[#tiles + 1] = {name = 'grass-' .. math.random(1, 4), position = p}
if math.random(1, 512) == 1 then if math.random(1, 512) == 1 then
treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'}
end end
@ -1426,7 +1432,7 @@ local function process_level_2_position(x, y, data)
if math.random(1, 2048) == 1 then if math.random(1, 2048) == 1 then
treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'}
end end
tiles[#tiles + 1] = {name = 'dirt-7', position = p} tiles[#tiles + 1] = {name = 'grass-' .. math.random(1, 4), position = p}
if math.random(1, 100) > 25 then if math.random(1, 100) > 25 then
entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p}
end end
@ -1508,9 +1514,9 @@ local function process_level_1_position(x, y, data)
--Resource Spots --Resource Spots
if smol_areas < -0.72 then if smol_areas < -0.72 then
if math.random(1, 8) == 1 then -- if math.random(1, 8) == 1 then
Generate_resources(buildings, p, Public.level_depth) Generate_resources(buildings, p, Public.level_depth)
end -- end
end end
local no_rocks = get_noise('no_rocks', p, seed + 25000) local no_rocks = get_noise('no_rocks', p, seed + 25000)
@ -1565,7 +1571,9 @@ local function process_level_1_position(x, y, data)
end end
Public.levels = { Public.levels = {
process_level_4_position,
process_level_1_position, process_level_1_position,
process_level_6_position,
process_level_2_position, process_level_2_position,
process_level_3_position, process_level_3_position,
process_level_4_position, process_level_4_position,
@ -1588,11 +1596,12 @@ local function is_out_of_map(p)
end end
local function process_bits(x, y, data) local function process_bits(x, y, data)
local levels = Public.levels
local left_top_y = data.area.left_top.y local left_top_y = data.area.left_top.y
local index = math.floor((math.abs(left_top_y / Public.level_depth)) % 13) + 1 local index = math.floor((math.abs(left_top_y / Public.level_depth)) % 15) + 1
local process_level = Public.levels[index] local process_level = levels[index]
if not process_level then if not process_level then
process_level = Public.levels[#Public.levels] process_level = levels[#levels]
end end
process_level(x, y, data) process_level(x, y, data)

View File

@ -47,7 +47,9 @@ local rpg_extra = {
enable_health_and_mana_bars = false, enable_health_and_mana_bars = false,
enable_mana = false, enable_mana = false,
enable_wave_defense = false, enable_wave_defense = false,
enable_flame_boots = false enable_flame_boots = false,
mana_per_tick = 0.1,
force_mana_per_tick = false
} }
local rpg_frame_icons = { local rpg_frame_icons = {
'entity/small-worm-turret', 'entity/small-worm-turret',
@ -111,7 +113,7 @@ local projectile_types = {
['petroleum-gas-barrel'] = {name = 'flamethrower-fire-stream', count = 4, max_range = 24, tick_speed = 1}, ['petroleum-gas-barrel'] = {name = 'flamethrower-fire-stream', count = 4, max_range = 24, tick_speed = 1},
['light-oil-barrel'] = {name = 'flamethrower-fire-stream', count = 4, max_range = 24, tick_speed = 1}, ['light-oil-barrel'] = {name = 'flamethrower-fire-stream', count = 4, max_range = 24, tick_speed = 1},
['heavy-oil-barrel'] = {name = 'flamethrower-fire-stream', count = 4, max_range = 24, tick_speed = 1}, ['heavy-oil-barrel'] = {name = 'flamethrower-fire-stream', count = 4, max_range = 24, tick_speed = 1},
['sulfuric-acid-barrel'] = { ['acid-stream-spitter-big'] = {
name = 'acid-stream-spitter-big', name = 'acid-stream-spitter-big',
count = 3, count = 3,
max_range = 16, max_range = 16,
@ -119,7 +121,7 @@ local projectile_types = {
force = 'enemy' force = 'enemy'
}, },
['lubricant-barrel'] = {name = 'acid-stream-spitter-big', count = 3, max_range = 16, tick_speed = 1}, ['lubricant-barrel'] = {name = 'acid-stream-spitter-big', count = 3, max_range = 16, tick_speed = 1},
['railgun-dart'] = {name = 'railgun-beam', count = 5, max_range = 40, tick_speed = 5}, ['railgun-beam'] = {name = 'railgun-beam', count = 5, max_range = 40, tick_speed = 5},
['shotgun-shell'] = {name = 'shotgun-pellet', count = 16, max_range = 24, tick_speed = 1}, ['shotgun-shell'] = {name = 'shotgun-pellet', count = 16, max_range = 24, tick_speed = 1},
['piercing-shotgun-shell'] = {name = 'piercing-shotgun-pellet', count = 16, max_range = 24, tick_speed = 1}, ['piercing-shotgun-shell'] = {name = 'piercing-shotgun-pellet', count = 16, max_range = 24, tick_speed = 1},
['firearm-magazine'] = {name = 'shotgun-pellet', count = 16, max_range = 24, tick_speed = 1}, ['firearm-magazine'] = {name = 'shotgun-pellet', count = 16, max_range = 24, tick_speed = 1},
@ -164,55 +166,243 @@ local conjure_items = {
[1] = { [1] = {
name = 'Stone Wall', name = 'Stone Wall',
obj_to_create = 'stone-wall', obj_to_create = 'stone-wall',
level = '10', level = 10,
target = true,
type = 'item', type = 'item',
mana_cost = 40, mana_cost = 35,
tick = 60, tick = 160,
enabled = true enabled = true
}, },
[2] = { [2] = {
name = 'Steel Chest', name = 'Wooden Chest',
obj_to_create = 'steel-chest', obj_to_create = 'wooden-chest',
level = '10', level = 2,
target = true,
type = 'item', type = 'item',
mana_cost = 40, mana_cost = 30,
tick = 60, tick = 160,
enabled = true enabled = true
}, },
[3] = { [3] = {
name = 'Transport Belt', name = 'Iron Chest',
obj_to_create = 'transport-belt', obj_to_create = 'iron-chest',
level = '10', level = 10,
target = true,
type = 'item', type = 'item',
mana_cost = 40, mana_cost = 40,
tick = 60, tick = 260,
enabled = true enabled = true
}, },
[4] = { [4] = {
name = 'Sandy Rock', name = 'Steel Chest',
obj_to_create = 'sand-rock-big', obj_to_create = 'steel-chest',
level = '10', level = 15,
type = 'entity', target = true,
mana_cost = 40, type = 'item',
tick = 120, mana_cost = 50,
tick = 360,
enabled = true enabled = true
}, },
[5] = { [5] = {
name = 'Smol Biter', name = 'Transport Belt',
obj_to_create = 'small-biter', obj_to_create = 'transport-belt',
level = '10', level = 3,
type = 'entity', target = true,
type = 'item',
mana_cost = 40, mana_cost = 40,
tick = 120, tick = 160,
enabled = true enabled = true
}, },
[6] = { [6] = {
name = 'Aoe Grenade', name = 'Fast Transport Belt',
obj_to_create = 'grenade', obj_to_create = 'fast-transport-belt',
level = '10', level = 20,
type = 'entity', target = true,
type = 'item',
mana_cost = 50,
tick = 260,
enabled = true
},
[7] = {
name = 'Express Transport Belt',
obj_to_create = 'express-transport-belt',
level = 60,
target = true,
type = 'item',
mana_cost = 60,
tick = 360,
enabled = true
},
[8] = {
name = 'Underground Belt',
obj_to_create = 'underground-belt',
level = 3,
target = true,
type = 'item',
mana_cost = 40, mana_cost = 40,
tick = 120, tick = 160,
enabled = true
},
[9] = {
name = 'Fast Underground Belt',
obj_to_create = 'fast-underground-belt',
level = 20,
target = true,
type = 'item',
mana_cost = 50,
tick = 260,
enabled = true
},
[10] = {
name = 'Express Underground Belt',
obj_to_create = 'express-underground-belt',
level = 60,
target = true,
type = 'item',
mana_cost = 60,
tick = 360,
enabled = true
},
[11] = {
name = 'Sandy Rock',
obj_to_create = 'sand-rock-big',
level = 80,
target = true,
type = 'entity',
mana_cost = 80,
tick = 420,
enabled = true
},
[12] = {
name = 'Smol Biter',
obj_to_create = 'small-biter',
level = 50,
target = true,
biter = true,
type = 'entity',
mana_cost = 55,
tick = 220,
enabled = true
},
[13] = {
name = 'Smol Spitter',
obj_to_create = 'small-spitter',
level = 50,
target = true,
biter = true,
type = 'entity',
mana_cost = 55,
tick = 220,
enabled = true
},
[14] = {
name = 'Medium Biter',
obj_to_create = 'medium-biter',
level = 70,
target = true,
biter = true,
type = 'entity',
mana_cost = 77,
tick = 420,
enabled = true
},
[15] = {
name = 'Medium Spitter',
obj_to_create = 'medium-spitter',
level = 70,
target = true,
type = 'entity',
mana_cost = 77,
tick = 420,
enabled = true
},
[16] = {
name = 'Bitter Spawner',
obj_to_create = 'biter-spawner',
level = 100,
target = true,
biter = true,
type = 'entity',
mana_cost = 300,
tick = 1420,
enabled = true
},
[17] = {
name = 'Spitter Spawner',
obj_to_create = 'spitter-spawner',
level = 100,
target = true,
biter = true,
type = 'entity',
mana_cost = 300,
tick = 1420,
enabled = true
},
[18] = {
name = 'AOE Grenade',
obj_to_create = 'grenade',
target = true,
amount = 1,
damage = true,
force = 'player',
level = 30,
type = 'special',
mana_cost = 60,
tick = 420,
enabled = true
},
[19] = {
name = 'Big AOE Grenade',
obj_to_create = 'cluster-grenade',
target = true,
amount = 2,
damage = true,
force = 'player',
level = 50,
type = 'special',
mana_cost = 80,
tick = 620,
enabled = true
},
[20] = {
name = 'Pointy Rocket',
obj_to_create = 'rocket',
range = 240,
target = true,
amount = 4,
damage = true,
force = 'enemy',
level = 40,
type = 'special',
mana_cost = 60,
tick = 420,
enabled = true
},
[21] = {
name = 'Bitter Spew',
obj_to_create = 'acid-stream-spitter-big',
target = true,
amount = 1,
range = 0,
force = 'player',
level = 70,
type = 'special',
mana_cost = 90,
tick = 520,
enabled = true
},
[22] = {
name = 'Fire my lazors!!',
obj_to_create = 'railgun-beam',
target = false,
amount = 3,
damage = true,
range = 240,
force = 'player',
level = 50,
type = 'special',
mana_cost = 66,
tick = 320,
enabled = true enabled = true
} }
} }
@ -356,7 +546,13 @@ local function get_heal_modifier(player)
end end
local function get_mana_modifier(player) local function get_mana_modifier(player)
return (rpg_t[player.index].magicka - 10) * 0.00505 if rpg_t[player.index].level <= 40 then
return (rpg_t[player.index].magicka - 10) * 0.02000
elseif rpg_t[player.index].level <= 80 then
return (rpg_t[player.index].magicka - 10) * 0.01800
else
return (rpg_t[player.index].magicka - 10) * 0.01400
end
end end
local function get_life_on_hit(player) local function get_life_on_hit(player)
@ -413,7 +609,7 @@ local function update_player_stats(player)
player_modifiers[player.index].character_loot_pickup_distance_bonus['rpg'] = math.round(v * 0.22, 3) player_modifiers[player.index].character_loot_pickup_distance_bonus['rpg'] = math.round(v * 0.22, 3)
player_modifiers[player.index].character_item_pickup_distance_bonus['rpg'] = math.round(v * 0.25, 3) player_modifiers[player.index].character_item_pickup_distance_bonus['rpg'] = math.round(v * 0.25, 3)
player_modifiers[player.index].character_resource_reach_distance_bonus['rpg'] = math.round(v * 0.15, 3) player_modifiers[player.index].character_resource_reach_distance_bonus['rpg'] = math.round(v * 0.15, 3)
rpg_t[player.index].mana_max = math.round(rpg_t[player.index].mana_max + math.round(v * 1, 3)) rpg_t[player.index].mana_max = math.round(rpg_t[player.index].mana_max + math.round(v * 0.9, 3))
local dexterity = rpg_t[player.index].dexterity - 10 local dexterity = rpg_t[player.index].dexterity - 10
player_modifiers[player.index].character_running_speed_modifier['rpg'] = math.round(dexterity * 0.0015, 3) player_modifiers[player.index].character_running_speed_modifier['rpg'] = math.round(dexterity * 0.0015, 3)
@ -554,7 +750,7 @@ local function extra_settings(player)
local setting_grid = scroll_pane.add({type = 'table', column_count = 2}) local setting_grid = scroll_pane.add({type = 'table', column_count = 2})
local health_bar_gui_input = nil local health_bar_gui_input
if rpg_extra.enable_health_and_mana_bars then if rpg_extra.enable_health_and_mana_bars then
local health_bar_label = local health_bar_label =
setting_grid.add( setting_grid.add(
@ -575,13 +771,16 @@ local function extra_settings(player)
input_style.vertical_align = 'center' input_style.vertical_align = 'center'
health_bar_gui_input = create_input_element(health_bar_input, 'boolean', rpg_t[player.index].show_bars) health_bar_gui_input = create_input_element(health_bar_input, 'boolean', rpg_t[player.index].show_bars)
health_bar_gui_input.tooltip = 'Checked = true\nUnchecked = false' health_bar_gui_input.tooltip = 'Checked = true\nUnchecked = false'
if not rpg_extra.enable_mana then
health_bar_label.caption = 'Show health bar?'
end
end end
local reset_label = local reset_label =
setting_grid.add( setting_grid.add(
{ {
type = 'label', type = 'label',
caption = 'Reset your skillpoints.', caption = 'Reset your skillpoints?',
tooltip = '' tooltip = ''
} }
) )
@ -615,7 +814,7 @@ local function extra_settings(player)
setting_grid.add( setting_grid.add(
{ {
type = 'label', type = 'label',
caption = 'Enable item reach distance bonus.', caption = 'Enable item reach distance bonus?',
tooltip = 'Don´t feeling like picking up others people loot?\nYou can toggle it here.' tooltip = 'Don´t feeling like picking up others people loot?\nYou can toggle it here.'
} }
) )
@ -645,7 +844,7 @@ local function extra_settings(player)
setting_grid.add( setting_grid.add(
{ {
type = 'label', type = 'label',
caption = 'Enable movement speed bonus.', caption = 'Enable movement speed bonus?',
tooltip = 'Don´t feeling like running like the flash?\nYou can toggle it here.' tooltip = 'Don´t feeling like running like the flash?\nYou can toggle it here.'
} }
) )
@ -671,16 +870,16 @@ local function extra_settings(player)
local movement_speed_gui_input = create_input_element(movement_speed_input, 'boolean', speed_mod) local movement_speed_gui_input = create_input_element(movement_speed_input, 'boolean', speed_mod)
movement_speed_gui_input.tooltip = 'Checked = true\nUnchecked = false' movement_speed_gui_input.tooltip = 'Checked = true\nUnchecked = false'
local enable_entity_gui_input = nil local enable_entity_gui_input
local conjure_gui_input = nil local conjure_gui_input
local flame_boots_gui_input = nil local flame_boots_gui_input
if rpg_extra.enable_flame_boots then if rpg_extra.enable_flame_boots then
local flame_boots_label = local flame_boots_label =
setting_grid.add( setting_grid.add(
{ {
type = 'label', type = 'label',
caption = 'Enable flame boots.', caption = 'Enable flame boots?',
tooltip = 'When the bullets simply don´t bite.' tooltip = 'When the bullets simply don´t bite.'
} }
) )
@ -716,8 +915,8 @@ local function extra_settings(player)
setting_grid.add( setting_grid.add(
{ {
type = 'label', type = 'label',
caption = 'Enable spawning entities with raw-fish.', caption = 'Enable spawning with raw-fish?',
tooltip = 'When simply constructing items is not enough.' tooltip = 'When simply constructing items is not enough.\nNOTE! Use Raw-fish to cast spells.'
} }
) )
@ -769,11 +968,19 @@ local function extra_settings(player)
if entity.type == 'item' then if entity.type == 'item' then
conjure_label.tooltip = conjure_label.tooltip =
conjure_label.tooltip .. conjure_label.tooltip ..
'[item=' .. entity.obj_to_create .. '] requires ' .. entity.mana_cost .. ' mana to cast.\n' '[item=' ..
entity.obj_to_create ..
'] requires ' .. entity.mana_cost .. ' mana to cast. Level: ' .. entity.level .. '\n'
elseif entity.type == 'entity' then elseif entity.type == 'entity' then
conjure_label.tooltip = conjure_label.tooltip =
conjure_label.tooltip .. conjure_label.tooltip ..
'[entity=' .. entity.obj_to_create .. '] requires ' .. entity.mana_cost .. ' mana to cast.\n' '[entity=' ..
entity.obj_to_create ..
'] requires ' .. entity.mana_cost .. ' mana to cast. Level: ' .. entity.level .. '\n'
elseif entity.type == 'special' then
conjure_label.tooltip =
conjure_label.tooltip ..
entity.name .. ' requires ' .. entity.mana_cost .. ' mana to cast. Level: ' .. entity.level .. '\n'
end end
end end
end end
@ -784,7 +991,7 @@ local function extra_settings(player)
movement_speed_gui_input = movement_speed_gui_input movement_speed_gui_input = movement_speed_gui_input
} }
if rpg_extra.health_bar_gui_input then if rpg_extra.enable_health_and_mana_bars then
data.health_bar_gui_input = health_bar_gui_input data.health_bar_gui_input = health_bar_gui_input
end end
@ -1057,7 +1264,7 @@ local function draw_gui(player, forced)
add_gui_description(tt, 'MANA\nBONUS', w1) add_gui_description(tt, 'MANA\nBONUS', w1)
local magic = rpg_t[player.index].magicka - 10 local magic = rpg_t[player.index].magicka - 10
local v = magic * 0.22 local v = magic * 0.22
value = '+ ' .. math.round(math.round(v * 1, 3)) value = '+ ' .. (math.floor(get_mana_modifier(player) * 10) / 10)
e = add_gui_stat(tt, value, w2) e = add_gui_stat(tt, value, w2)
e.tooltip = 'Mana regen bonus: ' .. (math.floor(get_mana_modifier(player) * 10) / 10) e.tooltip = 'Mana regen bonus: ' .. (math.floor(get_mana_modifier(player) * 10) / 10)
end end
@ -1370,10 +1577,10 @@ local function on_entity_died(event)
local amount = rpg_xp_yield[event.entity.name] local amount = rpg_xp_yield[event.entity.name]
amount = amount / 5 amount = amount / 5
if global.biter_health_boost then if global.biter_health_boost then
local health_pool = global.biter_health_boost_units[event.entity.unit_number] local health_pool = global.biter_health_boost_units[event.entity.unit_number]
if health_pool then if health_pool then
amount = amount * (1 / health_pool[2]) amount = amount * (1 / health_pool[2])
end end
end end
if rpg_extra.turret_kills_to_global_pool then if rpg_extra.turret_kills_to_global_pool then
@ -1457,7 +1664,7 @@ local function regen_health_player(players)
end end
end end
if player.gui.left[main_frame_name] then if player.gui.left[main_frame_name] then
draw_gui(player, true) draw_gui(player)
end end
::continue:: ::continue::
@ -1471,7 +1678,9 @@ local function regen_health_player(players)
player.character.prototype.max_health + player.character_health_bonus + player.character.prototype.max_health + player.character_health_bonus +
player.force.character_health_bonus player.force.character_health_bonus
) )
if not rendering.is_valid(rpg_t[player.index].health_bar) then if not rpg_t[player.index].health_bar then
rpg_t[player.index].health_bar = create_healthbar(player, 0.5)
elseif not rendering.is_valid(rpg_t[player.index].health_bar) then
rpg_t[player.index].health_bar = create_healthbar(player, 0.5) rpg_t[player.index].health_bar = create_healthbar(player, 0.5)
end end
set_bar(player.character.health, max_life, rpg_t[player.index].health_bar) set_bar(player.character.health, max_life, rpg_t[player.index].health_bar)
@ -1486,33 +1695,42 @@ local function regen_mana_player(players)
for i = 1, #players do for i = 1, #players do
local player = players[i] local player = players[i]
local mana_per_tick = get_mana_modifier(player) local mana_per_tick = get_mana_modifier(player)
if mana_per_tick <= 0 then if mana_per_tick <= 0.1 then
mana_per_tick = (math.floor(0.5 * 10) / 10) mana_per_tick = rpg_extra.mana_per_tick
end end
mana_per_tick = (math.floor(mana_per_tick * 10) / 10)
if rpg_extra.force_mana_per_tick then
mana_per_tick = 1
end
if player and player.valid then if player and player.valid then
if player.character and player.character.valid then if player.character and player.character.valid then
if rpg_t[player.index].mana >= rpg_t[player.index].mana_max then if rpg_t[player.index].mana >= rpg_t[player.index].mana_max then
return goto continue
end end
rpg_t[player.index].mana = rpg_t[player.index].mana + mana_per_tick rpg_t[player.index].mana = rpg_t[player.index].mana + mana_per_tick
rpg_t[player.index].mana = (math.floor(rpg_t[player.index].mana * 10) / 10)
if rpg_t[player.index].mana >= rpg_t[player.index].mana_max then if rpg_t[player.index].mana >= rpg_t[player.index].mana_max then
rpg_t[player.index].mana = rpg_t[player.index].mana_max rpg_t[player.index].mana = rpg_t[player.index].mana_max
end end
rpg_t[player.index].mana = (math.round(rpg_t[player.index].mana * 10) / 10)
end end
end end
::continue::
if rpg_extra.enable_health_and_mana_bars then if rpg_extra.enable_health_and_mana_bars then
if rpg_t[player.index].show_bars then if rpg_t[player.index].show_bars then
if not rendering.is_valid(rpg_t[player.index].mana_bar) then if not rpg_t[player.index].mana_bar then
rpg_t[player.index].mana_bar = create_manabar(player, 0.5)
elseif not rendering.is_valid(rpg_t[player.index].mana_bar) then
rpg_t[player.index].mana_bar = create_manabar(player, 0.5) rpg_t[player.index].mana_bar = create_manabar(player, 0.5)
end end
set_bar(rpg_t[player.index].mana, rpg_t[player.index].mana_max, rpg_t[player.index].mana_bar, true) set_bar(rpg_t[player.index].mana, rpg_t[player.index].mana_max, rpg_t[player.index].mana_bar, true)
end end
end end
if player.gui.left[main_frame_name] then if player.gui.left[main_frame_name] then
draw_gui(player, true) draw_gui(player)
end end
end end
end end
@ -1553,7 +1771,7 @@ local function give_player_flameboots(event)
rpg_t[player.index].mana = 0 rpg_t[player.index].mana = 0
end end
if player.gui.left[main_frame_name] then if player.gui.left[main_frame_name] then
draw_gui(player, true) draw_gui(player)
end end
end end
@ -1883,12 +2101,6 @@ local function on_player_joined_game(event)
Public.gain_xp(player, rpg_extra.reward_new_players) Public.gain_xp(player, rpg_extra.reward_new_players)
end end
end end
if rpg_extra.enable_health_and_mana_bars then
rpg_t[player.index].health_bar = create_healthbar(player, 0.5)
if rpg_extra.enable_mana then
rpg_t[player.index].mana_bar = create_manabar(player, 0.5)
end
end
for _, p in pairs(game.connected_players) do for _, p in pairs(game.connected_players) do
draw_level_text(p) draw_level_text(p)
end end
@ -1923,17 +2135,30 @@ local function splash_damage(surface, position, final_damage_amount)
end end
local function create_projectile(surface, name, position, force, target, max_range) local function create_projectile(surface, name, position, force, target, max_range)
surface.create_entity( if max_range then
{ surface.create_entity(
name = name, {
position = position, name = name,
force = force, position = position,
source = position, force = force,
target = target, source = position,
max_range = max_range, target = target,
speed = 0.4 max_range = max_range,
} speed = 0.4
) }
)
else
surface.create_entity(
{
name = name,
position = position,
force = force,
source = position,
target = target,
speed = 0.4
}
)
end
end end
local function get_near_coord_modifier(range) local function get_near_coord_modifier(range)
@ -1947,31 +2172,61 @@ local function get_near_coord_modifier(range)
return coord return coord
end end
local function get_near_range(range) local function damage_entity(e)
local r = math.random(1, math.floor(range * 2)) if not e.health then
for i = 1, 2, 1 do return
local r2 = math.random(1, math.floor(range * 2)) end
if r2 < r then
r = r2 if e.force.name == 'player' then
end return
end
e.surface.create_entity({name = 'water-splash', position = e.position})
if e.type == 'entity-ghost' then
e.destroy()
return
end
e.health = e.health - math.random(30, 90)
if e.health <= 0 then
e.die('enemy')
end end
return r
end end
local function is_position_near(area, p) local function floaty_hearts(entity, c)
local status = false local position = {x = entity.position.x - 0.75, y = entity.position.y - 1}
local function inside(pos) local b = 1.35
local lt = area.left_top for a = 1, c, 1 do
local rb = area.right_bottom local p = {
(position.x + 0.4) + (b * -1 + math.random(0, b * 20) * 0.1),
return pos.x >= lt.x and pos.y >= lt.y and pos.x <= rb.x and pos.y <= rb.y position.y + (b * -1 + math.random(0, b * 20) * 0.1)
}
entity.surface.create_entity(
{name = 'flying-text', position = p, text = '', color = {math.random(150, 255), 0, 255}}
)
end end
end
if inside(p, area) then local function tame_unit_effects(player, entity)
status = true floaty_hearts(entity, 7)
end
return status rendering.draw_text {
text = '~' .. player.name .. "'s pet~",
surface = player.surface,
target = entity,
target_offset = {0, -2.6},
color = {
r = player.color.r * 0.6 + 0.25,
g = player.color.g * 0.6 + 0.25,
b = player.color.b * 0.6 + 0.25,
a = 1
},
scale = 1.05,
font = 'default-large-semibold',
alignment = 'center',
scale_with_zoom = false
}
end end
local function on_player_used_capsule(event) local function on_player_used_capsule(event)
@ -2022,6 +2277,10 @@ local function on_player_used_capsule(event)
return return
end end
if rpg_t[player.index].level <= object.level then
return p('You lack the level to cast this spell.', Color.fail)
end
local object_name = object.name local object_name = object.name
local obj_name = object.obj_to_create local obj_name = object.obj_to_create
@ -2030,7 +2289,7 @@ local function on_player_used_capsule(event)
return return
end end
local radius = 10 local radius = 15
local area = { local area = {
left_top = {x = position.x - radius, y = position.y - radius}, left_top = {x = position.x - radius, y = position.y - radius},
right_bottom = {x = position.x + radius, y = position.y + radius} right_bottom = {x = position.x + radius, y = position.y + radius}
@ -2047,17 +2306,54 @@ local function on_player_used_capsule(event)
rpg_t[player.index].mana = rpg_t[player.index].mana - object.mana_cost rpg_t[player.index].mana = rpg_t[player.index].mana - object.mana_cost
end end
if projectile_types[obj_name] then local target_pos
if object.target then
target_pos = {position.x, position.y}
elseif projectile_types[obj_name] then
local coord_modifier = get_near_coord_modifier(projectile_types[obj_name].max_range) local coord_modifier = get_near_coord_modifier(projectile_types[obj_name].max_range)
local proj_pos = {position.x + coord_modifier.x, position.y + coord_modifier.y} local proj_pos = {position.x + coord_modifier.x, position.y + coord_modifier.y}
create_projectile(surface, obj_name, position, 'player', proj_pos, 0) target_pos = proj_pos
end
local range
if object.range then
range = object.range
else else
surface.create_entity({name = obj_name, position = position, force = 'player'}) range = 0
end
local force
if object.force then
force = object.force
else
force = 'player'
end
if projectile_types[obj_name] then
for i = 1, object.amount do
local damage_area = {
left_top = {x = position.x - 2, y = position.y - 2},
right_bottom = {x = position.x + 2, y = position.y + 2}
}
create_projectile(surface, obj_name, position, force, target_pos, range)
if object.damage then
for _, e in pairs(surface.find_entities_filtered({area = damage_area})) do
damage_entity(e)
end
end
end
else
if object.biter then
local e = surface.create_entity({name = obj_name, position = position, force = force})
tame_unit_effects(player, e)
else
surface.create_entity({name = obj_name, position = position, force = force})
end
end end
rpg_t[player.index].last_spawned = game.tick + object.tick rpg_t[player.index].last_spawned = game.tick + object.tick
if player.gui.left[main_frame_name] then if player.gui.left[main_frame_name] then
draw_gui(player, true) draw_gui(player)
end end
if rpg_extra.enable_health_and_mana_bars then if rpg_extra.enable_health_and_mana_bars then
if rpg_t[player.index].show_bars then if rpg_t[player.index].show_bars then
@ -2140,7 +2436,7 @@ function Public.rpg_reset_player(player, one_time_reset)
rotated_entity_delay = 0, rotated_entity_delay = 0,
gui_refresh_delay = 0, gui_refresh_delay = 0,
last_mined_entity_position = {x = 0, y = 0}, last_mined_entity_position = {x = 0, y = 0},
show_bars = true show_bars = false
} }
rpg_t[player.index].points_to_distribute = old_points_to_distribute + total rpg_t[player.index].points_to_distribute = old_points_to_distribute + total
rpg_t[player.index].xp = old_xp rpg_t[player.index].xp = old_xp
@ -2169,7 +2465,7 @@ function Public.rpg_reset_player(player, one_time_reset)
rotated_entity_delay = 0, rotated_entity_delay = 0,
gui_refresh_delay = 0, gui_refresh_delay = 0,
last_mined_entity_position = {x = 0, y = 0}, last_mined_entity_position = {x = 0, y = 0},
show_bars = true show_bars = false
} }
end end
draw_gui_char_button(player) draw_gui_char_button(player)
@ -2326,7 +2622,7 @@ function Public.enable_health_and_mana_bars(value)
if value then if value then
rpg_extra.enable_health_and_mana_bars = value rpg_extra.enable_health_and_mana_bars = value
else else
return error('No value given.', 2) rpg_extra.enable_health_and_mana_bars = false
end end
end end
@ -2336,7 +2632,7 @@ function Public.enable_mana(value)
if value then if value then
rpg_extra.enable_mana = value rpg_extra.enable_mana = value
else else
return error('No value given.', 2) rpg_extra.enable_mana = false
end end
end end
@ -2347,7 +2643,7 @@ function Public.enable_wave_defense(value)
if value then if value then
rpg_extra.enable_wave_defense = value rpg_extra.enable_wave_defense = value
else else
return error('No value given.', 2) rpg_extra.enable_wave_defense = false
end end
end end
@ -2357,7 +2653,17 @@ function Public.enable_flame_boots(value)
if value then if value then
rpg_extra.enable_flame_boots = value rpg_extra.enable_flame_boots = value
else else
return error('No value given.', 2) rpg_extra.enable_flame_boots = false
end
end
--- Enables/disabled personal tax.
---@param value <boolean>
function Public.personal_tax_rate(value)
if value then
rpg_extra.personal_tax_rate = value
else
rpg_extra.personal_tax_rate = nil
end end
end end
@ -2454,15 +2760,23 @@ Gui.on_click(
if health_bar_gui_input and health_bar_gui_input.valid then if health_bar_gui_input and health_bar_gui_input.valid then
if not health_bar_gui_input.state then if not health_bar_gui_input.state then
rpg_t[player.index].show_bars = false rpg_t[player.index].show_bars = false
if rendering.is_valid(rpg_t[player.index].health_bar) then if rpg_t[player.index].health_bar then
rendering.destroy(rpg_t[player.index].health_bar) if rendering.is_valid(rpg_t[player.index].health_bar) then
rendering.destroy(rpg_t[player.index].health_bar)
end
end end
if rendering.is_valid(rpg_t[player.index].mana_bar) then if rpg_extra.enable_mana then
rendering.destroy(rpg_t[player.index].mana_bar) if rpg_t[player.index].mana_bar then
if rendering.is_valid(rpg_t[player.index].mana_bar) then
rendering.destroy(rpg_t[player.index].mana_bar)
end
end
end end
elseif health_bar_gui_input.state then elseif health_bar_gui_input.state then
rpg_t[player.index].show_bars = true rpg_t[player.index].show_bars = true
if not rendering.is_valid(rpg_t[player.index].health_bar) then if not rpg_t[player.index].health_bar then
rpg_t[player.index].health_bar = create_healthbar(player, 0.5)
elseif not rendering.is_valid(rpg_t[player.index].health_bar) then
rpg_t[player.index].health_bar = create_healthbar(player, 0.5) rpg_t[player.index].health_bar = create_healthbar(player, 0.5)
end end
local max_life = local max_life =
@ -2471,14 +2785,25 @@ Gui.on_click(
player.force.character_health_bonus player.force.character_health_bonus
) )
set_bar(player.character.health, max_life, rpg_t[player.index].health_bar) set_bar(player.character.health, max_life, rpg_t[player.index].health_bar)
if not rendering.is_valid(rpg_t[player.index].mana_bar) then if rpg_extra.enable_mana then
rpg_t[player.index].mana_bar = create_manabar(player, 0.5) if not rpg_t[player.index].mana_bar then
rpg_t[player.index].mana_bar = create_manabar(player, 0.5)
elseif not rendering.is_valid(rpg_t[player.index].mana_bar) then
rpg_t[player.index].mana_bar = create_manabar(player, 0.5)
end
set_bar(
rpg_t[player.index].mana,
rpg_t[player.index].mana_max,
rpg_t[player.index].mana_bar,
true
)
end end
set_bar(rpg_t[player.index].mana, rpg_t[player.index].mana_max, rpg_t[player.index].mana_bar, true)
end end
end end
draw_gui(player, true) if player.gui.left[main_frame_name] then
draw_gui(player, false)
end
frame.destroy() frame.destroy()
end end
end end

View File

@ -88,7 +88,7 @@ end
local function get_random_close_spawner(surface) local function get_random_close_spawner(surface)
local wave_defense_table = WD.get_table() local wave_defense_table = WD.get_table()
local spawners = surface.find_entities_filtered({type = "unit-spawner"}) local spawners = surface.find_entities_filtered({type = "unit-spawner", force = 'enemy'})
if not spawners[1] then return false end if not spawners[1] then return false end
local center = wave_defense_table.target.position local center = wave_defense_table.target.position
local spawner = spawners[math_random(1,#spawners)] local spawner = spawners[math_random(1,#spawners)]