Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Games Sub Bot

Aaron Graubert edited this page Nov 13, 2018 · 1 revision

Games

This sub-bot adds utilities for running text-based games in your server. This is the single largest sub-bot in the Beymax standard library. To enable this suite, call EnableGames on a CoreBot or pass EnableGames to CoreBot.EnableAll

All members of the server will have a level, xp, and a balance of tokens. Tokens and xp are earned by playing games. The user's level increases their weekly allowance of tokens.

Channels

This suite reserves the games channel reference

Commands

  • !invite <user reference> : Invites the given user to your game

    Only the current host of a game can use this command. This invites a user to join the game. The user is notified via DM, and can accept by using !join in any channel

  • !join : Joins the current game, if the user was invited

    If the issuing user was invited to a game, they are added as a player. Only messages sent by players in the games channel are passed on to the active game as input to the game.

    Note: Some games may delay the join until a later time or deny joining entirely. A user is not considered a player until the game has fully processed the request to join

  • !leave : Leaves the current game, if the user was playing

    IF the issuing user was playing the current game, they are removed as a player. If the game's host leaves the game, the game session will end immediately

    Note: Some games may delay the leave until a later time, or deny leaving entirely. A user is still considered a player until the game has fully processed the request to leave

  • !games : Lists the available game backends and the individual games they support

  • !toggle-comments : Toggles comments in the games channel by non-players

    Only the host can use this command. When comments are allowed (default) messages in the games channel by users who are not playing are ignored by the game system and left as-is. When comments are disabled, those messages are deleted and the authors are DM'ed to indicate that they cannot currently post in that channel

  • !_start <game name> : Immediately starts a new game session

    This bypasses the bidding system and immediately starts a game with the command issuer as the game host

  • !balance : Gets the user's current token balance

    Sends a DM to the issuing user containing the user's current level, current token balance, and remaining xp needed to reach the next level

  • !bid <amount> <game> : Places a bid for the given game on the next game slot

    Places a bid of the given amount on the next game slot. If there are no active games, this immediately deducts the bid amount from the user's token balance and starts the requested game. If there is an active game, it places a bid for the given game (but does not deduct the amount). When the current game ends, the bot checks all bids (from highest to lowest), and if the bidder can afford that amount, it is deducted and their game starts. Users are notified via DM when they are outbid

  • !_payout <User reference> <amount> <type> : Pays the given user an amount of xp or tokens

    Adds the given amount of either xp or tokens (as specified by type) to the given user's balance

  • !reup : Extends the current game

    This can only be used by the game host. When a game is started, it has a maximum 2 day period. After the time expires, the game is ended. The host can use this command to extend their current game by an additional 1 day. The initial re-up cost for a game is 1 token, but increases by 1 every time the game session is extended. A game cannot be re-upped if the host has not yet played the game

  • !timeleft : Reports the current game, it's host, and the time remaining in the current game session

  • !highscore <game> : Gets the current highscore for the given game

    Checks the score tables for a the highest score from the given game

Tasks

  • Every week, the bot grants 5 xp to each user who sent a message to any channel in the last week.

    Additionally, it grants a number of tokens to all users based on the following rules:

    • If the user's token balance is less than 20x their level, they are granted 2x their level in tokens
    • If the user's balance is between 20x and 100x their level, they are granted 1x their level in tokens
    • Otherwise, the user is granted 0.1x their level (rounded down) in tokens

    Users who were active during the last week receive a DM indicating the amount of tokens they were paid.

  • Every 30 minutes the bot checks the time remaining in the current game:

    • If the game's time has expired, it ends the game
    • When the time passes 1 left and again at 6 hours left, the host gets a DM warning them of the impending expiration

Special Handlers

  • Messages sent into the games channel while a game is active are processed as follows:
    • If the message starts with the command prefix, it is ignored by the game system
    • If the user is playing the game, the message is forwarded to the active game system as input to the game
    • Otherwise, if the host has disabled comments, the message is deleted, and the author is sent a DM that they cannot currently post in this channel
    • Otherwise, the message is left as-is but otherwise ignored by the game system

Event Subscriptions

  • This suite adds a subscriber to grant_xp which takes the following arguments:

    • The event name, 'grant_xp'
    • The user object to receive xp
    • The amount of xp

    The given user's xp total will be increased by the given amount, which may increase their level

  • This suite adds a subscriber to endgame which takes the following arguments:

    • The event name, 'endgame'
    • The hardness of how the game was ended

    The current game is ended, dispatching appropriate cleanup methods on the game system. Hardness indicates the conditions for the game end:

    • soft : The game ended because the host left, the time expired, or the game naturally reached its end
    • hard : The game ended because the game system reached some unexpected internal state and could not continue
    • critical : The game ended because an exception was raised by the game system during a critical period
  • This suite adds a subscriber to startgame which takes the following arguments:

    • The event name, 'startgame'

    The bot checks all current bids (from highest amount to lowest) and starts the game from the highest bid that could be honored. The host will be DM'ed instructions on how to use the core game features (although each game and game system will have additional features beyond this command set). The game lasts for 2 days unless re-upped

  • This suite adds a subscriber to command which takes the following arguments:

    • The event name, 'command'
    • The command issued
    • The user issuing the command

    This event is dispatched whenever a user issues a command. This handler is used to track the set of commands that each user has used in the last week and grants 5xp to a user when they use any command for the first time each week

  • This suite adds a subscriber to after:message which takes the following arguments:

    • The event name, 'after:message'
    • The message object sent

    This is used to track users which have posted a message anywhere in the server during the last week

  • This suite adds a subscriber to cleanup which takes the following arguments:

    • The event name, 'cleanup'

    This handler saves the record of activity (saved by the after:message handler) to disk

XP, Tokens, and Levels

This suite turns the whole server into a game.

  • Tokens:
    • Users spend tokens by bidding on and re-upping games. Additionally, players use their tokens in poker games
    • Users earn tokens as part of their weekly allowance and as rewards for playing games
  • XP:
    • Users do not spend XP
    • Users earn XP as part of their weekly allowance and as rewards for playing games and being an active member of the server
  • Level:
    • Users do not lower their level
    • Users gain levels by earning XP

Game Systems

Currently this suite supports two game systems:

  • A story system, which can run text-based adventures built in Z-machine (infocom) .z5 files
  • A poker system, which can run Texas Hold 'em and Blackjack (although more will follow)

You can implement your own games by extending the GameSystem or PhasedGame classes

Clone this wiki locally