Compare commits

...

2 Commits

@ -35,18 +35,15 @@
<Reference Include="LogicWorld.BuildingManagement"> <Reference Include="LogicWorld.BuildingManagement">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.BuildingManagement.dll</HintPath> <HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.BuildingManagement.dll</HintPath>
</Reference> </Reference>
<Reference Include="LogicWorld.Players">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Players.dll</HintPath>
</Reference>
<Reference Include="LogicWorld.Physics">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Physics.dll</HintPath>
</Reference>
<Reference Include="LogicWorld.Interfaces"> <Reference Include="LogicWorld.Interfaces">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Interfaces.dll</HintPath> <HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Interfaces.dll</HintPath>
</Reference> </Reference>
<Reference Include="LogicWorld.Modding"> <Reference Include="LogicWorld.Modding">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Modding.dll</HintPath> <HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Modding.dll</HintPath>
</Reference> </Reference>
<Reference Include="LogicWorld.GameStates">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.GameStates.dll</HintPath>
</Reference>
<Reference Include="LogicWorld.SharedCode"> <Reference Include="LogicWorld.SharedCode">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.SharedCode.dll</HintPath> <HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.SharedCode.dll</HintPath>
</Reference> </Reference>
@ -69,7 +66,4 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\EccsLogicWorldAPI\EccsLogicWorldAPI.csproj"/> <ProjectReference Include="..\EccsLogicWorldAPI\EccsLogicWorldAPI.csproj"/>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="src\shared\" />
</ItemGroup>
</Project> </Project>

@ -1,6 +1,6 @@
MHG.SettingsMenu.Pages.Controls.Headings.DLatchPoke: "Mod: DLatch Poke" MHG.SettingsMenu.Pages.Controls.Headings.DLatchPoke: "Mod: DLatch Poke"
FancyInput.Trigger.DLatchPoke.Poke: "Poke a DLatch" FancyInput.Trigger.DLatchPoke.Poke: "Toggle DLatch State"
FancyInput.Trigger.DLatchPoke.Poke.Description: """ FancyInput.Trigger.DLatchPoke.Poke.Description: """
Toggles the internal state of the DLatch the player is looking at. Toggles the internal state of the DLatch (or multiple) the player is looking at or has selected.
""" """

@ -1,7 +1,7 @@
ID: D4VID_DLatchPoke ID: D4VID_DLatchPoke
Name: DLatch Poke Name: DLatch Poke
Author: D4VID Author: D4VID
Version: 1.0.0 Version: 2.0.0
Priority: 0 Priority: 0
Dependencies: Dependencies:
- EccsLogicWorldAPI - EccsLogicWorldAPI

@ -1,17 +1,9 @@
using System; using DLatchPoke.Client.Keybindings;
using DLatchPoke.Client.Keybindings;
using DLatchPoke.Client.Network; using DLatchPoke.Client.Network;
using DLatchPoke.Shared.Packets.C2S;
using DLatchPoke.Shared.Packets.S2C;
using EccsLogicWorldAPI.Client.Injectors; using EccsLogicWorldAPI.Client.Injectors;
using FancyInput; using FancyInput;
using LogicAPI.Client; using LogicAPI.Client;
using LogicAPI.Data;
using LogicLog; using LogicLog;
using LogicWorld;
using LogicWorld.Interfaces;
using LogicWorld.Physics;
using LogicWorld.Players;
namespace DLatchPoke.Client { namespace DLatchPoke.Client {
public class DLatchPokeClient : ClientMod { public class DLatchPokeClient : ClientMod {
@ -25,42 +17,10 @@ namespace DLatchPoke.Client {
// Register keybindings in the settings menu // Register keybindings in the settings menu
CustomInput.Register<DLatchPokeContext, DLatchPokeTrigger>("DLatchPoke"); CustomInput.Register<DLatchPokeContext, DLatchPokeTrigger>("DLatchPoke");
// Register the keybinding to enter the path analyzer game state
FirstPersonInteraction.RegisterBuildingKeybinding(DLatchPokeTrigger.Poke, () => {
if (!ServerSupportsMod) {
Logger.Error("Server does not support this mod");
return false;
}
return PokeDLatch();
}
);
// Inject packet handlers // Inject packet handlers
RawPacketHandlerInjector.addPacketHandler(new AnnounceModPacketHandler(Manifest.Version)); RawPacketHandlerInjector.addPacketHandler(new AnnounceModPacketHandler(Manifest.Version));
Logger.Info("DLatchPoke mod loaded"); Logger.Info("DLatchPoke mod loaded");
} }
private bool PokeDLatch() {
HitInfo hitInfo = PlayerCaster.CameraCast(Masks.Environment | Masks.Structure | Masks.Peg);
if (!hitInfo.HitSomething) {
return false;
}
ComponentAddress componentAddress;
if (hitInfo.HitComponent) {
componentAddress = hitInfo.cAddress;
} else if (hitInfo.HitPeg) {
componentAddress = hitInfo.pAddress.ComponentAddress;
} else {
return false;
}
Instances.SendData.Send(new DLatchPokeRequest() {
ComponentAddress = componentAddress,
});
return true;
}
} }
} }

