public DialogueConditionControl(DialogueCondition dialogueCondition) { InitializeComponent(); childIDList = new List <IDialoguePointID>(); if (dialogueCondition == null) { this.dialogueCondition = new DialogueCondition(); this.dialogueCondition.text = ""; this.dialogueCondition.enumDialogueType = EnumDialogueType.Normal; this.dialogueCondition.maxLevel = 99; this.dialogueCondition.minLevel = -1; this.dialogueCondition.overTask = -1; this.dialogueCondition.thisTask = -1; this.dialogueCondition.minGoodAndEvil = -9999; this.dialogueCondition.maxGoodAndEvil = 9999; this.dialogueCondition.race = RoleOfRace.None; } else { this.dialogueCondition = dialogueCondition; if (string.IsNullOrEmpty(this.dialogueCondition.text)) { this.dialogueCondition.text = ""; } } Init(); }
/// <summary> /// 初始化对话 /// 展示如下对话 /// </summary> /// <param name="dialogueCodition">对话数据</param> private void InitTalk(DialogueCondition dialogueCodition) { this.dialogueCodition = dialogueCodition; this.nowDialoguePoint = this.dialogueCodition.topPoint; showLeftOrRight = true; ShowTalk(); }
private bool EvaluateCondition(DialogueCondition condition) { //local dialogue condition if (condition.ID == "duringgreeting") { if (_entries.Count <= 0) { return(true); } else { return(false); } } else if (condition.ID == "isawake") { return(true); } //story condition if (condition.StoryTriggerID != null) { return(GameManager.Inst.QuestManager.StoryConditions[condition.StoryTriggerID].Evaluate(condition.StoryTriggerCompare, condition.StoryTriggerCompareOp)); } return(true); }
/// <summary> /// Creates a new DialogueCondition in the Assets folder. /// </summary> /// <param name="assetName">The file name for the new asset.</param> private void CreateConditionAsset(string assetName) { string assetPath = $"Assets/{assetName}.asset"; bool writeFile = true; // Check if the file already exists. if (File.Exists(assetPath)) { writeFile = EditorUtility.DisplayDialog( "Existing File Found", "A file with the same name already exists.Overwrite?", "Overwrite", "Cancel" ); } // If it isn't okay to write the file, exit early. if (!writeFile) { return; } // Create the DialogueCondition asset. DialogueCondition condition = CreateInstance <DialogueCondition>(); // Save the asset file. AssetDatabase.CreateAsset(condition, assetPath); // Reset the text field and select the new DialogueCondition. _conditionNameTextField.value = "New Condition"; _conditionObjectField.value = condition; }
/// <summary> /// 初始化不显示的节点 /// </summary> private void InitDontShowTalk(DialogueCondition dialogueCodition) { dontShowDialoguePointList = new List <DialoguePoint>(); //查找所有的存在任务id的节点 Queue <int> taskIDQueue = new Queue <int>(); Queue <DialoguePoint> taskPointQueue = new Queue <DialoguePoint>(); PushDialoguePointTask(dialogueCodition.topPoint, taskIDQueue, taskPointQueue); //判断可以接取的任务 TaskMap.RunTimeTaskInfo[] runTimeTaskInfos = iNowTaskState.GetWaitTask(null); var waitTaskIDs = runTimeTaskInfos.Select(temp => temp.ID); var waitTaskIDArray = waitTaskIDs.Intersect(taskIDQueue).ToArray(); foreach (DialoguePoint dialoguePoint in taskPointQueue) { DialoguePoint tempDP = null; foreach (int taskID in waitTaskIDArray) { if (DialoguePointHasThisTask(dialoguePoint, taskID.ToString(), out tempDP))//如果找到了则直接返回 { break; } } //如果没有找到,则表示节点下没有任务或者只存在过期的任务,放入不显示节点中 if (tempDP == null) { dontShowDialoguePointList.Add(dialoguePoint); } } }
public DialogueNodePort(Port port, Action <Node, Port> onClickRemovePort, string responseText = "", DialogueCondition condition = null) { Port = port; ResponseText = responseText; ConditionToToggle = condition; port.contentContainer.Add(GenerateDeleteButton(onClickRemovePort)); port.contentContainer.Add(GenerateFoldout()); }
/// <summary> /// 创建一个顶级节点 /// </summary> /// <param name="conditionData">关系数据</param> /// <param name="updateControl">是否立即更新</param> private DialogueConditionControl CreateNewTopNode(DialogueCondition conditionData = null, bool updateControl = true) { Panel p = new Panel(); FlowLayoutPanel_Main.Controls.Add(p); DialogueConditionControl dialogueConditionControl = new DialogueConditionControl(conditionData); dialogueConditionControl.Size = dialogueConditionControl.StopSize; dialogueConditionControl.SetListenControlSelected(ListenControlSelected); dialogueConditionControl.SetLiestenOpenStop(AddListenOpenStop); dialogueConditionControl.Tag = new List <Control>(); p.Controls.Add(dialogueConditionControl); p.Paint += (sender, e) => { Graphics g = e.Graphics; g.Clear(p.BackColor); //绘制连接线 Pen pen = new Pen(Color.Red); foreach (Control control in p.Controls.OfType <Control>()) { if (control.Tag == null) { continue; } Size parentSize = control.Size; Point parentLocation = control.Location; List <Control> childControls = control.Tag as List <Control>; if (parentLocation.X >= 0 && parentLocation.Y >= 0) { foreach (Control childControl in childControls) { Size childSize = childControl.Size; Point childLocation = childControl.Location; if (childLocation.X >= 0 && childLocation.Y >= 0) { g.DrawBezier(pen, new Point(parentLocation.X + parentSize.Width, parentLocation.Y + parentSize.Height / 2), new Point(parentLocation.X + parentSize.Width + 20, parentLocation.Y + parentSize.Height / 2), new Point(childLocation.X - 20, childLocation.Y + childSize.Height / 2), new Point(childLocation.X, childLocation.Y + childSize.Height / 2)); } } } } }; if (updateControl) { ResetControlRect(p); } if (searchNodeForm != null) { searchNodeForm.NodeChanged = true; } return(dialogueConditionControl); }
/// <summary> /// Generates a new ConditionNode with existing data. /// </summary> /// <param name="nodeData"></param> public ConditionNode(ConditionNodeData nodeData) { Guid = nodeData.guid; type = NodeType.Condition; ConditionToTest = nodeData.conditionToTest; styleSheets.Add(Resources.Load <StyleSheet>("Node")); GenerateOutputPorts(); BuildNodeControls(); UpdateNodeFields(); }
/// <summary> /// 将panel的数据设置到TreeNode中 /// </summary> /// <param name="treeNode">树节点</param> /// <param name="panel">对应的panel</param> private void SetPanelToTreeNode(TreeNode treeNode, Panel panel) { treeNode.Tag = panel; DialogueConditionControl dialogueConditionControl = panel.Controls.OfType <DialogueConditionControl>().FirstOrDefault(); DialogueCondition dialogueCondition = dialogueConditionControl.GetDialogueCondition(); treeNode.Text = "Text:[" + dialogueCondition.text + "];Type:[" + dialogueCondition.enumDialogueType + "]"; if (dialogueConditionControl.Tag != null && (dialogueConditionControl.Tag as List <Control>) != null && (dialogueConditionControl.Tag as List <Control>).Count > 0) { SetControlToTreeNode(treeNode, (dialogueConditionControl.Tag as List <Control>).ToArray()); } }
// Adds an empty DialogueNodePort to the node's output container. private void AddDialogueNodePorts(string responseText = "", DialogueCondition condition = null) { DialogueNodePort dialogueNodePort = new DialogueNodePort( GeneratePort(this, "Out", Direction.Output, type: typeof(string)), onClickRemovePort, responseText, condition); DialogueNodePorts.Add(dialogueNodePort); outputContainer.Add(dialogueNodePort.Port); RefreshExpandedState(); RefreshPorts(); }
private void GetTokens(XmlNode nodeItem, Stack <ConditionToken> theStack) { if (nodeItem.Name == "condition") { XmlAttributeCollection attributes = nodeItem.Attributes; Debug.Log("found condition " + attributes["story"].Value); DialogueCondition condition = new DialogueCondition(); condition.ID = attributes["name"].Value; if (condition.ID.Length > 0) { if (attributes["story"] != null) { condition.StoryTriggerID = attributes["story"].Value; } if (attributes["compare"] != null) { condition.StoryTriggerCompare = Convert.ToInt32(attributes["compare"].Value); } if (attributes["op"] != null) { condition.StoryTriggerCompareOp = Convert.ToInt32(attributes["op"].Value); } theStack.Push(condition); } } else if (nodeItem.Name == "logic") { DialogueConditionOperator op = new DialogueConditionOperator(); XmlAttributeCollection attributes = nodeItem.Attributes; op.Op = (LogicOperator)Enum.Parse(typeof(LogicOperator), attributes["type"].Value); theStack.Push(op); XmlNodeList nodeContent = nodeItem.ChildNodes; if (nodeContent.Count > 0) { foreach (XmlNode child in nodeContent) { Debug.Log("Found logic child"); GetTokens(child, theStack); } } } }
/// <summary> /// Builds the controls. /// </summary> private void BuildNodeControls() { // Create the containing foldout. _contentFoldout = new Foldout { text = "Condition Properties", name = "condition-properties-foldout" }; contentContainer.Add(_contentFoldout); // Create the UIElements.Object field to select the DialogueCondition to test against. _conditionObjectField = new ObjectField("Condition Object") { objectType = typeof(DialogueCondition), allowSceneObjects = false, value = ConditionToTest }; // Create the UIElements.Toggle that controls ConditionToTest.initialValue _conditionObjectToggle = new Toggle("Initial Value") { bindingPath = "initialValue" }; _conditionObjectField.RegisterValueChangedCallback(evt => { ConditionToTest = evt.newValue as DialogueCondition; _conditionObjectToggle.Unbind(); if (ConditionToTest != null) { SerializedObject so = new SerializedObject(ConditionToTest); _conditionObjectToggle.Bind(so); } UpdateNodeFields(); }); // Create the UIElements.TextField that names a new DialogueCondition asset. _conditionNameTextField = new TextField { name = "conditionNameTextField", value = "New Condition" }; // Create the UIElements.Button that will create a new DialogueCondition asset with the name in _conditionNameTextField _createConditionAssetButton = new Button(() => CreateConditionAsset(_conditionNameTextField.value)) { text = "New Condition" }; }
/// <summary> /// 根据现有数据创建控件 /// </summary> private void CreateControlByData() { int[] dialogueConditionIDs = dialogueAnalysisData.GetDialogueConditionAllID; foreach (int dialogueConditionID in dialogueConditionIDs) { DialogueCondition dialogueCondition = dialogueAnalysisData.GetDialogueConditionIDByID(dialogueConditionID); if (dialogueCondition == null) { continue; } DialogueConditionControl dialogueConditionControl = CreateNewTopNode(dialogueCondition, false); DialoguePoint dialoguePoint = dialogueCondition.topPoint; CreateControlByData(dialogueConditionControl, dialoguePoint); ResetControlRect(dialogueConditionControl.Parent); dialogueConditionControl.Parent.Refresh(); } ResetBackRect(); }
/// <summary> /// 接收到了点击npc的消息 /// </summary> public void ClickInteractiveNPCID() { if (npcData == null || playerState == null || iInteractiveState == null || npcIDToTalkShowStructDic == null) { return; } int thisClickNPCID = iInteractiveState.ClickInteractiveNPCID; if (npcIDToTalkShowStructDic.ContainsKey(thisClickNPCID)) { return; } //取出对话 DialogueCondition[] allTalkCondition = dialogueStructData.SearchDialogueConditionsByNPCID(thisClickNPCID, temp => temp.enumDialogueType == EnumDialogueType.Normal && //判断是否是对话 (temp.minLevel < 0 || temp.minLevel <= playerState.Level) && //判断最小等级是否复合 (temp.maxLevel < 0 || temp.maxLevel >= playerState.Level) && //判断最大等级是否复合 (temp.overTask < -1 || (runtimeTasksData.GetTasksWithID(temp.overTask, false) != null && (runtimeTasksData.GetTasksWithID(temp.overTask, false).TaskInfoStruct.TaskProgress == TaskMap.Enums.EnumTaskProgress.Sucessed))) && //判断完成任务是否复合 temp.thisTask < 0 //检测不需要任务要求 ); if (allTalkCondition != null && allTalkCondition.Length > 0) { //随机出一个任务,尽量从后往前 int selectIndex = allTalkCondition.Length - 1; while (true) { float rangeValue = Random.Range(0, 10); if (rangeValue > 2) { break; } selectIndex--; if (selectIndex < 0) { selectIndex = allTalkCondition.Length - 1; } } DialogueCondition selectTalkCondition = allTalkCondition[selectIndex]; ShowTalk(selectTalkCondition); } }
/// <summary> /// 显示对话 /// </summary> /// <param name="dialogueCondition">对话的文本</param> private void ShowTalk(DialogueCondition dialogueCondition) { TalkShowStruct talkShowStruct = new TalkShowStruct(); Queue <int> targetTaskIDs = new Queue <int>(); Queue <DialoguePoint> targetTaskPoints = new Queue <DialoguePoint>(); PushDialoguePointTask(dialogueCondition.topPoint, targetTaskIDs, targetTaskPoints); float maxTime = 0; foreach (DialoguePoint targetTaskPoint in targetTaskPoints) { DialogueValue dialogueValue = dialogueStructData.SearchDialogueValueByID(targetTaskPoint.dialogueID); if (dialogueValue == null) { continue; } string otherValue = dialogueValue.otherValue; if (string.IsNullOrEmpty(otherValue)) { continue; } string[] splitsValue = otherValue.Split(','); if (splitsValue.Length == 2) { float startTime = 0; //开始时间 float intervalTime = 0; //持续时间 if (!(float.TryParse(splitsValue[0], out startTime) && float.TryParse(splitsValue[1], out intervalTime))) { continue; } float endTime = startTime + intervalTime; maxTime = maxTime > endTime ? maxTime : endTime; talkShowStruct.pointToCreateTime.Add(targetTaskPoint, startTime); talkShowStruct.pointToIntervalTime.Add(targetTaskPoint, intervalTime); } } talkShowStruct.maxTime = maxTime; npcIDToTalkShowStructDic.Add(dialogueCondition.touchNPCID, talkShowStruct); }
/// <summary> /// Creates a UIElements.Foldout and adds the DialogueNodePort elements. /// </summary> /// <returns>Returns a UIElements.Foldout with the DialogueNodePort fields.</returns> private Foldout GenerateFoldout() { // The containing foldout Foldout foldout = new Foldout { text = "Port Options", name = "DialogueNodePort", value = false }; // The text to display on the response buttons in the game UI. TextField choiceTextField = new TextField { name = "Response Text", value = ResponseText }; // Sets the ResponseText property to the value entered in the TextField. choiceTextField.RegisterValueChangedCallback(evt => { ResponseText = evt.newValue; }); foldout.contentContainer.Add(choiceTextField); // Sets the dialogue that needs to be toggled when the StoryChoice is chosen in the UI. ObjectField dialogueToToggle = new ObjectField("Condition to Toggle") { name = "ConditionToToggle", objectType = typeof(DialogueCondition), value = ConditionToToggle, allowSceneObjects = false }; dialogueToToggle.RegisterValueChangedCallback(evt => { ConditionToToggle = evt.newValue as DialogueCondition; }); foldout.contentContainer.Add(dialogueToToggle); return(foldout); }
/// <summary> /// 初始化对话 /// </summary> private void InitTalk() { fisrtKeyUP = false; int touchNPCID = iInteractiveState.ClickInteractiveNPCID; TaskMap.RunTimeTaskInfo[] runTimeTaskInfos = runtimeTasksData.GetAllToDoList() .Where(temp => temp.TaskInfoStruct.ReceiveTaskNpcId == touchNPCID && temp.IsOver == false && temp.IsStart == false) .ToArray(); //首先选择 TaskMap.RunTimeTaskInfo runTimeTaskInfo = runTimeTaskInfos.Where(temp => temp.TaskInfoStruct.TaskType == TaskMap.Enums.EnumTaskType.Spur).FirstOrDefault(); if (runTimeTaskInfo == null) { runTimeTaskInfo = runTimeTaskInfos.Where(temp => temp.TaskInfoStruct.TaskType == TaskMap.Enums.EnumTaskType.Repeat).FirstOrDefault(); } if (runTimeTaskInfo != null) { this.runTimeTaskInfo = runTimeTaskInfo;//这个表示当前的任务 DialogueCondition[] dialogueConditions = dialogueStructData.SearchDialogueConditionsByNPCID(runTimeTaskInfo.TaskInfoStruct.ReceiveTaskNpcId, temp => temp.enumDialogueType == EnumDialogueType.Ask).ToArray(); DialoguePoint taskPoint; dialogueCodition = dialogueConditions.Where(temp => DialoguePointHasThisTask(temp.topPoint, this.runTimeTaskInfo.ID.ToString(), out taskPoint)).FirstOrDefault(); if (dialogueCodition != null)//如果存在该任务 { this.nowDialoguePoint = this.dialogueCodition.topPoint; InitDontShowTalk(dialogueCodition); ShowTalk(); } else { gameObject.SetActive(false); } } else { gameObject.SetActive(false); } }
/// <summary> /// 当前任务状态发生变化 /// </summary> /// <param name="iNowTaskState"></param> /// <param name="fieldName"></param> private void INowTaskStateChanged(INowTaskState iNowTaskState, string fieldName) { //开始任务 if (string.Equals(fieldName, GameState.GetFieldNameStatic <INowTaskState, int>(temp => temp.StartTask))) { Init(); // 如果存在该任务且该任务是主线 TaskMap.RunTimeTaskInfo runTimeTaskInfo = runtimeTasksData.GetTasksWithID(iNowTaskState.StartTask, true); if (runTimeTaskInfo != null && runTimeTaskInfo.TaskInfoStruct.TaskType == TaskMap.Enums.EnumTaskType.Main && runTimeTaskInfo.TaskInfoStruct.NeedShowTalk && !runTimeTaskInfo.TaskInfoStruct.NeedShowImageTip) { DialogueCondition dialogueCodition = dialogueStructData.SearchDialogueConditionsByNPCID(-1, temp => temp.enumDialogueType == EnumDialogueType.Task && temp.thisTask == iNowTaskState.StartTask).FirstOrDefault(); if (dialogueCodition != null) { gameObject.SetActive(true); //显示面板 InitTalk(dialogueCodition); //初始化对话 } } } else if (string.Equals(fieldName, GameState.GetFieldNameStatic <INowTaskState, int>(temp => temp.OverTaskID))) { Init(); // 如果存在该任务且该任务是主线 TaskMap.RunTimeTaskInfo runTimeTaskInfo = runtimeTasksData.GetTasksWithID(iNowTaskState.OverTaskID, false); if (runTimeTaskInfo != null && runTimeTaskInfo.TaskInfoStruct.TaskType == TaskMap.Enums.EnumTaskType.Main && runTimeTaskInfo.TaskInfoStruct.NeedShowTalk) { Debug.Log("显示结束任务对话:" + runTimeTaskInfo.ID); DialogueCondition dialogueCodition = dialogueStructData.SearchDialogueConditionsByNPCID(-1, temp => temp.enumDialogueType == EnumDialogueType.Task && temp.overTask == iNowTaskState.OverTaskID).FirstOrDefault(); if (dialogueCodition != null) { gameObject.SetActive(true); //显示面板 InitTalk(dialogueCodition); //初始化对话 } } } }
private bool EvalulateDialogueCondition(DialogueCondition condition) { return(condition.ConditionEvaluator(CurrentDialogueParam)); }
/// <summary> /// 保存方案 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 保存方案ToolStripMenuItem_Click(object sender, EventArgs e) { //重建对话关系数据集合以及对话数据字典 List <DialogueCondition> dialogueConditionList = new List <DialogueCondition>(); Dictionary <int, DialogueValue> dialogueValueDic = new Dictionary <int, DialogueValue>(); foreach (Panel panel in FlowLayoutPanel_Main.Controls.OfType <Panel>()) { DialogueConditionControl dialogueConditionContorl = panel.Controls.OfType <DialogueConditionControl>().FirstOrDefault(); if (dialogueConditionContorl == null) { continue; } //对话条件 DialogueCondition dialogueCondition = dialogueConditionContorl.GetDialogueCondition(); //对话关系 if (dialogueConditionContorl.Tag != null && dialogueConditionContorl.Tag.GetType().Equals(typeof(List <Control>)) && (dialogueConditionContorl.Tag as List <Control>).Count > 0) { List <Control> childControlList = dialogueConditionContorl.Tag as List <Control>; DialoguePointControl topPointControl = childControlList[0] as DialoguePointControl; if (topPointControl != null) { DialoguePoint topPoint = new DialoguePoint(); topPoint.dialogueID = topPointControl.GetDialogueValue().dialogueID; if (childControlList[0].Tag != null && childControlList[0].Tag.GetType().Equals(typeof(List <Control>)) && (childControlList[0].Tag as List <Control>).Count > 0) { SetDialoguePointData_Child(topPoint, (childControlList[0].Tag as List <Control>).ToArray()); } dialogueCondition.topPoint = topPoint; } } else { dialogueCondition.topPoint = null; } dialogueConditionList.Add(dialogueCondition); //对话数据 foreach (DialoguePointControl dialoguePointControl in panel.Controls.OfType <DialoguePointControl>()) { DialoguePointControl topPointControl = dialoguePointControl as DialoguePointControl; if (topPointControl != null) { if (!dialogueValueDic.ContainsKey(topPointControl.GetDialogueValue().dialogueID)) { dialogueValueDic.Add(topPointControl.GetDialogueValue().dialogueID, topPointControl.GetDialogueValue()); } } } } dialogueAnalysisData.ResetData(dialogueConditionList, dialogueValueDic); string dialogueConditionStr, dialogueValueStr; dialogueAnalysisData.GetData(out dialogueConditionStr, out dialogueValueStr); //保存 string folderPath = Path.GetDirectoryName(projectPath); File.WriteAllText(folderPath + "\\" + dialogueConditionFileName + ".txt", dialogueConditionStr, Encoding.UTF8); File.WriteAllText(folderPath + "\\" + dialogueValueFileName + ".txt", dialogueValueStr, Encoding.UTF8); }
/// <summary> /// 读取数据 /// </summary> /// <param name="relationValues">关系以及条件数据</param> /// <param name="dialogueValues">对话数据</param> /// <returns>返回最大的id</returns> public int ReadData(string relationValues, string dialogueValues) { dialogueValueDic = new Dictionary <int, DialogueValue>(); dialogueConditionList = new List <DialogueCondition>(); //处理关系 byte[] relationValueBytes = Encoding.UTF8.GetBytes(relationValues); MemoryStream ms_relation = new MemoryStream(relationValueBytes); using (StreamReader sr = new StreamReader(ms_relation)) { string readLine = null; DialogueCondition dialogueCondition = null; string dialogueStr = ""; while ((readLine = sr.ReadLine()) != null) { switch (readLine.Trim()) { case StartItemFlag: dialogueCondition = new DialogueCondition(); break; case EndItemFlag: if (dialogueCondition != null) { dialogueCondition.SetData(dialogueStr); dialogueConditionList.Add(dialogueCondition); dialogueStr = ""; dialogueCondition = null; } break; default: dialogueStr += readLine + "\r\n"; break; } } } int maxID = 0; //处理对话数据 byte[] dataValueBytes = Encoding.UTF8.GetBytes(dialogueValues); MemoryStream ms_data = new MemoryStream(dataValueBytes); using (StreamReader sr = new StreamReader(ms_data)) { string readLine = null; DialogueValue dialogueValue = null; string dialogueStr = ""; while ((readLine = sr.ReadLine()) != null) { switch (readLine.Trim()) { case StartItemFlag: dialogueValue = new DialogueValue(); break; case EndItemFlag: if (dialogueValue != null) { int id = dialogueValue.SetData(dialogueStr); if (!dialogueValueDic.ContainsKey(id)) { dialogueValueDic.Add(id, dialogueValue); } maxID = maxID > id ? maxID : id; dialogueStr = ""; dialogueValue = null; } break; default: dialogueStr += readLine + "\r\n"; break; } } } return(maxID); }
private DialogueCondition ParseConditionToken(string token) { //function and its parameters List <string> openPSplit = token.Split('(', ',').ToList(); string funcName = openPSplit[0]; //get rid of trailing for (int j = 1; j < openPSplit.Count; j++) { openPSplit[j] = openPSplit[j].TrimEnd(',', ')'); //remove empty if (openPSplit[j].Length == 0) { openPSplit.RemoveAt(j); j--; } } bool negationFlag = false; if (funcName[0] == '!') { negationFlag = true; funcName = funcName.TrimStart('!'); } DialogueCondition returned = null; switch (openPSplit.Count) { case 0: throw new TechnicalException("Can't parse " + token + ". It may be empty."); case 1: //no params returned = DialogueConditionsManager.GetDialogueCondition(funcName); break; case 2: // 1 param returned = DialogueConditionsManager.GetDialogueCondition(funcName, openPSplit[1]); break; case 3: // 2 params returned = DialogueConditionsManager.GetDialogueCondition(funcName, openPSplit[1], openPSplit[2]); break; case 4: // 3 params returned = DialogueConditionsManager.GetDialogueCondition(funcName, openPSplit[1], openPSplit[2], openPSplit[3]); break; default: throw new TechnicalException("Can't parse " + token + ". Possibly too many params."); } if (negationFlag) { returned = !returned; } return(returned); }
private DialogueCondition ParseCondition(string text) { if (text.Length == 0) { return(null); } try { //Simple as possible for now. No paranthesis support to group string[] tokens = text.Split(' '); if (tokens.Length == 0) { //user has entered empty condition string return(null); } else if (tokens.Length == 1) { //just a good old single function. return(ParseConditionToken(tokens[0])); } else if (tokens.Length % 2 == 0) { throw new TechnicalException("Invalid algebraic expression: " + text); } //tokens.Length is thus at least 3. DialogueCondition aggregate = null; DialogueCondition cur = null; aggregate = ParseConditionToken(tokens[0]); for (int i = 2; i < tokens.Length; i += 2) { if (i % 2 == 0) { cur = ParseConditionToken(tokens[i]); i -= 3; //we will add 2 to this and so we will get to the logic keyword. } else { //logic keyword AND OR if (tokens[i] == "AND" || tokens[i] == "&" || tokens[i] == "&&") { aggregate = aggregate & cur; } else if (tokens[i] == "OR" || tokens[i] == "|" || tokens[i] == "||") { aggregate = aggregate | cur; } else { throw new TechnicalException("Unrecognized logic keyword: " + tokens[i]); } i += 1; // we will add 2 to this and so we will get to next token. } } return(aggregate); } catch (Exception e) { ErrorHandler.ShowPureErrorMessage("Could not parse dialogue condition: \n" + text + "\n Error Message: \n" + e.Message); return(null); } }
/// <summary> /// 过场动画运行时携程(只能返回true或false) /// </summary> /// <returns></returns> IEnumerator RunningInterludes(InterludesItemStruct interludesItemStruct) { float runTime = 0; CanvasGroup canvasGroup = null; if (iGameState.InterludesPanel != null) { canvasGroup = iGameState.InterludesPanel.GetComponent <CanvasGroup>(); } iGameState.InterludesPanel.enabled = true; //开场先显示黑幕 while (runTime < 1) { runTime += Time.deltaTime; if (canvasGroup) { canvasGroup.alpha = runTime; } yield return(false); } canvasGroup.alpha = 1; //执行数据的读取和初始化操作 iGameState.ActionPanel.enabled = false; iGameState.SettingPanel.enabled = false; iGameState.MainPanel.enabled = false; iGameState.InterludesCamera.gameObject.SetActive(true); iGameState.InterludesCamera.transform.position = iPlayerState.PlayerCamera.transform.position; iGameState.InterludesCamera.transform.eulerAngles = iPlayerState.PlayerCamera.transform.eulerAngles; //将黑幕隐藏同时开始控制播放 bool interludesIsOver = false; runTime = 0; List <GameObject> rubbishList = new List <GameObject>(); //用于存放临时生成的垃圾 int interludesIndex = -1; //当前的过场项目下标 Action WaitOverAction = null; //等待持续时间结束委托对象 while (runTime < 1 || !interludesIsOver || WaitOverAction != null) { runTime += Time.deltaTime; if (canvasGroup) { float alpha = Mathf.Clamp(1 - runTime, 0, 1); canvasGroup.alpha = alpha; } if (!interludesIsOver) { //具体的控制逻辑 interludesIsOver = true; interludesIndex++; runTaskStruct.StopTask(); if (interludesIndex < interludesItemStruct.InterludesDataInfo.Datas.Count)//如果还有过场数据则取出来 { InterludesDataInfo.ItemData itemData = interludesItemStruct.InterludesDataInfo.Datas[interludesIndex]; float keepTime = itemData.baseKeepTime; //设置持续时间委托对象的实体 WaitOverAction = () => { keepTime -= Time.deltaTime; if (keepTime < 0) { interludesIsOver = false; WaitOverAction = null; } }; //根据不同的类型将数值传递给指定对象 //如果是对话则传递给对话控制 if (string.Equals(itemData.GetType().Name, typeof(InterludesDataInfo.ItemData_Talk).Name)) { //获取对话 InterludesDataInfo.ItemData_Talk itemData_talk = itemData as InterludesDataInfo.ItemData_Talk; DialogueCondition talkCondition = dialogueStructData.SearchDialogueConditionByID(itemData_talk.TalkID); ShowTalk(talkCondition); runTaskStruct.StartTask(0f, CheckTalk, -1, true); } else if (string.Equals(itemData.GetType().Name, typeof(InterludesDataInfo.ItemData_CameraPathAnimation).Name)) { //获取镜头动画 InterludesDataInfo.ItemData_CameraPathAnimation itemData_CameraPathAnimation = itemData as InterludesDataInfo.ItemData_CameraPathAnimation; if (itemData_CameraPathAnimation.ObjPrefab) { GameObject cameraPathAniamtionObj = GameObject.Instantiate <GameObject>(itemData_CameraPathAnimation.ObjPrefab); rubbishList.Add(cameraPathAniamtionObj); CameraPathAnimator cameraPathAniamtor = cameraPathAniamtionObj.GetComponent <CameraPathAnimator>(); cameraPathAniamtor.animationObject = iGameState.InterludesCamera.transform; cameraPathAniamtor.Play(); } } } else { WaitOverAction = null; } } if (WaitOverAction != null) { WaitOverAction(); } yield return(false); } //闭幕前显示黑幕 while (runTime < 1) { runTime += Time.deltaTime; if (canvasGroup) { canvasGroup.alpha = runTime; } yield return(false); } canvasGroup.alpha = 1; //初始化摄像机等数据 iGameState.ActionPanel.enabled = true; iGameState.SettingPanel.enabled = true; iGameState.MainPanel.enabled = true; iGameState.InterludesCamera.gameObject.SetActive(false); foreach (var item in rubbishList) { GameObject.Destroy(item); } //将黑幕隐藏 runTime = 0; while (runTime < 1) { runTime += Time.deltaTime; if (canvasGroup) { canvasGroup.alpha = 1 - runTime; } yield return(false); } canvasGroup.alpha = 0; iGameState.InterludesPanel.enabled = false; }
public DialogueResponse GetDialogueResponse(XmlNode node) { XmlNodeList nodeContent = node.ChildNodes; DialogueResponse response = new DialogueResponse(); foreach(XmlNode nodeItem in nodeContent) { if(nodeItem.Name == "condition") { DialogueCondition condition = new DialogueCondition(); condition.ID = nodeItem.InnerText; if(condition.ID.Length > 0) { XmlAttributeCollection attributes = nodeItem.Attributes; if(attributes["type"] != null) { if(attributes["type"].Value == "and") { condition.IsAND = true; } else { condition.IsAND = false; } } else { condition.IsAND = true; } response.Conditions.Add(condition); } } else if(nodeItem.Name == "text") { response.Text = nodeItem.InnerText; } else if(nodeItem.Name == "event") { response.Events.Add(nodeItem.InnerText); } } return response; }
public Topic GetDialogueOption(XmlNode node) { XmlNodeList nodeContent = node.ChildNodes; Topic topic = new Topic(); XmlAttributeCollection nodeAttributes = node.Attributes; if(nodeAttributes["id"] != null) { topic.ID = nodeAttributes["id"].Value; } foreach(XmlNode nodeItem in nodeContent) { if(nodeItem.Name == "condition") { DialogueCondition condition = new DialogueCondition(); condition.ID = nodeItem.InnerText; if(condition.ID.Length > 0) { XmlAttributeCollection attributes = nodeItem.Attributes; if(attributes["type"] != null) { if(attributes["type"].Value == "and") { condition.IsAND = true; } else { condition.IsAND = false; } } else { condition.IsAND = true; } topic.Conditions.Add(condition); } } else if(nodeItem.Name == "title") { topic.Title = nodeItem.InnerText; } else if(nodeItem.Name == "text") { topic.Request = nodeItem.InnerText; } else if(nodeItem.Name == "next_node") { topic.NextNode = nodeItem.InnerText; } } return topic; }
private bool EvaluateCondition(DialogueCondition condition) { if(condition.ID == "duringgreeting") { if(_entries.Count <= 0) { return true; } else { return false; } } else if(condition.ID == "isawake") { return true; } else if(condition.ID == "hastomatoseeds") { return true; } else if(condition.ID == "hasnotomatoseeds") { return false; } return true; }