Example #1
0
        public void SetUp()
        {
            theLog = new InMemoryScriptLog();
            theGameState = new StubGameState();
            theGameServer = new StubGameServer(theGameState);
            theGameStream = new GameStream(theGameState);

            theServices = new InMemoryServiceLocator();
            theServices.Add<IGameServer>(theGameServer);
            theServices.Add<IGameState>(theGameState);
            theServices.Add<IScriptLog>(theLog);
            theServices.Add<IVariableReplacer>(new VariableReplacer());
            theServices.Add<ICommandProcessor>(new CommandProcessor(theServices, theServices.Get<IVariableReplacer>(), theLog));
            theServices.Add<IIfBlocksParser>(new IfBlocksParser());
            var waitFor = new WaitForTokenHandler(theGameState, theGameStream);
            var waitForRe = new WaitForReTokenHandler(theGameState, theGameStream);
            var matchWait = new MatchWaitTokenHandler(theGameState, theGameStream);
            theServices.Add<WaitForTokenHandler>(waitFor);
            theServices.Add<WaitForReTokenHandler>(waitForRe);
            theServices.Add<MatchWaitTokenHandler>(matchWait);
            theServices.Add<IIfBlockExecuter>(new IfBlockExecuter(waitFor, waitForRe, matchWait));
            theServices.Add<IGameStream>(theGameStream);

            theScript = new Script(theServices, Tokenizer.With(TokenDefinitionRegistry.Default()));
        }
 public WeakMatchingTokenHandler(IGameState gameState, IGameStream gameStream)
 {
     _gameState = gameState;
     _gameStream = gameStream;
     _listener = new GameStreamListener(tag => {
         Check(tag.Text);
     });
     _listener.Subscribe(_gameStream);
 }
        public void SetUp()
        {
            theGameState = new StubGameState();
            theGameServer = new StubGameServer(theGameState);
            theLogger = new InMemoryScriptLog();
            theGameStream = new GameStream(theGameState);

            theServices = new InMemoryServiceLocator();
            theServices.Add<IGameServer>(theGameServer);
            theServices.Add<IGameState>(theGameState);
            theServices.Add<IScriptLog>(theLogger);
            theServices.Add<IVariableReplacer>(new VariableReplacer());
            theServices.Add<ICommandProcessor>(new CommandProcessor(theServices, theServices.Get<IVariableReplacer>(), theLogger));
            theServices.Add<IGameStream>(theGameStream);

            theScriptContext = new ScriptContext("1", "sendcommand", CancellationToken.None,  theServices, null);
            theScriptContext.DebugLevel = 5;

            theHandler = new SendCommandTokenHandler();
        }
 public WaitForReTokenHandler(IGameState gameState, IGameStream gameStream)
     : base(gameState, gameStream)
 {
 }
        public void SetUp()
        {
            theGameState = new StubGameState();
            theGameServer = new StubGameServer(theGameState);

            theGameState.Set(ComponentKeys.Roundtime, "0");

            theLog = new InMemoryScriptLog();

            theReplacer = new VariableReplacer();
            theGameStream = new GameStream(theGameState);

            theServices = new InMemoryServiceLocator();
            theServices.Add<IGameServer>(theGameServer);
            theServices.Add<IGameState>(theGameState);
            theServices.Add<IScriptLog>(theLog);
            theServices.Add<IVariableReplacer>(theReplacer);
            theServices.Add<IIfBlockExecuter>(
                new IfBlockExecuter(
                    new WaitForTokenHandler(theGameState, theGameStream),
                    new WaitForReTokenHandler(theGameState, theGameStream),
                    new MatchWaitTokenHandler(theGameState, theGameStream)
                ));
            theServices.Add<IGameStream>(theGameStream);

            theCommandProcessor = new CommandProcessor(theServices, theReplacer, theLog);
            theServices.Add<ICommandProcessor>(theCommandProcessor);

            theLocalVars = new SimpleDictionary<string, string>();

            theScriptContext = new ScriptContext("1", "if", CancellationToken.None, theServices, theLocalVars);
            theScriptContext.DebugLevel = 5;

            theHandler = new IfTokenHandler();
        }
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            InitializeVitalsAndRTBars();

            Window.Title = "Outlander";

            _gameServer = _bootStrapper.Build();
            _services = _bootStrapper.ServiceLocator();

            var appSettings = _services.Get<AppSettings>();
            var homeDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Documents/Outlander");
            appSettings.HomeDirectory = homeDir;

            _services.Get<IAppDirectoriesBuilder>().Build();
            _services.Get<IAppSettingsLoader>().Load();

            UpdateImages();

            _commandProcessor = _services.Get<ICommandProcessor>();
            _scriptLog = _services.Get<IScriptLog>();
            _services.Get<IRoundtimeHandler>().Changed += (sender, e) => {
                SetRoundtime(e);
            };

            _highlightSettings = _services.Get<HighlightSettings>();
            _mainTextViewWrapper = new TextViewWrapper(MainTextView, _highlightSettings);

            _scriptLog.Info += (sender, e) => {
                string log;
                if(e.LineNumber > -1)
                {
                    log = "[{0}({1})]:  {2}\n".ToFormat(e.Name, e.LineNumber, e.Data);
                }
                else
                {
                    log = "[{0}]:  {1}\n".ToFormat(e.Name, e.Data);
                }

                BeginInvokeOnMainThread(()=> {

                    var hasLineFeed = MainTextView.TextStorage.Value.EndsWith("\n");

                    if(!hasLineFeed)
                        log = "\n" + log;

                    var tag = TextTag.For(log, "#0066CC");

                    _mainTextViewWrapper.Append(tag);
                });
            };

            _scriptLog.NotifyStarted += (sender, e) => {

                var log = "[{0}]: {1} - script started\n".ToFormat(e.Name, e.Started.ToString("G"));

                BeginInvokeOnMainThread(()=> {

                    var hasLineFeed = MainTextView.TextStorage.Value.EndsWith("\n");

                    if(!hasLineFeed)
                        log = "\n" + log;

                    var tag = TextTag.For(log, "ADFF2F");
                    _mainTextViewWrapper.Append(tag);
                });
            };

            _scriptLog.NotifyAborted += (sender, e) => {
                var log = "[{0}]: total runtime {1:hh\\:mm\\:ss} - {2} seconds\n".ToFormat(e.Name, e.Runtime, Math.Round(e.Runtime.TotalSeconds, 2));

                BeginInvokeOnMainThread(()=> {

                    var hasLineFeed = MainTextView.TextStorage.Value.EndsWith("\n");

                    if(!hasLineFeed)
                        log = "\n" + log;

                    var tag = TextTag.For(log, "ADFF2F");
                    _mainTextViewWrapper.Append(tag);
                });
            };

            var notifyLogger = new NotificationLogger();
            notifyLogger.OnError = (err) => {
                BeginInvokeOnMainThread(()=> {
                    LogSystem(err.Message + "\n\n");
                });
            };

            var compositeLogger = _services.Get<ILog>().As<CompositeLog>();
            compositeLogger.Add(notifyLogger);

            _gameServer.GameState.Tags = (tags) => {
                tags.Apply(t => {
                    t.As<AppTag>().IfNotNull(appInfo => {
                        BeginInvokeOnMainThread(() => {
                            Window.Title = string.Format("{0}: {1} - {2}", appInfo.Game, appInfo.Character, "Outlander");
                        });
                    });

                    t.As<StreamTag>().IfNotNull(streamTag => {
                        if(!string.IsNullOrWhiteSpace(streamTag.Id) && streamTag.Id.Equals("logons")) {

                            var text = "[{0}]{1}".ToFormat(DateTime.Now.ToString("HH:mm"), streamTag.Text);
                            var highlights = _services.Get<Highlights>().For(TextTag.For(text));

                            BeginInvokeOnMainThread(()=> {
                                highlights.Apply(h => {
                                    h.Mono = true;
                                    Append(h, ArrivalsTextView);
                                });
                            });
                        }

                        if(!string.IsNullOrWhiteSpace(streamTag.Id) && streamTag.Id.Equals("thoughts")) {

                            var text = "[{0}]: {1}".ToFormat(DateTime.Now.ToString("HH:mm"), streamTag.Text);
                            var highlights = _services.Get<Highlights>().For(TextTag.For(text));

                            BeginInvokeOnMainThread(()=> {
                                highlights.Apply(h => {
                                    Append(h, ThoughtsTextView);
                                });
                            });
                        }

                        if(!string.IsNullOrWhiteSpace(streamTag.Id) && streamTag.Id.Equals("death")) {

                            var text = "[{0}]{1}".ToFormat(DateTime.Now.ToString("HH:mm"), streamTag.Text);
                            var highlights = _services.Get<Highlights>().For(TextTag.For(text));

                            BeginInvokeOnMainThread(()=> {
                                highlights.Apply(h => {
                                    Append(h, DeathsTextView);
                                });
                            });
                        }
                    });

                    t.As<SpellTag>().IfNotNull(s => {
                        BeginInvokeOnMainThread(() => {
                            _spell = s.Spell;
                            _count = 0;
                            SpellLabel.StringValue = "S: {0}".ToFormat(s.Spell);

                            if(!string.Equals(_spell, "None"))
                            {
                                _gameServer.GameState.Set(ComponentKeys.SpellTime, "0");
                                _spellTimer.Start();
                            }
                            else
                            {
                                _spellTimer.Stop();
                                _gameServer.GameState.Set(ComponentKeys.SpellTime, "0");
                            }
                        });
                    });

                    t.As<VitalsTag>().IfNotNull(v => {
                        UpdateVitals();
                    });

                    var ids = new string[]
                    {
                        ComponentKeys.RoomTitle,
                        ComponentKeys.RoomDescription,
                        ComponentKeys.RoomObjects,
                        ComponentKeys.RoomPlayers,
                        ComponentKeys.RoomExists
                    };

                    t.As<ComponentTag>().IfNotNull(c => {
                        if(!ids.Contains(c.Id))
                            return;
                        var builder = new StringBuilder();
                        _gameServer.GameState.Get(ComponentKeys.RoomTitle).IfNotNullOrEmpty(s=>builder.AppendLine(s));
                        _gameServer.GameState.Get(ComponentKeys.RoomDescription).IfNotNullOrEmpty(s=>builder.AppendLine(s));
                        _gameServer.GameState.Get(ComponentKeys.RoomObjectsH).IfNotNullOrEmpty(s=>builder.AppendLine(s));
                        _gameServer.GameState.Get(ComponentKeys.RoomPlayers).IfNotNullOrEmpty(s=>builder.AppendLine(s));
                        _gameServer.GameState.Get(ComponentKeys.RoomExists).IfNotNullOrEmpty(s=>builder.AppendLine(s));

                        BeginInvokeOnMainThread(()=> {
                            LogRoom(builder.ToString(), RoomTextView);
                        });
                    });

                    BeginInvokeOnMainThread(()=> {
                        UpdateImages();

                        LeftHandLabel.StringValue = string.Format("L: {0}", _gameServer.GameState.Get(ComponentKeys.LeftHand));
                        RightHandLabel.StringValue = string.Format("R: {0}", _gameServer.GameState.Get(ComponentKeys.RightHand));
                    });

                    _services.Get<IAppSettingsLoader>().SaveVariables();
                });
            };

            _gameServer.GameState.Exp = (exp) => {

                _expTracker.Update(exp);

                var skills = _expTracker.SkillsWithExp().ToList();
                var tags = skills
                        .OrderBy(x => x.Name)
                        .Select(x =>
                        {
                            var color = x.IsNew ? _highlightSettings.Get(HighlightKeys.Whisper).Color : string.Empty;
                            return TextTag.For(x.Display() + "\n", color, true);
                        }).ToList();
                var now = DateTime.Now;
                tags.Add(TextTag.For("Last updated: {0:hh\\:mm\\:ss tt}\n".ToFormat(now), string.Empty, true));
                if(_expTracker.StartedTracking.HasValue)
                    tags.Add(TextTag.For("Tracking for: {0:hh\\:mm\\:ss}\n".ToFormat(now - _expTracker.StartedTracking.Value), string.Empty, true));

                BeginInvokeOnMainThread(()=> {
                    ReplaceText(tags, ExpTextView);
                });
            };

            _gameStream = _services.Get<IGameStream>();
            _gameStreamListener = new GameStreamListener(tag => {
                BeginInvokeOnMainThread(()=>{
                    if(tag.Filtered)
                        return;
                    Log(tag);
                });
            });
            _gameStreamListener.Subscribe(_gameStream);
        }
        public void SetUp()
        {
            theGameState = new StubGameState();
            theGameServer = new StubGameServer(theGameState);

            theVariableReplacer = new VariableReplacer();
            theGameStream = new GameStream(theGameState);

            theScriptLog = new InMemoryScriptLog();

            theRunner = new StubScriptRunner();
            theServices = new InMemoryServiceLocator();

            theServices.Add<IGameServer>(theGameServer);
            theServices.Add<IGameState>(theGameState);
            theServices.Add<IScriptRunner>(theRunner);
            theServices.Add<IVariableReplacer>(theVariableReplacer);
            theServices.Add<IGameStream>(theGameStream);

            theProcessor = new CommandProcessor(theServices, theVariableReplacer, theScriptLog);
        }
 public MatchWaitTokenHandler(IGameState gameState, IGameStream gameStream)
     : base(gameState, gameStream)
 {
 }