Exemplo n.º 1
0
        public IntVector Teleport(string targetName, IntVector targetPos)
        {
            IntVector currentWorldPos = Player.main.transform.position;

            if (IsPlayerInVehicle())
            {
                Player.main.GetVehicle().TeleportVehicle(targetPos.ToVector3(), Quaternion.identity);
                Player.main.CompleteTeleportation();
                ErrorMessage.AddMessage($"Vehicle and Player Warped to:\n{targetName}\n({targetPos.ToString()})");
            }
            else if (Player.main.GetComponentInParent <SeaTruckMotor>() != null)
            {
                SeaTruckMotor motor        = Player.main.GetComponentInParent <SeaTruckMotor>();
                Rigidbody     useRigidbody = motor.useRigidbody;

                useRigidbody.isKinematic = true;
                motor.transform.position = targetPos;
                motor.transform.rotation = Quaternion.identity;
                motor.transform.Translate(new Vector3(0f, 2f, 4f), Space.Self);
                useRigidbody.isKinematic = false;
                ErrorMessage.AddMessage($"Seatruck and Player Warped to:\n{targetName}\n({targetPos.ToString()})");
            }
            else
            {
                Player.main.SetPosition(targetPos.ToVector3());
                Player.main.OnPlayerPositionCheat();
                ErrorMessage.AddMessage($"Player Warped to:\n{targetName}\n({targetPos.ToString()})");
            }

            return(currentWorldPos);
        }
Exemplo n.º 2
0
        public string Teleport(string targetName, string vector3string)
        {
            Vector3 currentWorldPos = Player.main.transform.position;

            string prevCwPos = string.Format("{0:D} {1:D} {2:D}", (int)currentWorldPos.x, (int)currentWorldPos.y, (int)currentWorldPos.z);

            if (IsPlayerInVehicle())
            {
                Player.main.GetVehicle().TeleportVehicle(ConvertStringPosToVector3(vector3string), Quaternion.identity);
                Player.main.CompleteTeleportation();
                ErrorMessage.AddMessage($"Vehicle and Player Warped to:\n{targetName}\n({vector3string})");
            }
            else if (Player.main.GetComponentInParent <SeaTruckMotor>() != null)
            {
                SeaTruckMotor motor        = Player.main.GetComponentInParent <SeaTruckMotor>();
                Rigidbody     useRigidbody = motor.useRigidbody;

                useRigidbody.isKinematic = true;
                motor.transform.position = ConvertStringPosToVector3(vector3string);
                motor.transform.rotation = Quaternion.identity;
                motor.transform.Translate(new Vector3(0f, 2f, 4f), Space.Self);
                useRigidbody.isKinematic = false;
                ErrorMessage.AddMessage($"Seatruck and Player Warped to:\n{targetName}\n({vector3string})");
            }
            else
            {
                Player.main.SetPosition(ConvertStringPosToVector3(vector3string));
                Player.main.OnPlayerPositionCheat();
                ErrorMessage.AddMessage($"Player Warped to:\n{targetName}\n({vector3string})");
            }

            return(prevCwPos);
        }
 internal void Initialise(ref SeaTruckUpgrades seaTruckUpgrades)
 {
     parentVehicle           = seaTruckUpgrades;
     parentMotor             = seaTruckUpgrades.motor;
     parentVehicle.onToggle += OnToggle;
     parentVehicle.onSelect += OnSelect;
 }
        public void Awake()
        {
            //helper = new SeaTruckHelper(gameObject, false, false, false);
            helper = SeatruckServices.Main.GetSeaTruckHelper(gameObject);

            mainCab     = helper.MainCab;
            motor       = helper.TruckMotor;
            engineSound = motor.engineSound;
            rigidbody   = helper.TruckWorldForces.useRigidbody;

            CoroutineHost.StartCoroutine(LoadBiodomeRobotArmResourcesAsync());

            CoroutineHost.StartCoroutine(Init_Graphics());

            engineDefault      = ScriptableObject.CreateInstance <FMODAsset>();
            engineDefault.name = "engine";
            engineDefault.path = "event:/bz/vehicles/seatruck/engine";

            engine      = ScriptableObject.CreateInstance <FMODAsset>();
            engine.name = "engine";
            engine.path = "event:/sub/drone/motor_loop";

            isFlying.changedEvent.AddHandler(this, new Event <Utils.MonitoredValue <bool> > .HandleFunction(OnFlyModeChanged));

            mainCabExitPoint = helper.TruckSegment.exitPosition.localPosition;

            //helper.onPilotingBegin += OnPilotingBegin;

#if DEBUG
            CoroutineHost.StartCoroutine(InitDebugHUD());
#endif
        }
