Avalon Online

Avalon Online

General Informations

Context

Avalon is extension of a hidden role playing boardgame named : The Resistance. In this extension, each role represent a character of the Legend Of King Arthur. Each role is part of one team, the arthur one and the mordred one, and has special power in the game. 

avalonOnlineBoardGame

My goal is to reproduce this extension in online version by creating a multiplayer video game where can join each other everywhere.

Main objectives were : 

  1. Think about the adaptation this boardgame in videogame
  2. Create a online videogame on Unity from scratch

Online Architecture

Pyr to pyr system

A player is hosting the game for everyone, no dedicated servers

pyrToPyrSystem

Main C# online classes

Network Manager

networkManagerHighlightImportantPart

This class is used to manage the online part with all multiplayers settings, in my case, I used it to set the number of player, to start and shutdown the server, and to spawn player class prefab when a new client is connected.

Player

avalonPlayerFull

The player is the class spawn by the Network Manager, it is handling by each client of the server and used to send information from a client to the server.

Network behavior

Network Behavior is used in online game instead of Mono Behavior, the goal is to call some multiplayer specific funtion like Server Rpc or Client Rpc. Basically, all classes that implement online in their code need to dervive from Network Behavior.

Code Architecture

Network Functions

There are two main functions used in Network Behavior :

  • [Server Rpc] Function : called by the server itself (in my case the host)
  • [Client Rpc] Function : called for each client of the server

Logic

codeArchitecture

Main Features

LObby System

  • Host chooses the player number before starting the server, when host changes the number, it is directly update in network manager.

 

  • When a player prefab is instantied, player can change the pseudo and set him ready as he wants. Those parameter are stack in boolean variables and string variables.
    Each parameters has 2 types of variables that are updated at the same time when player modifies them :

                  1 – The classic variable : visible and show by players wich are already in the lobby
                  2 – The network variable : catched by player when they arrive in the lobby (to have the right state of the variable at the begining)

Avalon Wood Tower

Avalon Wood Tower is a C# class that contains lots of element that player will interact with (pannel, visual effect…). Each player on server is linked with only one Avalon Wood Tower.

At the opening of the map the right number avalon wood tower is placed in circle around the central point of the map. All elements contained in this scipt are linked with the player.

Skin System

Player can change skin before the game starting. For that there are 2 different scripts on the player prefab that manage that. One is managing the skin during the game (when it was modifying) and another when player is currently modifying it.

Those scripts contain all skin meshes that are splited in many part depending of each skin (head, upper body…).

Each part have a specific RGB, Hue and Saturation value. Once the player opens the modifying menu, those values are represented on an interface, when player moving cursors values changes locally.

When player click on the modifying colors button, color values are updated for every players in the session following the online code architecture.

Set up Game rules

When host starts the game map, he starts in setup mode that allowed to set the game rules.

The most important is the role selection : mandatory role are selected automaticly and cannot be unselected. Host can choose other role as he wants.

There are other rules like timer between round or possibility to see player’s vote that could be modified.

When rule are well set up (only depending of the role number that are selected) the start game button appears that allow to host to access to player mode. Once he is in player mode, he can start the game by clicking on the « Start Game » pannel or return to set up rules by clicking on the « Parameters » pannel.

Random selection

When game starts, there are two parameters that are set randomly by the system :

The different roles : 

To select randomly a role for each player, on server side we take the list of selected roles and for each player in the player list we select a random integer from 0 to the last valid index of role list

This role is linked, for each client, to the current player in the list and removed from the selected role list

On setup side, even if the role is activated for each client, the UI regarding the role is only activated for the client that controls this player prefab.

 

The player who selects the quest for the first round :

For the first player to select quest, it’s the same process but more simple, we just take a random number from 0 to last valid index of player list and we setup this player as the first quest selector that consisting into active visuals and colliders (quest and other players) to interact with them. For the other players, visuals are activated but colliders disabled to doesn’t allowed to interact with them.

Choose quest & Team

During each round a chief is seletcted to selected quest and the team who will go in quest.

The chief needs to select a quest first, he has the choice among 5 different quests, only the uncomplited quest are selectable. Once the quest is selected visuals are updated in world and on the UI for each client.

After the quest selection , the quest selection, the chief needs to select the required number corresponding to the selected quest. Chief can click on player to select him and click a new time to unselect him.

Player votes

After the team selection phase and during the quest phase, players need to vote and choose between to option (Yes or No) and (Success or Failure), that are represented by a boolean. When a player interact with a vote pannel, this variable is modified and an event is sent to the server to know if all players have voted. If its the case we check the number of true and false vote, check the number of each vote needed to calcul and show the result