コード例 #1
0
        public static void SetPosition(NPC npc)
        {
            CaptiveElement modNPC = npc.modNPC as CaptiveElement;

            if (modNPC != null)
            {
                Vector2 center = Main.npc[modNPC.center].Center;
                double  angle  = Main.npc[modNPC.center].ai[3] + 2.0 * Math.PI * modNPC.captiveType / 5.0;
                npc.position = center + 300f * (new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle))) - npc.Size / 2f;
            }
        }
コード例 #2
0
        public override void AI()
        {
            if (Main.netMode != 1 && npc.localAI[0] == 0f)
            {
                for (int k = 0; k < 5; k++)
                {
                    int captive = NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, mod.NPCType("CaptiveElement"));
                    Main.npc[captive].ai[0] = npc.whoAmI;
                    Main.npc[captive].ai[1] = k;
                    Main.npc[captive].ai[2] = 50 * (k + 1);
                    CaptiveElement.SetPosition(Main.npc[captive]);
                    Main.npc[captive].netUpdate = true;
                }
                npc.netUpdate  = true;
                npc.localAI[0] = 1f;
            }
            Player player = Main.player[npc.target];

            if (!player.active || player.dead || player.position.Y < hellLayer * 16)
            {
                npc.TargetClosest(false);
                player = Main.player[npc.target];
                if (!player.active || player.dead || player.position.Y < hellLayer * 16)
                {
                    npc.velocity = new Vector2(0f, 10f);
                    if (npc.timeLeft > 10)
                    {
                        npc.timeLeft = 10;
                    }
                    return;
                }
            }
            moveCool -= 1f;
            if (Main.netMode != 1 && moveCool <= 0f)
            {
                npc.TargetClosest(false);
                player = Main.player[npc.target];
                double  angle    = Main.rand.NextDouble() * 2.0 * Math.PI;
                int     distance = sphereRadius + Main.rand.Next(200);
                Vector2 moveTo   = player.Center + (float)distance * new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
                moveCool      = (float)moveTime + (float)Main.rand.Next(100);
                npc.velocity  = (moveTo - npc.Center) / moveCool;
                rotationSpeed = (float)(Main.rand.NextDouble() + Main.rand.NextDouble());
                if (rotationSpeed > 1f)
                {
                    rotationSpeed = 1f + (rotationSpeed - 1f) / 2f;
                }
                if (Main.rand.Next(2) == 0)
                {
                    rotationSpeed *= -1;
                }
                rotationSpeed *= 0.01f;
                npc.netUpdate  = true;
            }
            if (Vector2.Distance(Main.player[npc.target].position, npc.position) > sphereRadius)
            {
                moveTimer--;
            }
            else
            {
                moveTimer += 3;
                if (moveTime >= 300 && moveTimer > 60)
                {
                    moveTimer = 60;
                }
            }
            if (moveTimer <= 0)
            {
                moveTimer += 60;
                moveTime  -= 3;
                if (moveTime < 99)
                {
                    moveTime  = 99;
                    moveTimer = 0;
                }
                npc.netUpdate = true;
            }
            else if (moveTimer > 60)
            {
                moveTimer    -= 60;
                moveTime     += 3;
                npc.netUpdate = true;
            }
            captiveRotation += rotationSpeed;
            if (captiveRotation < 0f)
            {
                captiveRotation += 2f * (float)Math.PI;
            }
            if (captiveRotation >= 2f * (float)Math.PI)
            {
                captiveRotation -= 2f * (float)Math.PI;
            }
            attackCool -= 1f;
            if (Main.netMode != 1 && difficulty > 1 && attackCool > 0f && attackCool <= 60f && (int)Math.Ceiling(attackCool) % 30 == 0)
            {
                Shoot(player);
            }
            if (Main.netMode != 1 && attackCool <= 0)
            {
                attackCool = 200f + 200f * (float)npc.life / (float)npc.lifeMax + (float)Main.rand.Next(200);
                Shoot(player);
                npc.netUpdate = true;
            }
            if (difficulty > 0)
            {
                ExpertLaser();
            }
            if (Main.rand.Next(2) == 0)
            {
                float  radius = (float)Math.Sqrt(Main.rand.Next(sphereRadius * sphereRadius));
                double angle  = Main.rand.NextDouble() * 2.0 * Math.PI;
                Dust.NewDust(new Vector2(npc.Center.X + radius * (float)Math.Cos(angle), npc.Center.Y + radius * (float)Math.Sin(angle)), 0, 0, mod.DustType("Sparkle"), 0f, 0f, 0, default(Color), 1.5f);
            }
        }