Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Nebula-specific files
DevEnv.targets
dist
.agents/


# User-specific files
Expand Down
2 changes: 1 addition & 1 deletion NebulaAPI/GameState/IPlayerData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region
#region

using NebulaAPI.DataStructures;
using NebulaAPI.Interfaces;
Expand Down
6 changes: 4 additions & 2 deletions NebulaModel/DataStructures/MechaData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region
#region

using System.IO;
using NebulaAPI.DataStructures;
Expand All @@ -17,6 +17,7 @@ public MechaData()
{
// This is needed for the serialization and deserialization
Forge = new MechaForge { tasks = [] };
FightData = new MechaFightData();
TechBonuses = new PlayerTechBonuses();
}

Expand Down Expand Up @@ -133,6 +134,7 @@ public void UpdateMech(Player destination)
public void Import(INetDataReader reader, int revision)
{
TechBonuses = new PlayerTechBonuses();
FightData = new MechaFightData();
Inventory = new StorageComponent(4);
DeliveryPackage = new DeliveryPackage();
DeliveryPackage.Init();
Expand All @@ -141,7 +143,7 @@ public void Import(INetDataReader reader, int revision)
Forge = new MechaForge { tasks = [], extraItems = new ItemBundle() };
ConstructionModule = new ConstructionModuleComponent();
TechBonuses.Import(reader, revision);
SandCount = reader.GetInt();
SandCount = revision >= 8 ? reader.GetLong() : reader.GetInt();
CoreEnergy = reader.GetDouble();
ReactorEnergy = reader.GetDouble();
var isPayloadPresent = reader.GetBool();
Expand Down
82 changes: 80 additions & 2 deletions NebulaModel/DataStructures/PlayerData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region
#region

using System;
using System.IO;
Expand All @@ -20,6 +20,8 @@ public PlayerData()
DIYAppearance = null;
DIYItemId = Array.Empty<int>();
DIYItemValue = Array.Empty<int>();
DashboardData = null;
ReplicatorMultipliersData = null;
}

public PlayerData(ushort playerId, int localPlanetId, string username = null, Float3 localPlanetPosition = new(),
Expand All @@ -37,6 +39,8 @@ public PlayerData()
DIYAppearance = null;
DIYItemId = Array.Empty<int>();
DIYItemValue = Array.Empty<int>();
DashboardData = null;
ReplicatorMultipliersData = null;
}

public string Username { get; set; }
Expand All @@ -52,6 +56,8 @@ public PlayerData()
public MechaAppearance DIYAppearance { get; set; }
public int[] DIYItemId { get; set; }
public int[] DIYItemValue { get; set; }
public byte[] DashboardData { get; set; }
public byte[] ReplicatorMultipliersData { get; set; }

public void Serialize(INetDataWriter writer)
{
Expand Down Expand Up @@ -93,6 +99,18 @@ public void Serialize(INetDataWriter writer)
writer.Put(DIYItemId[i]);
writer.Put(DIYItemValue[i]);
}
writer.Put(DashboardData != null);
if (DashboardData != null)
{
writer.Put(DashboardData.Length);
writer.Put(DashboardData);
}
writer.Put(ReplicatorMultipliersData != null);
if (ReplicatorMultipliersData != null)
{
writer.Put(ReplicatorMultipliersData.Length);
writer.Put(ReplicatorMultipliersData);
}
}

public void Deserialize(INetDataReader reader)
Expand Down Expand Up @@ -138,11 +156,43 @@ public void Deserialize(INetDataReader reader)
DIYItemId[i] = reader.GetInt();
DIYItemValue[i] = reader.GetInt();
}
var isDashboardPresent = reader.GetBool();
if (isDashboardPresent)
{
var len = reader.GetInt();
DashboardData = new byte[len];
reader.GetBytes(DashboardData, len);
}
else
{
DashboardData = null;
}
if (reader.AvailableBytes > 0)
{
var isMultipliersPresent = reader.GetBool();
if (isMultipliersPresent)
{
var len = reader.GetInt();
ReplicatorMultipliersData = new byte[len];
reader.GetBytes(ReplicatorMultipliersData, len);
}
else
{
ReplicatorMultipliersData = null;
}
}
else
{
ReplicatorMultipliersData = null;
}
}

