コード例 #1
0
        public override bool PreAI()
        {
            Player player = Main.player[npc.target];

            AAAI.DustOnNPCSpawn(npc, ModContent.DustType <AkumaADust>(), 2, 12);

            npc.spriteDirection = npc.velocity.X > 0 ? -1 : 1;
            npc.ai[1]++;
            if (npc.ai[1] >= 1200)
            {
                npc.ai[1] = 0;
            }
            npc.TargetClosest(true);
            if (!Main.player[npc.target].active || Main.player[npc.target].dead)
            {
                npc.TargetClosest(true);
                if (!Main.player[npc.target].active || Main.player[npc.target].dead)
                {
                    npc.ai[3]++;
                    npc.velocity.Y = npc.velocity.Y + 0.11f;
                    if (npc.ai[3] >= 300)
                    {
                        npc.active = false;
                    }
                }
                else
                {
                    npc.ai[3] = 0;
                }
            }
            if (Main.netMode != NetmodeID.MultiplayerClient)
            {
                if (npc.ai[0] == 0)
                {
                    npc.realLife = npc.whoAmI;
                    int latestNPC = npc.whoAmI;

                    for (int i = 0; i < 12; ++i)
                    {
                        latestNPC = NPC.NewNPC((int)npc.Center.X, (int)npc.Center.Y, mod.NPCType("AwakenedLungBody"), npc.whoAmI, 0, latestNPC);
                        Main.npc[latestNPC].realLife = npc.whoAmI;
                        Main.npc[latestNPC].ai[3]    = npc.whoAmI;
                    }

                    latestNPC = NPC.NewNPC((int)npc.Center.X, (int)npc.Center.Y, mod.NPCType("AwakenedLungTail"), npc.whoAmI, 0, latestNPC);
                    Main.npc[latestNPC].realLife = npc.whoAmI;
                    Main.npc[latestNPC].ai[3]    = npc.whoAmI;

                    npc.ai[0]     = 1;
                    npc.netUpdate = true;
                }
            }

            int minTilePosX = (int)(npc.position.X / 16.0) - 1;
            int maxTilePosX = (int)((npc.position.X + npc.width) / 16.0) + 2;
            int minTilePosY = (int)(npc.position.Y / 16.0) - 1;
            int maxTilePosY = (int)((npc.position.Y + npc.height) / 16.0) + 2;

            if (minTilePosX < 0)
            {
                minTilePosX = 0;
            }
            if (maxTilePosX > Main.maxTilesX)
            {
                maxTilePosX = Main.maxTilesX;
            }
            if (minTilePosY < 0)
            {
                minTilePosY = 0;
            }
            if (maxTilePosY > Main.maxTilesY)
            {
                maxTilePosY = Main.maxTilesY;
            }

            bool collision = true;

            float speed        = 16;
            float acceleration = 0.15f;

            Vector2 npcCenter  = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f);
            float   targetXPos = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2);
            float   targetYPos = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2);

            float targetRoundedPosX = (int)(targetXPos / 16.0) * 16;
            float targetRoundedPosY = (int)(targetYPos / 16.0) * 16;

            npcCenter.X = (int)(npcCenter.X / 16.0) * 16;
            npcCenter.Y = (int)(npcCenter.Y / 16.0) * 16;
            float dirX = targetRoundedPosX - npcCenter.X;
            float dirY = targetRoundedPosY - npcCenter.Y;

            Vector2 vector132 = player.Center - npc.Center;

            (vector132.X > 0f).ToDirectionInt();
            (vector132.Y > 0f).ToDirectionInt();
            if (vector132.Length() < 500f && vector132.Length() >= 100f && npc.velocity.X / vector132.X > 0)
            {
                flaming = true;
                Vector2 shootspeed = Vector2.Normalize(npc.velocity) * 20f;
                Vector2 shootpos   = Vector2.Normalize(npc.velocity).RotatedBy((float)Math.PI / 2 * npc.direction) * npc.height / 2;
                AAAI.BreatheFire(npc, true, mod.ProjectileType("AkumaABreath"), 2, 4);
            }
            else
            {
                flaming = false;
            }

            float length = (float)Math.Sqrt(dirX * dirX + dirY * dirY);

            if (!collision)
            {
                npc.TargetClosest(true);
                npc.velocity.Y = npc.velocity.Y + 0.11f;
                if (npc.velocity.Y > speed)
                {
                    npc.velocity.Y = speed;
                }
                if (Math.Abs(npc.velocity.X) + Math.Abs(npc.velocity.Y) < speed * 0.4)
                {
                    if (npc.velocity.X < 0.0)
                    {
                        npc.velocity.X = npc.velocity.X - acceleration * 1.1f;
                    }
                    else
                    {
                        npc.velocity.X = npc.velocity.X + acceleration * 1.1f;
                    }
                }
                else if (npc.velocity.Y == speed)
                {
                    if (npc.velocity.X < dirX)
                    {
                        npc.velocity.X = npc.velocity.X + acceleration;
                    }
                    else if (npc.velocity.X > dirX)
                    {
                        npc.velocity.X = npc.velocity.X - acceleration;
                    }
                }
                else if (npc.velocity.Y > 4.0)
                {
                    if (npc.velocity.X < 0.0)
                    {
                        npc.velocity.X = npc.velocity.X + acceleration * 0.9f;
                    }
                    else
                    {
                        npc.velocity.X = npc.velocity.X - acceleration * 0.9f;
                    }
                }
            }
            else
            {
                if (npc.soundDelay == 0)
                {
                    float num1 = length / 40f;
                    if (num1 < 10.0)
                    {
                        num1 = 10f;
                    }
                    if (num1 > 20.0)
                    {
                        num1 = 20f;
                    }
                    npc.soundDelay = (int)num1;
                }
                float absDirX  = Math.Abs(dirX);
                float absDirY  = Math.Abs(dirY);
                float newSpeed = speed / length;
                dirX *= newSpeed;
                dirY *= newSpeed;
                if (npc.velocity.X > 0.0 && dirX > 0.0 || npc.velocity.X < 0.0 && dirX < 0.0 || npc.velocity.Y > 0.0 && dirY > 0.0 || npc.velocity.Y < 0.0 && dirY < 0.0)
                {
                    if (npc.velocity.X < dirX)
                    {
                        npc.velocity.X = npc.velocity.X + acceleration;
                    }
                    else if (npc.velocity.X > dirX)
                    {
                        npc.velocity.X = npc.velocity.X - acceleration;
                    }
                    if (npc.velocity.Y < dirY)
                    {
                        npc.velocity.Y = npc.velocity.Y + acceleration;
                    }
                    else if (npc.velocity.Y > dirY)
                    {
                        npc.velocity.Y = npc.velocity.Y - acceleration;
                    }
                    if (Math.Abs(dirY) < speed * 0.2 && (npc.velocity.X > 0.0 && dirX < 0.0 || npc.velocity.X < 0.0 && dirX > 0.0))
                    {
                        if (npc.velocity.Y > 0.0)
                        {
                            npc.velocity.Y = npc.velocity.Y + acceleration * 2f;
                        }
                        else
                        {
                            npc.velocity.Y = npc.velocity.Y - acceleration * 2f;
                        }
                    }
                    if (Math.Abs(dirX) < speed * 0.2 && (npc.velocity.Y > 0.0 && dirY < 0.0 || npc.velocity.Y < 0.0 && dirY > 0.0))
                    {
                        if (npc.velocity.X > 0.0)
                        {
                            npc.velocity.X = npc.velocity.X + acceleration * 2f;
                        }
                        else
                        {
                            npc.velocity.X = npc.velocity.X - acceleration * 2f;
                        }
                    }
                }
                else if (absDirX > absDirY)
                {
                    if (npc.velocity.X < dirX)
                    {
                        npc.velocity.X = npc.velocity.X + acceleration * 1.1f;
                    }
                    else if (npc.velocity.X > dirX)
                    {
                        npc.velocity.X = npc.velocity.X - acceleration * 1.1f;
                    }
                    if (Math.Abs(npc.velocity.X) + Math.Abs(npc.velocity.Y) < speed * 0.5)
                    {
                        if (npc.velocity.Y > 0.0)
                        {
                            npc.velocity.Y = npc.velocity.Y + acceleration;
                        }
                        else
                        {
                            npc.velocity.Y = npc.velocity.Y - acceleration;
                        }
                    }
                }
                else
                {
                    if (npc.velocity.Y < dirY)
                    {
                        npc.velocity.Y = npc.velocity.Y + acceleration * 1.1f;
                    }
                    else if (npc.velocity.Y > dirY)
                    {
                        npc.velocity.Y = npc.velocity.Y - acceleration * 1.1f;
                    }
                    if (Math.Abs(npc.velocity.X) + Math.Abs(npc.velocity.Y) < speed * 0.5)
                    {
                        if (npc.velocity.X > 0.0)
                        {
                            npc.velocity.X = npc.velocity.X + acceleration;
                        }
                        else
                        {
                            npc.velocity.X = npc.velocity.X - acceleration;
                        }
                    }
                }
            }
            npc.rotation = (float)Math.Atan2(npc.velocity.Y, npc.velocity.X) + 1.57f;

            if (!Main.dayTime)
            {
                npc.velocity.Y = npc.velocity.Y - 1f;
                if (npc.position.Y - npc.height - npc.velocity.Y >= Main.maxTilesY && Main.netMode != NetmodeID.MultiplayerClient)
                {
                    BaseAI.KillNPC(npc); npc.netUpdate2 = true;
                }
            }



            if (Main.player[npc.target].dead || Math.Abs(npc.position.X - Main.player[npc.target].position.X) > 6000f || Math.Abs(npc.position.Y - Main.player[npc.target].position.Y) > 6000f)
            {
                npc.velocity.Y = npc.velocity.Y + 1f;
                if (npc.position.Y < 0)
                {
                    npc.velocity.Y = npc.velocity.Y + 1f;
                    speed          = 30f;
                }
                if (npc.position.Y < 0)
                {
                    for (int num957 = 0; num957 < 200; num957++)
                    {
                        if (Main.npc[num957].aiStyle == npc.aiStyle)
                        {
                            Main.npc[num957].active = false;
                        }
                    }
                }
            }

            if (collision)
            {
                if (npc.localAI[0] != 1)
                {
                    npc.netUpdate = true;
                }
                npc.localAI[0] = 1f;
            }
            else
            {
                if (npc.localAI[0] != 0.0)
                {
                    npc.netUpdate = true;
                }
                npc.localAI[0] = 0.0f;
            }
            if ((npc.velocity.X > 0.0 && npc.oldVelocity.X < 0.0 || npc.velocity.X < 0.0 && npc.oldVelocity.X > 0.0 || npc.velocity.Y > 0.0 && npc.oldVelocity.Y < 0.0 || npc.velocity.Y < 0.0 && npc.oldVelocity.Y > 0.0) && !npc.justHit)
            {
                npc.netUpdate = true;
            }

            return(false);
        }
