public AutoSplitSettingsRow(AutoSplit autosplit)
        {
            InitializeComponent();

            AutoSplit = autosplit;

            txtName.Text = autosplit.Name;

            cmbType.Items.Add(new Item(LABEL_CHAR_LEVEL, (int)AutoSplit.SplitType.CharLevel));
            cmbType.Items.Add(new Item(LABEL_AREA, (int)AutoSplit.SplitType.Area));
            cmbType.Items.Add(new Item(LABEL_ITEM, (int)AutoSplit.SplitType.Item));
            cmbType.Items.Add(new Item(LABEL_QUEST, (int)AutoSplit.SplitType.Quest));
            cmbType.Items.Add(new Item(LABEL_SPECIAL, (int)AutoSplit.SplitType.Special));
            cmbType.SelectedIndex = (int)autosplit.Type;

            FillComboBoxes();

            cmbDifficulty.SelectedIndex = autosplit.Difficulty;

            var i = 0;

            foreach (Item item in cmbValue.Items)
            {
                if (item.Value == autosplit.Value)
                {
                    cmbValue.SelectedIndex = i;
                    break;
                }
                i++;
            }
        }
示例#2
0
        private static bool IsCompleteableAutosplit(AutoSplit autoSplit, QuestCollection currentQuests, DataReadEventArgs eventArgs, GameDifficulty difficulty)
        {
            if (autoSplit.IsReached || !autoSplit.MatchesDifficulty(difficulty))
            {
                return(false);
            }

            switch (autoSplit.Type)
            {
            case AutoSplit.SplitType.CharLevel:
                return(autoSplit.Value <= eventArgs.Character.Level);

            case AutoSplit.SplitType.Area:
                return(autoSplit.Value == eventArgs.CurrentArea);

            case AutoSplit.SplitType.Item:
                return(eventArgs.ItemIds.Contains(autoSplit.Value));

            case AutoSplit.SplitType.Quest:
                return(currentQuests != null && currentQuests.IsQuestCompleted((QuestId)autoSplit.Value));

            case AutoSplit.SplitType.Gems:
                return(eventArgs.ItemIds.Contains(autoSplit.Value));
            }
            return(false);
        }
示例#3
0
        public AutoSplitEditor(AutoSplitEnv env, AutoSplit source = null)
        {
            InitializeComponent();

            MaximumSize               = new Size(Size.Width, Screen.AllScreens.Max(s => s.WorkingArea.Height));
            btnAdd.Text               = btnRemove.Text = string.Empty;
            btnAdd.BackgroundImage    = Resources.Add;
            btnRemove.BackgroundImage = Resources.Remove;
            foreach (var btn in tlpListBtn.Controls.OfType <Button>())
            {
                btn.FlatAppearance.MouseOverBackColor = Color.LightGray;
                btn.FlatAppearance.MouseDownBackColor = SystemColors.ControlLight;
            }
            lstVariables.Height = 0;             //hack to fix the control not filling its parent properly

            _env            = env;
            EditedAutoSplit = source?.Clone(_env) ?? new AutoSplit();

            txtName.DataBindings.Add("Text", EditedAutoSplit, "Name");
            RefreshEvents();
            cbEvent.DataBindings.Add("SelectedItem", EditedAutoSplit, "Event");
            lstVariables.Format       += (s, e) => e.Value = $"{((Variable)e.ListItem).ToString(_env)}";
            lstVariables.DataSource    = new BindingList <Variable>(EditedAutoSplit.Variables);
            lstVariables.SelectedIndex = -1;
#if DEBUG
            label2.Visible = cbEvent.Visible = true;
#endif
        }
        public void SetAutosplit(AutoSplit autosplit)
        {
            updating              = true;
            txtName.Text          = autosplit.Name;
            cmbType.SelectedIndex = (int)autosplit.Type;

            if (this.AutoSplit == null || autosplit.Type != this.AutoSplit.Type)
            {
                FillComboBoxes(autosplit);
            }

            cmbDifficulty.SelectedIndex = autosplit.Difficulty;

            var i = 0;

            foreach (Item item in cmbValue.Items)
            {
                if (item.Value == autosplit.Value)
                {
                    cmbValue.SelectedIndex = i;
                    break;
                }
                i++;
            }
            this.AutoSplit = autosplit;
            updating       = false;
        }
示例#5
0
        IEnumerable <GameEvent> GetAvailableEvents(AutoSplit split)
        {
            var events = split.Variables.GetRestrictedEvents() != null
                                ? _env.Events.Intersect(split.Variables.GetRestrictedEvents()).ToArray()
                                : _env.Events;

            return(events.OrderBy(e => e).ToArray());
        }
 public void StartAutoSplit()
 {
     if (!string.IsNullOrEmpty(AutoSplitPath) && File.Exists(AutoSplitPath))
     {
         AutoSplit?.Close();
         AutoSplit = new AutoSplitProcess(this);
     }
 }
        public void ShouldNotSplitIfDisabled()
        {
            var split = new AutoSplit(
                "one",
                AutoSplit.SplitType.CharLevel,
                10,
                (short)GameDifficulty.Normal
                );
            var appSettings = new ApplicationSettings();

            appSettings.DoAutosplit = false;
            appSettings.Autosplits.Add(split);
            var settingsServiceMock = new Mock <ISettingsService>();

            settingsServiceMock.SetupGet(x => x.CurrentSettings).Returns(appSettings);
            var gameService = new GameServiceMock();
            AutoSplitService autoSplitService = new AutoSplitService(
                settingsServiceMock.Object,
                gameService,
                new Mock <KeyService>().Object
                );
            var quests = new Quests(new List <List <Quest> >
            {
                new List <Quest>(), // NORMAL
                new List <Quest>(), // NM
                new List <Quest>(), // HELL
            });

            var characterMock = new Mock <Character>();

            characterMock.SetupGet(x => x.Level).Returns(9);
            characterMock.SetupGet(x => x.IsAutosplitChar).Returns(true);
            characterMock.SetupGet(x => x.EquippedItemStrings).Returns(new Dictionary <BodyLocation, string>());
            characterMock.SetupGet(x => x.InventoryItemIds).Returns(new List <int>());

            var game = new Game();

            game.Area       = 0;
            game.Difficulty = GameDifficulty.Normal;
            game.PlayersX   = 1;
            game.GameCount  = 0;
            game.CharCount  = 0;

            var args = new DataReadEventArgs(
                characterMock.Object,
                game,
                quests
                );

            // test autosplit by level
            gameService.triggerDataRead(null, args);
            Assert.AreEqual(false, split.IsReached);

            characterMock.SetupGet(x => x.Level).Returns(10);
            gameService.triggerDataRead(null, args);
            Assert.AreEqual(false, split.IsReached);
        }
示例#8
0
            public AutosplitBinding(AutoSplit autoSplit, Action <AutoSplit> reachedHandler, Action <AutoSplit> resetHandler)
            {
                this.autoSplit      = autoSplit;
                this.reachedHandler = reachedHandler;
                this.resetHandler   = resetHandler;

                this.autoSplit.Reached += reachedHandler;
                this.autoSplit.Reset   += resetHandler;
            }
示例#9
0
 public static AutoSplit ShowEditor(AutoSplitEnv env, AutoSplit source = null)
 {
     using (var form = new AutoSplitEditor(env, source))
     {
         return(form.ShowDialog() != DialogResult.Cancel
                                 ? form.EditedAutoSplit
                                 : source);
     }
 }
        private void State_OnSplit(object sender, EventArgs e)
        {
            if (IgnoreNextSplit)
            {
                IgnoreNextSplit = false;
                return;
            }

            AutoSplit.Send("split");
        }
        private void State_OnReset(object sender, TimerPhase e)
        {
            if (IgnoreNextReset)
            {
                IgnoreNextReset = false;
                return;
            }

            AutoSplit.Send("reset");
            Settings.OnReset();
        }
        void CompleteAutoSplit(AutoSplit autosplit)
        {
            // Autosplit already reached.
            if (autosplit.IsReached)
            {
                return;
            }

            autosplit.IsReached = true;
            TriggerAutosplit();

            var autoSplitIndex = settingsService.CurrentSettings.Autosplits.IndexOf(autosplit);

            Logger.Info($"AutoSplit: #{autoSplitIndex} ({autosplit.Name}, {autosplit.Difficulty}) Reached.");
        }
        private void State_OnStart(object sender, EventArgs e)
        {
            if (IgnoreNextStart)
            {
                IgnoreNextStart = false;
                return;
            }

            AutoSplit.Send("start");
            if (GameTimePausing)
            {
                Timer.InitializeGameTime();
            }

            Settings.OnStart();
        }
