Example #1
0
        public CustomBobberBar?Create(
            FishingInfo fishingInfo,
            FishEntry fishEntry,
            Item fishItem,
            float fishSizePercent,
            bool treasure,
            int bobber,
            bool fromFishPond
            )
        {
            // Try to get the fish traits
            if (!this.fishingApi.TryGetFishTraits(fishEntry.FishKey, out var fishTraits))
            {
                this.monitor.Log($"Missing fish traits for {fishEntry.FishKey}.", LogLevel.Error);
                return(null);
            }

            // Create the custom bobber bar
            return(new(
                       this.helper,
                       this.fishConfig,
                       this.treasureConfig,
                       fishingInfo,
                       fishEntry,
                       fishTraits,
                       fishItem,
                       fishSizePercent,
                       treasure,
                       bobber,
                       fromFishPond
                       ));
        }
Example #2
0
            public void Apply(FishingInfo fishingInfo)
            {
                var operation   = new Operation(this.chanceType, fishingInfo.User);
                var calculators = this.appliedFarmers.GetOrAdd(operation, () => new());

                calculators.Add(this.calculate);
            }
 /// <summary>
 /// Initializes a new instance of the <see cref="PreparedFishEventArgs"/> class.
 /// </summary>
 /// <param name="fishingInfo">Information about the <see cref="Farmer"/> that is fishing.</param>
 /// <param name="fishChances">The chances of finding fish.</param>
 /// <exception cref="ArgumentNullException">An argument was null.</exception>
 public PreparedFishEventArgs(
     FishingInfo fishingInfo,
     IList <IWeightedValue <FishEntry> > fishChances
     )
 {
     this.FishingInfo = fishingInfo ?? throw new ArgumentNullException(nameof(fishingInfo));
     this.FishChances = fishChances ?? throw new ArgumentNullException(nameof(fishChances));
 }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PreparedTreasureEventArgs"/> class.
 /// </summary>
 /// <param name="fishingInfo">Information about the <see cref="Farmer"/> that is fishing.</param>
 /// <param name="treasureChances">The chances of finding treasure.</param>
 /// <exception cref="ArgumentNullException">An argument was null.</exception>
 public PreparedTreasureEventArgs(
     FishingInfo fishingInfo,
     IList <IWeightedValue <TreasureEntry> > treasureChances
     )
 {
     this.FishingInfo     = fishingInfo ?? throw new ArgumentNullException(nameof(fishingInfo));
     this.TreasureChances = treasureChances
                            ?? throw new ArgumentNullException(nameof(treasureChances));
 }
        /// <summary>
        /// Calculates the chance of catching this entry.
        /// </summary>
        /// <param name="fishingInfo">The fishing info to calculate the chance for.</param>
        /// <returns>The chance of catching this entry, or <see langword="null"/> if the entry is not available.</returns>
        public double?GetWeightedChance(FishingInfo fishingInfo)
        {
            if (!this.IsAvailable(fishingInfo))
            {
                return(null);
            }

            return(this.availabilityInfo.GetChance(fishingInfo));
        }
Example #6
0
 public void Unapply(FishingInfo fishingInfo)
 {
     if (this.appliedFarmers.TryGetValue(
             new(this.chanceType, fishingInfo.User),
             out var calculators
             ))
     {
         calculators.Remove(this.calculate);
     }
 }
