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

◆ Colliding()

bool Terraria.Projectile.Colliding ( Rectangle myRect,
Rectangle targetRect )
inline

Definition at line 13277 of file Projectile.cs.

13278 {
13279 if (aiStyle == 15)
13280 {
13281 if (ai[0] == 0f)
13282 {
13283 Vector2 mountedCenter = Main.player[owner].MountedCenter;
13284 Vector2 vector = targetRect.ClosestPointInRect(mountedCenter) - mountedCenter;
13285 vector.Y /= 0.8f;
13286 float num = 55f;
13287 return vector.Length() <= num;
13288 }
13289 }
13290 else if (type == 973)
13291 {
13292 Vector2 v = targetRect.ClosestPointInRect(base.Center) - base.Center;
13293 v.SafeNormalize(Vector2.UnitX);
13294 float num2 = 100f * scale;
13295 if (v.Length() < num2 && Collision.CanHit(base.Center, 0, 0, targetRect.Center.ToVector2(), 0, 0))
13296 {
13297 return true;
13298 }
13299 }
13300 else
13301 {
13302 if (type == 85)
13303 {
13304 if (!myRect.Intersects(targetRect))
13305 {
13306 return false;
13307 }
13308 return Collision.CanHit(base.Center, 0, 0, targetRect.Center.ToVector2(), 0, 0);
13309 }
13310 if (type == 985)
13311 {
13312 float coneLength = 90f * scale;
13313 float maximumAngle = (float)Math.PI / 4f;
13314 float coneRotation = rotation;
13315 if (targetRect.IntersectsConeFastInaccurate(base.Center, coneLength, coneRotation, maximumAngle) && Collision.CanHit(base.Center, 0, 0, targetRect.Center.ToVector2(), 0, 0))
13316 {
13317 return true;
13318 }
13319 }
13320 else
13321 {
13322 if (aiStyle == 190)
13323 {
13324 float coneLength2 = 94f * scale;
13325 float num3 = (float)Math.PI * 2f / 25f * ai[0];
13326 float maximumAngle2 = (float)Math.PI / 4f;
13327 float num4 = rotation + num3;
13328 if (targetRect.IntersectsConeSlowMoreAccurate(base.Center, coneLength2, num4, maximumAngle2))
13329 {
13330 return true;
13331 }
13332 float num5 = Utils.Remap(localAI[0], ai[1] * 0.3f, ai[1] * 0.5f, 1f, 0f);
13333 if (num5 > 0f)
13334 {
13335 float coneRotation2 = num4 - (float)Math.PI / 4f * ai[0] * num5;
13336 if (targetRect.IntersectsConeSlowMoreAccurate(base.Center, coneLength2, coneRotation2, maximumAngle2))
13337 {
13338 return true;
13339 }
13340 }
13341 return false;
13342 }
13343 if (type == 623)
13344 {
13345 if (ai[0] == 2f)
13346 {
13347 Rectangle value = Utils.CenteredRectangle(base.Center + new Vector2(direction * 40, 0f), new Vector2(80f, 40f));
13348 if (targetRect.Intersects(value))
13349 {
13350 return true;
13351 }
13352 }
13353 }
13354 else
13355 {
13356 if (type == 933)
13357 {
13358 float collisionPoint = 0f;
13359 float num6 = 40f;
13360 for (int i = 14; i < oldPos.Length; i += 15)
13361 {
13362 float num7 = localAI[0] - (float)i;
13363 if (!(num7 < 0f) && !(num7 > 60f))
13364 {
13365 Vector2 vector2 = oldPos[i] + base.Size / 2f;
13366 Vector2 vector3 = (oldRot[i] + (float)Math.PI / 2f).ToRotationVector2();
13367 _lanceHitboxBounds.X = (int)vector2.X - _lanceHitboxBounds.Width / 2;
13368 _lanceHitboxBounds.Y = (int)vector2.Y - _lanceHitboxBounds.Height / 2;
13369 if (_lanceHitboxBounds.Intersects(targetRect) && Collision.CheckAABBvLineCollision(targetRect.TopLeft(), targetRect.Size(), vector2 - vector3 * num6, vector2 + vector3 * num6, 20f, ref collisionPoint))
13370 {
13371 return true;
13372 }
13373 }
13374 }
13375 Vector2 vector4 = (rotation + (float)Math.PI / 2f).ToRotationVector2();
13376 _lanceHitboxBounds.X = (int)position.X - _lanceHitboxBounds.Width / 2;
13377 _lanceHitboxBounds.Y = (int)position.Y - _lanceHitboxBounds.Height / 2;
13378 if (_lanceHitboxBounds.Intersects(targetRect) && Collision.CheckAABBvLineCollision(targetRect.TopLeft(), targetRect.Size(), base.Center - vector4 * num6, base.Center + vector4 * num6, 20f, ref collisionPoint))
13379 {
13380 return true;
13381 }
13382 return false;
13383 }
13384 if (type == 927)
13385 {
13386 for (float num8 = 0f; num8 <= 1f; num8 += 0.05f)
13387 {
13388 float num9 = Utils.Remap(num8, 0f, 1f, 1f, 5f);
13390 Vector2 vector5 = velocity.SafeNormalize(Vector2.Zero) * width * num9 * scale;
13391 rectangle.Offset((int)vector5.X, (int)vector5.Y);
13392 if (rectangle.Intersects(targetRect))
13393 {
13394 return true;
13395 }
13396 }
13397 }
13398 else
13399 {
13400 if (type == 877 || type == 878 || type == 879)
13401 {
13402 float f = rotation - (float)Math.PI / 4f - (float)Math.PI / 2f - ((spriteDirection == 1) ? ((float)Math.PI) : 0f);
13403 float collisionPoint2 = 0f;
13404 float num10 = 95f;
13405 _lanceHitboxBounds.X = (int)position.X - _lanceHitboxBounds.Width / 2;
13406 _lanceHitboxBounds.Y = (int)position.Y - _lanceHitboxBounds.Height / 2;
13407 if (_lanceHitboxBounds.Intersects(targetRect) && Collision.CheckAABBvLineCollision(targetRect.TopLeft(), targetRect.Size(), base.Center, base.Center + f.ToRotationVector2() * num10, 23f * scale, ref collisionPoint2))
13408 {
13409 return true;
13410 }
13411 return false;
13412 }
13413 if (type == 974)
13414 {
13415 float f2 = rotation;
13416 float collisionPoint3 = 0f;
13417 float num11 = 46f * scale;
13418 float num12 = 8f;
13419 Vector2 vector6 = f2.ToRotationVector2();
13420 Rectangle hitbox = base.Hitbox;
13421 hitbox.Inflate((int)num11, (int)num11);
13422 if (hitbox.Intersects(targetRect) && Collision.CheckAABBvLineCollision(targetRect.TopLeft(), targetRect.Size(), base.Center - vector6 * num11, base.Center + vector6 * num11, num12 * scale, ref collisionPoint3))
13423 {
13424 return true;
13425 }
13426 return false;
13427 }
13428 if (type == 919 || type == 932)
13429 {
13430 float f3 = rotation;
13431 float collisionPoint4 = 0f;
13432 float num13 = 40f;
13433 Vector2 vector7 = f3.ToRotationVector2();
13434 _lanceHitboxBounds.X = (int)position.X - _lanceHitboxBounds.Width / 2;
13435 _lanceHitboxBounds.Y = (int)position.Y - _lanceHitboxBounds.Height / 2;
13436 if (_lanceHitboxBounds.Intersects(targetRect) && Collision.CheckAABBvLineCollision(targetRect.TopLeft(), targetRect.Size(), base.Center - vector7 * num13, base.Center + vector7 * num13, 8f, ref collisionPoint4))
13437 {
13438 return true;
13439 }
13440 return false;
13441 }
13442 if (type == 923)
13443 {
13444 float collisionPoint5 = 0f;
13445 _ = scale;
13446 float f4 = rotation;
13447 Vector2 objectPosition = targetRect.TopLeft();
13448 Vector2 objectDimensions = targetRect.Size();
13449 Vector2 vector8 = f4.ToRotationVector2();
13450 float num14 = scale * 0.7f;
13451 if (Collision.CheckAABBvLineCollision(objectPosition, objectDimensions, base.Center, base.Center + vector8 * scale * 510f, num14 * 100f, ref collisionPoint5))
13452 {
13453 return true;
13454 }
13455 if (Collision.CheckAABBvLineCollision(objectPosition, objectDimensions, base.Center, base.Center + vector8 * scale * 660f, num14 * 60f, ref collisionPoint5))
13456 {
13457 return true;
13458 }
13459 if (Collision.CheckAABBvLineCollision(objectPosition, objectDimensions, base.Center, base.Center + vector8 * scale * 800f, num14 * 10f, ref collisionPoint5))
13460 {
13461 return true;
13462 }
13463 return false;
13464 }
13465 if (type == 598 && targetRect.Width > 8 && targetRect.Height > 8)
13466 {
13467 targetRect.Inflate(-targetRect.Width / 8, -targetRect.Height / 8);
13468 }
13469 else
13470 {
13471 if (type == 872)
13472 {
13473 Rectangle hitbox2 = base.Hitbox;
13474 int num15 = 80;
13475 for (int j = 0; j < num15; j += 2)
13476 {
13478 if (!(vector9 == Vector2.Zero))
13479 {
13480 hitbox2.X = (int)vector9.X;
13481 hitbox2.Y = (int)vector9.Y;
13482 if (hitbox2.Intersects(targetRect))
13483 {
13484 return true;
13485 }
13486 }
13487 }
13488 return false;
13489 }
13490 if (type == 871)
13491 {
13493 for (int k = 0; k < num16; k++)
13494 {
13495 HallowBossPelletStormInfo hallowBossPelletStormInfo = AI_172_GetPelletStormInfo(k);
13496 for (int l = 0; l < hallowBossPelletStormInfo.BulletsInStorm; l++)
13497 {
13498 if (hallowBossPelletStormInfo.IsValid(l) && hallowBossPelletStormInfo.GetBulletHitbox(l, base.Center).Intersects(targetRect))
13499 {
13500 return true;
13501 }
13502 }
13503 }
13504 return false;
13505 }
13507 {
13510 for (int m = 0; m < WhipPointsForCollision.Count; m++)
13511 {
13512 Point point = WhipPointsForCollision[m].ToPoint();
13513 myRect.Location = new Point(point.X - myRect.Width / 2, point.Y - myRect.Height / 2);
13514 if (myRect.Intersects(targetRect))
13515 {
13516 return true;
13517 }
13518 }
13519 return false;
13520 }
13521 if (type == 614 && targetRect.Width > 8 && targetRect.Height > 8)
13522 {
13523 targetRect.Inflate(-targetRect.Width / 8, -targetRect.Height / 8);
13524 }
13525 else if (type == 963 && ai[0] >= 2f)
13526 {
13527 targetRect.Inflate(30, 30);
13528 }
13529 else if (type == 758)
13530 {
13531 if (ai[0] == 2f && Utils.CenteredRectangle(base.Center + new Vector2(spriteDirection * 30, 0f), new Vector2(50f, 20f)).Intersects(targetRect))
13532 {
13533 return true;
13534 }
13535 }
13536 else if (type == 636 && targetRect.Width > 8 && targetRect.Height > 8)
13537 {
13538 targetRect.Inflate(-targetRect.Width / 8, -targetRect.Height / 8);
13539 }
13540 else if (type == 607)
13541 {
13542 myRect.X += (int)velocity.X;
13543 myRect.Y += (int)velocity.Y;
13544 }
13545 else if (type == 661)
13546 {
13547 if (Vector2.Distance(myRect.Center.ToVector2(), targetRect.Center.ToVector2()) > 500f || !Collision.CanHitLine(myRect.Center.ToVector2(), 0, 0, targetRect.Center.ToVector2(), 0, 0))
13548 {
13549 return false;
13550 }
13551 }
13552 else
13553 {
13554 if (aiStyle == 137)
13555 {
13556 if (myRect.Intersects(targetRect) && targetRect.Distance(base.Center) < (float)(height / 2 - 20))
13557 {
13558 if (AI_137_CanHit(targetRect.Center.ToVector2()))
13559 {
13560 return true;
13561 }
13562 if (AI_137_CanHit(targetRect.TopLeft() + new Vector2(targetRect.Width / 2, 0f)))
13563 {
13564 return true;
13565 }
13566 }
13567 return false;
13568 }
13569 if (aiStyle == 19)
13570 {
13571 Vector2 center = base.Center;
13573 {
13574 Vector2 vector10 = extensionBox.Center.ToVector2();
13576 Vector2 size = extensionBox.Size();
13577 float num18 = MathHelper.Max(extensionBox.Width, extensionBox.Height);
13578 if (num18 < 12f)
13579 {
13580 num18 = 12f;
13581 }
13582 for (float num19 = num18; num19 < num17; num19 += num18)
13583 {
13584 if (Utils.CenteredRectangle(Vector2.Lerp(center, vector10, num19 / num17), size).Intersects(targetRect))
13585 {
13586 return true;
13587 }
13588 }
13589 if (extensionBox.Intersects(targetRect))
13590 {
13591 return true;
13592 }
13593 }
13594 }
13595 }
13596 }
13597 }
13598 }
13599 }
13600 }
13601 if (myRect.Intersects(targetRect))
13602 {
13603 return true;
13604 }
13605 if (type == 461)
13606 {
13607 float collisionPoint6 = 0f;
13608 if (Collision.CheckAABBvLineCollision(targetRect.TopLeft(), targetRect.Size(), base.Center, base.Center + velocity * localAI[1], 22f * scale, ref collisionPoint6))
13609 {
13610 return true;
13611 }
13612 return false;
13613 }
13614 if (type == 697 || type == 707)
13615 {
13616 float f5 = rotation - (float)Math.PI / 4f * (float)Math.Sign(velocity.X);
13617 float collisionPoint7 = 0f;
13618 float num20 = 50f;
13619 if (type == 697)
13620 {
13621 num20 = 65f;
13622 }
13623 if (type == 707)
13624 {
13625 num20 = 110f;
13626 }
13627 if (Collision.CheckAABBvLineCollision(targetRect.TopLeft(), targetRect.Size(), base.Center + f5.ToRotationVector2() * (0f - num20), base.Center + f5.ToRotationVector2() * num20, 23f * scale, ref collisionPoint7))
13628 {
13629 return true;
13630 }
13631 return false;
13632 }
13633 if (type == 699)
13634 {
13635 float f6 = rotation - (float)Math.PI / 4f * (float)Math.Sign(velocity.X) + ((spriteDirection == -1) ? ((float)Math.PI) : 0f);
13636 float collisionPoint8 = 0f;
13637 float num21 = -95f;
13638 if (Collision.CheckAABBvLineCollision(targetRect.TopLeft(), targetRect.Size(), base.Center, base.Center + f6.ToRotationVector2() * num21, 23f * scale, ref collisionPoint8))
13639 {
13640 return true;
13641 }
13642 return false;
13643 }
13644 if (type == 642)
13645 {
13646 float collisionPoint9 = 0f;
13647 if (Collision.CheckAABBvLineCollision(targetRect.TopLeft(), targetRect.Size(), base.Center, base.Center + velocity * localAI[1], 30f * scale, ref collisionPoint9))
13648 {
13649 return true;
13650 }
13651 return false;
13652 }
13653 if (type == 802 || type == 842 || type == 938 || type == 939 || type == 940 || type == 941 || type == 942 || type == 943 || type == 944 || type == 945)
13654 {
13655 float collisionPoint10 = 0f;
13656 if (Collision.CheckAABBvLineCollision(targetRect.TopLeft(), targetRect.Size(), base.Center, base.Center + velocity * 6f, 10f * scale, ref collisionPoint10))
13657 {
13658 return true;
13659 }
13660 return false;
13661 }
13662 if (type == 632)
13663 {
13664 float collisionPoint11 = 0f;
13665 if (Collision.CheckAABBvLineCollision(targetRect.TopLeft(), targetRect.Size(), base.Center, base.Center + velocity * localAI[1], 22f * scale, ref collisionPoint11))
13666 {
13667 return true;
13668 }
13669 return false;
13670 }
13671 if (type == 455)
13672 {
13673 float collisionPoint12 = 0f;
13674 if (Collision.CheckAABBvLineCollision(targetRect.TopLeft(), targetRect.Size(), base.Center, base.Center + velocity * localAI[1], 36f * scale, ref collisionPoint12))
13675 {
13676 return true;
13677 }
13678 return false;
13679 }
13680 if (type == 611)
13681 {
13682 float collisionPoint13 = 0f;
13683 if (Collision.CheckAABBvLineCollision(targetRect.TopLeft(), targetRect.Size(), base.Center, base.Center + velocity + velocity.SafeNormalize(Vector2.Zero) * 48f, 16f * scale, ref collisionPoint13))
13684 {
13685 return true;
13686 }
13687 return false;
13688 }
13689 if (type == 684)
13690 {
13691 float collisionPoint14 = 0f;
13692 Vector2 vector11 = velocity.SafeNormalize(Vector2.UnitY).RotatedBy(-1.5707963705062866) * scale;
13693 if (Collision.CheckAABBvLineCollision(targetRect.TopLeft(), targetRect.Size(), base.Center - vector11 * 40f, base.Center + vector11 * 40f, 16f * scale, ref collisionPoint14))
13694 {
13695 return true;
13696 }
13697 return false;
13698 }
13699 if (type == 537)
13700 {
13701 float collisionPoint15 = 0f;
13702 if (Collision.CheckAABBvLineCollision(targetRect.TopLeft(), targetRect.Size(), base.Center, base.Center + velocity * localAI[1], 22f * scale, ref collisionPoint15))
13703 {
13704 return true;
13705 }
13706 return false;
13707 }
13708 if (type == 756 || type == 961)
13709 {
13710 float collisionPoint16 = 0f;
13711 if (Collision.CheckAABBvLineCollision(targetRect.TopLeft(), targetRect.Size(), base.Center, base.Center + velocity.SafeNormalize(-Vector2.UnitY) * 200f * scale, 22f * scale, ref collisionPoint16))
13712 {
13713 return true;
13714 }
13715 return false;
13716 }
13717 if (type == 687)
13718 {
13719 float collisionPoint17 = 0f;
13720 float num22 = ai[0] / 25f;
13721 if (num22 > 1f)
13722 {
13723 num22 = 1f;
13724 }
13725 float num23 = (ai[0] - 38f) / 40f;
13726 if (num23 < 0f)
13727 {
13728 num23 = 0f;
13729 }
13730 Vector2 lineStart = base.Center + rotation.ToRotationVector2() * 400f * num23;
13731 Vector2 lineEnd = base.Center + rotation.ToRotationVector2() * 400f * num22;
13732 if (Collision.CheckAABBvLineCollision(targetRect.TopLeft(), targetRect.Size(), lineStart, lineEnd, 40f * scale, ref collisionPoint17))
13733 {
13734 return true;
13735 }
13736 return false;
13737 }
13738 if (type == 466 || type == 580 || type == 686)
13739 {
13740 for (int n = 0; n < oldPos.Length && (oldPos[n].X != 0f || oldPos[n].Y != 0f); n++)
13741 {
13742 myRect.X = (int)oldPos[n].X;
13743 myRect.Y = (int)oldPos[n].Y;
13744 if (myRect.Intersects(targetRect))
13745 {
13746 return true;
13747 }
13748 }
13749 return false;
13750 }
13751 if (type == 711)
13752 {
13753 if (penetrate != -1)
13754 {
13755 for (int num24 = 0; num24 < oldPos.Length && (oldPos[num24].X != 0f || oldPos[num24].Y != 0f); num24++)
13756 {
13757 myRect.X = (int)oldPos[num24].X;
13758 myRect.Y = (int)oldPos[num24].Y;
13759 if (myRect.Intersects(targetRect))
13760 {
13761 return true;
13762 }
13763 }
13764 }
13765 }
13766 else if (type == 464 && ai[1] != 1f)
13767 {
13768 Vector2 vector12 = new Vector2(0f, -720f).RotatedBy(velocity.ToRotation());
13769 float num25 = ai[0] % 45f / 45f;
13771 for (int num26 = 0; num26 < 6; num26++)
13772 {
13773 float num27 = (float)num26 * ((float)Math.PI * 2f) / 6f;
13774 if (Utils.CenteredRectangle(base.Center + spinningpoint.RotatedBy(num27), new Vector2(30f, 30f)).Intersects(targetRect))
13775 {
13776 return true;
13777 }
13778 }
13779 }
13780 return false;
13781 }
static float Max(float value1, float value2)
Definition MathHelper.cs:41
const double PI
Definition Math.cs:16
static int Sign(decimal value)
Definition Math.cs:1202
Vector2 velocity
Definition Entity.cs:16
Vector2 position
Definition Entity.cs:14
HallowBossPelletStormInfo AI_172_GetPelletStormInfo(int stormIndex)
static void FillWhipControlPoints(Projectile proj, List< Vector2 > controlPoints)
static Rectangle _lanceHitboxBounds
bool AI_019_Spears_GetExtensionHitbox(out Rectangle extensionBox)
int AI_172_GetPelletStormsCount()
List< Vector2 > WhipPointsForCollision
bool AI_137_CanHit(Vector2 targetPosition)
void Inflate(int horizontalAmount, int verticalAmount)
Definition Rectangle.cs:84
bool Intersects(Rectangle value)
Definition Rectangle.cs:129
static float Distance(Vector2 value1, Vector2 value2)
Definition Vector2.cs:91
static Vector2 Lerp(Vector2 value1, Vector2 value2, float amount)
Definition Vector2.cs:227

