More details coming soon!
Bet tier used for matching Players with different currencies. Next example showing how to get bet amount for specific bet tier and currency
public async Task<long> GetBetAmount(int betTier, string currency)
{
// get all bet tiers data
var betTires = await _fireball.Multiplayer.GetBetTiers(currency);
// find selected bet tier
var betTierData = betTires.Tiers.Find(b => b.Tier == betTier);
// return bet amount
return betTierData.Value;
}
public async Task<MessageResult> StartSearch(BaseMessage message)
{
// selected bet tier
var betTiers = new List<int>() { 0, 1 };
// game type or critersar/filters for match
var criterias = new List<string>()
{
"Card Game"
};
// set players count
var minPlayers = 2;
var maxPlayers = 4;
// additional gamer settings
var settings = new Dictionary<string, string>()
{
{ "Difficulty", "Hard" }
};
return await _fireball.Multiplayer.StartSearchMatch(betTiers, criterias, minPlayers, maxPlayers, settings, message);
}
public async Task<MessageResult> HandleMessage(ParseResult parseResult)
{
if (parseResult.IsSuccess)
{
switch (parseResult.MessageName)
{
...
case FireballConstants.MessagesNames.MULTIPLAYER_MATCH_START:
return await StartMultiplayerMatch(parseResult.ToMessage<MatchStartMessage>());
...
}
}
...
}
public async Task<MessageResult> StartMultiplayerMatch(MatchStartMessage message)
{
// get match bet tier
var betTier = message.Tier;
// get match game type/criteria/filter
var matchType = message.MatchCriteria;
// get match players
var players = message.GetPlayers();
...
}
public async Task<bool> IsSearchingMatch(BaseMessage message)
{
var matchesList = await _fireball.Multiplayer.GetSearchingMatches(message.OperatorPlayerId, message);
if (matchesList != null && matchesList.Count > 1)
{
// searching matches found
foreach (var matchData in matchesList)
{
// check match data
}
return true;
}
// not searching any match
return false;
}
public async Task<MessageResult> CancelSearchMatch(BaseMessage message)
{
return await _fireball.Multiplayer.CancelSearchMatch(message.OperatorPlayerId, message);
}
public class MyGameState
{
public int BetTier;
public string MatchType;
}
public async Task<MessageResult> StartMultiplayerMatch(MatchStartMessage message)
{
// get match players
var players = message.GetPlayers();
// create custom game state
var gameState = new MyGameState()
{
BetTier = message.Tier,
MatchType = message.MatchCriteria,
};
// create new game session
var gameSession = await _fireball.Multiplayer.CreateGameSession(players, gameState, message);
// send session message to each player
foreach (var player in players)
{
var sessionMessage = message.CreateSessionMessage(gameSession, player.OperatorPlayerId, gameState);
var result = await _fireball.SendSessionToClient(sessionMessage);
}
return MessageResult.SuccessResult("Match started");
}
public async Task<bool> OnEndGame(BaseMessage message)
{
// send close game session message
return await _fireball.Multiplayer.CloseGameSession(message.GameSession);
}
For sending message to all players use miltiplayer BroadcastMessage method
// create custom message
public class MultiplayerMessage : BaseMessage
{
public string GameStatus;
}
public async Task<MessageResult> SendGameStatus(BaseMessage message)
{
// create message for all players
var moveResultMessage = new MultiplayerMessage()
{
GameStatus = "Game Started!",
};
moveResultMessage.CopyBaseParams(message);
// send message for all players
return await _fireball.Multiplayer.BroadcastMessage(message.GameSession, moveResultMessage);
}
If game need to make wait for longer delay, or set action after timeout use ScheduleCallback method
// create message for shedule it
var sheduledMessage = new MultiplayerMessage()
{
GameStatus = "Game Timeout!",
};
sheduledMessage.CopyBaseParams(message);
// generate unique id
string callbackId = FireballTools.GenerateGUID();
// set delay in seconds
double delay = 5;
// shedule message
await _fireball.Multiplayer.ScheduleCallback(sheduledMessage, callbackId, delay);
// cancel shedule message
await _fireball.Multiplayer.DeleteCallback(sheduledMessage.Environment, sheduledMessage.GameId, callbackId);