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

◆ AI_120_StardustGuardian()

void Terraria.Projectile.AI_120_StardustGuardian ( )
inlineprivate

Definition at line 36607 of file Projectile.cs.

36608 {
36609 Player player = Main.player[owner];
36610 if (!player.active)
36611 {
36612 active = false;
36613 return;
36614 }
36615 bool flag = type == 623;
36616 Vector2 vector = player.Center;
36617 float num = 100f;
36618 float num2 = 500f;
36619 float num3 = 500f;
36620 float num4 = 100f;
36621 bool flag2 = true;
36622 if (flag)
36623 {
36624 if (player.dead)
36625 {
36626 player.stardustGuardian = false;
36627 }
36628 if (player.stardustGuardian)
36629 {
36630 timeLeft = 2;
36631 }
36632 num = 150f;
36633 vector.X -= (5 + player.width / 2) * player.direction;
36634 vector.Y -= 25f;
36635 Lighting.AddLight(base.Center, 0.9f, 0.9f, 0.7f);
36636 if (ai[0] != 3f && alpha == 255)
36637 {
36638 alpha = 0;
36639 for (int i = 0; i < 30; i++)
36640 {
36641 int num5 = Dust.NewDust(position, width, height, 135, 0f, 0f, 200, default(Color), 1.7f);
36642 Main.dust[num5].noGravity = true;
36643 Main.dust[num5].velocity *= 3f;
36644 Main.dust[num5].shader = GameShaders.Armor.GetSecondaryShader(Main.player[owner].cPet, Main.player[owner]);
36645 num5 = Dust.NewDust(position, width, height, 135, 0f, 0f, 100);
36646 Main.dust[num5].velocity *= 2f;
36647 Main.dust[num5].noGravity = true;
36648 Main.dust[num5].fadeIn = 2.5f;
36649 Main.dust[num5].shader = GameShaders.Armor.GetSecondaryShader(Main.player[owner].cPet, Main.player[owner]);
36650 }
36651 }
36652 }
36653 if (ai[0] != 0f)
36654 {
36655 Main.player[owner].tankPet = whoAmI;
36656 Main.player[owner].tankPetReset = false;
36657 }
36658 if (ai[0] == 0f)
36659 {
36660 base.Center = Vector2.Lerp(base.Center, vector, 0.05f);
36661 velocity *= 0.5f;
36662 direction = (spriteDirection = player.direction);
36663 if (flag && ++frameCounter >= 9)
36664 {
36665 frameCounter = 0;
36666 if (++frame >= 8)
36667 {
36668 frame = 0;
36669 }
36670 }
36671 int targetNPCIndex = -1;
36673 bool flag3 = flag2;
36674 if (flag && Math.Abs(base.Center.X - vector.X) > num + 20f)
36675 {
36676 flag3 = false;
36677 }
36678 if (flag3)
36679 {
36681 }
36682 if (targetNPCIndex != -1)
36683 {
36684 NPC nPC = Main.npc[targetNPCIndex];
36685 direction = (spriteDirection = (nPC.Center.X > base.Center.X).ToDirectionInt());
36686 float num6 = Math.Abs(vector.X - base.Center.X);
36687 float num7 = Math.Abs(nPC.Center.X - base.Center.X);
36688 float num8 = Math.Abs(vector.Y - base.Center.Y);
36689 float num9 = Math.Abs(nPC.Center.Y - base.Bottom.Y);
36690 float num10 = (nPC.Center.Y > base.Bottom.Y).ToDirectionInt();
36691 if ((num6 < num || (vector.X - base.Center.X) * (float)direction < 0f) && num7 > 20f && num7 < num - num6 + 100f)
36692 {
36693 velocity.X += 0.1f * (float)direction;
36694 }
36695 else
36696 {
36697 velocity.X *= 0.7f;
36698 }
36699 if ((num8 < num4 || (vector.Y - base.Bottom.Y) * num10 < 0f) && num9 > 10f && num9 < num4 - num8 + 10f)
36700 {
36701 velocity.Y += 0.1f * num10;
36702 }
36703 else
36704 {
36705 velocity.Y *= 0.7f;
36706 }
36707 if (owner == Main.myPlayer && num7 < num3)
36708 {
36709 ai[0] = 2f;
36710 ai[1] = targetNPCIndex;
36711 netUpdate = true;
36712 }
36713 }
36714 }
36715 else if (ai[0] == 1f)
36716 {
36717 if (player.HasMinionRestTarget)
36718 {
36719 vector = player.MinionRestTargetPoint;
36720 }
36721 else
36722 {
36723 ai[0] = 0f;
36724 netUpdate = true;
36725 }
36726 int targetNPCIndex2 = -1;
36728 bool flag4 = true;
36729 if (flag && Math.Abs(base.Center.X - vector.X) > num + 20f)
36730 {
36731 flag4 = false;
36732 }
36733 if (flag4)
36734 {
36736 }
36737 if (targetNPCIndex2 != -1)
36738 {
36739 NPC nPC2 = Main.npc[targetNPCIndex2];
36740 direction = (spriteDirection = (nPC2.Center.X > base.Center.X).ToDirectionInt());
36741 float num11 = Math.Abs(vector.X - base.Center.X);
36742 float num12 = Math.Abs(nPC2.Center.X - base.Center.X);
36743 float num13 = Math.Abs(vector.Y - base.Center.Y);
36744 float num14 = Math.Abs(nPC2.Center.Y - base.Bottom.Y);
36745 float num15 = (nPC2.Center.Y > base.Bottom.Y).ToDirectionInt();
36746 if ((num11 < num || (vector.X - base.Center.X) * (float)direction < 0f) && num12 > 20f && num12 < num - num11 + 100f)
36747 {
36748 velocity.X += 0.1f * (float)direction;
36749 }
36750 else
36751 {
36752 velocity.X *= 0.7f;
36753 }
36754 if ((num13 < num4 || (vector.Y - base.Bottom.Y) * num15 < 0f) && num14 > 10f && num14 < num4 - num13 + 10f)
36755 {
36756 velocity.Y += 0.1f * num15;
36757 }
36758 else
36759 {
36760 velocity.Y *= 0.7f;
36761 }
36762 if (owner == Main.myPlayer && num12 < num3)
36763 {
36764 ai[0] = 2f;
36765 ai[1] = targetNPCIndex2;
36766 netUpdate = true;
36767 }
36768 }
36769 else
36770 {
36771 if (Math.Abs(vector.X - base.Center.X) > num + 40f)
36772 {
36773 ai[0] = 3f;
36774 netUpdate = true;
36775 }
36776 else if (Math.Abs(vector.X - base.Center.X) > 20f)
36777 {
36778 direction = (spriteDirection = (vector.X > base.Center.X).ToDirectionInt());
36779 velocity.X += 0.06f * (float)direction;
36780 }
36781 else
36782 {
36783 velocity.X *= 0.8f;
36784 direction = (spriteDirection = (player.Center.X < base.Center.X).ToDirectionInt());
36785 }
36786 if (Math.Abs(vector.Y - base.Center.Y) > num4)
36787 {
36788 ai[0] = 3f;
36789 netUpdate = true;
36790 }
36791 else if (Math.Abs(vector.Y - base.Center.Y) > 10f)
36792 {
36793 velocity.Y += 0.06f * (float)Math.Sign(vector.Y - base.Center.Y);
36794 }
36795 else
36796 {
36797 velocity.Y *= 0.8f;
36798 }
36799 }
36800 if (flag && ++frameCounter >= 9)
36801 {
36802 frameCounter = 0;
36803 if (++frame >= Main.projFrames[type] - 4)
36804 {
36805 frame = 0;
36806 }
36807 }
36808 }
36809 else if (ai[0] == 2f)
36810 {
36811 if (flag)
36812 {
36813 int num16 = 3;
36814 if (frame < 12)
36815 {
36816 frame = 12;
36817 }
36818 if (frame == 12 || frame == 13)
36819 {
36820 num16 = 8;
36821 }
36822 if (++frameCounter >= num16)
36823 {
36824 frameCounter = 0;
36825 if (++frame >= 19)
36826 {
36827 frame = 14;
36828 }
36829 }
36830 }
36831 bool flag5 = false;
36832 if (flag2)
36833 {
36834 flag5 = Distance(player.Center) < num2;
36835 }
36836 NPC nPC3 = null;
36837 int num17 = (int)ai[1];
36838 if (Main.npc.IndexInRange(num17))
36839 {
36840 nPC3 = Main.npc[num17];
36841 if (!nPC3.CanBeChasedBy(this) || Distance(nPC3.Center) > num3)
36842 {
36843 nPC3 = null;
36844 }
36845 }
36846 if (!flag5 || nPC3 == null)
36847 {
36848 ai[1] = 0f;
36849 ai[0] = 0f;
36850 netUpdate = true;
36851 if (frame < 18)
36852 {
36853 frame = 18;
36854 }
36855 }
36856 else
36857 {
36858 int num18 = (((nPC3.Center - player.Center).X > 1f) ? 1 : (-1));
36859 Vector2 targetPosition = nPC3.Center + new Vector2((float)(-num18) * ((float)nPC3.width * 0.5f + 70f), -10f) - base.Center;
36860 float maxAmountAllowedToMove = 6f * Utils.Remap(targetPosition.Length(), 50f, 400f, 1f, 4f);
36861 int num19 = 32;
36863 velocity = velocity.MoveTowards(targetPosition2, num19);
36865 if (localAI[0]++ >= 3f)
36866 {
36867 localAI[0] = 0f;
36868 int targetNPCIndex3 = -1;
36869 float distanceToClosestTarget3 = -1f;
36871 if (targetNPCIndex3 != -1)
36872 {
36873 ai[1] = targetNPCIndex3;
36874 netUpdate = true;
36875 }
36876 }
36877 }
36878 }
36879 else
36880 {
36881 _ = ai[0];
36882 _ = 2f;
36883 }
36884 if (ai[0] != 3f)
36885 {
36886 return;
36887 }
36888 if (player.HasMinionRestTarget)
36889 {
36890 vector = player.MinionRestTargetPoint;
36891 }
36892 else
36893 {
36894 ai[0] = 0f;
36895 netUpdate = true;
36896 }
36897 if (alpha == 0)
36898 {
36899 alpha = 255;
36900 for (int j = 0; j < 30; j++)
36901 {
36902 int num20 = Dust.NewDust(position, width, height, 135, 0f, 0f, 200, default(Color), 1.7f);
36903 Main.dust[num20].noGravity = true;
36904 Main.dust[num20].velocity *= 3f;
36905 Main.dust[num20].shader = GameShaders.Armor.GetSecondaryShader(Main.player[owner].cPet, Main.player[owner]);
36906 num20 = Dust.NewDust(position, width, height, 135, 0f, 0f, 100);
36907 Main.dust[num20].velocity *= 2f;
36908 Main.dust[num20].noGravity = true;
36909 Main.dust[num20].fadeIn = 2.5f;
36910 Main.dust[num20].shader = GameShaders.Armor.GetSecondaryShader(Main.player[owner].cPet, Main.player[owner]);
36911 }
36912 }
36913 else
36914 {
36915 for (int k = 0; k < 2; k++)
36916 {
36917 int num21 = Dust.NewDust(position, width, height, 135, 0f, 0f, 200, default(Color), 1.7f);
36918 Main.dust[num21].noGravity = true;
36919 Main.dust[num21].velocity *= 3f;
36920 Main.dust[num21].noLight = true;
36921 Main.dust[num21].shader = GameShaders.Armor.GetSecondaryShader(Main.player[owner].cPet, Main.player[owner]);
36922 num21 = Dust.NewDust(position, width, height, 135, 0f, 0f, 100);
36923 Main.dust[num21].velocity *= 2f;
36924 Main.dust[num21].noGravity = true;
36925 Main.dust[num21].fadeIn = 2.5f;
36926 Main.dust[num21].noLight = true;
36927 Main.dust[num21].shader = GameShaders.Armor.GetSecondaryShader(Main.player[owner].cPet, Main.player[owner]);
36928 }
36929 }
36930 velocity *= 0.7f;
36931 base.Center = Vector2.Lerp(base.Center, vector, 0.2f);
36932 if (Distance(vector) < 10f)
36933 {
36934 ai[0] = 1f;
36935 netUpdate = true;
36936 }
36937 }
static double Abs(double value)
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 ArmorShaderDataSet Armor
Definition GameShaders.cs:7
void AI_120_StardustGuardian_FindTarget(float lookupRange, ref int targetNPCIndex, ref float distanceToClosestTarget)
static Vector2 Lerp(Vector2 value1, Vector2 value2, float amount)
Definition Vector2.cs:227

References System.Math.Abs(), Terraria.Entity.active, Terraria.Lighting.AddLight(), Terraria.Graphics.Shaders.GameShaders.Armor, Terraria.Entity.Center, Terraria.Player.dead, Terraria.Entity.direction, Terraria.Main.dust, Terraria.Player.HasMinionRestTarget, Microsoft.Xna.Framework.Vector2.Lerp(), Terraria.Player.MinionRestTargetPoint, Terraria.Main.myPlayer, Terraria.Dust.NewDust(), Terraria.Main.npc, Terraria.Main.player, Terraria.Main.projFrames, Terraria.Utils.Remap(), System.Math.Sign(), Terraria.Player.stardustGuardian, System.type, System.X, and Microsoft.Xna.Framework.Vector2.Zero.