コード例 #1
0
        public void QueryModOrigin()
        {
            Point mouseTile = Main.MouseWorld.ToTileCoordinates();

            int   closestNPCIndex    = -1;
            float closestNPCDistance = float.MaxValue;

            for (int l = 0; l < 200; l++)
            {
                if (Main.npc[l].active)
                {
                    float distance = Utils.Distance(Main.npc[l].getRect(), Main.MouseWorld);
                    if (distance < closestNPCDistance)
                    {
                        closestNPCDistance = distance;
                        closestNPCIndex    = l;
                    }
                }
            }

            int   closestItemIndex    = -1;
            float closestItemDistance = float.MaxValue;

            for (int i = 0; i < 400; i++)
            {
                if (Main.item[i].active)
                {
                    float distance = Utils.Distance(Main.item[i].getRect(), Main.MouseWorld);
                    if (distance < closestItemDistance)
                    {
                        closestItemDistance = distance;
                        closestItemIndex    = i;
                    }
                }
            }


            int hoverBuffIndex = -1;
            int hoverBuffID    = -1;

            for (int k = 0; k < 22; k++)
            {
                if (Main.player[Main.myPlayer].buffType[k] > 0)
                {
                    int buffID = Main.player[Main.myPlayer].buffType[k];
                    int buffX  = 32 + k * 38;
                    int buffY  = 76;
                    if (k >= 11)
                    {
                        buffX  = 32 + (k - 11) * 38;
                        buffY += 50;
                    }

                    if (Main.mouseX < buffX + Main.buffTexture[buffID].Width && Main.mouseY <buffY + Main.buffTexture[buffID].Height && Main.mouseX> buffX && Main.mouseY > buffY)
                    {
                        hoverBuffIndex = k;
                        hoverBuffID    = buffID;
                    }
                }
            }

            //Top to Bottom:

            // Hover Buff
            if (hoverBuffIndex > -1 && !Main.playerInventory)
            {
                if (hoverBuffID >= BuffID.Count)
                {
                    ModBuff hoverBuff = BuffLoader.GetBuff(hoverBuffID);
                    Main.NewText("This buff is from: " + hoverBuff.mod.DisplayName);
                    if (HelpfulHotkeysClientConfig.Instance.ShowDeveloperInfoQueryModOrigin)
                    {
                        Main.NewText($"Developer Info: ModName: {hoverBuff.mod.Name}, InternalName: {hoverBuff.Name}, FullName: {hoverBuff.GetType().FullName}");
                    }
                }
                else
                {
                    Main.NewText("This is a vanilla buff.");
                }
            }

            // Item in inventory
            else if (Main.HoverItem.type > 0 && Main.HoverItem != null)
            {
                if (Main.HoverItem.modItem != null)
                {
                    Main.NewText("This item is from: " + Main.HoverItem.modItem.mod.DisplayName);
                    if (HelpfulHotkeysClientConfig.Instance.ShowDeveloperInfoQueryModOrigin)
                    {
                        Main.NewText($"Developer Info: ModName: {Main.HoverItem.modItem.mod.Name}, InternalName: {Main.HoverItem.modItem.Name}, FullName: {Main.HoverItem.modItem.GetType().FullName}");
                    }
                }
                else
                {
                    Main.NewText("This is a vanilla item.");
                    if (HelpfulHotkeysClientConfig.Instance.ShowDeveloperInfoQueryModOrigin)
                    {
                        Main.NewText($"Developer Info: ItemID: {ItemID.Search.GetName(Main.HoverItem.type)}, ItemID#: {Main.HoverItem.type}");
                    }
                }
            }

            // NPC
            else if (closestNPCDistance < 30)
            {
                NPC closestNPC = Main.npc[closestNPCIndex];
                if (closestNPC.modNPC != null)
                {
                    Main.NewText("This npc is from: " + closestNPC.modNPC.mod.DisplayName);
                    if (HelpfulHotkeysClientConfig.Instance.ShowDeveloperInfoQueryModOrigin)
                    {
                        Main.NewText($"Developer Info: ModName: {closestNPC.modNPC.mod.Name}, InternalName: {closestNPC.modNPC.Name}, FullName: {closestNPC.modNPC.GetType().FullName}");
                    }
                }
                else
                {
                    Main.NewText("This is a vanilla npc.");
                    if (HelpfulHotkeysClientConfig.Instance.ShowDeveloperInfoQueryModOrigin)
                    {
                        Main.NewText($"Developer Info: NPCID: {NPCID.Search.GetName(closestNPC.type)}, NPCID#: {closestNPC.type}");
                    }
                }
            }

            // Tile
            else if (Main.tile[mouseTile.X, mouseTile.Y].type >= TileID.Count)
            {
                ModTile modTile = TileLoader.GetTile(Main.tile[mouseTile.X, mouseTile.Y].type);
                Main.NewText("This tile is from: " + modTile.mod.DisplayName);
                if (HelpfulHotkeysClientConfig.Instance.ShowDeveloperInfoQueryModOrigin)
                {
                    Main.NewText($"Developer Info: ModName: {modTile.mod.Name}, InternalName: {modTile.Name}, FullName: {modTile.GetType().FullName}");
                }
                //Main.NewText("This tile is active: " + Main.tile[mouseTile.X, mouseTile.Y].active());
                //Main.NewText("This tile is inactive: " + Main.tile[mouseTile.X, mouseTile.Y].inActive());
                //Main.NewText("This tile is nactive: " + Main.tile[mouseTile.X, mouseTile.Y].nactive());
            }

            // Wall
            else if (Main.tile[mouseTile.X, mouseTile.Y].wall >= WallID.Count)
            {
                ModWall modWall = WallLoader.GetWall(Main.tile[mouseTile.X, mouseTile.Y].wall);
                Main.NewText("This wall is from: " + modWall.mod.DisplayName);
                if (HelpfulHotkeysClientConfig.Instance.ShowDeveloperInfoQueryModOrigin)
                {
                    Main.NewText($"Developer Info: ModName: {modWall.mod.Name}, InternalName: {modWall.Name}, FullName: {modWall.GetType().FullName}");
                }
            }

            // Item on ground
            else if (closestItemDistance < 5)
            {
                if (Main.item[closestItemIndex].modItem != null)
                {
                    ModItem modItem = Main.item[closestItemIndex].modItem;
                    Main.NewText("This item is from: " + modItem.mod.DisplayName);
                    if (HelpfulHotkeysClientConfig.Instance.ShowDeveloperInfoQueryModOrigin)
                    {
                        Main.NewText($"Developer Info: ModName: {modItem.mod.Name}, InternalName: {modItem.Name}, FullName: {modItem.GetType().FullName}");
                    }
                }
                else
                {
                    Main.NewText("This is a vanilla item.");
                    if (HelpfulHotkeysClientConfig.Instance.ShowDeveloperInfoQueryModOrigin)
                    {
                        Main.NewText($"Developer Info: ItemID: {ItemID.Search.GetName(Main.item[closestItemIndex].type)}, ItemID#: {Main.item[closestItemIndex].type}");
                    }
                }
            }

            // How to Use
            else if (true)
            {
                Main.NewText("Hover over an item, npc, tile, or wall to identify which mod it is from.");
            }
        }