Skip to content

Commit 4baeb1c

Browse files
authored
Miscellaneous content changes (#381)
# Description This adds scripting improvements, documentation, and additional functionality in general. It also adds a `jail` in Frostfang, an ephemeral room that locks players in for 1 hour (in game time) before letting them out. Later the jail will be used by guards to throw outlaw characters into jail (if caught). ## Changes - `teleport` admin command can target other players now. - Frostfang jail added, locks players in for 1 hour in game time if they get sent there. - Added scripting documentation and more scripting commands: - `ActorObject.TimerSet` / `ActorObject. TimerExpired ` / `ActorObject. TimerExists` - `RoomObject.IsEphemeral` / `RoomObject.RoomIdSource()` / `RoomObject.isLocked()` - Documented `onIdle()` room event. - `onEnter()` room event can return false to abort showing the Room description. - Updated some scripts to use new changes. - Characters can have timers added, useful for scripting some stuff. - Improved admin build command, adjusted optional formats for exits, added unit tests.
1 parent d968512 commit 4baeb1c

File tree

42 files changed

+596
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+596
-105
lines changed

_datafiles/guides/building/scripting/FUNCTIONS_ACTORS.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ ActorObjects are the basic object that represents Users and NPCs
8484
- [ActorObject.IsHome() bool](#actorobjectishome-bool)
8585
- [ActorObject.Pathing() bool](#actorobjectpathing-bool)
8686
- [ActorObject.PathingAtWaypoint() bool](#actorobjectpathingatwaypoint-bool)
87+
- [ActorObject.TimerSet(name string, period string)](#actorobjecttimersetname-string-period-string)
88+
- [ActorObject.TimerExpired(name string) bool](#actorobjecttimerexpiredname-string-bool)
89+
- [ActorObject.TimerExists(name string) bool](#actorobjecttimerexistsname-string-bool)
8790

8891

8992

@@ -566,3 +569,20 @@ returns the total specific statmod from worn items and buffs
566569

567570
## [ActorObject.PathingAtWaypoint() bool](/internal/scripting/actor_func.go)
568571
(mobs only) Returns true if actor is pathing and at a waypoint.
572+
573+
574+
## [ActorObject.TimerSet(name string, period string)](/internal/scripting/actor_func.go)
575+
Starts a new Round timer
576+
577+
| Argument | Explanation |
578+
| --- | --- |
579+
| name | A string identifier. Reusing names will overwrite previously assigned names. |
580+
| period | How long until the timer expires. `1 real hour`, `1 hour`, etc. |
581+
582+
## [ActorObject.TimerExpired(name string) bool](/internal/scripting/actor_func.go)
583+
Returns true if the specified timer has expired or doesn't exist.
584+
585+
## [ActorObject.TimerExists(name string) bool](/internal/scripting/actor_func.go)
586+
Returns true if the specified timer exists.
587+
Set timers always exist until they are checked for expiration with `TimerExpired(name string)`
588+

_datafiles/guides/building/scripting/FUNCTIONS_ROOMS.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
- [RoomObject.HasMutator(mutName string) bool](#roomobjecthasmutatormutname-string-bool)
2929
- [RoomObject.AddMutator(mutName string)](#roomobjectaddmutatormutname-string)
3030
- [RoomObject.RemoveMutator(mutName string)](#roomobjectremovemutatormutname-string)
31+
- [RoomObject.IsEphemeral() bool](#roomobjectisephemeral-bool)
32+
- [RoomObject.RoomIdSource() int](#roomobjectroomidsource-int)
3133
- [RoomObject.RepeatSpawnItem(itemId int, roundInterval int \[, containerName\]](#roomobjectrepeatspawnitemitemid-int-roundinterval-int--containername)
3234
- [RoomObject.SetLocked(exitName string, lockIt bool)](#roomobjectsetlockedexitname-string-lockit-bool)
35+
- [RoomObject.IsLocked(exitName string) bool](#roomobjectislockedexitname-string-bool)
3336

3437
## [CreateInstancesFromRoomIds(RoomIds [int, int...]) Object ](/internal/scripting/room_func.go)
3538
Returns an Object with key/value pairs of `ProvidedRoomId`=>`NewRoomId`
@@ -244,6 +247,18 @@ _Note: This only expires it. It may be a mutator that respawns, in which case th
244247
| --- | --- |
245248
| mutName | the MutatorId of the mutator. |
246249

250+
## [RoomObject.IsEphemeral() bool](/internal/scripting/room_func.go)
251+
Returns true if the room is an Ephemeral Copy of a room.
252+
253+
_Note: This only expires it. It may be a mutator that respawns, in which case this doens't really completely remove it._
254+
255+
| Argument | Explanation |
256+
| --- | --- |
257+
| mutName | the MutatorId of the mutator. |
258+
259+
## [RoomObject.RoomIdSource() int](/internal/scripting/room_func.go)
260+
Returns the source RoomId if this room is an ephemeral copy, otherwise just the normal RoomId
261+
247262

248263
## [RoomObject.RepeatSpawnItem(itemId int, roundInterval int [, containerName]](/internal/scripting/room_func.go)
249264
Removes a temporary exit
@@ -264,3 +279,5 @@ Sets an exit to locked or not (If it has a lock)
264279
| exitName | The exitname to lock/unlock |
265280
| lockIt | if true, sets it to locked. Otherwise, unlocks it. |
266281

282+
## [RoomObject.IsLocked(exitName string) bool](/internal/scripting/room_func.go)
283+
Returns true if exit is locked, false if unlocked or has no lock.

_datafiles/guides/building/scripting/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ See [Spell Scripting](SCRIPTING_SPELLS.md)
2929

3030
[Messaging Functions](FUNCTIONS_MESSAGING.md) - Helper and info functions.
3131

32+
# Time Periods
33+
34+
Whenever you need to specific a "period" of time, it takes the following string format:
35+
36+
- Should be in the format of: `{num} {unit}` or `{num} real {unit}`
37+
- Unit can be: `rounds`, `hours`, `days`, `weeks`, `months`, `years`
38+
- Default is in-game time, not real time.
39+
- **To use real time, use the following format:** `{num} real {unit}` - Example: `1 real day`
40+
3241
# Special symbols in user or mob commands:
3342

3443
There are some special prefixes that can help target more specifically than just a name.

_datafiles/guides/building/scripting/SCRIPTING_ROOMS.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ function onEnter(user ActorObject, room RoomObject) {
3838
```
3939

4040
`onEnter()` is called when a player enters the room.
41+
Return `false` to suppress showing the room description on arrival.
42+
4143

4244
| Argument | Explanation |
4345
| --- | --- |
@@ -60,6 +62,20 @@ function onExit(user ActorObject, room RoomObject) {
6062

6163
---
6264

65+
```
66+
function onIdle(room RoomObject) {
67+
}
68+
```
69+
70+
`onIdle()` is called when a round passes in a room that has players in it.
71+
Returning true prevents generic idle actions from taking place.
72+
73+
| Argument | Explanation |
74+
| --- | --- |
75+
| room | [RoomObject](FUNCTIONS_ROOMS.md) |
76+
77+
---
78+
6379
```
6480
function onCommand(cmd string, rest string, user ActorObject, room RoomObject) {
6581
}

_datafiles/world/default/rooms/frost_lake/828.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function onEnter(user, room) {
1111

1212
nextSpawnRound = lastSpawnRound + UtilGetSecondsToRounds(30);
1313
if ( lastSpawnRound > 0 && roundNow < nextSpawnRound ) {
14-
return;
14+
return true;
1515
}
1616

1717
allItems = room.GetItems();
@@ -20,14 +20,16 @@ function onEnter(user, room) {
2020
for ( i=0; i<allItems.length; i++ ) {
2121
if ( allItems[i].ItemId() == 10016 ) {
2222
oarExists = true;
23-
return;
23+
return true;
2424
}
2525
}
2626

2727
if ( !oarExists ) {
2828
room.SpawnItem(10016, false);
2929
lastSpawnRound = roundNow;
3030
}
31+
32+
return true;
3133
}
3234

3335

_datafiles/world/default/rooms/frostfang/1.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11

22
mapSignData = "";
33

4+
function onEnter(user, room) {
5+
6+
// Special case for if the player left the game while in jail.
7+
// The ephemeral room gets destroyed and the player gets sent back to TS
8+
// From here we can put them back in jail.
9+
if ( user.TimerExists("jail") ) {
10+
user.MoveRoom(1003);
11+
return false;
12+
}
13+
return true;
14+
}
15+
416
// Generic Command Handler
517
function onCommand(cmd, rest, user, room) {
618

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
roomid: 1002
2+
zone: Frostfang
3+
title: Jail
4+
description: The jail adjoins the Soldiers Barracks like a grim shadow, its cold stone
5+
walls damp with the weight of confinement. Dim torchlight flickers along the corridor,
6+
casting long, uneasy shadows across iron-barred windows and heavy oak doors reinforced
7+
with blackened steel. At the far end of the room, a thick iron door marked CELLS
8+
stands locked and unmoving, its rusted bolts and sturdy latch making it clearbno
9+
one passes through without command.
10+
biome: city
11+
exits:
12+
west:
13+
roomid: 270
14+
nouns:
15+
CELLS: :cells
16+
cell: :cells
17+
cells: The cells are inpenetrable. Only a guard can gain access.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
const JAIL_TIME = "1 hour";
3+
4+
function onEnter(user, room) {
5+
6+
if ( !room.IsEphemeral() ) {
7+
8+
var newRoomIds = CreateInstancesFromRoomIds( [room.RoomId()] );
9+
10+
if ( newRoomIds[room.RoomId()] ) {
11+
user.MoveRoom(newRoomIds[room.RoomId()]);
12+
return false;
13+
}
14+
15+
}
16+
17+
user.TimerSet("jail", JAIL_TIME);
18+
19+
room.SendText("");
20+
room.SendText("<ansi fg=\"red-bold\">********************************************************************************</ansi>");
21+
room.SendText("You hear a loud <ansi fg=\"red-bold\">!!!CLANK!!!</ansi>, and can immediately tell...");
22+
room.SendText("The cell door is LOCKED from the other side!");
23+
room.SendText('You hear someone shout, <ansi fg="saytext-mob">"Maybe an hour in a cell will cool you off!"</ansi>');
24+
room.SendText("<ansi fg=\"red-bold\">********************************************************************************</ansi>");
25+
room.SendText("");
26+
27+
user.Command("look", 1);
28+
29+
return false;
30+
}
31+
32+
function onIdle(room) {
33+
34+
if ( room.IsLocked("cell door") ) {
35+
var playersInRoom = room.GetPlayers();
36+
for( var i in playersInRoom ) {
37+
if ( playersInRoom[i].TimerExpired("jail") ) {
38+
room.SendText("You hear a loud CLANK, and the cell door is UNLOCKED from the other side.");
39+
room.SetLocked("cell door", false);
40+
}
41+
}
42+
}
43+
44+
return true;
45+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
roomid: 1003
2+
zone: Frostfang
3+
title: Inside a Jail Cell
4+
description: The cell is narrow and barren, carved from the same unforgiving stone
5+
as the rest of the jail. A single slit in the wall lets in a pale shaft of light,
6+
barely enough to see the rust-streaked walls and the straw-stuffed pallet shoved
7+
into the corner. The air is thick with mildew and the lingering stench of past occupants.
8+
Iron shackles hang limply from the wall, their presence more threatening than their
9+
current use. Every sound echoes with eerie claritybdrips of water, distant footsteps,
10+
or worse, silence.
11+
biome: city
12+
exits:
13+
cell door:
14+
roomid: 1002
15+
lock:
16+
difficulty: 32

_datafiles/world/default/rooms/frostfang/270.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ description: The Soldiers Barracks in Frostfang is a bastion of military discipl
88
area.
99
biome: city
1010
exits:
11+
jail:
12+
roomid: 1002
13+
mapdirection: east
1114
north:
1215
roomid: 829
1316
northeast:

0 commit comments

Comments
 (0)