public IPlayerData CreateCopyWithoutMechaData()
{
return new PlayerData(PlayerId, LocalPlanetId, Username, LocalPlanetPosition, UPosition, Rotation, BodyRotation);
var copy = new PlayerData(PlayerId, LocalPlanetId, Username, LocalPlanetPosition, UPosition, Rotation, BodyRotation);
copy.DashboardData = DashboardData;
copy.ReplicatorMultipliersData = ReplicatorMultipliersData;
return copy;
}

// Backward compatiblity for older versions
Expand Down Expand Up @@ -208,5 +258,33 @@ public void Import(INetDataReader reader, int revision)
DIYItemValue[i] = reader.GetInt();
}
}
if (revision >= 9 && reader.AvailableBytes > 0)
{
var isDashboardPresent = reader.GetBool();
if (isDashboardPresent)
{
var len = reader.GetInt();
DashboardData = new byte[len];
reader.GetBytes(DashboardData, len);
}
else
{
DashboardData = null;
}
}
if (revision >= 9 && reader.AvailableBytes > 0)
{
var isMultipliersPresent = reader.GetBool();
if (isMultipliersPresent)
{
var len = reader.GetInt();
ReplicatorMultipliersData = new byte[len];
reader.GetBytes(ReplicatorMultipliersData, len);
}
else
{
ReplicatorMultipliersData = null;
}
}
}
}
13 changes: 13 additions & 0 deletions NebulaModel/Packets/GameHistory/GameHistoryUnlockTutorialPacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace NebulaModel.Packets.GameHistory;

public class GameHistoryUnlockTutorialPacket
{
public GameHistoryUnlockTutorialPacket() { }

public GameHistoryUnlockTutorialPacket(int tutorialId)
{
TutorialId = tutorialId;
}

public int TutorialId { get; set; }
}
15 changes: 15 additions & 0 deletions NebulaModel/Packets/Players/PlayerDashboardPacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace NebulaModel.Packets.Players;

public class PlayerDashboardPacket
{
public PlayerDashboardPacket() { }

public PlayerDashboardPacket(ushort playerId, byte[] dashboardData)
{
PlayerId = playerId;
DashboardData = dashboardData;
}

public ushort PlayerId { get; set; }
public byte[] DashboardData { get; set; }
}
15 changes: 15 additions & 0 deletions NebulaModel/Packets/Players/PlayerReplicatorMultipliersPacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace NebulaModel.Packets.Players;

public class PlayerReplicatorMultipliersPacket
{
public PlayerReplicatorMultipliersPacket() { }

public PlayerReplicatorMultipliersPacket(ushort playerId, byte[] multipliersData)
{
PlayerId = playerId;
MultipliersData = multipliersData;
}

public ushort PlayerId { get; set; }
public byte[] MultipliersData { get; set; }
}
19 changes: 19 additions & 0 deletions NebulaModel/Packets/Statistics/StatisticsPowerDataPacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace NebulaModel.Packets.Statistics;

/// <summary>
/// Carries the vanilla power statistics (generation capacities, consumption demands,
/// totals and build counts) so clients can render the unmodified Power Dashboard.
/// </summary>
public class StatisticsPowerDataPacket
{
public StatisticsPowerDataPacket() { }

public StatisticsPowerDataPacket(int astroFilter, byte[] powerBinaryData)
{
AstroFilter = astroFilter;
PowerBinaryData = powerBinaryData;
}

public int AstroFilter { get; set; }
public byte[] PowerBinaryData { get; set; }
}
6 changes: 5 additions & 1 deletion NebulaModel/Packets/Universe/DysonSphereStatusPacket.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region
#region

using NebulaAPI.Packets;

Expand All @@ -13,6 +13,10 @@ public DysonSphereStatusPacket() { }

public DysonSphereStatusPacket(DysonSphere dysonSphere)
{
if (dysonSphere?.starData == null)
{
return;
}
StarIndex = dysonSphere.starData.index;
GrossRadius = dysonSphere.grossRadius;
EnergyReqCurrentTick = dysonSphere.energyReqCurrentTick;
Expand Down
4 changes: 2 additions & 2 deletions NebulaNetwork/Client.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region
#region

using System;
using System.IO;
Expand Down Expand Up @@ -82,7 +82,7 @@ public void Start()
PacketUtils.RegisterAllPacketProcessorsInAssembly(assembly, PacketProcessor as NebulaNetPacketProcessor, false);
}
#if DEBUG
PacketProcessor.SimulateLatency = true;
PacketProcessor.SimulateLatency = false;
#endif

