Пример #1
0
        ////////////////

        public WormholeManager()
        {
            switch (WorldHelpers.GetSize())
            {
            case WorldSize.SubSmall:
                WormholeManager.PortalCount = WormholesConfig.Instance.TinyWorldPortals;
                break;

            case WorldSize.Small:
                WormholeManager.PortalCount = WormholesConfig.Instance.SmallWorldPortals;
                break;

            case WorldSize.Medium:
                WormholeManager.PortalCount = WormholesConfig.Instance.MediumWorldPortals;
                break;

            case WorldSize.Large:
                WormholeManager.PortalCount = WormholesConfig.Instance.LargeWorldPortals;
                break;

            case WorldSize.SuperLarge:
                WormholeManager.PortalCount = WormholesConfig.Instance.HugeWorldPortals;
                break;
            }

            this.Links = new List <WormholeLink>(WormholeManager.PortalCount);
        }
Пример #2
0
        public override void PreUpdate()
        {
            var mymod = ResetModeMod.Instance;
            ResetModeSessionData sessData = mymod.Session?.Data;

            if (sessData == null)
            {
                LogHelpers.WarnOnce("No session data.");
            }

            if (sessData.IsRunning)
            {
                if (!sessData.AwaitingNextWorld)
                {
                    string worldId = WorldHelpers.GetUniqueIdForCurrentWorld(true);

                    if (sessData.CurrentSessionedWorldId == "")
                    {
                        LogHelpers.WarnOnce("Invalid world session state - No world id (world id: " + worldId + ")\n"
                                            + mymod.Session.DataOnLoad.ToString());
                    }
                    else if (sessData.CurrentSessionedWorldId != worldId)
                    {
                        LogHelpers.WarnOnce("Invalid world session state - Mismatched world id "
                                            + "(" + sessData.CurrentSessionedWorldId + " vs " + worldId + ")\n"
                                            + mymod.Session.DataOnLoad.ToString());
                    }
                }
            }
        }
        public bool EndSession()
        {
            var mymod = ResetModeMod.Instance;

            if (Main.netMode == 1)
            {
                throw new Exception("Clients cannot call this.");
            }

            // Already ended?
            if (!this.Data.IsRunning)
            {
                LogHelpers.Alert("Already stopped.");
                return(false);
            }

            if (mymod.Config.DebugModeInfo)
            {
                string worldId = WorldHelpers.GetUniqueIdForCurrentWorld(true);
                LogHelpers.Alert("Sets ALL session data to defaults, stops all TimeLimit \"reset\" commands (world id: " + worldId + ")");
            }

            this.IsExiting = false;
            this.Data.ResetAll();
            this.Save();

            if (Main.netMode == 2)
            {
                SessionProtocol.SyncToClients();
            }

            this.ResetCurrentWorldForSession();

            return(true);
        }
Пример #4
0
        ////////////////

        public WormholeManager(WormholesMod mymod)
        {
            switch (WorldHelpers.GetSize())
            {
            case WorldSize.SubSmall:
                WormholeManager.PortalCount = mymod.Config.Data.TinyWorldPortals;
                break;

            case WorldSize.Small:
                WormholeManager.PortalCount = mymod.Config.Data.SmallWorldPortals;
                break;

            case WorldSize.Medium:
                WormholeManager.PortalCount = mymod.Config.Data.MediumWorldPortals;
                break;

            case WorldSize.Large:
                WormholeManager.PortalCount = mymod.Config.Data.LargeWorldPortals;
                break;

            case WorldSize.SuperLarge:
                WormholeManager.PortalCount = mymod.Config.Data.HugeWorldPortals;
                break;
            }

            this.Links = new List <WormholeLink>(WormholeManager.PortalCount);
        }
Пример #5
0
        ////////////////

        public override void Initialize()
        {
            WorldSize size = WorldHelpers.GetSize();

            switch (size)
            {
            default:
            case WorldSize.SubSmall:
                this.MaxAmbushes = AmbushesMod.Config.TinyWorldInitialAmbushes;
                break;

            case WorldSize.Small:
                this.MaxAmbushes = AmbushesMod.Config.SmallWorldInitialAmbushes;
                break;

            case WorldSize.Medium:
                this.MaxAmbushes = AmbushesMod.Config.MediumWorldInitialAmbushes;
                break;

            case WorldSize.Large:
                this.MaxAmbushes = AmbushesMod.Config.LargeWorldInitialAmbushes;
                break;

            case WorldSize.SuperLarge:
                this.MaxAmbushes = AmbushesMod.Config.HugeWorldInitialAmbushes;
                break;
            }

            this.AmbushMngr = new AmbushManager(size);
        }
