Example #1
0
        private void RandomizeVirtualTarget(DowsingMod mymod, Player player)
        {
            float   max_tile_range = (float)Math.Max(mymod.Config.Data.MaxVirtualTargetRangeInTiles, 100);
            Vector2 pos = Vector2.Zero;
            int     i = 0, tile_x, tile_y;

            do
            {
                if (i++ >= 100)
                {
                    break;
                }

                float   rand_range_tiles = (Main.rand.NextFloat() * (max_tile_range - 100f)) + 99f;
                float   rand_range       = 16f * rand_range_tiles;
                Vector2 rand_heading     = Vector2.UnitX.RotatedBy((double)Main.rand.NextFloat() * (Math.PI * 2d));

                pos    = player.Center + (rand_heading * rand_range);
                tile_x = (int)pos.X / 16;
                tile_y = (int)pos.Y / 16;
            } while(!TileWorldHelpers.IsWithinMap(tile_x, tile_y) || TileHelpers.IsSolid(Framing.GetTileSafely(tile_x, tile_y)));

            this.VirtualTargetPosition = TileWorldHelpers.DropToGround(pos);
            this.ReAimVirtualTarget();
        }
        protected bool CastRareNpcDowse(Player player, Vector2 aiming_at, int tile_range)
        {
            var  mymod              = (DowsingMod)this.mod;
            var  modplayer          = player.GetModPlayer <DowsingPlayer>();
            bool dowsed             = false;
            var  npc_poses          = this.GetNpcPositions();
            NPC  npc                = null;
            var  rare_npc_type_list = WitchingTargetData.GetCurrentRareNpcTypes();

            if (rare_npc_type_list.Count == 0)
            {
                return(false);
            }
            var rare_npc_type_set = new HashSet <int>(rare_npc_type_list);
            int traveled          = 0;

            this.CurrentBeamTravelDistance = 0;

            this.CastDowseBeamWithinCone(player, aiming_at, new Utils.PerLinePoint(delegate(int tile_x, int tile_y) {
                if (!TileWorldHelpers.IsWithinMap(tile_x, tile_y) || traveled >= tile_range)
                {
                    return(false);
                }

                if (npc_poses.ContainsKey(tile_x) && npc_poses[tile_x].ContainsKey(tile_y))
                {
                    npc = Main.npc[npc_poses[tile_x][tile_y]];
                    if (rare_npc_type_set.Contains(npc.type))
                    {
                        dowsed = true;
                    }
                }

                if (dowsed)
                {
                    this.RenderRodHitFX(player, tile_x, tile_y);
                }
                else
                {
                    traveled++;
                    if (TileHelpers.IsSolid(Framing.GetTileSafely(tile_x, tile_y), false, false))
                    {
                        traveled++;
                    }
                }
                this.CurrentBeamTravelDistance = traveled;

                if ((mymod.DEBUGFLAGS & 1) != 0)
                {
                    DebugHelpers.Print("current rare npcs", (this.III++) + " " + string.Join(",", rare_npc_type_set.ToArray()), 20);
                    //var dust = Dust.NewDustPerfect( new Vector2( tile_x * 16, tile_y * 16 ), 259, Vector2.Zero, 0, Color.Red, 0.75f );
                    //dust.noGravity = true;
                }
                return(!dowsed);
            }));

            return(dowsed);
        }
        protected bool CastNpcTargetDowse(Player player, Vector2 aiming_at, int npc_who, int tile_range)
        {
            var  mymod     = (DowsingMod)this.mod;
            var  modplayer = player.GetModPlayer <DowsingPlayer>();
            bool dowsed    = false;
            int  traveled  = 0;

            this.CurrentBeamTravelDistance = 0;

            this.CastDowseBeamWithinCone(player, aiming_at, new Utils.PerLinePoint(delegate(int tile_x, int tile_y) {
                if (!TileWorldHelpers.IsWithinMap(tile_x, tile_y) || traveled >= tile_range)
                {
                    return(false);
                }

                NPC npc = Main.npc[npc_who];
                if (npc == null || !npc.active)
                {
                    return(false);
                }

                dowsed = npc.getRect().Intersects(new Rectangle((tile_x - 1) * 16, (tile_y - 1) * 16, 32, 32));

                if (dowsed)
                {
                    PsychokineticChargeDebuff.ApplyForTargetIfAnew(mymod, player);
                    this.RenderRodHitFX(player, tile_x, tile_y);
                }
                else
                {
                    traveled++;
                    if (TileHelpers.IsSolid(Framing.GetTileSafely(tile_x, tile_y)))
                    {
                        traveled++;
                    }
                }
                this.CurrentBeamTravelDistance = traveled;

                if ((mymod.DEBUGFLAGS & 1) != 0)
                {
                    var dust       = Dust.NewDustPerfect(new Vector2(tile_x * 16, tile_y * 16), 259, Vector2.Zero, 0, Color.Red, 0.75f);
                    dust.noGravity = true;
                }
                return(!dowsed);
            }));

            return(dowsed);
        }
        protected bool CastVirtualTargetDowse(Player player, Vector2 aiming_at, int tile_range)
        {
            var  mymod     = (DowsingMod)this.mod;
            var  modplayer = player.GetModPlayer <DowsingPlayer>();
            bool dowsed    = false;
            int  traveled  = 0;

            this.CurrentBeamTravelDistance = 0;

            this.CastDowseBeamWithinCone(player, aiming_at, new Utils.PerLinePoint(delegate(int tile_x, int tile_y) {
                if (!TileWorldHelpers.IsWithinMap(tile_x, tile_y) || traveled >= tile_range)
                {
                    return(false);
                }

                Vector2 from = modplayer.WitchingData.VirtualTargetPosition;
                float dist_x = (from.X / 16f) - (float)tile_x;
                float dist_y = (from.Y / 16f) - (float)tile_y;
                float dist   = (float)Math.Sqrt(dist_x * dist_x + dist_y * dist_y);

                dowsed = dist <= 8;

                if (dowsed)
                {
                    PsychokineticChargeDebuff.ApplyForTargetIfAnew(mymod, player);
                    this.VirtualTargetIsDowsed(player);
                    this.RenderRodHitFX(player, tile_x, tile_y);
                }
                else
                {
                    traveled++;
                    if (TileHelpers.IsSolid(Framing.GetTileSafely(tile_x, tile_y), false, false))
                    {
                        traveled++;
                    }
                }
                this.CurrentBeamTravelDistance = traveled;

                if ((mymod.DEBUGFLAGS & 1) != 0)
                {
                    var dust       = Dust.NewDustPerfect(new Vector2(tile_x * 16, tile_y * 16), 259, Vector2.Zero, 0, Color.Red, 0.75f);
                    dust.noGravity = true;
                }
                return(!dowsed);
            }));

            return(dowsed);
        }
