Class: HungryGames

HungryGames

Contains a Hunger Games style simulation.

new HungryGames(parent)

HungryGames constructor. Currently requires a valid SubModule as a parent.
Parameters:
Name Type Description
parent SubModule Parent submodule used to hook logging into.
Source:
To Do:
  • Remove reliance on SubModule.

Classes

ArenaEvent
Battle
Day
DefaultOptions
Event
FinalEvent
ForcedOutcome
Game
Grammar
GuildGame
Messages
OutcomeProbabilities
Player
Simulator
StatGroup
StatManager
Stats
Team
UserIconUrl
WeaponEvent

Members


<static, constant> largeServerCount :number

Games with more than this many members is considered large, and will have some features disabled in order to improve performance.
Type:
  • number
Default Value:
  • 20000
Source:

<private> _defaultArenaEvents :Array.<HungryGames~ArenaEvent>

Array of all arena events that can take place normally by default.
Type:
Default Value:
  • []
Source:

<private> _defaultBattles :Array.<HungryGames~Battle>

Array of all battles that can take place normally by default.
Type:
Default Value:
  • []
Source:

<private> _defaultBloodbathEvents :Array.<HungryGames~Event>

Array of all events that can take place in the bloodbath by default.
Type:
Default Value:
  • []
Source:

<private> _defaultPlayerEvents :Array.<HungryGames~Event>

Array of all events that can take place normally by default.
Type:
Default Value:
  • []
Source:

<private> _defaultWeapons :Array.<HungryGames~Weapon>

Array of all weapons that can be used normally by default.
Type:
  • Array.<HungryGames~Weapon>
Default Value:
  • []
Source:

<private, constant> _findDelay :number

The delay after failing to find a guild's data to look for it again.
Type:
  • number
Default Value:
  • 15 Seconds
Source:

<private, constant> _findTimestamps :object.<number>

Stores the guilds we have looked for their data recently and the timestamp at which we looked. Used to reduce filesystem requests and blocking.
Type:
  • object.<number>
Source:

<private, constant> _games :object.<HungryGames~GuildGame>

All currently tracked games. Mapped by guild ID. In most cases you should not reference this directly. Use HungryGames#getGame to get the game object for a guild.
Type:
Default Value:
  • {}
Source:
See:

<private, constant> _hgSaveDir :string

The file directory for finding saved data related to the hungry games data of individual guilds.
Type:
  • string
Default Value:
  • /hg/
Source:
See:

<private, constant> _parent :HG

Parent subModule for logging and bot hooking.
Type:
Source:

<private, constant> _saveFile :string

The file path to save current state for a specific guild relative to Common~guildSaveDir.
Type:
  • string
Default Value:
  • game.json
Source:
See:

<constant> defaultOptions :HungryGames~DefaultOptions

Default game options.
Type:
Source:

hgSaveDir

The file directory for finding saved data related to the hungry games data of individual guilds.
Source:
See:

<constant> maxDelta :number

Maximum amount of milliseconds long running operations are allowed to take to prevent cpu deadlock.
Type:
  • number
Default Value:
  • 5
Source:

<constant> messages :HungryGames~Messages

Current HungryGames~Messages instance.
Type:
Source:

saveFile

The file path to save current state for a specific guild relative to Common#guildSaveDir.
Source:
See:

Methods


<private, static> tmpRequire(name)

Wrapper for normal `require()` but also deletes cache reference to object before requiring. This forces the object to be updated.
Parameters:
Name Type Description
name string Name of module to require.
Source:
Returns:
The required module.
Type
object

<private> _find(id [, cb])

Returns a guild's game data. Returns cached version if that exists, or searches the file system for saved data. Data will only be checked from disk at most once every `HungryGames~findDelay` milliseconds. Returns `null` if data could not be found, or an error occurred.
Parameters:
Name Type Argument Description
id number | string The guild id to get the data for.
cb function <optional>
Callback to fire once complete. This becomes asyncronous if given, if not given this function is syncronous. Single parameter is null if not found, or HungryGames~GuildGame if found.
Source:
Returns:
The game data, or null if no game could be loaded or loading asyncronously because a callback was given.
Type
HungryGames~GuildGame

