예제 #1
0
        public Character(int _characterId)
        {
            characterId   = _characterId;
            nameVar       = "char" + _characterId.ToString() + "name";
            hairColorVar  = "char" + _characterId.ToString() + "haircolor";
            actionVar     = "char" + _characterId.ToString() + "action";
            actionItemVar = "char" + _characterId.ToString() + "actionitem";

            RantProgram setName       = RantProgram.CompileString(@"[vs:" + nameVar + ";<name>]");
            RantProgram setHairColor  = RantProgram.CompileString(@"[vs:" + hairColorVar + ";<adj-color>]");
            RantProgram setAction     = RantProgram.CompileString(@"[vs:" + actionVar + ";<verb>]");
            RantProgram setActionItem = RantProgram.CompileString(@"[vs:" + actionItemVar + ";<noun>]");

            rantEngine.Do(setName);
            rantEngine.Do(setHairColor);
            rantEngine.Do(setAction);
            rantEngine.Do(setActionItem);

            RantProgram getName       = RantProgram.CompileString("[v:" + nameVar + "]");
            RantProgram getHairColor  = RantProgram.CompileString("[v:" + hairColorVar + "]");
            RantProgram getAction     = RantProgram.CompileString("[v:" + actionVar + "]");
            RantProgram getActionItem = RantProgram.CompileString("[v:" + actionItemVar + "]");

            name       = rantEngine.Do(getName).Main;
            hairColor  = rantEngine.Do(getHairColor).Main;
            action     = rantEngine.Do(getAction).Main;
            actionItem = rantEngine.Do(getActionItem).Main;
        }
예제 #2
0
        public void ShowRoom()
        {
            RantProgram program = RantProgram.CompileString(@"You <descriptor-room_arrived>");
            RantOutput  output  = rantEngine.Do(program);

            string roomArrive = output.ToString();

            Console.WriteLine(Environment.NewLine + roomArrive + " " + this.description);
        }
예제 #3
0
        static async void OnMessage(object sender, MessageEventArgs eventArgs)
        {
            var messageText = eventArgs.Message.Text;

            _rant["tense"] = new RantObject(messageText);
            var program = RantProgram.CompileString("Прости, я пока что не понимаю, что ты [if: [eq:[v: tense];present];<verb.present>;<verb.simple_past>]!");
            var message = _rant.Do(program);
            await _client.SendTextMessageAsync(eventArgs.Message.Chat, message);
        }
예제 #4
0
        public string ExecuteRant(string rawMessage, bool gender, bool botGender)
        {
            _rant["gender"] = gender == Const.Gender.Male
                ? new RantObject("male")
                : new RantObject("female");

            _rant["botGender"] = botGender == Const.Gender.Male
                            ? new RantObject("male")
                            : new RantObject("female");

            var rantProgram = RantProgram.CompileString(rawMessage);

            return(_rant.Do(rantProgram));
        }
예제 #5
0
        public void SerializeAndExecute(string pattern)
        {
            var ms     = new MemoryStream();
            var pgmSer = RantProgram.CompileString(pattern);

            pgmSer.SaveToStream(ms);
            ms.Seek(0, SeekOrigin.Begin);
            var pgmDeser    = RantProgram.LoadStream("Test", ms);
            var resultSer   = rant.Do(pgmSer, seed: 0).Main;
            var resultDeser = rant.Do(pgmDeser, seed: 0).Main;

            Console.WriteLine($"Before: '{resultSer}'");
            Console.WriteLine($"After: '{resultDeser}'");
            Assert.AreEqual(resultSer, resultDeser);
        }
