1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-08 00:39:30 +02:00
ComfyFactorio/modules/biters_yield_coins.lua

94 lines
2.9 KiB
Lua
Raw Normal View History

2019-11-11 13:25:27 +02:00
-- biters yield coins -- by mewmew
2018-12-31 04:47:53 +02:00
local event = require 'utils.event'
local insert = table.insert
2019-11-11 13:25:27 +02:00
local math_floor = math.floor
2018-12-31 04:47:53 +02:00
local coin_yield = {
2019-11-11 13:15:14 +02:00
["behemoth-biter"] = 5,
["behemoth-spitter"] = 5,
2019-11-11 13:25:27 +02:00
["behemoth-worm-turret"] = 20,
["big-biter"] = 3,
["big-spitter"] = 3,
["big-worm-turret"] = 16,
2018-12-31 04:47:53 +02:00
["biter-spawner"] = 32,
2019-11-11 13:25:27 +02:00
["medium-biter"] = 2,
["medium-spitter"] = 2,
["medium-worm-turret"] = 12,
["small-biter"] = 1,
["small-spitter"] = 1,
2018-12-31 04:47:53 +02:00
["small-worm-turret"] = 8,
2019-11-11 13:25:27 +02:00
["spitter-spawner"] = 32,
2018-12-31 04:47:53 +02:00
}
local entities_that_earn_coins = {
["artillery-turret"] = true,
["gun-turret"] = true,
["laser-turret"] = true,
["flamethrower-turret"] = true
}
2019-11-11 13:25:27 +02:00
--extra coins for "boss" biters from biter_health_booster.lua
local function get_coin_count(entity)
local coin_count = coin_yield[entity.name]
if not coin_count then return end
if not global.biter_health_boost_units then return coin_count end
local unit_number = entity.unit_number
if not unit_number then return coin_count end
if not global.biter_health_boost_units[unit_number] then return coin_count end
if not global.biter_health_boost_units[unit_number][3] then return coin_count end
local m = 1 / global.biter_health_boost_units[unit_number][2]
coin_count = math_floor(coin_count * m)
if coin_count < 1 then return 1 end
return coin_count
end
2018-12-31 04:47:53 +02:00
2019-11-11 13:25:27 +02:00
local function on_entity_died(event)
local entity = event.entity
if not entity.valid then return end
if entity.force.index ~= 2 then return end
local coin_count = get_coin_count(entity)
if not coin_count then return end
2018-12-31 04:47:53 +02:00
local players_to_reward = {}
local reward_has_been_given = false
if event.cause then
if event.cause.valid then
if event.cause.name == "character" then
2018-12-31 04:47:53 +02:00
insert(players_to_reward, event.cause)
reward_has_been_given = true
end
if event.cause.type == "car" then
2019-10-14 20:38:27 +02:00
local player = event.cause.get_driver()
local passenger = event.cause.get_passenger()
2018-12-31 04:47:53 +02:00
if player then insert(players_to_reward, player.player) end
if passenger then insert(players_to_reward, passenger.player) end
reward_has_been_given = true
end
if event.cause.type == "locomotive" then
2019-10-14 20:38:27 +02:00
local train_passengers = event.cause.train.passengers
2018-12-31 04:47:53 +02:00
if train_passengers then
for _, passenger in pairs(train_passengers) do
insert(players_to_reward, passenger)
end
reward_has_been_given = true
end
end
for _, player in pairs(players_to_reward) do
2019-11-11 13:25:27 +02:00
player.insert({name = "coin", count = coin_count})
2018-12-31 04:47:53 +02:00
end
end
if entities_that_earn_coins[event.cause.name] then
2019-11-11 13:25:27 +02:00
event.entity.surface.spill_item_stack(event.cause.position,{name = "coin", count = coin_count}, true)
2018-12-31 04:47:53 +02:00
reward_has_been_given = true
end
end
if reward_has_been_given == false then
2019-11-11 13:25:27 +02:00
event.entity.surface.spill_item_stack(event.entity.position,{name = "coin", count = coin_count}, true)
2018-12-31 04:47:53 +02:00
end
end
event.add(defines.events.on_entity_died, on_entity_died)