Ejemplo n.º 1
0
        public void Install(TerrariaClient client)
        {
            _client = client;

            client.Connected += (s, e) => Console.WriteLine("Connected.");
            client.Disconnected += (s, e) => Console.WriteLine($"Disconnected: {e.Reason}");
            client.LoggedIn += (s, e) =>
            {
                Console.WriteLine("Logged in.");

                /* 
                   IMPORTANT : 
                   If your client is a command bot I recommend killing it on login.
                   This way it shouldn't interfere with monster ai and spawns.
                */

                _client.CurrentPlayer.Killme();
            };
            client.StatusReceived += (s, e) => Console.WriteLine($"Status: {e.Status.Text}");
            client.MessageReceived += (s, e) =>
            {
                Console.WriteLine($"<{client.GetExistingPlayer(e.Message.PlayerId).Appearance.Name}> {e.Message.Text}");

                if (e.Sender != MessageReceivedEventArgs.SenderType.Player) return;

                try
                {
                    // quick command hack thingy
                    string[] words = e.Message.Text.Split(' ');
                    switch (words[0])
                    {
                        case "!itemid": // !itemid <id> <amnt>
                            GiveItem(e.Player, new GameItem(short.Parse(words[1]), short.Parse(words[2])));
                            break;
                        case "!itemname": //!itemname <amnt> <name>
                            string name = string.Join(" ", words, 2, words.Length - 2);
                            GiveItem(e.Player, new GameItem(IdLookup.GetItem(name), short.Parse(words[1])));
                            break;
                        case "!goto": // !goto <username>
                            string query = string.Join(" ", words, 1, words.Length - 1).ToLowerInvariant();
                            Player target =
                                _client.Players.FirstOrDefault(
                                    p => p.Appearance.Name.ToLowerInvariant() == query);
                            _client.CurrentPlayer.SetPos(target.Position);
                            break;
                        case "!spawnboss": // !spawn <id>
                            short id = short.Parse(words[1]);
                            _client.Send(TerrPacketType.SpawnBossInvsaion,
                                new SpawnBossOrInvasion(_client.CurrentPlayer.PlayerId.Value, id));
                            break;
                    }
                }
                catch (Exception)
                {
                }
            };
        }
Ejemplo n.º 2
0
        private static void Main()
        {
            dynamic config = JObject.Parse(File.ReadAllText("config.json"));
            if (config == null) throw new InvalidOperationException("Failed parsing config.json");

            TerrariaClient client = new TerrariaClient(cfg =>
            {
                cfg.Player(player =>
                {
                    player.Health(400);
                    player.Appearance(appear =>
                    {
                        appear.Name("Bot Client");
                    });
                    player.Inventory(inv =>
                    {
                        inv.AddAccessory(ItemId.PutridScent);

                        inv.SetHelmet(ItemId.DTownsHelmet);
                        inv.SetChestplate(ItemId.DTownsBreastplate);
                        inv.SetLeggings(ItemId.DTownsLeggings);
                    });
                });
            });

            Task.Run(async () =>
            {
                client.Log.MessageReceived += (s, e) => StrmyCore.Logger.FormattedWrite(e.Severity.ToString(), e.Message, _colors[e.Severity]);
                client.Services.Add<BasicService>();

                await client.ConnectAndLogin((string) config.Host, (int) config.Port);
            });

            client.Wait();

            Console.WriteLine("\r\nPress any key to continue...");
            Console.ReadLine();
        }
Ejemplo n.º 3
0
 public PlayerEventArgs(byte pid, TerrariaClient client)
 {
     PlayerId = pid;
     Player = client.GetExistingPlayer(pid);
 }
Ejemplo n.º 4
0
 internal Player(byte pid, TerrariaClient client)
 {
     PlayerId = pid;
     Client = client;
 }
Ejemplo n.º 5
0
 public static TerrPacket Parse(byte[] data, TerrariaClient client)
 {
     ushort packetSize = GetSize(data);
     return Parse(data, packetSize, packetSize, client.Log);
 }
Ejemplo n.º 6
0
 public static TerrPacket Parse(byte[] data, int length, TerrariaClient client) => Parse(data, length, GetSize(data), client.Log);