Beispiel #1
0
        /// <summary>
        /// This is actually to get possible targets from Terraria, includding also targets from other mods.
        /// </summary>
        public TargetTranslator.Translator[] GetPossibleTargets(bool Allies, bool SelfIncluded = false, Vector2 Position = default(Vector2), float Distance = 0f, int MaxTargets = 0)
        {
            List <TargetTranslator.Translator> Targets = new List <TargetTranslator.Translator>();
            Player me = Main.player[Owner];

            for (int i = 0; i < 255; i++)
            {
                if (Main.player[i].active && (SelfIncluded || i != Owner))
                {
                    bool IsAlly = !Main.player[i].hostile || (me.team != 0 && me.team == Main.player[i].team);
                    if ((Allies && IsAlly) || (!Allies && !IsAlly))
                    {
                        Targets.Add(new TargetTranslator.PlayerTarget(Main.player[i]));
                    }
                }
                if (i < 200 && Main.npc[i].active)
                {
                    bool IsAlly = (Main.npc[i].townNPC || Main.npc[i].friendly);
                    if ((Allies && IsAlly) || (!Allies && !IsAlly))
                    {
                        Targets.Add(new TargetTranslator.NpcTarget(Main.npc[i]));
                    }
                }
            }
            Targets.AddRange(MainMod.GetOtherModTargets(me, Allies));
            if (Position != default(Vector2) && Distance > 0)
            {
                for (int t = 0; t < Targets.Count; t++)
                {
                    if ((Targets[t].Center - Position).Length() >= Distance) //Doesn't seems to work correctly with infos acquired from other mods.
                    {
                        Targets.RemoveAt(t);
                    }
                }
            }
            if (MaxTargets > 0)
            {
                while (Targets.Count > MaxTargets)
                {
                    Targets.RemoveAt(MaxTargets);
                }
            }
            return(Targets.ToArray());
        }
Beispiel #2
0
        public TargetTranslator.Translator[] GetPossibleTargets(bool Allies, Rectangle rectangle, bool SelfIncluded = false, int MaxTargets = 0)
        {
            List <TargetTranslator.Translator> Targets = new List <TargetTranslator.Translator>();
            Player me = Main.player[Owner];

            for (int i = 0; i < 255; i++)
            {
                if (Main.player[i].active && (SelfIncluded || i != Owner))
                {
                    bool IsAlly = !Main.player[i].hostile || (me.team != 0 && me.team == Main.player[i].team);
                    if ((Allies && IsAlly) || (!Allies && !IsAlly))
                    {
                        Targets.Add(new TargetTranslator.PlayerTarget(Main.player[i]));
                    }
                }
                if (i < 200 && Main.npc[i].active)
                {
                    bool IsAlly = (Main.npc[i].townNPC || Main.npc[i].friendly);
                    if ((Allies && IsAlly) || (!Allies && !IsAlly))
                    {
                        Targets.Add(new TargetTranslator.NpcTarget(Main.npc[i]));
                    }
                }
            }
            Targets.AddRange(MainMod.GetOtherModTargets(me, Allies));
            for (int t = Targets.Count - 1; t >= 0; t--)
            {
                if (!Targets[t].GetRectangle.Intersects(rectangle))
                {
                    Targets.RemoveAt(t);
                }
            }
            if (MaxTargets > 0)
            {
                while (Targets.Count > MaxTargets)
                {
                    Targets.RemoveAt(MaxTargets);
                }
            }
            return(Targets.ToArray());
        }