ns

package module
v4.19.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 17 Imported by: 10

Documentation

Overview

Package ns implements NoxScript 4 used in OpenNox maps.

NS4 is based on NoxScript 3 but provides a more Go-friendly object-oriented API.

These changes include:

- Most functions became methods on the corresponding object types. - Functions have a more generic signature, using interfaces where appropriate. - Similar methods were renamed, e.g. ObjectOn and WaypointOn is now called Enable for both types. - Type safety was improved. Package defines more names types for enums. - All enum constants were moved to their own sub-packages.

Package is compatible with NS3: methods like AsObj convert NS3 objects into NS4 objects.

Index

Constants

View Source
const (
	DialogNormal    = DialogType("NORMAL")
	DialogNext      = DialogType("NEXT")
	DialogYesNo     = DialogType("YESNO")
	DialogYesNoNext = DialogType("YESNONEXT")
	DialogFalse     = DialogType("FALSE")
)
View Source
const (
	AnswerGoodbye = DialogAnswer(0)
	AnswerYes     = DialogAnswer(1)
	AnswerNo      = DialogAnswer(2)
)
View Source
const (
	EventEnemySighted    = ObjectEvent(3)
	EventLookingForEnemy = ObjectEvent(4)
	EventDeath           = ObjectEvent(5)
	EventChangeFocus     = ObjectEvent(6)
	EventIsHit           = ObjectEvent(7)
	EventRetreat         = ObjectEvent(8)
	EventCollision       = ObjectEvent(9)
	EventEnemyHeard      = ObjectEvent(10)
	EventEndOfWaypoint   = ObjectEvent(11)
	EventLostEnemy       = ObjectEvent(13)
)
View Source
const (
	OblivionHalberd   = HalberdLevel(0)
	OblivionHeart     = HalberdLevel(1)
	OblivionWierdling = HalberdLevel(2)
	OblivionOrb       = HalberdLevel(3)
)
View Source
const (
	EntryGreen1 = EntryType(0) // green text, no sound
	EntryWhite  = EntryType(1) // white text
	EntryRed    = EntryType(2) // red text with quest label
	EntryGreen2 = EntryType(3) // green text
	EntryGrey   = EntryType(4) // grey text with completed label
	EntryYellow = EntryType(8) // yellow text with hint label
)
View Source
const (
	MapInitialize = MapEvent(iota + 1)
	MapEntry
	MapExit
	MapShutdown
)

Variables

This section is empty.

Functions

func AudioEvent

func AudioEvent(audio audio.Name, p Positioner)

AudioEvent play an audio event at a location.

func AutoSave

func AutoSave()

AutoSave triggers an autosave. Only solo games.

func BecomeEnemy

func BecomeEnemy(obj Obj)

BecomeEnemy unsets object as pet of host.

func BecomePet

func BecomePet(obj Obj)

BecomePet sets object as pet of host.

func Blind

func Blind()

Blind the host.

func CancelDialog

func CancelDialog(obj Obj)

CancelDialog cancels a conversation with object.

func CastSpell

func CastSpell(spell spell.Spell, source, target Positioner)

CastSpell casts a spell from source to target.

Example:

ns.CastSpell(spell.DEATH_RAY, ns.Object("CruelDude"), ns.GetHost())
ns.CastSpell(spell.DEATH_RAY, ns.Ptf(10, 5), ns.Waypoint("Target"))

func CastSpellLvl added in v4.5.0

func CastSpellLvl(spell spell.Spell, lvl int, source, target Positioner)

CastSpellLvl casts a spell from source to target with a given level.

Example:

ns.CastSpell(spell.DEATH_RAY, 1, ns.Object("CruelDude"), ns.GetHost())
ns.CastSpell(spell.DEATH_RAY, 3, ns.Ptf(10, 5), ns.Waypoint("Target"))

func ClearMessages

func ClearMessages(player Obj)

ClearMessages clears messages on player's screen.

func DeathScreen

func DeathScreen(which int)

DeathScreen shows death screen to host.

func DestroyEveryChat

func DestroyEveryChat()

DestroyEveryChat destroys all speech bubbles.

func Effect

func Effect(effect effect.Effect, p1, p2 Positioner)

Effect triggers an effect from point p1 to p2. Some effects only have one point, in which case p2 is ignored.

func EndGame

func EndGame(class player.Class)

EndGame end of game for a specific class.

func FindObjects added in v4.4.0

func FindObjects(fnc func(it Obj) bool, conditions ...ObjCond) int

FindObjects calls fnc for all map objects matching all the conditions. It returns a number of objects matched. If fnc returns false, the function stops the search. If fnc is nil, the function only counts a number of objects matching a condition.

Example:

// Find and damage all monsters in a 100px circle around obj.
ns.FindObjects(
	func(it ns.Obj) bool {
		it.Damage(obj, 10, damage.FLAME)
		return true
	},
	ns.InCirclef{Center: obj, R: 100},
	ns.HasClass(object.ClassMonster),
)

func FindWalls added in v4.15.0

func FindWalls(fnc func(it WallObj) bool, conditions ...WallCond) int

FindWalls calls fnc for all map walls matching all the conditions. It returns a number of walls matched. If fnc returns false, the function stops the search. If fnc is nil, the function only counts a number of walls matching a condition.

Example:

// Find and disable walls with a window in a 100px circle around obj.
g.FindWalls(
	func(it ns.WallObj) bool {
		it.Enable(false)
		return true
	},
	ns.InCirclef{Center: obj, R: 100},
	ns.HasWallFlags(ns.WallFlagWindow),
)

func Frame added in v4.13.0

func Frame() int

Frame returns current server frame number.

func FrameRate added in v4.13.0

func FrameRate() int

FrameRate returns current server update rate (aka server frame rate).

func GetCharacterData

func GetCharacterData(field int) int

GetCharacterData gets information about the loaded character.

func GetQuestStatus

func GetQuestStatus(name string) int

GetQuestStatus gets quest status (int).

func GetQuestStatusFloat

func GetQuestStatusFloat(name string) float32

GetQuestStatusFloat gets quest status (float).

func ImmediateBlind

func ImmediateBlind()

ImmediateBlind immediately blinds the host.

func IsCaller

func IsCaller(obj Obj) bool

IsCaller checks whether object is a target of an event.

func IsCrown

func IsCrown(obj Obj) bool

IsCrown gets whether object is a Crown.

func IsGameBall

func IsGameBall(obj Obj) bool

IsGameBall gets whether object is a GameBall.

func IsSummoned

func IsSummoned(obj Obj) bool

IsSummoned gets whether object is a summoned creature.

func IsTalking

func IsTalking() bool

IsTalking gets whether host is talking.

func IsTrading

func IsTrading() bool

IsTrading returns whether the host is currently talking to shopkeeper.

func IsTrigger

func IsTrigger(obj Obj) bool

IsTrigger checks whether object triggered an event.

func JournalDelete

func JournalDelete(obj Obj, message StringID)

JournalDelete deletes entry from player's journal.

If the player object is nil, then it will delete the journal entry for all players.

func JournalDeleteStr added in v4.2.0

func JournalDeleteStr(obj Obj, message string)

JournalDeleteStr deletes entry from player's journal. It does not localize the string.

If the player object is nil, then it will delete the journal entry for all players.

func JournalEdit

func JournalEdit(obj Obj, message StringID, typ EntryType)

JournalEdit edits entry in player's journal.

If the player object is nil, then it will edit the journal entry for all players.

func JournalEditStr added in v4.2.0

func JournalEditStr(obj Obj, message string, typ EntryType)

JournalEditStr edits entry in player's journal. It does not localize the string.

If the player object is nil, then it will edit the journal entry for all players.

func JournalEntry

func JournalEntry(obj Obj, message StringID, typ EntryType)

JournalEntry adds entry to player's journal.

If the player object is nil, then it will add the journal entry to all players.

func JournalEntryStr added in v4.2.0

func JournalEntryStr(obj Obj, message string, typ EntryType)

JournalEntryStr adds entry to player's journal. It does not localize the string.

If the player object is nil, then it will add the journal entry to all players.

func MakeEnemy

func MakeEnemy(obj Obj)

MakeEnemy unsets object as friendly.

func MakeFriendly

func MakeFriendly(obj Obj)

MakeFriendly sets object friendly with host.

func Music

func Music(music int, volume int)

Music plays music.

func MusicEvent

func MusicEvent()

func MusicPopEvent

func MusicPopEvent()

func MusicPushEvent

func MusicPushEvent()

func NoWallSound

func NoWallSound(noWallSound bool)

NoWallSound enables or disables wall sounds.

func Now added in v4.13.0

func Now() time.Duration

Now returns relative time from the server/map start. For absolute time, use time.Now().

func OnChat added in v4.9.0

func OnChat(fnc ChatFunc)

OnChat registers a callback function that will be called when each chat message is received. See ChatFunc for details.

func OnEachFrame added in v4.13.0

func OnEachFrame(each int, fnc FrameFunc)

OnEachFrame registers a callback function that will be called each N-th server frame. See FrameFunc for details.

func OnFrame added in v4.13.0

func OnFrame(fnc FrameFunc)

OnFrame registers a callback function that will be called each server frame. See FrameFunc for details.

func OnMapEvent added in v4.13.0

func OnMapEvent(typ MapEvent, fnc MapEventFunc)

OnMapEvent registers a callback function that will be called each server map event.

See MapEvent for a list of events and MapEventFunc for callback type.

func OnPlayerDeath added in v4.18.1

func OnPlayerDeath(fnc PlayerDeathFunc)

OnPlayerDeath registers a callback function that will be called when player dies.

func OnPlayerJoin added in v4.18.1

func OnPlayerJoin(fnc PlayerJoinFunc)

OnPlayerJoin registers a callback function that will be called when player joins the server.

func OnPlayerLeave added in v4.18.1

func OnPlayerLeave(fnc PlayerLeaveFunc)

OnPlayerLeave registers a callback function that will be called when player leaves the server.

func Print

func Print(message StringID)

Print displays a localized string on the screen of Other.

If the string is not in the string database, it will instead print an error message with "MISSING:".

func PrintStr added in v4.2.0

func PrintStr(message string)

PrintStr displays a string on the screen of Other. It does not localize the string.

func PrintStrToAll added in v4.2.0

func PrintStrToAll(message string)

PrintStrToAll displays a string to everyone. It does not localize the string.

func PrintToAll

func PrintToAll(message StringID)

PrintToAll displays a localized string to everyone.

If the string is not in the string database, it will instead print an error message with "MISSING:".

func Random

func Random(min int, max int) int

Random generates random int.

func RandomFloat

func RandomFloat(min float32, max float32) float32

RandomFloat generates random float.

func ResetQuestStatus

func ResetQuestStatus(name string)

ResetQuestStatus deletes a quest status.

The name can be a wildcard with an asterisk or with a map name.

func SetDialog

func SetDialog(obj Obj, typ DialogType, start Func, end Func)

SetDialog sets up a conversation with object.

The type of conversation is one of: DialogNormal, DialogNext, DialogYesNo, DialogYesNoNext. The start and end are script functions that are called at the start and end of the conversation.

If using a DialogYesNo conversation, the end script function should use GetAnswer to retrieve the result.

func SetHalberd

func SetHalberd(upgrade HalberdLevel)

SetHalberd upgrades host's oblivion staff.

func SetQuestStatus

func SetQuestStatus(status int, name string)

SetQuestStatus sets quest status (int).

func SetQuestStatusFloat

func SetQuestStatusFloat(status float32, name string)

SetQuestStatusFloat sets quest status (float).

func SetRuntime

func SetRuntime(r Implementation)

SetRuntime is used by the script host to bind runtime for the script package. Scripts must not call this functions.

func SetShopkeeperText

func SetShopkeeperText(obj Obj, text StringID)

SetShopkeeperText sets localized shopkeeper text.

func SetShopkeeperTextStr added in v4.2.0

func SetShopkeeperTextStr(obj Obj, text string)

SetShopkeeperTextStr sets shopkeeper text. It does not localize the string.

func StartDialog

func StartDialog(obj Obj, other Obj)

StartDialog starts a conversation between two objects.

This requires that SetDialog has already been used to set up the conversation on the object.

func StartupScreen

func StartupScreen(which int)

StartupScreen shows startup screen to host.

func StopScript

func StopScript(value any)

StopScript exits current script function.

func StoryPic

func StoryPic(obj Obj, name string)

StoryPic assigns a picture to a conversation.

func TellStory

func TellStory(audio audio.Name, story StringID)

TellStory causes the telling of a story.

This will cause a story to be told. It relies on Self and Other to be particular values, which limits this to being used in the SetDialog callbacks.

Example:

TellStory(audio.SwordsmanHurt, "Con05:OgreTalk07")

func TellStoryStr added in v4.2.0

func TellStoryStr(audio audio.Name, story string)

TellStoryStr causes the telling of a story. It does not localize the string.

This will cause a story to be told. It relies on Self and Other to be particular values, which limits this to being used in the SetDialog callbacks.

Example:

TellStoryStr(audio.SwordsmanHurt, "Hello there!")

func UnBlind

func UnBlind()

UnBlind the host.

func Unknownb8

func Unknownb8(id int) bool

func Unknownb9

func Unknownb9(id int) bool

func Unknownc4

func Unknownc4()

func Unused1f

func Unused1f(id int)

func Unused20

func Unused20(id int)

func Unused50

func Unused50()

func Unused58

func Unused58(arg1 int, arg2 int)

func Unused59

func Unused59(arg1 int, arg2 int)

func Unused5a

func Unused5a(arg1 int, arg2 int)

func Unused5b

func Unused5b(arg1 int, arg2 int)

func Unused5c

func Unused5c(arg1 int, arg2 int)

func Unused5d

func Unused5d(arg1 int, arg2 int)

func Unused5e

func Unused5e(str string) int

func Unused74

func Unused74(arg1 int, arg2 int)

func WideScreen

func WideScreen(enable bool)

WideScreen enables or disables cinematic wide-screen effect.

func WithRuntime added in v4.2.0

func WithRuntime(ctx context.Context, g Implementation) context.Context

WithRuntime stores Implementation in the context.

Types

type AND added in v4.4.0

type AND []ObjCond

AND matches an object if all conditions match an object.

func (AND) Matches added in v4.4.0

func (arr AND) Matches(obj Obj) bool

type ChatFunc added in v4.9.0

type ChatFunc func(t Team, p Player, obj Obj, msg string) string

ChatFunc is a callback type for OnChat. It returns a modified message. If message is empty, it will be ignored (muted).

A nil player will be passed to the callback for non-player messages (e.g. ones sent via Obj.Chat).

For team chat a team will be passed to the callback. It will be nil for regular chat.

type Color added in v4.19.0

type Color = color.Color

func RGB added in v4.19.0

func RGB(r, g, b byte) Color

RGB creates an RGB color.

func RGBA added in v4.19.0

func RGBA(r, g, b, a byte) Color

RGBA creates an RGBA color.

type DialogAnswer

type DialogAnswer int

func GetAnswer

func GetAnswer(obj Obj) DialogAnswer

GetAnswer gets answer from conversation.

type DialogType

type DialogType string

type Direction

type Direction = int
const (
	NW Direction = 0
	N  Direction = 1
	NE Direction = 2
	W  Direction = 3
	E  Direction = 5
	SW Direction = 6
	S  Direction = 7
	SE Direction = 8
)

type Duration added in v4.3.0

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

Duration for script events.

It's separate from time.Duration because it can be expressed in game frames.

func Frames added in v4.3.0

func Frames(num int) Duration

Frames returns duration in game frames.

func Infinite added in v4.12.0

func Infinite() Duration

Infinite returns an infinite duration.

func NowWithSource added in v4.3.1

func NowWithSource(s TimeSource) Duration

NowWithSource returns current timestamp of the time source.

func Seconds added in v4.3.0

func Seconds(sec float64) Duration

Seconds returns duration in seconds.

func Time added in v4.3.0

func Time(dt time.Duration) Duration

Time returns duration given time.Duration.

func (Duration) Add added in v4.3.0

func (d Duration) Add(d2 Duration) Duration

func (Duration) Frames added in v4.3.0

func (d Duration) Frames() (int, bool)

Frames checks if duration is set in frames and returns it.

func (Duration) IsFrames added in v4.3.0

func (d Duration) IsFrames() bool

IsFrames checks if duration is set in frames.

func (Duration) IsInfinite added in v4.12.0

func (d Duration) IsInfinite() bool

IsInfinite checks if duration is infinite.

func (Duration) IsTime added in v4.3.0

func (d Duration) IsTime() bool

IsTime checks if duration is set in seconds.

func (Duration) LessOrEq added in v4.3.0

func (d Duration) LessOrEq(d2 Duration) bool

func (Duration) Sub added in v4.3.1

func (d Duration) Sub(d2 Duration) Duration

func (Duration) Time added in v4.3.0

func (d Duration) Time() (time.Duration, bool)

Time checks if duration is set in seconds and returns it.

type EntryType

type EntryType int

type EqualClass added in v4.4.0

type EqualClass object.Class

EqualClass checks that class of object exactly matches this value.

func (EqualClass) Matches added in v4.4.0

func (c EqualClass) Matches(obj Obj) bool

type FrameFunc added in v4.13.0

type FrameFunc func()

FrameFunc is a callback type for OnFrame.

type Func

type Func = any

type Game

type Game interface {
	// NoxScript returns implementation of NoxScript runtime.
	NoxScript() Implementation
}

Game is an optional interface for the engine that exposes NoxScript runtime.

type HalberdLevel

type HalberdLevel int

type Handle

type Handle interface {
	// ScriptID returns internal script ID for the object.
	ScriptID() int
}

type HasAllClasses added in v4.4.0

type HasAllClasses object.Class

HasAllClasses checks that class of object matches all of provided classes.

func (HasAllClasses) Matches added in v4.4.0

func (c HasAllClasses) Matches(obj Obj) bool

type HasAllObjFlags added in v4.10.0

type HasAllObjFlags object.Flags

HasAllObjFlags checks that object's flags match all of provided flags.

func (HasAllObjFlags) Matches added in v4.10.0

func (c HasAllObjFlags) Matches(obj Obj) bool

type HasClass added in v4.4.0

type HasClass object.Class

HasClass checks that class of object matches any of provided classes.

func (HasClass) Matches added in v4.4.0

func (c HasClass) Matches(obj Obj) bool

type HasObjFlags added in v4.10.0

type HasObjFlags object.Flags

HasObjFlags checks that object's flags match any of provided flags.

func (HasObjFlags) Matches added in v4.10.0

func (c HasObjFlags) Matches(obj Obj) bool

type HasTeam added in v4.9.0

type HasTeam []Team

HasTeam checks that object matches any of provided teams.

func (HasTeam) Matches added in v4.9.0

func (arr HasTeam) Matches(obj Obj) bool

type HasType added in v4.4.0

type HasType []ObjType

HasType checks that object matches any of provided types.

func (HasType) Matches added in v4.4.0

func (arr HasType) Matches(obj Obj) bool

type HasTypeName added in v4.4.0

type HasTypeName []string

HasTypeName checks that object matches any of provided type names.

func (HasTypeName) Matches added in v4.4.0

func (arr HasTypeName) Matches(obj Obj) bool

type HasWallFlags added in v4.15.0

type HasWallFlags wall.Flags

HasWallFlags checks that wall's flags match any of provided flags.

func (HasWallFlags) WallMatches added in v4.15.0

func (c HasWallFlags) WallMatches(obj WallObj) bool

type Implementation

type Implementation interface {
	TimeSource
	FrameRate() int
	Store(typ StorageType) Storage

	TimerByHandle(h TimerHandle) Timer
	NewTimer(dt Duration, fnc Func, args ...any) Timer
	RandomFloat(min float32, max float32) float32
	Random(min int, max int) int
	StopScript(value any)
	AutoSave()
	StartupScreen(which int)
	DeathScreen(which int)

	ObjectType(name string) ObjType
	ObjectTypeByInd(ind int) ObjType

	ObjectByHandle(h ObjHandle) Obj
	Object(name string) Obj
	ObjectGroupByHandle(h ObjGroupHandle) ObjGroup
	ObjectGroup(name string) ObjGroup
	CreateObject(typ string, pos Positioner) Obj
	ObjSearcher
	GetTrigger() Obj
	GetCaller() Obj
	GetHost() Obj
	IsTrigger(obj Obj) bool
	IsCaller(obj Obj) bool
	IsGameBall(obj Obj) bool
	IsCrown(obj Obj) bool
	IsSummoned(obj Obj) bool
	MakeFriendly(obj Obj)
	MakeEnemy(obj Obj)
	BecomePet(obj Obj)
	BecomeEnemy(obj Obj)

	Teams() []Team

	HostPlayer() Player
	Players() []Player

	GetCharacterData(field int) int
	Print(message StringID)
	PrintStr(message string)
	PrintToAll(message StringID)
	PrintStrToAll(message string)
	ClearMessages(player Obj)
	UnBlind()
	Blind()
	ImmediateBlind()
	WideScreen(enable bool)
	IsTalking() bool
	IsTrading() bool
	SetHalberd(upgrade HalberdLevel)
	EndGame(class player.Class)

	DestroyEveryChat()
	SetShopkeeperText(obj Obj, text StringID)
	SetShopkeeperTextStr(obj Obj, text string)
	SetDialog(obj Obj, typ DialogType, start Func, end Func)
	CancelDialog(obj Obj)
	StoryPic(obj Obj, name string)
	TellStory(audio audio.Name, story StringID)
	TellStoryStr(audio audio.Name, story string)
	StartDialog(obj Obj, other Obj)
	GetAnswer(obj Obj) DialogAnswer

	AudioEvent(audio audio.Name, p Positioner)
	Music(music int, volume int)
	MusicPushEvent()
	MusicPopEvent()
	MusicEvent()

	Effect(effect effect.Effect, p1, p2 Positioner)
	CastSpell(spell spell.Spell, source, target Positioner)
	CastSpellLvl(spell spell.Spell, lvl int, source, target Positioner)
	NewTrap(pos Positioner, spells []TrapSpell) Obj

	GetQuestStatus(name string) int
	GetQuestStatusFloat(name string) float32
	SetQuestStatus(status int, name string)
	SetQuestStatusFloat(status float32, name string)
	ResetQuestStatus(name string)

	JournalEntry(obj Obj, message StringID, typ EntryType)
	JournalEdit(obj Obj, message StringID, typ EntryType)
	JournalDelete(obj Obj, message StringID)
	JournalEntryStr(obj Obj, message string, typ EntryType)
	JournalEditStr(obj Obj, message string, typ EntryType)
	JournalDeleteStr(obj Obj, message string)

	Waypoints() []WaypointObj
	WaypointByHandle(h WaypointHandle) WaypointObj
	Waypoint(name string) WaypointObj
	NewWaypoint(name string, pos Pointf) WaypointObj
	WaypointGroupByHandle(h WaypointGroupHandle) WaypointGroupObj
	WaypointGroup(name string) WaypointGroupObj

	NoWallSound(noWallSound bool)
	WallByHandle(h WallHandle) WallObj
	Wall(x int, y int) WallObj
	WallGroupByHandle(h WallGroupHandle) WallGroupObj
	WallGroup(name string) WallGroupObj
	FindWalls(fnc func(it WallObj) bool, conditions ...WallCond) int

	OnFrame(fnc FrameFunc)
	OnMapEvent(typ MapEvent, fnc MapEventFunc)
	OnChat(fnc ChatFunc)
	OnPlayerJoin(fnc PlayerJoinFunc)
	OnPlayerLeave(fnc PlayerLeaveFunc)
	OnPlayerDeath(fnc PlayerDeathFunc)

	Unused1f(id int)
	Unused20(id int)
	Unused50()
	Unused58(arg1 int, arg2 int)
	Unused59(arg1 int, arg2 int)
	Unused5a(arg1 int, arg2 int)
	Unused5b(arg1 int, arg2 int)
	Unused5c(arg1 int, arg2 int)
	Unused5d(arg1 int, arg2 int)
	Unused5e(str string) int
	Unused74(arg1 int, arg2 int)
	Unknownb8(id int) bool
	Unknownb9(id int) bool
	Unknownc4()
}

