mirror of
https://github.com/rmroc451/TweaksAndThings.git
synced 2025-12-16 01:09:38 -06:00
move loco post notice about WP set to host, so clients get them
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
using Game.Notices;
|
||||
using Game.State;
|
||||
using HarmonyLib;
|
||||
using Model;
|
||||
using Network;
|
||||
using Serilog;
|
||||
using UI.EngineControls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RMROC451.TweaksAndThings.Patches;
|
||||
|
||||
|
||||
[HarmonyPatch(typeof(AutoEngineerOrdersHelper))]
|
||||
[HarmonyPatch(nameof(AutoEngineerOrdersHelper.SetWaypoint), typeof(Track.Location), typeof(string))]
|
||||
[HarmonyPatchCategory("RMROC451TweaksAndThings")]
|
||||
internal class AutoEngineerOrdersHelper_SetWaypoint_patch
|
||||
{
|
||||
private static Serilog.ILogger _log => Log.ForContext<AutoEngineerOrdersHelper_SetWaypoint_patch>();
|
||||
static void Postfix(AutoEngineerOrdersHelper __instance, Track.Location location, string coupleToCarId)
|
||||
{
|
||||
if (StateManager.IsHost)
|
||||
{
|
||||
_log.Debug($"start setWP");
|
||||
Car selectedLoco = __instance._locomotive;
|
||||
_log.Debug($"{selectedLoco?.DisplayName ?? ""} set WP");
|
||||
Vector3 gamePoint = location.GetPosition();
|
||||
EntityReference entityReference = new EntityReference(EntityType.Position, new Vector4(gamePoint.x, gamePoint.y, gamePoint.z, 0));
|
||||
selectedLoco.PostNotice("ai-wpt-rmroc451", new Hyperlink(entityReference.URI(), $"WP SET"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Game;
|
||||
using Game.Messages;
|
||||
using Game.Notices;
|
||||
using Game.State;
|
||||
using HarmonyLib;
|
||||
using Model;
|
||||
@@ -15,8 +16,10 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Track;
|
||||
using UI.EngineControls;
|
||||
using UI.EngineRoster;
|
||||
using UnityEngine;
|
||||
using static Unity.IO.LowLevel.Unsafe.AsyncReadManagerMetrics;
|
||||
using static UnityEngine.InputSystem.InputRemoting;
|
||||
|
||||
@@ -33,6 +36,7 @@ internal class AutoEngineerPlanner_HandleCommand_Patch
|
||||
static bool Prefix(AutoEngineerPlanner __instance, ref AutoEngineerCommand command, ref IPlayer sender)
|
||||
{
|
||||
TweaksAndThingsPlugin tweaksAndThings = SingletonPluginBase<TweaksAndThingsPlugin>.Shared;
|
||||
LocoNoticeWPSet(__instance, command, sender);
|
||||
if (!tweaksAndThings.IsEnabled() || !tweaksAndThings.SafetyFirst() || (sender.IsRemote && !tweaksAndThings.SafetyFirstClientEnforce()) || command.MaxSpeedMph <= governedSpeed) return true;
|
||||
BaseLocomotive loco = __instance._locomotive;
|
||||
|
||||
@@ -49,9 +53,10 @@ internal class AutoEngineerPlanner_HandleCommand_Patch
|
||||
|
||||
string message = $"{Enum.GetName(typeof(AutoEngineerMode), command.Mode)}[{loco.DisplayName}] governed{{0}}due to Safety First rules.";
|
||||
if (orig != command.MaxSpeedMph)
|
||||
{
|
||||
{
|
||||
message = string.Format(message, $" from {orig} to {command.MaxSpeedMph} MPH ");
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
message = string.Format(message, " ");
|
||||
}
|
||||
@@ -62,6 +67,47 @@ internal class AutoEngineerPlanner_HandleCommand_Patch
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void LocoNoticeWPSet(AutoEngineerPlanner __instance, AutoEngineerCommand command, IPlayer sender)
|
||||
{
|
||||
OrderWaypoint? wp =
|
||||
string.IsNullOrEmpty(command.WaypointLocationString) ?
|
||||
null :
|
||||
new OrderWaypoint?(new OrderWaypoint(command.WaypointLocationString, command.WaypointCoupleToCarId));
|
||||
|
||||
if (
|
||||
wp.HasValue &&
|
||||
!string.IsNullOrEmpty(wp.Value.LocationString) &&
|
||||
!__instance._orders.Waypoint.Equals(wp)
|
||||
)
|
||||
{
|
||||
_log.Debug($"start setWP");
|
||||
Car selectedLoco = __instance._locomotive;
|
||||
_log.Debug($"{selectedLoco?.DisplayName ?? ""} set WP");
|
||||
if (LocationPositionFromString(wp.Value, out Vector3 gamePoint))
|
||||
{
|
||||
EntityReference entityReference = new EntityReference(EntityType.Position, new Vector4(gamePoint.x, gamePoint.y, gamePoint.z, 0));
|
||||
selectedLoco.PostNotice("ai-wpt-rmroc451", new Hyperlink(entityReference.URI(), $"WP SET [{sender.Name}]"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool LocationPositionFromString(OrderWaypoint waypoint, out Vector3 position)
|
||||
{
|
||||
Location location;
|
||||
position = default;
|
||||
try
|
||||
{
|
||||
location = Graph.Shared.ResolveLocationString(waypoint.LocationString);
|
||||
position = location.GetPosition();
|
||||
return true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Couldn't get location from waypoint: {locStr}", waypoint.LocationString);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool SafetyFirstGoverningApplies(BaseLocomotive loco)
|
||||
{
|
||||
var _persistence = new AutoEngineerPersistence(loco.KeyValueObject);
|
||||
|
||||
Reference in New Issue
Block a user