示例#1
0
        public override bool PreAI()
        {
            if (!init)
            {
                nodes.Add(projectile.Center);
                targetPosition = projectile.position + new Vector2(0, projectile.ai[1]);
                boltRect       = new Rectangle(
                    (int)boundLeft,
                    (int)projectile.position.Y,
                    projectile.width,
                    (int)projectile.ai[1]);
                airRect = new Rectangle(
                    (int)(targetPosition.X - airRadius),
                    (int)(targetPosition.Y - airRadius),
                    (int)(airRadius * 2),
                    (int)(airRadius * 2));
                float halfWidth = projectile.width / 2f;
                boundLeft  = targetPosition.X - halfWidth;
                boundRight = targetPosition.X + halfWidth - (minVariance.X * 2);
                init       = true;
            }

            if (isCloud)
            {
                for (int i = 0; i < Main.maxPlayers; i++)
                {
                    Player player = Main.player[i];
                    if (player.active && !player.dead)
                    {
                        Rectangle playerRect = player.getRect();
                        if (playerRect.Intersects(airRect))
                        {
                            player.GetModPlayer <BuffPlayer>().AddShockedAirBuff(player, projectile.ai[0]);
                        }
                    }
                }

                for (int i = 0; i < Main.maxNPCs; i++)
                {
                    NPC npc = Main.npc[i];
                    if (npc.active && (!npc.friendly || npc.townNPC) && !npc.dontTakeDamage)
                    {
                        Rectangle npcRect = npc.getRect();
                        if (npcRect.Intersects(airRect))
                        {
                            BuffNPC pomNPC = npc.GetGlobalNPC <BuffNPC>();
                            pomNPC.AddShockedAirBuff(npc, projectile.ai[0]);
                        }
                    }
                }

                Lighting.AddLight(targetPosition, emittedLight);
            }
            else
            {
                if (projectile.position != targetPosition)
                {
                    float nextX = Main.rand.NextFloat(boundLeft, boundRight);
                    float diff  = nextX - projectile.position.X;
                    if (Math.Abs(diff) < minVariance.X)
                    {
                        nextX += minVariance.X * 2;
                    }

                    float velocityY = Main.rand.NextFloat(0, varianceHeight) + varianceYOffset;
                    if (velocityY < 0)
                    {
                        if (justWentUp)
                        {
                            velocityY  = minVariance.Y;
                            justWentUp = false;
                        }
                        else if (velocityY > -minVariance.Y)
                        {
                            velocityY = -minVariance.Y;
                        }
                    }
                    else
                    {
                        justWentUp = false;
                    }
                    if (velocityY < 0)
                    {
                        justWentUp = true;
                    }

                    Vector2 position = new Vector2(nextX, projectile.position.Y + velocityY);

                    if ((position.Y > targetPosition.Y ||
                         (targetPosition - position).LengthSquared() < snapRadiusSqr))
                    {
                        position            = targetPosition;
                        projectile.timeLeft = PathOfModifiers.ailmentDuration;
                    }

                    projectile.position = position;

                    nodes.Add(projectile.Center);

                    foreach (var node in nodes)
                    {
                        Lighting.AddLight(node, emittedLight);
                    }
                }
                else
                {
                    Explode();
                }
            }


            return(false);
        }