Factorio: Inventory Spill Traps (#4457)
This commit is contained in:
parent
90417e0022
commit
8622cb6204
|
@ -304,6 +304,11 @@ class EvolutionTrapIncrease(Range):
|
|||
range_end = 100
|
||||
|
||||
|
||||
class InventorySpillTrapCount(TrapCount):
|
||||
"""Trap items that when received trigger dropping your main inventory and trash inventory onto the ground."""
|
||||
display_name = "Inventory Spill Traps"
|
||||
|
||||
|
||||
class FactorioWorldGen(OptionDict):
|
||||
"""World Generation settings. Overview of options at https://wiki.factorio.com/Map_generator,
|
||||
with in-depth documentation at https://lua-api.factorio.com/latest/Concepts.html#MapGenSettings"""
|
||||
|
@ -484,6 +489,7 @@ class FactorioOptions(PerGameCommonOptions):
|
|||
artillery_traps: ArtilleryTrapCount
|
||||
atomic_rocket_traps: AtomicRocketTrapCount
|
||||
atomic_cliff_remover_traps: AtomicCliffRemoverTrapCount
|
||||
inventory_spill_traps: InventorySpillTrapCount
|
||||
attack_traps: AttackTrapCount
|
||||
evolution_traps: EvolutionTrapCount
|
||||
evolution_trap_increase: EvolutionTrapIncrease
|
||||
|
@ -518,6 +524,7 @@ option_groups: list[OptionGroup] = [
|
|||
ArtilleryTrapCount,
|
||||
AtomicRocketTrapCount,
|
||||
AtomicCliffRemoverTrapCount,
|
||||
InventorySpillTrapCount,
|
||||
],
|
||||
start_collapsed=True
|
||||
),
|
||||
|
|
|
@ -78,6 +78,7 @@ all_items["Cluster Grenade Trap"] = factorio_base_id - 5
|
|||
all_items["Artillery Trap"] = factorio_base_id - 6
|
||||
all_items["Atomic Rocket Trap"] = factorio_base_id - 7
|
||||
all_items["Atomic Cliff Remover Trap"] = factorio_base_id - 8
|
||||
all_items["Inventory Spill Trap"] = factorio_base_id - 9
|
||||
|
||||
|
||||
class Factorio(World):
|
||||
|
@ -112,6 +113,8 @@ class Factorio(World):
|
|||
science_locations: typing.List[FactorioScienceLocation]
|
||||
removed_technologies: typing.Set[str]
|
||||
settings: typing.ClassVar[FactorioSettings]
|
||||
trap_names: tuple[str] = ("Evolution", "Attack", "Teleport", "Grenade", "Cluster Grenade", "Artillery",
|
||||
"Atomic Rocket", "Atomic Cliff Remover", "Inventory Spill")
|
||||
|
||||
def __init__(self, world, player: int):
|
||||
super(Factorio, self).__init__(world, player)
|
||||
|
@ -136,15 +139,11 @@ class Factorio(World):
|
|||
random = self.random
|
||||
nauvis = Region("Nauvis", player, self.multiworld)
|
||||
|
||||
location_count = len(base_tech_table) - len(useless_technologies) - self.skip_silo + \
|
||||
self.options.evolution_traps + \
|
||||
self.options.attack_traps + \
|
||||
self.options.teleport_traps + \
|
||||
self.options.grenade_traps + \
|
||||
self.options.cluster_grenade_traps + \
|
||||
self.options.atomic_rocket_traps + \
|
||||
self.options.atomic_cliff_remover_traps + \
|
||||
self.options.artillery_traps
|
||||
location_count = len(base_tech_table) - len(useless_technologies) - self.skip_silo
|
||||
|
||||
for name in self.trap_names:
|
||||
name = name.replace(" ", "_").lower()+"_traps"
|
||||
location_count += getattr(self.options, name)
|
||||
|
||||
location_pool = []
|
||||
|
||||
|
@ -196,9 +195,8 @@ class Factorio(World):
|
|||
def create_items(self) -> None:
|
||||
self.custom_technologies = self.set_custom_technologies()
|
||||
self.set_custom_recipes()
|
||||
traps = ("Evolution", "Attack", "Teleport", "Grenade", "Cluster Grenade", "Artillery", "Atomic Rocket",
|
||||
"Atomic Cliff Remover")
|
||||
for trap_name in traps:
|
||||
|
||||
for trap_name in self.trap_names:
|
||||
self.multiworld.itempool.extend(self.create_item(f"{trap_name} Trap") for _ in
|
||||
range(getattr(self.options,
|
||||
f"{trap_name.lower().replace(' ', '_')}_traps")))
|
||||
|
|
|
@ -48,3 +48,40 @@ function fire_entity_at_entities(entity_name, entities, speed)
|
|||
target=target, speed=speed}
|
||||
end
|
||||
end
|
||||
|
||||
function spill_character_inventory(character)
|
||||
if not (character and character.valid) then
|
||||
return false
|
||||
end
|
||||
|
||||
-- grab attrs once pre-loop
|
||||
local position = character.position
|
||||
local surface = character.surface
|
||||
|
||||
local inventories_to_spill = {
|
||||
defines.inventory.character_main, -- Main inventory
|
||||
defines.inventory.character_trash, -- Logistic trash slots
|
||||
}
|
||||
|
||||
for _, inventory_type in pairs(inventories_to_spill) do
|
||||
local inventory = character.get_inventory(inventory_type)
|
||||
if inventory and inventory.valid then
|
||||
-- Spill each item stack onto the ground
|
||||
for i = 1, #inventory do
|
||||
local stack = inventory[i]
|
||||
if stack and stack.valid_for_read then
|
||||
local spilled_items = surface.spill_item_stack{
|
||||
position = position,
|
||||
stack = stack,
|
||||
enable_looted = false, -- do not mark for auto-pickup
|
||||
force = nil, -- do not mark for auto-deconstruction
|
||||
allow_belts = true, -- do mark for putting it onto belts
|
||||
}
|
||||
if #spilled_items > 0 then
|
||||
stack.clear() -- only delete if spilled successfully
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -750,6 +750,11 @@ end,
|
|||
fire_entity_at_entities("atomic-rocket", {cliffs[math.random(#cliffs)]}, 0.1)
|
||||
end
|
||||
end,
|
||||
["Inventory Spill Trap"] = function ()
|
||||
for _, player in ipairs(game.forces["player"].players) do
|
||||
spill_character_inventory(player.character)
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
commands.add_command("ap-get-technology", "Grant a technology, used by the Archipelago Client.", function(call)
|
||||
|
|
Loading…
Reference in New Issue