From 155257514dedbb362d0514e6c16d7d0049a4d004 Mon Sep 17 00:00:00 2001 From: biglyderv Date: Mon, 25 Nov 2024 14:14:21 -0500 Subject: [PATCH] change scoring and sorting --- common/player.js | 8 ++++++-- game.js | 5 +++-- index.js | 5 +++++ static/js/index.js | 4 ++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/common/player.js b/common/player.js index c30d341..9e02f12 100644 --- a/common/player.js +++ b/common/player.js @@ -51,9 +51,13 @@ class Player extends Entity { player.ticks = 0; } handleTick(game) { + let { entities, width, height } = game; let ent = this; + ent.headCount += 1/200; + + ent.headCount = Math.round(ent.headCount * 1000) / 1000; if (ent.health <= 0) return; @@ -95,7 +99,7 @@ class Player extends Entity { } if (target.type == 'Shooter') { - this.health = 0; + this.health -= 1; } if (target.immortal) continue; @@ -113,7 +117,7 @@ class Player extends Entity { console.log(`Player ${target.you} died to a player ${ent.you}`); ent.health -= dmg; if (ent.health > 100) ent.health = 100; - ent.headCount++; + ent.headCount += 100; } } } diff --git a/game.js b/game.js index b63c023..043a6fa 100644 --- a/game.js +++ b/game.js @@ -49,7 +49,8 @@ class Game extends GameBasic { if (!hash) { hash = createHash('sha256'); - hash.update(client.ip || ''); + hash.update((+new Date) + ''); + //hash.update(client.ip || ''); hash = hash.digest('hex'); } @@ -108,7 +109,7 @@ class Game extends GameBasic { that.entities.push(new NPC(false, that)) } - for (let i = 0; i < 30; i++) { + for (let i = 0; i < 18; i++) { that.entities.push(new Shooter(false, that)) } diff --git a/index.js b/index.js index 40aa8dd..a19d324 100644 --- a/index.js +++ b/index.js @@ -62,7 +62,12 @@ app.ws('/', function (ws, req) { } ); j = await j.json(); + if (game.ws.findIndex(x => x.username == j.username) != -1) { + console.log(`Player ${player.you} uses username ${ws.username} illegally`) + return; + } ws.username = j.username; + console.log(`Player ${player.you} uses username ${ws.username}`) })() return; diff --git a/static/js/index.js b/static/js/index.js index 6dbfaf4..58ababf 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -100,7 +100,7 @@ class Game extends GameBasic { ctx.textBaseline = "bottom"; ctx.font = "bold 16px sans-serif"; - let args = [`HP: ${ent.health} KO: ${ent.headCount} XY: ${Math.round(ent.pos.x)}, ${Math.round(ent.pos.y)}`, ent.pos.x, ent.pos.y - 64 / 2]; + let args = [`HP: ${ent.health} PT: ${ent.headCount} XY: ${Math.round(ent.pos.x)}, ${Math.round(ent.pos.y)}`, ent.pos.x, ent.pos.y - 64 / 2]; ctx.strokeText(...args); ctx.fillText(...args); @@ -259,7 +259,7 @@ class Game extends GameBasic { scores[e.ip] += e.ko ** 2; } - scores = Object.entries(scores).sort((a,b) => b.ko - a.ko); + scores = Object.entries(scores).sort((a,b) => b[1] - a[1]); document.querySelector('.lb').textContent = scores.map(x => `${x[0]}: ${x[1]}`).join('\n'); }