Traps and Buildings
Traps
Save this out as __init__.py
in your mod folder, and you’ve got a mod that adds a trap:
from faust.Building import Building, TrapBuilding
from faust.Constant import del_constant
def init():
TrapBuilding(
building_id='belly_poker',
name='Belly Poker',
desc='This is the description in the buildings table.',
entrap_desc='{attacker.name} can barely gurgle "Aww, beans", before {attacker.hes} fatally poked in the belly.')
def deinit():
del_constant('building.belly_poker0')
How does it work?
The init() code runs when the player enables your mod in the mod menu (or on game start if you’ve enabled it previously), and the deinit() code runs when the player disables it.
If you have programming experience, you may be wondering, “Wait a minute, you made that TrapBuilding but you didn’t file it anywhere. How’s the GUI find it again?” Buildings are ConstantMixins, so they automatically register themselves in the constant registry. Then the GUI can come along later and search for every constant with an ID that starts with building.
. Other classes do require explicit filing though, like adding a transformation to a Tome.
Other kinds of Buildings
from faust.Building import Building, TrapBuilding
from faust.Constant import del_constant, get_constant
def init():
def on_building_install(building, response, player):
# You could run pretty much anything in here
# but here we'll raise the protagonist's research rate
player.doms[0].innate_research += 1 # Add one to the value
return response
def am_i_unlocked(building, player):
# If this is a quest reward, you'd check the quest stage here
return True
my_building = Building('brain_jar',
level=0,
name='Brain Jar',
desc='This is the description in the buildings table.',
effect_desc="This is the description before you've bought it.",
price=80, upkeep=2,
install_fn=on_building_install,
is_unlocked_fn=am_i_unlocked) # Optional, if you omit this parameter it'll always be available
def deinit():
del_constant('building.brain_jar0')
The level parameter that’s set to zero is used if you want a sequence of buildings that unlock one by one, like the housing upgrades. You give them consecutive level numbers, and then they check that the number below is installed. If you’re not interested in doing that, just set it to zero.