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

◆ UpdateNetworkCode()

void Terraria.NPC.UpdateNetworkCode ( int i)
inlineprivate

Definition at line 87404 of file NPC.cs.

87405 {
87406 if (!active)
87407 {
87408 netUpdate = true;
87409 }
87410 if (Main.netMode != 2)
87411 {
87412 return;
87413 }
87414 if (Main.npcStreamSpeed > 0 && !townNPC && NPCID.Sets.UsesMultiplayerProximitySyncing[type] && (double)(Math.Abs(velocity.X) + Math.Abs(velocity.Y)) >= 0.5)
87415 {
87416 netStream++;
87417 if (netStream >= Main.npcStreamSpeed)
87418 {
87419 for (int j = 0; j < 255; j++)
87420 {
87421 if (Main.player[j].active)
87422 {
87423 netStream = 0;
87424 float num = Math.Abs(base.Center.X - Main.player[j].Center.X) + Math.Abs(base.Center.Y - Main.player[j].Center.Y);
87425 if (num < 250f)
87426 {
87427 streamPlayer[j] -= 8;
87428 }
87429 else if (num < 500f)
87430 {
87431 streamPlayer[j] -= 4;
87432 }
87433 else if (num < 1000f)
87434 {
87435 streamPlayer[j] -= 2;
87436 }
87437 else if (num < 1500f)
87438 {
87439 streamPlayer[j]--;
87440 }
87441 if (streamPlayer[j] <= 0)
87442 {
87443 streamPlayer[j] = 8;
87444 NetMessage.SendData(23, j, -1, null, i);
87445 }
87446 }
87447 }
87448 }
87449 }
87450 if (townNPC || aiStyle == 16)
87451 {
87452 netSpam = 0;
87453 }
87454 if (netUpdate2)
87455 {
87456 netUpdate = true;
87457 }
87458 if (!active)
87459 {
87460 netSpam = 0;
87461 }
87462 if (netUpdate)
87463 {
87464 if (boss)
87465 {
87467 if (netSpam <= 15)
87468 {
87469 netSpam += 5;
87470 NetMessage.SendData(23, -1, -1, null, i);
87471 netUpdate2 = false;
87472 }
87473 else
87474 {
87475 netUpdate2 = true;
87476 }
87477 }
87478 else if (netSpam <= 90)
87479 {
87480 netSpam += 30;
87481 NetMessage.SendData(23, -1, -1, null, i);
87482 netUpdate2 = false;
87483 }
87484 else
87485 {
87486 netUpdate2 = true;
87487 }
87488 }
87489 if (netSpam > 0)
87490 {
87491 netSpam--;
87492 }
87494 {
87496 {
87497 byte householdStatus = WorldGen.TownManager.GetHouseholdStatus(this);
87498 NetMessage.SendData(60, -1, -1, null, i, Main.npc[i].homeTileX, Main.npc[i].homeTileY, (int)householdStatus);
87499 }
87503 }
87504 }
static double Abs(double value)
Vector2 oldPosition
Definition Entity.cs:18
Vector2 velocity
Definition Entity.cs:16
Vector2 position
Definition Entity.cs:14
static bool[] UsesMultiplayerProximitySyncing
Definition NPCID.cs:4192
bool boss
Definition NPC.cs:515
static int TypeToDefaultHeadIndex(int type)
Definition NPC.cs:1651
int netSpam
Definition NPC.cs:67
bool oldHomeless
Definition NPC.cs:549
int aiStyle
Definition NPC.cs:453
int oldHomeTileX
Definition NPC.cs:551
bool netUpdate2
Definition NPC.cs:509
int homeTileX
Definition NPC.cs:543
int type
Definition NPC.cs:445
int oldHomeTileY
Definition NPC.cs:553
int netStream
Definition NPC.cs:149
bool homeless
Definition NPC.cs:541
int[] streamPlayer
Definition NPC.cs:151
bool netUpdate
Definition NPC.cs:507
bool townNPC
Definition NPC.cs:537
int homeTileY
Definition NPC.cs:545

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