1. #===============================================================================
  2. #
  3. #===============================================================================
  4. class PokemonBox
  5. attr_reader :pokemon
  6. attr_accessor :name
  7. attr_accessor :background
  8.  
  9. BOX_WIDTH = 15
  10. BOX_HEIGHT = 8
  11. BOX_SIZE = BOX_WIDTH * BOX_HEIGHT
  12.  
  13. def initialize(name, maxPokemon = BOX_SIZE)
  14. @name = name
  15. @background = 0
  16. @pokemon = []
  17. maxPokemon.times { |i| @pokemon[i] = nil }
  18. end
  19.  
  20. def length
  21. return @pokemon.length
  22. end
  23.  
  24. def nitems
  25. ret = 0
  26. @pokemon.each { |pkmn| ret += 1 if !pkmn.nil? }
  27. return ret
  28. end
  29.  
  30. def full?
  31. return nitems == self.length
  32. end
  33.  
  34. def empty?
  35. return nitems == 0
  36. end
  37.  
  38. def [](i)
  39. return @pokemon[i]
  40. end
  41.  
  42. def []=(i, value)
  43. @pokemon[i] = value
  44. end
  45.  
  46. def each
  47. @pokemon.each { |item| yield item }
  48. end
  49.  
  50. def clear
  51. @pokemon.clear
  52. end
  53. end
  54.  
  55. #===============================================================================
  56. #
  57. #===============================================================================
  58. class PokemonStorage
  59. attr_reader :boxes
  60. attr_accessor :currentBox
  61. attr_writer :unlockedWallpapers
  62.  
  63. BASICWALLPAPERQTY = 16
  64.  
  65. def initialize(maxBoxes = Settings::NUM_STORAGE_BOXES, maxPokemon = PokemonBox::BOX_SIZE)
  66. @boxes = []
  67. maxBoxes.times do |i|
  68. @boxes[i] = PokemonBox.new(_INTL("Box {1}", i + 1), maxPokemon)
  69. @boxes[i].background = i % BASICWALLPAPERQTY
  70. end
  71. @currentBox = 0
  72. @boxmode = -1
  73. @unlockedWallpapers = []
  74. allWallpapers.length.times do |i|
  75. @unlockedWallpapers[i] = false
  76. end
  77. end
  78.  
  79. def allWallpapers
  80. return [
  81. # Basic wallpapers
  82. _INTL("Forest"), _INTL("City"), _INTL("Desert"), _INTL("Savanna"),
  83. _INTL("Crag"), _INTL("Volcano"), _INTL("Snow"), _INTL("Cave"),
  84. _INTL("Beach"), _INTL("Seafloor"), _INTL("River"), _INTL("Sky"),
  85. _INTL("Poké Center"), _INTL("Machine"), _INTL("Checks"), _INTL("Simple"),
  86. # Special wallpapers
  87. _INTL("Space"), _INTL("Backyard"), _INTL("Nostalgic 1"), _INTL("Torchic"),
  88. _INTL("Trio 1"), _INTL("PikaPika 1"), _INTL("Legend 1"), _INTL("Team Galactic 1"),
  89. _INTL("Distortion"), _INTL("Contest"), _INTL("Nostalgic 2"), _INTL("Croagunk"),
  90. _INTL("Trio 2"), _INTL("PikaPika 2"), _INTL("Legend 2"), _INTL("Team Galactic 2"),
  91. _INTL("Heart"), _INTL("Soul"), _INTL("Big Brother"), _INTL("Pokéathlon"),
  92. _INTL("Trio 3"), _INTL("Spiky Pika"), _INTL("Kimono Girl"), _INTL("Revival")
  93. ]
  94. end
  95.  
  96. def unlockedWallpapers
  97. @unlockedWallpapers = [] if !@unlockedWallpapers
  98. return @unlockedWallpapers
  99. end
  100.  
  101. def isAvailableWallpaper?(i)
  102. @unlockedWallpapers = [] if !@unlockedWallpapers
  103. return true if i < BASICWALLPAPERQTY
  104. return true if @unlockedWallpapers[i]
  105. return false
  106. end
  107.  
  108. def availableWallpapers
  109. ret = [[], []] # Names, IDs
  110. papers = allWallpapers
  111. @unlockedWallpapers = [] if !@unlockedWallpapers
  112. papers.length.times do |i|
  113. next if !isAvailableWallpaper?(i)
  114. ret[0].push(papers[i])
  115. ret[1].push(i)
  116. end
  117. return ret
  118. end
  119.  
  120. def party
  121. $player.party
  122. end
  123.  
  124. def party=(_value)
  125. raise ArgumentError.new("Not supported")
  126. end
  127.  
  128. def party_full?
  129. return $player.party_full?
  130. end
  131.  
  132. def maxBoxes
  133. return @boxes.length
  134. end
  135.  
  136. def maxPokemon(box)
  137. return 0 if box >= self.maxBoxes
  138. return (box < 0) ? Settings::MAX_PARTY_SIZE : PokemonBox::BOX_SIZE
  139. end
  140.  
  141. def full?
  142. self.maxBoxes.times do |i|
  143. return false if !@boxes[i].full?
  144. end
  145. return true
  146. end
  147.  
  148. def pbFirstFreePos(box)
  149. if box == -1
  150. ret = self.party.length
  151. return (ret >= Settings::MAX_PARTY_SIZE) ? -1 : ret
  152. end
  153. maxPokemon(box).times do |i|
  154. return i if !self[box, i]
  155. end
  156. return -1
  157. end
  158.  
  159. def [](x, y = nil)
  160. if y.nil?
  161. return (x == -1) ? self.party : @boxes[x]
  162. else
  163. @boxes.each do |i|
  164. raise "Box is a Pokémon, not a box" if i.is_a?(Pokemon)
  165. end
  166. return (x == -1) ? self.party[y] : @boxes[x][y]
  167. end
  168. end
  169.  
  170. def []=(x, y, value)
  171. if x == -1
  172. self.party[y] = value
  173. else
  174. @boxes[x][y] = value
  175. end
  176. end
  177.  
  178. def pbCopy(boxDst, indexDst, boxSrc, indexSrc)
  179. if indexDst < 0 && boxDst < self.maxBoxes
  180. found = false
  181. maxPokemon(boxDst).times do |i|
  182. next if self[boxDst, i]
  183. found = true
  184. indexDst = i
  185. break
  186. end
  187. return false if !found
  188. end
  189. if boxDst == -1 # Copying into party
  190. return false if party_full?
  191. self.party[self.party.length] = self[boxSrc, indexSrc]
  192. self.party.compact!
  193. else # Copying into box
  194. pkmn = self[boxSrc, indexSrc]
  195. raise "Trying to copy nil to storage" if !pkmn
  196. if Settings::HEAL_STORED_POKEMON
  197. old_ready_evo = pkmn.ready_to_evolve
  198. pkmn.heal
  199. pkmn.ready_to_evolve = old_ready_evo
  200. end
  201. self[boxDst, indexDst] = pkmn
  202. end
  203. return true
  204. end
  205.  
  206. def pbMove(boxDst, indexDst, boxSrc, indexSrc)
  207. return false if !pbCopy(boxDst, indexDst, boxSrc, indexSrc)
  208. pbDelete(boxSrc, indexSrc)
  209. return true
  210. end
  211.  
  212. def pbMoveCaughtToParty(pkmn)
  213. return false if party_full?
  214. self.party[self.party.length] = pkmn
  215. end
  216.  
  217. def pbMoveCaughtToBox(pkmn, box)
  218. maxPokemon(box).times do |i|
  219. next unless self[box, i].nil?
  220. if Settings::HEAL_STORED_POKEMON && box >= 0
  221. old_ready_evo = pkmn.ready_to_evolve
  222. pkmn.heal
  223. pkmn.ready_to_evolve = old_ready_evo
  224. end
  225. self[box, i] = pkmn
  226. return true
  227. end
  228. return false
  229. end
  230.  
  231. def pbStoreCaught(pkmn)
  232. if Settings::HEAL_STORED_POKEMON && @currentBox >= 0
  233. old_ready_evo = pkmn.ready_to_evolve
  234. pkmn.heal
  235. pkmn.ready_to_evolve = old_ready_evo
  236. end
  237. maxPokemon(@currentBox).times do |i|
  238. if self[@currentBox, i].nil?
  239. self[@currentBox, i] = pkmn
  240. return @currentBox
  241. end
  242. end
  243. self.maxBoxes.times do |j|
  244. maxPokemon(j).times do |i|
  245. next unless self[j, i].nil?
  246. self[j, i] = pkmn
  247. @currentBox = j
  248. return @currentBox
  249. end
  250. end
  251. return -1
  252. end
  253.  
  254. def pbDelete(box, index)
  255. if self[box, index]
  256. self[box, index] = nil
  257. self.party.compact! if box == -1
  258. end
  259. end
  260.  
  261. def clear
  262. self.maxBoxes.times { |i| @boxes[i].clear }
  263. end
  264. end
  265.  
  266. #===============================================================================
  267. # Regional Storage scripts
  268. #===============================================================================
  269. class RegionalStorage
  270. def initialize
  271. @storages = []
  272. @lastmap = -1
  273. @rgnmap = -1
  274. end
  275.  
  276. def getCurrentStorage
  277. if !$game_map
  278. raise _INTL("The player is not on a map, so the region could not be determined.")
  279. end
  280. if @lastmap != $game_map.map_id
  281. @rgnmap = pbGetCurrentRegion # may access file IO, so caching result
  282. @lastmap = $game_map.map_id
  283. end
  284. if @rgnmap < 0
  285. raise _INTL("The current map has no region set. Please set the MapPosition metadata setting for this map.")
  286. end
  287. @storages[@rgnmap] = PokemonStorage.new if !@storages[@rgnmap]
  288. return @storages[@rgnmap]
  289. end
  290.  
  291. def allWallpapers
  292. return getCurrentStorage.allWallpapers
  293. end
  294.  
  295. def availableWallpapers
  296. return getCurrentStorage.availableWallpapers
  297. end
  298.  
  299. def unlockWallpaper(index)
  300. getCurrentStorage.unlockWallpaper(index)
  301. end
  302.  
  303. def boxes
  304. return getCurrentStorage.boxes
  305. end
  306.  
  307. def party
  308. return getCurrentStorage.party
  309. end
  310.  
  311. def party_full?
  312. return getCurrentStorage.party_full?
  313. end
  314.  
  315. def maxBoxes
  316. return getCurrentStorage.maxBoxes
  317. end
  318.  
  319. def maxPokemon(box)
  320. return getCurrentStorage.maxPokemon(box)
  321. end
  322.  
  323. def full?
  324. getCurrentStorage.full?
  325. end
  326.  
  327. def currentBox
  328. return getCurrentStorage.currentBox
  329. end
  330.  
  331. def currentBox=(value)
  332. getCurrentStorage.currentBox = value
  333. end
  334.  
  335. def [](x, y = nil)
  336. getCurrentStorage[x, y]
  337. end
  338.  
  339. def []=(x, y, value)
  340. getCurrentStorage[x, y] = value
  341. end
  342.  
  343. def pbFirstFreePos(box)
  344. getCurrentStorage.pbFirstFreePos(box)
  345. end
  346.  
  347. def pbCopy(boxDst, indexDst, boxSrc, indexSrc)
  348. getCurrentStorage.pbCopy(boxDst, indexDst, boxSrc, indexSrc)
  349. end
  350.  
  351. def pbMove(boxDst, indexDst, boxSrc, indexSrc)
  352. getCurrentStorage.pbMove(boxDst, indexDst, boxSrc, indexSrc)
  353. end
  354.  
  355. def pbMoveCaughtToParty(pkmn)
  356. getCurrentStorage.pbMoveCaughtToParty(pkmn)
  357. end
  358.  
  359. def pbMoveCaughtToBox(pkmn, box)
  360. getCurrentStorage.pbMoveCaughtToBox(pkmn, box)
  361. end
  362.  
  363. def pbStoreCaught(pkmn)
  364. getCurrentStorage.pbStoreCaught(pkmn)
  365. end
  366.  
  367. def pbDelete(box, index)
  368. getCurrentStorage.pbDelete(box, index)
  369. end
  370. end
  371.  
  372. #===============================================================================
  373. #
  374. #===============================================================================
  375. def pbUnlockWallpaper(index)
  376. $PokemonStorage.unlockedWallpapers[index] = true
  377. end
  378.  
  379. # NOTE: I don't know why you'd want to do this, but here you go.
  380. def pbLockWallpaper(index)
  381. $PokemonStorage.unlockedWallpapers[index] = false
  382. end
  383.  
  384. #===============================================================================
  385. # Look through Pokémon in storage
  386. #===============================================================================
  387. # Yields every Pokémon/egg in storage in turn.
  388. def pbEachPokemon
  389. (-1...$PokemonStorage.maxBoxes).each do |i|
  390. $PokemonStorage.maxPokemon(i).times do |j|
  391. pkmn = $PokemonStorage[i][j]
  392. yield(pkmn, i) if pkmn
  393. end
  394. end
  395. end
  396.  
  397. # Yields every Pokémon in storage in turn.
  398. def pbEachNonEggPokemon
  399. pbEachPokemon { |pkmn, box| yield(pkmn, box) if !pkmn.egg? }
  400. end