@caspertech/node-metaverse 0.7.24 → 0.7.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,63 +1,63 @@
1
- import { ExampleBot } from '../ExampleBot';
2
- import { BalanceUpdatedEvent } from '../../lib/events/BalanceUpdatedEvent';
3
- import { AvatarQueryResult } from '../../lib/classes/public/AvatarQueryResult';
4
- import { MoneyTransactionType } from '../../lib/enums/MoneyTransactionType';
5
-
6
- class Money extends ExampleBot
7
- {
8
- private balance = 0;
9
-
10
- async onConnected(): Promise<void>
11
- {
12
- this.bot.clientEvents.onBalanceUpdated.subscribe(this.onBalanceUpdated.bind(this));
13
- try
14
- {
15
- this.balance = await this.bot.clientCommands.grid.getBalance();
16
- console.log('Balance is L$' + this.balance);
17
- await this.bot.clientCommands.grid.payAvatar('d1cd5b71-6209-4595-9bf0-771bf689ce00', 1, 'This is a gift for being so awesome!');
18
- console.log('Payment success');
19
- }
20
- catch (error)
21
- {
22
- console.log('Payment failed');
23
- }
24
- }
25
-
26
- async onBalanceUpdated(evt: BalanceUpdatedEvent): Promise<void>
27
- {
28
- this.balance = evt.balance;
29
- if (evt.transaction.from.equals(this.bot.agentID()))
30
- {
31
- if (evt.transaction.toGroup)
32
- {
33
- console.log('You paid a group L$' + evt.transaction.amount);
34
- }
35
- else
36
- {
37
- const result = await this.bot.clientCommands.grid.avatarKey2Name(evt.transaction.to) as AvatarQueryResult;
38
- console.log('You paid L$' + evt.transaction.amount + ' to ' + result.getName() + ' "' + evt.transaction.description + '" (' + MoneyTransactionType[evt.transaction.type] + ')');
39
- }
40
- }
41
- else
42
- {
43
- if (evt.transaction.fromGroup)
44
- {
45
- console.log('A group paid you L$' + evt.transaction.amount);
46
- }
47
- else
48
- {
49
- const result = await this.bot.clientCommands.grid.avatarKey2Name(evt.transaction.from) as AvatarQueryResult;
50
- console.log(result.getName() + ' paid you L$' + evt.transaction.amount + ' "' + evt.transaction.description + '" (' + MoneyTransactionType[evt.transaction.type] + ')');
51
- }
52
- }
53
- console.log('Balance updated (New balance L$' + evt.balance + ')');
54
- }
55
- }
56
-
57
- new Money().run().then(() =>
58
- {
59
-
60
- }).catch((err) =>
61
- {
62
- console.error(err);
63
- });
1
+ import { ExampleBot } from '../ExampleBot';
2
+ import { BalanceUpdatedEvent } from '../../lib/events/BalanceUpdatedEvent';
3
+ import { AvatarQueryResult } from '../../lib/classes/public/AvatarQueryResult';
4
+ import { MoneyTransactionType } from '../../lib/enums/MoneyTransactionType';
5
+
6
+ class Money extends ExampleBot
7
+ {
8
+ private balance = 0;
9
+
10
+ async onConnected(): Promise<void>
11
+ {
12
+ this.bot.clientEvents.onBalanceUpdated.subscribe(this.onBalanceUpdated.bind(this));
13
+ try
14
+ {
15
+ this.balance = await this.bot.clientCommands.grid.getBalance();
16
+ console.log('Balance is L$' + this.balance);
17
+ await this.bot.clientCommands.grid.payAvatar('d1cd5b71-6209-4595-9bf0-771bf689ce00', 1, 'This is a gift for being so awesome!');
18
+ console.log('Payment success');
19
+ }
20
+ catch (error)
21
+ {
22
+ console.log('Payment failed');
23
+ }
24
+ }
25
+
26
+ async onBalanceUpdated(evt: BalanceUpdatedEvent): Promise<void>
27
+ {
28
+ this.balance = evt.balance;
29
+ if (evt.transaction.from.equals(this.bot.agentID()))
30
+ {
31
+ if (evt.transaction.toGroup)
32
+ {
33
+ console.log('You paid a group L$' + evt.transaction.amount);
34
+ }
35
+ else
36
+ {
37
+ const result = await this.bot.clientCommands.grid.avatarKey2Name(evt.transaction.to) as AvatarQueryResult;
38
+ console.log('You paid L$' + evt.transaction.amount + ' to ' + result.getName() + ' "' + evt.transaction.description + '" (' + MoneyTransactionType[evt.transaction.type] + ')');
39
+ }
40
+ }
41
+ else
42
+ {
43
+ if (evt.transaction.fromGroup)
44
+ {
45
+ console.log('A group paid you L$' + evt.transaction.amount);
46
+ }
47
+ else
48
+ {
49
+ const result = await this.bot.clientCommands.grid.avatarKey2Name(evt.transaction.from) as AvatarQueryResult;
50
+ console.log(result.getName() + ' paid you L$' + evt.transaction.amount + ' "' + evt.transaction.description + '" (' + MoneyTransactionType[evt.transaction.type] + ')');
51
+ }
52
+ }
53
+ console.log('Balance updated (New balance L$' + evt.balance + ')');
54
+ }
55
+ }
56
+
57
+ new Money().run().then(() =>
58
+ {
59
+
60
+ }).catch((err) =>
61
+ {
62
+ console.error(err);
63
+ });
@@ -1,35 +1,35 @@
1
- import { ExampleBot } from '../ExampleBot';
2
- import { GameObject, Utils } from '../../lib';
3
-
4
- class TaskInventory extends ExampleBot
5
- {
6
- async onConnected(): Promise<void>
7
- {
8
- let attachments: GameObject[] = [];
9
- while(!attachments.length)
10
- {
11
- await Utils.sleep(1000);
12
- attachments = this.bot.currentRegion.objects.getObjectsByParent(this.bot.agent.localID);
13
- }
14
- console.log('Got ' + attachments.length + ' attachments');
15
-
16
- for(const obj of attachments)
17
- {
18
- await obj.updateInventory();
19
- for(const task of obj.inventory)
20
- {
21
- console.log('Found task inventory item ' + task.name);
22
- }
23
- }
24
-
25
- console.log('Finished!');
26
- }
27
- }
28
-
29
- new TaskInventory().run().then(() =>
30
- {
31
-
32
- }).catch((err) =>
33
- {
34
- console.error(err);
35
- });
1
+ import { ExampleBot } from '../ExampleBot';
2
+ import { GameObject, Utils } from '../../lib';
3
+
4
+ class TaskInventory extends ExampleBot
5
+ {
6
+ async onConnected(): Promise<void>
7
+ {
8
+ let attachments: GameObject[] = [];
9
+ while(!attachments.length)
10
+ {
11
+ await Utils.sleep(1000);
12
+ attachments = this.bot.currentRegion.objects.getObjectsByParent(this.bot.agent.localID);
13
+ }
14
+ console.log('Got ' + attachments.length + ' attachments');
15
+
16
+ for(const obj of attachments)
17
+ {
18
+ await obj.updateInventory();
19
+ for(const task of obj.inventory)
20
+ {
21
+ console.log('Found task inventory item ' + task.name);
22
+ }
23
+ }
24
+
25
+ console.log('Finished!');
26
+ }
27
+ }
28
+
29
+ new TaskInventory().run().then(() =>
30
+ {
31
+
32
+ }).catch((err) =>
33
+ {
34
+ console.error(err);
35
+ });
@@ -1,81 +1,81 @@
1
- import { ExampleBot } from '../ExampleBot';
2
- import { Avatar } from '../../lib/classes/public/Avatar';
3
- import { Subscription } from 'rxjs';
4
-
5
- class Region extends ExampleBot
6
- {
7
- private subscriptions: { [key: string]: {
8
- onMovedSubscription: Subscription;
9
- onTitleSubscription: Subscription;
10
- onLeftRegionSubscription: Subscription;
11
- onVisibleSubscription: Subscription;
12
- } } = {};
13
-
14
- public async onConnected(): Promise<void>
15
- {
16
- this.bot.clientEvents.onAvatarEnteredRegion.subscribe(this.onAvatarEntered.bind(this));
17
-
18
- const avs = this.bot.clientCommands.region.getAvatarsInRegion();
19
- for (const av of avs)
20
- {
21
- this.onAvatarEntered(av);
22
- }
23
- }
24
-
25
- private onAvatarEntered(av: Avatar): void
26
- {
27
- console.log(av.getName() + ' entered the region (' + ((av.isVisible) ? 'visible' : 'invisible') + ')');
28
- const avatarKey = av.getKey().toString();
29
- this.unsubscribe(avatarKey);
30
- this.subscriptions[avatarKey] = {
31
- onLeftRegionSubscription: av.onLeftRegion.subscribe(this.onAvatarLeft.bind(this)),
32
- onMovedSubscription: av.onMoved.subscribe(this.onAvatarMoved.bind(this)),
33
- onTitleSubscription: av.onTitleChanged.subscribe(this.onTitleChanged.bind(this)),
34
- onVisibleSubscription: av.onVisibleChanged.subscribe(this.onAvatarVisible.bind(this))
35
- }
36
- }
37
-
38
- private unsubscribe(key: string): void
39
- {
40
- const sub = this.subscriptions[key];
41
- if (sub === undefined)
42
- {
43
- return;
44
- }
45
- delete this.subscriptions[key];
46
-
47
- sub.onVisibleSubscription.unsubscribe();
48
- sub.onMovedSubscription.unsubscribe();
49
- sub.onTitleSubscription.unsubscribe();
50
- sub.onLeftRegionSubscription.unsubscribe();
51
- }
52
-
53
- private onAvatarLeft(av: Avatar): void
54
- {
55
- console.log(av.getName() + ' left the region');
56
- this.unsubscribe(av.getKey().toString());
57
- }
58
-
59
- private onAvatarMoved(av: Avatar): void
60
- {
61
- console.log(av.getName() + ' moved, position: ' + av.position.toString());
62
- }
63
-
64
- private onTitleChanged(av: Avatar): void
65
- {
66
- console.log(av.getName() + ' changed their title to: ' + av.getTitle());
67
- }
68
-
69
- private onAvatarVisible(av: Avatar): void
70
- {
71
- console.log(av.getName() + ' is now ' + (av.isVisible ? 'visible' : 'invisible'));
72
- }
73
- }
74
-
75
- new Region().run().then(() =>
76
- {
77
-
78
- }).catch((err) =>
79
- {
80
- console.error(err);
81
- });
1
+ import { ExampleBot } from '../ExampleBot';
2
+ import { Avatar } from '../../lib/classes/public/Avatar';
3
+ import { Subscription } from 'rxjs';
4
+
5
+ class Region extends ExampleBot
6
+ {
7
+ private subscriptions: { [key: string]: {
8
+ onMovedSubscription: Subscription;
9
+ onTitleSubscription: Subscription;
10
+ onLeftRegionSubscription: Subscription;
11
+ onVisibleSubscription: Subscription;
12
+ } } = {};
13
+
14
+ public async onConnected(): Promise<void>
15
+ {
16
+ this.bot.clientEvents.onAvatarEnteredRegion.subscribe(this.onAvatarEntered.bind(this));
17
+
18
+ const avs = this.bot.clientCommands.region.getAvatarsInRegion();
19
+ for (const av of avs)
20
+ {
21
+ this.onAvatarEntered(av);
22
+ }
23
+ }
24
+
25
+ private onAvatarEntered(av: Avatar): void
26
+ {
27
+ console.log(av.getName() + ' entered the region (' + ((av.isVisible) ? 'visible' : 'invisible') + ')');
28
+ const avatarKey = av.getKey().toString();
29
+ this.unsubscribe(avatarKey);
30
+ this.subscriptions[avatarKey] = {
31
+ onLeftRegionSubscription: av.onLeftRegion.subscribe(this.onAvatarLeft.bind(this)),
32
+ onMovedSubscription: av.onMoved.subscribe(this.onAvatarMoved.bind(this)),
33
+ onTitleSubscription: av.onTitleChanged.subscribe(this.onTitleChanged.bind(this)),
34
+ onVisibleSubscription: av.onVisibleChanged.subscribe(this.onAvatarVisible.bind(this))
35
+ }
36
+ }
37
+
38
+ private unsubscribe(key: string): void
39
+ {
40
+ const sub = this.subscriptions[key];
41
+ if (sub === undefined)
42
+ {
43
+ return;
44
+ }
45
+ delete this.subscriptions[key];
46
+
47
+ sub.onVisibleSubscription.unsubscribe();
48
+ sub.onMovedSubscription.unsubscribe();
49
+ sub.onTitleSubscription.unsubscribe();
50
+ sub.onLeftRegionSubscription.unsubscribe();
51
+ }
52
+
53
+ private onAvatarLeft(av: Avatar): void
54
+ {
55
+ console.log(av.getName() + ' left the region');
56
+ this.unsubscribe(av.getKey().toString());
57
+ }
58
+
59
+ private onAvatarMoved(av: Avatar): void
60
+ {
61
+ console.log(av.getName() + ' moved, position: ' + av.position.toString());
62
+ }
63
+
64
+ private onTitleChanged(av: Avatar): void
65
+ {
66
+ console.log(av.getName() + ' changed their title to: ' + av.getTitle());
67
+ }
68
+
69
+ private onAvatarVisible(av: Avatar): void
70
+ {
71
+ console.log(av.getName() + ' is now ' + (av.isVisible ? 'visible' : 'invisible'));
72
+ }
73
+ }
74
+
75
+ new Region().run().then(() =>
76
+ {
77
+
78
+ }).catch((err) =>
79
+ {
80
+ console.error(err);
81
+ });
@@ -1,34 +1,34 @@
1
- import { ExampleBot } from '../ExampleBot';
2
-
3
- class Estate extends ExampleBot
4
- {
5
- wait(ms: number): Promise<void>
6
- {
7
- return new Promise<void>((resolve) =>
8
- {
9
- setTimeout(() =>
10
- {
11
- resolve();
12
- }, ms)
13
- });
14
- }
15
- async onConnected(): Promise<void>
16
- {
17
- console.log('Sending a message');
18
- await this.bot.clientCommands.region.simulatorMessage('In about 10 seconds, the region will begin to restart. This is only a test, and the restart will be cancelled.');
19
- await this.wait(10000);
20
- console.log('Restarting');
21
- await this.bot.clientCommands.region.restartRegion(120);
22
- await this.wait(10000);
23
- console.log('Canceling restart');
24
- await this.bot.clientCommands.region.cancelRestart();
25
- }
26
- }
27
-
28
- new Estate().run().then(() =>
29
- {
30
-
31
- }).catch((err) =>
32
- {
33
- console.error(err);
34
- });
1
+ import { ExampleBot } from '../ExampleBot';
2
+
3
+ class Estate extends ExampleBot
4
+ {
5
+ wait(ms: number): Promise<void>
6
+ {
7
+ return new Promise<void>((resolve) =>
8
+ {
9
+ setTimeout(() =>
10
+ {
11
+ resolve();
12
+ }, ms)
13
+ });
14
+ }
15
+ async onConnected(): Promise<void>
16
+ {
17
+ console.log('Sending a message');
18
+ await this.bot.clientCommands.region.simulatorMessage('In about 10 seconds, the region will begin to restart. This is only a test, and the restart will be cancelled.');
19
+ await this.wait(10000);
20
+ console.log('Restarting');
21
+ await this.bot.clientCommands.region.restartRegion(120);
22
+ await this.wait(10000);
23
+ console.log('Canceling restart');
24
+ await this.bot.clientCommands.region.cancelRestart();
25
+ }
26
+ }
27
+
28
+ new Estate().run().then(() =>
29
+ {
30
+
31
+ }).catch((err) =>
32
+ {
33
+ console.error(err);
34
+ });
@@ -1,31 +1,31 @@
1
- import { ExampleBot } from '../ExampleBot';
2
- import { LandStatReportType } from '../../lib/enums/LandStatReportType';
3
- import { LandStatFlags } from '../../lib/enums/LandStatFlags';
4
-
5
- class Parcels extends ExampleBot
6
- {
7
- async onConnected(): Promise<void>
8
- {
9
- const parcelInMiddle = await this.bot.clientCommands.region.getParcelAt(128, 128);
10
- console.log('Parcel at 128x128 is ' + parcelInMiddle.Name);
11
-
12
- const parcels = await this.bot.clientCommands.region.getParcels();
13
- console.log('Parcels on region:');
14
- console.log('========================');
15
- for (const p of parcels)
16
- {
17
- console.log(p.Name);
18
- }
19
- console.log('========================');
20
- const stats = await this.bot.clientCommands.parcel.getLandStats(parcels[0].ParcelID, LandStatReportType.Scripts, LandStatFlags.FilterByOwner);
21
- console.log(JSON.stringify(stats, null, 4));
22
- }
23
- }
24
-
25
- new Parcels().run().then(() =>
26
- {
27
-
28
- }).catch((err) =>
29
- {
30
- console.error(err);
31
- });
1
+ import { ExampleBot } from '../ExampleBot';
2
+ import { LandStatReportType } from '../../lib/enums/LandStatReportType';
3
+ import { LandStatFlags } from '../../lib/enums/LandStatFlags';
4
+
5
+ class Parcels extends ExampleBot
6
+ {
7
+ async onConnected(): Promise<void>
8
+ {
9
+ const parcelInMiddle = await this.bot.clientCommands.region.getParcelAt(128, 128);
10
+ console.log('Parcel at 128x128 is ' + parcelInMiddle.Name);
11
+
12
+ const parcels = await this.bot.clientCommands.region.getParcels();
13
+ console.log('Parcels on region:');
14
+ console.log('========================');
15
+ for (const p of parcels)
16
+ {
17
+ console.log(p.Name);
18
+ }
19
+ console.log('========================');
20
+ const stats = await this.bot.clientCommands.parcel.getLandStats(parcels[0].ParcelID, LandStatReportType.Scripts, LandStatFlags.FilterByOwner);
21
+ console.log(JSON.stringify(stats, null, 4));
22
+ }
23
+ }
24
+
25
+ new Parcels().run().then(() =>
26
+ {
27
+
28
+ }).catch((err) =>
29
+ {
30
+ console.error(err);
31
+ });
@@ -1,23 +1,23 @@
1
- import { ExampleBot } from '../ExampleBot';
2
- import { SimStatsEvent } from '../../lib/events/SimStatsEvent';
3
-
4
- class Region extends ExampleBot
5
- {
6
- async onConnected(): Promise<void>
7
- {
8
- this.bot.clientEvents.onSimStats.subscribe(this.onSimStats.bind(this));
9
- }
10
-
11
- onSimStats(stats: SimStatsEvent): void
12
- {
13
- console.log(JSON.stringify(stats, null, 4));
14
- }
15
- }
16
-
17
- new Region().run().then(() =>
18
- {
19
-
20
- }).catch((err) =>
21
- {
22
- console.error(err);
23
- });
1
+ import { ExampleBot } from '../ExampleBot';
2
+ import { SimStatsEvent } from '../../lib/events/SimStatsEvent';
3
+
4
+ class Region extends ExampleBot
5
+ {
6
+ async onConnected(): Promise<void>
7
+ {
8
+ this.bot.clientEvents.onSimStats.subscribe(this.onSimStats.bind(this));
9
+ }
10
+
11
+ onSimStats(stats: SimStatsEvent): void
12
+ {
13
+ console.log(JSON.stringify(stats, null, 4));
14
+ }
15
+ }
16
+
17
+ new Region().run().then(() =>
18
+ {
19
+
20
+ }).catch((err) =>
21
+ {
22
+ console.error(err);
23
+ });
@@ -1,60 +1,60 @@
1
- import { LureEvent, Vector3 } from '../../lib';
2
- import { ExampleBot } from '../ExampleBot';
3
-
4
- class Teleports extends ExampleBot
5
- {
6
- // We can make the bot always try to get to a certain region regardless of where it logged in
7
- protected stayRegion = 'Izanagi';
8
-
9
- // And we can optionally specify a position
10
- protected stayPosition = new Vector3([122, 156, 189]);
11
-
12
- async onConnected(): Promise<void>
13
- {
14
- // "OnLure" event fires when someone tries to teleport us
15
- this.bot.clientEvents.onLure.subscribe(this.onLure.bind(this));
16
-
17
- // Alternatively we can TP someone else to us
18
- await this.bot.clientCommands.comms.sendTeleport(this.masterAvatar);
19
- }
20
-
21
- async onLure(lureEvent: LureEvent): Promise<void>
22
- {
23
- try
24
- {
25
- const regionInfo = await this.bot.clientCommands.grid.getRegionMapInfo(lureEvent.gridX / 256, lureEvent.gridY / 256);
26
- if (lureEvent.from.toString() === this.masterAvatar)
27
- {
28
- console.log('Accepting teleport lure to ' + regionInfo.block.name + ' (' + regionInfo.avatars.length + ' avatar' + ((regionInfo.avatars.length === 1) ? '' : 's') + '' +
29
- ' present) from ' + lureEvent.fromName + ' with message: ' + lureEvent.lureMessage);
30
- try
31
- {
32
- await this.bot.clientCommands.teleport.acceptTeleport(lureEvent);
33
- }
34
- catch (error)
35
- {
36
- console.error('Teleport error:');
37
- console.error(error);
38
- }
39
- }
40
- else
41
- {
42
- console.log('Ignoring teleport lure to ' + regionInfo.block.name + ' (' + regionInfo.avatars.length + ' avatar' + ((regionInfo.avatars.length === 1) ? '' : 's') + ' ' +
43
- 'present) from ' + lureEvent.fromName + ' with message: ' + lureEvent.lureMessage);
44
- }
45
- }
46
- catch (error)
47
- {
48
- console.error('Failed to get region map info:');
49
- console.error(error);
50
- }
51
- }
52
- }
53
-
54
- new Teleports().run().then(() =>
55
- {
56
-
57
- }).catch((err) =>
58
- {
59
- console.error(err)
60
- });
1
+ import { LureEvent, Vector3 } from '../../lib';
2
+ import { ExampleBot } from '../ExampleBot';
3
+
4
+ class Teleports extends ExampleBot
5
+ {
6
+ // We can make the bot always try to get to a certain region regardless of where it logged in
7
+ protected stayRegion = 'Izanagi';
8
+
9
+ // And we can optionally specify a position
10
+ protected stayPosition = new Vector3([122, 156, 189]);
11
+
12
+ async onConnected(): Promise<void>
13
+ {
14
+ // "OnLure" event fires when someone tries to teleport us
15
+ this.bot.clientEvents.onLure.subscribe(this.onLure.bind(this));
16
+
17
+ // Alternatively we can TP someone else to us
18
+ await this.bot.clientCommands.comms.sendTeleport(this.masterAvatar);
19
+ }
20
+
21
+ async onLure(lureEvent: LureEvent): Promise<void>
22
+ {
23
+ try
24
+ {
25
+ const regionInfo = await this.bot.clientCommands.grid.getRegionMapInfo(lureEvent.gridX / 256, lureEvent.gridY / 256);
26
+ if (lureEvent.from.toString() === this.masterAvatar)
27
+ {
28
+ console.log('Accepting teleport lure to ' + regionInfo.block.name + ' (' + regionInfo.avatars.length + ' avatar' + ((regionInfo.avatars.length === 1) ? '' : 's') + '' +
29
+ ' present) from ' + lureEvent.fromName + ' with message: ' + lureEvent.lureMessage);
30
+ try
31
+ {
32
+ await this.bot.clientCommands.teleport.acceptTeleport(lureEvent);
33
+ }
34
+ catch (error)
35
+ {
36
+ console.error('Teleport error:');
37
+ console.error(error);
38
+ }
39
+ }
40
+ else
41
+ {
42
+ console.log('Ignoring teleport lure to ' + regionInfo.block.name + ' (' + regionInfo.avatars.length + ' avatar' + ((regionInfo.avatars.length === 1) ? '' : 's') + ' ' +
43
+ 'present) from ' + lureEvent.fromName + ' with message: ' + lureEvent.lureMessage);
44
+ }
45
+ }
46
+ catch (error)
47
+ {
48
+ console.error('Failed to get region map info:');
49
+ console.error(error);
50
+ }
51
+ }
52
+ }
53
+
54
+ new Teleports().run().then(() =>
55
+ {
56
+
57
+ }).catch((err) =>
58
+ {
59
+ console.error(err)
60
+ });