示例#14
0
        private void AddAutoSplit(AutoSplit autosplit)
        {
            if (autosplit == null)
            {
                return;
            }

            // Operate on a copy.
            autosplit = new AutoSplit(autosplit);

            // Create and show the autosplit row.
            AutoSplitSettingsRow row = new AutoSplitSettingsRow(autosplit);

            row.OnDelete += (item) => autoSplitTable.Controls.Remove(row);
            autoSplitTable.Controls.Add(row);
            autoSplitTable.ScrollControlIntoView(row);
        }
        public AutoSplitSettingsRow(AutoSplit autosplit)
        {
            updating = false;
            InitializeComponent();

            cmbType.Items.Add(new Item(LABEL_CHAR_LEVEL, (int)AutoSplit.SplitType.CharLevel));
            cmbType.Items.Add(new Item(LABEL_AREA, (int)AutoSplit.SplitType.Area));
            cmbType.Items.Add(new Item(LABEL_ITEM, (int)AutoSplit.SplitType.Item));
            cmbType.Items.Add(new Item(LABEL_QUEST, (int)AutoSplit.SplitType.Quest));
            cmbType.Items.Add(new Item(LABEL_SPECIAL, (int)AutoSplit.SplitType.Special));
            cmbType.Items.Add(new Item(LABEL_GEMS, (int)AutoSplit.SplitType.Gems));

            cmbDifficulty.Items.Clear();
            cmbDifficulty.Items.Add(new Item(LABEL_NORMAL, 0));
            cmbDifficulty.Items.Add(new Item(LABEL_NIGHTMARE, 1));
            cmbDifficulty.Items.Add(new Item(LABEL_HELL, 2));

            SetAutosplit(autosplit);
        }
示例#16
0
        private bool IsCompleteableAutoSplit(AutoSplit split, DataReadEventArgs args)
        {
            if (split.IsReached || !split.MatchesDifficulty(args.Game.Difficulty))
            {
                return(false);
            }

            switch (split.Type)
            {
            case AutoSplit.SplitType.Special:
                switch (split.Value)
                {
                case (int)AutoSplit.Special.GameStart:
                    return(true);

                case (int)AutoSplit.Special.Clear100Percent:
                    return(args.Quests.DifficultyFullyCompleted(args.Game.Difficulty));

                case (int)AutoSplit.Special.Clear100PercentAllDifficulties:
                    return(args.Quests.FullyCompleted());

                default:
                    return(false);
                }

            case AutoSplit.SplitType.Quest:
                return(args.Quests.QuestCompleted(args.Game.Difficulty, (QuestId)split.Value));

            case AutoSplit.SplitType.CharLevel:
                return(split.Value <= args.Character.Level);

            case AutoSplit.SplitType.Area:
                return(split.Value == args.Game.Area);

            case AutoSplit.SplitType.Item:
            case AutoSplit.SplitType.Gems:
                return(args.Character.InventoryItemIds.Contains(split.Value));

            default:
                return(false);
            }
        }
示例#17
0
        public Control AddAutoSplit(AutoSplit autosplit)
        {
            if (autosplit == null)
            {
                return(null);
            }

            // Operate on a copy.
            autosplit = new AutoSplit(autosplit);

            // Create and show the autosplit row.
            AutoSplitSettingsRow row = new AutoSplitSettingsRow(autosplit);

            Controls.Add(row);
            rows.Add(row);
            row.OnDelete += (item) =>
            {
                Controls.Remove(row);
                rows.Remove(row);
            };
            return(row);
        }
        private void FillComboBoxes(AutoSplit autosplit)
        {
            if (autosplit.IsDifficultyIgnored())
            {
                cmbDifficulty.Hide();
            }
            else
            {
                cmbDifficulty.Show();
                cmbDifficulty.SelectedIndex = autosplit.Difficulty;
            }

            cmbValue.Items.Clear();
            switch (autosplit.Type)
            {
            case AutoSplit.SplitType.CharLevel:
                for (int i = 1; i < 100; i++)
                {
                    cmbValue.Items.Add(new Item("" + i, i));
                }
                break;

            case AutoSplit.SplitType.Area:
                foreach (Area area in Area.getAreaList())
                {
                    if (area.Id > 0)
                    {
                        cmbValue.Items.Add(new Item(area.ToString(), area.Id));
                    }
                }
                break;

            case AutoSplit.SplitType.Item:
                cmbValue.Items.Add(new Item(LABEL_HORADRIC_CUBE, (int)D2Data.ItemId.HORADRIC_CUBE));
                cmbValue.Items.Add(new Item(LABEL_HORADRIC_SHAFT, (int)D2Data.ItemId.HORADRIC_SHAFT));
                cmbValue.Items.Add(new Item(LABEL_HORADRIC_AMULET, (int)D2Data.ItemId.HORADRIC_AMULET));
                cmbValue.Items.Add(new Item(LABEL_KHALIMS_EYE, (int)D2Data.ItemId.KHALIM_EYE));
                cmbValue.Items.Add(new Item(LABEL_KHALIMS_HEART, (int)D2Data.ItemId.KHALIM_HEART));
                cmbValue.Items.Add(new Item(LABEL_KHALIMS_BRAIN, (int)D2Data.ItemId.KHALIM_BRAIN));
                break;

            case AutoSplit.SplitType.Quest:
                foreach (QuestId questId in Enum.GetValues(typeof(QuestId)))
                {
                    var quest = QuestFactory.Create(questId, 0);
                    var name  = (quest.IsBossQuest ? "" : $"Act {quest.Act} - ") + quest.CommonName;

                    cmbValue.Items.Add(new Item(name, (int)questId));
                }
                break;

            case AutoSplit.SplitType.Special:
                cmbValue.Items.Add(new Item(LABEL_GAME_START, (int)AutoSplit.Special.GameStart));
                cmbValue.Items.Add(new Item(LABEL_CLEAR_100_PERCENT, (int)AutoSplit.Special.Clear100Percent));
                cmbValue.Items.Add(new Item(LABEL_CLEAR_100_PERCENT_ALL, (int)AutoSplit.Special.Clear100PercentAllDifficulties));
                break;

            case AutoSplit.SplitType.Gems:
                foreach (Gem gem in Enum.GetValues(typeof(Gem)))
                {
                    var name = Regex.Replace(gem.ToString(), @"(\B[A-Z])", " $1");
                    cmbValue.Items.Add(new Item(name, (int)gem));
                }

                break;
            }
        }
 private void State_OnUndoSplit(object sender, EventArgs e) => AutoSplit.Send("undo");
