-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPotatosDen.lua
247 lines (224 loc) · 7.68 KB
/
PotatosDen.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
name = "Catch pokemon from a list at Dragon den"
author = "PotatoBlood"
description = [[Catch pokemon from a list at Dragons Den, uses leftovers, teamsorting and pathfinding]]
catchList = {"Electabuzz", "Charmander", "Abra", "Dratini", "Dragonair", "Snorlax"}
-- Max level - set to 100 to stop at 100, 101 to keep going
maxPokeLevel = 101
-- Please make sure that you have CUT AND SURF
--------------------------------------------------------------
-- Only touch the code below if you know what you are doing --
--------------------------------------------------------------
local sys = require "Libs/syslib"
local game = require "Libs/gamelib"
local PathFinder = require "Pathfinder/Maps_Pathfind"
function leftovers()
ItemName = "Leftovers"
local PokemonNeedLeftovers = game.getFirstUsablePokemon()
local PokemonWithLeftovers = game.getPokemonIdWithItem(ItemName)
if getTeamSize() > 0 then
if PokemonWithLeftovers > 0 then
if PokemonNeedLeftovers == PokemonWithLeftovers then
return false -- now leftovers is on rightpokemon
else
takeItemFromPokemon(PokemonWithLeftovers)
return true
end
else
if hasItem(ItemName) and PokemonNeedLeftovers ~= 0 then
giveItemToPokemon(ItemName,PokemonNeedLeftovers)
return true
else
return false-- don't have leftovers in bag and is not on pokemons
end
end
else
return false
end
end
function advanceSorting()
local pokemonsUsable = game.getTotalUsablePokemonCount()
for pokemonId=1, pokemonsUsable, 1 do
if not isPokemonUsable(pokemonId) then --Move it at bottom of the Team
for pokemonId_ = pokemonsUsable + 1, getTeamSize(), 1 do
if isPokemonUsable(pokemonId_) then
swapPokemon(pokemonId, pokemonId_)
return true
end
end
end
end
if not isTeamRangeSortedByLevelAscending(1, pokemonsUsable) then --Sort the team without not usable pokemons
return sortTeamRangeByLevelAscending(1, pokemonsUsable)
end
return false
end
function onStart()
pcVisits = 0
shinyCounter = 0
wildCounter = 0
catchCounter = 0
dragonairCounter = 0
log("Start botting.")
end
function onPause()
log("Shinies Caught: " .. shinyCounter)
log("Pokemons encountered: " .. wildCounter)
log("Pokemons caught: " .. catchCounter)
log("Dragonairs caught: " .. dragonairCounter)
log("You have visited the PokeCenter ".. pcVisits .." times.")
log("*********************************************************************************************")
end
function onDestination()
if getMapName() == "Pokecenter Blackthorn" or getMapName() == "Blackthorn City" or getMapName() == "Dragons Den Entrance" or getMapName() == "Dragons Den" or
getMapName() == "Blackthorn City Pokemart" then
return true
else
return false
end
end
function onPathAction()
if advanceSorting() then
return true
end
if leftovers() then
return true
end
if not isMounted() and hasItem("Bicycle") and isOutside() and not isSurfing() then
useItem ("Bicycle")
log ("Getting on bicycle")
elseif not onDestination() then
PathFinder.MoveTo("Blackthorn City")
else
farmDragonsDen()
end
end
function onBattleAction()
if isWildBattle() and isOpponentShiny() then
if useItem("Ultra Ball") or useItem("Great Ball") or useItem("Pokeball") then
return true
end
elseif isWildBattle() and not isAlreadyCaught() then
if useItem("Ultra Ball") or useItem("Great Ball") or useItem("Pokeball") then
return true
end
elseif isWildBattle() and isPokemonInList() then
if useItem("Ultra Ball") or useItem("Great Ball") or useItem("Pokeball") then
return true
end
end
-- if we do not try to catch it
if getTeamSize() == 1 or getUsablePokemonCount() > 1 then
local opponentLevel = getOpponentLevel()
local myPokemonLvl = getPokemonLevel(getActivePokemonNumber())
if opponentLevel >= myPokemonLvl then
local requestedId, requestedLevel = game.getMaxLevelUsablePokemon()
if requestedId ~= nil and requestedLevel > myPokemonLvl then
return sendPokemon(requestedId)
end
end
return attack() or sendUsablePokemon() or run() or sendAnyPokemon()
else
if not canRun then
return attack() or game.useAnyMove()
end
return run() or attack() or sendUsablePokemon() or sendAnyPokemon()
end
end
function onBattleMessage(message)
if stringContains(message, "You can not run away!") or sys.stringContains(message, "You failed to run away!") then
canRun = false
elseif stringContains(message, "A wild") then
canRun = true
wildCounter = wildCounter + 1
elseif stringContains(message, "You can not switch this Pokemon!") then
fatal("Cant switch pokemon, restarting bot, be sure auto reconnect is on") -- not the ideal fix
elseif stringContains(message, "A Wild SHINY ") then
shinyCounter = shinyCounter + 1
wildCounter = wildCounter + 1
elseif stringContains(message, "Success!") and stringContains(message, "Dragonair") then
dragonairCounter = dragonairCounter + 1
elseif stringContains(message, "Success! You caught ") then
catchCounter = catchCounter + 1
end
end
function onDialogMessage(message)
if stringContains(message, "There you go, take care of them!") then
pcVisits = pcVisits + 1
log("You have visited the PokeCenter ".. pcVisits .." times.")
end
end
function farmDragonsDen()
if isPokemonUsable(4) then
if getMapName() == "Pokecenter Blackthorn" then
moveToMap("Blackthorn City")
elseif getMapName() == "Blackthorn City" then
moveToMap("Dragons Den Entrance")
elseif getMapName() == "Dragons Den Entrance" then
moveToMap("Dragons Den")
elseif getMapName() == "Dragons Den" then
moveToWater()
end
else
if getMapName() == "Dragons Den" then
moveToMap("Dragons Den Entrance")
elseif getMapName() == "Dragons Den Entrance" then
moveToMap("Blackthorn City")
elseif getMapName() == "Blackthorn City" then
moveToMap("Pokecenter Blackthorn")
elseif getMapName() == "Pokecenter Blackthorn" then
usePokecenter()
end
end
end
local hmMoves = {
"cut",
"surf",
"flash"
}
function chooseForgetMove(moveName, pokemonIndex) -- Calc the WrostAbility ((Power x PP)*(Accuract/100))
local ForgetMoveName
local ForgetMoveTP = 9999
for moveId=1, 4, 1 do
local MoveName = getPokemonMoveName(pokemonIndex, moveId)
if MoveName == nil or MoveName == "cut" or MoveName == "surf" or MoveName == "rock smash" or MoveName == "dive" or (MoveName == "sleep powder" and not hasItem("Plain Badge")) then
else
local CalcMoveTP = math.modf((getPokemonMaxPowerPoints(pokemonIndex,moveId) * getPokemonMovePower(pokemonIndex,moveId))*(math.abs(getPokemonMoveAccuracy(pokemonIndex,moveId)) / 100))
if CalcMoveTP < ForgetMoveTP then
ForgetMoveTP = CalcMoveTP
ForgetMoveName = MoveName
end
end
end
log("[Learning Move: " .. moveName .. " --> Forget Move: " .. ForgetMoveName .. "]")
return ForgetMoveName
end
function onlearningMove(moveName, pokemonIndex)
return forgetMove(chooseForgetMove(moveName, pokemonIndex))
end
------------------------------------
-- Comparison or Checking Function -
------------------------------------
function isOnMap (mapName)
if getMapName () == mapName then
return true
else
return false
end
end
function isPokemonInList ()
if catchList[1] ~= "" then
for i = 1, tableLength (catchList), 1 do
if getOpponentName() == catchList[i] then
return true
end
end
end
return false
end
function tableLength (t)
local count = 0
for _ in pairs(t) do
count = count + 1
end
return count
end