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

Action
ActionManager
ActionStore
ArenaEvent
Battle
ChannelAction
Day
DefaultOptions
Event
EventContainer
FinalEvent
ForcedOutcome
Game
Grammar
GuildGame
MemberAction
Messages
NormalEvent
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> _defaultBattles :Array.<HungryGames~Battle>

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

<private, nullable> _defaultEventStore :HungryGames~EventContainer

Object storing all default events for the games. Null until specified by instantiator.
Type:
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> _purgeDelta :number

The minimum amount of time to keep a HungryGames~GuildGame in memory before purging after a save.
Type:
  • number
Default Value:
  • 3 minutes
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> _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

createEvent(evt [, cb])

Create a new event.
Parameters:
Name Type Argument Description
evt HungryGames~Event Event object, or Event-like object, to finalize and save.
cb function <optional>
Optional callback that fires once data is saved to file. First parameter is optional error string argument. Second is otherwise the final created event.
Source:
Returns:
The event's ID if the event was created successfully, or null if failed to parse data.
Type
string

deleteEvent(user, id [, cb])

Completely delete an event and all of its data.
Parameters:
Name Type Argument Description
user string The user requesting deletion.
id string The ID of the event to delete.
cb function <optional>
Callback once completed. Only parameter is optional error string.
Source:
To Do:
  • Deleting a sub-event is not safe for multiple requests, it does not handle the requests properly if a second request is made before the first is completed.

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:

fetchUserEvents(user [, cb])

Fetch all event IDs of the events the given user has created.
Parameters:
Name Type Argument Description
user string The user requesting deletion.
cb basicCB <optional>
Callback once completed. First parameter is optional error string, second is otherwise an array if database rows.
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
HungryGames~EventContainer

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

insertAction(gId, trigger, action [, args] [, cb])

Create and insert an action for a trigger in the given guild.
Parameters:
Name Type Argument Default Description
gId string The guild ID of the game to modify.
trigger string The name of the trigger to insert the action into.
action string The name of the action to create.
args object <optional>
{} The optional additional arguments required for the action to be created.
cb function <optional>
Callback once completed. Single argument is error string if failed, or null if succeeded.
Source:

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

removeAction(gId, trigger, id [, cb])

Remove an action for a trigger in the given guild.
Parameters:
Name Type Argument Description
gId string The guild ID of the game to modify.
trigger string The name of the trigger to remove the action from.
id string The id of the action to remove.
cb function <optional>
Callback once completed. Single argument is error string if failed, or null if succeeded.
Source:

replaceEvent(user, evt [, cb])

Replace an event with new data.
Parameters:
Name Type Argument Description
user string The user requesting deletion.
evt HungryGames~Event The new event data.
cb function <optional>
Callback once completed. Only parameter is optional error string.
Source:

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:

setDefaultBattles(list)

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

setDefaultEvents(ec)

Update reference to the current HungryGames~EventContainer that stores all custom events.
Parameters:
Name Type Description
ec HungryGames~EventContainer The container reference.
Source:

shutdown()

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

updateAction(gId, trigger, id, key, value [, cb])

Update a specific action for a trigger in the given guild.
Parameters:
Name Type Argument Description
gId string The guild ID of the game to modify.
trigger string The name of the trigger to remove the action from.
id string The id of the action to remove.
key string The key of the value to change.
value number | string The value to set the setting to.
cb function <optional>
Callback once completed. Single argument is error string if failed, or null if succeeded.
Source:

Type Definitions


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:

MemberActionHandler(hg, game, member)

Handler function for a action to be performed on a player.
Parameters:
Name Type Description
hg HungryGames HG context.
game HungryGames~GuildGame Game context.
member external:Discord~GuildMember Guild member the player represents.
Source: