Class: Simulator

HungryGames~ Simulator


new Simulator(game, hg [, msg])

Create a simulator instance.
Parameters:
Name Type Argument Description
game HungryGames~GuildGame The GuildGame to simulate.
hg HungryGames Parent game manager for logging and SubModule references.
msg Discord~Message <optional>
Message to reply to if necessary.
Source:

Classes

Worker

Members


<private, static, constant> _littleDeathRate :number

If a lower percentage of people die in one day than this value, then show a relevant message.
Type:
  • number
Default Value:
  • 0.15
Source:

<private, static, constant> _lotsOfDeathRate :number

If a larger percentage of people die in one day than this value, then show a relevant message.
Type:
  • number
Default Value:
  • 0.75
Source:

<private, static, constant> _multiEventUserDistribution :object.<number>

Probability of each amount of people being chosen for an event. Must total to 1.0.
Type:
  • object.<number>
Default Value:
  • {"undefined":0.0005}
Source:

<private, static, constant> _workerPath :string

Relative path from CWD where the simulation worker is located.
Type:
  • string
Default Value:
  • ./src/hg/simulator/worker.js
Source:

Methods


<private, static> _applyOutcome(game, a, k [, w], outcome)

Apply the given outcome to a player in the given guild game.
Parameters:
Name Type Argument Description
game HungryGames~GuildGame Current GuildGame being affected.
a HungryGames~Player The player to affect.
k number The number of kills the player gets in this action.
w Object <optional>
The weapon being used if any.
outcome string The outcome to apply.
Source:
Returns:
True if valid outcome was successfully applied, false otherwise. ('nothing' is considered not valid, but outcome will still be applied).
Type
boolean

<private, static> _effectUser(game, affected, kills [, weapon])

Base of all actions to perform on a player.
Parameters:
Name Type Argument Description
game HungryGames~GuildGame Current GuildGame being affected.
affected HungryGames~Player The player to affect.
kills number The number of kills the player gets in this action.
weapon Object <optional>
The weapon being used if any.
Source:

<private, static> _killUser(game, a, k [, w])

Kill the given player in the given guild game.
Parameters:
Name Type Argument Description
game HungryGames~GuildGame Current GuildGame being affected.
a HungryGames~Player The player to affect.
k number The number of kills the player gets in this action.
w Object <optional>
The weapon being used if any.
Source:

<private, static> _parseConsumeCount(consumeString, numVictim, numAttacker)

Parse the number of items consumed from the given consumed value, and number of victims and attackers.
Parameters:
Name Type Description
consumeString string The consumes value for the event.
numVictim number The number of victims in the event.
numAttacker number The number of attackers in the event.
Source:
Returns:
The number of consumed items.
Type
number

<private, static> _pickAffectedPlayers(evt, options, userPool, deadPool, teams, weaponWielder)

Pick the players to put into an event.
Parameters:
Name Type Argument Description
evt HungryGames~NormalEvent The event data to pick players for.
options object Options for this game.
userPool Array.<HungryGames~Player> Pool of all remaining players to put into an event.
deadPool Array.<HungryGames~Player> Pool of all dead players that can be revived.
teams Array.<HungryGames~Team> All teams in this game.
weaponWielder Player <nullable>
A player that is using a weapon in this event, or null if no player is using a weapon.
Source:
Returns:
Array of all players that will be affected by this event.
Type
Array.<HungryGames~Player>

<private, static> _pickEvent(userPool, eventPool, options, numAlive, numTotal, teams, probOpts, weaponWielder, weaponId)

Pick event that satisfies all requirements and settings.
Parameters:
Name Type Argument Description
userPool Array.<HungryGames~Player> Pool of players left to chose from in this day.
eventPool Array.<HungryGames~NormalEvent> Pool of all events available to choose at this time.
options object The options set in the current game.
numAlive number Number of players in the game still alive.
numTotal number Number of players in the game total.
teams Array.<HungryGames~Team> Array of teams in this game.
probOpts HungryGames~OutcomeProbabilities Death rate weights.
weaponWielder Player <nullable>
A player that is using a weapon in this event, or null if no player is using a weapon.
weaponId string ID of the weapon the player is trying to use.
Source:
Returns:
The chosen event that satisfies all requirements, or null if something went wrong.
Type
HungryGames~NormalEvent

<private, static> _probabilityEvent(eventPool, probabilityOpts [, customWeight] [, recurse])

Produce a random event that using probabilities set in options.
Parameters:
Name Type Argument Default Description
eventPool Array.<HungryGames~NormalEvent> The pool of all events to consider.
probabilityOpts Object The probabilities of each type of event being used.
customWeight number <optional>
1 The weight of custom events.
recurse number <optional>
0 The current recursive depth.
Source:
Returns:
The index of the event that was chosen.
Type
number

<private, static> _restoreUser(game, a, k [, w])

Heal the given player in the given guild game.
Parameters:
Name Type Argument Description
game HungryGames~GuildGame Current GuildGame being affected.
a HungryGames~Player The player to affect.
k number The number of kills the player gets in this action.
w Object <optional>
The weapon being used if any.
Source:

<private, static> _reviveUser(game, a, k [, w])

Revive the given player in the given guild game.
Parameters:
Name Type Argument Description
game HungryGames~GuildGame Current GuildGame being affected.
a HungryGames~Player The player to affect.
k number The number of kills the player gets in this action.
w Object <optional>
The weapon being used if any.
Source:

<private, static> _validateEventNumConstraint(numVictim, numAttacker, userPool, numAlive)

Ensure the number of users in an event is mathematically possible.
Parameters:
Name Type Description
numVictim number Number of victims in this event.
numAttacker number Number of attackers in this event.
userPool Array.<HungryGames~Player> Pool of all remaining players to put into an event.
numAlive number Total number of living players left in the game.
Source:
Returns:
If the event requires a number of players that is valid from the number of players left to choose from.
Type
boolean

<private, static> _validateEventRequirements(numVictim, numAttacker, userPool, numAlive, teams, options, victimsDie, attackersDie, weaponWielder)

Ensure the event chosen meets all requirements for actually being used in the current game.
Parameters:
Name Type Argument Description
numVictim number Number of victims in this event.
numAttacker number Number of attackers in this event.
userPool Array.<HungryGames~Player> Pool of all remaining players to put into an event.
numAlive number Total number of living players left in the game.
teams Array.<HungryGames~Team> All teams in this game.
options object The options set for this game.
victimsDie boolean Do the victims die in this event?
attackersDie boolean Do the attackers die in this event?
weaponWielder Player <nullable>
A player that is using a weapon in this event, or null if no player is using a weapon.
Source:
Returns:
String of failing constraint check, or null if passes.
Type
string

<private, static> _validateEventTeamConstraint(numVictim, numAttacker, userPool, teams, options, victimsDie, attackersDie, weaponWielder)

Ensure teammates don't attack each other.
Parameters:
Name Type Argument Description
numVictim number The number of victims in the event.
numAttacker number The number of attackers in the event.
userPool Array.<HungryGames~Player> Pool of all remaining players to put into an event.
teams Array.<HungryGames~Team> All teams in this game.
options object Options for this game.
victimsDie boolean Do the victims die in this event?
attackersDie boolean Do the attackers die in this event?
weaponWielder Player <nullable>
A player that is using a weapon in this event, or null if no player is using a weapon.
Source:
Returns:
String describing failing check, or null of pass.
Type
string

<private, static> _validateEventVictorConstraint(numVictim, numAttacker, numAlive, options, victimsDie, attackersDie)

Ensure the event we choose will not force all players to be dead.
Parameters:
Name Type Description
numVictim number Number of victims in this event.
numAttacker number Number of attackers in this event.
numAlive number Total number of living players left in the game.
options object The options set for this game.
victimsDie boolean Do the victims die in this event?
attackersDie boolean Do the attackers die in this event?
Source:
Returns:
Will this event follow current options set about number of victors required.
Type
boolean

<private, static> _woundUser(game, a, k [, w])

Wound the given player in the given guild game.
Parameters:
Name Type Argument Description
game HungryGames~GuildGame Current GuildGame being affected.
a HungryGames~Player The player to affect.
k number The number of kills the player gets in this action.
w Object <optional>
The weapon being used if any.
Source:

<static> formatWeaponCounts(eventTry, affectedUsers, weapons, nameFormat)

Format the text that shows all users' inventories in an event.
Parameters:
Name Type Description
eventTry HungryGames~NormalEvent The event to format inventories for.
affectedUsers Array.<HungryGames~Player> Array of all player affected by this event.
weapons object.<HungryGames~WeaponEvent> The default weapons object injected with custom weapons.
nameFormat string The format for HungryGames~Grammar~formatMultiNames.
Source:
Returns:
The additional text to append.
Type
string

<static> formatWeaponEvent(eventTry, userWithWeapon, ownerName, firstAttacker, weaponId, weapons [, countOverride])

Format an event message for the given weapon information.
Parameters:
Name Type Argument Description
eventTry HungryGames~NormalEvent The event to format.
userWithWeapon HungryGames~Player The player using the weapon.
ownerName string The formated name to insert fot the weapon owner.
firstAttacker boolean Is the weapon owner the first attacker in list of affected users.
weaponId string The id of the chosen weapon.
weapons object.<HungryGames~WeaponEvent> The default weapons object injected with custom weapons.
countOverride number <optional>
If specified, this value is used as the final amount the player will end up with, instead of using the calculated value.
Source:
Returns:
Additional subMessage.
Type
string

<static> weightedUserRand()

Produce a random number that is weighted by multiEventUserDistribution.
Source:
See:
  • multiEventUserDistribution
Returns:
The weighted number outcome.
Type
number

go(cb)

Simulate a day with the current GuildGame.
Parameters:
Name Type Description
cb function Callback that always fires on completion. The only parameter is a possible error string, null if no error.
Source:

setGame(game)

Change the GuildGame to simulate.
Parameters:
Name Type Description
game HungryGames~GuildGame The new GuildGame.
Source:

setMessage(msg)

Update the message to reply to.
Parameters:
Name Type Description
msg Discord~Message New message to reference.
Source:

setParent(hg)

Update the reference to the parent HungryGames.
Parameters:
Name Type Description
hg HungryGames New parent reference.
Source: