public async Task <IActionResult> GetDialogsObjectIsReferenced(string objectId) { List <TaleDialog> dialogs = await _taleDbAccess.GetDialogsObjectIsReferenced(objectId); List <KortistoNpc> npcs = await _npcDbAccess.ResolveFlexFieldObjectNames(dialogs.Select(d => d.RelatedObjectId).ToList()); Dictionary <string, string> npcNames = npcs.ToDictionary(n => n.Id, n => n.Name); List <ObjectReference> objectReferences = dialogs.Select(d => { if (!npcNames.ContainsKey(d.RelatedObjectId)) { return(null); } return(_referenceAnalyzer.BuildObjectReferences(objectId, d.RelatedObjectId, npcNames[d.RelatedObjectId], d.Action, d.Condition, d.Reference, d.Choice)); }).Where(o => o != null).ToList(); return(Ok(objectReferences)); }
public async Task <IActionResult> GetStateMachineObjectIsReferenced(string objectId) { List <StateMachine> stateMachines = await _stateMachineDbAccess.GetStateMachinesObjectIsReferenced(objectId); List <KortistoNpc> npcs = await _npcDbAccess.ResolveFlexFieldObjectNames(stateMachines.Select(d => d.RelatedObjectId).ToList()); List <KortistoNpc> npcTemplates = await _npcTemplateDbAccess.ResolveFlexFieldObjectNames(stateMachines.Select(d => d.RelatedObjectId).ToList()); Dictionary <string, string> npcNames = npcs.ToDictionary(n => n.Id, n => n.Name); Dictionary <string, string> npcTemplateNames = npcTemplates.ToDictionary(n => n.Id, n => n.Name); List <ObjectReferenceWithType> objectReferences = stateMachines.SelectMany(d => { ObjectReferenceType?referenceType = null; string objectName = string.Empty; if (npcNames.ContainsKey(d.RelatedObjectId)) { referenceType = ObjectReferenceType.Npc; objectName = npcNames[d.RelatedObjectId]; } else if (npcTemplateNames.ContainsKey(d.RelatedObjectId)) { referenceType = ObjectReferenceType.NpcTemplate; objectName = npcTemplateNames[d.RelatedObjectId]; } else { return(new List <ObjectReferenceWithType>()); } return(d.State.Where(s => s.ScriptNodeGraph != null).Select(s => { ObjectReference objRef = _referenceAnalyzer.BuildObjectReferences(objectId, d.RelatedObjectId, objectName, s.ScriptNodeGraph.Action, s.ScriptNodeGraph.Condition, s.ScriptNodeGraph.Reference, null); ObjectReferenceWithType refWithType = ObjectReferenceWithType.FromObjectReference(objRef, referenceType.Value); return refWithType; }).Where(r => r.DetailedReferences.Any()).ToList()); }).ToList(); return(Ok(objectReferences)); }