diff --git a/NewHorizons/Assets/translations/english.json b/NewHorizons/Assets/translations/english.json index d844ac63..9d1a4c28 100644 --- a/NewHorizons/Assets/translations/english.json +++ b/NewHorizons/Assets/translations/english.json @@ -48,6 +48,18 @@ "NH_VESSEL_WARP": { "Name": "Lore Accurate", "Description": "Warp to a star system using the Vessel." + }, + "NH_RAFTING": { + "Name": "The Raft and the Furious", + "Description": "Go rafting." + }, + "NH_SUCKED_INTO_LAVA_BY_TORNADO": { + "Name": "Dieclone", + "Description": "Get sucked into lava by a tornado." + }, + "NH_TALK_TO_FIVE_CHARACTERS": { + "Name": "Society", + "Description": "Talk to 5 characters." } } } diff --git a/NewHorizons/Builder/Props/DialogueBuilder.cs b/NewHorizons/Builder/Props/DialogueBuilder.cs index 738f9da8..d4b5c844 100644 --- a/NewHorizons/Builder/Props/DialogueBuilder.cs +++ b/NewHorizons/Builder/Props/DialogueBuilder.cs @@ -6,6 +6,7 @@ using System.Xml; using UnityEngine; using NewHorizons.Utility; using Logger = NewHorizons.Utility.Logger; +using NewHorizons.Components; namespace NewHorizons.Builder.Props { @@ -114,7 +115,7 @@ namespace NewHorizons.Builder.Props interact.enabled = false; } - var dialogueTree = conversationZone.AddComponent(); + var dialogueTree = conversationZone.AddComponent(); var xml = File.ReadAllText(Path.Combine(mod.Manifest.ModFolderPath, info.xmlFile)); var text = new TextAsset(xml) diff --git a/NewHorizons/Builder/Props/RaftBuilder.cs b/NewHorizons/Builder/Props/RaftBuilder.cs index dbfc80ee..ae27cea2 100644 --- a/NewHorizons/Builder/Props/RaftBuilder.cs +++ b/NewHorizons/Builder/Props/RaftBuilder.cs @@ -1,4 +1,5 @@ using NewHorizons.Components; +using NewHorizons.Components.Achievement; using NewHorizons.Components.Volumes; using NewHorizons.External.Modules; using NewHorizons.Handlers; @@ -78,6 +79,16 @@ namespace NewHorizons.Builder.Props sector.OnSectorOccupantsUpdated += lightSensor.OnSectorOccupantsUpdated; } + var achievementObject = new GameObject("AchievementVolume"); + achievementObject.transform.SetParent(raftObject.transform, false); + + var shape = achievementObject.AddComponent(); + shape.radius = 3; + shape.SetCollisionMode(Shape.CollisionMode.Volume); + + achievementObject.AddComponent()._shape = shape; + achievementObject.AddComponent(); + raftObject.SetActive(true); return raftObject; diff --git a/NewHorizons/Components/NHCharacterDialogueTree.cs b/NewHorizons/Components/NHCharacterDialogueTree.cs new file mode 100644 index 00000000..c68c85f4 --- /dev/null +++ b/NewHorizons/Components/NHCharacterDialogueTree.cs @@ -0,0 +1,6 @@ +namespace NewHorizons.Components +{ + public class NHCharacterDialogueTree : CharacterDialogueTree + { + } +} diff --git a/NewHorizons/External/NewHorizonsData.cs b/NewHorizons/External/NewHorizonsData.cs index 2a2c8c5d..ea787b2b 100644 --- a/NewHorizons/External/NewHorizonsData.cs +++ b/NewHorizons/External/NewHorizonsData.cs @@ -83,12 +83,14 @@ namespace NewHorizons.External KnownSignals = new List(); NewlyRevealedFactIDs = new List(); PopupsRead = new List(); + CharactersTalkedTo = new List(); } public List KnownFrequencies { get; } public List KnownSignals { get; } public List NewlyRevealedFactIDs { get; } public List PopupsRead { get; } + public List CharactersTalkedTo { get; } } #region Frequencies @@ -172,5 +174,28 @@ namespace NewHorizons.External } #endregion + + #region Characters talked to + + public static void OnTalkedToCharacter(string name) + { + if (name == CharacterDialogueTree.RECORDING_NAME || name == CharacterDialogueTree.SIGN_NAME) return; + _activeProfile?.CharactersTalkedTo.SafeAdd(name); + Save(); + } + + public static bool HasTalkedToFiveCharacters() + { + if (_activeProfile == null) return false; + return _activeProfile.CharactersTalkedTo.Count >= 5; + } + + public static int GetCharactersTalkedTo() + { + if (_activeProfile == null) return 0; + return _activeProfile.CharactersTalkedTo.Count; + } + + #endregion } } \ No newline at end of file diff --git a/NewHorizons/OtherMods/AchievementsPlus/AchievementHandler.cs b/NewHorizons/OtherMods/AchievementsPlus/AchievementHandler.cs index 32942654..89355b4b 100644 --- a/NewHorizons/OtherMods/AchievementsPlus/AchievementHandler.cs +++ b/NewHorizons/OtherMods/AchievementsPlus/AchievementHandler.cs @@ -39,6 +39,9 @@ namespace NewHorizons.OtherMods.AchievementsPlus NH.EatenOutsideBrambleAchievement.Init(); NH.NewFrequencyAchievement.Init(); NH.ProbeLostAchievement.Init(); + NH.RaftingAchievement.Init(); + NH.TalkToFiveCharactersAchievement.Init(); + NH.SuckedIntoLavaByTornadoAchievement.Init(); API.RegisterTranslationsFromFiles(Main.Instance, "Assets/translations"); @@ -87,6 +90,27 @@ namespace NewHorizons.OtherMods.AchievementsPlus API.RegisterAchievement(unique_id, secret, mod); } + public static bool HasAchievement(string unique_id) + { + if (!Enabled) return false; + + return API.HasAchievement(unique_id); + } + + public static void UpdateProgess(string unique_id, int current, int final, bool showPopup) + { + if (!Enabled) return; + + API.UpdateProgress(unique_id, current, final, showPopup); + } + + public static int GetProgress(string unique_id) + { + if (!Enabled) return 0; + + return API.GetProgress(unique_id); + } + public static void OnLearnSignal() { if (!Enabled) return; diff --git a/NewHorizons/OtherMods/AchievementsPlus/IAchievements.cs b/NewHorizons/OtherMods/AchievementsPlus/IAchievements.cs index 9572ca1e..349002e2 100644 --- a/NewHorizons/OtherMods/AchievementsPlus/IAchievements.cs +++ b/NewHorizons/OtherMods/AchievementsPlus/IAchievements.cs @@ -9,5 +9,7 @@ namespace NewHorizons.OtherMods.AchievementsPlus void RegisterTranslationsFromFiles(ModBehaviour mod, string folderPath); void EarnAchievement(string uniqueID); bool HasAchievement(string uniqueID); + void UpdateProgress(string uniqueID, int current, int final, bool showPopup); + int GetProgress(string uniqueID); } } diff --git a/NewHorizons/OtherMods/AchievementsPlus/NH/RaftingAchievement.cs b/NewHorizons/OtherMods/AchievementsPlus/NH/RaftingAchievement.cs new file mode 100644 index 00000000..8fd2a23e --- /dev/null +++ b/NewHorizons/OtherMods/AchievementsPlus/NH/RaftingAchievement.cs @@ -0,0 +1,29 @@ +using NewHorizons.Components.Achievement; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.OtherMods.AchievementsPlus.NH +{ + public class RaftingAchievement : AchievementVolume + { + public static readonly string UNIQUE_ID = "NH_RAFTING"; + + private void Awake() + { + achievementID = UNIQUE_ID; + } + + public static void Init() + { + AchievementHandler.Register(UNIQUE_ID, false, Main.Instance); + } + + public static void Earn() + { + AchievementHandler.Earn(UNIQUE_ID); + } + } +} diff --git a/NewHorizons/OtherMods/AchievementsPlus/NH/SuckedIntoLavaByTornadoAchievement.cs b/NewHorizons/OtherMods/AchievementsPlus/NH/SuckedIntoLavaByTornadoAchievement.cs new file mode 100644 index 00000000..066eed0b --- /dev/null +++ b/NewHorizons/OtherMods/AchievementsPlus/NH/SuckedIntoLavaByTornadoAchievement.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.OtherMods.AchievementsPlus.NH +{ + public static class SuckedIntoLavaByTornadoAchievement + { + public static readonly string UNIQUE_ID = "NH_SUCKED_INTO_LAVA_BY_TORNADO"; + + public static void Init() + { + AchievementHandler.Register(UNIQUE_ID, false, Main.Instance); + GlobalMessenger.AddListener("PlayerDeath", OnPlayerDeath); + } + + public static void OnPlayerDeath(DeathType deathType) + { + if (deathType == DeathType.Lava && Locator.GetPlayerDetector().GetComponent()._activeVolumes.Any(fluidVolume => fluidVolume is TornadoFluidVolume or TornadoBaseFluidVolume or HurricaneFluidVolume)) + { + AchievementHandler.Earn(UNIQUE_ID); + } + } + } +} diff --git a/NewHorizons/OtherMods/AchievementsPlus/NH/TalkToFiveCharactersAchievement.cs b/NewHorizons/OtherMods/AchievementsPlus/NH/TalkToFiveCharactersAchievement.cs new file mode 100644 index 00000000..b2947bd7 --- /dev/null +++ b/NewHorizons/OtherMods/AchievementsPlus/NH/TalkToFiveCharactersAchievement.cs @@ -0,0 +1,43 @@ +using NewHorizons.External; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.OtherMods.AchievementsPlus.NH +{ + public static class TalkToFiveCharactersAchievement + { + public static readonly string UNIQUE_ID = "NH_TALK_TO_FIVE_CHARACTERS"; + + public static void Init() + { + AchievementHandler.Register(UNIQUE_ID, false, Main.Instance); + UpdateProgress(false); + if (NewHorizonsData.HasTalkedToFiveCharacters()) Earn(); + } + + public static void OnTalkedToCharacter(string name) + { + NewHorizonsData.OnTalkedToCharacter(name); + if (NewHorizonsData.HasTalkedToFiveCharacters()) + { + UpdateProgress(false); + Earn(); + } + else + UpdateProgress(true); + } + + public static void Earn() + { + AchievementHandler.Earn(UNIQUE_ID); + } + + public static void UpdateProgress(bool showPopup) + { + AchievementHandler.UpdateProgess(UNIQUE_ID, NewHorizonsData.GetCharactersTalkedTo(), 5, showPopup); + } + } +} diff --git a/NewHorizons/Patches/AchievementPatches.cs b/NewHorizons/Patches/AchievementPatches.cs new file mode 100644 index 00000000..5c1a21ed --- /dev/null +++ b/NewHorizons/Patches/AchievementPatches.cs @@ -0,0 +1,43 @@ +using HarmonyLib; +using NewHorizons.Components; +using NewHorizons.OtherMods.AchievementsPlus.NH; +using System.Linq; +using UnityEngine; + +namespace NewHorizons.Patches +{ + [HarmonyPatch] + public static class AchievementPatches + { + [HarmonyPrefix] + [HarmonyPatch(typeof(ProbeDestructionDetector), nameof(ProbeDestructionDetector.FixedUpdate))] + public static bool ProbeDestructionDetector_FixedUpdate(ProbeDestructionDetector __instance) + { + if (__instance._activeVolumes.Count > 0 && __instance._safetyVolumes.Count == 0) + { + if (LoadManager.GetCurrentScene() == OWScene.EyeOfTheUniverse) + { + DialogueConditionManager.SharedInstance.SetConditionState("PROBE_ENTERED_EYE", conditionState: true); + Debug.Log("PROBE DESTROYED (ENTERED THE EYE)"); + } + else + Debug.Log("PROBE DESTROYED"); + + ProbeLostAchievement.Earn(); + Object.Destroy(__instance._probe.gameObject); + } + __instance.enabled = false; + return false; + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(CharacterDialogueTree), nameof(CharacterDialogueTree.StartConversation))] + public static void CharacterDialogueTree_StartConversation(CharacterDialogueTree __instance) + { + if (__instance is NHCharacterDialogueTree) + { + TalkToFiveCharactersAchievement.OnTalkedToCharacter(__instance._characterName); + } + } + } +}