static bool Prefix(Raft __instance, ref Rigidbody ___body, ref float ___speed, ref StudioEventEmitter ___eventEmitter_idle, ref Vector3 ___previousPosition)
 {
     if (!Semih_Network.IsHost)
     {
         return(false);
     }
     if (!__instance.IsAnchored && ___speed != 0f)
     {
         __instance.moveDirection = Vector3.forward;
         List <Sail> allSails = Sail.AllSails;
         Vector3     vector   = Vector3.zero;
         int         i        = 0;
         int         num      = 1;
         while (i < allSails.Count)
         {
             Sail sail = allSails[i];
             if (sail.open)
             {
                 vector += sail.GetNormalizedDirection() * (float)(num / Math.Pow(num, rate));
             }
             i++;
             num++;
         }
         if (vector.z < 0f)
         {
             vector.z = ((Mathf.Abs(vector.x) <= 0.7) ? -0.8f : (__instance.moveDirection.z = 0f));
         }
         __instance.moveDirection += vector;
         ___body.AddForce(__instance.moveDirection * ___speed);
     }
     if (___body.velocity.sqrMagnitude > __instance.maxVelocity)
     {
         ___body.velocity = Vector3.ClampMagnitude(___body.velocity, __instance.maxVelocity);
     }
     ___eventEmitter_idle.SetParameter("velocity", ___body.velocity.sqrMagnitude / __instance.maxVelocity);
     ___previousPosition = ___body.transform.position;
     return(false);
 }
Example #2
0
    private static bool Prefix
    (
        Raft __instance,
        ref Rigidbody ___body,
        ref float ___currentMovementSpeed,
        ref float ___speed,
        ref float ___maxDistanceFromAnchorPoint,
        ref StudioEventEmitter ___eventEmitter_idle,
        ref Vector3 ___previousPosition,
        ref Vector3 ___moveDirection,
        ref Vector3 ___anchorPosition
    )
    {
        if (!Semih_Network.IsHost)
        {
            return(false);
        }
        if (GameModeValueManager.GetCurrentGameModeValue().raftSpecificVariables.isRaftAlwaysAnchored)
        {
            return(false);
        }
        if (!__instance.IsAnchored)
        {
            if (___speed != 0f)
            {
                float openedSails = 0f;
                ___moveDirection = Vector3.forward;
                if (RaftVelocityManager.MotorDirection == Vector3.zero)
                {
                    List <Sail> allSails = Sail.AllSails;

                    Vector3 vector = Vector3.zero;

                    for (int i = 0; i < allSails.Count; i++)
                    {
                        Sail sail = allSails[i];
                        if (sail.open)
                        {
                            openedSails++;
                            vector += sail.GetNormalizedDirection();
                        }
                    }
                    if (vector.z < 0f)
                    {
                        if ((double)Mathf.Abs(vector.x) > 0.7)
                        {
                            vector.z = (___moveDirection.z = 0f);
                        }
                        else
                        {
                            vector.z = -0.8f;
                        }
                    }
                    ___moveDirection += vector;
                }
                else
                {
                    ___moveDirection = RaftVelocityManager.MotorDirection;
                }
                ___currentMovementSpeed = ___speed;
                if (RaftVelocityManager.MotorDirection != Vector3.zero)
                {
                    ___currentMovementSpeed = RaftVelocityManager.motorSpeed;
                    if (RaftVelocityManager.MotorWheelWeightStrength == MotorWheel.WeightStrength.Weak)
                    {
                        ___currentMovementSpeed *= 0.5f;
                    }
                    if (___currentMovementSpeed < ___speed)
                    {
                        ___currentMovementSpeed = ___speed;
                    }
                }
                else
                {
                    for (float i = 1; i < (openedSails + 1); i++)
                    {
                        ___currentMovementSpeed += (1.5f * (float)(i / Math.Pow(i, MoreSailsMoreSpeed.RaftFixedUpdatePatchRate)));
                    }
                }
                if (___speed != 0f)
                {
                    if (___currentMovementSpeed > __instance.maxSpeed)
                    {
                        ___currentMovementSpeed = __instance.maxSpeed;
                    }
                    ___moveDirection = Vector3.ClampMagnitude(___moveDirection, 1f);
                    ___body.AddForce(___moveDirection * ___currentMovementSpeed);
                }
            }
            List <SteeringWheel> steeringWheels = RaftVelocityManager.steeringWheels;
            float num = 0f;
            foreach (SteeringWheel steeringWheel in steeringWheels)
            {
                num += steeringWheel.SteeringRotation;
            }
            num = Mathf.Clamp(num, -1f, 1f);
            if (num != 0f)
            {
                Vector3 torque = new Vector3(0f, Mathf.Tan(0.0174532924f * num), 0f) * __instance.maxSteeringTorque;
                ___body.AddTorque(torque, ForceMode.Acceleration);
            }
        }
        else if (__instance.transform.position.DistanceXZ(___anchorPosition) > ___maxDistanceFromAnchorPoint)
        {
            Vector3 vector2 = ___anchorPosition - __instance.transform.position;
            vector2.y = 0f;
            ___body.AddForce(vector2.normalized * 2f);
        }
        if (___body.velocity.sqrMagnitude > __instance.maxVelocity)
        {
            ___body.velocity = Vector3.ClampMagnitude(___body.velocity, __instance.maxVelocity);
        }
        ___eventEmitter_idle.SetParameter("velocity", ___body.velocity.sqrMagnitude / __instance.maxVelocity);
        ___previousPosition = ___body.transform.position;
        return(false);
    }