Skip to content

Commit

Permalink
Merge pull request #651 from NebulaModTeam/0.10.29
Browse files Browse the repository at this point in the history
0.10.29 Update WIP
  • Loading branch information
starfi5h authored Feb 5, 2024
2 parents 96bf46c + 55f1f51 commit 4979d62
Show file tree
Hide file tree
Showing 18 changed files with 235 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ public enum StorageSyncRealtimeChangeEvent
AddItem1 = 1,
AddItem2 = 2,
AddItemStacked = 3,
TakeItem = 4,
TakeItemFromGrid = 5,
TakeHeadItems = 6,
TakeTailItems1 = 7,
TakeTailItems2 = 8
AddItemFiltered = 4,
TakeItem = 5,
TakeItemFromGrid = 6,
TakeHeadItems = 7,
TakeTailItems1 = 8,
TakeTailItems2 = 9
}
17 changes: 17 additions & 0 deletions NebulaModel/Packets/Factory/Turret/TurretPhaseUpdatePacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace NebulaModel.Packets.Factory.Turret;

public class TurretPhaseUpdatePacket
{
public TurretPhaseUpdatePacket() { }

public TurretPhaseUpdatePacket(int turretId, int phasePos, int planetId)
{
TurretId = turretId;
PhasePos = phasePos;
PlanetId = planetId;
}

public int TurretId { get; set; }
public int PhasePos { get; set; }
public int PlanetId { get; set; }
}
8 changes: 5 additions & 3 deletions NebulaModel/Packets/Factory/Turret/TurretSuperNovaPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ public class TurretSuperNovaPacket
{
public TurretSuperNovaPacket() { }

public TurretSuperNovaPacket(int turretIndex, bool inSuperNova, int planetId)
public TurretSuperNovaPacket(int turretIndex, int brustModeIndex, bool setSuperNova, int planetId)
{
TurretIndex = turretIndex;
InSuperNova = inSuperNova;
BrustModeIndex = brustModeIndex;
SetSuperNova = setSuperNova;
PlanetId = planetId;
}

public int TurretIndex { get; set; }
public bool InSuperNova { get; set; }
public int BrustModeIndex { get; set; }
public bool SetSuperNova { get; set; }
public int PlanetId { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected override void ProcessPacket(BattleBaseSettingUpdatePacket packet, Nebu
break;

case BattleBaseSettingEvent.ChangeDronesPriority:
battleBase.constructionModule.ChangeDronesPriority(factory, packet.Arg1);
battleBase.constructionModule.ChangeDronesPriority(factory, (int)packet.Arg1);
break;

case BattleBaseSettingEvent.ToggleCombatModuleEnabled:
Expand All @@ -58,6 +58,10 @@ protected override void ProcessPacket(BattleBaseSettingUpdatePacket packet, Nebu

case BattleBaseSettingEvent.ToggleAutoReconstruct:
battleBase.constructionModule.autoReconstruct = packet.Arg1 != 0f;
if (battleBase.constructionModule.autoReconstruct)
{
battleBase.constructionModule.SearchAutoReconstructTargets(factory, GameMain.mainPlayer, true);
}
break;

case BattleBaseSettingEvent.ToggleAutoPickEnabled:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,22 @@ protected override void ProcessPacket(NewBattleBaseDroneOrderPacket packet, Nebu

switch (packet.IsConstruction)
{
// TODO(0.10.29.21869)
/*
case true when
factory.constructionSystem.TakeEnoughItemsFromBase(battleBaseComponent, packet.EntityId):
battleBaseComponent.constructionModule.EjectBaseDrone(factory, ref drone, ref craftData,
packet.EntityId);
battleBaseComponent.energy -= (long)droneEjectEnergy;
factory.constructionSystem.constructServing.Add(packet.EntityId);
return;
*/
case false:
battleBaseComponent.constructionModule.EjectBaseDrone(factory, ref drone, ref craftData,
packet.EntityId);
// TODO(0.10.29.21869)
// battleBaseComponent.constructionModule.EjectBaseDrone(factory, ref drone, ref craftData,
// packet.EntityId);
battleBaseComponent.energy -= (long)droneEjectEnergy;

/* TODO: needed?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,23 @@ protected override void ProcessPacket(StorageSyncRealtimeChangePacket packet, Ne
var inc = packet.Inc;
switch (packet.StorageEvent)
{
case StorageSyncRealtimeChangeEvent.AddItem1:
storage.AddItem(itemId, count, inc, out _, true);
break;
case StorageSyncRealtimeChangeEvent.AddItem2:
storage.AddItem(itemId, count, packet.StartIndex, packet.Length, inc, out _);
break;
case StorageSyncRealtimeChangeEvent.AddItemStacked:
storage.AddItemStacked(itemId, count, inc, out _);
break;
case StorageSyncRealtimeChangeEvent.TakeItemFromGrid:
storage.TakeItemFromGrid(packet.Length, ref itemId, ref count, out _);
break;
case StorageSyncRealtimeChangeEvent.AddItem1: //BattleBase AutoPickTrash
storage.AddItem(itemId, count, inc, out _, true);
case StorageSyncRealtimeChangeEvent.AddItemFiltered: // Use by BattleBaseComponent.AutoPickTrash
storage.AddItemFiltered(itemId, count, inc, out _, true);
break;
case StorageSyncRealtimeChangeEvent.TakeItem:
break;
case StorageSyncRealtimeChangeEvent.TakeItemFromGrid:
storage.TakeItemFromGrid(packet.Length, ref itemId, ref count, out _);
break;
case StorageSyncRealtimeChangeEvent.TakeHeadItems:
break;
case StorageSyncRealtimeChangeEvent.TakeTailItems1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,22 @@ protected override void ProcessPacket(TurretGroupUpdatePacket packet, NebulaConn
{
return;
}
var turret = pool.buffer[packet.TurretIndex];
ref var turret = ref pool.buffer[packet.TurretIndex];
if (turret.id != -1)
{
turret.SetGroup(packet.Group);
}

// Refresh UI if viewing on the same turret
var uiTurret = UIRoot.instance.uiGame.turretWindow;
if (uiTurret.factory == null || uiTurret.factory.planetId != packet.PlanetId || uiTurret.turretId != packet.TurretIndex)
{
return;
}
for (var i = 0; i < uiTurret.groupSelectionBtns.Length; i++)
{
var uibutton = uiTurret.groupSelectionBtns[i];
uibutton.highlighted = uibutton.data == (int)turret.group;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#region

using NebulaAPI.Packets;
using NebulaModel.Networking;
using NebulaModel.Packets;
using NebulaModel.Packets.Factory.Turret;

#endregion

namespace NebulaNetwork.PacketProcessors.Factory.Turret;

[RegisterPacketProcessor]
internal class TurretPhaseUpdateProcessor : PacketProcessor<TurretPhaseUpdatePacket>
{
protected override void ProcessPacket(TurretPhaseUpdatePacket packet, NebulaConnection conn)
{
var pool = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory?.defenseSystem.turrets;
if (pool == null || packet.TurretId < 0 || packet.TurretId >= pool.buffer.Length)
{
return;
}
ref var turret = ref pool.buffer[packet.TurretId];
turret.phasePos = packet.PhasePos;

// Refresh UI if viewing on the same turret
var uiTurret = UIRoot.instance.uiGame.turretWindow;
if (uiTurret.factory == null || uiTurret.factory.planetId != packet.PlanetId || uiTurret.turretId != packet.TurretId)
{
return;
}
uiTurret.phaseText.text = (turret.phasePos / 60f).ToString("0.##");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using NebulaModel.Networking;
using NebulaModel.Packets;
using NebulaModel.Packets.Factory.Turret;
using NebulaWorld;

#endregion

Expand All @@ -14,23 +15,29 @@ internal class TurretSuperNovaProcessor : PacketProcessor<TurretSuperNovaPacket>
{
protected override void ProcessPacket(TurretSuperNovaPacket packet, NebulaConnection conn)
{
var defenseSystem = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory?.defenseSystem;
var planet = GameMain.galaxy.PlanetById(packet.PlanetId);
var defenseSystem = planet?.factory?.defenseSystem;
var pool = defenseSystem?.turrets;
if (pool == null || packet.TurretIndex == -1 || packet.TurretIndex >= pool.buffer.Length ||
pool.buffer[packet.TurretIndex].id == -1)
{
return;
}
//TODO: Evaluate in PR, should I count on other packet, or should I pass through?
var burstModeIndex = UITurretWindow.burstModeIndex;
var inSuperNova = packet.InSuperNova;

var refTurret = pool.buffer[packet.TurretIndex];
if (IsHost)
{
// Broadcast supernova events to other players in the system
var starId = planet.star.id;
Multiplayer.Session.Network.SendPacketToStar(packet, starId);
}

switch (burstModeIndex)
var setSuperNova = packet.SetSuperNova;
UITurretWindow.burstModeIndex = packet.BrustModeIndex; // Leave a mark in UI
ref var refTurret = ref pool.buffer[packet.TurretIndex];
switch (packet.BrustModeIndex)
{
case 1:
if (inSuperNova)
if (setSuperNova)
{
refTurret.SetSupernova();
}
Expand All @@ -40,7 +47,7 @@ protected override void ProcessPacket(TurretSuperNovaPacket packet, NebulaConnec
}
break;
case 2:
if (inSuperNova)
if (setSuperNova)
{
defenseSystem.SetGroupTurretsSupernova(refTurret.group);
}
Expand All @@ -50,7 +57,7 @@ protected override void ProcessPacket(TurretSuperNovaPacket packet, NebulaConnec
}
break;
case 3:
if (inSuperNova)
if (setSuperNova)
{
defenseSystem.SetGlobalTurretsSupernova();
}
Expand All @@ -60,5 +67,16 @@ protected override void ProcessPacket(TurretSuperNovaPacket packet, NebulaConnec
}
break;
}

var uiTurret = UIRoot.instance.uiGame.turretWindow;
if (uiTurret.factory == null || uiTurret.factory.planetId != packet.PlanetId || uiTurret.turretId != packet.TurretIndex)
{
return;
}
uiTurret.supernovaWait = packet.SetSuperNova;
if (refTurret.inSupernova)
{
GameMain.gameScenario.NotifyOnSupernovaUITriggered();
}
}
}
13 changes: 11 additions & 2 deletions NebulaNetwork/PacketProcessors/Players/NewDroneOrderProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ protected override void ProcessPacket(NewMechaDroneOrderPacket packet, NebulaCon
if (factory != null)
{
DroneManager.EjectDronesOfOtherPlayer(packet.PlayerId, packet.PlanetId, packet.EntityId);
factory.constructionSystem.constructServing.Add(packet.EntityId);
// TODO(0.10.29.21869)
// factory.constructionSystem.constructServing.Add(packet.EntityId);
}
break;
}
Expand All @@ -100,11 +101,15 @@ protected override void ProcessPacket(NewMechaDroneOrderPacket packet, NebulaCon

if (factory != null)
{
// TODO(0.10.29.21869)
/*
factory.constructionSystem.TakeEnoughItemsFromPlayer(packet.EntityId);
GameMain.mainPlayer.mecha.constructionModule.EjectMechaDrone(factory, GameMain.mainPlayer,
packet.EntityId,
packet.Priority);
factory.constructionSystem.constructServing.Add(packet.EntityId);
*/
}
break;
}
Expand Down Expand Up @@ -155,7 +160,8 @@ private void informAndEjectRemoteDrones(NewMechaDroneOrderPacket packet, PlanetF
Multiplayer.Session.Network.SendPacketToPlanet(
new NewMechaDroneOrderPacket(packet.PlanetId, packet.EntityId, closestPlayerId, packet.Priority),
packet.PlanetId);
factory.constructionSystem.constructServing.Add(packet.EntityId);
// TODO(0.10.29.21869)
// factory.constructionSystem.constructServing.Add(packet.EntityId);

// only render other drones when on same planet
if (packet.PlanetId == GameMain.mainPlayer.planetId)
Expand All @@ -175,9 +181,12 @@ private void informAndEjectLocalDrones(NewMechaDroneOrderPacket packet, PlanetFa
new NewMechaDroneOrderPacket(packet.PlanetId, packet.EntityId, closestPlayerId, packet.Priority),
packet.PlanetId);

// TODO(0.10.29.21869)
/*
factory.constructionSystem.TakeEnoughItemsFromPlayer(packet.EntityId);
GameMain.mainPlayer.mecha.constructionModule.EjectMechaDrone(factory, GameMain.mainPlayer, packet.EntityId,
packet.Priority);
factory.constructionSystem.constructServing.Add(packet.EntityId);
*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ protected override void ProcessPacket(RemoveDroneOrdersPacket packet, NebulaConn
{
continue;
}
factory.constructionSystem.constructServing.Remove(targetObjectId); // in case it was a construction drone.
// TODO(0.10.29.21869)
// factory.constructionSystem.constructServing.Remove(targetObjectId); // in case it was a construction drone.

if (GameMain.mainPlayer.planetId == player.Data.LocalPlanetId)
{
Expand Down Expand Up @@ -81,7 +82,9 @@ protected override void ProcessPacket(RemoveDroneOrdersPacket packet, NebulaConn
Multiplayer.Session.Network.SendPacketToPlanet(
new NewMechaDroneOrderPacket(player.Data.LocalPlanetId, targetObjectId,
nextClosestPlayer, /*TODO: rip*/true), player.Data.LocalPlanetId);
factory.constructionSystem.constructServing.Add(targetObjectId);

// TODO(0.10.29.21869)
//factory.constructionSystem.constructServing.Add(targetObjectId);

// only render other drones when on same planet
if (player.Data.LocalPlanetId == GameMain.mainPlayer.planetId)
Expand Down Expand Up @@ -117,8 +120,9 @@ protected override void ProcessPacket(RemoveDroneOrdersPacket packet, NebulaConn
}

DroneManager.RemoveBuildRequest(drone.targetObjectId);
factory.constructionSystem.constructServing
.Remove(drone.targetObjectId); // in case it was a construction drone.
// TODO(0.10.29.21869)
//factory.constructionSystem.constructServing
// .Remove(drone.targetObjectId); // in case it was a construction drone.
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public static void RecycleDrone_Postfix(ConstructionModuleComponent __instance,
}

// clients should skip the procedure for BattleBases. The host will tell them when to eject drones.
[HarmonyPrefix]
[HarmonyPatch(nameof(ConstructionModuleComponent.IdleDroneProcedure))]
// TODO(0.10.29.21869)
//[HarmonyPrefix]
//[HarmonyPatch(nameof(ConstructionModuleComponent.IdleDroneProcedure))]
public static bool IdleDroneProcedure_Prefix(ConstructionModuleComponent __instance)
{
if (!Multiplayer.IsActive)
Expand Down
6 changes: 3 additions & 3 deletions NebulaPatcher/Patches/Dynamic/UIBattleBaseWindow_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public static bool OnDronePriorityButtonClick_Prefix(UIBattleBaseWindow __instan
{
return true;
}
var ratio = __instance.constructionModule.dronePriorConstructRatio;
var newRatio = ratio < 0.25f ? 0.5f : ratio < 0.75f ? 1f : 0f;
SendEvent(__instance, BattleBaseSettingEvent.ChangeDronesPriority, newRatio);
var dronePriority = __instance.constructionModule.dronePriority;
var newDronePriority = (dronePriority + 1) % 3;
SendEvent(__instance, BattleBaseSettingEvent.ChangeDronesPriority, newDronePriority);
return Multiplayer.Session.LocalPlayer.IsHost;
}

Expand Down
Loading

0 comments on commit 4979d62

Please sign in to comment.