Skip to content

Commit

Permalink
#4: Add explainer to denied island food.
Browse files Browse the repository at this point in the history
  • Loading branch information
tinyhoot committed Feb 17, 2024
1 parent d4caab4 commit adeba69
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
3 changes: 3 additions & 0 deletions DeathrunRemade/Assets/Localization/English.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
"EncyDesc_Deathrun_AuroraFiltration": "The Aurora features a sophisticated air filtration system. Based on patented Alterra technology, it provides a clean and safe atmosphere onboard the vessel even on long distance journeys, ensuring optimal productivity of Alterra staff.\n\nAlterra advises staff not to pay attention to jealous detractors criticising the supposedly immense power draw of the system.",

"dr_auroraRepairedBreathable": "The air filtration system roars to life!",
"dr_foodChallengeAfter": "The plant is working hard to expel any poison. Check back later.",
"dr_foodChallengeAfterSoon": "The plant is working hard to expel any poison. It is almost done!",
"dr_foodChallengeNever": "The irradiated plant decays at your touch!",
"dr_lifepodHitBottom": "The lifepod has hit bottom!",
"dr_notEnoughCraftPower": "Not enough power (need {0}).",
"dr_vehicleExitPowerLoss": "{0} drained of {1} energy for exiting at {2} depth.",
Expand Down
36 changes: 30 additions & 6 deletions DeathrunRemade/Patches/FoodChallengePatcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using DeathrunRemade.Handlers;
using DeathrunRemade.Objects;
using DeathrunRemade.Objects.Attributes;
using DeathrunRemade.Objects.Enums;
Expand Down Expand Up @@ -83,7 +84,9 @@ private static void ChangeFoodValues(Eatable __instance, ref float __result)
[HarmonyPatch(typeof(Knife), nameof(Knife.GiveResourceOnDamage))]
private static bool CancelKnifeHarvest(GameObject target)
{
bool allowed = AllowPickup(target);
bool allowed = AllowPickup(target, out string explainerKey);
if (!allowed)
NotificationHandler.VanillaMessage(explainerKey);
return allowed;
}

Expand All @@ -96,7 +99,8 @@ private static bool CancelKnifeHarvest(GameObject target)
[HarmonyPatch(typeof(PickPrefab), nameof(PickPrefab.OnHandClick))]
private static bool CancelHandPickup(PickPrefab __instance)
{
return AllowPickup(__instance.gameObject);
// No explainer here since that would happen every single time you look at the plant.
return AllowPickup(__instance.gameObject, out string _);
}

/// <summary>
Expand All @@ -106,7 +110,9 @@ private static bool CancelHandPickup(PickPrefab __instance)
[HarmonyPatch(typeof(PropulsionCannon), nameof(PropulsionCannon.ValidateObject))]
private static bool CancelPropulsionPickup(GameObject go, ref bool __result)
{
__result = AllowPickup(go);
__result = AllowPickup(go, out string explainerKey);
if (!__result)
NotificationHandler.VanillaMessage(explainerKey);
return __result;
}

Expand All @@ -117,30 +123,48 @@ private static bool CancelPropulsionPickup(GameObject go, ref bool __result)
[HarmonyPatch(typeof(RepulsionCannon), nameof(RepulsionCannon.ShootObject))]
private static bool CancelRepulsionShoot(Rigidbody rb)
{
return AllowPickup(rb.gameObject);
return AllowPickup(rb.gameObject, out string _);
}

/// <summary>
/// Check whether the player is allowed to pick up food from the island.
/// </summary>
private static bool AllowPickup(GameObject gameObject)
private static bool AllowPickup(GameObject gameObject, out string explainerKey)
{
RelativeToExplosion difficulty = SaveData.Main.Config.IslandFoodChallenge;
explainerKey = "";
if (difficulty == RelativeToExplosion.Always)
return true;
// These changes only apply to surface plants, so allow any other food. Surface bases are also alright.
if (Ocean.GetDepthOf(gameObject) > 1f || !Plants.Contains(CraftData.GetTechType(gameObject)) || Player.main.IsInsideWalkable())
return true;
if (difficulty == RelativeToExplosion.Never)
{
explainerKey = "dr_foodChallengeNever";
return false;
}

// The Aurora has not exploded yet, so we can rule out this specific case.
if (difficulty == RelativeToExplosion.After
&& (CrashedShipExploder.main == null || !CrashedShipExploder.main.IsExploded()))
{
explainerKey = "dr_foodChallengeNever";
return false;
}

// Both remaining config options are covered with this check.
return !RadiationPatcher.IsSurfaceIrradiated();
bool allowed = !RadiationPatcher.IsSurfaceIrradiated();
if (!RadiationPatcher.IsRadiationFixed())
{
explainerKey = "dr_foodChallengeNever";
}
else
{
// Display a different explainer depending on how much time is left until radiation is completely gone.
float seconds = LeakingRadiation.main.currentRadius / LeakingRadiation.main.kNaturalDissipation;
explainerKey = seconds > 600f ? "dr_foodChallengeAfter" : "dr_foodChallengeAfterSoon";
}
return allowed;
}
}
}

0 comments on commit adeba69

Please sign in to comment.