Files
Net.Like.Xue.Tokyo/Packages-Local/Com.Project.B.Unity/Quest/WorldQuestService.cs

71 lines
2.6 KiB
C#
Raw Normal View History

2025-06-24 23:49:13 +08:00
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using BITKit;
using BITKit.Entities;
using Net.BITKit.Localization;
using Net.Project.B.Interaction;
using Project.B.Map;
using UnityEngine;
using Object = UnityEngine.Object;
namespace Net.Project.B.Quest
{
public class WorldQuestService
{
private readonly IGameMapService _gameMapService;
private readonly ILocalizationService _localizationService;
private readonly IQuestService _questService;
private readonly IEntitiesService _entitiesService;
private readonly IWorldInteractionService _interactionService;
private readonly ConcurrentDictionary<int, QuestData> _quests = new();
public WorldQuestService(IWorldInteractionService interactionService, IEntitiesService entitiesService, IQuestService questService, ILocalizationService localizationService, IGameMapService gameMapService)
{
_interactionService = interactionService;
_entitiesService = entitiesService;
_questService = questService;
_localizationService = localizationService;
_gameMapService = gameMapService;
_interactionService.OnInteraction += OnInteraction;
_gameMapService.OnMapChanged += OnMapChangeCompleted;
}
private void OnMapChangeCompleted(Guid arg1, string arg2)
{
foreach (var questData in _quests.Values.ToArray())
{
var quest = questData;
quest.CurrentState = QuestState.Canceled;
_questService.AddOrUpdateQuest(quest);
}
}
private void OnInteraction(object arg1, IWorldInteractable arg2, WorldInteractionProcess arg3, object arg4)
{
if (arg3 is not (WorldInteractionProcess.Performed or WorldInteractionProcess.System)) return;
if (_entitiesService.Entities.TryGetValue(arg2.Id, out var entity) is false) return;
if (entity.ServiceProvider.QueryComponents(out IQuestNode questNode) is false) return;
if (arg2.WorldObject is GameObject gameObject)
{
Object.Destroy(gameObject);
}
_questService.AddOrUpdateQuest(_quests[arg2.Id] = new QuestData()
{
Identity = arg2.Id,
Name = _localizationService.GetLocalizedString(questNode.GetType().Name),
CurrentState = QuestState.Active
// Description = "去指定地点,对目标进行调查"
});
}
}
}