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

◆ AI_009_MagicMissiles()

void Terraria.Projectile.AI_009_MagicMissiles ( )
inlineprivate

Definition at line 35261 of file Projectile.cs.

35262 {
35263 if (type == 491)
35264 {
35266 return;
35267 }
35268 int num = 32;
35269 Player player = Main.player[owner];
35270 int num2 = Main.maxTilesY * 16;
35271 int num3 = 0;
35272 if (ai[0] >= 0f)
35273 {
35274 num3 = (int)(ai[1] / (float)num2);
35275 }
35276 bool flag = ai[0] == -1f || ai[0] == -2f;
35277 if (type == 34)
35278 {
35279 if (frameCounter++ >= 4)
35280 {
35281 frameCounter = 0;
35282 if (++frame >= Main.projFrames[type])
35283 {
35284 frame = 0;
35285 }
35286 }
35287 if (penetrate == 1 && ai[0] >= 0f && num3 == 0)
35288 {
35289 ai[1] += num2;
35290 num3 = 1;
35291 netUpdate = true;
35292 }
35293 if (penetrate == 1 && ai[0] == -1f)
35294 {
35295 ai[0] = -2f;
35296 netUpdate = true;
35297 }
35298 if (num3 > 0 || ai[0] == -2f)
35299 {
35300 localAI[0] += 1f;
35301 }
35302 }
35303 if (owner == Main.myPlayer)
35304 {
35305 if (ai[0] >= 0f)
35306 {
35307 if (player.channel && player.HeldItem.shoot == type)
35308 {
35309 Vector2 pointPoisition = Main.MouseWorld;
35310 player.LimitPointToPlayerReachableArea(ref pointPoisition);
35311 if (ai[0] != pointPoisition.X || ai[1] != pointPoisition.Y)
35312 {
35313 netUpdate = true;
35314 ai[0] = pointPoisition.X;
35315 ai[1] = pointPoisition.Y + (float)(num2 * num3);
35316 }
35317 }
35318 else
35319 {
35320 netUpdate = true;
35321 ai[0] = -1f;
35322 ai[1] = -1f;
35324 if (num4 != -1)
35325 {
35326 ai[1] = num4;
35327 }
35328 else if (velocity.Length() < 2f)
35329 {
35330 velocity = DirectionFrom(player.Center) * num;
35331 }
35332 else
35333 {
35334 velocity = velocity.SafeNormalize(Vector2.Zero) * num;
35335 }
35336 }
35337 }
35338 if (flag && ai[1] == -1f)
35339 {
35341 if (num5 != -1)
35342 {
35343 ai[1] = num5;
35344 netUpdate = true;
35345 }
35346 }
35347 }
35348 Vector2? vector = null;
35349 float amount = 1f;
35350 if (ai[0] > 0f && ai[1] > 0f)
35351 {
35352 vector = new Vector2(ai[0], ai[1] % (float)num2);
35353 }
35354 if (flag && ai[1] >= 0f)
35355 {
35356 int num6 = (int)ai[1];
35357 if (Main.npc.IndexInRange(num6))
35358 {
35359 NPC nPC = Main.npc[num6];
35360 if (nPC.CanBeChasedBy(this))
35361 {
35362 vector = nPC.Center;
35363 float t = Distance(vector.Value);
35364 float num7 = Utils.GetLerpValue(0f, 100f, t, clamped: true) * Utils.GetLerpValue(600f, 400f, t, clamped: true);
35365 amount = MathHelper.Lerp(0f, 0.2f, Utils.GetLerpValue(200f, 20f, 1f - num7, clamped: true));
35366 }
35367 else
35368 {
35369 ai[1] = -1f;
35370 netUpdate = true;
35371 }
35372 }
35373 }
35374 bool flag2 = false;
35375 if (flag)
35376 {
35377 flag2 = true;
35378 }
35379 if (vector.HasValue)
35380 {
35381 Vector2 value = vector.Value;
35382 if (Distance(value) >= 64f)
35383 {
35384 flag2 = true;
35385 Vector2 v = value - base.Center;
35386 Vector2 vector2 = v.SafeNormalize(Vector2.Zero);
35387 float num8 = Math.Min(num, v.Length());
35389 if (velocity.Length() < 4f)
35390 {
35391 velocity += velocity.SafeNormalize(Vector2.Zero).RotatedBy(0.7853981852531433).SafeNormalize(Vector2.Zero) * 4f;
35392 }
35393 if (velocity.HasNaNs())
35394 {
35395 Kill();
35396 }
35398 }
35399 else
35400 {
35401 velocity *= 0.3f;
35402 velocity += (value - base.Center) * 0.3f;
35403 flag2 = velocity.Length() >= 2f;
35404 }
35405 if (timeLeft < 60)
35406 {
35407 timeLeft = 60;
35408 }
35409 }
35410 if (flag && ai[1] < 0f)
35411 {
35412 if (velocity.Length() != (float)num)
35413 {
35414 velocity = velocity.MoveTowards(velocity.SafeNormalize(Vector2.UnitY) * num, 4f);
35415 }
35416 if (timeLeft > 300)
35417 {
35418 timeLeft = 300;
35419 }
35420 }
35421 if (flag2 && velocity != Vector2.Zero)
35422 {
35423 rotation = rotation.AngleTowards(velocity.ToRotation(), (float)Math.PI / 4f);
35424 }
35425 else
35426 {
35427 rotation = rotation.AngleLerp(0f, 0.2f);
35428 }
35429 bool flag3 = velocity.Length() > 0.1f && Vector2.Dot(oldVelocity.SafeNormalize(Vector2.Zero), velocity.SafeNormalize(Vector2.Zero)) < 0.2f;
35430 if (type == 16)
35431 {
35432 if (soundDelay == 0 && Math.Abs(velocity.X) + Math.Abs(velocity.Y) > 2f)
35433 {
35434 soundDelay = 10;
35436 }
35437 if (Main.rand.Next(9) == 0)
35438 {
35439 int num9 = Dust.NewDust(position, width, height, 15, 0f, 0f, 100, default(Color), 2f);
35440 Main.dust[num9].velocity *= 0.3f;
35441 Main.dust[num9].position.X = position.X + (float)(width / 2) + 4f + (float)Main.rand.Next(-4, 5);
35442 Main.dust[num9].position.Y = position.Y + (float)(height / 2) + (float)Main.rand.Next(-4, 5);
35443 Main.dust[num9].noGravity = true;
35444 Main.dust[num9].velocity += Main.rand.NextVector2Circular(2f, 2f);
35445 }
35446 if (flag3)
35447 {
35448 int num10 = Main.rand.Next(2, 5);
35449 for (int i = 0; i < num10; i++)
35450 {
35451 Dust dust = Dust.NewDustDirect(position, width, height, 15, 0f, 0f, 100, default(Color), 1.5f);
35452 dust.velocity *= 0.3f;
35453 dust.position = base.Center;
35454 dust.noGravity = true;
35455 dust.velocity += Main.rand.NextVector2Circular(0.5f, 0.5f);
35456 dust.fadeIn = 2.2f;
35457 }
35458 }
35459 }
35460 if (type != 34)
35461 {
35462 return;
35463 }
35464 float lerpValue = Utils.GetLerpValue(0f, 10f, localAI[0], clamped: true);
35466 if (Main.rand.Next(6) == 0)
35467 {
35468 Dust dust2 = Dust.NewDustDirect(base.Center, 0, 0, 6, velocity.X * 0.2f, velocity.Y * 0.2f, 100, newColor, 3.5f);
35469 dust2.noGravity = true;
35470 dust2.velocity *= 1.4f;
35471 dust2.velocity += Main.rand.NextVector2Circular(1f, 1f);
35472 dust2.velocity += velocity * 0.15f;
35473 }
35474 if (Main.rand.Next(12) == 0)
35475 {
35476 Dust dust3 = Dust.NewDustDirect(base.Center, 0, 0, 6, velocity.X * 0.2f, velocity.Y * 0.2f, 100, newColor, 1.5f);
35477 dust3.velocity += Main.rand.NextVector2Circular(1f, 1f);
35478 dust3.velocity += velocity * 0.15f;
35479 }
35480 if (flag3)
35481 {
35482 int num11 = Main.rand.Next(2, 5 + (int)(lerpValue * 4f));
35483 for (int j = 0; j < num11; j++)
35484 {
35485 Dust dust4 = Dust.NewDustDirect(position, width, height, 6, 0f, 0f, 100, newColor, 1.5f);
35486 dust4.velocity *= 0.3f;
35487 dust4.position = base.Center;
35488 dust4.noGravity = true;
35489 dust4.velocity += Main.rand.NextVector2Circular(0.5f, 0.5f);
35490 dust4.fadeIn = 2.2f;
35491 dust4.position += (dust4.position - base.Center) * lerpValue * 10f;
35492 }
35493 }
35494 }
static float Lerp(float value1, float value2, float amount)
Definition MathHelper.cs:53
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static double Abs(double value)
const double PI
Definition Math.cs:16
static void PlaySound(int type, Vector2 position, int style=1)
Vector2 DirectionFrom(Vector2 Source)
Definition Entity.cs:202
Vector2 velocity
Definition Entity.cs:16
float Distance(Vector2 Other)
Definition Entity.cs:187
Vector2 position
Definition Entity.cs:14
Vector2 oldVelocity
Definition Entity.cs:20
static readonly LegacySoundStyle Item9
Definition SoundID.cs:432
void AI_009_MagicMissiles_Old()
int FindTargetWithLineOfSight(float maxRange=800f)
static Color Transparent
Definition Color.cs:76
static Color Lerp(Color value1, Color value2, float amount)
Definition Color.cs:491
static float Dot(Vector2 value1, Vector2 value2)
Definition Vector2.cs:121
static Vector2 Lerp(Vector2 value1, Vector2 value2, float amount)
Definition Vector2.cs:227

References System.Math.Abs(), Terraria.Entity.Center, Terraria.Player.channel, Microsoft.Xna.Framework.Color.Crimson, Microsoft.Xna.Framework.Vector2.Dot(), Terraria.Main.dust, Terraria.Utils.GetLerpValue(), Terraria.Player.HeldItem, Terraria.ID.SoundID.Item9, Microsoft.Xna.Framework.Vector2.Length(), Microsoft.Xna.Framework.Color.Lerp(), Microsoft.Xna.Framework.MathHelper.Lerp(), Microsoft.Xna.Framework.Vector2.Lerp(), Terraria.Player.LimitPointToPlayerReachableArea(), System.Math.Min(), Terraria.Main.MouseWorld, Terraria.Main.myPlayer, Terraria.Dust.NewDust(), Terraria.Dust.NewDustDirect(), Terraria.Main.npc, System.Math.PI, Terraria.Main.player, Terraria.Audio.SoundEngine.PlaySound(), Terraria.Main.projFrames, Terraria.Main.rand, Terraria.Item.shoot, Microsoft.Xna.Framework.Color.Transparent, System.type, Microsoft.Xna.Framework.Vector2.UnitY, System.value, and Microsoft.Xna.Framework.Vector2.Zero.