Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix only one faction having access to Anomaly research in Multifaction #496

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Source/Client/Comp/World/MultiplayerWorldComp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ void RemoveOpponentFaction()
AddSpectatorFaction();
RemoveOpponentFaction();
}

// Fix old save files by ensuring all factions have access to Anomaly research if
// it was enabled. This needs to be done since Anomaly state is shared by all players.
var anomaly = Find.Anomaly;
// Don't use anomaly.Level, as it'll return 0 due to monolith not being
// spawned. If we want to include that check then we'd need to move this
// code into a postfix to Building_VoidMonolith:SpawnSetup.
if (anomaly.level > 0 && anomaly.monolith != null)
{
foreach (var (_, data) in factionData)
data.researchManager.Notify_MonolithLevelChanged(anomaly.level);
}
}

private void ExposeFactionData()
Expand Down
4 changes: 4 additions & 0 deletions Source/Client/Factions/FactionCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ private static void InitNewGame()
{
PawnUtility.GiveAllStartingPlayerPawnsThought(ThoughtDefOf.NewColonyOptimism);
ResearchUtility.ApplyPlayerStartingResearch();
// Initialize anomaly. Since the Anomaly comp is currently shared by all players,
// we need to ensure that any new factions have access to anomaly research if
// anomaly content was started.
Find.ResearchManager.Notify_MonolithLevelChanged(Find.Anomaly.Level);
}

private static void PrepareGameInitData(int sessionId)
Expand Down
14 changes: 14 additions & 0 deletions Source/Client/Factions/FactionRepeater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,18 @@ ref ignore
);
}

[HarmonyPatch(typeof(ResearchManager), nameof(ResearchManager.Notify_MonolithLevelChanged))]
static class MonolithLevelChangedPatch
{
static bool ignore;

static bool Prefix(int newLevel) =>
FactionRepeater.Template(
Multiplayer.game?.worldComp.factionData,
d => d.researchManager.Notify_MonolithLevelChanged(newLevel),
null,
ref ignore
);
}

}
8 changes: 8 additions & 0 deletions Source/Client/Networking/HostUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ private static void SetupGameFromSingleplayer()

factionData.researchManager.progress = new(playerFactionData.researchManager.progress);
factionData.researchManager.techprints = new(playerFactionData.researchManager.techprints);
factionData.researchManager.anomalyKnowledge = new(playerFactionData.researchManager.anomalyKnowledge);
factionData.researchManager.currentAnomalyKnowledgeProjects = new(playerFactionData.researchManager.currentAnomalyKnowledgeProjects ?? Enumerable.Empty<ResearchManager.KnowledgeCategoryProject>());
factionData.researchManager.tabInfoVisibility = new();
if (playerFactionData.researchManager.tabInfoVisibility != null)
{
foreach (var (def, value) in playerFactionData.researchManager.tabInfoVisibility)
factionData.researchManager.tabInfoVisibility[def] = value;
}
}

foreach (FactionWorldData data in worldComp.factionData.Values)
Expand Down
Loading