count newly user set pixels that void steps upon too

This commit is contained in:
HF 2020-05-25 17:52:03 +02:00
parent 94c26f0ee2
commit e6ebc08e26
2 changed files with 22 additions and 4 deletions

View File

@ -26,6 +26,7 @@ class Void extends WebSocketEvents {
msTimeout: number;
pixelStack: Array;
area: Object;
userArea: Object;
curRadius: number;
curAngle: number;
curAngleDelta: number;
@ -42,12 +43,13 @@ class Void extends WebSocketEvents {
const area = TARGET_RADIUS ** 2 * Math.PI;
const online = webSockets.onlineCounter;
// require an average of 0.25 px / min / user
const requiredSpeed = Math.floor(online / 6);
const requiredSpeed = Math.floor(online / 10);
const ppm = Math.ceil(area / EVENT_DURATION_MIN + requiredSpeed);
// timeout between pixels
this.msTimeout = 60 * 1000 / ppm;
// area where we log placed pixels
this.area = new Uint8Array(TILE_SIZE * 3 * TILE_SIZE * 3);
this.userArea = new Uint8Array(TILE_SIZE * 3 * TILE_SIZE * 3);
// array of pixels that we place before continue building (instant-defense)
this.pixelStack = [];
this.curRadius = 0;
@ -87,6 +89,15 @@ class Void extends WebSocketEvents {
return false;
}
/*
* check if pixel is set by user during event
*/
isUserSet(x, y) {
const off = x + y * TILE_SIZE * 3;
const clr = this.userArea[off];
return clr || false;
}
static coordsToOffset(x, y) {
const ox = x % TILE_SIZE;
const oy = y % TILE_SIZE;
@ -139,6 +150,11 @@ class Void extends WebSocketEvents {
continue;
}
this.sendPixel(x, y, clr);
if (this.isUserSet(x, y)) {
// if drawing on a user set pixel, wait longer
setTimeout(this.voidLoop, this.msTimeout * 4);
return;
}
break;
}
}
@ -175,6 +191,8 @@ class Void extends WebSocketEvents {
const y = vOff + Math.floor(off / TILE_SIZE);
if (this.isSet(x, y, true)) {
this.pixelStack.push([x, y]);
} else {
this.userArea[x + y * TILE_SIZE * 3] = color;
}
}
}

View File

@ -215,7 +215,7 @@ class Event {
});
chatProvider.broadcastChatMessage(
'event',
`Alert! Void is rising in 2min near #d,${xNear},${yNear},30`,
`Alert! Threat is rising in 2min near #d,${xNear},${yNear},30`,
);
}
if (eventState !== 7) {
@ -232,7 +232,7 @@ class Event {
this.eventState = 9;
chatProvider.broadcastChatMessage(
'event',
'Alert! Threat rising!',
'Alert! Danger!',
);
}
if (eventState !== 9) {
@ -273,7 +273,7 @@ class Event {
if (now > this.chatTimeout) {
chatProvider.broadcastChatMessage(
'event',
`Void reached ${percent}% of its max size`,
`Clown Void reached ${percent}% of its max size`,
);
this.chatTimeout = now + 40000;
}