Пример #6
0
        public override void ModifyWorldGenTasks(List <GenPass> tasks, ref float totalWeight)
        {
            if (!MMMConfig.Instance.GenerateMountedMirrorsForNewWorlds)
            {
                return;
            }

            int mirrors;

            switch (WorldHelpers.GetSize())
            {
            default:
            case WorldSize.SubSmall:
                mirrors = MMMConfig.Instance.TinyWorldMirrors;
                break;

            case WorldSize.Small:
                mirrors = MMMConfig.Instance.SmallWorldMirrors;
                break;

            case WorldSize.Medium:
                mirrors = MMMConfig.Instance.MediumWorldMirrors;
                break;

            case WorldSize.Large:
                mirrors = MMMConfig.Instance.LargeWorldMirrors;
                break;

            case WorldSize.SuperLarge:
                mirrors = MMMConfig.Instance.HugeWorldMirrors;
                break;
            }

            tasks.Add(new MountedMirrorsGenPass(mirrors));
        }
Пример #7
0
        public MapLayer(int[] map, int width, int height, int layer)
        {
            Layer      = layer;
            Map        = new int[width, height];
            Bouncers   = new List <Node> [width, height];
            Walls      = new List <Rail> [width, height];
            Water      = new List <Rectangle> [width, height];
            Teleports  = new List <KeyValuePair <Rectangle, List <Rectangle> > > [width, height];
            Elevations = new Elevation[width, height];
            var i = 0;

            for (int r = 0; r < height; r++)
            {
                for (var c = 0; c < width; c++)
                {
                    Map[c, r]        = map[i];
                    Bouncers[c, r]   = WorldHelpers.AddBouncerNodes(WorldHelpers.GetBouncers(map[i]), layer);
                    Walls[c, r]      = WorldHelpers.AddWallRails(WorldHelpers.GetLineSegments(map[i]), layer);
                    Water[c, r]      = WorldHelpers.GetWater(map[i]);
                    Teleports[c, r]  = WorldHelpers.GetTeleports(map[i]);
                    Elevations[c, r] = WorldHelpers.GetElevation(map[i]);
                    if (Layer == 2 && Elevations[c, r] != Elevation.Flat)
                    {
                        throw new Exception("Yeah nah we can only have elevations on layer 1");
                    }
                    i++;
                }
            }
            Width  = width;
            Height = height;
        }
        internal void Begin()
        {
            if (!this.HasEnteredWorld)
            {
                throw new ModHelpersException("Cannot begin game if player hasn't joined game.");
            }

            this.BegunWorldIds.Add(WorldHelpers.GetUniqueIdForCurrentWorld(true));
        }
        ////////////////

        internal bool HasBegunCurrentWorld()
        {
            if (!this.HasEnteredWorld)
            {
                throw new ModHelpersException("Cannot check if game is running for player if player hasn't joined game.");
            }

            return(this.BegunWorldIds.Contains(WorldHelpers.GetUniqueIdForCurrentWorld(true)));
        }
Пример #10
0
        public void LoadKillData()
        {
            var  mymod   = RewardsMod.Instance;
            bool success = this.WorldData.Load(this.GetDataFileBaseName());

            if (mymod.SettingsConfig.DebugModeInfo || mymod.SettingsConfig.DebugModeKillInfo)
            {
                LogHelpers.Alert("World id: " + WorldHelpers.GetUniqueIdForCurrentWorld(true) + ", success: " + success + ", " + this.WorldData.ToString());
            }
        }
Пример #11
0
        ////

        protected override Ambush CloneRandomized(int tileX, int tileY)
        {
            bool isEntrapping = AmbushesMod.Config.AmbushEntrapmentOdds <= 0
                                ? false
                                : TmlHelpers.SafelyGetRand().Next(AmbushesMod.Config.AmbushEntrapmentOdds) == 0;

            isEntrapping = isEntrapping && !WorldHelpers.IsWithinUnderworld(new Vector2(tileX << 4, tileY << 4));

            return(new FlyerSwarmAmbush(tileX, tileY, isEntrapping));
        }
