Module server.team_matchmaker.player_party

Classes

class GroupInvite (recipient: Player,
created_at: float)
Expand source code
class GroupInvite(NamedTuple):
    recipient: Player
    created_at: float

    def is_expired(self) -> bool:
        return time.time() - self.created_at >= PARTY_INVITE_TIMEOUT

GroupInvite(recipient, created_at)

Ancestors

  • builtins.tuple

Instance variables

var created_at : float
Expand source code
class GroupInvite(NamedTuple):
    recipient: Player
    created_at: float

    def is_expired(self) -> bool:
        return time.time() - self.created_at >= PARTY_INVITE_TIMEOUT

Alias for field number 1

var recipientPlayer
Expand source code
class GroupInvite(NamedTuple):
    recipient: Player
    created_at: float

    def is_expired(self) -> bool:
        return time.time() - self.created_at >= PARTY_INVITE_TIMEOUT

Alias for field number 0

Methods

def is_expired(self) ‑> bool
Expand source code
def is_expired(self) -> bool:
    return time.time() - self.created_at >= PARTY_INVITE_TIMEOUT
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()]
    }