Skip to content

Commit 1e92d30

Browse files
authored
Merge pull request #747 from starfi5h/pr-update
Sync p2p route and pairing tab. Fix bugs
2 parents 51ff7cc + 72fef51 commit 1e92d30

14 files changed

Lines changed: 580 additions & 12 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace NebulaModel.Packets.Logistics.ControlPanel;
5+
6+
public class LCPStationNameSearchPacket
7+
{
8+
public LCPStationNameSearchPacket() { }
9+
10+
public string SearchString { get; set; }
11+
public bool IsExact { get; set; }
12+
public int LocalPlanetId { get; set; }
13+
public int[] ResultGids { get; set; }
14+
public string[] ResultNames { get; set; }
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace NebulaModel.Packets.Logistics.ControlPanel;
2+
3+
public class LCPStationRouteResultsPacket
4+
{
5+
public LCPStationRouteResultsPacket() { }
6+
7+
public int QueryPlanetId { get; set; }
8+
public int QueryStationGid { get; set; }
9+
10+
// Return routeResultCounts, resultPositions, routeResults
11+
public int[] RouteResultCounts { get; set; }
12+
public int[] ResultPositions { get; set; }
13+
14+
// Members of StationRouteResult
15+
public int[] TargetIds { get; set; }
16+
public int[] PairStorageIndexMasks { get; set; }
17+
public int[] PlanetIds { get; set; }
18+
public short[] RouteTypes { get; set; }
19+
public int[] StationIds { get; set; }
20+
public double[] DistanceToInspectorStationSqrs { get; set; }
21+
}

NebulaNetwork/PacketProcessors/Combat/GroundEnemy/DFGKillEnemyProcessor.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ protected override void ProcessPacket(DFGKillEnemyPacket packet, NebulaConnectio
1818
var factory = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory;
1919
if (factory == null || packet.EnemyId >= factory.enemyPool.Length) return;
2020

21+
ref var ptr = ref factory.enemyPool[packet.EnemyId];
22+
var killStatistics = GameMain.data.spaceSector.skillSystem.killStatistics;
2123
if (IsHost)
2224
{
2325
// Alive, broadcast the event to all clients in the system
24-
if (factory.enemyPool[packet.EnemyId].id > 0)
26+
if (ptr.id > 0)
2527
{
28+
killStatistics.RegisterFactoryKillStat(factory.index, ptr.modelIndex);
2629
factory.KillEnemyFinally(packet.EnemyId, ref CombatStat.empty);
2730
}
2831
// If the enemy is already dead, that mean the client is behind and kill event has been sent by the server
@@ -31,15 +34,16 @@ protected override void ProcessPacket(DFGKillEnemyPacket packet, NebulaConnectio
3134
{
3235
using (Multiplayer.Session.Combat.IsIncomingRequest.On())
3336
{
34-
if (factory.enemyPool[packet.EnemyId].id > 0)
37+
if (ptr.id > 0)
3538
{
39+
killStatistics.RegisterFactoryKillStat(factory.index, ptr.modelIndex);
3640
factory.KillEnemyFinally(packet.EnemyId, ref CombatStat.empty);
3741
}
38-
else if (factory.enemyPool[packet.EnemyId].isInvincible) // Mark
42+
else if (ptr.isInvincible) // The marked enemy that waiting for kill approve
3943
{
40-
ref var ptr = ref factory.enemyPool[packet.EnemyId];
4144
ptr.id = packet.EnemyId;
4245
ptr.isInvincible = false;
46+
// kill stat is already registered
4347
factory.KillEnemyFinally(packet.EnemyId, ref CombatStat.empty);
4448
}
4549
}

NebulaNetwork/PacketProcessors/Combat/SpaceEnemy/DFSKillEnemyProcessor.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ protected override void ProcessPacket(DFSKillEnemyPacket packet, NebulaConnectio
1919
var hive = GameMain.spaceSector.GetHiveByAstroId(packet.OriginAstroId);
2020
if (hive == null || packet.EnemyId < 0 || packet.EnemyId >= spaceSector.enemyCursor) return;
2121

22+
ref var ptr = ref spaceSector.enemyPool[packet.EnemyId];
23+
var killStatistics = spaceSector.skillSystem.killStatistics;
2224
if (IsHost)
2325
{
2426
// Alive, broadcast the event to all clients in the system
25-
if (spaceSector.enemyPool[packet.EnemyId].id > 0)
27+
if (ptr.id > 0)
2628
{
29+
killStatistics.RegisterStarKillStat(hive.starData.id, ptr.modelIndex);
2730
spaceSector.KillEnemyFinal(packet.EnemyId, ref CombatStat.empty);
2831
}
2932
// If the enemy is already dead, that mean the client is behind and kill event has been sent by the server
@@ -32,15 +35,16 @@ protected override void ProcessPacket(DFSKillEnemyPacket packet, NebulaConnectio
3235
{
3336
using (Multiplayer.Session.Enemies.IsIncomingRequest.On())
3437
{
35-
if (spaceSector.enemyPool[packet.EnemyId].id > 0)
38+
if (ptr.id > 0)
3639
{
40+
killStatistics.RegisterStarKillStat(hive.starData.id, ptr.modelIndex);
3741
spaceSector.KillEnemyFinal(packet.EnemyId, ref CombatStat.empty);
3842
}
39-
else if (spaceSector.enemyPool[packet.EnemyId].isInvincible) // Mark
43+
else if (ptr.isInvincible) // The marked enemy that waiting for kill approve
4044
{
41-
ref var ptr = ref spaceSector.enemyPool[packet.EnemyId];
4245
ptr.id = packet.EnemyId;
4346
ptr.isInvincible = false;
47+
// kill stat is already registered
4448
spaceSector.KillEnemyFinal(packet.EnemyId, ref CombatStat.empty);
4549
}
4650
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#region
2+
3+
using System.Collections.Generic;
4+
using NebulaAPI.Packets;
5+
using NebulaModel.Networking;
6+
using NebulaModel.Packets;
7+
using NebulaModel.Packets.Logistics.ControlPanel;
8+
using UnityEngine;
9+
10+
#endregion
11+
12+
namespace NebulaNetwork.PacketProcessors.Logistics.ControlPanel;
13+
14+
[RegisterPacketProcessor]
15+
public class LCPStationNameSearchProcessor : PacketProcessor<LCPStationNameSearchPacket>
16+
{
17+
protected override void ProcessPacket(LCPStationNameSearchPacket packet, NebulaConnection conn)
18+
{
19+
if (IsHost)
20+
{
21+
// Modify from UIStationRoutePanel.RefreshSearchEntries
22+
// For all ILS, find the station that custom name that match that search string
23+
var searchString = packet.SearchString;
24+
var isExact = packet.IsExact;
25+
var localPlanetId = packet.LocalPlanetId;
26+
var resultGids = new List<int>();
27+
var resultNames = new List<string>();
28+
if (!string.IsNullOrEmpty(searchString))
29+
{
30+
var factories = GameMain.data.factories;
31+
var factoryCount = GameMain.data.factoryCount;
32+
for (var i = 0; i < factoryCount; i++)
33+
{
34+
var planetFactory = factories[i];
35+
var entityPool = planetFactory.entityPool;
36+
var stationPool = planetFactory.transport.stationPool;
37+
var buffer = planetFactory.digitalSystem.extraInfoes.buffer;
38+
var cursor = planetFactory.digitalSystem.extraInfoes.cursor;
39+
for (var j = 1; j < cursor; j++)
40+
{
41+
var extraInfoComponent = buffer[j];
42+
if (extraInfoComponent != null && extraInfoComponent.objectType == EObjectType.None)
43+
{
44+
if (isExact && extraInfoComponent.info != searchString) continue;
45+
if (!extraInfoComponent.info.Contains(searchString)) continue;
46+
ref var ptr = ref entityPool[extraInfoComponent.objectId];
47+
if (ptr.id == extraInfoComponent.objectId)
48+
{
49+
var stationComponent = stationPool[ptr.stationId];
50+
if (stationComponent != null && stationComponent.id == ptr.stationId && stationComponent.isStellar && stationComponent.planetId != localPlanetId)
51+
{
52+
resultGids.Add(stationComponent.gid);
53+
resultNames.Add(extraInfoComponent.info);
54+
}
55+
}
56+
}
57+
}
58+
}
59+
}
60+
packet.ResultGids = resultGids.ToArray();
61+
packet.ResultNames = resultNames.ToArray();
62+
conn.SendPacket(packet);
63+
}
64+
else // Client
65+
{
66+
UIStationRoutePanel panel = null;
67+
if (UIRoot.instance.uiGame.stationWindow.uiRoutePanel.active)
68+
{
69+
panel = UIRoot.instance.uiGame.stationWindow.uiRoutePanel;
70+
}
71+
if (UIRoot.instance.uiGame.controlPanelWindow.stationInspector.uiRoutePanel.active)
72+
{
73+
panel = UIRoot.instance.uiGame.controlPanelWindow.stationInspector.uiRoutePanel;
74+
}
75+
if (panel != null && panel.searchNameInputField.text == packet.SearchString)
76+
{
77+
if (packet.IsExact)
78+
{
79+
// Continue from RefreshSearchEntries
80+
panel.addGids.Clear();
81+
panel.addGids.AddRange(packet.ResultGids);
82+
panel.RefreshAddEntry();
83+
}
84+
else if (packet.ResultNames != null)
85+
{
86+
// Modify from UIStationRoutePanel.OnSearchNameInputChanged
87+
panel.searchDropDownRt.gameObject.SetActive(true);
88+
panel.activeSearchEntryCount = 0;
89+
var parent = panel.searchEntryPrefab.transform.parent;
90+
91+
for (var i = 0; i < packet.ResultNames.Length; i++)
92+
{
93+
if (panel.searchEntries.Count <= panel.activeSearchEntryCount)
94+
{
95+
panel.searchEntries.Add(null);
96+
}
97+
var entry = panel.searchEntries[panel.activeSearchEntryCount];
98+
if (entry == null)
99+
{
100+
entry = Object.Instantiate(panel.searchEntryPrefab, parent);
101+
entry._Create();
102+
entry.rt.anchoredPosition = new Vector2(0f, (float)(-(float)panel.activeSearchEntryCount) * panel.searchEntryPrefab.rt.rect.height);
103+
panel.searchEntries[panel.activeSearchEntryCount] = entry;
104+
}
105+
entry._Init(null);
106+
entry._Open();
107+
entry.realName = packet.ResultNames[i];
108+
entry.SetName(packet.SearchString);
109+
panel.activeSearchEntryCount++;
110+
}
111+
112+
for (var i = panel.activeSearchEntryCount; i < panel.searchEntries.Count; i++)
113+
{
114+
panel.searchEntries[i]._Close();
115+
}
116+
}
117+
}
118+
}
119+
}
120+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#region
2+
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using NebulaAPI.Packets;
6+
using NebulaModel.Networking;
7+
using NebulaModel.Packets;
8+
using NebulaModel.Packets.Logistics.ControlPanel;
9+
10+
#endregion
11+
12+
namespace NebulaNetwork.PacketProcessors.Logistics.ControlPanel;
13+
14+
[RegisterPacketProcessor]
15+
public class LCPStationRouteResultsProcessor : PacketProcessor<LCPStationRouteResultsPacket>
16+
{
17+
protected override void ProcessPacket(LCPStationRouteResultsPacket packet, NebulaConnection conn)
18+
{
19+
if (IsHost)
20+
{
21+
// Use the host's UI component for calculation and restore the data back afterward
22+
var panel = UIRoot.instance.uiGame.controlPanelWindow.stationInspector.uiRouteViewPanel;
23+
var oldIsRemoteRoute = panel.isRemoteRoute;
24+
var oldFactory = panel.inspectorFactory;
25+
var oldStation = panel.inspectorStation;
26+
var newFactory = GameMain.galaxy.PlanetById(packet.QueryPlanetId)?.factory;
27+
StationComponent newStation = null;
28+
if (packet.QueryStationGid < GameMain.data.galacticTransport.stationPool.Length)
29+
{
30+
newStation = GameMain.data.galacticTransport.stationPool[packet.QueryStationGid];
31+
}
32+
if (newFactory != null && newStation != null)
33+
{
34+
panel.isRemoteRoute = true;
35+
panel.SetData(newStation, newFactory);
36+
panel.DetermineRouteResult();
37+
ExportResults(panel, packet);
38+
39+
panel.isRemoteRoute = oldIsRemoteRoute;
40+
if (oldFactory != null && oldStation != null)
41+
{
42+
panel.SetData(oldStation, oldFactory);
43+
}
44+
else
45+
{
46+
// SetData expect factory parameter is not null, so assign directly here
47+
panel.inspectorFactory = null;
48+
panel.inspectorStation = null;
49+
}
50+
}
51+
conn.SendPacket(packet);
52+
}
53+
else // Client
54+
{
55+
var panel = UIRoot.instance.uiGame.controlPanelWindow.stationInspector.uiRouteViewPanel;
56+
var factory = GameMain.galaxy.PlanetById(packet.QueryPlanetId)?.factory;
57+
StationComponent station = null;
58+
if (packet.QueryStationGid < GameMain.data.galacticTransport.stationPool.Length)
59+
{
60+
station = GameMain.data.galacticTransport.stationPool[packet.QueryStationGid];
61+
}
62+
if (panel.inspectorFactory != factory || panel.inspectorStation != station)
63+
{
64+
return;
65+
}
66+
panel.ResetEntryPool();
67+
panel.ClearResult();
68+
ImportResults(panel, packet);
69+
for (var i = 0; i < panel.resultPositions.Count; i++)
70+
{
71+
// resultEntries should have same length as resultPositions
72+
panel.resultEntries.Add(null);
73+
}
74+
panel.needDetermineEntryVisible = true;
75+
}
76+
}
77+
78+
private static void ExportResults(UIControlPanelStationRouteViewPanel panel, LCPStationRouteResultsPacket packet)
79+
{
80+
packet.RouteResultCounts = panel.routeResultCounts.ToArray();
81+
packet.ResultPositions = panel.resultPositions.ToArray();
82+
83+
var length = panel.routeResults.Count;
84+
packet.TargetIds = new int[length];
85+
packet.PairStorageIndexMasks = new int[length];
86+
packet.PlanetIds = new int[length];
87+
packet.RouteTypes = new short[length];
88+
packet.StationIds = new int[length];
89+
packet.DistanceToInspectorStationSqrs = new double[length];
90+
for (var i = 0; i < length; i++)
91+
{
92+
var result = panel.routeResults[i];
93+
packet.TargetIds[i] = result.targetId;
94+
packet.PairStorageIndexMasks[i] = result.pairStorageIndexMask;
95+
packet.PlanetIds[i] = result.planetId;
96+
packet.RouteTypes[i] = (short)result.routeType;
97+
packet.StationIds[i] = result.stationId;
98+
packet.DistanceToInspectorStationSqrs[i] = result.distanceToInspectorStationSqr;
99+
}
100+
}
101+
102+
private static void ImportResults(UIControlPanelStationRouteViewPanel panel, LCPStationRouteResultsPacket packet)
103+
{
104+
if (packet.RouteResultCounts == null) return;
105+
106+
panel.routeResultCounts = packet.RouteResultCounts;
107+
panel.resultPositions = new List<int>(packet.ResultPositions);
108+
109+
var length = packet.TargetIds.Length;
110+
panel.routeResults = new List<StationRouteResult>(length);
111+
for (var i = 0; i < length; i++)
112+
{
113+
var result = new StationRouteResult
114+
{
115+
targetId = packet.TargetIds[i],
116+
pairStorageIndexMask = packet.PairStorageIndexMasks[i],
117+
planetId = packet.PlanetIds[i],
118+
routeType = (EUIControlPanelRouteType)packet.RouteTypes[i],
119+
stationId = packet.StationIds[i],
120+
distanceToInspectorStationSqr = packet.DistanceToInspectorStationSqrs[i]
121+
};
122+
panel.routeResults.Add(result);
123+
}
124+
}
125+
}

0 commit comments

Comments
 (0)