Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ AI_007_GrapplingHooks()

void Terraria.Projectile.AI_007_GrapplingHooks ( )
inlineprivate

Definition at line 42689 of file Projectile.cs.

42690 {
42691 if (Main.player[owner].dead || Main.player[owner].stoned || Main.player[owner].webbed || Main.player[owner].frozen)
42692 {
42693 Kill();
42694 return;
42695 }
42696 Vector2 mountedCenter = Main.player[owner].MountedCenter;
42697 Vector2 vector = new Vector2(position.X + (float)width * 0.5f, position.Y + (float)height * 0.5f);
42698 float num = mountedCenter.X - vector.X;
42699 float num2 = mountedCenter.Y - vector.Y;
42700 float num3 = (float)Math.Sqrt(num * num + num2 * num2);
42701 rotation = (float)Math.Atan2(num2, num) - 1.57f;
42702 if (ai[0] == 2f && type == 865)
42703 {
42704 float num4 = (float)Math.PI / 2f;
42705 int num5 = (int)Math.Round(rotation / num4);
42706 rotation = (float)num5 * num4;
42707 }
42708 if (Main.myPlayer == owner)
42709 {
42710 int num6 = (int)(base.Center.X / 16f);
42711 int num7 = (int)(base.Center.Y / 16f);
42712 if (num6 > 0 && num7 > 0 && num6 < Main.maxTilesX && num7 < Main.maxTilesY && Main.tile[num6, num7].nactive() && TileID.Sets.CrackedBricks[Main.tile[num6, num7].type] && Main.rand.Next(16) == 0)
42713 {
42714 WorldGen.KillTile(num6, num7);
42715 if (Main.netMode != 0)
42716 {
42717 NetMessage.SendData(17, -1, -1, null, 20, num6, num7);
42718 }
42719 }
42720 }
42721 if (num3 > 2500f)
42722 {
42723 Kill();
42724 }
42725 if (type == 256)
42726 {
42727 rotation = (float)Math.Atan2(num2, num) + 3.9250002f;
42728 }
42729 if (type == 446)
42730 {
42731 Lighting.AddLight(mountedCenter, 0f, 0.4f, 0.3f);
42732 localAI[0] += 1f;
42733 if (localAI[0] >= 28f)
42734 {
42735 localAI[0] = 0f;
42736 }
42737 DelegateMethods.v3_1 = new Vector3(0f, 0.4f, 0.3f);
42738 Utils.PlotTileLine(base.Center, mountedCenter, 8f, DelegateMethods.CastLightOpen);
42739 }
42740 if (type == 652 && ++frameCounter >= 7)
42741 {
42742 frameCounter = 0;
42743 if (++frame >= Main.projFrames[type])
42744 {
42745 frame = 0;
42746 }
42747 }
42748 if (type >= 646 && type <= 649)
42749 {
42751 switch (type)
42752 {
42753 case 646:
42754 vector2 = new Vector3(0.7f, 0.5f, 0.1f);
42755 break;
42756 case 647:
42757 vector2 = new Vector3(0f, 0.6f, 0.7f);
42758 break;
42759 case 648:
42760 vector2 = new Vector3(0.6f, 0.2f, 0.6f);
42761 break;
42762 case 649:
42763 vector2 = new Vector3(0.6f, 0.6f, 0.9f);
42764 break;
42765 }
42766 Lighting.AddLight(mountedCenter, vector2);
42767 Lighting.AddLight(base.Center, vector2);
42768 DelegateMethods.v3_1 = vector2;
42769 Utils.PlotTileLine(base.Center, mountedCenter, 8f, DelegateMethods.CastLightOpen);
42770 }
42771 if (ai[0] == 0f)
42772 {
42773 if ((num3 > 300f && type == 13) || (num3 > 400f && type == 32) || (num3 > 440f && type == 73) || (num3 > 440f && type == 74) || (num3 > 375f && type == 165) || (num3 > 350f && type == 256) || (num3 > 500f && type == 315) || (num3 > 550f && type == 322) || (num3 > 400f && type == 331) || (num3 > 550f && type == 332) || (num3 > 400f && type == 372) || (num3 > 300f && type == 396) || (num3 > 550f && type >= 646 && type <= 649) || (num3 > 600f && type == 652) || (num3 > 300f && type == 865) || (num3 > 500f && type == 935) || (num3 > 480f && type >= 486 && type <= 489) || (num3 > 500f && type == 446))
42774 {
42775 ai[0] = 1f;
42776 }
42777 else if (type >= 230 && type <= 235)
42778 {
42779 int num8 = 300 + (type - 230) * 30;
42780 if (num3 > (float)num8)
42781 {
42782 ai[0] = 1f;
42783 }
42784 }
42785 else if (type == 753)
42786 {
42787 int num9 = 420;
42788 if (num3 > (float)num9)
42789 {
42790 ai[0] = 1f;
42791 }
42792 }
42793 Vector2 vector3 = base.Center - new Vector2(5f);
42794 Vector2 vector4 = base.Center + new Vector2(5f);
42795 Point point = (vector3 - new Vector2(16f)).ToTileCoordinates();
42796 Point point2 = (vector4 + new Vector2(32f)).ToTileCoordinates();
42797 int num10 = point.X;
42798 int num11 = point2.X;
42799 int num12 = point.Y;
42800 int num13 = point2.Y;
42801 if (num10 < 0)
42802 {
42803 num10 = 0;
42804 }
42805 if (num11 > Main.maxTilesX)
42806 {
42807 num11 = Main.maxTilesX;
42808 }
42809 if (num12 < 0)
42810 {
42811 num12 = 0;
42812 }
42813 if (num13 > Main.maxTilesY)
42814 {
42815 num13 = Main.maxTilesY;
42816 }
42817 Player player = Main.player[owner];
42819 for (int i = 0; i < player.grapCount; i++)
42820 {
42821 Projectile projectile = Main.projectile[player.grappling[i]];
42822 if (projectile.aiStyle != 7 || projectile.ai[0] != 2f)
42823 {
42824 continue;
42825 }
42826 Point pt = projectile.Center.ToTileCoordinates();
42827 Tile tileSafely = Framing.GetTileSafely(pt);
42828 if (tileSafely.type != 314 && !TileID.Sets.Platforms[tileSafely.type])
42829 {
42830 continue;
42831 }
42832 for (int j = -2; j <= 2; j++)
42833 {
42834 for (int k = -2; k <= 2; k++)
42835 {
42836 Point point3 = new Point(pt.X + j, pt.Y + k);
42837 Tile tileSafely2 = Framing.GetTileSafely(point3);
42838 if (tileSafely2.type == 314 || TileID.Sets.Platforms[tileSafely2.type])
42839 {
42840 list.Add(point3);
42841 }
42842 }
42843 }
42844 }
42845 Vector2 vector5 = default(Vector2);
42846 for (int l = num10; l < num11; l++)
42847 {
42848 for (int m = num12; m < num13; m++)
42849 {
42850 if (Main.tile[l, m] == null)
42851 {
42852 Main.tile[l, m] = new Tile();
42853 }
42854 vector5.X = l * 16;
42855 vector5.Y = m * 16;
42856 if (!(vector3.X + 10f > vector5.X) || !(vector3.X < vector5.X + 16f) || !(vector3.Y + 10f > vector5.Y) || !(vector3.Y < vector5.Y + 16f))
42857 {
42858 continue;
42859 }
42860 Tile tile = Main.tile[l, m];
42861 if (!tile.nactive() || !AI_007_GrapplingHooks_CanTileBeLatchedOnTo(tile) || list.Contains(new Point(l, m)) || (type == 403 && tile.type != 314) || Main.player[owner].IsBlacklistedForGrappling(new Point(l, m)))
42862 {
42863 continue;
42864 }
42865 if (Main.player[owner].grapCount < 10)
42866 {
42867 Main.player[owner].grappling[Main.player[owner].grapCount] = whoAmI;
42868 Main.player[owner].grapCount++;
42869 }
42870 if (Main.myPlayer != owner)
42871 {
42872 continue;
42873 }
42874 int num14 = 0;
42875 int num15 = -1;
42876 int num16 = 100000;
42877 if (type == 73 || type == 74)
42878 {
42879 for (int n = 0; n < 1000; n++)
42880 {
42881 if (n != whoAmI && Main.projectile[n].active && Main.projectile[n].owner == owner && Main.projectile[n].aiStyle == 7 && Main.projectile[n].ai[0] == 2f)
42882 {
42883 Main.projectile[n].Kill();
42884 }
42885 }
42886 }
42887 else
42888 {
42889 int num17 = 3;
42890 if (type == 165)
42891 {
42892 num17 = 8;
42893 }
42894 if (type == 256)
42895 {
42896 num17 = 2;
42897 }
42898 if (type == 372)
42899 {
42900 num17 = 2;
42901 }
42902 if (type == 652)
42903 {
42904 num17 = 1;
42905 }
42906 if (type >= 646 && type <= 649)
42907 {
42908 num17 = 4;
42909 }
42910 for (int num18 = 0; num18 < 1000; num18++)
42911 {
42912 if (Main.projectile[num18].active && Main.projectile[num18].owner == owner && Main.projectile[num18].aiStyle == 7)
42913 {
42914 if (Main.projectile[num18].timeLeft < num16)
42915 {
42916 num15 = num18;
42917 num16 = Main.projectile[num18].timeLeft;
42918 }
42919 num14++;
42920 }
42921 }
42922 if (num14 > num17)
42923 {
42924 Main.projectile[num15].Kill();
42925 }
42926 }
42927 WorldGen.KillTile(l, m, fail: true, effectOnly: true);
42928 SoundEngine.PlaySound(0, l * 16, m * 16);
42929 velocity.X = 0f;
42930 velocity.Y = 0f;
42931 ai[0] = 2f;
42932 position.X = l * 16 + 8 - width / 2;
42933 position.Y = m * 16 + 8 - height / 2;
42934 Rectangle? tileVisualHitbox = WorldGen.GetTileVisualHitbox(l, m);
42935 if (tileVisualHitbox.HasValue)
42936 {
42937 base.Center = tileVisualHitbox.Value.Center.ToVector2();
42938 }
42939 damage = 0;
42940 netUpdate = true;
42941 if (Main.myPlayer == owner)
42942 {
42943 if (type == 935)
42944 {
42945 Main.player[owner].DoQueenSlimeHookTeleport(base.Center);
42946 }
42947 NetMessage.SendData(13, -1, -1, null, owner);
42948 }
42949 break;
42950 }
42951 if (ai[0] == 2f)
42952 {
42953 break;
42954 }
42955 }
42956 }
42957 else if (ai[0] == 1f)
42958 {
42959 float num19 = 11f;
42960 if (type == 32)
42961 {
42962 num19 = 15f;
42963 }
42964 if (type == 73 || type == 74)
42965 {
42966 num19 = 17f;
42967 }
42968 if (type == 315)
42969 {
42970 num19 = 20f;
42971 }
42972 if (type == 322)
42973 {
42974 num19 = 22f;
42975 }
42976 if (type >= 230 && type <= 235)
42977 {
42978 num19 = 11f + (float)(type - 230) * 0.75f;
42979 }
42980 if (type == 753)
42981 {
42982 num19 = 15f;
42983 }
42984 if (type == 446)
42985 {
42986 num19 = 20f;
42987 }
42988 if (type >= 486 && type <= 489)
42989 {
42990 num19 = 18f;
42991 }
42992 if (type >= 646 && type <= 649)
42993 {
42994 num19 = 24f;
42995 }
42996 if (type == 652)
42997 {
42998 num19 = 24f;
42999 }
43000 if (type == 332)
43001 {
43002 num19 = 17f;
43003 }
43004 if (num3 < 24f)
43005 {
43006 Kill();
43007 }
43008 num3 = num19 / num3;
43009 num *= num3;
43010 num2 *= num3;
43011 velocity.X = num;
43012 velocity.Y = num2;
43013 }
43014 else if (ai[0] == 2f)
43015 {
43016 Point point4 = base.Center.ToTileCoordinates();
43017 if (Main.tile[point4.X, point4.Y] == null)
43018 {
43019 Main.tile[point4.X, point4.Y] = new Tile();
43020 }
43021 bool flag = true;
43022 if (Main.tile[point4.X, point4.Y].nactive() && AI_007_GrapplingHooks_CanTileBeLatchedOnTo(Main.tile[point4.X, point4.Y]))
43023 {
43024 flag = false;
43025 }
43026 if (flag)
43027 {
43028 ai[0] = 1f;
43029 }
43030 else if (Main.player[owner].grapCount < 10)
43031 {
43032 Main.player[owner].grappling[Main.player[owner].grapCount] = whoAmI;
43033 Main.player[owner].grapCount++;
43034 }
43035 }
43036 }
void Add(TKey key, TValue value)
static double Atan2(double y, double x)
static double Sqrt(double d)
static decimal Round(decimal d)
Definition Math.cs:1096
const double PI
Definition Math.cs:16
static void PlaySound(int type, Vector2 position, int style=1)
Vector2 position
Definition Entity.cs:14
static bool[] CrackedBricks
Definition TileID.cs:113
static bool[] Platforms
Definition TileID.cs:163
bool AI_007_GrapplingHooks_CanTileBeLatchedOnTo(Tile theTile)

