Module gamelogic

Functions

new_game (mapSeed, playTutorial, cheats, branch) Starts a new game, and does all the bookkeeping necessary for that.
parse_name_for_level (name) Figures out which level to load based on a given string.
initialize_player (creatureID, class, name, gender, pronouns) Creates the player character entity.
initialize_game () Create the currGame object
initialize_world () Generate stores, factions, and dungeon branches
calc_hit_chance (attacker, target, item) Calculates the chance of hitting an opponent.
calc_attack (attacker, target, forceHit, item) Calculates whether an attacker hits a target, whether it was a critical, and how much damage was done.
advance_turn () Sets the game to advance a turn.
turn_logic () Actually advances the turn, causing NPCs to move, effects and projectiles to advance, the map's lighting to recalculate, creature conditions to do their thing, and the output buffer to clear.
win () This function is called when you win.
game_over () This function is called when you lose.
goToMap (depth, branch, force) Move to another map
regen_map () Regenerates the current map.
generate_boss (silent) Generates the boss for the map.
update_stat (stat_type, id) Update a game statistic (like turns played, creatures killed, etc.).
get_stat (stat_type, id) Get the value of a game statistic (like turns played, creatures killed, etc.)
perform_move (direction) Handle movement keys.
move_player (newX, newY, force, attack_when_zero) Move the player to a new location.
pathTo (x, y, pathAction., noMsg, pathTarget) Find a path from the player's location to a new location, and start the player moving along it.
endPath (aborted) Ends player pathing
setTarget (x, y) Set the player's target, and if targeting an action, apply that action to the target.
perform_target_action (target) Performs whatever action is stored up
player_dies () Called when the player dies.
downtime () Function that causes things to happen during "downtime." What that means and when that happens is up to you, this is just an example.
refresh_player_sight () Refreshes the player's sightmap.
show_tutorial (tutorial) Show a tutorial message
start_mission (missionID, startVal, source, values, skipFunc, noPopup) Starts a mission at 0 and runs its begin() code
get_mission_status (missionID) Gets the status of a given mission.
is_mission_finished (missionID, includeFailure) Returns whether the given mission has been finished
set_mission_status (missionID, value) Sets a the status value of a mission to a specific value.
get_mission_data (missionID, index, includeFinished) Gets the value of an index of a given mission.
set_mission_data (missionID, index, value) Sets a particular index of a mission to a specific value.
update_mission_status (missionID, amt) Updates a mission's status value by a given number value.
finish_mission (missionID, endVal, skipFunc, noPopup) Marks a mission as finished, removing it from the active mission table.
fail_mission (missionID, endVal, skipFunc, noPopup) Marks a mission as failed, removing it from the active mission table.
check_event (eid) Checks whether an event can fire
activate_event (eid, force) Cause an event to run its code
run_all_events_of_type (event_type) Loop through the list of events and activate all eligible ones of a given type
get_money_name (amount) Returns the name of the money


Functions

new_game (mapSeed, playTutorial, cheats, branch)
Starts a new game, and does all the bookkeeping necessary for that. Generates the first map, and puts the player on it.

Parameters:

  • mapSeed Number. The seed to use to generate the world. (optional)
  • playTutorial Boolean. Whether or not to show tutorial messages this game. (optional)
  • cheats Table. A table listing all the cheats in use this game. (optional)
  • branch String. The ID of the branch to start on. (optional)
parse_name_for_level (name)
Figures out which level to load based on a given string. Used for level-skip cheats.

Parameters:

  • name String. If it matches a branch ID, start at that branch
initialize_player (creatureID, class, name, gender, pronouns)
Creates the player character entity.

Parameters:

  • creatureID String. The ID of the creature definition to use to create the player. Optional, defeaults to player_human
  • class String. The ID of the playerclass to apply to the player entity. Optional
  • name String. The name of the new player character. Optional, f blank, will be randomized.
  • gender String. Either "male", "female", "neuter", "other", or "custom". Optional, if blank, will be set to "other" and use they/them pronouns.
  • pronouns Table. A table of custom pronouns. Optional, only needed if using "custom" gender.
initialize_game ()
Create the currGame object
initialize_world ()
Generate stores, factions, and dungeon branches
calc_hit_chance (attacker, target, item)
Calculates the chance of hitting an opponent. *MAY WANT TO CHANGE FOR YOUR OWN GAME*

Parameters:

  • attacker Creature. The creature doing the attacking.
  • target Creature. The creature getting potentially hit
  • item Item. The item the attacker is using.
