コード例 #1
0
        public override void AI()
        {
            npc.TargetClosest();

            Player player = Main.player[npc.target];

            if (player == null)
            {
                npc.TargetClosest();
            }

            if (player.dead || !player.active || Vector2.Distance(player.Center, npc.Center) > 5000)
            {
                npc.TargetClosest();

                if (player.dead || !player.active || Vector2.Distance(player.Center, npc.Center) > 5000)
                {
                    Projectile.NewProjectile(npc.Center, new Vector2(0f, 0f), mod.ProjectileType("MonarchRUNAWAY"), 0, 0);
                    npc.active = false;
                    return;
                }
            }

            float dist = npc.Distance(player.Center);

            npc.frameCounter++;
            if (internalAI[1] != AISTATE_JUMP && internalAI[1] != AISTATE_FLY) //walk or charge
            {
                int FrameSpeed = 10;
                if (internalAI[1] == AISTATE_CHARGE)
                {
                    FrameSpeed = 6;
                }

                if (npc.frameCounter >= FrameSpeed)
                {
                    npc.frameCounter = 0;
                    npc.frame.Y     += 108;
                    if (npc.frame.Y > (108 * 4))
                    {
                        npc.frameCounter = 0;
                        npc.frame.Y      = 0;
                    }
                }
                if (npc.velocity.Y != 0)
                {
                    if (npc.velocity.Y < 0)
                    {
                        npc.frame.Y = 648;
                    }
                    else
                    if (npc.velocity.Y > 0)
                    {
                        npc.frame.Y = 756;
                    }
                }
            }
            else if (internalAI[1] == AISTATE_FLY)
            {
                npc.frameCounter = 0;
                npc.frame.Y     += 108;
                if (npc.frame.Y > (108 * 11) || npc.frame.Y < (108 * 8))
                {
                    npc.frameCounter = 0;
                    npc.frame.Y      = 108 * 8;
                }
            }
            else //jump
            {
                if (npc.velocity.Y == 0)
                {
                    npc.frame.Y = 540;
                }
                else
                {
                    if (npc.velocity.Y < 0)
                    {
                        npc.frame.Y = 648;
                    }
                    else
                    if (npc.velocity.Y > 0)
                    {
                        npc.frame.Y = 756;
                    }
                }
            }
            if (player.Center.X > npc.Center.X) // so it faces the player
            {
                npc.spriteDirection = -1;
            }
            else
            {
                npc.spriteDirection = 1;
            }

            if (npc.collideX && npc.velocity.Y <= 0)
            {
                npc.velocity.Y = -4f;
                internalAI[1]  = AISTATE_CHARGE;
            }
            else if (((player.Center.Y - npc.Center.Y) < -150f && (internalAI[1] == AISTATE_WALK || internalAI[1] == AISTATE_CHARGE)) || Collision.SolidCollision(new Vector2(npc.Center.X, npc.position.Y - npc.height / 2 + 10), npc.width, npc.height))
            {
                internalAI[1] = AISTATE_FLY;
                npc.ai        = new float[4];
                npc.netUpdate = true;
            }
            else if ((player.Center.Y - npc.Center.Y) > 100f && internalAI[1] != AISTATE_FLY) // player is below the npc.
            {
                internalAI[3] = internalAI[1];                                                //record the action
                internalAI[1] = AISTATE_WALK;
                npc.ai        = new float[4];
                npc.netUpdate = true;
            }
            else if (internalAI[1] != AISTATE_WALK)
            {
                internalAI[3] = internalAI[1];
            }
            else
            {
                internalAI[1] = internalAI[3];
            }


            if (Main.netMode != 1)
            {
                if (internalAI[1] != AISTATE_FLY)
                {
                    internalAI[0]++;
                }
                if (internalAI[0] >= 180)
                {
                    internalAI[0] = 0;
                    internalAI[1] = Main.rand.Next(3);
                    npc.ai        = new float[4];
                    npc.netUpdate = true;
                }
            }
            if (internalAI[1] == AISTATE_WALK)            //fighter
            {
                npc.noGravity = false;
                if (Main.netMode != 1)
                {
                    internalAI[2]++;
                }
                if ((player.Center.Y - npc.Center.Y) > 60f) // player is below the npc.
                {
                    npc.noTileCollide = true;
                }
                else
                {
                    npc.noTileCollide = false;
                }

                if (NPC.CountNPCS(ModContent.NPCType <RedMushling>()) < 4)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        int Minion = NPC.NewNPC((int)npc.Center.X, (int)npc.Center.Y, ModContent.NPCType <RedMushling>(), 0);
                        Main.npc[Minion].netUpdate = true;
                    }
                    internalAI[2] = 0;
                }
                AAAI.InfernoFighterAI(npc, ref npc.ai, true, false, 0, 0.07f, 3f, 3, 4, 60, true, 10, 60, true, null, false);
            }
            else
            if (internalAI[1] == AISTATE_JUMP)           //jumper
            {
                npc.noGravity     = false;
                npc.noTileCollide = false;
                if (npc.ai[0] < -10)
                {
                    npc.ai[0] = -10;                 //force rapid jumping
                }
                BaseAI.AISlime(npc, ref npc.ai, true, 30, 6f, -8f, 6f, -10f);
            }
            else if (internalAI[1] == AISTATE_FLY)//fly
            {
                npc.noTileCollide = true;
                npc.noGravity     = true;
                if ((player.Center.Y - npc.Center.Y) > 60f)
                {
                    if (NPC.CountNPCS(ModContent.NPCType <RedMushling>()) < 6)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            int Minion = NPC.NewNPC((int)npc.Center.X, (int)npc.Center.Y, ModContent.NPCType <RedMushling>(), 0);
                            Main.npc[Minion].netUpdate = true;
                        }
                    }
                    MoveToPoint(player.Center);
                }
                else
                {
                    BaseAI.AISpaceOctopus(npc, ref npc.ai, .05f, 8, 250, 0, null);
                }


                npc.rotation = 0;
                if ((player.Center.Y - npc.Center.Y) > 30f && !Collision.SolidCollision(new Vector2(npc.Center.X, npc.position.Y - npc.height / 2 + 10), npc.width, npc.height))
                {
                    npc.rotation      = 0;
                    npc.noGravity     = false;
                    internalAI[0]     = 0;
                    internalAI[1]     = Main.rand.Next(3);
                    npc.ai            = new float[4];
                    npc.netUpdate     = true;
                    npc.noTileCollide = false;
                }
            }
            else //charger
            {
                BaseAI.AICharger(npc, ref npc.ai, 0.07f, 10f, false, 30);
            }
        }
