public PlayerTask DoAI(List <PlayerTask> tasks) { IScore score = new AggroScore(); Game currentGame = Session.Game; if (currentGame.CurrentPlayer.Choice == null) { List <OptionNode> solutions = OptionNode.GetSolutions(currentGame, currentGame.CurrentPlayer.Id, score, 10, 500); var solution = new List <PlayerTask>(); solutions.OrderByDescending(p => p.Score).First().PlayerTasks(ref solution); return(solution.First()); } if (currentGame.CurrentPlayer.Choice.ChoiceType == ChoiceType.MULLIGAN) { return(tasks[Rand.Next(0, tasks.Count)]); //return ChooseTask.Mulligan(currentGame.CurrentPlayer, // score.MulliganRule() // .Invoke( // currentGame.CurrentPlayer.Choice.Choices.Select(p => currentGame.IdEntityDic[p]).ToList())); } // random ai!! return(tasks[Rand.Next(0, tasks.Count)]); }
internal static object RetrieveDirectives() { #if FIRST_PASS return(null); #else java.lang.AssertionStatusDirectives asd = new java.lang.AssertionStatusDirectives(); string[] arrStrings = new string[Count(classes)]; bool[] arrBools = new bool[arrStrings.Length]; OptionNode n = classes; for (int i = 0; i < arrStrings.Length; i++) { arrStrings[i] = n.name; arrBools[i] = n.enabled; n = n.next; } asd.classes = arrStrings; asd.classEnabled = arrBools; arrStrings = new string[Count(packages)]; arrBools = new bool[arrStrings.Length]; n = packages; for (int i = 0; i < arrStrings.Length; i++) { arrStrings[i] = n.name; arrBools[i] = n.enabled; n = n.next; } asd.packages = arrStrings; asd.packageEnabled = arrBools; asd.deflt = userAsserts; return(asd); #endif }
public static void OptionNodeTest() { var game = new Game( new GameConfig() { StartPlayer = 1, Player1Name = "FitzVonGerald", Player1HeroClass = CardClass.WARRIOR, DeckPlayer1 = Decks.WarriorPirate, Player2Name = "RehHausZuckFuchs", Player2HeroClass = CardClass.MAGE, DeckPlayer2 = Decks.SimpleMage, FillDecks = false, Shuffle = true }); game.StartGame(); while (game.State != State.COMPLETE) { Log.Info(""); Log.Info($"Player1: {game.Player1.PlayState} / Player2: {game.Player2.PlayState} - " + $"ROUND {(game.Turn + 1) / 2} - {game.CurrentPlayer.Name}"); Log.Info($"Hero[P1]: {game.Player1.Hero.Health} / Hero[P2]: {game.Player2.Hero.Health}"); Log.Info(""); while (game.CurrentPlayer == game.Player1) { Log.Info($"* Calculating solutions *** Player 1 ***"); var solutions = OptionNode.GetSolutions(game, game.Player1.Id, 10, 500); var solution = new List <PlayerTask>(); solutions.OrderByDescending(p => p.Score).First().PlayerTasks(ref solution); Log.Info($"- Player 1 - <{game.CurrentPlayer.Name}> ---------------------------"); solution.ForEach(p => { Log.Info(p.FullPrint()); game.Process(p); }); } // Random mode for Player 2 Log.Info($"- Player 2 - <{game.CurrentPlayer.Name}> ---------------------------"); while (game.CurrentPlayer == game.Player2) { //var options = game.Options(game.CurrentPlayer); //var option = options[Rnd.Next(options.Count)]; //Log.Info($"[{option.FullPrint()}]"); //game.Process(option); Log.Info($"* Calculating solutions *** Player 1 ***"); var solutions = OptionNode.GetSolutions(game, game.Player2.Id, 10, 500); var solution = new List <PlayerTask>(); solutions.OrderByDescending(p => p.Score).First().PlayerTasks(ref solution); Log.Info($"- Player 1 - <{game.CurrentPlayer.Name}> ---------------------------"); solution.ForEach(p => { Log.Info(p.FullPrint()); game.Process(p); }); } } Log.Info($"Game: {game.State}, Player1: {game.Player1.PlayState} / Player2: {game.Player2.PlayState}"); }
public void PlayOptionNode(OptionNode node) { if (isInstinate) { for (int i = 0; i < OptionArea.transform.childCount; i++) { Destroy(OptionArea.transform.GetChild(i).gameObject); } OpUIs.Clear(); isInstinate = false; node.GetTitle(); for (int i = 0; i < node.options.Count; i++) { GameObject temp = Instantiate(Optionprefrab, OptionArea.transform); OptionUI aaa = temp.GetComponentInChildren <OptionUI>(); aaa.id = i; OpUIs.Add(temp); } } if (isNoNeedWaitPack) { isNoNeedWaitPack = false; ShowOptionUI(); //展开Option后播放标题 } }
public OptionManager() { _root = new OptionNode(); _unloadedProviders = new HashSet<IOptionProvider>(); _providers = new Zongsoft.Collections.Collection<IOptionProvider>(); _providers.CollectionChanged += Providers_CollectionChanged; }
public void VisitOption(OptionNode node) { writeLine("option {"); depth++; writeTabs(); writeLine("id: " + node.ID); writeTabs(); write("key: "); node.Key.Accept(this); writeTabs(); write("case: "); node.Case.Accept(this); writeTabs(); write("case_decision: "); node.CaseDecision.Accept(this); writeTabs(); write("case_default: "); node.DefaultDecision.Accept(this); depth--; writeTabs(); writeLine("}"); }
public void ShowOptionUI() { title.text = ""; Tweener tweener = OptionBack.DOScale(new Vector3(1, 1, 1), UIspeed); tweener.SetEase(Ease.Linear); tweener.OnComplete(() => { Tweener tweener2 = title.DOText(textvalue, GetPlayTextTime(textvalue)); tweener2.SetEase(Ease.Linear); isGoNextNode = true; tweener2.OnComplete(() => { OptionNode temp = currentNode as OptionNode; for (int i = 0; i < temp.options.Count; i++) { OptionUI aaa = OpUIs[i].GetComponentInChildren <OptionUI>(); if (aaa.id == i) { Text temp1 = OpUIs[i].GetComponentInChildren <Text>(); temp1.text = temp.options[i]; } } }); }); }
public OptionConfigurationLoader(OptionNode rootNode) { if(rootNode == null) throw new ArgumentNullException("rootNode"); _root = rootNode; }
private void Print(ICommandOutlet output, OptionNode node, int depth) { if (node == null) { return; } output.Write(CommandOutletColor.DarkYellow, (depth > 0 ? new string('\t', depth) : string.Empty) + node.Name); if (string.IsNullOrWhiteSpace(node.Title)) { output.WriteLine(); } else { output.WriteLine(CommandOutletColor.DarkGray, " [{0}]", node.Title); } if (node.Option != null && node.Option.OptionObject != null) { output.WriteLine(Zongsoft.Runtime.Serialization.Serializer.Text.Serialize(node.Option.OptionObject)); } foreach (var child in node.Children) { Print(output, child, depth + 1); } }
public OptionLoaderSelector(OptionNode root) { if(root == null) throw new ArgumentNullException("root"); _root = root; _loaders = new ConcurrentDictionary<Type, IOptionLoader>(); }
public IAstNode BuildTree() { var optionNode = new OptionNode(new Token(), _tracer); var exprNode = _expr.BuildTree(); optionNode.Expression = exprNode; return(optionNode); }
public override void VisitOption(OptionNode node) { node.Case.Accept(this); node.CaseDecision.Accept(this); node.DefaultDecision.Accept(this); implementOptionType(node); }
//Crea el OptionNode public OptionNode AddOptionNode(Rect rect, int id, DialogueNode parent = null) { OptionNode optionNode = new OptionNode(); optionNode.SetWindowRect(rect).SetWindowTitle("Option").SetParent(parent).SetId(id).SetReference(this); _nodes.Add(optionNode); return(optionNode); }
public OptionConfigurationLoader(OptionNode rootNode) { if (rootNode == null) { throw new ArgumentNullException("rootNode"); } _root = rootNode; }
public void AddOption() { int count = optionNodes.Count; if (count < 4) { OptionNode node = new OptionNode(count + 1, parentNode, optionNodeStyle, optionNodeStyle, RemoveOption, onClickConnectionPoint); optionNodes.Add(node); } }
private void Initialize(OptionNode node, IOptionProvider provider, IOptionView view, IOptionViewBuilder viewBuilder) { if(node == null) throw new ArgumentNullException("node"); _node = node; _provider = provider; _view = view; _viewBuilder = viewBuilder; _isDirty = false; }
public OptionArgumentNode(Token token, IArgument argument, OptionNode parent) : base(token, parent) { if (token.Type != TokenType.Argument) { throw new ArgumentException($"Incorrect token type: {token}"); } Argument = argument; ParentOptionNode = parent; }
private static int Count(OptionNode n) { int count = 0; while (n != null) { count++; n = n.next; } return(count); }
public static void OneTurn() { var game = new Game( new GameConfig() { StartPlayer = 1, Player1Name = "FitzVonGerald", Player1HeroClass = CardClass.WARRIOR, Player1Deck = Decks.AggroPirateWarrior, Player2Name = "RehHausZuckFuchs", Player2HeroClass = CardClass.SHAMAN, Player2Deck = Decks.MidrangeJadeShaman, FillDecks = false, Shuffle = false, SkipMulligan = false }); game.Player1.BaseMana = 10; game.StartGame(); var aiPlayer1 = new AggroScore(); var aiPlayer2 = new AggroScore(); game.Process(ChooseTask.Mulligan(game.Player1, aiPlayer1.MulliganRule().Invoke(game.Player1.Choice.Choices.Select(p => game.IdEntityDic[p]).ToList()))); game.Process(ChooseTask.Mulligan(game.Player2, aiPlayer2.MulliganRule().Invoke(game.Player2.Choice.Choices.Select(p => game.IdEntityDic[p]).ToList()))); game.MainReady(); while (game.CurrentPlayer == game.Player1) { Console.WriteLine($"* Calculating solutions *** Player 1 ***"); List <OptionNode> solutions = OptionNode.GetSolutions(game, game.Player1.Id, aiPlayer1, 10, 500); var solution = new List <PlayerTask>(); solutions.OrderByDescending(p => p.Score).First().PlayerTasks(ref solution); Console.WriteLine($"- Player 1 - <{game.CurrentPlayer.Name}> ---------------------------"); foreach (PlayerTask task in solution) { Console.WriteLine(task.FullPrint()); game.Process(task); if (game.CurrentPlayer.Choice != null) { break; } } } Console.WriteLine(game.Player1.HandZone.FullPrint()); Console.WriteLine(game.Player1.BoardZone.FullPrint()); }
public void ChangeSelectID(int id) { if (isGoNextNode) { isGoNextNode = false; selectID = id; OptionNode temp = currentNode as OptionNode; isInstinate = true; //获取连接的下一个节点,同时关闭该UI lastCurrent = current; currentNode = temp.MoveNext(selectID, out current); PackUpOptionUI(); } }
public AIOption(OptionNode optionNode, DataIteratorNode dataIteratorNode = null) { // Saving linked optionNode OptionNode = optionNode; Description = OptionNode.Description; // Calculate weight Weight = OptionNode.GetWeight(); // Calculate rank Rank = OptionNode.GetRank(); // Fetch actions foreach (ActionNode actionNode in OptionNode.GetActions()) { AiActions.Add(new AIAction(actionNode)); } }
private static void AddOption(string classOrPackage, bool enabled) { if (classOrPackage == null) { throw new ArgumentNullException("classOrPackage"); } if (classOrPackage.EndsWith("...")) { packages = new OptionNode(classOrPackage.Substring(0, classOrPackage.Length - 3), enabled, packages); } else { classes = new OptionNode(classOrPackage, enabled, classes); } }
private void defineOptionType(OptionNode node) { var tb = Compiler.ModuleBuilder.DefineType("OptionCalculusCompiled.Option" + node.ID, TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Class, typeof(Option)); var cb = tb.DefineConstructor(MethodAttributes.Public | MethodAttributes.ReuseSlot | MethodAttributes.HideBySig, CallingConventions.Standard, new Type[0]); var il = cb.GetILGenerator(); il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Ldstr, node.Key.Ident); il.Emit(OpCodes.Ldc_I4, node.ID); il.Emit(OpCodes.Conv_U4); il.Emit(OpCodes.Call, typeof(Option).GetConstructor(new[] { typeof(string), typeof(uint) })); il.Emit(OpCodes.Ret); Compiler.OptionTypes[node.ID] = new OptionData(tb, cb); }
private Dictionary <string, LocalBuilder> generateLocals(ILGenerator il, OptionNode node) { var locals = new Dictionary <string, LocalBuilder>(); var idents = new List <string>(); var @case = node.Case as IdentNode; if (@case != null && !idents.Contains(@case.Ident)) { idents.Add(@case.Ident); } var caseDecision = node.CaseDecision as IdentNode; if (caseDecision != null && !idents.Contains(caseDecision.Ident)) { idents.Add(caseDecision.Ident); } var defaultDecision = node.DefaultDecision as IdentNode; if (defaultDecision != null && !idents.Contains(defaultDecision.Ident)) { idents.Add(defaultDecision.Ident); } if (idents.Contains(node.Key.Ident)) { idents.Remove(node.Key.Ident); } foreach (var s in idents) { var lb = il.DeclareLocal(typeof(Option)); lb.SetLocalSymInfo(s); il.Emit(OpCodes.Ldarg_1); il.Emit(OpCodes.Ldstr, s); il.Emit(OpCodes.Call, typeof(Scope <Option>).GetMethod("Lookup")); il.Emit(OpCodes.Stloc, lb); locals[s] = lb; } return(locals); }
public IDialogueContext GetDialogueContext() { int n = optionNodes.Count; DialogueOption[] options = new DialogueOption[n]; for (int i = 0; i < n; i++) { OptionNode current = optionNodes[i]; options[i] = new DialogueOption(current.text, current.proceedToNextSpeaker); } OptionsDialogue dialogue = ScriptableObject.CreateInstance <OptionsDialogue>(); dialogue.Init(options); return(dialogue); }
public override object Build(BuilderContext context) { Builtin builtin = context.Builtin; IOptionProvider provider = null; string providerValue = builtin.Properties.GetRawValue("provider"); var node = new OptionNode(builtin.Name, builtin.Properties.GetValue <string>("title"), builtin.Properties.GetValue <string>("description")); if (string.IsNullOrWhiteSpace(providerValue)) { return(node); } switch (providerValue.Trim().ToLower()) { case ".": case "plugin": provider = OptionUtility.GetConfiguration(builtin.Plugin); break; case "/": case "application": provider = context.PluginContext.ApplicationContext.Configuration; break; default: provider = builtin.Properties.GetValue <IOptionProvider>("provider"); break; } if (provider == null) { throw new PluginException(string.Format("Cann't obtain OptionProvider with '{0}'.", providerValue)); } node.Option = new Option(node, provider) { View = context.Builtin.Properties.GetValue <IOptionView>("view"), ViewBuilder = context.Builtin.Properties.GetValue <IOptionViewBuilder>("viewBuilder"), }; return(node); }
public AIOption(OptionNode optionNode) { // Saving linked optionNode OptionNode = optionNode; Description = OptionNode.Description; // Calculate weight Weight = OptionNode.GetWeight(); // Fetch actions foreach (ActionNode actionNode in OptionNode.GetActions()) { AiActions.Add(new AIAction(actionNode)); } // Saving iterator current output if (OptionNode.DataIteratorNode != null) { IteratorIndex = OptionNode.DataIteratorNode.Index; } }
internal static bool IsEnabled(TypeWrapper tw) { string className = tw.Name; // match class name for (OptionNode n = classes; n != null; n = n.next) { if (n.name == className) { return(n.enabled); } } // match package name if (packages != null) { int len = className.Length; while (len > 0 && className[--len] != '.') { ; } do { for (OptionNode n = packages; n != null; n = n.next) { #if WINRT if (String.Compare(n.name, 0, className, 0, len) == 0 && len == n.name.Length) #else if (String.Compare(n.name, 0, className, 0, len, false, CultureInfo.InvariantCulture) == 0 && len == n.name.Length) #endif { return(n.enabled); } } while (len > 0 && className[--len] != '.') { ; } } while (len > 0); } return(tw.GetClassLoader() == ClassLoaderWrapper.GetBootstrapClassLoader() ? sysAsserts : userAsserts); }
public void OptionNode_WithExpression_ReturnsCorrectString() { // Arranged: var exprNodeMock = new Mock <IExpressionNode>(); exprNodeMock.Setup(exprNode => exprNode.AstNodeType).Returns(AstNodeType.Expression); exprNodeMock.Setup(exprNode => exprNode.ToString()).Returns(() => "<T>"); var node = new OptionNode(new Token(TokenKind.LeftBracket, "["), _tracer) { Expression = exprNodeMock.Object }; // Act: var actual = node.ToString(); // Assert: Assert.That(actual, Is.EqualTo("[ <T> ]")); }
private void implementOptionType(OptionNode node) { var nodeData = Compiler.OptionTypes[node.ID]; var tb = nodeData.TypeBuilder; var mb = tb.DefineMethod("Eval", MethodAttributes.Public | MethodAttributes.ReuseSlot | MethodAttributes.HideBySig | MethodAttributes.Virtual, typeof(Option), new[] { typeof(Scope <Option>), typeof(Option) }); mb.DefineParameter(1, ParameterAttributes.None, "scope"); mb.DefineParameter(2, ParameterAttributes.None, node.Key.Ident); var getID = typeof(Option).GetMethod("get_ID"); var il = mb.GetILGenerator(); var locals = generateLocals(il, node); var paramNullLabel = il.DefineLabel(); il.Emit(OpCodes.Ldarg_2); il.Emit(OpCodes.Ldnull); il.Emit(OpCodes.Beq_S, paramNullLabel); var caseDecisionLabel = il.DefineLabel(); il.Emit(OpCodes.Ldarg_2); il.Emit(OpCodes.Call, getID); generateExpression(il, node.Case, locals); il.Emit(OpCodes.Call, getID); il.Emit(OpCodes.Beq_S, caseDecisionLabel); generateExpression(il, node.DefaultDecision, locals); il.Emit(OpCodes.Ret); il.MarkLabel(caseDecisionLabel); generateExpression(il, node.CaseDecision, locals); il.Emit(OpCodes.Ret); il.MarkLabel(paramNullLabel); il.Emit(OpCodes.Ldnull); il.Emit(OpCodes.Ret); }
public override PlayerTask GetMove() { Game game = _BoundController.Game.Clone(); if (CurrentTurn == game.Turn) { //we probably have a solution calculated already! PlayerTask move = FoundSolution[0]; FoundSolution.RemoveAt(0); return(move); } //next turn! Find a solution again! CurrentTurn = game.Turn; List <OptionNode> solutions = OptionNode.GetSolutions(game, EntityID, EvaluationRule, 10, 500); var solution = new List <PlayerTask>(); solutions.OrderByDescending(p => p.Score).First().PlayerTasks(ref solution); FoundSolution = solution; return(GetMove()); }
private void Invoke(OptionNode node, InvokeMethod method) { if(node == null) return; if(node.Option != null) { switch(method) { case InvokeMethod.Apply: node.Option.Apply(); break; case InvokeMethod.Reset: node.Option.Reset(); break; } } foreach(var child in node.Children) this.Invoke(child, method); }
public Option(OptionNode node, IOptionProvider provider, IOptionViewBuilder viewBuilder) { this.Initialize(node, provider, null, viewBuilder); }
public Option(OptionNode node, IOptionProvider provider, IOptionView view) { this.Initialize(node, provider, view, null); }
public Option(OptionNode node, IOptionProvider provider) { this.Initialize(node, provider, null, null); }
public Option(OptionNode node) { this.Initialize(node, null, null, null); }
internal OptionNode(string name, bool enabled, OptionNode next) { this.name = name; this.enabled = enabled; this.next = next; }
public static void PlayConversation(string id) { if (xmld == null) { Init(); } string query = string.Format("//*[@id='{0}']", id); XmlElement conv = (XmlElement)xmld.SelectSingleNode(query); XmlNodeList nodes = conv.SelectNodes("*"); Conversation convModel = new Conversation(); convModel.nodes = new Node[nodes.Count]; for (int i = 0; i < nodes.Count; ++i) { XmlNode node = nodes[i]; string name = node.Name; Node nodeModel = null; if (name == "dialogue-node") { DialogNode dialogNodeModel = new DialogNode(); XmlNodeList dialogSpeaks = node.SelectNodes("*"); dialogNodeModel.speaks = new Speak[node.SelectNodes("speak-player").Count + node.SelectNodes("speak-char").Count]; int z = 0; for (int j = 0; j < dialogSpeaks.Count; ++j) { XmlNode speakNode = dialogSpeaks[j]; string speakName = speakNode.Name; if (speakName == "speak-player") { Speak speakModel = new Speak(); speakModel.text = speakNode.InnerText; dialogNodeModel.speaks[z] = speakModel; ++z; } else if (speakName == "speak-char") { Speak speakModel = new Speak(); speakModel.text = speakNode.InnerText; speakModel.isPhone = true; dialogNodeModel.speaks[z] = speakModel; ++z; } else if (speakName == "condition") { Condition conditionModel = new Condition(); XmlNodeList activesList = speakNode.SelectNodes("active"); conditionModel.actives = new string[activesList.Count]; for (int y = 0; y < activesList.Count; y++) { conditionModel.actives[y] = activesList[y].Attributes["flag"].Value; } XmlNodeList inactivesList = speakNode.SelectNodes("inactive"); conditionModel.inactives = new string[inactivesList.Count]; for (int y = 0; y < inactivesList.Count; y++) { conditionModel.inactives[y] = inactivesList[y].Attributes["flag"].Value; } dialogNodeModel.speaks[z - 1].condition = conditionModel; } else if (speakName == "child") { dialogNodeModel.nextIndex = Utils.IntParseFast(speakNode.Attributes["nodeindex"].Value); } else if (speakName == "end-conversation") { XmlNode effect = speakNode.SelectSingleNode("effect"); if (effect != null) { XmlNodeList effectsList = effect.SelectNodes("*"); dialogNodeModel.effects = new EndConvEffect[ effectsList.Count - effect.SelectNodes("condition").Count]; int m = 0; for (int x = 0; x < effectsList.Count; ++x) { XmlNode effectNode = effectsList[x]; string effectNodeName = effectNode.Name; if (effectNodeName == "activate") { ActivateFlagEffect activateFlageffect = new ActivateFlagEffect(); activateFlageffect.flag = effectNode.Attributes["flag"].Value; dialogNodeModel.effects[m] = activateFlageffect; ++m; } else if (effectNodeName == "deactivate") { DeactivateFlagEffect deactivateFlageffect = new DeactivateFlagEffect(); deactivateFlageffect.flag = effectNode.Attributes["flag"].Value; dialogNodeModel.effects[m] = deactivateFlageffect; ++m; } else if (effectNodeName == "increment") { IncrementFlagEffect eff = new IncrementFlagEffect(); eff.val = Utils.IntParseFast( effectNode.Attributes["value"].Value); eff.var = effectNode.Attributes["var"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "decrement") { DecrementFlagEffect eff = new DecrementFlagEffect(); eff.val = Utils.IntParseFast( effectNode.Attributes["value"].Value); eff.var = effectNode.Attributes["var"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "trigger-conversation") { TriggerConvEffect eff = new TriggerConvEffect(); eff.idTarget = effectNode.Attributes["idTarget"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "trigger-scene") { TriggerSceneEffect eff = new TriggerSceneEffect(); eff.idTarget = effectNode.Attributes["idTarget"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "trigger-cutscene") { TriggerCutSceneEffect eff = new TriggerCutSceneEffect(); eff.idTarget = effectNode.Attributes["idTarget"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "condition") { Condition conditionModel = new Condition(); XmlNodeList activesList = effectNode.SelectNodes("active"); conditionModel.actives = new string[activesList.Count]; for (int y = 0; y < activesList.Count; y++) { conditionModel.actives[y] = activesList[y].Attributes["flag"].Value; } XmlNodeList inactivesList = effectNode.SelectNodes("inactive"); conditionModel.inactives = new string[inactivesList.Count]; for (int y = 0; y < inactivesList.Count; y++) { conditionModel.inactives[y] = inactivesList[y].Attributes["flag"].Value; } dialogNodeModel.effects[m - 1].condition = conditionModel; } } } } else if (speakName == "effect") { XmlNodeList effectsList = speakNode.SelectNodes("*"); dialogNodeModel.effects = new EndConvEffect[ effectsList.Count - speakNode.SelectNodes("condition").Count]; int m = 0; for (int x = 0; x < effectsList.Count; ++x) { XmlNode effectNode = effectsList[x]; string effectNodeName = effectNode.Name; if (effectNodeName == "activate") { ActivateFlagEffect activateFlageffect = new ActivateFlagEffect(); activateFlageffect.flag = effectNode.Attributes["flag"].Value; dialogNodeModel.effects[m] = activateFlageffect; ++m; } else if (effectNodeName == "deactivate") { DeactivateFlagEffect deactivateFlageffect = new DeactivateFlagEffect(); deactivateFlageffect.flag = effectNode.Attributes["flag"].Value; dialogNodeModel.effects[m] = deactivateFlageffect; ++m; } else if (effectNodeName == "increment") { IncrementFlagEffect eff = new IncrementFlagEffect(); eff.val = Utils.IntParseFast( effectNode.Attributes["value"].Value); eff.var = effectNode.Attributes["var"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "decrement") { DecrementFlagEffect eff = new DecrementFlagEffect(); eff.val = Utils.IntParseFast( effectNode.Attributes["value"].Value); eff.var = effectNode.Attributes["var"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "trigger-conversation") { TriggerConvEffect eff = new TriggerConvEffect(); eff.idTarget = effectNode.Attributes["idTarget"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "trigger-scene") { TriggerSceneEffect eff = new TriggerSceneEffect(); eff.idTarget = effectNode.Attributes["idTarget"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "trigger-cutscene") { TriggerCutSceneEffect eff = new TriggerCutSceneEffect(); eff.idTarget = effectNode.Attributes["idTarget"].Value; dialogNodeModel.effects[m] = eff; ++m; } else if (effectNodeName == "condition") { Condition conditionModel = new Condition(); XmlNodeList activesList = effectNode.SelectNodes("active"); conditionModel.actives = new string[activesList.Count]; for (int y = 0; y < activesList.Count; y++) { conditionModel.actives[y] = activesList[y].Attributes["flag"].Value; } XmlNodeList inactivesList = effectNode.SelectNodes("inactive"); conditionModel.inactives = new string[inactivesList.Count]; for (int y = 0; y < inactivesList.Count; y++) { conditionModel.inactives[y] = inactivesList[y].Attributes["flag"].Value; } dialogNodeModel.effects[m - 1].condition = conditionModel; } } } } nodeModel = dialogNodeModel; } else if (name == "option-node") { OptionNode optionNodeModel = new OptionNode(); XmlAttribute randomAttr = node.Attributes["random"]; if (randomAttr != null && randomAttr.Value == "yes") { optionNodeModel.isRandom = true; } XmlNodeList optionSpeaks = node.SelectNodes("*"); optionNodeModel.options = new Option[node.SelectNodes("speak-player").Count]; int z = 0; for (int j = 0; j < optionSpeaks.Count; ++j) { XmlNode optionNode = optionSpeaks[j]; string optionName = optionNode.Name; if (optionName == "speak-player") { Option speakModel = new Option(); speakModel.text = optionNode.InnerText; optionNodeModel.options[z] = speakModel; ++z; } else if (optionName == "condition") { Condition conditionModel = new Condition(); XmlNodeList activesList = optionNode.SelectNodes("active"); conditionModel.actives = new string[activesList.Count]; for (int y = 0; y < activesList.Count; y++) { conditionModel.actives[y] = activesList[y].Attributes["flag"].Value; } XmlNodeList inactivesList = optionNode.SelectNodes("inactive"); conditionModel.inactives = new string[inactivesList.Count]; for (int y = 0; y < inactivesList.Count; y++) { conditionModel.inactives[y] = inactivesList[y].Attributes["flag"].Value; } optionNodeModel.options[z - 1].condition = conditionModel; } else if (optionName == "child") { optionNodeModel.options[z - 1].nextIndex = Utils.IntParseFast(optionNode.Attributes["nodeindex"].Value); } } nodeModel = optionNodeModel; } convModel.nodes[i] = nodeModel; } convModel.exec(); }
private void generateOption(ILGenerator il, OptionNode node, Dictionary <string, LocalBuilder> locals) { var nodeData = Compiler.OptionTypes[node.ID]; il.Emit(OpCodes.Newobj, nodeData.ConstructorBuilder); }
private static int Count(OptionNode n) { int count = 0; while (n != null) { count++; n = n.next; } return count; }
public void GetNodeFunction(List <NodePort> _ports) { //cannot find a way to use a switch, so we'll have to stick with a bunch of if statements :notlikethis: foreach (NodePort _nodePort in _ports) { XNode.Node _node = _nodePort.node; if (_node.GetType() == typeof(DialogueNode)) { dialoguePanel.SetActive(true); currentDialogue = _node as DialogueNode; ShowDialogue(currentDialogue); return; //do NOT grab the node after this, and wait for the player to advance the dialogue } if (_node.GetType() == typeof(VoiceClipNode)) { VoiceClipNode voiceClipNode = _node as VoiceClipNode; voiceClipNode.OnUse(); return; } if (_node.GetType() == typeof(EndSceneNode)) { EndCutscene(); return; } else if (_node.GetType() == typeof(EndBattleSceneNode)) { EndCutscene(); BattleManager BM = GameObject.Find("BattleManager").GetComponent <BattleManager>(); BM.EnableUI(); BM.StartActor(); //Move Battle UI Back In? return; } if (_node is MovementNode movementNode) { movementNode.CharacterMovement(); } if (_node.GetType() == typeof(CloseDialogue)) { dialoguePanel.SetActive(false); speakerPanel.SetActive(false); } if (_node.GetType() == typeof(CG)) { CG scopedCGNode = _node as CG; showCG(_node as CG); if (scopedCGNode.waitForInput) { currentCGNode = scopedCGNode; dialoguePanel.gameObject.SetActive(false); _charactersInScene.SetActive(false); CGWaitingForInput = true; return; } } if (_node.GetType() == typeof(SetSpriteNode)) { SetImage(_node as SetSpriteNode); } if (_node.GetType() == typeof(CGHide)) { _cgGraphic.enabled = false; } if (_node.GetType() == typeof(WaitFor)) { WaitFor _waitForNode = _node as WaitFor; StartCoroutine(WaitToAdvance(_waitForNode)); //do not get next node automatically return; } if (_node.GetType() == typeof(Choices)) { ChoicePanel.SetActive(true); nodeOptions = new List <Node>(); int listIndex = 0; Choices _choiceNode = _node as Choices; NodePort _choicePort = _choiceNode.GetOutputPort("output"); List <NodePort> _nodePorts = _choicePort.GetConnections(); foreach (NodePort _NP in _nodePorts) { nodeOptions.Add(_NP.node); Button _newOption = Instantiate(choiceButton) as Button; _newOption.transform.SetParent(ChoicePanel.transform); listIndex++;//on this button it where on the list it is, using this //ChoiceOptionHolder _holder = _newOption.GetComponent<ChoiceOptionHolder>(); OptionNode optionNode = _NP.node as OptionNode; _newOption.GetComponentInChildren <Text>().text = optionNode.optionText; _newOption.GetComponent <ChoiceOptionHolder>().node = _NP.node; // _holder.node = _NP.node; // _holder.indexOfOptions = listIndex; } return; //do not load next node, since we want the player input to decide the branch to go down } if (_node.GetType() == typeof(TimelineNode)) { TimelineNode timelineNode = _node as TimelineNode; timelineNode.PlayTimeLine(); } //get next node(s) NodePort _port = _node.GetOutputPort("output"); if (_port.IsConnected) { GetNodeFunction(_port.GetConnections()); } } }