Module server.team_matchmaker
The team matchmaking system
Used to keep track of current player parties, manage players joining/leaving and matching them against each other used for matchmaking in the global rating system
Sub-modules
server.team_matchmaker.party_member
server.team_matchmaker.player_party
Classes
class PartyMember (player: Player)
-
Expand source code
class PartyMember: def __init__(self, player: Player): self.player = player self.factions = [ Faction.uef, Faction.aeon, Faction.cybran, Faction.seraphim ] def set_player_faction(self) -> None: assert self.factions, "At least one faction must be allowed!" # NOTE: In the far fetched future we may want to limit the list of # playable factions for special game modes. For flexibility we will # assume for now that the client will take care of this for us. self.player.faction = random.choice(self.factions) def to_dict(self): return { "player": self.player.id, "factions": list(faction.name for faction in self.factions) }
Methods
def set_player_faction(self) ‑> None
-
Expand source code
def set_player_faction(self) -> None: assert self.factions, "At least one faction must be allowed!" # NOTE: In the far fetched future we may want to limit the list of # playable factions for special game modes. For flexibility we will # assume for now that the client will take care of this for us. self.player.faction = random.choice(self.factions)
def to_dict(self)
-
Expand source code
def to_dict(self): return { "player": self.player.id, "factions": list(faction.name for faction in self.factions) }
class PlayerParty (owner: Player)
-
Expand source code
class PlayerParty(): def __init__(self, owner: Player): self._members = { owner: PartyMember(owner) } self.invited_players = {} self.owner = owner def __contains__(self, player: Player) -> bool: return player in self._members def __iter__(self): return iter(self._members.values()) @property def members(self) -> frozenset[PartyMember]: return frozenset(self._members.values()) @property def players(self) -> list[Player]: return list(member.player for member in self._members.values()) def is_disbanded(self) -> bool: return not any(m.player == self.owner for m in self._members.values()) def get_member_by_player(self, player: Player) -> Optional[PartyMember]: return self._members.get(player) def add_player(self, player: Player) -> None: self._members[player] = PartyMember(player) def remove_player(self, player: Player) -> None: assert player in self._members del self._members[player] if player == self.owner: self.invited_players.clear() def add_member(self, member: PartyMember) -> None: self._members[member.player] = member def add_invited_player(self, player: Player) -> None: self.invited_players[player] = GroupInvite(player, time.time()) def remove_invited_player(self, player: Player) -> None: assert player in self.invited_players del self.invited_players[player] def set_factions(self, player: Player, factions: list[Faction]) -> None: self._members[player].factions = factions def on_matched(self, search1: Search, search2: Search) -> None: for member in self: member.set_player_faction() async def send_party(self, player: Player) -> None: await player.send_message({ "command": "update_party", **self.to_dict() }) def clear(self): self._members.clear() self.invited_players.clear() def to_dict(self): return { "owner": self.owner.id, "members": [m.to_dict() for m in self._members.values()] }
Instance variables
prop members : frozenset[PartyMember]
-
Expand source code
@property def members(self) -> frozenset[PartyMember]: return frozenset(self._members.values())
prop players : list[Player]
-
Expand source code
@property def players(self) -> list[Player]: return list(member.player for member in self._members.values())
Methods
def add_invited_player(self,
player: Player) ‑> None-
Expand source code
def add_invited_player(self, player: Player) -> None: self.invited_players[player] = GroupInvite(player, time.time())
def add_member(self,
member: PartyMember) ‑> None-
Expand source code
def add_member(self, member: PartyMember) -> None: self._members[member.player] = member
def add_player(self,
player: Player) ‑> None-
Expand source code
def add_player(self, player: Player) -> None: self._members[player] = PartyMember(player)
def clear(self)
-
Expand source code
def clear(self): self._members.clear() self.invited_players.clear()
def get_member_by_player(self,
player: Player) ‑> PartyMember | None-
Expand source code
def get_member_by_player(self, player: Player) -> Optional[PartyMember]: return self._members.get(player)
def is_disbanded(self) ‑> bool
-
Expand source code
def is_disbanded(self) -> bool: return not any(m.player == self.owner for m in self._members.values())
def on_matched(self,
search1: Search,
search2: Search) ‑> None-
Expand source code
def on_matched(self, search1: Search, search2: Search) -> None: for member in self: member.set_player_faction()
def remove_invited_player(self,
player: Player) ‑> None-
Expand source code
def remove_invited_player(self, player: Player) -> None: assert player in self.invited_players del self.invited_players[player]
def remove_player(self,
player: Player) ‑> None-
Expand source code
def remove_player(self, player: Player) -> None: assert player in self._members del self._members[player] if player == self.owner: self.invited_players.clear()
async def send_party(self,
player: Player) ‑> None-
Expand source code
async def send_party(self, player: Player) -> None: await player.send_message({ "command": "update_party", **self.to_dict() })
def set_factions(self,
player: Player,
factions: list[Faction]) ‑> None-
Expand source code
def set_factions(self, player: Player, factions: list[Faction]) -> None: self._members[player].factions = factions
def to_dict(self)
-
Expand source code
def to_dict(self): return { "owner": self.owner.id, "members": [m.to_dict() for m in self._members.values()] }