IFriendController - jimdroberts/FishMMO GitHub Wiki
Interface for friend controllers, providing access and management for a character's friend list. Used to add, remove, and track friends, and handle related events.
-
event Action<long, bool> OnAddFriend
Event invoked when a friend is added. Parameters: friend ID, online status.
-
event Action OnRemoveFriend
Event invoked when a friend is removed. Parameter: friend ID.
-
HashSet Friends { get; }
Set of friend IDs for this character.
-
void AddFriend(long friendID)
Adds a friend by ID if not already present. friendID (long): The ID of the friend to add.
- Implement IFriendController on your character or controller class.
- Provide logic for managing the Friends set and handling events.
- Use AddFriend to add friends by their ID.
// Example 1: Implementing IFriendController
public class MyFriendController : IFriendController {
public event Action<long, bool> OnAddFriend;
public event Action<long> OnRemoveFriend;
public HashSet<long> Friends { get; private set; } = new HashSet<long>();
public void AddFriend(long friendID) {
if (!Friends.Contains(friendID)) Friends.Add(friendID);
}
}
// Example 2: Using the interface
friendController.AddFriend(1234567890L);
- Always use AddFriend to add friends to ensure duplicates are not added.
- Subscribe to OnAddFriend and OnRemoveFriend to update UI or trigger gameplay logic.
- Keep the Friends set up to date and clear it on character reset or logout.