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

Cave Miner > Fish Bank update

This commit is contained in:
MewMew 2018-10-30 07:48:02 +01:00
parent 17c633469e
commit 12541349d5
3 changed files with 63 additions and 5 deletions

View File

@ -469,6 +469,10 @@ local function secret_shop(pos)
local surface = game.surfaces[1]
local market = surface.create_entity {name = "market", position = pos}
market.destructible = false
market.add_market_item({price = {}, offer = {type = 'nothing', effect_description = 'Deposit Fish'}})
market.add_market_item({price = {}, offer = {type = 'nothing', effect_description = 'Withdraw Fish - 2% Bank Fee'}})
market.add_market_item({price = {}, offer = {type = 'nothing', effect_description = 'Show Account Balance'}})
local market_items_to_add = math.random(8,12)
while market_items_to_add >= 0 do
local i = math.random(1,#secret_market_items)
@ -1276,12 +1280,10 @@ end
local function on_gui_click(event)
if not event then return end
if not event.element then return end
if not event.element.valid then return end
if not event.element.valid then return end
local player = game.players[event.element.player_index]
local name = event.element.name
local frame = player.gui.top["caver_miner_stats_frame"]
if name == "caver_miner_stats_toggle_button" and frame == nil then create_cave_miner_stats_gui(player) end
if name == "caver_miner_stats_toggle_button" and frame then
if player.gui.left["cave_miner_info"] then
@ -1304,6 +1306,59 @@ local function on_player_used_capsule(event)
end
end
local bank_messages = {
"Thank you for using our Fishbank terminal!",
"Caves are dangerous. Did you hear about our insurance programs?",
"Get your wealth flowing today with Fishbank!",
"Hungry? Take a look at our credit offers! No questions asked.",
"Fishbank. The only choice.",
"Smart miners use Fishbank!",
"Your wealth is save with Fishbank!",
"Fishbank, because inventory space matters!"
}
local function on_market_item_purchased(event)
local player = game.players[event.player_index]
local market = event.market
local offer_index = event.offer_index
local count = event.count
local offers = market.get_market_items()
local bought_offer = offers[offer_index].offer
if bought_offer.type ~= "nothing" then return end
if not global.fish_bank then global.fish_bank = {} end
if not global.fish_bank[player.name] then global.fish_bank[player.name] = 0 end
if offer_index == 1 then
local fish_removed = player.remove_item({name = "raw-fish", count = 999999})
if fish_removed == 0 then return end
global.fish_bank[player.name] = global.fish_bank[player.name] + fish_removed
player.print(fish_removed .. " Fish deposited into your account. Your balance is " .. global.fish_bank[player.name] .. ".", { r=0.10, g=0.75, b=0.5})
player.print(bank_messages[math.random(1,#bank_messages)], { r=0.77, g=0.77, b=0.77})
end
if offer_index == 2 then
local requested_withdraw_amount = 500
local fee = 10
if global.fish_bank[player.name] < requested_withdraw_amount + fee then
fee = math.ceil(global.fish_bank[player.name] * 0.02, 0)
requested_withdraw_amount = global.fish_bank[player.name] - fee
end
local fish_withdrawn = player.insert({name = "raw-fish", count = requested_withdraw_amount})
if fish_withdrawn ~= requested_withdraw_amount then
player.remove_item({name = "raw-fish", count = fish_withdrawn})
return
end
global.fish_bank[player.name] = global.fish_bank[player.name] - (fish_withdrawn + fee)
player.print(fish_withdrawn .. " Fish withdrawn from your account. Your balance is " .. global.fish_bank[player.name] .. ".", { r=0.10, g=0.75, b=0.5})
player.print(bank_messages[math.random(1,#bank_messages)], { r=0.77, g=0.77, b=0.77})
end
if offer_index == 3 then
player.print("Your balance is " .. global.fish_bank[player.name] .. " Fish.", { r=0.10, g=0.75, b=0.5})
end
end
Event.add(defines.events.on_market_item_purchased, on_market_item_purchased)
Event.add(defines.events.on_player_used_capsule, on_player_used_capsule)
Event.add(defines.events.on_gui_click, on_gui_click)
Event.add(defines.events.on_research_finished, on_research_finished)

View File

@ -1,5 +1,8 @@
local items = {}
items.spawn = {
{price = {}, offer = {type = 'nothing', effect_description = 'Deposit Fish'}},
{price = {}, offer = {type = 'nothing', effect_description = 'Withdraw Fish - 2% Bank Fee'}},
{price = {}, offer = {type = 'nothing', effect_description = 'Show Account Balance'}},
{price = {{"raw-fish", 5}}, offer = {type = 'give-item', item = 'rail', count = 4}},
{price = {{"raw-fish", 5}}, offer = {type = 'give-item', item = 'rail-signal', count = 2}},
{price = {{"raw-fish", 5}}, offer = {type = 'give-item', item = 'rail-chain-signal', count = 2}},

View File

@ -12,11 +12,11 @@ function cheat_mode()
game.players[1].insert({name="express-loader"})
game.players[1].insert({name="infinity-chest"})
game.players[1].insert({name="computer", count=2})
game.players[1].insert({name="raw-fish", count=100})
game.players[1].insert({name="raw-fish", count=2000})
game.players[1].insert({name="submachine-gun", count=1})
game.players[1].insert({name="uranium-rounds-magazine", count=200})
game.players[1].insert({name="steel-chest", count=200})
game.players[1].insert({name="explosives", count=2000})
game.players[1].insert({name="explosives", count=1000})
game.forces.player.manual_mining_speed_modifier = 100
game.forces.player.character_reach_distance_bonus = 10000
game.speed = 1