boolean vprint(string message, string color, int level) {
if (level == 0) abort(message);
# if (to_int(vars["verbosity"]) >= abs(level)) print(message,color);
if (3 >= abs(level)) print(message,color);
return (level > 0);
}
boolean vprint(string message, int level) { if (level > 0) return vprint(message,"black",level); return vprint(message,"red",level); }
boolean send_gift(string to, string message, int meat, int[item] goodies, string insidenote) {
// parse items into query string
string itemstring = "";
int j = 0;
int[item] extra;
foreach i in goodies {
if (is_tradeable(i) || is_giftable(i)) {
j = j+1;
if (j < 4)
itemstring = itemstring + "&howmany"+j+"="+goodies[i]+"&whichitem"+j+"="+to_int(i);
else extra[i] = goodies[i];
}
}
int shipping = 200;
int pnum = 3;
if (count(goodies) < 3) {
shipping = 50*max(1,count(goodies));
pnum = max(1,count(goodies));
}
if (my_meat() < meat+shipping) return vprint("Not enough meat to send the package.",-2);
// send gift
string url = visit_url("town_sendgift.php?pwd=&towho="+to+"¬e="+message+"&insidenote="+insidenote+"&whichpackage="+pnum+"&fromwhere=0&sendmeat="+meat+"&action=Yep."+itemstring);
if (!contains_text(url,"Package sent.")) return vprint("The message didn't send for some reason.",-2);
if (count(extra) > 0) return send_gift(to,message,0,extra,insidenote);
return true;
}
boolean send_gift(string to, string message, int meat, int[item] goodies) { return send_gift(to,message,meat,goodies,""); }
boolean kmail(string to, string message, int meat, int[item] goodies, string insidenote) {
if (meat > my_meat()) return vprint("You don't have "+meat+" meat.",-2);
// parse items into query strings
string itemstring = "";
int j = 0;
string[int] itemstrings;
foreach i in goodies {
if (is_tradeable(i) || is_giftable(i)) {
j = j+1;
itemstring = itemstring + "&howmany"+j+"="+goodies[i]+"&whichitem"+j+"="+to_int(i);
if (j > 10) {
itemstrings[count(itemstrings)] = itemstring;
itemstring = '';
j = 0;
}
}
}
if (itemstring != "") itemstrings[count(itemstrings)] = itemstring;
if (count(itemstrings) == 0) itemstrings[0] = "";
else vprint(count(goodies)+" item types split into "+count(itemstrings)+" separate kmails.",5);
// send message(s)
foreach q in itemstrings {
string url = visit_url("sendmessage.php?pwd=&action=send&towho="+to+"&message="+message+"&savecopy=on&sendmeat="+meat+itemstrings[q]);
if (contains_text(url,"That player cannot receive Meat or items"))
return (vprint("That player cannot receive stuff, sending gift instead...",4) && send_gift(to, message, meat, goodies, insidenote));
if (!contains_text(url,"Message sent.")) return vprint("The message didn't send for some reason.",-2);
}
return true;
}