コード例 #2
0
        public override bool PreAI()
        {
            Vector2 chasePosition   = Main.npc[(int)npc.ai[1]].Center;
            Vector2 directionVector = chasePosition - npc.Center;

            npc.spriteDirection = (directionVector.X > 0f) ? 1 : -1;
            if (npc.ai[3] > 0)
            {
                npc.realLife = (int)npc.ai[3];
            }
            if (npc.target < 0 || npc.target == byte.MaxValue || Main.player[npc.target].dead)
            {
                npc.TargetClosest(true);
            }
            if (Main.player[npc.target].dead && npc.timeLeft > 300)
            {
                npc.timeLeft = 300;
            }
            AAAI.DustOnNPCSpawn(npc, ModContent.DustType <AkumaADust>(), 2, 12);

            if (Main.netMode != NetmodeID.MultiplayerClient)
            {
                if (!Main.npc[(int)npc.ai[1]].active || Main.npc[(int)npc.ai[3]].type != mod.NPCType("AwakenedLung"))
                {
                    npc.life = 0;
                    npc.HitEffect(0, 10.0);
                    npc.active = false;
                    NetMessage.SendData(MessageID.StrikeNPC, -1, -1, null, npc.whoAmI, -1f, 0.0f, 0.0f, 0, 0, 0);
                }
            }

            if (npc.ai[1] < (double)Main.npc.Length)
            {
                Vector2 npcCenter = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f);
                float   dirX      = Main.npc[(int)npc.ai[1]].position.X + Main.npc[(int)npc.ai[1]].width / 2 - npcCenter.X;
                float   dirY      = Main.npc[(int)npc.ai[1]].position.Y + Main.npc[(int)npc.ai[1]].height / 2 - npcCenter.Y;
                npc.rotation = (float)Math.Atan2(dirY, dirX) + 1.57f;
                float length = (float)Math.Sqrt(dirX * dirX + dirY * dirY);
                float dist   = (length - npc.width) / length;
                float posX   = dirX * dist;
                float posY   = dirY * dist;

                if (dirX < 0f)
                {
                    npc.spriteDirection = 1;
                }
                else
                {
                    npc.spriteDirection = -1;
                }

                npc.velocity   = Vector2.Zero;
                npc.position.X = npc.position.X + posX;
                npc.position.Y = npc.position.Y + posY;
            }

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

            if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
            {
                npc.TargetClosest(true);
            }
            npc.netUpdate = true;
            return(false);
        }