Integrate map tile coordinates into boss detection

rabi_display
wcko87 8 years ago
parent 6f0576376b
commit 81430f90f0
  1. 29
      rabi_splitter_WPF/BossFightConfig.cs
  2. 7
      rabi_splitter_WPF/BossFightEnum.cs
  3. 34
      rabi_splitter_WPF/BossFightIdentifier.cs
  4. 16
      rabi_splitter_WPF/MemorySnapshot.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;
}
);

@ -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<Boss> startingBosses;
public readonly Func<HashSet<Boss>, Music, Map, bool> extraCondition;
public readonly Func<HashSet<Boss>, Music, Map, MapTileCoordinate, bool> extraCondition;
private BossFight(string displayName = null,
Music? music = null,
Map? map = null,
MapTileCoordinate? mapTile = null,
Boss[] startingBosses = null,
Func<HashSet<Boss>, Music, Map, bool> extraCondition = null)
Func<HashSet<Boss>, 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<Boss>(startingBosses) : null;
this.extraCondition = extraCondition;
}

@ -7,6 +7,7 @@ namespace rabi_splitter_WPF
{
public static partial class BossFightIdentifier
{
private static ILookup<MapTileCoordinate, BossFight> _matchMapTile;
private static ILookup<Tuple<Music, Map>, BossFight> _matchMusicAndMap;
private static ILookup<Music, BossFight> _matchMusic;
private static ILookup<Map, BossFight> _matchMap;
@ -15,6 +16,7 @@ namespace rabi_splitter_WPF
static BossFightIdentifier()
{
// Build dictionaries here.
var specifiedMapTile = new List<BossFight>();
var specifiedMusicAndMap = new List<BossFight>();
var specifiedMusicOnly = new List<BossFight>();
var specifiedMapOnly = new List<BossFight>();
@ -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<Music, Map>(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<Boss> startingBosses, Music music, Map map)
private static bool Matches(BossFight bossFight, HashSet<Boss> 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<Boss>(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>(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;
}
}

@ -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

Loading…
Cancel
Save