calc_attack (attacker, target, forceHit, item)
Calculates whether an attacker hits a target, whether it was a critical, and how much damage was done. Important to note: This function just *calculates* the damage, it does not apply it!

Parameters:

  • attacker Creature. The creature attacking.
  • target Creature. The creature getting attacked.
  • forceHit Boolean. Whether to ignore hit chance and force a hit. (optional)
  • item Item. The item the attacker is using, if any. (optional)

Returns:

  1. result String. "hit", "miss", or "critical"
  2. dmg Number. The damage to do.
advance_turn ()
Sets the game to advance a turn. The turn itself will not actually advance until the next update cycle there is nothing with stopsInput set
turn_logic ()
Actually advances the turn, causing NPCs to move, effects and projectiles to advance, the map's lighting to recalculate, creature conditions to do their thing, and the output buffer to clear.
win ()
This function is called when you win. It saves the win for posterity, and blacks out the screen.
game_over ()
This function is called when you lose. It clears out the player and current game variables, and switches back to the main menu.
goToMap (depth, branch, force)
Move to another map

Parameters:

  • depth Number. The depth of the map you're trying to reach
  • branch Text. Which branch the map is on
  • force Boolean. Whether to force the game to go to the map, ignoring whether the boss is dead or not. (optional)
regen_map ()
Regenerates the current map.
generate_boss (silent)
Generates the boss for the map.

Parameters:

  • silent Boolean. If true, don't display any text when generating the boss
update_stat (stat_type, id)
Update a game statistic (like turns played, creatures killed, etc.). Increments the given stat by 1.

Parameters:

  • stat_type String. The stat type to return.
  • id String. The sub-stat type to return (for example, kills of a specific creature type)
get_stat (stat_type, id)
Get the value of a game statistic (like turns played, creatures killed, etc.)

Parameters:

  • stat_type String. The stat type to return.
  • id String. The sub-stat type to return (for example, kills of a specific creature type)
perform_move (direction)
Handle movement keys. If action is set to "targeting" then it'll move the cursor, otherwise it'll move the player.

Parameters:

  • direction String. The keycode of the pressed key.
move_player (newX, newY, force, attack_when_zero)
Move the player to a new location. Also handles warnings for moving into a dangerous area, and advances the turn if the player moves.

Parameters:

  • newX Number. The X-coordinate to move the player to.
  • newY Number. The Y-coordinate to move the player to.
  • force Boolean. Whether to ignore warnings and move the player into a potentially dangerous tile. (optional)
  • attack_when_zero Boolean. if true, attack a feature even if damage is zero

Returns:

    Boolean. Whether the move was successful or not.
pathTo (x, y, pathAction., noMsg, pathTarget)
Find a path from the player's location to a new location, and start the player moving along it.

Parameters:

  • x Number. The x-coordinate to move to.
  • y Number. The y-coordinate to move to.
  • pathAction. The action to perform at the end of the path. (optional)
  • noMsg Boolean. Whether to suppress the "moving to" notification.
  • pathTarget Entity. A creature, feature, or item. The target of the action at the end of the path. (optional)
endPath (aborted)
Ends player pathing

Parameters:

  • aborted Boolean. If true, did not reach the end of the path
setTarget (x, y)
Set the player's target, and if targeting an action, apply that action to the target. If targeting a tile with a creature, that creature will be the player's target for UI purposes.

Parameters:

  • x Number. The x-coordinate of the target.
  • y Number. The y-coordinate of the target.
perform_target_action (target)
Performs whatever action is stored up

Parameters:

  • target Entity. The target for the action
player_dies ()
Called when the player dies. Starts the screen going black, saves a graveyard file, and updates death statistics.
downtime ()
Function that causes things to happen during "downtime." What that means and when that happens is up to you, this is just an example.
refresh_player_sight ()
Refreshes the player's sightmap. Called every turn, may need to be called if something changes visibility for some reason (new lights or something that blocks sight showing up)
show_tutorial (tutorial)
Show a tutorial message

Parameters:

  • tutorial String. The ID of the tutorial to show.
start_mission (missionID, startVal, source, values, skipFunc, noPopup)
Starts a mission at 0 and runs its begin() code

Parameters:

  • missionID String. The ID of the mission. Can either be a pre-defined mission, or you can use any ad-hoc value if you want to use this to track something that's not an actual mission.
  • startVal Anything. The starting status of the mission (Optional, defaults to 0)
  • source Object. Where the mission came from (Optional)
  • values Table. A table of values to store in the mission table in the format {index=value,index2=value2}
  • skipFunc Boolean. Whether to skip the start() function (assuming the mission actually has one) (Optional)
  • noPopup Boolean. If true, don't show a popup

