IChatHelper - jimdroberts/FishMMO GitHub Wiki
Interface for chat helper functionality in FishMMO. Provides methods for handling chat commands and processing messages for each chat channel, enabling extensible and consistent chat behavior across the system.
-
ChatCommand GetChannelCommand(ChatChannel channel)
Gets the chat command delegate for a specific chat channel. channel: Chat channel to get the command for. Returns: ChatCommand delegate for the channel.
-
bool OnWorldChat(IPlayerCharacter sender, ChatBroadcast msg)
Handles a world chat message. sender: Sender character. msg: Chat message broadcast. Returns: True if the message should be written to the database.
-
bool OnRegionChat(IPlayerCharacter sender, ChatBroadcast msg)
Handles a region chat message. sender: Sender character. msg: Chat message broadcast. Returns: True if the message should be written to the database.
-
bool OnPartyChat(IPlayerCharacter sender, ChatBroadcast msg)
Handles a party chat message. sender: Sender character. msg: Chat message broadcast. Returns: True if the message should be written to the database.
-
bool OnGuildChat(IPlayerCharacter sender, ChatBroadcast msg)
Handles a guild chat message. sender: Sender character. msg: Chat message broadcast. Returns: True if the message should be written to the database.
-
bool OnTellChat(IPlayerCharacter sender, ChatBroadcast msg)
Handles a tell (private) chat message. sender: Sender character. msg: Chat message broadcast. Returns: True if the message should be written to the database.
-
bool OnTradeChat(IPlayerCharacter sender, ChatBroadcast msg)
Handles a trade chat message. sender: Sender character. msg: Chat message broadcast. Returns: True if the message should be written to the database.
-
bool OnSayChat(IPlayerCharacter sender, ChatBroadcast msg)
Handles a say (local) chat message. sender: Sender character. msg: Chat message broadcast. Returns: True if the message should be written to the database.
- Implement the
IChatHelper
interface in a class. - Provide logic for each chat channel method (e.g., OnWorldChat, OnRegionChat, etc.).
- Register the implementation with the chat system or dependency injection container as needed.
// Example 1: Implementing IChatHelper for custom chat handling
public class MyChatHelper : IChatHelper {
public ChatCommand GetChannelCommand(ChatChannel channel) {
// Return appropriate command delegate
}
public bool OnWorldChat(IPlayerCharacter sender, ChatBroadcast msg) {
// Handle world chat
return true;
}
// Implement other methods similarly...
}
// Example 2: Using the chat helper in a chat manager
IChatHelper chatHelper = new MyChatHelper();
bool result = chatHelper.OnWorldChat(player, message);
- Always implement all interface methods to ensure consistent chat behavior.
- Validate and sanitize chat messages before processing or storing them.
- Use dependency injection to manage chat helper implementations for flexibility and testability.