-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (52 loc) · 2.14 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { RGBot } from "rg-bot";
import RGCTFUtils, { CTFEvent } from "rg-ctf-utils";
import { Vec3 } from "vec3";
/**
* This strategy is the simplest example of how to get started
* with the rg-bot and rg-ctf-utils packages. The Bot will get
* the flag and then run back to base to score.
*
* Ways to extend this code:
* TODO: What happens when a bot is completing an action and
* another event happens?
* TODO: How do we respond to item spawn and drop events?
* TODO: How do we target and attack enemies?
* TODO: What different states is my bot in, and how can I organize
* its behavior based on these states?
* rg-bot docs: https://github.com/Regression-Games/RegressionBot/blob/main/docs/api.md
* rg-ctf-utils docs: https://github.com/Regression-Games/rg-ctf-utils
* @param {RGBot} bot The configurable RGBot
*/
export function configureBot(bot) {
// Since most blocks can't be broken on Arctic Algorithm Field,
// don't allow digging while pathfinding
bot.allowDigWhilePathing(false);
// Instantiate our helper utilities and events for Capture the Flag
const rgctfUtils = new RGCTFUtils(bot);
// When a player types "start" in the chat, the bot will begin
// looking for and approaching the flag
bot.on('chat', async (username, message) => {
if (username === bot.username()) return;
if (message === 'start') {
bot.chat("Going to start capturing the flag!")
await rgctfUtils.approachFlag()
}
})
// When a player obtains the flag, this event gets called.
// In the case where that player is this bot, the bot
// navigates back to their scoring location.
bot.on(CTFEvent.FLAG_OBTAINED, async (collector) => {
if (collector == bot.username()) {
await rgctfUtils.scoreFlag()
}
});
// If the flag was scored, simply chat a message
bot.on(CTFEvent.FLAG_SCORED, async (teamName) => {
bot.chat(`Flag scored by ${teamName} team, waiting until it respawns`)
})
// Once the flag respawns on the map, look for and approach the flag.
bot.on(CTFEvent.FLAG_AVAILABLE, async (position) => {
bot.chat("Flag is available, going to get it")
await rgctfUtils.approachFlag();
})
}