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

luacheck update

This commit is contained in:
danielmartin0 2022-05-07 21:56:16 +01:00
parent c068fc68e5
commit 0910c3ea31
5 changed files with 101 additions and 76 deletions

View File

@ -706,9 +706,9 @@ end
function Public.transfer_healthbar(old_unit_number, new_entity, location_override) function Public.transfer_healthbar(old_unit_number, new_entity, location_override)
location_override = location_override or Memory.get_crew_memory() location_override = location_override or Memory.get_crew_memory()
local new_unit_number = new_entity.unit_number
if not location_override.healthbars then return end if not location_override.healthbars then return end
local old_healthbar = location_override.healthbars[old_unit_number] local old_healthbar = location_override.healthbars[old_unit_number]
-- local new_unit_number = new_entity.unit_number
-- if new_surface_bool then -- if new_surface_bool then
-- Public.new_healthbar(old_healthbar.render2, new_entity, old_healthbar.max_health, old_healthbar.id, old_healthbar.health, rendering.get_y_scale(old_healthbar.render1)) -- Public.new_healthbar(old_healthbar.render2, new_entity, old_healthbar.max_health, old_healthbar.id, old_healthbar.health, rendering.get_y_scale(old_healthbar.render1))

View File

@ -130,12 +130,12 @@ end
local function protect_special_entities(event) local function protect_special_entities(event)
local memory = Memory.get_crew_memory() -- local memory = Memory.get_crew_memory()
local entity = event.entity local entity = event.entity
if event.cause and event.cause.valid and entity and entity.valid then if event.cause and event.cause.valid and entity and entity.valid then
local surfacedata = Surfaces.SurfacesCommon.decode_surface_name(entity.surface.name) local surfacedata = Surfaces.SurfacesCommon.decode_surface_name(entity.surface.name)
local dest = Common.current_destination() -- local dest = Common.current_destination()
if surfacedata.type == Surfaces.enum.CROWSNEST or surfacedata.type == Surfaces.enum.LOBBY then if surfacedata.type == Surfaces.enum.CROWSNEST or surfacedata.type == Surfaces.enum.LOBBY then
entity.health = entity.health + event.final_damage_amount entity.health = entity.health + event.final_damage_amount
end end

View File

@ -1,17 +1,17 @@
local Memory = require 'maps.pirates.memory' local Memory = require 'maps.pirates.memory'
-- local Roles = require 'maps.pirates.roles.roles' -- local Roles = require 'maps.pirates.roles.roles'
local Balance = require 'maps.pirates.balance' -- local Balance = require 'maps.pirates.balance'
local Common = require 'maps.pirates.common' -- local Common = require 'maps.pirates.common'
-- local Utils = require 'maps.pirates.utils_local' -- local Utils = require 'maps.pirates.utils_local'
-- local Math = require 'maps.pirates.math' -- local Math = require 'maps.pirates.math'
-- local Loot = require 'maps.pirates.loot' -- local Loot = require 'maps.pirates.loot'
local _inspect = require 'utils.inspect'.inspect local _inspect = require 'utils.inspect'.inspect
local Upgrades = require 'maps.pirates.boat_upgrades' local Upgrades = require 'maps.pirates.boat_upgrades'
-- local Hold = require 'maps.pirates.surfaces.hold' -- local Hold = require 'maps.pirates.surfaces.hold'
local Crew = require 'maps.pirates.crew' -- local Crew = require 'maps.pirates.crew'
local Boats = require 'maps.pirates.structures.boats.boats' -- local Boats = require 'maps.pirates.structures.boats.boats'
local Dock = require 'maps.pirates.surfaces.dock' -- local Dock = require 'maps.pirates.surfaces.dock'
local CustomEvents = require 'maps.pirates.custom_events' local CustomEvents = require 'maps.pirates.custom_events'
local Public = {} local Public = {}

View File