예제 #6
0
        public void SendBotChatMessage(Player p, LocalizedString message, RantProgramArgs args)
        {
            if (!Game.Settings.ChatEnabled || message == null)
            {
                return;
            }
            int seed = _rng.Next();
            var cfg  = Game.Settings.BotConfig;

            async void send(ClientConnectionBase connection, Random rng)
            {
                await Task.Delay(rng.Next(1500, 3000));

                RantProgram pgm;

                try
                {
                    pgm = RantProgram.CompileString(message[connection.ClientLanguage]);
                    var output = _rant.Do(pgm, seed: seed, charLimit: 0, timeout: -1, args: args).Main.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var msg in output)
                    {
                        int delay = rng.Next(cfg.MinTypingDelay, cfg.MaxTypingDelay + 1)
                                    + msg.Length * rng.Next(cfg.MinTypingInterval, cfg.MaxTypingInterval + 1);
                        await Task.Delay(delay);

                        connection.SendChatMessage(p, msg);
                        Console.WriteLine($"{p} says: \"{msg}\"");
                    }
                }
                catch (RantCompilerException ex)
                {
                    Console.WriteLine($"Rant compiler error: {ex}");
                    return;
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Rant failure: {ex}");
                    return;
                }
            }

            foreach (var connection in _connections.ToArray())
            {
                var rng = new Random(seed);
                send(connection, rng);
            }
        }
예제 #7
0
파일: Map.cs 프로젝트: newellewen/rantGame
        private static List <Room> GetRooms(int roomCount)
        {
            RantProgram program = RantProgram.CompileString(@"<adj> <noun-indoor>");
            RantOutput  output  = null;
            List <Room> rooms   = new List <Room>();

            for (int i = 0; i < roomCount; i++)
            {
                output = rantEngine.Do(program);
                Room newRoom = new Room();
                newRoom.roomId      = i + 1;
                newRoom.name        = output.ToString();
                newRoom.description = output.ToString();
                rooms.Add(newRoom);
            }
            return(rooms);
        }
        static void Main(string[] args)
        {
            var rant = new RantEngine();

            rant.LoadPackage("Rantionary-3.0.20.rantpkg");
            rant.Dictionary.IncludeHiddenClass("nsfw");

            Console.WriteLine("Press <Enter> to create a list of 1000 groups");
            Console.ReadKey(true);
            Console.Clear();

            var pgm    = RantProgram.CompileString(@"[rs:1000;\n]{<adj> <adj> <noun.pl>}");
            var output = rant.Do(pgm);

            Console.WriteLine(output.Main);



            Console.ReadLine();
        }
예제 #9
0
        public void generate_product_reviews()
        {
            var reviews = new[]
            {
                "this $product is <adj>.",
                "I tried to <verb-violent> it but got <noun-food> all over it.",
                "i use it <timeadv-frequency> when i'm in my <noun-place-indoor>.",
                "My <noun-living-animal> loves to play with it.",
                "[vl:ending][ladd:ending;!;!!;!!!;.]The box this comes in is [num:3;5] <unit-length> by [num:5;6] <unit-length> and weights [num:10;20] <unit-weight>[lrand:ending]",
                "This $product works <advattr> well. It <adv> improves my <activity> by a lot.",
                "I saw one of these in <country> and I bought one.",
                "one of my hobbies is <hobby::=A>. and when i'm <hobby.pred::=A> this works great.",
                "It only works when I'm <country>.",
                "My neighbor <name-female> has one of these. She works as a <noun-living-job> and she says it looks <adj-appearance>.",
                "My co-worker <name-male> has one of these. He says it looks <adj-appearance>.",
                "heard about this on <musicgenre> radio, decided to give it a try.",
                "[vl:ending][ladd:ending;!;!!;!!!;.]talk about <noun-uc-emotion>[lrand:ending]"
            };

            var singles = new[]
            {
                "This $product, does exactly what it's suppose to do.",
                "SoCal cockroaches are unwelcome, crafty, and tenacious. This $product keeps them away.",
                "works okay.",
                "I saw this on TV and wanted to give it a try.",
                "This is a really good $product."
            };

            var genReviews = reviews
                             .Select(rant => RantProgram.CompileString(rant))
                             .SelectMany(pgm =>
            {
                return(Enumerable.Range(1, 25)
                       .Select(_ => rant.Do(pgm, rng).Main));
            })
                             .Concat(singles)
                             .Distinct()
                             .ToList();

            Inject("en", "rant", "review", genReviews);
        }
