Ejemplo n.º 1
0
        /// <summary>Get the locale codes (like <c>ja-JP</c>) used in asset keys.</summary>
        /// <param name="reflection">Simplifies access to private game code.</param>
        private IDictionary <string, LanguageCode> GetKeyLocales(Reflector reflection)
        {
            // get the private code field directly to avoid changed-code logic
            IReflectedField <LanguageCode> codeField = reflection.GetField <LanguageCode>(typeof(LocalizedContentManager), "_currentLangCode");

            // remember previous settings
            LanguageCode previousCode     = codeField.GetValue();
            string       previousOverride = this.LanguageCodeOverride;

            // create locale => code map
            IDictionary <string, LanguageCode> map = new Dictionary <string, LanguageCode>(StringComparer.InvariantCultureIgnoreCase);

            this.LanguageCodeOverride = null;
            foreach (LanguageCode code in Enum.GetValues(typeof(LanguageCode)))
            {
                codeField.SetValue(code);
                map[this.GetKeyLocale.Invoke <string>()] = code;
            }

            // restore previous settings
            codeField.SetValue(previousCode);
            this.LanguageCodeOverride = previousOverride;

            return(map);
        }
Ejemplo n.º 2
0
        public void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e)
        {
            System.Console.Write($"Type of new menu is {e.NewMenu.GetType().ToString()}");

            if (e.NewMenu is CraftingPage page && !(e.NewMenu is ListenerCraftingPage))
            {
                ListenerCraftingPage replacement = new ListenerCraftingPage(page, this.replacer);
                Game1.activeClickableMenu = replacement;
            }

            if (e.NewMenu is GameMenu)
            {
                IReflectedField <List <IClickableMenu> > pages = this.Helper.Reflection.GetField <List <IClickableMenu> >(e.NewMenu, "pages");
                var menuPages = pages.GetValue();
                for (int i = 0; i < menuPages.Count; i++)
                {
                    if (menuPages[i] is CraftingPage craftingPage)
                    {
                        menuPages[i] = new ListenerCraftingPage(craftingPage, this.replacer);
                        break;
                    }
                }

                pages.SetValue(menuPages);
            }
        }
Ejemplo n.º 3
0
 protected virtual void InitializeReflection()
 {
     SeenFarmer            = Utility.Helper.Reflection.GetField <bool>(this, "seenFarmer");
     RunningAwayFromFarmer = Utility.Helper.Reflection.GetField <bool>(this, "runningAwayFromFarmer");
     ChargingFarmer        = Utility.Helper.Reflection.GetField <bool>(this, "chargingFarmer");
     Multiplayer           = Utility.Helper.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer");
 }
Ejemplo n.º 4
0
 public TVIntercept(TV tv)
     : base(tv.parentSheetIndex, tv.tileLocation)
 {
     this.tv   = tv;
     tvScreen  = CustomTVMod.Modhelper.Reflection.GetField <TemporaryAnimatedSprite>(tv, "screen");
     tvOverlay = CustomTVMod.Modhelper.Reflection.GetField <TemporaryAnimatedSprite>(tv, "screenOverlay");
 }
