Пример #1
0
        public void TestClassList()
        {
            ClassList classList = new ClassList("races");

            classList.AddClass(new Class("dwarf",
                                         new AttributeModifier(AttributeModifier.AttributeModifierOptions.SET, "use_hammer"),
                                         new AttributeModifier(AttributeModifier.AttributeModifierOptions.FORBID, "use_bow")
                                         ));

            classList.AddClass(new Class("elf",
                                         new AttributeModifier(AttributeModifier.AttributeModifierOptions.SET, "use_bow")
                                         ));

            Assert.IsTrue(classList.IsClassExisting("dwarf"));
            Assert.IsTrue(classList.IsClassExisting("elf"));
            Assert.IsFalse(classList.IsClassExisting("human"));

            Class dwarf = classList.GetClassByName("dwarf");
            Class elf   = classList.GetClassByName("elf");

            Assert.IsTrue(dwarf.ContainsAttributeModifier("use_hammer"));
            Assert.IsTrue(dwarf.ContainsAttributeModifier("use_bow"));

            Assert.AreEqual(dwarf.GetAttributeModifier("use_bow").Option, AttributeModifier.AttributeModifierOptions.FORBID);
        }
Пример #2
0
        public void TestClassvars()
        {
            SchemeFunction f = new SchemeFunction();

            f.AddCommand(new CommandOf("race", "actor", "ThorinRace"));
            f.AddCommand(new CommandIs("ThorinRace", "dwarf", "ThorinIsDwarf"));
            f.AddCommand(new CommandOf("friend", "actor", "_0"));
            f.AddCommand(new CommandOf("race", "_0", "ThorinsFriendRace"));
            f.AddCommand(new CommandIs("ThorinsFriendRace", "elf", "ThorinsFriendIsElf"));
            f.AddCommand(new CommandOf("race", "me", "LegolasRace"));
            f.AddCommand(new CommandIs("LegolasRace", "elf", "LegolasIsElf"));

            Character Thorin  = new Character("Thorin", "Thorin");
            Object    Legolas = new Object("Legolas", "Legolas");

            ClassList classList = new ClassList("races");
            Class     dwarf     = new Class("dwarf");
            Class     elf       = new Class("elf");

            classList.AddClass(dwarf);
            classList.AddClass(elf);

            Thorin.Scheme = new Scheme("thorin_scheme");
            Thorin.Variables.Add(new ObjectVariable("races", "race", dwarf));       //Thorin is dwarf
            Thorin.Variables.Add(new ObjectVariable("object", "friend", Legolas));  //Legolas is Thorin's friend

            Legolas.Scheme = new Scheme("legolas_scheme");
            Legolas.Variables.Add(new ObjectVariable("races", "race", elf));        //Legolas is elf

            Legolas.Variables.Add(new ObjectVariable("logical", "ThorinIsDwarf", false));
            Legolas.Variables.Add(new ObjectVariable("logical", "ThorinsFriendIsElf", false));
            Legolas.Variables.Add(new ObjectVariable("logical", "LegolasIsElf", false));
            Legolas.Variables.Add(new ObjectVariable("races", "ThorinRace", false));
            Legolas.Variables.Add(new ObjectVariable("races", "ThorinsFriendRace", false));
            Legolas.Variables.Add(new ObjectVariable("races", "LegolasRace", false));

            Config config = new Config();

            config.AddClassList(classList);

            Game game = new Game(config);

            f.Execute(Legolas, Thorin, game);

            Assert.AreEqual(true, Legolas.GetVariableByName("ThorinIsDwarf", config).Value);
            Assert.AreEqual(true, Legolas.GetVariableByName("ThorinsFriendIsElf", config).Value);
            Assert.AreEqual(true, Legolas.GetVariableByName("LegolasIsElf", config).Value);

            Assert.AreEqual(dwarf, Legolas.GetVariableByName("ThorinRace", config).Value);
            Assert.AreEqual(elf, Legolas.GetVariableByName("ThorinsFriendRace", config).Value);
            Assert.AreEqual(elf, Legolas.GetVariableByName("LegolasRace", config).Value);
        }
