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

◆ DrawNPCExtras()

void Terraria.Main.DrawNPCExtras ( NPC n,
bool beforeDraw,
float addHeight,
float addY,
Microsoft::Xna::Framework::Color npcColor,
Vector2 halfSize,
SpriteEffects npcSpriteEffect,
Vector2 screenPosition )
inlineprotected

Definition at line 25235 of file Main.cs.

25236 {
25237 if (!beforeDraw && n.UsesPartyHat())
25238 {
25239 int num = n.frame.Y / n.frame.Height;
25241 if (num >= array.Length)
25242 {
25243 num = 0;
25244 }
25245 Texture2D value = TextureAssets.Extra[72].Value;
25246 int num2 = 0;
25247 switch (n.GetPartyHatColor())
25248 {
25249 case PartyHatColor.Pink:
25250 num2 = 16;
25251 break;
25252 case PartyHatColor.Cyan:
25253 num2 = 17;
25254 break;
25255 case PartyHatColor.Purple:
25256 num2 = 18;
25257 break;
25258 case PartyHatColor.White:
25259 num2 = 19;
25260 break;
25261 }
25263 rectangle.Width -= 2;
25264 rectangle.Height -= 2;
25265 int num3 = 0;
25266 int num4 = 0;
25267 int num5 = n.spriteDirection;
25268 if (n.type == 663)
25269 {
25270 num3 = 1;
25271 }
25272 if (n.type == 637)
25273 {
25274 num3 = 6;
25275 switch (num)
25276 {
25277 case 19:
25278 case 22:
25279 case 23:
25280 case 24:
25281 case 25:
25282 case 26:
25283 case 27:
25284 num3 -= 2;
25285 break;
25286 case 11:
25287 case 12:
25288 case 13:
25289 case 14:
25290 case 15:
25291 num3 += 2;
25292 break;
25293 }
25294 }
25295 if (n.type == 638)
25296 {
25297 num3 = 12;
25298 }
25299 if (n.type == 656)
25300 {
25301 num3 = 6;
25302 switch (num)
25303 {
25304 case 1:
25305 case 2:
25306 case 3:
25307 num3 -= 2;
25308 break;
25309 case 18:
25310 case 19:
25311 case 20:
25312 case 21:
25313 case 22:
25314 case 23:
25315 case 24:
25316 case 25:
25317 num3 -= 4;
25318 break;
25319 case 8:
25320 num3 -= 2;
25321 break;
25322 }
25323 }
25324 if (NPCID.Sets.IsTownSlime[n.type])
25325 {
25326 num5 *= -1;
25327 switch (n.type)
25328 {
25329 default:
25330 num3 = 1;
25331 break;
25332 case 670:
25333 num3 = -1;
25334 break;
25335 case 681:
25336 num3 = -2;
25337 break;
25338 case 682:
25339 num3 = -1;
25340 num4 = 2;
25341 break;
25342 case 683:
25343 num3 = -1;
25344 num4 = -2;
25345 break;
25346 case 684:
25347 num3 = -4;
25348 break;
25349 case 679:
25350 break;
25351 }
25352 }
25353 if (n.IsShimmerVariant)
25354 {
25355 switch (n.type)
25356 {
25357 case 38:
25358 num3 += 2;
25359 num4 = -2;
25360 break;
25361 case 178:
25362 case 228:
25363 num3 = -4;
25364 num4 = -4;
25365 break;
25366 case 107:
25367 num3 = 2;
25368 num4 = -6;
25369 break;
25370 case 54:
25371 num4 = -6;
25372 break;
25373 case 160:
25374 num4 = -2;
25375 break;
25376 case 108:
25377 case 124:
25378 case 208:
25379 case 209:
25380 case 227:
25381 num4 = -4;
25382 break;
25383 }
25384 }
25385 Vector2 vector = n.Top + new Vector2(-2 * num5, n.gfxOffY);
25386 vector.X += num3 * num5;
25387 vector.Y += array[num];
25388 vector.Y += num4;
25389 vector.Y += NPCID.Sets.HatOffsetY[n.type];
25390 int num6 = 0;
25391 if (n.ai[0] == 5f)
25392 {
25393 num6 = -4;
25394 if (n.type == 38)
25395 {
25396 num6 = -8;
25397 }
25398 if (n.type == 124)
25399 {
25400 num6 = -2;
25401 }
25402 if (n.type == 550)
25403 {
25404 num6 = -4;
25405 }
25406 if (n.type == 588)
25407 {
25408 num6 = -4;
25409 }
25410 if (n.type == 108 || n.type == 178)
25411 {
25412 num6 = -6;
25413 }
25414 if (n.type == 637)
25415 {
25416 num6 = -12;
25417 }
25418 if (n.type == 663)
25419 {
25420 num6 = -8;
25421 }
25422 }
25423 vector.Y += num6;
25424 if (n.type == 229 && n.ai[0] == 12f)
25425 {
25426 vector.X -= num5 * 4;
25427 }
25428 if (n.type == 550 && n.ai[0] == 5f)
25429 {
25430 vector.X += num5 * 7;
25431 }
25432 Vector2 origin = rectangle.Size() - new Vector2(rectangle.Width / 2, 12f);
25433 int num7 = 0;
25434 switch (n.type)
25435 {
25436 case 550:
25437 num7 = -4;
25438 break;
25439 case 588:
25440 num7 = 0;
25441 break;
25442 case 227:
25443 num7 = -4;
25444 break;
25445 case 228:
25446 num7 = -2;
25447 break;
25448 case 17:
25449 case 18:
25450 case 19:
25451 case 20:
25452 case 22:
25453 case 124:
25454 case 229:
25455 case 353:
25456 case 633:
25457 case 637:
25458 case 638:
25459 case 656:
25460 case 670:
25461 case 678:
25462 case 679:
25463 case 680:
25464 case 681:
25465 case 682:
25466 case 683:
25467 case 684:
25468 num7 = -1;
25469 break;
25470 case 37:
25471 case 38:
25472 case 54:
25473 case 107:
25474 case 108:
25475 case 160:
25476 case 207:
25477 case 209:
25478 num7 = -3;
25479 break;
25480 case 178:
25481 case 208:
25482 case 369:
25483 num7 = 1;
25484 break;
25485 }
25486 vector.X += num7 * num5;
25487 vector.X += 4 * num5;
25489 if (NPCID.Sets.IsTownSlime[n.type])
25490 {
25491 spriteEffects ^= SpriteEffects.FlipHorizontally;
25492 }
25493 float num8 = 1f;
25494 if (n.shimmerTransparency > 0f)
25495 {
25496 num8 *= 1f - n.shimmerTransparency;
25497 }
25498 spriteBatch.Draw(value, new Vector2(vector.X - screenPosition.X, vector.Y - screenPosition.Y), rectangle, npcColor * n.Opacity * num8, 0f, origin, n.scale, spriteEffects, 0f);
25499 }
25500 if (!beforeDraw && n.type == 681)
25501 {
25502 spriteBatch.Draw(TextureAssets.Extra[250].Value, new Vector2(n.position.X - screenPosition.X + (float)(n.width / 2) - (float)TextureAssets.Npc[n.type].Width() * n.scale / 2f + halfSize.X * n.scale, n.position.Y - screenPosition.Y + (float)n.height - (float)TextureAssets.Npc[n.type].Height() * n.scale / (float)npcFrameCount[n.type] + 4f + halfSize.Y * n.scale + addHeight + addY + n.gfxOffY), n.frame, n.GetAlpha(npcColor), n.rotation, halfSize, n.scale, npcSpriteEffect, 0f);
25503 }
25504 if (NPCID.Sets.AttackType[n.type] == 1 && n.ai[0] == 12f && !beforeDraw)
25505 {
25506 if (n.type == 228 || n.type == 229 || n.type == 209)
25507 {
25508 return;
25509 }
25510 float num9 = n.ai[2];
25512 if (n.spriteDirection == 1)
25513 {
25514 vector2.X *= -1f;
25515 }
25516 Vector2 vector3 = n.Bottom - vector2;
25517 if (n.type == 22 && n.ai[2] > -0.1f)
25518 {
25519 vector3.Y += 4f;
25520 }
25521 if (n.type == 368 && hardMode && n.ai[2] > -0.1f)
25522 {
25523 vector3.Y += 4f;
25524 }
25525 if (n.type == 368 && !hardMode && n.ai[2] < -0.1f)
25526 {
25527 vector3.Y -= 8f;
25528 }
25529 float rotation = num9 * ((float)Math.PI / 2f) * (float)n.spriteDirection;
25530 float num10 = 1f;
25531 int itemtype = 0;
25532 int num11 = 4;
25533 if (n.type == 19)
25534 {
25535 itemtype = (hardMode ? 98 : 95);
25536 if (hardMode)
25537 {
25538 vector3.X -= 10 * n.direction;
25539 vector3.Y += 4f;
25540 }
25541 }
25542 else if (n.type == 22)
25543 {
25544 itemtype = 39;
25545 num11 = 18;
25546 }
25547 else if (n.type == 178)
25548 {
25549 itemtype = 434;
25550 }
25551 else if (n.type == 227)
25552 {
25553 itemtype = 3350;
25554 num11 = 16;
25555 num10 = 0.85f;
25556 }
25557 else if (n.type == 368)
25558 {
25559 itemtype = (hardMode ? 2223 : 2269);
25560 if (hardMode)
25561 {
25562 num11 = 18;
25563 }
25564 else
25565 {
25566 if (n.ai[2] < -0.1f)
25567 {
25568 num11 = 28;
25569 }
25570 num10 = 0.75f;
25571 }
25572 }
25575 int num12 = (int)vector4.X - num11;
25576 Vector2 origin2 = new Vector2(-num12, value2.Height / 2);
25577 if (n.spriteDirection == -1)
25578 {
25579 origin2 = new Vector2(value2.Width + num12, value2.Height / 2);
25580 }
25581 spriteBatch.Draw(itemTexture, new Vector2((int)(vector3.X - screenPosition.X), (int)(vector3.Y - screenPosition.Y)), value2, npcColor, rotation, origin2, n.scale * num10, npcSpriteEffect ^ SpriteEffects.FlipHorizontally, 0f);
25582 if (n.type == 22 && n.frame.Y / (TextureAssets.Npc[n.type].Height() / npcFrameCount[n.type]) >= 21)
25583 {
25584 Texture2D value3 = TextureAssets.Extra[52].Value;
25585 if (n.IsShimmerVariant)
25586 {
25587 value3 = TextureAssets.Extra[264].Value;
25588 }
25589 Microsoft.Xna.Framework.Rectangle value4 = value3.Frame(1, 5, 0, n.frame.Y / (TextureAssets.Npc[n.type].Height() / npcFrameCount[n.type]) - 21);
25590 spriteBatch.Draw(value3, new Vector2(n.position.X - screenPosition.X + (float)(n.width / 2) - (float)TextureAssets.Npc[n.type].Width() * n.scale / 2f + halfSize.X * n.scale, n.position.Y - screenPosition.Y + (float)n.height - (float)TextureAssets.Npc[n.type].Height() * n.scale / (float)npcFrameCount[n.type] + 4f + halfSize.Y * n.scale + addHeight + addY + n.gfxOffY), value4, n.GetAlpha(npcColor), n.rotation, halfSize, n.scale, npcSpriteEffect, 0f);
25591 }
25592 else if (n.type == 368 && n.frame.Y / (TextureAssets.Npc[n.type].Height() / npcFrameCount[n.type]) >= 21)
25593 {
25594 Texture2D value5 = TextureAssets.Extra[53].Value;
25595 if (n.IsShimmerVariant)
25596 {
25597 value5 = TextureAssets.Extra[265].Value;
25598 }
25599 Microsoft.Xna.Framework.Rectangle value6 = value5.Frame(1, 5, 0, n.frame.Y / (TextureAssets.Npc[n.type].Height() / npcFrameCount[n.type]) - 21);
25600 spriteBatch.Draw(value5, new Vector2(n.position.X - screenPosition.X + (float)(n.width / 2) - (float)TextureAssets.Npc[n.type].Width() * n.scale / 2f + halfSize.X * n.scale, n.position.Y - screenPosition.Y + (float)n.height - (float)TextureAssets.Npc[n.type].Height() * n.scale / (float)npcFrameCount[n.type] + 4f + halfSize.Y * n.scale + addHeight + addY + n.gfxOffY), value6, n.GetAlpha(npcColor), n.rotation, halfSize, n.scale, npcSpriteEffect, 0f);
25601 }
25602 }
25603 if (NPCID.Sets.AttackType[n.type] == 2 && (n.ai[0] == 14f || (n.ai[0] == 24f && n.frameCounter < 240.0)) && !beforeDraw)
25604 {
25605 Texture2D value7 = TextureAssets.Extra[51].Value;
25606 Vector2 vector5 = n.Bottom + new Vector2(0f, n.gfxOffY + 4f);
25607 Microsoft.Xna.Framework.Rectangle rectangle2 = value7.Frame(1, 4, 0, (int)n.frameCounter % 48 / 12);
25608 Vector2 origin3 = rectangle2.Size() * new Vector2(0.5f, 1f);
25609 spriteBatch.Draw(value7, new Vector2((int)(vector5.X - screenPosition.X), (int)(vector5.Y - screenPosition.Y)), rectangle2, n.GetMagicAuraColor(), 0f, origin3, n.scale, npcSpriteEffect ^ SpriteEffects.FlipHorizontally, 0f);
25610 }
25611 if (NPCID.Sets.AttackType[n.type] == 3 && n.ai[0] == 15f)
25612 {
25613 int num13 = 32;
25614 float num14 = 0f;
25616 short num15 = 4;
25617 if (n.type == 207)
25618 {
25619 num15 = 3349;
25620 num14 = 0.15f;
25621 if (beforeDraw)
25622 {
25623 return;
25624 }
25625 if (n.ai[1] > (float)NPCID.Sets.AttackTime[n.type] * 0.66f)
25626 {
25627 zero.Y = 12f;
25628 }
25629 }
25630 else if (n.type == 353)
25631 {
25632 num15 = 3352;
25633 num14 = 0.15f;
25634 if (!beforeDraw)
25635 {
25636 return;
25637 }
25638 if (n.ai[1] > (float)NPCID.Sets.AttackTime[n.type] * 0.66f)
25639 {
25640 zero.Y = 12f;
25641 }
25642 }
25643 else if (n.type == 441)
25644 {
25645 num15 = 3351;
25646 num13 = 28;
25647 num14 = 0.1f;
25648 if (!beforeDraw)
25649 {
25650 return;
25651 }
25652 if (n.ai[1] > (float)NPCID.Sets.AttackTime[n.type] * 0.66f)
25653 {
25654 zero.Y = 12f;
25655 }
25656 }
25658 Tuple<Vector2, float> swingStats = n.GetSwingStats(NPCID.Sets.AttackTime[n.type] * 2, (int)n.ai[1], n.spriteDirection, num13, num13);
25659 Vector2 vector6 = swingStats.Item1 + (swingStats.Item1 - n.Center) * num14 + zero;
25660 Vector2 origin4 = rectangle3.Size() * new Vector2((n.spriteDirection != 1) ? 1 : 0, 1f);
25661 spriteBatch.Draw(itemTexture2, new Vector2((int)(vector6.X - screenPosition.X), (int)(vector6.Y - screenPosition.Y)), rectangle3, n.GetAlpha(npcColor), swingStats.Item2, origin4, n.scale, npcSpriteEffect ^ SpriteEffects.FlipHorizontally, 0f);
25662 }
25663 if (n.type == 550 && n.ai[0] == 18f)
25664 {
25665 if (beforeDraw)
25666 {
25667 return;
25668 }
25669 instance.LoadItem(353);
25670 Texture2D value8 = TextureAssets.Item[353].Value;
25671 int num16 = 32;
25672 float num17 = 0.15f;
25675 int num18 = (int)n.ai[2];
25676 if (num18 >= 0 && num18 < 255)
25677 {
25678 Player player = Main.player[num18];
25679 bool flag = player.HeldItem.type == 353 && player.direction == Math.Sign(n.Center.X - player.Center.X);
25680 float num19 = player.Hitbox.Distance(n.Center);
25681 float num20 = n.localAI[3];
25682 if (num19 < 46f && flag)
25683 {
25684 n.localAI[3] = 1f;
25685 if (n.localAI[3] != num20)
25686 {
25687 Vector2 vector7 = n.Center + new Vector2(n.spriteDirection * 30, -6f);
25688 Vector2 vector8 = new Vector2(10f, 10f);
25689 for (int i = 0; i < 30; i++)
25690 {
25691 Dust obj = Dust.NewDustDirect(vector7 - vector8 / 2f, (int)vector8.X, (int)vector8.Y, 4, 0f, 0f, 50, new Microsoft.Xna.Framework.Color(245, 200, 30, 155), 0.7f);
25692 obj.noGravity = true;
25693 obj.velocity *= 1f;
25694 Dust.NewDustDirect(vector7 - vector8 / 2f, (int)vector8.X, (int)vector8.Y, 4, 0f, 0f, 50, new Microsoft.Xna.Framework.Color(245, 200, 30, 155), 0.6f).velocity *= 2f;
25695 }
25696 }
25697 }
25698 else if (n.localAI[3] == 1f)
25699 {
25700 n.localAI[3] = 2f;
25701 }
25702 }
25703 Tuple<Vector2, float> swingStats2 = n.GetSwingStats(40, 12, n.spriteDirection, num16, num16);
25704 Vector2 vector9 = swingStats2.Item1 + (swingStats2.Item1 - n.Center) * num17 + zero2;
25705 Vector2 origin5 = rectangle4.Size() * new Vector2((n.spriteDirection != 1) ? 1 : 0, 1f);
25706 spriteBatch.Draw(value8, new Vector2((int)(vector9.X - screenPosition.X), (int)(vector9.Y - screenPosition.Y)), rectangle4, n.GetAlpha(npcColor), swingStats2.Item2, origin5, n.scale, npcSpriteEffect ^ SpriteEffects.FlipHorizontally, 0f);
25707 }
25708 if (beforeDraw || n.ai[0] != 23f)
25709 {
25710 return;
25711 }
25712 int num21 = (int)n.ai[2];
25714 {
25715 return;
25716 }
25718 int num22 = 0;
25719 num22 = (((int)n.frameCounter < 6) ? 1 : 2);
25720 if (n.ai[1] < 6f)
25721 {
25722 num22 = 1;
25723 }
25724 if (num22 == 0)
25725 {
25726 return;
25727 }
25729 if (num22 == 1)
25730 {
25731 vector10 = new Vector2(10f, 6f);
25732 }
25733 if (num22 == 2)
25734 {
25735 vector10 = new Vector2(16f, 0f);
25736 }
25737 if (!npcSpriteEffect.HasFlag(SpriteEffects.FlipHorizontally))
25738 {
25739 vector10.X *= -1f;
25740 }
25741 if (n.type == 369)
25742 {
25743 vector10.X *= 0.5f;
25744 vector10.Y += 4f;
25745 }
25746 if (n.type == 453)
25747 {
25748 vector10.Y += 8f;
25749 }
25750 if (n.type == 550)
25751 {
25752 if (num21 == 353)
25753 {
25754 rectangle5 = itemTexture3.Frame(1, 3, 0, 1);
25755 }
25756 vector10.Y += 6f;
25757 }
25758 Vector2 vector11 = n.Center + vector10;
25759 Vector2 origin6 = rectangle5.Size() * new Vector2((n.spriteDirection != 1) ? 1 : 0, 1f);
25760 Vector2 position = new Vector2((int)(vector11.X - screenPosition.X), (int)(vector11.Y - screenPosition.Y));
25761 Microsoft.Xna.Framework.Color alpha = n.GetAlpha(npcColor);
25762 spriteBatch.Draw(itemTexture3, position, rectangle5, alpha, 0f, origin6, n.scale, npcSpriteEffect ^ SpriteEffects.FlipHorizontally, 0f);
25763 }
const double PI
Definition Math.cs:16
static int Sign(decimal value)
Definition Math.cs:1202
static Asset< Texture2D >[] Npc
static Asset< Texture2D >[] Item
static Asset< Texture2D >[] Extra
static readonly short Count
Definition ItemID.cs:12138
static int[][] TownNPCsFramingGroups
Definition NPCID.cs:4256
static int[] AttackTime
Definition NPCID.cs:4224
static bool[] IsTownSlime
Definition NPCID.cs:4101
static int[] AttackType
Definition NPCID.cs:4228
static int[] HatOffsetY
Definition NPCID.cs:4206
static int[] NPCFramingGroup
Definition NPCID.cs:4252
static Vector2[] OffsetsNPCOffhand
Definition Main.cs:463
static int[] npcFrameCount
Definition Main.cs:2002
static SpriteBatch spriteBatch
Definition Main.cs:974
static Main instance
Definition Main.cs:283
static Vector2 screenPosition
Definition Main.cs:1715
static Vector2 DrawPlayerItemPos(float gravdir, int itemtype)
Definition Main.cs:3063
static void GetItemDrawFrame(int item, out Texture2D itemTexture, out Microsoft.Xna.Framework.Rectangle itemFrame)
Definition Main.cs:25221
static bool hardMode
Definition Main.cs:1022
static Player[] player
Definition Main.cs:1803

References System.array, Terraria.ID.NPCID.Sets.AttackTime, Terraria.ID.NPCID.Sets.AttackType, Terraria.ID.ItemID.Count, Terraria.Main.DrawPlayerItemPos(), Terraria.GameContent.TextureAssets.Extra, Terraria.Main.GetItemDrawFrame(), Terraria.Main.hardMode, Terraria.ID.NPCID.Sets.HatOffsetY, System.Text.RegularExpressions.i, Terraria.Main.instance, Terraria.ID.NPCID.Sets.IsTownSlime, Terraria.GameContent.TextureAssets.Item, Terraria.Dust.NewDustDirect(), Terraria.GameContent.TextureAssets.Npc, Terraria.Main.npcFrameCount, Terraria.ID.NPCID.Sets.NPCFramingGroup, System.obj, Terraria.Main.OffsetsNPCOffhand, System.Math.PI, Terraria.Main.player, Terraria.Main.screenPosition, System.Math.Sign(), Terraria.Main.spriteBatch, Terraria.ID.NPCID.Sets.TownNPCsFramingGroups, System.value, Microsoft.Xna.Framework.Graphics.Vector2, and Microsoft.Xna.Framework.Vector2.Zero.

Referenced by Terraria.Main.DrawNPCDirect().