Exemple #1
0
 public TargetSearchResults(NPC searcher, int nearestNPCIndex, float nearestNPCDistance, int nearestTankIndex, float nearestTankDistance, float adjustedTankDistance, NPCUtils.TargetType tankType)
 {
     this._nearestNPCIndex      = nearestNPCIndex;
     this._nearestNPCDistance   = nearestNPCDistance;
     this._nearestTankIndex     = nearestTankIndex;
     this._adjustedTankDistance = adjustedTankDistance;
     this._nearestTankDistance  = nearestTankDistance;
     this._nearestTankType      = tankType;
     if (this._nearestNPCIndex != -1 && this._nearestTankIndex != -1)
     {
         if ((double)this._nearestNPCDistance < (double)this._adjustedTankDistance)
         {
             this._nearestTargetType = NPCUtils.TargetType.NPC;
         }
         else
         {
             this._nearestTargetType = tankType;
         }
     }
     else if (this._nearestNPCIndex != -1)
     {
         this._nearestTargetType = NPCUtils.TargetType.NPC;
     }
     else if (this._nearestTankIndex != -1)
     {
         this._nearestTargetType = tankType;
     }
     else
     {
         this._nearestTargetType = NPCUtils.TargetType.None;
     }
 }
Exemple #2
0
 // Token: 0x0600095D RID: 2397 RVA: 0x003B60A0 File Offset: 0x003B42A0
 public static void TargetClosestBetsy(NPC searcher, bool faceTarget = true, Vector2?checkPosition = null)
 {
     NPCUtils.TargetSearchResults targetSearchResults = NPCUtils.SearchForTarget(searcher, NPCUtils.TargetSearchFlag.All, null, new NPCUtils.SearchFilter <NPC>(NPCUtils.SearchFilters.OnlyCrystal));
     if (!targetSearchResults.FoundTarget)
     {
         return;
     }
     NPCUtils.TargetType value = targetSearchResults.NearestTargetType;
     if (targetSearchResults.FoundTank && !targetSearchResults.NearestTankOwner.dead)
     {
         value = NPCUtils.TargetType.Player;
     }
     searcher.target     = targetSearchResults.NearestTargetIndex;
     searcher.targetRect = targetSearchResults.NearestTargetHitbox;
     if (searcher.ShouldFaceTarget(ref targetSearchResults, new NPCUtils.TargetType?(value)) & faceTarget)
     {
         searcher.FaceTarget();
     }
 }
Exemple #3
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));
        }
Exemple #4
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));
        }
Exemple #5
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));
        }