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

◆ AI_121_StardustDragon()

void Terraria.Projectile.AI_121_StardustDragon ( )
inlineprivate

Definition at line 34881 of file Projectile.cs.

34882 {
34883 Player player = Main.player[owner];
34884 if ((int)Main.timeForVisualEffects % 120 == 0)
34885 {
34886 netUpdate = true;
34887 }
34888 if (!player.active)
34889 {
34890 active = false;
34891 return;
34892 }
34893 bool num = type == 625;
34894 bool flag = type == 625 || type == 626 || type == 627 || type == 628;
34895 int num2 = 10;
34896 if (flag)
34897 {
34898 if (player.dead)
34899 {
34900 player.stardustDragon = false;
34901 }
34902 if (player.stardustDragon)
34903 {
34904 timeLeft = 2;
34905 }
34906 num2 = 30;
34907 if (Main.rand.Next(30) == 0)
34908 {
34909 int num3 = Dust.NewDust(position, width, height, 135, 0f, 0f, 0, default(Color), 2f);
34910 Main.dust[num3].noGravity = true;
34911 Main.dust[num3].fadeIn = 2f;
34912 Point point = Main.dust[num3].position.ToTileCoordinates();
34913 if (WorldGen.InWorld(point.X, point.Y, 5) && WorldGen.SolidTile(point.X, point.Y))
34914 {
34915 Main.dust[num3].noLight = true;
34916 }
34917 }
34918 }
34919 if (num)
34920 {
34921 Vector2 center = player.Center;
34922 float num4 = 700f;
34923 float num5 = 1000f;
34924 int num6 = -1;
34925 if (Distance(center) > 2000f)
34926 {
34927 base.Center = center;
34928 netUpdate = true;
34929 }
34930 if (true)
34931 {
34933 if (ownerMinionAttackTargetNPC != null && ownerMinionAttackTargetNPC.CanBeChasedBy(this))
34934 {
34936 if (num7 < num4 * 2f)
34937 {
34940 {
34942 }
34943 else
34944 {
34946 }
34947 }
34948 }
34949 if (num6 < 0)
34950 {
34951 for (int i = 0; i < 200; i++)
34952 {
34953 NPC nPC = Main.npc[i];
34954 if (nPC.CanBeChasedBy(this) && player.Distance(nPC.Center) < num5)
34955 {
34956 float num8 = Distance(nPC.Center);
34957 if (num8 < num4)
34958 {
34959 num6 = i;
34960 _ = nPC.boss;
34961 }
34962 }
34963 }
34964 }
34965 }
34966 if (num6 != -1)
34967 {
34968 NPC nPC2 = Main.npc[num6];
34969 Vector2 vector = nPC2.Center - base.Center;
34970 (vector.X > 0f).ToDirectionInt();
34971 (vector.Y > 0f).ToDirectionInt();
34972 float num9 = 0.4f;
34973 if (vector.Length() < 600f)
34974 {
34975 num9 = 0.6f;
34976 }
34977 if (vector.Length() < 300f)
34978 {
34979 num9 = 0.8f;
34980 }
34981 if (vector.Length() > nPC2.Size.Length() * 0.75f)
34982 {
34983 velocity += Vector2.Normalize(vector) * num9 * 1.5f;
34984 if (Vector2.Dot(velocity, vector) < 0.25f)
34985 {
34986 velocity *= 0.8f;
34987 }
34988 }
34989 float num10 = 30f;
34990 if (velocity.Length() > num10)
34991 {
34993 }
34994 }
34995 else
34996 {
34997 float num11 = 0.2f;
34998 Vector2 vector2 = center - base.Center;
34999 if (vector2.Length() < 200f)
35000 {
35001 num11 = 0.12f;
35002 }
35003 if (vector2.Length() < 140f)
35004 {
35005 num11 = 0.06f;
35006 }
35007 if (vector2.Length() > 100f)
35008 {
35009 if (Math.Abs(center.X - base.Center.X) > 20f)
35010 {
35011 velocity.X += num11 * (float)Math.Sign(center.X - base.Center.X);
35012 }
35013 if (Math.Abs(center.Y - base.Center.Y) > 10f)
35014 {
35015 velocity.Y += num11 * (float)Math.Sign(center.Y - base.Center.Y);
35016 }
35017 }
35018 else if (velocity.Length() > 2f)
35019 {
35020 velocity *= 0.96f;
35021 }
35022 if (Math.Abs(velocity.Y) < 1f)
35023 {
35024 velocity.Y -= 0.1f;
35025 }
35026 float num12 = 15f;
35027 if (velocity.Length() > num12)
35028 {
35030 }
35031 }
35032 rotation = velocity.ToRotation() + (float)Math.PI / 2f;
35033 int num13 = direction;
35034 direction = (spriteDirection = ((velocity.X > 0f) ? 1 : (-1)));
35035 if (num13 != direction)
35036 {
35037 netUpdate = true;
35038 }
35039 float num14 = MathHelper.Clamp(localAI[0], 0f, 50f);
35040 position = base.Center;
35041 scale = 1f + num14 * 0.01f;
35042 width = (height = (int)((float)num2 * scale));
35043 base.Center = position;
35044 if (alpha > 0)
35045 {
35046 for (int j = 0; j < 2; j++)
35047 {
35048 int num15 = Dust.NewDust(new Vector2(position.X, position.Y), width, height, 135, 0f, 0f, 100, default(Color), 2f);
35049 Main.dust[num15].noGravity = true;
35050 Main.dust[num15].noLight = true;
35051 }
35052 alpha -= 42;
35053 if (alpha < 0)
35054 {
35055 alpha = 0;
35056 }
35057 }
35058 }
35059 else
35060 {
35061 bool flag2 = false;
35063 _ = Vector2.Zero;
35064 float num16 = 0f;
35065 float num17 = 0f;
35066 float num18 = 1f;
35067 if (ai[1] == 1f)
35068 {
35069 ai[1] = 0f;
35070 netUpdate = true;
35071 }
35072 int byUUID = GetByUUID(owner, (int)ai[0]);
35073 if (Main.projectile.IndexInRange(byUUID))
35074 {
35075 Projectile projectile = Main.projectile[byUUID];
35076 if (flag && projectile.active && (projectile.type == 625 || projectile.type == 626 || projectile.type == 627))
35077 {
35078 flag2 = true;
35079 vector3 = projectile.Center;
35080 _ = projectile.velocity;
35081 num16 = projectile.rotation;
35082 num18 = MathHelper.Clamp(projectile.scale, 0f, 50f);
35083 num17 = 16f;
35084 _ = projectile.alpha;
35085 projectile.localAI[0] = localAI[0] + 1f;
35086 if (projectile.type != 625)
35087 {
35088 projectile.localAI[1] = whoAmI;
35089 }
35090 if (owner == Main.myPlayer && type == 628 && projectile.type == 625)
35091 {
35092 projectile.Kill();
35093 Kill();
35094 return;
35095 }
35096 }
35097 }
35098 if (!flag2)
35099 {
35100 for (int k = 0; k < 1000; k++)
35101 {
35102 Projectile projectile2 = Main.projectile[k];
35103 if (projectile2.active && projectile2.owner == owner && ProjectileID.Sets.StardustDragon[projectile2.type] && projectile2.localAI[1] == ai[0])
35104 {
35105 ai[0] = projectile2.projUUID;
35106 projectile2.localAI[1] = whoAmI;
35107 netUpdate = true;
35108 }
35109 }
35110 return;
35111 }
35112 if (alpha > 0)
35113 {
35114 for (int l = 0; l < 2; l++)
35115 {
35116 int num19 = Dust.NewDust(position, width, height, 135, 0f, 0f, 100, default(Color), 2f);
35117 Main.dust[num19].noGravity = true;
35118 Main.dust[num19].noLight = true;
35119 }
35120 }
35121 alpha -= 42;
35122 if (alpha < 0)
35123 {
35124 alpha = 0;
35125 }
35127 Vector2 vector4 = vector3 - base.Center;
35128 if (num16 != rotation)
35129 {
35131 vector4 = vector4.RotatedBy(num20 * 0.1f);
35132 }
35133 rotation = vector4.ToRotation() + (float)Math.PI / 2f;
35134 position = base.Center;
35135 scale = num18;
35136 width = (height = (int)((float)num2 * scale));
35137 base.Center = position;
35138 if (vector4 != Vector2.Zero)
35139 {
35140 base.Center = vector3 - Vector2.Normalize(vector4) * num17 * num18;
35141 }
35142 spriteDirection = ((vector4.X > 0f) ? 1 : (-1));
35143 }
35144 position.X = MathHelper.Clamp(position.X, 160f, Main.maxTilesX * 16 - 160);
35145 position.Y = MathHelper.Clamp(position.Y, 160f, Main.maxTilesY * 16 - 160);
35146 }
static float WrapAngle(float angle)
Definition MathHelper.cs:87
static float Clamp(float value, float min, float max)
Definition MathHelper.cs:46
static double Abs(double value)
const double PI
Definition Math.cs:16
static int Sign(decimal value)
Definition Math.cs:1202
Vector2 velocity
Definition Entity.cs:16
float Distance(Vector2 Other)
Definition Entity.cs:187
Vector2 position
Definition Entity.cs:14
static int GetByUUID(int owner, float uuid)
static float Dot(Vector2 value1, Vector2 value2)
Definition Vector2.cs:121

References System.Math.Abs(), Terraria.Entity.active, Terraria.Projectile.alpha, Terraria.Entity.Center, Microsoft.Xna.Framework.MathHelper.Clamp(), Terraria.Player.dead, Terraria.Entity.Distance(), Microsoft.Xna.Framework.Vector2.Dot(), Terraria.Main.dust, Terraria.WorldGen.InWorld(), Terraria.Projectile.Kill(), Terraria.Projectile.localAI, Terraria.Main.maxTilesX, Terraria.Main.maxTilesY, Terraria.Main.myPlayer, Terraria.Dust.NewDust(), Microsoft.Xna.Framework.Vector2.Normalize(), Terraria.Main.npc, System.Math.PI, Terraria.Main.player, Terraria.Main.projectile, Terraria.Main.rand, Terraria.Projectile.rotation, Terraria.Projectile.scale, System.Math.Sign(), Terraria.WorldGen.SolidTile(), Terraria.ID.ProjectileID.Sets.StardustDragon, Terraria.Player.stardustDragon, Terraria.Main.timeForVisualEffects, System.type, Terraria.Projectile.type, Terraria.Entity.velocity, Microsoft.Xna.Framework.MathHelper.WrapAngle(), Microsoft.Xna.Framework.Point.X, Microsoft.Xna.Framework.Vector2.X, Microsoft.Xna.Framework.Point.Y, Microsoft.Xna.Framework.Vector2.Y, and Microsoft.Xna.Framework.Vector2.Zero.