1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-01 13:08:05 +02:00

93 lines
3.8 KiB
Lua
Raw Normal View History

2019-12-18 14:31:50 +01:00
local Town_center = require "modules.towny.town_center"
2019-12-17 22:40:16 +01:00
local Public = {}
2019-12-18 14:31:50 +01:00
local upgrade_functions = {
--Upgrade Town Center Health
[1] = function(town_center)
2019-12-21 19:47:32 +01:00
if town_center.max_health > 500000 then return end
2019-12-18 14:31:50 +01:00
town_center.health = town_center.health + town_center.max_health
town_center.max_health = town_center.max_health * 2
Town_center.set_market_health(town_center.market, 0)
end,
2019-12-20 21:13:50 +01:00
--Upgrade Backpack
[2] = function(town_center)
2019-12-21 19:47:32 +01:00
local force = town_center.market.force
if force.character_inventory_slots_bonus > 100 then return end
force.character_inventory_slots_bonus = force.character_inventory_slots_bonus + 5
2019-12-20 21:13:50 +01:00
end,
2019-12-18 14:31:50 +01:00
}
local function clear_offers(market)
for i = 1, 256, 1 do
local a = market.remove_market_item(1)
if a == false then return end
end
end
local function set_offers(town_center)
local market = town_center.market
2019-12-20 21:13:50 +01:00
local force = market.force
2019-12-21 19:47:32 +01:00
local special_offers = {}
if town_center.max_health < 500000 then
special_offers[1] = {{{"coin", town_center.max_health * 0.1}}, "Upgrade Town Center Health"}
else
special_offers[1] = {{{"computer", 1}}, "Maximum Health upgrades reached!"}
end
if force.character_inventory_slots_bonus <= 100 then
special_offers[2] = {{{"coin", (force.character_inventory_slots_bonus / 5 + 1) * 35}}, "Upgrade Backpack +5 Slot"}
else
special_offers[2] = {{{"computer", 1}}, "Maximum Backpack upgrades reached!"}
end
local market_items = {}
for _, v in pairs(special_offers) do
table.insert(market_items, {price = v[1], offer = {type = 'nothing', effect_description = v[2]}})
--table.insert(market_items, {price = {v[1], offer = {type = 'nothing', effect_description = v[2]}}})
end
table.insert(market_items, {price = {{"coin", 1}}, offer = {type = 'give-item', item = 'raw-fish', count = 1}})
table.insert(market_items, {price = {{"coin", 8}}, offer = {type = 'give-item', item = 'wood', count = 50}})
table.insert(market_items, {price = {{"coin", 8}}, offer = {type = 'give-item', item = 'iron-ore', count = 50}})
table.insert(market_items, {price = {{"coin", 8}}, offer = {type = 'give-item', item = 'copper-ore', count = 50}})
table.insert(market_items, {price = {{"coin", 8}}, offer = {type = 'give-item', item = 'stone', count = 50}})
table.insert(market_items, {price = {{"coin", 8}}, offer = {type = 'give-item', item = 'coal', count = 50}})
table.insert(market_items, {price = {{"coin", 12}}, offer = {type = 'give-item', item = 'uranium-ore', count = 50}})
table.insert(market_items, {price = {{'wood', 7}}, offer = {type = 'give-item', item = "coin"}})
table.insert(market_items, {price = {{'iron-ore', 7}}, offer = {type = 'give-item', item = "coin"}})
table.insert(market_items, {price = {{'copper-ore', 7}}, offer = {type = 'give-item', item = "coin"}})
table.insert(market_items, {price = {{'stone', 7}}, offer = {type = 'give-item', item = "coin"}})
table.insert(market_items, {price = {{'coal', 7}}, offer = {type = 'give-item', item = "coin"}})
table.insert(market_items, {price = {{'uranium-ore', 5}}, offer = {type = 'give-item', item = "coin"}})
2019-12-18 14:31:50 +01:00
for _, item in pairs(market_items) do
market.add_market_item(item)
end
end
function Public.refresh_offers(event)
local market = event.entity or event.market
if not market then return end
if not market.valid then return end
if market.name ~= "market" then return end
local town_center = global.towny.town_centers[market.force.name]
if not town_center then return end
clear_offers(market)
set_offers(town_center)
end
function Public.offer_purchased(event)
local offer_index = event.offer_index
if not upgrade_functions[offer_index] then return end
local market = event.market
local town_center = global.towny.town_centers[market.force.name]
if not town_center then return end
upgrade_functions[offer_index](town_center)
end
return Public
2019-12-17 22:40:16 +01:00