Skip to content

Commit c2c1d76

Browse files
committed
Merge branch 'main' into stack/07-world-mesh
2 parents 8a98175 + e5fa207 commit c2c1d76

39 files changed

Lines changed: 868 additions & 527 deletions

Assets/Gothic-Core/Scripts/Adapters/Npc/AiHandler.cs

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using Gothic.Core.Extensions;
77
using Gothic.Core.Logging;
88
using Gothic.Core.Models.Vm;
9+
using FreePoint = Gothic.Core.Models.Vob.WayNet.FreePoint;
10+
using WayPoint = Gothic.Core.Models.Vob.WayNet.WayPoint;
911
using Gothic.Core.Services;
1012
using Gothic.Core.Services.Config;
1113
using Gothic.Core.Services.Npc;
@@ -52,12 +54,23 @@ private void Start()
5254
/// </summary>
5355
private void Update()
5456
{
55-
// If NPC/Monster is dead, stop any further process logic.
57+
// If NPC/Monster is dead, only play out the already queued animations (e.g. the dying animation
58+
// enqueued by FightService), then stop any further process logic.
5659
if (Properties.BodyState == VmGothicEnums.BodyState.BsDead)
5760
{
58-
enabled = false;
61+
Properties.CurrentAction.Tick();
62+
63+
if (Properties.CurrentAction.IsFinished())
64+
{
65+
if (Properties.AnimationQueue.Count > 0)
66+
PlayNextAnimation(Properties.AnimationQueue.Dequeue());
67+
else
68+
enabled = false;
69+
}
70+
71+
return;
5972
}
60-
73+
6174
ExecuteActivePerceptions();
6275
ExecuteStates();
6376

@@ -87,7 +100,6 @@ private void Update()
87100
Vm.GlobalOther = Vm.GlobalHero;
88101
}
89102

90-
DaedalusSymbol loopSymbol;
91103
switch (Properties.CurrentLoopState)
92104
{
93105
// None means, the NPC is newly created and didn't execute any Routine as of now OR a State was changed via Daedalus scripts.
@@ -135,7 +147,9 @@ private void Update()
135147
// Go on
136148
else
137149
{
138-
Logger.Log($"Start playing >{Properties.AnimationQueue.Peek().GetType()}< on >{Go.transform.parent.name}<", LogCat.Ai);
150+
// Editor-only: this fires for every dequeued action of every NPC - the string interpolation
151+
// plus file sink would be measurable noise on device.
152+
Logger.LogEditor($"Start playing >{Properties.AnimationQueue.Peek().GetType()}< on >{Go.transform.parent.name}<", LogCat.Ai);
139153
PlayNextAnimation(Properties.AnimationQueue.Dequeue());
140154
}
141155
}
@@ -180,18 +194,25 @@ private void ExecuteActivePerceptions()
180194
return;
181195
}
182196

183-
_npcAiService.UpdateEnemyNpc(NpcInstance);
197+
var hero = (NpcInstance)_gameStateService.GothicVm.GlobalHero;
198+
var assessPlayerRange = _npcHelperService.GetPerceptionRange(VmGothicEnums.PerceptionType.AssessPlayer);
184199

185-
// FIXME - CanSense is not separating between smell, hear, and see as of now. Please add functionality.
186-
if(_npcHelperService.CanSenseNpc(NpcInstance, (NpcInstance)_gameStateService.GothicVm.GlobalHero, false))
200+
if(_npcHelperService.CanSenseNpc(NpcInstance, hero, false, assessPlayerRange))
187201
{
188-
_npcAiService.ExecutePerception(VmGothicEnums.PerceptionType.AssessPlayer, Properties, NpcInstance,null, (NpcInstance)_gameStateService.GothicVm.GlobalHero);
202+
_npcAiService.ExecutePerception(VmGothicEnums.PerceptionType.AssessPlayer, Properties, NpcInstance, null, hero);
189203
}
190204

