Skip to content

Commit 8af13b1

Browse files
committed
Further logic adjustments
* Use mapping from player to point instead of one variable, to prevent breakage when two players use the command simultaneously * No need to have a variable for p2
1 parent 850bef1 commit 8af13b1

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

build/scripts/playerCommands.js

Lines changed: 7 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/playerCommands.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,21 @@ export const commands = commandList({
143143
},
144144

145145
aoelog: command(() => {
146-
let p1: [number,number] | null = null;
147-
let p2: [number,number] | null = null;
148146
const allowedActions = [
149147
"built", "broke", "rotated", "killed", "configured", "pay-dropped", "picked up", "controlled"
150148
];
149+
const cachedPointMap = Object.create(null) as Partial<Record<string, [number, number]>>;
151150
return {
152151
args: ['persist:boolean?', 'amount:number?', 'action:string?'],
153152
description: 'Checks the history of all tiles in the selected region. Can be filtered by action.',
154153
perm: Perm.none,
155-
handler({args, outputSuccess, currentTapMode, handleTaps}) {
154+
handler({args, sender, outputSuccess, currentTapMode, handleTaps}) {
156155
if(currentTapMode === "off" || args.action || args.amount) {
157156
if(args.action && !allowedActions.includes(args.action))
158157
fail(`Invalid action. Allowed actions: ${allowedActions.join(", ")}`);
159158
if(args.amount && args.amount > 100) fail(`Limit cannot be greater than 100.`);
160159

161-
p1 = null;
162-
p2 = null;
160+
cachedPointMap[sender.uuid] = undefined;
163161
handleTaps("on");
164162
outputSuccess(`Aoelog mode enabled. To see the recent history of all tiles in a rectangular region, tap opposite corners of the rectangle. Run /aoelog with no arguments to disable.`);
165163
} else {
@@ -206,19 +204,18 @@ export const commands = commandList({
206204
if(limitTiles == amount)
207205
output(`Displaying first ${limitTiles} entries. To show other entries, increase the limit or select a smaller area.`);
208206
}
207+
const p1 = cachedPointMap[sender.uuid];
209208
if(!p1){
210-
p1 = [x, y];
209+
cachedPointMap[sender.uuid] = [x, y];
211210
output(`1st point set at (${x},${y})`);
212-
} else if(!p2){
213-
p2 = [x, y];
211+
} else {
212+
const p2 = [x, y] as [number, number];
214213
output(`2nd point set at (${x}, ${y})`);
215214
const width = Math.abs(p1[0] - p2[0]);
216215
const height = Math.abs(p1[1] - p2[1]);
217216
if(width > 50 || height > 50) fail("Selection too large: width/height cannot be more than 50.");
218217
handleArea(p1, p2);
219218
if(!args.persist) handleTaps("off");
220-
p1 = null;
221-
p2 = null;
222219
}
223220
},
224221
};

0 commit comments

Comments
 (0)