public static Task SpawnEncounter(DiscordChannel channel, DiscordUser user, string encounterId) { var encounter = EncounterManager.GetEncounter(encounterId); return(Task.Run(async() => { var message = await channel.SendMessageAsync(embed: encounter.ToEmbed(user)); encounter.OnEnter(channel, user); Logger.LogMessage(LogLevel.Info, "Encounter", $"{user} is beginning encounter {encounter.id}.", DateTime.Now); var trigger = Instance.AddReactionTrigger(message, user, (u, selection) => { var activeEncounter = EncounterManager.GetActiveEncounter(user); var selectedOption = encounter.GetOptionFromEmoji(selection); if (selectedOption != null) { Instance.RemoveReactionTrigger(message); message.DeleteAllReactionsAsync(); if (selectedOption != null) { selectedOption.action.Execute(channel, user); } encounter.OnExit(channel, user); } else if (!activeEncounter.lootCollected && encounter.lootAction != null) { activeEncounter.lootCollected = true; if (encounter.flags.HasFlag(EncounterFlags.IsExit)) { message.DeleteAllReactionsAsync(); encounter.OnExit(channel, user); } else { Task.Run(async() => { var users = await message.GetReactionsAsync(EmojiUtils.moneybag); for (int i = 0; i < users.Count; i++) { var task = message.DeleteReactionAsync(EmojiUtils.moneybag, users[i]); } }); } encounter.lootAction.Execute(channel, user); } }); if (encounter.flags.HasFlag(EncounterFlags.IsExit)) { if (encounter.lootAction == null) { encounter.OnExit(channel, user); } } else { if (encounter.options != null) { var tasks = new Task[encounter.options.Length]; for (int i = 0; i < encounter.options.Length; i++) { var option = encounter.options[i]; DiscordEmoji emoji; if (option.displayIcon != null) { emoji = option.displayIcon; } else { emoji = EmojiUtils.emojiNumbers[i]; } await message.CreateReactionAsync(option.displayIcon); } } } if (encounter.lootAction != null) { await message.CreateReactionAsync(EmojiUtils.moneybag); } })); }
public async Task BeginEncounter(CommandContext c) { await c.TriggerTypingAsync(); string encounterId; var canSpawn = EncounterManager.TrySpawnEncounterForUser(c.Member, out encounterId); if (!canSpawn) { if (encounterId != null) { await c.RespondAsync(embed : DiscordEmbedUtils.MakeEmbed(text: $"You're already in the encounter **{EncounterManager.GetEncounter( encounterId ).title}**! Get back there!", author: c.Member)); } else { await c.RespondAsync(embed : DiscordEmbedUtils.MakeEmbed(text: $"You searched but nothing interesting seems to be happening at the moment...", author: c.Member)); } } else { if (encounterId != null) { await EncounterManager.SpawnEncounter(c.Channel, c.User, encounterId); } else { await c.RespondAsync(embed : DiscordEmbedUtils.MakeEmbed(text: $"You searched but nothing interesting seems to be happening at the moment...", author: c.Member)); } } }