public ShopSession(ArcadeContext context, Shop shop) { Context = context; Shop = shop; State = ShopState.Enter; Catalog = context.Data.Data.GetOrGenerateCatalog(shop, context.Account); List <Vendor> possibleVendors = ShopHelper.GetVendors(ShopHelper.GetUniqueTags(Catalog)).ToList(); Vendor = Check.NotNullOrEmpty(possibleVendors) ? Randomizer.Choose(possibleVendors) : null; if (!context.Account.CatalogHistory.ContainsKey(shop.Id)) { context.Account.CatalogHistory[shop.Id] = new CatalogHistory(); } if (!context.Account.CatalogHistory[shop.Id].HasVisited) { context.Account.CatalogHistory[shop.Id].HasVisited = true; context.Account.AddToVar(ShopHelper.GetVisitId(shop.Id)); } Var.SetIfEmpty(context.Account, ShopHelper.GetTierId(shop.Id), 1); long tier = context.Account.GetVar(ShopHelper.GetTierId(shop.Id)); if (Check.NotNullOrEmpty(shop.CriteriaTiers) && shop.CriteriaTiers.ContainsKey(tier + 1) && shop.CriteriaTiers[tier + 1].All(x => Var.MeetsCriterion(context.Account, x))) { context.Account.AddToVar(ShopHelper.GetTierId(shop.Id)); } }
public TradeSession(ArcadeContext context, ArcadeUser participant) { Context = context; LastState = null; State = TradeState.Invite; CurrentId = null; Host = Context.Account; Participant = participant; HostReady = ParticipantReady = false; HostOffer = new Dictionary <string, int>(); ParticipantOffer = new Dictionary <string, int>(); }
public async Task ReadInputAsync(SocketMessage arg) { // Ignore bots if (arg.Author.IsBot) { return; } // Ignore users if they are in a game session if (_games.ReservedUsers.ContainsKey(arg.Author.Id)) { return; } // Ignore system messages if (!(arg is SocketUserMessage source)) { return; } var ctx = new ArcadeContext(_client, _container, source); bool deleteInput = false; bool prefixFound = false; string input = null; // TODO: Handle message filters here to prevent additional command execution within another listener // Check all possible prefix formats int i = 0; if (source.HasMentionPrefix(_client.CurrentUser, ref i)) { await ExecuteAsync(ctx, i); return; } if (source.HasStringPrefix(GetPrefix(ctx) + "d]", ref i)) { prefixFound = true; deleteInput = true; } // Move this functionality to [about <input> if (source.HasStringPrefix(GetPrefix(ctx) + "?]", ref i)) { string inner = source.Content[(GetPrefix(ctx) + "?]").Length..].ToLower();
public static string ViewOffers(ArcadeUser user, ArcadeContext ctx) { var info = new StringBuilder(); info.AppendLine($"> ✉️ **Trade Offers**"); info.AppendLine($"> Because connections matter."); if (user.Offers.Count == 0) { info.AppendLine($"\nYou do not have any active offers."); } else { foreach (TradeOffer offer in user.Offers) { info.AppendLine($"\n{ViewOffer(offer, ctx)}"); } } return(info.ToString()); }
public static string ViewOffer(TradeOffer offer, ArcadeContext ctx) { var info = new StringBuilder(); if (!offer.Target.Id.HasValue || !offer.Author.Id.HasValue) { throw new Exception("Expected a specified user ID for both the target and author in the specified trade offer"); } ctx.TryGetUser(offer.Target.Id.Value, out ArcadeUser target); ctx.TryGetUser(offer.Author.Id.Value, out ArcadeUser author); if (!IsOfferValid(target, author, offer)) { info.AppendLine(Format.Warning("This trade offer is invalid or expired and will be removed.")); target.Offers.RemoveAll(x => x.Id == offer.Id); author.Offers.RemoveAll(x => x.Id == offer.Id); } info.AppendLine($"> `{offer.Id}` {(offer.Type == OfferType.Inbound ? $"**From: {offer.Author.ToString("Unknown User")}**" : $"**To: {offer.Target.ToString("Unknown User")}**")}"); info.AppendLine($"> Expires in {Format.LongCounter(TimeSpan.FromHours(24) - (DateTime.UtcNow - offer.CreatedAt))}"); if (offer.ItemIds.Count > 0) { info.AppendLine("**Offers**:"); info.AppendJoin("\n", offer.ItemIds.Select(x => WriteItem(x.Key, x.Value))); if (offer.RequestedItemIds.Count > 0) { info.AppendLine(); } } if (offer.RequestedItemIds.Count > 0) { info.AppendLine("**Requests**:"); info.AppendJoin("\n", offer.RequestedItemIds.Select(x => WriteItem(x.Key, x.Value))); } return(info.ToString()); }
public string GetPrefix(ArcadeContext ctx) => ctx.Account?.Config.Prefix ?? ctx.Server?.Config.Prefix ?? OriGlobal.DEFAULT_PREFIX;
public static string View(ArcadeUser user, ArcadeContext ctx) { var details = new StringBuilder(); details.AppendLine($"> **{user.Username}**"); details.AppendLine($"> Joined: **{Format.Date(user.CreatedAt, '.')}**"); details.AppendLine("\n> **Level**"); details.AppendLine($"> {LevelViewer.GetLevel(user.Level, user.Ascent)}"); if (user.Balance > 0 || user.Debt > 0 || user.ChipBalance > 0) { details.AppendLine("\n> **Wallet**"); if (user.Balance > 0 || user.Debt > 0) { string icon = user.Balance > 0 ? Icons.Balance : Icons.Debt; long value = user.Balance > 0 ? user.Balance : user.Debt; string id = user.Balance > 0 ? Vars.Balance : Vars.Debt; int position = Leaderboard.GetPosition(ctx.Data.Users.Values.Values, user, id); string pos = ""; if (position < 4) { pos = $" (#**{position:##,0}** global)"; } details.AppendLine($"> {icon} **{value:##,0}**{pos}"); } if (user.ChipBalance > 0) { int position = Leaderboard.GetPosition(ctx.Data.Users.Values.Values, user, Vars.Chips); string pos = ""; if (position < 4) { pos = $" (#**{position:##,0}** global)"; } details.AppendLine($"> {Icons.Chips} **{user.ChipBalance:##,0}**{pos}"); } } if (user.Items.Count > 0) { details.AppendLine($"\n> **Inventory**"); details.AppendLine($"> **{user.Items.Count}** used {Format.TryPluralize("slot", user.Items.Count)}"); } List <string> randomStats = GetRandomStats(user, 3); if (Check.NotNullOrEmpty(randomStats)) { return(details.ToString()); } details.AppendLine($"\n> **Random Statistics**"); foreach (string stat in randomStats) { details.AppendLine($"> **{Var.WriteName(stat)}**: {Var.WriteValue(user, stat)}"); } return(details.ToString()); }