Class: GuildGame

HungryGames~ GuildGame

A single instance of a game in a guild.

new GuildGame(bot, id, options [, name] [, includedUsers] [, excludedUsers] [, includedNPCs] [, excludedNPCs], customEventIds, disabledEventIds)

Create a game instance for a single guild.
Parameters:
Name Type Argument Description
bot string User id of the current bot instance.
id string Guild id of the Guild that this object is for.
options object.<(number|boolean|string|object)> The game options.
name string <optional>
Name of this game to be passed to the Game object.
includedUsers Array.<string> | Array.<HungryGames~Player> <optional>
Array of user IDs that will be included in the next game, or array of Players to include.
excludedUsers Array.<string> <optional>
Array of user IDs that have been excluded from the games.
includedNPCs Array.<HungryGames~NPC> <optional>
Array of NPC objects to include in the game.
excludedNPCs Array.<HungryGames~NPC> <optional>
Array of NPC objects to exclude from the game.
customEventIds Object Array of IDs of custom events to load.
disabledEventIds Array.<string> Array of IDs of events to be disabled from game.
Source:

Members


<private, nullable> _autoPlayTimeout :Timeout

The timeout to continue autoplaying after the day ends. Used for cancelling if user ends the game between days.
Type:
  • Timeout
Source:

<private> _autoStep :boolean

Is this game automatically stepping, or are steps controlled manually.
Type:
  • boolean
Default Value:
  • false
Source:

<private, nullable> _dayEventInterval :Timeout

Interval for day events.
Type:
  • Timeout
Source:

<private, nullable> _stateUpdateCallback :HungryGames~GuildGame~StateUpdateCB

Function to call when state is modified.
Type:
Source:

<private, constant> _stats :HungryGames~StatManager

Manages all stats for all players.
Type:
Source:

actions :HungryGames~ActionStore

The actions to perform when certain events occur.
Type:
Source:

<nullable> author :string

The id of the user that last sent a command which interacted with this guild game.
Type:
  • string
Source:

autoPlay :boolean

Is this game autoplaying?
Type:
  • boolean
Default Value:
  • false
Source:

<constant> bot :string

The ID of the current bot account.
Type:
  • string
Source:

<nullable> channel :string

The channel id a command was last sent from that affected this guild game.
Type:
  • string
Source:

currentGame :HungryGames~Game

Current game information.
Type:
Source:

<constant> customEventStore :HungryGames~EventContainer

Storage manager for all custom events.
Type:
Source:
To Do:
  • Currently each guild will cache all events on its own, this will be find for now, but would be more efficient if a global cache was used instead.

disabledEventIds :Object

List of IDs of events to disable per-category.
Type:
  • Object
Source:

excludedNPCs :Array.<HungryGames~NPC>

Array of NPCs that will be excluded from the game.
Type:
  • Array.<HungryGames~NPC>
Default Value:
  • []
Source:

excludedUsers :Array.<string>

Array of user IDs that will be excluded from the next game.
Type:
  • Array.<string>
Default Value:
  • []
Source:

<constant> id :string

The ID of the Guild this is for.
Type:
  • string
Source:

includedNPCs :Array.<HungryGames~NPC>

Array of NPCs that will be included in the game.
Type:
  • Array.<HungryGames~NPC>
Default Value:
  • []
Source:

includedUsers :Array.<string>

Array of user IDs that will be included in the next game.
Type:
  • Array.<string>
Default Value:
  • []
Source:

loading :boolean

Does this game currently have any long running operations being performed.
Type:
  • boolean
Default Value:
  • false
Source:

options :object

Game options.
Type:
  • object
Source:

<nullable> outputChannel :string

The channel id where the game messages are currently being sent in.
Type:
  • string
Source:

<nullable> reactMessage :Object

Message ID of the message to fetch reactions from for join via react.
Type:
  • Object
Source:

serializable

Get a serializable version of this class instance. Strips all private variables, and all functions. Assumes all public variables are serializable if they aren't a function.
Source:

<nullable> statGroup :string

The ID of the currently active HungryGames~StatGroup tracking stats.
Type:
  • string
Source:

Methods


<static> forcePlayerState(game, list, state, messages, text, locale, cb)

Force a player to have a certain outcome in the current day being simulated, or the next day that will be simulated. This is acheived by adding a custom event in which the player will be affected after their normal event for the day.
Parameters:
Name Type Argument Description
game HungryGames~GuildGame The game context.
list Array.<string> The array of player IDs of which to affect.
state string The outcome to force the players to have been victims of by the end of the simulated day. ("living", "dead", "wounded", or "thriving").
messages HungryGames~Messages Reference to current Messages instance.
text string | Array.<HungryGames~NormalEvent> Message to show when the user is affected, or array of default events if not specifying a specific message.
locale string <nullable>
Language locale to use for string lookup.
cb function Callback once complete. Single parameter is the output message to tell the user of the outcome of the operation.
Source:

<static> from(data, client)

Create a GuildGame from data parsed from file. Similar to copy constructor.
Parameters:
Name Type Description
data object GuildGame like object.
client Discord~Client Discord client reference for creating HungryGames~ActionStore.
Source:
Returns:
Created GuildGame.
Type
HungryGames~GuildGame

clearIntervals()

Clear all timeouts and intervals.
Source:

createInterval( [cb])

Create an interval for this guild. Calls the callback every time the game state is about to be modified. State is updated immediately after the callback completes. This also sets `_autoStep` to true.
Parameters:
Name Type Argument Description
cb HungryGames~GuildGame~StateUpdateCB <optional>
Callback to fire on the interval. Optional only if set via setStateUpdateCallback prior to call to this function.
Source:

end()

Force this current game to end immediately.
Source:

formTeams()

Add users to teams, and remove excluded users from teams. Deletes empty teams, and adds teams once all teams have teamSize of players.
Source:
Returns:
Null if success, string if error.
Type
string

modifyPlayerWeapon(player, weapon [, text] [, count] [, set] [, cb])

Give or take a weapon from a player.
Parameters:
Name Type Argument Default Description
player string The ID of the player to modify.
weapon string The weapon ID to give/take.
text string | HungryGames <optional>
null The message text to show, or reference to object storing default events. If no value is given, a random message is chosen from `./save/hgMessages.json`.
count number <optional>
1 The amount to give to the player. Negative to take away.
set boolean <optional>
false Set the amount to `count` instead of incrementing.
cb function <optional>
Callback once complete. First parameter is string key, following are optional values to fill template.
Source:

setStateUpdateCallback(cb)

Set the state update callback function.
Parameters:
Name Type Description
cb HungryGames~GuildGame~StateUpdateCB Callback to fire when stepped.
Source:

step()

Progress to the next game state. Calls `_stateUpdateCallback` prior to any action, if it's set.
Source:

Type Definitions


StateUpdateCB(dayComplete, doSim)

Callback to fire when game state is about to be modified.
Parameters:
Name Type Description
dayComplete boolean True if this update is after a day has ended, false if the state is still during a day.
doSim boolean True if the next day should be simulated and started.
Source: