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

◆ UpdateNPC()

void Terraria.NPC.UpdateNPC ( int i)
inline

Definition at line 87092 of file NPC.cs.

87093 {
87094 whoAmI = i;
87095 if (!active)
87096 {
87097 return;
87098 }
87099 if (offSetDelayTime > 0)
87100 {
87101 netOffset *= 0f;
87102 }
87103 else if (Main.netMode == 2)
87104 {
87105 netOffset *= 0f;
87106 }
87107 else if (Main.multiplayerNPCSmoothingRange <= 0)
87108 {
87109 netOffset *= 0f;
87110 }
87111 else if (netOffset != new Vector2(0f, 0f))
87112 {
87114 {
87115 netOffset *= 0f;
87116 }
87118 {
87119 netOffset *= 0f;
87120 }
87121 else
87122 {
87123 float num = 2f;
87124 float num2 = Main.multiplayerNPCSmoothingRange;
87125 float num3 = netOffset.Length();
87126 if (num3 > num2)
87127 {
87129 netOffset *= num2;
87130 num3 = netOffset.Length();
87131 }
87132 num += num3 / num2 * num;
87134 vector.Normalize();
87135 vector *= num;
87136 netOffset -= vector;
87137 if (netOffset.Length() < num)
87138 {
87139 netOffset *= 0f;
87140 }
87141 if (townNPC)
87142 {
87143 if (Vector2.Distance(position, new Vector2(homeTileX * 16 + 8 - width / 2, (float)(homeTileY * 16 - height) - 0.1f)) < 1f)
87144 {
87145 netOffset *= 0f;
87146 }
87147 if (ai[0] == 25f)
87148 {
87149 netOffset *= 0f;
87150 }
87151 }
87152 }
87153 }
87155 if (type == 368)
87156 {
87157 travelNPC = true;
87158 }
87159 if (Main.netMode != 2)
87160 {
87162 }
87166 if (aiStyle == 7 && position.Y > Main.bottomWorld - 640f + (float)height && Main.netMode != 1 && !Main.xMas)
87167 {
87168 StrikeNPCNoInteraction(9999, 0f, 0);
87169 if (Main.netMode == 2)
87170 {
87171 NetMessage.SendData(28, -1, -1, null, whoAmI, 9999f);
87172 }
87173 }
87174 if (Main.netMode == 1)
87175 {
87176 bool flag = false;
87177 int num4 = (int)(position.X + (float)(width / 2)) / 16;
87178 int num5 = (int)(position.Y + (float)(height / 2)) / 16;
87179 try
87180 {
87181 if (num4 >= 4 && num4 <= Main.maxTilesX - 4 && num5 >= 4 && num5 <= Main.maxTilesY - 4)
87182 {
87183 if (Main.tile[num4, num5] == null)
87184 {
87185 flag = true;
87186 }
87187 else if (Main.tile[num4 - 3, num5] == null)
87188 {
87189 flag = true;
87190 }
87191 else if (Main.tile[num4 + 3, num5] == null)
87192 {
87193 flag = true;
87194 }
87195 else if (Main.tile[num4, num5 - 3] == null)
87196 {
87197 flag = true;
87198 }
87199 else if (Main.tile[num4, num5 + 3] == null)
87200 {
87201 flag = true;
87202 }
87203 }
87204 }
87205 catch
87206 {
87207 flag = true;
87208 }
87209 if (flag)
87210 {
87211 return;
87212 }
87213 }
87221 UpdateNPC_UpdateGravity(out var maxFallSpeed);
87222 if (soundDelay > 0)
87223 {
87224 soundDelay--;
87225 }
87226 if (life <= 0)
87227 {
87228 active = false;
87230 netUpdate = false;
87231 justHit = false;
87232 return;
87233 }
87234 oldTarget = target;
87237 float num6 = 1f + Math.Abs(velocity.X) / 3f;
87238 if (gfxOffY > 0f)
87239 {
87240 gfxOffY -= num6 * stepSpeed;
87241 if (gfxOffY < 0f)
87242 {
87243 gfxOffY = 0f;
87244 }
87245 }
87246 else if (gfxOffY < 0f)
87247 {
87248 gfxOffY += num6 * stepSpeed;
87249 if (gfxOffY > 0f)
87250 {
87251 gfxOffY = 0f;
87252 }
87253 }
87254 if (gfxOffY > 16f)
87255 {
87256 gfxOffY = 16f;
87257 }
87258 if (gfxOffY < -16f)
87259 {
87260 gfxOffY = -16f;
87261 }
87263 IdleSounds();
87264 AI();
87266 if (Main.netMode != 2 && extraValue > 0)
87267 {
87268 int num7 = 244;
87269 float num8 = 30f;
87270 if (extraValue >= 1000000)
87271 {
87272 num7 = 247;
87273 num8 *= 0.25f;
87274 }
87275 else if (extraValue >= 10000)
87276 {
87277 num7 = 246;
87278 num8 *= 0.5f;
87279 }
87280 else if (extraValue >= 100)
87281 {
87282 num7 = 245;
87283 num8 *= 0.75f;
87284 }
87285 if (Main.rand.Next((int)num8) == 0)
87286 {
87288 int num9 = Dust.NewDust(position, width, height, num7, 0f, 0f, 254, default(Color), 0.25f);
87289 Main.dust[num9].velocity *= 0.1f;
87291 }
87292 }
87293 for (int j = 0; j < 256; j++)
87294 {
87295 if (immune[j] > 0)
87296 {
87297 immune[j]--;
87298 }
87299 }
87300 if (!noGravity && !noTileCollide)
87301 {
87302 int num10 = (int)(position.X + (float)(width / 2)) / 16;
87303 int num11 = (int)(position.Y + (float)(height / 2)) / 16;
87304 if (WorldGen.InWorld(num10, num11) && Main.tile[num10, num11] == null)
87305 {
87306 gravity = 0f;
87307 velocity.X = 0f;
87308 velocity.Y = 0f;
87309 }
87310 }
87311 if (!noGravity)
87312 {
87313 velocity.Y += gravity;
87314 if (velocity.Y > maxFallSpeed)
87315 {
87316 velocity.Y = maxFallSpeed;
87317 }
87318 }
87319 if ((double)velocity.X < 0.005 && (double)velocity.X > -0.005)
87320 {
87321 velocity.X = 0f;
87322 }
87323 if (Main.netMode != 1 && type != 37 && (friendly || NPCID.Sets.TakesDamageFromHostilesWithoutBeingFriendly[type]))
87324 {
87325 if (townNPC)
87326 {
87327 CheckDrowning();
87328 }
87331 }
87332 if (Main.netMode != 1 && (npcsFoundForCheckActive[210] || npcsFoundForCheckActive[211]) && !NPCID.Sets.HurtingBees[type])
87333 {
87335 }
87336 if (!noTileCollide)
87337 {
87339 }
87340 else
87341 {
87344 position += velocity;
87345 if (onFire && boss && Main.netMode != 1 && Collision.WetCollision(position, width, height))
87346 {
87347 for (int k = 0; k < maxBuffs; k++)
87348 {
87349 if (buffType[k] == 24)
87350 {
87351 DelBuff(k);
87352 }
87353 }
87354 }
87355 }
87356 if (Main.netMode != 1 && !noTileCollide && lifeMax > 1 && Collision.SwitchTiles(position, width, height, oldPosition, 2) && (type == 46 || type == 148 || type == 149 || type == 303 || type == 361 || type == 362 || type == 364 || type == 366 || type == 367 || (type >= 442 && type <= 448) || type == 602 || type == 608 || type == 614 || type == 687))
87357 {
87358 ai[0] = 1f;
87359 ai[1] = 400f;
87360 ai[2] = 0f;
87361 }
87362 FindFrame();
87365 CheckActive();
87366 netUpdate = false;
87367 justHit = false;
87368 }
static double Abs(double value)
Vector2 oldPosition
Definition Entity.cs:18
int oldDirection
Definition Entity.cs:22
Vector2 velocity
Definition Entity.cs:16
Vector2 position
Definition Entity.cs:14
static bool[] AllNPCs
Definition NPCID.cs:4174
static bool[] TakesDamageFromHostilesWithoutBeingFriendly
Definition NPCID.cs:4172
static bool[] NoMultiplayerSmoothingByType
Definition NPCID.cs:4194
static bool[] NoMultiplayerSmoothingByAI
Definition NPCID.cs:4196
static bool[] HurtingBees
Definition NPCID.cs:4176
bool boss
Definition NPC.cs:515
Vector2 netOffset
Definition NPC.cs:103
void UpdateNPC_CritterSounds()
Definition NPC.cs:88944
int[] immune
Definition NPC.cs:441
void FindFrame()
Definition NPC.cs:59052
void UpdateNPC_BuffApplyDOTs()
Definition NPC.cs:88284
void CheckDrowning()
Definition NPC.cs:91557
void UpdateNPC_BuffSetFlags(bool lowerBuffTime=true)
Definition NPC.cs:88727
int oldTarget
Definition NPC.cs:499
static readonly int maxBuffs
Definition NPC.cs:211
int lifeMax
Definition NPC.cs:479
float gfxOffY
Definition NPC.cs:125
int aiStyle
Definition NPC.cs:453
void UpdateNPC_BuffApplyVFX()
Definition NPC.cs:87875
static float gravity
Definition NPC.cs:129
static bool travelNPC
Definition NPC.cs:539
bool noGravity
Definition NPC.cs:503
void UpdateNPC_CastLights()
Definition NPC.cs:89049
float[] ai
Definition NPC.cs:447
int oldDirectionY
Definition NPC.cs:497
int extraValue
Definition NPC.cs:525
void UpdateNPC_BuffFlagsReset()
Definition NPC.cs:88861
int homeTileX
Definition NPC.cs:543
void UpdateNetworkCode(int i)
Definition NPC.cs:87404
bool friendly
Definition NPC.cs:555
float stepSpeed
Definition NPC.cs:127
void CheckActive()
Definition NPC.cs:70168
void UpdateNPC_UpdateTrails()
Definition NPC.cs:87556
bool onFire
Definition NPC.cs:225
void TryPortalJumping()
Definition NPC.cs:91611
int type
Definition NPC.cs:445
double StrikeNPCNoInteraction(int Damage, float knockBack, int hitDirection, bool crit=false, bool noEffect=false, bool fromNet=false)
Definition NPC.cs:78015
void DelBuff(int buffIndex)
Definition NPC.cs:86824
void SubAI_HandleTemporaryCatchableNPCPlayerInvulnerability()
Definition NPC.cs:87370
void IdleSounds()
Definition NPC.cs:86893
bool noTileCollide
Definition NPC.cs:505
static int offSetDelayTime
Definition NPC.cs:634
void UpdateAltTexture()
Definition NPC.cs:87028
void UpdateNPC_UpdateGravity(out float maxFallSpeed)
Definition NPC.cs:87655
bool justHit
Definition NPC.cs:455
void UpdateCollision()
Definition NPC.cs:89241
void CheckLifeRegen()
Definition NPC.cs:89208
void TrySyncingUniqueTownNPCData(int npcIndex)
Definition NPC.cs:87395
void GetHurtByOtherNPCs(bool[] acceptableNPCIDs)
Definition NPC.cs:89134
int life
Definition NPC.cs:477
static bool[] npcsFoundForCheckActive
Definition NPC.cs:429
int soundDelay
Definition NPC.cs:437
void UpdateNPC_BloodMoonTransformations()
Definition NPC.cs:88673
void UpdateNPC_BuffClearExpiredBuffs()
Definition NPC.cs:88654
void UpdateNPC_SoulDrainDebuff()
Definition NPC.cs:87735
int[] buffType
Definition NPC.cs:213
int directionY
Definition NPC.cs:443
bool netUpdate
Definition NPC.cs:507
int target
Definition NPC.cs:459
bool townNPC
Definition NPC.cs:537
void AI()
Definition NPC.cs:13607
int homeTileY
Definition NPC.cs:545
void UpdateNPC_TeleportVisuals()
Definition NPC.cs:88895
static float Distance(Vector2 value1, Vector2 value2)
Definition Vector2.cs:91

References System.Math.Abs(), Terraria.ID.NPCID.Sets.AllNPCs, Terraria.Main.bottomWorld, Microsoft.Xna.Framework.Vector2.Distance(), Terraria.Main.dust, Terraria.ID.NPCID.Sets.HurtingBees, Terraria.WorldGen.InWorld(), Microsoft.Xna.Framework.Vector2.Length(), Terraria.Main.maxTilesY, Terraria.Main.multiplayerNPCSmoothingRange, Terraria.Main.netMode, Terraria.Dust.NewDust(), Terraria.ID.NPCID.Sets.NoMultiplayerSmoothingByAI, Terraria.ID.NPCID.Sets.NoMultiplayerSmoothingByType, Microsoft.Xna.Framework.Vector2.Normalize(), Terraria.Main.rand, Terraria.NetMessage.SendData(), Terraria.Collision.SwitchTiles(), Terraria.ID.NPCID.Sets.TakesDamageFromHostilesWithoutBeingFriendly, Terraria.Main.tile, System.type, Microsoft.Xna.Framework.Graphics.Vector2, Terraria.Collision.WetCollision(), and Terraria.Main.xMas.