Skip to content

Commit

Permalink
Merge pull request #638 from TheTrackerCouncil/legacy-logic
Browse files Browse the repository at this point in the history
Add legacy logic for AP seeds
  • Loading branch information
MattEqualsCoder authored Jan 3, 2025
2 parents 04dc630 + bf92aaa commit 3e80b60
Show file tree
Hide file tree
Showing 68 changed files with 4,199 additions and 17 deletions.
6 changes: 6 additions & 0 deletions TrackerCouncil.Smz3.sln
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TrackerCouncil.Smz3.Data.Sc
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TrackerCouncil.Smz3.UI", "src\TrackerCouncil.Smz3.UI\TrackerCouncil.Smz3.UI.csproj", "{07BA0552-C03C-4996-AD9B-DEFFECAC0987}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrackerCouncil.Smz3.LegacyLogic", "src\TrackerCouncil.Smz3.LegacyLogic\TrackerCouncil.Smz3.LegacyLogic.csproj", "{87623A81-7721-46E4-8CF6-F9C1705F4D7B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -104,6 +106,10 @@ Global
{07BA0552-C03C-4996-AD9B-DEFFECAC0987}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07BA0552-C03C-4996-AD9B-DEFFECAC0987}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07BA0552-C03C-4996-AD9B-DEFFECAC0987}.Release|Any CPU.Build.0 = Release|Any CPU
{87623A81-7721-46E4-8CF6-F9C1705F4D7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{87623A81-7721-46E4-8CF6-F9C1705F4D7B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87623A81-7721-46E4-8CF6-F9C1705F4D7B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87623A81-7721-46E4-8CF6-F9C1705F4D7B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion src/TrackerCouncil.Smz3.Data/Logic/Logic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public bool CheckAgahnim(Progression items, World world, bool requireRewards)

public static IEnumerable<ItemType[]> GetMissingRequiredItems(Location location, Progression items, out IEnumerable<ItemType> allPossibleMissingItems)
{
if (location.IsAvailable(items))
if (location.Accessibility is Accessibility.Available or Accessibility.AvailableWithKeys)
{
allPossibleMissingItems = Enumerable.Empty<ItemType>();
return Enumerable.Empty<ItemType[]>();
Expand Down
1 change: 1 addition & 0 deletions src/TrackerCouncil.Smz3.Data/Options/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public class Config

public GameMode GameMode { get; set; } = GameMode.Normal;
public KeysanityMode KeysanityMode { get; set; } = KeysanityMode.None;
public SMLogic LegacyMetroidLogic { get; set; } = SMLogic.Normal;
public bool Race { get; set; } = false;
public bool DisableSpoilerLog { get; set; } = false;
public bool DisableTrackerSpoilers { get; set; } = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

<ItemGroup>
<ProjectReference Include="..\TrackerCouncil.Smz3.Chat.Integration\TrackerCouncil.Smz3.Chat.Integration.csproj" />
<ProjectReference Include="..\TrackerCouncil.Smz3.LegacyLogic\TrackerCouncil.Smz3.LegacyLogic.csproj" />
<ProjectReference Include="..\TrackerCouncil.Smz3.Shared\TrackerCouncil.Smz3.Shared.csproj" />
</ItemGroup>

Expand Down
24 changes: 24 additions & 0 deletions src/TrackerCouncil.Smz3.Data/WorldData/Boss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,30 @@ public void UpdateAccessibility(Progression actualProgression, Progression withK
}
}

public void UpdateLegacyAccessibility(bool isActuallyAccessible, bool isAccessibleWithKeys)
{
if (Defeated)
{
Accessibility = Accessibility.Cleared;
}
else if (Region == null)
{
Accessibility = Accessibility.Unknown;
}
else if (isActuallyAccessible)
{
Accessibility = Accessibility.Available;
}
else if (isAccessibleWithKeys)
{
Accessibility = Accessibility.AvailableWithKeys;
}
else
{
Accessibility = Accessibility.OutOfLogic;
}
}

public event EventHandler? UpdatedBossState;

public event EventHandler? UpdatedAccessibility;
Expand Down
30 changes: 30 additions & 0 deletions src/TrackerCouncil.Smz3.Data/WorldData/Location.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,22 @@ public Accessibility GetAccessibility(Progression actualProgression, Progression
/// <summary>
/// Returns the status of a location based on the given items
/// </summary>
/// <param name="actualProgression"></param>

Check warning on line 331 in src/TrackerCouncil.Smz3.Data/WorldData/Location.cs

View workflow job for this annotation

GitHub Actions / build

XML comment has a param tag for 'actualProgression', but there is no parameter by that name

Check warning on line 331 in src/TrackerCouncil.Smz3.Data/WorldData/Location.cs

View workflow job for this annotation

GitHub Actions / build

XML comment has a param tag for 'actualProgression', but there is no parameter by that name

Check warning on line 331 in src/TrackerCouncil.Smz3.Data/WorldData/Location.cs

View workflow job for this annotation

GitHub Actions / build-mac

XML comment has a param tag for 'actualProgression', but there is no parameter by that name

Check warning on line 331 in src/TrackerCouncil.Smz3.Data/WorldData/Location.cs

View workflow job for this annotation

GitHub Actions / build-mac

XML comment has a param tag for 'actualProgression', but there is no parameter by that name
/// <param name="withKeysProgression"></param>

Check warning on line 332 in src/TrackerCouncil.Smz3.Data/WorldData/Location.cs

View workflow job for this annotation

GitHub Actions / build

XML comment has a param tag for 'withKeysProgression', but there is no parameter by that name

Check warning on line 332 in src/TrackerCouncil.Smz3.Data/WorldData/Location.cs

View workflow job for this annotation

GitHub Actions / build

XML comment has a param tag for 'withKeysProgression', but there is no parameter by that name

Check warning on line 332 in src/TrackerCouncil.Smz3.Data/WorldData/Location.cs

View workflow job for this annotation

GitHub Actions / build-mac

XML comment has a param tag for 'withKeysProgression', but there is no parameter by that name

Check warning on line 332 in src/TrackerCouncil.Smz3.Data/WorldData/Location.cs

View workflow job for this annotation

GitHub Actions / build-mac

XML comment has a param tag for 'withKeysProgression', but there is no parameter by that name
/// <param name="isAccessible"></param>
/// <param name="isAccessibleWithKeys"></param>
/// <returns></returns>
public Accessibility GetLegacyAccessibility(bool isAccessible, bool isAccessibleWithKeys)
{
if (State.Cleared) return Accessibility.Cleared;
else if (isAccessible) return Accessibility.Available;
else if (isAccessibleWithKeys) return Accessibility.AvailableWithKeys;
else return Accessibility.OutOfLogic;
}

/// <summary>
/// Updates the status of a location based on the given items
/// </summary>
/// <param name="actualProgression">The available items</param>
/// <param name="withKeysProgression">The available items plus additional keys</param>
/// <returns>The LocationStatus enum of the location</returns>
Expand All @@ -339,6 +355,20 @@ public void UpdateAccessibility(Progression actualProgression, Progression withK
AccessibilityUpdated?.Invoke(this, EventArgs.Empty);
}

/// <summary>
/// Updates the status of a location based on the given items
/// </summary>
/// <param name="isAccessible"></param>
/// <param name="isAccessibleWithKeys"></param>
/// <returns>The LocationStatus enum of the location</returns>
public void UpdateLegacyAccessibility(bool isAccessible, bool isAccessibleWithKeys)
{
var newValue = GetLegacyAccessibility(isAccessible, isAccessibleWithKeys);
if (newValue == Accessibility) return;
Accessibility = newValue;
AccessibilityUpdated?.Invoke(this, EventArgs.Empty);
}

/// <summary>
/// Determines whether the specified item can be assigned to this
/// location.
Expand Down
9 changes: 9 additions & 0 deletions src/TrackerCouncil.Smz3.Data/WorldData/Progression.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using Randomizer.SMZ3;
using TrackerCouncil.Smz3.Shared;
using TrackerCouncil.Smz3.Shared.Enums;

Expand Down Expand Up @@ -194,6 +195,14 @@ public bool Remove(ItemType item)
public IEnumerator<ItemType> GetEnumerator()
=> Items.GetEnumerator();

public void InitLegacyProgression()
{
var itemIds = Items.Select(x => (int)x).ToList();
LegacyProgression = new LegacyProgression(itemIds);
}

public LegacyProgression? LegacyProgression { get; private set; }

public bool HasMarkedMedallion(ItemType? medallion)
=> (medallion != null && medallion != ItemType.Nothing && Contains(medallion.Value)) || (Bombos && Ether && Quake);

Expand Down
24 changes: 24 additions & 0 deletions src/TrackerCouncil.Smz3.Data/WorldData/Reward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,30 @@ public void UpdateAccessibility(Progression actualProgression, Progression withK
}
}

public void UpdateLegacyAccessibility(bool isActuallyAccessible, bool isAccessibleWithKeys)
{
if (HasReceivedReward)
{
Accessibility = Accessibility.Cleared;
}
else if (Region == null)
{
Accessibility = Accessibility.Unknown;
}
else if (isActuallyAccessible)
{
Accessibility = Accessibility.Available;
}
else if (isAccessibleWithKeys)
{
Accessibility = Accessibility.AvailableWithKeys;
}
else
{
Accessibility = Accessibility.OutOfLogic;
}
}

public bool HasCorrectlyMarkedReward => MarkedReward == Type;

public event EventHandler? UpdatedRewardState;
Expand Down
91 changes: 91 additions & 0 deletions src/TrackerCouncil.Smz3.Data/WorldData/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Randomizer.SMZ3;
using TrackerCouncil.Smz3.Shared;
using TrackerCouncil.Smz3.Data.Logic;
using TrackerCouncil.Smz3.Data.Options;
Expand Down Expand Up @@ -101,6 +102,22 @@ public World(Config config, string player, int id, string guid, bool isLocalWorl
RewardRegions = Regions.OfType<IHasReward>().ToImmutableList();
BossRegions = Regions.OfType<IHasBoss>().ToImmutableList();
PrerequisiteRegions = Regions.OfType<IHasPrerequisite>().ToImmutableList();

if (Config.RomGenerator != RomGenerator.Cas)
{
var legacyConfig = new LegacyConfig()
{
LegacyGameMode = (LegacyGameMode)Config.GameMode,
LegacySmLogic = (LegacySMLogic)Config.LegacyMetroidLogic,
LegacyKeyShuffle = Config.MetroidKeysanity || Config.ZeldaKeysanity
? LegacyKeyShuffle.Keysanity
: LegacyKeyShuffle.None,
};

LegacyWorld = new LegacyWorld(legacyConfig, Player, Id, Guid);

UpdateLegacyWorld();
}
}

public Config Config { get; }
Expand Down Expand Up @@ -170,6 +187,7 @@ public World(Config config, string player, int id, string guid, bool isLocalWorl
public WreckedShip WreckedShip { get; }
public WorldItemPools ItemPools { get; }
public IEnumerable<PlayerHintTile> HintTiles { get; set; } = [];
public LegacyWorld? LegacyWorld { get; private set; }

public IEnumerable<LocationId> ActiveHintTileLocations => HintTiles
.Where(x => x.State?.HintState == HintState.Viewed && x.Locations?.Any() == true && x.WorldId == Id)
Expand Down Expand Up @@ -305,6 +323,79 @@ private void SetBottles(Random rnd)
}
}

public void UpdateLegacyWorld()
{
if (LegacyWorld == null)
{
return;
}

var worldState = new LegacyWorldState()
{
Medallions =
[
GetLegacyMedallion(MiseryMire),
GetLegacyMedallion(TurtleRock)
],
Rewards =
[
GetLegacyRewardType(EasternPalace),
GetLegacyRewardType(DesertPalace),
GetLegacyRewardType(TowerOfHera),
GetLegacyRewardType(PalaceOfDarkness),
GetLegacyRewardType(SwampPalace),
GetLegacyRewardType(SkullWoods),
GetLegacyRewardType(ThievesTown),
GetLegacyRewardType(IcePalace),
GetLegacyRewardType(MiseryMire),
GetLegacyRewardType(TurtleRock),
GetLegacyRewardType(KraidsLair),
GetLegacyRewardType(WreckedShip),
GetLegacyRewardType(InnerMaridia),
GetLegacyRewardType(LowerNorfairEast),
],
TowerCrystals = Config.GanonsTowerCrystalCount,
GanonCrystals = Config.GanonCrystalCount,
TourianBossTokens = Config.TourianBossCount
};

LegacyWorld.Setup(worldState);
}

private LegacyRewardType GetLegacyRewardType(IHasReward region)
{
return region.MarkedReward switch
{
RewardType.Agahnim => LegacyRewardType.Agahnim,
RewardType.PendantGreen => LegacyRewardType.PendantGreen,
RewardType.PendantBlue => LegacyRewardType.PendantNonGreen,
RewardType.PendantRed => LegacyRewardType.PendantNonGreen,
RewardType.CrystalBlue => LegacyRewardType.CrystalBlue,
RewardType.CrystalRed => LegacyRewardType.CrystalRed,
RewardType.KraidToken => LegacyRewardType.BossTokenKraid,
RewardType.PhantoonToken => LegacyRewardType.BossTokenPhantoon,
RewardType.DraygonToken => LegacyRewardType.BossTokenDraygon,
RewardType.RidleyToken => LegacyRewardType.BossTokenRidley,
_ => LegacyRewardType.None
};
}

private LegacyWorldState.LegacyMedallion GetLegacyMedallion(IHasPrerequisite region)
{
var unobtainedMedallion = AllItems.FirstOrDefault(x =>
x.IsLocalPlayerItem && x.Type.IsInCategory(ItemCategory.Medallion) && x.TrackingState == 0)?.Type;

var requiredItemType =
region.MarkedItem ?? unobtainedMedallion ?? region.RequiredItem;

return requiredItemType switch
{
ItemType.Bombos => LegacyWorldState.LegacyMedallion.Bombos,
ItemType.Ether => LegacyWorldState.LegacyMedallion.Ether,
_ => LegacyWorldState.LegacyMedallion.Bombos
};
}

public int CountReceivedReward(Progression items, RewardType reward)
{
return CountReceivedRewards(items, [reward]);
Expand Down
Loading

0 comments on commit 3e80b60

Please sign in to comment.