Наследование: Terraria.ModLoader.ModNPC
Пример #1
0
        private bool?CanBeHitByPlayer(Player player)
        {
            NPC          owner    = Main.npc[(int)npc.ai[0]];
            PuritySpirit modOwner = owner.modNPC == null ? null : owner.modNPC as PuritySpirit;

            if (modOwner != null && !modOwner.targets.Contains(player.whoAmI))
            {
                return(false);
            }
            return(null);
        }
Пример #2
0
        public override void AI()
        {
            NPC owner = Main.npc[(int)npc.ai[0]];

            if (!owner.active || owner.type != NPCType <PuritySpirit>())
            {
                npc.active = false;
                return;
            }
            PuritySpirit modOwner = (PuritySpirit)owner.modNPC;

            if (npc.localAI[0] == 0f)
            {
                if (modOwner.targets.Contains(Main.myPlayer))
                {
                    Main.PlaySound(SoundID.Item2);
                }
                else
                {
                    Main.PlaySound(SoundID.Item2, npc.position);
                }
                npc.localAI[0] = 1f;
            }
            Vector2 targetPos = new Vector2(npc.ai[1], npc.ai[2]);
            Vector2 direction = targetPos - npc.Center;

            if (direction != Vector2.Zero)
            {
                float speed = direction.Length();
                if (speed > 2f)
                {
                    speed = 2f;
                }
                direction.Normalize();
                direction    *= speed;
                npc.position += direction;
            }
            else
            {
                npc.localAI[1] = 1f;
            }
        }