forked from aly/qstbak
91 lines
2.7 KiB
C#
91 lines
2.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Numerics;
|
|
using Microsoft.Extensions.Logging;
|
|
using Questionable.Data;
|
|
using Questionable.Model;
|
|
using Questionable.Model.Questing;
|
|
using Questionable.Navigation;
|
|
using SmartNav;
|
|
using SmartNav.Data;
|
|
using SmartNav.Model;
|
|
|
|
namespace Questionable.Controller.Steps.Shared;
|
|
|
|
internal static class SmartNavStep
|
|
{
|
|
internal sealed class Factory(NavRouter navRouter, PlayerNavStateBuilder playerNavStateBuilder, RouteInstructionBuilder instructionBuilder, SmartNavTaskMapper taskMapper, SmartNavReRouteService reRouteService, AetheryteData aetheryteData, TerritoryData territoryData, ILogger<Factory> logger) : ITaskFactory
|
|
{
|
|
public bool HandledRouting { get; private set; }
|
|
|
|
public IEnumerable<ITask> CreateAllTasks(Quest quest, QuestSequence sequence, QuestStep step)
|
|
{
|
|
HandledRouting = false;
|
|
Vector3? vector = ResolveDestination(step);
|
|
if (!vector.HasValue)
|
|
{
|
|
yield break;
|
|
}
|
|
PlayerNavState playerNavState = playerNavStateBuilder.Build();
|
|
if (playerNavState == null)
|
|
{
|
|
yield break;
|
|
}
|
|
RouteResult routeResult = navRouter.FindRoute(playerNavState, step.TerritoryId, vector.Value);
|
|
if (routeResult.Segments.Count == 0)
|
|
{
|
|
yield break;
|
|
}
|
|
HandledRouting = true;
|
|
logger.LogDebug("SmartNav routing to {Territory} with {Count} segments", territoryData.GetNameAndId(step.TerritoryId), routeResult.Segments.Count);
|
|
reRouteService.SetDestination(step.TerritoryId, vector.Value);
|
|
foreach (ITask item in taskMapper.MapInstructions(instructionBuilder.Build(routeResult, step.TerritoryId, step.DisableNavmesh), step))
|
|
{
|
|
yield return item;
|
|
}
|
|
}
|
|
|
|
private Vector3? ResolveDestination(QuestStep step)
|
|
{
|
|
if (step.Position.HasValue)
|
|
{
|
|
return step.Position;
|
|
}
|
|
EAetheryteLocation valueOrDefault = default(EAetheryteLocation);
|
|
bool flag;
|
|
if (step != null)
|
|
{
|
|
EInteractionType interactionType = step.InteractionType;
|
|
if ((uint)(interactionType - 4) <= 1u)
|
|
{
|
|
EAetheryteLocation? aetheryte = step.Aetheryte;
|
|
if (aetheryte.HasValue)
|
|
{
|
|
valueOrDefault = aetheryte.GetValueOrDefault();
|
|
flag = true;
|
|
goto IL_004b;
|
|
}
|
|
}
|
|
}
|
|
flag = false;
|
|
goto IL_004b;
|
|
IL_004b:
|
|
if (flag && aetheryteData.Locations.TryGetValue(valueOrDefault, out var value))
|
|
{
|
|
return value;
|
|
}
|
|
if (step != null && step.InteractionType == EInteractionType.AttuneAethernetShard)
|
|
{
|
|
EAetheryteLocation? aetheryte = step.AethernetShard;
|
|
if (aetheryte.HasValue)
|
|
{
|
|
EAetheryteLocation valueOrDefault2 = aetheryte.GetValueOrDefault();
|
|
if (aetheryteData.Locations.TryGetValue(valueOrDefault2, out var value2))
|
|
{
|
|
return value2;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|