Пример #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();
        }
        public static Vector2?ScanForExitCandidate(Vector2 src, float rad, float range)
        {
            var dir = new Vector2(
                (float)Math.Cos(rad),
                -(float)Math.Sin(rad)
                );
            var dest = src + (dir * range * 16);

            int x = (int)(dest.X / 16f);
            int y = (int)(dest.Y / 16f);

            for (int i = x; i < x + TrainTunnelTile.Width; i++)
            {
                for (int j = y; j < y + TrainTunnelTile.Height; j++)
                {
                    Tile tile = Main.tile[i, j];

                    if (tile.wall == 0 || TileHelpers.IsSolid(tile) || tile.type != 0)
                    {
                        return(null);
                    }
                }
            }

            return(dest);
        }
Пример #3
0
        ////////////////

        private void AttemptShoot(CustomEntity ent, Player targetPlayer)
        {
            if (!this.IgnoresSolidCover)
            {
                bool isBlocked = false;

                Utils.PlotTileLine(ent.Core.Center, targetPlayer.Center, 1f, (x, y) => {
                    if (TileHelpers.IsSolid(Main.tile[x, y]))
                    {
                        isBlocked = true;
                        return(false);
                    }
                    return(true);
                });

                if (isBlocked)
                {
                    return;
                }
            }

            if (this.Cooldown <= 0)
            {
                this.Cooldown = this.MaxCooldown;

                this.Shoot(ent, targetPlayer);
            }
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
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);
        }
Пример #8
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);
        }
Пример #9
0
        /////////////////

        private Vector2 GetRandomClearMapPos()
        {
            Vector2 rand_pos;
            int     world_x, world_y;
            bool    found = false, is_empty = false;

            do
            {
                found = true;

                do
                {
                    world_x = Main.rand.Next(64, Main.maxTilesX - 64);
                    world_y = Main.rand.Next((int)Main.worldSurface, Main.maxTilesY - 220);

                    is_empty = true;
                    for (int i = world_x; i < world_x + 6; i++)
                    {
                        for (int j = world_y; j < world_y + 8; j++)
                        {
                            Tile tile = Framing.GetTileSafely(i, j);

                            is_empty = !TileHelpers.IsSolid(tile, true, true) && !tile.lava() && !TileWallHelpers.IsDungeon(tile);
                            if (!is_empty)
                            {
                                break;
                            }
                        }
                        if (!is_empty)
                        {
                            break;
                        }
                    }
                } while(!is_empty);
                //} while( Collision.SolidCollision( new Vector2(world_x*16f, world_y*16f), WormholePortal.Width, WormholePortal.Height ) );

                rand_pos = new Vector2(world_x * 16f, world_y * 16f);

                // Not too close to other portals?
                for (int i = 0; i < this.Links.Count; i++)
                {
                    var link = this.Links[i];

                    float dist = Vector2.Distance(link.LeftPortal.Pos, rand_pos);
                    if (dist < 2048)
                    {
                        found = false;
                        break;
                    }

                    dist = Vector2.Distance(link.RightPortal.Pos, rand_pos);
                    if (dist < 2048)
                    {
                        found = false;
                        break;
                    }
                }
            } while(!found);

            return(rand_pos);
        }
 public static bool CanPaintForeground(Tile tile)
 {
     return(TileHelpers.IsSolid(tile, true, true));
 }
Пример #11
0
        /////////////////

        private Vector2 GetRandomClearMapPos()
        {
            Vector2 randPos;
            int     worldX, worldY;
            bool    found = false, isEmpty = false;
            int     minWldDistSqr = WormholesConfig.Instance.MinimumTileDistanceBetweenWormholes * 16;

            minWldDistSqr *= minWldDistSqr;

            (int minX, int maxX, int minY, int maxY)bounds = WormholesWorld.GetTileBoundsForWormholes();

            do
            {
                found = true;

                do
                {
                    worldX = Main.rand.Next(bounds.minX, bounds.maxX);
                    worldY = Main.rand.Next(bounds.minY, bounds.maxY);

                    isEmpty = true;
                    for (int i = worldX; i < worldX + 6; i++)
                    {
                        for (int j = worldY; j < worldY + 8; j++)
                        {
                            Tile tile = Framing.GetTileSafely(i, j);

                            bool _;
                            isEmpty = !TileHelpers.IsSolid(tile, true, true) && !tile.lava() && !TileWallGroupIdentityHelpers.IsDungeon(tile, out _);
                            if (!isEmpty)
                            {
                                break;
                            }
                        }
                        if (!isEmpty)
                        {
                            break;
                        }
                    }
                } while(!isEmpty);
                //} while( Collision.SolidCollision( new Vector2(world_x*16f, world_y*16f), WormholePortal.Width, WormholePortal.Height ) );

                randPos = new Vector2(worldX * 16f, worldY * 16f);

                // Not too close to other portals?
                for (int i = 0; i < this.Links.Count; i++)
                {
                    var link = this.Links[i];

                    float distSqr = Vector2.DistanceSquared(link.LeftPortal.Pos, randPos);
                    if (distSqr < minWldDistSqr)
                    {
                        found = false;
                        break;
                    }

                    distSqr = Vector2.DistanceSquared(link.RightPortal.Pos, randPos);
                    if (distSqr < minWldDistSqr)
                    {
                        found = false;
                        break;
                    }
                }
            } while(!found);

            return(randPos);
        }
