def __clientUpdate(self): dt = BigWorld.time() - self.__lastUpdateTime self.__setClientUpdateCallBack() if EntityStates.inState(self._owner, EntityStates.DEAD | EntityStates.OBSERVER): self.__stopShootingSounds() if EntityStates.inState(self._owner, EntityStates.GAME): self._wrdh.update(dt) if not self.__prevControllerPosition: self.__prevControllerPosition = Math.Vector3( self._owner.getShootingControllerPosition()) self.__prevControllerRotation = Math.Quaternion( self._owner.getShootingControllerRotation()) shootingGroups = self._owner.shootingGroups() singleShotGroups = self._owner.popSingleShotGroups( shootingGroups & self.__guns.singleShotMask) from Helpers.AvatarHelper import isSpectating if shootingGroups or singleShotGroups or self.__isPlayer or isSpectating( self._owner.id): if self.__pastTime > 0.0: self.__guns.commonUpdate(self.__pastTime, 0) self.__guns.commonUpdate(dt, shootingGroups) self.__pastTime = 0.0 shootClient = False shootingGroups &= ~self.__guns.singleShotMask weaponGroups = self.__guns.shoot(shootingGroups) if weaponGroups: self.__shootClient(dt, weaponGroups) shootClient = True if singleShotGroups: self.__guns.reload(singleShotGroups) weaponGroups = self.__guns.shoot(singleShotGroups) if weaponGroups: self.__shootClient(dt, weaponGroups) shootClient = True if COLLISION_RECORDER: self._owner.markPosition( 0, self.__prevControllerPosition, self._owner.syncedRandom.getInfo()) if not shootClient: self.__stopShootingSounds() else: if self.__pastTime == 0.0: self.__stopShootingSounds() self.__pastTime += dt self.__prevControllerPosition.set( self._owner.getShootingControllerPosition()) if COLLISION_RECORDER: self._owner.markPosition(1, self.__prevControllerPosition, self._owner.syncedRandom.getInfo()) self.__prevControllerRotation = self._owner.getShootingControllerRotation( ) if self.__isOwnerAvatar: self._owner.updateAmmo() Weapons.debug_showBulletCollisionEffects()
def _updateConsumable(self, playerConsumable, modelConsumable, status): modelConsumable.amount = playerConsumable.chargesCount consumableID = modelConsumable.id.get() activeEndTime = int( round(playerConsumable.activeTill - BigWorld.player().arenaStartTime)) if modelConsumable.activeEndTime.get() != activeEndTime: modelConsumable.activeEndTime = activeEndTime if playerConsumable.chargesCount == 0: modelConsumable.isEmpty = True modelConsumable.respawnEndTime = 0 else: modelConsumable.isEmpty = False respawnEndTime = int( round(playerConsumable.coolDownTill - BigWorld.player().arenaStartTime)) cooldownTime = self._db.getConsumableByID( consumableID).coolDownTime respawnStartTime = int(respawnEndTime - cooldownTime) modelConsumable.respawnEndTime = respawnEndTime modelConsumable.respawnStartTime = respawnStartTime self._updateStatus(modelConsumable, status) if EntityStates.inState( self._playerAvatar, EntityStates.END_GAME) and modelConsumable.status.get() == 2: modelConsumable.isEmpty = True
def __updatePreparations(self): self.__avatar = BigWorld.entities.get(self.__avatarID, None) if not self.__inProcess or not self.__avatar or EntityStates.inState( self.__avatar, EntityStates.DESTROYED): return False else: return True
def __updateVisibleAxis(self): if not self._notControlledByUser and EntityStates.inState(BigWorld.player(), EntityStates.GAME): player = BigWorld.player() fmRotation = BigWorld.player().getRotation() norm = Math.Vector3(self.__camDirection) norm.normalise() yawAngle = 0.5 * math.pi - math.acos(clamp(-1.0, fmRotation.getAxisX().dot(norm), 1.0)) pitchAngle = 0.5 * math.pi - math.acos(clamp(-1.0, fmRotation.getAxisY().dot(norm), 1.0)) mouseRoll = -sign(yawAngle) * clamp(-1.0, max(0.0, abs(yawAngle) / math.radians(5.0) - 1.0), 1.0) hAxis = clamp(-1.0, yawAngle / math.radians(5.0) * 8.0, 1.0) * (1 - abs(self.__lastKeyBoardAxis[HORIZONTAL_AXIS])) + self.__lastKeyBoardAxis[HORIZONTAL_AXIS] vAxis = clamp(-1.0, pitchAngle / math.radians(10.0), 1.0) * (1 - abs(self.__lastKeyBoardAxis[VERTICAL_AXIS])) + self.__lastKeyBoardAxis[VERTICAL_AXIS] rAxis = bool(InputMapping.g_instance.mouseSettings.ROLL_SPEED_CFC) * mouseRoll * (1 - abs(self.__lastKeyBoardAxis[ROLL_AXIS])) + self.__lastKeyBoardAxis[ROLL_AXIS] speedDirection = player.getWorldVector() speedDirection.normalise() dotX = clamp(-1.0, fmRotation.getAxisX().dot(speedDirection), 1.0) dotY = clamp(-1.0, fmRotation.getAxisY().dot(speedDirection), 1.0) angleX = abs(0.5 * math.pi - math.acos(dotX)) / math.radians(10.0) angleY = abs(0.5 * math.pi - math.acos(dotY)) / math.radians(35.0 / 2.0) signX = sign(dotX) signY = sign(dotY) hAxis = clamp(-1.0, hAxis - (1.0 - abs(hAxis)) * clamp(-1.0, signX * angleX, 1.0), 1.0) vAxis = clamp(-1.0, vAxis - (1.0 - abs(vAxis)) * clamp(-1.0, signY * angleY, 1.0), 1.0) mouseAngle = math.acos(clamp(-1.0, fmRotation.getAxisZ().dot(norm), 1.0)) equalizerAngle = 0.5 * (0.3 + 0.7 * InputMapping.g_instance.mouseSettings.RADIUS_OF_CONDUCTING) * BigWorld.projection().fov * InputMapping.g_instance.mouseSettings.EQUALIZER_ZONE_SIZE equalizer = max(0.0, (equalizerAngle - mouseAngle) / equalizerAngle) * clamp(-1.0, 3.0 * bool(InputMapping.g_instance.mouseSettings.EQUALIZER_FORCE) * player.roll / math.pi, 1.0) if equalizerAngle else 0.0 rAxis = clamp(-1.0, rAxis - (1.0 - abs(rAxis)) * equalizer, 1.0) self.__applyInputAxis(HORIZONTAL_AXIS, clamp(-1.0, hAxis, 1.0)) self.__applyInputAxis(ROLL_AXIS, clamp(-1.0, rAxis, 1.0)) self.__applyInputAxis(VERTICAL_AXIS, clamp(-1.0, vAxis, 1.0)) self.__applyInputAxis(FORCE_AXIS, self.__lastKeyBoardAxis[FORCE_AXIS]) automaticFlaps = False if InputMapping.g_instance.mouseSettings.AUTOMATIC_FLAPS: automaticFlaps = int(max(0.0, player.asymptoteVMaxPitch - abs(player.getRotationSpeed().y)) < 0.25 * player.asymptoteVMaxPitch) self.__applyInputAxis(FLAPS_AXIS, self.__lastKeyBoardAxis[FLAPS_AXIS] or automaticFlaps)
def __updateAirwave(self, target): AIRWAVE_DISTANCE = db.DBLogic.g_instance.cameraEffects.airwaveDistance if target.inWorld and EntityStates.inState(target, EntityStates.GAME): targetDir = target.position - BigWorld.player().position targetDist = targetDir.length if targetDist < AIRWAVE_DISTANCE: if target.id not in self.__nearPlaneDistances: self.__nearPlaneDistances[target.id] = (targetDist, targetDir, target.id) else: targetPrevInfo = self.__nearPlaneDistances[target.id] if targetPrevInfo: targetPrevDist = targetPrevInfo[0] if targetPrevDist < targetDist: self.__startAirwaveEffect(targetPrevInfo) self.__nearPlaneDistances[target.id] = None else: self.__nearPlaneDistances[target.id] = (targetDist, targetDir, target.id) return if target.id in self.__nearPlaneDistances: targetInfo = self.__nearPlaneDistances[target.id] if targetInfo: self.__startAirwaveEffect(targetInfo) self.__nearPlaneDistances.pop(target.id) return
def _canPerformUpdate(self): if not (self._player and self._player.inWorld and EntityStates.inState(self._player, EntityStates.GAME)): return False if not (self._getArena and self._gameMode and self._gameMode.isReady): return False return True
def __getFightPhase(self, flag=FLAG.NONE): if self.__currentSoundPhase in ( SOUND_PHASES.RESULT_SCREEN, SOUND_PHASES.SCREEN) or self.__currentSoundPhase in ( SOUND_PHASES.SPECTATOR, SOUND_PHASES.NOSEDIVING) and not flag == FLAG.RESPAWN: return phase = SOUND_PHASES.PILOTING player = BigWorld.player() visibleAvatars = player.visibleAvatars.values() if flag == FLAG.LEAVE_WORLD: enemiesCounter = 0 for avatar in visibleAvatars: arena = GameEnvironment.getClientArena() isTeamate = arena.avatarInfos.get(player.id).get( 'teamIndex', -1) == arena.avatarInfos.get(avatar.id).get('teamIndex', -1) if not isTeamate and not EntityStates.inState( avatar, EntityStates.DESTROYED): if not flag == FLAG.LEAVE_WORLD or enemiesCounter: phase = SOUND_PHASES.DOGFIGHT break else: enemiesCounter += 1 return phase
def __updateHUDProgress(self): arenaStartTime = BigWorld.player().arenaStartTime serverTime = BigWorld.serverTime() curTime = int(round(arenaStartTime - serverTime)) if arenaStartTime > 0: if curTime <= self.__class__.PRE_INTRO_CINEMATIC_START_TIME: if curTime > self.__class__.PRE_INTRO_ZOOM_START_TIME: if not self.__cinematicStarted: player = BigWorld.player() if EntityStates.inState(player, EntityStates.PRE_START_INTRO): if 'scenarioCameraController' in player.controllers: import BWPersonality player.controllers[ 'scenarioCameraController'].onEvent( BWPersonality.getNextIntroTimeline(), BigWorld.serverTime()) cinematicStartTime = self.__class__.PRE_INTRO_CINEMATIC_START_TIME - curTime if cinematicStartTime < self.__class__.PRE_INTRO_CINEMATIC_START_TIME: self.getStateObject().setCinematicTime( cinematicStartTime) self.__cinematicStarted = True elif not self.__preintroFinished: curTime = clamp(0.0, curTime, self.__class__.PRE_INTRO_ZOOM_START_TIME) self.stopPreIntro(curTime)
def _isValidTarget(self, target): return EntityStates.inState( target, EntityStates.GAME ) and self._ownerEntity.teamIndex != target.teamIndex and self._ownerLogic.targetInTurretSector( target) and not BigWorld.hm_collideSimple( self._ownerEntity.spaceID, self._ownerEntity.position, target.position) and target.id not in self._ignoreList
def __updateWakeTarget(self, target): if target.inWorld and EntityStates.inState(target, EntityStates.GAME): dirFromTarget = BigWorld.player().position - target.position distToTarget = dirFromTarget.length WAKE_HALF_ANGLE = db.DBLogic.g_instance.cameraEffects.wakeParams.angle * 0.5 if distToTarget <= db.DBLogic.g_instance.cameraEffects.wakeParams.distance and not EntityStates.inState( target, EntityStates.OBSERVER | EntityStates.DESTROYED): targetDir = target.getRotation().getAxisZ() angleToTarget = math.pi - abs(dirFromTarget.angle(targetDir)) if angleToTarget < WAKE_HALF_ANGLE: playerCamPresetID = BigWorld.player( ).settings.airplane.visualSettings.camera targetCamPresetID = target.settings.airplane.visualSettings.camera camPresetInfo = db.DBLogic.g_instance.cameraEffects.camPresetInfo if targetCamPresetID in camPresetInfo and playerCamPresetID in camPresetInfo: targetFactor = camPresetInfo[ targetCamPresetID].amplitudeFactor playerFactor = camPresetInfo[ playerCamPresetID].amplitudeFactor force = playerFactor / targetFactor * ( 1.0 - distToTarget / db.DBLogic.g_instance. cameraEffects.wakeParams.distance) self.__wakePlaneForces[target.id] = force return if target.id in self.__wakePlaneForces: self.__wakePlaneForces.pop(target.id)
def __changeInputState(self): if EntityStates.inState( BigWorld.player(), EntityStates.OBSERVER | EntityStates.END_GAME | EntityStates.DEAD | EntityStates.OUTRO): return self.setState( self.__inputToCamState[self.__inputState][self.__inputBattleMode])
def __findPartCollisionHealth(self, start, end): partsCollider = BigWorld.hm_collideParts(self._owner.spaceID, start, end, self._owner) if partsCollider: for entity, partId, position in partsCollider: if hasattr(entity, 'health') and EntityStates.inState( entity, EntityStates.GAME): return (entity, partId, position)
def update(self): if self.getState( ) is not None and self.curZoomData is not None and EntityStates.inState( BigWorld.player(), EntityStates.GAME): self.__updateZoomDataPosition() self.getStateObject().onZoomIndexChanged(self.__curZoomState, self.curZoomData) return
def isActive(self): if self._lockTargetId > 0: target = BigWorld.entities.get(self._lockTargetId) if target is not None and isTeamObject( target) and EntityStates.inState(target, EntityStates.GAME): return self._lockTargetDamage > _HotChickSkillTargetHPCfc * target.maxHealth self._lockTargetId = -1 return False
def setEffectsEnabled(self, isEnabled): if self.__cam: self.__cam.effectController.setEnabled( isEnabled or EntityStates.inState(BigWorld.player(), EntityStates.OBSERVER)) else: LOG_ERROR( "Cannot change camera effects state, bacause AircraftCamera isn't created yet." )
def isActive(self): if self._lockTargetId > 0: target = BigWorld.entities.get(self._lockTargetId) if target is not None and isAvatar( target) and EntityStates.inState(target, EntityStates.GAME): return self._isFrontAttack(target) self._lockTargetId = -1 return False
def onFlyKeyBoardInputAllowed(self, flag, playerAvatar): if not flag and EntityStates.inState(playerAvatar, EntityStates.GAME): if self.getState() not in [ CameraState.DebugCamera, CameraState.Spectator, CameraState.DestroyedFall, CameraState.SuperFree, CameraState.ReplayFree, CameraState.Gunner, CameraState.Bomber ]: self.reset()
def handleSpeed(self, speedMPS, ignoreNonForsageStates=True): cam = GameEnvironment.getCamera() cameraState = cam.getState() isValidCameraState = cameraState in self.__class__.__FORSAGE_STATES if ignoreNonForsageStates else True if EntityStates.inState( BigWorld.player(), EntityStates.GAME | EntityStates.PRE_START_INTRO ) and speedMPS > 0 and isValidCameraState: speedNorm = clamp(0.0, speedMPS / self.__maxSpeed, 1.0) self.__speedStateMachine.setTargetSpeed(speedNorm)
def __setStrategy(self, soundModeID): if self.__strategy: self.__strategy.finish() if soundModeID is None: self.__strategy = None else: avatar = BigWorld.entities.get(self._avatarID) if avatar and not EntityStates.inState(avatar, EntityStates.DESTROYED): self.__strategy = self._createSoundStrategy(soundModeID) return
def _updateBelts(self): if EntityStates.inState(self._playerAvatar, EntityStates.WAIT_START): self._model.ammoBelts.clean() self._addBaseBelts() else: ammoGroups = self._playerAvatar.getBeltsAmmoCountByGroup() for groupID in ammoGroups: beltStructure = self._model.ammoBelts.first( lambda e: e.id.get() == groupID) if beltStructure: status = ammoGroups[groupID] if status != beltStructure.status.get(): beltStructure.status = status
def _getCurrTargetID(self): if self._targetID <= 0 and self._active: targetEntity = BigWorld.entities.get(self._lastTargetID, None) if targetEntity is not None and EntityStates.inState( targetEntity, EntityStates.GAME ) and self._context.basePosition.distTo( targetEntity.position ) < self._context.targetLockShootDistance and self.__playerDirection.angle( targetEntity.position - self._context.basePosition ) < self._context.turretLoseBorderZone: return self._lastTargetID self._lastTargetID = self._targetID return self._lastTargetID
def pushMessage(self, data): if EntityStates.inState(self._avatarPlayer, EntityStates.OUTRO): return LOG_DEBUG(' BattleAlertsSource: pushMessage ', vars(data)) self._alertCounter += 1 battleAlertData = dict(type=data.type, title=data.title, icon=data.icon, lifetime=data.lifeTime, priority=data.priority, alertCounter=self._alertCounter, data=data.data) battleAlertData = self._checkOnAddValue( data, self._checkOnTimer(data, battleAlertData)) self._model.battleAlert = battleAlertData
def _onPlayerStateChanged(self, oldState, state): LOG_DEBUG(' STATES TEST : currentState : ', EntityStates.getStateName(state)) if state & (EntityStates.DESTROYED | EntityStates.DESTROYED_FALL): if oldState & EntityStates.GAME_CONTROLLED: LOG_DEBUG(' STATES TEST : ', 'DEAD') self._stateMachine.signal(ON_DEATH) self.___endDeathStateCallback = BigWorld.callback( 10, self._endDeathState) if state & EntityStates.GAME: LOG_DEBUG('STATES TEST : ', 'START GAME AFTER RESPAWN') if not self._awaitLoadPlaneResources: self._stateMachine.signal(ON_END_RESPAWN) if state & EntityStates.OUTRO: LOG_DEBUG(' STATES TEST : ', ' OUTRO ') self._stateMachine.signal(ON_OUTRO)
def update(self, dt): md = self._cursor() baseDirection = self._owner.getShootingControllerRotation().getAxisZ() wData = self.weaponSettings validData = md is not None and self._currCursor is not None and baseDirection.angle( md) < wData.cursorAngleMax if not EntityStates.inState(self._owner, EntityStates.GAME): self._currCursor = baseDirection elif self._maxSpeed >= 0 and validData: angle = self._currCursor.angle(md) axis = self._currCursor.cross(md) _Q.fromAngleAxis(min(angle, self._maxSpeed * dt), axis) self._currCursor = _Q.rotateVec(self._currCursor) else: self._currCursor = md return
def update(self, dt): if EntityStates.inState(self._owner, EntityStates.GAME): self._wrdh.update(dt) if not self.__prevControllerPosition: self.__prevControllerPosition = Math.Vector3( self._owner.getShootingControllerPosition()) self.__prevControllerRotation = Math.Quaternion( self._owner.getShootingControllerRotation()) groups1 = reduce( ior, map(lambda group: group.singleShotBit, filter(lambda group: group.isReady(), self.__guns.groups)), 0) armaments = self.__guns.cellUpdate( dt, self.oneTickFireFlag | self.fireFlags) groups2 = reduce( ior, map(lambda group: group.singleShotBit, filter(lambda group: group.isReady(), self.__guns.groups)), 0) groups = ~groups1 & groups2 if groups: self._owner.onSingleShotReady(groups) if COLLISION_RECORDER: self._owner.markPosition(0, self.__prevControllerPosition, self._owner.syncedRandom.getInfo()) if self._owner.armamentStates and self._owner.armamentStates != armaments: self._owner.shootingSync = self._owner.syncedRandom.refresh() self.syncGunsRandom() if armaments != 0: self._owner.onDisclosure() self.__storedArmament |= armaments readyGroups = self.__guns.shoot(armaments) if readyGroups: self.__shootCell(dt, readyGroups) self.oneTickFireFlag = 0 if armaments != self._owner.armamentStates: if self._owner.armamentStates: self._owner.syncGunsWithClient(self.__guns.getSyncData()) self._owner.armamentStates = armaments self.__prevControllerPosition = Math.Vector3( self._owner.getShootingControllerPosition()) if COLLISION_RECORDER: self._owner.markPosition(1, self.__prevControllerPosition, self._owner.syncedRandom.getInfo()) self.__prevControllerRotation = Math.Quaternion( self._owner.getShootingControllerRotation())
def __sendCursor(self): import BattleReplay if BattleReplay.isPlaying(): return if EntityStates.inState(BigWorld.player(), EntityStates.GAME): self.__updateCurrentRadius() direction = self.__cameraStrategy.cursorDirection if not self.__isExtraMode else self.__lastDirection self.__profile.setCamDirection(direction) dataDir, up = self.__prepareMousePackage(direction) self.__lastDirection = direction if dataDir != self.__lastDataDir: self._lastDataDir = dataDir timeSend = GameEnvironment.getInput().inputAxis.serverTime BigWorld.player().cell.sendMouseDirData(timeSend, dataDir) if up != self.__lastUp: self.__lastUp = up BigWorld.player().cell.sendMouseUp(up)
def __idleAnimate(self): if self.__callback is not None: BigWorld.cancelCallback(self.__callback) if not IS_EDITOR and isAvatar( BigWorld.player()) and EntityStates.inState( BigWorld.player(), EntityStates.GAME): if self.__passiveTime > 0: self.__passiveTime -= PilotHeadController.CALLBACK_TIME else: rudderY = choice([-1, 0, 1]) self.matrixProvider.yaw = self.maxAngle * rudderY rudderP = choice([0, -1]) * (1 if not self.reversed else -1) self.matrixProvider.pitch = self.maxAngle * rudderP self.__passiveTime = PilotHeadController.PASSIVE_TIME self.__callback = BigWorld.callback(PilotHeadController.CALLBACK_TIME, self.__idleAnimate) return
def processMouseEvent(self, event): if EntityStates.inState(BigWorld.player(), EntityStates.WAIT_START | EntityStates.CREATED): return if getattr(self.getStateObject(), 'isInOverview', False): self.__cameraStateMachine.updateStateAttr(self.getState(), 'onOverlookScroll', event.dz) elif not self.__cameraStateMachine.updateStateAttr( self.getState(), 'onMouseScroll', event.dz): stateInstance = self.getStateObject() if stateInstance and stateInstance.zoomPresent( ) and self.__isZoomEnable: if event.dz > 0 and self.__curZoomState != ZoomStates.Sniper: self.__setZoom(ZoomStates.Sniper) elif event.dz < 0 and self.__curZoomState != ZoomStates.Normal: self.__setZoom(ZoomStates.Normal) else: camStateStrategy = self.getStateStrategy() if hasattr(camStateStrategy, 'distance'): dist = self.getStateStrategy().distance self.eDistanceChanged(dist)
def update(self): isPlayerInGame = EntityStates.inState( BigWorld.player(), EntityStates.GAME | EntityStates.PRE_START_INTRO | EntityStates.WAIT_START) if self.__curState: self.__curState.setActive(isPlayerInGame) if self.__targetSpeed is None: return else: if self.__ticker is None: self.__curSpeed = self.__targetSpeed self.__ticker = time() dt = 0 else: currTime = time() dt = currTime - self.__ticker self.__ticker = currTime self.__curSpeed += (self.__targetSpeed - self.__curSpeed) * dt * 0.5 if self.__curState: self.__curState.update(self.__curSpeed) return
def _positionUpdate(self): t = self._getCurrentTime() if t >= 0.0: curState = self.getState() if curState == UPDATABLE_STATE.CREATE: newMovement = self.__getDistForTime(t) self.__tickMovement = newMovement - self.__totalMovement self.__totalMovement = newMovement self.position = self._startPosition + self.__direction * self.__totalMovement if not IS_CLIENT: r = self.__shellDescription.lockRange * self._owner.controllers[ 'externalModifiers'].modifiers.ACTIVATE_ROCKET_DETONATOR if next((e for e in self._owner.entitiesInRange( r, 'Avatar', self.position) + self._owner. entitiesInRange(r, 'AvatarBot', self.position) if EntityStates.inState(e, EntityStates.GAME) and self._owner.teamIndex != e.teamIndex), None): self.__doExplosion() return if self.__findPartCollisionHealth( self.position - self.__direction * self.__tickMovement * 0.5, self.position + self.__direction * self.__tickMovement * 0.5): self.__doExplosion() return if self.__totalMovement >= self.__maxFlightDist: normal = Math.Vector3(self._startVector) normal.normalise() self.position = self.__maxFlightDist * normal + self._startPosition self.__doExplosion() return if IS_CLIENT: self.__updatableSound.updatePosition(self.position) if IS_CLIENT: if self.model: self.matrix.translation = self.position return