Esempio n. 1
0
        private void Test()
        {
            SchemeFunction f = new SchemeFunction();

            f.AddCommand(new CommandAddAction("grab"));
            f.AddCommand(new CommandAddAction("examine"));

            f.AddCommand(new CommandRemoveAction("grab"));
            f.AddCommand(new CommandAddAction("drop"));

            MapObject @object = new MapObject();

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

            @object.Scheme = new Scheme("some_scheme");
            @object.Scheme.CompiledScheme = new CompiledScheme();
            @object.Scheme.CompiledScheme.AddAction(new SchemeFunction("grab"));
            @object.Scheme.CompiledScheme.AddAction(new SchemeFunction("examine"));
            @object.Scheme.CompiledScheme.AddAction(new SchemeFunction("drop"));

            Config config = new Config();

            config.AddScheme(@object.Scheme);

            Game game = new Game(config);

            game._AddObject(@object);

            //Execute function on object
            f.Execute(@object, new Character(), game);
        }
Esempio n. 2
0
        public int ExecuteAction(string actionName, Object actor, Game game)
        {
            SchemeFunction action = Scheme?.GetFunctionByName(actionName);

            if (action == null)
            {
                throw new GameException("Given action does not exist.");
            }

            return(action.Execute(this, actor, game));
        }
Esempio n. 3
0
        public void ExecuteSquareAction(SquareType squareType, Character actor, Game game)
        {
            if (squareType == null || Scheme == null || squareType.ActionName == null || squareType.ActionName == "")
            {
                return;
            }

            SchemeFunction action = Scheme.GetFunctionByName(squareType.ActionName);

            if (action == null)
            {
                throw new GameException($"No such action in map: {squareType.ActionName}");
            }

            action.Execute(SchemeObject, actor, game);
        }