Implementation of the script runtime. Only used in the engine itself.

func GetRuntime added in v4.2.0

func GetRuntime(ctx context.Context) Implementation

GetRuntime loads Implementation from the context.

func Runtime

func Runtime() Implementation

Runtime returns implementation of all the accessible functions as an interface.

type InCirclef added in v4.4.0

type InCirclef struct {
	Center Positioner
	R      float64
}

InCirclef filters objects that are inside a circle on the map.

func (InCirclef) Matches added in v4.4.0

func (c InCirclef) Matches(obj Obj) bool

func (InCirclef) WallMatches added in v4.15.0

func (c InCirclef) WallMatches(wl WallObj) bool

type InRectf added in v4.4.0

type InRectf struct {
	Min, Max Pointf
}

InRectf filters objects that are inside a given map rectangle.

func (InRectf) Matches added in v4.4.0

func (c InRectf) Matches(obj Obj) bool

func (InRectf) WallMatches added in v4.15.0

func (c InRectf) WallMatches(wl WallObj) bool

type MapEvent added in v4.13.0

type MapEvent int

MapEvent is an event type for OnMapEvent function.

type MapEventFunc added in v4.13.0

type MapEventFunc func()

MapEventFunc is a callback type for OnMapEvent.

type NOT added in v4.4.0

type NOT struct {
	Cond ObjCond
}

NOT matches an object if any other condition returns false.

func (NOT) Matches added in v4.4.0

func (c NOT) Matches(obj Obj) bool

type OR added in v4.4.0

type OR []ObjCond

OR matches an object if any of the conditions matches an object.

func (OR) Matches added in v4.4.0

func (arr OR) Matches(obj Obj) bool

type Obj