Пример #12
0
 private void UpdateTileDefs()
 {
     Rails        = WorldHelpers.AddWallRails(WorldHelpers.GetLineSegments(CurrentTile), 1);
     SpecialRails = WorldHelpers.AddWallRails(WorldHelpers.GetLineSpecialSegments(CurrentTile, new Point(-1, -1)), 1);
     Bouncers     = WorldHelpers.AddBouncerNodes(WorldHelpers.GetBouncers(CurrentTile), 1);
     Water        = WorldHelpers.GetWater(CurrentTile);
     Teleporters  = WorldHelpers.GetTeleporters(CurrentTile);
     Elevation    = WorldHelpers.GetElevation(CurrentTile);
     Connections  = WorldHelpers.GetSideConnections(CurrentTile);
 }
Пример #13
0
        ////////////////

        public string GetDataFileBaseName()
        {
            if (RewardsMod.Instance.SettingsConfig.UseUpdatedWorldFileNameConvention)
            {
                return(WorldHelpers.GetUniqueIdForCurrentWorld(true));
            }
            else
            {
                return("World_" + FileHelpers.SanitizePath(Main.worldName) + "_" + Main.worldID);
            }
        }
Пример #14
0
        ////////////////

        public override float SpawnChance(NPCSpawnInfo spawnInfo)
        {
            if (Timers.GetTimerTickDuration("IntrinsicsGhostExists") <= 0)
            {
                if (WorldHelpers.IsRockLayer(spawnInfo.player.position))
                {
                    var mymod = (IntrinsicsMod)this.mod;
                    return(mymod.Config.GhostNpcSpawnChance);
                }
            }
            return(0f);
        }
        ////////////////

        private void UpdateGame()
        {
            var    mymod   = ResetModeMod.Instance;
            string worldId = WorldHelpers.GetUniqueIdForCurrentWorld(true);

            if (this.IsSessionNeedingWorld())
            {
                if (mymod.Config.DebugModeInfo)
                {
                    LogHelpers.Alert("Session needs a world (current world id: " + worldId + ")");
                }

                if (this.HasWorldEverBeenPlayed(worldId))
                {
                    //if( Main.netMode != 2 ) {   // Servers should just indefinitely boot people until closed; stopgap measure
                    this.GoodExit();
                }
                else
                {
                    this.BeginResetTimer();
                    this.AddWorldToSession();                        // Changes world status
                }
            }
            else if (this.IsSessionedWorldNotOurs())
            {
                if (mymod.Config.DebugModeInfo)
                {
                    LogHelpers.Alert("World has expired (current world id: " + worldId + "). Session data: " + this.Data.ToString());
                }

                if (mymod.Config.WrongWorldForcesHardReset)
                {
                    if (mymod.Config.DebugModeInfo)
                    {
                        LogHelpers.Alert("WrongWorldForcesHardReset == true. Sets AwaitingNextWorld=true, CurrentSessionedWorldId=\"\"");
                    }
                    this.Data.AwaitingNextWorld       = true;
                    this.Data.CurrentSessionedWorldId = "";
                    this.Save();
                }

                if (this.HasWorldEverBeenPlayed(worldId))
                {
                    this.GoodExit();
                }
                else
                {
                    this.BadExit();
                }
            }
        }
Пример #16
0
        ////////////////

        public override void Initialize()
        {
            var mymod = (ModHelpersMod)this.mod;

            this.ObsoleteId    = Guid.NewGuid().ToString("D");
            this.ObsoleteId2   = WorldHelpers.GetUniqueId(false);
            this.HasObsoleteId = false;              // 'Load()' decides if no pre-existing one is found

            this.WorldLogic = new WorldLogic();

            if (String.IsNullOrEmpty(this.ObsoleteId2))
            {
                throw new HamstarException("UID not defined.");
            }
        }
Пример #17
0
        ////

        public static void Eject(Player player)
        {
            var mymod = ResetModeMod.Instance;

            if (mymod.Session.HasWorldEverBeenPlayed(WorldHelpers.GetUniqueIdForCurrentWorld(true)))
            {
                LogHelpers.Log("Ejecting player " + Main.LocalPlayer.name + " via good exit...");
                mymod.Session.GoodExit();
            }
            else
            {
                LogHelpers.Log("Ejecting player " + Main.LocalPlayer.name + " via bad exit...");
                mymod.Session.BadExit();
            }
        }
Пример #18
0
        private void LoadDataSources()
        {
            DataDumper.SetDumpSource("WorldUidWithSeed", () => {
                return("  " + WorldHelpers.GetUniqueIdForCurrentWorld(true) + " (net mode: " + Main.netMode + ")");
            });

            DataDumper.SetDumpSource("PlayerUid", () => {
                if (Main.myPlayer < 0 || Main.myPlayer >= (Main.player.Length - 1))
                {
                    return("  Unobtainable");
                }

                return("  " + PlayerIdentityHelpers.GetUniqueId());
            });
        }