Пример #3
0
        public override object VisitClassName([NotNull] classlist_langParser.ClassNameContext context)
        {
            //Check if class already exists in current list

            if (currentClassList == null)
            {
                return(base.VisitClassName(context));
            }

            bool exists = false;

            foreach (var @class in currentClassList.Classes)
            {
                if (@class.Name == context.GetText())
                {
                    Errors.Add(new ErrorDescriptor("Class '" + @class.Name + "' already exists in classlist", context.Start.Line, context.Start.Column, context.Start.StartIndex, context.Start.StopIndex));
                    exists = true;
                    break;
                }
            }

            if (!exists)
            {
                Class c = new Class();
                c.Name = context.GetText();
                currentClassList.AddClass(c);
            }

            return(base.VisitClassName(context));
        }
Пример #4
0
        public void TestAbilities()
        {
            ClassList races = new ClassList("races");

            races.AddClass(new Class("dwarf", new AbilityModifier("STR", 2)));
            races.AddClass(new Class("elf", new AbilityModifier("STR", 3)));

            ClassList jobs = new ClassList("jobs");

            jobs.AddClass(new Class("smith", new AbilityModifier("STR", 4)));
            jobs.AddClass(new Class("mage", new AbilityModifier("STR", -1)));

            SchemeFunction f = new SchemeFunction();

            f.AddCommand(new CommandSetVariable("strength", "STR"));

            MapObject @object = new MapObject();

            @object.Name   = "some_object";
            @object.Scheme = new Scheme("some_scheme");

            @object.Variables.Add(new ObjectVariable(VariableTypes.Ability, "STR", 5));                 //STR = 5
            @object.Variables.Add(new ObjectVariable(VariableTypes.Number, "strength", 0));

            Config config = new Config();

            config.AddScheme(@object.Scheme);
            config.AddClassList(races);
            config.AddClassList(jobs);

            @object.Variables.Add(new ObjectVariable("races", "race", races.GetClassByName("dwarf")));  //dwarf: STR+2
            @object.Variables.Add(new ObjectVariable("jobs", "job", jobs.GetClassByName("mage")));      //mage:  STR-1

            Game game = new Game(config);

            game._AddObject(@object);

            //Execute function on object
            f.Execute(@object, new Character(), game);

            Assert.AreEqual(6, @object.GetVariableByName("strength", config).Value);
        }
Пример #5
0
        public void TestClasslistHandling()
        {
            ClassList races = new ClassList("races");

            races.AddClass(new Class("dwarf"));
            races.AddClass(new Class("elf"));

            SchemeFunction f = new SchemeFunction();

            f.AddCommand(new CommandOf("race", "actor", "_0"));
            f.AddCommand(new CommandEquals("_0", "dwarf", "isDwarf"));
            f.AddCommand(new CommandOf("race", "actor", "_0"));
            f.AddCommand(new CommandEquals("_0", "elf", "isElf"));

            MapObject @object = new MapObject();

            @object.Name   = "some_object";
            @object.Scheme = new Scheme("some_scheme");
            @object.Variables.Add(new ObjectVariable("logical", "isDwarf", false));
            @object.Variables.Add(new ObjectVariable("logical", "isElf", false));

            Config config = new Config();

            config.AddScheme(@object.Scheme);
            config.AddClassList(races);

            Game game = new Game(config);

            game._AddObject(@object);

            Character actor = new Character();

            actor.Scheme = new Scheme("character");
            actor.Variables.Add(new ObjectVariable("races", "race", races.GetClassByName("dwarf")));

            //Execute function on object
            f.Execute(@object, actor, game);

            Assert.AreEqual(@object.GetVariableByName("isDwarf", config).Value, true);
            Assert.AreEqual(@object.GetVariableByName("isElf", config).Value, false);
        }