src/core/WeaponSystem.js
/**
	* Adds a weapon of the specified type to the bot's inventory.
	* If the bot already has a weapon of this type only the ammo is added.
	*
	* @param {WEAPON_TYPES} type - The weapon type.
	* @return {WeaponSystem} A reference to this weapon system.
	*/
Adds a weapon of the specified type to the bot's inventory.
If the bot already has a weapon of this type only the ammo is added.

@param {WEAPON_TYPES} type - The weapon type.
@return {WeaponSystem} A reference to this weapon system.
Adds a weapon of the specified type to the bot ' s inventory . If the bot already has a weapon of this type only the ammo is added . @param { WEAPON_TYPES } type - The weapon type . @return { WeaponSystem } A reference to this weapon system .
addWeapon( type ) {
		const owner = this.owner;
		let weapon;
		switch ( type ) {
			case WEAPON_TYPES_BLASTER:
				weapon = new Blaster( owner );
				weapon.fuzzyModule = this.fuzzyModules.blaster;
				weapon.muzzle = this.renderComponents.blaster.muzzle;
				weapon.audios = this.renderComponents.blaster.audios;
				break;
			case WEAPON_TYPES_SHOTGUN:
				weapon = new Shotgun( owner );
				weapon.fuzzyModule = this.fuzzyModules.shotGun;
				weapon.muzzle = this.renderComponents.shotgun.muzzle;
				weapon.audios = this.renderComponents.shotgun.audios;
				break;
			case WEAPON_TYPES_ASSAULT_RIFLE:
				weapon = new AssaultRifle( owner );
				weapon.fuzzyModule = this.fuzzyModules.assaultRifle;
				weapon.muzzle = this.renderComponents.assaultRifle.muzzle;
				weapon.audios = this.renderComponents.assaultRifle.audios;
				break;
			default:
				console.error( 'DIVE.WeaponSystem: Invalid weapon type:', type );
				break;
		}
		const weaponInventory = this.weaponsMap.get( type );
		if ( weaponInventory !== null ) {
			weaponInventory.addRounds( weapon.getRemainingRounds() );
		} else {
			this.weaponsMap.set( type, weapon );
			this.weapons.push( weapon );
			owner.weaponContainer.add( weapon );
			if ( owner.isPlayer ) {
				weapon.scale.set( 2, 2, 2 );
				weapon.position.set( 0.3, - 0.3, - 1 );
				weapon.rotation.fromEuler( 0, Math.PI, 0 );
				weapon.initAnimations();
			} else {
				weapon.position.set( - 0.1, - 0.2, 0.5 );
			}
		}
		return this;
	}
addWeapon ( type ) { const owner = this . owner ; let weapon ; switch ( type ) { case WEAPON_TYPES_BLASTER : weapon = new Blaster ( owner ) ; weapon . fuzzyModule = this . fuzzyModules . blaster ; weapon . muzzle = this . renderComponents . blaster . muzzle ; weapon . audios = this . renderComponents . blaster . audios ; break ; case WEAPON_TYPES_SHOTGUN : weapon = new Shotgun ( owner ) ; weapon . fuzzyModule = this . fuzzyModules . shotGun ; weapon . muzzle = this . renderComponents . shotgun . muzzle ; weapon . audios = this . renderComponents . shotgun . audios ; break ; case WEAPON_TYPES_ASSAULT_RIFLE : weapon = new AssaultRifle ( owner ) ; weapon . fuzzyModule = this . fuzzyModules . assaultRifle ; weapon . muzzle = this . renderComponents . assaultRifle . muzzle ; weapon . audios = this . renderComponents . assaultRifle . audios ; break ; default : console . error ( 'DIVE.WeaponSystem: Invalid weapon type:' , type ) ; break ; } const weaponInventory = this . weaponsMap . get ( type ) ; if ( weaponInventory !== null ) { weaponInventory . addRounds ( weapon . getRemainingRounds ( ) ) ; } else { this . weaponsMap . set ( type , weapon ) ; this . weapons . push ( weapon ) ; owner . weaponContainer . add ( weapon ) ; if ( owner . isPlayer ) { weapon . scale . set ( 2 , 2 , 2 ) ; weapon . position . set ( 0.3 , - 0.3 , - 1 ) ; weapon . rotation . fromEuler ( 0 , Math . PI , 0 ) ; weapon . initAnimations ( ) ; } else { weapon . position . set ( - 0.1 , - 0.2 , 0.5 ) ; } } return this ; }
Adds a weapon of the specified type to the bot's inventory.
Adds a weapon of the specified type to the bot ' s inventory .
// check inventory // if the bot already holds a weapon of this type, just add its ammo // if not already present, add to inventory // also add it to owner entity so the weapon is correctly updated by // the entity manager