Пример #19
0
        public override void EditSpawnPool(IDictionary <int, float> pool, NPCSpawnInfo spawnInfo)
        {
            if (Main.gameMenu)
            {
                return;
            }

            if (!DynamicInvasionsMod.Config.Enabled)
            {
                return;
            }
            var myworld = ModContent.GetInstance <DynamicInvasionsWorld>();

            if (myworld.Logic.HasInvasionFinishedArriving() && WorldHelpers.IsAboveWorldSurface(spawnInfo.player.position))
            {
                myworld.Logic.EditSpawnPool(pool, spawnInfo);
            }
        }
        private void LoadDataSources()
        {
            DataDumper.SetDumpSource("WorldUidWithSeed", () => {
                return("  " + WorldHelpers.GetUniqueIdWithSeed() + " (net mode: " + Main.netMode + ")");
            });

            DataDumper.SetDumpSource("PlayerUid", () => {
                if (Main.myPlayer < 0 || Main.myPlayer >= (Main.player.Length - 1))
                {
                    return("  Unobtainable");
                }

                bool _;
                string oldUid = PlayerIdentityHelpers._GetUniqueId(Main.LocalPlayer, out _);

                return("  " + PlayerIdentityHelpers.GetMyProperUniqueId() + " (old uid: " + oldUid + ")");
            });
        }
Пример #21
0
        public Map(Golf game, TileSet tileSet, MapLayer layer1, MapLayer layer2, int columns, int rows, Vector2 start, Side startStartSide, int startLayer, Vector2 end, Side endEndSide, int endLayer, List <Player> players, int currentPlayer, Procedure <Map> endLevel)
        {
            Game       = game;
            EndLevel   = endLevel;
            ColorTween = new Tween(new TimeSpan(0, 0, 0, 1), 0.0f, 0.8f, true);
            //TileSet = tileSet;
            Layer1           = layer1;
            Layer2           = layer2;
            Columns          = columns;
            Start            = start;
            StartSide        = startStartSide;
            StartLayer       = startLayer;
            StartWorldCenter =
                new Vector2(Math.Max(Start.X, 0) * TileSet.TileWidth,
                            Math.Max(Start.Y, 0) * TileSet.TileHeight) + WorldHelpers.GetStartOffset(StartSide);
            End            = end;
            EndSide        = endEndSide;
            EndLayer       = endLayer;
            EndWorldCenter =
                new Vector2(Math.Max(End.X, 0) * TileSet.TileWidth,
                            Math.Max(End.Y, 0) * TileSet.TileHeight) + WorldHelpers.GetEndOffset(EndSide);

            Players       = players;
            CurrentPlayer = currentPlayer;
            Rows          = rows;

            Camera = new Camera2D();
            if (!Players.Any())
            {
                return;
            }
            foreach (var p in Players)
            {
                p.Node              = new Node(new Vector2(Math.Max(Start.X, 0) * tileSet.TileWidth, Math.Max(Start.Y, 0) * tileSet.TileHeight) + WorldHelpers.GetStartOffset(StartSide), 2.5f, 1, Vector2.Zero, Vector2.Zero, startLayer);
                p.LastTile          = GetPlayerTile(p);
                p.PreviousTile      = p.LastTile;
                p.Layer             = startLayer;
                p.Node.OnCollision += PlayBounce;
                p.State             = PlayerState.Finished;
                p.Par = -1;
            }
            Camera.Focus = Game.Center - Players[CurrentPlayer].Position;
            Players[CurrentPlayer].Start();
        }
Пример #22
0
        public void DrawMap(SpriteBatch batch, Vector2 posistion)
        {
            posistion += Camera.Position;
            var yOffset = posistion.Y;

            for (var y = 0; y < Rows; y++)
            {
                var xOffset = posistion.X;
                for (var x = 0; x < Columns; x++)
                {
                    var offset = new Vector2(xOffset, yOffset);
                    TileSet.DrawTile(batch, Layer1.GetTile(x, y), offset, posistion, null, 0.4f);
                    if (x == (int)Start.X && y == (int)Start.Y)
                    {
                        TileSet.DrawTile(batch, WorldHelpers.GetStartTile(StartSide), offset, posistion, null, 0.45f);
                    }
                    if (x == (int)End.X && y == (int)End.Y)
                    {
                        TileSet.DrawTile(batch, WorldHelpers.GetEndTile(EndSide), offset, posistion, null, 0.45f);
                    }
                    foreach (var p in Players)
                    {
                        p.Draw(batch, posistion);
                    }

                    TileSet.DrawTileBridges(batch, Layer1.GetTile(x, y), offset, posistion, null, 0.6f);


                    TileSet.DrawTile(batch, Layer2.GetTile(x, y), offset, posistion, Players, 0.7f);
                    TileSet.DrawTileBridges(batch, Layer2.GetTile(x, y), offset, posistion, null, 0.9f);
                    xOffset += TileSet.TileWidth;
                    if (xOffset > Game.Width)
                    {
                        break;
                    }
                }
                yOffset += TileSet.TileHeight;
                if (yOffset > Game.Height)
                {
                    break;
                }
            }
        }
