當前位置: 首頁>>代碼示例>>C#>>正文


C# NPC.TargetClosest方法代碼示例

本文整理匯總了C#中Terraria.NPC.TargetClosest方法的典型用法代碼示例。如果您正苦於以下問題:C# NPC.TargetClosest方法的具體用法?C# NPC.TargetClosest怎麽用?C# NPC.TargetClosest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Terraria.NPC的用法示例。


在下文中一共展示了NPC.TargetClosest方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: NPCAiStyles

        public static void NPCAiStyles(NPC npc, int aiStyle)
        {
            if (npc.aiStyle == 102)
            {
                npc.ai[11]++;
                if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
                {
                    npc.TargetClosest(false); //Change Target in Multiplayer if current Target is dead
                }
                if (!Main.player[npc.target].dead && Main.player[npc.target].active) //If the target is alive then:
                {
                    float distance = Vector2.Distance(npc.Center, Main.player[npc.target].Center); //Distance from player
                    float num248 = 0.5f;
                    if (Main.expertMode)
                    {
                        num248 = 0.60f;
                    }
                    if ((float)npc.life < (float)npc.lifeMax * num248)
                    {
                        npc.ai[0] = 1f;
                        npc.ai[1] = 0f;
                        npc.ai[2] = 0f;
                        npc.ai[3] = 0f;
                        npc.ai[9] = 0f;
                        if (npc.ai[4] == 0f)
                        {
                            for (int k = 0; k < 20; k++)
                            {
                                int dust = Dust.NewDust(new Vector2(npc.position.X + Main.rand.Next(-2, 2), npc.position.Y + Main.rand.Next(-2, 2)), npc.width, npc.height, 270, (float)Main.rand.Next(-3, 3), (float)Main.rand.Next(-3, 3), 0, default(Color), 1.3f);
                                Main.dust[dust].velocity *= npc.velocity;
                            }
                            npc.ai[4]++;
                        }
                        npc.netUpdate = true;
                        if (npc.netSpam > 10)
                        {
                            npc.netSpam = 10;
                            return;
                        }
                    }
                    if (distance > 750f && npc.ai[11] > 180 && npc.ai[9] < 600f && npc.ai[8] < 600f)
                    {
                        float sp = 30f;
                        Vector2 pos = new Vector2(Main.player[npc.target].Center.X, Main.player[npc.target].Center.Y - 200f) - npc.Center;
                        float mag = (float)Math.Sqrt(Math.Pow(pos.X, 2) + Math.Pow(pos.Y, 2));
                        if (mag > sp)
                        {
                            pos *= sp / mag;
                        }
                        npc.velocity = pos;
                    }
                    else if (npc.ai[0] == 0f)
                    {
                        npc.ai[9]++;
                        if (npc.ai[9] < 600f)
                        {
                            if (npc.ai[1] == 0f)
                            {
                                float num243 = 10f;
                                if (Main.expertMode)
                                {
                                    num243 = 11f;
                                }
                                Vector2 vector28 = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f);
                                float num244 = Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2) - vector28.X;
                                float num245 = Main.player[npc.target].position.Y + (float)(Main.player[npc.target].height / 2) - vector28.Y;
                                float num246 = (float)Math.Sqrt((double)(num244 * num244 + num245 * num245));
                                num246 = num243 / num246;
                                npc.velocity.X = num244 * num246;
                                npc.velocity.Y = num245 * num246;
                                npc.ai[1] = 1f;
                                npc.netUpdate = true;
                                if (npc.netSpam > 10)
                                {
                                    npc.netSpam = 10;
                                }
                            }
                            else if (npc.ai[1] == 1f)
                            {
                                npc.ai[2] += 1f;
                                if (npc.ai[2] >= 20f)
                                {
                                    npc.velocity *= 0.97f;
                                    if (Main.expertMode)
                                    {
                                        npc.velocity *= 0.98f;
                                    }
                                    if ((double)npc.velocity.X > -0.1 && (double)npc.velocity.X < 0.1)
                                    {
                                        npc.velocity.X = 0f;
                                    }
                                    if ((double)npc.velocity.Y > -0.1 && (double)npc.velocity.Y < 0.1)
                                    {
                                        npc.velocity.Y = 0f;
                                    }
                                }
                                int num247 = 30;
                                if (Main.expertMode)
                                {
                                    num247 = 45;
//.........這裏部分代碼省略.........
開發者ID:thegamingboffin,項目名稱:Ulterraria_Reborn_GitHub,代碼行數:101,代碼來源:UlterrariaNPCs.cs


注:本文中的Terraria.NPC.TargetClosest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。