Skip to content
This repository was archived by the owner on Jun 22, 2025. It is now read-only.

Commit b16f310

Browse files
committed
2 parents 1bebde9 + f8dd8a5 commit b16f310

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

SDLU_Shooting_Server/Types/Type.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class User {
2121
this.kill = kill;
2222
this.death = death;
2323
this.exp = exp;
24+
/** @type {number} */
25+
this.hp = 100;
2426

2527
/** @type {GameUser} */
2628
this.gameUser = null;

SDLU_Shooting_Server/Utils/UserUtil.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class UserUtil
6464
console.log("userNotFinded...: " + this.userArr[i]);
6565
return null;
6666
}
67+
/**
68+
* @returns {User}
69+
*/
6770
getUserBySessionId(sessionId)
6871
{
6972
for (var i = 0; i < this.userArr.length; i++) {

SDLU_Shooting_Server/server.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,18 @@ wsServer.on("connection", socket => {
7272
broadcast(JSON.stringify(new DataVO(type, payload)));
7373
break;
7474
case "damage":
75-
console.log(`[${socket.sessionId}] ${type}: ${payload}`);
75+
console.log(`[${socket.sessionId}] ${type}: ${payload}` + ", HP: " + UserUtil.getUserBySessionId(id).hp);
76+
if (isNaN(UserUtil.getUserBySessionId(id).hp))
77+
UserUtil.getUserBySessionId(id).hp = 100;
7678
var { id, damage } = payload;
77-
UserUtil.getUserBySessionId(id).hp -= damage;
79+
damage = Number(damage);
80+
UserUtil.getUserBySessionId(id).hp -= 20;
7881

7982
if (UserUtil.getUserBySessionId(id).hp <= 0)
8083
{
84+
console.log("dead: " + id);
8185
broadcast(JSON.stringify(new DataVO("dead", payload)));
86+
socket.disconnect();
8287
}
8388
else
8489
broadcast(JSON.stringify(new DataVO(type, payload)));

0 commit comments

Comments
 (0)