mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-14 15:24:52 +09:00
Raise the main inventory only by the armor equipment's bonus
The raise covered the whole gap between the serialized main inventory and the main inventory with the armor restored, but only the bonus of the armor's equipment arrives at the end of the tick. When the destination force has a smaller character_inventory_slots_bonus than the source, the rest of the gap never arrived and removing the raise on the armor event dropped those slots on the ground. The raise is now the equipment's inventory bonus minus what the grid already applies, at most the gap, and the slots past it overflow into a corpse as without the raise. Factorio 1.1 has no inventory bonus equipment and gets no raise. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
4228b40562
commit
916b57b37c
1 file changed
+13
-4
@@ -10,6 +10,7 @@ local v2_storage_api = compat.version_ge("2.0.0")
|
||||
local v2_remote_controller = compat.version_ge("2.0.0")
|
||||
local v2_space_platform = compat.version_ge("2.0.0")
|
||||
local v2_exit_remote_view = compat.version_ge("2.0.56")
|
||||
local v2_inventory_bonus_equipment = compat.version_ge("2.0.0")
|
||||
local recipe_notifications_api = compat.version_ge("2.0.67")
|
||||
local v2_0_quick_bar_api = compat.version_ge("2.0.0")
|
||||
local v2_1_quick_bar_api = compat.version_ge("2.1.0")
|
||||
@@ -82,10 +83,17 @@ local function last_slot_index(serialized)
|
||||
return last
|
||||
end
|
||||
|
||||
--- Raise the inventory bonus of a character with its armor restored to fit a serialized main inventory
|
||||
--- Raise the inventory bonus of a character with its armor restored by the bonus of the armor's equipment which is
|
||||
--- still to come, as far as a serialized main inventory needs it
|
||||
--- @return integer raise Slots added to character_inventory_slots_bonus, removed again once the armor's bonus applies
|
||||
local function raise_inventory_bonus(character, main)
|
||||
local raise = math.max(0, last_slot_index(main) - #character.get_main_inventory())
|
||||
local grid = character.grid --[[@as LuaEquipmentGrid]]
|
||||
local equipment_bonus = 0
|
||||
for _, equipment in pairs(grid.equipment) do
|
||||
equipment_bonus = equipment_bonus + equipment.inventory_bonus
|
||||
end
|
||||
local delayed = equipment_bonus - grid.inventory_bonus
|
||||
local raise = math.max(0, math.min(last_slot_index(main) - #character.get_main_inventory(), delayed))
|
||||
character.character_inventory_slots_bonus = character.character_inventory_slots_bonus + raise
|
||||
return raise
|
||||
end
|
||||
@@ -1387,12 +1395,13 @@ function serialize.deserialize_player(player, serialized, components, local_cont
|
||||
end
|
||||
local craft = character and queue
|
||||
-- The bonus of the armor's equipment (toolbelts) only applies at the end of the tick, so once the armor is
|
||||
-- restored the main inventory is raised to fit the data. Only for armor with a grid, restoring it raises
|
||||
-- restored the main inventory is raised by the part of that bonus still to come. Slots past it overflow and
|
||||
-- are left over as without the raise. Only for armor with a grid, restoring it raises
|
||||
-- on_player_armor_inventory_changed which removes the raise.
|
||||
spill = serialize.place_items(
|
||||
serialize.item_destinations(player), inventories, not craft and queue and queue.ingredients or nil,
|
||||
function()
|
||||
if stats and inventories.main and character and character.grid then
|
||||
if v2_inventory_bonus_equipment and stats and inventories.main and character and character.grid then
|
||||
inventory_bonus_raise = raise_inventory_bonus(character, inventories.main)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user