type Obj interface {
	ObjHandle
	// Type returns object type.
	Type() ObjType
	// Pos returns current position of the object.
	Pos() Pointf
	// SetPos instantly moves object to a given position.
	SetPos(p Pointf)
	// Z returns current Z offset for the object.
	Z() float32
	// SetZ sets Z offset for the object.
	SetZ(z float32)
	// Vel returns current velocity of the object.
	Vel() Pointf
	// IsEnabled checks if object is currently enabled.
	IsEnabled() bool
	// Enable or disable the object.
	Enable(enable bool)
	// Toggle the object's enabled state.
	// It returns the new state after toggling the object.
	Toggle() bool
	// IsLocked checks if object is currently locked.
	IsLocked() bool
	// Lock or unlock the object.
	Lock(lock bool)

	// Class returns object class.
	Class() object.Class

	// HasClass checks whether object has a class.
	// It uses string values instead of enum as Class does.
	HasClass(class class.Class) bool

	// HasSubclass tests whether an object has a specific subclass.
	// The subclass overlaps, so you should probably test for the class first (via HasClass).
	HasSubclass(subclass subclass.SubClass) bool

	// Flags returns object flags.
	Flags() object.Flags

	// SetFlags sets object flags to the given value.
	// For switching individual flags see FlagsEnable and FlagsDisable.
	SetFlags(v object.Flags)

	// FlagsEnable enables specific object flags.
	FlagsEnable(v object.Flags)

	// FlagsDisable disables specific object flags.
	FlagsDisable(v object.Flags)

	// HasTeam checks if an object belongs to a team.
	HasTeam(t Team) bool

	// Team returns current team of an object, if any.
	Team() Team

	// SetTeam sets team of an object.
	SetTeam(t Team)

	// DisplayName returns current display name for an object (if any).
	DisplayName() string

	// SetDisplayName sets a display name for an object, with an optional color.
	// Passing nil color resets it to a default value.
	SetDisplayName(name string, cl Color)

	// MonsterStatus returns monster/NPC status flags.
	// It returns 0 if object's class is not a monster/NPC.
	MonsterStatus() object.MonsterStatus

	// SetMonsterStatus sets monster status flags to the given value.
	// For switching individual statuses see MonsterStatusEnable and MonsterStatusDisable.
	// It does nothing if object's class is not a monster/NPC.
	SetMonsterStatus(v object.MonsterStatus)

	// MonsterStatusEnable enables specific monster status flags.
	// It does nothing if object's class is not a monster/NPC.
	MonsterStatusEnable(v object.MonsterStatus)

	// MonsterStatusDisable disables specific monster status flags.
	// It does nothing if object's class is not a monster/NPC.
	MonsterStatusDisable(v object.MonsterStatus)

	// HasEnchant gets whether object has an enchant.
	HasEnchant(enchant enchant.Enchant) bool

	// Direction gets object direction.
	//
	// See LookWithAngle.
	Direction() Direction

	// CursorPos returns aim cursor position for the object. Only valid for players.
	CursorPos() types.Pointf

	// CursorObj returns target under the aim cursor for the object. Only valid for players.
	CursorObj() Obj

	// CurrentHealth gets object's health.
	CurrentHealth() int

	// MaxHealth gets object's maximum health.
	MaxHealth() int

	// RestoreHealth restores object's health.
	RestoreHealth(amount int)

	// SetHealth sets current object health.
	SetHealth(v int)

	// SetMaxHealth sets maximum object health.
	SetMaxHealth(v int)

	// CurrentMana gets object's mana. Only works on players.
	CurrentMana() int

	// MaxMana gets object's maximum mana. Only works on players.
	MaxMana() int

	// SetMana sets current object mana. Only works on players.
	SetMana(v int)

	// SetMaxMana sets maximum object mana. Only works on players.
	SetMaxMana(v int)

	// SetHealthRegenToMaxDur sets "classical" health regen for an object.
	// It will restore a percent of the health each frame, so that full health can be restored in a given time interval.
	//
	// Setting it to -1 restores the default.
	//
	// To disable regeneration completely, use SetHealthRegenPerFrame(0).
	SetHealthRegenToMaxDur(t time.Duration)

	// SetHealthRegenPerFrame sets per-frame health regen for an object.
	// Each frame a given amount of health will be restored.
	//
	// To disable health regen, set it to 0.
	//
	// To use "classic" health regen, set it to -1.
	SetHealthRegenPerFrame(v float32)

	// Mass of the object.
	Mass() float32

	// SetMass sets mass of the object.
	SetMass(v float32)

	// CurrentSpeed returns current speed of the object.
	CurrentSpeed() float32

	// BaseSpeed returns base speed of the object.
	BaseSpeed() float32

	// SetBaseSpeed sets base speed of the object.
	SetBaseSpeed(v float32)

	// Strength returns strength of the unit.
	Strength() int

	// SetStrength sets strength of the unit.
	SetStrength(v int)

	// SetColor sets NPC or player color, given its index.
	//
	// Example:
	//
	// 		obj.SetColor(0, ns.RGB(80, 0, 0)) // dark red
	SetColor(ind int, cl Color)

	// GetGold gets amount of gold for player object.
	GetGold() int

	// ChangeGold changes amount of gold for player object.
	ChangeGold(delta int)

	// GiveXp grants experience to a player.
	GiveXp(xp float32)

	// GetLevel gets player's level.
	GetLevel() int

	// GetClass gets player's character class.
	GetClass() player.Class

	// Player returns player associated with the object.
	Player() Player

	// GetScore gets player's score.
	//
	// Deprecated: use Player.GetScore.
	GetScore() int

	// ChangeScore changes player's score.
	//
	// Deprecated: use Player.ChangeScore.
	ChangeScore(score int)

	// HasOwner checks whether target is owned by object.
	HasOwner(owner Obj) bool

	// HasOwnerIn checks whether target is owned by any object in the group.
	HasOwnerIn(owners ObjGroup) bool

	// SetOwner makes an object the owner of the target. This will make the target
	// friendly to the owner, and it will accredit the target's kills to the owner.
	//
	// Passing nil will clear the owner.
	//
	// For example, in a multiplayer map, you might have a switch that activates a
	// hazard. You can use this so that if the hazard kills anyone, the player who
	// activated the hazard gets the credit.
	SetOwner(owner Obj)

	// SetOwners is the same as SetOwner but with an object group as the owner.
	SetOwners(owners ObjGroup)

	// Freeze or unfreeze an object in place.
	Freeze(freeze bool)

	// Pause an object temporarily.
	Pause(dt Duration)

	// Move an object to a waypoint. The object must be movable or attached to a "Mover".
	//
	// If the waypoint is linked, the object will continue to move once it reaches the first waypoint.
	Move(wp WaypointObj)

	// WalkTo causes an object to walk to a location.
	WalkTo(p Pointf)

	// LookAtDirection causes object to look in a direction.
	LookAtDirection(dir Direction)

	// LookWithAngle sets an object's direction. The direction is an angle represented as an integer between 0 and 255.
	// Due east is 0, and the angle increases as the object turns clock-wise.
	LookWithAngle(angle int)

	// LookAtObject sets direction of object so it is looking at another object.
	LookAtObject(target Positioner)

	// CanSee first checks if the location of the objects are within 512 of each other coordinate-wise. It not, it returns false.
	//
	// It then checks whether the first object can see the second object.
	CanSee(obj Obj) bool

	// ApplyForce applies a force vector to an object.
	ApplyForce(force Pointf)

	// PushTo calculate a unit vector from the object's location to the specified
	// location, and multiply it by the specified magnitude. This vector will be
	// applied as a force via ApplyForce.
	PushTo(pos Positioner, force float32)

	// Damage the target with a given source object, amount, and damage type.
	Damage(source Obj, amount int, typ damage.Type) bool

	// Delete an object.
	Delete()

	// DeleteAfter delete object after a delay.
	DeleteAfter(dt Duration)

	// Idle causes creature to idle.
	Idle()

	// Wander causes an object to wander.
	Wander()

	// Hunt causes creature to hunt.
	Hunt()

	// Return cause object to move to its starting location.
	Return()

	// Follow causes a creature to follow target, and it won't attack anything unless disrupted or instructed to.
	Follow(target Positioner)

	// Guard causes a creature to move to a location, guard a nearby location,
	// and attack any enemies that move within range of the guarded location.
	Guard(p1, p2 Pointf, distance float32)

	// Attack a target.
	Attack(target Positioner)

	// IsAttackedBy gets whether object is being attacked by another object.
	IsAttackedBy(by Obj) bool

	// HitMelee causes object to melee attacks a location.
	HitMelee(p Pointf)

	// HitRanged causes object to ranged attacks a location.
	HitRanged(p Pointf)

	// Flee causes creature to run away from target.
	Flee(target Positioner, dt Duration)

	// HasItem gets whether this specific item is in the object's inventory.
	// For searching items by object type or other properties, see InItems().FindObjects(...).
	HasItem(item Obj) bool

	// HasEquipment gets whether this specific item is in the object's inventory and is equipped.
	// For searching items by object type or other properties, see InEquipment().FindObjects(...).
	HasEquipment(item Obj) bool

	// FindItems calls fnc for all items matching all the conditions.
	// It returns a number of items matched. If fnc returns false, the function stops the search.
	// If fnc is nil, the function only counts a number of objects matching a condition.
	//
	// Example:
	//
	//	// Check if unit has at least one apple
	//	if obj.FindItems(nil, ns.HasTypeName{"RedApple"}) != 0 {
	//		fmt.Println("Has an apple!")
	//	}
	//
	//	// Drop all armor
	//	obj.FindItems(
	//		func(it ns.Obj) {
	//			obj.Drop(it)
	//			return true
	//		},
	//		ns.EqualClass(object.ClassArmor),
	//	)
	//
	// Deprecated: use InItems().FindObjects(...)
	FindItems(fnc func(obj Obj) bool, conditions ...ObjCond) int

	// GetLastItem returns the object of the last item in the object's inventory. If the inventory is empty, it returns nil.
	//
	// This is used with GetPreviousItem to iterate through an object's inventory.
	//
	// Deprecated: Use Items instead.
	//
	// Example:
	//
	//		for it := obj.GetLastItem(); it != nil; it = it.GetPreviousItem() {
	//			// ...
	//		}
	GetLastItem() Obj

	// GetPreviousItem returns the object of the previous item in the inventory from the given object.
	// If the specified object is not in an inventory, or there are no more items in the inventory, it returns nil.
	//
	// This is used with GetLastItem to iterate through an object's inventory.
	//
	// Deprecated: Use Items instead.
	GetPreviousItem() Obj

	// Items returns all items in the object's inventory.
	// An optional list of conditions can be specified for filtering returned items.
	//
	// Resulting slice is read-only, changes to it won't be reflected on the object.
	// Use Pickup or Drop for adding or removing items.
	Items(conditions ...ObjCond) []Obj

	// Equipment returns all equipped items in the object's inventory.
	// An optional list of conditions can be specified for filtering returned items.
	//
	// Resulting slice is read-only, changes to it won't be reflected on the object.
	// Use Equip or Unequip for changing equipment.
	Equipment(conditions ...ObjCond) []Obj

	// InItems returns an ObjSearcher that can be used in FindObjectIn and FindAllObjectsIn or searched directly.
	//
	// Calling InItems().FindObjects() will call fnc for all items matching all the conditions.
	// It returns a number of items matched. If fnc returns false, the function stops the search.
	// If fnc is nil, the function only counts a number of objects matching a condition.
	//
	// Example:
	//
	//	// Check if unit has at least one apple
	//	if obj.InItems().FindObjects(nil, ns.HasTypeName{"RedApple"}) != 0 {
	//		fmt.Println("Has an apple!")
	//	}
	//
	//	// Drop all armor
	//	obj.InItems().FindObjects(
	//		func(it ns.Obj) {
	//			obj.Drop(it)
	//			return true
	//		},
	//		ns.EqualClass(object.ClassArmor),
	//	)
	InItems() ObjSearcher

	// InEquipment returns an ObjSearcher that can be used in FindObjectIn and FindAllObjectsIn or searched directly.
	//
	// Calling InEquipment().FindObjects() will call fnc for all equipped items matching all the conditions.
	// It returns a number of items matched. If fnc returns false, the function stops the search.
	// If fnc is nil, the function only counts a number of objects matching a condition.
	//
	// Example:
	//
	//	// Check if unit has sword equipped
	//	if obj.InEquipment().FindObjects(nil, ns.HasTypeName{"Sword"}) != 0 {
	//		fmt.Println("Has an apple!")
	//	}
	//
	//	// Drop all equipped armor
	//	obj.InEquipment().FindObjects(
	//		func(it ns.Obj) {
	//			obj.Drop(it)
	//			return true
	//		},
	//		ns.EqualClass(object.ClassArmor),
	//	)
	InEquipment() ObjSearcher

	// GetHolder returns the object that contains the item in its inventory.
	GetHolder() Obj

	// Pickup cause object to pick up an item.
	//
	// Returns false if object cannot pick up the item.
	Pickup(item Obj) bool

	// Drop cause object to drop an item.
	//
	// Returns false if object cannot drop the item.
	Drop(item Obj) bool

	// Equip cause object to equip an item.
	//
	// If an item is not in object's inventory, it will be transferred to it.
	//
	// Returns false if object cannot pick up or equip the item.
	Equip(item Obj) bool

	// Unequip cause object to unequip an item.
	//
	// If an item is not in object's inventory, it will do nothing.
	//
	// Returns false if object cannot unequip the item.
	Unequip(item Obj) bool

	// ZombieStayDown sets zombie to stay down.
	ZombieStayDown()

	// RaiseZombie raises a zombie. Also clears stay down state.
	RaiseZombie()

	// Chat displays a localized string in a speech bubble.
	//
	// If the string is not in the string database, it will instead print an error message with "MISSING:".
	Chat(message StringID)

	// ChatTimer displays a localized string in a speech bubble for a given duration (in seconds or frames).
	//
	// If the string is not in the string database, it will instead print an error message with "MISSING:".
	ChatTimer(message StringID, dt Duration)

	// ChatStr displays a string in a speech bubble.
	// It does not localize the string.
	ChatStr(message string)

	// ChatStrTimer displays a string in a speech bubble for a given duration (in seconds or frames).
	// It does not localize the string.
	ChatStrTimer(message string, dt Duration)

	// DestroyChat destroys object's speech bubble.
	DestroyChat()

	// CreateMover creates a Mover for an object.
	CreateMover(wp WaypointObj, speed float32) Obj

	// GetElevatorStatus gets elevator status.
	GetElevatorStatus() int

	// AggressionLevel sets a creature's aggression level. The most commonly used value is 0.83.
	AggressionLevel(level float32)

	// SetRoamFlag sets roaming flags for object. Default is 0x80.
	SetRoamFlag(flags int)

	// RetreatLevel causes the creature to retreat if its health falls below the specified percentage (0.0 - 1.0).
	RetreatLevel(percent float32)

	// ResumeLevel causes the creature to stop retreating if its health is above the specified percentage (0.0 - 1.0).
	ResumeLevel(percent float32)

	// AwardSpell awards spell level to object.
	//
	// This will raise the spell level of the object.
	// If the object can not cast this spell then it will have no effect.
	AwardSpell(spell spell.Spell) bool

	// Enchant grants object an enchantment of a specified duration.
	Enchant(enchant enchant.Enchant, dt Duration)

	// EnchantOff removes enchant from an object.
	EnchantOff(enchant enchant.Enchant)

	// TrapSpells sets spells on a bomber or a wizard trap.
	TrapSpells(spells ...spell.Spell)

	// TrapSpellsAdv sets spells on a bomber or a wizard trap. It's an advanced version of TrapSpells.
	TrapSpellsAdv(spells []TrapSpell)

	// OnEvent sets a function script to call for an event.
	// This function overrides previous event of the same type set on an object.
	OnEvent(event ObjectEvent, fnc Func)
}

