public int UpdateFriendship(int delta) { int prevFriendship = Friendship; int newFriendship = Math.Max(0, Math.Min(MaxFriendship, Friendship + delta)); int actualDelta = newFriendship - Friendship; OnUpdateFriendship?.Invoke(this, new UpdateFriendshipEventArgs(this, actualDelta)); Friendship += actualDelta; OnFriendshipUpdated?.Invoke(this, new FriendshipUpdatedEventArgs(this, prevFriendship)); return(Friendship); }
public void UpdateFriendshipStatus(FriendshipUpdateStatusMessage msg) { if (!friends.ContainsKey(msg.userId)) { friends.Add(msg.userId, new UserStatus() { }); } switch (msg.action) { case FriendshipAction.NONE: break; case FriendshipAction.APPROVED: friends[msg.userId].friendshipStatus = FriendshipStatus.FRIEND; break; case FriendshipAction.REJECTED: friends[msg.userId].friendshipStatus = FriendshipStatus.NONE; break; case FriendshipAction.CANCELLED: friends[msg.userId].friendshipStatus = FriendshipStatus.NONE; break; case FriendshipAction.REQUESTED_FROM: friends[msg.userId].friendshipStatus = FriendshipStatus.REQUESTED_FROM; break; case FriendshipAction.REQUESTED_TO: friends[msg.userId].friendshipStatus = FriendshipStatus.REQUESTED_TO; break; case FriendshipAction.DELETED: friends[msg.userId].friendshipStatus = FriendshipStatus.NONE; break; } if (VERBOSE) { Debug.Log($"Change friend status of {msg.userId} to {friends[msg.userId].friendshipStatus}"); } if (friends[msg.userId].friendshipStatus == FriendshipStatus.NONE) { friends.Remove(msg.userId); } OnUpdateFriendship?.Invoke(msg.userId, msg.action); }
public void RaiseUpdateFriendship(string id, FriendshipAction action) { if (action == FriendshipAction.NONE) { if (friends.ContainsKey(id)) { friends.Remove(id); } } if (action == FriendshipAction.APPROVED) { if (!friends.ContainsKey(id)) { friends.Add(id, new FriendsController.UserStatus()); } } OnUpdateFriendship?.Invoke(id, action); }