Esempio n. 1
0
 public override void PreUpdate()
 {
     if (vacuumSwitch)
     {
         Item   item   = Main.item[serchNumber];
         Player player = Main.LocalPlayer;
         if (item.active && item.noGrabDelay == 0 && !ItemLoader.GrabStyle(item, player) && ItemLoader.CanPickup(item, player))
         {
             item.position = player.Center + (player.Center - prePosition);
             if (item.position.X < 0)
             {
                 item.position.X = 0;
             }
             else if (item.position.X > Main.rightWorld)
             {
                 item.position.X = Main.rightWorld;
             }
             if (item.position.Y < 0)
             {
                 item.position.Y = 0;
             }
             else if (item.position.Y > Main.bottomWorld)
             {
                 item.position.Y = Main.bottomWorld;
             }
         }
         serchNumber += 1;
         if (serchNumber >= Main.item.Length)
         {
             serchNumber = 0;
         }
     }
     prePosition = Main.LocalPlayer.Center;
 }
Esempio n. 2
0
 public override void PreUpdate()
 {
     if (vacuumSwitch)
     {
         Player player   = Main.LocalPlayer;
         int    velocity = 12;
         foreach (Item item in Main.item)
         {
             if (item.active && item.noGrabDelay == 0 && !ItemLoader.GrabStyle(item, player) && ItemLoader.CanPickup(item, player))
             {
                 int distanceX   = (int)player.Center.X - (int)item.position.X;
                 int distanceY   = (int)player.Center.Y - (int)item.position.Y;
                 int distanceSum = System.Math.Abs(distanceX) + System.Math.Abs(distanceY);
                 if (distanceSum > 0)
                 {
                     if (item.velocity.X <= 1 && item.velocity.Y <= 1)
                     {
                         item.velocity.X  = (float)(velocity * distanceX / distanceSum + distanceX * 0.0125);
                         item.velocity.Y  = (float)(velocity * distanceY / distanceSum + distanceY * 0.0125);
                         item.position.X += item.velocity.X;
                         item.position.Y += item.velocity.Y;
                     }
                     else
                     {
                         item.velocity.X = (float)(velocity * distanceX / distanceSum + distanceX * 0.0125);
                         item.velocity.Y = (float)(velocity * distanceY / distanceSum + distanceY * 0.0125);
                     }
                 }
             }
         }
     }
 }
        private void pickup()
        {
            int    defaultItemGrabRange = 38;
            Player thisPlayer           = Main.player[projectile.owner];

            for (int j = 0; j < 400; j++)
            {
                if (Main.item[j].active && Main.item[j].noGrabDelay == 0 && Main.item[j].owner == projectile.owner && ItemLoader.CanPickup(Main.item[j], thisPlayer))
                {
                    int num = defaultItemGrabRange;                    //Player.defaultItemGrabRange;

                    if (new Rectangle((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height).Intersects(new Rectangle((int)Main.item[j].position.X, (int)Main.item[j].position.Y, Main.item[j].width, Main.item[j].height)))
                    {
                        if (projectile.owner == Main.myPlayer && (thisPlayer.inventory[thisPlayer.selectedItem].type != 0 || thisPlayer.itemAnimation <= 0))
                        {
                            // TODO, fix this maybe?
                            if (!ItemLoader.OnPickup(Main.item[j], thisPlayer))
                            {
                                Main.item[j] = new Item();
                                if (Main.netMode == 1)
                                {
                                    NetMessage.SendData(21, -1, -1, null, j, 0f, 0f, 0f, 0, 0, 0);
                                }
                                continue;
                            }

                            if (ItemID.Sets.NebulaPickup[Main.item[j].type])
                            {
                                continue;
                                //Main.PlaySound(7, (int)thisPlayer.position.X, (int)thisPlayer.position.Y, 1);
                                //int num2 = Main.item[j].buffType;
                                //Main.item[j] = new Item();
                                //if (Main.netMode == 1)
                                //{
                                //    NetMessage.SendData(102, -1, -1, "", projectile.owner, (float)num2, thisPlayer.Center.X, thisPlayer.Center.Y, 0, 0, 0);
                                //    NetMessage.SendData(21, -1, -1, "", j, 0f, 0f, 0f, 0, 0, 0);
                                //}
                                //else
                                //{
                                //    thisPlayer.NebulaLevelup(num2);
                                //}
                            }
                            if (Main.item[j].type == 58 || Main.item[j].type == 1734 || Main.item[j].type == 1867)
                            {
                                continue;
                                //Main.PlaySound(7, (int)thisPlayer.position.X, (int)thisPlayer.position.Y, 1);
                                //thisPlayer.statLife += 20;
                                //if (Main.myPlayer == thisPlayer.whoAmI)
                                //{
                                //    thisPlayer.HealEffect(20, true);
                                //}
                                //if (thisPlayer.statLife > thisPlayer.statLifeMax2)
                                //{
                                //    thisPlayer.statLife = thisPlayer.statLifeMax2;
                                //}
                                //Main.item[j] = new Item();
                                //if (Main.netMode == 1)
                                //{
                                //    NetMessage.SendData(21, -1, -1, "", j, 0f, 0f, 0f, 0, 0, 0);
                                //}
                            }
                            else if (Main.item[j].type == 184 || Main.item[j].type == 1735 || Main.item[j].type == 1868)
                            {
                                continue;
                                //Main.PlaySound(7, (int)thisPlayer.position.X, (int)thisPlayer.position.Y, 1);
                                //thisPlayer.statMana += 100;
                                //if (Main.myPlayer == thisPlayer.whoAmI)
                                //{
                                //    thisPlayer.ManaEffect(100);
                                //}
                                //if (thisPlayer.statMana > thisPlayer.statManaMax2)
                                //{
                                //    thisPlayer.statMana = thisPlayer.statManaMax2;
                                //}
                                //Main.item[j] = new Item();
                                //if (Main.netMode == 1)
                                //{
                                //    NetMessage.SendData(21, -1, -1, "", j, 0f, 0f, 0f, 0, 0, 0);
                                //}
                            }
                            else
                            {
                                Main.item[j] = thisPlayer.GetItem(projectile.owner, Main.item[j], false, false);
                                if (Main.netMode == 1)
                                {
                                    NetMessage.SendData(21, -1, -1, null, j, 0f, 0f, 0f, 0, 0, 0);
                                }
                            }

                            //  Main.item[j] = thisPlayer.GetItem(projectile.owner, Main.item[j], false, false);
                            //   ErrorLogger.Log("whoa");
                        }
                    }
                }
            }
        }
        public override void AI()
        {
            pullSpeed           = projectile.damage / 100f;
            projectile.velocity = new Vector2(0, 0);
            projectile.scale    = projectile.damage / 40f;

            Player player = Main.player[projectile.owner];

            player.itemAnimation = 2;
            if (!player.channel)
            {
                projectile.Kill();
            }
            else
            {
                manaTimer++;
                if (manaTimer % 15 == 0)
                {
                    if (player.statMana > player.inventory[player.selectedItem].mana)
                    {
                        player.statMana    -= player.inventory[player.selectedItem].mana;
                        projectile.timeLeft = 60;
                    }
                    else
                    {
                        projectile.Kill();
                    }
                }
                else
                {
                }
            }

            direction        = (projectile.Center - player.Center).ToRotation();
            horiSpeed        = (float)Math.Cos(direction) * pullSpeed / 2;
            vertSpeed        = (float)Math.Sin(direction) * pullSpeed / 2;
            player.velocity += new Vector2(horiSpeed, vertSpeed);
            for (int d = 0; d < (int)(80 * projectile.scale); d++)
            {
                float theta = Main.rand.NextFloat(-(float)Math.PI, (float)Math.PI);
                Dust  dust  = Dust.NewDustPerfect(projectile.Center + QwertyMethods.PolarVector(Main.rand.NextFloat(10 * projectile.scale, 200 * projectile.scale), theta), mod.DustType("BlackHoleMatter"), QwertyMethods.PolarVector(6 * projectile.scale, theta + (float)Math.PI / 2));
                dust.scale = 1f;
            }



            for (int i = 0; i < Main.dust.Length; i++)
            {
                dust = Main.dust[i];
                if (!dust.noGravity)
                {
                    direction      = (projectile.Center - dust.position).ToRotation();
                    horiSpeed      = (float)Math.Cos(direction) * pullSpeed * 5;
                    vertSpeed      = (float)Math.Sin(direction) * pullSpeed * 5;
                    dust.velocity += new Vector2(horiSpeed, vertSpeed);
                }
                if (dust.type == mod.DustType("BlackHoleMatter"))
                {
                    direction      = (projectile.Center - dust.position).ToRotation();
                    dust.velocity += QwertyMethods.PolarVector(.8f, direction);
                    if ((dust.position - projectile.Center).Length() < 10 * projectile.scale)
                    {
                        dust.scale = 0f;
                    }
                    else
                    {
                        dust.scale = .35f;
                    }
                }
            }
            for (int i = 0; i < 200; i++)
            {
                mass = Main.npc[i];
                if (!mass.boss && mass.active && mass.knockBackResist != 0f)
                {
                    direction      = (projectile.Center - mass.Center).ToRotation();
                    horiSpeed      = (float)Math.Cos(direction) * pullSpeed;
                    vertSpeed      = (float)Math.Sin(direction) * pullSpeed;
                    mass.velocity += new Vector2(horiSpeed, vertSpeed);
                    for (int g = 0; g < 1; g++)
                    {
                        int dust = Dust.NewDust(mass.position, mass.width, mass.height, mod.DustType("B4PDust"), horiSpeed * dustSpeed, vertSpeed * dustSpeed);
                    }
                }
            }
            for (int i = 0; i < 200; i++)
            {
                item = Main.item[i];
                if (item.position != new Vector2(0, 0))
                {
                    //This part of the code puts the items the black hole grabs in the player inventory. It's partialy based on the lugage from The Luggage mod
                    if (item.active && item.noGrabDelay == 0 && item.owner == projectile.owner && ItemLoader.CanPickup(item, player))
                    {
                        int num = Player.defaultItemGrabRange;
                        if (new Rectangle((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height).Intersects(new Rectangle((int)item.position.X, (int)item.position.Y, item.width, item.height)))
                        {
                            if (projectile.owner == Main.myPlayer && (player.inventory[player.selectedItem].type != 0 || player.itemAnimation <= 0))
                            {
                                if (ItemID.Sets.NebulaPickup[item.type])
                                {
                                    item.velocity = new Vector2(0, 0);
                                    item.position = player.Center;
                                }
                                if (item.type == 58 || item.type == 1734 || item.type == 1867)
                                {
                                    item.velocity = new Vector2(0, 0);
                                    item.position = player.Center;
                                }
                                else if (item.type == 184 || item.type == 1735 || item.type == 1868)
                                {
                                    item.velocity = new Vector2(0, 0);
                                    item.position = player.Center;
                                }
                                else
                                {
                                    for (int g = 0; g < 58; g++)
                                    {
                                        if (!player.inventory[g].active)
                                        {
                                            item.velocity = new Vector2(0, 0);
                                            item.position = player.Center;
                                        }
                                    }

                                    //item = player.GetItem(projectile.owner, item, false, false);
                                }
                            }
                        }
                    }
                    /////////////////////
                    direction      = (projectile.Center - item.Center).ToRotation();
                    horiSpeed      = (float)Math.Cos(direction) * pullSpeed;
                    vertSpeed      = (float)Math.Sin(direction) * pullSpeed;
                    item.velocity += new Vector2(horiSpeed, vertSpeed);
                    for (int g = 0; g < 1; g++)
                    {
                        int dust = Dust.NewDust(item.position, item.width, item.height, mod.DustType("B4PDust"), horiSpeed * dustSpeed, vertSpeed * dustSpeed);
                    }
                }
            }
            for (int i = 0; i < 1000; i++)
            {
                proj = Main.projectile[i];
                if (proj.active && proj.type != mod.ProjectileType("BlackHolePlayer") && proj.type != mod.ProjectileType("SideLaser"))
                {
                    direction      = (projectile.Center - proj.Center).ToRotation();
                    horiSpeed      = (float)Math.Cos(direction) * pullSpeed;
                    vertSpeed      = (float)Math.Sin(direction) * pullSpeed;
                    proj.velocity += new Vector2(horiSpeed, vertSpeed);
                    for (int g = 0; g < 1; g++)
                    {
                        int dust = Dust.NewDust(proj.position, proj.width, proj.height, mod.DustType("B4PDust"), horiSpeed * dustSpeed, vertSpeed * dustSpeed);
                    }
                }
            }
        }
        private int targetLoot()
        {
            int   target         = -1;
            float range          = 400f;
            float playerRange    = 700f;
            float targetDistance = float.MaxValue;

            for (int j = 0; j < 400; j++)
            {
                if (Main.item[j].active && Main.item[j].noGrabDelay == 0 && Main.item[j].owner == projectile.owner && ItemLoader.CanPickup(Main.item[j], Main.player[Main.item[j].owner]) && Main.player[Main.item[j].owner].ItemSpace(Main.item[j]))
                {
                    if (ItemID.Sets.NebulaPickup[Main.item[j].type])
                    {
                        continue;
                    }
                    if (Main.item[j].type == 58 || Main.item[j].type == 1734 || Main.item[j].type == 1867)
                    {
                        continue;
                    }
                    else if (Main.item[j].type == 184 || Main.item[j].type == 1735 || Main.item[j].type == 1868)
                    {
                        continue;
                    }


                    float distanceToPotential       = projectile.Distance(Main.item[j].Center);
                    float playerDistanceToPotential = Main.player[projectile.owner].Distance(Main.item[j].Center);
                    if (playerDistanceToPotential < playerRange && distanceToPotential < targetDistance && distanceToPotential < range)
                    {
                        target         = j;
                        targetDistance = distanceToPotential;
                    }
                }
            }

            return(target);
        }