This repository was archived by the owner on Jun 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +12
-2
lines changed
Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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 ++ ) {
Original file line number Diff line number Diff 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 ) ) ) ;
You can’t perform that action at this time.
0 commit comments