191-
// FIXME - Throws a lot of errors and warnings when NPCs are nearby monsters (e.g. Bridge guard next to OC)
192-
if(Properties.EnemyNpc != null)
205+
// Scanning all NPCs for the closest enemy is expensive - only do it for NPCs that react to enemies at all.
206+
if (Properties.Perceptions.TryGetValue(VmGothicEnums.PerceptionType.AssessEnemy, out var enemyPerception) &&
207+
enemyPerception >= 0)
193208
{
194-
_npcAiService.ExecutePerception(VmGothicEnums.PerceptionType.AssessEnemy, Properties, NpcInstance,null, Properties.EnemyNpc);
209+
_npcAiService.UpdateEnemyNpc(NpcInstance);
210+
211+
// FIXME - Throws a lot of errors and warnings when NPCs are nearby monsters (e.g. Bridge guard next to OC)
212+
if(Properties.EnemyNpc != null)
213+
{
214+
_npcAiService.ExecutePerception(VmGothicEnums.PerceptionType.AssessEnemy, Properties, NpcInstance,null, Properties.EnemyNpc);
215+
}
195216
}
196217

197218

@@ -267,6 +288,10 @@ public void StartRoutine(int action)
267288
var routineSymbol = Vm.GetSymbolByIndex(action)!;
268289
Vob.CurrentStateName = routineSymbol.Name;
269290

291+
// Reset the previous routine's symbols: a new ZS without own _Loop/_End must not call the old ones.
292+
Properties.StateLoop = 0;
293+
Properties.StateEnd = 0;
294+
270295
var symbolLoop = Vm.GetSymbolByName($"{routineSymbol.Name}_Loop");
271296
if (symbolLoop != null)
272297
{
@@ -316,6 +341,7 @@ public void ClearState(bool callEndFunction)
316341
Properties.AnimationQueue.Clear();
317342
Properties.CurrentAction = new None(new AnimationAction(), NpcData);
318343
Properties.CurrentLoopState = NpcProperties.LoopState.None; // i.e. call StartNextState() next frame
344+
Properties.BodyState = VmGothicEnums.BodyState.BsStand;
319345

320346
PrefabProps.AnimationSystem.StopAllAnimations();
321347
}
@@ -339,7 +365,11 @@ public void ReEnableNpc()
339365
{
340366
var wp = _wayNetService.GetWayNetPoint(currentRoutine.Waypoint);
341367
if (wp != null)
368+
{
342369
gameObject.transform.position = _npcService.GetFreeAreaAtSpawnPoint(wp.Position);
370+
Properties.CurrentFreePoint = wp as FreePoint;
371+
Properties.CurrentWayPoint = wp as WayPoint;
372+
}
343373
else
344374
Logger.LogWarning($"ReEnableNpc: waypoint '{currentRoutine.Waypoint}' not found for {gameObject.name} — NPC will re-enable at current position.", LogCat.Npc);
345375
}

Assets/Gothic-Core/Scripts/Adapters/Npc/INpcSubtitles.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ public interface INpcSubtitles
44
{
55
void ShowSubtitles(string text);
66
void HideSubtitles();
7+
void ScheduleHide(float delay);
78
}
89
}

Assets/Gothic-Core/Scripts/Adapters/Npc/RoutineHandler.cs

Lines changed: 0 additions & 102 deletions
This file was deleted.

Assets/Gothic-Core/Scripts/Adapters/Npc/RoutineHandler.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Assets/Gothic-Core/Scripts/Adapters/UI/Menus/QuestLogMenu.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ private void CreateLists()
203203
rect.SetHeight(rend.sharedMaterial.mainTexture.height);
204204
rect.SetPositionX(halfMainWidth - _arrowMargin);
205205
rect.SetPositionY(halfMainHeight - _arrowMargin);
206+
SetLocalZ(rect, -0.03f);
206207
}
207208

208209
// DOWN
@@ -221,6 +222,7 @@ private void CreateLists()
221222
rect.SetHeight(rend.sharedMaterial.mainTexture.height);
222223
rect.SetPositionX(halfMainWidth - _arrowMargin);
223224
rect.SetPositionY(-halfMainHeight + _arrowMargin);
225+
SetLocalZ(rect, -0.03f);
224226
}
225227
}
226228

@@ -239,7 +241,7 @@ private void CreateContentViewer()
239241
textComp.overflowMode = TextOverflowModes.Page;
240242
textComp.pageToDisplay = 0;
241243

