Exemplo n.º 1
0
        private OpWord PCReadOpWord()
        {
            OpWord op = Program[pc];

            pc++;
            return(op);
        }
Exemplo n.º 2
0
 public OpCodeComputer Run(Action <long> output = null)
 {
     idle.Reset();
     while (pc >= 0 && pc < Program.Length)
     {
         var cancel = new CancelEventArgs(false);
         PreExecute?.Invoke(pc, cancel);
         OpWord op = PCReadOpWord();
         if (cancel.Cancel)
         {
             break;
         }
         if (op.OpCode == OpCode.nop)
         {
             //nop
         }
         else if (op.OpCode == OpCode.acc)
         {
             Accumulator += op.Arg;
         }
         else if (op.OpCode == OpCode.jmp)
         {
             pc += op.Arg - 1;
         }
         else
         {
             throw new Exception("Opcode error");
         }
     }
     return(this);
 }
        public List <Page> CreateOpWordPages(OpWord op)
        {
            string      img   = $"{s3.Url}avatars/{op.OperatorCode}.png";
            List <Page> pages = new List <Page>();
            string      text  = string.Empty;
            int         i     = 0;
            int         page  = 1;

            if (op.Words != null && op.Words.Any())
            {
                foreach (Word w in op.Words)
                {
                    i++;
                    text += $"{Formatter.Bold(w.Title+':')} {w.Text}\n";
                    if (i == 8)
                    {
                        var embed = new DiscordEmbedBuilder()
                                    .WithTitle($"[{op.Rarity}★] {op.Name} - Quote {page}")
                                    .WithThumbnail(img, 60, 60)
                                    .WithDescription(text)
                                    .Build();
                        pages.Add(new Page {
                            Embed = embed
                        });
                        text = string.Empty;
                        i    = 0;
                        page++;
                    }
                }
                if (!string.IsNullOrEmpty(text))
                {
                    var embed = new DiscordEmbedBuilder()
                                .WithTitle($"[{op.Rarity}★] {op.Name} - Quote {page}")
                                .WithThumbnail(img, 60, 60)
                                .WithDescription(text)
                                .Build();
                    pages.Add(new Page {
                        Embed = embed
                    });
                }
            }
            return(pages);
        }
Exemplo n.º 4
0
        public async Task GetOperatorQuote(CommandContext ctx,
                                           [Description("Operator's name")] string name)
        {
            try
            {
                OpWord op = await operatorService.GetOperatorQuote(name);

                if (op is null)
                {
                    await ctx.RespondAsync("Operator not found.");

                    return;
                }
                var         itr   = ctx.Client.GetInteractivity();
                List <Page> pages = embedService.CreateOpWordPages(op);
                await itr.SendPaginatedMessageAsync(ctx.Channel, ctx.User, pages, timeoutoverride : TimeSpan.FromMinutes(5));
            }
            catch (Exception e)
            {
                await ctx.RespondAsync($"An error occurred:{e.Message}");
            }
        }