示例#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
                       ));
        }
        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
            {