示例#1
0
 public override void UpdateAccessory(Player player, bool hideVisual)
 {
     Gyrolite.GetPlayer(player).yoyoStringBall = true;
 }
示例#2
0
        /// <summary>
        /// LocalAI[1] cannot be used in either of the Extra Actions due to it being used for the initialization (or at least if it is never set to 0 it can be).
        /// </summary>
        /// <param name="index">Index of the projectile in the Main.projecile array.</param>
        /// <param name="seconds">How long before the yoyo comes back to the player in seconds.</param>
        /// <param name="length">How far away from the player the yoyo can go.</param>
        /// <param name="acceleration">How fast the yoyo travels?</param>
        /// <param name="rotationSpeed">The rotation speed of the yoyo.</param>
        /// <param name="action">An action to perform when the projectile is out in front of the player.</param>
        /// <param name="initialize">An action to perform once when initializing.</param>
        public static void YoyoAI(int index, float seconds, float length, float acceleration = 14f, float rotationSpeed = 0.45f, ExtraAction action = null, ExtraAction initialize = null) //0.45f is the default
        {
            //extra action allows us to shoot extra projectiles and such

            /*variable dictionary:
             * num7 = max length of yoyo in pixels, so 16 = 1 tile.
             * num6 = something related to velocity
             */
            Projectile projectile = Main.projectile[index];

            bool flag = false;

            if (initialize != null && projectile.localAI[1] == 0)
            {
                projectile.localAI[1] = 1;
                initialize();
            }
            for (int i = 0; i < projectile.whoAmI; i++)
            {
                if (Main.projectile[i].active && Main.projectile[i].owner == projectile.owner && Main.projectile[i].type == projectile.type)
                {
                    flag = true;
                }
            }
            if (projectile.owner == Main.myPlayer)
            {
                projectile.localAI[0] += 1f;
                if (flag)
                {
                    projectile.localAI[0] += (float)Main.rand.Next(10, 31) * 0.1f;
                }
                float num = projectile.localAI[0] / 60f;
                num /= (1f + Main.player[projectile.owner].meleeSpeed) / 2f;
                if (num > seconds)
                {
                    projectile.ai[0] = -1f; //retract yoyo
                }
            }
            bool flag2 = false; //Just gonna leave this here, it was to check if it is a counterweight but in our case it never can be

            if (Main.player[projectile.owner].dead)
            {
                projectile.Kill();
                return;
            }
            if (!flag2 && !flag)
            {
                Main.player[projectile.owner].heldProj      = projectile.whoAmI;
                Main.player[projectile.owner].itemAnimation = 2;
                Main.player[projectile.owner].itemTime      = 2;
                if (projectile.position.X + (float)(projectile.width / 2) > Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2))
                {
                    Main.player[projectile.owner].ChangeDir(1);
                    projectile.direction = 1;
                }
                else
                {
                    Main.player[projectile.owner].ChangeDir(-1);
                    projectile.direction = -1;
                }
            }
            if (projectile.velocity.HasNaNs())
            {
                projectile.Kill();
            }
            projectile.timeLeft = 6;
            float num6 = acceleration;
            float num7 = length;

            if (Main.player[projectile.owner].yoyoString)
            {
                num7 = num7 * 1.25f + 30f;
            }
            // take this part out if we were ever to release this :P
            if (Gyrolite.GetPlayer(Main.player[projectile.owner]).yoyoStringBall)
            {
                num7 += 112f;
            }
            //
            num7 /= (1f + Main.player[projectile.owner].meleeSpeed * 3f) / 4f;
            num6 /= (1f + Main.player[projectile.owner].meleeSpeed * 3f) / 4f;
            float num10 = 14f - num6 / 2f;
            float num11 = 5f + num6 / 2f;

            if (flag)
            {
                num11 += 20f;
            }
            if (projectile.ai[0] >= 0f)
            {
                if (projectile.velocity.Length() > num6)
                {
                    projectile.velocity *= 0.98f;
                }
                bool    flag3   = false;
                bool    flag4   = false;
                Vector2 vector3 = Main.player[projectile.owner].Center - projectile.Center;
                if (vector3.Length() > num7)
                {
                    flag3 = true;
                    if ((double)vector3.Length() > (double)num7 * 1.3)
                    {
                        flag4 = true;
                    }
                }
                if (projectile.owner == Main.myPlayer)
                {
                    if (!Main.player[projectile.owner].channel || Main.player[projectile.owner].stoned || Main.player[projectile.owner].frozen)
                    {
                        projectile.ai[0]     = -1f;
                        projectile.ai[1]     = 0f;
                        projectile.netUpdate = true;
                    }
                    else
                    {
                        Vector2 vector4 = Main.ReverseGravitySupport(Main.MouseScreen, 0f) + Main.screenPosition;
                        float   x       = vector4.X;
                        float   y       = vector4.Y;
                        Vector2 vector5 = new Vector2(x, y) - Main.player[projectile.owner].Center;
                        if (vector5.Length() > num7)
                        {
                            vector5.Normalize();
                            vector5 *= num7;
                            vector5  = Main.player[projectile.owner].Center + vector5;
                            x        = vector5.X;
                            y        = vector5.Y;
                        }
                        if (projectile.ai[0] != x || projectile.ai[1] != y)
                        {
                            Vector2 value   = new Vector2(x, y);
                            Vector2 vector6 = value - Main.player[projectile.owner].Center;
                            if (vector6.Length() > num7 - 1f)
                            {
                                vector6.Normalize();
                                vector6 *= num7 - 1f;
                                value    = Main.player[projectile.owner].Center + vector6;
                                x        = value.X;
                                y        = value.Y;
                            }
                            projectile.ai[0]     = x;
                            projectile.ai[1]     = y;
                            projectile.netUpdate = true;
                        }
                    }
                }
                if (flag4 && projectile.owner == Main.myPlayer)
                {
                    projectile.ai[0]     = -1f;
                    projectile.netUpdate = true;
                }
                if (projectile.ai[0] >= 0f)
                {
                    if (flag3)
                    {
                        num10 /= 2f;
                        num6  *= 2f;
                        if (projectile.Center.X > Main.player[projectile.owner].Center.X && projectile.velocity.X > 0f)
                        {
                            projectile.velocity.X = projectile.velocity.X * 0.5f;
                        }
                        if (projectile.Center.Y > Main.player[projectile.owner].Center.Y && projectile.velocity.Y > 0f)
                        {
                            projectile.velocity.Y = projectile.velocity.Y * 0.5f;
                        }
                        if (projectile.Center.X < Main.player[projectile.owner].Center.X && projectile.velocity.X > 0f)
                        {
                            projectile.velocity.X = projectile.velocity.X * 0.5f;
                        }
                        if (projectile.Center.Y < Main.player[projectile.owner].Center.Y && projectile.velocity.Y > 0f)
                        {
                            projectile.velocity.Y = projectile.velocity.Y * 0.5f;
                        }
                    }
                    Vector2 value2  = new Vector2(projectile.ai[0], projectile.ai[1]);
                    Vector2 vector7 = value2 - projectile.Center;
                    projectile.velocity.Length();
                    if (vector7.Length() > num11)
                    {
                        vector7.Normalize();
                        vector7            *= num6;
                        projectile.velocity = (projectile.velocity * (num10 - 1f) + vector7) / num10;
                    }
                    else if (flag)
                    {
                        if ((double)projectile.velocity.Length() < (double)num6 * 0.6)
                        {
                            vector7 = projectile.velocity;
                            vector7.Normalize();
                            vector7            *= num6 * 0.6f;
                            projectile.velocity = (projectile.velocity * (num10 - 1f) + vector7) / num10;
                        }
                    }
                    else
                    {
                        projectile.velocity *= 0.8f;
                    }
                    if (flag && !flag3 && (double)projectile.velocity.Length() < (double)num6 * 0.6)
                    {
                        projectile.velocity.Normalize();
                        projectile.velocity *= num6 * 0.6f;
                    }
                    if (action != null)
                    {
                        action(); // Run the action specified.
                    }
                }
            }
            else // projectile is returning to player
            {
                num10 = (float)((int)((double)num10 * 0.8));
                num6 *= 1.5f;
                projectile.tileCollide = false;
                Vector2 vector8 = Main.player[projectile.owner].position - projectile.Center;
                float   num12   = vector8.Length();
                if (num12 < num6 + 10f || num12 == 0f)
                {
                    projectile.Kill();
                }
                else
                {
                    vector8.Normalize();
                    vector8            *= num6;
                    projectile.velocity = (projectile.velocity * (num10 - 1f) + vector8) / num10;
                }
            }
            projectile.rotation += rotationSpeed;
        }