Encounter
┗> Class
Encounters detail the setup of unique battles in Kristal, from the enemies that appear to the environment and special mechanics.
Encounter files should be placed inside scripts/battle/encounters/
.
Methods
Encounter:addEnemy(enemy: string|EnemyBattler, x: number?, y: number?, : any)
Adds an enemy to the encounter.
@param enemy
— The id of an EnemyBattler
, or an EnemyBattler
instance.
@param ...
— Additional arguments to pass to EnemyBattler:init()
.
Arguments:
enemy: string|EnemyBattler | The id of an |
x: number? | |
y: number? | |
: any | Additional arguments to pass to |
Returns:
1: EnemyBattler |
Encounter:addFlag(flag: string, amount: number?)
Increments a numerical flag by amount
.
@param amount
— (Defaults to 1
)
Arguments:
flag: string | |
amount: number? | (Defaults to |
Returns:
1: number |
Encounter:beforeStateChange(old: string, new: string)
(Override) Called when Battle:setState()
is called.
Changing the state to something other than new
, or returning true
will stop the standard state change code for this state change from occurring.
Arguments:
old: string | |
new: string |
Returns:
1: boolean? |
Encounter:canSwoon(target: PartyBattler)
(Override) Whether a party member can get swooned in this encounter or not.
By default, returns true
for everyone.
@param target
— The current target.
Arguments:
target: PartyBattler | The current target. |
Returns:
1: boolean |
Encounter:createSoul(x: number, y: number, color: table?)
(Override) Creates the soul being used this battle (Called at the start of the first wave) By default, returns the regular (red) soul.
@param x
— The x-coordinate the soul should spawn at.
@param y
— The y-coordinate the soul should spawn at.
@param color
— A custom color for the soul, that should override its default.
Arguments:
x: number | The x-coordinate the soul should spawn at. |
y: number | The y-coordinate the soul should spawn at. |
color: table? | A custom color for the soul, that should override its default. |
Returns:
1: Soul |
Encounter:draw(fade: number)
(Override) Called before anything has been rendered each frame. Usable to draw custom backgrounds for specific encounters.
@param fade
— The opacity of the background when fading in/out of the world.
Arguments:
fade: number | The opacity of the background when fading in/out of the world. |
Encounter:drawBackground(fade: number)
(Override) Called after everything has been rendered each frame. Usable to draw custom effects for specific encounters.
@param fade
— The opacity of the background when fading in/out of the world.
Arguments:
fade: number | The opacity of the background when fading in/out of the world. |
Encounter:getDefeatedEnemies()
@return defeated_enemies
— A table indicating the enemies defeated in battle.
Returns:
defeated_enemies: table | A table indicating the enemies defeated in battle. |
Encounter:getDefendTension(battler: PartyBattler)
Returns the tension gained from defending. Returns 2% if reduced tension, otherwise 16%.
@param battler
— The current battler about to defend.
@return tension
— The tension gained from defending.
Arguments:
battler: PartyBattler | The current battler about to defend. |
Returns:
tension: number | The tension gained from defending. |
Encounter:getDialogueCutscene()
(Override) Called whenever dialogue is about to start, if this returns a value, it will be unpacked and passed
into Battle:startCutscene(...)
, as an alternative to standard dialogue.
Returns:
1: table? |
Encounter:getEncounterText()
(Override) Called to receive the encounter text to be displayed each turn.
(Not called on turn one, getInitialEncounterText
is used instead.)
By default, gets an encounter text from a random enemy, falling back on the encounter's
encounter text if none have encounter text.
@return text
— If a table, you should use [next] to advance the text
@return portrait
— The portrait to show
@return actor
— The actor to use for the text settings (ex. voice, portrait settings)
Returns:
text: string|string[] | If a table, you should use [next] to advance the text |
portrait: string? | The portrait to show |
actor: (string|Actor|PartyBattler|PartyMember)? | The actor to use for the text settings (ex. voice, portrait settings) |
Encounter:getInitialEncounterText()
(Override) Called to receive the initial encounter text to be displayed on the first turn.
(Not called on any other turns unless getEncounterText
can't find any usable text.)
By default, returns the encounter text
.
@return text
— If a table, you should use [next] to advance the text
@return portrait
— The portrait to show
@return actor
— The actor to use for the text settings (ex. voice, portrait settings)
Returns:
text: string|string[] | If a table, you should use [next] to advance the text |
portrait: string? | The portrait to show |
actor: (string|Actor|PartyBattler|PartyMember)? | The actor to use for the text settings (ex. voice, portrait settings) |
Encounter:getNextWaves()
(Override) Retrieves the waves to be used for the next defending phase.
By default, iterates through all active enemies and selects one wave each using EnemyBattler:selectWave()
Returns:
1: Wave[] |
Encounter:getPartyPosition(index: integer)
(Override) Gets the position the party member at index
should stand at in this battle.
@param index
— The index of the party member in Game.battle.party
.
Arguments:
index: integer | The index of the party member in |
Returns:
x: number | |
y: number |
Encounter:getSoulSpawnLocation()
(Override) Gets the position that the soul will appear at when starting waves.
Returns:
x: integer | |
y: integer |
Encounter:getVictoryMoney(money: integer)
@param money
— Current victory money based on normal money calculations
Arguments:
money: integer | Current victory money based on normal money calculations |
Returns:
money: integer? |
Encounter:getVictoryText(text: string, money: integer, xp: integer)
@param text
— Current victory text
@param money
— Money earned on victory
@param xp
— XP earned on victory
Arguments:
text: string | Current victory text |
money: integer | Money earned on victory |
xp: integer | XP earned on victory |
Returns:
text: string? |
Encounter:getVictoryXP(xp: integer)
@param xp
— Current victory xp based on normal xp calculations
Arguments:
xp: integer | Current victory xp based on normal xp calculations |
Returns:
xp: integer? |
Encounter:hasReducedTension()
Checks if the encounter has reduced tension.
@return reduced
— Whether the encounter has reduced tension.
Returns:
reduced: boolean | Whether the encounter has reduced tension. |
Encounter:isAutoHealingEnabled(battler: PartyBattler)
(Override) Whether automatic healing while downed is enabled in this encounter.
By default, returns true
.
@param battler
— The current battler about to auto-heal.
Arguments:
battler: PartyBattler | The current battler about to auto-heal. |
Returns:
1: boolean |
Encounter:onActionSelect(battler: PartyBattler, button: ActionButton)
(Override) Called when an ActionButton
is selected.
Arguments:
battler: PartyBattler |
|
button: ActionButton |
Encounter:onActionsEnd()
(Override) Called when the party finish performing their actions.
Encounter:onActionsStart()
(Override) Called when the party start performing their actions.
Encounter:onBattleEnd()
(Override) Called when the battle is completed and the victory text (if presesnt) is advanced, just before the transition out.
Encounter:onBattleInit()
(Override) Called in Battle:postInit()
.
If this function returns true
, then the battle will not override any state changes made here.
Returns:
1: boolean? |
Encounter:onBattleStart()
(Override) Called when the battle enters the "INTRO"
state and the characters do their starting animations.
Encounter:onCharacterTurn(battler: PartyBattler, undo: boolean)
(Override) Called when a character's turn selecting actions begins.
@param battler
— The battler whose turn it is.
@param undo
— Whether this character's turn was entered by undoing their previously selected action.
Arguments:
battler: PartyBattler | The battler whose turn it is. |
undo: boolean | Whether this character's turn was entered by undoing their previously selected action. |
Encounter:onDialogueEnd()
(Override) Called when enemy dialogue is finished and closed, before the transition into a wave.
Encounter:onEnemyCancel(state_reason: string, enemy_index: integer)
(Override) Called when the player backs out of an enemyselect menu in battle.
@param state_reason
— The current value of Battle.state_reason
@param enemy_index
— The index of the selected enemy on the menu.
Arguments:
state_reason: string | The current value of |
enemy_index: integer | The index of the selected enemy on the menu. |
Encounter:onEnemySelect(state_reason: string, enemy_index: integer)
(Override) Called when the player selects an enemy in battle.
@param state_reason
— The current value of Battle.state_reason
@param enemy_index
— The index of the selected enemy on the menu.
Arguments:
state_reason: string | The current value of |
enemy_index: integer | The index of the selected enemy on the menu. |
Encounter:onGameOver()
(Override) Called just before a Game Over.
If this function returns true
, then the Game Over will not occur
Returns:
1: boolean? |
Encounter:onMenuCancel(state_reason: string, item: table)
(Override) Called when the player backs out of a menu.
@param state_reason
— The current value of Battle.state_reason
@param item
— A table of information representing the menu item that was being hovered over.
Arguments:
state_reason: string | The current value of |
item: table | A table of information representing the menu item that was being hovered over. |
Encounter:onMenuSelect(state_reason: string, item: table, can_select: boolean)
(Override) Called when an item in a menu is selected (confirm key pressed).
@param state_reason
— The current value of Battle.state_reason
@param item
— A table of information representing the menu item.
@param can_select
— Whether the item is actually selectable or is greyed out.
Arguments:
state_reason: string | The current value of |
item: table | A table of information representing the menu item. |
can_select: boolean | Whether the item is actually selectable or is greyed out. |
Encounter:onPartyCancel(state_reason: string, party_index: number)
(Override) Called when the player backs out of a partyselect menu in battle.
@param state_reason
— The current value of Battle.state_reason
@param party_index
— The index of the selected enemy on the menu.
Arguments:
state_reason: string | The current value of |
party_index: number | The index of the selected enemy on the menu. |
Encounter:onPartySelect(state_reason: string, party_index: integer)
(Override) Called when the player selects a party member in a partyselect menu in battle.
@param state_reason
— The current value of Battle.state_reason
@param party_index
— The index of the selected enemy on the menu.
Arguments:
state_reason: string | The current value of |
party_index: integer | The index of the selected enemy on the menu. |
Encounter:onReturnToWorld(events: Character)
(Override) Called just before returning to the world.
@param events
— A list of enemy events in the world that are linked to the enemies in battle.
Arguments:
events: Character | A list of enemy events in the world that are linked to the enemies in battle. |
Encounter:onStateChange(old: string, new: string)
(Override) Called when Battle:setState()
is called, after any state change code has run.
Arguments:
old: string | |
new: string |
Encounter:onTurnEnd()
(Override) Called at the end of each turn, at the same time all waves end.
Encounter:onTurnStart()
(Override) Called at the start of each new turn, just before the player starts choosing actions.
Encounter:onWavesDone()
(Override) Called when all the waves of the current turn have finished.