clientSocket = new WebSocket($"{serverProtocol}://{ServerEndpoint}/socket");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region
#region

using NebulaAPI.Packets;
using NebulaModel.Networking;
Expand All @@ -13,8 +13,16 @@ namespace NebulaNetwork.PacketProcessors.GameHistory;
[RegisterPacketProcessor]
public class GameHistoryFeatureKeyProcessor : PacketProcessor<GameHistoryFeatureKeyPacket>
{
private const int MAX_ADVISOR_TIP_ID = FeatureID.ADVISOR_TIP_USED_START - FeatureID.ADVISOR_TIP_START; // 1000
private const int ADVISOR_TIP_USED_END = FeatureID.ADVISOR_TIP_USED_START + MAX_ADVISOR_TIP_ID; // 2002000

protected override void ProcessPacket(GameHistoryFeatureKeyPacket packet, NebulaConnection conn)
{
if (packet == null)
{
return;
}

if (IsHost)
{
Multiplayer.Session.Network.SendPacketExclude(packet, conn);
Expand All @@ -24,11 +32,24 @@ protected override void ProcessPacket(GameHistoryFeatureKeyPacket packet, Nebula
{
if (packet.Add)
{
GameMain.data.history.RegFeatureKey(packet.FeatureId);
GameMain.data?.history?.RegFeatureKey(packet.FeatureId);

if (packet.FeatureId >= FeatureID.ADVISOR_TIP_START && packet.FeatureId < FeatureID.ADVISOR_TIP_USED_START)
{
int tipId = packet.FeatureId - FeatureID.ADVISOR_TIP_START;
GameMain.gameScenario?.advisorLogic?.SetAdvisorTipFinished(tipId);
DismissAdvisorTipUI(tipId);
}
else if (packet.FeatureId >= FeatureID.ADVISOR_TIP_USED_START && packet.FeatureId < ADVISOR_TIP_USED_END)
{
int tipId = packet.FeatureId - FeatureID.ADVISOR_TIP_USED_START;
GameMain.gameScenario?.advisorLogic?.SetAdvisorTipUsed(tipId);
DismissAdvisorTipUI(tipId);
}
}
else
{
GameMain.data.history.UnregFeatureKey(packet.FeatureId);
GameMain.data?.history?.UnregFeatureKey(packet.FeatureId);
}

if (packet.FeatureId == 1100002)
Expand All @@ -39,4 +60,23 @@ protected override void ProcessPacket(GameHistoryFeatureKeyPacket packet, Nebula
}
}
}

private static void DismissAdvisorTipUI(int tipId)
{
var advisorTip = UIRoot.instance?.uiGame?.advisorTip;
if (advisorTip == null)
{
return;
}

if (advisorTip.playingTip?.ID == tipId)
{
advisorTip.StopAdvisorTip();
}
advisorTip.requests?.RemoveAll(id => id == tipId);
if (advisorTip.nextTip?.ID == tipId)
{
advisorTip.nextTip = null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#region

using NebulaAPI.Packets;
using NebulaModel.Networking;
using NebulaModel.Packets;
using NebulaModel.Packets.GameHistory;
using NebulaWorld;

#endregion

namespace NebulaNetwork.PacketProcessors.GameHistory;

[RegisterPacketProcessor]
public class GameHistoryUnlockTutorialProcessor : PacketProcessor<GameHistoryUnlockTutorialPacket>
{
protected override void ProcessPacket(GameHistoryUnlockTutorialPacket packet, NebulaConnection conn)
{
if (packet == null || packet.TutorialId <= 0)
{
return;
}

if (IsHost)
{
Multiplayer.Session.Network.SendPacketExclude(packet, conn);
}

using (Multiplayer.Session.History.IsIncomingRequest.On())
{
GameMain.data?.history?.UnlockTutorial(packet.TutorialId);
UIRoot.instance?.uiGame?.tutorialTip?.CloseTip(packet.TutorialId);
}
}
}
Loading