events

package
v0.9.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2025 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoListenerSampleSize = 20

	First QueueFlag = 1
	Last  QueueFlag = 2
	//
	// Event return codes
	//
	// Allows the event to continu to the next listener
	Continue ListenerReturn = 0b00000001
	// Cancels any further processing of the event
	Cancel ListenerReturn = 0b00000010
	// Cancels processing, but adds back into the queue for the next event loop.
	CancelAndRequeue ListenerReturn = 0b00000100
)

Variables

This section is empty.

Functions

func AddToQueue

func AddToQueue(e Event, priority ...int)

Enqueue adds an event to the global queue. The caller can optionally pass a priority value. If omitted, the default priority is 0.

func ClearListeners

func ClearListeners()

func GetLogger

func GetLogger() eventLogger

func ProcessEvents

func ProcessEvents()

ProcessEvents runs the event loop until the queue is empty. It processes events one at a time in order of priority. Any events enqueued (even from within a handler) will be picked up in order.

func SetDebug

func SetDebug(on bool)

func UnregisterListener

func UnregisterListener(emptyEvent Event, id ListenerId) bool

Returns true if listener found and removed.

Types

type Broadcast

type Broadcast struct {
	Text             string
	TextScreenReader string // optional text for screenreader friendliness
	IsCommunication  bool
	SourceIsMod      bool
	SkipLineRefresh  bool
}

Messages that are intended to reach all users on the system

func (Broadcast) Type

func (b Broadcast) Type() string

type Buff

type Buff struct {
	UserId        int
	MobInstanceId int
	BuffId        int
	Source        string // optional source such as spell,
}

EVENT DEFINITIONS FOLLOW NOTE: If you give an event the following receiver function: `UniqueID() string`

      It will become a "unique event", meaning only one can be in the event queue
		 at a time matching the string return value.
	 Example: See `RedrawPrompt`

Used to apply or remove buffs

func (Buff) Type

func (b Buff) Type() string

type BuffsTriggered

type BuffsTriggered struct {
	UserId        int
	MobInstanceId int
	BuffIds       []int
}

func (BuffsTriggered) Type

func (b BuffsTriggered) Type() string

type CharacterChanged

type CharacterChanged struct {
	UserId            int
	LastCharacterName string
	CharacterName     string
}

Fired when a character alt change has occured.

func (CharacterChanged) Type

func (p CharacterChanged) Type() string

type CharacterCreated

type CharacterCreated struct {
	UserId        int
	CharacterName string
}

Fired after creating a new character and giving the character a name.

func (CharacterCreated) Type

func (p CharacterCreated) Type() string

type CharacterStatsChanged

type CharacterStatsChanged struct {
	UserId int
}

any stats or healthmax etc. have changed

func (CharacterStatsChanged) Type

func (p CharacterStatsChanged) Type() string

type CharacterTrained

type CharacterTrained struct {
	UserId int
}

Health, mana, etc.

func (CharacterTrained) Type

func (p CharacterTrained) Type() string

type CharacterVitalsChanged

type CharacterVitalsChanged struct {
	UserId int
}

Health, mana, etc.

func (CharacterVitalsChanged) Type

func (p CharacterVitalsChanged) Type() string

type Communication

type Communication struct {
	SourceUserId        int    // User that sent the message
	SourceMobInstanceId int    // Mob that sent the message
	TargetUserId        int    // Sent to only 1 person
	CommType            string // say, party, broadcast, whisper, shout
	Name                string
	Message             string
}

func (Communication) Type

func (m Communication) Type() string

type DayNightCycle

type DayNightCycle struct {
	IsSunrise bool
	Day       int
	Month     int
	Year      int
	Time      string
}

func (DayNightCycle) Type

func (l DayNightCycle) Type() string

type EquipmentChange

type EquipmentChange struct {
	UserId        int
	MobInstanceId int
	GoldChange    int
	BankChange    int
	ItemsWorn     []items.Item
	ItemsRemoved  []items.Item
}

Gained or lost an item

func (EquipmentChange) Type

func (i EquipmentChange) Type() string

type Event

type Event interface {
	Type() string
}

Event is the common interface for events.

type EventFlag

