-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
NebulaModel/Packets/Factory/Storage/StorageSyncSetFilterPacket.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace NebulaModel.Packets.Factory.Storage; | ||
|
||
public class StorageSyncSetFilterPacket | ||
{ | ||
public StorageSyncSetFilterPacket() { } | ||
|
||
// @TODO: This can potentially be moved up the call stack - in UI input - for storage boxes- | ||
// to avoid sending redundant data like `StorageIndex` & `StorageType` per every grid slot. | ||
public StorageSyncSetFilterPacket(int storageIndex, int planetId, int gridIndex, int filterId, EStorageType storageType) | ||
{ | ||
StorageIndex = storageIndex; | ||
PlanetId = planetId; | ||
GridIndex = gridIndex; | ||
FilterId = filterId; | ||
StorageType = storageType; | ||
} | ||
public int StorageIndex { get; set; } | ||
public int PlanetId { get; set; } | ||
public int GridIndex { get; set; } | ||
public int FilterId { get; set; } | ||
public EStorageType StorageType { get; set; } | ||
} |
43 changes: 43 additions & 0 deletions
43
NebulaNetwork/PacketProcessors/Factory/Storage/StorageSyncSetFilterProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#region | ||
|
||
using NebulaAPI.Packets; | ||
using NebulaModel.Networking; | ||
using NebulaModel.Packets; | ||
using NebulaModel.Packets.Factory.Storage; | ||
using NebulaWorld; | ||
|
||
#endregion | ||
|
||
namespace NebulaNetwork.PacketProcessors.Factory.Storage; | ||
|
||
[RegisterPacketProcessor] | ||
public class StorageSyncSetFilterProcessor : PacketProcessor<StorageSyncSetFilterPacket> | ||
{ | ||
protected override void ProcessPacket(StorageSyncSetFilterPacket packet, NebulaConnection conn) | ||
{ | ||
StorageComponent storage = null; | ||
var pool = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory?.factoryStorage?.storagePool; | ||
|
||
var poolIsInvalid = pool is null; | ||
if (poolIsInvalid) | ||
{ | ||
return; | ||
} | ||
|
||
var storageIsValid = packet.StorageIndex != -1 && packet.StorageIndex < pool.Length; | ||
if (storageIsValid) | ||
{ | ||
storage = pool[packet.StorageIndex]; | ||
} | ||
|
||
if (storage is null) | ||
return; | ||
|
||
using (Multiplayer.Session.Storage.IsIncomingRequest.On()) | ||
{ | ||
storage.type = packet.StorageType; | ||
storage.SetFilter(packet.GridIndex, packet.FilterId); | ||
storage.NotifyStorageChange(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters