mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-10 00:43:27 +02:00
Merge pull request #6 from ComfyFactory/planet_prison_fix_v5
Planet prison fix v5
This commit is contained in:
commit
5f78cf907b
@ -14,6 +14,7 @@ local Timers = require 'maps.planet_prison.mod.timers'
|
||||
local ClaimsFunctions = require 'maps.planet_prison.mod.claims'
|
||||
local MapConfig = require 'maps.planet_prison.config'
|
||||
local Token = require 'utils.token'
|
||||
require 'modules.thirst'
|
||||
|
||||
local this = {}
|
||||
local floor = math.floor
|
||||
@ -74,8 +75,8 @@ this.maps = {
|
||||
},
|
||||
{
|
||||
name = 'swampy-rivers',
|
||||
height = 1500,
|
||||
width = 1500,
|
||||
height = 2500,
|
||||
width = 2500,
|
||||
water = 1,
|
||||
terrain_segmentation = 6,
|
||||
property_expression_names = {
|
||||
@ -116,6 +117,15 @@ this.maps = {
|
||||
}
|
||||
}
|
||||
|
||||
local function assign_perks(player)
|
||||
this.perks[player.name] = {
|
||||
flashlight_enable = true,
|
||||
minimap = false,
|
||||
chat_global = true
|
||||
}
|
||||
return this.perks[player.name]
|
||||
end
|
||||
|
||||
local assign_camouflage = function(ent, common)
|
||||
local shade = common.rand_range(20, 200)
|
||||
ent.color = {
|
||||
@ -315,7 +325,8 @@ local swampy_rivers_layers = {
|
||||
name = 'hostile',
|
||||
objects = {
|
||||
'character',
|
||||
'gun-turret'
|
||||
'gun-turret',
|
||||
'small-biter'
|
||||
},
|
||||
elevation = 0.92,
|
||||
resolution = 0.99,
|
||||
@ -358,14 +369,19 @@ local function find_force(name)
|
||||
return nil
|
||||
end
|
||||
|
||||
local function init_player_ship_bp(entity, player)
|
||||
entity.force = player.force
|
||||
if entity.name == 'crash-site-chest-1' then
|
||||
for _, stack in pairs(MapConfig.player_ship_loot) do
|
||||
entity.insert(stack)
|
||||
local init_player_ship_bp =
|
||||
Token.register(
|
||||
function(data)
|
||||
local player = data.player
|
||||
local entity = data.entity
|
||||
entity.force = player.force
|
||||
if entity.name == 'crash-site-chest-1' then
|
||||
for _, stack in pairs(MapConfig.player_ship_loot) do
|
||||
entity.insert(stack)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
this.events = {
|
||||
merchant = {
|
||||
@ -377,18 +393,23 @@ this.events = {
|
||||
offer = MapConfig.merchant_offer
|
||||
}
|
||||
}
|
||||
local function init_merchant_bp(entity, _)
|
||||
entity.force = 'merchant'
|
||||
entity.rotatable = false
|
||||
entity.minable = false
|
||||
if entity.name ~= 'market' then
|
||||
entity.operable = false
|
||||
else
|
||||
for _, entry in pairs(this.events.merchant.offer) do
|
||||
entity.add_market_item(entry)
|
||||
|
||||
local init_merchant_bp =
|
||||
Token.register(
|
||||
function(data)
|
||||
local entity = data.entity
|
||||
entity.force = 'merchant'
|
||||
entity.rotatable = false
|
||||
entity.minable = false
|
||||
if entity.name ~= 'market' then
|
||||
entity.operable = false
|
||||
else
|
||||
for _, entry in pairs(this.events.merchant.offer) do
|
||||
entity.add_market_item(entry)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
local function create_orbit_group()
|
||||
local orbit = game.permissions.create_group('orbit')
|
||||
@ -424,7 +445,7 @@ local function init_game()
|
||||
create_orbit_group()
|
||||
game.map_settings.pollution.enabled = false
|
||||
game.map_settings.enemy_evolution.enabled = false
|
||||
game.difficulty_settings.technology_price_multiplier = 0.1
|
||||
game.difficulty_settings.technology_price_multiplier = 0.3
|
||||
game.difficulty_settings.research_queue_setting = 'always'
|
||||
|
||||
LayersFunctions.set_collision_mask({'water-tile'})
|
||||
@ -593,6 +614,9 @@ end
|
||||
|
||||
local function draw_common_gui(player)
|
||||
local perks = this.perks[player.name]
|
||||
if not perks then
|
||||
perks = assign_perks(player)
|
||||
end
|
||||
local chat_type = 'Global chat'
|
||||
if not perks.chat_global then
|
||||
chat_type = 'NAP chat'
|
||||
@ -635,10 +659,13 @@ end
|
||||
local function print_merchant_position(player)
|
||||
local position = this.events.merchant.position
|
||||
local perks = this.perks[player.name]
|
||||
if not perks.minimap then
|
||||
player.print(string.format('>> You were able to spot him %s from your location', CommonFunctions.get_readable_direction(player.position, position)))
|
||||
else
|
||||
if not perks then
|
||||
perks = assign_perks(player)
|
||||
end
|
||||
if perks and perks.minimap then
|
||||
player.print(string.format('>> You received a broadcast with [gps=%d,%d] coordinates', position.x, position.y))
|
||||
else
|
||||
player.print(string.format('>> You were able to spot him %s from your location', CommonFunctions.get_readable_direction(player.position, position)))
|
||||
end
|
||||
end
|
||||
|
||||
@ -696,6 +723,9 @@ local function on_gui_click(e)
|
||||
local elem = e.element
|
||||
local p = game.players[e.player_index]
|
||||
local perks = this.perks[p.name]
|
||||
if not perks then
|
||||
perks = assign_perks(p)
|
||||
end
|
||||
|
||||
if not elem.valid then
|
||||
return
|
||||
@ -756,7 +786,12 @@ local function init_player(p)
|
||||
this.perks[p.name] = nil
|
||||
p.teleport(position, 'arena')
|
||||
--p.name = get_random_name() --player name is read only
|
||||
p.force = game.create_force(p.name)
|
||||
local pf = game.forces[p.force.name]
|
||||
if not pf then
|
||||
p.force = game.create_force(p.name)
|
||||
else
|
||||
p.force = pf
|
||||
end
|
||||
p.force.set_friend('neutral', true)
|
||||
this.perks[p.name] = {
|
||||
flashlight_enable = true,
|
||||
@ -764,6 +799,16 @@ local function init_player(p)
|
||||
chat_global = true
|
||||
}
|
||||
|
||||
for i = 1, 7 do
|
||||
p.force.technologies['inserter-capacity-bonus-' .. i].enabled = false
|
||||
p.force.technologies['inserter-capacity-bonus-' .. i].researched = false
|
||||
end
|
||||
|
||||
if not p.character or not p.character.valid then
|
||||
p.set_controller({type = defines.controllers.god})
|
||||
p.create_character()
|
||||
end
|
||||
|
||||
local merch = find_force('merchant')
|
||||
if merch then
|
||||
p.force.set_friend(merch, true)
|
||||
@ -1189,7 +1234,15 @@ local function on_player_died(e)
|
||||
|
||||
local p = game.players[index]
|
||||
ClaimsFunctions.on_player_died(p)
|
||||
game.merge_forces(p.name, 'neutral')
|
||||
ClaimsFunctions.clear_player_base(p)
|
||||
|
||||
if game.forces[p.name] then
|
||||
game.merge_forces(p.name, 'neutral')
|
||||
end
|
||||
if p.connected then
|
||||
return
|
||||
end
|
||||
game.remove_offline_players({p})
|
||||
end
|
||||
|
||||
local function on_player_respawned(e)
|
||||
@ -1455,6 +1508,9 @@ local function on_market_item_purchased(e)
|
||||
local m = e.market
|
||||
local o = m.get_market_items()[e.offer_index].offer
|
||||
local perks = this.perks[p.name]
|
||||
if not perks then
|
||||
perks = assign_perks(p)
|
||||
end
|
||||
|
||||
if o.effect_description == 'Construct a GPS receiver' then
|
||||
perks.minimap = true
|
||||
@ -1513,7 +1569,10 @@ local function on_console_chat(e)
|
||||
for _, peer in pairs(game.players) do
|
||||
if peer.name ~= p.name then
|
||||
local perks = this.perks[peer.name]
|
||||
if perks.minimap then
|
||||
if not perks then
|
||||
perks = assign_perks(peer)
|
||||
end
|
||||
if perks and perks.minimap then
|
||||
peer.print(msg)
|
||||
else
|
||||
peer.print(filter_out_gps(msg))
|
||||
@ -1526,7 +1585,10 @@ local function on_console_chat(e)
|
||||
local peer = f.players[1]
|
||||
if peer.name ~= p.name then
|
||||
local perks = this.perks[peer.name]
|
||||
if perks.minimap then
|
||||
if not perks then
|
||||
perks = assign_perks(peer)
|
||||
end
|
||||
if perks and perks.minimap then
|
||||
peer.print(msg)
|
||||
else
|
||||
peer.print(filter_out_gps(msg))
|
||||
|
@ -1 +1 @@
|
||||
return '{"blueprint":{"icons":[{"signal":{"type":"item","name":"crash-site-spaceship-wreck-medium-1"},"index":1},{"signal":{"type":"item","name":"crash-site-spaceship-wreck-big-1"},"index":2}],"entities":[{"entity_number":1,"name":"crash-site-spaceship-wreck-big-2","position":{"x":3,"y":-3.5}},{"entity_number":2,"name":"crash-site-spaceship-wreck-medium-3","position":{"x":-2,"y":-1}},{"entity_number":3,"name":"crash-site-chest-1","position":{"x":4,"y":-1}},{"entity_number":4,"name":"crash-site-chest-2","position":{"x":-3,"y":3}},{"entity_number":5,"name":"assembling-machine-1","position":{"x":-2,"y":-5},"revoke_minable":"true"}, {"entity_number":6,"name":"small-electric-pole","position":{"x":-4,"y":-6}}, {"entity_number":7,"name":"burner-generator","position":{"x":-6,"y":-6},"fill":{"name":"coal","count":"50"},"revoke_minable":"true"}],"item":"blueprint","version":73019621376}}'
|
||||
return '{"blueprint":{"icons":[{"signal":{"type":"item","name":"crash-site-spaceship-wreck-medium-1"},"index":1},{"signal":{"type":"item","name":"crash-site-spaceship-wreck-big-1"},"index":2}],"entities":[{"entity_number":1,"name":"crash-site-spaceship-wreck-big-2","position":{"x":3,"y":-3.5}},{"entity_number":2,"name":"crash-site-spaceship-wreck-medium-3","position":{"x":-2,"y":-1}},{"entity_number":3,"name":"crash-site-chest-1","position":{"x":4,"y":-1}},{"entity_number":4,"name":"crash-site-chest-2","position":{"x":-3,"y":3}},{"entity_number":5,"name":"assembling-machine-1","position":{"x":-2,"y":-5},"revoke_minable":"true"}, {"entity_number":6,"name":"small-electric-pole","position":{"x":-4,"y":-6}}, {"entity_number":7,"name":"burner-generator","position":{"x":-6,"y":-6},"fill":{"name":"coal","count":"50"},"revoke_minable":"true", "operable":"false"}],"item":"blueprint","version":73019621376}}'
|
||||
|
@ -270,7 +270,7 @@ local function _build_tiles(surf, point, tiles)
|
||||
return _tiles
|
||||
end
|
||||
|
||||
local function _build_entities(surf, point, entities, hook, args)
|
||||
local function _build_entities(surf, point, entities, hook, player)
|
||||
local _entities = {}
|
||||
|
||||
local get_axis = CommonFunctions.get_axis
|
||||
@ -296,10 +296,15 @@ local function _build_entities(surf, point, entities, hook, args)
|
||||
e.minable = false
|
||||
end
|
||||
|
||||
if ent.operable then
|
||||
e.operable = false
|
||||
end
|
||||
|
||||
if hook then
|
||||
local token = Token.get(hook)
|
||||
if token then
|
||||
token(e, args)
|
||||
local data = {player = player, entity = e}
|
||||
token(data)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -84,7 +84,7 @@ local function claim_on_build_entity(ent)
|
||||
end
|
||||
|
||||
if not in_range then
|
||||
claim_new_claim(ent, deps)
|
||||
claim_new_claim(ent)
|
||||
end
|
||||
end
|
||||
|
||||
@ -172,6 +172,23 @@ Public.on_player_died = function(player)
|
||||
this._claims_info[player.name] = nil
|
||||
end
|
||||
|
||||
Public.clear_player_base = function(player)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local position = player.position
|
||||
local x, y = position.x, position.y
|
||||
local entities = player.surface.find_entities_filtered {force = player.force, area = {{x - 50, y - 50}, {x + 50, y + 50}}}
|
||||
|
||||
for i = 1, #entities do
|
||||
local e = entities[i]
|
||||
if e and e.valid then
|
||||
e.destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
get_claims - Get all claims data points for given force.
|
||||
@param f_name - Force name.
|
||||
|
@ -1,116 +1,139 @@
|
||||
--Players will have to carry water barrels or stand next to a water tile, to keep themselves hydrated!
|
||||
|
||||
local Player_modifiers = require "player_modifiers"
|
||||
local math_random = math.random
|
||||
local tooltip = "How thirsty your character is.\nStand next to water,\nor keep water-barrels in your inventory to take a sip."
|
||||
|
||||
local water_tiles = {
|
||||
["water"] = true,
|
||||
["deepwater"] = true,
|
||||
}
|
||||
local Event = require 'utils.event'
|
||||
local Player_modifiers = require 'player_modifiers'
|
||||
local random = math.random
|
||||
local tooltip = 'How thirsty your character is.\nStand next to water,\nor keep water-barrels in your inventory to take a sip.'
|
||||
|
||||
local function update_player_modifiers(player)
|
||||
if global.hydration[player.index] <= 0 then
|
||||
global.hydration[player.index] = 100
|
||||
player.character.die()
|
||||
game.print(player.name .. " forgot to take a sip.")
|
||||
return
|
||||
end
|
||||
if global.hydration[player.index] <= 0 then
|
||||
global.hydration[player.index] = 100
|
||||
player.character.die()
|
||||
game.print(player.name .. ' forgot to take a sip.')
|
||||
return
|
||||
end
|
||||
|
||||
local m = ((global.hydration[player.index] - 100) * 0.01) + 0.2
|
||||
local modifiers = Player_modifiers.get_table()
|
||||
modifiers[player.index].character_mining_speed_modifier["thirst"] = m
|
||||
modifiers[player.index].character_running_speed_modifier["thirst"] = m
|
||||
modifiers[player.index].character_crafting_speed_modifier["thirst"] = m
|
||||
Player_modifiers.update_player_modifiers(player)
|
||||
local m = ((global.hydration[player.index] - 100) * 0.01) + 0.2
|
||||
local modifiers = Player_modifiers.get_table()
|
||||
modifiers[player.index].character_mining_speed_modifier['thirst'] = m
|
||||
modifiers[player.index].character_running_speed_modifier['thirst'] = m
|
||||
modifiers[player.index].character_crafting_speed_modifier['thirst'] = m
|
||||
Player_modifiers.update_player_modifiers(player)
|
||||
end
|
||||
|
||||
local function update_hydration_meter(player)
|
||||
local hydration_meter = player.gui.top.hydration_meter
|
||||
|
||||
if not hydration_meter then
|
||||
global.hydration[player.index] = 100
|
||||
|
||||
hydration_meter = player.gui.top.add({type = "frame", name = "hydration_meter"})
|
||||
hydration_meter.style.padding = 3
|
||||
hydration_meter.tooltip = tooltip
|
||||
|
||||
local label = hydration_meter.add({type = "label", caption = "Hydration:"})
|
||||
label.style.font = "heading-2"
|
||||
label.style.font_color = {125, 125, 255}
|
||||
label.tooltip = tooltip
|
||||
local label = hydration_meter.add({type = "label", caption = 100})
|
||||
label.style.font = "heading-2"
|
||||
label.style.font_color = {175, 175, 175}
|
||||
label.tooltip = tooltip
|
||||
local label = hydration_meter.add({type = "label", caption = "%"})
|
||||
label.style.font = "heading-2"
|
||||
label.style.font_color = {175, 175, 175}
|
||||
label.tooltip = tooltip
|
||||
return
|
||||
end
|
||||
|
||||
hydration_meter.children[2].caption = global.hydration[player.index]
|
||||
local hydration_meter = player.gui.top.hydration_meter
|
||||
|
||||
if not hydration_meter then
|
||||
global.hydration[player.index] = 100
|
||||
|
||||
hydration_meter = player.gui.top.add({type = 'frame', name = 'hydration_meter'})
|
||||
hydration_meter.style.padding = 3
|
||||
hydration_meter.tooltip = tooltip
|
||||
|
||||
local label = hydration_meter.add({type = 'label', caption = 'Hydration:'})
|
||||
label.style.font = 'heading-2'
|
||||
label.style.font_color = {125, 125, 255}
|
||||
label.tooltip = tooltip
|
||||
local label2 = hydration_meter.add({type = 'label', caption = 100})
|
||||
label2.style.font = 'heading-2'
|
||||
label2.style.font_color = {175, 175, 175}
|
||||
label2.tooltip = tooltip
|
||||
local label3 = hydration_meter.add({type = 'label', caption = '%'})
|
||||
label3.style.font = 'heading-2'
|
||||
label3.style.font_color = {175, 175, 175}
|
||||
label3.tooltip = tooltip
|
||||
return
|
||||
end
|
||||
|
||||
hydration_meter.children[2].caption = global.hydration[player.index]
|
||||
end
|
||||
|
||||
local function sip(player)
|
||||
if not global.hydration[player.index] then return end
|
||||
if math_random(1, 4) == 1 then global.hydration[player.index] = global.hydration[player.index] - 1 end
|
||||
if global.hydration[player.index] == 100 then return end
|
||||
|
||||
if player.surface.count_tiles_filtered({name = {"water", "deepwater"}, area = {{player.position.x - 1, player.position.y - 1}, {player.position.x + 1, player.position.y + 1}}}) > 0 then
|
||||
global.hydration[player.index] = global.hydration[player.index] + 20
|
||||
if global.hydration[player.index] > 100 then global.hydration[player.index] = 100 end
|
||||
return
|
||||
end
|
||||
|
||||
if global.hydration[player.index] > 90 then return end
|
||||
|
||||
local inventory = player.get_main_inventory()
|
||||
local removed_count = inventory.remove({name = "water-barrel", count = 1})
|
||||
if removed_count == 0 then return end
|
||||
if not global.hydration[player.index] then
|
||||
return
|
||||
end
|
||||
if random(1, 4) == 1 then
|
||||
global.hydration[player.index] = global.hydration[player.index] - 1
|
||||
end
|
||||
if global.hydration[player.index] == 100 then
|
||||
return
|
||||
end
|
||||
|
||||
global.hydration[player.index] = global.hydration[player.index] + 10
|
||||
player.play_sound{path="utility/armor_insert", volume_modifier=0.9}
|
||||
|
||||
local inserted_count = inventory.insert({name = "empty-barrel", count = 1})
|
||||
if inserted_count > 0 then return end
|
||||
|
||||
player.surface.spill_item_stack(player.position, {name = "empty-barrel", count = 1}, true)
|
||||
if
|
||||
player.surface.count_tiles_filtered(
|
||||
{name = {'water', 'deepwater'}, area = {{player.position.x - 1, player.position.y - 1}, {player.position.x + 1, player.position.y + 1}}}
|
||||
) > 0
|
||||
then
|
||||
global.hydration[player.index] = global.hydration[player.index] + 20
|
||||
if global.hydration[player.index] > 100 then
|
||||
global.hydration[player.index] = 100
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if global.hydration[player.index] > 90 then
|
||||
return
|
||||
end
|
||||
|
||||
local inventory = player.get_main_inventory()
|
||||
local removed_count = inventory.remove({name = 'water-barrel', count = 1})
|
||||
if removed_count == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
global.hydration[player.index] = global.hydration[player.index] + 10
|
||||
player.play_sound {path = 'utility/armor_insert', volume_modifier = 0.9}
|
||||
|
||||
local inserted_count = inventory.insert({name = 'empty-barrel', count = 1})
|
||||
if inserted_count > 0 then
|
||||
return
|
||||
end
|
||||
|
||||
player.surface.spill_item_stack(player.position, {name = 'empty-barrel', count = 1}, true)
|
||||
end
|
||||
|
||||
local function on_player_changed_position(event)
|
||||
if math_random(1, 320) ~= 1 then return end
|
||||
local player = game.players[event.player_index]
|
||||
if not player.character then return end
|
||||
if not player.character.valid then return end
|
||||
if player.vehicle then return end
|
||||
global.hydration[player.index] = global.hydration[player.index] - 1
|
||||
if random(1, 320) ~= 1 then
|
||||
return
|
||||
end
|
||||
local player = game.players[event.player_index]
|
||||
if not player.character then
|
||||
return
|
||||
end
|
||||
if not player.character.valid then
|
||||
return
|
||||
end
|
||||
if player.vehicle then
|
||||
return
|
||||
end
|
||||
global.hydration[player.index] = global.hydration[player.index] - 1
|
||||
end
|
||||
|
||||
local function on_player_died(event)
|
||||
if not global.hydration[event.player_index] then return end
|
||||
global.hydration[event.player_index] = 100
|
||||
if not global.hydration[event.player_index] then
|
||||
return
|
||||
end
|
||||
global.hydration[event.player_index] = 100
|
||||
end
|
||||
|
||||
local function tick()
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if player.character then
|
||||
if player.character.valid then
|
||||
sip(player)
|
||||
update_hydration_meter(player)
|
||||
update_player_modifiers(player)
|
||||
end
|
||||
end
|
||||
end
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if player.character then
|
||||
if player.character.valid then
|
||||
sip(player)
|
||||
update_hydration_meter(player)
|
||||
update_player_modifiers(player)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
global.hydration = {}
|
||||
global.hydration = {}
|
||||
end
|
||||
|
||||
local Event = require 'utils.event'
|
||||
Event.add(defines.events.on_player_changed_position, on_player_changed_position)
|
||||
Event.add(defines.events.on_player_died, on_player_died)
|
||||
Event.on_nth_tick(120, tick)
|
||||
Event.on_init(on_init)
|
||||
Event.on_init(on_init)
|
||||
|
Loading…
Reference in New Issue
Block a user