# Undersell command for gccg (Mtg). # # Copyright (C) 2005, 2006 Neil Moore . Distributed with NO # WARRANTY under the terms of the GPL, version 2 (only). # # 2006-11-16: added support for "/us all". Do not sell a card if the new # price would be less than 75% of the old. Add a three-argument invocation # to ignore this restriction. if(msg.box != NULL) { Msg("Loading {gold}Undersell.command"); } # undersell_price(c) - Find a new selling price for card c: undersell_pct # percent of its current selling price. # # Returns the new price, 0.0 if the price would not change def undersell_price { push(c); push(sell); push(myprice); push(price); push(newprice); c = ARG; price = (book_entry(card.book,c))[1]; myprice = (book_entry(card.book,c))[3]; sell = (book_entry(card.book,c))[4]; if(sell > 0 && price < myprice) { newprice = max(0.01, toint(undersell_pct*price)/100.0); if(newprice < myprice) { return(newprice); } else { return(0.0); } } else { return(0.0); } newprice = pop(); price = pop(); myprice = pop(); sell = pop(); c = pop(); } # Undersell everyone else for cards on current page. # def ChatCommandUndersell { push(cards); push(c); push(i); push(price); push(myprice); push(newprice); push(undersell_pct); push(minpct); minpct = 0.50; undersell_pct = 100; if(length(ARG) >= 1) { if(uc(ARG[length(ARG)-1]) == "FORCE") { minpct = 0.0; } if(uc(ARG[0]) != "FORCE") { if(toint(ARG[0]) >= 0) { undersell_pct = 100 - toint(ARG[0]); } } } if(length(ARG) >= 2) { if(uc(ARG[1]) != "FORCE") { cards = book.filter{"default"}; if(uc(ARG[1]) != "ALL") { cards = select("set_of(#)==\"" + uc(ARG[1]) + "\"", cards); } if(length(cards) == 0) { Msg("{red}No cards found in set {gold}" + uc(ARG[1]) + "{red}."); } } else { cards = book_cards(card.book,book_page(card.book)); } } else { cards = book_cards(card.book,book_page(card.book)); } i = 0; for(c)(cards) { price = (book_entry(card.book,c))[1]; myprice = (book_entry(card.book,c))[3]; newprice = undersell_price(c); if(newprice == 0.0) { } else if(newprice < minpct*myprice) { Msg("{orange}Not setting price for {white}" + canonical_name(c) + "{gold}: ${cyan}" + format("%3.2f", myprice) + "{gold} -> ${yellow}" + format("%3.2f",price)); } else { Msg("{gold}Setting price for {white}" + canonical_name(c) + "{gold}: ${cyan}" + format("%3.2f", myprice) + "{gold} -> ${cyan}" + format("%3.2f",newprice)); BookSetPrice(c, newprice); i = i + 1; # Pause every four cards, and turn off screen updates between pauses. if(i % 4 == 0) { refresh(1); sleep(1); refresh(0); } } } refresh(1); minpct = pop(); undersell_pct = pop(); newprice = pop(); myprice = pop(); price = pop(); i = pop(); c = pop(); cards = pop(); } HELP{"chat"}{"undersell"}=("[pct [set [{white}force{gold}]]]","undersell cards",NULL, "Set prices of cards on current page so that you are the lowest seller. {yellow}{white}, if given, is the percentage below the current lowest selling price at which to set the new price; it defaults to {cyan}0{white}. If {yellow}{white} is specified, all cards from that set are considered and the collection page is ignored. If only one argument is specified, it is assumed to be {yellow}{white}. Your current price will not be reduced by more than half unless {cyan}force{white} is given as the third argument.");