local ran = false

local function log(message)
  g_logger.info("[Phase3Bot] " .. message)
end

local function step(delay, label, callback)
  scheduleEvent(function()
    log(label)
    callback()
  end, delay)
end

local function runPhase3Evidence()
  if ran or not g_game.isOnline() then
    return
  end
  ran = true
  local player = g_game.getLocalPlayer()
  if player then
    log("online as " .. player:getName())
  end

  step(8000, "say !stats", function()
    g_game.talkChannel(MessageModes.Say, 0, "!stats")
  end)

  step(11000, "cast exura forge", function()
    g_game.talkChannel(MessageModes.Say, 0, "exura forge")
  end)

  step(14000, "use inventory item 30001", function()
    g_game.useInventoryItem(30001)
  end)

  step(17000, "walk east", function()
    g_game.walk(Directions.East)
  end)

  step(20000, "walk west", function()
    g_game.walk(Directions.West)
  end)
end

function init()
  connect(g_game, { onGameStart = runPhase3Evidence })
  if g_game.isOnline() then
    scheduleEvent(runPhase3Evidence, 1000)
  end
end

function terminate()
  disconnect(g_game, { onGameStart = runPhase3Evidence })
end