예제 #10
0
        public void SaveLoadRun()
        {
            var package = new RantPackage
            {
                ID          = "TestPackage",
                Description = "This is a test.",
                Title       = "Test Package?!",
                Version     = new RantPackageVersion(1, 1, 0)
            };

            package.AddResource(RantDictionaryTable.FromStream("nouns", File.Open("Tables/nouns.table", FileMode.Open)));
            package.AddResource(RantProgram.CompileString("TestProgram", @"[case:title]<noun-food-fruit-yellow> [rs:5;,\s]{[rn]}"));
            package.Save("TestPackage.rantpkg");

            package = RantPackage.Load("TestPackage.rantpkg");
            rant.LoadPackage(package);

            Assert.AreEqual("Banana 1, 2, 3, 4, 5", rant.DoName("TestProgram").Main);
            Assert.AreEqual("TestPackage", package.ID);
            Assert.AreEqual("This is a test.", package.Description);
            Assert.AreEqual("Test Package?!", package.Title);
            Assert.AreEqual("1.1.0", package.Version.ToString());
        }
예제 #11
0
 public void MissingQueryClassFilter()
 {
     RantProgram.CompileString(@"<noun->");
 }
예제 #12
0
 public void MissingQuerySubtype()
 {
     RantProgram.CompileString(@"<noun.>");
 }
예제 #13
0
 public void InvalidQuerySubtype()
 {
     RantProgram.CompileString(@"<noun.???>");
 }
예제 #14
0
 public void InvalidQueryTableName(string name)
 {
     RantProgram.CompileString($"<{name}>");
 }
예제 #15
0
 public void UnterminatedQuery()
 {
     RantProgram.CompileString(@"<noun");
 }
예제 #16
0
 public void UnterminatedFunctionCall()
 {
     RantProgram.CompileString(@"[rep:10");
 }
예제 #17
0
        public async Task MakeRant([Remainder] string cmd)
        {
            var pgm = RantProgram.CompileString(cmd);

            await ReplyAsync(rant.Do(pgm).Main);
        }
예제 #18
0
 public void UnterminatedQueryComplement()
 {
     RantProgram.CompileString(@"<verb.ing [the <noun>>");
 }
예제 #19
0
 public void TooManyCarrierOperators()
 {
     RantProgram.CompileString(@"<noun::!A::@B>");
 }
예제 #20
0
 public void MissingReplacerArgument()
 {
     RantProgram.CompileString(@"[`\s*`:this is a test]");
 }
예제 #21
0
 public void ExtraOpeningBracket()
 {
     RantProgram.CompileString(@"[[rep:10]");
 }
예제 #22
0
 public void UnterminatedBlock()
 {
     RantProgram.CompileString(@"{");
 }
예제 #23
0
 public void BadNameArgsSeparator()
 {
     RantProgram.CompileString(@"[numfmt;verbal-en]");
 }
예제 #24
0
 public void BadParameterNames()
 {
     RantProgram.CompileString(@"[$[epic_fail:good_param;bad=param]:NO]");
 }
예제 #25
0
 public void MissingQuantifierComma()
 {
     RantProgram.CompileString(@"\123a");
 }
예제 #26
0
 public void EmptyTag()
 {
     RantProgram.CompileString(@"[]");
 }
예제 #27
0
 public void UnexpectedTagTerminator()
 {
     RantProgram.CompileString(@"]");
 }
예제 #28
0
 public void UnexpectedQueryTerminator()
 {
     RantProgram.CompileString(@">");
 }
예제 #29
0
 public void UnexpectedBlockTerminator()
 {
     RantProgram.CompileString(@"}");
 }
예제 #30
0
 public void ParameterMismatch(string pattern)
 {
     RantProgram.CompileString(pattern);
 }