Пример #1
0
 public static void Log(string format, params object[] args)
 {
     ErrorLogger.Log(String.Format("[Antiaris][{0}] {1}", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), String.Format(format, args)));
 }
 public static Vector2 AttemptJump(Vector2 position, Vector2 velocity, int width, int height, int direction, float directionY = 0, int tileDistX = 3, int tileDistY = 4, float maxSpeedX = 1f, bool jumpUpPlatforms = false, Entity target = null, bool ignoreTiles = false)
 {
     try
     {
         tileDistX -= 2;
         Vector2 newVelocity = velocity;
         int     tileX       = Math.Max(10, Math.Min(Main.maxTilesX - 10, (int)((position.X + (width * 0.5f) + (float)(((width * 0.5f) + 8f) * direction)) / 16f)));
         int     tileY       = Math.Max(10, Math.Min(Main.maxTilesY - 10, (int)((position.Y + (float)height - 15f) / 16f)));
         int     tileItX     = Math.Max(10, Math.Min(Main.maxTilesX - 10, tileX + (direction * tileDistX)));
         int     tileItY     = Math.Max(10, Math.Min(Main.maxTilesY - 10, tileY - tileDistY));
         int     lastY       = tileY;
         int     tileHeight  = (int)(height / 16f);
         if (height > tileHeight * 16)
         {
             tileHeight += 1;
         }
         Rectangle hitbox = new Rectangle((int)position.X, (int)position.Y, width, height);
         if (ignoreTiles && target != null && Math.Abs((position.X + (width * 0.5f)) - target.Center.X) < width + 120)
         {
             float dist = (int)Math.Abs(position.Y + ((float)height * 0.5f) - target.Center.Y) / 16;
             if (dist < tileDistY + 2)
             {
                 newVelocity.Y = -8f + (dist * -0.5f);
             }
         }
         if (newVelocity.Y == velocity.Y)
         {
             for (int y = tileY; y >= tileItY; y--)
             {
                 Tile tile     = Main.tile[tileX, y];
                 Tile tileNear = Main.tile[Math.Min(Main.maxTilesX, tileX - direction), y];
                 if (tile == null)
                 {
                     tile = Main.tile[tileX, y] = new Tile();
                 }
                 if (tileNear == null)
                 {
                     tileNear = Main.tile[Math.Min(Main.maxTilesX, tileX - direction), y] = new Tile();
                 }
                 if (tile.nactive() && (y != tileY || (!tile.halfBrick() && tile.slope() == 0)) && Main.tileSolid[tile.type] && (jumpUpPlatforms || !Main.tileSolidTop[tile.type]))
                 {
                     if (!Main.tileSolidTop[tile.type])
                     {
                         Rectangle tileHitbox = new Rectangle(tileX * 16, y * 16, 16, 16);
                         tileHitbox.Y = hitbox.Y;
                         if (tileHitbox.Intersects(hitbox))
                         {
                             newVelocity = velocity; break;
                         }
                     }
                     if (tileNear.nactive() && Main.tileSolid[tileNear.type] && !Main.tileSolidTop[tileNear.type])
                     {
                         newVelocity = velocity; break;
                     }
                     if (target != null && y * 16 < target.Center.Y)
                     {
                         continue;
                     }
                     lastY         = y;
                     newVelocity.Y = -(5f + (float)(tileY - y) * (tileY - y > 3 ? 1f - ((tileY - y - 2) * 0.0525f) : 1f));
                 }
                 else
                 if (lastY - y >= tileHeight)
                 {
                     break;
                 }
             }
         }
         if (newVelocity.Y == velocity.Y)
         {
             if (Main.tile[tileX, tileY + 1] == null)
             {
                 Main.tile[tileX, tileY + 1] = new Tile();
             }
             if (Main.tile[tileX + direction, tileY + 1] == null)
             {
                 Main.tile[tileX, tileY + 1] = new Tile();
             }
             if (Main.tile[tileX + direction, tileY + 2] == null)
             {
                 Main.tile[tileX, tileY + 2] = new Tile();
             }
             if (directionY < 0 && (!Main.tile[tileX, tileY + 1].nactive() || !Main.tileSolid[(int)Main.tile[tileX, tileY + 1].type]) && (!Main.tile[tileX + direction, tileY + 1].nactive() || !Main.tileSolid[(int)Main.tile[tileX + direction, tileY + 1].type]))
             {
                 if (!Main.tile[tileX + direction, tileY + 2].nactive() || !Main.tileSolid[(int)Main.tile[tileX, tileY + 2].type] || (target == null || ((target.Center.Y + (target.height * 0.25f)) < tileY * 16f)))
                 {
                     newVelocity.Y  = -8f;
                     newVelocity.X *= 1.5f * (1f / maxSpeedX);
                     if (tileX <= tileItX)
                     {
                         for (int x = tileX; x < tileItX; x++)
                         {
                             Tile tile = Main.tile[x, tileY + 1];
                             if (tile == null)
                             {
                                 tile = Main.tile[x, tileY + 1] = new Tile();
                             }
                             if (x != tileX && !tile.nactive())
                             {
                                 newVelocity.Y -= 0.0325f;
                                 newVelocity.X += direction * 0.255f;
                             }
                         }
                     }
                     else
                     if (tileX > tileItX)
                     {
                         for (int x = tileItX; x < tileX; x++)
                         {
                             Tile tile = Main.tile[x, tileY + 1];
                             if (tile == null)
                             {
                                 tile = Main.tile[x, tileY + 1] = new Tile();
                             }
                             if (x != tileItX && !tile.nactive())
                             {
                                 newVelocity.Y -= 0.0325f;
                                 newVelocity.X += direction * 0.255f;
                             }
                         }
                     }
                 }
             }
         }
         return(newVelocity);
     }
     catch (Exception e) { ErrorLogger.Log(e.Message); ErrorLogger.Log(e.StackTrace); return(velocity); }
 }
Пример #3
0
 public static void Log(object message)
 {
     ErrorLogger.Log(String.Format("[Antiaris][{0}] {1}", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), message));
 }