diff --git a/disenchanter.rb b/disenchanter.rb index a4babbd..5c76479 100644 --- a/disenchanter.rb +++ b/disenchanter.rb @@ -13,15 +13,12 @@ def run set_globals current_version = "v1.4.0" - sep = - "____________________________________________________________".light_black - puts "Hi! :)".light_green puts "Running Disenchanter #{current_version}".light_blue puts "You can exit this script at any point by pressing ".light_blue + "[CTRL + C]".light_white + ".".light_blue check_update(current_version) - puts sep + puts $sep summoner = get_current_summoner if summoner["displayName"].nil? || summoner["displayName"].empty? @@ -30,24 +27,22 @@ def run exit 1 end puts "\nYou're logged in as #{summoner["displayName"]}.".light_blue - puts sep + puts $sep puts "\nFeel free to try the options, no actions will be taken until you confirm a banner like this:".light_blue puts "CONFIRM: Perform this action? [y|n]".light_magenta - puts sep + puts $sep done = false things_todo = { - "1" => "Event Tokens", - "2" => "Mythic Essence", - "3" => "Key Fragments", - "4" => "Capsules", - "5" => "Emotes", - "6" => "Ward Skin Shards", - "7" => "Skin Shards", - "8" => "Eternals", - "9" => "Champion Shards", - "10" => "Upgrade Mastery Tokens", - "s" => "Show Global Stats", + "1" => "Materials", + "2" => "Champions", + "3" => "Skins", + #"4" => "Tacticians", + "5" => "Eternals", + "6" => "Emotes", + "7" => "Ward Skins", + "8" => "Icons", + "s" => "Open Disenchanter Global Stats", "r" => "Open GitHub repository", "x" => "Exit" } @@ -66,54 +61,50 @@ def run todo = user_input_check( - "\nWhat would you like to do? (Hint: do 1-4 first so you don't miss anything)\n\n".light_cyan + + "\nWhat would you like to do? (Hint: do Materials first so you don't miss anything!)\n\n".light_cyan + todo_string + "Option: ", - %w[1 2 3 4 5 6 7 8 9 10 s r x], + things_todo.keys, "", "" ) things_done << todo - puts sep + puts $sep puts puts "Option chosen: #{things_todo[todo]}".light_white case todo when "1" - handle_event_tokens + handle_materials when "2" - handle_mythic_essence + handle_champions when "3" - handle_key_fragments - when "4" - handle_capsules + handle_skins + # when "4" + # handle_tacticians when "5" - handle_emotes + handle_eternals when "6" - handle_ward_skin_shards + handle_emotes when "7" - handle_skin_shards + handle_ward_skins when "8" - handle_eternals - when "9" - handle_champion_shards - when "10" - handle_mastery_tokens + handle_icons when "s" - handle_open_stats + open_stats when "r" - handle_open_github + open_github when "x" done = true end - puts sep + puts $sep end puts "That's it!".light_green if $actions > 0 puts "We saved you about #{$actions * 3} seconds of waiting for animations to finish.".light_green - puts sep + puts $sep end handle_stat_submission puts "See you next time :)".light_green @@ -144,6 +135,9 @@ def set_globals end $host = "https://127.0.0.1:#{$port}" + $sep = + "____________________________________________________________".light_black + $actions = 0 $s_disenchanted = 0 $s_opened = 0 @@ -331,6 +325,166 @@ def handle_exception(exception, name) puts "Skipping this step...".yellow end +def handle_materials + done = false + things_todo = { + "1" => "Mythic Essence", + "2" => "Event Tokens", + "3" => "Key Fragments", + "4" => "Capsules", + "5" => "Mastery Tokens", + "x" => "Back to main menu" + } + things_done = [] + + until done + todo_string = "" + things_todo.each do |k, v| + todo_string += "[#{k}] ".light_white + unless things_done.include? k + todo_string += "#{v}\n".light_cyan + else + todo_string += "#{v} (done)\n".light_green + end + end + + todo = + user_input_check( + "\nWhat would you like to do?\n\n".light_cyan + todo_string + + "Option: ", + things_todo.keys, + "", + "" + ) + things_done << todo + + puts $sep + puts + + puts "Option chosen: #{things_todo[todo]}".light_white + + case todo + when "1" + handle_mythic_essence + when "2" + handle_event_tokens + when "3" + handle_key_fragments + when "4" + handle_capsules + when "5" + handle_mastery_tokens + when "x" + done = true + end + puts $sep + end +end + +def handle_mythic_essence + begin + player_loot = get_player_loot + mythic_loot_id = "CURRENCY_mythic" + + loot_essence = player_loot.select { |l| l["lootId"] == mythic_loot_id } + loot_essence = loot_essence[0] + if !loot_essence.nil? && loot_essence["count"] > 0 + puts "Found #{loot_essence["count"]} Mythic Essence.".light_blue + craft_mythic_type_names = [ + "Blue Essence", + "Orange Essence", + "Random Skin Shards" + ] + + craft_mythic_type = + user_input_check( + "Okay, what would you like to craft?\n" + + "[1] #{craft_mythic_type_names[0]}\n" + + "[2] #{craft_mythic_type_names[1]}\n" + + "[3] #{craft_mythic_type_names[2]}\n" + "[x] Cancel\n", + %w[1 2 3 x], + "[1|2|3|x]" + ) + + unless craft_mythic_type == "x" + case craft_mythic_type + # Blue Essence, Orange Essence, Random Skin Shard + when "1" + recipe_target = "CURRENCY_champion" + when "2" + recipe_target = "CURRENCY_cosmetic" + when "3" + recipe_target = "CHEST_291" + end + + recipes = get_recipes_for_item(mythic_loot_id) + recipes = + recipes.select { |r| r["outputs"][0]["lootName"] == recipe_target } + unless recipes.length == 0 + recipe = recipes[0] + + puts "Recipe found: #{recipe["contextMenuText"]} for #{recipe["slots"][0]["quantity"]} Mythic Essence".light_blue + + craft_mythic_amount = + user_input_check( + "Alright, how much Mythic Essence should we use to craft #{craft_mythic_type_names[craft_mythic_type.to_i - 1]}?", + (1..loot_essence["count"].to_i) + .to_a + .append("all") + .map! { |n| n.to_s }, + "[1..#{loot_essence["count"]}|all]" + ) + + if craft_mythic_amount == "all" + craft_mythic_amount = loot_essence["count"] + end + craft_mythic_amount = craft_mythic_amount.to_i + + could_craft = + (craft_mythic_amount / recipe["slots"][0]["quantity"]).floor + unless could_craft < 1 + if ($ans_y).include? user_input_check( + "Craft #{could_craft * recipe["outputs"][0]["quantity"]} " + + "#{craft_mythic_type_names[craft_mythic_type.to_i - 1]} from " + + "#{(craft_mythic_amount / recipe["slots"][0]["quantity"]).floor * recipe["slots"][0]["quantity"]} Mythic Essence?", + $ans_yn, + $ans_yn_d, + "confirm" + ) + case craft_mythic_type + when "1" + $s_blue_essence += + could_craft * recipe["outputs"][0]["quantity"] + when "2" + $s_orange_essence += + could_craft * recipe["outputs"][0]["quantity"] + end + $s_crafted += could_craft + + post_recipe( + recipe["recipeName"], + mythic_loot_id, + (craft_mythic_amount / recipe["slots"][0]["quantity"]).floor + ) + puts "Done!".green + end + else + puts "Not enough Mythic Essence for that recipe.".yellow + end + else + puts "Recipes for #{craft_mythic_type_names[craft_mythic_type.to_i - 1]} seem to be unavailable.".yellow + end + else + puts "Mythic crafting canceled.".yellow + end + else + puts "Found no Mythic Essence to use.".yellow + end + rescue => exception + handle_exception(exception, "Mythic Essence") + end +end + def handle_event_tokens begin player_loot = get_player_loot @@ -370,11 +524,14 @@ def handle_event_tokens recipe_targets = %w[CHEST_187] end + token_recipes = token_recipes.select { |r| !r["outputs"][0].nil? } + token_recipes = token_recipes.select do |r| recipe_targets.include? r["outputs"][0]["lootName"] end - token_recipes.sort_by { |r| r["slots"][0]["quantity"] }.reverse! + token_recipes = + token_recipes.sort_by { |r| r["slots"][0]["quantity"] }.reverse! token_recipes.each do |r| puts "Recipe found: #{r["contextMenuText"]} for #{r["slots"][0]["quantity"]} Tokens".light_black @@ -454,110 +611,6 @@ def handle_event_tokens end end -def handle_mythic_essence - begin - player_loot = get_player_loot - mythic_loot_id = "CURRENCY_mythic" - - loot_essence = player_loot.select { |l| l["lootId"] == mythic_loot_id } - loot_essence = loot_essence[0] - if !loot_essence.nil? && loot_essence["count"] > 0 - puts "Found #{loot_essence["count"]} Mythic Essence.".light_blue - craft_mythic_type_names = [ - "Blue Essence", - "Orange Essence", - "Random Skin Shards" - ] - - craft_mythic_type = - user_input_check( - "Okay, what would you like to craft?\n" + - "[1] #{craft_mythic_type_names[0]}\n" + - "[2] #{craft_mythic_type_names[1]}\n" + - "[3] #{craft_mythic_type_names[2]}\n" + "[x] Cancel\n", - %w[1 2 3 x], - "[1|2|3|x]" - ) - - unless craft_mythic_type == "x" - case craft_mythic_type - # Blue Essence, Orange Essence, Random Skin Shard - when "1" - recipe_target = "CURRENCY_champion" - when "2" - recipe_target = "CURRENCY_cosmetic" - when "3" - recipe_target = "CHEST_291" - end - - recipes = get_recipes_for_item(mythic_loot_id) - recipes = - recipes.select { |r| r["outputs"][0]["lootName"] == recipe_target } - unless recipes.length == 0 - recipe = recipes[0] - - puts "Recipe found: #{recipe["contextMenuText"]} for #{recipe["slots"][0]["quantity"]} Mythic Essence".light_blue - - craft_mythic_amount = - user_input_check( - "Alright, how much Mythic Essence should we use to craft #{craft_mythic_type_names[craft_mythic_type.to_i - 1]}?", - (1..loot_essence["count"].to_i) - .to_a - .append("all") - .map! { |n| n.to_s }, - "[1..#{loot_essence["count"]}|all]" - ) - - if craft_mythic_amount == "all" - craft_mythic_amount = loot_essence["count"] - end - craft_mythic_amount = craft_mythic_amount.to_i - - could_craft = - (craft_mythic_amount / recipe["slots"][0]["quantity"]).floor - unless could_craft < 1 - if ($ans_y).include? user_input_check( - "Craft #{could_craft * recipe["outputs"][0]["quantity"]} " + - "#{craft_mythic_type_names[craft_mythic_type.to_i - 1]} from " + - "#{(craft_mythic_amount / recipe["slots"][0]["quantity"]).floor * recipe["slots"][0]["quantity"]} Mythic Essence?", - $ans_yn, - $ans_yn_d, - "confirm" - ) - case craft_mythic_type - when "1" - $s_blue_essence += - could_craft * recipe["outputs"][0]["quantity"] - when "2" - $s_orange_essence += - could_craft * recipe["outputs"][0]["quantity"] - end - $s_crafted += could_craft - - post_recipe( - recipe["recipeName"], - mythic_loot_id, - (craft_mythic_amount / recipe["slots"][0]["quantity"]).floor - ) - puts "Done!".green - end - else - puts "Not enough Mythic Essence for that recipe.".yellow - end - else - puts "Recipes for #{craft_mythic_type_names[craft_mythic_type.to_i - 1]} seem to be unavailable.".yellow - end - else - puts "Mythic crafting canceled.".yellow - end - else - puts "Found no Mythic Essence to use.".yellow - end - rescue => exception - handle_exception(exception, "Mythic Essence") - end -end - def handle_key_fragments begin player_loot = get_player_loot @@ -635,6 +688,99 @@ def handle_capsules end end +def handle_mastery_tokens + begin + player_loot = get_player_loot + loot_shards = player_loot.select { |l| l["type"] == "CHAMPION_RENTAL" } + + recipes6 = get_recipes_for_item("CHAMPION_TOKEN_6-1") + recipes7 = get_recipes_for_item("CHAMPION_TOKEN_7-1") + recipe6_cost = + recipes6.select do |r| + r["recipeName"] == "CHAMPION_TOKEN_6_redeem_withessence" + end + recipe6_cost = recipe6_cost[0]["slots"][1]["quantity"] + recipe7_cost = + recipes7.select do |r| + r["recipeName"] == "CHAMPION_TOKEN_7_redeem_withessence" + end + recipe7_cost = recipe7_cost[0]["slots"][1]["quantity"] + + loot_mastery_tokens = + player_loot.select do |l| + (l["lootName"] == "CHAMPION_TOKEN_6" && l["count"] == 2) || + (l["lootName"] == "CHAMPION_TOKEN_7" && l["count"] == 3) + end + + if loot_mastery_tokens.count > 0 + loot_mastery_tokens = + loot_mastery_tokens.sort_by { |l| [l["lootName"], l["itemDesc"]] } + puts "We'd upgrade the following champions:\n".light_blue + needed_shards = 0 + needed_essence = 0 + + loot_mastery_tokens.each do |t| + ref_shard = + loot_shards.select { |l| t["refId"] == l["storeItemId"].to_s } + + print pad(t["itemDesc"], 15, false).light_white + print " to Mastery Level ".light_black + print "#{(t["lootName"])[-1]}".light_white + print " using ".light_black + if !ref_shard.empty? && ref_shard[0]["count"] > 0 + print "a champion shard.".green + needed_shards += 1 + t["upgrade_type"] = "shard" + else + recipe_cost = (t["lootName"])[-1] == "6" ? recipe6_cost : recipe7_cost + print "#{recipe_cost} Blue Essence.".yellow + needed_essence += recipe_cost + t["upgrade_type"] = "essence" + end + puts + end + puts + + owned_essence = + player_loot.select { |l| l["lootId"] == "CURRENCY_champion" } + owned_essence = owned_essence[0]["count"] + if (owned_essence > needed_essence) + if $ans_y.include? user_input_check( + "Upgrade #{loot_mastery_tokens.count} champions using #{needed_shards} Shards and #{needed_essence} Blue Essence?", + $ans_yn, + $ans_yn_d, + "confirm" + ) + loot_mastery_tokens.each do |t| + $s_redeemed += 1 + target_level = (t["lootName"])[-1] + case t["upgrade_type"] + when "shard" + post_recipe( + "CHAMPION_TOKEN_#{target_level}_redeem_withshard", + [t["lootId"], "CHAMPION_RENTAL_#{t["refId"]}"], + 1 + ) + when "essence" + post_recipe( + "CHAMPION_TOKEN_#{target_level}_redeem_withessence", + [t["lootId"], "CURRENCY_champion"], + 1 + ) + end + end + end + else + puts "You're missing #{needed_essence - owned_essence} Blue Essence needed to proceed. Skipping...".yellow + end + else + puts "Found no upgradable Mastery Tokens.".yellow + end + rescue => exception + handle_exception(exception, "token upgrades") + end +end + def handle_generic(name, type, recipe) begin player_loot = get_player_loot @@ -720,11 +866,19 @@ def handle_generic(name, type, recipe) end end +def handle_skins + handle_generic("Skin Shards", "SKIN_RENTAL", "SKIN_RENTAL_DISENCHANT") +end + +def handle_eternals + handle_generic("Eternals", "STATSTONE_SHARD", "STATSTONE_SHARD_DISENCHANT") +end + def handle_emotes handle_generic("Emotes", "EMOTE", "EMOTE_disenchant") end -def handle_ward_skin_shards +def handle_ward_skins handle_generic( "Ward Skin Shards", "WARDSKIN_RENTAL", @@ -732,15 +886,11 @@ def handle_ward_skin_shards ) end -def handle_skin_shards - handle_generic("Skin Shards", "SKIN_RENTAL", "SKIN_RENTAL_DISENCHANT") +def handle_icons + handle_generic("Icons", "SUMMONERICON", "SUMMONERICON_disenchant") end -def handle_eternals - handle_generic("Eternals", "STATSTONE_SHARD", "STATSTONE_SHARD_DISENCHANT") -end - -def handle_champion_shards +def handle_champions begin player_loot = get_player_loot @@ -761,7 +911,7 @@ def handle_champion_shards $ans_yn, $ans_yn_d ) - loot_shards = handle_champion_shards_owned(loot_shards) + loot_shards = handle_champions_owned(loot_shards) end else puts "Found no shards of champions you don't own yet.".light_blue @@ -789,22 +939,22 @@ def handle_champion_shards user_input_check( "Okay, which option would you like to go by?\n" + modes_string + "Option: ", - %w[1 2 3 4 5 x], + disenchant_modes.keys, "[1|2|3|4|5|x]", "" ) unless disenchant_shards_mode == "x" case disenchant_shards_mode when "1" - # done + # no filtering needed -> done when "2" - loot_shards = handle_champion_shards_tokens(player_loot, loot_shards) + loot_shards = handle_champions_tokens(player_loot, loot_shards) when "3" - loot_shards = handle_champion_shards_mastery(loot_shards) + loot_shards = handle_champions_mastery(loot_shards) when "4" - loot_shards = handle_champion_shards_mastery(loot_shards, true) + loot_shards = handle_champions_mastery(loot_shards, true) when "5" - loot_shards = handle_champion_shards_collection(loot_shards) + loot_shards = handle_champions_collection(loot_shards) end loot_shards = loot_shards.select { |l| l["count"] > 0 } @@ -828,7 +978,7 @@ def handle_champion_shards end end - loot_shards = handle_champion_shards_exceptions(loot_shards) + loot_shards = handle_champions_exceptions(loot_shards) total_be_value = 0 loot_shards.each do |l| @@ -874,7 +1024,7 @@ def handle_champion_shards end end -def handle_champion_shards_owned(loot_shards) +def handle_champions_owned(loot_shards) begin loot_shards.each do |l| unless l["redeemableStatus"] == "ALREADY_OWNED" @@ -888,7 +1038,7 @@ def handle_champion_shards_owned(loot_shards) end end -def handle_champion_shards_tokens(player_loot, loot_shards) +def handle_champions_tokens(player_loot, loot_shards) begin token6_champion_ids = [] token7_champion_ids = [] @@ -922,7 +1072,7 @@ def handle_champion_shards_tokens(player_loot, loot_shards) end end -def handle_champion_shards_mastery(loot_shards, keep_all = false) +def handle_champions_mastery(loot_shards, keep_all = false) begin summoner = get_current_summoner player_mastery = get_champion_mastery(summoner["summonerId"]) @@ -974,7 +1124,7 @@ def handle_champion_shards_mastery(loot_shards, keep_all = false) end end -def handle_champion_shards_collection(loot_shards) +def handle_champions_collection(loot_shards) begin loot_shards.each do |l| l["count"] -= 1 @@ -987,7 +1137,7 @@ def handle_champion_shards_collection(loot_shards) end end -def handle_champion_shards_exceptions(loot_shards) +def handle_champions_exceptions(loot_shards) begin exclusions_str = "" exclusions_done = false @@ -1003,7 +1153,7 @@ def handle_champion_shards_exceptions(loot_shards) "," + ask( "Okay, which champions? ".light_cyan + - "(case-sensitive, comma-separated)".light_white + + "(case-sensitive, comma-$separated)".light_white + ": ".light_cyan ) @@ -1027,105 +1177,12 @@ def handle_champion_shards_exceptions(loot_shards) end end -def handle_mastery_tokens - begin - player_loot = get_player_loot - loot_shards = player_loot.select { |l| l["type"] == "CHAMPION_RENTAL" } - - recipes6 = get_recipes_for_item("CHAMPION_TOKEN_6-1") - recipes7 = get_recipes_for_item("CHAMPION_TOKEN_7-1") - recipe6_cost = - recipes6.select do |r| - r["recipeName"] == "CHAMPION_TOKEN_6_redeem_withessence" - end - recipe6_cost = recipe6_cost[0]["slots"][1]["quantity"] - recipe7_cost = - recipes7.select do |r| - r["recipeName"] == "CHAMPION_TOKEN_7_redeem_withessence" - end - recipe7_cost = recipe7_cost[0]["slots"][1]["quantity"] - - loot_mastery_tokens = - player_loot.select do |l| - (l["lootName"] == "CHAMPION_TOKEN_6" && l["count"] == 2) || - (l["lootName"] == "CHAMPION_TOKEN_7" && l["count"] == 3) - end - - if loot_mastery_tokens.count > 0 - loot_mastery_tokens = - loot_mastery_tokens.sort_by { |l| [l["lootName"], l["itemDesc"]] } - puts "We'd upgrade the following champions:\n".light_blue - needed_shards = 0 - needed_essence = 0 - - loot_mastery_tokens.each do |t| - ref_shard = - loot_shards.select { |l| t["refId"] == l["storeItemId"].to_s } - - print pad(t["itemDesc"], 15, false).light_white - print " to Mastery Level ".light_black - print "#{(t["lootName"])[-1]}".light_white - print " using ".light_black - if !ref_shard.empty? && ref_shard[0]["count"] > 0 - print "a champion shard.".green - needed_shards += 1 - t["upgrade_type"] = "shard" - else - recipe_cost = (t["lootName"])[-1] == "6" ? recipe6_cost : recipe7_cost - print "#{recipe_cost} Blue Essence.".yellow - needed_essence += recipe_cost - t["upgrade_type"] = "essence" - end - puts - end - puts - - owned_essence = - player_loot.select { |l| l["lootId"] == "CURRENCY_champion" } - owned_essence = owned_essence[0]["count"] - if (owned_essence > needed_essence) - if $ans_y.include? user_input_check( - "Upgrade #{loot_mastery_tokens.count} champions using #{needed_shards} Shards and #{needed_essence} Blue Essence?", - $ans_yn, - $ans_yn_d, - "confirm" - ) - loot_mastery_tokens.each do |t| - $s_redeemed += 1 - target_level = (t["lootName"])[-1] - case t["upgrade_type"] - when "shard" - post_recipe( - "CHAMPION_TOKEN_#{target_level}_redeem_withshard", - [t["lootId"], "CHAMPION_RENTAL_#{t["refId"]}"], - 1 - ) - when "essence" - post_recipe( - "CHAMPION_TOKEN_#{target_level}_redeem_withessence", - [t["lootId"], "CURRENCY_champion"], - 1 - ) - end - end - end - else - puts "You're missing #{needed_essence - owned_essence} Blue Essence needed to proceed. Skipping...".yellow - end - else - puts "Found no upgradable Mastery Tokens.".yellow - end - rescue => exception - handle_exception(exception, "token upgrades") - end -end - -def handle_open_github +def open_github puts "Opening GitHub repository at https://github.com/marvinscham/disenchanter/ in your browser...".light_blue Launchy.open("https://github.com/marvinscham/disenchanter/") end -def handle_open_stats +def open_stats puts "Opening Global Stats at https://github.com/marvinscham/disenchanter/wiki/Stats in your browser...".light_blue Launchy.open("https://github.com/marvinscham/disenchanter/wiki/Stats") end