Skip to content

Commit

Permalink
Changed the handling of unknown boss accessibility in Boss Shuffle to…
Browse files Browse the repository at this point in the history
… return SequenceBreak if some boss types are defeatable and Normal if all boss types are defeatable.

Changed the handling of dungeon items to return Partial if some of the items are accessible until the maximum number of items in the section that are accessible has been collected.
Changed clearing a location to do so 1 item at a time to check for partial sections.
Incremented version from 0.6.2 to 0.7.0 for release.
  • Loading branch information
trippsc2 committed Apr 2, 2020
1 parent e4462f7 commit aa31ec9
Show file tree
Hide file tree
Showing 12 changed files with 1,516 additions and 155 deletions.
76 changes: 76 additions & 0 deletions OpenTracker.Models/BossDictionary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using OpenTracker.Models.Enums;
using System.Collections.Generic;
using System.ComponentModel;

namespace OpenTracker.Models
{
public class BossDictionary : Dictionary<BossType, Boss>, INotifyPropertyChanged
{
private readonly Game _game;

public event PropertyChangedEventHandler PropertyChanged;

private AccessibilityLevel _unknownBossAccessibility;
public AccessibilityLevel UnknownBossAccessibility
{
get => _unknownBossAccessibility;
private set
{
if (_unknownBossAccessibility != value)
{
_unknownBossAccessibility = value;
OnPropertyChanged(nameof(UnknownBossAccessibility));
}
}
}

public BossDictionary(Game game, int capacity) : base(capacity)
{
_game = game;
}

private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

private void OnRequirementChanged(object sender, PropertyChangedEventArgs e)
{
UpdateUnknownBossAccessibility();
}

private void UpdateUnknownBossAccessibility()
{
bool BossInaccessibility = false;

foreach (Boss boss in Values)
{
if (boss.Type != BossType.Aga)
{
if (boss.Accessibility < AccessibilityLevel.SequenceBreak)
{
BossInaccessibility = true;
break;
}
}
}

if (BossInaccessibility)
UnknownBossAccessibility = AccessibilityLevel.SequenceBreak;
else
UnknownBossAccessibility = AccessibilityLevel.Normal;
}

public void SubscribeToMemberEvents()
{
foreach (Boss boss in Values)
{
if (boss.Type != BossType.Aga)
boss.PropertyChanged += OnRequirementChanged;
}

UpdateUnknownBossAccessibility();
}
}
}
14 changes: 10 additions & 4 deletions OpenTracker.Models/BossSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public BossSection(Game game, LocationID iD)
GetAccessibility = () =>
{
if ((_game.Items.Has(ItemType.Bow) || _game.Mode.EnemyShuffle.Value) &&
_game.Items.Has(ItemType.GTSmallKey, 2) && _game.Items.Has(ItemType.GTBigKey))
_game.Items.Has(ItemType.GTSmallKey, 1) && _game.Items.Has(ItemType.GTBigKey))
return AccessibilityLevel.Normal;

return AccessibilityLevel.None;
Expand Down Expand Up @@ -444,7 +444,9 @@ private void UpdateAccessibility()

if (_game.Mode.BossShuffle.Value)
{
if (Boss != null)
if (Boss == null)
bossAccessibility = _game.Bosses.UnknownBossAccessibility;
else
bossAccessibility = Boss.Accessibility;
}
else
Expand Down Expand Up @@ -484,7 +486,9 @@ private void OnPropertyChanging(string propertyName)
{
if (propertyName == nameof(Boss))
{
if (Boss != null)
if (Boss == null)
_game.Bosses.PropertyChanged -= OnBossChanged;
else if (Boss != _defaultBoss)
Boss.PropertyChanged -= OnBossChanged;
}

Expand All @@ -508,7 +512,9 @@ private void OnPropertyChanged(string propertyName)

if (propertyName == nameof(Boss))
{
if (Boss != null)
if (Boss == null)
_game.Bosses.PropertyChanged += OnBossChanged;
else if (Boss != _defaultBoss)
Boss.PropertyChanged += OnBossChanged;

UpdateAccessibility();
Expand Down
6 changes: 4 additions & 2 deletions OpenTracker.Models/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace OpenTracker.Models
public class Game
{
public Mode Mode { get; }
public Dictionary<BossType, Boss> Bosses { get; }
public BossDictionary Bosses { get; }
public ItemDictionary Items { get; }
public Dictionary<RegionID, Region> Regions { get; }
public LocationDictionary Locations { get; }
Expand All @@ -24,7 +24,7 @@ public Game()
EnemyShuffle = false
};

Bosses = new Dictionary<BossType, Boss>(Enum.GetValues(typeof(BossType)).Length);
Bosses = new BossDictionary(this, Enum.GetValues(typeof(BossType)).Length);
Items = new ItemDictionary(Mode, Enum.GetValues(typeof(ItemType)).Length);
Regions = new Dictionary<RegionID, Region>(Enum.GetValues(typeof(RegionID)).Length);
Locations = new LocationDictionary(Enum.GetValues(typeof(LocationID)).Length);
Expand All @@ -35,6 +35,8 @@ public Game()
foreach (BossType type in Enum.GetValues(typeof(BossType)))
Bosses.Add(type, new Boss(this, type));

Bosses.SubscribeToMemberEvents();

foreach (RegionID iD in Enum.GetValues(typeof(RegionID)))
Regions.Add(iD, new Region(this, iD));

Expand Down
Loading

0 comments on commit aa31ec9

Please sign in to comment.