Example #5
0
        ////////////////

        protected bool CastBlockDowse(Player player, Vector2 aiming_at, int tile_range, int tile_type)
        {
            var  mymod     = (DowsingMod)this.mod;
            var  modplayer = player.GetModPlayer <DowsingPlayer>();
            bool dowsed    = false;
            int  traveled  = 0;

            this.CurrentBeamTravelDistance = 0;

            this.CastDowseBeamWithinCone(player, aiming_at, new Utils.PerLinePoint(delegate(int tile_x, int tile_y) {
                if (!TileWorldHelpers.IsWithinMap(tile_x, tile_y) || traveled >= tile_range)
                {
                    return(false);
                }

                dowsed = modplayer.TileData.ApplyDowseIfTileIsTarget(tile_x, tile_y, tile_type);

                if (dowsed)
                {
                    PsychokineticChargeDebuff.ApplyForTilesIfAnew(mymod, player);
                    this.RenderRodHitFX(player, tile_x, tile_y);
                }
                else
                {
                    traveled++;
                    if (TileHelpers.IsSolid(Framing.GetTileSafely(tile_x, tile_y), false, false))
                    {
                        traveled++;
                    }
                }
                this.CurrentBeamTravelDistance = traveled;

                if ((mymod.DEBUGFLAGS & 1) != 0)
                {
                    var dust       = Dust.NewDustPerfect(new Vector2(tile_x * 16, tile_y * 16), 259, Vector2.Zero, 0, Color.Red, 0.75f);
                    dust.noGravity = true;
                }
                return(!dowsed);
            }));

            return(dowsed);
        }
Example #6
0
        public int TestVirtualTargetMovement(DowsingMod mymod, Player player, out Vector2 newpos)
        {
            int max_range = mymod.Config.Data.MaxWitchingRangeInTiles * 16;
            int min_range = mymod.Config.Data.VirtualTargetApproachTriggerInTiles * 16;

            newpos = this.VirtualTargetPosition + (this.VirtualTargetHeading * 2);

            int dist   = (int)Vector2.Distance(newpos, player.Center);
            int tile_x = (int)newpos.X / 16;
            int tile_y = (int)newpos.Y / 16;

            if ((mymod.DEBUGFLAGS & 1) != 0)
            {
                DebugHelpers.Print("dist", min_range + "(" + (dist <= min_range) + ") <= " + dist + " >= " + max_range + "(" + (dist >= max_range) + ")", 20);
            }

            if (dist >= max_range)                  // Target out-of-range
            {
                return(-1);
            }
            if (dist <= min_range)                  // Target reached
            {
                return(1);
            }
            if (TileHelpers.IsSolid(Framing.GetTileSafely(tile_x, tile_y)))                   // Target collides with solid tile?
            {
                return(2);
            }
            if (!TileWorldHelpers.IsWithinMap(tile_x, tile_y))                   // Target outside map?
            {
                return(3);
            }
            if (!TileFinderHelpers.HasNearbySolid(tile_x, tile_y, 10))                    // Not near solids?
            {
                return(4);
            }
            return(0);
        }