PokeBot/util/player.lua

47 lines
945 B
Lua
Raw Normal View History

2015-04-06 01:18:46 -07:00
local Player = {}
2014-07-12 18:47:39 -07:00
2015-04-06 01:18:46 -07:00
local Textbox = require "action.textbox"
2014-07-12 18:47:39 -07:00
2015-04-06 01:18:46 -07:00
local Input = require "util.input"
local Memory = require "util.memory"
2014-07-12 18:47:39 -07:00
2015-04-07 04:52:03 -07:00
local yellow = YELLOW
2014-07-12 18:47:39 -07:00
local facingDirections = {Up=8, Right=1, Left=2, Down=4}
2015-04-11 14:03:44 -07:00
local fast = false
2014-07-12 18:47:39 -07:00
2015-04-06 01:18:46 -07:00
function Player.isFacing(direction)
return Memory.value("player", "facing") == facingDirections[direction]
2014-07-12 18:47:39 -07:00
end
2015-04-06 01:18:46 -07:00
function Player.face(direction)
if Player.isFacing(direction) then
2014-07-12 18:47:39 -07:00
return true
end
2015-04-06 01:18:46 -07:00
if Textbox.handle() then
Input.press(direction, 0)
2014-07-12 18:47:39 -07:00
end
end
2015-04-13 00:47:34 -07:00
function Player.interact(direction, extended)
2015-04-06 01:18:46 -07:00
if Player.face(direction) then
2015-04-13 00:47:34 -07:00
local speed = extended and 3 or 2
2015-04-11 14:03:44 -07:00
if yellow and instant then
fast = not fast
speed = fast and 1 or 2
end
Input.press("A", speed)
2014-07-12 18:47:39 -07:00
return true
end
2015-04-11 14:03:44 -07:00
fast = false
2014-07-12 18:47:39 -07:00
end
2015-04-06 01:18:46 -07:00
function Player.isMoving()
return Memory.value("player", "moving") ~= 0
2014-07-12 18:47:39 -07:00
end
2015-04-06 01:18:46 -07:00
function Player.position()
return Memory.value("player", "x"), Memory.value("player", "y")
2014-07-12 18:47:39 -07:00
end
2015-04-06 01:18:46 -07:00
return Player