Returns:

    Anything. Either false if the mission didn't start, the returned value of the start() function if there was one, or true.
get_mission_status (missionID)
Gets the status of a given mission.

Parameters:

  • missionID String. The ID of the mission. Can either be a pre-defined mission, or you can use any ad-hoc value if you want to use this to track something that's not an actual mission.

Returns:

    Anything. The status of the mission.
is_mission_finished (missionID, includeFailure)
Returns whether the given mission has been finished

Parameters:

  • missionID String. The ID of the mission. Can either be a pre-defined mission, or you can use any ad-hoc value if you want to use this to track something that's not an actual mission.
  • includeFailure Boolean. If true, also look at failed missions

Returns:

    Boolean. Whether the mission is finished or not
set_mission_status (missionID, value)
Sets a the status value of a mission to a specific value.

Parameters:

  • missionID String. The ID of the mission. Can either be a pre-defined mission, or you can use any ad-hoc value if you want to use this to track something that's not a pre-defined mission.
  • value Anything. The value you'd like to store.
get_mission_data (missionID, index, includeFinished)
Gets the value of an index of a given mission.

Parameters:

  • missionID String. The ID of the mission. Can either be a pre-defined mission, or you can use any ad-hoc value if you want to use this to track something that's not a pre-defined mission.
  • index String. The string that used as the index to search
  • includeFinished Boolean. If true, look at mission data for finished missions too

Returns:

    Anything. The value stored in the index given
set_mission_data (missionID, index, value)
Sets a particular index of a mission to a specific value.

Parameters:

  • missionID String. The ID of the mission. Can either be a pre-defined mission, or you can use any ad-hoc value if you want to use this to track something that's not an actual mission.
  • index String. The string that will be used as the index to store this value
  • value Anything. The value you'd like to store.
update_mission_status (missionID, amt)
Updates a mission's status value by a given number value. Generally, you should inly call this function on a mission that's already has number values as it status. If you don't, though, it'll just set the mission status to whatever the number you passed.

Parameters:

  • missionID String. The ID of the mission. Can either be a pre-defined mission, or you can use any ad-hoc value if you want to use this to track something that's not an actual mission.
  • amt Number. The amount to increase the status by. (optional, defaults to 1)
finish_mission (missionID, endVal, skipFunc, noPopup)
Marks a mission as finished, removing it from the active mission table. Also runs the mission's finish() code if it's a pre-defined mission.

Parameters:

  • missionID String. The ID of the mission. Can either be a pre-defined mission, or you can use any ad-hoc value if you want to use this to track something that's not an actual mission.
  • endVal Anything. A value you want to store in the finished missions table (eg to determine how the mission ended if it has multiple endings). (Optional)
  • skipFunc Boolean. Whether to skip the finish() function (assuming the mission actually has one) (Optional)
  • noPopup Boolean. if true, don't show a popup

Returns:

    Anything. Either false if the mission didn't end, the returned value of the finish() function if there was one, or true.
fail_mission (missionID, endVal, skipFunc, noPopup)
Marks a mission as failed, removing it from the active mission table. Also runs the mission's fail() code if it's a pre-defined mission.

Parameters:

  • missionID String. The ID of the mission. Can either be a pre-defined mission, or you can use any ad-hoc value if you want to use this to track something that's not an actual mission.
  • endVal Anything. A value you want to store in the finished missions table (eg to determine how the mission ended if it has multiple endings). (Optional)
  • skipFunc Boolean. Whether to skip the fail() function (assuming the mission actually has one) (Optional)
  • noPopup Boolean. If true, don't show a popup

Returns:

    Anything. Either false if the mission didn't fail, the returned value of the fail() function if there was one, or true.
check_event (eid)
Checks whether an event can fire

Parameters:

  • eid Number. The ID of the event

Returns:

    Boolean. Whether or not the event can fire
activate_event (eid, force)
Cause an event to run its code

Parameters:

  • eid Number. The event ID
  • force Boolean. Whether to ignore the requires() code for the event
run_all_events_of_type (event_type)
Loop through the list of events and activate all eligible ones of a given type

Parameters:

  • event_type Text. The type of event. Possible event types: enter_map, enter_map_first_time, random, player_kills, boss_dies
get_money_name (amount)
Returns the name of the money

Parameters:

  • amount Number. The amount of money

Returns:

    Text. The name of the money
generated by LDoc 1.5.0 Last updated 2025-05-24 09:49:55