Exemplo n.º 5
0
        internal static void PostSeatruckStart(ref SeaTruckMotor __instance)
        {
            QuickLogger.Debug(nameof(PostSeatruckStart));
            VehicleUpgrader vehicleUpgrader = __instance.gameObject.EnsureComponent <VehicleUpgrader>();

            vehicleUpgrader.Initialize(ref __instance);
        }
 protected void OnDestroy()
 {
     parentVehicle.onToggle -= OnToggle;
     parentVehicle.onSelect -= OnSelect;
     parentMotor             = null;
     parentVehicle           = null;
 }
Exemplo n.º 7
0
        internal static void PostSeaTruckUpgradesModuleChange(ref SeaTruckUpgrades __instance, TechType techType)
        {
            QuickLogger.Debug($"{nameof(PostSeaTruckUpgradesModuleChange)} {techType.AsString()}", true);
            SeaTruckMotor cab = __instance.motor;

            //cab.gameObject.EnsureComponent<VehicleUpgrader>().UpgradeVehicle(techType, ref cab);
            CoroutineHost.StartCoroutine(DeferUpgrade(cab, techType));
        }
        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);
        }
 static void Postfix(SeaTruckMotor __instance)
 {
     if (MainPatch.pilotingSeaTruck)
     {
         if (__instance.useRigidbody != null)
         {
             MainPatch.speed = Mathf.FloorToInt(__instance.useRigidbody.velocity.magnitude);
             ErrorMessage.AddMessage($"Speed SeaTruck: {MainPatch.speed}");
         }
     }
 }
 public static bool Prefix(SeaTruckMotor __instance)
 {
     if (__instance.TryGetComponent(out FlyManager manager))
     {
         if (manager.altitude > 0)
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 11
0
        public static void PostStart(ref SeaTruckMotor __instance)
        {
            if (__instance.gameObject != null && __instance.gameObject.TryGetComponent <LiveMixin>(out LiveMixin mixin) && Main.defaultHealth.TryGetValue(TechType.SeaTruck, out float defaultHealth))
            {
                float instanceHealthPct = Mathf.Min(mixin.GetHealthFraction(), 1f);
                float maxHealth         = defaultHealth * Main.config.SeatruckVehicleHealthMult;

                mixin.data.maxHealth = maxHealth;
                mixin.health         = maxHealth * instanceHealthPct;
            }
        }
 public static bool Prefix(SeaTruckMotor __instance, ref bool __result)
 {
     if (__instance.TryGetComponent(out FlyManager manager))
     {
         if (manager.isEnabled)
         {
             __result = true;
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 13
0
        internal static void Postfix(ref SeaTruckMotor __instance)
        {
            SeaTruckConfig config = QPatch.Config;

            Console.WriteLine($"[UnSlowSeaTruck] Original steeringMultiplier: {__instance.steeringMultiplier}");
            Console.WriteLine($"[UnSlowSeaTruck] Original acceleration: {__instance.acceleration}");

            __instance.steeringMultiplier *= config.SteeringMultiplier;     // better steering
            __instance.acceleration       *= config.AccelerationMultiplier; // better acceleration

            Console.WriteLine($"[UnSlowSeaTruck] Modified steeringMultiplier: {__instance.steeringMultiplier} [Config:{config.SteeringMultiplier}] (More is faster)");
            Console.WriteLine($"[UnSlowSeaTruck] Modified acceleration: {__instance.acceleration} [Config:{config.AccelerationMultiplier}] (More is faster)");
        }
        internal virtual void PostUpgradeModuleChange(int slotID, TechType techType, bool added, SeaTruckUpgrades instance)
        {
            if (parentVehicle == null && instance != null)
            {
                parentVehicle = instance;
                parentMotor   = instance.motor;
            }

            if (parentVehicle == null)
            {
                return;
            }


            if (techType == sonarModuleTechType)
            {
                if (added)
                {
                    sonarSlotID = slotID;
                }
                else
                {
                    sonarSlotID = -1;
                }
            }
            else if (techType == repairModuleTechType)
            {
                if (added)
                {
                    repairSlotID = slotID;
                }
                else
                {
                    repairSlotID = -1;
                }

                VehicleRepairComponent repairComponent = gameObject.EnsureComponent <VehicleRepairComponent>();
                repairComponent.SetEnabled(added, parentMotor);
                repairComponent.SetActiveState(false);
            }
            base.CancelInvoke("UpdateRecharge");
            base.CancelInvoke("UpdateSonar");

            solarCount   = parentVehicle.modules.GetCount(solarModuleTechType);
            thermalCount = parentVehicle.modules.GetCount(thermalModuleTechType);
            if (solarCount + thermalCount > 0)
            {
                base.InvokeRepeating("UpdateRecharge", 1f, 1f);
            }
        }
        public static bool Prefix(SeaTruckMotor __instance, bool waitForDocking, bool forceStop, ref bool __result)
        {
            if (__instance.TryGetComponent(out FlyManager manager))
            {
                if (manager.altitude > 0 && manager.isFlying.value)
                {
                    ErrorMessage.AddDebug("Cannot leave Seatruck while flying!");
                    __result = false;
                    return(false);
                }
            }

            return(true);
        }
        private void SetupScannerModule()
        {
            GameObject FabricatorSpawn = GameObjectClone.transform.Find("FabricatorSpawn").gameObject;

            UnityEngine.Object.DestroyImmediate(FabricatorSpawn);

            GameInfoIcon gameInfoIcon = GameObjectClone.GetComponent <GameInfoIcon>();

            gameInfoIcon.techType = TechType;

            SeaTruckMotor seaTruckMotor = GameObjectClone.GetComponent <SeaTruckMotor>();

            seaTruckMotor.mouseOver = Language.main.Get("SeatruckScanner_PilotScannerModule");
        }
        public bool Initialise(GameObject vehicle)
        {
#if SUBNAUTICA_STABLE
            SeaMoth s = vehicle.GetComponent <SeaMoth>();
#elif BELOWZERO
            SeaTruckMotor s = vehicle.GetComponent <SeaTruckMotor>();
#endif
            Exosuit exosuit = vehicle.GetComponent <Exosuit>();

            if (s == null && exosuit == null)
            {
                return(false);
            }

            ParentVehicle    = (s != null ? s : exosuit);
            ParentGameObject = vehicle;
            return(true);
        }
Exemplo n.º 18
0
        public static void PostStart(ref SeaTruckMotor __instance)
        {
            if (__instance.gameObject != null && __instance.gameObject.TryGetComponent <LiveMixin>(out LiveMixin mixin))
            {
                float defaultHealth     = mixin.defaultHealth;
                float instanceHealthPct = Mathf.Min(mixin.GetHealthFraction(), 1f);
                float maxHealth         = defaultHealth;
                if (__instance.gameObject.GetComponent <SeaTruckUpgrades>() != null)
                {
                    maxHealth *= Main.config.SeatruckVehicleHealthMult;
                }
                else
                {
                    maxHealth *= Main.config.SeatruckModulesHealthMult;
                }

                mixin.data.maxHealth = maxHealth;
                mixin.health         = maxHealth * instanceHealthPct;
            }
        }
Exemplo n.º 19
0
        public static void PostUpdate(uGUI_SeaTruckHUD __instance)
        {
            if (__instance == null)
            {
                return;
            }

            if (!Main.config.bHUDAbsoluteValues)
            {
                return;
            }

            if (Player.main == null)
            {
                return;
            }

            if (!Player.main.inSeatruckPilotingChair)
            {
                return;
            }

            SeaTruckMotor motor = Player.main.GetComponentInParent <SeaTruckMotor>();

            if (motor != null)
            {
                PowerRelay relay = motor.relay;
                if (relay != null)
                {
                    float power       = Mathf.Floor(relay.GetPower());
                    float truckhealth = Mathf.Floor(motor.liveMixin.health);
                    __instance.textHealth.text = truckhealth.ToString();
                    //__instance.textHealth.fontSize = (truckhealth > 9999 ? 20 : 36);
                    __instance.textPower.text     = power.ToString();
                    __instance.textPower.fontSize = (power > 9999 ? 28 : 36);
                }
            }
        }
        private void OnSelect(int slotID)
        {
            if (parentVehicle == null)
            {
                return;
            }
            if (parentMotor == null)
            {
                parentMotor = parentVehicle.motor;
            }

            if (slotID >= SeaTruckUpgrades.slotIDs.Length)
            {
                Log.LogDebug("SeatruckUpdate.OnSelect() invoked with slotID outside the bounds of the slotIDs array");
                return;
            }

            TechType equippedTech = parentVehicle.modules.GetTechTypeInSlot(SeaTruckUpgrades.slotIDs[slotID]);

            if (equippedTech == sonarModuleTechType)
            {
                sonarSlotID  = slotID;
                bSonarActive = !bSonarActive;
                if (bSonarActive)
                {
                    base.InvokeRepeating("UpdateSonar", 0f, SonarCooldown);
                }
                else
                {
                    base.CancelInvoke("UpdateSonar");
                }
            }
            else if (equippedTech == repairModuleTechType)
            {
                ErrorMessage.AddMessage("Repair module state: " + (gameObject.EnsureComponent <VehicleRepairComponent>().ToggleActiveState(parentMotor) ? "active" : "passive"));
            }
        }
Exemplo n.º 21
0
 public static bool Prefix(SeaTruckMotor __instance, float ___afterBurnerTime, bool ___waitForDocking, GameObject ___inputStackDummy, float ___animAccel, FMOD.Studio.PARAMETER_ID ___velocityParamIndex,
                           FMOD.Studio.PARAMETER_ID ___depthParamIndex, FMOD.Studio.PARAMETER_ID ___rpmParamIndex, FMOD.Studio.PARAMETER_ID ___turnParamIndex, FMOD.Studio.PARAMETER_ID ___upgradeParamIndex,
                           FMOD.Studio.PARAMETER_ID ___damagedParamIndex, Animator ___animator)
 {
     if (!FreeLookPatcher.isFreeLooking)
     {
         Logger.Log("Motor as usual");
         return(true);
     }
     else
     {
         Logger.Log("Motor differently");
         if (__instance.afterBurnerActive && Time.time > ___afterBurnerTime)
         {
             __instance.afterBurnerActive = false;
         }
         __instance.UpdateDrag();
         if (__instance.piloting && __instance.useRigidbody != null && !__instance.IsBusyAnimating() && !___waitForDocking)
         {
             if ((__instance.truckSegment.isMainCab ? (AvatarInputHandler.main.IsEnabled() && !Player.main.GetPDA().isInUse) : ___inputStackDummy.activeInHierarchy) && GameInput.GetButtonDown(GameInput.Button.Exit))
             {
                 __instance.StopPiloting(false, false, false);
             }
             else if (!__instance.truckSegment.isMainCab && GameInput.GetButtonDown(GameInput.Button.PDA))
             {
                 __instance.StopPiloting(false, false, false);
                 __instance.OpenPDADelayed(0.7f);
             }
             else if (!__instance.truckSegment.isMainCab && Player.main.transform.position.y > -1.5f)
             {
                 __instance.StopPiloting(false, false, false);
                 float d = 5f;
                 __instance.useRigidbody.AddForce(-Vector3.up * d, ForceMode.VelocityChange);
             }
             else if (!__instance.truckSegment.underCreatureAttack && __instance.IsPowered())
             {
                 if (__instance.CanTurn())
                 {
                     if (___animator)
                     {
                         ___animAccel = Mathf.Lerp(___animAccel, (float)__instance.leverDirection.y, Time.deltaTime * 3f);
                         ___animator.SetFloat("move_speed_z", ___animAccel);
                     }
                 }
                 if (__instance.upgrades && GameInput.GetButtonDown(GameInput.Button.Sprint))
                 {
                     __instance.upgrades.TryActivateAfterBurner();
                 }
             }
             if (___inputStackDummy.activeInHierarchy && IngameMenu.main != null)
             {
                 if (GameInput.GetButtonDown(GameInput.Button.UIMenu))
                 {
                     IngameMenu.main.Open();
                 }
                 else if (!IngameMenu.main.gameObject.activeInHierarchy)
                 {
                     UWE.Utils.lockCursor = true;
                 }
             }
         }
         if (__instance.engineSound)
         {
             if (__instance.piloting && __instance.IsPowered())
             {
                 __instance.engineSound.Play();
                 __instance.engineSound.SetParameterValue(___velocityParamIndex, __instance.useRigidbody.velocity.magnitude);
                 __instance.engineSound.SetParameterValue(___depthParamIndex, __instance.transform.root.position.y);
                 __instance.engineSound.SetParameterValue(___rpmParamIndex, (GameInput.GetMoveDirection().z + 1f) * 0.5f);
                 __instance.engineSound.SetParameterValue(___turnParamIndex, Mathf.Clamp(GameInput.GetLookDelta().x * 0.3f, -1f, 1f));
                 __instance.engineSound.SetParameterValue(___upgradeParamIndex, (float)(((__instance.powerEfficiencyFactor < 1f) ? 1 : 0) + (__instance.horsePowerUpgrade ? 2 : 0)));
                 if (__instance.liveMixin)
                 {
                     __instance.engineSound.SetParameterValue(___damagedParamIndex, 1f - __instance.liveMixin.GetHealthFraction());
                 }
             }
             else
             {
                 __instance.engineSound.Stop();
             }
         }
         if (___waitForDocking && !__instance.truckSegment.IsDocking())
         {
             ___waitForDocking = false;
             Player.main.ExitLockedMode(false, false, null);
         }
         return(false);
     }
 }