Exemple #1
0
        private static void Setup(LoginFile script)
        {
            lsApi.Connected += (IEnumerable <Model.GameServer> gameServers) =>
            {
                Model.GameServer gameServer = gameServers
                                              .Single(gs => gs.Id == script.GameServer);

                if (gameServer != null)
                {
                    lsApi.SelectGameServer(gameServer);
                }
                else
                {
                    throw new KeyNotFoundException();
                }
            };

            lsApi.ServerSelected += (byte[] loginKey, byte[] gameKey) =>
            {
                string login    = script.Account.Login;
                int    protocol = script.LoginServer.Protocol;
                gsApi.Connect(lsApi.GameServer, login, loginKey, gameKey, protocol);
            };

            gsApi.Connected += (IEnumerable <Model.Player> characters) =>
            {
                int?number = null;
                foreach (var character in characters)
                {
                    if (character.Name == script.Character)
                    {
                        number = character.Number;
                    }
                }

                if (number.HasValue)
                {
                    gsApi.SelectCharacter(number.Value);
                }
                else
                {
                    throw new KeyNotFoundException();
                }
            };

            gsApi.ChatMessage += (Lineage.Channel channel, string message, string name, Model.Creature author) =>
            {
                var me = gsApi.World.Me;
                if (Global || channel == Lineage.Channel.Tell)
                {
                    if (name != me.Name && Access.Allow(name) && message.Trim().StartsWith("/"))
                    {
                        Command(message.Trim().Substring(1).ToLower(), name, author);
                    }
                }
            };

            gsApi.QuestionAsked += (Lineage.Question question, string name, string value) =>
            {
                if (Access.Allow(name))
                {
                    gsApi.QuestionReply(question, Lineage.Answer.Yes);
                }
            };

            gsApi.LoggedOut += () =>
            {
                Environment.Exit(0);
            };

            gsApi.EnterWorld += () =>
            {
                ConsoleThread.Start();
            };

            lsApi.Connect(script.LoginServer, script.Account);
        }