Пример #23
0
        public override void EditSpawnRate(Player player, ref int spawnRate, ref int maxSpawns)
        {
            if (Main.gameMenu)
            {
                return;
            }

            if (!DynamicInvasionsMod.Config.Enabled)
            {
                return;
            }
            var myworld = ModContent.GetInstance <DynamicInvasionsWorld>();

            if (myworld.Logic.HasInvasionFinishedArriving() && WorldHelpers.IsAboveWorldSurface(player.position))
            {
                spawnRate = DynamicInvasionsMod.Config.InvasionSpawnRate;
                maxSpawns = DynamicInvasionsMod.Config.InvasionSpawnMax;
            }
        }
Пример #24
0
        public void AddWorldToSession()
        {
            var    mymod   = ResetModeMod.Instance;
            string worldId = WorldHelpers.GetUniqueIdForCurrentWorld(true);

            if (mymod.Config.DebugModeInfo)
            {
                LogHelpers.Alert("Sets AllPlayedWorlds.Add(<world id>), CurrentSessionedWorldId=<world id>, AwaitingNextWorld=false (worldId: " + worldId + ")");
            }

            this.Data.AllPlayedWorlds.Add(worldId);
            this.Data.CurrentSessionedWorldId = worldId;
            this.Data.AwaitingNextWorld       = false;
            if (Main.netMode != 1)
            {
                this.Save();
            }

            this.RunModCalls();
        }
        internal void Update()
        {
            var mymod = ResetModeMod.Instance;

            if (mymod.Config.DebugModeRealTimeInfo)
            {
                string worldId  = WorldHelpers.GetUniqueIdForCurrentWorld(true);
                var    myplayer = (ResetModePlayer)TmlHelpers.SafelyGetModPlayer(Main.LocalPlayer, mymod, "ResetModePlayer");

                DebugHelpers.Print("ResetModeSession",
                                   "Is running? " + this.Data.IsRunning
                                   + ", Exiting? " + this.IsExiting
                                   + ", Needs world? " + this.IsSessionNeedingWorld()
                                   + ", World id: " + worldId
                                   + ", Been played? " + this.HasWorldEverBeenPlayed(worldId), 20);
                DebugHelpers.Print("ResetModePlayer",
                                   "IsPromptingForResetOnLocal? " + myplayer.Logic.IsPromptingForResetOnLocal
                                   + ", IsSynced? " + myplayer.IsSynced
                                   + ", HasModSettings? " + myplayer.HasModSettings
                                   + ", HasSessionData? " + myplayer.HasSessionData, 20);
            }

            if (this.Data.IsRunning && !this.IsExiting)
            {
                if (Main.netMode == 0)
                {
                    this.UpdateSingle();
                }
                else if (Main.netMode == 1)
                {
                    this.UpdateClient();
                }
                else
                {
                    this.UpdateServer();
                }
            }
        }
Пример #26
0
        public override bool CheckDead(NPC npc)
        {
            if (Main.gameMenu)
            {
                return(base.CheckDead(npc));
            }

            if (!DynamicInvasionsMod.Config.Enabled)
            {
                return(base.CheckDead(npc));
            }
            var modworld = ModContent.GetInstance <DynamicInvasionsWorld>();

            if (modworld.Logic.HasInvasionFinishedArriving() && WorldHelpers.IsAboveWorldSurface(npc.position))
            {
                if (npc.life <= 0)
                {
                    modworld.Logic.InvaderKilled(npc);
                }
            }

            return(base.CheckDead(npc));
        }
