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

◆ AI_156_Think()

void Terraria.Projectile.AI_156_Think ( List< int > blacklist)
inlineprivate

Definition at line 41875 of file Projectile.cs.

41876 {
41877 bool flag = type == 755;
41878 bool flag2 = type == 946;
41879 int num = 60;
41880 int num2 = num - 1;
41881 int num3 = num + 60;
41882 int num4 = num3 - 1;
41883 int num5 = num + 1;
41884 if (flag)
41885 {
41886 num = 66;
41887 }
41888 if (flag2)
41889 {
41890 num = 40;
41891 num2 = num - 1;
41892 num3 = num + 40;
41893 num4 = num3 - 1;
41894 num5 = num + 1;
41895 }
41896 Player player = Main.player[owner];
41897 if (player.active && Vector2.Distance(player.Center, base.Center) > 2000f)
41898 {
41899 ai[0] = 0f;
41900 ai[1] = 0f;
41901 netUpdate = true;
41902 }
41903 if (ai[0] == -1f)
41904 {
41908 base.Center = base.Center.MoveTowards(idleSpot, 32f);
41909 rotation = rotation.AngleLerp(idleRotation, 0.2f);
41910 if (Distance(idleSpot) < 2f)
41911 {
41912 ai[0] = 0f;
41913 netUpdate = true;
41914 }
41915 return;
41916 }
41917 if (ai[0] == 0f)
41918 {
41919 if (flag)
41920 {
41924 base.Center = Vector2.SmoothStep(base.Center, idleSpot2, 0.45f);
41925 if (Main.rand.Next(20) == 0)
41926 {
41928 if (num6 != -1)
41929 {
41931 ai[0] = num;
41932 ai[1] = num6;
41933 netUpdate = true;
41934 return;
41935 }
41936 }
41937 }
41938 if (!flag2)
41939 {
41940 return;
41941 }
41945 base.Center = Vector2.SmoothStep(base.Center, idleSpot3, 0.45f);
41946 rotation = rotation.AngleLerp(idleRotation3, 0.45f);
41947 if (Main.rand.Next(20) == 0)
41948 {
41950 if (num7 != -1)
41951 {
41953 ai[0] = Main.rand.NextFromList<int>(num, num3);
41954 ai[0] = num3;
41955 ai[1] = num7;
41956 netUpdate = true;
41957 }
41958 }
41959 return;
41960 }
41961 if (flag)
41962 {
41963 int num8 = (int)ai[1];
41964 if (!Main.npc.IndexInRange(num8))
41965 {
41966 ai[0] = 0f;
41967 netUpdate = true;
41968 return;
41969 }
41970 NPC nPC = Main.npc[num8];
41971 if (!nPC.CanBeChasedBy(this))
41972 {
41973 ai[0] = 0f;
41974 netUpdate = true;
41975 return;
41976 }
41977 ai[0] -= 1f;
41978 if (ai[0] >= (float)num2)
41979 {
41980 velocity *= 0.8f;
41981 if (ai[0] == (float)num2)
41982 {
41983 localAI[0] = base.Center.X;
41984 localAI[1] = base.Center.Y;
41985 }
41986 return;
41987 }
41988 float lerpValue = Utils.GetLerpValue(num2, 0f, ai[0], clamped: true);
41989 Vector2 vector = new Vector2(localAI[0], localAI[1]);
41990 if (lerpValue >= 0.5f)
41991 {
41992 vector = Main.player[owner].Center;
41993 }
41994 Vector2 center = nPC.Center;
41995 float num9 = (center - vector).ToRotation();
41996 float num10 = ((center.X > vector.X) ? (-(float)Math.PI) : ((float)Math.PI));
41997 float num11 = num10 + (0f - num10) * lerpValue * 2f;
41998 Vector2 spinningpoint = num11.ToRotationVector2();
41999 spinningpoint.Y *= (float)Math.Sin((float)identity * 2.3f) * 0.5f;
42000 spinningpoint = spinningpoint.RotatedBy(num9);
42001 float num12 = (center - vector).Length() / 2f;
42003 base.Center = center2;
42004 Vector2 vector2 = MathHelper.WrapAngle(num9 + num11 + 0f).ToRotationVector2() * 10f;
42005 velocity = vector2;
42006 position -= velocity;
42007 if (ai[0] == 0f)
42008 {
42010 if (num13 != -1)
42011 {
42012 ai[0] = num;
42013 ai[1] = num13;
42015 netUpdate = true;
42016 return;
42017 }
42018 ai[1] = 0f;
42019 netUpdate = true;
42020 }
42021 }
42022 if (!flag2)
42023 {
42024 return;
42025 }
42026 bool skipBodyCheck = true;
42027 int num14 = 0;
42028 int num15 = num2;
42029 int num16 = 0;
42030 if (ai[0] >= (float)num5)
42031 {
42032 num14 = 1;
42033 num15 = num4;
42034 num16 = num5;
42035 }
42036 int num17 = (int)ai[1];
42037 if (!Main.npc.IndexInRange(num17))
42038 {
42040 if (num18 != -1)
42041 {
42042 ai[0] = Main.rand.NextFromList<int>(num, num3);
42043 ai[1] = num18;
42045 netUpdate = true;
42046 }
42047 else
42048 {
42049 ai[0] = -1f;
42050 ai[1] = 0f;
42051 netUpdate = true;
42052 }
42053 return;
42054 }
42055 NPC nPC2 = Main.npc[num17];
42056 if (!nPC2.CanBeChasedBy(this))
42057 {
42059 if (num19 != -1)
42060 {
42061 ai[0] = Main.rand.NextFromList<int>(num, num3);
42063 ai[1] = num19;
42064 netUpdate = true;
42065 }
42066 else
42067 {
42068 ai[0] = -1f;
42069 ai[1] = 0f;
42070 netUpdate = true;
42071 }
42072 return;
42073 }
42074 ai[0] -= 1f;
42075 if (ai[0] >= (float)num15)
42076 {
42077 direction = ((base.Center.X < nPC2.Center.X) ? 1 : (-1));
42078 if (ai[0] == (float)num15)
42079 {
42080 localAI[0] = base.Center.X;
42081 localAI[1] = base.Center.Y;
42082 }
42083 }
42084 float lerpValue2 = Utils.GetLerpValue(num15, num16, ai[0], clamped: true);
42085 if (num14 == 0)
42086 {
42087 Vector2 vector3 = new Vector2(localAI[0], localAI[1]);
42088 if (lerpValue2 >= 0.5f)
42089 {
42090 vector3 = Vector2.Lerp(nPC2.Center, Main.player[owner].Center, 0.5f);
42091 }
42092 Vector2 center3 = nPC2.Center;
42093 float num20 = (center3 - vector3).ToRotation();
42094 float num21 = ((direction == 1) ? (-(float)Math.PI) : ((float)Math.PI));
42095 float num22 = num21 + (0f - num21) * lerpValue2 * 2f;
42096 Vector2 spinningpoint2 = num22.ToRotationVector2();
42097 spinningpoint2.Y *= 0.5f;
42098 spinningpoint2.Y *= 0.8f + (float)Math.Sin((float)identity * 2.3f) * 0.2f;
42099 spinningpoint2 = spinningpoint2.RotatedBy(num20);
42100 float num23 = (center3 - vector3).Length() / 2f;
42102 base.Center = center4;
42103 float num24 = MathHelper.WrapAngle(num20 + num22 + 0f);
42104 rotation = num24 + (float)Math.PI / 2f;
42105 Vector2 vector4 = num24.ToRotationVector2() * 10f;
42106 velocity = vector4;
42107 position -= velocity;
42108 }
42109 if (num14 == 1)
42110 {
42111 Vector2 vector5 = new Vector2(localAI[0], localAI[1]);
42112 vector5 += new Vector2(0f, Utils.GetLerpValue(0f, 0.4f, lerpValue2, clamped: true) * -100f);
42113 Vector2 v = nPC2.Center - vector5;
42114 Vector2 vector6 = v.SafeNormalize(Vector2.Zero) * MathHelper.Clamp(v.Length(), 60f, 150f);
42115 Vector2 value = nPC2.Center + vector6;
42116 float lerpValue3 = Utils.GetLerpValue(0.4f, 0.6f, lerpValue2, clamped: true);
42117 float lerpValue4 = Utils.GetLerpValue(0.6f, 1f, lerpValue2, clamped: true);
42118 float targetAngle = v.SafeNormalize(Vector2.Zero).ToRotation() + (float)Math.PI / 2f;
42119 rotation = rotation.AngleTowards(targetAngle, (float)Math.PI / 5f);
42120 base.Center = Vector2.Lerp(vector5, nPC2.Center, lerpValue3);
42121 if (lerpValue4 > 0f)
42122 {
42123 base.Center = Vector2.Lerp(nPC2.Center, value, lerpValue4);
42124 }
42125 }
42126 if (ai[0] == (float)num16)
42127 {
42129 if (num25 != -1)
42130 {
42131 ai[0] = Main.rand.NextFromList<int>(num, num3);
42132 ai[1] = num25;
42134 netUpdate = true;
42135 }
42136 else
42137 {
42138 ai[0] = -1f;
42139 ai[1] = 0f;
42140 netUpdate = true;
42141 }
42142 }
42143 }
static float WrapAngle(float angle)
Definition MathHelper.cs:87
static float Clamp(float value, float min, float max)
Definition MathHelper.cs:46
static double Sin(double a)
const double PI
Definition Math.cs:16
Vector2 velocity
Definition Entity.cs:16
float Distance(Vector2 Other)
Definition Entity.cs:187
Vector2 position
Definition Entity.cs:14
void AI_156_GetIdlePosition(int stackedIndex, int totalIndexes, out Vector2 idleSpot, out float idleRotation)
void AI_GetMyGroupIndexAndFillBlackList(List< int > blackListedTargets, out int index, out int totalIndexesInGroup)
int AI_156_TryAttackingNPCs(List< int > blackListedTargets, bool skipBodyCheck=false)
static Vector2 SmoothStep(Vector2 value1, Vector2 value2, float amount)
Definition Vector2.cs:255
static float Distance(Vector2 value1, Vector2 value2)
Definition Vector2.cs:91
static Vector2 Lerp(Vector2 value1, Vector2 value2, float amount)
Definition Vector2.cs:227

References Terraria.Entity.active, Terraria.Entity.Center, Microsoft.Xna.Framework.MathHelper.Clamp(), Microsoft.Xna.Framework.Vector2.Distance(), Terraria.Utils.GetLerpValue(), System.index, System.index2, System.index3, Microsoft.Xna.Framework.Vector2.Length(), Microsoft.Xna.Framework.Vector2.Lerp(), Terraria.Main.npc, System.Math.PI, Terraria.Main.player, Terraria.Main.rand, System.Math.Sin(), Microsoft.Xna.Framework.Vector2.SmoothStep(), System.type, System.value, Microsoft.Xna.Framework.MathHelper.WrapAngle(), and Microsoft.Xna.Framework.Vector2.Zero.