mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-10 00:43:27 +02:00
Merge pull request #139 from Agocelt/Inventory-fullness-flying-text
Turning fullness warning into flying text
This commit is contained in:
commit
65df3c76d7
@ -16,6 +16,7 @@ Global.register(
|
|||||||
local Public = {}
|
local Public = {}
|
||||||
local random = math.random
|
local random = math.random
|
||||||
local ceil = math.ceil
|
local ceil = math.ceil
|
||||||
|
local floor = math.floor
|
||||||
|
|
||||||
local function is_player_warned(player, reset)
|
local function is_player_warned(player, reset)
|
||||||
if reset and this.warned[player.index] then
|
if reset and this.warned[player.index] then
|
||||||
@ -31,12 +32,13 @@ local function is_player_warned(player, reset)
|
|||||||
return this.warned[player.index]
|
return this.warned[player.index]
|
||||||
end
|
end
|
||||||
|
|
||||||
local function compute_fullness(player)
|
local function compute_fullness(player, position)
|
||||||
if not player.mining_state.mining then
|
if not player.mining_state.mining then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local warn_player = is_player_warned(player)
|
local warn_player = is_player_warned(player)
|
||||||
local free_slots = player.get_main_inventory().count_empty_stacks()
|
local free_slots = player.get_main_inventory().count_empty_stacks()
|
||||||
|
local inventory_size = #player.get_main_inventory()
|
||||||
if free_slots == 0 or free_slots == 1 then
|
if free_slots == 0 or free_slots == 1 then
|
||||||
if player.character and player.character.valid then
|
if player.character and player.character.valid then
|
||||||
local damage = ceil((warn_player.count / 2) * warn_player.count)
|
local damage = ceil((warn_player.count / 2) * warn_player.count)
|
||||||
@ -48,7 +50,14 @@ local function compute_fullness(player)
|
|||||||
'Just a fleshwound.',
|
'Just a fleshwound.',
|
||||||
'Better keep those hands to yourself or you might loose them.'
|
'Better keep those hands to yourself or you might loose them.'
|
||||||
}
|
}
|
||||||
player.print(messages[random(1, #messages)], {r = 0.75, g = 0.0, b = 0.0})
|
player.surface.create_entity(
|
||||||
|
{
|
||||||
|
name = 'flying-text',
|
||||||
|
position = {position.x, position.y + 0.6},
|
||||||
|
text = messages[random(1, #messages)],
|
||||||
|
color = {r = 0.75, g = 0.0, b = 0.0}
|
||||||
|
}
|
||||||
|
)
|
||||||
else
|
else
|
||||||
player.character.die('enemy')
|
player.character.die('enemy')
|
||||||
is_player_warned(player, true)
|
is_player_warned(player, true)
|
||||||
@ -59,12 +68,24 @@ local function compute_fullness(player)
|
|||||||
else
|
else
|
||||||
is_player_warned(player, true)
|
is_player_warned(player, true)
|
||||||
end
|
end
|
||||||
|
if free_slots > 1 then
|
||||||
|
if floor(inventory_size / free_slots) == 10 then -- When player has 10% free slots
|
||||||
|
player.surface.create_entity(
|
||||||
|
{
|
||||||
|
name = 'flying-text',
|
||||||
|
position = {position.x, position.y + 0.6},
|
||||||
|
text = 'You are feeling heavy',
|
||||||
|
color = {r = 1.0, g = 0.5, b = 0.0}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
return free_slots
|
return free_slots
|
||||||
end
|
end
|
||||||
|
|
||||||
function Public.check_fullness(player)
|
function Public.check_fullness(player, position)
|
||||||
if this.fullness_enabled then
|
if this.fullness_enabled then
|
||||||
local fullness = compute_fullness(player)
|
local fullness = compute_fullness(player, position)
|
||||||
if fullness == 0 then
|
if fullness == 0 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -107,7 +128,8 @@ Event.add(
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
check_fullness(player)
|
local position = event.entity.position
|
||||||
|
check_fullness(player, position)
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user