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

◆ NewProjectile() [1/2]

static int Terraria.Projectile.NewProjectile ( IEntitySource spawnSource,
float X,
float Y,
float SpeedX,
float SpeedY,
int Type,
int Damage,
float KnockBack,
int Owner = -1,
float ai0 = 0f,
float ai1 = 0f,
float ai2 = 0f )
inlinestatic

Definition at line 9684 of file Projectile.cs.

9685 {
9686 if (Owner == -1)
9687 {
9688 Owner = Main.myPlayer;
9689 }
9690 int num = 1000;
9691 for (int i = 0; i < 1000; i++)
9692 {
9693 if (!Main.projectile[i].active)
9694 {
9695 num = i;
9696 break;
9697 }
9698 }
9699 if (num == 1000)
9700 {
9701 num = FindOldestProjectile();
9702 }
9703 Projectile projectile = Main.projectile[num];
9704 projectile.SetDefaults(Type);
9705 projectile.position.X = X - (float)projectile.width * 0.5f;
9706 projectile.position.Y = Y - (float)projectile.height * 0.5f;
9707 projectile.owner = Owner;
9708 projectile.velocity.X = SpeedX;
9709 projectile.velocity.Y = SpeedY;
9710 projectile.damage = Damage;
9711 projectile.knockBack = KnockBack;
9712 projectile.identity = num;
9713 projectile.gfxOffY = 0f;
9714 projectile.stepSpeed = 1f;
9715 projectile.wet = Collision.WetCollision(projectile.position, projectile.width, projectile.height);
9716 if (projectile.ignoreWater)
9717 {
9718 projectile.wet = false;
9719 }
9720 projectile.honeyWet = Collision.honey;
9721 projectile.shimmerWet = Collision.shimmer;
9722 Main.projectileIdentity[Owner, num] = num;
9724 if (projectile.aiStyle == 1)
9725 {
9726 while (projectile.velocity.X >= 16f || projectile.velocity.X <= -16f || projectile.velocity.Y >= 16f || projectile.velocity.Y < -16f)
9727 {
9728 projectile.velocity.X *= 0.97f;
9729 projectile.velocity.Y *= 0.97f;
9730 }
9731 }
9732 if (Owner == Main.myPlayer)
9733 {
9734 switch (Type)
9735 {
9736 case 206:
9737 projectile.ai[0] = (float)Main.rand.Next(-100, 101) * 0.0005f;
9738 projectile.ai[1] = (float)Main.rand.Next(-100, 101) * 0.0005f;
9739 break;
9740 case 335:
9741 projectile.ai[1] = Main.rand.Next(4);
9742 break;
9743 case 358:
9744 projectile.ai[1] = (float)Main.rand.Next(10, 31) * 0.1f;
9745 break;
9746 case 406:
9747 projectile.ai[1] = (float)Main.rand.Next(10, 21) * 0.1f;
9748 break;
9749 default:
9750 projectile.ai[0] = ai0;
9751 projectile.ai[1] = ai1;
9752 projectile.ai[2] = ai2;
9753 break;
9754 }
9755 }
9756 if (Type == 434)
9757 {
9758 projectile.ai[0] = projectile.position.X;
9759 projectile.ai[1] = projectile.position.Y;
9760 }
9761 if (Type > 0 && Type < ProjectileID.Count)
9762 {
9764 {
9765 projectile.projUUID = projectile.identity;
9766 }
9768 {
9769 int num2 = Main.projectile[(int)projectile.ai[0]].projUUID;
9770 if (num2 >= 0)
9771 {
9772 projectile.ai[0] = num2;
9773 }
9774 }
9775 }
9776 if (Main.netMode != 0 && Owner == Main.myPlayer)
9777 {
9778 NetMessage.SendData(27, -1, -1, null, num);
9779 }
9780 if (Owner == Main.myPlayer)
9781 {
9783 {
9784 int num3 = 0;
9785 int num4 = 0;
9786 int num5 = 99999999;
9787 for (int j = 0; j < 1000; j++)
9788 {
9789 if (Main.projectile[j].active && ProjectileID.Sets.IsAGolfBall[Main.projectile[j].type] && Main.projectile[j].owner == Owner && Main.projectile[j].damage <= 0)
9790 {
9791 num3++;
9792 if (num5 > Main.projectile[j].timeLeft)
9793 {
9794 num4 = j;
9795 num5 = Main.projectile[j].timeLeft;
9796 }
9797 }
9798 }
9799 if (num3 > 10)
9800 {
9801 Main.projectile[num4].Kill();
9802 }
9803 }
9804 if (Type == 28)
9805 {
9806 projectile.timeLeft = 180;
9807 }
9808 if (Type == 516)
9809 {
9810 projectile.timeLeft = 180;
9811 }
9812 if (Type == 519)
9813 {
9814 projectile.timeLeft = 180;
9815 }
9816 if (Type == 29)
9817 {
9818 projectile.timeLeft = 300;
9819 }
9820 if (Type == 470)
9821 {
9822 projectile.timeLeft = 300;
9823 }
9824 if (Type == 637)
9825 {
9826 projectile.timeLeft = 300;
9827 }
9828 if (Type == 30)
9829 {
9830 projectile.timeLeft = 180;
9831 }
9832 if (Type == 517)
9833 {
9834 projectile.timeLeft = 180;
9835 }
9836 if (Type == 37)
9837 {
9838 projectile.timeLeft = 180;
9839 }
9840 if (Type == 773)
9841 {
9842 projectile.timeLeft = 180;
9843 }
9844 if (Type == 75)
9845 {
9846 projectile.timeLeft = 180;
9847 }
9848 if (Type == 133)
9849 {
9850 projectile.timeLeft = 180;
9851 }
9852 if (Type == 136)
9853 {
9854 projectile.timeLeft = 180;
9855 }
9856 if (Type == 139)
9857 {
9858 projectile.timeLeft = 180;
9859 }
9860 if (Type == 142)
9861 {
9862 projectile.timeLeft = 180;
9863 }
9864 if (Type == 397)
9865 {
9866 projectile.timeLeft = 180;
9867 }
9868 if (Type == 419)
9869 {
9870 projectile.timeLeft = 600;
9871 }
9872 if (Type == 420)
9873 {
9874 projectile.timeLeft = 600;
9875 }
9876 if (Type == 421)
9877 {
9878 projectile.timeLeft = 600;
9879 }
9880 if (Type == 422)
9881 {
9882 projectile.timeLeft = 600;
9883 }
9884 if (Type == 588)
9885 {
9886 projectile.timeLeft = 180;
9887 }
9888 if (Type == 779)
9889 {
9890 projectile.timeLeft = 60;
9891 }
9892 if (Type == 783)
9893 {
9894 projectile.timeLeft = 60;
9895 }
9896 if (Type == 862 || Type == 863)
9897 {
9898 projectile.timeLeft = 60;
9899 }
9900 if (Type == 443)
9901 {
9902 projectile.timeLeft = 300;
9903 }
9904 if (Type == 681)
9905 {
9906 projectile.timeLeft = 600;
9907 }
9908 if (Type == 684)
9909 {
9910 projectile.timeLeft = 60;
9911 }
9912 if (Type == 706)
9913 {
9914 projectile.timeLeft = 120;
9915 }
9916 if (Type == 680 && Main.player[projectile.owner].setSquireT2)
9917 {
9918 projectile.penetrate = 7;
9919 }
9920 if (Type == 777 || Type == 781 || Type == 794 || Type == 797 || Type == 800 || Type == 785 || Type == 788 || Type == 791 || Type == 903 || Type == 904 || Type == 905 || Type == 906 || Type == 910 || Type == 911)
9921 {
9922 projectile.timeLeft = 180;
9923 }
9924 }
9925 if (Type == 249)
9926 {
9927 projectile.frame = Main.rand.Next(5);
9928 }
9929 if (Owner == Main.myPlayer)
9930 {
9931 Main.player[Owner].TryUpdateChannel(projectile);
9932 }
9933 return num;
9934 }
static readonly short Count
static void FindBannerToAssociateTo(IEntitySource spawnSource, Projectile next)
static int FindOldestProjectile()

References Terraria.Projectile.ai, Terraria.Projectile.aiStyle, Terraria.ID.ProjectileID.Count, Terraria.Projectile.Damage(), Terraria.Projectile.FindBannerToAssociateTo(), Terraria.Projectile.FindOldestProjectile(), Terraria.Entity.height, Terraria.Collision.honey, Terraria.Projectile.identity, Terraria.Projectile.ignoreWater, Terraria.ID.ProjectileID.Sets.IsAGolfBall, Terraria.Main.myPlayer, Terraria.ID.ProjectileID.Sets.NeedsUUID, Terraria.Main.netMode, Terraria.Projectile.owner, Terraria.Main.player, Terraria.Entity.position, Terraria.Main.projectile, Terraria.Main.projectileIdentity, Terraria.Main.rand, Terraria.NetMessage.SendData(), Terraria.Projectile.SetDefaults(), Terraria.Collision.shimmer, Terraria.ID.ProjectileID.Sets.StardustDragon, Terraria.Entity.velocity, Terraria.Collision.WetCollision(), Terraria.Entity.width, Microsoft.Xna.Framework.Vector2.X, System.X, Microsoft.Xna.Framework.Vector2.Y, and System.Y.