forked from smogon/pokemon-showdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat-plugins.js
165 lines (164 loc) · 8.4 KB
/
chat-plugins.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**
* Chat plug-ins
* Pokemon Showdown - http://pokemonshowdown.com/
*
* These are chat plugins - small programs to enhace the chat rooms on Pokemon Showdown.
* Plugins are objects inside the plugins object. The objects are expected to have data values and a commands object inside.
* The data object saves the data relevant to the plugin, like scores.
* The commands object is used to import the commands onto the chat commands.
* It's very important that you don't add plug-in commands with the same name as existing commands.
*
* @license MIT license
*/
var plugins = exports.plugins = {
/**
* Scavenger hunts plugin.
* This game is meant to show a first hint. Players will find the name of a room with that hint.
* When you find a room, it gives you a hint for the next room.
* You finish upon reaching the third room.
* This plugin requires the server to have a room with the id 'scavengers'.
*/
scavenger: {
status: 'off',
firstHint: '',
roomOne: '',
secondHint: '',
roomTwo: '',
thirdHint: '',
roomThree: '',
participants: {},
finished: [],
commands: {
scavengerstarthunt: function(target, room, user) {
if (!this.can('ban', null, room)) return false;
if (room.id !== 'scavengers') return this.sendReply('You can only start scavenger hunts on Scavengers room.');
if (plugins.scavenger.status === 'on') return this.sendReply('There is already an active scavenger hunt.');
var targets = target.split(',');
if (!targets[0] || !targets[1] || !targets[2] || !targets[3] || !targets[4] || !targets[5])
return this.sendReply('You need to add three rooms and three hints in a [room, hint,] format.');
plugins.scavenger.status = 'on';
plugins.scavenger.roomOne = toId(targets[0]);
plugins.scavenger.firstHint = targets[1].trim();
plugins.scavenger.roomTwo = toId(targets[2]);
plugins.scavenger.secondHint = targets[3].trim();
plugins.scavenger.roomThree = toId(targets[4]);
plugins.scavenger.thirdHint = targets[5].trim();
if (Rooms.rooms.scavengers) Rooms.rooms.scavengers.add(
'|raw|<div class="broadcast-blue"><strong>A new Scavenger Hunt has been started!'
+ ' The first hint is: ' + plugins.scavenger.firstHint + '</strong></div>'
);
return this.sendReply('Scavenger hunt started.');
},
scavengerendhunt: function(target, room, user) {
if (!this.can('ban', null, room)) return false;
if (room.id !== 'scavengers') return this.sendReply('You can only end scavenger hunts on Scavengers room.');
if (plugins.scavenger.status !== 'on') return this.sendReply('There is no active scavenger hunt.');
var result = '';
var winner = plugins.scavenger.finished[0];
var second = plugins.scavenger.finished[1];
var third = plugins.scavenger.finished[2];
var consolation = plugins.scavenger.finished.slice(3);
result += '<strong>Winner of Scavenger Hunt: ' + ((winner)? winner : 'no one') + '.';
result += '</strong> Second place: ' + ((second)? second : 'no one') + '.';
result += ' Third place: ' + ((third)? third : 'no one') + '.';
result += ' Consolation prize to: ' + ((consolation.length > 0)? consolation.join(', ') : 'no one') + '.';
result += '<br />Solution: ' + plugins.scavenger.roomOne + ', '
+ plugins.scavenger.roomTwo + ', ' + plugins.scavenger.roomThree + '.';
if (Rooms.rooms.scavengers) Rooms.rooms.scavengers.add('|raw|<div class="broadcast-blue"><strong>' + result + '</strong></div>');
this.parse('/scavengerresethunt');
return this.sendReply('Scavenger hunt finished.');
},
scavengerresethunt: function(target, room, user) {
if (!this.can('ban', null, room)) return false;
if (room.id !== 'scavengers') return this.sendReply('You can only reset scavenger hunts on Scavengers room.');
plugins.scavenger.status = 'off';
plugins.scavenger.roomOne = '';
plugins.scavenger.roomTwo = '';
plugins.scavenger.roomThree = '';
plugins.scavenger.firstHint = '';
plugins.scavenger.secondHint = '';
plugins.scavenger.thirdHint = '';
plugins.scavenger.participants = {};
plugins.scavenger.finished = [];
return this.sendReply('Scavenger hunt reset.');
},
scavenger: 'scavengers',
scavengers: function(target, room, user) {
return this.parse('/join scavengers');
},
scavengerhint: function(target, room, user) {
if (plugins.scavenger.status !== 'on') return this.sendReply('There is no active scavenger hunt right now.');
if (!plugins.scavenger.participants[user.userid]) return this.sendReply('You are not participating in the current scavenger hunt.');
if (plugins.scavenger.participants[user.userid].room >= 3) return this.sendReply('You have already finished!');
return this.sendReply(
'Your current hint: '
+ plugins.scavenger[{0:'firstHint', 1:'secondHint', 2:'thirdHint'}[plugins.scavenger.participants[user.userid].room]]
+ '. Type /scavenge [solution] to find out if you are right.'
);
},
scavenge: function(target, room, user) {
if (plugins.scavenger.status !== 'on') return this.sendReply('There is no active scavenger hunt right now.');
if (!plugins.scavenger.participants[user.userid]) return this.sendReply('You are not participating in the current scavenger hunt.');
if (plugins.scavenger.participants[user.userid].room >= 3) return this.sendReply('You have already finished!');
target = toId(target);
var room = plugins.scavenger.participants[user.userid].room;
if (plugins.scavenger[{0:'roomOne', 1:'roomTwo', 2:'roomThree'}[room]] === target) {
plugins.scavenger.participants[user.userid].room++;
room++;
if (room < 3) {
var currentHint = {1:'secondHint', 2:'thirdHint'};
return this.sendReply(
'Well done! You have advanced to the next room! The next hint is: '
+ plugins.scavenger[currentHint[room]]
);
} else {
// User finished, let's check the result
plugins.scavenger.finished.push(user.name);
var winningPositions = {1:'winner', 2:'second', 3:'third'};
var position = plugins.scavenger.finished.length;
var result = 'The user ' + user.name + ' has finished the hunt! (S)he is the '
+ ((winningPositions[position])? winningPositions[position] : position + 'th') + '!';
if (Rooms.rooms.scavengers) Rooms.rooms.scavengers.add(
'|raw|<div class="broadcast-blue"><strong>' + result + '</strong></div>'
);
}
} else {
return this.sendReply('Fat luck - that is not the next room!');
}
},
joinhunt: function(target, room, user) {
if (plugins.scavenger.status !== 'on') return this.sendReply('There is no active scavenger hunt right now.');
if (plugins.scavenger.participants[user.userid]) return this.sendReply('You are already participating in the current scavenger hunt.');
plugins.scavenger.participants[user.userid] = {id: user.userid, room: 0};
return this.sendReply('You joined the scavenger hunt! Type /scavenge name to try to find the room and /scavengerhint to read your current hint.');
},
scavengerstatus: function(target, room, user) {
if (plugins.scavenger.status !== 'on') return this.sendReply('There is no active scavenger hunt right now.');
if (!plugins.scavenger.participants[user.userid]) return this.sendReply('You are not participating in the current scavenger hunt.');
var currentHint = {0:'firstHint', 1:'secondHint', 2:'thirdHint'};
var room = plugins.scavenger.participants[user.userid].room;
return this.sendReply(
'Your current hunt status: You are in the room #' + room + ((room < 3)? '. Your current hint is '
+ plugins.scavenger[currentHint[room]] : '. You have finished') + '.'
);
},
scavengerhelp: function(target, room, user) {
if (room.id !== 'scavengers') return;
if (!this.canBroadcast()) return;
this.sendReplyBox(
'<strong>Player commands:</strong><br />' +
'- /scavengers: Join the scavengers room<br />' +
'- /joinhunt: Join the current hunt<br />' +
'- /scavengerhint: Get your current hint<br />' +
'- /scavengerstatus: Get your current game status<br />' +
'- /scavenge <em>name</em>: Test the [name] to find a room<br />' +
'<br />' +
'<strong>Admin commands:</strong><br />' +
'- /scavengerstarthunt <em>room one, hint, room two, hint, room three, hint</em>: Start a new hunt<br />' +
'- /scavengerendhunt: Finish current hunt and announce winners<br />' +
'- /scavengerresethunt: Reset the current hunt to mint status'
);
}
}
}
};