Skip to main content

FriendshipManager

A class in Root.Township, the global namespace.

Each Player has one. Holds that player's friend list, and on the client, whether that player is a friend of the local player. Data comes from the Alta social API.

Constructors​

MemberWhat it is
FriendshipManager()Creates a FriendshipManager with default values.

Fields​

2 private and internal fields
MemberWhat it is
private static Logger loggerNLog logger for this class.
private int playerUser ID of the player this manager belongs to, set in Setup.

Properties​

MemberWhat it is
List<UserInfo> Friends { get; }The friends' user info. Entries added by LocalStatusUpdate have the placeholder name [temp].
bool IsFriend { get; private set; }Whether this player is friends with the local player. Used for name boards.
bool IsUpdating { get; private set; }True while GetFriends is waiting on the API.
3 private and internal properties
MemberWhat it is
private HashSet<int> friendsIDs { get; }User IDs of this player's accepted friends, filled by GetFriends and status updates.
private HashSet<int> incomingRequestsIDs { get; }User IDs that sent this player a friend request.
private HashSet<int> outgoingRequestsIDs { get; }User IDs this player has sent friend requests to.

Events​

MemberWhat it is
static event Action<int, bool> AnyFriendshipStatusUpdatedStatic. Raised with the player's ID and new state whenever any player's IsFriend changes.
event Action FriendshipStatusUpdatedRaised when IsFriend changes or the friend list is reloaded.
static event Action LocalFriendshipStatusUpdatedStatic. Raised when the local player's friend list finishes loading or a friend is added on the client.

Methods​

MemberWhat it is
void AddFriend(FriendshipInfo newFriendShip)Adds a friend to the list. On the client also raises the update events.
bool FriendRequestReceived(int player)Whether this player has an incoming friend request from the given user. Only filled in for the local player.
bool FriendRequestSent(int player)Whether this player has sent a friend request to the given user. Only filled in for the local player.
async Task GetFriends(bool isLocalPlayer)Reloads the friend list from the API. For the local player it also loads sent and received requests. Skipped on clients for remote players.
FriendshipType GetFriendshipType(int player)Whether the given user is a friend, has a pending request either way, or neither.
bool IsFriendsWith(int player)Whether the given user ID is in this player's friend list.
void LocalStatusUpdate(int playerId, FriendshipType newStatus)Moves a user between friends, incoming and outgoing request lists without calling the API.
void Setup(int player)Sets which user ID this manager belongs to.
async void UpdateFromNetwork(IPlayer player)Asks the API whether this player and the given player are friends, then updates both managers.
void UpdateStatus(bool isFriend)Sets IsFriend and raises the events if it changed.
void UpdateStatusWithPlayer(bool isFriend, int playerId)Adds or removes a user ID from this player's friend list.

Used in​

Members of other types that take, return or hold a FriendshipManager: