Skip to content

Commit

Permalink
Add support for syncing dark fog settings in lobby and combat setting…
Browse files Browse the repository at this point in the history
…s screen.
  • Loading branch information
AJH16 committed Dec 16, 2023
1 parent 6dd5d62 commit 96b3d52
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 3 deletions.
30 changes: 30 additions & 0 deletions NebulaModel/Packets/Session/LobbyUpdateCombatValues.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace NebulaModel.Packets.Session
{
public class LobbyUpdateCombatValues
{
public LobbyUpdateCombatValues() { }

public LobbyUpdateCombatValues(CombatSettings combatSettings)
{
CombatAggressiveness = combatSettings.aggressiveness;
CombatInitialLevel = combatSettings.initialLevel;
CombatInitialGrowth = combatSettings.initialGrowth;
CombatInitialColonize = combatSettings.initialColonize;
CombatMaxDensity = combatSettings.maxDensity;
CombatGrowthSpeedFactor = combatSettings.growthSpeedFactor;
CombatPowerThreatFactor = combatSettings.powerThreatFactor;
CombatBattleThreatFactor = combatSettings.battleThreatFactor;
CombatBattleExpFactor = combatSettings.battleExpFactor;
}

public float CombatAggressiveness { get; set; }
public float CombatInitialLevel { get; set; }
public float CombatInitialGrowth { get; set; }
public float CombatInitialColonize { get; set; }
public float CombatMaxDensity { get; set; }
public float CombatGrowthSpeedFactor { get; set; }
public float CombatPowerThreatFactor { get; set; }
public float CombatBattleThreatFactor { get; set; }
public float CombatBattleExpFactor { get; set; }
}
}
22 changes: 21 additions & 1 deletion NebulaModel/Packets/Session/LobbyUpdateValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,38 @@ public class LobbyUpdateValues
{
public LobbyUpdateValues() { }

public LobbyUpdateValues(int galaxyAlgo, int galaxySeed, int starCount, float resourceMultiplier, bool isSandboxMode)
public LobbyUpdateValues(int galaxyAlgo, int galaxySeed, int starCount, float resourceMultiplier, bool isSandboxMode, bool isPeaceMode, CombatSettings combatSettings)
{
GalaxyAlgo = galaxyAlgo;
GalaxySeed = galaxySeed;
StarCount = starCount;
ResourceMultiplier = resourceMultiplier;
IsSandboxMode = isSandboxMode;
IsPeaceMode = isPeaceMode;
CombatAggressiveness = combatSettings.aggressiveness;
CombatInitialLevel = combatSettings.initialLevel;
CombatInitialGrowth = combatSettings.initialGrowth;
CombatInitialColonize = combatSettings.initialColonize;
CombatMaxDensity = combatSettings.maxDensity;
CombatGrowthSpeedFactor = combatSettings.growthSpeedFactor;
CombatPowerThreatFactor = combatSettings.powerThreatFactor;
CombatBattleThreatFactor = combatSettings.battleThreatFactor;
CombatBattleExpFactor = combatSettings.battleExpFactor;
}

public int GalaxyAlgo { get; set; }
public int GalaxySeed { get; set; }
public int StarCount { get; set; }
public float ResourceMultiplier { get; set; }
public bool IsSandboxMode { get; set; }
public bool IsPeaceMode { get; set; }
public float CombatAggressiveness { get; set; }
public float CombatInitialLevel { get; set; }
public float CombatInitialGrowth { get; set; }
public float CombatInitialColonize { get; set; }
public float CombatMaxDensity { get; set; }
public float CombatGrowthSpeedFactor { get; set; }
public float CombatPowerThreatFactor { get; set; }
public float CombatBattleThreatFactor { get; set; }
public float CombatBattleExpFactor { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#region

using NebulaAPI.Packets;
using NebulaModel.Networking;
using NebulaModel.Packets;
using NebulaModel.Packets.Session;

#endregion

namespace NebulaNetwork.PacketProcessors.Session
{
[RegisterPacketProcessor]
internal class LobbyUpdateCombatValuesProcessor:PacketProcessor<LobbyUpdateCombatValues>

Check warning on line 13 in NebulaNetwork/PacketProcessors/Session/LobbyUpdateCombatValuesProcessor.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check warning on line 13 in NebulaNetwork/PacketProcessors/Session/LobbyUpdateCombatValuesProcessor.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check warning on line 13 in NebulaNetwork/PacketProcessors/Session/LobbyUpdateCombatValuesProcessor.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check warning on line 13 in NebulaNetwork/PacketProcessors/Session/LobbyUpdateCombatValuesProcessor.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
{
protected override void ProcessPacket(LobbyUpdateCombatValues packet, NebulaConnection conn)
{
if (IsHost)
{
return;
}

var gameDesc = UIRoot.instance.galaxySelect.gameDesc;
if (!gameDesc.isPeaceMode)
{
gameDesc.combatSettings.aggressiveness = packet.CombatAggressiveness;
gameDesc.combatSettings.initialLevel = packet.CombatInitialLevel;
gameDesc.combatSettings.initialGrowth = packet.CombatInitialGrowth;
gameDesc.combatSettings.initialColonize = packet.CombatInitialColonize;
gameDesc.combatSettings.maxDensity = packet.CombatMaxDensity;
gameDesc.combatSettings.growthSpeedFactor = packet.CombatGrowthSpeedFactor;
gameDesc.combatSettings.powerThreatFactor = packet.CombatPowerThreatFactor;
gameDesc.combatSettings.battleThreatFactor = packet.CombatBattleThreatFactor;
gameDesc.combatSettings.battleExpFactor = packet.CombatBattleExpFactor;
}

UIRoot.instance.galaxySelect.gameDesc = gameDesc;
UIRoot.instance.galaxySelect.SetStarmapGalaxy();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ protected override void ProcessPacket(LobbyUpdateValues packet, NebulaConnection
var gameDesc = new GameDesc();
gameDesc.SetForNewGame(packet.GalaxyAlgo, packet.GalaxySeed, packet.StarCount, 1, packet.ResourceMultiplier);
gameDesc.isSandboxMode = packet.IsSandboxMode;
gameDesc.isPeaceMode = packet.IsPeaceMode;
if (!packet.IsPeaceMode)
{
gameDesc.combatSettings.aggressiveness = packet.CombatAggressiveness;
gameDesc.combatSettings.initialLevel = packet.CombatInitialLevel;
gameDesc.combatSettings.initialGrowth = packet.CombatInitialGrowth;
gameDesc.combatSettings.initialColonize = packet.CombatInitialColonize;
gameDesc.combatSettings.maxDensity = packet.CombatMaxDensity;
gameDesc.combatSettings.growthSpeedFactor = packet.CombatGrowthSpeedFactor;
gameDesc.combatSettings.powerThreatFactor = packet.CombatPowerThreatFactor;
gameDesc.combatSettings.battleThreatFactor = packet.CombatBattleThreatFactor;
gameDesc.combatSettings.battleExpFactor = packet.CombatBattleExpFactor;
}

UIRoot.instance.galaxySelect.gameDesc = gameDesc;
UIRoot.instance.galaxySelect.SetStarmapGalaxy();
Expand Down
46 changes: 46 additions & 0 deletions NebulaPatcher/Patches/Dynamic/UICombatSettingsDF_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#region

using System.Diagnostics.CodeAnalysis;
using HarmonyLib;
using NebulaModel;
using NebulaModel.Logger;
using NebulaModel.Packets.Session;
using NebulaPatcher.Patches.Transpilers;
using NebulaWorld;
using UnityEngine;
using UnityEngine.UI;

#endregion

namespace NebulaPatcher.Patches.Dynamic
{
[HarmonyPatch(typeof(UICombatSettingsDF))]
internal class UICombatSettingsDF_Patch
{
[HarmonyPostfix]
[HarmonyPatch(nameof(UICombatSettingsDF.ApplySettings))]
public static void ApplySettings_Postfix(UICombatSettingsDF __instance)
{
if (!Multiplayer.IsInMultiplayerMenu || !Multiplayer.Session.LocalPlayer.IsHost)
{
return;
}
// syncing players are those who have not loaded into the game yet, so they might still be in the lobby. they need to check if this packet is relevant for them in the corresponding handler.
// just remembered others cant be in game anyways when host ist still in lobby >.>
using (Multiplayer.Session.Network.PlayerManager.GetSyncingPlayers(out var syncingPlayers))
{
foreach (var entry in syncingPlayers)
{
entry.Key.SendPacket(new LobbyUpdateCombatValues(__instance.gameDesc.combatSettings));
}
}
using (Multiplayer.Session.Network.PlayerManager.GetPendingPlayers(out var pendingPlayers))
{
foreach (var entry in pendingPlayers)
{
entry.Key.SendPacket(new LobbyUpdateCombatValues(__instance.gameDesc.combatSettings));
}
}
}
}
}
6 changes: 4 additions & 2 deletions NebulaPatcher/Patches/Dynamic/UIGalaxySelect_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static void _OnOpen_Postfix(UIGalaxySelect __instance)
galaxySelectRect.Find("property-multiplier").gameObject.SetActive(false);
galaxySelectRect.Find("seed-key").gameObject.SetActive(false);
galaxySelectRect.Find("sandbox-mode").gameObject.SetActive(false);
galaxySelectRect.Find("DF-toggle").gameObject.SetActive(false);
}
if (!Multiplayer.IsActive)
{
Expand Down Expand Up @@ -141,6 +142,7 @@ public static void _OnClose_Prefix(UIGalaxySelect __instance)
galaxySelectRect.Find("resource-multiplier").gameObject.SetActive(true);
galaxySelectRect.Find("galaxy-seed").GetComponentInChildren<InputField>().enabled = true;
galaxySelectRect.Find("random-button").gameObject.SetActive(true);
galaxySelectRect.Find("DF-toggle").gameObject.SetActive(true);
}

[HarmonyPrefix]
Expand Down Expand Up @@ -181,7 +183,7 @@ public static void UpdateParametersUIDisplay_Postfix(UIGalaxySelect __instance)
{
entry.Key.SendPacket(new LobbyUpdateValues(__instance.gameDesc.galaxyAlgo, __instance.gameDesc.galaxySeed,
__instance.gameDesc.starCount, __instance.gameDesc.resourceMultiplier,
__instance.gameDesc.isSandboxMode));
__instance.gameDesc.isSandboxMode, __instance.gameDesc.isPeaceMode, __instance.gameDesc.combatSettings));
}
}
using (Multiplayer.Session.Network.PlayerManager.GetPendingPlayers(out var pendingPlayers))
Expand All @@ -190,7 +192,7 @@ public static void UpdateParametersUIDisplay_Postfix(UIGalaxySelect __instance)
{
entry.Key.SendPacket(new LobbyUpdateValues(__instance.gameDesc.galaxyAlgo, __instance.gameDesc.galaxySeed,
__instance.gameDesc.starCount, __instance.gameDesc.resourceMultiplier,
__instance.gameDesc.isSandboxMode));
__instance.gameDesc.isSandboxMode, __instance.gameDesc.isPeaceMode, __instance.gameDesc.combatSettings));
}
}
}
Expand Down

0 comments on commit 96b3d52

Please sign in to comment.