#===============================================================================
# * Triple Triad Booster Pack - by FL (Credits will be appreciated)
#===============================================================================
#
# This script is for Pokémon Essentials. It's a booster pack item for
# Triple Triad minigame.
#
#===============================================================================
#
# To this script works, put it above main. Put an item into item.txt like:
#
# 712,BOOSTERPACK,Booster Pack,Booster Packs,1,500,An booster pack for Triple Triad game. Contains 3 cards ,2,0,0,
#
# You can set a max/min value for the biggest attribute in a card. So, you can
# create several types of packs, an example where 3 is the number of cards,
# 5 is the minimum level and 9 is the maximum level:
#
# ItemHandlers::UseFromBag.add(:SUPERPACK,proc{|item|
# giveBoosterPack(item,3,5,9)
# })
# You can set a BOOSTER_LIST lists. So, you can create several types of
# packs. For helping in making these lists, this script includes a
# method (getSpeciesOfType) that return the index of a pokémon type. An
# example: if you call the line 'p getSpeciesOfType(PBTypes::DRAGON)', you can
# copy/paste the species array of all Dragon pokémon in pokemon.txt. If you
# copy into the index 2 (remember that the first index is 0), all that you need
# to do in the item script is:
#
# ItemHandlers::UseFromBag.add(:DRAGONPACK,proc{|item|
# giveBoosterPack(item,3,2)
# })
#
# This script generates random cards, but generate some cards in order to a
# player won't reset the game trying to get other cards. The variable
# MIN_BOOSTER_STOCK defines how many cards are stocked in save. If the number
# in this variable is 5, by example, and the values are initialized. Even if
# the player saves and keep opening the packs and resetting, he gets the same
# first 5 cards, since these cards are randomized only the 5 cards ahead. To
# disable this feature, just make the variable value as 0.
#
# I suggest you to initialize this list after the professor lecture, for all
# packs. If, in your game, the last pack index that you use is 2, after
# professor lecture add the script commands:
#
# $PokemonGlobal.fillBoosterStock(0)
# $PokemonGlobal.fillBoosterStock(1)
# $PokemonGlobal.fillBoosterStock(2)
#
#===============================================================================
MIN_BOOSTER_STOCK=30
BOOSTER_LIST= [
[1,4,7,10,13,16,19,21,23,25,27,29,32,35,37,39,41,43,46,48,50,52,54,56,58,60,63,
66,69,72,74,77,79,81,83,84,86,88,90,92,95,96,98,100,102,104,106,107,108,109,111,
113,114,115,116,118,120,122,123,124,125,126,127,128,129,131,132,133,137,138,140,
142,143,147],
# The below line is the booster of index 1
[1,4,7,10,13,16,19,21,25,29,
32,35,39,41,56],
# index 2
[137,138,139,140,141,142,143,144,145,146,150,151,243,244,245,249,250,251,
377,378,379,380,381,382,383,384,385,386]
]
if MIN_BOOSTER_STOCK>0
class PokemonGlobalMetadata
def fillBoosterStock(boosterIndex)
@boosterStock=[] if !@boosterStock
@boosterStock[boosterIndex]=[] if @boosterStock.size<=boosterIndex
while @boosterStock[boosterIndex].size<MIN_BOOSTER_STOCK
randomCard = getRandomTriadCard(boosterIndex)
@boosterStock[boosterIndex].push(randomCard)
end
end
def getFirstBoosterAtStock(boosterIndex)
# Called twice since the variable maybe isn't initialized
fillBoosterStock(boosterIndex)
newCard = @boosterStock[boosterIndex].shift
fillBoosterStock(boosterIndex)
return newCard
end
end
end
def getRandomTriadCard(boosterIndex)
overflowCount=0
loop do
overflowCount+=1
raise "Can't draw a random card!" if overflowCount>10000
randomPokemon = rand(PBSpecies.maxValue)+1
cname=getConstantName(PBSpecies,randomPokemon) rescue nil
next if !cname
if (!BOOSTER_LIST[boosterIndex] || BOOSTER_LIST[boosterIndex].empty? ||
BOOSTER_LIST[boosterIndex].include?(randomPokemon))
return randomPokemon
end
end
end
def giveBoosterPack(item,numberOfCards,boosterIndex=0)
Kernel.pbMessage(_INTL("{1} opened the {2}.",
$Trainer.name,PBItems.getName(item)))
cardEarned = 0
overflowCount = 0
for i in 0...numberOfCards
card=-1
if MIN_BOOSTER_STOCK>0
card = $PokemonGlobal.getFirstBoosterAtStock(boosterIndex)
else
card = getRandomTriadCard(boosterIndex)
end
pbGiveTriadCard(card,1)
Kernel.pbMessage(_INTL("{1} draws {2} card!",
$Trainer.name,getConstantName(PBSpecies,card)))
end
return 3
end
def getSpeciesOfType(type)
ret = []
dexdata=pbOpenDexData
for species in 1..PBSpecies.maxValue
# Type
pbDexDataOffset(dexdata,species,8)
type1=dexdata.fgetb
type2=dexdata.fgetb
ret.push(species) if type==type1 || type==type2
end
return ret
end
ItemHandlers::UseFromBag.add(:BOOSTERPACK,proc{|item|
giveBoosterPack(item,3,0)
})
ItemHandlers::UseFromBag.add(:STARTERPACK,proc{|item|
giveBoosterPack(item,3,1)
})
ItemHandlers::UseFromBag.add(:LEGENDARYPACK,proc{|item|
giveBoosterPack(item,1,2)
})