Changed: PokemonMessages --- Left +++ Right @@ -1401,5 +1401,5 @@ signWaitCount=21 elsif control=="cl" - text=text.sub(/\001$/,"") + text=text.sub(/\001(?!\n)$/,"") # fix: '$' can match end of line as well haveSpecialClose=true specialCloseSE=param @@ -1419,5 +1419,5 @@ end elsif control=="wtnp" || control=="^" - text=text.sub(/\001$/,"") + text=text.sub(/\001(?!\n)$/,"") # fix: '$' can match end of line as well end end @@ -1499,5 +1499,5 @@ msgwindow.waitcount+=Graphics.frame_rate elsif control=="wt" # Wait - param=param.sub(/^\s+/,"").sub(/\s+$/,"") + param=param.sub(/^\s+/,"").sub(/\s+(?!\n)$/,"") msgwindow.waitcount+=param.to_i*2 elsif control=="w" # Windowskin @@ -1510,5 +1510,5 @@ autoresume=true elsif control=="wtnp" # Wait, no pause - param=param.sub(/^\s+/,"").sub(/\s+$/,"") + param=param.sub(/^\s+/,"").sub(/\s+(?!\n)$/,"") msgwindow.waitcount=param.to_i*2 autoresume=true @@ -1901,11 +1901,21 @@ else $game_map.start_scroll(direction, distance, speed); + oldx=$game_map.display_x + oldy=$game_map.display_y loop do Graphics.update Input.update - break if !$game_map.scrolling? + if !$game_map.scrolling? + break + end pbUpdateSceneMap + if $game_map.display_x==oldx && + $game_map.display_y==oldy + break + end + oldx=$game_map.display_x + oldy=$game_map.display_y end end end Changed: PokemonEntry --- Left +++ Right @@ -1087,7 +1087,4 @@ [191,"/","?"], [219,"[","{"], -# [190,".",">"], -# [188,",","<"], -# [220,"\\","|"], [190,".",""], [188,",",""], @@ -1152,5 +1149,5 @@ ] -USEKEYBOARD=true +USEKEYBOARD=false def pbStartScene(helptext,minlength,maxlength,initialText) @@ -1159,11 +1156,14 @@ @viewport.z=99999 if USEKEYBOARD - @sprites["entry"]=Window_TextEntry_Keyboard.new(initialText,40,0,400,96,helptext) + @sprites["entry"]=Window_TextEntry_Keyboard.new(initialText, + 0,0,400,96,helptext) else - @sprites["entry"]=Window_TextEntry.new(initialText,40,0,400,96,helptext) + @sprites["entry"]=Window_TextEntry.new(initialText,0,0,400,96,helptext) end + @sprites["entry"].x=(Graphics.width/2)-(@sprites["entry"].width/2) @sprites["entry"].viewport=@viewport @sprites["entry"].visible=true @minlength=minlength + @maxlength=maxlength @symtype=0 @sprites["entry"].maxlength=maxlength @@ -1222,7 +1222,11 @@ index=@sprites["entry2"].index if index==-3 # Confirm text - pbPlayDecisionSE() ret=@sprites["entry"].text - break + if ret.length<@minlength || ret.length>@maxlength + pbPlayBuzzerSE() + else + pbPlayDecisionSE() + break + end elsif index==-1 # Insert a space if @sprites["entry"].insert(" ") @@ -1677,3 +1681,37 @@ } return ret +end + +class Interpreter + def command_303 + if $data_actors[@parameters[0]] != nil + # Set battle abort flag + $game_temp.battle_abort = true + ret="" + pbFadeOutIn(99999){ + sscene=PokemonEntryScene.new + sscreen=PokemonEntry.new(sscene) + $game_actors[@parameters[0]].name=sscreen.pbStartScreen( + _INTL("Enter {1}'s name.",$game_actors[@parameters[0]].name), + 1,@parameters[1],$game_actors[@parameters[0]].name) + } + end + return true + end +end +class Game_Interpreter + def command_303 + if $data_actors[@params[0]] != nil + # Set battle abort flag + ret="" + pbFadeOutIn(99999){ + sscene=PokemonEntryScene.new + sscreen=PokemonEntry.new(sscene) + $game_actors[@params[0]].name=sscreen.pbStartScreen( + _INTL("Enter {1}'s name.",$game_actors[@params[0]].name), + 1,@params[1],$game_actors[@params[0]].name) + } + end + return true + end end Changed: DrawText --- Left +++ Right @@ -617,21 +617,19 @@ end elsif control=="o" - opacitystack.pop if endtag - opacitystack.push(param.sub(/\s+$/,"").to_i) if !endtag + if endtag + opacitystack.pop + else + opacitystack.push(param.sub(/\s+$/,"").to_i) + end elsif control=="b" - boldcount-=1 if endtag - boldcount+=1 if !endtag + boldcount+=(endtag ? -1 : 1) elsif control=="outln" - outlinecount-=1 if endtag - outlinecount+=1 if !endtag + outlinecount+=(endtag ? -1 : 1) elsif control=="i" - italiccount-=1 if endtag - italiccount+=1 if !endtag + italiccount+=(endtag ? -1 : 1) elsif control=="u" - underlinecount-=1 if endtag - underlinecount+=1 if !endtag + underlinecount+=(endtag ? -1 : 1) elsif control=="s" - strikecount-=1 if endtag - strikecount+=1 if !endtag + strikecount+=(endtag ? -1 : 1) elsif control=="fs" # Font size if endtag @@ -656,5 +654,5 @@ nextline=1 if x>0 && nextline==0 else - alignstack.pop; + alignstack.pop nextline=1 if x>0 && nextline==0 end Changed: PokeBattle_Battler --- Left +++ Right @@ -42,16 +42,16 @@ ### -- complex accessors -def gender - return @pokemon.gender if @pokemon +def gender() + return @pokemon.gender() if @pokemon return 2 end -def nature - return @pokemon.nature if @pokemon +def nature() + return @pokemon.nature() if @pokemon return 0 end -def happiness - return @pokemon.happiness if @pokemon +def happiness() + return @pokemon.happiness() if @pokemon return 0 end @@ -60,5 +60,5 @@ def level=(value) @level=value - @pokemon.level=value if @pokemon + @pokemon.level=(value) if @pokemon end attr_reader :status @@ -347,5 +347,5 @@ end -def pbThis +def pbThis() if @battle.pbIsOpposing?(@index) if @battle.opponent @@ -361,5 +361,5 @@ end -def pbSpeed +def pbSpeed() stagemul=[10,10,10,10,10,10,10,15,20,25,30,35,40] stagediv=[40,35,30,25,20,15,10,10,10,10,10,10,10] Changed: PokemonBag --- Left +++ Right @@ -354,5 +354,4 @@ Input.update yield - cmdwindow.update if Input.trigger?(Input::B) @@ -466,10 +465,5 @@ bm=@sprites["pocketwindow"].bitmap bm.clear - pocketNames=["", - _INTL("Items"),_INTL("Pokeballs"), - _INTL("TMs & HMs"),_INTL("Berries"), - _INTL("Key Items") - ] - name=pocketNames[@bag.lastpocket] + name=PokemonBag.pocketNames()[@bag.lastpocket] # Set the bitmap for the currently selected bag @sprites["bag"].setBitmap("Graphics/Pictures/Bag#{@bag.lastpocket}") @@ -519,9 +513,10 @@ end # Change pockets if Left/Right pressed + numpockets=PokemonBag.numPockets if Input.trigger?(Input::LEFT) - itemwindow.pocket=(itemwindow.pocket==1) ? 5 : itemwindow.pocket-1 + itemwindow.pocket=(itemwindow.pocket==1) ? numpockets : itemwindow.pocket-1 pbRefresh elsif Input.trigger?(Input::RIGHT) - itemwindow.pocket=(itemwindow.pocket==5) ? 1 : itemwindow.pocket+1 + itemwindow.pocket=(itemwindow.pocket==numpockets) ? 1 : itemwindow.pocket+1 pbRefresh end @@ -725,4 +720,14 @@ attr_accessor :lastpocket attr_reader :pockets + def self.pocketNames() + return ["", + _INTL("Items"),_INTL("Pokeballs"), + _INTL("TMs & HMs"),_INTL("Berries"), + _INTL("Key Items") + ] + end + def self.numPockets() + return self.pocketNames().length-1 + end MAXPERSLOT=99 # Maximum number of items per item slot MAXPOCKETSIZE=[0,256,-1,-1,-1,-1] # Maximum size per pocket @@ -730,18 +735,18 @@ @lastpocket=1 @pockets=[] + @choices=[] # Initialize each pocket of the array - @pockets[0]=[] - @pockets[1]=[] - @pockets[2]=[] - @pockets[3]=[] - @pockets[4]=[] - @pockets[5]=[] - @choices=[0,0,0,0,0,0] + for i in 0..PokemonBag.numPockets + @pockets[i]=[] + @choices[i]=0 + end @registeredItem=0 end # Gets the index of the current selected item in the pocket def getChoice(pocket) - raise ArgumentError.new(_INTL("Invalid pocket: {1}",pocket.inspect)) if pocket<=0 || pocket>5 - return @choices[pocket] + if pocket<=0 || pocket>PokemonBag.numPockets + raise ArgumentError.new(_INTL("Invalid pocket: {1}",pocket.inspect)) + end + return @choices[pocket] || 0 end # Clears the entire bag @@ -753,6 +758,10 @@ # Sets the index of the current selected item in the pocket def setChoice(pocket,value) - raise ArgumentError.new(_INTL("Invalid pocket: {1}",pocket.inspect)) if pocket<=0 || pocket>5 - @choices[pocket]=value if value<@pockets[pocket].length + if pocket<=0 || pocket>PokemonBag.numPockets + raise ArgumentError.new(_INTL("Invalid pocket: {1}",pocket.inspect)) + end + if value<@pockets[pocket].length + @choices[pocket]=value + end end # Registers the item as a key item. Can be retrieved with $PokemonBag.registeredItem Changed: PokemonUtilities --- Left +++ Right @@ -1261,4 +1261,5 @@ bgm=pbStringToAudioFile(bgm) pbMEPlay(bgm) + return end end @@ -1343,5 +1344,5 @@ def pbGetTrainerVictoryME(trainer) # can be a PokeBattle_Trainer or an array of PokeBattle_Trainer if $PokemonGlobal.nextBattleME - return $PokemonGlobal.nextBattleME.clone + return $PokemonGlobal.nextBattleME.clone end music=nil Changed: PokemonBattleSwap --- Left +++ Right @@ -114,9 +114,9 @@ _INTL("POKéMON SWAP"),0,0,Graphics.width,64,@viewport) @sprites["help"]=Window_UnformattedTextPokemon.newWithSize( - _INTL(""),0,Graphics.height-64,Graphics.width,64,@viewport) + "",0,Graphics.height-64,Graphics.width,64,@viewport) @sprites["list"]=Window_AdvancedCommandPokemonEx.newWithSize( [],0,64,Graphics.width,Graphics.height-128,@viewport) @sprites["msgwindow"]=Window_AdvancedTextPokemon.newWithSize( - _INTL(""),0,Graphics.height-64,Graphics.width,64,@viewport) + "",0,Graphics.height-64,Graphics.width,64,@viewport) @sprites["msgwindow"].visible=false addBackgroundPlane(@sprites,"bg","swapbg",@viewport) @@ -182,5 +182,5 @@ @scene.pbUpdateChoices(chosen.clone) if chosen.length==3 - if @scene.pbConfirm(_INTL("Are these three Pokemon OK?")) + if @scene.pbConfirm(_INTL("Are these three Pokémon OK?")) retval=[] chosen.each{|i| retval.push(rentals[i]) } @@ -211,5 +211,5 @@ pkmn=@scene.pbChoosePokemon(true) if pkmn>=0 - if @scene.pbConfirm(_INTL("Accept this Pokemon?")) + if @scene.pbConfirm(_INTL("Accept this Pokémon?")) @scene.pbEndScene currentPokemon[yourPkmn]=newPokemon[pkmn] Changed: PokemonItems --- Left +++ Right @@ -21,4 +21,8 @@ end +def pbGetPrice(item) + return $ItemData[item][ITEMPRICE] +end + def pbIsImportantItem?(item) return $ItemData[item] && ($ItemData[item][ITEMPOCKET]==5 || pbIsHiddenMachine?(item)) Changed: PokemonMap --- Left +++ Right @@ -397,7 +397,5 @@ $PokemonTemp.pokemonMetadata=[] else - pbRgssOpen("Data/metadata.dat","rb"){|f| - $PokemonTemp.pokemonMetadata=Marshal.load(f) - } + $PokemonTemp.pokemonMetadata=load_data("Data/metadata.dat") end end Changed: PokemonTrainers --- Left +++ Right @@ -455,5 +455,5 @@ p.moves[2]=PBMove.new(pbRandomMove) p.moves[3]=PBMove.new(pbRandomMove) - p.item=rand(300-1)+1 + p.item=rand(PBItems.maxValue)+1 p.calcStats return p Changed: PokeBattle_BattleArena --- Left +++ Right @@ -307,5 +307,5 @@ dimmingvp.dispose infowindow.contents.dispose - infowindow.dispose + infowindow.dispose end end Changed: Main --- Left +++ Right @@ -12,4 +12,5 @@ end + def mainFunction if $DEBUG Changed: Compiler --- Left +++ Right @@ -14,7 +14,7 @@ if emessage && !FileTest.exist?("Game.rgssad") && !FileTest.exist?("Game.rgss2a") emessage=emessage.gsub(/uninitialized constant PBItems\:\:(\S+)/){ - "The item '#{$1}' is not valid. Please add the item\r\nto the PBS/items.txt file. See the notes for more information." } + "The item '#{$1}' is not valid. Please add the item\r\nto the list of items in the editor. See the notes for more information." } emessage=emessage.gsub(/undefined method `(\S+?)' for PBItems\:Module/){ - "The item '#{$1}' is not valid. Please add the item\r\nto the PBS/items.txt file. See the notes for more information." } + "The item '#{$1}' is not valid. Please add the item\r\nto the list of items in the editor. See the notes for more information." } emessage=emessage.gsub(/uninitialized constant PBTypes\:\:(\S+)/){ "The type '#{$1}' is not valid. Please add the type\r\nto the PBS/types.txt file." } @@ -273,6 +273,13 @@ class SerialRecord < Array def bytesize + return SerialRecord.bytesize(self) + end + def encode(strm) + return SerialRecord.encode(self,strm) + end + def self.bytesize(arr) ret=0 - for field in self + return 0 if !arr + for field in arr if field==nil || field==true || field==false ret+=1 @@ -285,6 +292,7 @@ return ret end - def encode(strm) - for field in self + def self.encode(arr,strm) + return if !arr + for field in arr if field==nil strm.write("0") @@ -303,5 +311,5 @@ end def self.decode(strm,offset,length) - ret=[] + ret=SerialRecord.new strm.pos=offset while strm.possy ww=sy*ww - wh=416.0 + wh=(Graphics.height-64).to_f() else wh=sx*wh - ww=224.0 + ww=(Graphics.width-256).to_f() end end @sprite.zoom_x=ww*1.0/@sprite.bitmap.width @sprite.zoom_y=wh*1.0/@sprite.bitmap.height - @sprite.x=368-(ww/2) - @sprite.y=192-(wh/2) + @sprite.x=(Graphics.width-((Graphics.width-256)/2))-(ww/2) + @sprite.y=(Graphics.height-((Graphics.height-64)/2))-(wh/2) end end @@ -1652,19 +1652,19 @@ ww=@sprite.bitmap.width wh=@sprite.bitmap.height - sx=224.0/ww - sy=416.0/wh + sx=(Graphics.width-256).to_f()/ww + sy=(Graphics.height-64).to_f()/wh if sx<1.0 || sy<1.0 if sx>sy ww=sy*ww - wh=416.0 + wh=(Graphics.height-64).to_f() else wh=sx*wh - ww=224.0 + ww=(Graphics.width-256).to_f() end end @sprite.zoom_x=ww*1.0/@sprite.bitmap.width @sprite.zoom_y=wh*1.0/@sprite.bitmap.height - @sprite.x=368-(ww/2) - @sprite.y=192-(wh/2) + @sprite.x=(Graphics.width-((Graphics.width-256)/2))-(ww/2) + @sprite.y=(Graphics.height-((Graphics.height-64)/2))-(wh/2) end end @@ -1714,6 +1714,6 @@ return if index==0 && @addGlobalOffset==1 @sprite.bitmap=createMinimap(@maps[index-@addGlobalOffset][0]) - @sprite.x=368-(@sprite.bitmap.width/2) - @sprite.y=192-(@sprite.bitmap.height/2) + @sprite.x=(Graphics.width-((Graphics.width-256)/2))-(@sprite.bitmap.width/2) + @sprite.y=(Graphics.height-((Graphics.height-64)/2))-(@sprite.bitmap.height/2) end end @@ -1757,7 +1757,5 @@ metadata=nil mapinfos=pbLoadRxData("Data/MapInfos") - pbRgssOpen("Data/metadata.dat","rb"){|f| - metadata=Marshal.load(f) - } + metadata=load_data("Data/metadata.dat") map=defaultMapId ? defaultMapId : 0 loop do @@ -1877,4 +1875,7 @@ end end + def defaultValue + return 0 + end def format(value) return value ? @values[value] : value.inspect @@ -2491,7 +2492,5 @@ @mapconns.push(c.clone) end - pbRgssOpen("Data/metadata.dat","rb"){|f| - @metadata=Marshal.load(f) - } + @metadata=load_data("Data/metadata.dat") if $game_map @currentmap=$game_map.map_id @@ -2974,96 +2973,22 @@ ww=@sprite.bitmap.width wh=@sprite.bitmap.height - sx=224.0/ww - sy=416.0/wh + sx=(Graphics.width-256).to_f()/ww + sy=(Graphics.height-64).to_f()/wh if sx<1.0 || sy<1.0 if sx>sy ww=sy*ww - wh=416.0 + wh=(Graphics.height-64).to_f() else wh=sx*wh - ww=224.0 + ww=(Graphics.width-256).to_f() end end @sprite.zoom_x=ww*1.0/@sprite.bitmap.width @sprite.zoom_y=wh*1.0/@sprite.bitmap.height - @sprite.x=368-(ww/2) - @sprite.y=192-(wh/2) + @sprite.x=(Graphics.width-((Graphics.width-256)/2))-(ww/2) + @sprite.y=(Graphics.height-((Graphics.height-64)/2))-(wh/2) end end - -class PokemonLister - def initialize(selection,includeNew) - @sprite=IconSprite.new(0,0) - @sprite.bitmap=nil - @sprite.z=2 - @selection=selection - @commands=[] - @ids=[] - @includeNew=includeNew - @trainers=nil - @index=0 - end - def setViewport(viewport) - @sprite.viewport=viewport - end - def startIndex - return @index - end - def commands - @commands.clear - @ids.clear - if @includeNew - @commands.push(_ISPRINTF("[NEW POKéMON]")) - @ids.push(-1) - end - for i in 1..PBSpecies.maxValue - # Index: TrainerType TrainerName - @commands.push(_ISPRINTF("{1:3d}: {2:s}",i,PBSpecies.getName(i))) - @ids.push(i) - end - @index=@selection - @index=@commands.length-1 if @index>=@commands.length - @index=0 if @index<0 - return @commands - end - def value(index) - return nil if (index<0) - return -1 if index==0 && @includeNew - realIndex=(@includeNew) ? index-1 : index - return realIndex+1 - end - def dispose - @sprite.bitmap.dispose if @sprite.bitmap - @sprite.dispose - end - def refresh(index) - @sprite.bitmap.dispose if @sprite.bitmap - return if index<0 - begin - @sprite.setBitmap(sprintf("Graphics/Battlers/%03d",@ids[index]),0) - rescue - @sprite.setBitmap(nil) - end - ww=@sprite.bitmap.width - wh=@sprite.bitmap.height - sx=224.0/ww - sy=416.0/wh - if sx<1.0 || sy<1.0 - if sx>sy - ww=sy*ww - wh=416.0 - else - wh=sx*wh - ww=224.0 - end - end - @sprite.zoom_x=ww*1.0/@sprite.bitmap.width - @sprite.zoom_y=wh*1.0/@sprite.bitmap.height - @sprite.x=368-(ww/2) - @sprite.y=192-(wh/2) - end -end - module TrainerPokemonProperty def self.set(settingname,oldsetting) @@ -3421,46 +3346,4 @@ _INTL("Special Defense effort values earned when this species is defeated.")], ] - messages=Messages.new("Data/messages.dat") - pbListScreenBlock(_INTL("Pokémon"),PokemonLister.new(selection,true)){|button,trtype| - if trtype - if button==Input::A - elsif button==Input::C - selection=trtype - if selection<0 - Kernel.pbMessage("New Pokémon would be created here.") - # newid=pbTrainerTypeEditorNew(nil) - # if newid>=0 - # selection=newid - # end - else - dexdata=pbOpenDexData - pbDexDataOffset(dexdata,selection,8) - type1=dexdata.fgetb - type2=dexdata.fgetb - base=[ - dexdata.fgetb,dexdata.fgetb,dexdata.fgetb, - dexdata.fgetb,dexdata.fgetb,dexdata.fgetb - ] - pbDexDataOffset(dexdata,selection,31) - compat1=dexdata.fgetb - compat2=dexdata.fgetb - data=[ -messages.get(MessageTypes::Species,selection), -getConstantName(PBSpecies,selection), -messages.get(MessageTypes::Kinds,selection), -messages.get(MessageTypes::Entries,selection), -type1,type2,base[0],base[1],base[2],base[3],base[4],base[5], -0,compat1,compat2,0,0, -0,0,0,0,0,0 - ] - dexdata.close - save=pbPropertyList("Edit Species",data,trainerTypes,true) - # if save - # pbTrainerTypeEditorSave(selection,data) - # end - end - end - end - } end Changed: PokemonField --- Left +++ Right @@ -808,5 +808,5 @@ othertrainer.party=$PokemonGlobal.partner[3] combinedParty=[] - for i in othertrainer.party; i.heal; end + pbHealAll() for i in 0...$Trainer.party.length combinedParty[i]=$Trainer.party[i] @@ -832,7 +832,5 @@ } if $PokemonGlobal.partner - for i in $Trainer.party - i.heal - end + pbHealAll() end if decision==2 @@ -943,5 +941,4 @@ Kernel.pbStartOver } - next end end @@ -1542,7 +1539,5 @@ return end - for i in $Trainer.party - i.heal - end + pbHealAll() if $PokemonGlobal.pokecenterMapId && $PokemonGlobal.pokecenterMapId>=0 if gameover @@ -1552,4 +1547,5 @@ end Kernel.pbCancelVehicles + pbRemoveDependencies() $game_switches[STARTING_OVER_SWITCH]=true $game_temp.player_new_map_id=$PokemonGlobal.pokecenterMapId @@ -1565,7 +1561,5 @@ Kernel.pbMessage(_ISPRINTF("Can't find the map 'Map{1:03d}' in the Data folder. The game will resume at the player's position.",homedata[0])) end - for i in $Trainer.party - i.heal - end + pbHealAll() return end @@ -1577,4 +1571,5 @@ if homedata Kernel.pbCancelVehicles + pbRemoveDependencies() $game_switches[STARTING_OVER_SWITCH]=true $game_temp.player_new_map_id=homedata[0] @@ -1585,7 +1580,5 @@ $game_map.refresh else - for i in $Trainer.party - i.heal - end + pbHealAll() end end @@ -1780,5 +1773,5 @@ def command_314 if pbParams[0] == 0 && $Trainer && $Trainer.party - for i in $Trainer.party; i.heal; end + pbHealAll() end return true Changed: PokemonSummary --- Left +++ Right @@ -784,5 +784,5 @@ if ret>=0 && moveToLearn!=0 && pbIsHiddenMove?(party[partyindex].moves[ret].id) - Kernel.pbMessage(_INTL("HM moves can't be forgotten now.")){ pbUpdate } + Kernel.pbMessage(_INTL("HM moves can't be forgotten now.")){ @scene.pbUpdate } else break Changed: PokemonMart --- Left +++ Right @@ -1,7 +1,170 @@ +# Abstraction layer for Pokemon Essentials +class PokemonMartAdapter + def getMoney + return $Trainer.money + end + def setMoney(value) + $Trainer.money=value + end + def getInventory() + return $PokemonBag + end + def getPrice(item) + return $ItemData[item][ITEMPRICE] + end + def getItemIcon(item) + return !item ? nil : sprintf("Graphics/Icons/item%03d",item) + end + def getItemIconRect(item) + return Rect.new(0,0,48,48) + end + def getDisplayName(item) + itemname=PBItems.getName(item) + if $ItemData[item][ITEMPOCKET]==3 + machine=$ItemData[item][ITEMMACHINE] + itemname=_INTL("{1} {2}",itemname,PBMoves.getName(machine)) + end + return itemname + end + def getName(item) + return PBItems.getName(item) + end + def getDisplayPrice(item) + price=getPrice(item) + return _ISPRINTF("${1:d}",price) + end + def getDescription(item) + return pbGetMessage(MessageTypes::ItemDescriptions,item) + end + def addItem(item) + return $PokemonBag.pbStoreItem(item) + end + def getQuantity(item) + return $PokemonBag.pbQuantity(item) + end + def canSell?(item) + return getPrice(item)>0 && !pbIsImportantItem?(item) + end + def removeItem(item) + return $PokemonBag.pbDeleteItem(item) + end +end - def pbGetPrice(item) - return $ItemData[item][ITEMPRICE] +# Abstraction layer for RPG Maker XP/VX + class RpgxpMartAdapter + def getMoney + return $game_party.gold + end + def setMoney(value) + $game_party.gain_gold(-$game_party.gold) + $game_party.gain_gold(value) + end + def getPrice(item) + return item.price + end + def getItemIcon(item) + if !item || item==0 + return nil + elsif item.respond_to?("icon_index") + return "Graphics/System/IconSet" + else + return sprintf("Graphics/Icons/%s",item.icon_name) + end + end + def getItemIconRect(item) + if item && item.respond_to?("icon_index") + ix=item.icon_index % 16 * 24 + iy=item.icon_index / 16 * 24 + return Rect.new(ix,iy,24,24) + else + return Rect.new(0,0,32,32) + end + end + def getInventory() + data = [] + for i in 1...$data_items.size + if getQuantity($data_items[i]) > 0 + data.push($data_items[i]) + end + end + for i in 1...$data_weapons.size + if getQuantity($data_weapons[i]) > 0 + data.push($data_weapons[i]) + end + end + for i in 1...$data_armors.size + if getQuantity($data_armors[i]) > 0 + data.push($data_armors[i]) + end + end + return data + end + def canSell?(item) + return item ? item.price>0 : false + end + def getName(item) + return item ? item.name : "" + end + def getDisplayName(item) + return item ? item.name : "" + end + def getDisplayPrice(item) + price=item.price + return _ISPRINTF("{1:d}",price) + end + def getDescription(item) + return item ? item.description : "" + end + def addItem(item) + ret=(getQuantity(item)<99) + if $game_party.respond_to?("gain_weapon") + case item + when RPG::Item + $game_party.gain_item(item.id, 1) if ret + when RPG::Weapon + $game_party.gain_weapon(item.id, 1) if ret + when RPG::Armor + $game_party.gain_armor(item.id, 1) if ret + end + else + $game_party.gain_item(item,1) if ret + end + return ret + end + def getQuantity(item) + ret=0 + if $game_party.respond_to?("weapon_number") + case item + when RPG::Item + ret=$game_party.item_number(item.id) + when RPG::Weapon + ret=($game_party.weapon_number(item.id)) + when RPG::Armor + ret=($game_party.armor_number(item.id)) + end + else + return $game_party.item_number(item) + end + return ret + end + def removeItem(item) + ret=(getQuantity(item)>0) + if $game_party.respond_to?("lose_weapon") + case item + when RPG::Item + $game_party.lose_item(item.id, 1) if ret + when RPG::Weapon + $game_party.lose_weapon(item.id, 1) if ret + when RPG::Armor + $game_party.lose_armor(item.id, 1) if ret + end + else + $game_party.lose_item(item,1) if ret + end + return ret + end end + ################### @@ -9,7 +172,8 @@ attr_reader :baseColor attr_reader :shadowColor - def initialize(stock,x,y,width,height) + def initialize(stock,adapter,x,y,width,height) super(x,y,width,height) @stock=stock + @adapter=adapter self.windowskin=nil @selarrow=AnimatedBitmap.new("Graphics/Pictures/selarrow") @@ -51,10 +215,13 @@ dheight=self.height-self.borderY self.contents=pbDoEnsureBitmap(self.contents,dwidth,dheight) - @uparrow.x=self.x+(self.width/2)-(@uparrow.framewidth/2) + + +@uparrow.x=self.x+(self.width/2)-(@uparrow.framewidth/2) @downarrow.x=self.x+(self.width/2)-(@downarrow.framewidth/2) @uparrow.y=self.y @downarrow.y=self.y+self.height-@downarrow.frameheight @uparrow.visible=self.active && (self.top_row!=0 && @item_max > self.page_item_max) - @downarrow.visible=self.active && (self.top_row+self.page_item_max<@item_max && @item_max > self.page_item_max) + @downarrow.visible=self.active && (self.top_row+self.page_item_max<@item_max && + @item_max > self.page_item_max) @uparrow.viewport=self.viewport @downarrow.viewport=self.viewport @@ -73,11 +240,6 @@ else item=thispocket[i] - itemname=PBItems.getName(item) - if $ItemData[item][ITEMPOCKET]==3 - machine=$ItemData[item][ITEMMACHINE] - itemname=_INTL("{1} {2}",itemname,PBMoves.getName(machine)) - end - price=Kernel.pbGetPrice(item) - qty=_ISPRINTF("${1:d}",price) + itemname=@adapter.getDisplayName(item) + qty=@adapter.getDisplayPrice(item) sizeQty=self.contents.text_size(qty).width xQty=contentsWidth-sizeQty-2 @@ -99,7 +261,30 @@ end +class BuyAdapter + def initialize(adapter) + @adapter=adapter + end + def getDisplayName(item) + @adapter.getDisplayName(item) + end + def getDisplayPrice(item) + @adapter.getDisplayPrice(item) + end +end +class SellAdapter + def initialize(adapter) + @adapter=adapter + end + def getDisplayName(item) + @adapter.getDisplayName(item) + end + def getDisplayPrice(item) + sprintf("x%d",@adapter.getQuantity(item)) + end +end + class PokemonMartScene @@ -113,9 +298,9 @@ ret=0 helpwindow=@sprites["helpwindow"] - itemprice=pbGetPrice(item) + itemprice=@adapter.getPrice(item) itemprice/=2 if !@buying pbDisplay(helptext,true) using(numwindow=Window_AdvancedTextPokemon.new("")){ # Showing number of items - qty=$PokemonBag.pbQuantity(item) + qty=@adapter.getQuantity(item) using(inbagwindow=Window_UnformattedTextPokemon.new("")){ # Showing quantity in bag pbPrepareWindow(numwindow) @@ -123,9 +308,9 @@ numwindow.viewport=@viewport inbagwindow.visible=@buying - numwindow.resizeToFit(_INTL("x000 $000000"),480) + numwindow.resizeToFit(_INTL("x000 $000000"),Graphics.width) inbagwindow.viewport=@viewport inbagwindow.text=_ISPRINTF("IN BAG: {1:d}",qty) - inbagwindow.resizeToFit(inbagwindow.text,480) - numwindow.text=_ISPRINTF("x{1:03d} ${2:d}",curnumber,curnumber*itemprice) + inbagwindow.resizeToFit(inbagwindow.text,Graphics.width) + numwindow.text=_ISPRINTF("x{1:03d}${2:d}",curnumber,curnumber*itemprice) pbBottomRight(numwindow) numwindow.y-=helpwindow.height @@ -181,5 +366,5 @@ end -def pbStartBuyScene(stock) +def pbStartBuyOrSellScene(buying,stock,adapter) # Scroll right before showing screen pbScrollMap(6,5,5) @@ -187,9 +372,12 @@ @viewport.z=99999 @stock=stock + @adapter=adapter @sprites={} @sprites["background"]=IconSprite.new(0,0,@viewport) @sprites["background"].setBitmap("Graphics/Pictures/martscreen") @sprites["icon"]=IconSprite.new(16,Graphics.height-72,@viewport) - @sprites["itemwindow"]=Window_PokemonMart.new(stock,160,0,304,224) + winAdapter=buying ? BuyAdapter.new(adapter) : SellAdapter.new(adapter) + @sprites["itemwindow"]=Window_PokemonMart.new(stock,winAdapter, + Graphics.width-304-16,0,304,Graphics.height-96) @sprites["itemwindow"].viewport=@viewport @sprites["itemwindow"].index=0 @@ -198,5 +386,5 @@ pbPrepareWindow(@sprites["itemtextwindow"]) @sprites["itemtextwindow"].x=64 - @sprites["itemtextwindow"].y=208 + @sprites["itemtextwindow"].y=Graphics.height-96-16 @sprites["itemtextwindow"].width=Graphics.width-64 @sprites["itemtextwindow"].height=128 @@ -220,11 +408,32 @@ @sprites["moneywindow"].height=96 pbDeactivateWindows(@sprites) - @buying=true + @buying=buying pbRefresh Graphics.frame_reset end -def pbStartSellScene(bag) +def pbStartBuyScene(stock,adapter) + pbStartBuyOrSellScene(true,stock,adapter) +end + +def pbStartSellScene(bag,adapter) + if $PokemonBag + pbStartSellScene2(bag,adapter) + else + pbStartBuyOrSellScene(false,bag,adapter) + end +end + +def pbStartSellScene2(bag,adapter) @subscene=PokemonBag_Scene.new + @adapter=adapter + @viewport2=Viewport.new(0,0,Graphics.width,Graphics.height) + @viewport2.z=99999 + for j in 0..17 + col=Color.new(0,0,0,j*15) + @viewport2.color=col + Graphics.update + Input.update + end @subscene.pbStartScene(bag) @viewport=Viewport.new(0,0,Graphics.width,Graphics.height) @@ -267,7 +476,21 @@ def pbEndSellScene + if @subscene + @subscene.pbEndScene + end pbDisposeSpriteHash(@sprites) - @subscene.pbEndScene + if @viewport2 + for j in 0..17 + col=Color.new(0,0,0,(17-j)*15) + @viewport2.color=col + Graphics.update + Input.update + end + @viewport2.dispose + end @viewport.dispose + if !@subscene + pbScrollMap(4,5,5) + end end @@ -357,13 +580,14 @@ def pbRefresh - if @buying + if !@subscene itemwindow=@sprites["itemwindow"] - filename=sprintf("Graphics/Icons/item%03d",itemwindow.item) + filename=@adapter.getItemIcon(itemwindow.item) @sprites["icon"].setBitmap(filename) + @sprites["icon"].src_rect=@adapter.getItemIconRect(itemwindow.item) @sprites["itemtextwindow"].text=(itemwindow.item==0) ? _INTL("Quit shopping.") : - pbGetMessage(MessageTypes::ItemDescriptions,itemwindow.item) + @adapter.getDescription(itemwindow.item) itemwindow.refresh end - @sprites["moneywindow"].text=_INTL("MONEY:\r\n${1}",$Trainer.money) + @sprites["moneywindow"].text=_INTL("MONEY:\r\n${1}",@adapter.getMoney()) end @@ -379,8 +603,9 @@ self.update if itemwindow.item!=olditem - filename=sprintf("Graphics/Icons/item%03d",itemwindow.item) + filename=@adapter.getItemIcon(itemwindow.item) @sprites["icon"].setBitmap(filename) + @sprites["icon"].src_rect=@adapter.getItemIconRect(itemwindow.item) @sprites["itemtextwindow"].text=(itemwindow.item==0) ? _INTL("Quit shopping.") : - pbGetMessage(MessageTypes::ItemDescriptions,itemwindow.item) + @adapter.getDescription(itemwindow.item) end if Input.trigger?(Input::B) @@ -400,13 +625,20 @@ def pbChooseSellItem - return @subscene.pbChooseItem + if @subscene + return @subscene.pbChooseItem + else + return pbChooseBuyItem + end end end +####################################################### + class PokemonMartScreen def initialize(scene,stock) @scene=scene @stock=stock + @adapter=$PokemonBag ? PokemonMartAdapter.new : RpgxpMartAdapter.new end def pbConfirm(msg) @@ -420,18 +652,19 @@ end def pbBuyScreen - @scene.pbStartBuyScene(@stock) + @scene.pbStartBuyScene(@stock,@adapter) item=0 loop do item=@scene.pbChooseBuyItem break if item==0 - itemname=PBItems.getName(item) - price=Kernel.pbGetPrice(item) - if $Trainer.money99 - quantity=@scene.pbChooseNumber(_INTL("{1}? Certainly.\r\nHow many would you like?",itemname),item,maxafford) + quantity=@scene.pbChooseNumber( + _INTL("{1}? Certainly.\r\nHow many would you like?",itemname),item,maxafford) if quantity==0 next @@ -441,5 +674,5 @@ next end - if $Trainer.money=10 && isConst?(item,PBItems,:POKeBALL) && hasConst?(PBItems,:PREMIERBALL) - if $PokemonBag.pbStoreItem(getConst(PBItems,:PREMIERBALL)) - pbDisplayPaused(_INTL("I'll throw in a Premier Ball, too.")) + if $PokemonBag + if quantity>=10 && isConst?(item,PBItems,:POKeBALL) && + hasConst?(PBItems,:PREMIERBALL) + if @adapter.addItem(getConst(PBItems,:PREMIERBALL)) + pbDisplayPaused(_INTL("I'll throw in a Premier Ball, too.")) + end end end @@ -472,19 +708,15 @@ end def pbSellScreen - item=@scene.pbStartSellScene($PokemonBag) + item=@scene.pbStartSellScene(@adapter.getInventory,@adapter) loop do item=@scene.pbChooseSellItem break if item==0 - itemname=PBItems.getName(item) - price=Kernel.pbGetPrice(item) - if price==0 + itemname=@adapter.getName(item) + price=@adapter.getPrice(item) + if !@adapter.canSell?(item) pbDisplayPaused(_INTL("{1}? Oh, no.\r\nI can't buy that.",itemname)) next end - if pbIsImportantItem?(item) - pbDisplayPaused(_INTL("{1}? Oh, no.\r\nI can't buy that.",itemname)) - next - end - qty=$PokemonBag.pbQuantity(item) + qty=@adapter.getQuantity(item) next if qty==0 @scene.pbShowMoney @@ -501,6 +733,8 @@ price*=qty if pbConfirm(_INTL("I can pay ${1}.\r\nWould that be OK?",price)) - $Trainer.money+=price - $PokemonBag.pbDeleteItem(item,qty) + @adapter.setMoney(@adapter.getMoney()+price) + for i in 0...qty + @adapter.removeItem(item) + end pbDisplayPaused(_INTL("Turned over the {1} and received ${2}.",itemname,price)) end @@ -512,21 +746,25 @@ -def pbPokemonMart(stock,speech=nil) +def pbPokemonMart(stock,speech=nil,cantsell=false) + commands=[] + cmdBuy=-1 + cmdSell=-1 + cmdQuit=-1 + commands[cmdBuy=commands.length]=_INTL("BUY") + commands[cmdSell=commands.length]=_INTL("SELL") if !cantsell + commands[cmdQuit=commands.length]=_INTL("QUIT") cmd=Kernel.pbMessage( - speech ? speech : _INTL("Welcome!\r\nHow may I serve you?"), - [_INTL("BUY"),_INTL("SELL"),_INTL("QUIT")],3) + speech ? speech : _INTL("Welcome!\r\nHow may I serve you?"), + commands,cmdQuit+1) loop do - case cmd - when 0# Buy + if cmdBuy>=0 && cmd==cmdBuy scene=PokemonMartScene.new screen=PokemonMartScreen.new(scene,stock) screen.pbBuyScreen - when 1 # Sell - pbFadeOutIn(99999){ - scene=PokemonMartScene.new - screen=PokemonMartScreen.new(scene,stock) - screen.pbSellScreen - } - when 2 + elsif cmdSell>=0 && cmd==cmdSell + scene=PokemonMartScene.new + screen=PokemonMartScreen.new(scene,stock) + screen.pbSellScreen + else Kernel.pbMessage(_INTL("Please come again!")) break @@ -534,5 +772,65 @@ cmd=Kernel.pbMessage( _INTL("Is there anything else I can help you with?"), - [_INTL("BUY"),_INTL("SELL"),_INTL("QUIT")],3) + commands,cmdQuit+1) end +end + +class Interpreter + def getItem(p) + if p[0]==0 + return $data_items[p[1]] + elsif p[0]==1 + return $data_weapons[p[1]] + elsif p[0]==2 + return $data_armors[p[1]] + end + return nil + end + def command_302 + $game_temp.battle_abort = true + shop_goods = [getItem(@parameters)] + # Loop + loop do + # Advance index + @index += 1 + # If next event command has shop on second line or after + if @list[@index].code == 605 + # Add goods list to new item + shop_goods.push(getItem(@list[@index].parameters)) + else + # End + pbPokemonMart(shop_goods.compact) + return true + end + end + end +end +class Game_Interpreter + def getItem(p) + if p[0]==0 + return $data_items[p[1]] + elsif p[0]==1 + return $data_weapons[p[1]] + elsif p[0]==2 + return $data_armors[p[1]] + end + return nil + end + def command_302 + shop_goods = [getItem(@params)] + # Loop + loop do + # Advance index + @index += 1 + # If next event command has shop on second line or after + if @list[@index].code == 605 + # Add goods list to new item + shop_goods.push(getItem(@list[@index].parameters)) + else + # End + pbPokemonMart(shop_goods.compact,nil,@params[2]) + return true + end + end + end end Changed: DependentEvents --- Left +++ Right @@ -8,4 +8,9 @@ end +def pbRemoveDependencies() + $PokemonTemp.dependentEvents.removeAllEvents() + pbDeregisterPartner() rescue nil +end + def pbAddDependency(event) $PokemonTemp.dependentEvents.addEvent(event) @@ -442,4 +447,10 @@ end return nil + end + def removeAllEvents + events=$PokemonGlobal.dependentEvents + events.clear + @realEvents.clear + @lastUpdate+=1 end def removeEventByName(name)