Пример #1
0
        public async Task SetCharacterStance(string s = "")
        {
            _ = Context.Message.DeleteAsync();
            L5RCharacter character = CharacterRepository.FindCurrentByMention <L5RCharacter>(Context.Message.Author.Mention);

            if (character == null)
            {
                await Context.Channel.SendMessageAsync("Error 404: Character not found or not loaded!");

                return;
            }

            try
            {
                character.SetCurrentStance(s);
            }
            catch (Exception ex)
            {
                await Context.Channel.SendMessageAsync($"{Context.User.Mention} {ex.Message}");
            }

            var msg = await Context.Channel.SendMessageAsync($"{Context.User.Mention} Posture modifiée!");

            await Task.Delay(3000);

            _ = msg.DeleteAsync();
        }
Пример #2
0
        public async static Task HandleFile(IAttachment attachment, string mention)
        {
            if (Path.GetExtension(attachment.Filename) != ".xlsx")
            {
                throw new ArgumentException("Format de fichier incorrect.");
            }

            using (HttpClient hclient = new HttpClient())
            {
                Stream stream;
                try
                {
                    stream = await hclient.GetStreamAsync(attachment.Url);
                }
                catch (Exception)
                {
                    try
                    {
                        stream = await hclient.GetStreamAsync(attachment.ProxyUrl);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
                MemoryStream memoryStream = new MemoryStream();
                stream.CopyTo(memoryStream);
                using (ExcelPackage package = new ExcelPackage(memoryStream))
                {
                    PlayableCharacter character = null;
                    ExcelWorkbook     workbook  = package.Workbook;
                    ExcelWorksheet    worksheet = workbook.Worksheets["Feuille de personnage"];
                    if (worksheet != null)//Fiche de perso anima
                    {
                        character = new AnimaCharacter(worksheet, mention);
                    }
                    worksheet = workbook.Worksheets["Stat"];
                    if (worksheet != null)//Fiche de perso L5R => peut encore changer
                    {
                        character = new L5RCharacter(worksheet, mention);
                    }

                    int charIndex = CharacterRepository.Characters.FindIndex(x => x.Player == mention && x.Name == character.Name);

                    if (charIndex == -1)
                    {
                        CharacterRepository.Characters.Add(character);
                    }
                    else
                    {
                        CharacterRepository.Characters[charIndex] = character;
                    }

                    CharacterRepository.SaveExcelCharacter(package, mention, character.Name);
                }
            }
        }
Пример #3
0
        public static void LoadFromCurrentDirectory()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            string[] allFiles = Directory.GetFiles(savePath, "@*");
            int      cCount   = 0;

            Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss", CultureInfo.CurrentCulture)} Loading characters: {cCount}/{allFiles.Length}");
            foreach (string file in allFiles)
            {
                string mention = "<" + Path.GetFileNameWithoutExtension(file).Split('_').First() + ">";
                using (Stream strm = File.Open(file, FileMode.Open))
                {
                    MemoryStream memoryStream = new MemoryStream();
                    strm.CopyTo(memoryStream);
                    using (ExcelPackage package = new ExcelPackage(memoryStream))
                    {
                        PlayableCharacter character = null;
                        ExcelWorkbook     workbook  = package.Workbook;
                        ExcelWorksheet    worksheet = workbook.Worksheets["Feuille de personnage"];
                        if (worksheet != null)//Fiche de perso anima
                        {
                            character = new AnimaCharacter(worksheet, mention);
                        }
                        worksheet = workbook.Worksheets["Stat"];
                        if (worksheet != null)//Fiche de perso L5R => peut encore changer
                        {
                            character = new L5RCharacter(worksheet, mention);
                        }
                        Characters.Add(character);
                    }
                }
                cCount++;
                Console.Clear();
                Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss", CultureInfo.CurrentCulture)} Loading characters: {cCount}/{allFiles.Length}");
            }
            sw.Stop();
            Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss", CultureInfo.CurrentCulture)} All characters loaded in : {sw.ElapsedMilliseconds}ms");
        }
Пример #4
0
        public async Task CharacterRoll(params string[] s)
        {
            L5RDiceHelper.GuildEmotes = Context.Guild.Emotes;

            L5RCharacter character = CharacterRepository.FindCurrentByMention <L5RCharacter>(Context.Message.Author.Mention);

            if (character == null)
            {
                await Context.Channel.SendMessageAsync("Error 404: Character not found or not loaded!");

                return;
            }

            string ring = "";

            if (character.Rings.ContainsKey(s.Last()))
            {
                ring = s.Last();
            }

            string rawStat = string.Join(" ", s).ToLower();

            if (!string.IsNullOrWhiteSpace(ring))
            {
                rawStat = rawStat.Replace($" {ring}", "");
            }

            if (rawStat == null || rawStat == string.Empty)
            {
                await Context.Message.DeleteAsync();

                await Context.Channel.SendMessageAsync(character.KeywordsHelp());
            }
            else
            {
                MessageReference msgRef = new MessageReference(Context.Message.Id);
                await Context.Channel.SendMessageAsync(character.Roll(rawStat, ring), messageReference : msgRef);
            }
        }
Пример #5
0
 private static bool SaveL5RCharacter(L5RCharacter character, FileInfo file)
 {
     throw new NotImplementedException();
 }