public override AstNode ShallowClone() { var res = new AstAccessor(Source, Start, End, Name, IsGenerator, Async); res.Body.AddRange(Body.AsReadOnlySpan()); res.ArgNames.AddRange(ArgNames.AsReadOnlySpan()); res.HasUseStrictDirective = HasUseStrictDirective; res.Pure = Pure; return(res); }
public InsightArgs() { _args = Environment.GetCommandLineArgs(); Names = new ArgNames(); NetworkAddress = ExtractValue(Names.NetworkAddress, "localhost"); NetworkPort = ExtractValueInt(Names.NetworkPort, 7777); UniqueID = ExtractValue(Names.UniqueID, ""); SceneName = ExtractValue(Names.SceneName, ""); }
/// <summary> /// Game decision point. This method gets messages from connection and decides what arguments to call, as well /// as taking care of runtime handlers for SoM requests /// </summary> /// <param name="msg"></param> /// <param name="player"></param> /// <param name="data"></param> public void getMessageFromConnection(Messages.GameMessages msg, DataPlayer player, List <object> data) { if (!checkTurn(player))//Not right turn? { (this as IGameObservable).notifyObservers(Messages.GameMessages.NotPlayerTurn, player, null); Match.updateTranscript("Not your turn"); return; } CharacterData attacker = Turn == 0?Player1.Character:Player2.Character, defender = Turn == 0?Player2.Character:Player1.Character; ArgNames actionName = 0; ArgumentFeedback argFeedback = null; if (waiting && msg != Messages.GameMessages.somChosen) { Match.updateTranscript("Waiting for SOM"); return; } switch (msg) { ///This case handles the response from a request to get SoM from the user ///We need to translate the response (SoMName,value) into values the Handler needs (JoySorrowValue,AngerFearValue) case Messages.GameMessages.somChosen: SOM name = (SOM)data[0]; switch (name) { case SOM.Joy: argFeedback = SoMHandler(1, 0); break; case SOM.Sorrow: argFeedback = SoMHandler(-1, 0); break; case SOM.Anger: argFeedback = SoMHandler(0, 1); break; case SOM.Fear: argFeedback = SoMHandler(0, -1); break; } waiting = false; //Just in case break; case Messages.GameMessages.Trick: actionName = ArgNames.Trick; argFeedback = arguments[actionName].doArgument(attacker, defender, World); if ((arguments[actionName] as Trick).repeatTurn()) { Turn--; //We turn it back then the regular turn counter turns it back to my turn } break; case Messages.GameMessages.Manipulate: actionName = ArgNames.Manipulate; goto case Messages.GameMessages.SoMDependentArgument; case Messages.GameMessages.Taunt: actionName = ArgNames.Taunt; goto case Messages.GameMessages.SoMDependentArgument; case Messages.GameMessages.Focus: actionName = ArgNames.Focus; goto case Messages.GameMessages.SoMDependentArgument; case Messages.GameMessages.Empathy: actionName = ArgNames.Empathy; argFeedback = (arguments[actionName] as Empathy).doArgument(attacker, defender, World); if (argFeedback != null && argFeedback.result == Result.None) { Match.updateTranscript("Empathy cannot be used\n"); } break; case Messages.GameMessages.Bluff: actionName = ArgNames.Bluff; goto case Messages.GameMessages.GenericArgument; case Messages.GameMessages.Charm: actionName = ArgNames.Charm; goto case Messages.GameMessages.GenericArgument; case Messages.GameMessages.Coerce: actionName = ArgNames.Coerce; goto case Messages.GameMessages.GenericArgument; case Messages.GameMessages.Convince: actionName = ArgNames.Convince; goto case Messages.GameMessages.GenericArgument; case Messages.GameMessages.Scare: actionName = ArgNames.Scare; goto case Messages.GameMessages.GenericArgument; case Messages.GameMessages.GenericArgument: argFeedback = arguments[actionName].doArgument(attacker, defender, World); break; case Messages.GameMessages.SoMDependentArgument: (arguments[actionName] as SoMDependentArgument).Selector = this; argFeedback = (arguments[actionName] as SoMDependentArgument).doArgument(attacker, defender, World); //If true then it succeeded so it needs to get SoM if (argFeedback == null) { waiting = true; } break; }//End Switch //Update transcript if there is feedback if (argFeedback != null) { argFeedback.playerName = player.PlayerName; Match.updateTranscript(argFeedback); } if (!waiting) { //Check Game over if (Match.Goal.isGoalReached(defender)) { (this as IGameObservable).notifyObservers(Messages.GameMessages.GameOver, Match.Player1, null); (this as IGameObservable).notifyObservers(Messages.GameMessages.GameOver, Match.Player2, null); } else//Not over { //Tell players to update and go to next turn (this as IGameObservable).notifyObservers(Messages.GameMessages.ArgumentDone, player, null); Turn = (Turn + 1) % 2; } } }
public ArgumentNode(string commandstring, Dictionary <string, bool>?possibleflags = null) { // "subcommand <requiredparam1> <requiredparam2> [-a <>] [-b] [<optionalparam1> <optionalparam2> [<optionalparam3> [-c]]] [-d <>]" // <Key=subcommand, [requiredparam1, requiredparam2], {a:"", b:null, d:""}, <Key=null, [optionalparam1, optionalparam2], {}, <Key=null, [optionalparam3], {c:null}, null>>> // subcommand val val -b -a val val val val -c (no d) // TODO: long/descriptive flag names, (ignored) comments on commands as part of command strings? // Flags can appear anywhere so add parent node's flags if (possibleflags != null) { PossibleFlags = possibleflags; } int bracketcounter = 0; int open = -1; for (int i = 0; i < commandstring.Length; i++) { if (commandstring[i] == '[') { bracketcounter++; if (bracketcounter == 1) { open = i; } } else if (commandstring[i] == ']') { bracketcounter--; if (bracketcounter == 0) { //outerbracketpairs.Add(new Tuple<int, int>(open, i)); string contents = commandstring.Substring(open + 1, i - open - 1); if (contents[0] == '-') // Is flag? { if (contents.Contains("<>")) // Takes value? { PossibleFlags.Add(contents[1].ToString(), true); } else { PossibleFlags.Add(contents[1].ToString(), false); } } else // is optional param(s) { ChildNode = new ArgumentNode(contents, PossibleFlags); } if (i != commandstring.Length - 1) { commandstring = commandstring.Substring(0, open) + commandstring.Substring(i + 2); // Remove the backets we just handled } else { commandstring = commandstring.Substring(0, open - 1); } i = open - 2; // Reset i } } } string[] kargs = commandstring.Split(); int x; if (kargs[0][0] == '<') { Key = null; x = 0; } else { Key = kargs[0]; x = 1; } for (; x < kargs.Length; x++) { ArgNames.Add(kargs[x].Substring(1, kargs[x].Length - 2)); // strip out "<>" } }