@ -53,14 +53,9 @@ end
local function purchaseData(market, player, offer_index)
--a proper rewriting of this function would directly check market entities against saved references to them in memory, but we haven't had time to rewrite it yet
function Public.event_on_market_item_purchased(event)
local player_index, market, offer_index, trade_count = event.player_index, event.market, event.offer_index, event.count
local player = game.players[player_index]
if not (market and market.valid and offer_index and Common.validate_player(player)) then return end
local crew_id = tonumber(string.sub(player.force.name, -3, -1)) or nil
Memory.set_working_id(crew_id)
local memory = Memory.get_crew_memory() local memory = Memory.get_crew_memory()
local destination = Common.current_destination() local destination = Common.current_destination()
@ -74,9 +69,6 @@ function Public.event_on_market_item_purchased(event)
offer_giveitem_count = this_offer.offer.count offer_giveitem_count = this_offer.offer.count
end end
local inv = player.get_inventory(defines.inventory.character_main)
-- check for BARTER vs STATIC vs ONE-OFF -- check for BARTER vs STATIC vs ONE-OFF
-- One-off becomes unavailable after purchase, such as class purchase -- One-off becomes unavailable after purchase, such as class purchase
-- Static doesn't decay -- Static doesn't decay
@ -112,41 +104,74 @@ function Public.event_on_market_item_purchased(event)
decay_type = 'decay' decay_type = 'decay'
end end
return {
decay_type = decay_type,
price = price,
offer_type = offer_type,
offer_giveitem_name = offer_giveitem_name,
offer_giveitem_count = offer_giveitem_count,
dock_bool = dock_bool,
island_bool = island_bool,
purchase_bool = purchase_bool,
simple_efficiency_trade_bool = simple_efficiency_trade_bool,
special_purchase_bool = special_purchase_bool,
in_captains_cabin = in_captains_cabin,
dock_upgrades_market = dock_upgrades_market,
permission_level_fail = permission_level_fail,
}
end
function Public.event_on_market_item_purchased(event)
local player_index, market, offer_index, trade_count = event.player_index, event.market, event.offer_index, event.count
local player = game.players[player_index]
if not (market and market.valid and offer_index and Common.validate_player(player)) then return end
local crew_id = tonumber(string.sub(player.force.name, -3, -1)) or nil
Memory.set_working_id(crew_id)
local memory = Memory.get_crew_memory()
local destination = Common.current_destination()
local inv = player.get_inventory(defines.inventory.character_main)
local thisPurchaseData = purchaseData(market, player, offer_index)
local refunds = 0 local refunds = 0
-- Normally we want to disallow multi-purchases in this game (with the exception of static trades for items), so refund any additional purchases: -- Normally we want to disallow multi-purchases in this game (with the exception of static trades for items), so refund any additional purchases:
if (decay_type ~= 'static' or offer_type == 'nothing') and player and trade_count and trade_count > 1 then if (thisPurchaseData.decay_type ~= 'static' or thisPurchaseData.offer_type == 'nothing') and player and trade_count and trade_count > 1 then
inv = player.get_inventory(defines.inventory.character_main) inv = player.get_inventory(defines.inventory.character_main)
if not inv then return end if not inv then return end
for _, p in pairs(price) do for _, p in pairs(thisPurchaseData.price) do
inv.insert{name = p.name, count = p.amount * (trade_count - 1)} inv.insert{name = p.name, count = p.amount * (trade_count - 1)}
end end
if offer_type == 'give-item' then if thisPurchaseData.offer_type == 'give-item' then
inv.remove{name = offer_giveitem_name, count = offer_giveitem_count * (trade_count - 1)} inv.remove{name = thisPurchaseData.offer_giveitem_name, count = thisPurchaseData.offer_giveitem_count * (trade_count - 1)}
end end
refunds = refunds + (trade_count - 1) refunds = refunds + (trade_count - 1)
end end
if decay_type == 'one-off' then if thisPurchaseData.decay_type == 'one-off' then
local force = player.force local force = player.force
if dock_upgrades_market then if thisPurchaseData.dock_upgrades_market then
if offer_type == 'give-item' then if thisPurchaseData.offer_type == 'give-item' then
-- this is the dummy artillery purchase -- this is the dummy artillery purchase
inv.remove{name = offer_giveitem_name, count = offer_giveitem_count} inv.remove{name = thisPurchaseData.offer_giveitem_name, count = thisPurchaseData.offer_giveitem_count}
end end
if permission_level_fail then if thisPurchaseData.permission_level_fail then
Common.notify_player_error(player, string.format('Purchase error: You need to be a captain or officer to buy this.', player.name)) Common.notify_player_error(player, string.format('Purchase error: You need to be a captain or officer to buy this.', player.name))
-- refund: -- refund:
inv = player.get_inventory(defines.inventory.character_main) inv = player.get_inventory(defines.inventory.character_main)
if not inv then return end if not inv then return end
for _, p in pairs(price) do for _, p in pairs(thisPurchaseData.price) do
inv.insert{name = p.name, count = p.amount} inv.insert{name = p.name, count = p.amount}
end end
refunds = refunds + 1 refunds = refunds + 1
else else
if offer_type == 'give-item' then if thisPurchaseData.offer_type == 'give-item' then
-- heal all cannons: -- heal all cannons:
local cannons = game.surfaces[destination.surface_name].find_entities_filtered({type = 'artillery-turret'}) local cannons = game.surfaces[destination.surface_name].find_entities_filtered({type = 'artillery-turret'})
for _, c in pairs(cannons) do for _, c in pairs(cannons) do
@ -173,7 +198,7 @@ function Public.event_on_market_item_purchased(event)
else else
if offer_type == 'nothing' and destination.static_params.class_for_sale then if thisPurchaseData.offer_type == 'nothing' and destination.static_params.class_for_sale then
local class_for_sale = destination.static_params.class_for_sale local class_for_sale = destination.static_params.class_for_sale
-- if not class_for_sale then return end -- if not class_for_sale then return end
@ -223,81 +248,81 @@ function Public.event_on_market_item_purchased(event)
--refund --refund
inv = player.get_inventory(defines.inventory.character_main) inv = player.get_inventory(defines.inventory.character_main)
if not inv then return end if not inv then return end
for _, p in pairs(price) do for _, p in pairs(thisPurchaseData.price) do
inv.insert{name = p.name, count = p.amount} inv.insert{name = p.name, count = p.amount}
end end
refunds = refunds + 1 refunds = refunds + 1
end end
else else
Common.notify_force_light(player.force, player.name .. ' bought ' .. this_offer.offer.count .. ' ' .. this_offer.offer.item .. ' for ' .. price[1].amount .. ' ' .. price[1].name .. '.') Common.notify_force_light(player.force, player.name .. ' bought ' .. thisPurchaseData.this_offer.offer.count .. ' ' .. thisPurchaseData.this_offer.offer.item .. ' for ' .. thisPurchaseData.price[1].amount .. ' ' .. thisPurchaseData.price[1].name .. '.')
market.remove_market_item(offer_index) market.remove_market_item(offer_index)
end end
end end
else else
if in_captains_cabin and permission_level_fail then if thisPurchaseData.in_captains_cabin and thisPurchaseData.permission_level_fail then
Common.notify_player_error(player, string.format('Purchase error: You need to be a captain or officer to buy this.', player.name)) Common.notify_player_error(player, string.format('Purchase error: You need to be a captain or officer to buy this.', player.name))
-- refund: -- refund:
inv = player.get_inventory(defines.inventory.character_main) inv = player.get_inventory(defines.inventory.character_main)
if not inv then return end if not inv then return end
for _, p in pairs(price) do for _, p in pairs(thisPurchaseData.price) do
inv.insert{name = p.name, count = p.amount} inv.insert{name = p.name, count = p.amount}
end end
if offer_type == 'give-item' then if thisPurchaseData.offer_type == 'give-item' then
inv.remove{name = offer_giveitem_name, count = offer_giveitem_count} inv.remove{name = thisPurchaseData.offer_giveitem_name, count = thisPurchaseData.offer_giveitem_count}
end end
refunds = refunds + 1 refunds = refunds + 1
else else
-- print: -- print:
if (price and price[1]) then if (thisPurchaseData.price and thisPurchaseData.price[1]) then
if not (price[1].name and price[1].name == 'burner-mining-drill') then --this one is too boring to announce if not (thisPurchaseData.price[1].name and thisPurchaseData.price[1].name == 'burner-mining-drill') then --this one is too boring to announce
if in_captains_cabin and offer_type == 'nothing' then if thisPurchaseData.in_captains_cabin and thisPurchaseData.offer_type == 'nothing' then
local price_name = price[1].name local price_name = thisPurchaseData.price[1].name
Common.notify_force_light(player.force, player.name .. ' bought extra time at sea for ' .. price[1].amount .. ' ' .. price_name .. '.') Common.notify_force_light(player.force, player.name .. ' bought extra time at sea for ' .. thisPurchaseData.price[1].amount .. ' ' .. price_name .. '.')
else else
Public.print_transaction(player, this_offer.offer, price) Public.print_transaction(player, thisPurchaseData.this_offer.offer, thisPurchaseData.price)
end end
end end
end end
if in_captains_cabin and offer_type == 'nothing' then if thisPurchaseData.in_captains_cabin and thisPurchaseData.offer_type == 'nothing' then
local success = Crew.try_add_extra_time_at_sea(60 * 60) local success = Crew.try_add_extra_time_at_sea(60 * 60)
if not success then if not success then
Common.notify_player_error(player, string.format('Purchase error: Reached the maximum allowed loading time.', player.name)) Common.notify_player_error(player, string.format('Purchase error: Reached the maximum allowed loading time.', player.name))
-- refund: -- refund:
inv = player.get_inventory(defines.inventory.character_main) inv = player.get_inventory(defines.inventory.character_main)
if not inv then return end if not inv then return end
for _, p in pairs(price) do for _, p in pairs(thisPurchaseData.price) do
inv.insert{name = p.name, count = p.amount} inv.insert{name = p.name, count = p.amount}
end end
refunds = refunds + 1 refunds = refunds + 1
end end
else else
if decay_type == 'static' then if thisPurchaseData.decay_type == 'static' then
if not inv then return end if not inv then return end
local flying_text_color = {r = 255, g = 255, b = 255} local flying_text_color = {r = 255, g = 255, b = 255}
local text1 = '[color=1,1,1]+' .. this_offer.offer.count .. '[/color] [item=' .. alloffers[offer_index].offer.item .. ']' local text1 = '[color=1,1,1]+' .. thisPurchaseData.this_offer.offer.count .. '[/color] [item=' .. thisPurchaseData.alloffers[offer_index].offer.item .. ']'
local text2 = '[color=' .. flying_text_color.r .. ',' .. flying_text_color.g .. ',' .. flying_text_color.b .. '](' .. inv.get_item_count(alloffers[offer_index].offer.item) .. ')[/color]' local text2 = '[color=' .. flying_text_color.r .. ',' .. flying_text_color.g .. ',' .. flying_text_color.b .. '](' .. inv.get_item_count(thisPurchaseData.alloffers[offer_index].offer.item) .. ')[/color]'
Common.flying_text(player.surface, player.position, text1 .. ' [font=count-font]' .. text2 .. '[/font]') Common.flying_text(player.surface, player.position, text1 .. ' [font=count-font]' .. text2 .. '[/font]')
else else
local decay_param = Balance.barter_decay_parameter() local decay_param = Balance.barter_decay_parameter()
if decay_type == 'fast_decay' then decay_param = Balance.barter_decay_parameter()^3 end if thisPurchaseData.decay_type == 'fast_decay' then decay_param = Balance.barter_decay_parameter()^3 end
if not inv then return end if not inv then return end
local flying_text_color = {r = 255, g = 255, b = 255} local flying_text_color = {r = 255, g = 255, b = 255}
local text1 = '[color=1,1,1]+' .. this_offer.offer.count .. '[/color] [item=' .. alloffers[offer_index].offer.item .. ']' local text1 = '[color=1,1,1]+' .. thisPurchaseData.this_offer.offer.count .. '[/color] [item=' .. thisPurchaseData.alloffers[offer_index].offer.item .. ']'
local text2 = '[color=' .. flying_text_color.r .. ',' .. flying_text_color.g .. ',' .. flying_text_color.b .. '](' .. inv.get_item_count(this_offer.offer.item) .. ')[/color]' local text2 = '[color=' .. flying_text_color.r .. ',' .. flying_text_color.g .. ',' .. flying_text_color.b .. '](' .. inv.get_item_count(thisPurchaseData.this_offer.offer.item) .. ')[/color]'
Common.flying_text(player.surface, player.position, text1 .. ' [font=count-font]' .. text2 .. '[/font]') Common.flying_text(player.surface, player.position, text1 .. ' [font=count-font]' .. text2 .. '[/font]')
--update market trades: --update market trades:
alloffers[offer_index].offer.count = Math.max(Math.floor(alloffers[offer_index].offer.count * decay_param),1) thisPurchaseData.alloffers[offer_index].offer.count = Math.max(Math.floor(thisPurchaseData.alloffers[offer_index].offer.count * decay_param),1)
market.clear_market_items() market.clear_market_items()
for _, offer in pairs(alloffers) do for _, offer in pairs(thisPurchaseData.alloffers) do
market.add_market_item(offer) market.add_market_item(offer)
end end
end end
@ -305,8 +330,8 @@ function Public.event_on_market_item_purchased(event)
end end
end end
if this_offer.offer.item == 'coin' then if thisPurchaseData.this_offer.offer.item == 'coin' and refunds < trade_count then
memory.playtesting_stats.coins_gained_by_markets = memory.playtesting_stats.coins_gained_by_markets + this_offer.offer.count memory.playtesting_stats.coins_gained_by_markets = memory.playtesting_stats.coins_gained_by_markets + thisPurchaseData.this_offer.offer.count
end end
end end