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

◆ UpdateNetworkCode()

void Terraria.NPC.UpdateNetworkCode ( int i)
inlineprivate

Definition at line 107419 of file NPC.cs.

107420 {
107421 //IL_01e7: Unknown result type (might be due to invalid IL or missing references)
107422 //IL_01ed: Unknown result type (might be due to invalid IL or missing references)
107423 //IL_01f2: Unknown result type (might be due to invalid IL or missing references)
107424 //IL_00ad: Unknown result type (might be due to invalid IL or missing references)
107425 //IL_00be: Unknown result type (might be due to invalid IL or missing references)
107426 //IL_00cf: Unknown result type (might be due to invalid IL or missing references)
107427 //IL_00e0: Unknown result type (might be due to invalid IL or missing references)
107428 if (!active)
107429 {
107430 netUpdate = true;
107431 }
107432 if (Main.netMode != 2)
107433 {
107434 return;
107435 }
107436 if (Main.npcStreamSpeed > 0 && !townNPC && NPCID.Sets.UsesMultiplayerProximitySyncing[type] && (double)(Math.Abs(velocity.X) + Math.Abs(velocity.Y)) >= 0.5)
107437 {
107438 netStream++;
107439 if (netStream >= Main.npcStreamSpeed)
107440 {
107441 for (int j = 0; j < 255; j++)
107442 {
107443 if (Main.player[j].active)
107444 {
107445 netStream = 0;
107446 float num = Math.Abs(base.Center.X - Main.player[j].Center.X) + Math.Abs(base.Center.Y - Main.player[j].Center.Y);
107447 if (num < 250f)
107448 {
107449 streamPlayer[j] -= 8;
107450 }
107451 else if (num < 500f)
107452 {
107453 streamPlayer[j] -= 4;
107454 }
107455 else if (num < 1000f)
107456 {
107457 streamPlayer[j] -= 2;
107458 }
107459 else if (num < 1500f)
107460 {
107461 streamPlayer[j]--;
107462 }
107463 if (streamPlayer[j] <= 0)
107464 {
107465 streamPlayer[j] = 8;
107466 NetMessage.SendData(23, j, -1, null, i);
107467 }
107468 }
107469 }
107470 }
107471 }
107472 if (townNPC || aiStyle == 16)
107473 {
107474 netSpam = 0;
107475 }
107476 if (netUpdate2)
107477 {
107478 netUpdate = true;
107479 }
107480 if (!active)
107481 {
107482 netSpam = 0;
107483 }
107484 if (netUpdate)
107485 {
107486 if (boss)
107487 {
107488 _ = oldPosition - position;
107489 if (netSpam <= 15)
107490 {
107491 netSpam += 5;
107492 NetMessage.SendData(23, -1, -1, null, i);
107493 netUpdate2 = false;
107494 }
107495 else
107496 {
107497 netUpdate2 = true;
107498 }
107499 }
107500 else if (netSpam <= 90)
107501 {
107502 netSpam += 30;
107503 NetMessage.SendData(23, -1, -1, null, i);
107504 netUpdate2 = false;
107505 }
107506 else
107507 {
107508 netUpdate2 = true;
107509 }
107510 }
107511 if (netSpam > 0)
107512 {
107513 netSpam--;
107514 }
107515 if (active && townNPC && TypeToDefaultHeadIndex(type) > 0)
107516 {
107518 {
107519 byte householdStatus = WorldGen.TownManager.GetHouseholdStatus(this);
107520 NetMessage.SendData(60, -1, -1, null, i, Main.npc[i].homeTileX, Main.npc[i].homeTileY, (int)householdStatus);
107521 }
107525 }
107526 }
Vector2 oldPosition
Definition Entity.cs:35
Vector2 velocity
The velocity of this Entity in world coordinates per tick.
Definition Entity.cs:33
Vector2 position
The position of this Entity in world coordinates.
Definition Entity.cs:28
bool active
If true, the Entity actually exists within the game world. Within the specific entity array,...
Definition Entity.cs:21
static bool[] UsesMultiplayerProximitySyncing
If true for a given NPC type (F:Terraria.NPC.type), then that NPC will sync more the closer it is to ...
Definition NPCID.cs:380
bool boss
Set to true if the NPC is a boss. Prevents off-screen despawn. Bosses also need [AutoloadBossHead] an...
Definition NPC.cs:1141
static int TypeToDefaultHeadIndex(int type)
Definition NPC.cs:2472
int netSpam
Definition NPC.cs:466
bool oldHomeless
Definition NPC.cs:1186
int aiStyle
Selects which vanilla code to use for the AI method. Vanilla NPC AI styles are enumerated in the T:Te...
Definition NPC.cs:1013
int oldHomeTileX
Definition NPC.cs:1188
bool netUpdate2
Definition NPC.cs:1132
int homeTileX
Definition NPC.cs:1180
int type
The NPC ID of this NPC. The NPC ID is a unique number assigned to each NPC loaded into the game....
Definition NPC.cs:990
int oldHomeTileY
Definition NPC.cs:1190
int netStream
Definition NPC.cs:574
bool homeless
Definition NPC.cs:1178
int[] streamPlayer
Definition NPC.cs:576
bool netUpdate
Definition NPC.cs:1130
bool townNPC
Definition NPC.cs:1174
int homeTileY
Definition NPC.cs:1182

References Terraria.Main.netMode, Terraria.Main.npc, Terraria.Main.npcStreamSpeed, Terraria.Main.player, Terraria.NetMessage.SendData(), Terraria.WorldGen.TownManager, and Terraria.ID.NPCID.Sets.UsesMultiplayerProximitySyncing.

+ Here is the call graph for this function: