Exemplo n.º 1
0
        private void InitalizeDefaultBehavior()
        {
            _behaviorDefinition = new ActorBehaviorDefinition();

            Script script = new Script(EngineConstants.FILEPATH_SCRIPTS + "aggressive_npc.lua");

            this.BehaviorDefinition.Attack    = new ScriptFunction(args => script.GetFunction("Attack").Call(args));
            this.BehaviorDefinition.OnCreated = new ScriptAction((args => script.GetFunction("OnCreated").Call(args)));
            this.BehaviorDefinition.Attacked  = new ScriptAction((args =>
            {
                script.GetFunction("Attacked").Call(args);
            }
                                                                  ));
            this.BehaviorDefinition.OnDeath = new ScriptAction((args =>
            {
                script.GetFunction("OnDeath").Call(args);
            }
                                                                ));

            this.BehaviorDefinition.Update = new ScriptAction((args =>
            {
                script.GetFunction("Update").Call(args);
            }
                                                               ));
        }
Exemplo n.º 2
0
        private void InitalizeScripts(IEnumerable <string> scriptPaths)
        {
            foreach (var scriptPath in scriptPaths)
            {
                Script script = Engine.Services.Get <ScriptManager>().CreateScript(Constants.FILEPATH_DATA + scriptPath);
                ActorBehaviorDefinition behaviorDefinition = script?.GetVariable <ActorBehaviorDefinition>("BehaviorDefinition");

                if (behaviorDefinition != null)
                {
                    this.Behavior = behaviorDefinition;
                }
            }
        }
Exemplo n.º 3
0
        private void InitalizeScripts(NPCDescriptor descriptor)
        {
            _behaviorDefinition = new ActorBehaviorDefinition();
            foreach (var scriptDef in descriptor.Scripts)
            {
                string scriptActionHook = scriptDef.Key;
                string scriptContent    = scriptDef.Value;

                Script script = new Script(scriptContent, false);

                switch (scriptActionHook)
                {
                case "OnAttack":
                    this.BehaviorDefinition.Attack = new ScriptFunction(args => script.GetFunction("Attack").Call(args));
                    break;

                case "OnCreated":
                    this.BehaviorDefinition.OnCreated = new ScriptAction((args =>
                    {
                        script.GetFunction("OnCreated").Call(args);
                    }
                                                                          ));
                    break;

                case "OnAttacked":
                    this.BehaviorDefinition.Attacked = new ScriptAction((args =>
                    {
                        script.GetFunction("Attacked").Call(args);
                    }
                                                                         ));
                    break;

                case "OnDeath":
                    this.BehaviorDefinition.OnDeath = new ScriptAction((args =>
                    {
                        script.GetFunction("OnDeath").Call(args);
                    }
                                                                        ));
                    break;

                case "OnUpdate":
                    this.BehaviorDefinition.Update = new ScriptAction((args =>
                    {
                        script.GetFunction("Update").Call(args);
                    }
                                                                       ));
                    break;
                }
            }
        }