コード例 #2
0
        public override void AI()
        {
            Player player = Main.player[npc.target]; // makes it so you can reference the player the npc is targetting

            npc.frameCounter++;
            if (internalAI[1] != AISTATE_JUMP) //walk or charge
            {
                npc.frameCounter++;
                if (npc.frameCounter >= 10)
                {
                    npc.frameCounter = 0;
                    npc.frame.Y     += 108;
                    if (npc.frame.Y > (108 * 4))
                    {
                        npc.frameCounter = 0;
                        npc.frame.Y      = 0;
                    }
                }
                if (npc.velocity.Y != 0)
                {
                    if (npc.velocity.Y < 0)
                    {
                        npc.frame.Y = 648;
                    }
                    else
                    if (npc.velocity.Y > 0)
                    {
                        npc.frame.Y = 756;
                    }
                }
            }
            else  //jump
            {
                if (npc.velocity.Y == 0)
                {
                    npc.frame.Y = 540;
                }
                else
                {
                    if (npc.velocity.Y < 0)
                    {
                        npc.frame.Y = 648;
                    }
                    else
                    if (npc.velocity.Y > 0)
                    {
                        npc.frame.Y = 756;
                    }
                }
            }
            if (player.Center.X > npc.Center.X) // so it faces the player
            {
                npc.spriteDirection = -1;
            }
            else
            {
                npc.spriteDirection = 1;
            }
            if (Main.netMode != 1)
            {
                internalAI[0]++;
                if (internalAI[0] >= 180)
                {
                    internalAI[0] = 0;
                    internalAI[1] = Main.rand.Next(3);
                    npc.ai        = new float[4];
                    npc.netUpdate = true;
                }
            }
            if (internalAI[1] == AISTATE_WALK)            //fighter
            {
                AAAI.InfernoFighterAI(npc, ref npc.ai, true, false, 0, 0.07f, 3f, 3, 4, 60, true, 10, 60, true, null, false);
            }
            else
            if (internalAI[1] == AISTATE_JUMP)           //jumper
            {
                if (npc.ai[0] < -10)
                {
                    npc.ai[0] = -10;                                 //force rapid jumping
                }
                BaseAI.AISlime(npc, ref npc.ai, true, 30, 6f, -8f, 6f, -10f);
            }
            else              //charger
            {
                BaseAI.AICharger(npc, ref npc.ai, 0.07f, 10f, false, 30);
            }
        }