Пример #12
0
        public void ScatterTiles(int tileX, int tileY, int radius, int scatterRadius)
        {
            int  toX, toY, style = 0;
            Tile froTile;

            for (int i = tileX - radius; i <= tileX + radius; i++)
            {
                for (int j = tileY - radius; j <= tileY + radius; j++)
                {
                    float xDist = i - tileX;
                    float yDist = j - tileY;
                    if ((xDist * xDist) + (yDist * yDist) > (radius * radius))
                    {
                        continue;
                    }                                                                                           // Crude

                    froTile = Main.tile[i, j];
                    if (froTile == null)
                    {
                        continue;
                    }
                    if (!TileHelpers.IsSolid(froTile, true, true))
                    {
                        continue;
                    }
                    if (TileHelpers.IsWire(froTile))
                    {
                        continue;
                    }
                    if (froTile.lava())
                    {
                        continue;
                    }
                    if (TileHelpers.IsNotVanillaBombable(i, j))
                    {
                        continue;
                    }

                    var tileData = TileObjectData.GetTileData(froTile);
                    if (tileData != null && (tileData.Width > 1 || tileData.Height > 1))
                    {
                        continue;
                    }

                    if (!TileFinderHelpers.FindNearbyRandomMatch(TilePattern.NonSolid,
                                                                 tileX,
                                                                 tileY,
                                                                 scatterRadius,
                                                                 100,
                                                                 false,
                                                                 out toX,
                                                                 out toY))
                    {
                        break;
                    }

                    try {
                        style = TileObjectData.GetTileStyle(froTile);
                    } catch (Exception) {
                        style = 0;
                    }

                    int oldType = froTile.type;
                    WorldGen.KillTile(i, j, false, false, true);
                    WorldGen.PlaceTile(toX, toY, oldType, true, true, this.projectile.owner, style);

                    if (Main.netMode != 0)
                    {
                        NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, (float)i, (float)j, 0f, 0, 0, 0);
                        NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, (float)toX, (float)toY, 0f, 0, 0, 0);
                    }

                    Dust.NewDust(new Vector2(i * 16, j * 16), 0, 0, 15, 0, 0, 150, Color.Cyan, 1f);
                    Dust.NewDust(new Vector2(toX * 16, toY * 16), 0, 0, 15, 0, 0, 150, Color.Cyan, 1f);
                }
            }
        }
        public void ScatterTiles(int tile_x, int tile_y, int radius, int scatter_radius)
        {
            int  to_x, to_y, style = 0;
            Tile fro_tile;

            for (int i = tile_x - radius; i <= tile_x + radius; i++)
            {
                for (int j = tile_y - radius; j <= tile_y + radius; j++)
                {
                    float x_dist = i - tile_x;
                    float y_dist = j - tile_y;
                    if (Math.Sqrt((x_dist * x_dist) + (y_dist * y_dist)) > radius)
                    {
                        continue;
                    }                                                                                                   // Crude

                    fro_tile = Main.tile[i, j];
                    if (fro_tile == null)
                    {
                        continue;
                    }
                    if (!TileHelpers.IsSolid(fro_tile, true, true))
                    {
                        continue;
                    }
                    if (TileHelpers.IsWire(fro_tile))
                    {
                        continue;
                    }
                    if (fro_tile.lava())
                    {
                        continue;
                    }
                    if (TileHelpers.IsNotBombable(i, j))
                    {
                        continue;
                    }

                    var tile_data = TileObjectData.GetTileData(fro_tile);
                    if (tile_data != null && (tile_data.Width > 1 || tile_data.Height > 1))
                    {
                        continue;
                    }

                    if (!TileFinderHelpers.FindNearbyRandomAirTile(tile_x, tile_y, scatter_radius, out to_x, out to_y))
                    {
                        break;
                    }

                    try {
                        style = TileObjectData.GetTileStyle(fro_tile);
                    } catch (Exception _) {
                        style = 0;
                    }

                    int old_type = fro_tile.type;
                    WorldGen.KillTile(i, j, false, false, true);
                    WorldGen.PlaceTile(to_x, to_y, old_type, true, true, this.projectile.owner, style);

                    if (Main.netMode != 0)
                    {
                        NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, (float)i, (float)j, 0f, 0, 0, 0);
                        NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, (float)to_x, (float)to_y, 0f, 0, 0, 0);
                    }

                    Dust.NewDust(new Vector2(i * 16, j * 16), 0, 0, 15, 0, 0, 150, Color.Cyan, 1f);
                    Dust.NewDust(new Vector2(to_x * 16, to_y * 16), 0, 0, 15, 0, 0, 150, Color.Cyan, 1f);
                }
            }
        }