Skip to content

Commit

Permalink
ASA setting loads ASA values. skipped levels not shown
Browse files Browse the repository at this point in the history
  • Loading branch information
cadon committed Nov 4, 2023
1 parent ac8e4b0 commit 8f3720f
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 32 deletions.
10 changes: 10 additions & 0 deletions ARKBreedingStats/Ark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ public enum Game
/// </summary>
ASA
}

/// <summary>
/// Collection indicator for ARK: Survival Evolved.
/// </summary>
public const string Ase = "ASE";

/// <summary>
/// Collection indicator for ARK: Survival Ascended, also the mod tag id for the ASA values.
/// </summary>
public const string Asa = "ASA";
}

/// <summary>
Expand Down
14 changes: 14 additions & 0 deletions ARKBreedingStats/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ARKBreedingStats/Form1.collection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ private bool LoadCollectionFile(string filePath, bool keepCurrentCreatures = fal
speciesSelector1.SetSpecies(_creatureCollection.creatures[0].Species);

// set library species to what it was before loading
selectedLibrarySpecies = Values.V.SpeciesByBlueprint(selectedLibrarySpecies?.blueprintPath);
if (selectedLibrarySpecies != null)
listBoxSpeciesLib.SelectedItem = selectedLibrarySpecies;
else if (Properties.Settings.Default.LibrarySelectSelectedSpeciesOnLoad)
Expand Down
59 changes: 54 additions & 5 deletions ARKBreedingStats/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,9 +1109,9 @@ private async void CheckForUpdates(bool silentCheck = false, bool selectDefaultI
(bool statValuesLoaded, bool kibbleValuesLoaded) success = (false, false);
if (LoadStatValues(Values.V, forceReload))
{
speciesSelector1.SetSpeciesLists(Values.V.species, Values.V.aliases);
if (applySettings)
ApplySettingsToValues();
speciesSelector1.SetSpeciesLists(Values.V.species, Values.V.aliases);
UpdateStatusBar();
success.statValuesLoaded = true;
}
Expand Down Expand Up @@ -1964,6 +1964,7 @@ private void OpenSettingsDialog(SettingsTabPages page = SettingsTabPages.Unknown

bool libraryTopCreatureColorHighlight = Properties.Settings.Default.LibraryHighlightTopCreatures;
bool considerWastedStatsForTopCreatures = Properties.Settings.Default.ConsiderWastedStatsForTopCreatures;
var gameSettingBefore = _creatureCollection.Game;

using (Settings settingsForm = new Settings(_creatureCollection, page))
{
Expand All @@ -1984,6 +1985,28 @@ private void OpenSettingsDialog(SettingsTabPages page = SettingsTabPages.Unknown
}
}

if (_creatureCollection.Game != gameSettingBefore)
{
// ASA setting changed
var asaCurrentlyLoaded = _creatureCollection.modIDs?.Contains(Ark.Asa) == true;

if ((_creatureCollection.Game == Ark.Asa) ^ asaCurrentlyLoaded)
{
if (asaCurrentlyLoaded)
{
_creatureCollection.modIDs.Remove(Ark.Asa);
_creatureCollection.ModList.RemoveAll(m => m.id == Ark.Asa);
}
else
{
if (_creatureCollection.modIDs == null) _creatureCollection.modIDs = new List<string>();
_creatureCollection.modIDs.Insert(0, Ark.Asa);
}
_creatureCollection.modListHash = 0; // making sure the mod values are reevaluated
ReloadModValuesOfCollectionIfNeeded(!asaCurrentlyLoaded, false, false);
}
}

ApplySettingsToValues();
CreatureColored.InitializeSpeciesImageLocation();
creatureBoxListView.CreatureCollection = _creatureCollection;
Expand Down Expand Up @@ -2680,6 +2703,7 @@ private bool LoadModValuesOfCollection(CreatureCollection cc, bool showResult, b
{
// nothing to do, and no error, the modHash seems to be wrong.
cc.UpdateModList();
UpdateAsaIndicator();
return true;
}

Expand Down Expand Up @@ -2708,7 +2732,17 @@ private bool LoadModValuesOfCollection(CreatureCollection cc, bool showResult, b
"Unknown mod IDs", MessageBoxButtons.OK, MessageBoxIcon.Warning);

bool result = LoadModValueFiles(filePaths, showResult, applySettings, out _);
UpdateAsaIndicator();
return result;

}

/// <summary>
/// Displays a small indicator in the UI if the ASA values are loaded.
/// </summary>
private void UpdateAsaIndicator()
{
LbAsa.Visible = _creatureCollection.Game == Ark.Asa;
}

private void loadAdditionalValuesToolStripMenuItem_Click(object sender, EventArgs e)
Expand All @@ -2723,17 +2757,32 @@ private void loadAdditionalValuesToolStripMenuItem_Click(object sender, EventArg
(Properties.Settings.Default.ModManagerWindowRect, _) = Utils.GetWindowRectangle(modValuesManager);
}

// if Asa values are added or removed manually, adjust Asa setting
_creatureCollection.Game = _creatureCollection.modIDs?.Contains(Ark.Asa) == true ? Ark.Asa : null;
ReloadModValuesOfCollectionIfNeeded();
}

/// <summary>
/// Loads mod value files according to the ModList of the library.
/// </summary>
/// <param name="onlyAdd">If true the values are not reset to the default first.</param>
private void ReloadModValuesOfCollectionIfNeeded(bool onlyAdd = false, bool showResult = true, bool applySettings = true)
{
// if the mods for the library changed,
// first check if all mod value files are available and load missing files if possible,
// then reload all values and mod values
if (_creatureCollection.ModValueReloadNeeded)
{
var modValuesNeedToBeLoaded = _creatureCollection.ModList?.Any() == true;
// first reset values to default
LoadStatAndKibbleValues(!modValuesNeedToBeLoaded);
var modValuesNeedToBeLoaded = _creatureCollection.modIDs?.Any() == true;
// first reset values to default if needed
if (!onlyAdd)
LoadStatAndKibbleValues(!modValuesNeedToBeLoaded);
// then load mod values if any
if (modValuesNeedToBeLoaded)
LoadModValuesOfCollection(_creatureCollection, true, true);
LoadModValuesOfCollection(_creatureCollection, showResult, applySettings);
else
UpdateAsaIndicator();

SetCollectionChanged(true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion ARKBreedingStats/Form1.extractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private void ShowSumOfChosenLevels()
}

// ASA can have up to 511 levels because 255 mutation levels also contribute to the wild value. TODO separate to mutation levels
if (_creatureCollection.Game != "ASA")
if (_creatureCollection.Game != Ark.Asa)
{
if (_statIOs[s].LevelWild > 255)
levelStatus |= LevelStatus.UltraMaxLevel;
Expand Down
2 changes: 1 addition & 1 deletion ARKBreedingStats/Form1.values.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ private bool LoadModValueFiles(List<string> modFilesToLoad, bool showResult, boo

if (modFilesLoaded)
{
speciesSelector1.SetSpeciesLists(Values.V.species, Values.V.aliases);
if (applySettings)
ApplySettingsToValues();
speciesSelector1.SetSpeciesLists(Values.V.species, Values.V.aliases);
}
if (showResult && !string.IsNullOrEmpty(resultsMessage))
MessageBox.Show(resultsMessage, "Loading Mod Values", MessageBoxButtons.OK, MessageBoxIcon.Information);
Expand Down
1 change: 0 additions & 1 deletion ARKBreedingStats/library/CreatureCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public CreatureCollection()
/// <summary>
/// Hash-Code that represents the loaded mod-values and their order
/// </summary>
[JsonProperty]
public int modListHash;

[JsonProperty]
Expand Down
5 changes: 2 additions & 3 deletions ARKBreedingStats/settings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using ARKBreedingStats.library;
using ARKBreedingStats.uiControls;
using ARKBreedingStats.utils;
using static System.Net.Mime.MediaTypeNames;

namespace ARKBreedingStats.settings
{
Expand Down Expand Up @@ -209,7 +208,7 @@ private void LoadSettings(CreatureCollection cc)
}
cbSingleplayerSettings.Checked = cc.singlePlayerSettings;
CbAtlasSettings.Checked = _cc.AtlasSettings;
if (_cc.Game == "ASA") RbGameAsa.Checked = true;
if (_cc.Game == Ark.Asa) RbGameAsa.Checked = true;
else RbGameAse.Checked = true;

nudMaxDomLevels.ValueSave = cc.maxDomLevel;
Expand Down Expand Up @@ -468,7 +467,7 @@ private void SaveSettings()

_cc.singlePlayerSettings = cbSingleplayerSettings.Checked;
_cc.AtlasSettings = CbAtlasSettings.Checked;
_cc.Game = RbGameAsa.Checked ? "ASA" : "ASE";
_cc.Game = RbGameAsa.Checked ? Ark.Asa : Ark.Ase;

_cc.maxDomLevel = (int)nudMaxDomLevels.Value;
_cc.maxWildLevel = (int)nudMaxWildLevels.Value;
Expand Down
47 changes: 27 additions & 20 deletions ARKBreedingStats/species/Species.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,35 +146,42 @@ private void Initialize(StreamingContext _)
if (altBaseStatsRaw != null)
altStats = new CreatureStat[Stats.StatsCount];

var fullStatsRawLength = fullStatsRaw?.Length ?? 0;

usedStats = 0;
if (fullStatsRaw != null)

double[][] completeRaws = new double[Stats.StatsCount][];
for (int s = 0; s < Stats.StatsCount; s++)
{
double[][] completeRaws = new double[Stats.StatsCount][];
for (int s = 0; s < Stats.StatsCount; s++)
{
stats[s] = new CreatureStat();
if (altBaseStatsRaw?.ContainsKey(s) ?? false)
altStats[s] = new CreatureStat();
// so far it seems stats that are skipped in wild are not displayed either
var statBit = (1 << s);
if ((skipWildLevelStats & statBit) != 0)
displayedStats &= ~statBit;


completeRaws[s] = new double[] { 0, 0, 0, 0, 0 };
if (fullStatsRaw.Length > s && fullStatsRaw[s] != null)
stats[s] = new CreatureStat();
if (altBaseStatsRaw?.ContainsKey(s) ?? false)
altStats[s] = new CreatureStat();

completeRaws[s] = new double[] { 0, 0, 0, 0, 0 };
if (fullStatsRawLength > s && fullStatsRaw[s] != null)
{
for (int i = 0; i < 5; i++)
{
for (int i = 0; i < 5; i++)
if (fullStatsRaw[s].Length > i)
{
if (fullStatsRaw[s].Length > i)
completeRaws[s][i] = fullStatsRaw[s]?[i] ?? 0;
if (i == 0 && fullStatsRaw[s][0] > 0)
{
completeRaws[s][i] = fullStatsRaw[s]?[i] ?? 0;
if (i == 0 && fullStatsRaw[s][0] > 0)
{
usedStats |= (1 << s);
}
usedStats |= (1 << s);
}
}
}
}
}

if (fullStatsRawLength != -0)
fullStatsRaw = completeRaws;
}

if (TamedBaseHealthMultiplier == null)
TamedBaseHealthMultiplier = 1;
Expand Down Expand Up @@ -318,17 +325,17 @@ public void SetCustomImprintingMultipliers(double?[] overrides)
/// <summary>
/// Returns if the species uses a stat, i.e. it has a base value > 0.
/// </summary>
public bool UsesStat(int statIndex) => (usedStats & 1 << statIndex) != 0;
public bool UsesStat(int statIndex) => (usedStats & (1 << statIndex)) != 0;

/// <summary>
/// Returns if the species displays a stat ingame in the inventory.
/// </summary>
public bool DisplaysStat(int statIndex) => (displayedStats & 1 << statIndex) != 0;
public bool DisplaysStat(int statIndex) => (displayedStats & (1 << statIndex)) != 0;

/// <summary>
/// Returns if a spawned creature can have wild levels in a stat.
/// </summary>
public bool CanLevelupWild(int statIndex) => (skipWildLevelStats & 1 << statIndex) == 0;
public bool CanLevelupWild(int statIndex) => (skipWildLevelStats & (1 << statIndex)) == 0;

public override string ToString()
{
Expand Down
2 changes: 1 addition & 1 deletion ARKBreedingStats/values/Values.cs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public void ApplyMultipliers(CreatureCollection cc, bool eventMultipliers = fals

currentServerMultipliers.FixZeroValues();
double[] defaultMultipliers = new double[] { 1, 1, 1, 1 }; // used if serverMultipliers don't specify non-default values
var useAsa = cc.Game == "ASA";
var useAsa = cc.Game == Ark.Asa;

foreach (Species sp in species)
{
Expand Down

0 comments on commit 8f3720f

Please sign in to comment.