create(guild [, cb])

Create a new GuildGame.
Parameters:
Name Type Argument Description
guild external:Discord~Guild | string Guild object, or ID to create a game for.
cb function <optional>
Callback once game has been fully created. Passes the created game as the only argument.
Source:
Fires:
  • HG#event:create

fetchGame(id, cb)

Similar to HungryGames.getGame except asyncronous and fetched game is passed as callback argument.
Parameters:
Name Type Description
id string The guild id to get the data for.
cb function Callback with single argument. Null if unable to be found, HungryGames~GuildGame if found.
Source:

getAllPlayers(members, excluded, bots, included, excludeByDefault [, includedNPCs], cb)

Form an array of Player objects based on guild members, excluded members, and whether to include bots.
Parameters:
Name Type Argument Default Description
members external:Discord~Collection.<external:Discord~GuildMember> All members in guild.
excluded Array.<string> Array of ids of users that should not be included in the games.
bots boolean Should bots be included in the games.
included Array.<string> Array of ids of users that should be included in the games. Used if excludeByDefault is true.
excludeByDefault boolean Should new users be excluded from the game by default?
includedNPCs Array.<NPC> <optional>
[] NPCs to include as players.
cb basicCB Callback on completion. Only argument is array of HungryGames~Player to include in the games.
Source:

getDefaultEvents()

Returns an object storing all of the default events for the games.
Source:
Returns:
Object storing default events.
Type
Object

getGame(id)

Returns a reference to the current games object for a given guild.
Parameters:
Name Type Description
id string The guild id to get the data for.
Source:
Returns:
The current object storing all data about game in a guild.
Type
HungryGames~GuildGame

refresh(guild [, cb])

Create a new Game for a guild, and refresh the player lists.
Parameters:
Name Type Argument Description
guild external:Discord~Guild | string Guild object, or ID to refresh a game for.
cb function <optional>
Callback once game has been fully refreshed. Passes the refreshed game as the only argument, or null if unable to find the game.
Source:
Fires:
  • HG#event:refresh

resetGame(id, command)

Reset the specified category of data from a game.
Parameters:
Name Type Description
id string The id of the guild to modify.
command string The category of data to reset.
Source:
Fires:
  • HG#event:reset
Returns:
The message explaining what happened.
Type
string

save( [opt])

Save all HG related data to file. Purges old data from memory as well.
Parameters:
Name Type Argument Default Description
opt string <optional>
'sync' Can be 'async', otherwise defaults to synchronous.
Source:

setDefaultArenaEvents(list)

Update the reference to the array storing default arena events.
Parameters:
Name Type Description
list Array.<HungryGames~ArenaEvent> Array to reference.
Source:

setDefaultBattles(list)

Update the reference to the array storing default battles events.
Parameters:
Name Type Description
list Array.<HungryGames~Battle> Array to reference.
Source:

setDefaultBloodbathEvents(list)

Update the reference to the array storing default bloodbath events.
Parameters:
Name Type Description
list Array.<HungryGames~Event> Array to reference.
Source:

setDefaultPlayerEvents(list)

Update the reference to the array storing default player events.
Parameters:
Name Type Description
list Array.<HungryGames~Event> Array to reference.
Source:

setDefaultWeapons(list)

Update the reference to the array storing default weapons events.
Parameters:
Name Type Description
list Array.<HungryGames~Weapon> Array to reference.
Source:

shutdown()

End all event listeners, intervals, and timeouts to prepare for a full stop.
Source:

Type Definitions


createEventBooleanCallback(outcome)

The callback after receiving a boolean input.
Parameters:
Name Type Description
outcome boolean The value chosen by the user.
Source:

createEventNumCallback(num)

The callback after receiving a number from user input.
Parameters:
Name Type Description
num number The number received from the user.
Source:

createEventOutcomeCallback(outcome)

The callback after receiving an event outcome from a user.
Parameters:
Name Type Description
outcome string The outcome chosen by the user.
Source:

hgCommandHandler(msg, id)

Handler for a Hungry Games command.
Parameters:
Name Type Description
msg Discord~Message The message sent in Discord that triggered this command.
id string The id of the guild this command was run on for convenience.
Source: