public static bool ImportArticyQuests(Project project, string questContainerExternalId) { ArticyFlowObject questContainer; try { questContainer = project.GetFlowObject(questContainerExternalId); } catch { throw new UserFriendlyException( String.Format("Could not find quest container '{0}' in the project.", questContainerExternalId), "One of data files does not contain required information." ); } IList <GraphNode> quests = questContainer.Children; GameDebugger.Log(LogLevel.Debug, "{0} quests found:", quests.Count); ArticyFlowFragment articyQuest; Quest quest; Dictionary <ulong, QuestPin> pinIndex = new Dictionary <ulong, QuestPin>(); List <Jump> articyJumps = new List <Jump>(); bool badScripts = false; // copy quests foreach (GraphNode node in questContainer.Children) { // hubs are used to join quests for further story progression: hub remains inactive until all quests connected to the hub are complete if (node is ArticyHub) { ArticyHub articyHub = (ArticyHub)node; QuestHub hub = new QuestHub(articyHub.Id, articyHub.ExternalId); badScripts |= ImportArticyPins(articyHub, hub, true, true, pinIndex); GameDebugger.Log(LogLevel.Debug, "Adding quest hub '0x{0:X16}'", hub.Id); Add(hub); } // flow fragments are quests if (node is ArticyFlowFragment) { articyQuest = (ArticyFlowFragment)node; quest = new Quest(articyQuest.Id, articyQuest.ExternalId); GameDebugger.Log(LogLevel.Debug, "Importing quest '{0}'", quest.Key); GameDebugger.Log(LogLevel.Debug, "Quest has {0} inputs and {1} outputs", articyQuest.Inputs.Count, articyQuest.Outputs.Count); badScripts |= ImportArticyPins(articyQuest, quest, true, true, pinIndex); quest.Name = articyQuest.DisplayName; quest.Description = articyQuest.Text; Add(quest); // copy quest fragments foreach (GraphNode childNode in node.Children) { if (childNode is ArticyDialogue || childNode is ArticyDialogueFragment) { throw new UserFriendlyException( String.Format("Dialogue or dialogue fragment '0x{0:X16}' is not supposed to be a part of a quest", ((ArticyFlowFragment)childNode).Id), "One of data files is either corupt or has a version that is not supported by the game engine." ); } if (childNode is ArticyFlowFragment) { ArticyFlowFragment articyFragment = (ArticyFlowFragment)childNode; if (string.IsNullOrWhiteSpace(articyFragment.DisplayName)) { QuestLogicGate gate = new QuestLogicGate(articyFragment.Id, articyFragment.ExternalId); badScripts |= ImportArticyPins(articyFragment, gate, true, true, pinIndex); GameDebugger.Log(LogLevel.Debug, "Adding logic gate '0x{0:X16}' to the quest", gate.Id); quest.AddChild(gate); Add(gate); } else { QuestObjective objective = new QuestObjective(articyFragment.Id, articyFragment.ExternalId); objective.Description = articyFragment.Text; badScripts |= ImportArticyPins(articyFragment, objective, true, true, pinIndex); GameDebugger.Log(LogLevel.Debug, "Adding objective '0x{0:X16}' to the quest", objective.Id); objective.Name = articyFragment.DisplayName; objective.Description = articyFragment.Text; quest.AddChild(objective); Add(objective); } } if (childNode is ArticyCondition) { ArticyCondition articyCondition = (ArticyCondition)childNode; QuestCondition condition = new QuestCondition(articyCondition.Id, articyCondition.ExternalId); if (string.IsNullOrWhiteSpace(articyCondition.Script)) { badScripts = true; GameDebugger.Log(LogLevel.Error, "Condition '0x{0:X16}' has no script", condition.Id); } else { if ((condition.Script = CompileScript(articyCondition.Script, Quests.ConditionScriptEnvironment, "condition", condition.Id)) == null) { badScripts = true; } } badScripts |= ImportArticyPins(articyCondition, condition, true, true, pinIndex); GameDebugger.Log(LogLevel.Debug, "Adding condition '0x{0:X16}' to the quest", condition.Id); quest.AddChild(condition); Add(condition); } if (childNode is ArticyInstruction) { ArticyInstruction articyInstruction = (ArticyInstruction)childNode; QuestInstruction instruction = new QuestInstruction(articyInstruction.Id, articyInstruction.ExternalId); if (string.IsNullOrWhiteSpace(articyInstruction.Script)) { GameDebugger.Log(LogLevel.Notice, "Instruction '0x{0:X16}' has no script", instruction.Id); } else { if ((instruction.Script = CompileScript(articyInstruction.Script, Quests.ConditionScriptEnvironment, "instruction", instruction.Id)) == null) { badScripts = true; } } badScripts |= ImportArticyPins(articyInstruction, instruction, true, true, pinIndex); GameDebugger.Log(LogLevel.Debug, "Adding instruction '0x{0:X16}' to the quest", instruction.Id); quest.AddChild(instruction); Add(instruction); } if (childNode is ArticyHub) { ArticyHub articyHub = (ArticyHub)childNode; QuestSavePoint savePoint = new QuestSavePoint(articyHub.Id, articyHub.ExternalId); badScripts |= ImportArticyPins(articyHub, savePoint, true, true, pinIndex); GameDebugger.Log(LogLevel.Debug, "Adding save point '0x{0:X16}' to the quest", savePoint.Id); quest.AddChild(savePoint); Add(savePoint); } if (childNode is Jump) { articyJumps.Add((Jump)childNode); } } } } // jumps need postprocessing, because we must make sure all quest system nodes are already added // jumps must be treated as connections. they must be disallowed to connect to anything outside the scope of current quest. BaseQuestObject obj; QuestPin srcPin, dstPin; IList <GraphPin> inputs; foreach (Jump articyJump in articyJumps) { GameDebugger.Log(LogLevel.Debug, "Linking jump '0x{0:X16}'", articyJump.Id); if (articyJump.TargetPin != null) { if (!pinIndex.TryGetValue(articyJump.TargetPin.Id, out dstPin)) { GameDebugger.Log(LogLevel.Debug, "Ignoring jump '0x{0:X16}' since it's target pin is outside the quest container", articyJump.Id); continue; } } else if (articyJump.Target != null) { inputs = articyJump.Target.Inputs; if (inputs.Count == 0) { GameDebugger.Log(LogLevel.Debug, "Ignoring jump '0x{0:X16}' since it's target does not have input pins", articyJump.Id); continue; } if (!pinIndex.TryGetValue(((FlowObjectPin)inputs[0]).Id, out dstPin)) { GameDebugger.Log(LogLevel.Debug, "Ignoring jump '0x{0:X16}' since it's target is outside the quest container", articyJump.Id); continue; } } else { continue; } obj = (BaseQuestObject)dstPin.Node; if (obj.Parent == null || !(obj.Parent is Quest) || ((Quest)obj.Parent).Id != ((ArticyFlowObject)articyJump.Parent).Id) { GameDebugger.Log(LogLevel.Debug, "Ignoring jump '0x{0:X16}' since it's not targetting an object within the same quest", articyJump.Id); continue; } foreach (FlowObjectPin pin in articyJump.Inputs) { foreach (ArticyFlowConnection articyConnection in pin.Connections) { if (articyConnection.Target != pin) { continue; } if (!pinIndex.TryGetValue(((FlowObjectPin)articyConnection.Source).Id, out srcPin)) { continue; } QuestConnection newConnection = new QuestConnection(articyConnection.Id, articyConnection.ExternalId); newConnection.Source = srcPin; newConnection.Target = dstPin; GameDebugger.Log(LogLevel.Debug, "Connected '0x{0:X16}' to '0x{1:X16}' (jump replacement)", ((BaseQuestObject)newConnection.Source.Node).Id, ((BaseQuestObject)newConnection.Target.Node).Id); } } } // recreate connections foreach (ArticyFlowConnection articyConnection in project.FlowConnections) { if (!pinIndex.TryGetValue(((FlowObjectPin)articyConnection.Target).Id, out dstPin)) { continue; } if (dstPin.Type == GraphPin.PinType.Input && dstPin.Node is Quest && articyConnection.Source.Node == questContainer) { if (!m_InitiallyActiveQuestPins.Contains(dstPin)) { m_InitiallyActiveQuestPins.Add(dstPin); } GameDebugger.Log(LogLevel.Debug, "Adding pin '0x{0:X16}' to list of initially active quest pins", dstPin.Id); continue; } if (!pinIndex.TryGetValue(((FlowObjectPin)articyConnection.Source).Id, out srcPin)) { continue; } QuestConnection newConnection = new QuestConnection(articyConnection.Id, articyConnection.ExternalId); newConnection.Source = srcPin; newConnection.Target = dstPin; GameDebugger.Log(LogLevel.Debug, "Connected '0x{0:X16}' to '0x{1:X16}'", ((BaseQuestObject)newConnection.Source.Node).Id, ((BaseQuestObject)newConnection.Target.Node).Id); } return(badScripts); }
public static bool ImportArticyDialogues(Project project, string dialogueContainerExternalId) { ArticyFlowObject dialogueContainer; try { dialogueContainer = project.GetFlowObject(dialogueContainerExternalId); } catch { throw new UserFriendlyException( String.Format("Could not find dialogue container '{0}' in the project.", dialogueContainerExternalId), "One of data files does not contain required information." ); } IList <GraphNode> dialogues = dialogueContainer.Children; GameDebugger.Log(LogLevel.Debug, "{0} dialogues found:", dialogues.Count); ArticyDialogue articyDialogue; Dialogue dialogue; Dictionary <ulong, DialoguePin> pinIndex = new Dictionary <ulong, DialoguePin>(); List <Jump> articyJumps = new List <Jump>(); DialogueJump jump; bool badScripts = false; // copy dialogues foreach (GraphNode node in dialogueContainer.Children) { if (!(node is ArticyDialogue)) { continue; } articyDialogue = (ArticyDialogue)node; dialogue = new Dialogue(articyDialogue.Id, articyDialogue.ExternalId); GameDebugger.Log(LogLevel.Debug, "Importing dialogue '{0}'", dialogue.Key); GameDebugger.Log(LogLevel.Debug, "Dialogue has {0} inputs and {1} outputs", articyDialogue.Inputs.Count, articyDialogue.Outputs.Count); badScripts |= ImportArticyPins(articyDialogue, dialogue, false, false, pinIndex); Add(dialogue); // copy dialogue fragments foreach (GraphNode childNode in node.Children) { if (childNode is ArticyFlowFragment) { throw new UserFriendlyException( String.Format("FlowFragment '0x{0:X16}' is not supposed to be a part of a dialogue", ((ArticyFlowFragment)childNode).Id), "One of data files is either corupt or has a version that is not supported by the game engine." ); } if (childNode is ArticyDialogueFragment) { ArticyDialogueFragment articyFragment = (ArticyDialogueFragment)childNode; DialogueFragment fragment = new DialogueFragment(articyFragment.Id, articyFragment.ExternalId); fragment.ActorId = (articyFragment.Speaker == null) ? 0UL : articyFragment.Speaker.Id; fragment.MenuText = articyFragment.MenuText; fragment.Text = articyFragment.Text; fragment.Extra = articyFragment.StageDirections; badScripts |= ImportArticyPins(articyFragment, fragment, true, true, pinIndex); GameDebugger.Log(LogLevel.Debug, "Adding fragment '0x{0:X16}' to the dialogue", fragment.Id); dialogue.AddChild(fragment); Add(fragment); } if (childNode is ArticyCondition) { ArticyCondition articyCondition = (ArticyCondition)childNode; DialogueCondition condition = new DialogueCondition(articyCondition.Id, articyCondition.ExternalId); if (string.IsNullOrWhiteSpace(articyCondition.Script)) { badScripts = true; GameDebugger.Log(LogLevel.Error, "Condition '0x{0:X16}' has no script", condition.Id); } else { if ((condition.Script = CompileScript(articyCondition.Script, Dialogues.ConditionScriptEnvironment, "condition", condition.Id)) == null) { badScripts = true; } } badScripts |= ImportArticyPins(articyCondition, condition, true, true, pinIndex); GameDebugger.Log(LogLevel.Debug, "Adding condition '0x{0:X16}' to the dialogue", condition.Id); dialogue.AddChild(condition); Add(condition); } if (childNode is ArticyInstruction) { ArticyInstruction articyInstruction = (ArticyInstruction)childNode; DialogueInstruction instruction = new DialogueInstruction(articyInstruction.Id, articyInstruction.ExternalId); if (string.IsNullOrWhiteSpace(articyInstruction.Script)) { GameDebugger.Log(LogLevel.Notice, "Instruction '0x{0:X16}' has no script", instruction.Id); } else { if ((instruction.Script = CompileScript(articyInstruction.Script, Dialogues.ConditionScriptEnvironment, "instruction", instruction.Id)) == null) { badScripts = true; } } badScripts |= ImportArticyPins(articyInstruction, instruction, true, true, pinIndex); GameDebugger.Log(LogLevel.Debug, "Adding instruction '0x{0:X16}' to the dialogue", instruction.Id); dialogue.AddChild(instruction); Add(instruction); } if (childNode is ArticyHub) { ArticyHub articyHub = (ArticyHub)childNode; DialogueHub hub = new DialogueHub(articyHub.Id, articyHub.ExternalId); badScripts |= ImportArticyPins(articyHub, hub, true, true, pinIndex); GameDebugger.Log(LogLevel.Debug, "Adding hub '0x{0:X16}' to the dialogue", hub.Id); dialogue.AddChild(hub); Add(hub); } if (childNode is Jump) { Jump articyJump = (Jump)childNode; jump = new DialogueJump(articyJump.Id, articyJump.ExternalId); badScripts |= ImportArticyPins(articyJump, jump, true, true, pinIndex); GameDebugger.Log(LogLevel.Debug, "Adding jump '0x{0:X16}' to the dialogue", jump.Id); m_Objects.Add(jump.Id, jump); dialogue.AddChild(jump); Add(jump); articyJumps.Add(articyJump); } } } // jumps need postprocessing, because we must make sure all dialogue system nodes are already added BaseDialogueObject obj; DialoguePin pin; foreach (Jump articyJump in articyJumps) { jump = (DialogueJump)m_Objects[articyJump.Id]; GameDebugger.Log(LogLevel.Debug, "Linking jump '0x{0:X16}'", jump.Id); if (articyJump.Target != null) { if (!m_Objects.TryGetValue(articyJump.Target.Id, out obj)) { throw new UserFriendlyException( String.Format("Jump '0x{0:X16}' references an object outside the dialogue container", jump.Id), "One of data files is either corupt or has a version that is not supported by the game engine." ); } jump.Target = obj; GameDebugger.Log(LogLevel.Debug, "Linked target to {0} '0x{1:X16}'", obj.GetType().Name, obj.Id); } if (articyJump.TargetPin != null) { if (articyJump.TargetPin.Node == dialogueContainer) { throw new UserFriendlyException( String.Format("Jump '0x{0:X16}' references a pin of the dialogue container itself", jump.Id), "One of data files is either corupt or has a version that is not supported by the game engine." ); } if (!pinIndex.TryGetValue(articyJump.TargetPin.Id, out pin)) { throw new UserFriendlyException( String.Format("Jump '0x{0:X16}' references a pin outside the dialogue container", jump.Id), "One of data files is either corupt or has a version that is not supported by the game engine." ); } jump.TargetPin = pin; GameDebugger.Log(LogLevel.Debug, "Linked target pin to '0x{0:X16}'", articyJump.TargetPin.Id); } } // recreate connections DialoguePin srcPin, dstPin; foreach (ArticyFlowConnection articyConnection in project.FlowConnections) { if (articyConnection.Source.Node is ArticyFlowFragment || articyConnection.Target.Node is ArticyFlowFragment || (articyConnection.Source.Node is ArticyDialogue && articyConnection.Target.Node is ArticyDialogue) || !pinIndex.TryGetValue(((FlowObjectPin)articyConnection.Source).Id, out srcPin) || !pinIndex.TryGetValue(((FlowObjectPin)articyConnection.Target).Id, out dstPin) ) { continue; } GraphConnection newConnection = new GraphConnection(); newConnection.Source = srcPin; newConnection.Target = dstPin; GameDebugger.Log(LogLevel.Debug, "Connected '0x{0:X16}' to '0x{1:X16}'", ((BaseDialogueObject)newConnection.Source.Node).Id, ((BaseDialogueObject)newConnection.Target.Node).Id); } return(badScripts); }