242-
// UP
244+
// UP - right side, above content
243245
{
244246
var go = _resourceCacheService.TryGetPrefabObject(PrefabType.UiButtonTextured, name: "ARROW_UP", parent: contentViewer.go)!;
245247
var rect = go.GetComponentInChildren<RectTransform>();
@@ -254,9 +256,10 @@ private void CreateContentViewer()
254256
rect.SetHeight(rend.sharedMaterial.mainTexture.height);
255257
rect.SetPositionX(halfTextWidth + rend.sharedMaterial.mainTexture.width);
256258
rect.SetPositionY(halfTextHeight + rend.sharedMaterial.mainTexture.height);
259+
SetLocalZ(rect, -0.03f);
257260
}
258261

259-
// DOWN
262+
// DOWN - right side, below content
260263
{
261264
var go = _resourceCacheService.TryGetPrefabObject(PrefabType.UiButtonTextured, name: "ARROW_DOWN", parent: contentViewer.go)!;
262265
var rect = go.GetComponentInChildren<RectTransform>();
@@ -271,9 +274,10 @@ private void CreateContentViewer()
271274
rect.SetHeight(rend.sharedMaterial.mainTexture.height);
272275
rect.SetPositionX(halfTextWidth + rend.sharedMaterial.mainTexture.width);
273276
rect.SetPositionY(-halfTextHeight - rend.sharedMaterial.mainTexture.height);
277+
SetLocalZ(rect, -0.03f);
274278
}
275279

276-
// BACK
280+
// BACK - bottom-left corner, same Y as ARROW_DOWN
277281
{
278282
var go = _resourceCacheService.TryGetPrefabObject(PrefabType.UiButtonTextured, name: "ARROW_BACK", parent: contentViewer.go)!;
279283
var rect = go.GetComponentInChildren<RectTransform>();
@@ -284,10 +288,12 @@ private void CreateContentViewer()
284288
rend.sharedMaterial = TextureService.ArrowLeftMaterial;
285289
button.onClick.AddListener(OnContentViewerBackClick);
286290

291+
var arrowW = rend.sharedMaterial.mainTexture.width * go.transform.localScale.x;
287292
rect.SetWidth(rend.sharedMaterial.mainTexture.width);
288293
rect.SetHeight(rend.sharedMaterial.mainTexture.height);
289-
rect.SetPositionX(-halfTextWidth - rend.sharedMaterial.mainTexture.width);
290-
rect.SetPositionY(halfTextHeight + rend.sharedMaterial.mainTexture.height);
294+
rect.SetPositionX(-halfTextWidth + arrowW);
295+
rect.SetPositionY(-halfTextHeight - rend.sharedMaterial.mainTexture.height);
296+
SetLocalZ(rect, -0.03f);
291297
}
292298
}
293299

@@ -399,8 +405,12 @@ private void OnListItemClicked(int index)
399405
Background.SetActive(false);
400406

401407
var contentViewer = MenuItemCache[_instanceContentViewer].go;
402-
contentViewer.GetComponentInChildren<TMP_Text>().text = text;
408+
var tmpText = contentViewer.GetComponentInChildren<TMP_Text>();
409+
tmpText.text = text;
403410
contentViewer.SetActive(true);
411+
tmpText.ForceMeshUpdate(ignoreActiveState: true);
412+
foreach (var subMesh in tmpText.GetComponentsInChildren<TMP_SubMeshUI>())
413+
SetLocalZ(subMesh.rectTransform, -0.02f);
404414
}
405415

406416
private void OnArrowUpClick()
@@ -464,5 +474,12 @@ protected override void ExecuteCommand(string itemName, string commandName)
464474
// If the Command==ListMenu, then we set it as currently active.
465475
_listMenuCache.TryGetValue(menuItemName, out _activeListMenu);
466476
}
477+
478+
private static void SetLocalZ(RectTransform rect, float z)
479+
{
480+
var pos = rect.localPosition;
481+
pos.z = z;
482+
rect.localPosition = pos;
483+
}
467484
}
468485
}

0 commit comments

Comments
 (0)