type EventFlag uint64
const (

	// Not using iota here to avoid accidentally renumbering if they get moved around.
	CmdNone                    EventFlag = 0
	CmdSkipScripts             EventFlag = 0b00000001                      // Skip any scripts that would normally process this command
	CmdSecretly                EventFlag = 0b00000010                      // User beahvior should not be alerted to the room
	CmdIsRequeue               EventFlag = 0b00000100                      // This command was a requeue. The flag is intended to help avoid a infinite requeue loop.
	CmdBlockInput              EventFlag = 0b00001000                      // This command when started sets user input to blocking all commands that don't AllowWhenDowned.
	CmdUnBlockInput            EventFlag = 0b00010000                      // When this command finishes, it will make sure user input is not blocked.
	CmdBlockInputUntilComplete EventFlag = CmdBlockInput | CmdUnBlockInput // SHortcut to include both in one command
)

func (*EventFlag) Add

func (f *EventFlag) Add(flag EventFlag)

func (EventFlag) Has

func (f EventFlag) Has(flag EventFlag) bool

func (*EventFlag) Remove

func (f *EventFlag) Remove(flag EventFlag)

type EventType

type EventType string

type GainExperience

type GainExperience struct {
	UserId     int
	Experience int
	Scale      int
}

func (GainExperience) Type

func (l GainExperience) Type() string

type GenericEvent

type GenericEvent interface {
	Event
	Data(name string) any
}

Generic events are mostly used for plugins

type Input

type Input struct {
	UserId        int
	MobInstanceId int
	InputText     string
	ReadyTurn     uint64
	Flags         EventFlag
}

Used for Input from players/mobs

func (Input) Type

func (i Input) Type() string

type ItemOwnership

type ItemOwnership struct {
	UserId        int
	MobInstanceId int
	Item          items.Item
	Gained        bool
}

Gained or lost an item

func (ItemOwnership) Type

func (i ItemOwnership) Type() string

type LevelUp

type LevelUp struct {
	UserId         int
	RoomId         int
	Username       string
	CharacterName  string
	LevelsGained   int
	NewLevel       int
	StatsDelta     stats.Statistics
	TrainingPoints int
	StatPoints     int
	LivesGained    int
}

func (LevelUp) Type

func (l LevelUp) Type() string

type Listener

type Listener func(Event) ListenerReturn

Return false to stop further handling of this event.

type ListenerId

type ListenerId uint64

func RegisterListener

func RegisterListener(emptyEvent any, cbFunc Listener, qFlag ...QueueFlag) ListenerId

Returns an ID for the listener which can be used to unregister later.

type ListenerReturn

type ListenerReturn int8

func DoListeners

func DoListeners(e Event) ListenerReturn

type ListenerWrapper

type ListenerWrapper struct {
	// contains filtered or unexported fields
}

type Log

type Log struct {
	FollowAdd    connections.ConnectionId
	FollowRemove connections.ConnectionId
	Level        string
	Data         []any
}

func (Log) Type

func (l Log) Type() string

type Looking

type Looking struct {
	UserId int
	RoomId int
	Target string
	Hidden bool
}

func (Looking) Type

func (l Looking) Type() string

type MSP

type MSP struct {
	UserId    int
	SoundType string // SOUND or MUSIC
	SoundFile string
	Volume    int    // 1-100
	Category  string // special category/type for MSP string
}

Payloads describing sound/music to play

func (MSP) Type

func (m MSP) Type() string

type Message

type Message struct {
	UserId          int
	ExcludeUserIds  []int
	RoomId          int
	Text            string
	IsQuiet         bool // whether it can only be heard by superior "hearing"
	IsCommunication bool // If true, this is a communication such as "say" or "emote"
}

func (Message) Type

func (m Message) Type() string

type MobDeath

type MobDeath struct {
	MobId         int
	InstanceId    int
	RoomId        int
	CharacterName string
	Level         int
	PlayerDamage  map[int]int
}

func (MobDeath) Type

func (l MobDeath) Type() string

type MobIdle

type MobIdle struct {
	MobInstanceId int
}

Anytime a mob is idle

func (MobIdle) Type

func (i MobIdle) Type() string

type NewRound

type NewRound struct {
	RoundNumber uint64
	TimeNow     time.Time
}

Fired every new round

func (NewRound) Type

func (n NewRound) Type() string

type NewTurn

type NewTurn struct {
	TurnNumber uint64
	TimeNow    time.Time
}

Each new turn (TurnMs in config.yaml)

func (NewTurn) Type

func (n NewTurn) Type() string

type Party

type Party struct {
	LeaderUserId  int
	UserIds       []int
	InviteUserIds []int
	AutoAttackers []int
	Position      map[int]string
}

