Skip to content

Commit

Permalink
1.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Cattlesquat committed Dec 20, 2020
1 parent b1a48a5 commit d7dc2ba
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 87 deletions.
28 changes: 20 additions & 8 deletions Common/BasicText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public BasicText()
cloneFont = true;
cloneStyle = true;
cloneMaterial = true;
overBlackScreen = false;
}

public BasicText(bool overBlack) : this()
{
overBlackScreen = overBlack;
}

public BasicText(int set_x, int set_y) : this()
Expand Down Expand Up @@ -406,20 +412,26 @@ private void InitializeText()
// This puts the text OVER the black "you are dead" screen, so it will still show for a death message
// One could of course get into parenting this object to different things, in different layers, but for
// basic purposes we're creating text that will "definitely show up".
//var go = uGUI.main.overlays.overlays[0].graphic;
//textObject.transform.SetParent(go.transform, false); // Parents our text to the black overlay
//textText.canvas.overrideSorting = true; // Turn on canvas sort override so the layers will work
//textObject.layer += 100; // Set to a higher layer than the black overlay

textObject.transform.SetParent(uGUI.main.screenCanvas.transform, false); // Parents our text to the black overlay
textText.canvas.overrideSorting = true; // Turn on canvas sort override so the layers will work
textObject.layer = 31; // Set to what seems to be Subnautica's highest layer
if (overBlackScreen)
{
var go = uGUI.main.overlays.overlays[0].graphic;
textObject.transform.SetParent(go.transform, false); // Parents our text to the black overlay
textText.canvas.overrideSorting = true; // Turn on canvas sort override so the layers will work
textObject.layer++; // Set to a higher layer than the black overlay
}
else
{
textObject.transform.SetParent(uGUI.main.screenCanvas.transform, false); // Parents our text to the black overlay
textText.canvas.overrideSorting = true; // Turn on canvas sort override so the layers will work
textObject.layer = 31; // Set to what seems to be Subnautica's highest layer
}

doAlignment();
}

protected float x { get; set; } = 0; // X position anchor
protected float y { get; set; } = 210f; // Y position anchor (defaults to a comfortable centered about 1/3 from top of screen)
protected bool overBlackScreen { get; set; } // True if should forced be over the "death" screen
protected bool cloneAlign { get; set; } // True if we're cloning Subnautica's "Press Any Button To Begin" alignment
protected bool cloneColor { get; set; } // True if we're cloning Subnautica's "Press Any Button To Begin" color
protected bool cloneSize { get; set; } // True if we're cloning Subnautica's "Press Any Button To Begin" fontsize
Expand Down
19 changes: 14 additions & 5 deletions DeathRun/DeathRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public class DeathRun
// So that the explody fish stay hidden in ambush
public static bool crashFishSemaphore = false;

// Don't do extra warnings during respawn process while player is already dead
public static bool playerIsDead = false;

// Let player know if patch didn't complete
public static bool patchFailed = false;

Expand All @@ -86,7 +89,7 @@ public class DeathRun
public static void Patch()
{
CattleLogger.setModName(modName);
CattleLogger.PatchStart("1.3.2");
CattleLogger.PatchStart("1.3.5");

try
{
Expand Down Expand Up @@ -163,7 +166,7 @@ public static void Patch()
//{
harmony.Patch(AccessTools.Method(typeof(RadiatePlayerInRange), "Radiate"),
new HarmonyMethod(typeof(RadiationPatcher).GetMethod("Radiate")), null);

harmony.Patch(AccessTools.Method(typeof(DamagePlayerInRadius), "DoDamage"),
new HarmonyMethod(typeof(RadiationPatcher).GetMethod("DoDamage")), null);
//}
Expand All @@ -174,6 +177,9 @@ public static void Patch()
harmony.Patch(AccessTools.Method(typeof(PowerSystem), "AddEnergy"),
new HarmonyMethod(typeof(PowerPatcher).GetMethod("AddEnergyBase")), null);

harmony.Patch(AccessTools.Method(typeof(SolarPanel), "Update"),
new HarmonyMethod(typeof(PowerPatcher).GetMethod("SolarPanelUpdate")), null);

harmony.Patch(AccessTools.Method(typeof(EnergyMixin), "AddEnergy"),
new HarmonyMethod(typeof(PowerPatcher).GetMethod("AddEnergyTool")), null);

Expand Down Expand Up @@ -554,15 +560,16 @@ public static void Patch()

Console.WriteLine("[DeathRun] Patched");

statsData.LoadStats();

Console.WriteLine("[DeathRun] Stats Loaded");
}
catch (Exception ex)
{
CattleLogger.PatchFailed(ex);
patchFailed = true;
}

statsData.LoadStats();

Console.WriteLine("[DeathRun] Stats Loaded");
}

