public override void Update(Player player, ref int buffIndex)
        {
            player.buffTime[buffIndex] = 18000;
            TheLuggagePlayer modPlayer = player.GetModPlayer <TheLuggagePlayer>();

            modPlayer.theLuggagePet = true;
            //player.truffle = true;
            bool theLuggageNotSpawned = true;

            if (player.ownedProjectileCounts[mod.ProjectileType <Projectiles.TheLuggagePet>()] > 0)
            {
                theLuggageNotSpawned = false;
            }
            if (theLuggageNotSpawned && player.whoAmI == Main.myPlayer)
            {
                Projectile.NewProjectile(player.position.X + (float)(player.width / 2) * 2, player.position.Y + (float)(player.height / 2), 0f, 0f, mod.ProjectileType <Projectiles.TheLuggagePet>(), 0, 0f, player.whoAmI, 0f, 0f);
            }
        }
        public override void AI()
        {
            Entity target = Main.player[projectile.owner];

            if (!Main.player[projectile.owner].active)
            {
                projectile.active = false;
                return;
            }

            pickup();

            int num = 85;

            // Change "target" to player OR items.  No teleporting to items....?
            int lootTarget = targetLoot();

            if (lootTarget != -1)
            {
                //Item targetedLootItem = Main.item[lootTarget];
                target = Main.item[lootTarget];
                num    = 0;
                //Vector2 vector132 = targetedLootItem.Center - projectile.Center;
            }


            bool playerOutOfRangeLeftSide  = false;
            bool playerOutOfRangeRightSide = false;
            bool playerBelowPet            = false;
            bool flag4 = false;



            //if (projectile.type == 209)
            //{
            Player           player    = Main.player[projectile.owner];
            TheLuggagePlayer modPlayer = player.GetModPlayer <TheLuggagePlayer>(mod);

            if (Main.player[projectile.owner].dead)
            {
                modPlayer.theLuggagePet = false;
                //   Main.player[projectile.owner].truffle = false;
            }
            if (modPlayer.theLuggagePet)
            {
                projectile.timeLeft = 2;
            }
            //}


            //if (Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2) < projectile.position.X + (float)(projectile.width / 2) - (float)num)
            //{
            //    playerOutOfRangeLeftSide = true;
            //}
            //else if (Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2) > projectile.position.X + (float)(projectile.width / 2) + (float)num)
            //{
            //    playerOutOfRangeRightSide = true;
            //}

            if (target.position.X + (float)(target.width / 2) < projectile.position.X + (float)(projectile.width / 2) - (float)num)
            {
                playerOutOfRangeLeftSide = true;
            }
            else if (target.position.X + (float)(target.width / 2) > projectile.position.X + (float)(projectile.width / 2) + (float)num)
            {
                playerOutOfRangeRightSide = true;
            }



            {
                if (projectile.ai[1] == 0f)
                {
                    int num36 = 1000;

                    if (Main.player[projectile.owner].rocketDelay2 > 0)
                    {
                        projectile.ai[0] = 1f;
                    }
                    Vector2 petCenter         = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f);
                    float   distanceXToPlayer = Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2) - petCenter.X;

                    float distanceYToPlayer = Main.player[projectile.owner].position.Y + (float)(Main.player[projectile.owner].height / 2) - petCenter.Y;
                    float distanceToPlayer  = (float)Math.Sqrt((double)(distanceXToPlayer * distanceXToPlayer + distanceYToPlayer * distanceYToPlayer));
                    if (distanceToPlayer > 2000f)
                    {
                        // teleport now!
                        projectile.position.X = Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2) - (float)(projectile.width / 2);
                        projectile.position.Y = Main.player[projectile.owner].position.Y + (float)(Main.player[projectile.owner].height / 2) - (float)(projectile.height / 2);
                    }
                    else if (distanceToPlayer > (float)num36 || (Math.Abs(distanceYToPlayer) > 800f && (true || projectile.localAI[0] <= 0f)))
                    {
                        projectile.ai[0] = 1f;
                    }
                }
                // if teleporting.
                if (/*projectile.type == 209 && */ projectile.ai[0] != 0f)
                {
                    if (Main.player[projectile.owner].velocity.Y == 0f && projectile.alpha >= 100)
                    {
                        // Teleport Directly to player
                        projectile.position.X = Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2) - (float)(projectile.width / 2);
                        projectile.position.Y = Main.player[projectile.owner].position.Y + (float)Main.player[projectile.owner].height - (float)projectile.height;
                        projectile.ai[0]      = 0f;
                        return;
                    }
                    projectile.velocity.X = 0f;
                    projectile.velocity.Y = 0f;
                    projectile.alpha     += 5;
                    if (projectile.alpha > 255)
                    {
                        projectile.alpha = 255;
                        return;
                    }
                }
                //else if (projectile.ai[0] != 0f)
                //{
                //    float num40 = 0.2f;
                //    int num41 = 200;


                //    projectile.tileCollide = false;
                //    Vector2 vector7 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f);
                //    float num42 = Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2) - vector7.X;

                //    float num48 = Main.player[projectile.owner].position.Y + (float)(Main.player[projectile.owner].height / 2) - vector7.Y;

                //    float num49 = (float)Math.Sqrt((double)(num42 * num42 + num48 * num48));
                //    float num50 = 10f;
                //    float num51 = num49;


                //    if (num49 < (float)num41 && Main.player[projectile.owner].velocity.Y == 0f && projectile.position.Y + (float)projectile.height <= Main.player[projectile.owner].position.Y + (float)Main.player[projectile.owner].height && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height))
                //    {
                //        projectile.ai[0] = 0f;
                //        if (projectile.velocity.Y < -6f)
                //        {
                //            projectile.velocity.Y = -6f;
                //        }
                //    }
                //    if (num49 < 60f)
                //    {
                //        num42 = projectile.velocity.X;
                //        num48 = projectile.velocity.Y;
                //    }
                //    else
                //    {
                //        num49 = num50 / num49;
                //        num42 *= num49;
                //        num48 *= num49;
                //    }

                //    {
                //        if (projectile.velocity.X < num42)
                //        {
                //            projectile.velocity.X = projectile.velocity.X + num40;
                //            if (projectile.velocity.X < 0f)
                //            {
                //                projectile.velocity.X = projectile.velocity.X + num40 * 1.5f;
                //            }
                //        }
                //        if (projectile.velocity.X > num42)
                //        {
                //            projectile.velocity.X = projectile.velocity.X - num40;
                //            if (projectile.velocity.X > 0f)
                //            {
                //                projectile.velocity.X = projectile.velocity.X - num40 * 1.5f;
                //            }
                //        }
                //        if (projectile.velocity.Y < num48)
                //        {
                //            projectile.velocity.Y = projectile.velocity.Y + num40;
                //            if (projectile.velocity.Y < 0f)
                //            {
                //                projectile.velocity.Y = projectile.velocity.Y + num40 * 1.5f;
                //            }
                //        }
                //        if (projectile.velocity.Y > num48)
                //        {
                //            projectile.velocity.Y = projectile.velocity.Y - num40;
                //            if (projectile.velocity.Y > 0f)
                //            {
                //                projectile.velocity.Y = projectile.velocity.Y - num40 * 1.5f;
                //            }
                //        }
                //    }

                //    if ((double)projectile.velocity.X > 0.5)
                //    {
                //        projectile.spriteDirection = -1;
                //    }
                //    else if ((double)projectile.velocity.X < -0.5)
                //    {
                //        projectile.spriteDirection = 1;
                //    }



                //    else if (projectile.spriteDirection == -1)
                //    {
                //        projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X);
                //    }
                //    else
                //    {
                //        projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 3.14f;
                //    }


                //    //if (projectile.type != 398 && projectile.type != 390 && projectile.type != 391 && projectile.type != 392 && projectile.type != 127 && projectile.type != 200 && projectile.type != 208 && projectile.type != 210 && projectile.type != 236 && projectile.type != 266 && projectile.type != 268 && projectile.type != 269 && projectile.type != 313 && projectile.type != 314 && projectile.type != 319 && projectile.type != 324 && projectile.type != 334 && projectile.type != 353)
                //    //{
                //    //    int num56 = Dust.NewDust(new Vector2(projectile.position.X + (float)(projectile.width / 2) - 4f, projectile.position.Y + (float)(projectile.height / 2) - 4f) - projectile.velocity, 8, 8, 16, -projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f, 50, default(Color), 1.7f);
                //    //    Main.dust[num56].velocity.X = Main.dust[num56].velocity.X * 0.2f;
                //    //    Main.dust[num56].velocity.Y = Main.dust[num56].velocity.Y * 0.2f;
                //    //    Main.dust[num56].noGravity = true;
                //    //    return;
                //    //}
                //}
                else
                {
                    //bool flag6 = false;
                    Vector2 vector9 = Vector2.Zero;
                    //bool flag7 = false;
                    // ?? does nothing.
                    if (projectile.ai[1] != 0f)
                    {
                        playerOutOfRangeLeftSide  = false;
                        playerOutOfRangeRightSide = false;
                    }
                    float xAccelerationValue = 0.08f;
                    float xVelocityLimit     = 6.5f;
                    if (playerOutOfRangeLeftSide)
                    {
                        if ((double)projectile.velocity.X > -3.5)
                        {
                            projectile.velocity.X = projectile.velocity.X - xAccelerationValue;
                        }
                        else
                        {
                            projectile.velocity.X = projectile.velocity.X - xAccelerationValue * 0.25f;
                        }
                    }
                    else if (playerOutOfRangeRightSide)
                    {
                        if ((double)projectile.velocity.X < 3.5)
                        {
                            projectile.velocity.X = projectile.velocity.X + xAccelerationValue;
                        }
                        else
                        {
                            projectile.velocity.X = projectile.velocity.X + xAccelerationValue * 0.25f;
                        }
                    }
                    else
                    {
                        projectile.velocity.X = projectile.velocity.X * 0.9f;
                        if (projectile.velocity.X >= -xAccelerationValue && projectile.velocity.X <= xAccelerationValue)
                        {
                            projectile.velocity.X = 0f;
                        }
                    }
                    if (playerOutOfRangeLeftSide || playerOutOfRangeRightSide)
                    {
                        int petPositionTileX = (int)(projectile.position.X + (float)(projectile.width / 2)) / 16;
                        int petPositionTileY = (int)(projectile.position.Y + (float)(projectile.height / 2)) / 16;

                        if (playerOutOfRangeLeftSide)
                        {
                            petPositionTileX--;
                        }
                        if (playerOutOfRangeRightSide)
                        {
                            petPositionTileX++;
                        }
                        petPositionTileX += (int)projectile.velocity.X;
                        if (WorldGen.SolidTile(petPositionTileX, petPositionTileY))
                        {
                            flag4 = true;
                        }
                    }
                    if (Main.player[projectile.owner].position.Y + (float)Main.player[projectile.owner].height - 8f > projectile.position.Y + (float)projectile.height)
                    {
                        playerBelowPet = true;
                    }
                    Collision.StepUp(ref projectile.position, ref projectile.velocity, projectile.width, projectile.height, ref projectile.stepSpeed, ref projectile.gfxOffY, 1, false, 0);
                    if (projectile.velocity.Y == 0f)
                    {
                        if (!playerBelowPet && (projectile.velocity.X < 0f || projectile.velocity.X > 0f))
                        {
                            int num102 = (int)(projectile.position.X + (float)(projectile.width / 2)) / 16;
                            int j3     = (int)(projectile.position.Y + (float)(projectile.height / 2)) / 16 + 1;
                            if (playerOutOfRangeLeftSide)
                            {
                                num102--;
                            }
                            if (playerOutOfRangeRightSide)
                            {
                                num102++;
                            }
                            WorldGen.SolidTile(num102, j3);
                        }
                        if (flag4)
                        {
                            int num103 = (int)(projectile.position.X + (float)(projectile.width / 2)) / 16;
                            int num104 = (int)(projectile.position.Y + (float)projectile.height) / 16 + 1;
                            if (WorldGen.SolidTile(num103, num104) || Main.tile[num103, num104].halfBrick() || Main.tile[num103, num104].slope() > 0 /*|| projectile.type == 200*/)
                            {
                                {
                                    try
                                    {
                                        num103 = (int)(projectile.position.X + (float)(projectile.width / 2)) / 16;
                                        num104 = (int)(projectile.position.Y + (float)(projectile.height / 2)) / 16;
                                        if (playerOutOfRangeLeftSide)
                                        {
                                            num103--;
                                        }
                                        if (playerOutOfRangeRightSide)
                                        {
                                            num103++;
                                        }
                                        num103 += (int)projectile.velocity.X;
                                        if (!WorldGen.SolidTile(num103, num104 - 1) && !WorldGen.SolidTile(num103, num104 - 2))
                                        {
                                            projectile.velocity.Y = -5.1f;
                                        }
                                        else if (!WorldGen.SolidTile(num103, num104 - 2))
                                        {
                                            projectile.velocity.Y = -7.1f;
                                        }
                                        else if (WorldGen.SolidTile(num103, num104 - 5))
                                        {
                                            projectile.velocity.Y = -11.1f;
                                        }
                                        else if (WorldGen.SolidTile(num103, num104 - 4))
                                        {
                                            projectile.velocity.Y = -10.1f;
                                        }
                                        else
                                        {
                                            projectile.velocity.Y = -9.1f;
                                        }
                                    }
                                    catch
                                    {
                                        projectile.velocity.Y = -9.1f;
                                    }
                                }
                            }
                        }
                    }
                    if (projectile.velocity.X > xVelocityLimit)
                    {
                        projectile.velocity.X = xVelocityLimit;
                    }
                    if (projectile.velocity.X < -xVelocityLimit)
                    {
                        projectile.velocity.X = -xVelocityLimit;
                    }
                    if (projectile.velocity.X < 0f)
                    {
                        projectile.direction = -1;
                    }
                    if (projectile.velocity.X > 0f)
                    {
                        projectile.direction = 1;
                    }
                    if (projectile.velocity.X > xAccelerationValue && playerOutOfRangeRightSide)
                    {
                        projectile.direction = 1;
                    }
                    if (projectile.velocity.X < -xAccelerationValue && playerOutOfRangeLeftSide)
                    {
                        projectile.direction = -1;
                    }

                    if ((double)projectile.velocity.X > 0.5)
                    {
                        projectile.spriteDirection = -1;
                    }
                    else if ((double)projectile.velocity.X < -0.5)
                    {
                        projectile.spriteDirection = 1;
                    }


                    //else if (projectile.type == 209)
                    {
                        if (projectile.alpha > 0)
                        {
                            projectile.alpha -= 5;
                            if (projectile.alpha < 0)
                            {
                                projectile.alpha = 0;
                            }
                        }
                        if (projectile.velocity.Y == 0f)
                        {
                            if (projectile.velocity.X == 0f)
                            {
                                projectile.frame        = 0;
                                projectile.frameCounter = 0;
                            }
                            else if ((double)projectile.velocity.X < -0.1 || (double)projectile.velocity.X > 0.1)
                            {
                                projectile.frameCounter += (int)Math.Abs(projectile.velocity.X);
                                projectile.frameCounter++;
                                if (projectile.frameCounter > 6)
                                {
                                    projectile.frame++;
                                    projectile.frameCounter = 0;
                                }
                                if (projectile.frame > 4)
                                {
                                    projectile.frame = 2;
                                }
                                if (projectile.frame < 2)
                                {
                                    projectile.frame = 2;
                                }
                            }
                            else
                            {
                                projectile.frame        = 0;
                                projectile.frameCounter = 0;
                            }
                        }
                        else
                        {
                            projectile.frame        = 1;
                            projectile.frameCounter = 0;
                            projectile.rotation     = 0f;
                        }
                        projectile.velocity.Y = projectile.velocity.Y + 0.4f;
                        if (projectile.velocity.Y > 10f)
                        {
                            projectile.velocity.Y = 10f;
                            return;
                        }
                    }
                }
            }
        }