• Guides
  • Api Documentation
Show / Hide Table of Contents
  • Discord.Addons.MpGame
    • CurrentlyPlaying
    • GameBase<TPlayer>
    • IMpGameData
    • MpGameModuleBase<TService, TGame, TPlayer>
    • MpGameService<TGame, TPlayer>
    • MpGameService<TGame, TPlayer>.MpGameData
    • Player
  • Discord.Addons.MpGame.Collections
    • CircularLinkedList<T>
    • Hand<T>
    • IWrapper<T>
    • Node<T>
    • Pile<T>
    • WrappingPile<T, TWrapper>
  • Discord.Addons.Preconditions
    • Measure
    • MinimumOnlineUsersAttribute
    • RatelimitAttribute
    • RatelimitFlags
    • RequireLowerHierarchyAttribute
    • RequireRoleAttribute
    • UserMustBeInVoiceAttribute

Class MpGameService<TGame, TPlayer>

Service managing games for a MpGameModuleBase<TService, TGame, TPlayer>.


Inheritance
Object
MpGameService<TGame, TPlayer>
Implements
IDisposable
Namespace: Discord.Addons.MpGame
Assembly: Discord.Addons.MpGame.dll
Syntax
public class MpGameService<TGame, TPlayer>
    where TGame   : GameBase<TPlayer>
    where TPlayer : Player
Type Parameters
Name Description
TGame

The type of game to manage.

TPlayer

The type of the Player object.

Constructors

| Improve this Doc View Source

MpGameService(BaseSocketClient, IMpGameServiceConfig, Func<LogMessage, Task>)

Instantiates the MpGameService for the specified Game and Player type.

Declaration
public MpGameService(BaseSocketClient client, IMpGameServiceConfig mpconfig = null, Func<LogMessage, Task> logger = null)
Parameters
Type Name Description
BaseSocketClient client

The Discord client.

Discord.Addons.MpGame.IMpGameServiceConfig mpconfig

An optional config type.

Func<LogMessage, Task> logger

An optional logging method.

Properties

| Improve this Doc View Source

Logger

Logger function.

Declaration
protected Func<LogMessage, Task> Logger { get; }
Property Value
Type Description
Func<LogMessage, Task>
| Improve this Doc View Source

MessageChannelComparer

A cached IEqualityComparer<IMessageChannel> instance to use when instantiating a Dictionary<IMessageChannel, TValue>. This is the same instance as DiscordComparers.ChannelComparer.

Declaration
protected static IEqualityComparer<IMessageChannel> MessageChannelComparer { get; }
Property Value
Type Description
IEqualityComparer<IMessageChannel>
Examples
    private readonly ConcurrentDictionary<IMessageChannel, MyData> _data
        = new ConcurrentDictionary<IMessageChannel, MyData>(MessageChannelComparer);

Methods

| Improve this Doc View Source

AddPlayerAsync(TGame, TPlayer)

Adds a player to an ongoing game.

Declaration
public async Task<bool> AddPlayerAsync(TGame game, TPlayer player)
Parameters
Type Name Description
TGame game

The game instance.

TPlayer player

The player to add.

Returns
Type Description
Task<Boolean>

true if the operation succeeded, otherwise false.

Examples
  if (await GameService.AddPlayerAsync(Game, new MyPlayer(Context.User, Context.Channel)).ConfigureAwait(false))
      await ReplyAsync($"**{Context.User.Username}** has joined.").ConfigureAwait(false);
| Improve this Doc View Source

AddUserAsync(IMessageChannel, IUser)

Add a user to join an unstarted game.

Declaration
public async Task<bool> AddUserAsync(IMessageChannel channel, IUser user)
Parameters
Type Name Description
IMessageChannel channel

Public facing channel of this game.

IUser user

The user.

Returns
Type Description
Task<Boolean>

true if the operation succeeded, otherwise false.

| Improve this Doc View Source

CancelGameAsync(IMessageChannel)

Cancel a game that has not yet started.

Declaration
public Task<bool> CancelGameAsync(IMessageChannel channel)
Parameters
Type Name Description
IMessageChannel channel

Public facing channel of this game.

Returns
Type Description
Task<Boolean>

true if the operation succeeded, otherwise false.

| Improve this Doc View Source

Dispose()

Declaration
protected virtual void Dispose()
| Improve this Doc View Source

GetGameData(ICommandContext)

Gets the game metadata associated with this context.

