Пример #1
0
        public override void OnUpdate()
        {
            // Need to do this on update, as the part module gets loaded before the scenario
            if (fishingData == null && SportsScenario.Instance != null)
            {
                fishingData = SportsScenario.Instance.GetFishingData(pcm);
                fishRecord  = fishingData.BiggestFish(vessel.mainBody);
                fishCount   = fishingData.FishCount(vessel.mainBody);
            }

            if (vessel.situation != Vessel.Situations.LANDED || !vessel.mainBody.ocean || vessel.altitude > 250)
            {
                SetShowing(false);
            }
            // Perform the more expensive check
            else
            {
                // Check 5 meters forward for water
                Vector3 checkPosition = vessel.transform.localPosition + vessel.transform.forward * 5.0f;
                double  latitude      = vessel.mainBody.GetLatitude(checkPosition);
                double  longitude     = vessel.mainBody.GetLongitude(checkPosition);
                double  height        = Util.TerrainHeight(vessel.mainBody, latitude, longitude);

                int adminLevel = (int)Math.Round(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.Administration) *
                                                 ScenarioUpgradeableFacilities.GetFacilityLevelCount(SpaceCenterFacility.Administration)) + 1;

                if (height <= 0.0 || adminLevel == 3 && Util.adminPool.Contains(new Vector2((float)latitude, (float)longitude)))
                {
                    SetShowing(true);

                    // Set the fish type found at the current location
                    Fish.FishType ft = Fish.GetFishType(vessel.mainBody, vessel.latitude, vessel.longitude);
                    fishType = ft.Name();
                }
                else
                {
                    SetShowing(false);
                }
            }
        }
Пример #2
0
        void SetState(FishingState newState)
        {
            Debug.Log("set fishing state to " + newState);

            // Remove any looping clips
            loopingClipName = null;

            // Enable/disable stuff
            if (newState == FishingState.StartFishing)
            {
                // Set control locks
                ControlTypes locks = ControlTypes.All ^ ControlTypes.QUICKLOAD;
                InputLockManager.SetControlLock(locks, "Fishing");

                // Hide navball
                navballToggled = NavBallToggle.Instance.panel.expanded;
                if (navballToggled)
                {
                    NavBallToggle.Instance.panel.Collapse();
                }
            }
            // Undo what we did
            else if (newState == FishingState.NotFishing)
            {
                // Clear the locks
                InputLockManager.RemoveControlLock("Fishing");

                // Restore navball
                if (navballToggled && NavBallToggle.Instance != null)
                {
                    NavBallToggle.Instance.panel.Expand();
                }

                // Remove the fishing pole
                Destroy(fishingPole);

                if (evaVessel != null)
                {
                    // Set the animation back to the idle one
                    KerbalEVA eva = evaVessel.GetComponent <KerbalEVA>();
                    animation.Stop();
                    animation.Play(eva.Animations.idle.animationName);

                    // Update the fishing module record
                    ModuleFishing mFishing = evaVessel.GetComponent <ModuleFishing>();
                    if (mFishing != null)
                    {
                        mFishing.fishRecord = fishingData.BiggestFish(evaVessel.mainBody);
                        mFishing.fishCount  = fishingData.FishCount(evaVessel.mainBody);
                    }
                }
            }

            // Calculate the camera start position
            if (newState == FishingState.StartFishing)
            {
                Vector3 cameraRelPos = FlightCamera.fetch.transform.position - evaVessel.transform.position;
                Vector3 projection   = Vector3.ProjectOnPlane(cameraRelPos, evaVessel.transform.up);
                startAngle  = (float)Math.Acos(Vector3.Dot(projection.normalized, evaVessel.transform.forward));
                startHeight = Vector3.Dot(cameraRelPos, evaVessel.transform.up);
                double x = Vector3.Dot(cameraRelPos, evaVessel.transform.right);
                double y = Vector3.Dot(cameraRelPos, evaVessel.transform.forward);
                startDist = (float)Math.Sqrt(x * x + y * y);

                cameraZoomTime = defaultCameraZoomTime;
                if (Math.Abs(startAngle - cameraAngle) / minAngularVelocity < cameraZoomTime)
                {
                    cameraZoomTime = Math.Abs(startAngle - cameraAngle) / minAngularVelocity;
                }
                if (cameraZoomTime != defaultCameraZoomTime && Math.Abs(startHeight - cameraHeight) / maxZoomVelocity > cameraZoomTime)
                {
                    cameraZoomTime = Math.Min(defaultCameraZoomTime, Math.Abs(startHeight - cameraHeight) / maxZoomVelocity);
                }
                if (cameraZoomTime != defaultCameraZoomTime && Math.Abs(startDist - cameraDist) / maxZoomVelocity > cameraZoomTime)
                {
                    cameraZoomTime = Math.Min(defaultCameraZoomTime, Math.Abs(startDist - cameraDist) / maxZoomVelocity);
                }
            }

            // Play the idle animation
            if (newState == FishingState.Idle)
            {
                KerbalEVA eva = evaVessel.GetComponent <KerbalEVA>();
                animation.Stop();
                animation.Play(eva.Animations.idle.animationName);
            }
            // Play the casting animation
            else if (newState == FishingState.Casting)
            {
                // Set the casting animation
                animation.Stop();
                animation.Play("fishingCasting");

                // Start at the zero distance when casting
                bobDistance = 0.0f;
            }
            // Reeling animation
            else if (newState == FishingState.Reeling)
            {
                // Set the casting animation
                loopingClipStart = Time.time;
                loopingClipTime  = 4.0f;
                loopingClipName  = "fishingReeling";
                animation.Stop();
            }
            // Hooked animation
            else if (newState == FishingState.Hooked)
            {
                animation.Stop();
            }
            else if (newState == FishingState.Caught)
            {
                animation.Stop();
                animation.Play("fishingCaught");
            }

            // Decide if a fish will be caught on this cast, and when
            if (newState == FishingState.Reeling)
            {
                double catchChance = (SportsScenario.Instance.failedAttempts + 1) / 5.0;
                if (catchChance >= 1.0 || rand.NextDouble() < catchChance)
                {
                    fishHookDistance = (float)rand.NextDouble() * 0.55f + 0.25f;
                }
                else
                {
                    fishHookDistance = -1.0f;
                }
            }

            // Center the rod when we hook a fish
            if (newState == FishingState.Hooked)
            {
                rodPosition      = 0.5f;
                rodLeeway        = 0.0f;
                fishHookDistance = -1.0f;
            }

            // Caught a fish, record it
            if (newState == FishingState.Caught)
            {
                fishingData.CaughtFish(evaVessel.mainBody, currentFish);
                fishingData.IncreaseSkill(caughtSkillIncrease);
            }

            stateStartTime = Time.fixedTime;
            lCtrlTime      = rCtrlTime = 0.0;
            fishingState   = newState;
        }