@ -0,0 +1,37 @@
using DLatchPoke.Client.Keybindings;
using DLatchPoke.Shared.Packets.C2S;
using FancyInput;
using LogicAPI.Data;
using LogicAPI.Services;
using LogicWorld.Building.Overhaul;
using LogicWorld.GameStates;
using LogicWorld.Interfaces;
namespace DLatchPoke.Client {
public class DLatchPokeOperation : BuildingOperation {
public override string IconHexCode => "f363";
public override bool CanOperateOn(ComponentSelection selection) {
if (!DLatchPokeClient.ServerSupportsMod) {
DLatchPokeClient.Logger.Error("Server does not support this mod");
return false;
}
ComponentType dLatchType = Instances.MainWorld.ComponentTypes.GetComponentType("MHG.DLatch");
foreach (ComponentAddress componentAddress in selection) {
if (Instances.MainWorld.Data.Lookup(componentAddress).Data.Type != dLatchType) {
return false;
}
}
return true;
}
public override void BeginOperationOn(ComponentSelection selection) {
Instances.SendData.Send(new DLatchPokeRequest() {
ComponentAddresses = selection.ComponentsInSelection,
});
GameStateManager.TransitionBackToBuildingState();
}
public override InputTrigger OperationStarter => DLatchPokeTrigger.Poke;
}
}

@ -1,6 +1,6 @@
namespace DLatchPoke.Client.Keybindings { namespace DLatchPoke.Client.Keybindings {
public enum DLatchPokeContext { public enum DLatchPokeContext {
None, None = 0,
DLatchPoke, DLatchPoke,
} }
} }