Example #7
0
        private void ApplyMapOverrides(object?sender, CreatedDefaultFishingInfoEventArgs e)
        {
            if (e.FishingInfo.User.currentLocation is Farm farm &&
                GetFarmLocationOverride(farm) is var(overrideLocation, overrideChance) &&
                Game1.random.NextDouble() < overrideChance)
            {
                e.FishingInfo = e.FishingInfo with
                {
                    Locations = FishingInfo.GetDefaultLocationNames(
                        Game1.getLocationFromName(overrideLocation)
                        )
                                .ToImmutableArray(),
                };
            }

            (string, float)? GetFarmLocationOverride(Farm farm)
            {
                var overrideLocationField =
                    this.helper.Reflection.GetField <string?>(farm, "_fishLocationOverride");
                var overrideChanceField =
                    this.helper.Reflection.GetField <float>(farm, "_fishChanceOverride");

                // Set override
                float overrideChance;

                if (overrideLocationField.GetValue() is not {
                } overrideLocation)
                {
                    // Read from the map properties
                    var mapProperty = farm.getMapProperty("FarmFishLocationOverride");
                    if (mapProperty == string.Empty)
                    {
                        overrideLocation = string.Empty;
                        overrideChance   = 0.0f;
                    }
                    else
                    {
                        var splitProperty = mapProperty.Split(' ');
                        if (splitProperty.Length >= 2 &&
                            float.TryParse(splitProperty[1], out overrideChance))
                        {
                            overrideLocation = splitProperty[0];
                        }
                        else
                        {
                            overrideLocation = string.Empty;
                            overrideChance   = 0.0f;
                        }
                    }

                    // Set the fields
                    overrideLocationField.SetValue(overrideLocation);
                    overrideChanceField.SetValue(overrideChance);
                }
Example #8
0
        /// <summary>
        /// Calculates whether the entry is available.
        /// </summary>
        /// <param name="fishingInfo">The fishing info to calculate the availability for.</param>
        /// <returns>Whether the entry is available.</returns>
        public bool IsAvailable(FishingInfo fishingInfo)
        {
            if (!this.conditions.IsAvailable(fishingInfo))
            {
                return(false);
            }

            if (this.managedConditions is not {
            } managedConditions)
            {
                return(true);
            }

            managedConditions.UpdateContext();
            return(managedConditions.IsMatch);
        }
Example #9
0
        /// <summary>
        /// Calculates the chance of catching this entry.
        /// </summary>
        /// <param name="fishingInfo">The fishing info to calculate the chance for.</param>
        /// <returns>The chance of catching this entry, or <see langword="null"/> if the entry is not available.</returns>
        public double?GetWeightedChance(FishingInfo fishingInfo)
        {
            return(this.availabilityInfo.GetWeightedChance(fishingInfo)
                   .Where(
                       _ =>
            {
                if (this.managedConditions is not {
                } conditions)
                {
                    return true;
                }

                conditions.UpdateContext();
                return conditions.IsMatch;
            }
                       ));
        }
        public bool?UpdateEnabled(FishingInfo fishingInfo)
        {
            switch (this.Enabled)
            {
            case false when this.ConditionsCalculator.IsAvailable(fishingInfo):
                this.Enabled = true;

                return(true);

            case true when !this.ConditionsCalculator.IsAvailable(fishingInfo):
                this.Enabled = false;
                return(false);

            default:
                return(null);
            }
        }
        public void TryBeginFishing(int playerId, int projectileId, int projectileType)
        {
            if (!IsFishingProjectile(projectileType))
            {
                return;
            }

            if (!playerToFishingInfos.TryGetValue(playerId, out var fishingInfo))
            {
                Debug.Print($"Player #{playerId} has started fishing.");

                fishingInfo = new FishingInfo()
                {
                    ProjectileId = projectileId
                                   //ProjectileType = projectileType
                };

                playerToFishingInfos.TryAdd(playerId, fishingInfo);
            }
            //else this was just a projectile update, so ignore
        }
Example #12
0
        private void OnUpdateTicking(object?sender, UpdateTickingEventArgs e)
        {
            if (Game1.player is null)
            {
                return;
            }

            foreach (var manager in this.fishingApi.fishingEffectManagers)
            {
                var info = new FishingInfo(Game1.player);
                switch (manager.UpdateEnabled(info))
                {
                case true:
                    manager.Effect.Apply(info);
                    break;

                case false:
                    manager.Effect.Unapply(info);
                    break;
                }
            }
        }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CreatedDefaultFishingInfoEventArgs"/> class.
 /// </summary>
 /// <param name="fishingInfo">Information about the <see cref="Farmer"/> that is fishing.</param>
 /// <exception cref="ArgumentNullException">An argument was null.</exception>
 public CreatedDefaultFishingInfoEventArgs(FishingInfo fishingInfo)
 {
     this.FishingInfo = fishingInfo ?? throw new ArgumentNullException(nameof(fishingInfo));
 }
Example #14
0
 public void Apply(FishingInfo fishingInfo)
 {
 }
Example #15
0
            static bool Prefix(FishingSystem_t __instance, FishInfo ___fishInfo, Transform ___shoal, IFishingMan ___fishingMan, ref MoveArea ___area, FishingInfo ___fishingAreaInfo, float ___fishSpeedBaseFactor, float ___fishDashBaseFactor, float ___fishWaitBaseFactor, FishingUI_t ___hud)
            {
                if (!enabled)
                {
                    if (origBaitID != -1)
                    {
                        OtherConfig.Self.BaitID = origBaitID;
                    }
                    return(true);
                }
                Dbgl("Wait for fish");

                if (OtherConfig.Self.BaitID != -1)
                {
                    origBaitID = OtherConfig.Self.BaitID;
                    OtherConfig.Self.BaitID = -1;
                }

                Fish_t fish = null;

                if (string.IsNullOrEmpty(___fishInfo.fishPrefabPath))
                {
                    UnityEngine.Debug.LogError("fishPrefabPath = is null!");
                }
                else
                {
                    GameObject original = Singleton <ResMgr> .Instance.LoadSync <GameObject>(___fishInfo.fishPrefabPath, false, false);

                    GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(original, ___fishInfo.FishBornTrans.position, Quaternion.identity);
                    gameObject.transform.parent     = ___shoal;
                    gameObject.transform.localScale = Vector3.one;
                    gameObject.SetActive(true);
                    fish = gameObject.GetComponent <Fish_t>();
                }
                if (fish != null)
                {
                    Vector3 vector = ___fishInfo.FishBornTrans.position - ___fishingMan.Pos;
                    ___area               = new MoveArea();
                    ___area.angle         = ___fishingAreaInfo.angleLimit / 2f;
                    ___area.dir           = vector.normalized;
                    ___area.fishingManPos = ___fishingMan.Pos;
                    ___fishInfo.GenPowerFactor(fish.PowerValue);
                    ___fishInfo.GenSpeedFactor(fish.SpeedValue, ___fishSpeedBaseFactor);
                    ___fishInfo.GenAngerFactor(fish.AngerValue, ___fishDashBaseFactor);
                    ___fishInfo.GenTenacityFactor(fish.TenacityValue);
                    ___fishInfo.SetBaseWaitTime(___fishWaitBaseFactor);
                    fish.SetFishInfo(___fishInfo);
                }

                if (settings.PlayHereFishy && fishyClip != null)
                {
                    PlayClip(fishyClip, settings.HereFishyVolume, false);
                }

                Singleton <TaskRunner> .Self.RunDelayTask(fishyClip.length, true, delegate
                {
                    if (___hud == null)
                    {
                        return;
                    }

                    if (fish != null)
                    {
                        if (settings.PlayWee && weeClip != null)
                        {
                            PlayClip(weeClip, settings.WeeVolume, true, fish.transform);
                        }
                        __instance.GetType().GetField("curFish", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__instance, fish);
                        origPos = (__instance.GetType().GetField("curFish", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance) as Fish_t).gameObject.transform.position;
                        flatPos = origPos;
                        Singleton <TaskRunner> .Self.StartCoroutine(FishJump(__instance));
                    }
                    else
                    {
                        Module <Player> .Self.actor.TryDoAction(ACType.Animation, ACTAnimationPara.Construct("Throw_2", null, null, false));

                        typeof(FishingSystem_t).GetMethod("FishingEnd", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { true, false });
                    }
                    //__instance.GetType().GetField("curFish", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__instance, __instance.GetType().GetMethod("CreateFish", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[0]));
                    //typeof(FishingSystem_t).GetMethod("FishingBegin", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { });
                });

                return(false);
            }
 /// <summary>
 /// Initializes a new instance of the <see cref="OpeningChestEventArgs"/> class.
 /// </summary>
 /// <param name="fishingInfo">Information about the <see cref="Farmer"/> that is fishing.</param>
 /// <param name="caughtItems">The items in the chest.</param>
 /// <exception cref="ArgumentNullException">An argument was null.</exception>
 public OpeningChestEventArgs(FishingInfo fishingInfo, IList <CaughtItem> caughtItems)
 {
     this.FishingInfo = fishingInfo ?? throw new ArgumentNullException(nameof(fishingInfo));
     this.CaughtItems = caughtItems ?? throw new ArgumentNullException(nameof(caughtItems));
 }
 /// <inheritdoc/>
 public abstract IEnumerable <IWeightedValue <FishEntry> > GetFishChances(
     FishingInfo fishingInfo
     );
        public CustomBobberBar(
            IModHelper helper,
            FishConfig fishConfig,
            TreasureConfig treasureConfig,
            FishingInfo fishingInfo,
            FishEntry fishEntry,
            FishTraits fishTraits,
            Item fishItem,
            float fishSizePercent,
            bool treasure,
            int bobber,
            bool fromFishPond
            )
            : base(0, fishSizePercent, treasure, bobber)
        {
            _ = helper ?? throw new ArgumentNullException(nameof(helper));
            this.fishConfig     = fishConfig ?? throw new ArgumentNullException(nameof(fishConfig));
            this.treasureConfig =
                treasureConfig ?? throw new ArgumentNullException(nameof(treasureConfig));
            this.fishingInfo = fishingInfo ?? throw new ArgumentNullException(nameof(fishingInfo));
            this.fishEntry   = fishEntry;
            this.fishTraits  = fishTraits ?? throw new ArgumentNullException(nameof(fishTraits));
            this.fishItem    = fishItem ?? throw new ArgumentNullException(nameof(fishItem));

            this.treasureField         = helper.Reflection.GetField <bool>(this, "treasure");
            this.treasureCaughtField   = helper.Reflection.GetField <bool>(this, "treasureCaught");
            this.treasurePositionField =
                helper.Reflection.GetField <float>(this, "treasurePosition");
            this.treasureAppearTimerField =
                helper.Reflection.GetField <float>(this, "treasureAppearTimer");
            this.treasureScaleField = helper.Reflection.GetField <float>(this, "treasureScale");

            this.distanceFromCatchingField =
                helper.Reflection.GetField <float>(this, "distanceFromCatching");
            this.treasureCatchLevelField =
                helper.Reflection.GetField <float>(this, "treasureCatchLevel");

            this.bobberBarPosField    = helper.Reflection.GetField <float>(this, "bobberBarPos");
            this.bobberInBarField     = helper.Reflection.GetField <bool>(this, "bobberInBar");
            this.difficultyField      = helper.Reflection.GetField <float>(this, "difficulty");
            this.fishQualityField     = helper.Reflection.GetField <int>(this, "fishQuality");
            this.perfectField         = helper.Reflection.GetField <bool>(this, "perfect");
            this.scaleField           = helper.Reflection.GetField <float>(this, "scale");
            this.flipBubbleField      = helper.Reflection.GetField <bool>(this, "flipBubble");
            this.bobberBarHeightField = helper.Reflection.GetField <int>(this, "bobberBarHeight");
            this.reelRotationField    = helper.Reflection.GetField <float>(this, "reelRotation");
            this.bobberPositionField  = helper.Reflection.GetField <float>(this, "bobberPosition");
            this.bossFishField        = helper.Reflection.GetField <bool>(this, "bossFish");
            this.motionTypeField      = helper.Reflection.GetField <int>(this, "motionType");
            this.fishSizeField        = helper.Reflection.GetField <int>(this, "fishSize");
            this.minFishSizeField     = helper.Reflection.GetField <int>(this, "minFishSize");
            this.maxFishSizeField     = helper.Reflection.GetField <int>(this, "maxFishSize");
            this.fromFishPondField    = helper.Reflection.GetField <bool>(this, "fromFishPond");

            this.barShakeField        = helper.Reflection.GetField <Vector2>(this, "barShake");
            this.fishShakeField       = helper.Reflection.GetField <Vector2>(this, "fishShake");
            this.treasureShakeField   = helper.Reflection.GetField <Vector2>(this, "treasureShake");
            this.everythingShakeField =
                helper.Reflection.GetField <Vector2>(this, "everythingShake");
            this.fadeOutField = helper.Reflection.GetField <bool>(this, "fadeOut");

            this.sparkleTextField = helper.Reflection.GetField <SparklingText?>(this, "sparkleText");

            // Track state
            this.lastDistanceFromCatching = 0f;
            this.lastTreasureCatchLevel   = 0f;
            this.state = new(true, treasure ? TreasureState.NotCaught : TreasureState.None);

            // Track player streak
            this.perfectField.SetValue(true);
            var fishSizeReductionTimerField =
                helper.Reflection.GetField <int>(this, "fishSizeReductionTimer");

            fishSizeReductionTimerField.SetValue(800);

            // Fish size
            var minFishSize = fishTraits.MinSize;
            var maxFishSize = fishTraits.MaxSize;
            var fishSize    = (int)(minFishSize + (maxFishSize - minFishSize) * fishSizePercent) + 1;

            this.minFishSizeField.SetValue(minFishSize);
            this.maxFishSizeField.SetValue(maxFishSize);
            this.fishSizeField.SetValue(fishSize);

            // Track other information (not all tracked by vanilla)
            this.fromFishPondField.SetValue(fromFishPond);
            this.bossFishField.SetValue(fishTraits.IsLegendary);

            // Adjust quality to be increased by streak
            var fishQuality = fishSizePercent switch
            {
Example #19
0
 public void Unapply(FishingInfo fishingInfo)
 {
 }