import ; boolean MIXBOT_REFRESHED = false; string MIX_MESSAGE = "Thank you for choosing FREE BEER as your bartender today!"; string NOMIX_MESSAGE = ""; string [string, item, item] RECIPES; string as_list(int[item] stuff) { string s = ""; foreach thing in stuff { if (s != "") { s += ", "; } s += stuff[thing] + " " + thing; } return s; } int[item] diff(int[item] before, int[item] after) { int[item] delta; foreach it in before { if (before[it] != after[it]) { delta[it] = after[it] - before[it]; } } foreach it in after { if (before[it] != after[it]) { delta[it] = after[it] - before[it]; } } return delta; } int[item] sum(int[item] first, int[item] second) { int[item] delta; foreach it in first { if (first[it] != 0) { delta[it] += first[it]; } } foreach it in second { if (second[it] != 0) { delta[it] += second[it]; } } return delta; } void parse_recipes() { item [string, string, item] r; file_to_map("concoctions.txt", r); foreach target, str, src1, src2 in r { if (str == "MIX" || str == "ACOCK" || str == "SCOCK") { RECIPES["cocktail", src1, src2] = target; } } } int[item] mix(int[item] stuff) { int [item] before = get_inventory(); foreach method in RECIPES { foreach it1 in stuff { if (stuff[it1] == 0) { continue; } foreach it2 in stuff { if (stuff[it2] == 0) { continue; } if (RECIPES[method, it1] contains it2) { print(method + " " + it1 + " + " + it2 + " = " + RECIPES[method, it1, it2]); int qty = min(stuff[it1], stuff[it2]); craft(method, qty, it1, it2); stuff[it1] -= qty; stuff[it2] -= qty; before[it1] -= qty; before[it2] -= qty; } } } } return sum(diff(before, get_inventory()), stuff); } int [item] fullmix(int[item] stuff) { int[item] yield = mix(stuff); int[item] oldYield; while (count(diff(oldYield, yield)) > 0) { oldYield = yield; yield = mix(yield); } return yield; } boolean mixbot_process(kmessage msg) { print("Got " + as_list(msg.items) + " from " + msg.fromname + "."); int[item] yield = (msg.message.contains_text("fullmix")) ? fullmix(msg.items) : mix(msg.items); print("Mixed " + as_list(yield) + "."); if (count(yield) > 0) { kmail(msg.fromname, MIX_MESSAGE, 0, yield); return true; } return false; } void mixbot() { MIXBOT_REFRESHED = false; load_kmail("mixbot"); cli_execute("refresh inv"); process_kmail("mixbot_process"); } parse_recipes(); void main(string sender, string message, string channel){ if (channel == "Events") { mixbot(); } // less than 3 minutes remaining if (86400000 - gametime_to_int() < 180000) { waitq(900); // sleep 15 minutes cli_execute("login free beer"); } }