public override void OnResponse(RelayInfo info) { int id = info.ButtonID; if (id == 0) { ReleaseHidden(User); return; } PlayerProfile profile = UltimaStore.GetProfile(User); switch (id) { // Change Category case 100: case 101: case 102: case 103: case 104: case 105: { Search = false; StoreCategory oldCat = profile.Category; profile.Category = (StoreCategory)id - 99; if (oldCat != profile.Category) { StoreList = UltimaStore.GetList(Category); Page = 0; } Refresh(); return; } // Promo Code case 106: { Refresh(); SendGump(new PromoCodeGump(User, this)); return; } // FAQ case 107: { if (!string.IsNullOrWhiteSpace(Configuration.Website)) { User.LaunchBrowser(Configuration.Website); } else { User.LaunchBrowser("https://uo.com/ultima-store/"); } Refresh(); return; } // Change Sort Method case 108: case 109: case 110: case 111: case 112: { SortBy oldSort = profile.SortBy; profile.SortBy = (SortBy)id - 108; if (oldSort != profile.SortBy) { // re-orders the list if (oldSort == SortBy.Newest || oldSort == SortBy.Oldest) { ColUtility.Free(StoreList); StoreList = UltimaStore.GetList(Category); } UltimaStore.SortList(StoreList, profile.SortBy); Page = 0; } Refresh(); return; } // Cart View case 113: { if (profile != null) { profile.Category = StoreCategory.Cart; } Refresh(); return; } // Search case 114: { TextRelay searchTxt = info.GetTextEntry(0); if (searchTxt != null && !string.IsNullOrEmpty(searchTxt.Text)) { Search = true; SearchText = searchTxt.Text; } else { User.SendLocalizedMessage(1150315); // That text is unacceptable. } Refresh(); return; } // Buy case 115: { if (UltimaStore.CartCount(User) == 0) { if (profile != null) { profile.Category = StoreCategory.Cart; } Refresh(); return; } int total = UltimaStore.GetSubTotal(Cart); if (total <= UltimaStore.GetCurrency(User, true)) { SendGump(new ConfirmPurchaseGump(User)); } else { SendGump(new NoFundsGump(User)); } return; } // Next Page case 116: { ++Page; Refresh(); return; } // Previous Page case 117: { --Page; Refresh(); return; } } if (id < 2000) // Add To Cart { Refresh(); StoreEntry entry = StoreList[id - 1000]; if (Cart == null || Cart.Count < 10) { SendGump(new ConfirmCartGump(User, this, entry)); return; } User.SendLocalizedMessage(1156745); // Your store cart is currently full. } else if (id < 3000) // Change Amount In Cart { Refresh(); StoreEntry entry = UltimaStore.Entries[id - 2000]; SendGump(new ConfirmCartGump(User, this, entry, Cart != null && Cart.ContainsKey(entry) ? Cart[entry] : 0)); return; } else if (id < 4000) // Remove From Cart { StoreEntry entry = UltimaStore.Entries[id - 3000]; if (profile != null) { profile.RemoveFromCart(entry); } Refresh(); return; } ReleaseHidden(User); }
public static void TryPurchase(Mobile m) { Dictionary <StoreEntry, int> cart = GetCart(m); int total = GetSubTotal(cart); if (cart == null || cart.Count == 0 || total == 0) { // Purchase failed due to your cart being empty. m.SendLocalizedMessage(1156842); } else if (total > GetCurrency(m, true)) { if (m is PlayerMobile) { BaseGump.SendGump(new NoFundsGump((PlayerMobile)m)); } } else { int subtotal = 0; bool fail = false; List <StoreEntry> remove = new List <StoreEntry>(); foreach (KeyValuePair <StoreEntry, int> entry in cart) { for (int i = 0; i < entry.Value; i++) { if (!entry.Key.Construct(m)) { fail = true; try { using (StreamWriter op = File.AppendText("UltimaStoreError.log")) { op.WriteLine("Bad Constructor: {0}", entry.Key.ItemType.Name); Utility.WriteConsoleColor(ConsoleColor.Red, "[Ultima Store]: Bad Constructor: {0}", entry.Key.ItemType.Name); } } catch (Exception e) { Server.Diagnostics.ExceptionLogging.LogException(e); } } else { remove.Add(entry.Key); subtotal += entry.Key.Cost; } } } if (subtotal > 0) { DeductCurrency(m, subtotal); } PlayerProfile profile = GetProfile(m); foreach (StoreEntry entry in remove) { profile.RemoveFromCart(entry); } if (fail) { // Failed to process one of your items. Please check your cart and try again. m.SendLocalizedMessage(1156853); } } }