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

Lesser restrictions for buying class

You now are able to buy class upgrades without being that class yourself. It upgrades the class wherever it is. In addition when you buy any class and you're using one already, it doesn't replace the class you're using with the newer one.
This commit is contained in:
Piratux 2022-06-04 17:01:34 +03:00
parent 0ba747baaf
commit 0bc327ba50

View File

@ -210,34 +210,49 @@ function Public.event_on_market_item_purchased(event)
-- if not class_for_sale then return end -- if not class_for_sale then return end
local required_class = Classes.class_purchase_requirement[class_for_sale] local required_class = Classes.class_purchase_requirement[class_for_sale]
local ok = true local ok = false
-- check if they have the required class to buy it
if memory.classes_table and memory.spare_classes then
if required_class then if required_class then
if not (memory.classes_table and memory.classes_table[player.index] and memory.classes_table[player.index] == required_class) then local chosen_class_assigned = false
ok = false local spare_class_assigned = false
Common.notify_force_error(force, {'pirates.class_purchase_error_prerequisite_class',Classes.display_form(required_class)})
if required_class then
for p_index, chosen_class in pairs(memory.classes_table) do
if chosen_class == required_class then
memory.classes_table[p_index] = class_for_sale
chosen_class_assigned = true
ok = true
break
end
end
end
if not chosen_class_assigned then
for i, spare_class in pairs(memory.spare_classes) do
if spare_class == required_class then
memory.spare_classes[i] = class_for_sale
spare_class_assigned = true
ok = true
break
end
end
end
else -- there is no required class
if not memory.classes_table[player.index] then
memory.classes_table[player.index] = class_for_sale
else
memory.spare_classes[#memory.spare_classes + 1] = class_for_sale
end
ok = true
end end
end end
if ok then if ok then
if required_class then
if force and force.valid then
local message = {'pirates.class_upgrade', player.name, Classes.display_form(required_class), Classes.display_form(class_for_sale), Classes.explanation(class_for_sale)}
Common.notify_force_light(force,message)
end
else
-- check if they have a role already - renounce it if so
if memory.classes_table and memory.classes_table[player.index] then
Classes.try_renounce_class(player, false)
end
if force and force.valid then if force and force.valid then
local message = {'pirates.class_purchase', player.name, Classes.display_form(class_for_sale), Classes.explanation(class_for_sale)} local message = {'pirates.class_purchase', player.name, Classes.display_form(class_for_sale), Classes.explanation(class_for_sale)}
Common.notify_force_light(force, message) Common.notify_force_light(force, message)
end end
end
memory.classes_table[player.index] = class_for_sale
memory.available_classes_pool = Utils.ordered_table_with_single_value_removed(memory.available_classes_pool, class_for_sale) memory.available_classes_pool = Utils.ordered_table_with_single_value_removed(memory.available_classes_pool, class_for_sale)
@ -253,6 +268,10 @@ function Public.event_on_market_item_purchased(event)
end end
end end
else else
if force and force.valid then
Common.notify_force_error(force, {'pirates.class_purchase_error_prerequisite_class', Classes.display_form(required_class)})
end
--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