References Terraria.Lighting.AddLight(), Terraria.Projectile.ai, Terraria.Projectile.aiStyle, System.Math.Atan2(), Terraria.DelegateMethods.CastLightOpen(), Terraria.Entity.Center, Terraria.ID.TileID.Sets.CrackedBricks, Terraria.Framing.GetTileSafely(), Terraria.WorldGen.GetTileVisualHitbox(), Terraria.Player.grapCount, Terraria.Player.grappling, Terraria.WorldGen.KillTile(), System.list, Terraria.Main.maxTilesX, Terraria.Main.maxTilesY, Terraria.Main.myPlayer, Terraria.Tile.nactive(), Terraria.Main.netMode, System.Math.PI, Terraria.ID.TileID.Sets.Platforms, Terraria.Main.player, Terraria.Audio.SoundEngine.PlaySound(), Terraria.Utils.PlotTileLine(), Terraria.Main.projectile, Terraria.Main.projFrames, Terraria.Main.rand, System.Math.Round(), Terraria.NetMessage.SendData(), System.Math.Sqrt(), Terraria.DataStructures.Tile, Terraria.Main.tile, System.type, Terraria.Tile.type, Microsoft.Xna.Framework.Point.X, Microsoft.Xna.Framework.Vector2.X, Microsoft.Xna.Framework.Point.Y, Microsoft.Xna.Framework.Vector2.Y, and Microsoft.Xna.Framework.Vector3.Zero.