func AsObj

func AsObj(h ObjHandle) Obj

AsObj looks up an Obj for a given handle.

func CreateObject

func CreateObject(typ string, pos Positioner) Obj

CreateObject creates an object given a type and a starting location.

Example:
  spider := CreateObject("SmallAlbinoSpider", Waypoint("SpiderHole"))

func FindAllObjects added in v4.4.0

func FindAllObjects(conditions ...ObjCond) []Obj

FindAllObjects is similar to FindObjects, but returns all objects as an array/slice.

Example:

// Find and return all missiles in a 50px circle around obj.
arr := ns.FindAllObjects(
	ns.InCirclef{Center: obj, R: 50},
	ns.HasClass(object.ClassMissile),
)

func FindAllObjectsIn added in v4.9.0

func FindAllObjectsIn(s ObjSearcher, conditions ...ObjCond) []Obj

FindAllObjectsIn iterates over objects, and returns all matched objects as an array/slice.

Example:

// Find and return missiles in a 50px circle around obj.
arr := ns.FindAllObjects(g,
	ns.InCirclef{Center: obj, R: 50},
	ns.HasClass(object.ClassMissile),
)

func FindClosestObject added in v4.4.0

func FindClosestObject(from Positioner, conditions ...ObjCond) Obj

FindClosestObject searches the map for closest object that matches all conditions. If no objects are found, it returns nil.

Example:

// Find monster or player closest to obj.
found := ns.FindClosestObject(obj, ns.HasClass(object.ClassMonster | object.ClassPlayer))

func FindClosestObjectIn added in v4.9.0

func FindClosestObjectIn(from Positioner, s ObjSearcher, conditions ...ObjCond) Obj

FindClosestObjectIn searches the set for closest object that matches all conditions. If no objects are found, it returns nil.

Example:

// Find monster or player closest to obj.
found := ns.FindClosestObjectIn(obj, g, ns.HasClass(object.ClassMonster | object.ClassPlayer))

func FindObject added in v4.4.0

func FindObject(conditions ...ObjCond) Obj

FindObject searches the map for any object that matches all conditions. If object is not found it returns nil.

Example:

// Find exit on the map.
found := ns.FindObject(ns.EqualClass(object.ClassExit))

func FindObjectIn added in v4.9.0

func FindObjectIn(s ObjSearcher, conditions ...ObjCond) Obj

FindObjectIn searches the set for any object that matches all conditions. If object is not found it returns nil.

Example:

// Find exit on the map.
found := ns.FindObject(ns.EqualClass(object.ClassExit))

func GetCaller

func GetCaller() Obj

GetCaller returns object that was the target of an event, if valid.

func GetHost

func GetHost() Obj

GetHost gets host's player object.

func GetTrigger

func GetTrigger() Obj

GetTrigger returns object which triggered an event, if valid.

func NewTrap added in v4.5.0

func NewTrap(pos Positioner, spells ...spell.Spell) Obj

NewTrap creates a trap at a given point.

Example:

ns.NewTrap(ns.Ptf(10, 5), spell.DEATH_RAY)
ns.NewTrap(ns.GetHost(), spell.DEATH_RAY, spell.SPELL_CONFUSE)

func NewTrapAdv added in v4.5.0

func NewTrapAdv(pos Positioner, spells []TrapSpell) Obj

NewTrapAdv creates a trap at a given point. It's an advanced version of NewTrap.

Example:

	ns.NewTrapAdv(ns.Ptf(10, 5), ns.TrapSpell{Spell: spell.DEATH_RAY, Level: 3})
	ns.NewTrapAdv(ns.GetHost(), []ns.TrapSpell{
 		{Spell: spell.DEATH_RAY, Level: 1},
 		{Spell: spell.SPELL_CONFUSE}, // default level
	}...)

func Object

func Object(name string) Obj

Object looks up an object by name.

type ObjCond added in v4.4.0

type ObjCond interface {
	// Matches returns true if object matches a condition.
	// It must not modify the object.
	Matches(obj Obj) bool
}

ObjCond checks if object matches a certain condition.

type ObjCondFunc added in v4.4.0

type ObjCondFunc func(obj Obj) bool

ObjCondFunc is a function that implements ObjCond.

func (ObjCondFunc) Matches added in v4.4.0

func (f ObjCondFunc) Matches(obj Obj) bool

type ObjGroup

type ObjGroup interface {
	ObjGroupHandle
	ObjSearcher

	// Name returns object group name.
	Name() string
	// Enable or disable the object.
	Enable(enable bool)
	// Toggle the object's enabled state.
	// It returns the new state after toggling the object.
	Toggle() bool

	// HasOwner checks whether any object in target group is owned by object.
	HasOwner(owner Obj) bool

	// HasOwnerIn checks whether any object in target is owned by any object in the group.
	HasOwnerIn(owners ObjGroup) bool

	// SetOwner sets the owner for each object in a group. See Obj.SetOwner for details.
	SetOwner(owner Obj)

	// SetOwners is the same as SetOwner but with an object group as the owner.
	SetOwners(owners ObjGroup)

	// Pause objects of a group temporarily.
	Pause(dt Duration)

	// Move moves the objects in a group to a waypoint. The objects must be movable or attached to a "Mover".
	//
	// If the waypoint is linked, the objects will continue to move once they reach the first waypoint.
	Move(wp WaypointObj)

	// WalkTo causes objects in a group to walk to a location.
	WalkTo(p Pointf)

	// LookAtDirection causes objects in a group to look in a direction.
	LookAtDirection(dir Direction)

	// Damage damages the target objects with a given source object, amount, and damage type.
	Damage(source Obj, amount int, typ damage.Type)

	// Delete deletes objects in a group.
	Delete()

	// Idle causes creatures in a group to idle.
	Idle()

	// Wander cause objects in a group to wander.
	Wander()

	// Hunt causes creatures in a group to hunt.
	Hunt()

	// Follow causes the creatures to follow target, and they won't attack anything unless disrupted or instructed to.
	Follow(target Positioner)

	// Guard is the same as CreatureGuard but applies to creatures in a group.
	Guard(p1, p2 Pointf, distance float32)

	// Flee causes creatures to run away from target.
	Flee(target Positioner, dt Duration)

	// HitMelee causes objects in a group to melee attacks a location.
	HitMelee(p Pointf)

	// HitRanged causes objects in a group to ranged attacks a location.
	HitRanged(p Pointf)

	// Attack causes objects in a group to attack a target.
	Attack(target Positioner)

	// ZombieStayDown sets group of zombies to stay down.
	ZombieStayDown()

	// RaiseZombie raises a zombie group. Also clears stay down state.
	RaiseZombie()

	// CreateMover creates a Mover for every object in a group.
	CreateMover(wp WaypointObj, speed float32)

	// AggressionLevel sets a group of creature's aggression level. The most commonly used value is 0.83.
	AggressionLevel(level float32)

	// SetRoamFlag sets roaming flags for objects in a group. Default is 0x80.
	SetRoamFlag(flags int)

	// RetreatLevel causes the creatures to retreat if its health falls below the specified percentage (0.0 - 1.0).
	RetreatLevel(percent float32)

	// ResumeLevel causes the creatures to stop retreating if its health is above the specified percentage (0.0 - 1.0).
	ResumeLevel(percent float32)

	// AwardSpell awards spell level to objects in a group.
	//
	// This will raise the spell level of the objects in the group.
	// If an object can not cast this spell then it will have no effect on that object.
	AwardSpell(spell spell.Spell)

	// Enchant grants objects in a group an enchantment of a specified duration.
	Enchant(enchant enchant.Enchant, dt Duration)

	// AllObjects returns all objects as a list.
	AllObjects() Objects

	// EachObject calls fnc for all objects in the group.
	// If fnc returns false, the iteration stops.
	// If recursive is true, iteration will include items from nested groups.
	EachObject(recursive bool, fnc func(obj Obj) bool)
}