Пример #27
0
        public void SaveEveryonesKillData()
        {
            var mymod = RewardsMod.Instance;

            if (mymod.SettingsConfig.DebugModeInfo || mymod.SettingsConfig.DebugModeKillInfo)
            {
                LogHelpers.Alert("World id: " + WorldHelpers.GetUniqueIdForCurrentWorld(true) + ", " + this.WorldData.ToString());
            }

            for (int i = 0; i < Main.player.Length; i++)
            {
                Player player = Main.player[i];
                if (player == null || !player.active)
                {
                    continue;
                }

                var myplayer = (RewardsPlayer)TmlHelpers.SafelyGetModPlayer(player, mymod, "RewardsPlayer");
                myplayer.SaveKillData();
            }

            this.WorldData.Save(this.GetDataFileBaseName());
        }
Пример #28
0
        ////////////////

        public static bool AreSpamProjectileLikelyToExist()
        {
            var  config       = UPMod.Instance.Config;
            bool unclutBoss   = config.UnclutterDuringBosses;
            bool unclutEclip  = config.UnclutterDuringEclipses;
            bool unclutInvas  = config.UnclutterDuringInvasions;
            bool unclutLunar  = config.UnclutterDuringLunarApocalypse;
            bool isBossActive = UPNpc.IsAnyBossActive();

            if (unclutBoss && !isBossActive)                                      // No boss active?
            {
                if (!WorldHelpers.IsAboveWorldSurface(Main.LocalPlayer.position)) // Not above world surface?
                {
                    return(false);
                }
            }

            return((unclutBoss && isBossActive) ||
                   (unclutEclip && Main.eclipse) ||
                   (unclutInvas && Main.invasionType != 0) ||
                   (unclutInvas && Main.pumpkinMoon) ||
                   (unclutInvas && Main.snowMoon) ||
                   (unclutLunar && NPC.LunarApocalypseIsUp));
        }
Пример #29
0
        public override bool PreNPCLoot(NPC npc)
        {
            if (Main.gameMenu)
            {
                return(base.PreNPCLoot(npc));
            }

            if (!DynamicInvasionsMod.Config.Enabled)
            {
                return(base.PreNPCLoot(npc));
            }

            var myworld = ModContent.GetInstance <DynamicInvasionsWorld>();

            bool hasInvasionArrived = myworld.Logic.HasInvasionFinishedArriving();
            bool isAboveSurface     = WorldHelpers.IsAboveWorldSurface(npc.position);

            if (hasInvasionArrived && isAboveSurface)
            {
                float chancePercent = DynamicInvasionsMod.Config.InvaderLootDropPercentChance;
                return(Main.rand.NextFloat() < chancePercent);
            }
            return(base.PreNPCLoot(npc));
        }
Пример #30
0
        ////////////////

        private Item AccountForPurchase(Player player, long spent, Item lastBuyItem)
        {
            NPC talkNpc = Main.npc[player.talkNPC];

            if (talkNpc == null || !talkNpc.active)
            {
                LogHelpers.Log("AccountForPurchase - No shop npc.");
                return(null);
            }

            var        mymod             = CapitalismMod.Instance;
            ISet <int> possiblePurchases = ItemFinderHelpers.FindPossiblePurchaseTypes(player.inventory, spent);
            Item       item  = null;
            int        stack = 1;

            if (possiblePurchases.Count > 0)
            {
                var changesAt = PlayerItemFinderHelpers.FindInventoryChanges(player, this.PrevMouseInfo, this.PrevInventoryInfos);
                changesAt = ItemFinderHelpers.FilterByTypes(changesAt, possiblePurchases);

                if (changesAt.Count == 1)
                {
                    foreach (var entry in changesAt)
                    {
                        if (entry.Key == -1)
                        {
                            item = Main.mouseItem;
                        }
                        else
                        {
                            item = player.inventory[entry.Key];
                        }

                        if (item != null)
                        {
                            // Must be a false positive?
                            if (lastBuyItem != null && lastBuyItem.type != item.type)
                            {
                                item = null;
                            }
                            else
                            {
                                //stack = entry.Value.Value;
                                break;
                            }
                        }
                    }
                }
            }
            if (item == null)
            {
                if (lastBuyItem != null)
                {
                    var vendor = this.GetOrCreateVendor(WorldHelpers.GetUniqueIdForCurrentWorld(true), talkNpc.type);
                    int value  = (int)vendor.GetPriceOf(lastBuyItem.type);

                    if ((spent % value) == 0)
                    {
                        item  = lastBuyItem;
                        stack = (int)(spent / value);
                    }
                }
            }

            if (item != null)
            {
                this.BoughtFrom(player, talkNpc, item, stack);
            }
            return(item);
        }