예제 #1
0
        private void SpawnNpc(ICommandSender sender, NpcId npcId, [Option("x")] int x, [Option("y")] int y, [Option("amount")] int amount)
        {
            if ((x <= 0 || y <= 0) && sender is ConsoleCommandSender)
            {
                sender.SendMessage("You must provide coordinates when spawning mobs via console: spawnmob <npc ID or name> -x <tile x> -y <tile y>");
                return;
            }

            if (npcId == NpcId.None)
            {
                sender.SendMessage("Invalid NPC.");
                return;
            }

            var playerSender = sender as PlayerCommandSender;

            x      = x <= 0 ? (int)playerSender.Player.Position.X / 16 : x;
            y      = y <= 0 ? (int)playerSender.Player.Position.Y / 16 : y;
            amount = Math.Max(1, amount);

            for (var i = 0; i < amount; ++i)
            {
                _server.Npcs.Spawn(npcId, new Vector2f(x * 16, y * 16));
            }

            sender.SendMessage($"You have spawned {amount} '{npcId.ToString().SplitPascalCase()}' NPC(s).");
        }
예제 #2
0
        public INpc?Spawn(NpcId id, Vector2f position)
        {
            Log.Debug("Spawning {NpcId} at {Position}", id, position);

            lock (_lock)
            {
                var npcIndex = Terraria.NPC.NewNPC((int)position.X, (int)position.Y, (int)id);
                return(npcIndex >= 0 && npcIndex < Count ? this[npcIndex] : null);
            }
        }
예제 #3
0
파일: BeanNpc.cs 프로젝트: linxscc/LoveGame
        public override int GetHashCode()
        {
            int hash = 1;

            if (NpcId != 0)
            {
                hash ^= NpcId.GetHashCode();
            }
            if (NpcName.Length != 0)
            {
                hash ^= NpcName.GetHashCode();
            }
            return(hash);
        }
예제 #4
0
        public void NpcSetDefaults_EventModified(NpcId oldId, NpcId newId)
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var npcService = new OrionNpcService(events, log);

            Mock.Get(events)
            .Setup(em => em.Raise(It.IsAny <NpcDefaultsEvent>(), log))
            .Callback <NpcDefaultsEvent, ILogger>((evt, log) => evt.Id = newId);

            Terraria.Main.npc[0].SetDefaults((int)oldId);

            Assert.Equal(newId, (NpcId)Terraria.Main.npc[0].netID);

            Mock.Get(events).VerifyAll();
        }
예제 #5
0
        public void NpcSetDefaults_EventTriggered(NpcId id)
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var npcService = new OrionNpcService(events, log);

            Mock.Get(events)
            .Setup(em => em.Raise(
                       It.Is <NpcDefaultsEvent>(evt => ((OrionNpc)evt.Npc).Wrapped == Terraria.Main.npc[0] && evt.Id == id),
                       log));

            Terraria.Main.npc[0].SetDefaults((int)id);

            Assert.Equal(id, (NpcId)Terraria.Main.npc[0].netID);

            Mock.Get(events).VerifyAll();
        }
예제 #6
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (UserId != 0)
            {
                hash ^= UserId.GetHashCode();
            }
            if (SceneId != 0)
            {
                hash ^= SceneId.GetHashCode();
            }
            if (NpcId != 0)
            {
                hash ^= NpcId.GetHashCode();
            }
            hash ^= selectIds_.GetHashCode();
            if (ReadState != 0)
            {
                hash ^= ReadState.GetHashCode();
            }
            if (CreateTime != 0L)
            {
                hash ^= CreateTime.GetHashCode();
            }
            hash ^= listenIds_.GetHashCode();
            if (FinishTime != 0L)
            {
                hash ^= FinishTime.GetHashCode();
            }
            if (TipState != 0)
            {
                hash ^= TipState.GetHashCode();
            }
            return(hash);
        }
예제 #7
0
 public NpcTextEvent(NpcId npcId, byte textId)
 {
     TextId = textId;
     NpcId  = npcId;
 }
예제 #8
0
 public StartDialogueEvent(NpcId npcId) => NpcId = npcId;
예제 #9
0
 public ContextTextEvent(byte textId, TextLocation?location, NpcId npcId)
 {
     TextId   = textId;
     Location = location;
     NpcId    = npcId;
 }
예제 #10
0
 public NpcEnteredTileEvent(NpcId id, int x, int y)
 {
     Id = id;
     X  = x;
     Y  = y;
 }
예제 #11
0
 /// <summary>
 /// Returns a value indicating whether the NPC <paramref name="id"/> is catchable.
 /// </summary>
 /// <param name="id">The NPC ID.</param>
 /// <returns>
 /// <see langword="true"/> if the NPC <paramref name="id"/> is catchable; otherwise, <see langword="false"/>.
 /// </returns>
 public static bool IsCatchable(this NpcId id) => _catchables.Contains(id);
예제 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NpcFishEvent"/> class with the specified
 /// <paramref name="player"/>, NPC <paramref name="position"/>, and NPC <paramref name="id"/>.
 /// </summary>
 /// <param name="player">The player fishing the NPC.</param>
 /// <param name="position">The fished NPC's position.</param>
 /// <param name="id">The NPC ID being fished.</param>
 /// <exception cref="ArgumentNullException"><paramref name="player"/> is <see langword="null"/>.</exception>
 public NpcFishEvent(IPlayer player, Vector2f position, NpcId id) : base(player)
 {
     Position = position;
     Id       = id;
 }