Skip to content

Commit

Permalink
Merge pull request #653 from starfi5h/pr-drone
Browse files Browse the repository at this point in the history
Rework drone syncing for 0.10.29.21950
  • Loading branch information
starfi5h authored Feb 18, 2024
2 parents 4979d62 + ac018e6 commit f9f1386
Show file tree
Hide file tree
Showing 22 changed files with 445 additions and 1,360 deletions.
17 changes: 17 additions & 0 deletions NebulaModel/Packets/Factory/PrebuildItemRequiredUpdate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace NebulaModel.Packets.Factory;

public class PrebuildItemRequiredUpdate
{
public PrebuildItemRequiredUpdate() { }

public PrebuildItemRequiredUpdate(int planetId, int prebuildId, int itemCount)
{
PlanetId = planetId;
PrebuildId = prebuildId;
ItemCount = itemCount;
}

public int PlanetId { get; set; }
public int PrebuildId { get; set; }
public int ItemCount { get; set; }
}
23 changes: 0 additions & 23 deletions NebulaModel/Packets/Players/NewMechaDroneOrderPacket.cs

This file was deleted.

26 changes: 26 additions & 0 deletions NebulaModel/Packets/Players/PlayerEjectMechaDronePacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace NebulaModel.Packets.Players;

public class PlayerEjectMechaDronePacket
{
public PlayerEjectMechaDronePacket() { }

public PlayerEjectMechaDronePacket(ushort playerId, int planetId, int targetObjectId,
int next1ObjectId, int next2ObjectId, int next3ObjectId, int dronePriority)
{
PlayerId = playerId;
PlanetId = planetId;
TargetObjectId = targetObjectId;
Next1ObjectId = next1ObjectId;
Next2ObjectId = next2ObjectId;
Next3ObjectId = next3ObjectId;
DronePriority = dronePriority;
}

public ushort PlayerId { get; set; }
public int PlanetId { get; set; }
public int TargetObjectId { get; set; }
public int Next1ObjectId { get; set; }
public int Next2ObjectId { get; set; }
public int Next3ObjectId { get; set; }
public int DronePriority { get; set; }
}
17 changes: 17 additions & 0 deletions NebulaModel/Packets/Players/PlayerGiveItemPacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace NebulaModel.Packets.Players;

public class PlayerGiveItemPacket
{
public PlayerGiveItemPacket() { }

public PlayerGiveItemPacket(int itemId, int itemCount, int itemInc)
{
ItemId = itemId;
ItemCount = itemCount;
ItemInc = itemInc;
}

public int ItemId { get; set; }
public int ItemCount { get; set; }
public int ItemInc { get; set; }
}
15 changes: 0 additions & 15 deletions NebulaModel/Packets/Players/RemoveDroneOrdersPacket.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ protected override void ProcessPacket(BuildEntityRequest packet, NebulaConnectio
{
if (IsHost && !Multiplayer.Session.Factories.ContainsPrebuildRequest(packet.PlanetId, packet.PrebuildId))
{
Log.Warn(
$"BuildEntityRequest received does not have a corresponding PrebuildRequest with the id {packet.PrebuildId} for the planet {packet.PlanetId}");
// Prebuild has already been removed, so skip it.
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#region

using NebulaAPI.Packets;
using NebulaModel.Networking;
using NebulaModel.Packets;
using NebulaModel.Packets.Factory;
using NebulaModel.Packets.Players;
using NebulaWorld;

#endregion

namespace NebulaNetwork.PacketProcessors.Factory.Entity;

[RegisterPacketProcessor]
public class PrebuildItemRequiredUpdateProcessor : PacketProcessor<PrebuildItemRequiredUpdate>
{
protected override void ProcessPacket(PrebuildItemRequiredUpdate packet, NebulaConnection conn)
{
var planet = GameMain.galaxy.PlanetById(packet.PlanetId);
if (planet.factory == null || packet.PrebuildId >= planet.factory.prebuildCursor)
{
return;
}
var factory = planet.factory;

ref var ptr = ref factory.prebuildPool[packet.PrebuildId];
if (ptr.id != packet.PrebuildId || ptr.itemRequired == 0)
{
//Prebuild not exist or the prebuild has satisfied the item requirement (green)
if (IsHost)
{
//Refund the item back to the player
var itemId = ptr.protoId;
conn.SendPacket(new PlayerGiveItemPacket(itemId, packet.ItemCount, 0));
}
return;
}

using (Multiplayer.Session.Factories.IsIncomingRequest.On())
{
//From ConstructionModuleComponent.PlaceItems
ptr.itemRequired = 0;
factory.NotifyPrebuildChange(ptr.id, 3);
if (factory.planet.factoryLoaded || factory.planet.factingCompletedStage >= 3)
{
factory.AlterPrebuildModelState(ptr.id, false);
}
factory.constructionSystem.AddBuildTargetToModules(ptr.id, ref ptr.pos);
}
}
}
192 changes: 0 additions & 192 deletions NebulaNetwork/PacketProcessors/Players/NewDroneOrderProcessor.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#region

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

#endregion

namespace NebulaNetwork.PacketProcessors.Players;

[RegisterPacketProcessor]
public class PlayerEjectMechaDroneProcessor : PacketProcessor<PlayerEjectMechaDronePacket>
{
protected override void ProcessPacket(PlayerEjectMechaDronePacket packet, NebulaConnection conn)
{
var factory = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory;
if (factory == null) return;

Multiplayer.Session.Drones.EjectMechaDroneFromOtherPlayer(packet);
}
}
Loading

0 comments on commit f9f1386

Please sign in to comment.