More achievements (#331)

Resolves #203
This commit is contained in:
Noah Pilarski 2022-11-26 18:48:57 -05:00 committed by GitHub
commit 443086c4e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 224 additions and 1 deletions

View File

@ -48,6 +48,18 @@
"NH_VESSEL_WARP": { "NH_VESSEL_WARP": {
"Name": "Lore Accurate", "Name": "Lore Accurate",
"Description": "Warp to a star system using the Vessel." "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."
} }
} }
} }

View File

@ -6,6 +6,7 @@ using System.Xml;
using UnityEngine; using UnityEngine;
using NewHorizons.Utility; using NewHorizons.Utility;
using Logger = NewHorizons.Utility.Logger; using Logger = NewHorizons.Utility.Logger;
using NewHorizons.Components;
namespace NewHorizons.Builder.Props namespace NewHorizons.Builder.Props
{ {
@ -114,7 +115,7 @@ namespace NewHorizons.Builder.Props
interact.enabled = false; interact.enabled = false;
} }
var dialogueTree = conversationZone.AddComponent<CharacterDialogueTree>(); var dialogueTree = conversationZone.AddComponent<NHCharacterDialogueTree>();
var xml = File.ReadAllText(Path.Combine(mod.Manifest.ModFolderPath, info.xmlFile)); var xml = File.ReadAllText(Path.Combine(mod.Manifest.ModFolderPath, info.xmlFile));
var text = new TextAsset(xml) var text = new TextAsset(xml)

View File

@ -1,4 +1,5 @@
using NewHorizons.Components; using NewHorizons.Components;
using NewHorizons.Components.Achievement;
using NewHorizons.Components.Volumes; using NewHorizons.Components.Volumes;
using NewHorizons.External.Modules; using NewHorizons.External.Modules;
using NewHorizons.Handlers; using NewHorizons.Handlers;
@ -78,6 +79,16 @@ namespace NewHorizons.Builder.Props
sector.OnSectorOccupantsUpdated += lightSensor.OnSectorOccupantsUpdated; sector.OnSectorOccupantsUpdated += lightSensor.OnSectorOccupantsUpdated;
} }
var achievementObject = new GameObject("AchievementVolume");
achievementObject.transform.SetParent(raftObject.transform, false);
var shape = achievementObject.AddComponent<SphereShape>();
shape.radius = 3;
shape.SetCollisionMode(Shape.CollisionMode.Volume);
achievementObject.AddComponent<OWTriggerVolume>()._shape = shape;
achievementObject.AddComponent<OtherMods.AchievementsPlus.NH.RaftingAchievement>();
raftObject.SetActive(true); raftObject.SetActive(true);
return raftObject; return raftObject;

View File

@ -0,0 +1,6 @@
namespace NewHorizons.Components
{
public class NHCharacterDialogueTree : CharacterDialogueTree
{
}
}

View File

@ -83,12 +83,14 @@ namespace NewHorizons.External
KnownSignals = new List<string>(); KnownSignals = new List<string>();
NewlyRevealedFactIDs = new List<string>(); NewlyRevealedFactIDs = new List<string>();
PopupsRead = new List<string>(); PopupsRead = new List<string>();
CharactersTalkedTo = new List<string>();
} }
public List<string> KnownFrequencies { get; } public List<string> KnownFrequencies { get; }
public List<string> KnownSignals { get; } public List<string> KnownSignals { get; }
public List<string> NewlyRevealedFactIDs { get; } public List<string> NewlyRevealedFactIDs { get; }
public List<string> PopupsRead { get; } public List<string> PopupsRead { get; }
public List<string> CharactersTalkedTo { get; }
} }
#region Frequencies #region Frequencies
@ -172,5 +174,28 @@ namespace NewHorizons.External
} }
#endregion #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
} }
} }

View File

@ -39,6 +39,9 @@ namespace NewHorizons.OtherMods.AchievementsPlus
NH.EatenOutsideBrambleAchievement.Init(); NH.EatenOutsideBrambleAchievement.Init();
NH.NewFrequencyAchievement.Init(); NH.NewFrequencyAchievement.Init();
NH.ProbeLostAchievement.Init(); NH.ProbeLostAchievement.Init();
NH.RaftingAchievement.Init();
NH.TalkToFiveCharactersAchievement.Init();
NH.SuckedIntoLavaByTornadoAchievement.Init();
API.RegisterTranslationsFromFiles(Main.Instance, "Assets/translations"); API.RegisterTranslationsFromFiles(Main.Instance, "Assets/translations");
@ -87,6 +90,27 @@ namespace NewHorizons.OtherMods.AchievementsPlus
API.RegisterAchievement(unique_id, secret, mod); 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() public static void OnLearnSignal()
{ {
if (!Enabled) return; if (!Enabled) return;

View File

@ -9,5 +9,7 @@ namespace NewHorizons.OtherMods.AchievementsPlus
void RegisterTranslationsFromFiles(ModBehaviour mod, string folderPath); void RegisterTranslationsFromFiles(ModBehaviour mod, string folderPath);
void EarnAchievement(string uniqueID); void EarnAchievement(string uniqueID);
bool HasAchievement(string uniqueID); bool HasAchievement(string uniqueID);
void UpdateProgress(string uniqueID, int current, int final, bool showPopup);
int GetProgress(string uniqueID);
} }
} }

View File

@ -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);
}
}
}

View File

@ -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<DeathType>.AddListener("PlayerDeath", OnPlayerDeath);
}
public static void OnPlayerDeath(DeathType deathType)
{
if (deathType == DeathType.Lava && Locator.GetPlayerDetector().GetComponent<FluidDetector>()._activeVolumes.Any(fluidVolume => fluidVolume is TornadoFluidVolume or TornadoBaseFluidVolume or HurricaneFluidVolume))
{
AchievementHandler.Earn(UNIQUE_ID);
}
}
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}
}