func AsObjGroup

func AsObjGroup(h ObjGroupHandle) ObjGroup

AsObjGroup looks up a ObjGroup for a given handle.

func ObjectGroup

func ObjectGroup(name string) ObjGroup

ObjectGroup looks up object group by name.

type ObjGroupHandle

type ObjGroupHandle interface {
	Handle
	// ObjGroupScriptID returns internal script ID for the object group.
	ObjGroupScriptID() int
}

type ObjHandle

type ObjHandle interface {
	Handle
	// ObjScriptID returns internal script ID for the object.
	ObjScriptID() int
}

type ObjSearcher added in v4.9.0

type ObjSearcher interface {
	// FindObjects calls fnc for all objects in a set matching all the conditions.
	// It returns a number of objects matched. If fnc returns false, the function stops the search.
	// If fnc is nil, the function only counts a number of objects matching a condition.
	//
	// Example:
	//
	//	// Find and damage monsters in a 100px circle around obj.
	//	g.FindObjects(
	//		func(it ns.Obj) bool {
	//			it.Damage(obj, 10, damage.FLAME)
	//			return true
	//		},
	//		ns.InCirclef{Center: obj, R: 100},
	//		ns.HasClass(object.ClassMonster),
	//	)
	FindObjects(fnc func(it Obj) bool, conditions ...ObjCond) int
}

ObjSearcher is an interface for iterating and filtering over objects.

type ObjType added in v4.2.0

type ObjType interface {
	// Name returns object type name.
	Name() string

	// Index returns an index of the type in the game's database.
	// It can be used to quickly compare object types, or as a map key for them.
	//
	// It is strongly advised against comparing it with hardcoded values, since mods may add/remove object types.
	// Use ObjectType to find object types instead.
	Index() int

	// Class returns object type class.
	Class() object.Class

	// HasClass checks whether object type has a class.
	// It uses string values instead of enum as Class does.
	HasClass(class class.Class) bool

	// HasSubclass tests whether an object has a specific subclass.
	// The subclass overlaps, so you should probably test for the class first (via HasClass).
	HasSubclass(subclass subclass.SubClass) bool

	// Flags returns object type flags.
	Flags() object.Flags

	// Create and object of this type.
	Create(pos Positioner) Obj
}

func ObjectType added in v4.2.0

func ObjectType(name string) ObjType

ObjectType looks up an object type by name.

func ObjectTypeByInd added in v4.2.0

func ObjectTypeByInd(ind int) ObjType

ObjectTypeByInd looks up an object type by index.

type ObjectEvent

type ObjectEvent int

type Objects added in v4.9.0

type Objects []Obj

Objects is a list of objects. It can be searched.

func (Objects) Delete added in v4.9.0

func (arr Objects) Delete()

Delete deletes objects in a list.

func (Objects) Enable added in v4.9.0

func (arr Objects) Enable(enable bool)

Enable or disable the objects.

func (Objects) FindObjects added in v4.9.0

func (arr Objects) FindObjects(fnc func(it Obj) bool, conditions ...ObjCond) int

FindObjects calls fnc for all objects in the list. See ObjSearcher.

func (Objects) SetOwner added in v4.9.0

func (arr Objects) SetOwner(owner Obj)

SetOwner sets the owner for each object in a list. See Obj.SetOwner for details.

func (Objects) SetOwners added in v4.9.0

func (arr Objects) SetOwners(owners ObjGroup)

SetOwners is the same as SetOwner but with an object group as the owner.

func (Objects) Toggle added in v4.9.0

func (arr Objects) Toggle() bool

Toggle the objects enabled state. It returns the new state after toggling the objects. If at least one object is enabled, it returns true.

type Persistent added in v4.17.0

type Persistent struct {
	Name string
}

Persistent returns a persistent storage with a given name. It will persist between OpenNox restarts.

type Player added in v4.2.0

type Player interface {
	// Name returns player's name.
	Name() string
	// Unit returns player's character unit.
	Unit() Obj
	// GetScore gets player's score.
	GetScore() int
	// ChangeScore adds or removes player's score(s).
	ChangeScore(score int)
	// Print displays a localized string on the screen of the player.
	//
	// If the string is not in the string database, it will instead print an error message with "MISSING:".
	Print(message StringID)
	// PrintStr displays a string on the screen of the player. It does not localize the string.
	PrintStr(message string)
	// Blind or unblind the player.
	Blind(blind bool)
	// HasTeam checks if a player belongs to a team.
	HasTeam(t Team) bool
	// Team returns current team of a player, if any.
	Team() Team
	// CursorPos returns aim cursor position for the player.
	CursorPos() types.Pointf
	// Store returns a player storage with a given type.
	Store(typ StorageType) Storage
}

func HostPlayer added in v4.2.0

func HostPlayer() Player

HostPlayer gets host player.

func Players added in v4.2.0

func Players() []Player

Players returns a list of active players.

type PlayerDeathFunc added in v4.17.0

type PlayerDeathFunc func(p Player, killer Obj)

PlayerDeathFunc is a callback type for OnPlayerDeath.

type PlayerJoinFunc added in v4.17.0

type PlayerJoinFunc func(p Player) bool

PlayerJoinFunc is a callback type for OnPlayerJoin.

type PlayerLeaveFunc added in v4.17.0

type PlayerLeaveFunc func(p Player)

PlayerLeaveFunc is a callback type for OnPlayerLeave.

type Point added in v4.15.0

type Point = image.Point

func Pt added in v4.15.0

func Pt(x, y int) Point

type Pointf

type Pointf = types.Pointf

func Ptf

func Ptf(x, y float32) Pointf

type Positioner

type Positioner interface {
	// Pos returns current position of the object.
	Pos() Pointf
}

Positioner is an interface for objects that have position on the map.

type Session added in v4.17.0

type Session struct {
	Name string
}

Session is a game session storage with a given name. It will persist as long as a single game session runs.

type Storage added in v4.17.0

type Storage interface {
	// Get fetches a custom object or value from the storage with a given key.
	// Argument must be a pointer to a value of the same type as used during Set.
	Get(key string, obj any) error
	// Set stores a custom object or value into the storage with a given key.
	Set(key string, obj any) error
}

func Store added in v4.17.0

func Store(typ StorageType) Storage

Store returns a global storage with a given type.

type StorageType added in v4.17.0

type StorageType interface {
	// contains filtered or unexported methods
}

type StringID

type StringID = string

StringID is an ID of a localized string in the string database.

type Team added in v4.9.0

type Team interface {
	// Name of the team.
	Name() string
	// Players returns a list of players belonging to the team.
	Players() []Player
	// GetScore returns the current team score.
	GetScore() int
	// ChangeScore adds or removes team's score(s).
	ChangeScore(score int)
	// Color returns team color.
	Color() Color
}

Team is an interface for game teams.

func Teams added in v4.9.0

func Teams() []Team

Teams return current teams.

type TimeSource added in v4.3.0

type TimeSource interface {
	// Frame returns current server tick/frame number.
	Frame() int
	// Time returns relative time from server start.
	Time() time.Duration
}

