public override bool Start(FieldUser target, FieldNPC self)
        {
            var script = self.Template.Scripts.FirstOrDefault()?.Script;

            if (target.ConversationContext != null)
            {
                return(false);
            }
            if (script == null)
            {
                return(false);
            }

            script = Path.Combine(_options.ScriptPath, $"{script}.lua");

            if (!File.Exists(script))
            {
                return(false);
            }

            var context      = new ConversationContext(new CancellationTokenSource(), target.Socket);
            var conversation = new ScriptedConversation <FieldUserSpeaker, FieldNPCSpeaker>(script);

            target.ConversationContext = context;
            conversation.Start(
                context,
                new FieldUserSpeaker(context, target),
                new FieldNPCSpeaker(context, self)
                ).ContinueWith(t =>
            {
                target.ConversationContext = null;
                target.ModifyStats(exclRequest: true);
            });
            return(true);
        }
        public override Task Start(ConversationContext context, T target, S self)
        {
            var script = new Script();

            script.Globals["target"] = UserData.Create(target);
            script.Globals["self"]   = UserData.Create(self);

            return(Task.Run(() =>
            {
                try
                {
                    script.DoFile(_scriptPath);
                }
                catch (Exception e)
                {
                    Logger.Error(e.ToString);
                }
            },
                            context.TokenSource.Token));
        }
예제 #3
0
 public abstract Task Start(ConversationContext context, T target, S self);