83 lines
1.5 KiB
Go
83 lines
1.5 KiB
Go
package events
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
|
|
"eq2emu/internal/entity"
|
|
"eq2emu/internal/quests"
|
|
"eq2emu/internal/spawn"
|
|
)
|
|
|
|
// EventType represents different types of events
|
|
type EventType int
|
|
|
|
const (
|
|
EventTypeSpell EventType = iota
|
|
EventTypeSpawn
|
|
EventTypeQuest
|
|
EventTypeCombat
|
|
EventTypeZone
|
|
EventTypeItem
|
|
)
|
|
|
|
func (et EventType) String() string {
|
|
switch et {
|
|
case EventTypeSpell:
|
|
return "spell"
|
|
case EventTypeSpawn:
|
|
return "spawn"
|
|
case EventTypeQuest:
|
|
return "quest"
|
|
case EventTypeCombat:
|
|
return "combat"
|
|
case EventTypeZone:
|
|
return "zone"
|
|
case EventTypeItem:
|
|
return "item"
|
|
default:
|
|
return "unknown"
|
|
}
|
|
}
|
|
|
|
// EventContext provides context for event handling
|
|
type EventContext struct {
|
|
// Core context
|
|
Context context.Context
|
|
|
|
// Event information
|
|
EventType EventType
|
|
EventName string
|
|
FunctionName string
|
|
|
|
// Game objects (nil if not applicable)
|
|
Caster *entity.Entity
|
|
Target *entity.Entity
|
|
Spawn *spawn.Spawn
|
|
Quest *quests.Quest
|
|
|
|
// Parameters and results
|
|
Parameters map[string]any
|
|
Results map[string]any
|
|
|
|
// Synchronization
|
|
mutex sync.RWMutex
|
|
}
|
|
|
|
// EventFunction represents a callable event function
|
|
type EventFunction func(ctx *EventContext) error
|
|
|
|
// EventHandler manages event registration and execution
|
|
type EventHandler struct {
|
|
events map[string]EventFunction
|
|
mutex sync.RWMutex
|
|
}
|
|
|
|
// EventLogger provides logging for events
|
|
type EventLogger interface {
|
|
Debug(msg string, args ...any)
|
|
Info(msg string, args ...any)
|
|
Warn(msg string, args ...any)
|
|
Error(msg string, args ...any)
|
|
}
|