private float GetOceanLevel() { #if SUBNAUTICA return(Ocean.main.GetOceanLevel()); #elif BELOWZERO return(Ocean.GetOceanLevel()); #endif }
public static bool Prefix(SeaTruckMotor __instance, bool ____piloting) { /* * foreach (KeyCode kcode in Enum.GetValues(typeof(KeyCode))) * { * if (Input.GetKeyDown(kcode)) * Logger.Log("KeyCode down: " + kcode); * } */ bool isThisOurTruck = Vector3.Distance(Player.main.transform.position, __instance.transform.position) < 2; bool isAutoMoveClicked = (Input.GetKey(KeyCode.X) || Input.GetKey(KeyCode.JoystickButton8)); if (!isThisOurTruck) { return(true); } if (FreeReadPatcher.isInPDA && isAutoMoveClicked) { Logger.Log("Toggling cruise"); FreeReadPatcher.isCruising = !FreeReadPatcher.isCruising; } if (FreeReadPatcher.isCruising) { Logger.Log("...cruising..."); // if keyboard, allow translation ( f and b cancel auto-move ) // if controller, allow rotation //===================================== // the rest of this is base game code //===================================== bool myIsPowered = !__instance.requiresPower || (__instance.relay && __instance.relay.IsPowered()); bool myIsBusyAnimating = __instance.waitForAnimation && __instance.seatruckanimation != null && __instance.seatruckanimation.currentAnimation > SeaTruckAnimation.Animation.Idle; if (Player.main.transform.position.y < Ocean.GetOceanLevel() && __instance.useRigidbody != null && myIsPowered && !myIsBusyAnimating) { // "vector" as described by GameInput.UpdateMoveDirection Vector3 vector = new Vector3(0, 0, 1); Vector3 a = MainCameraControl.main.rotation * vector; float myGetWeight = __instance.truckSegment.GetWeight() + __instance.truckSegment.GetAttachedWeight() * (__instance.horsePowerUpgrade ? 0.65f : 0.8f); float num = 1f / Mathf.Max(1f, myGetWeight * 0.35f) * __instance.acceleration; __instance.useRigidbody.AddForce(num * a, ForceMode.Acceleration); if (__instance.relay) { float num2; __instance.relay.ConsumeEnergy(Time.deltaTime * __instance.powerEfficiencyFactor * 0.12f, out num2); } return(false); } } return(true); }
public static void MCC_Update_Postfix(MainCameraControl __instance) { Transform forwardReference = __instance.GetComponentInParent <PlayerController>().forwardReference; if (MainPatcher.pdaIsClosing && MainPatcher.pdaCloseTimer < MainPatcher.pdaCloseDelay) { MainPatcher.pdaCloseTimer += Time.deltaTime; } else if (MainPatcher.pdaCloseTimer >= MainPatcher.pdaCloseDelay || (MainPatcher.pdaIsClosing && Player.main.GetPDA().state == PDA.State.Opened)) { MainPatcher.pdaIsClosing = false; MainPatcher.pdaCloseTimer = 0f; } if (Player.main.GetPDA().state == PDA.State.Closing) { MainPatcher.pdaIsClosing = true; } if (Player.main.GetPDA().state == PDA.State.Closed && !MainPatcher.pdaIsClosing) { if (Player.main.motorMode == Player.MotorMode.Seaglide) { __instance.viewModel.transform.localPosition = __instance.viewModel.transform.parent.worldToLocalMatrix.MultiplyPoint(forwardReference.position + forwardReference.up * MainPatcher.seaglideYOffset + forwardReference.forward * MainPatcher.seaglideZOffset); return; } #if SN1 if (Player.main.transform.position.y < Ocean.main.GetOceanLevel() + 1f && !Player.main.IsInside() && !Player.main.precursorOutOfWater) #elif BZ if (Player.main.transform.position.y < Ocean.GetOceanLevel() + 1f && !Player.main.IsInside() && !Player.main.forceWalkMotorMode) #endif { string name = Player.main.playerAnimator.GetCurrentAnimatorClipInfo(0)[0].clip.name; if (name == "Back_lean" || name == "view_surface_swim_forward") { __instance.viewModel.transform.localPosition = __instance.viewModel.transform.parent.worldToLocalMatrix.MultiplyPoint(forwardReference.position + __instance.viewModel.transform.up * (MainPatcher.swimYOffset - 0.1f) + __instance.viewModel.transform.forward * (MainPatcher.swimZOffset - 0.1f)); return; } __instance.viewModel.transform.localPosition = __instance.viewModel.transform.parent.worldToLocalMatrix.MultiplyPoint(forwardReference.position + __instance.viewModel.transform.up * MainPatcher.swimYOffset + __instance.viewModel.transform.forward * MainPatcher.swimZOffset); return; } else if (!__instance.cinematicMode && Player.main.motorMode != Player.MotorMode.Vehicle && Player.main.motorMode != Player.MotorMode.Seaglide) { if (Player.main.movementSpeed == 0f) { __instance.viewModel.transform.localPosition = __instance.viewModel.transform.parent.worldToLocalMatrix.MultiplyPoint(forwardReference.position + Vector3.up * MainPatcher.defaultYOffset + new Vector3(forwardReference.forward.x, 0f, forwardReference.forward.z).normalized *MainPatcher.defaultZOffset); return; } __instance.viewModel.transform.localPosition = __instance.viewModel.transform.parent.worldToLocalMatrix.MultiplyPoint(forwardReference.position + Vector3.up * MainPatcher.defaultYOffset + new Vector3(forwardReference.forward.x, 0f, forwardReference.forward.z).normalized *(MainPatcher.defaultZOffset - 0.1f)); } } }
/// <summary> /// Gets the prefab game object /// </summary> public sealed override GameObject GetGameObject() { V2.Logger.Debug($"[FishFramework] Initializing fish: {this.ClassID}"); GameObject mainObj = modelPrefab; Renderer[] renderers = mainObj.GetComponentsInChildren <Renderer>(); foreach (Renderer rend in renderers) { rend.material.shader = Shader.Find("MarmosetUBER"); } Rigidbody rb = mainObj.EnsureComponent <Rigidbody>(); rb.useGravity = false; rb.angularDrag = 1f; WorldForces forces = mainObj.EnsureComponent <WorldForces>(); forces.useRigidbody = rb; forces.aboveWaterDrag = 0f; forces.aboveWaterGravity = 9.81f; forces.handleDrag = true; forces.handleGravity = true; forces.underwaterDrag = 1f; forces.underwaterGravity = 0; #if BELOWZERO || SUBNAUTICA_EXP forces.waterDepth = Ocean.GetOceanLevel(); #else forces.waterDepth = Ocean.main.GetOceanLevel(); #endif forces.enabled = false; forces.enabled = true; mainObj.EnsureComponent <EntityTag>().slotType = EntitySlot.Type.Creature; mainObj.EnsureComponent <PrefabIdentifier>().ClassId = this.ClassID; mainObj.EnsureComponent <TechTag>().type = this.TechType; mainObj.EnsureComponent <SkyApplier>().renderers = renderers; mainObj.EnsureComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.Near; mainObj.EnsureComponent <LiveMixin>().health = 10f; Creature creature = mainObj.EnsureComponent <Creature>(); creature.initialCuriosity = AnimationCurve.Linear(0f, 0.5f, 1f, 0.5f); creature.initialFriendliness = AnimationCurve.Linear(0f, 0.5f, 1f, 0.5f); creature.initialHunger = AnimationCurve.Linear(0f, 0.5f, 1f, 0.5f); SwimBehaviour behaviour = null; if (isWaterCreature) { behaviour = mainObj.EnsureComponent <SwimBehaviour>(); SwimRandom swim = mainObj.EnsureComponent <SwimRandom>(); swim.swimVelocity = swimSpeed; swim.swimRadius = swimRadius; swim.swimInterval = swimInterval; } else { behaviour = mainObj.EnsureComponent <WalkBehaviour>(); WalkOnGround walk = mainObj.EnsureComponent <WalkOnGround>(); OnSurfaceMovement move = mainObj.EnsureComponent <OnSurfaceMovement>(); move.onSurfaceTracker = mainObj.EnsureComponent <OnSurfaceTracker>(); } Locomotion loco = mainObj.EnsureComponent <Locomotion>(); loco.useRigidbody = rb; mainObj.EnsureComponent <EcoTarget>().type = EcoTargetType.Peeper; mainObj.EnsureComponent <CreatureUtils>(); mainObj.EnsureComponent <VFXSchoolFishRepulsor>(); SplineFollowing spline = mainObj.EnsureComponent <SplineFollowing>(); spline.locomotion = loco; spline.levelOfDetail = mainObj.EnsureComponent <BehaviourLOD>(); spline.GoTo(mainObj.transform.position + mainObj.transform.forward, mainObj.transform.forward, 5f); behaviour.splineFollowing = spline; if (pickupable) { mainObj.EnsureComponent <Pickupable>(); } creature.ScanCreatureActions(); return(mainObj); }