60 lines
2.3 KiB
C#
60 lines
2.3 KiB
C#
using System;
|
|
using KernelPanic.Core;
|
|
using KernelPanic.Data;
|
|
using KernelPanic.Run;
|
|
|
|
namespace KernelPanic.Meta
|
|
{
|
|
/// <summary>
|
|
/// Read-only unlock rule for language availability.
|
|
/// </summary>
|
|
public static class LanguageUnlock
|
|
{
|
|
public static bool IsUnlocked(Language language, PlayerCollection collection)
|
|
{
|
|
if (language == Language.CPlusPlus || language == Language.TypeScript)
|
|
{
|
|
return collection?.HasCampaignClear(language == Language.CPlusPlus ? Language.C : Language.JavaScript) == true;
|
|
}
|
|
|
|
if (collection == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
LanguageCatalogEntry entry = LanguageCatalog.Get(language);
|
|
for (int unitIndex = 0; unitIndex < collection.OwnedUnits.Count; unitIndex++)
|
|
{
|
|
DistroDefinition unit = collection.OwnedUnits[unitIndex];
|
|
if (unit == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
for (int distroIndex = 0; distroIndex < entry.SupportingDistros.Count; distroIndex++)
|
|
{
|
|
if (string.Equals(unit.Id, entry.SupportingDistros[distroIndex].Id, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// Qualifying languages are the selected build languages, not generated or exclusive cards.
|
|
public static bool RecordCampaignClear(SaveData data, RunConfig config, RunJourney journey, int wavesCleared)
|
|
{
|
|
if (data == null || config == null || config.IsTutorial || journey?.campaign != true
|
|
|| journey.FinalWave != RunJourney.BossWave || wavesCleared < RunJourney.BossWave) return false;
|
|
data.campaignClearLanguages ??= new();
|
|
bool changed = false;
|
|
foreach (var language in new[] { config.PrimaryLanguage, config.SecondaryLanguage })
|
|
if ((language == Language.C || language == Language.JavaScript) && !data.campaignClearLanguages.Contains(language))
|
|
{ data.campaignClearLanguages.Add(language); changed = true; }
|
|
return changed;
|
|
}
|
|
}
|
|
}
|