@ -1,7 +1,7 @@
namespace DLatchPoke.Client.Keybindings { namespace DLatchPoke.Client.Keybindings {
// Define all available keybindings of the mod // Define all available keybindings of the mod
public enum DLatchPokeTrigger { public enum DLatchPokeTrigger {
None, None = 0,
Poke, Poke,
} }
} }

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using DLatchPoke.Server.Network; using DLatchPoke.Server.Network;
@ -7,7 +6,6 @@ using EccsLogicWorldAPI.Server;
using EccsLogicWorldAPI.Server.Injectors; using EccsLogicWorldAPI.Server.Injectors;
using EccsLogicWorldAPI.Shared.PacketWrapper; using EccsLogicWorldAPI.Shared.PacketWrapper;
using LogicAPI.Data; using LogicAPI.Data;
using LogicAPI.Networking;
using LogicAPI.Networking.Packets.Initialization; using LogicAPI.Networking.Packets.Initialization;
using LogicAPI.Server; using LogicAPI.Server;
using LogicAPI.Server.Components; using LogicAPI.Server.Components;
@ -31,9 +29,6 @@ namespace DLatchPoke.Server {
Logger.Info("DLatchPoke server mod loading"); Logger.Info("DLatchPoke server mod loading");
_networkServer = ServiceGetter.getService<NetworkServer>(); _networkServer = ServiceGetter.getService<NetworkServer>();
if (_networkServer == null) {
throw new Exception("Could not get Service 'NetworkServer'.");
}
// Inject client verifier: // Inject client verifier:
RawJoinVerifierInjector.addVerifier(this); RawJoinVerifierInjector.addVerifier(this);
@ -53,7 +48,6 @@ namespace DLatchPoke.Server {
bool hasMod = ctx.ApprovalPacket.ClientMods.Contains(Manifest.ID); bool hasMod = ctx.ApprovalPacket.ClientMods.Contains(Manifest.ID);
string playerName = ctx.PlayerID.Name; string playerName = ctx.PlayerID.Name;
_playerHasMod[playerName] = hasMod; _playerHasMod[playerName] = hasMod;
Logger.Info($"Verifying player {playerName}: hasMod={hasMod}");
} }
/// <summary> /// <summary>
@ -73,8 +67,7 @@ namespace DLatchPoke.Server {
/// Gets called from the DLatchPokeRequestHandler. /// Gets called from the DLatchPokeRequestHandler.
/// Toggle the internal state of the DLatch /// Toggle the internal state of the DLatch
/// </summary> /// </summary>
public void PokeDLatch(Connection sender, ComponentAddress componentAddress) { public void PokeDLatch(ComponentAddress componentAddress) {
Logger.Info("Got Poke DLatch request");
LogicComponent component = _circuits.LookupComponent(componentAddress); LogicComponent component = _circuits.LookupComponent(componentAddress);
if (component == null) { if (component == null) {
return; return;
@ -82,7 +75,6 @@ namespace DLatchPoke.Server {
DLatch dLatch = component as DLatch; DLatch dLatch = component as DLatch;
if (dLatch == null) { // the component is not of type DLatch if (dLatch == null) { // the component is not of type DLatch
Logger.Info("Poke target is not a DLatch");
return; return;
} }

@ -1,15 +1,19 @@
using DLatchPoke.Shared.Packets.C2S; using DLatchPoke.Shared.Packets.C2S;
using LogicAPI.Data;
using LogicWorld.SharedCode.Networking; using LogicWorld.SharedCode.Networking;
namespace DLatchPoke.Server.Network { namespace DLatchPoke.Server.Network {
public class DLatchPokeRequestHandler : PacketHandler<DLatchPokeRequest> { public class DLatchPokeRequestHandler : PacketHandler<DLatchPokeRequest> {
private readonly DLatchPokeServer _dLatchPokeServer; private readonly DLatchPokeServer _dLatchPokeServer;
public DLatchPokeRequestHandler(DLatchPokeServer dLatchPokeServer) { public DLatchPokeRequestHandler(DLatchPokeServer dLatchPokeServer) {
_dLatchPokeServer = dLatchPokeServer; _dLatchPokeServer = dLatchPokeServer;
} }
public override void Handle(DLatchPokeRequest packet, HandlerContext context) { public override void Handle(DLatchPokeRequest packet, HandlerContext context) {
_dLatchPokeServer.PokeDLatch(context.Sender, packet.ComponentAddress); foreach (ComponentAddress componentAddress in packet.ComponentAddresses) {
_dLatchPokeServer.PokeDLatch(componentAddress);
}
} }
} }
} }

@ -1,3 +1,4 @@
using System.Collections.Generic;
using LogicAPI.Data; using LogicAPI.Data;
using LogicAPI.Networking.Packets; using LogicAPI.Networking.Packets;
using MessagePack; using MessagePack;
@ -5,6 +6,6 @@ using MessagePack;
namespace DLatchPoke.Shared.Packets.C2S { namespace DLatchPoke.Shared.Packets.C2S {
[MessagePackObject] [MessagePackObject]
public class DLatchPokeRequest : Packet { public class DLatchPokeRequest : Packet {
[Key(0)] public ComponentAddress ComponentAddress; [Key(0)] public IEnumerable<ComponentAddress> ComponentAddresses;
} }
} }
Loading…
Cancel
Save