TimeSource is an interface for getting relative time.

type Timer

type Timer interface {
	TimerHandle
	// Cancel a timer. Returns true if successful.
	Cancel() bool
}

func AsTimer

func AsTimer(h TimerHandle) Timer

AsTimer looks up a Timer for a given handle.

func NewTimer

func NewTimer(dt Duration, fnc Func, args ...any) Timer

NewTimer creates a timer that calls the given script function after a given delay.

Example:

// Trigger by function reference:
NewTimer(Frames(10), myCallback)
// Trigger by function name (can call original NoxScript as well):
NewTimer(Seconds(10), "myCallback")
// Passing arguments to the callback:
NewTimer(Time(3*time.Second), "myCallback", obj)

type TimerHandle

type TimerHandle interface {
	Handle
	// TimerScriptID returns internal script ID for the timer.
	TimerScriptID() int
}

type TrapSpell added in v4.5.0

type TrapSpell struct {
	Spell spell.Spell
	Level int
}

type WallCond added in v4.15.0

type WallCond interface {
	// WallMatches returns true if wall matches a condition.
	// It must not modify the wall.
	WallMatches(obj WallObj) bool
}

WallCond checks if wall matches a certain condition.

type WallGroupHandle

type WallGroupHandle interface {
	Handle
	// WallGroupScriptID returns internal script ID for the wall group.
	WallGroupScriptID() int
}

type WallGroupObj

type WallGroupObj interface {
	WallGroupHandle
	// Name returns wall group name.
	Name() string
	// Enable or disable the object.
	Enable(enable bool)
	// Toggle the object's enabled state.
	// It returns the new state after toggling the object.
	Toggle() bool

	// Destroy breaks walls in a group.
	Destroy()

	// EachWall calls fnc for all walls in the group.
	// If fnc returns false, the iteration stops.
	// If recursive is true, iteration will include items from nested groups.
	EachWall(recursive bool, fnc func(obj WallObj) bool)
}

WallGroupObj is a group of walls.

func AsWallGroup

func AsWallGroup(h WallGroupHandle) WallGroupObj

AsWallGroup looks up a WallGroupObj for a given handle.

func WallGroup

func WallGroup(name string) WallGroupObj

WallGroup lookups wall group by name.

type WallHandle

type WallHandle interface {
	Handle
	// WallScriptID returns internal script ID for the wall.
	WallScriptID() int
}

type WallObj

type WallObj interface {
	WallHandle
	// IsEnabled checks if object is currently enabled.
	IsEnabled() bool
	// Enable or disable the object.
	Enable(enable bool)
	// Toggle the object's enabled state.
	// It returns the new state after toggling the object.
	Toggle() bool
	// Flags returns wall flags.
	Flags() wall.Flags

	// Pos returns position of the wall in object coordinates.
	Pos() Pointf
	// GridPos returns wall grid position.
	GridPos() Point

	// Destroy breaks a wall.
	Destroy()
}

WallObj is a pointer to a wall.

func AsWall

func AsWall(h WallHandle) WallObj

AsWall looks up a WallObj for a given handle.

func FindAllWalls added in v4.15.0

func FindAllWalls(conditions ...WallCond) []WallObj

FindAllWalls is similar to FindWalls, but returns all walls as an array/slice.

Example:

// Find and return all walls in a 50px circle around obj.
arr := ns.FindAllWalls(
	ns.InCirclef{Center: obj, R: 50},
)

func FindAllWallsIn added in v4.15.0

func FindAllWallsIn(s WallSearcher, conditions ...WallCond) []WallObj

FindAllWallsIn iterates over walls, and returns all matched walls as an array/slice.

Example:

// Find and return missiles in a 50px circle around obj.
arr := ns.FindAllWalls(
	ns.InCirclef{Center: obj, R: 50},
)

func FindClosestWall added in v4.15.0

func FindClosestWall(from Positioner, conditions ...WallCond) WallObj

FindClosestWall searches the map for closest wall that matches all conditions. If no walls are found, it returns nil.

Example:

// Find window closest to obj.
found := ns.FindClosestWall(obj, ns.HasWallFlags(ns.WallFlagWindow))

func FindClosestWallIn added in v4.15.0

func FindClosestWallIn(from Positioner, s WallSearcher, conditions ...WallCond) WallObj

FindClosestWallIn searches the set for closest wall that matches all conditions. If no walls are found, it returns nil.

Example:

// Find window closest to obj.
found := ns.FindClosestWall(obj, ns.HasWallFlags(ns.WallFlagWindow))

func FindWall added in v4.15.0

func FindWall(conditions ...WallCond) WallObj

FindWall searches the map for any wall that matches all conditions. If wall is not found it returns nil.

Example:

// Find window on the map.
found := ns.FindWall(ns.HasWallFlags(ns.WallFlagWindow))

func FindWallIn added in v4.15.0

func FindWallIn(s WallSearcher, conditions ...WallCond) WallObj

FindWallIn searches the set for any walls that matches all conditions. If wall is not found it returns nil.

Example:

// Find window on the map.
found := ns.FindWall(ns.HasWallFlags(ns.WallFlagWindow))

func Wall

func Wall(x int, y int) WallObj

Wall gets a wall by its grid coordinates.

type WallSearcher added in v4.15.0

type WallSearcher interface {
	// FindWalls calls fnc for all walls in a set matching all the conditions.
	// It returns a number of walls matched. If fnc returns false, the function stops the search.
	// If fnc is nil, the function only counts a number of walls matching a condition.
	//
	// Example:
	//
	//	// Find and disable walls with a window in a 100px circle around obj.
	//	g.FindWalls(
	//		func(it ns.WallObj) bool {
	//			it.Enable(false)
	//			return true
	//		},
	//		ns.InCirclef{Center: obj, R: 100},
	//		ns.HasWallFlags(ns.WallFlagWindow),
	//	)
	FindWalls(fnc func(it WallObj) bool, conditions ...WallCond) int
}

WallSearcher is an interface for iterating and filtering over walls.

type WaypointGroupHandle

type WaypointGroupHandle interface {
	Handle
	// WaypointGroupScriptID returns internal script ID for the waypoint.
	WaypointGroupScriptID() int
}

type WaypointGroupObj

type WaypointGroupObj interface {
	WaypointGroupHandle
	// Name returns waypoint group name.
	Name() string
	// Enable or disable the object.
	Enable(enable bool)
	// Toggle the object's enabled state.
	// It returns the new state after toggling the object.
	Toggle() bool

	// EachWaypoint calls fnc for all waypoints in the group.
	// If fnc returns false, the iteration stops.
	// If recursive is true, iteration will include items from nested groups.
	EachWaypoint(recursive bool, fnc func(obj WaypointObj) bool)
}

func AsWaypointGroup

func AsWaypointGroup(h WaypointGroupHandle) WaypointGroupObj

AsWaypointGroup looks up a WaypointGroupObj for a given handle.

func WaypointGroup

func WaypointGroup(name string) WaypointGroupObj

WaypointGroup looks up waypoint group by name.

type WaypointHandle

type WaypointHandle interface {
	Handle
	// WaypointScriptID returns internal script ID for the waypoint.
	WaypointScriptID() int
}

type WaypointObj

type WaypointObj interface {
	WaypointHandle
	// Name returns waypoint name.
	Name() string
	// Pos returns current position of the object.
	Pos() Pointf
	// SetPos instantly moves object to a given position.
	SetPos(p Pointf)
	// IsEnabled checks if object is currently enabled.
	IsEnabled() bool
	// Enable or disable the object.
	Enable(enable bool)
	// Toggle the object's enabled state.
	// It returns the new state after toggling the object.
	Toggle() bool
}

func AsWaypoint

func AsWaypoint(h WaypointHandle) WaypointObj

AsWaypoint looks up a WaypointObj for a given handle.

func NewWaypoint added in v4.4.0

func NewWaypoint(name string, pos Pointf) WaypointObj

NewWaypoint creates a new waypoint with a given name and position.

func Waypoint

func Waypoint(name string) WaypointObj

Waypoint looks up waypoint by name.

func Waypoints added in v4.2.0

func Waypoints() []WaypointObj

Waypoints returns a list of all waypoints.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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