src/entities/Enemy.js
/**
	* Holds the implementation for the message handling of this game entity.
	*
	* @param {Telegram} telegram - The telegram with the message data.
	* @return {Boolean} Whether the message was processed or not.
	*/
Holds the implementation for the message handling of this game entity.
@param {Telegram} telegram - The telegram with the message data.
@return {Boolean} Whether the message was processed or not.
Holds the implementation for the message handling of this game entity . @param { Telegram } telegram - The telegram with the message data . @return { Boolean } Whether the message was processed or not .
handleMessage( telegram ) {
		switch ( telegram.message ) {
			case MESSAGE_HIT:
				this.health -= telegram.data.damage;
				if ( this.world.debug ) {
					console.log( 'DIVE.Enemy: Enemy with ID %s hit by Game Entity with ID %s receiving %i damage.', this.uuid, telegram.sender.uuid, telegram.data.damage );
				}
				if ( telegram.sender.isPlayer && this.status === STATUS_ALIVE ) {
					this.world.uiManager.showHitIndication();
				}
				if ( this.health <= 0 && this.status === STATUS_ALIVE ) {
					this.initDeath();
					const competitors = this.world.competitors;
					for ( let i = 0, l = competitors.length; i < l; i ++ ) {
						const competitor = competitors[ i ];
						if ( this !== competitor ) this.sendMessage( competitor, MESSAGE_DEAD );
					}
					this.world.uiManager.addFragMessage( telegram.sender, this );
				} else {
					if ( telegram.sender.status === STATUS_ALIVE ) {
						this.searchAttacker = true;
						this.endTimeSearch = this.currentTime + this.searchTime; 
						this.attackDirection.copy( telegram.data.direction ).multiplyScalar( - 1 ); 
					}
				}
				break;
			case MESSAGE_DEAD:
				const sender = telegram.sender;
				const memoryRecord = this.memorySystem.getRecord( sender );
				if ( memoryRecord && memoryRecord.visible ) {
					this.removeEntityFromMemory( sender );
					this.targetSystem.update();
				}
				break;
		}
		return true;
	}
handleMessage ( telegram ) { switch ( telegram . message ) { case MESSAGE_HIT : this . health -= telegram . data . damage ; if ( this . world . debug ) { console . log ( 'DIVE.Enemy: Enemy with ID %s hit by Game Entity with ID %s receiving %i damage.' , this . uuid , telegram . sender . uuid , telegram . data . damage ) ; } if ( telegram . sender . isPlayer && this . status === STATUS_ALIVE ) { this . world . uiManager . showHitIndication ( ) ; } if ( this . health <= 0 && this . status === STATUS_ALIVE ) { this . initDeath ( ) ; const competitors = this . world . competitors ; for ( let i = 0 , l = competitors . length ; i < l ; i ++ ) { const competitor = competitors [ i ] ; if ( this !== competitor ) this . sendMessage ( competitor , MESSAGE_DEAD ) ; } this . world . uiManager . addFragMessage ( telegram . sender , this ) ; } else { if ( telegram . sender . status === STATUS_ALIVE ) { this . searchAttacker = true ; this . endTimeSearch = this . currentTime + this . searchTime ; this . attackDirection . copy ( telegram . data . direction ) . multiplyScalar ( - 1 ) ; } } break ; case MESSAGE_DEAD : const sender = telegram . sender ; const memoryRecord = this . memorySystem . getRecord ( sender ) ; if ( memoryRecord && memoryRecord . visible ) { this . removeEntityFromMemory ( sender ) ; this . targetSystem . update ( ) ; } break ; } return true ; }
Holds the implementation for the message handling of this game entity.
Holds the implementation for the message handling of this game entity .
// reduce health // logging // if the player is the sender and if the enemy still lives, change the style of the crosshairs // check if the enemy is death // inform all other competitors about its death // update UI // if not, search for attacker if he is still alive // only search for a specific amount of time // negate the vector // delete the dead enemy from the memory system when it was visible. // also update the target system so the bot looks for a different target