2015-05-24 15:39:11 -07:00
--##################################################
--############# ############
--############# SETTING ############
--############# ############
--##################################################
--Reset Settings
RESET_FOR_TIME = false -- Set to false if you just want to see the bot finish a run without reset for time
RESET_FOR_ENCOUNTERS = false -- Set to false if you just want to see the bot finish a run without reset for encounters
--Game Settings
2015-05-25 15:52:34 -07:00
GAME_NAME = " Crystal " -- Set to Gold/Silver(not done) or Crystal
2015-05-24 15:39:11 -07:00
GAME_RUN = " " -- Set to "" or "" for the run you want
GAME_HOURS = 17 -- Set the internal game hour (0-23h)
2015-05-27 03:36:20 -07:00
GAME_MINUTES = 50 -- Set the internal game minutes (0-59min)
GAME_DAY = 0 -- Set the internal game day (0-6 // sunday-saturday)
2015-05-24 15:39:11 -07:00
GAME_GENDER = 1 -- Set the player gender (1-2 // boy-girl)
GAME_TEXT_SPEED = 128 -- Set the Text Speed (247-249 // slow-fast)
GAME_BATTLE_ANIMATION = 133 -- Set the battle animation (141-142 // no-yes)
GAME_BATTLE_STYLE = 132 -- Set the battle style (130-131 // choice-set)
GAME_SOUND_STYLE = 145 -- Set the sound style (132 or 141 // stereo-mono)
GAME_PRINT_STYLE = 127 -- Set the print style (64=normal // 96=dark // 127=dark+ // 0=clear+ // 32=clear)
GAME_ACCOUNT_STYLE = 0 -- Set the account style (0-1 // no-yes)
GAME_WINDOWS_STYLE = 3 -- Set the windows style (0-7)
--Connection Settings
INTERNAL = false -- Allow connection with LiveSplit ?
STREAMING_MODE = false -- Enable Streaming mode
--Script Settings
CUSTOM_SEED = nil -- Set to a known seed to replay it, or leave nil for random runs
PAINT_ON = true -- Display contextual information while the bot runs
--Names Settings
2015-05-27 03:36:20 -07:00
PLAYER_NAME = " TeSt-< " -- Player name
2015-05-24 15:39:11 -07:00
RIVAL_NAME = " URRival " -- Rival name
TOTODILE_NAME = " ToTo " -- Set Totodile name
--Advanced area Settings
PATH_IDX = 0 -- Start the bot to the specified path idx
STEP_IDX = 0 -- Start the bot to the specified step idx
PRINT_PATH = false -- Print the current path in the console.
PRINT_STEP = false -- Print the current step in the console.
--NAMES SETTINGS TIPS :
-- - Can use up to 7 letter ingame
-- - Upper and Lower case allowed
-- - Specials Characters : <=Special X, {=Pk, }=Mn
--#####################################################################################
--#####################################################################################
--########### ###############
--########### PLEASE DON'T EDIT ANYTHING BELLOW, IT'S AT YOUR RISK ###############
--########### START CODE (hard hats on) ###############
--########### ###############
--#####################################################################################
--#####################################################################################
-- SET VALUES
2015-05-27 03:36:20 -07:00
local VERSION = " 0.21-BETA "
2015-05-24 15:39:11 -07:00
local START_WAIT = 99
local hasAlreadyStartedPlaying = false
local oldSeconds
local running = true
local lastHP
--RUNNING4CONTINUE = false --used to continue a game
--RUNNING4NEWGAME = true --used to make a new game (remove last save also)
--EXTERNALDONE = false --used when the above settings are done externally
--local InternalDone = false --used when the above settings are done internally
--local UsingCustomPath = false --used when we set a custom path
-- LOAD DIR
local LowerGameName = string.lower ( GAME_NAME )
local Battle = require " action.battle "
local Textbox = require " action.textbox "
local Walk = require " action.walk "
local Combat = require " ai.combat "
local Control = require " ai.control "
local Strategies = require ( " ai. " .. LowerGameName .. " .strategies " )
local Bridge = require " util.bridge "
local Input = require " util.input "
local Memory = require " util.memory "
local Menu = require " util.menu "
local Paint = require " util.paint "
local Utils = require " util.utils "
local Settings = require " util.settings "
local Pokemon = require " storage.pokemon "
-- GLOBAL
function p ( ... ) --print
local string
if # arg == 0 then
string = arg [ 0 ]
else
string = " "
for i , str in ipairs ( arg ) do
if str == true then
string = string .. " \n "
else
string = string .. str .. " "
end
end
end
print ( string )
end
-- RESET
local function resetAll ( )
Strategies.softReset ( )
Combat.reset ( )
Control.reset ( )
Walk.reset ( )
Paint.reset ( )
Bridge.reset ( )
oldSeconds = 0
running = false
-- client.speedmode = 200
if CUSTOM_SEED then
Strategies.seed = CUSTOM_SEED
p ( " RUNNING WITH A FIXED SEED ( " .. Strategies.seed .. " ), every run will play out identically! " , true )
else
Strategies.seed = os.time ( )
p ( " Starting a new run with seed " .. Strategies.seed , true )
end
math.randomseed ( Strategies.seed )
end
-- EXECUTE
local OWNER = " Bouletmarc "
p ( " Welcome to PokeBot Version " .. VERSION , true )
p ( " Actually running Pokemon " .. GAME_NAME .. " Speedruns by " .. OWNER , true )
Control.init ( )
--STREAMING_MODE = not walk.init()
2015-05-25 15:52:34 -07:00
if INTERNAL and STREAMING_MODE then
RESET_FOR_TIME = true
end
2015-05-24 15:39:11 -07:00
if CUSTOM_SEED then
client.reboot_core ( )
else
hasAlreadyStartedPlaying = Utils.ingame ( )
end
Strategies.init ( hasAlreadyStartedPlaying )
if RESET_FOR_TIME and hasAlreadyStartedPlaying then
RESET_FOR_TIME = false
p ( " Disabling time-limit resets as the game is already running. Please reset the emulator and restart the script if you'd like to go for a fast time. " , true )
end
2015-05-25 15:52:34 -07:00
if STREAMING_MODE then
Bridge.init ( )
else
2015-05-24 15:39:11 -07:00
Input.setDebug ( true )
2015-05-25 15:52:34 -07:00
end
2015-05-24 15:39:11 -07:00
--if PATH_IDX ~= 0 and STEP_IDX ~= 0 then
-- UsingCustomPath = true
--end
-- MAIN LOOP
local previousMap
local previousMap2
local RebootDone = false
while true do
local currentMap = Memory.value ( " game " , " map " )
local currentMap2 = Memory.value ( " game " , " map2 " )
if currentMap ~= previousMap or currentMap2 ~= previousMap2 then
Input.clear ( )
previousMap = currentMap
previousMap2 = currentMap2
end
if Strategies.frames then
if Memory.value ( " game " , " battle " ) == 0 then
Strategies.frames = Strategies.frames + 1
end
Utils.drawText ( 0 , 80 , Strategies.frames )
end
--if Bridge.polling then
-- Settings.pollForResponse()
--end
if not Input.update ( ) then
if not Utils.ingame ( ) and currentMap == 0 then
--if not Utils.ingame() and currentMap == 0 and currentMap2 == 0 then
2015-05-25 15:52:34 -07:00
if running then
if not hasAlreadyStartedPlaying then
client.reboot_core ( )
hasAlreadyStartedPlaying = true
2015-05-24 15:39:11 -07:00
else
2015-05-25 15:52:34 -07:00
--if not RUNNING4CONTINUE then
resetAll ( ) --reset if not running to continue
--RUNNING4NEWGAME = true --set back on in case we done a reboot
--else
-- running = false --continue adventure
2015-05-24 15:39:11 -07:00
--end
end
2015-05-25 15:52:34 -07:00
else
--if UsingCustomPath then
-- if not EXTERNALDONE then --continue adventure
-- RUNNING4CONTINUE, RUNNING4NEWGAME = true, false
-- elseif EXTERNALDONE and InternalDone then
-- RUNNING4NEWGAME = true --set back to new game
-- end
2015-05-24 15:39:11 -07:00
--end
2015-05-25 15:52:34 -07:00
Settings.startNewAdventure ( START_WAIT ) --start/continue adventure
end
2015-05-24 15:39:11 -07:00
else
if not running then
2015-05-25 15:52:34 -07:00
Bridge.liveSplit ( )
2015-05-24 15:39:11 -07:00
running = true
end
--if RUNNING4NEWGAME then --remove last save game
-- Settings.RemoveLastAdventure(START_WAIT)
--elseif RUNNING4CONTINUE then --continue the last adventure
-- EXTERNALDONE = true
-- InternalDone = true
-- Settings.ContinueAdventure()
--else
local battleState = Memory.value ( " game " , " battle " )
Control.encounter ( battleState )
2015-05-25 15:52:34 -07:00
local curr_hp = Pokemon.index ( 0 , " hp " )
if curr_hp == 0 and not Control.canDie ( ) and Pokemon.index ( 0 ) > 0 then
Strategies.death ( currentMap , currentMap2 )
elseif Walk.strategy then
2015-05-24 15:39:11 -07:00
if Strategies.execute ( Walk.strategy ) then
Walk.traverse ( currentMap , currentMap2 )
end
elseif battleState > 0 then
2015-05-25 15:52:34 -07:00
if not Control.shouldCatch ( partySize ) then
2015-05-24 15:39:11 -07:00
Battle.automate ( )
2015-05-25 15:52:34 -07:00
end
2015-05-24 15:39:11 -07:00
elseif Textbox.handle ( ) then
Walk.traverse ( currentMap , currentMap2 )
end
--end
end
end
2015-05-25 15:52:34 -07:00
if STREAMING_MODE then
2015-05-24 15:39:11 -07:00
local newSeconds = Memory.value ( " time " , " seconds " )
if newSeconds ~= oldSeconds and ( newSeconds > 0 or Memory.value ( " time " , " frames " ) > 0 ) then
Bridge.time ( Utils.elapsedTime ( ) )
oldSeconds = newSeconds
end
2015-05-25 15:52:34 -07:00
elseif PAINT_ON then
2015-05-24 15:39:11 -07:00
Paint.draw ( currentMap , currentMap2 )
end
Input.advance ( )
emu.frameadvance ( )
end
Bridge.close ( )