func (Party) Type

func (p Party) Type() string

type PartyUpdated

type PartyUpdated struct {
	Action  string // create, disband, membership
	UserIds []int
}

any stats or healthmax etc. have changed

func (PartyUpdated) Type

func (p PartyUpdated) Type() string

type PlayerDeath

type PlayerDeath struct {
	UserId        int
	RoomId        int
	Username      string
	CharacterName string
	Permanent     bool
	KilledByUsers []int
}

func (PlayerDeath) Type

func (l PlayerDeath) Type() string

type PlayerDespawn

type PlayerDespawn struct {
	UserId        int
	RoomId        int
	Username      string
	CharacterName string
	TimeOnline    string
}

Left the world

func (PlayerDespawn) Type

func (p PlayerDespawn) Type() string

type PlayerDrop

type PlayerDrop struct {
	UserId int
	RoomId int
}

func (PlayerDrop) Type

func (l PlayerDrop) Type() string

type PlayerSpawn

type PlayerSpawn struct {
	UserId        int
	ConnectionId  uint64
	RoomId        int
	Username      string
	CharacterName string
}

Entered the world

func (PlayerSpawn) Type

func (p PlayerSpawn) Type() string

type Quest

type Quest struct {
	UserId     int
	QuestToken string
}

Used for giving/taking quest progress

func (Quest) Type

func (q Quest) Type() string

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

A go-routine safe FIFO (first in first out) data stucture.

func NewQueue

func NewQueue[T any]() *Queue[T]

Creates a new pointer to a new queue.

func (*Queue[T]) Len

func (q *Queue[T]) Len() int

Returns the number of elements in the queue (i.e. size/length) go-routine safe.

func (*Queue[T]) Peek

func (q *Queue[T]) Peek() T

Returns a read value at the front of the queue. i.e. the oldest value in the queue. Note: this function does NOT mutate the queue. go-routine safe.

func (*Queue[T]) Poll

func (q *Queue[T]) Poll() T

Returns the value at the front of the queue. i.e. the oldest value in the queue. Note: this function does mutate the queue. go-routine safe.

func (*Queue[T]) Push

func (q *Queue[T]) Push(item T)

Pushes/inserts a value at the end/tail of the queue. Note: this function does mutate the queue. go-routine safe.

func (*Queue[T]) Shift

func (q *Queue[T]) Shift(item T)

Shifts/inserts a value at the front/head of the queue. Note: this function does mutate the queue. go-routine safe.

type QueueFlag

type QueueFlag int

type RebuildMap

type RebuildMap struct {
	MapRootRoomId int
	SkipIfExists  bool
}

Rebuilds mapper for a given RoomId NOTE: RoomId should USUALLY be the Room's Zone.RootRoomId

func (RebuildMap) Type

func (r RebuildMap) Type() string

func (RebuildMap) UniqueID

func (r RebuildMap) UniqueID() string

type RedrawPrompt

type RedrawPrompt struct {
	UserId        int
	OnlyIfChanged bool
}

func (RedrawPrompt) Type

func (l RedrawPrompt) Type() string

func (RedrawPrompt) UniqueID

func (l RedrawPrompt) UniqueID() string

type RoomAction

type RoomAction struct {
	RoomId       int
	SourceUserId int
	SourceMobId  int
	Action       string
	Details      any
	ReadyTurn    uint64
}

For special room-targetting actions

func (RoomAction) Type

func (r RoomAction) Type() string

type RoomChange

type RoomChange struct {
	UserId        int
	MobInstanceId int
	FromRoomId    int
	ToRoomId      int
	Unseen        bool
}

Fired whenever a mob or player changes rooms

func (RoomChange) Type

func (r RoomChange) Type() string

type ScriptedEvent

type ScriptedEvent struct {
	Name string
	Data map[string]any
}

Triggered by a script

func (ScriptedEvent) Type

func (s ScriptedEvent) Type() string

type System

type System struct {
	Command     string
	Data        any
	Description string
}

Messages that are intended to reach all users on the system

func (System) Type

func (s System) Type() string

type UserSettingChanged

type UserSettingChanged struct {
	UserId int
	Name   string
}

func (UserSettingChanged) Type

func (i UserSettingChanged) Type() string

type WebClientCommand

type WebClientCommand struct {
	ConnectionId uint64
	Text         string
}

Special commands that only the webclient is equipped to handle

func (WebClientCommand) Type

func (w WebClientCommand) Type() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL