Documentation
¶
Index ¶
- Constants
- func AddToQueue(e Event, priority ...int)
- func ClearListeners()
- func GetLogger() eventLogger
- func ProcessEvents()
- func SetDebug(on bool)
- func UnregisterListener(emptyEvent Event, id ListenerId) bool
- type AggroGained
- type AggroLost
- type AttackAvoided
- type Broadcast
- type Buff
- type BuffsTriggered
- type CharacterAlignmentChanged
- type CharacterChanged
- type CharacterCreated
- type CharacterStatsChanged
- type CharacterTrained
- type CharacterVitalsChanged
- type CombatActionCompleted
- type CombatActionInterrupted
- type CombatActionStarted
- type CombatEffectTriggered
- type CombatEnded
- type CombatStarted
- type CombatantFled
- type Communication
- type DamageDealt
- type DayNightCycle
- type EquipmentChange
- type Event
- type EventFlag
- type EventType
- type ExitLockChanged
- type GainExperience
- type GenericEvent
- type HealingReceived
- type Input
- type ItemOwnership
- type LevelUp
- type Listener
- type ListenerId
- type ListenerReturn
- type ListenerWrapper
- type Log
- type Looking
- type MSP
- type Message
- type MobDeath
- type MobIdle
- type MobStatusChanged
- type MobVitalsChanged
- type NewRound
- type NewTurn
- type Party
- type PartyUpdated
- type PlayerDeath
- type PlayerDespawn
- type PlayerDrop
- type PlayerSpawn
- type Quest
- type Queue
- type QueueFlag
- type RebuildMap
- type RedrawPrompt
- type RoomAction
- type RoomChange
- type ScriptedEvent
- type System
- type TargetChanged
- type UserSettingChanged
- type WebClientCommand
Constants ¶
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 ¶
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 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 UnregisterListener ¶
func UnregisterListener(emptyEvent Event, id ListenerId) bool
Returns true if listener found and removed.
Types ¶
type AggroGained ¶
type AggroGained struct {
MobId int
MobName string
TargetId int
TargetType string // "player" or "mob"
TargetName string
IsInitial bool // True if this is the first aggro
ThreatLevel int
}
AggroGained fires when a mob becomes hostile to someone
func (AggroGained) Type ¶
func (a AggroGained) Type() string
type AggroLost ¶
type AggroLost struct {
MobId int
MobName string
TargetId int
TargetType string // "player" or "mob"
TargetName string
Reason string // "death", "distance", "reset", "peace", etc.
}
AggroLost fires when a mob stops being hostile
type AttackAvoided ¶
type AttackAvoided struct {
AttackerId int
AttackerType string // "player" or "mob"
AttackerName string
DefenderId int
DefenderType string // "player" or "mob"
DefenderName string
AvoidType string // "miss", "dodge", "parry", "block"
WeaponName string
}
AttackAvoided fires when an attack fails to connect
func (AttackAvoided) Type ¶
func (a AttackAvoided) Type() string
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
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
type BuffsTriggered ¶
func (BuffsTriggered) Type ¶
func (b BuffsTriggered) Type() string
type CharacterAlignmentChanged ¶
func (CharacterAlignmentChanged) Type ¶
func (p CharacterAlignmentChanged) Type() string
type CharacterChanged ¶
Fired when a character alt change has occured.
func (CharacterChanged) Type ¶
func (p CharacterChanged) Type() string
type CharacterCreated ¶
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 CombatActionCompleted ¶
type CombatActionCompleted struct {
EntityId int
EntityType string // "player" or "mob"
EntityName string
Action string
ActionName string
Success bool
FailureReason string
}
CombatActionCompleted fires when an action finishes (successfully or not)
func (CombatActionCompleted) Type ¶
func (c CombatActionCompleted) Type() string
type CombatActionInterrupted ¶
type CombatActionInterrupted struct {
EntityId int
EntityType string // "player" or "mob"
EntityName string
Action string
ActionName string
InterruptedById int
InterruptedByType string // Type of interrupter
InterruptedByName string
InterruptType string // "damage", "stun", "silence", etc.
}
CombatActionInterrupted fires when an action is interrupted before completion
func (CombatActionInterrupted) Type ¶
func (c CombatActionInterrupted) Type() string
type CombatActionStarted ¶
type CombatActionStarted struct {
EntityId int
EntityType string // "player" or "mob"
EntityName string
Action string // "spell", "ability", "item", etc.
ActionName string
TargetId int
TargetName string
CastTime float64 // Time to complete in seconds
Interruptible bool
}
CombatActionStarted fires when combat actions begin (casting, channeling, etc.)
func (CombatActionStarted) Type ¶
func (c CombatActionStarted) Type() string
type CombatEffectTriggered ¶
type CombatEffectTriggered struct {
SourceId int
SourceName string
TargetId int
TargetType string // "player" or "mob"
TargetName string
Effect string // "bleed", "poison", "burn", etc.
Damage int
TicksRemaining int
}
CombatEffectTriggered fires when DoTs, bleeds, or other effects tick
func (CombatEffectTriggered) Type ¶
func (c CombatEffectTriggered) Type() string
type CombatEnded ¶
type CombatEnded struct {
EntityId int
EntityType string // "player" or "mob"
EntityName string
Reason string // "fled", "broke", "peace", "distance", etc.
RoomId int
Duration int // Combat duration in seconds
}
CombatEnded fires when combat ends (not due to death)
func (CombatEnded) Type ¶
func (c CombatEnded) Type() string
type CombatStarted ¶
type CombatStarted struct {
AttackerId int
AttackerType string // "player" or "mob"
AttackerName string
DefenderId int
DefenderType string // "player" or "mob"
DefenderName string
RoomId int
InitiatedBy string // command/action that started combat
}
CombatStarted fires when combat begins between entities
func (CombatStarted) Type ¶
func (c CombatStarted) Type() string
type CombatantFled ¶
type CombatantFled struct {
EntityId int
EntityType string // "player" or "mob"
EntityName string
Direction string
Success bool
PreventedBy string // What prevented it (if failed)
}
CombatantFled fires when someone attempts to flee
func (CombatantFled) Type ¶
func (c CombatantFled) 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 DamageDealt ¶
type DamageDealt struct {
SourceId int
SourceType string // "player" or "mob"
SourceName string
TargetId int
TargetType string // "player" or "mob"
TargetName string
Amount int
DamageType string // "physical", "magical", "fire", etc.
WeaponName string // Name of weapon used (if applicable)
SpellName string // Name of spell used (if applicable)
IsCritical bool
IsKillingBlow bool
}
DamageDealt fires immediately after damage calculation and application
func (DamageDealt) Type ¶
func (d DamageDealt) Type() string
type DayNightCycle ¶
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 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 CmdNoRoomGMCP EventFlag = 0b00100000 // Skip GMCP room updates for this command (used to prevent duplicate sends) )
type ExitLockChanged ¶
type ExitLockChanged struct {
Event
RoomId int
ExitName string
Locked bool // true if now locked, false if now unlocked
}
ExitLockChanged fires when an exit's lock state changes
func (ExitLockChanged) Type ¶
func (e ExitLockChanged) Type() string
type GainExperience ¶
func (GainExperience) Type ¶
func (l GainExperience) Type() string
type GenericEvent ¶
Generic events are mostly used for plugins
type HealingReceived ¶
type HealingReceived struct {
SourceId int
SourceType string // "player", "mob", "item", "regen"
SourceName string
TargetId int
TargetType string // "player" or "mob"
TargetName string
Amount int
HealType string // "spell", "potion", "regen", "item", etc.
SpellName string // Name of healing spell (if applicable)
IsOverheal bool
}
HealingReceived fires whenever health is restored
func (HealingReceived) Type ¶
func (h HealingReceived) Type() string
type Input ¶
type Input struct {
UserId int
MobInstanceId int
InputText string
ReadyTurn uint64
Flags EventFlag
}
Used for Input from players/mobs
type ItemOwnership ¶
Gained or lost an item
func (ItemOwnership) Type ¶
func (i ItemOwnership) Type() string
type LevelUp ¶
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
}
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
type Message ¶
type MobDeath ¶
type MobStatusChanged ¶
type MobStatusChanged struct {
MobId int
Status string // "stunned", "blinded", "slowed", etc.
Added bool // True if added, false if removed
Duration int // Duration in seconds (0 for permanent)
SourceId int // Who applied the status
}
MobStatusChanged fires when status effects are applied/removed from mobs
func (MobStatusChanged) Type ¶
func (m MobStatusChanged) Type() string
type MobVitalsChanged ¶
type MobVitalsChanged struct {
MobId int
OldHealth int
NewHealth int
OldMana int
NewMana int
ChangeType string // "damage", "heal", "regen", etc.
}
MobVitalsChanged fires whenever a mob's health or mana changes
func (MobVitalsChanged) Type ¶
func (m MobVitalsChanged) Type() string
type Party ¶
type PartyUpdated ¶
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 ¶
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 Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
A go-routine safe FIFO (first in first out) data stucture.
func (*Queue[T]) Len ¶
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.
type RebuildMap ¶
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 ¶
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 ¶
Fired whenever a mob or player changes rooms
func (RoomChange) Type ¶
func (r RoomChange) Type() string
type ScriptedEvent ¶
Triggered by a script
func (ScriptedEvent) Type ¶
func (s ScriptedEvent) Type() string
type TargetChanged ¶
type TargetChanged struct {
EntityId int
EntityType string // "player" or "mob"
EntityName string
OldTargetId int
OldTargetType string
OldTargetName string
NewTargetId int
NewTargetType string
NewTargetName string
Reason string // "manual", "death", "fled", "taunt", etc.
}
TargetChanged fires when a combatant's primary target changes
func (TargetChanged) Type ¶
func (t TargetChanged) Type() string
type UserSettingChanged ¶
func (UserSettingChanged) Type ¶
func (i UserSettingChanged) Type() string
type WebClientCommand ¶
Special commands that only the webclient is equipped to handle
func (WebClientCommand) Type ¶
func (w WebClientCommand) Type() string