Ejemplo n.º 5
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="reflection">Simplifies access to private code.</param>
        /// <param name="options">The available dropdown options.</param>
        /// <param name="selected">The selected key, if any.</param>
        /// <param name="getKeyString">The logic to get the </param>
        public SimpleDropdown(IReflectionHelper reflection, IEnumerable <KeyValuePair <TKey, string> > options, TKey?selected = default, Func <TKey, string>?getKeyString = null)
        {
            getKeyString ??= raw => raw.ToString() ?? string.Empty;

            // parse options
            var optionKeys   = new List <string?>();
            var optionLabels = new List <string>();
            var lookup       = new List <Tuple <string, TKey, string> >();

            foreach ((TKey key, string value) in options)
            {
                string keyStr = getKeyString(key);

                optionKeys.Add(keyStr);
                optionLabels.Add(value);
                lookup.Add(Tuple.Create(keyStr, key, value));
            }

            // build dropdown
            this.Options  = lookup;
            this.Dropdown = new OptionsDropDown(null, -int.MaxValue)
            {
                dropDownOptions        = optionKeys,
                dropDownDisplayOptions = optionLabels
            };
            this.IsExpandedField = reflection.GetField <bool>(this.Dropdown, "clicked");

            // select element
            this.TrySelect(selected);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds in a junimo actor at the current location. Allows for multiple.
        /// </summary>
        /// <param name="EventManager"></param>
        /// <param name="EventData"></param>
        public static void AddInJumimoActorForEvent(EventManager EventManager, string EventData)
        {
            string[] splits = EventData.Split(' ');
            string   name   = splits[0];

            string actorName = splits[1];
            int    xPos      = Convert.ToInt32(splits[2]);
            int    yPos      = Convert.ToInt32(splits[3]);
            Color  color     = new Color(Convert.ToInt32(splits[4]), Convert.ToInt32(splits[5]), Convert.ToInt32(splits[6]));
            bool   flipped   = Convert.ToBoolean(splits[7]);

            List <NPC> actors = Game1.CurrentEvent.actors;
            Junimo     junimo = new Junimo(new Vector2(xPos * 64, yPos * 64), -1, false);

            junimo.Name       = actorName;
            junimo.EventActor = true;
            junimo.flip       = flipped;

            IReflectedField <NetColor> colorF = StardustCore.ModCore.ModHelper.Reflection.GetField <NetColor>(junimo, "color", true);
            NetColor c = colorF.GetValue();

            c.R = color.R;
            c.G = color.G;
            c.B = color.B;
            colorF.SetValue(c);

            actors.Add((NPC)junimo);
            ++Game1.CurrentEvent.CurrentCommand; //I've been told ++<int> is more efficient than <int>++;
        }
        public CachedMessageEmojis(IModHelper helper, int numberVanillaEmojis)
        {
            Reflection = helper.Reflection;

            messagesField             = Reflection.GetField <List <ChatMessage> >(Game1.chatBox, "messages");
            cheatHistoryPositionField = Reflection.GetField <int>(Game1.chatBox, "cheatHistoryPosition");
            choosingEmojiField        = Reflection.GetField <bool>(Game1.chatBox, "choosingEmoji");
            emojiMenuIconField        = Reflection.GetField <ClickableTextureComponent>(Game1.chatBox, "emojiMenuIcon");

            formatMessageMethod = Reflection.GetMethod(Game1.chatBox, "formatMessage");
            messageColorMethod  = Reflection.GetMethod(Game1.chatBox, "messageColor");

            PlayerMessageList = new List <PlayerMessage>();

            NumberVanillaEmoji = numberVanillaEmojis;

            chatCommandsIsLoaded = helper.ModRegistry.IsLoaded("cat.chatcommands");
            if (chatCommandsIsLoaded)
            {
                displayLineIndexField    = Reflection.GetField <int>(Game1.chatBox, "displayLineIndex");
                getEndDisplayIndexMethod = Reflection.GetMethod(Game1.chatBox, "GetEndDisplayIndex");
            }

            SubscribeEvents();
        }
Ejemplo n.º 8
0
        public void OnUpdate(object sender, EventArgs args)
        {
            if (dialogActions.Count < 1 && !wait)
            {
                GameEvents.EighthUpdateTick -= OnUpdate;
            }

            if (wait && waitTickCount >= 0)
            {
                waitTickCount--;
            }
            else
            {
                wait = false;
            }

            if (waitTickCount == 3)
            {
                FinishTextPrinting();
            }

            if (waitTickCount == 0)
            {
                waitAction?.Invoke();
            }

            if (Game1.activeClickableMenu is DialogueBox dialogueBox && !ReferenceEquals(dialogueBox, previousDialogBox))
            {
                previousDialogBox  = dialogueBox;
                transitioningField = helper.Reflection.GetField <bool>(Game1.activeClickableMenu, "transitioning");
            }
Ejemplo n.º 9
0
        public Ping(Farmer player, Vector2 position, string locationName, Color color)
        {
            this.Player       = player;
            this.Position     = position;
            this.LocationName = locationName;
            this.PingColor    = color;

            Vector2 mapPos = Utility.getTopLeftPositionForCenteringOnScreen(Sprites.Map.SourceRectangle.Width * Game1.pixelZoom, Sprites.Map.SourceRectangle.Height * Game1.pixelZoom, 0, 0);

            Vector2 pingArrowPos = new Vector2((mapPos.X + Position.X) - (Sprites.VanillaPingArrow.SourceRectangle.Width * Game1.pixelZoom) / 2, (mapPos.Y + Position.Y) - arrowSpritePeriodicRange - Sprites.VanillaPingArrow.SourceRectangle.Height * Game1.pixelZoom);

            // // Original texture
            //AnimatedIcon = new TemporaryAnimatedSprite(Sprites.VanillaPingArrow.AssetName, Sprites.VanillaPingArrow.SourceRectangle, 90f, 6, 999999, pingArrowPos, false, false, 0.89f, 0.0f, color, 4f, 0.0f, 0.0f, 0.0f, true) {
            //	yPeriodic = true,
            //	yPeriodicLoopTime = 1500f,
            //	yPeriodicRange = 8f
            //};
            AnimatedArrowSprite = new TemporaryAnimatedSprite(Sprites.VanillaPingArrow.AssetName, Sprites.PingArrow.SourceRectangle, 90f, 6, 999999, pingArrowPos, false, false, 0.89f, 0.0f, color, 4f, 0.0f, 0.0f, 0.0f, true)
            {
                texture           = Sprites.PingArrow.Texture(ModEntry.ModHelper),
                yPeriodic         = true,
                yPeriodicLoopTime = arrowSpriteLoopTime,
                yPeriodicRange    = arrowSpritePeriodicRange
            };

            totalTimerField = ModEntry.ModHelper.Reflection.GetField <float>(AnimatedArrowSprite, "totalTimer");

            Vector2 pingWavePos = new Vector2((mapPos.X + Position.X) - (Sprites.VanillaPingArrow.SourceRectangle.Width * Game1.pixelZoom) / 2, (mapPos.Y + Position.Y) - Sprites.VanillaPingArrow.SourceRectangle.Height * Game1.pixelZoom);

            AnimatedWaveSprite = new TemporaryAnimatedSprite(Sprites.PingWave.AssetName, Sprites.PingWave.SourceRectangle, 150f, 8, 0, pingWavePos, false, Game1.random.NextDouble() < 0.5, 0.001f, 0.01f, Color.White, 0.75f, 3f / 1000f, 0.0f, 0.0f, true);
        }
Ejemplo n.º 10
0
        private void PlayerUsedTool(object sender, UpdateTickedEventArgs e)
        {
            if (Game1.player.UsingTool != UsingToolOnPreviousTick)                                                                                                          //if UsingTool has changed since the previous tick
            {
                UsingToolOnPreviousTick = Game1.player.UsingTool;                                                                                                           //update the "last tick" value

                if (Game1.player.UsingTool && !(Game1.player.CurrentTool is Axe))                                                                                           //if the player stopped using a tool on this tick
                {
                    Vector2   targetTile = new Vector2((int)(Game1.player.GetToolLocation().X / Game1.tileSize), (int)(Game1.player.GetToolLocation().Y / Game1.tileSize)); //get the tile on which the tool was used
                    Rectangle targetBox  = new Rectangle(((int)targetTile.X) * 64, ((int)targetTile.Y) * 64, Game1.tileSize, Game1.tileSize);                               //get a rectangle representing the target tile
                    var       ltf        = Game1.currentLocation.largeTerrainFeatures;                                                                                      //alias the current location's large terrain feature list

                    for (int x = ltf.Count - 1; x >= 0; x--)                                                                                                                //for each large terrain feature at the current location (looping backward for removal purposes)
                    {
                        if (ltf[x] is LargeResourceClump clump)                                                                                                             //if this is a large resource clump
                        {
                            if (clump.getBoundingBox(clump.tilePosition.Value).Intersects(targetBox))                                                                       //if this was hit by the tool
                            {
                                //NOTE: the reflection below prevents a non-fatal error when an Axe or Pickaxe is used for the first time to hit a LargeResourceClump containing a GiantCrop;
                                //      this is due to the "lastUser" field being null during the first use of those tool subclasses
                                IReflectedField <Farmer> lastUser = Utility.Helper.Reflection.GetField <Farmer>(Game1.player.CurrentTool, "lastUser", false); //get the protected "lastUser" field of this tool
                                lastUser?.SetValue(Game1.player);                                                                                             //set "lastUser" to the player

                                clump.performToolAction(Game1.player.CurrentTool, 0, targetTile, Game1.currentLocation);                                      //make the inner ResourceClump react to being hit by the tool
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
        private void Junimo_Lives(object sender, EventArgs args)
        {
            if (!Context.IsWorldReady)
            {
                return;
            }

            if (Game1.currentMinigame is MineCart game)
            {
                IReflectedField <int> livesLeft = this.Helper.Reflection.GetField <int>(game, "livesLeft");
                if (livesLeft != null)
                {
                    if (livesLeft.GetValue() < 3)
                    {
                        livesLeft.SetValue(3);
                        //this.Monitor.Log("Set Cart Lives to 3");
                    }
                    else
                    {
                        return;
                    }
                }
            }
            else
            {
                return;
            }
        }
Ejemplo n.º 12
0
        public AnimalQueryMenuExtended(FarmAnimal farmAnimal) : base(farmAnimal)
        {
            _farmAnimal = farmAnimal;
            if (Context.IsMainPlayer && !DataLoader.ModConfig.DisablePregnancy)
            {
                if (PregnancyController.IsAnimalPregnant(this._farmAnimal.myID.Value))
                {
                    this.allowReproductionButton = null;
                    pregnantStatus = new ClickableTextureComponent(
                        new Microsoft.Xna.Framework.Rectangle(
                            this.xPositionOnScreen + AnimalQueryMenu.width + Game1.pixelZoom * 3,
                            this.yPositionOnScreen + AnimalQueryMenu.height - Game1.tileSize * 2 - IClickableMenu.borderWidth + Game1.pixelZoom,
                            Game1.pixelZoom * 11, Game1.pixelZoom * 11), DataLoader.LooseSprites,
                        new Microsoft.Xna.Framework.Rectangle(34, 29, 11, 11), 4f, false);
                }
            }

            if (Context.IsMainPlayer && !DataLoader.ModConfig.DisableTreats && TreatsController.CanReceiveTreat(farmAnimal))
            {
                if (TreatsController.IsReadyForTreat(farmAnimal))
                {
                    treatStatus = new ClickableTextureComponent(
                        new Microsoft.Xna.Framework.Rectangle(
                            this.xPositionOnScreen + AnimalQueryMenu.width + Game1.tileSize + 4,
                            this.yPositionOnScreen + AnimalQueryMenu.height - Game1.tileSize * 2 - IClickableMenu.borderWidth,
                            Game1.tileSize, Game1.tileSize), DataLoader.ToolsSprites,
                        new Microsoft.Xna.Framework.Rectangle(240, 0, 16, 16), 4f, false);
                }
                else
                {
                    treatStatus = new ClickableTextureComponent(
                        new Microsoft.Xna.Framework.Rectangle(
                            this.xPositionOnScreen + AnimalQueryMenu.width + Game1.tileSize + 4,
                            this.yPositionOnScreen + AnimalQueryMenu.height - Game1.tileSize * 2 - IClickableMenu.borderWidth,
                            Game1.tileSize, Game1.tileSize), DataLoader.LooseSprites,
                        new Microsoft.Xna.Framework.Rectangle(16, 28, 16, 16), 4f, false);
                }
            }

            if (AnimalContestController.IsParticipant(farmAnimal))
            {
                animalContestIndicator = new ClickableTextureComponent(new Microsoft.Xna.Framework.Rectangle(this.xPositionOnScreen + AnimalQueryMenu.width + Game1.tileSize + 4, this.yPositionOnScreen + AnimalQueryMenu.height - Game1.tileSize * 4 - IClickableMenu.borderWidth, Game1.tileSize, Game1.tileSize), DataLoader.ToolsSprites, new Microsoft.Xna.Framework.Rectangle(256, 0, 16, 16), 4f, false);
            }

            if (!DataLoader.ModConfig.DisableMeat && MeatController.CanGetMeatFrom(farmAnimal))
            {
                if (!this._farmAnimal.isBaby())
                {
                    meatButton = new ClickableTextureComponent(new Microsoft.Xna.Framework.Rectangle(this.xPositionOnScreen + AnimalQueryMenu.width + Game1.tileSize + 4, this.yPositionOnScreen + AnimalQueryMenu.height - Game1.tileSize * 3 - IClickableMenu.borderWidth, Game1.tileSize, Game1.tileSize), DataLoader.LooseSprites, new Microsoft.Xna.Framework.Rectangle(0, 28, 16, 16), 4f, false);
                }
            }

            _parentName     = DataLoader.Helper.Reflection.GetField <String>(this, "parentName").GetValue();
            _textBox        = DataLoader.Helper.Reflection.GetField <TextBox>(this, "textBox").GetValue();
            _movingAnimal   = DataLoader.Helper.Reflection.GetField <bool>(this, "movingAnimal");
            _confirmingSell = DataLoader.Helper.Reflection.GetField <bool>(this, "confirmingSell");
            _lovelLevel     = DataLoader.Helper.Reflection.GetField <double>(this, "loveLevel");
            _hoverText      = DataLoader.Helper.Reflection.GetField <string>(this, "hoverText");
        }
Ejemplo n.º 13
0
        private void GetFields()
        {
            AlphaField    = ModEntry.Instance.Helper.Reflection.GetField <float>(this, "alpha");         // TODO: FIX: CustomBush.AlphaField null after SpaceCore deserialise
            ShakeField    = ModEntry.Instance.Helper.Reflection.GetField <float>(this, "shakeRotation");
            MaxShakeField = ModEntry.Instance.Helper.Reflection.GetField <float>(this, "maxShake");

            ShakeMethod = ModEntry.Instance.Helper.Reflection.GetMethod(this, "shake");
        }
Ejemplo n.º 14
0
 public CalicoJackExitable(int toBet = -1, bool highStakes = false)
 {
     game                = new CalicoJack(toBet, highStakes);
     this.toBet          = toBet;
     this.highStakes     = highStakes;
     playAgain           = M.Helper.Reflection.GetField <ClickableComponent>(game, "playAgain").GetValue();
     showingResultScreen = M.Helper.Reflection.GetField <bool>(game, "showingResultsScreen");
 }
Ejemplo n.º 15
0
        /// <summary>Render the UI.</summary>
        /// <param name="spriteBatch">The sprite batch being drawn.</param>
        public override void draw(SpriteBatch spriteBatch)
        {
            // disable when game is using immediate sprite sorting
            if (!ValidatedDrawMode)
            {
                IReflectedField <SpriteSortMode> sortModeField =
                    ClimatesOfFerngill.Reflection.GetField <SpriteSortMode>(Game1.spriteBatch, "spriteSortMode", required: false) // XNA
                    ?? ClimatesOfFerngill.Reflection.GetField <SpriteSortMode>(Game1.spriteBatch, "_sortMode");                   // MonoGame
                if (sortModeField.GetValue() == SpriteSortMode.Immediate)
                {
                    ClimatesOfFerngill.Logger.Log("Aborted the weather draw because the game's current rendering mode isn't compatible with the mod's UI. This only happens in rare cases (e.g. the Stardew Valley Fair).", LogLevel.Warn);
                    exitThisMenu(playSound: false);
                    return;
                }
                ValidatedDrawMode = true;
            }

            // calculate dimensions
            int       x             = xPositionOnScreen;
            int       y             = yPositionOnScreen;
            const int gutter        = 15;
            float     leftOffset    = gutter;
            float     topOffset     = gutter;
            float     contentWidth  = width - gutter * 2;
            float     contentHeight = height - gutter * 2;

            // get font
            SpriteFont font       = Game1.smallFont;
            float      lineHeight = font.MeasureString("ABC").Y;

            //at this point I'm going to manually put this in as I don't need in many places,
            // and I kinda want to have this where I can understand what it's for
            float spaceWidth = DrawHelper.GetSpaceWidth(font);

            // draw background
            // (This uses a separate sprite batch because it needs to be drawn before the
            // foreground batch, and we can't use the foreground batch because the background is
            // outside the clipping area.)
            spriteBatch.DrawSprite(Sprites.Letter.Sheet, Sprites.Letter.Sprite, x, y, scale: width / (float)Sprites.Letter.Sprite.Width);

            // begin draw

            // draw weather icon
            spriteBatch.Draw(IconSheet.WeatherSource, new Vector2(x + leftOffset, y + topOffset), Sprites.Icons.GetWeatherSprite(CurrentWeather.GetCurrentConditions()), Color.White);
            leftOffset += 72;

            // draw text as sent from outside the menu

            float wrapWidth = width - leftOffset - gutter;

            {
                Vector2 textSize = spriteBatch.DrawTextBlock(font, MenuText, new Vector2(x + leftOffset, y + topOffset), wrapWidth);
                topOffset += textSize.Y + lineHeight;
            }


            drawMouse(Game1.spriteBatch);
        }
        public static void CaskMachine(object __instance)
        {
            IReflectedField <Dictionary <int, float> > agingRates = CustomCaskModEntry.Helper.Reflection.GetField <Dictionary <int, float> >(__instance, "AgingRates");

            foreach (var keyValuePair in DataLoader.CaskDataId)
            {
                agingRates.GetValue()[keyValuePair.Key] = keyValuePair.Value;
            }
        }
Ejemplo n.º 17
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="gameServer">The underlying game server.</param>
 /// <param name="reflection">Simplifies access to private code.</param>
 /// <param name="readFarmer">A method which reads farmer data from the given binary reader.</param>
 /// <param name="onProcessingMessage">A callback to raise when receiving a message. This receives the server instance, raw/parsed incoming message, and a callback to run the default logic.</param>
 /// <param name="onSendingMessage">A callback to raise when sending a message. This receives the server instance, outgoing connection, outgoing message, and a callback to run the default logic.</param>
 public SLidgrenServer(IGameServer gameServer, Reflector reflection, Func <BinaryReader, NetFarmerRoot> readFarmer, Action <SLidgrenServer, NetIncomingMessage, IncomingMessage, Action> onProcessingMessage, Action <SLidgrenServer, NetConnection, OutgoingMessage, Action> onSendingMessage)
     : base(gameServer)
 {
     this.ReadFarmer          = readFarmer;
     this.OnProcessingMessage = onProcessingMessage;
     this.OnSendingMessage    = onSendingMessage;
     this.Peers  = reflection.GetField <Bimap <long, NetConnection> >(this, "peers").GetValue();
     this.Server = reflection.GetField <NetServer>(this, "server");
 }
Ejemplo n.º 18
0
 /*
  * Private Methods
  */
 private void GameLoop_TimeChanged(object sender, TimeChangedEventArgs e)
 {
     if (e.NewTime == 2500)
     {
         IReflectedField <int> timePass = this.Helper.Reflection.GetField <int>(typeof(Game1), "timeOfDay");
         timePass.SetValue(2400);
     }
     //throw new NotImplementedException();
 }
Ejemplo n.º 19
0
 public UBush(Vector2 tileLocation, int size, GameLocation location) : base(tileLocation, size, location)
 {
     _shakeLeft       = helper.Reflection.GetField <bool>(this, "shakeLeft");
     _shakeRotation   = helper.Reflection.GetField <float>(this, "shakeRotation");
     _maxShake        = helper.Reflection.GetField <float>(this, "maxShake");
     _lastPlayerToHit = helper.Reflection.GetField <long>(this, "lastPlayerToHit");
     _shakeTimer      = helper.Reflection.GetField <float>(this, "shakeTimer");
     _sourceRect      = helper.Reflection.GetField <Rectangle>(this, "sourceRect");
 }
Ejemplo n.º 20
0
        private void MenuChanged(object sender, MenuChangedEventArgs e)
        {
            var shop = e.NewMenu as StardewValley.Menus.ShopMenu;

            if (shop == null || Game1.currentLocation.Name != "Forest" || !shop.potraitPersonDialogue.Contains("hats"))
            {
                return;
            }

            // no bundles for Joja members
            if (Game1.player.hasOrWillReceiveMail("JojaMember"))
            {
                return;
            }
            CommunityCenter communityCenter = Game1.locations.OfType <CommunityCenter>().First();

            if (communityCenter.areAllAreasComplete())
            {
                return;
            }

            IReflectedField <Dictionary <Item, int[]> > inventoryInformation = this.Helper.Reflection.GetField <Dictionary <Item, int[]> >(shop, "itemPriceAndStock");
            Dictionary <Item, int[]>       itemPriceAndStock  = inventoryInformation.GetValue();
            IReflectedField <List <Item> > forSaleInformation = this.Helper.Reflection.GetField <List <Item> >(shop, "forSale");
            List <Item> forSale = forSaleInformation.GetValue();

            foreach (var bundle in GetBundles())
            {
                if (communityCenter.isBundleComplete(bundle.ID))
                {
                    continue;
                }

                foreach (var ing in bundle.Ingredients)
                {
                    if (communityCenter.bundles[bundle.ID][ing.Index])
                    {
                        continue;
                    }
                    int itemId      = ing.ItemID;
                    var objectToAdd = new StardewValley.Object(Vector2.Zero, itemId, ing.Stack);
                    objectToAdd.Quality = ing.Quality;
                    if (objectToAdd.Name.Contains("rror"))
                    {
                        continue;
                    }
                    itemPriceAndStock.Add(objectToAdd, new int[2] {
                        5000, ing.Stack
                    });
                    forSale.Add(objectToAdd);
                }
            }

            inventoryInformation.SetValue(itemPriceAndStock);
            forSaleInformation.SetValue(forSale);
        }
Ejemplo n.º 21
0
        public static void AutoFishing(BobberBar bar)
        {
            AutoFishingCounter = (AutoFishingCounter + 1) % 3;
            if (AutoFishingCounter > 0)
            {
                return;
            }


            IReflectedField <float> bobberSpeed = Reflection.GetField <float>(bar, "bobberBarSpeed");

            float barPos               = Reflection.GetField <float>(bar, "bobberBarPos").GetValue();
            int   barHeight            = Reflection.GetField <int>(bar, "bobberBarHeight").GetValue();
            float fishPos              = Reflection.GetField <float>(bar, "bobberPosition").GetValue();
            float treasurePos          = Reflection.GetField <float>(bar, "treasurePosition").GetValue();
            float distanceFromCatching = Reflection.GetField <float>(bar, "distanceFromCatching").GetValue();
            bool  treasureCaught       = Reflection.GetField <bool>(bar, "treasureCaught").GetValue();
            bool  treasure             = Reflection.GetField <bool>(bar, "treasure").GetValue();
            float treasureApeearTimer  = Reflection.GetField <float>(bar, "treasureAppearTimer").GetValue();
            float bobberBarSpeed       = bobberSpeed.GetValue();

            float top = barPos;

            if (treasure && treasureApeearTimer <= 0 && !treasureCaught)
            {
                if (!CatchingTreasure && distanceFromCatching > 0.7f)
                {
                    CatchingTreasure = true;
                }
                if (CatchingTreasure && distanceFromCatching < 0.3f)
                {
                    CatchingTreasure = false;
                }
                if (CatchingTreasure)
                {
                    fishPos = treasurePos;
                }
            }

            if (fishPos > barPos + (barHeight / 2f))
            {
                return;
            }

            float strength = (fishPos - (barPos + barHeight / 2f)) / 18f;
            float distance = fishPos - top;

            float threshold = Util.Cap(InstanceHolder.Config.CpuThresholdFishing, 0, 0.5f);

            if (distance < threshold * barHeight || distance > (1 - threshold) * barHeight)
            {
                bobberBarSpeed = strength;
            }

            bobberSpeed.SetValue(bobberBarSpeed);
        }
Ejemplo n.º 22
0
 public BetterSlingshot(IReflectionHelper reflection, BetterSlingshotsConfig config, SObject currentProjectile, bool isActionButtonDown, int which) : base(which)
 {
     this.attachments[0]     = currentProjectile;
     this.reflection         = reflection;
     this.config             = config;
     this.isActionButtonDown = isActionButtonDown;
     this.autoFireRate       = this.GetFireRate();
     this.baseCanPlaySound   = reflection.GetField <bool>(this, "canPlaySound");
     this.isAutomatic        = config.AutomaticSlingshots.IndexOf(Enum.GetName(typeof(SlingshotType), SlingshotManager.GetTypeFromIndex(this.initialParentTileIndex)), StringComparison.InvariantCultureIgnoreCase) != -1;
 }
        /// <summary>Perform any logic needed on update while the animation is active.</summary>
        /// <param name="playerAnimationID">The player's current animation ID.</param>
        public override void Update(int playerAnimationID)
        {
            LoadGameMenu          menu        = (LoadGameMenu)this.Reflection.GetField <IClickableMenu>(typeof(TitleMenu), "_subMenu").GetValue();
            IReflectedField <int> timerToLoad = this.GetTimerToLoad(menu);

            this.ApplySkips(
                run: () => menu.update(Game1.currentGameTime),
                until: () => timerToLoad.GetValue() <= 0
                );
        }
Ejemplo n.º 24
0
        /// <summary>Perform any logic needed on update while the animation is active.</summary>
        /// <param name="playerAnimationID">The player's current animation ID.</param>
        public override void Update(int playerAnimationID)
        {
            LoadGameMenu          menu        = (LoadGameMenu)this.Reflection.GetField <IClickableMenu>(typeof(TitleMenu), "_subMenu").GetValue();
            IReflectedField <int> timerToLoad = this.GetTimerToLoad(menu);

            for (int i = 1; i < this.Multiplier && timerToLoad.GetValue() > 0; i++)
            {
                menu.update(Game1.currentGameTime);
            }
        }
Ejemplo n.º 25
0
        public static void Postfix(Farm __instance)
        {
            IReflectedField <NetRectangle> houseSource      = FarmHouseStates.reflector.GetField <NetRectangle>(__instance, "houseSource");
            IReflectedField <NetRectangle> greenhouseSource = FarmHouseStates.reflector.GetField <NetRectangle>(__instance, "greenhouseSource");

            houseSource.SetValue(new NetRectangle(new Microsoft.Xna.Framework.Rectangle(0, 0, 0, 0)));
            greenhouseSource.SetValue(new NetRectangle(new Microsoft.Xna.Framework.Rectangle(0, 0, 0, 0)));
            FarmState.init();
            FarmState.setUpFarm(__instance);
        }
Ejemplo n.º 26
0
        /// <summary>Get a static field.</summary>
        /// <typeparam name="TValue">The field type.</typeparam>
        /// <param name="type">The type which has the field.</param>
        /// <param name="name">The field name.</param>
        /// <param name="required">Whether to throw an exception if the field is not found.</param>
        public IReflectedField <TValue> GetField <TValue>(Type type, string name, bool required = true)
        {
            // get field from hierarchy
            IReflectedField <TValue> field = this.GetFieldFromHierarchy <TValue>(type, null, name, BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public);

            if (required && field == null)
            {
                throw new InvalidOperationException($"The {type.FullName} object doesn't have a '{name}' static field.");
            }
            return(field);
        }
Ejemplo n.º 27
0
 public void updateStructure(Vector2 tile)
 {
     //seed should remain constant for any tree, so it is tied to their location and whether they are flipped.
     seed   = (int)(tile.X * 100 * tile.Y * Math.PI) * (tree.flipped ? 2 : 3);
     random = new Random(seed);
     Logger.log("Seed is " + seed);
     shakeRotation = Reflector.reflector.GetField <float>(tree, "shakeRotation");
     falling       = Reflector.reflector.GetField <Netcode.NetBool>(tree, "falling");
     buildStructure();
     //treeStructure.draw(Game1.spriteBatch, tile, 0f, 0f);
 }
Ejemplo n.º 28
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="AStarGraph" /> class.
        /// </summary>
        /// <param name="gameLocation">
        ///     The game location associated to this graph.
        /// </param>
        public AStarGraph(GameLocation gameLocation)
        {
            this.gameLocation = gameLocation;

            if (gameLocation is Beach)
            {
                this.oldMariner = ClickToMoveManager.Reflection.GetField <NPC>(gameLocation, "oldMariner");
            }

            this.Init();
        }
Ejemplo n.º 29
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="AStarGraph"/> class.
        /// </summary>
        /// <param name="gameLocation">The game location associated to this graph.</param>
        /// <param name="reflection">Simplifies access to private game code.</param>
        public AStarGraph(GameLocation gameLocation, IReflectionHelper reflection)
        {
            this.GameLocation = gameLocation;
            this.reflection   = reflection;

            if (gameLocation is Beach)
            {
                this.oldMariner = this.reflection.GetField <NPC>(gameLocation, "oldMariner");
            }

            this.Init();
        }
Ejemplo n.º 30
0
        public void SaveEvents_AfterLoad(object sender, EventArgs e)
        {
            //this.Monitor.Log($"SaveEvents_AfterLoad called");

            IReflectedField <NetEvent0> passOutEventField = this.Helper.Reflection.GetField <NetEvent0>(Game1.player, "passOutEvent");
            NetEvent0 passOutEvent = new NetEvent0();

            passOutEvent.onEvent += new NetEvent0.Event(this.performPassOut);
            passOutEventField.SetValue(passOutEvent);

            //this.Monitor.Log($"SaveEvents_AfterLoad ended");
        }