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


C# NPC.StrikeNPC方法代碼示例

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


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

示例1: AIFriendly

        // 7 - 1.1.2
        private void AIFriendly(NPC npc, bool flag, Func<Int32, Int32, ITile> TileRefs)
        {
            if (npc.type == NPCType.N142_SANTA_CLAUS && !Main.Xmas)
            {
                npc.StrikeNPC(World.Sender, 9999, 0f, 0);
                NetMessage.SendData(28, -1, -1, "", npc.whoAmI, 9999f, 0f, 0f, 0);
            }
            int num129 = (int)(npc.Position.X + (float)(npc.Width / 2)) / 16;
            int num130 = (int)(npc.Position.Y + (float)npc.Height + 1f) / 16;

            if (num129 < 0 || num129 > Main.maxTilesX)
                return;
            else if (num130 < 0 || num130 > Main.maxTilesY)
                return;

            if (npc.type == NPCType.N107_GOBLIN_TINKERER)
            {
                savedGoblin = true;
            }
            if (npc.type == NPCType.N108_WIZARD)
            {
                savedWizard = true;
            }
            if (npc.type == NPCType.N124_MECHANIC)
            {
                savedMech = true;
            }
            if (npc.type == NPCType.N46_BUNNY && npc.target == 255)
            {
                npc.TargetClosest(true);
            }
            bool flag15 = false;
            npc.directionY = -1;
            if (npc.direction == 0)
            {
                npc.direction = 1;
            }
            for (int num131 = 0; num131 < Main.MAX_PLAYERS; num131++)
            {
                if (Main.players[num131].Active && Main.players[num131].talkNPC == npc.whoAmI)
                {
                    flag15 = true;
                    if (npc.ai[0] != 0f)
                    {
                        npc.netUpdate = true;
                    }
                    npc.ai[0] = 0f;
                    npc.ai[1] = 300f;
                    npc.ai[2] = 100f;
                    if (Main.players[num131].Position.X + (float)(Main.players[num131].Width / 2) < npc.Position.X + (float)(npc.Width / 2))
                    {
                        npc.direction = -1;
                    }
                    else
                    {
                        npc.direction = 1;
                    }
                }
            }
            if (npc.ai[3] > 0f)
            {
                npc.life = -1;
                npc.HitEffect(0, 10.0);
                npc.Active = false;
            }
            if (npc.type == NPCType.N37_OLD_MAN)
            {
                npc.homeless = false;
                npc.homeTileX = Main.dungeonX;
                npc.homeTileY = Main.dungeonY;
                if (downedBoss3)
                {
                    npc.ai[3] = 1f;
                    npc.netUpdate = true;
                }
            }
            int num132 = npc.homeTileY;
            if (npc.homeTileY > 0)
            {
                while (!WorldModify.SolidTile(TileRefs, npc.homeTileX, num132) && num132 < Main.maxTilesY - 20)
                {
                    num132++;
                }
            }
            var type = (int)Main.tile.At(num129, num130).Type;
            if (npc.townNPC && (!Main.dayTime || Main.tileDungeon[type]) && (num129 != npc.homeTileX || num130 != num132) && !npc.homeless)
            {
                bool flag16 = true;
                for (int num133 = 0; num133 < 2; num133++)
                {
                    Rectangle rectangle3 = new Rectangle((int)(npc.Position.X + (float)(npc.Width / 2) - (float)(sWidth / 2) - (float)safeRangeX), (int)(npc.Position.Y + (float)(npc.Height / 2) - (float)(sHeight / 2) - (float)safeRangeY), sWidth + safeRangeX * 2, sHeight + safeRangeY * 2);
                    if (num133 == 1)
                    {
                        rectangle3 = new Rectangle(npc.homeTileX * 16 + 8 - sWidth / 2 - safeRangeX, num132 * 16 + 8 - sHeight / 2 - safeRangeY, sWidth + safeRangeX * 2, sHeight + safeRangeY * 2);
                    }
                    for (int num134 = 0; num134 < 255; num134++)
                    {
                        if (Main.players[num134].Active)
                        {
//.........這裏部分代碼省略.........
開發者ID:jason14747,項目名稱:Terraria-s-Dedicated-Server-Mod,代碼行數:101,代碼來源:NPC.cs

示例2: AISphere

        // 9 - 1.1.2
        private void AISphere(NPC npc, bool flag, Func<Int32, Int32, ITile> TileRefs)
        {
            if (npc.target == 255)
            {
                npc.TargetClosest(true);
                float num157 = 6f;
                if (npc.type == NPCType.N25_BURNING_SPHERE)
                {
                    num157 = 5f;
                }
                if (npc.type == NPCType.N112_VILE_SPIT)
                {
                    num157 = 7f;
                }
                Vector2 vector15 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                float num158 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - vector15.X;
                float num159 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - vector15.Y;
                float num160 = (float)Math.Sqrt((double)(num158 * num158 + num159 * num159));
                num160 = num157 / num160;
                npc.Velocity.X = num158 * num160;
                npc.Velocity.Y = num159 * num160;
            }
            if (npc.type == NPCType.N112_VILE_SPIT)
            {
                npc.ai[0] += 1f;
                if (npc.ai[0] > 3f)
                {
                    npc.ai[0] = 3f;
                }
                if (npc.ai[0] == 2f)
                {
                    npc.Position += npc.Velocity;
                }
            }
            if (npc.type == NPCType.N112_VILE_SPIT && Collision.SolidCollision(npc.Position, npc.Width, npc.Height))
            {
                int num163 = (int)(npc.Position.X + (float)(npc.Width / 2)) / 16;
                int num164 = (int)(npc.Position.Y + (float)(npc.Height / 2)) / 16;
                int num165 = 8;
                for (int num166 = num163 - num165; num166 <= num163 + num165; num166++)
                {
                    for (int num167 = num164 - num165; num167 < num164 + num165; num167++)
                    {
                        if ((double)(Math.Abs(num166 - num163) + Math.Abs(num167 - num164)) < (double)num165 * 0.5)
                        {
                            if (Main.tile.At(num166, num167).Type == 2)
                            {
                                Main.tile.At(num166, num167).SetType(23);
                                WorldModify.SquareTileFrame(TileRefs, null, num166, num167, true);
                                NetMessage.SendTileSquare(-1, num166, num167, 1);
                            }
                            else if (Main.tile.At(num166, num167).Type == 1)
                            {
                                Main.tile.At(num166, num167).SetType(25);
                                WorldModify.SquareTileFrame(TileRefs, null, num166, num167, true);
                                NetMessage.SendTileSquare(-1, num166, num167, 1);
                            }
                            else if (Main.tile.At(num166, num167).Type == 53)
                            {
                                Main.tile.At(num166, num167).SetType(112);
                                WorldModify.SquareTileFrame(TileRefs, null, num166, num167, true);
                                NetMessage.SendTileSquare(-1, num166, num167, 1);
                            }
                            else if (Main.tile.At(num166, num167).Type == 109)
                            {
                                Main.tile.At(num166, num167).SetType(23);
                                WorldModify.SquareTileFrame(TileRefs, null, num166, num167, true);
                                NetMessage.SendTileSquare(-1, num166, num167, 1);
                            }
                            else if (Main.tile.At(num166, num167).Type == 117)
                            {
                                Main.tile.At(num166, num167).SetType(25);
                                WorldModify.SquareTileFrame(TileRefs, null, num166, num167, true);
                                NetMessage.SendTileSquare(-1, num166, num167, 1);
                            }
                            else if (Main.tile.At(num166, num167).Type == 116)
                            {
                                Main.tile.At(num166, num167).SetType(112);
                                WorldModify.SquareTileFrame(TileRefs, null, num166, num167, true);
                                NetMessage.SendTileSquare(-1, num166, num167, 1);
                            }
                        }
                    }
                }
                npc.StrikeNPC(World.Sender, 999, 0f, 0, false);
            }
            if (npc.timeLeft > 100)
            {
                npc.timeLeft = 100;
            }

            npc.rotation += 0.4f * (float)npc.direction;
            return;
        }
開發者ID:jason14747,項目名稱:Terraria-s-Dedicated-Server-Mod,代碼行數:95,代碼來源:NPC.cs


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