From 81430f90f007b380dde12f1a93f24a2608cc65d9 Mon Sep 17 00:00:00 2001 From: wcko87 Date: Mon, 8 May 2017 18:24:16 +0800 Subject: [PATCH] Integrate map tile coordinates into boss detection --- rabi_splitter_WPF/BossFightConfig.cs | 29 ++++++++++++++++++-- rabi_splitter_WPF/BossFightEnum.cs | 7 +++-- rabi_splitter_WPF/BossFightIdentifier.cs | 34 ++++++++++++++++++------ rabi_splitter_WPF/MemorySnapshot.cs | 16 +++++++++++ 4 files changed, 74 insertions(+), 12 deletions(-) diff --git a/rabi_splitter_WPF/BossFightConfig.cs b/rabi_splitter_WPF/BossFightConfig.cs index 992b704..46af57a 100644 --- a/rabi_splitter_WPF/BossFightConfig.cs +++ b/rabi_splitter_WPF/BossFightConfig.cs @@ -46,6 +46,30 @@ namespace rabi_splitter_WPF startingBosses: new[] {Boss.Ashuri} ); + public static BossFight Rita = + new BossFight ( + displayName: "Rita", + music: Music.MIDSTREAM_JAM, + mapTile: new MapTileCoordinate(86, 10), + startingBosses: new[] { Boss.Rita } + ); + + public static BossFight Cicini = + new BossFight ( + displayName: "Cicini", + music: Music.HI_TECH_DUEL, + mapTile: new MapTileCoordinate(22, 14), + startingBosses: new[] { Boss.Cicini } + ); + + public static BossFight Cocoa2 = + new BossFight ( + displayName: "Cocoa2", + music: Music.GET_ON_WITH_IT, + mapTile: new MapTileCoordinate(14, 10), + startingBosses: new[] { Boss.Cocoa2 } + ); + public static BossFight BigBox = new BossFight ( displayName: "Big Box", @@ -149,13 +173,14 @@ namespace rabi_splitter_WPF map: Map.WarpDestination, startingBosses: new[] {Boss.Noah3} ); - + public static BossFight SideChapter = new BossFight ( displayName: "Side Chapter", music: Music.GET_ON_WITH_IT, map: Map.RabiRabiTown, - extraCondition: (startingBosses, music, map) => { + mapTile: new MapTileCoordinate(133, 12), + extraCondition: (startingBosses, music, map, mapTile) => { return startingBosses.Count == 3; } ); diff --git a/rabi_splitter_WPF/BossFightEnum.cs b/rabi_splitter_WPF/BossFightEnum.cs index e5c3e5c..0624d41 100644 --- a/rabi_splitter_WPF/BossFightEnum.cs +++ b/rabi_splitter_WPF/BossFightEnum.cs @@ -19,19 +19,22 @@ namespace rabi_splitter_WPF public readonly string displayName; public readonly Music? music; public readonly Map? map; + public readonly MapTileCoordinate? mapTile; public readonly HashSet startingBosses; - public readonly Func, Music, Map, bool> extraCondition; + public readonly Func, Music, Map, MapTileCoordinate, bool> extraCondition; private BossFight(string displayName = null, Music? music = null, Map? map = null, + MapTileCoordinate? mapTile = null, Boss[] startingBosses = null, - Func, Music, Map, bool> extraCondition = null) + Func, Music, Map, MapTileCoordinate, bool> extraCondition = null) { _value = nextAvailableValue++; this.displayName = displayName; this.music = music; this.map = map; + this.mapTile = mapTile; this.startingBosses = (startingBosses != null) ? new HashSet(startingBosses) : null; this.extraCondition = extraCondition; } diff --git a/rabi_splitter_WPF/BossFightIdentifier.cs b/rabi_splitter_WPF/BossFightIdentifier.cs index 795ef44..46c857d 100644 --- a/rabi_splitter_WPF/BossFightIdentifier.cs +++ b/rabi_splitter_WPF/BossFightIdentifier.cs @@ -7,6 +7,7 @@ namespace rabi_splitter_WPF { public static partial class BossFightIdentifier { + private static ILookup _matchMapTile; private static ILookup, BossFight> _matchMusicAndMap; private static ILookup _matchMusic; private static ILookup _matchMap; @@ -15,6 +16,7 @@ namespace rabi_splitter_WPF static BossFightIdentifier() { // Build dictionaries here. + var specifiedMapTile = new List(); var specifiedMusicAndMap = new List(); var specifiedMusicOnly = new List(); var specifiedMapOnly = new List(); @@ -22,7 +24,14 @@ namespace rabi_splitter_WPF foreach (var bossFight in BossFight.GetBossFights()) { - //if (bossFight == null) continue; + if (bossFight == null || bossFight == BossFight.UNKNOWN) continue; + + if (bossFight.mapTile != null) + { + specifiedMapTile.Add(bossFight); + continue; + } + if (bossFight.music != null) { if (bossFight.map != null) specifiedMusicAndMap.Add(bossFight); @@ -35,17 +44,18 @@ namespace rabi_splitter_WPF } } + _matchMapTile = specifiedMapTile.ToLookup(bossFight => bossFight.mapTile.Value, bossFight => bossFight); _matchMusicAndMap = specifiedMusicAndMap.ToLookup(bossFight => new Tuple(bossFight.music.Value, bossFight.map.Value), bossFight => bossFight); _matchMusic = specifiedMusicOnly.ToLookup(bossFight => bossFight.music.Value, bossFight => bossFight); _matchMap = specifiedMapOnly.ToLookup(bossFight => bossFight.map.Value, bossFight => bossFight); _remainingDescriptions = specifiedNeither.ToArray(); } - private static bool Matches(BossFight bossFight, HashSet startingBosses, Music music, Map map) + private static bool Matches(BossFight bossFight, HashSet startingBosses, Music music, Map map, MapTileCoordinate mapTile) { if (bossFight.startingBosses != null && !bossFight.startingBosses.SetEquals(startingBosses)) return false; if (bossFight.extraCondition == null) return true; - return bossFight.extraCondition(startingBosses, music, map); + return bossFight.extraCondition(startingBosses, music, map, mapTile); } public static BossFight IdentifyBossFight(MemorySnapshot snapshot) @@ -56,28 +66,36 @@ namespace rabi_splitter_WPF var music = music_.Value; var map = map_.Value; + var mapTile = snapshot.mapTile; var startingBosses = new HashSet(snapshot.bossList .Select(bossStats => StaticData.GetBoss(bossStats.id)) .Where(boss => boss != null) .Select(boss => boss.Value) ); - + + foreach (var bossFight in _matchMapTile[mapTile]) + { + if ((bossFight.music == null || music == bossFight.music) && + (bossFight.map == null || map == bossFight.map) && + Matches(bossFight, startingBosses, music, map, mapTile)) return bossFight; + } + foreach (var bossFight in _matchMusicAndMap[new Tuple(music, map)]) { - if (Matches(bossFight, startingBosses, music, map)) return bossFight; + if (Matches(bossFight, startingBosses, music, map, mapTile)) return bossFight; } foreach (var bossFight in _matchMusic[music]) { - if (Matches(bossFight, startingBosses, music, map)) return bossFight; + if (Matches(bossFight, startingBosses, music, map, mapTile)) return bossFight; } foreach (var bossFight in _matchMap[map]) { - if (Matches(bossFight, startingBosses, music, map)) return bossFight; + if (Matches(bossFight, startingBosses, music, map, mapTile)) return bossFight; } - return _remainingDescriptions.FirstOrDefault(bossFight => Matches(bossFight, startingBosses, music, map)) ?? BossFight.UNKNOWN; + return _remainingDescriptions.FirstOrDefault(bossFight => Matches(bossFight, startingBosses, music, map, mapTile)) ?? BossFight.UNKNOWN; } } diff --git a/rabi_splitter_WPF/MemorySnapshot.cs b/rabi_splitter_WPF/MemorySnapshot.cs index fba2fb5..0c827d4 100644 --- a/rabi_splitter_WPF/MemorySnapshot.cs +++ b/rabi_splitter_WPF/MemorySnapshot.cs @@ -26,6 +26,22 @@ namespace rabi_splitter_WPF return new MapTileCoordinate(x, y); } + + #region Equals, Hashcode + // override object.Equals + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) return false; + var other = (MapTileCoordinate)obj; + return x == other.x && y == other.y; + } + + // override object.GetHashCode + public override int GetHashCode() + { + return x.GetHashCode() * 31 + y.GetHashCode(); + } + #endregion } public struct BossStats