From e6ebc08e264453fac5752367c6296ef0c7ea3443 Mon Sep 17 00:00:00 2001 From: HF Date: Mon, 25 May 2020 17:52:03 +0200 Subject: [PATCH] count newly user set pixels that void steps upon too --- src/core/Void.js | 20 +++++++++++++++++++- src/core/event.js | 6 +++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/core/Void.js b/src/core/Void.js index ae797c6..26e81d1 100644 --- a/src/core/Void.js +++ b/src/core/Void.js @@ -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; } } } diff --git a/src/core/event.js b/src/core/event.js index e3648d5..ef02b66 100644 --- a/src/core/event.js +++ b/src/core/event.js @@ -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; }