public static void setCause(string newCause)
Expand Down Expand Up @@ -600,6 +607,8 @@ public static void StartNewGame()
causeObject = null;
cinematicCause = CAUSE_UNKNOWN;
cinematicCauseObject = null;

playerIsDead = false;
}
}

Expand Down
91 changes: 72 additions & 19 deletions DeathRun/DeathRunUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace DeathRun
public class DeathRunUtils
{
public static CenterText[] centerMessages = new CenterText[] {
new CenterText(250f),
new CenterText(210f),
new CenterText(250f, true),
new CenterText(210f, true),
new CenterText(-210f),
new CenterText(-250f),
new CenterText(100f)
Expand All @@ -34,6 +34,11 @@ public CenterText(float set_y) : base()
{
setLoc(0, set_y);
}

public CenterText(float set_y, bool over) : base(over)
{
setLoc(0, set_y);
}
}


Expand Down Expand Up @@ -82,7 +87,7 @@ public static bool isIntroStillGoing ()
}

// Checks if opening animation is running
if ((EscapePod.main.IsPlayingIntroCinematic() && EscapePod.main.IsNewBorn()))
if ((EscapePod.main == null) || ((EscapePod.main.IsPlayingIntroCinematic() && EscapePod.main.IsNewBorn())))
{
return true;
}
Expand Down Expand Up @@ -202,20 +207,38 @@ public static string sayBriefTime(TimeSpan time, bool noDays)

public static bool wouldBeShowing = false; // If true, then only reason High Scores aren't currently showing is that they are hidden by the preference

public static List<String> tips = new List<String>() { "How long can YOU survive?",
"Did you know eating raw bladderfish yields oxygen?",
"First aid kits also purge nitrogen.",
"Eating some native fish purges nitrogen.",
"Speak softly, but carry a floating pump.",
"Never stop moving - those things bite!",
"Keep your food and water topped up: it heals you!",
"The more Death Run settings you use - the higher your score!",
"Survive longer? Higher score. Win fastest? Highest Score."
};


public static void InitHighScores ()
{
for (int row = 0; row < HIGH_SCORE_ROWS; row++)
{
highScoreNumbers[row] = new HighScoreText(TextAnchor.MiddleCenter);
highScoreStarts[row] = new HighScoreText(TextAnchor.MiddleCenter);
highScoreCauses[row] = new HighScoreText(TextAnchor.MiddleCenter);
highScoreTimes[row] = new HighScoreText(TextAnchor.MiddleCenter);
highScoreDeaths[row] = new HighScoreText(TextAnchor.MiddleCenter);
highScorePercents[row] = new HighScoreText(TextAnchor.MiddleCenter);
highScoreScores[row] = new HighScoreText(TextAnchor.MiddleCenter);
}
}


public static void ShowHighScores(bool should)
{
if (highScoreNumbers[0] == null)
{
for (int row = 0; row < HIGH_SCORE_ROWS; row++)
{
highScoreNumbers[row] = new HighScoreText(TextAnchor.MiddleCenter);
highScoreStarts[row] = new HighScoreText(TextAnchor.MiddleCenter);
highScoreCauses[row] = new HighScoreText(TextAnchor.MiddleCenter);
highScoreTimes[row] = new HighScoreText(TextAnchor.MiddleCenter);
highScoreDeaths[row] = new HighScoreText(TextAnchor.MiddleCenter);
highScorePercents[row] = new HighScoreText(TextAnchor.MiddleCenter);
highScoreScores[row] = new HighScoreText(TextAnchor.MiddleCenter);
}
InitHighScores();
}

// When "should" is false, it means we're being called because of an Options/Preference change, not a menu state change
Expand Down Expand Up @@ -251,7 +274,18 @@ public static void ShowHighScores(bool should)
highScoreLabel.setAlign(TextAnchor.MiddleCenter);
highScoreLabel.ShowMessage("Death Run - Best Scores");
highScoreTag.setAlign(TextAnchor.MiddleCenter);
highScoreTag.ShowMessage("How long can YOU survive?");

int pick;
if (DeathRun.statsData.VeryFirstTime)
{
DeathRun.statsData.VeryFirstTime = false;
pick = 0;
} else
{
pick = UnityEngine.Random.Range(0, tips.Count);
}

highScoreTag.ShowMessage(tips[pick]); // "How long can YOU survive?");

int index = 0;
foreach (RunData score in DeathRun.statsData.HighScores)
Expand Down Expand Up @@ -312,6 +346,11 @@ public static void ShowHighScores(bool should)

public static void HideHighScores(bool should)
{
if (highScoreNumbers[0] == null)
{
InitHighScores();
}

// When "should" is false, it means we're being called because of an Options/Preference change, not a menu state change
// When "should" is true, it means the actual menu state has changed
if (should)
Expand Down Expand Up @@ -518,6 +557,7 @@ public bool betterThan (RunData other)
{
// Mostly at this point use score
if (Score > other.Score) return true;
if (other.Score > Score) return false;

// Victory beats defeat
if (Victory && !other.Victory) return true;
Expand All @@ -527,16 +567,18 @@ public bool betterThan (RunData other)
if (Victory)
{
if (Deaths < other.Deaths) return true; // Fewer deaths is definitive comparison between victories
return RunTime < other.RunTime; // In victory a SHORTER time is best
if (other.Deaths <= Deaths) return false;

return RunTime <= other.RunTime; // In victory a SHORTER time is best
}

// Otherwise we are comparing two defeats. In death, longer survival is best.
if ((Deaths > 0) && other.Deaths > 0)
{
return RunTime / Deaths > other.RunTime / other.Deaths;
return RunTime / Deaths >= other.RunTime / other.Deaths;
}

return RunTime > other.RunTime;
return RunTime >= other.RunTime;
}
}

Expand Down Expand Up @@ -679,6 +721,7 @@ public void OnProtoSerialize(ProtobufSerializer serializer)
*/
public class DeathRunStats
{
public bool VeryFirstTime { get; set; }
public int RunCounter { get; set; }
public int RecentIndex { get; set; }
public List<RunData> HighScores { get; set; }
Expand All @@ -693,6 +736,7 @@ public DeathRunStats()

public void setDefaults()
{
VeryFirstTime = true;
RunCounter = 0;
RecentIndex = -1;
}
Expand Down Expand Up @@ -744,9 +788,11 @@ public void JustLoadedStats()
* Adds a completed run to our high score list at the appropriate place. If
*/
public int addRun(RunData run)
{
{
ClearExtraScores();

if (run.ID < 0) return 0;

// Remove any earlier lower-scoring entries from this same run ID
foreach (RunData existing in HighScores)
{
Expand All @@ -760,12 +806,17 @@ public int addRun(RunData run)
}

int place;
bool added = false;
for (place = 0; place < HighScores.Count; place++)
{
CattleLogger.Message("Place: " + place + " Existing: " + HighScores[place].Score + " Comparing: " + run.Score);
if (!run.betterThan(HighScores[place])) continue;

CattleLogger.Message("BETTER THAN!");

// Add our score to the list
HighScores.Insert(place, run);
added = true;

// If we bomped some other run down to 11th place then remove it
ClearExtraScores();
Expand All @@ -774,7 +825,7 @@ public int addRun(RunData run)

// Add to bottom of the list if we didn't displace anyone.
// This will also result in a temporary "11th place" for the current run if it didn't beat anyone
if (place == HighScores.Count)
if (!added && (place == HighScores.Count))
{
HighScores.Insert(place, run);
}
Expand All @@ -789,6 +840,8 @@ public int addRun(RunData run)

public void SaveStats()
{
if (DeathRun.patchFailed) return;

try
{
var settings = new JsonSerializerSettings
Expand Down
Loading

0 comments on commit d7dc2ba

Please sign in to comment.