Ejemplo n.º 1
0
 public static NPCUtils.TargetSearchResults SearchForTarget(
     NPC searcher,
     NPCUtils.TargetSearchFlag flags             = NPCUtils.TargetSearchFlag.All,
     NPCUtils.SearchFilter <Player> playerFilter = null,
     NPCUtils.SearchFilter <NPC> npcFilter       = null)
 {
     return(NPCUtils.SearchForTarget(searcher, searcher.Center, flags, playerFilter, npcFilter));
 }
Ejemplo n.º 2
0
 public static NPCUtils.TargetSearchResults SearchForTarget(
     Vector2 position,
     NPCUtils.TargetSearchFlag flags             = NPCUtils.TargetSearchFlag.All,
     NPCUtils.SearchFilter <Player> playerFilter = null,
     NPCUtils.SearchFilter <NPC> npcFilter       = null)
 {
     return(NPCUtils.SearchForTarget((NPC)null, position, flags, playerFilter, npcFilter));
 }
Ejemplo n.º 3
0
        public static NPCUtils.TargetSearchResults SearchForTarget(NPC searcher, Vector2 position, NPCUtils.TargetSearchFlag flags = NPCUtils.TargetSearchFlag.All, NPCUtils.SearchFilter <Player> playerFilter = null, NPCUtils.SearchFilter <NPC> npcFilter = null)
        {
            float num1                 = float.MaxValue;
            int   nearestNPCIndex      = -1;
            float adjustedTankDistance = float.MaxValue;
            float nearestTankDistance  = float.MaxValue;
            int   nearestTankIndex     = -1;

            NPCUtils.TargetType tankType = NPCUtils.TargetType.Player;
            if (flags.HasFlag((Enum)NPCUtils.TargetSearchFlag.NPCs))
            {
                for (int index = 0; index < 200; ++index)
                {
                    NPC entity = Main.npc[index];
                    if (entity.active && (npcFilter == null || npcFilter(entity)))
                    {
                        float num2 = Vector2.DistanceSquared(position, entity.Center);
                        if ((double)num2 < (double)num1)
                        {
                            nearestNPCIndex = index;
                            num1            = num2;
                        }
                    }
                }
            }
            if (flags.HasFlag((Enum)NPCUtils.TargetSearchFlag.Players))
            {
                for (int index = 0; index < (int)byte.MaxValue; ++index)
                {
                    Player entity = Main.player[index];
                    if (entity.active && !entity.dead && !entity.ghost && (playerFilter == null || playerFilter(entity)))
                    {
                        float num2 = Vector2.Distance(position, entity.Center);
                        float num3 = num2 - (float)entity.aggro;
                        bool  flag = searcher != null && entity.npcTypeNoAggro[searcher.type];
                        if (searcher != null && flag && searcher.direction == 0)
                        {
                            num3 += 1000f;
                        }
                        if ((double)num3 < (double)adjustedTankDistance)
                        {
                            nearestTankIndex     = index;
                            adjustedTankDistance = num3;
                            nearestTankDistance  = num2;
                            tankType             = NPCUtils.TargetType.Player;
                        }
                        if (entity.tankPet >= 0 && !flag)
                        {
                            Vector2 center = Main.projectile[entity.tankPet].Center;
                            float   num4   = Vector2.Distance(position, center);
                            float   num5   = num4 - 200f;
                            if ((double)num5 < (double)adjustedTankDistance && (double)num5 < 200.0 && Collision.CanHit(position, 0, 0, center, 0, 0))
                            {
                                nearestTankIndex     = index;
                                adjustedTankDistance = num5;
                                nearestTankDistance  = num4;
                                tankType             = NPCUtils.TargetType.TankPet;
                            }
                        }
                    }
                }
            }
            return(new NPCUtils.TargetSearchResults(searcher, nearestNPCIndex, (float)Math.Sqrt((double)num1), nearestTankIndex, nearestTankDistance, adjustedTankDistance, tankType));
        }
Ejemplo n.º 4
0
        // Token: 0x0600095B RID: 2395 RVA: 0x003B5E64 File Offset: 0x003B4064
        public static NPCUtils.TargetSearchResults SearchForTarget(NPC searcher, Vector2 position, NPCUtils.TargetSearchFlag flags = NPCUtils.TargetSearchFlag.All, NPCUtils.SearchFilter <Player> playerFilter = null, NPCUtils.SearchFilter <NPC> npcFilter = null)
        {
            float num                 = 3.40282347E+38f;
            int   nearestNPCIndex     = -1;
            float num2                = 3.40282347E+38f;
            float nearestTankDistance = 3.40282347E+38f;
            int   nearestTankIndex    = -1;

            NPCUtils.TargetType tankType = NPCUtils.TargetType.Player;
            if (flags.HasFlag(NPCUtils.TargetSearchFlag.NPCs))
            {
                for (int i = 0; i < 200; i++)
                {
                    NPC nPC = Main.npc[i];
                    if (nPC.active && (npcFilter == null || npcFilter(nPC)))
                    {
                        float num3 = Vector2.DistanceSquared(position, nPC.Center);
                        if (num3 < num)
                        {
                            nearestNPCIndex = i;
                            num             = num3;
                        }
                    }
                }
            }
            if (flags.HasFlag(NPCUtils.TargetSearchFlag.Players))
            {
                for (int j = 0; j < 255; j++)
                {
                    Player player = Main.player[j];
                    if (player.active && !player.dead && !player.ghost && (playerFilter == null || playerFilter(player)))
                    {
                        float num4 = Vector2.Distance(position, player.Center);
                        float num5 = num4 - (float)player.aggro;
                        bool  flag = searcher != null && player.npcTypeNoAggro[searcher.type];
                        if ((searcher != null & flag) && searcher.direction == 0)
                        {
                            num5 += 1000f;
                        }
                        if (num5 < num2)
                        {
                            nearestTankIndex    = j;
                            num2                = num5;
                            nearestTankDistance = num4;
                            tankType            = NPCUtils.TargetType.Player;
                        }
                        if (player.tankPet >= 0 && !flag)
                        {
                            Vector2 center = Main.projectile[player.tankPet].Center;
                            num4 = Vector2.Distance(position, center);
                            num5 = num4 - 200f;
                            if (num5 < num2 && num5 < 200f && Collision.CanHit(position, 0, 0, center, 0, 0))
                            {
                                nearestTankIndex    = j;
                                num2                = num5;
                                nearestTankDistance = num4;
                                tankType            = NPCUtils.TargetType.TankPet;
                            }
                        }
                    }
                }
            }
            return(new NPCUtils.TargetSearchResults(searcher, nearestNPCIndex, (float)Math.Sqrt((double)num), nearestTankIndex, nearestTankDistance, num2, tankType));
        }
Ejemplo n.º 5
0
        public static NPCUtils.TargetSearchResults SearchForTargetHook(On.Terraria.Utilities.NPCUtils.orig_SearchForTarget_NPC_Vector2_TargetSearchFlag_SearchFilter1_SearchFilter1 orig, NPC searcher, Vector2 position, NPCUtils.TargetSearchFlag flags = NPCUtils.TargetSearchFlag.All, NPCUtils.SearchFilter <Player> playerFilter = null, NPCUtils.SearchFilter <NPC> npcFilter = null)
        {
            if (IsOrBelongsToNPCID(searcher) == EnemyA)
            {
                if (EnemyB != -1)
                {
                    if (Main.npc[EnemyB].active && FakePlayer.Dummy2Available())
                    {
                        Main.player[FakePlayer2].dead   = false;
                        Main.player[FakePlayer2].Center = Main.npc[EnemyB].Center;
                        return(AnotherDD2TargetSelect(searcher, position, FakePlayer2, flags, npcFilter));
                    }
                }
            }

            if (IsOrBelongsToNPCID(searcher) == EnemyB)
            {
                if (EnemyA != -1)
                {
                    if (Main.npc[EnemyA].active && FakePlayer.Dummy1Available())
                    {
                        Main.player[FakePlayer1].dead   = false;
                        Main.player[FakePlayer1].Center = Main.npc[EnemyA].Center;
                        return(AnotherDD2TargetSelect(searcher, position, FakePlayer1, flags, npcFilter));
                    }
                }
            }
            return(orig.Invoke(searcher, position, flags, playerFilter, npcFilter));
        }
Ejemplo n.º 6
0
        public static NPCUtils.TargetSearchResults AnotherDD2TargetSelect(NPC searcher, Vector2 position, int Target, NPCUtils.TargetSearchFlag flags = NPCUtils.TargetSearchFlag.All, NPCUtils.SearchFilter <NPC> npcFilter = null)
        {
            float nearestNPCDistance          = float.MaxValue;
            int   nearestNPCIndex             = -1;
            float nearestAdjustedTankDistance = float.MaxValue;
            float nearestTankDistance         = float.MaxValue;
            int   nearestTankIndex            = -1;

            NPCUtils.TargetType tankType = NPCUtils.TargetType.Player;


            if (flags.HasFlag(NPCUtils.TargetSearchFlag.Players))
            {
                Player player = Main.player[Target];
                nearestTankIndex            = Target;
                nearestTankDistance         = searcher.Distance(player.Center);
                nearestAdjustedTankDistance = searcher.Distance(player.Center);
                tankType = NPCUtils.TargetType.Player;
            }
            else if (flags.HasFlag(NPCUtils.TargetSearchFlag.NPCs))
            {
                for (int i = 0; i < 200; i++)
                {
                    NPC npc = Main.npc[i];
                    if (npc.active && (npcFilter == null || npcFilter(npc)))
                    {
                        float dist = Vector2.DistanceSquared(position, npc.Center);
                        if (dist < nearestNPCDistance)
                        {
                            nearestNPCIndex    = i;
                            nearestNPCDistance = dist;
                        }
                    }
                }
            }


            return(new NPCUtils.TargetSearchResults(searcher, nearestNPCIndex, (float)Math.Sqrt(nearestNPCDistance), nearestTankIndex, nearestTankDistance, nearestAdjustedTankDistance, tankType));
        }