diff --git a/ai/control.lua b/ai/control.lua index b568e60..3051fa3 100644 --- a/ai/control.lua +++ b/ai/control.lua @@ -16,7 +16,7 @@ local potionInBattle = true local fightEncounter, caveFights = 0, 0 local encounters = 0 -local shouldFight, minExp +local canDie, shouldFight, minExp local shouldCatch, attackIdx local extraEncounter, maxEncounters local isYolo, battleYolo @@ -105,7 +105,14 @@ local controlFunctions = { } --- Combat +-- COMBAT + +function control.canDie(enabled) + if enabled == nil then + return canDie + end + canDie = enabled +end local function isNewFight() if (fightEncounter < encounters and memory.double("battle", "opponent_hp") == memory.double("battle", "opponent_max_hp")) then @@ -218,6 +225,7 @@ function control.wildEncounter() end function control.reset() + canDie = false oneHits = false shouldCatch = nil shouldFight = nil diff --git a/ai/strategies.lua b/ai/strategies.lua index 1c532dc..b5bec5e 100644 --- a/ai/strategies.lua +++ b/ai/strategies.lua @@ -356,17 +356,12 @@ end local function isPrepared(...) if (tries == 0) then tries = {} - for i,name in ipairs(arg) do - tries[i] = {name, inventory.count(name)} - end end - local item, found - for i,itemState in ipairs(tries) do - local name = itemState[1] - local count = itemState[2] - if (count > 0 and count == inventory.count(name)) then - local opp = itemState[3] - if (not opp or opp == memory.value("battle", "opponent_id")) then + for i,name in ipairs(arg) do + local currentCount = inventory.count(name) + if (currentCount > 0) then + local previousCount = tries[name] + if (previousCount == nil or currentCount == previousCount) then return false end end @@ -377,29 +372,26 @@ end local function prepare(...) if (tries == 0) then tries = {} - for i,name in ipairs(arg) do - tries[i] = {name, inventory.count(name)} - end end - local item, found - for i,itemState in ipairs(tries) do - local name = itemState[1] - local count = itemState[2] - if (count > 0 and count == inventory.count(name)) then - local opp = itemState[3] - found = true - if (not opp or opp == memory.value("battle", "opponent_id")) then - item = name - break - end + local item + for idx,name in ipairs(arg) do + local currentCount = inventory.count(name) + local needsItem = currentCount > 0 + local previousCount = tries[name] + if (previousCount == nil) then + tries[name] = currentCount + elseif (needsItem) then + needsItem = currentCount == previousCount + end + if (needsItem) then + item = name + break end end if (not item) then - if (not found) then - return true - end - battle.automate() - elseif (battle.isActive()) then + return true + end + if (battle.isActive()) then inventory.use(item, nil, true) else input.cancel() @@ -772,7 +764,7 @@ strategyFunctions = { end, allowDeath = function(data) - strategies.canDie = data.on + control.canDie(data.on) return true end, @@ -1112,7 +1104,7 @@ strategyFunctions = { superlative = " min stat" exclaim = "." end - nStatus = "Beat Brock with a"..superlative.." Nidoran"..exclaim.." "..nStatus..", caught at lv. "..(level4Nidoran and "4" or "3") + nStatus = "Beat Brock with a"..superlative.." Nidoran"..exclaim.." "..nStatus..", caught at level "..(level4Nidoran and "4" or "3").."." bridge.chat(nStatus) else tries = tries + 1 @@ -1214,7 +1206,7 @@ strategyFunctions = { catchFlierBackup = function() if (initialize()) then - strategies.canDie = true + control.canDie(true) end if (not control.canCatch()) then return true @@ -1223,7 +1215,7 @@ strategyFunctions = { if (battle.isActive()) then if (memory.double("battle", "our_hp") == 0) then if (pokemon.info("squirtle", "hp") == 0) then - strategies.canDie = false + control.canDie(false) elseif (utils.onPokemonSelect(memory.value("battle", "menu"))) then menu.select(pokemon.indexOf("squirtle"), true) else @@ -1264,7 +1256,7 @@ strategyFunctions = { startMtMoon = function() strategies.moonEncounters = 0 - strategies.canDie = nil + control.canDie(false) return true end, @@ -2163,16 +2155,48 @@ strategyFunctions = { silphRival = function() if (battle.isActive()) then - canProgress = true - if (prepare("x_accuracy", "x_speed")) then - local forced - if (pokemon.isOpponent("pidgeot")) then + if (initialize()) then + tempDir = combat.healthFor("RivalGyarados") + print("Gyarados "..tempDir) + canProgress = true + end + local gyaradosDamage = tempDir + + local forced + local readyToAttack = false + local opName = battle.opponent() + if opName == "gyarados" then + readyToAttack = true + local hp, red_hp = pokemon.index(0, "hp"), redHP() + if (hp > gyaradosDamage * 0.98 and hp - gyaradosDamage * 0.975 < red_hp) then --TODO + if (prepare("x_special")) then + forced = "ice_beam" + else + readyToAttack = false + end + elseif (isPrepared("x_special")) then + local canPotion + if (inventory.contains("potion") and hp + 20 > gyaradosDamage and hp + 20 - gyaradosDamage < red_hp) then + canPotion = "potion" + elseif (inventory.contains("super_potion") and hp + 50 > gyaradosDamage and hp + 50 - gyaradosDamage < red_hp) then + canPotion = "super_potion" + end + if (canPotion) then + inventory.use(canPotion, nil, true) + readyToAttack = false + end + end + elseif (prepare("x_accuracy", "x_speed")) then + if (opName == "pidgeot") then if (riskGiovanni or nidoSpecial < 45 or pokemon.info("nidoking", "hp") > 85) then forced = "thunderbolt" end - elseif (pokemon.isOpponent("alakazam", "growlithe")) then + elseif (opName == "alakazam" or opName == "growlithe") then forced = "earthquake" end + readyToAttack = true + end + if (readyToAttack) then battle.automate(forced) end elseif (canProgress) then @@ -2207,6 +2231,34 @@ strategyFunctions = { -- 9: SILPH CO. + healBeforeHypno = function() + local curr_hp, red_hp = pokemon.index(0, "hp"), redHP() + local healthUnderRedBar = red_hp - curr_hp + local yoloHP = combat.healthFor("HypnoHeadbutt") * 0.9 + local healTarget + local rareCandyCount = inventory.count("rare_candy") + local useRareCandy + if (healthUnderRedBar >= 0) then + healTarget = "HypnoHeadbutt" + if (healthUnderRedBar > 2) then + if (rareCandyCount > 2) then + useRareCandy = true + end + end + else + healTarget = "HypnoConfusion" + useRareCandy = rareCandyCount > 2 + end + if useRareCandy then + if (menu.pause()) then + inventory.use("rare_candy", nil, false) + end + return false + end + + return strategyFunctions.potion({hp=healTarget, yolo=yoloHP, close=true}) + end, + fightHypno = function() if (battle.isActive()) then local forced @@ -2228,7 +2280,7 @@ strategyFunctions = { end end, - fightKoga = function() + fightKoga = function() --TODO x-accuracy? if (battle.isActive()) then local forced if (pokemon.isOpponent("weezing")) then @@ -2237,7 +2289,7 @@ strategyFunctions = { return false end forced = "thunderbolt" - strategies.canDie = true + control.canDie(true) end battle.fight(forced) canProgress = true @@ -2663,10 +2715,13 @@ strategyFunctions = { end, lance = function() - if (tries == 0) then - tries = {{"x_special", inventory.count("x_special")}, {"x_speed", inventory.count("x_speed"), 89}} + local xItem + if (pokemon.isOpponent("dragonair")) then + xItem = "x_speed" + else + xItem = "x_special" end - return prepare() + return prepare(xItem) end, prepareForBlue = function() @@ -2773,7 +2828,6 @@ function strategies.softReset() initialized = false maxEtherSkip = false tempDir = nil - strategies.canDie = nil strategies.moonEncounters = nil tries = 0 deepRun = false diff --git a/data/opponents.lua b/data/opponents.lua index 312c230..edeefb6 100644 --- a/data/opponents.lua +++ b/data/opponents.lua @@ -1,6 +1,33 @@ local opponents = { - KogaHypno = { + RivalGyarados = { + type1 = "water", + type2 = "flying", + def = 71, + id = 22, + spec = 87, + hp = 126, + speed = 72, + level = 38, + att = 106, + moves = { + { + name = "Hydro-Pump", + accuracy = 80, + power = 120, + id = 56, + special = true, + max_pp = 5, + move_type = "water", + } + }, + boost = { + stat = "spec", + mp = 1.5 + } + }, + + HypnoHeadbutt = { type1 = "psychic", type2 = "psychic", def = 58, @@ -12,8 +39,31 @@ local opponents = { att = 60, moves = { { + name = "Headbutt", accuracy = 100, + power = 70, + id = 29, + special = false, + max_pp = 15, + move_type = "normal", + } + } + }, + + HypnoConfusion = { + type1 = "psychic", + type2 = "psychic", + def = 58, + id = 129, + spec = 88, + hp = 107, + speed = 56, + level = 34, + att = 60, + moves = { + { name = "Confusion", + accuracy = 100, power = 50, id = 93, special = true, @@ -35,8 +85,8 @@ local opponents = { att = 90, moves = { { - accuracy = 100, name = "Self-Destruct", + accuracy = 100, power = 260, id = 120, special = false, @@ -58,9 +108,9 @@ local opponents = { att = 89, moves = { { + name = "Stomp", move_type = "normal", accuracy = 100, - name = "Stomp", power = 65, id = 23, special = false, @@ -82,8 +132,8 @@ local opponents = { att = 90, moves = { { - accuracy = 100, name = "Aurora-Beam", + accuracy = 100, power = 65, id = 62, special = true, @@ -109,8 +159,8 @@ local opponents = { att = 160, moves = { { - accuracy = 80, name = "Hydro-Pump", + accuracy = 80, power = 120, id = 56, special = true, @@ -136,8 +186,8 @@ local opponents = { att = 113, moves = { { - accuracy = 100, name = "Wing-Attack", + accuracy = 100, power = 35, id = 17, special = false, @@ -159,8 +209,8 @@ local opponents = { att = 113, moves = { { - accuracy = 90, name = "Sky-Attack", + accuracy = 90, power = 140, id = 143, special = false, @@ -172,4 +222,4 @@ local opponents = { } -return opponents \ No newline at end of file +return opponents diff --git a/data/paths.lua b/data/paths.lua index 7a394bf..5fb972d 100644 --- a/data/paths.lua +++ b/data/paths.lua @@ -334,8 +334,7 @@ local paths = { -- To Koga {7, {19,28}, {s="a",a="Koga's Gym"}, {5,28}, {5,27}}, -- Koga - -- TODO save turn frames? - {157, {4,17}, {9,17}, {9,9}, {7,9}, {s="interact",dir="Up"}, {9,9}, {9,1}, {1,1}, {1,2}, {s="potion",hp="KogaHypno",yolo=18,chain=true}, {s="earthquakeElixer",min=2,close=true}, {1,3}, {2,3}, {2,5}, {1,5}, {c="potion",b=false}, {1,7}, {s="fightHypno"}, {1,9}, {2,9}, {s="earthquakeElixer",min=4}, {4,9}, {s="interact",dir="Down"}, {s="fightKoga"}, {s="split"}, {1,9}, {1,5}, {2,5}, {2,3}, {1,3}, {1,1}, {9,1}, {9,16}, {5,16}, {5,18}}, + {157, {4,17}, {9,17}, {9,9}, {7,9}, {s="interact",dir="Up"}, {9,9}, {9,1}, {1,1}, {1,2}, {s="earthquakeElixer",min=2,chain=true}, {s="healBeforeHypno"}, {1,3}, {2,3}, {2,5}, {1,5}, {c="potion",b=false}, {1,7}, {s="fightHypno"}, {1,9}, {2,9}, {s="earthquakeElixer",min=4}, {4,9}, {s="interact",dir="Down"}, {s="fightKoga"}, {s="split"}, {1,9}, {1,5}, {2,5}, {2,3}, {1,3}, {1,1}, {9,1}, {9,16}, {5,16}, {5,18}}, -- 12: KOGA diff --git a/main.lua b/main.lua index e0124d5..55b80f9 100644 --- a/main.lua +++ b/main.lua @@ -193,7 +193,7 @@ while true do -- bridge.hp(currentHP, pokemon.index(0, "max_hp")) -- lastHP = currentHP -- end - if (currentHP == 0 and not strategies.canDie and pokemon.index(0) > 0) then + if (currentHP == 0 and not control.canDie() and pokemon.index(0) > 0) then strategies.death(currentMap) elseif (walk.strategy) then if (strategies.execute(walk.strategy)) then diff --git a/storage/pokemon.lua b/storage/pokemon.lua index 1764253..cdac975 100644 --- a/storage/pokemon.lua +++ b/storage/pokemon.lua @@ -26,6 +26,7 @@ local pokeIDs = { jinx = 72, meowth = 77, pikachu = 84, + dragonair = 89, zubat = 107, ekans = 108, paras = 109, diff --git a/util/bridge.lua b/util/bridge.lua index 641a7fc..60ffa5b 100644 --- a/util/bridge.lua +++ b/util/bridge.lua @@ -119,10 +119,7 @@ function bridge.liveSplit() timeStopped = false end -function bridge.split(encounters, finished) - if (encounters) then - -- database.split(utils.igt(), encounters) - end +function bridge.split(finished) if (finished) then timeStopped = true end