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

◆ SpawnOnPlayer()

static void Terraria.NPC.SpawnOnPlayer ( int plr,
int Type )
inlinestatic

Definition at line 90808 of file NPC.cs.

90809 {
90810 //IL_0055: Unknown result type (might be due to invalid IL or missing references)
90811 //IL_006c: Unknown result type (might be due to invalid IL or missing references)
90812 //IL_03ac: Unknown result type (might be due to invalid IL or missing references)
90813 //IL_03b9: Unknown result type (might be due to invalid IL or missing references)
90814 //IL_044e: Unknown result type (might be due to invalid IL or missing references)
90815 //IL_02c8: Unknown result type (might be due to invalid IL or missing references)
90816 //IL_02d5: Unknown result type (might be due to invalid IL or missing references)
90817 //IL_0371: Unknown result type (might be due to invalid IL or missing references)
90818 //IL_0257: Unknown result type (might be due to invalid IL or missing references)
90819 //IL_093a: Unknown result type (might be due to invalid IL or missing references)
90820 //IL_0733: Unknown result type (might be due to invalid IL or missing references)
90821 //IL_073d: Unknown result type (might be due to invalid IL or missing references)
90822 //IL_074f: Unknown result type (might be due to invalid IL or missing references)
90823 //IL_0759: Unknown result type (might be due to invalid IL or missing references)
90824 //IL_0772: Unknown result type (might be due to invalid IL or missing references)
90825 //IL_077c: Unknown result type (might be due to invalid IL or missing references)
90826 //IL_078c: Unknown result type (might be due to invalid IL or missing references)
90827 if (Main.netMode == 1 || (Type == 262 && AnyNPCs(262)))
90828 {
90829 return;
90830 }
90831 Tile tile;
90832 switch (Type)
90833 {
90834 case 245:
90835 if (AnyNPCs(245))
90836 {
90837 return;
90838 }
90839 try
90840 {
90841 int num12 = (int)Main.player[plr].Center.X / 16;
90842 int num23 = (int)Main.player[plr].Center.Y / 16;
90843 int num25 = 0;
90844 int num26 = 0;
90845 for (int j = num12 - 20; j < num12 + 20; j++)
90846 {
90847 for (int k = num23 - 20; k < num23 + 20; k++)
90848 {
90849 tile = Main.tile[j, k];
90850 if (!tile.active())
90851 {
90852 continue;
90853 }
90854 tile = Main.tile[j, k];
90855 if (tile.type != 237)
90856 {
90857 continue;
90858 }
90859 tile = Main.tile[j, k];
90860 if (tile.frameX == 18)
90861 {
90862 tile = Main.tile[j, k];
90863 if (tile.frameY == 0)
90864 {
90865 num25 = j;
90866 num26 = k;
90867 }
90868 }
90869 }
90870 }
90871 if (num25 <= 0 || num26 <= 0)
90872 {
90873 return;
90874 }
90875 int num27 = num26 - 15;
90876 int num28 = num26 - 15;
90877 for (int num29 = num26; num29 > num26 - 50; num29--)
90878 {
90879 if (WorldGen.SolidTile(num25, num29))
90880 {
90881 num27 = num29;
90882 break;
90883 }
90884 }
90885 for (int l = num26; l < num26 + 50; l++)
90886 {
90887 if (WorldGen.SolidTile(num25, l))
90888 {
90889 num28 = l;
90890 break;
90891 }
90892 }
90893 num26 = (num27 + num27 + num28) / 3;
90894 int num30 = NewNPC(GetBossSpawnSource(plr), num25 * 16 + 8, num26 * 16, 245);
90895 Main.npc[num30].target = plr;
90896 string typeName2 = Main.npc[num30].TypeName;
90897 if (Main.netMode == 0)
90898 {
90899 Main.NewText(Language.GetTextValue("Announcement.HasAwoken", typeName2), 175, 75);
90900 }
90901 else if (Main.netMode == 2)
90902 {
90903 ChatHelper.BroadcastChatMessage(NetworkText.FromKey("Announcement.HasAwoken", Main.npc[num30].GetTypeNetName()), new Color(175, 75, 255));
90904 }
90905 return;
90906 }
90907 catch
90908 {
90909 return;
90910 }
90911 case 370:
90912 {
90913 Player player2 = Main.player[plr];
90914 if (!player2.active || player2.dead)
90915 {
90916 return;
90917 }
90918 for (int i = 0; i < 1000; i++)
90919 {
90920 Projectile projectile = Main.projectile[i];
90921 if (projectile.active && projectile.bobber && projectile.owner == plr)
90922 {
90923 int num = NewNPC(GetBossSpawnSource(plr), (int)projectile.Center.X, (int)projectile.Center.Y + 100, 370);
90924 string typeName = Main.npc[num].TypeName;
90925 if (Main.netMode == 0)
90926 {
90927 Main.NewText(Language.GetTextValue("Announcement.HasAwoken", typeName), 175, 75);
90928 }
90929 else if (Main.netMode == 2)
90930 {
90931 ChatHelper.BroadcastChatMessage(NetworkText.FromKey("Announcement.HasAwoken", Main.npc[num].GetTypeNetName()), new Color(175, 75, 255));
90932 }
90933 break;
90934 }
90935 }
90936 return;
90937 }
90938 case 398:
90939 if (!AnyNPCs(Type))
90940 {
90941 Player player = Main.player[plr];
90942 NewNPC(GetBossSpawnSource(plr), (int)player.Center.X, (int)player.Center.Y - 150, Type);
90943 if (Main.netMode == 0)
90944 {
90945 Main.NewText(Language.GetTextValue("Announcement.HasAwoken", Language.GetTextValue("Enemies.MoonLord")), 175, 75);
90946 }
90947 else if (Main.netMode == 2)
90948 {
90949 ChatHelper.BroadcastChatMessage(NetworkText.FromKey("Announcement.HasAwoken", NetworkText.FromKey("Enemies.MoonLord")), new Color(175, 75, 255));
90950 }
90951 }
90952 return;
90953 }
90954 bool flag = false;
90955 int num2 = 0;
90956 int num3 = 0;
90957 int num4 = (int)(Main.player[plr].position.X / 16f) - spawnRangeX * 2;
90958 int num5 = (int)(Main.player[plr].position.X / 16f) + spawnRangeX * 2;
90959 int num6 = (int)(Main.player[plr].position.Y / 16f) - spawnRangeY * 2;
90960 int num7 = (int)(Main.player[plr].position.Y / 16f) + spawnRangeY * 2;
90961 int num8 = (int)(Main.player[plr].position.X / 16f) - safeRangeX;
90962 int num9 = (int)(Main.player[plr].position.X / 16f) + safeRangeX;
90963 int num10 = (int)(Main.player[plr].position.Y / 16f) - safeRangeY;
90964 int num11 = (int)(Main.player[plr].position.Y / 16f) + safeRangeY;
90965 if (num4 < 0)
90966 {
90967 num4 = 0;
90968 }
90969 if (num5 > Main.maxTilesX)
90970 {
90971 num5 = Main.maxTilesX;
90972 }
90973 if (num6 < 0)
90974 {
90975 num6 = 0;
90976 }
90977 if (num7 > Main.maxTilesY)
90978 {
90979 num7 = Main.maxTilesY;
90980 }
90981 Rectangle rectangle = default(Rectangle);
90982 Rectangle rectangle2 = default(Rectangle);
90983 for (int m = 0; m < 1000; m++)
90984 {
90985 for (int n = 0; n < 100; n++)
90986 {
90987 int num13 = Main.rand.Next(num4, num5);
90988 int num14 = Main.rand.Next(num6, num7);
90989 tile = Main.tile[num13, num14];
90990 if (tile.nactive())
90991 {
90992 bool[] tileSolid = Main.tileSolid;
90993 tile = Main.tile[num13, num14];
90994 if (tileSolid[tile.type])
90995 {
90996 goto IL_085c;
90997 }
90998 }
90999 bool[] wallHouse = Main.wallHouse;
91000 tile = Main.tile[num13, num14];
91001 if (wallHouse[tile.wall] && m < 999)
91002 {
91003 continue;
91004 }
91005 if (Type == 50 && m < 500)
91006 {
91007 tile = Main.tile[num14, num14];
91008 if (tile.wall > 0)
91009 {
91010 continue;
91011 }
91012 }
91013 for (int num15 = num14; num15 < Main.maxTilesY; num15++)
91014 {
91015 tile = Main.tile[num13, num15];
91016 if (!tile.nactive())
91017 {
91018 continue;
91019 }
91020 bool[] tileSolid2 = Main.tileSolid;
91021 tile = Main.tile[num13, num15];
91022 if (tileSolid2[tile.type])
91023 {
91025 {
91026 tile = Main.tile[num13, num15];
91027 _ = ref tile.type;
91028 num2 = num13;
91029 num3 = num15;
91030 flag = true;
91031 }
91032 break;
91033 }
91034 }
91035 if (flag && Type == 50 && m < 900)
91036 {
91037 int num16 = 20;
91038 if (!Collision.CanHit(new Vector2((float)num2, (float)(num3 - 1)) * 16f, 16, 16, new Vector2((float)num2, (float)(num3 - 1 - num16)) * 16f, 16, 16) || !Collision.CanHit(new Vector2((float)num2, (float)(num3 - 1 - num16)) * 16f, 16, 16, Main.player[plr].Center, 0, 0))
91039 {
91040 num2 = 0;
91041 num3 = 0;
91042 flag = false;
91043 }
91044 }
91045 if (flag && m < 999)
91046 {
91047 int num17 = num2 - spawnSpaceX / 2;
91048 int num18 = num2 + spawnSpaceX / 2;
91049 int num19 = num3 - spawnSpaceY;
91050 int num20 = num3;
91051 if (num17 < 0)
91052 {
91053 flag = false;
91054 }
91055 if (num18 > Main.maxTilesX)
91056 {
91057 flag = false;
91058 }
91059 if (num19 < 0)
91060 {
91061 flag = false;
91062 }
91063 if (num20 > Main.maxTilesY)
91064 {
91065 flag = false;
91066 }
91067 if (flag)
91068 {
91069 for (int num21 = num17; num21 < num18; num21++)
91070 {
91071 for (int num22 = num19; num22 < num20; num22++)
91072 {
91073 tile = Main.tile[num21, num22];
91074 if (tile.nactive())
91075 {
91076 bool[] tileSolid3 = Main.tileSolid;
91077 tile = Main.tile[num21, num22];
91078 if (tileSolid3[tile.type])
91079 {
91080 flag = false;
91081 break;
91082 }
91083 }
91084 }
91085 }
91086 }
91087 }
91088 goto IL_085c;
91089 IL_085c:
91090 if (flag || flag)
91091 {
91092 break;
91093 }
91094 }
91095 if (flag && m < 999)
91096 {
91097 ((Rectangle)(ref rectangle))._002Ector(num2 * 16, num3 * 16, 16, 16);
91098 for (int num24 = 0; num24 < 255; num24++)
91099 {
91100 if (Main.player[num24].active)
91101 {
91102 ((Rectangle)(ref rectangle2))._002Ector((int)(Main.player[num24].position.X + (float)(Main.player[num24].width / 2) - (float)(sWidth / 2) - (float)safeRangeX), (int)(Main.player[num24].position.Y + (float)(Main.player[num24].height / 2) - (float)(sHeight / 2) - (float)safeRangeY), sWidth + safeRangeX * 2, sHeight + safeRangeY * 2);
91103 if (((Rectangle)(ref rectangle)).Intersects(rectangle2))
91104 {
91105 flag = false;
91106 }
91107 }
91108 }
91109 }
91110 if (flag)
91111 {
91112 break;
91113 }
91114 }
91115 if (flag)
91116 {
91117 int spawnPositionX = num2 * 16 + 8;
91118 int spawnPositionY = num3 * 16;
91120 }
91121 }
static void BroadcastChatMessage(NetworkText text, Color color, int excludedPlayer=-1)
Definition ChatHelper.cs:51
static string GetTextValue(string key)
Retrieves the text value for a specified localization key. The text returned will be for the currentl...
Definition Language.cs:35
Contains methods to access or retrieve localization values. The Localization Guideteaches more about ...
Definition Language.cs:12
static NetworkText FromKey(string key, params object[] substitutions)
Creates a NetworkText object from a localization key and optional substitutions. The receiving client...
Represents text that will be sent over the network in multiplayer and displayed to the receiving user...
static int spawnRangeY
Definition NPC.cs:614
static void SpawnBoss(int spawnPositionX, int spawnPositionY, int Type, int targetPlayerIndex)
Definition NPC.cs:91149
static int safeRangeY
Definition NPC.cs:618
static int spawnSpaceX
Definition NPC.cs:542
static int spawnRangeX
Definition NPC.cs:612
static int sWidth
Definition NPC.cs:608
static bool AnyNPCs(int Type)
Returns true if there are any active NPC in the world of the given NPC type (F:Terraria....
Definition NPC.cs:106615
static int safeRangeX
Definition NPC.cs:616
static int NewNPC(IEntitySource source, int X, int Y, int Type, int Start=0, float ai0=0f, float ai1=0f, float ai2=0f, float ai3=0f, int Target=255)
Spawns an NPC into the game world with the given type. This method should not be called on multipla...
Definition NPC.cs:91239
static IEntitySource GetBossSpawnSource(int targetPlayerIndex)
Definition NPC.cs:91144
static int spawnSpaceY
Definition NPC.cs:544
static int sHeight
Definition NPC.cs:610

References Terraria.Entity.active, Terraria.Tile.active(), Terraria.Projectile.bobber, Terraria.Chat.ChatHelper.BroadcastChatMessage(), Terraria.Collision.CanHit(), Terraria.Entity.Center, Terraria.Tile.frameX, Terraria.Tile.frameY, Terraria.Localization.NetworkText.FromKey(), Terraria.Localization.Language.GetTextValue(), Terraria.Main.maxTilesX, Terraria.Main.maxTilesY, Terraria.Tile.nactive(), Terraria.Main.netMode, Terraria.Main.NewText(), Terraria.Main.npc, Terraria.Projectile.owner, Terraria.Main.player, Terraria.Main.projectile, Terraria.Main.rand, Terraria.WorldGen.SolidTile(), Terraria.Main.tile, Terraria.Main.tileSolid, Terraria.Tile.type, Terraria.Tile.wall, and Terraria.Main.wallHouse.

Referenced by Terraria.WorldGen.Check3x3(), Terraria.WorldGen.CheckJunglePlant(), Terraria.WorldGen.CheckOrb(), Terraria.WorldGen.CheckSign(), Terraria.NPC.DoDeathEvents(), Terraria.NPC.DoDeathEvents_AdvanceSlimeRain(), Terraria.MessageBuffer.GetData(), Terraria.Player.ItemCheck_CheckFishingBobber_PullBobber(), Terraria.Player.ItemCheck_UseBossSpawners(), Terraria.WorldGen.SmashAltar(), Terraria.NPC.SpawnMechQueen(), Terraria.GameContent.Events.DD2Event.SummonBetsy(), Terraria.Player.TileInteractionsUse(), and Terraria.Main.UpdateTime().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: