Factorio: Inventory Spill Traps (#4457)
This commit is contained in:
parent
90417e0022
commit
8622cb6204
|
@ -304,6 +304,11 @@ class EvolutionTrapIncrease(Range):
|
||||||
range_end = 100
|
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):
|
class FactorioWorldGen(OptionDict):
|
||||||
"""World Generation settings. Overview of options at https://wiki.factorio.com/Map_generator,
|
"""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"""
|
with in-depth documentation at https://lua-api.factorio.com/latest/Concepts.html#MapGenSettings"""
|
||||||
|
@ -484,6 +489,7 @@ class FactorioOptions(PerGameCommonOptions):
|
||||||
artillery_traps: ArtilleryTrapCount
|
artillery_traps: ArtilleryTrapCount
|
||||||
atomic_rocket_traps: AtomicRocketTrapCount
|
atomic_rocket_traps: AtomicRocketTrapCount
|
||||||
atomic_cliff_remover_traps: AtomicCliffRemoverTrapCount
|
atomic_cliff_remover_traps: AtomicCliffRemoverTrapCount
|
||||||
|
inventory_spill_traps: InventorySpillTrapCount
|
||||||
attack_traps: AttackTrapCount
|
attack_traps: AttackTrapCount
|
||||||
evolution_traps: EvolutionTrapCount
|
evolution_traps: EvolutionTrapCount
|
||||||
evolution_trap_increase: EvolutionTrapIncrease
|
evolution_trap_increase: EvolutionTrapIncrease
|
||||||
|
@ -518,6 +524,7 @@ option_groups: list[OptionGroup] = [
|
||||||
ArtilleryTrapCount,
|
ArtilleryTrapCount,
|
||||||
AtomicRocketTrapCount,
|
AtomicRocketTrapCount,
|
||||||
AtomicCliffRemoverTrapCount,
|
AtomicCliffRemoverTrapCount,
|
||||||
|
InventorySpillTrapCount,
|
||||||
],
|
],
|
||||||
start_collapsed=True
|
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["Artillery Trap"] = factorio_base_id - 6
|
||||||
all_items["Atomic Rocket Trap"] = factorio_base_id - 7
|
all_items["Atomic Rocket Trap"] = factorio_base_id - 7
|
||||||
all_items["Atomic Cliff Remover Trap"] = factorio_base_id - 8
|
all_items["Atomic Cliff Remover Trap"] = factorio_base_id - 8
|
||||||
|
all_items["Inventory Spill Trap"] = factorio_base_id - 9
|
||||||
|
|
||||||
|
|
||||||
class Factorio(World):
|
class Factorio(World):
|
||||||
|
@ -112,6 +113,8 @@ class Factorio(World):
|
||||||
science_locations: typing.List[FactorioScienceLocation]
|
science_locations: typing.List[FactorioScienceLocation]
|
||||||
removed_technologies: typing.Set[str]
|
removed_technologies: typing.Set[str]
|
||||||
settings: typing.ClassVar[FactorioSettings]
|
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):
|
def __init__(self, world, player: int):
|
||||||
super(Factorio, self).__init__(world, player)
|
super(Factorio, self).__init__(world, player)
|
||||||
|
@ -136,15 +139,11 @@ class Factorio(World):
|
||||||
random = self.random
|
random = self.random
|
||||||
nauvis = Region("Nauvis", player, self.multiworld)
|
nauvis = Region("Nauvis", player, self.multiworld)
|
||||||
|
|
||||||
location_count = len(base_tech_table) - len(useless_technologies) - self.skip_silo + \
|
location_count = len(base_tech_table) - len(useless_technologies) - self.skip_silo
|
||||||
self.options.evolution_traps + \
|
|
||||||
self.options.attack_traps + \
|
for name in self.trap_names:
|
||||||
self.options.teleport_traps + \
|
name = name.replace(" ", "_").lower()+"_traps"
|
||||||
self.options.grenade_traps + \
|
location_count += getattr(self.options, name)
|
||||||
self.options.cluster_grenade_traps + \
|
|
||||||
self.options.atomic_rocket_traps + \
|
|
||||||
self.options.atomic_cliff_remover_traps + \
|
|
||||||
self.options.artillery_traps
|
|
||||||
|
|
||||||
location_pool = []
|
location_pool = []
|
||||||
|
|
||||||
|
@ -196,9 +195,8 @@ class Factorio(World):
|
||||||
def create_items(self) -> None:
|
def create_items(self) -> None:
|
||||||
self.custom_technologies = self.set_custom_technologies()
|
self.custom_technologies = self.set_custom_technologies()
|
||||||
self.set_custom_recipes()
|
self.set_custom_recipes()
|
||||||
traps = ("Evolution", "Attack", "Teleport", "Grenade", "Cluster Grenade", "Artillery", "Atomic Rocket",
|
|
||||||
"Atomic Cliff Remover")
|
for trap_name in self.trap_names:
|
||||||
for trap_name in traps:
|
|
||||||
self.multiworld.itempool.extend(self.create_item(f"{trap_name} Trap") for _ in
|
self.multiworld.itempool.extend(self.create_item(f"{trap_name} Trap") for _ in
|
||||||
range(getattr(self.options,
|
range(getattr(self.options,
|
||||||
f"{trap_name.lower().replace(' ', '_')}_traps")))
|
f"{trap_name.lower().replace(' ', '_')}_traps")))
|
||||||
|
|
|
@ -48,3 +48,40 @@ function fire_entity_at_entities(entity_name, entities, speed)
|
||||||
target=target, speed=speed}
|
target=target, speed=speed}
|
||||||
end
|
end
|
||||||
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)
|
fire_entity_at_entities("atomic-rocket", {cliffs[math.random(#cliffs)]}, 0.1)
|
||||||
end
|
end
|
||||||
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)
|
commands.add_command("ap-get-technology", "Grant a technology, used by the Archipelago Client.", function(call)
|
||||||
|
|
Loading…
Reference in New Issue