Esempio n. 1
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            if (node.HasNode("FISHING"))
            {
                ConfigNode fishingNode = node.GetNode("FISHING");
                failedAttempts = Convert.ToInt32(fishingNode.GetValue("failedAttempts"));
                if (fishingNode.HasValue("tutorialDialogShown"))
                {
                    tutorialDialogShown = Convert.ToBoolean(fishingNode.GetValue("tutorialDialogShown"));
                }

                foreach (ConfigNode kerbalNode in fishingNode.GetNodes("KERBAL"))
                {
                    string      name = kerbalNode.GetValue("name");
                    FishingData data = fishingData[name] = new FishingData();
                    data.skill = (float)Convert.ToDouble(kerbalNode.GetValue("skill"));
                    foreach (ConfigNode bodyNode in kerbalNode.nodes)
                    {
                        CelestialBody body = FlightGlobals.Bodies.Where(cb => cb.name == bodyNode.name).FirstOrDefault();
                        if (body != null)
                        {
                            FishingData.FishingStats stats = data.fishingStats[body] = new FishingData.FishingStats();
                            stats.biggestFish = Convert.ToDouble(bodyNode.GetValue("biggestFish"));
                            stats.fishCaught  = Convert.ToInt32(bodyNode.GetValue("fishCaught"));
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Starts the fishing program.
        /// </summary>
        public void StartFishing(Vessel v, ProtoCrewMember pcm)
        {
            evaVessel    = v;
            kerbalFisher = pcm;
            fishingData  = SportsScenario.Instance.GetFishingData(pcm);

            SetState(FishingState.StartFishing);

            // Get the kerbal EVA
            KerbalEVA eva = evaVessel.GetComponent <KerbalEVA>();

            // Create the fishing pole object
            GameObject poleObject = new GameObject("fishingPole");

            fishingPole = poleObject.AddComponent <FishingPole>();
            fishingPole.referenceTransform = eva.transform.FindDeepChild("bn_r_mid_a01");
            poleObject.SetActive(true);

            // Initialize animations
            animation = eva.GetComponent <Animation>();
            castingClip.Initialize(animation, eva.transform);
            reelingClip.Initialize(animation, eva.transform);
            hookedClip.Initialize(animation, eva.transform);
            caughtClip.Initialize(animation, eva.transform);

            // Close the window that caused us to open
            UIPartActionWindow paw = UnityEngine.Object.FindObjectOfType <UIPartActionWindow>();

            if (paw != null)
            {
                paw.isValid = false;
            }

            // Determine the body difficulty
            double gravityModifier = evaVessel.mainBody.gravParameter / (evaVessel.mainBody.Radius * evaVessel.mainBody.Radius) / 9.81;
            double scienceModifier = evaVessel.mainBody.scienceValues.SplashedDataValue / 10.0f;

            bodyDifficulty     = gravityModifier + scienceModifier;
            hookedReelingSpeed = defaultHookedReelingSpeed / (float)bodyDifficulty;
            Debug.Log("Body difficulty for " + evaVessel.mainBody.name + " = " + bodyDifficulty);

            // Pop up the tutorial dialog
            if (firstTimeDialog == null && !SportsScenario.Instance.tutorialDialogShown)
            {
                firstTimeDialog = gameObject.AddComponent <GenericDialog>();
                firstTimeDialog.instructorName = "Strategy_MechanicGuy";
                firstTimeDialog.text           = tutorialText;
                firstTimeDialog.animation      = GenericDialog.Animation.true_nodA;

                SportsScenario.Instance.tutorialDialogShown = true;
            }
        }
Esempio n. 3
0
        public FishingData GetFishingData(ProtoCrewMember pcm)
        {
            if (pcm == null)
            {
                return(null);
            }

            if (!fishingData.ContainsKey(pcm.name))
            {
                FishingData data = fishingData[pcm.name] = new FishingData();

                string traitName = pcm.experienceTrait.Config.Name;
                data.skill = traitName == "Engineer" ? 20 : traitName == "Scientist" ? 10 : 0;
            }
            return(fishingData[pcm.name]);
        }
Esempio n. 4
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);
                }
            }
        }