· 6 years ago · Jul 04, 2019, 02:36 PM
1PROGRESS COUNTER TOOL:
2Usage: At initial login (or anytime display breaks), use <progressresetall> to setup.
3After disconnecting/reconnect, use the <linkdead> command before killing anything, or progress will not display correctly once next level is reached. It uses some crazy regex to capture the names of your leader and teammates and fill in some replicated mud.gmcp.char.team values for leader and members so the progress tracker attributes kills correctly. At least...it should. Please report in if this does not seem to be working. Alternatively, if you are leading and you get disconnected, toggle the team stay/follow command to refresh the GMCP team information.
4
5Known issues: team members that have not been introduced will not have their kills counted
6
7Author: Shanoga (team kills added by Kelrhys)
8
9PROGRESS COUNTER ALIAS
10---------------------------------------------------------------------------------------------------
11Name:
12 progress (or whatever you want)
13---------------------------------------------------------------------------------------------------
14Pattern (JavaScript):
15
16// Initialize a few variables for formatting and timekeeping
17var space = " ";
18var secondsBetween = 0;
19var minutesBetween = 0;
20var hoursBetween = 0;
21var hoursBetween = 0;
22
23// Make sure that we have at least one kill
24if (gwc.userdata.dailyKills === undefined ||
25 gwc.userdata.dailyKills == 0) {
26 gwc.output.append("You haven't killed anything yet...");
27 return;
28}
29
30// Skip a line and set the header and form for the table
31gwc.output.append("@----------------------------------------------@");
32gwc.output.append("| PROGRESS THIS SESSION | DURATION |");
33gwc.output.append("|----------------------------------------------|");
34
35// Loop through each progress level and the number of kills
36// Format to left-align the name of the progress level
37// Reserve spaces for up to 9999 (over 1000) kills per progress level
38// Right-align the labeled kill count
39for (var progress in gwc.userdata.progressTable) {
40 if (gwc.userdata.currentProgress == "insignificant") {
41 gwc.output.append("| NO PROGRESS YET | |");
42 continue;
43 } else if (progress == "insignificant") {
44 //gwc.output.append("| | |");
45 continue;
46 }
47 secondsBetween = gwc.userdata.progressTimeTable[progress];
48 if (secondsBetween > 60 && secondsBetween < 3601) {
49 minutesBetween = Math.floor(secondsBetween / 60);
50 secondsBetween = secondsBetween % 60;
51 gwc.output.append("| " + progress + ":" + space.repeat(16 - progress.length) + " " +
52 space.repeat(4 - gwc.userdata.progressTable[progress].toString().length) +
53 gwc.userdata.progressTable[progress] + " kills | " +
54 space.repeat(2 - minutesBetween.toString().length) + minutesBetween + "m " +
55 space.repeat(2 - secondsBetween.toString().length) + secondsBetween + "s |");
56 } else if (secondsBetween < 60) {
57 gwc.output.append("| " + progress + ":" + space.repeat(16 - progress.length) + " " +
58 space.repeat(4 - gwc.userdata.progressTable[progress].toString().length) +
59 gwc.userdata.progressTable[progress] + " kills | " +
60 space.repeat(2 - secondsBetween.toString().length) + secondsBetween + "s |");
61 } else {
62 hoursBetween = Math.floor(secondsBetween / 3600);
63 minutesBetween = Math.floor((secondsBetween - (hoursBetween * 3600)) / 60);
64 secondsBetween = secondsBetween % 60;
65 gwc.output.append("| " + progress + ":" + space.repeat(16 - progress.length) + " " +
66 space.repeat(4 - gwc.userdata.progressTable[progress].toString().length) +
67 gwc.userdata.progressTable[progress] + " kills | " +
68 space.repeat(2 - hoursBetween.toString().length) + hoursBetween + "h " +
69 space.repeat(2 - minutesBetween.toString().length) + minutesBetween + "m " +
70 space.repeat(2 - secondsBetween.toString().length) + secondsBetween + "s |");
71 }
72}
73if (progress != "insignificant") gwc.output.append("|----------------------------------------------|");
74gwc.output.append("| Total Kills: " + gwc.userdata.dailyKills + " -- Fantastics: " +
75 gwc.userdata.fantasticProgress +
76 space.repeat(16 - (gwc.userdata.dailyKills.toString().length +
77 gwc.userdata.fantasticProgress.toString().length)) + "|");
78
79// Show team kills
80var killStringList = [];
81for (var who in gwc.userdata.killsTable) {
82 killStringList.push("[" + gwc.userdata.killsTable[who] + "] " + who);
83}
84// Print 2 names per line, if possible
85for (var i=0; i<killStringList.length; i++) {
86 // Print even-numbered element plus next in list, if it exists
87 if ((i%2 == 0) && (i+1 < killStringList.length)) {
88 gwc.output.append("| " + killStringList[i] + space.repeat(22 - killStringList[i].length) +
89 killStringList[i+1] + space.repeat(22 - killStringList[i+1].length) + " |");
90 i++;
91 } else {
92 // Print last/only element
93 gwc.output.append("| " + killStringList[i] + space.repeat(44 - killStringList[i].length) +
94 " |");
95 }
96}
97gwc.output.append("@----------------------------------------------@");
98
99=============================================================================================
100=============================================================================================
101=============================================================================================
102=============================================================================================
103
104LAST PROGRESS ALIAS
105---------------------------------------------------------------------------------------------------
106Name:
107 lastprogress (or whatever you want)
108---------------------------------------------------------------------------------------------------
109Pattern (JavaScript):
110
111// Initialize some variables and get the current time
112var space = ' ';
113var tempDate = new Date();
114var tempTime = Math.floor((tempDate.getTime() - gwc.userdata.progressTime) / 1000 );
115var timeString = '';
116
117// Set the string value for the amount of time since last progress
118if (tempTime > 3599) {
119 timeString = Math.floor(tempTime/3600) + ' hour';
120 if (Math.floor(tempTime/3600) != 1) timeString += 's';
121 tempTime -= 3600 * (Math.floor(tempTime/3600));
122}
123timeString += ' ' + Math.floor(tempTime/60) + ' minute';
124if (Math.floor(tempTime/60) != 1) timeString += 's';
125timeString += ' ' + tempTime % 60 + ' second';
126if (tempTime % 60 != 1) timeString += 's';
127
128// Print the messages
129gwc.output.append('@----------------------------------------------------------@');
130gwc.output.append('| Kills since last progress: ' + gwc.userdata.progressKills + space.repeat(30 - gwc.userdata.progressKills.toString().length) + "|");
131gwc.output.append('| Time since last progress: ' + timeString + space.repeat(31 - timeString.length) + "|");
132gwc.output.append('@----------------------------------------------------------@');
133
134
135=============================================================================================
136=============================================================================================
137=============================================================================================
138=============================================================================================
139
140PROGRESS RESET ALIAS
141---------------------------------------------------------------------------------------------------
142Name:
143 progressreset (or whatever you want)
144---------------------------------------------------------------------------------------------------
145Pattern (JavaScript):
146
147// Resets the progress counter variables
148gwc.userdata.progressKills = 0;
149gwc.userdata.progressTime = new Date();
150gwc.userdata.progressTable = {};
151gwc.userdata.progressTimeTable = {};
152
153
154=============================================================================================
155=============================================================================================
156=============================================================================================
157=============================================================================================
158
159PROGRESS RESET ALL ALIAS
160---------------------------------------------------------------------------------------------------
161Name:
162 progressresetall (or whatever you want)
163---------------------------------------------------------------------------------------------------
164Pattern (JavaScript):
165
166// Resets the progress counter variables
167gwc.userdata.dailyKills = 0;
168gwc.userdata.progressKills = 0;
169gwc.userdata.progressTime = new Date();
170gwc.userdata.progressTable = {};
171gwc.userdata.progressTimeTable = {};
172gwc.userdata.killsTable = {};
173gwc.userdata.fantasticProgress = 0;
174
175=============================================================================================
176=============================================================================================
177=============================================================================================
178=============================================================================================
179
180RETURN FROM LINKDEATH ALIAS
181---------------------------------------------------------------------------------------------------
182Name:
183 linkdead (or whatever you want)
184---------------------------------------------------------------------------------------------------
185Pattern (JavaScript):
186
187// Reset progress time, it becomes unusable for new session for some reason
188gwc.userdata.progressTime = new Date();
189gwc.connection.send('team');
190gwc.output.append('Reset progressTime and team after returning from linkdeath.');
191
192=============================================================================================
193=============================================================================================
194=============================================================================================
195=============================================================================================
196
197PROGRESS COUNTER TRIGGER:
198---------------------------------------------------------------------------------------------------
199Pattern (Regex):
200 ^(\w+) killed (.*)\.$
201---------------------------------------------------------------------------------------------------
202Script (JavaScript):
203
204// Initialize and define the gmcp variables in case we are fighting solo
205if (mud.gmcp['char.team'] === undefined) mud.gmcp['char.team'] = {};
206if (mud.gmcp['char.team'].members === undefined) mud.gmcp['char.team'].members = [];
207if (mud.gmcp['char.team'].leader === undefined) mud.gmcp['char.team'].leader = '';
208var members = mud.gmcp['char.team'].members;
209var leader = mud.gmcp['char.team'].leader;
210
211//gwc.output.append('Killer: ' + args[1]);
212
213// Check to see if the enemy died to me or a teammate
214if (args[1] != 'You') {
215 // I didn't get the kill...
216 if (leader === undefined || leader == 0) {
217 // ...and I'm not in a team. Don't count it.
218 return;
219 } else if (args[1] != leader) {
220 // ...my leader didn't get the kill...
221 if (Object.values(members).indexOf(args[1]) == -1) {
222 // ...none of my teammates to the kill. Don't count it.
223 return;
224 }
225 }
226}
227
228// Teammate or I got the kill - Update kill counters
229if (gwc.userdata.killsTable === undefined) gwc.userdata.killsTable = {};
230var found = false;
231for (var who in gwc.userdata.killsTable) {
232 if (who == args[1]) {
233 gwc.userdata.killsTable[who] += 1;
234 found = true;
235 break;
236 }
237}
238if (!found) {
239 gwc.userdata.killsTable[args[1]] = 1;
240}
241
242// Record our progress level after the kill
243var newProgress = gwc.gmcp.data.character.vitals.progress;
244
245// Initialize the userdata after the first kill of the session
246if (gwc.userdata.dailyKills === undefined) gwc.userdata.dailyKills = 0;
247if (gwc.userdata.progressKills === undefined) gwc.userdata.progressKills = 0;
248if (gwc.userdata.fantasticProgress === undefined) gwc.userdata.fantasticProgress = 0;
249if (gwc.userdata.currentProgress === undefined) gwc.userdata.currentProgress = "no measurable";
250if (gwc.userdata.progressTable === undefined) gwc.userdata.progressTable = {};
251if (gwc.userdata.progressTimeTable === undefined) gwc.userdata.progressTimeTable = {};
252if (gwc.userdata.progressTime === undefined) {
253 gwc.userdata.progressTime = new Date();
254 gwc.userdata.progressTime.getTime();
255}
256
257// Increment the counters of kills for the session (dailyKills)
258// and the kills since the last progress level (progressKills)
259gwc.userdata.dailyKills += 1;
260gwc.userdata.progressKills += 1;
261
262// Check if the progress level after the kill is the same as before the kill
263// If the progress level is new, then record the level and its number of kills in a table
264if (gwc.userdata.currentProgress != newProgress && newProgress != 'insignificant') {
265 gwc.output.append('Adding new progress entry: ' + newProgress + ' from ' + gwc.userdata.currentProgress);
266 gwc.userdata.progressTable[newProgress] = gwc.userdata.progressKills;
267 var tempDate = new Date();
268 gwc.userdata.progressTimeTable[newProgress] = Math.floor((tempDate.getTime() - gwc.userdata.progressTime) / 1000);
269 gwc.userdata.progressKills = 0;
270 gwc.userdata.progressTime = tempDate;
271 gwc.connection.send('progress', true);
272}
273
274// Reset the counters when at fantastic
275if (newProgress == "fantastic") {
276 gwc.userdata.fantasticProgress += 1;
277 gwc.output.append("FANTASTIC PROGRESS - STATS RESET");
278 gwc.connection.send("stats reset");
279 gwc.userdata.currentProgress = "no measurable";
280 gwc.userdata.progressTable = {};
281 gwc.userdata.progressTime = tempDate;
282}
283
284// Store the new progress level as our current progress level
285gwc.userdata.currentProgress = newProgress;
286
287
288=============================================================================================
289=============================================================================================
290=============================================================================================
291=============================================================================================
292
293TEAM RESET TRIGGER
294---------------------------------------------------------------------------------------------------
295Pattern (Regex):
296
297^(The leader of your team is (\w+)\. (You are the only member\.|The other member is (\w+)\.|The other members are (\w+) and (\w+)\.|The other members are (\w+), (\w+) and (\w+)\.|The other members are (\w+), (\w+), (\w+) and (\w+)\.|The other members are (\w+), (\w+), (\w+), (\w+) and (\w+)\.|The other members are (\w+), (\w+), (\w+), (\w+), (\w+) and (\w+)\.|The other members are (\w+), (\w+), (\w+), (\w+), (\w+), (\w+) and (\w+)\.|The other members are (\w+), (\w+), (\w+), (\w+), (\w+), (\w+) and (\w+)\.)|You are the leader of your team\. (The members are (\w+)\.|The members are (\w+) and (\w+)\.|The members are (\w+), (\w+) and (\w+)\.|The members are (\w+), (\w+), (\w+) and (\w+)\.|The members are (\w+), (\w+), (\w+), (\w+) and (\w+)\.|The members are (\w+), (\w+), (\w+), (\w+), (\w+) and (\w+)\.|The members are (\w+), (\w+), (\w+), (\w+), (\w+), (\w+) and (\w+)\.|The members are (\w+), (\w+), (\w+), (\w+), (\w+), (\w+), (\w+) and (\w+)\.|The members are (\w+), (\w+), (\w+), (\w+), (\w+), (\w+), (\w+), (\w+) and (\w+)\.))$
298
299---------------------------------------------------------------------------------------------------
300Pattern (JavaScript):
301
302// 20190211 - simplified
303// First check to see if we already have team values
304// We'll keep what is already there
305if (mud.gmcp['char.team'] != undefined) {
306 gwc.output.append('char.team exists, returning');
307 return;
308}
309
310// Create empty gmcp objects that we will fill below
311mud.gmcp['char.team'] = {};
312mud.gmcp['char.team'].members = [];
313
314// Set team leader and members
315// Add our GMCP object values so that they are captured by the progress trigger
316mud.gmcp['char.team'].leader = args[2];
317gwc.output.append('Team leader set to: ' + mud.gmcp['char.team'].leader);
318if (args[0].includes('You are the only member.')) {
319 mud.gmcp['char.team'].members[0] = 'You';
320 gwc.output.append('Team members set to: ' + mud.gmcp['char.team'].members);
321 return;
322}
323
324// Set other team members
325var i=4;
326while (args[i] != undefined) {
327 //gwc.output.append('i: ' + i + ' setting member ' + i-4 + ' to: ' + args[i]);
328 mud.gmcp['char.team'].members[i-4] = args[i];
329 i++;
330}
331gwc.output.append('Team members set to: ' + mud.gmcp['char.team'].members);