-
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #702 from starfi5h/pr-warning
Sync WarningBroadcastData and tweak battle notification messages
- Loading branch information
Showing
15 changed files
with
248 additions
and
33 deletions.
There are no files selected for viewing
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
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,21 @@ | ||
using NebulaAPI.DataStructures; | ||
using UnityEngine; | ||
|
||
namespace NebulaModel.Packets.Warning; | ||
|
||
public class WarningBroadcastDataPacket | ||
{ | ||
public WarningBroadcastDataPacket() { } | ||
public WarningBroadcastDataPacket(EBroadcastVocal vocal, int astroId, int content, in Vector3 lpos) | ||
{ | ||
Vocal = (short)vocal; | ||
AstroId = astroId; | ||
Content = content; | ||
Lpos = new Float3(lpos); | ||
} | ||
|
||
public short Vocal { get; set; } | ||
public int AstroId { get; set; } | ||
public int Content { get; set; } | ||
public Float3 Lpos { get; set; } | ||
} |
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
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
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
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
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
38 changes: 38 additions & 0 deletions
38
NebulaNetwork/PacketProcessors/Warning/WarningBroadcastDataProcessor.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,38 @@ | ||
#region | ||
|
||
using NebulaAPI.DataStructures; | ||
using NebulaAPI.Packets; | ||
using NebulaModel.Networking; | ||
using NebulaModel.Packets; | ||
using NebulaModel.Packets.Warning; | ||
using NebulaWorld; | ||
using UnityEngine; | ||
|
||
#endregion | ||
|
||
namespace NebulaNetwork.PacketProcessors.Warning; | ||
|
||
[RegisterPacketProcessor] | ||
internal class WarningBroadcastDataProcessor : PacketProcessor<WarningBroadcastDataPacket> | ||
{ | ||
protected override void ProcessPacket(WarningBroadcastDataPacket packet, NebulaConnection conn) | ||
{ | ||
using (Multiplayer.Session.Warning.IsIncomingBroadcast.On()) | ||
{ | ||
var vocal = (EBroadcastVocal)packet.Vocal; | ||
var factoryIndex = GameMain.data.galaxy.astrosFactory[packet.AstroId]?.index ?? -1; | ||
var astroId = packet.AstroId; | ||
var content = packet.Content; | ||
var lpos = packet.Lpos.ToVector3(); | ||
|
||
if (lpos == Vector3.zero) | ||
{ | ||
GameMain.data.warningSystem.Broadcast(vocal, factoryIndex, astroId, content); | ||
} | ||
else | ||
{ | ||
GameMain.data.warningSystem.Broadcast(vocal, factoryIndex, astroId, content, lpos); | ||
} | ||
} | ||
} | ||
} |
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
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
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
71 changes: 71 additions & 0 deletions
71
NebulaPatcher/Patches/Dynamic/UIBroadcastWarningEntry_Patch.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,71 @@ | ||
#region | ||
|
||
using HarmonyLib; | ||
using NebulaModel.Packets.Factory.Tank; | ||
using NebulaWorld; | ||
using UnityEngine; | ||
|
||
#endregion | ||
|
||
namespace NebulaPatcher.Patches.Dynamic; | ||
|
||
[HarmonyPatch(typeof(UIBroadcastWarningEntry))] | ||
internal class UIBroadcastWarningEntry_Patch | ||
{ | ||
[HarmonyPrefix] | ||
[HarmonyPatch(nameof(UIBroadcastWarningEntry.DrawLine))] | ||
public static bool DrawLine_Prefix(UIBroadcastWarningEntry __instance) | ||
{ | ||
if (!Multiplayer.IsActive || Multiplayer.Session.IsServer) return true; | ||
|
||
// Fix guide line to unloaded factory in client | ||
switch (__instance.broadcastData.vocal) | ||
{ | ||
case EBroadcastVocal.LandingRelay: | ||
case EBroadcastVocal.ApproachingSeed: | ||
// Guard to avoid index out of range exception | ||
if (__instance.broadcastData.context >= __instance.window.gameData.spaceSector.enemyPool.Length) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
|
||
case EBroadcastVocal.BuildingDestroyed: | ||
case EBroadcastVocal.MineralDepleted: | ||
case EBroadcastVocal.OilSeepDepleted: | ||
// Replace factory reference with planet | ||
var position = __instance.trackerTrans.transform.position; | ||
var vector = UIRoot.instance.overlayCanvas.worldCamera.WorldToScreenPoint(position); | ||
var startPos = GameCamera.main.ScreenPointToRay(vector).GetPoint(4.5f); | ||
var relativePos = __instance.window.gameData.relativePos; | ||
var relativeRot = __instance.window.gameData.relativeRot; | ||
var planet = GameMain.galaxy.PlanetById(__instance.broadcastData.astroId); | ||
if (planet == null) return true; | ||
|
||
var lpos = __instance.broadcastData.lpos; | ||
var vectorLF5 = planet.uPosition + Maths.QRotateLF(planet.runtimeRotation, lpos); | ||
var vectorLF6 = Maths.QInvRotateLF(relativeRot, vectorLF5 - relativePos); | ||
UniverseSimulator.VirtualMapping(vectorLF6.x, vectorLF6.y, vectorLF6.z, GameCamera.main.transform.position, out var endPos, out _, 10000.0); | ||
|
||
if (__instance.gizmo == null) | ||
{ | ||
__instance.gizmo = LineGizmo.Create(1, startPos, endPos); | ||
__instance.gizmo.autoRefresh = false; | ||
__instance.gizmo.multiplier = 1.5f; | ||
__instance.gizmo.alphaMultiplier = 0.4f; | ||
__instance.gizmo.width = 0.15f; | ||
__instance.gizmo.color = Configs.builtin.gizmoColors[3]; | ||
__instance.gizmo.spherical = false; | ||
__instance.gizmo.Open(); | ||
return false; | ||
} | ||
__instance.gizmo.startPoint = startPos; | ||
__instance.gizmo.endPoint = endPos; | ||
__instance.gizmo.ManualRefresh(); | ||
return false; | ||
|
||
default: | ||
return true; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.