Skip to content

Commit

Permalink
Merge pull request #21 from Rympex/patch-10
Browse files Browse the repository at this point in the history
Quest.lua: Add leftovers() + gamelib: getFirstUsablePokemon() getPokemonIdWithItem()
  • Loading branch information
g0ldPRO authored Jul 13, 2016
2 parents 71be4f0 + b3ef881 commit a43e613
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Libs/gamelib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,22 @@ function game.getUsablePokemonCountUnderLevel(level)
end
return count
end

function game.getFirstUsablePokemon()
for pokemonId=1, getTeamSize(), 1 do
if isPokemonUsable(pokemonId) then
return pokemonId
end
end
end

function game.getPokemonIdWithItem(ItemName)
for pokemonId=1, getTeamSize(), 1 do
if getPokemonHeldItem(pokemonId) == ItemName then
return pokemonId
end
end
return 0
end

return game
25 changes: 25 additions & 0 deletions Quests/Quest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,28 @@ function Quest:isTrainingOver()
return false
end

function Quest:leftovers()
ItemName = "Leftovers"
local PokemonNeedLeftovers = game.getFirstUsablePokemon()
local PokemonWithLeftovers = game.getPokemonIdWithItem(ItemName)

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) then
giveItemToPokemon(ItemName,PokemonNeedLeftovers)
return true
else
return false-- don't have leftovers in bag and is not on pokemons
end
end
end

function Quest:startTraining()
self.training = true
end
Expand Down Expand Up @@ -166,6 +188,9 @@ function Quest:path()
if not isTeamSortedByLevelAscending() then
return sortTeamByLevelAscending()
end
if self:leftovers() then
return true
end
local mapFunction = self:mapToFunction()
assert(self[mapFunction] ~= nil, self.name .. " quest has no method for map: " .. getMapName())
self[mapFunction](self)
Expand Down

0 comments on commit a43e613

Please sign in to comment.