From 362b9afc396d510e116f482580ed238c1880a13f Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 13 Apr 2022 10:16:17 +0100 Subject: [PATCH] fix some stuff??? --- .../Messages/DreamLanternStateMessage.cs | 3 +- .../Ghosts/Actions/QSBGhostActionStub.cs | 48 +++++++++++++++++++ .../Ghosts/Actions/QSBGrabAction.cs | 9 ++++ .../Ghosts/Actions/QSBSentryAction.cs | 5 ++ .../Ghosts/Patches/GhostBrainPatches.cs | 5 -- .../Patches/GhostPartyPathDirectorPatches.cs | 5 ++ QSB/EchoesOfTheEye/Ghosts/QSBGhostAction.cs | 25 +++++++--- .../Ghosts/WorldObjects/QSBGhostBrain.cs | 36 +++++++++++++- QSB/Utility/DebugGUI.cs | 41 ++++++++++++++++ 9 files changed, 162 insertions(+), 15 deletions(-) create mode 100644 QSB/EchoesOfTheEye/Ghosts/Actions/QSBGhostActionStub.cs diff --git a/QSB/EchoesOfTheEye/DreamLantern/Messages/DreamLanternStateMessage.cs b/QSB/EchoesOfTheEye/DreamLantern/Messages/DreamLanternStateMessage.cs index c611a1c4..9ad9ca29 100644 --- a/QSB/EchoesOfTheEye/DreamLantern/Messages/DreamLanternStateMessage.cs +++ b/QSB/EchoesOfTheEye/DreamLantern/Messages/DreamLanternStateMessage.cs @@ -16,7 +16,7 @@ internal class DreamLanternStateMessage : QSBMessage<(DreamLanternActionType Typ if (heldItem is not QSBDreamLanternItem lantern) { - DebugLog.ToConsole($"Error - Got DreamLanternStateMessage from player {From}, but they are not holding a QSBDreamLanternItem!"); + DebugLog.ToConsole($"Error - Got DreamLanternStateMessage from player {From}, but they are not holding a QSBDreamLanternItem!", OWML.Common.MessageType.Error); return; } @@ -25,6 +25,7 @@ internal class DreamLanternStateMessage : QSBMessage<(DreamLanternActionType Typ switch (Data.Type) { case DreamLanternActionType.CONCEAL: + DebugLog.DebugWrite($"CONCEAL {lantern.AttachedObject.name}"); controller.SetConcealed(Data.BoolValue); break; case DreamLanternActionType.FOCUS: diff --git a/QSB/EchoesOfTheEye/Ghosts/Actions/QSBGhostActionStub.cs b/QSB/EchoesOfTheEye/Ghosts/Actions/QSBGhostActionStub.cs new file mode 100644 index 00000000..df0b1235 --- /dev/null +++ b/QSB/EchoesOfTheEye/Ghosts/Actions/QSBGhostActionStub.cs @@ -0,0 +1,48 @@ +using System; + +namespace QSB.EchoesOfTheEye.Ghosts.Actions; + +public class QSBGhostActionStub : QSBGhostAction +{ + public GhostAction.Name Name; + + public override GhostAction.Name GetName() + { + return Name; + } + + public override float CalculateUtility() + { + throw new NotImplementedException(); + } + + public override bool IsInterruptible() + { + throw new NotImplementedException(); + } + + protected override void OnEnterAction() + { + throw new NotImplementedException(); + } + + protected override void OnExitAction() + { + throw new NotImplementedException(); + } + + public override bool Update_Action() + { + throw new NotImplementedException(); + } + + public override void FixedUpdate_Action() + { + throw new NotImplementedException(); + } + + public override void OnArriveAtPosition() + { + throw new NotImplementedException(); + } +} diff --git a/QSB/EchoesOfTheEye/Ghosts/Actions/QSBGrabAction.cs b/QSB/EchoesOfTheEye/Ghosts/Actions/QSBGrabAction.cs index ef586ff0..682da805 100644 --- a/QSB/EchoesOfTheEye/Ghosts/Actions/QSBGrabAction.cs +++ b/QSB/EchoesOfTheEye/Ghosts/Actions/QSBGrabAction.cs @@ -1,4 +1,5 @@ using GhostEnums; +using QSB.Utility; using System; using System.Collections.Generic; using System.Linq; @@ -65,15 +66,23 @@ internal class QSBGrabAction : QSBGhostAction { return true; } + if (_data.interestedPlayer.playerLocation.distanceXZ > 1.7f) { _controller.MoveToLocalPosition(_data.interestedPlayer.playerLocation.localPosition, MoveType.GRAB); } + _controller.FaceLocalPosition(_data.interestedPlayer.playerLocation.localPosition, TurnSpeed.FASTEST); if (_sensors.CanGrabPlayer(_data.interestedPlayer)) { + DebugLog.DebugWrite($"Grab player {_data.interestedPlayer.player.PlayerId}!"); GrabPlayer(); } + else + { + DebugLog.DebugWrite($"can't grab player {_data.interestedPlayer.player.PlayerId}"); + } + return !_grabAnimComplete; } diff --git a/QSB/EchoesOfTheEye/Ghosts/Actions/QSBSentryAction.cs b/QSB/EchoesOfTheEye/Ghosts/Actions/QSBSentryAction.cs index 26a274f1..8fd8962c 100644 --- a/QSB/EchoesOfTheEye/Ghosts/Actions/QSBSentryAction.cs +++ b/QSB/EchoesOfTheEye/Ghosts/Actions/QSBSentryAction.cs @@ -1,5 +1,6 @@ using GhostEnums; using QSB.EchoesOfTheEye.Ghosts; +using QSB.Utility; /// /// @@ -27,6 +28,7 @@ public class QSBSentryAction : QSBGhostAction protected override void OnEnterAction() { + DebugLog.DebugWrite($"ON ENTER ACTION"); _spotlighting = false; _controller.SetLanternConcealed(true, true); _effects.AttachedObject.SetMovementStyle(GhostEffects.MovementStyle.Stalk); @@ -50,6 +52,7 @@ public class QSBSentryAction : QSBGhostAction if (_data.interestedPlayer.isPlayerLocationKnown && !_spotlighting) { + DebugLog.DebugWrite($"Spotlighting player..."); _spotlighting = true; _controller.ChangeLanternFocus(1f, 2f); } @@ -58,12 +61,14 @@ public class QSBSentryAction : QSBGhostAction { if (_data.interestedPlayer.timeSincePlayerLocationKnown > 3f) { + DebugLog.DebugWrite($"Give up on spotlighting player"); _spotlighting = false; _controller.SetLanternConcealed(true, true); _controller.FaceLocalPosition(_targetSentryNode.localPosition + _targetSentryNode.localForward * 10f, TurnSpeed.MEDIUM); return; } + DebugLog.DebugWrite($"Facing last known position..."); _controller.FaceLocalPosition(_data.interestedPlayer.lastKnownPlayerLocation.localPosition, TurnSpeed.FAST); } } diff --git a/QSB/EchoesOfTheEye/Ghosts/Patches/GhostBrainPatches.cs b/QSB/EchoesOfTheEye/Ghosts/Patches/GhostBrainPatches.cs index 6f5fdd5c..c1939fc8 100644 --- a/QSB/EchoesOfTheEye/Ghosts/Patches/GhostBrainPatches.cs +++ b/QSB/EchoesOfTheEye/Ghosts/Patches/GhostBrainPatches.cs @@ -274,11 +274,6 @@ internal class GhostBrainPatches : QSBPatch return true; } - if (!QSBCore.IsHost) - { - return false; - } - __instance.GetWorldObject().Update(); return false; } diff --git a/QSB/EchoesOfTheEye/Ghosts/Patches/GhostPartyPathDirectorPatches.cs b/QSB/EchoesOfTheEye/Ghosts/Patches/GhostPartyPathDirectorPatches.cs index f9d6aeb8..42e0e44d 100644 --- a/QSB/EchoesOfTheEye/Ghosts/Patches/GhostPartyPathDirectorPatches.cs +++ b/QSB/EchoesOfTheEye/Ghosts/Patches/GhostPartyPathDirectorPatches.cs @@ -45,6 +45,11 @@ internal class GhostPartyPathDirectorPatches : QSBPatch return true; } + if (!QSBCore.IsHost) + { + return false; + } + if (__instance._connectedCampfireExtinguished) { return false; diff --git a/QSB/EchoesOfTheEye/Ghosts/QSBGhostAction.cs b/QSB/EchoesOfTheEye/Ghosts/QSBGhostAction.cs index 78450e72..91c0f324 100644 --- a/QSB/EchoesOfTheEye/Ghosts/QSBGhostAction.cs +++ b/QSB/EchoesOfTheEye/Ghosts/QSBGhostAction.cs @@ -1,12 +1,6 @@ using QSB.EchoesOfTheEye.Ghosts.Actions; using QSB.EchoesOfTheEye.Ghosts.WorldObjects; -using QSB.Utility; using QSB.WorldSync; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using UnityEngine; namespace QSB.EchoesOfTheEye.Ghosts; @@ -24,6 +18,11 @@ public abstract class QSBGhostAction public static QSBGhostAction CreateAction(GhostAction.Name name) { + if (!QSBCore.IsHost) + { + return new QSBGhostActionStub { Name = name }; + } + QSBGhostAction ghostAction; switch (name) { @@ -31,7 +30,7 @@ public abstract class QSBGhostAction ghostAction = new QSBWaitAction(); break; case GhostAction.Name.Sleep: - ghostAction = new QSBSleepAction(); + ghostAction = new QSBSleepAction(); break; case GhostAction.Name.Sleepwalk: ghostAction = new QSBSleepwalkAction(); @@ -93,12 +92,24 @@ public abstract class QSBGhostAction { this._running = true; this._enterTime = Time.time; + + if (!QSBCore.IsHost) + { + return; + } + this.OnEnterAction(); } public void ExitAction() { this._running = false; + + if (!QSBCore.IsHost) + { + return; + } + this.OnExitAction(); } diff --git a/QSB/EchoesOfTheEye/Ghosts/WorldObjects/QSBGhostBrain.cs b/QSB/EchoesOfTheEye/Ghosts/WorldObjects/QSBGhostBrain.cs index c58aebf5..bc5ce2cc 100644 --- a/QSB/EchoesOfTheEye/Ghosts/WorldObjects/QSBGhostBrain.cs +++ b/QSB/EchoesOfTheEye/Ghosts/WorldObjects/QSBGhostBrain.cs @@ -1,4 +1,5 @@ using Cysharp.Threading.Tasks; +using GhostEnums; using QSB.EchoesOfTheEye.Ghosts.Messages; using QSB.Messaging; using QSB.Player; @@ -40,6 +41,14 @@ public class QSBGhostBrain : WorldObject, IGhostObject $"\r\nCurrent action:{AttachedObject.GetCurrentActionName()}" + $"\r\nIllumination meter:{_data.illuminatedByPlayerMeter}"; + if (QSBCore.IsHost) + { + foreach (var action in _actionLibrary.OrderByDescending(x => x.CalculateUtility())) + { + label += $"\r\n{action.GetName()}:{action.CalculateUtility()}"; + } + } + return label; } @@ -336,11 +345,19 @@ public class QSBGhostBrain : WorldObject, IGhostObject { if (!AttachedObject.enabled) { + DebugLog.DebugWrite($"attached object is not enabled!"); return; } + AttachedObject._controller.FixedUpdate_Controller(); AttachedObject._sensors.FixedUpdate_Sensors(); _data.FixedUpdate_Data(AttachedObject._controller, AttachedObject._sensors); + + if (!QSBCore.IsHost) + { + return; + } + AttachedObject.FixedUpdate_ThreatAwareness(); if (_currentAction != null) { @@ -354,9 +371,16 @@ public class QSBGhostBrain : WorldObject, IGhostObject { return; } + AttachedObject._controller.Update_Controller(); AttachedObject._sensors.Update_Sensors(); AttachedObject._effects.Update_Effects(); + + if (!QSBCore.IsHost) + { + return; + } + var flag = false; if (_currentAction != null) { @@ -384,8 +408,11 @@ public class QSBGhostBrain : WorldObject, IGhostObject return; } - if (!AttachedObject._intruderConfirmPending && (_data.threatAwareness > GhostData.ThreatAwareness.EverythingIsNormal || _data.players.Values.Any(x => x.playerLocation.distance < 20f) || _data.players.Values.Any(x => x.sensor.isPlayerIlluminatedByUs)) && (_data.players.Values.Any(x => x.sensor.isPlayerVisible) || _data.players.Values.Any(x => x.sensor.inContactWithPlayer))) + if (!AttachedObject._intruderConfirmPending + && (_data.threatAwareness > GhostData.ThreatAwareness.EverythingIsNormal || _data.players.Values.Any(x => x.playerLocation.distance < 20f) || _data.players.Values.Any(x => x.sensor.isPlayerIlluminatedByUs)) + && (_data.players.Values.Any(x => x.sensor.isPlayerVisible) || _data.players.Values.Any(x => x.sensor.inContactWithPlayer))) { + DebugLog.DebugWrite($"INTRUDER CONFIRMED BY SELF"); AttachedObject._intruderConfirmedBySelf = true; AttachedObject._intruderConfirmPending = true; var closestPlayer = _data.players.Values.MinBy(x => x.playerLocation.distance); @@ -498,6 +525,11 @@ public class QSBGhostBrain : WorldObject, IGhostObject public void OnArriveAtPosition() { + if (!QSBCore.IsHost) + { + return; + } + if (_currentAction != null) { _currentAction.OnArriveAtPosition(); @@ -551,7 +583,7 @@ public class QSBGhostBrain : WorldObject, IGhostObject { AttachedObject.enabled = false; AttachedObject._controller.GetDreamLanternController().enabled = false; - ChangeAction(null); + //ChangeAction(null); _data.OnPlayerExitDreamWorld(); } } diff --git a/QSB/Utility/DebugGUI.cs b/QSB/Utility/DebugGUI.cs index 069d865a..c7ddbe37 100644 --- a/QSB/Utility/DebugGUI.cs +++ b/QSB/Utility/DebugGUI.cs @@ -150,9 +150,18 @@ internal class DebugGUI : MonoBehaviour, IAddComponentOnStart WriteLine(2, $"Visible : {player.Visible}"); WriteLine(2, $"Ready : {player.IsReady}"); WriteLine(2, $"Suited Up : {player.SuitedUp}"); + WriteLine(2, $"InDreamWorld : {player.InDreamWorld}"); + if (player.IsReady && QSBWorldSync.AllObjectsReady) { + WriteLine(2, $"Illuminated : {player.LightSensor.IsIlluminated()}"); + var singleLightSensor = player.LightSensor as SingleLightSensor; + foreach (var item in singleLightSensor._lightSources) + { + WriteLine(2, $"- {item.GetLightSourceType()}"); + } + var networkTransform = player.TransformSync; var referenceSector = networkTransform.ReferenceSector; var referenceTransform = networkTransform.ReferenceTransform; @@ -223,6 +232,37 @@ internal class DebugGUI : MonoBehaviour, IAddComponentOnStart #endregion + if (QSBWorldSync.AllObjectsReady) + { + var ghost = QSBWorldSync.GetWorldObjects().First(x => x.AttachedObject._name == "Kamaji"); + WriteLine(4, ghost.AttachedObject._name); + WriteLine(4, $"Action:{ghost.GetCurrentActionName()}"); + WriteLine(4, $"Threat Awareness:{ghost.GetThreatAwareness()}"); + var interestedPlayer = ghost._data.interestedPlayer; + WriteLine(4, $"InterestedPlayer:{(interestedPlayer == null ? "NULL" : interestedPlayer.player.PlayerId)}"); + + foreach (var player in ghost._data.players.Values) + { + WriteLine(4, $"{player.player.PlayerId}"); + WriteLine(4, $"- isPlayerVisible:{player.sensor.isPlayerVisible}"); + WriteLine(4, $"- isPlayerHeldLanternVisible:{player.sensor.isPlayerHeldLanternVisible}"); + WriteLine(4, $"- isIlluminatedByPlayer:{player.sensor.isIlluminatedByPlayer}"); + WriteLine(4, $"- isPlayerLocationKnown:{player.isPlayerLocationKnown}"); + WriteLine(4, $"- timeSincePlayerLocationKnown:{player.timeSincePlayerLocationKnown}"); + var lantern = player.player.AssignedSimulationLantern; + WriteLine(4, $"- IsHeldByPlayer:{lantern.AttachedObject.GetLanternController().IsHeldByPlayer()}"); + WriteLine(4, $"- Concealed:{lantern.AttachedObject.GetLanternController().IsConcealed()}"); + var position = player.player.Camera.transform.position; + WriteLine(4, $"- Camera in vision cone:{ghost.AttachedObject._sensors.CheckPointInVisionCone(position)}"); + WriteLine(4, $"- CheckLineOccluded:{ghost.AttachedObject._sensors.CheckLineOccluded(ghost.AttachedObject._sensors._sightOrigin.position, position)}"); + } + + WriteLine(4, $"First check:{!ghost.AttachedObject._intruderConfirmPending}"); + WriteLine(4, $"Second check:{ghost._data.threatAwareness > GhostData.ThreatAwareness.EverythingIsNormal || ghost._data.players.Values.Any(x => x.playerLocation.distance < 20f) || ghost._data.players.Values.Any(x => x.sensor.isPlayerIlluminatedByUs)}"); + WriteLine(4, $"Third check:{ghost._data.players.Values.Any(x => x.sensor.isPlayerVisible) || ghost._data.players.Values.Any(x => x.sensor.inContactWithPlayer)}"); + } + + /* #region Column4 - Quantum Object Possesion foreach (var player in QSBPlayerManager.PlayerList) @@ -261,6 +301,7 @@ internal class DebugGUI : MonoBehaviour, IAddComponentOnStart } #endregion + */ } private static void DrawWorldObjectLabels()