123 lines
3.8 KiB
Go
123 lines
3.8 KiB
Go
package chat
|
|
|
|
import "context"
|
|
|
|
// ChannelDatabase defines database operations for chat channels
|
|
type ChannelDatabase interface {
|
|
// LoadWorldChannels retrieves all persistent world channels from database
|
|
LoadWorldChannels(ctx context.Context) ([]ChatChannelData, error)
|
|
|
|
// SaveChannel persists a channel to database (world channels only)
|
|
SaveChannel(ctx context.Context, channel ChatChannelData) error
|
|
|
|
// DeleteChannel removes a channel from database
|
|
DeleteChannel(ctx context.Context, channelName string) error
|
|
}
|
|
|
|
// ClientManager handles client communication for chat system
|
|
type ClientManager interface {
|
|
// SendChannelList sends available channels to a client
|
|
SendChannelList(characterID int32, channels []ChannelInfo) error
|
|
|
|
// SendChannelMessage delivers a message to a client
|
|
SendChannelMessage(characterID int32, message ChannelMessage) error
|
|
|
|
// SendChannelUpdate notifies client of channel membership changes
|
|
SendChannelUpdate(characterID int32, channelName string, action int, characterName string) error
|
|
|
|
// SendChannelUserList sends who list to client
|
|
SendChannelUserList(characterID int32, channelName string, members []ChannelMember) error
|
|
|
|
// IsClientConnected checks if a character is currently online
|
|
IsClientConnected(characterID int32) bool
|
|
}
|
|
|
|
// PlayerManager provides player information for chat system
|
|
type PlayerManager interface {
|
|
// GetPlayerInfo retrieves basic player information
|
|
GetPlayerInfo(characterID int32) (PlayerInfo, error)
|
|
|
|
// ValidatePlayer checks if player meets channel requirements
|
|
ValidatePlayer(characterID int32, levelReq, raceReq, classReq int32) bool
|
|
|
|
// GetPlayerLanguages returns languages known by player
|
|
GetPlayerLanguages(characterID int32) ([]int32, error)
|
|
}
|
|
|
|
// LanguageProcessor handles multilingual chat processing
|
|
type LanguageProcessor interface {
|
|
// ProcessMessage processes a message for language comprehension
|
|
ProcessMessage(senderID, receiverID int32, message string, languageID int32) (string, error)
|
|
|
|
// CanUnderstand checks if receiver can understand sender's language
|
|
CanUnderstand(senderID, receiverID int32, languageID int32) bool
|
|
|
|
// GetDefaultLanguage returns the default language for a character
|
|
GetDefaultLanguage(characterID int32) int32
|
|
}
|
|
|
|
// PlayerInfo contains basic player information needed for chat
|
|
type PlayerInfo struct {
|
|
CharacterID int32
|
|
CharacterName string
|
|
Level int32
|
|
Race int32
|
|
Class int32
|
|
IsOnline bool
|
|
}
|
|
|
|
// ChatAware interface for entities that can participate in chat
|
|
type ChatAware interface {
|
|
GetCharacterID() int32
|
|
GetCharacterName() string
|
|
GetLevel() int32
|
|
GetRace() int32
|
|
GetClass() int32
|
|
}
|
|
|
|
// EntityChatAdapter adapts entities to work with chat system
|
|
type EntityChatAdapter struct {
|
|
entity interface {
|
|
GetID() int32
|
|
// Add other entity methods as needed
|
|
}
|
|
playerManager PlayerManager
|
|
}
|
|
|
|
// GetCharacterID returns the character ID from the adapted entity
|
|
func (a *EntityChatAdapter) GetCharacterID() int32 {
|
|
return a.entity.GetID()
|
|
}
|
|
|
|
// GetCharacterName returns the character name from player manager
|
|
func (a *EntityChatAdapter) GetCharacterName() string {
|
|
if info, err := a.playerManager.GetPlayerInfo(a.entity.GetID()); err == nil {
|
|
return info.CharacterName
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// GetLevel returns the character level from player manager
|
|
func (a *EntityChatAdapter) GetLevel() int32 {
|
|
if info, err := a.playerManager.GetPlayerInfo(a.entity.GetID()); err == nil {
|
|
return info.Level
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// GetRace returns the character race from player manager
|
|
func (a *EntityChatAdapter) GetRace() int32 {
|
|
if info, err := a.playerManager.GetPlayerInfo(a.entity.GetID()); err == nil {
|
|
return info.Race
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// GetClass returns the character class from player manager
|
|
func (a *EntityChatAdapter) GetClass() int32 {
|
|
if info, err := a.playerManager.GetPlayerInfo(a.entity.GetID()); err == nil {
|
|
return info.Class
|
|
}
|
|
return 0
|
|
}
|