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

Merge pull request #12 from Piratux/develop

This commit is contained in:
danielmartin0 2022-07-28 18:32:19 +01:00 committed by GitHub
commit 096abe983b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 300 additions and 198 deletions

View File

@ -16,7 +16,7 @@ softmod_info_tips_1=Features of the game that are hard to work out alone
softmod_info_tips_2=• The captain can steer the boat from the crow's nest by placing 100 rail signals in one of the blue boxes.\n• Resources granted to the ship appear in the captain's cabin.\n• Charging a silo drains power from everything else on its network.\n• The quantity of ore available on an island is independent of the order in which you break rocks.\n• Passive pollution ramps up over time on each island.\n• The strength of attacks is proportional to the number of remaining nests. (The time-based rate of evolution is proportional to nests too, but destroying a nest will immediately jump evolution by most of the amount it 'would have' made had it survived.)\n• Lab productivity increases with each league.\n• item-on-ground entities on the deck are moved to the cabin when the boat moves, for performance reasons.\n• Commands: /ccolor gives you a fun color. /classinfo {classname} gives the description of the named class. To manage your class, use /take {classname} or /giveup.
softmod_info_updates_1=Significant recent changes
softmod_info_updates_2=v1.3.1\n• Fixed quartermaster and its tooltip. Also buffed physical damage buff it provides to nearby players from 10% to 30%.\n• Slightly increased amount of items received from purchasing items in covered structure market\n\nv1.3\n• Hold chests are now destructible.\n• Fluid is now transportable between decks.\n• New classes, and new 'Class Window'.\n• Many other improvements, small features, and balance changes.\n\nv1.2\n• Mod portal release.
softmod_info_updates_2=v1.3.2\n• Fixed a case where class could remain taken when last player in crew left the game.\n• Fixed a case where buying a class upgrade would wrongly update the unlocked classes and cause some classes to be untakable\n• Classes that generate ore passively now don't generate ore when at sea\n\nv1.3.1\n• Fixed quartermaster and its tooltip. Also buffed physical damage buff it provides to nearby players from 10% to 30%.\n• Slightly increased amount of items received from purchasing items in covered structure market\n\nv1.3\n• Hold chests are now destructible.\n• Fluid is now transportable between decks.\n• New classes, and new 'Class Window'.\n• Many other improvements, small features, and balance changes.\n\nv1.2\n• Mod portal release.
softmod_info_credits_1=Credits
softmod_info_credits_2=Pirate Ship designed and coded by thesixthroc. Updates from Piratux. Comfy codebase and help from Gerkiz, Hanakocz and Mew @ Comfy Industries (https://getcomfy.eu). Some island structure blueprints contributed by Mattisso.\n\nCome chat with us: https://getcomfy.eu/discord\n\n"Those white gloves. I'll never forget them 'till the day I die." - Dr. John

View File

@ -152,8 +152,11 @@ local function damage_to_silo(event)
if event.cause and event.cause.valid and entity and entity.valid and entity.force.name == memory.force_name then
local destination = Common.current_destination()
if destination.dynamic_data.rocketsilos and destination.dynamic_data.rocketsilos[1] and destination.dynamic_data.rocketsilos[1].valid and entity == Common.current_destination().dynamic_data.rocketsilos[1] then
if destination.dynamic_data.rocketsilos and
destination.dynamic_data.rocketsilos[1] and
destination.dynamic_data.rocketsilos[1].valid and
entity == Common.current_destination().dynamic_data.rocketsilos[1]
then
if string.sub(event.cause.force.name, 1, 4) ~= 'crew' then
-- play alert sound for all crew members
@ -182,26 +185,29 @@ end
local function damage_to_enemyboat_spawners(event)
local memory = Memory.get_crew_memory()
if memory.enemyboats and #memory.enemyboats > 0 then
if event.cause and event.cause.valid and event.entity and event.entity.valid then
if event.entity.force.name == memory.enemy_force_name then
for i = 1, #memory.enemyboats do
local eb = memory.enemyboats[i]
if eb.spawner and eb.spawner.valid and event.entity == eb.spawner then
-- if eb.spawner and eb.spawner.valid and event.entity == eb.spawner and eb.state == Structures.Boats.enum_state.APPROACHING then
local damage = event.final_damage_amount
local adjusted_damage = damage
if memory.enemyboats and
#memory.enemyboats > 0 and
event.cause and
event.cause.valid and
event.entity and
event.entity.valid and
event.entity.force.name == memory.enemy_force_name
then
for i = 1, #memory.enemyboats do
local eb = memory.enemyboats[i]
if eb.spawner and eb.spawner.valid and event.entity == eb.spawner then
-- if eb.spawner and eb.spawner.valid and event.entity == eb.spawner and eb.state == Structures.Boats.enum_state.APPROACHING then
local damage = event.final_damage_amount
local adjusted_damage = damage
adjusted_damage = adjusted_damage / 2.6
adjusted_damage = adjusted_damage / 2.6
-- if event.cause.name == 'artillery-turret' then
-- adjusted_damage = adjusted_damage / 1
-- end
-- if event.cause.name == 'artillery-turret' then
-- adjusted_damage = adjusted_damage / 1
-- end
if Common.entity_damage_healthbar(event.entity, adjusted_damage) <= 0 then
event.entity.die()
end
end
if Common.entity_damage_healthbar(event.entity, adjusted_damage) <= 0 then
event.entity.die()
end
end
end
@ -215,7 +221,6 @@ local function damage_to_artillery(event)
if not event.cause.valid then return end
if not event.cause.name then return end
if (event.cause.name == 'small-biter')
or (event.cause.name == 'small-spitter')
or (event.cause.name == 'medium-biter')
@ -223,7 +228,8 @@ local function damage_to_artillery(event)
or (event.cause.name == 'big-biter')
or (event.cause.name == 'big-spitter')
or (event.cause.name == 'behemoth-biter')
or (event.cause.name == 'behemoth-spitter') then
or (event.cause.name == 'behemoth-spitter')
then
if event.cause.force.name ~= memory.enemy_force_name then return end
-- play alert sound for all crew members
@ -304,13 +310,14 @@ local function damage_to_players_changes(event)
-- if not (event.cause.name == 'small-biter') or (event.cause.name == 'small-spitter') or (event.cause.name == 'medium-biter') or (event.cause.name == 'medium-spitter') or (event.cause.name == 'big-biter') or (event.cause.name == 'big-spitter') or (event.cause.name == 'behemoth-biter') or (event.cause.name == 'behemoth-spitter') then return end
local player_index = event.entity.player.index
local class = memory.classes_table and memory.classes_table[player_index]
local player = game.players[player_index]
if not (player and player.valid and player.character and player.character.valid) then
return
end
if not player then return end
if not player.valid then return end
if not player.character then return end
if not player.character.valid then return end
local class = Classes.get_class(player_index)
local damage_multiplier = 1
--game.print('on damage info: {name: ' .. event.damage_type.name .. ', object_name: ' .. event.damage_type.object_name .. '}')
@ -321,6 +328,7 @@ local function damage_to_players_changes(event)
if class then
if class == Classes.enum.SCOUT then
damage_multiplier = damage_multiplier * Balance.scout_damage_taken_multiplier
-- merchant is disabled
-- elseif class == Classes.enum.MERCHANT then
-- damage_multiplier = damage_multiplier * 1.10
elseif class == Classes.enum.SAMURAI then
@ -429,15 +437,15 @@ local function damage_dealt_by_players_changes(event)
local acid = event.damage_type.name == 'acid'
local player_index = player.index
local class = memory.classes_table and memory.classes_table[player_index]
local class = Classes.get_class(player_index)
if class and class == Classes.enum.SCOUT and event.final_health > 0 then --lethal damage must be unaffected
event.entity.health = event.entity.health + (1 - Balance.scout_damage_dealt_multiplier) * event.final_damage_amount
elseif class and (class == Classes.enum.SAMURAI or class == Classes.enum.HATAMOTO) then
local samurai = memory.classes_table[player_index] == Classes.enum.SAMURAI
local hatamoto = memory.classes_table[player_index] == Classes.enum.HATAMOTO
local samurai = class == Classes.enum.SAMURAI
local hatamoto = class == Classes.enum.HATAMOTO
--==Note this!
--==Note this! (what the hell is this)
if not (samurai or hatamoto) then return end
local no_weapon = (not (character.get_inventory(defines.inventory.character_guns) and character.get_inventory(defines.inventory.character_guns)[character.selected_gun_index] and character.get_inventory(defines.inventory.character_guns)[character.selected_gun_index].valid_for_read))
@ -779,6 +787,7 @@ local function event_on_player_mined_entity(event)
if memory.classes_table[event.player_index] == Classes.enum.LUMBERJACK then
give[#give + 1] = {name = 'wood', count = 1}
Classes.lumberjack_bonus_items(give)
-- wood lord is disabled
-- elseif memory.classes_table[event.player_index] == Classes.enum.WOOD_LORD then
-- give[#give + 1] = {name = 'wood', count = 1}
-- give[#give + 1] = {name = 'iron-ore', count = 1}
@ -852,29 +861,38 @@ local function event_on_player_mined_entity(event)
local give = {}
-- prospector and chief excavator are disabled
-- if memory.overworldx > 0 then --no coins on first map, else the optimal strategy is to handmine everything there
-- if memory.classes_table and memory.classes_table[event.player_index] and memory.classes_table[event.player_index] == Classes.enum.PROSPECTOR then
-- local a = 3
-- give[#give + 1] = {name = 'coin', count = a}
-- memory.playtesting_stats.coins_gained_by_ore = memory.playtesting_stats.coins_gained_by_ore + a
-- give[#give + 1] = {name = entity.name, count = 6}
-- elseif memory.classes_table and memory.classes_table[event.player_index] and memory.classes_table[event.player_index] == Classes.enum.CHIEF_EXCAVATOR then
-- local a = 4
-- give[#give + 1] = {name = 'coin', count = a}
-- memory.playtesting_stats.coins_gained_by_ore = memory.playtesting_stats.coins_gained_by_ore + a
-- give[#give + 1] = {name = entity.name, count = 12}
-- else
-- if memory.overworldx > 0 then
-- local a = 1
-- give[#give + 1] = {name = 'coin', count = a}
-- memory.playtesting_stats.coins_gained_by_ore = memory.playtesting_stats.coins_gained_by_ore + a
-- end
-- give[#give + 1] = {name = entity.name, count = 2}
-- end
-- else
-- give[#give + 1] = {name = entity.name, count = 2}
-- end
if memory.overworldx > 0 then --no coins on first map, else the optimal strategy is to handmine everything there
if memory.classes_table and memory.classes_table[event.player_index] and memory.classes_table[event.player_index] == Classes.enum.PROSPECTOR then
local a = 3
give[#give + 1] = {name = 'coin', count = a}
memory.playtesting_stats.coins_gained_by_ore = memory.playtesting_stats.coins_gained_by_ore + a
give[#give + 1] = {name = entity.name, count = 6}
elseif memory.classes_table and memory.classes_table[event.player_index] and memory.classes_table[event.player_index] == Classes.enum.CHIEF_EXCAVATOR then
local a = 4
give[#give + 1] = {name = 'coin', count = a}
memory.playtesting_stats.coins_gained_by_ore = memory.playtesting_stats.coins_gained_by_ore + a
give[#give + 1] = {name = entity.name, count = 12}
else
if memory.overworldx > 0 then
local a = 1
give[#give + 1] = {name = 'coin', count = a}
memory.playtesting_stats.coins_gained_by_ore = memory.playtesting_stats.coins_gained_by_ore + a
end
give[#give + 1] = {name = entity.name, count = 2}
end
else
give[#give + 1] = {name = entity.name, count = 2}
local a = 1
give[#give + 1] = {name = 'coin', count = a}
memory.playtesting_stats.coins_gained_by_ore = memory.playtesting_stats.coins_gained_by_ore + a
end
give[#give + 1] = {name = entity.name, count = 2}
Common.give(player, give, entity.position)
event.buffer.clear()
@ -1955,7 +1973,7 @@ local function event_on_player_respawned(event)
local boat = memory.boat
if player.surface == game.surfaces[Common.current_destination().surface_name] then
if boat and boat.state == Boats.enum_state.ATSEA_SAILING or boat.state == Boats.enum_state.ATSEA_WAITING_TO_SAIL or boat.state == Boats.enum_state.ATSEA_LOADING_MAP then
if Boats.is_boat_at_sea() then
-- assuming sea is always default:
local seasurface = game.surfaces[memory.sea_name]
player.teleport(memory.spawnpoint, seasurface)

View File

@ -866,11 +866,11 @@ end
function Public.crowsnest_natural_move(tickinterval)
local memory = Memory.get_crew_memory()
if not memory.loadingticks then
if not Public.overworld_check_collisions() then
Overworld.try_overworld_move_v2{x = 1, y = 0}
end
end
if not (memory.boat and memory.boat.state == Structures.Boats.enum_state.ATSEA_SAILING) then return end
if memory.loadingticks then return end
if Public.overworld_check_collisions() then return end
Overworld.try_overworld_move_v2{x = 1, y = 0}
end
@ -886,8 +886,6 @@ end
function Public.loading_update(tickinterval)
local memory = Memory.get_crew_memory()
if memory.game_lost then return end
@ -1034,38 +1032,46 @@ function Public.loading_update(tickinterval)
end
function Public.crowsnest_steer(tickinterval)
local memory = Memory.get_crew_memory()
if memory.game_lost then return end
if memory.boat and memory.boat.state == Structures.Boats.enum_state.ATSEA_SAILING and memory.game_lost == false and memory.boat.crowsneststeeringchests then
local leftchest, rightchest = memory.boat.crowsneststeeringchests.left, memory.boat.crowsneststeeringchests.right
if leftchest and leftchest.valid and rightchest and rightchest.valid then
local inv_left = leftchest.get_inventory(defines.inventory.chest)
local inv_right = rightchest.get_inventory(defines.inventory.chest)
local count_left = inv_left.get_item_count("rail-signal")
local count_right = inv_right.get_item_count("rail-signal")
if not
(
memory.boat and
memory.boat.state and
memory.boat.state == Structures.Boats.enum_state.ATSEA_SAILING and
memory.game_lost == false and
memory.boat.crowsneststeeringchests
)
then
return
end
if count_left >= 100 and count_right < 100 and memory.overworldy > -24 then
if Overworld.try_overworld_move_v2{x = 0, y = -24} then
local force = memory.force
Common.notify_force(force, {'pirates.steer_left'})
inv_left.remove({name = "rail-signal", count = 100})
end
return
elseif count_right >= 100 and count_left < 100 and memory.overworldy < 24 then
if Overworld.try_overworld_move_v2{x = 0, y = 24} then
local force = memory.force
Common.notify_force(force, {'pirates.steer_right'})
inv_right.remove({name = "rail-signal", count = 100})
end
return
end
local leftchest = memory.boat.crowsneststeeringchests.left
local rightchest = memory.boat.crowsneststeeringchests.right
if not (leftchest and leftchest.valid and rightchest and rightchest.valid) then return end
local inv_left = leftchest.get_inventory(defines.inventory.chest)
local inv_right = rightchest.get_inventory(defines.inventory.chest)
local count_left = inv_left.get_item_count("rail-signal")
local count_right = inv_right.get_item_count("rail-signal")
if count_left >= 100 and count_right < 100 and memory.overworldy > -24 then
if Overworld.try_overworld_move_v2{x = 0, y = -24} then
local force = memory.force
Common.notify_force(force, {'pirates.steer_left'})
inv_left.remove({name = "rail-signal", count = 100})
end
return
elseif count_right >= 100 and count_left < 100 and memory.overworldy < 24 then
if Overworld.try_overworld_move_v2{x = 0, y = 24} then
local force = memory.force
Common.notify_force(force, {'pirates.steer_right'})
inv_right.remove({name = "rail-signal", count = 100})
end
return
end
end

View File

@ -38,6 +38,7 @@ local Highscore = require 'maps.pirates.highscore'
local CustomEvents = require 'maps.pirates.custom_events'
local Classes = require 'maps.pirates.roles.classes'
local Gui = require 'maps.pirates.gui.gui'
local GUIcolor = require 'maps.pirates.gui.color'
@ -609,6 +610,46 @@ function(cmd)
end
end)
-- Unlock a class
commands.add_command(
'unlock',
{'pirates.cmd_explain_dev'},
function(cmd)
cmd_set_memory(cmd)
local param = tostring(cmd.parameter)
if check_admin(cmd) then
local memory = Memory.get_crew_memory()
if not Common.is_id_valid(memory.id) then return end
local player = game.players[cmd.player_index]
Classes.try_unlock_class(param, player, true)
end
end)
-- Remove all classes
commands.add_command(
'remove_classes',
{'pirates.cmd_explain_dev'},
function(cmd)
cmd_set_memory(cmd)
local param = tostring(cmd.parameter)
if check_admin(cmd) then
local memory = Memory.get_crew_memory()
if not Common.is_id_valid(memory.id) then return end
if not Gui.classes then return end
memory.spare_classes = {}
memory.classes_table = {}
memory.unlocked_classes = {}
memory.available_classes_pool = Classes.initial_class_pool()
local players = Common.crew_get_crew_members_and_spectators()
for _, player in pairs(players) do
Gui.classes.full_update(player, true)
end
end
end)
if _DEBUG then
@ -1181,21 +1222,6 @@ if _DEBUG then
end
end)
-- Unlock a class
commands.add_command(
'unlock',
{'pirates.cmd_explain_dev'},
function(cmd)
cmd_set_memory(cmd)
local param = tostring(cmd.parameter)
if check_admin(cmd) then
local memory = Memory.get_crew_memory()
if not Common.is_id_valid(memory.id) then return end
local player = game.players[cmd.player_index]
Classes.try_unlock_class(param, player, true)
end
end)
commands.add_command(
'piratux_test',
'is a dev command of piratux.',

View File

@ -7,7 +7,7 @@ local _inspect = require 'utils.inspect'.inspect
local Public = {}
Public.scenario_id_name = 'pirates'
Public.version_string = '1.3.0' --major.minor.patch versioning, to match factorio mod portal
Public.version_string = '1.3.2' --major.minor.patch versioning, to match factorio mod portal
Public.blueprint_library_allowed = true
Public.blueprint_importing_allowed = true

View File

@ -451,14 +451,14 @@ function Public.leave_crew(player, to_lobby, quiet)
if not (memory.difficulty_votes) then memory.difficulty_votes = {} end
memory.difficulty_votes[player.index] = nil
Roles.player_left_so_redestribute_roles(player)
if #Common.crew_get_crew_members() == 0 then
if Common.autodisband_ticks then
memory.crew_disband_tick = game.tick + Common.autodisband_ticks
end
-- memory.crew_disband_tick = game.tick + 60*60*2 --give players time to log back in after a crash or save
if _DEBUG then memory.crew_disband_tick = game.tick + 30*60*60 end
else
Roles.player_left_so_redestribute_roles(player)
end
end

View File

@ -168,7 +168,14 @@ end
function Public.full_update(player)
function Public.full_update(player, force_refresh)
force_refresh = force_refresh or nil
-- close and open the window to reconstruct the window (not really necessary when window is closed, but doesn't really matter as it should be ran once and only when necessary)
if force_refresh then
Public.toggle_window(player)
Public.toggle_window(player)
end
if not player.gui.screen[window_name .. '_piratewindow'] then return end
local flow = player.gui.screen[window_name .. '_piratewindow']

View File

@ -81,7 +81,7 @@ function Public.full_update(player)
local types = {'leagues', 'kraken', 'time', 'silo', 'nests', 'sandwurms'}
if memory.boat and memory.boat.state and (memory.boat.state == Boats.enum_state.ATSEA_SAILING or memory.boat.state == Boats.enum_state.ATSEA_WAITING_TO_SAIL or memory.boat.state == Boats.enum_state.ATSEA_LOADING_MAP) then
if Boats.is_boat_at_sea() then
evolution_leagues = evo - (memory.kraken_evo or 0)
local krakens = false
if memory.active_sea_enemies and memory.active_sea_enemies.krakens then

View File

@ -33,10 +33,12 @@ ComfyGui.set_disabled_tab('Groups', true)
local Public = {}
-- this seems to be never used
local enum = {
PROGRESS = 'progress',
RUNS = 'runs',
CREW = 'crew',
CLASSES = 'classes',
FUEL = 'fuel',
MINIMAP = 'minimap',
INFO = 'info',
@ -54,6 +56,8 @@ Public.color = require 'maps.pirates.gui.color'
function Public.update_crew_gui(which_gui)
if not Public[which_gui] then return end
local players = Common.crew_get_crew_members_and_spectators()
for _, player in pairs(players) do

View File

@ -175,9 +175,7 @@ local function crew_tick()
if tick % 60 == 0 then
PiratesApiOnTick.captain_warn_afk(60)
PiratesApiOnTick.ship_deplete_fuel(60)
if memory.boat and memory.boat.state == Structures.Boats.enum_state.ATSEA_SAILING then
PiratesApiOnTick.crowsnest_natural_move(60)
end
PiratesApiOnTick.crowsnest_natural_move(60)
PiratesApiOnTick.slower_boat_tick(60)
PiratesApiOnTick.raft_raids(60)
PiratesApiOnTick.place_cached_structures(60)
@ -259,15 +257,14 @@ local function crew_tick()
end
if tick % 60 == 15 or tick % 60 == 45 then
-- @TODO move this ugly check to function?
if memory.boat and memory.boat.state == Structures.Boats.enum_state.ATSEA_SAILING then
PiratesApiOnTick.overworld_check_collisions(120)
end
end
if tick % 60 == 30 then
if memory.boat and memory.boat.state == Structures.Boats.enum_state.ATSEA_SAILING then
PiratesApiOnTick.crowsnest_steer(120)
end
PiratesApiOnTick.crowsnest_steer(120)
end
if tick % Common.loading_interval == 0 then

View File

@ -79,6 +79,7 @@ function Public.initialise_crew_memory(id) --mostly serves as a dev reference of
memory.available_classes_pool = nil
-- Duplicating unlocked classes data for consistency reasons (this way, entries will remain in the same order when unlocked class data changes)
-- @TODO Might have to consider sacrificing consistency(or find a way to retain consistency) to reduce the chance of contradicting data which results in weird bugs (this happened once already)
memory.unlocked_classes = nil
memory.seconds_until_alert_sound_can_be_played_again = 0

View File

@ -20,7 +20,7 @@ local Dock = require 'maps.pirates.surfaces.dock'
-- local Sea = require 'maps.pirates.surfaces.sea.sea'
local Crew = require 'maps.pirates.crew'
-- local Roles = require 'maps.pirates.roles.roles'
local Classes = require 'maps.pirates.roles.classes'
-- local Classes = require 'maps.pirates.roles.classes'
-- local Quest = require 'maps.pirates.quest'
-- local Parrot = require 'maps.pirates.parrot'
-- local Hold = require 'maps.pirates.surfaces.hold'
@ -671,17 +671,18 @@ function Public.try_overworld_move_v2(vector) --islands stay, crowsnest moves
if vector.x > 0 then
-- merchant is disabled
-- crew bonus resources per x:
local crew = Common.crew_get_crew_members()
for _, player in pairs(crew) do
if Common.validate_player_and_character(player) then
local player_index = player.index
if memory.classes_table and memory.classes_table[player_index] and memory.classes_table[player_index] == Classes.enum.MERCHANT then
Common.flying_text_small(player.surface, player.position, '[color=0.97,0.9,0.2]+[/color]')
Common.give_items_to_crew{{name = 'coin', count = 50 * vector.x}}
end
end
end
-- local crew = Common.crew_get_crew_members()
-- for _, player in pairs(crew) do
-- if Common.validate_player_and_character(player) then
-- local player_index = player.index
-- if memory.classes_table and memory.classes_table[player_index] == Classes.enum.MERCHANT then
-- Common.flying_text_small(player.surface, player.position, '[color=0.97,0.9,0.2]+[/color]')
-- Common.give_items_to_crew{{name = 'coin', count = 50 * vector.x}}
-- end
-- end
-- end
-- other freebies:
for i=1,vector.x do

View File

@ -443,8 +443,12 @@ function Public.lumberjack_bonus_items(give_table)
end
function Public.try_unlock_class(class_for_sale, player, force_unlock)
force_unlock = force_unlock or nil
local memory = Memory.get_crew_memory()
if not class_for_sale then return false end
if not player then return false end
local required_class = Public.class_purchase_requirement[class_for_sale]
if not (memory.classes_table and memory.spare_classes) then
@ -459,7 +463,7 @@ function Public.try_unlock_class(class_for_sale, player, force_unlock)
-- update GUI data
for _, class_entry in ipairs(memory.unlocked_classes) do
if class_entry.taken_by == player.index then
if class_entry.taken_by == p_index then
class_entry.class = class_for_sale
break
end
@ -518,6 +522,25 @@ function Public.try_unlock_class(class_for_sale, player, force_unlock)
return false
end
function Public.has_class(player_index)
local memory = Memory.get_crew_memory()
if memory.classes_table and memory.classes_table[player_index] then
return true
else
return false
end
end
function Public.get_class(player_index)
local memory = Memory.get_crew_memory()
if Public.has_class(player_index) then
return memory.classes_table[player_index]
else
return nil
end
end
local event = require 'utils.event'

View File

@ -166,7 +166,8 @@ function Public.update_character_properties(tickinterval)
if Common.validate_player_and_character(player) then
local player_index = player.index
local character = player.character
if memory.classes_table and memory.classes_table[player_index] then
local class = memory.classes_table and memory.classes_table[player_index] or nil
if class then
--local max_reach_bonus = 0
-- if memory.classes_table[player_index] == Classes.enum.DECKHAND then
-- max_reach_bonus = Math.max(max_reach_bonus, 6)
@ -175,11 +176,11 @@ function Public.update_character_properties(tickinterval)
-- character.character_build_distance_bonus = 0
-- end
if memory.classes_table[player_index] == Classes.enum.FISHERMAN then
if class == Classes.enum.FISHERMAN then
character.character_reach_distance_bonus = Balance.fisherman_reach_bonus
elseif memory.classes_table[player_index] == Classes.enum.MASTER_ANGLER then
elseif class == Classes.enum.MASTER_ANGLER then
character.character_reach_distance_bonus = Balance.master_angler_reach_bonus
elseif memory.classes_table[player_index] == Classes.enum.DREDGER then
elseif class == Classes.enum.DREDGER then
character.character_reach_distance_bonus = Balance.dredger_reach_bonus
else
character.character_reach_distance_bonus = 0
@ -210,29 +211,26 @@ function Public.update_character_properties(tickinterval)
if memory.speed_boost_characters and memory.speed_boost_characters[player_index] then
speed_boost = speed_boost * Balance.respawn_speed_boost
else
if memory.classes_table and memory.classes_table[player_index] then
local class = memory.classes_table[player_index]
if class == Classes.enum.SCOUT then
speed_boost = speed_boost * Balance.scout_extra_speed
elseif class == Classes.enum.DECKHAND or class == Classes.enum.BOATSWAIN or class == Classes.enum.SHORESMAN then
local surfacedata = Surfaces.SurfacesCommon.decode_surface_name(player.surface.name)
local type = surfacedata.type
local on_ship_bool = type == Surfaces.enum.HOLD or type == Surfaces.enum.CABIN or type == Surfaces.enum.CROWSNEST or (player.surface.name == memory.boat.surface_name and Boats.on_boat(memory.boat, player.position))
local hold_bool = surfacedata.type == Surfaces.enum.HOLD
elseif memory.classes_table and memory.classes_table[player_index] then
if class == Classes.enum.SCOUT then
speed_boost = speed_boost * Balance.scout_extra_speed
elseif (class == Classes.enum.DECKHAND) or (class == Classes.enum.BOATSWAIN) or (class == Classes.enum.SHORESMAN) then
local surfacedata = Surfaces.SurfacesCommon.decode_surface_name(player.surface.name)
local type = surfacedata.type
local on_ship_bool = (type == Surfaces.enum.HOLD) or (type == Surfaces.enum.CABIN) or (type == Surfaces.enum.CROWSNEST) or (player.surface.name == memory.boat.surface_name and Boats.on_boat(memory.boat, player.position))
local hold_bool = (type == Surfaces.enum.HOLD)
if class == Classes.enum.DECKHAND then
if on_ship_bool and (not hold_bool) then
speed_boost = speed_boost * Balance.deckhand_extra_speed
end
elseif class == Classes.enum.BOATSWAIN then
if hold_bool then
speed_boost = speed_boost * Balance.boatswain_extra_speed
end
elseif class == Classes.enum.SHORESMAN then
if not on_ship_bool then
speed_boost = speed_boost * Balance.shoresman_extra_speed
end
if class == Classes.enum.DECKHAND then
if on_ship_bool and (not hold_bool) then
speed_boost = speed_boost * Balance.deckhand_extra_speed
end
elseif class == Classes.enum.BOATSWAIN then
if hold_bool then
speed_boost = speed_boost * Balance.boatswain_extra_speed
end
elseif class == Classes.enum.SHORESMAN then
if not on_ship_bool then
speed_boost = speed_boost * Balance.shoresman_extra_speed
end
end
end
@ -245,59 +243,64 @@ end
function Public.class_rewards_tick(tickinterval)
--assuming tickinterval = 7 seconds for now
local memory = Memory.get_crew_memory()
local crew = Common.crew_get_crew_members()
for _, player in pairs(crew) do
if Common.validate_player_and_character(player) then
local player_index = player.index
if Common.validate_player_and_character(player) and
game.tick % tickinterval == 0 and
memory.classes_table and
memory.classes_table[player.index]
then
local class = memory.classes_table[player.index]
if memory.classes_table and memory.classes_table[player_index] then
if game.tick % tickinterval == 0 and Common.validate_player_and_character(player) then
if memory.classes_table[player.index] == Classes.enum.SMOLDERING then
local inv = player.get_inventory(defines.inventory.character_main)
if not (inv and inv.valid) then return end
local max_coal = 50
-- local max_transfer = 1
local wood_count = inv.get_item_count('wood')
local coal_count = inv.get_item_count('coal')
if wood_count >= 1 and coal_count < max_coal then
-- local count = Math.min(wood_count, max_coal-coal_count, max_transfer)
local count = 1
inv.remove({name = 'wood', count = count})
inv.insert({name = 'coal', count = count})
Common.flying_text_small(player.surface, player.position, '[item=coal]')
end
if not Boats.is_boat_at_sea() and --it is possible to spend infinite time here, so don't give out freebies
(
class == Classes.enum.DECKHAND or
class == Classes.enum.SHORESMAN or
class == Classes.enum.BOATSWAIN or
class == Classes.enum.QUARTERMASTER
)
then --watch out for this line! (why?)
local surfacedata = Surfaces.SurfacesCommon.decode_surface_name(player.surface.name)
local type = surfacedata.type
local on_ship_bool = (type == Surfaces.enum.HOLD) or (type == Surfaces.enum.CABIN) or (type == Surfaces.enum.CROWSNEST) or (player.surface.name == memory.boat.surface_name and Boats.on_boat(memory.boat, player.position))
local hold_bool = (type == Surfaces.enum.HOLD)
if class == Classes.enum.DECKHAND and on_ship_bool and (not hold_bool) then
Classes.class_ore_grant(player, Balance.deckhand_ore_grant_multiplier, Balance.deckhand_ore_scaling_enabled)
elseif class == Classes.enum.BOATSWAIN and hold_bool then
Classes.class_ore_grant(player, Balance.boatswain_ore_grant_multiplier, Balance.boatswain_ore_scaling_enabled)
elseif class == Classes.enum.SHORESMAN and (not on_ship_bool) then
Classes.class_ore_grant(player, Balance.shoresman_ore_grant_multiplier, Balance.shoresman_ore_scaling_enabled)
elseif class == Classes.enum.QUARTERMASTER then
local nearby_players = #player.surface.find_entities_filtered{position = player.position, radius = Balance.quartermaster_range, name = 'character'}
if nearby_players > 1 then
Classes.class_ore_grant(player, nearby_players - 1, Balance.quartermaster_ore_scaling_enabled)
end
end
end
if game.tick % tickinterval == 0 and (not (memory.boat and memory.boat.state and memory.boat.state == Structures.Boats.enum_state.ATSEA_LOADING_MAP)) then --it is possible to spend extra time here, so don't give out freebies
if memory.classes_table and memory.classes_table[player_index] then
local class = memory.classes_table[player_index]
if class == Classes.enum.DECKHAND or class == Classes.enum.SHORESMAN or class == Classes.enum.BOATSWAIN or class == Classes.enum.QUARTERMASTER then --watch out for this line!
local surfacedata = Surfaces.SurfacesCommon.decode_surface_name(player.surface.name)
local type = surfacedata.type
local on_ship_bool = type == Surfaces.enum.HOLD or type == Surfaces.enum.CABIN or type == Surfaces.enum.CROWSNEST or (player.surface.name == memory.boat.surface_name and Boats.on_boat(memory.boat, player.position))
local hold_bool = surfacedata.type == Surfaces.enum.HOLD
if class == Classes.enum.DECKHAND and on_ship_bool and (not hold_bool) then
Classes.class_ore_grant(player, Balance.deckhand_ore_grant_multiplier, Balance.deckhand_ore_scaling_enabled)
elseif class == Classes.enum.BOATSWAIN and hold_bool then
Classes.class_ore_grant(player, Balance.boatswain_ore_grant_multiplier, Balance.boatswain_ore_scaling_enabled)
elseif class == Classes.enum.SHORESMAN and (not on_ship_bool) then
Classes.class_ore_grant(player, Balance.shoresman_ore_grant_multiplier, Balance.shoresman_ore_scaling_enabled)
elseif class == Classes.enum.QUARTERMASTER then
local nearby_players = #player.surface.find_entities_filtered{position = player.position, radius = Balance.quartermaster_range, name = 'character'}
if nearby_players > 1 then
Classes.class_ore_grant(player, nearby_players - 1, Balance.quartermaster_ore_scaling_enabled)
end
end
end
end
end
-- Smoldering class is disabled
-- if memory.classes_table and memory.classes_table[player.index] then
-- if game.tick % tickinterval == 0 and Common.validate_player_and_character(player) then
-- if memory.classes_table[player.index] == Classes.enum.SMOLDERING then
-- local inv = player.get_inventory(defines.inventory.character_main)
-- if not (inv and inv.valid) then return end
-- local max_coal = 50
-- -- local max_transfer = 1
-- local wood_count = inv.get_item_count('wood')
-- local coal_count = inv.get_item_count('coal')
-- if wood_count >= 1 and coal_count < max_coal then
-- -- local count = Math.min(wood_count, max_coal-coal_count, max_transfer)
-- local count = 1
-- inv.remove({name = 'wood', count = count})
-- inv.insert({name = 'coal', count = count})
-- Common.flying_text_small(player.surface, player.position, '[item=coal]')
-- end
-- end
-- end
-- end
end
end
end

View File

@ -211,7 +211,7 @@ function Public.event_on_market_item_purchased(event)
-- if not class_for_sale then return end
local required_class = Classes.class_purchase_requirement[class_for_sale]
local ok = Classes.try_unlock_class(class_for_sale, player)
local ok = Classes.try_unlock_class(class_for_sale, player, false)
if ok then
if force and force.valid then

View File

@ -1381,4 +1381,20 @@ function Public.teleport_boat(boat, newsurface_name, newposition, new_floor_tile
end
function Public.is_boat_at_sea()
local memory = Memory.get_crew_memory()
if memory.boat and
memory.boat.state and
(
memory.boat.state == Public.enum_state.ATSEA_SAILING or
memory.boat.state == Public.enum_state.ATSEA_WAITING_TO_SAIL or
memory.boat.state == Public.enum_state.ATSEA_LOADING_MAP
)
then
return true
else
return false
end
end
return Public

View File

@ -796,7 +796,7 @@ function Public.player_exit_crows_nest(player, player_relative_pos)
local memory = Memory.get_crew_memory()
local surface
if memory.boat and (memory.boat.state == Boats.enum_state.ATSEA_SAILING or memory.boat.state == Boats.enum_state.ATSEA_WAITING_TO_SAIL or memory.boat.state == Boats.enum_state.ATSEA_LOADING_MAP) then
if Boats.is_boat_at_sea() then
surface = game.surfaces[SurfacesCommon.encode_surface_name(memory.id, 0, Public.enum.SEA, Public.Sea.enum.DEFAULT)]
else
surface = game.surfaces[Common.current_destination().surface_name]
@ -835,7 +835,7 @@ function Public.player_exit_hold(player, relative_pos)
local memory = Memory.get_crew_memory()
local surface
if memory.boat and (memory.boat.state == Boats.enum_state.ATSEA_SAILING or memory.boat.state == Boats.enum_state.ATSEA_WAITING_TO_SAIL or memory.boat.state == Boats.enum_state.ATSEA_LOADING_MAP) then
if Boats.is_boat_at_sea() then
surface = game.surfaces[SurfacesCommon.encode_surface_name(memory.id, 0, Public.enum.SEA, Public.Sea.enum.DEFAULT)]
else
surface = game.surfaces[Common.current_destination().surface_name]
@ -873,7 +873,7 @@ function Public.player_exit_cabin(player, relative_pos)
local memory = Memory.get_crew_memory()
local surface
if memory.boat and (memory.boat.state == Boats.enum_state.ATSEA_SAILING or memory.boat.state == Boats.enum_state.ATSEA_WAITING_TO_SAIL or memory.boat.state == Boats.enum_state.ATSEA_LOADING_MAP) then
if Boats.is_boat_at_sea() then
surface = game.surfaces[SurfacesCommon.encode_surface_name(memory.id, 0, Public.enum.SEA, Public.Sea.enum.DEFAULT)]
else
surface = game.surfaces[Common.current_destination().surface_name]