Declaration
public MpGameService<TGame, TPlayer>.MpGameData GetGameData(ICommandContext context)
Parameters
Type Name Description
ICommandContext context

The CommandContext to fetch metadata for.

Returns
Type Description
MpGameService.MpGameData<>

A snapshot of the current game metadata.

| Improve this Doc View Source

GetGameFromChannel(IMessageChannel)

Retrieve the game instance being played, if any.

Declaration
public TGame GetGameFromChannel(IMessageChannel channel)
Parameters
Type Name Description
IMessageChannel channel

A message channel. Can be both the public-facing channel or the DM channel of one of the players.

Returns
Type Description
TGame

The TGame instance being played in the specified channel, or that the user is playing in, or null if there is none.

| Improve this Doc View Source

GetJoinedUsers(IMessageChannel)

Retrieve the users set to join an open game, if any.

Declaration
public IReadOnlyCollection<IUser> GetJoinedUsers(IMessageChannel channel)
Parameters
Type Name Description
IMessageChannel channel

A message channel. Can be both the public-facing channel or the DM channel of one of the players.

Returns
Type Description
IReadOnlyCollection<IUser>

The users set to join a new game, or an empty collection if there is no data.

| Improve this Doc View Source

IsOpenToJoin(IMessageChannel)

Retrieve whether a game has been opened and users can join.

Declaration
public bool IsOpenToJoin(IMessageChannel channel)
Parameters
Type Name Description
IMessageChannel channel

A message channel. Can be both the public-facing channel or the DM channel of one of the players.

Returns
Type Description
Boolean

true if a game has been opened and users can join, otherwise false.

| Improve this Doc View Source

KickPlayerAsync(TGame, TPlayer)

Kicks a player from an ongoing game.

Declaration
public Task<bool> KickPlayerAsync(TGame game, TPlayer player)
Parameters
Type Name Description
TGame game

The game instance.

TPlayer player

The player to kick.

Returns
Type Description
Task<Boolean>

true if the operation succeeded, otherwise false.

| Improve this Doc View Source

OpenNewGameAsync(ICommandContext)

Prepare to set up a new game in a specified channel.

Declaration
public async Task<bool> OpenNewGameAsync(ICommandContext context)
Parameters
Type Name Description
ICommandContext context

Context of where this game is intended to be opened.

Returns
Type Description
Task<Boolean>

true if the operation succeeded, otherwise false.

| Improve this Doc View Source

RemoveUserAsync(IMessageChannel, IUser)

Remove a user from an unstarted game.

Declaration
public async Task<bool> RemoveUserAsync(IMessageChannel channel, IUser user)
Parameters
Type Name Description
IMessageChannel channel

Public facing channel of this game.

IUser user

The user.

Returns
Type Description
Task<Boolean>

true if the operation succeeded, otherwise false.

Examples
  if (await GameService.RemoveUserAsync(Context.Channel, user).ConfigureAwait(false))
      await ReplyAsync($"**{user.Username}** has been kicked.").ConfigureAwait(false);
| Improve this Doc View Source

TryAddNewGameAsync(IMessageChannel, TGame)

Add a new game to the list of active games.

Declaration
public async Task<bool> TryAddNewGameAsync(IMessageChannel channel, TGame game)
Parameters
Type Name Description
IMessageChannel channel

Public facing channel of this game.

TGame game

Instance of the game.

Returns
Type Description
Task<Boolean>

true if the operation succeeded, otherwise false.

| Improve this Doc View Source

TryGetGameChannel(IDMChannel, out IMessageChannel)

Declaration
protected static bool TryGetGameChannel(IDMChannel dmChannel, out IMessageChannel publicChannel)
Parameters
Type Name Description
IDMChannel dmChannel
IMessageChannel publicChannel
Returns
Type Description
Boolean
| Improve this Doc View Source

TryUpdateOpenToJoin(IMessageChannel, Boolean)

Updates the flag indicating if a game can be joined or not.

Declaration
public bool TryUpdateOpenToJoin(IMessageChannel channel, bool newValue)
Parameters
Type Name Description
IMessageChannel channel

A message channel. Can be both the public-facing channel or the DM channel of one of the players.

Boolean newValue

The new value.

Returns
Type Description
Boolean

true if the value was updated, otherwise false.

Explicit Interface Implementations

| Improve this Doc View Source

IDisposable.Dispose()

Declaration
void IDisposable.Dispose()

Implements

System.IDisposable
  • Improve this Doc
  • View Source
Back to top Generated by DocFX