References Terraria.Projectile._lanceHitboxBounds, Terraria.Projectile.ai, Terraria.Projectile.AI_019_Spears_GetExtensionHitbox(), Terraria.Projectile.AI_137_CanHit(), Terraria.Projectile.AI_172_GetPelletStormInfo(), Terraria.Projectile.AI_172_GetPelletStormsCount(), Terraria.Projectile.aiStyle, Terraria.Collision.CanHit(), Terraria.Collision.CanHitLine(), Microsoft.Xna.Framework.Rectangle.Center, Terraria.Utils.CenteredRectangle(), Terraria.Collision.CheckAABBvLineCollision(), System.Collections.Generic.List< T >.Clear(), System.Collections.Generic.List< T >.Count, Terraria.Entity.direction, Microsoft.Xna.Framework.Vector2.Distance(), Terraria.Projectile.FillWhipControlPoints(), Microsoft.Xna.Framework.Rectangle.Height, Terraria.Entity.height, Microsoft.Xna.Framework.Rectangle.Inflate(), Microsoft.Xna.Framework.Intersects, Microsoft.Xna.Framework.Rectangle.Intersects(), Terraria.ID.ProjectileID.Sets.IsAWhip, Microsoft.Xna.Framework.Vector2.Length(), Microsoft.Xna.Framework.Vector2.Lerp(), Terraria.Projectile.localAI, Microsoft.Xna.Framework.MathHelper.Max(), Terraria.Projectile.oldPos, Terraria.Projectile.oldRot, Terraria.Projectile.owner, Terraria.Projectile.penetrate, System.Math.PI, Terraria.Main.player, Terraria.Entity.position, Terraria.Utils.Remap(), Terraria.Projectile.rotation, Terraria.Projectile.scale, System.Math.Sign(), Terraria.Projectile.spriteDirection, Terraria.Projectile.type, Microsoft.Xna.Framework.Vector2.UnitX, Microsoft.Xna.Framework.Vector2.UnitY, System.value, Terraria.Entity.velocity, Terraria.Projectile.WhipPointsForCollision, Microsoft.Xna.Framework.Rectangle.Width, Terraria.Entity.width, Microsoft.Xna.Framework.Point.X, Microsoft.Xna.Framework.Vector2.X, System.X, Microsoft.Xna.Framework.Point.Y, Microsoft.Xna.Framework.Vector2.Y, System.Y, and Microsoft.Xna.Framework.Vector2.Zero.

Referenced by Terraria.Projectile.AI(), and Terraria.Projectile.Damage().