public void RotateWeapon(WeaponRotationUpdateGyroscopeEvent e, WeaponGyroscopeNode weapon, [JoinByTank] TankNode tank, [JoinByTank] Optional <SingleNode <VulcanWeaponComponent> > vulkanWeapon, [JoinAll] SelfBattleUser selfBattleUser) { WeaponRotationControlComponent weaponRotationControl = weapon.weaponRotationControl; float gyroscopePower = weapon.weaponGyroscopeRotation.GyroscopePower; weaponRotationControl.ForceGyroscopeEnabled = vulkanWeapon.IsPresent() && (gyroscopePower > float.Epsilon); bool mouseControlEnable = selfBattleUser.mouseControlStateHolder.MouseControlEnable; WeaponGyroscopeRotationComponent weaponGyroscopeRotation = weapon.weaponGyroscopeRotation; weaponGyroscopeRotation.WeaponTurnCoeff = 1f; weaponGyroscopeRotation.DeltaAngleOfHullRotation = 0f; Vector3 forwardDir = weaponGyroscopeRotation.ForwardDir; Vector3 upDir = weaponGyroscopeRotation.UpDir; this.UpdateGyroscopeData(weapon, tank); Vector3 nextForward = weaponGyroscopeRotation.ForwardDir; Vector3 nextUp = weaponGyroscopeRotation.UpDir; if (weaponRotationControl.ForceGyroscopeEnabled || mouseControlEnable) { weaponGyroscopeRotation.DeltaAngleOfHullRotation = this.CalculateDeltaAngleOfHullRotationAroundUpAxis(forwardDir, nextForward, upDir, nextUp); float max = tank.speed.TurnSpeed * e.DeltaTime; weaponGyroscopeRotation.DeltaAngleOfHullRotation = Mathf.Clamp(weaponGyroscopeRotation.DeltaAngleOfHullRotation, -max, max); if (weaponRotationControl.ForceGyroscopeEnabled) { if (mouseControlEnable) { weaponRotationControl.MouseRotationCumulativeHorizontalAngle -= weaponGyroscopeRotation.DeltaAngleOfHullRotation * (1f - gyroscopePower); } float weaponTurnDecelerationCoeff = vulkanWeapon.Get().component.WeaponTurnDecelerationCoeff; weaponGyroscopeRotation.WeaponTurnCoeff = weaponTurnDecelerationCoeff + ((1f - gyroscopePower) * (1f - weaponTurnDecelerationCoeff)); weaponGyroscopeRotation.DeltaAngleOfHullRotation *= gyroscopePower; } } }
private void ApplyWeaponControl(WeaponRotationControlComponent weaponRotationComponent, float?weaponControl) { if (weaponControl != null) { base.Log.Debug("APPLY WEAPON_CONTROL"); weaponRotationComponent.Control = weaponControl.Value; } }
public void OnTankInactive(NodeRemoveEvent e, SelfTankNode selfTank, [JoinByTank] WeaponNode weapon) { WeaponRotationControlComponent weaponRotationControl = weapon.weaponRotationControl; if (weaponRotationControl.EffectiveControl != 0f) { weaponRotationControl.PrevEffectiveControl = 0f; weaponRotationControl.EffectiveControl = 0f; base.ScheduleEvent <WeaponRotationControlChangedEvent>(weapon); } }
private bool CheckManualTargetingActivity(WeaponRotationControlComponent rotation, VerticalSectorsTargetingComponent verticalSectors, ShaftAimingWorkingStateComponent working, bool isInputActive) { if (rotation.IsRotating()) { return(true); } if (!isInputActive) { return(false); } float verticalAngle = working.VerticalAngle; return((verticalAngle != verticalSectors.VAngleUp) ? (verticalAngle != -verticalSectors.VAngleDown) : false); }
private void ApplyMissBehaviour(AutopilotTankNode tank, WeaponNode weapon) { Vector3 vector2 = weapon.weaponInstance.WeaponInstance.transform.InverseTransformPoint(tank.autopilotWeaponController.TargetRigidbody.position); WeaponRotationControlComponent weaponRotationControl = weapon.weaponRotationControl; weaponRotationControl.Centering = false; if (Math.Abs(vector2.x) > 3f) { tank.autopilotWeaponController.Fire = true; weaponRotationControl.Control = 0f; } else { tank.autopilotWeaponController.Fire = false; weaponRotationControl.Control = -this.ToDiscrete(vector2.x, 0f); } }
public void OnWeaponUpdateEvent(UpdateEvent e, WeaponNode weapon, [JoinByTank] SelfTankNode tank, [JoinByUser] SingleNode <MouseControlStateHolderComponent> mouseControlStateHolder, [JoinAll] Optional <SingleNode <BattleShaftAimingStateComponent> > shaftAimingState) { WeaponRotationControlComponent weaponRotationControl = weapon.weaponRotationControl; float mouseSpeed = ((Camera.main.fieldOfView * mouseControlStateHolder.component.MouseSensivity) * 1f) / ((float)Screen.height); if (shaftAimingState.IsPresent()) { if (!mouseControlStateHolder.component.MouseControlEnable) { weaponRotationControl.MouseRotationCumulativeHorizontalAngle = 0f; int num4 = !InputManager.CheckAction(ShaftAimingActions.AIMING_UP) ? 0 : 1; weaponRotationControl.ShaftElevationDirectionByKeyboard = num4 - (!InputManager.CheckAction(ShaftAimingActions.AIMING_DOWN) ? 0 : 1); weaponRotationControl.Control = Mathf.Clamp((float)(InputManager.GetAxis(WeaponActions.WEAPON_RIGHT, false) - InputManager.GetAxis(WeaponActions.WEAPON_LEFT, false)), (float)-1f, (float)1f); weaponRotationControl.CenteringControl = InputManager.CheckAction(WeaponActions.WEAPON_CENTER); } else { float axis = InputManager.GetAxis(CameraRotationActions.MOUSEY_MOVE_SHAFT_AIM, false); if (mouseControlStateHolder.component.MouseVerticalInverted) { axis *= -1f; } weaponRotationControl.MouseShaftAimCumulativeVerticalAngle += (axis * mouseSpeed) / e.DeltaTime; float num3 = this.GetMouseXDelta(weapon.weaponInstance.WeaponInstance, mouseSpeed, e.DeltaTime); weaponRotationControl.MouseRotationCumulativeHorizontalAngle = MathUtil.ClampAngle180(weaponRotationControl.MouseRotationCumulativeHorizontalAngle + num3); weaponRotationControl.Centering = false; weaponRotationControl.CenteringControl = false; weaponRotationControl.BlockRotate = InputManager.CheckAction(WeaponActions.WEAPON_LOCK_ROTATION); } } else { weaponRotationControl.Control = Mathf.Clamp((float)(InputManager.GetAxis(WeaponActions.WEAPON_RIGHT, false) - InputManager.GetAxis(WeaponActions.WEAPON_LEFT, false)), (float)-1f, (float)1f); weaponRotationControl.CenteringControl = InputManager.CheckAction(WeaponActions.WEAPON_CENTER); if ((weaponRotationControl.Control != 0f) || weaponRotationControl.CenteringControl) { mouseControlStateHolder.component.MouseControlEnable = false; weaponRotationControl.MouseRotationCumulativeHorizontalAngle = 0f; } else { float num10 = (InputManager.GetAxis(CameraRotationActions.MOUSEY_ROTATE, false) * mouseSpeed) / e.DeltaTime; float num11 = this.GetMouseXDelta(weapon.weaponInstance.WeaponInstance, mouseSpeed, e.DeltaTime); if ((num11 != 0f) || (num10 != 0f)) { mouseControlStateHolder.component.MouseControlEnable = true; } if (mouseControlStateHolder.component.MouseVerticalInverted) { num10 *= -1f; } weaponRotationControl.MouseRotationCumulativeHorizontalAngle = MathUtil.ClampAngle180(weaponRotationControl.MouseRotationCumulativeHorizontalAngle + num11); weaponRotationControl.MouseRotationCumulativeVerticalAngle += num10; weaponRotationControl.BlockRotate = InputManager.CheckAction(WeaponActions.WEAPON_LOCK_ROTATION); weaponRotationControl.CenteringControl = InputManager.CheckAction(WeaponActions.WEAPON_CENTER_BY_MOUSE); } } weaponRotationControl.Centering |= weaponRotationControl.CenteringControl; if (weaponRotationControl.Centering && ((weaponRotationControl.Control != 0f) || (weaponRotationControl.Rotation == 0f))) { weaponRotationControl.Centering = false; } }
private void UpdateWeaponRotation(WeaponNode weapon, SingleNode <MouseControlStateHolderComponent> mouseControlStateHolder, float dt, bool rem = false) { WeaponRotationControlComponent weaponRotationControl = weapon.weaponRotationControl; weaponRotationControl.EffectiveControl = !weaponRotationControl.Centering ? weaponRotationControl.Control : ((weaponRotationControl.Rotation >= 180f) ? ((float)1) : ((float)(-1))); WeaponGyroscopeRotationComponent weaponGyroscopeRotation = weapon.weaponGyroscopeRotation; bool flag = (mouseControlStateHolder != null) && mouseControlStateHolder.component.MouseControlEnable; if (flag && (weaponRotationControl.BlockRotate && !weaponRotationControl.ForceGyroscopeEnabled)) { weaponRotationControl.MouseRotationCumulativeHorizontalAngle -= weaponGyroscopeRotation.DeltaAngleOfHullRotation; weaponRotationControl.MouseRotationCumulativeHorizontalAngle = MathUtil.ClampAngle(weaponRotationControl.MouseRotationCumulativeHorizontalAngle * 0.01745329f) * 57.29578f; weaponGyroscopeRotation.DeltaAngleOfHullRotation = 0f; } float num2 = (weapon.weaponRotation.Acceleration * weaponGyroscopeRotation.WeaponTurnCoeff) * dt; float max = weapon.weaponRotation.Speed * weaponGyroscopeRotation.WeaponTurnCoeff; float num4 = 0f; float f = 0f; bool flag2 = false; while (true) { float mouseRotationCumulativeHorizontalAngle = weaponRotationControl.MouseRotationCumulativeHorizontalAngle; float effectiveControl = weaponRotationControl.EffectiveControl; weaponRotationControl.Speed += num2; weaponRotationControl.Speed = Mathf.Clamp(weaponRotationControl.Speed, 0f, max); num4 = weaponRotationControl.Speed * dt; if (!flag) { f = effectiveControl * num4; if (weaponRotationControl.ForceGyroscopeEnabled) { f -= weaponGyroscopeRotation.DeltaAngleOfHullRotation; } } else { if (weaponRotationControl.ForceGyroscopeEnabled) { if (!weaponRotationControl.BlockRotate) { if (weaponRotationControl.Centering) { f = Mathf.Clamp(-MathUtil.ClampAngle180(weaponRotationControl.Rotation + weaponGyroscopeRotation.DeltaAngleOfHullRotation), -num4, num4); effectiveControl = (Mathf.Abs(num4) > 0.001f) ? (f / num4) : 0f; } else { f = Mathf.Clamp(mouseRotationCumulativeHorizontalAngle, -num4, num4); effectiveControl = (Mathf.Abs(num4) > 0.001f) ? (f / num4) : 0f; } mouseRotationCumulativeHorizontalAngle -= f; } f -= weaponGyroscopeRotation.DeltaAngleOfHullRotation; } else if (!weaponRotationControl.BlockRotate) { if (!weaponRotationControl.Centering) { f = Mathf.Clamp(mouseRotationCumulativeHorizontalAngle - weaponGyroscopeRotation.DeltaAngleOfHullRotation, -num4, num4); effectiveControl = (Mathf.Abs(num4) > 0.001f) ? (f / num4) : 0f; } else { f = effectiveControl * num4; float num9 = MathUtil.ClampAngle180(weaponRotationControl.Rotation); if (Mathf.Abs(num9) < Mathf.Abs(f)) { f = -num9; effectiveControl = (Mathf.Abs(num4) > 0.001f) ? (f / num4) : 0f; } } mouseRotationCumulativeHorizontalAngle = (mouseRotationCumulativeHorizontalAngle - f) - weaponGyroscopeRotation.DeltaAngleOfHullRotation; } if (weaponRotationControl.BlockRotate) { effectiveControl = 0f; } } if (flag2) { flag2 = false; } else if (Math.Sign(weaponRotationControl.PrevDeltaRotaion) != Math.Sign(f)) { weaponRotationControl.Speed = 0f; flag2 = true; } if (!flag2) { float num11; weaponRotationControl.MouseRotationCumulativeHorizontalAngle = mouseRotationCumulativeHorizontalAngle; weaponRotationControl.EffectiveControl = effectiveControl; weaponRotationControl.PrevDeltaRotaion = f; float rotation = weaponRotationControl.Rotation; if (!weaponRotationControl.Centering || ((rotation >= -f) && ((360f - rotation) >= f))) { num11 = this.ClampAngle(rotation + f); } else { weaponRotationControl.Centering = false; num11 = 0f; } weapon.weaponInstance.WeaponInstance.transform.SetLocalRotationSafe(Quaternion.AngleAxis(num11, Vector3.up)); weapon.weaponInstance.WeaponInstance.transform.localPosition = Vector3.zero; weaponRotationControl.Rotation = num11; weaponRotationControl.EffectiveControl = Mathf.Round(weaponRotationControl.EffectiveControl); if (!Mathf.Approximately(weaponRotationControl.PrevEffectiveControl, weaponRotationControl.EffectiveControl) && ((PreciseTime.Time - weaponRotationControl.PrevControlChangedTime) > 0.1)) { weaponRotationControl.PrevControlChangedTime = PreciseTime.Time; weaponRotationControl.PrevEffectiveControl = weaponRotationControl.EffectiveControl; base.ScheduleEvent <WeaponRotationControlChangedEvent>(weapon); } return; } } }