示例#20
0
        public void ShouldReachAutosplits()
        {
            var splitOnGameStart = new AutoSplit(
                "game start",
                AutoSplit.SplitType.Special,
                1,
                (short)GameDifficulty.Normal
                );
            var splitOnGameClear = new AutoSplit(
                "100% done",
                AutoSplit.SplitType.Special,
                2,
                (short)GameDifficulty.Normal
                );
            var splitOnGameClearAllDifficulties = new AutoSplit(
                "100% done all difficulties",
                AutoSplit.SplitType.Special,
                3,
                (short)GameDifficulty.Normal
                );
            var splitOnCharLevel10 = new AutoSplit(
                "char level 10",
                AutoSplit.SplitType.CharLevel,
                10,
                (short)GameDifficulty.Normal
                );
            var splitOnArea1 = new AutoSplit(
                "area 1",
                AutoSplit.SplitType.Area,
                (int)Area.ROGUE_ENCAMPMENT,
                (short)GameDifficulty.Normal
                );
            var splitOnItem1 = new AutoSplit(
                "item 1",
                AutoSplit.SplitType.Item,
                1,
                (short)GameDifficulty.Normal
                );
            var splitOnGem1 = new AutoSplit(
                "gem 1",
                AutoSplit.SplitType.Gems,
                1,
                (short)GameDifficulty.Normal
                );
            var splitOnQuest81 = new AutoSplit(
                "quest 81 (den of evil)",
                AutoSplit.SplitType.Quest,
                81,
                (short)GameDifficulty.Normal
                );

            var cfg = new Config();

            cfg.Enabled = true;
            cfg.Splits  = new List <AutoSplit>();
            cfg.Splits.Add(splitOnGameStart);
            cfg.Splits.Add(splitOnGameClear);
            cfg.Splits.Add(splitOnGameClearAllDifficulties);
            cfg.Splits.Add(splitOnCharLevel10);
            cfg.Splits.Add(splitOnArea1);
            cfg.Splits.Add(splitOnItem1);
            cfg.Splits.Add(splitOnGem1);
            cfg.Splits.Add(splitOnQuest81);

            var config = new Mock <ApplicationConfig>();

            config.Setup(x => x.PluginConf(It.IsAny <string>())).Returns(cfg);
            var configService = new Mock <IConfigService>();

            configService.SetupGet(x => x.CurrentConfig).Returns(config.Object);

            var gameService = new Mock <IGameService>();

            var diabloInterface = new Mock <IDiabloInterface>();

            diabloInterface.Setup(x => x.configService).Returns(configService.Object);
            diabloInterface.Setup(x => x.game).Returns(gameService.Object);

            var autoSplitService = new Plugin();

            autoSplitService.Initialize(diabloInterface.Object);

            var normalQuests = new List <Quest>()
            {
                QuestFactory.Create(QuestId.DenOfEvil, 0),
                QuestFactory.Create(QuestId.Andariel, 0),
            };

            var nightmareQuests = new List <Quest>()
            {
                QuestFactory.Create(QuestId.DenOfEvil, 0),
                QuestFactory.Create(QuestId.Andariel, 0),
            };

            var hellQuests = new List <Quest>()
            {
                QuestFactory.Create(QuestId.DenOfEvil, 0),
                QuestFactory.Create(QuestId.Andariel, 0),
            };

            var quests = new Quests(new List <List <Quest> >
            {
                normalQuests,
                nightmareQuests,
                hellQuests,
            });

            var itemStrings = new Dictionary <BodyLocation, string>();
            var itemsIds    = new List <int>();

            var characterMock = new Mock <Character>();

            characterMock.SetupGet(x => x.Level).Returns(9);
            characterMock.SetupGet(x => x.IsNewChar).Returns(true);
            characterMock.SetupGet(x => x.InventoryItemIds).Returns(itemsIds);

            var processInfo = new ProcessInfo();

            var game = new Game();

            game.Area       = 0;
            game.Difficulty = GameDifficulty.Normal;
            game.PlayersX   = 1;
            game.GameCount  = 0;
            game.CharCount  = 0;
            game.Character  = characterMock.Object;
            game.Quests     = quests;

            List <Monster> killedMonsters = null;
            var            args           = new DataReadEventArgs(processInfo, game, killedMonsters);

            // test autosplit by game start
            Assert.AreEqual(false, splitOnGameStart.IsReached);
            gameService.Raise(g => g.DataRead += null, args);
            Assert.AreEqual(true, splitOnGameStart.IsReached);

            // test autosplit by level
            Assert.AreEqual(false, splitOnCharLevel10.IsReached);
            gameService.Raise(g => g.DataRead += null, args);
            Assert.AreEqual(false, splitOnCharLevel10.IsReached);

            characterMock.SetupGet(x => x.Level).Returns(10);
            gameService.Raise(g => g.DataRead += null, args);
            Assert.AreEqual(true, splitOnCharLevel10.IsReached);

            // test autosplit by area
            Assert.AreEqual(false, splitOnArea1.IsReached);
            game.Area = (int)Area.ROGUE_ENCAMPMENT;
            gameService.Raise(g => g.DataRead += null, args);
            game.Area = (int)Area.ROGUE_ENCAMPMENT + 1;
            Assert.AreEqual(true, splitOnArea1.IsReached);

            // test autosplit by item
            Assert.AreEqual(false, splitOnItem1.IsReached);
            Assert.AreEqual(false, splitOnGem1.IsReached);
            itemsIds.Add(1);
            gameService.Raise(g => g.DataRead += null, args);
            Assert.AreEqual(true, splitOnItem1.IsReached);
            Assert.AreEqual(true, splitOnGem1.IsReached);

            // test autosplit by quest
            Assert.AreEqual(false, splitOnQuest81.IsReached);
            normalQuests.Clear();
            normalQuests.Add(QuestFactory.Create(QuestId.DenOfEvil, 1 << 0));
            normalQuests.Add(QuestFactory.Create(QuestId.Andariel, 0));
            gameService.Raise(g => g.DataRead += null, args);
            Assert.AreEqual(true, splitOnQuest81.IsReached);

            // test autosplit on game clear
            Assert.AreEqual(false, splitOnGameClear.IsReached);
            normalQuests.Clear();
            normalQuests.Add(QuestFactory.Create(QuestId.DenOfEvil, 1 << 0));
            normalQuests.Add(QuestFactory.Create(QuestId.Andariel, 1 << 0));
            gameService.Raise(g => g.DataRead += null, args);
            Assert.AreEqual(true, splitOnGameClear.IsReached);

            // test autosplit on game clear all difficulties
            Assert.AreEqual(false, splitOnGameClearAllDifficulties.IsReached);
            nightmareQuests.Clear();
            nightmareQuests.Add(QuestFactory.Create(QuestId.DenOfEvil, 1 << 0));
            nightmareQuests.Add(QuestFactory.Create(QuestId.Andariel, 1 << 0));
            gameService.Raise(g => g.DataRead += null, args);
            Assert.AreEqual(false, splitOnGameClearAllDifficulties.IsReached);
            hellQuests.Clear();
            hellQuests.Add(QuestFactory.Create(QuestId.DenOfEvil, 1 << 0));
            hellQuests.Add(QuestFactory.Create(QuestId.Andariel, 1 << 0));
            gameService.Raise(g => g.DataRead += null, args);
            Assert.AreEqual(true, splitOnGameClearAllDifficulties.IsReached);
        }
 public void Dispose() => AutoSplit?.Close();
 private void State_OnSkipSplit(object sender, EventArgs e) => AutoSplit.Send("skip");
示例#23
0
 private string AutoSplitString(int i, AutoSplit s) => $"#{i} [{s.Type}, {s.Value}, {s.Difficulty}] \"{s.Name}\"";
示例#24
0
 public void addAutosplit(AutoSplit autosplit)
 {
     Settings.Autosplits.Add(autosplit);
 }
        public void ShouldReachAutosplits()
        {
            var splitOnGameStart = new AutoSplit(
                "game start",
                AutoSplit.SplitType.Special,
                1,
                (short)GameDifficulty.Normal
                );
            var splitOnGameClear = new AutoSplit(
                "100% done",
                AutoSplit.SplitType.Special,
                2,
                (short)GameDifficulty.Normal
                );
            var splitOnGameClearAllDifficulties = new AutoSplit(
                "100% done all difficulties",
                AutoSplit.SplitType.Special,
                3,
                (short)GameDifficulty.Normal
                );
            var splitOnCharLevel10 = new AutoSplit(
                "char level 10",
                AutoSplit.SplitType.CharLevel,
                10,
                (short)GameDifficulty.Normal
                );
            var splitOnArea1 = new AutoSplit(
                "area 1",
                AutoSplit.SplitType.Area,
                1,
                (short)GameDifficulty.Normal
                );
            var splitOnItem1 = new AutoSplit(
                "item 1",
                AutoSplit.SplitType.Item,
                1,
                (short)GameDifficulty.Normal
                );
            var splitOnGem1 = new AutoSplit(
                "gem 1",
                AutoSplit.SplitType.Gems,
                1,
                (short)GameDifficulty.Normal
                );
            var splitOnQuest81 = new AutoSplit(
                "quest 81 (den of evil)",
                AutoSplit.SplitType.Quest,
                81,
                (short)GameDifficulty.Normal
                );
            var appSettings = new ApplicationSettings();

            appSettings.DoAutosplit = true;
            appSettings.Autosplits.Add(splitOnGameStart);
            appSettings.Autosplits.Add(splitOnGameClear);
            appSettings.Autosplits.Add(splitOnGameClearAllDifficulties);
            appSettings.Autosplits.Add(splitOnCharLevel10);
            appSettings.Autosplits.Add(splitOnArea1);
            appSettings.Autosplits.Add(splitOnItem1);
            appSettings.Autosplits.Add(splitOnGem1);
            appSettings.Autosplits.Add(splitOnQuest81);
            var settingsServiceMock = new Mock <ISettingsService>();

            settingsServiceMock.SetupGet(x => x.CurrentSettings).Returns(appSettings);
            var gameService = new GameServiceMock();
            AutoSplitService autoSplitService = new AutoSplitService(
                settingsServiceMock.Object,
                gameService,
                new Mock <KeyService>().Object
                );

            var normalQuests = new List <Quest>()
            {
                QuestFactory.Create(QuestId.DenOfEvil, 0),
                QuestFactory.Create(QuestId.Andariel, 0),
            };

            var nightmareQuests = new List <Quest>()
            {
                QuestFactory.Create(QuestId.DenOfEvil, 0),
                QuestFactory.Create(QuestId.Andariel, 0),
            };

            var hellQuests = new List <Quest>()
            {
                QuestFactory.Create(QuestId.DenOfEvil, 0),
                QuestFactory.Create(QuestId.Andariel, 0),
            };

            var quests = new Quests(new List <List <Quest> >
            {
                normalQuests,
                nightmareQuests,
                hellQuests,
            });

            var itemStrings = new Dictionary <BodyLocation, string>();
            var itemsIds    = new List <int>();

            var characterMock = new Mock <Character>();

            characterMock.SetupGet(x => x.Level).Returns(9);
            characterMock.SetupGet(x => x.IsAutosplitChar).Returns(true);
            characterMock.SetupGet(x => x.EquippedItemStrings).Returns(itemStrings);
            characterMock.SetupGet(x => x.InventoryItemIds).Returns(itemsIds);

            var game = new Game();

            game.Area       = 0;
            game.Difficulty = GameDifficulty.Normal;
            game.PlayersX   = 1;
            game.GameCount  = 0;
            game.CharCount  = 0;

            var args = new DataReadEventArgs(
                characterMock.Object,
                game,
                quests
                );

            // test autosplit by game start
            Assert.AreEqual(false, splitOnGameStart.IsReached);
            gameService.triggerDataRead(null, args);
            Assert.AreEqual(true, splitOnGameStart.IsReached);

            // test autosplit by level
            Assert.AreEqual(false, splitOnCharLevel10.IsReached);
            gameService.triggerDataRead(null, args);
            Assert.AreEqual(false, splitOnCharLevel10.IsReached);

            characterMock.SetupGet(x => x.Level).Returns(10);
            gameService.triggerDataRead(null, args);
            Assert.AreEqual(true, splitOnCharLevel10.IsReached);

            // test autosplit by area
            Assert.AreEqual(false, splitOnArea1.IsReached);
            game.Area = 1;
            gameService.triggerDataRead(null, args);
            game.Area = 0;
            Assert.AreEqual(true, splitOnArea1.IsReached);

            // test autosplit by item
            Assert.AreEqual(false, splitOnItem1.IsReached);
            Assert.AreEqual(false, splitOnGem1.IsReached);
            itemsIds.Add(1);
            gameService.triggerDataRead(null, args);
            Assert.AreEqual(true, splitOnItem1.IsReached);
            Assert.AreEqual(true, splitOnGem1.IsReached);

            // test autosplit by quest
            Assert.AreEqual(false, splitOnQuest81.IsReached);
            normalQuests.Clear();
            normalQuests.Add(QuestFactory.Create(QuestId.DenOfEvil, 1 << 0));
            normalQuests.Add(QuestFactory.Create(QuestId.Andariel, 0));
            gameService.triggerDataRead(null, args);
            Assert.AreEqual(true, splitOnQuest81.IsReached);

            // test autosplit on game clear
            Assert.AreEqual(false, splitOnGameClear.IsReached);
            normalQuests.Clear();
            normalQuests.Add(QuestFactory.Create(QuestId.DenOfEvil, 1 << 0));
            normalQuests.Add(QuestFactory.Create(QuestId.Andariel, 1 << 0));
            gameService.triggerDataRead(null, args);
            Assert.AreEqual(true, splitOnGameClear.IsReached);

            // test autosplit on game clear all difficulties
            Assert.AreEqual(false, splitOnGameClearAllDifficulties.IsReached);
            nightmareQuests.Clear();
            nightmareQuests.Add(QuestFactory.Create(QuestId.DenOfEvil, 1 << 0));
            nightmareQuests.Add(QuestFactory.Create(QuestId.Andariel, 1 << 0));
            gameService.triggerDataRead(null, args);
            Assert.AreEqual(false, splitOnGameClearAllDifficulties.IsReached);
            hellQuests.Clear();
            hellQuests.Add(QuestFactory.Create(QuestId.DenOfEvil, 1 << 0));
            hellQuests.Add(QuestFactory.Create(QuestId.Andariel, 1 << 0));
            gameService.triggerDataRead(null, args);
            Assert.AreEqual(true, splitOnGameClearAllDifficulties.IsReached);
        }
        public ApplicationSettings Read()
        {
            var settings = new ApplicationSettings();
            Dictionary <string, object> data = ReadToDict();

            // Helper methods for assigning fields.
            bool GetBoolDefault(string field, bool defaultValue) =>
            data.ContainsKey(field) ? (string)data[field] == "1" : defaultValue;

            string GetStringDefault(string field, string defaultValue) =>
            data.ContainsKey(field) ? (string)data[field] : defaultValue;

            int GetIntDefault(string field, int defaultValue)
            {
                if (!data.TryGetValue(field, out var obj))
                {
                    return(defaultValue);
                }
                return(int.TryParse((string)obj, out int value) ? value : defaultValue);
            }

            // Assign fields from settings.
            settings.FontName      = GetStringDefault("Font", settings.FontName);
            settings.FontSize      = GetIntDefault("FontSize", settings.FontSize);
            settings.FontSizeTitle = GetIntDefault("FontSizeTitle", settings.FontSizeTitle);
            settings.CheckUpdates  = GetBoolDefault("CheckUpdates", settings.CheckUpdates);
            settings.CreateFiles   = GetBoolDefault("CreateFiles", settings.CreateFiles);
            settings.DoAutosplit   = GetBoolDefault("DoAutosplit", settings.DoAutosplit);

            ConvertRuneData(settings, data);

            // Handle auto splits.
            if (data.ContainsKey("AutoSplits"))
            {
                settings.Autosplits = new List <AutoSplit>();
                var splits = (List <string>)data["AutoSplits"];
                foreach (var autoSplitData in splits)
                {
                    string[] splitParts = autoSplitData.Split(new[] { "|" }, 4, StringSplitOptions.None);
                    if (splitParts.Length < 3)
                    {
                        continue;
                    }

                    string splitName = splitParts[0];
                    short  splitType;
                    short  splitValue;
                    short  splitDifficulty = 0;

                    if (!short.TryParse(splitParts[1], out splitType))
                    {
                        continue;
                    }
                    if (!short.TryParse(splitParts[2], out splitValue))
                    {
                        continue;
                    }

                    if (splitParts.Length == 4)
                    {
                        if (!short.TryParse(splitParts[3], out splitDifficulty))
                        {
                            continue;
                        }
                    }

                    var autoSplit = new AutoSplit(splitName, (AutoSplit.SplitType)splitType, splitValue, splitDifficulty);
                    settings.Autosplits.Add(autoSplit);
                }
            }

            var legacyObject = new LegacySettingsObject(data);

            return(resolver.ResolveSettings(settings, legacyObject));
        }
示例#27
0
        public void ShouldNotSplitIfDisabled()
        {
            var split = new AutoSplit(
                "one",
                AutoSplit.SplitType.CharLevel,
                10,
                (short)GameDifficulty.Normal
                );

            var cfg = new Config();

            cfg.Enabled = false;
            cfg.Splits  = new List <AutoSplit>();
            cfg.Splits.Add(split);

            var config = new Mock <ApplicationConfig>();

            config.Setup(x => x.PluginConf(It.IsAny <string>())).Returns(cfg);
            var configService = new Mock <IConfigService>();

            configService.SetupGet(x => x.CurrentConfig).Returns(config.Object);

            var gameService = new Mock <IGameService>();

            var diabloInterface = new Mock <IDiabloInterface>();

            diabloInterface.Setup(x => x.configService).Returns(configService.Object);
            diabloInterface.Setup(x => x.game).Returns(gameService.Object);

            var autoSplitService = new Plugin();

            autoSplitService.Initialize(diabloInterface.Object);

            var quests = new Quests(new List <List <Quest> >
            {
                new List <Quest>(), // NORMAL
                new List <Quest>(), // NM
                new List <Quest>(), // HELL
            });

            var character = new Mock <Character>();

            character.SetupGet(x => x.Level).Returns(9);
            character.SetupGet(x => x.IsNewChar).Returns(true);
            character.SetupGet(x => x.InventoryItemIds).Returns(new List <int>());

            var processInfo = new ProcessInfo();
            var game        = new Game();

            game.Area       = 0;
            game.Difficulty = GameDifficulty.Normal;
            game.PlayersX   = 1;
            game.GameCount  = 0;
            game.CharCount  = 0;
            game.Character  = character.Object;
            game.Quests     = quests;

            List <Monster> killedMonsters = null;
            var            args           = new DataReadEventArgs(processInfo, game, killedMonsters);

            // test autosplit by level
            gameService.Raise(g => g.DataRead += null, args);
            Assert.AreEqual(false, split.IsReached);

            character.SetupGet(x => x.Level).Returns(10);
            gameService.Raise(g => g.DataRead += null, args);
            Assert.AreEqual(false, split.IsReached);
        }