Advertisement
Clara_Dragon

Triple Triad Rebalanceado y por monedas

Feb 18th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 39.98 KB | None | 0 0
  1. ################################################################################
  2. # "Triple Triad" mini-game
  3. # By Unknown
  4. ################################################################################
  5. class TriadCard
  6.   attr_reader :north, :east, :south, :west, :type, :species
  7.  
  8.   def baseStatToValue(stat)
  9.     return 10 if stat>=200
  10.     return 9 if stat>=170
  11.     return 8 if stat>=150
  12.     return 7 if stat>=120
  13.     return 6 if stat>=100
  14.     return 5 if stat>=70
  15.     return 4 if stat>=50
  16.     return 3 if stat>=20
  17.     return 2 if stat>=10
  18.     return 1
  19.   end
  20.  
  21.   def attack(panel)
  22.     return [@west,@east,@north,@south][panel]
  23.   end
  24.  
  25.   def defense(panel)
  26.     return [@east,@west,@south,@north][panel]
  27.   end
  28.  
  29.   def price
  30.     maxvalue=[@west,@east,@north,@south].max
  31.     return [
  32.        100,100,100,100,500,500,1000,1500,1500,1500,2000
  33.     ][maxvalue]
  34.   end
  35.  
  36.   def bonus(opponent)
  37.     atype=@type
  38.     otype=opponent.type
  39.     mod=PBTypes.getEffectiveness(atype,otype)
  40.     return -2 if mod==0
  41.     return -1 if mod==1
  42.     return 1 if mod==4
  43.     return 0
  44.   end
  45.  
  46.   def initialize(species)
  47.     dexdata=pbOpenDexData
  48.     @species=species
  49.     pbDexDataOffset(dexdata,species,10)
  50.     dexdata.fgetb # HP
  51.     @west=baseStatToValue(dexdata.fgetb) # Attack
  52.     @east=baseStatToValue(dexdata.fgetb) # Defense
  53.     dexdata.fgetb # Speed
  54.     @north=baseStatToValue(dexdata.fgetb) # Special Attack
  55.     @south=baseStatToValue(dexdata.fgetb) # Special Defense
  56.     pbDexDataOffset(dexdata,species,8)
  57.     @type=dexdata.fgetb # Type
  58.     if isConst?(@type,PBTypes,:NORMAL)
  59.       type2=dexdata.fgetb
  60.       @type=type2 if !isConst?(type2,PBTypes,:NORMAL)
  61.     end
  62.     dexdata.close
  63.   end
  64.  
  65.   def self.createBack(type=-1,noback=false)
  66.     bitmap=BitmapWrapper.new(84,84)
  67.     if !noback
  68.       bitmap.fill_rect(0,0,84,84,Color.new(210,67,40))
  69.       bitmap.fill_rect(2,2,80,80,Color.new(232,88,56))
  70.     end
  71.     if type>=0
  72.       typebitmap=AnimatedBitmap.new(_INTL("Graphics/Pictures/types"))
  73.       typerect=Rect.new(0,type*28,64,28)
  74.       bitmap.blt(10,28,typebitmap.bitmap,typerect,192)
  75.       typebitmap.dispose
  76.     end
  77.     return bitmap
  78.   end
  79.  
  80.   def createBitmap(owner)
  81.     if owner==0
  82.       return TriadCard.createBack
  83.     end
  84.     bitmap=BitmapWrapper.new(84,84)
  85.     iconfile=pbCheckPokemonIconFiles([@species,0,false,0,false])
  86.     typebitmap=AnimatedBitmap.new(_INTL("Graphics/Pictures/types"))
  87.     icon=AnimatedBitmap.new(iconfile)
  88.     typerect=Rect.new(0,@type*28,64,28)
  89.     if owner==2
  90.       # opponent
  91.       bitmap.fill_rect(0,0,84,84,Color.new(210,67,40))
  92.       bitmap.fill_rect(2,2,80,80,Color.new(232,88,56))
  93.     else
  94.       # player
  95.       bitmap.fill_rect(0,0,84,84,Color.new(58,58,80))
  96.       bitmap.fill_rect(2,2,80,80,Color.new(80,80,104))
  97.     end
  98.     bitmap.blt(10,28,typebitmap.bitmap,typerect,192)
  99.     bitmap.blt(10,2,icon.bitmap,Rect.new(0,0,64,64))
  100.     pbSetSmallFont(bitmap)
  101.     pbDrawTextPositions(bitmap,[
  102.        ["0123456789A"[@north,1],84/2,2,2,Color.new(248,248,248),Color.new(96,96,96)],
  103.        ["0123456789A"[@south,1],84/2,82-25,2,Color.new(248,248,248),Color.new(96,96,96)],
  104.        ["0123456789A"[@west,1],2,(84/2)-12,0,Color.new(248,248,248),Color.new(96,96,96)],
  105.        ["0123456789A"[@east,1],82,(84/2)-12,1,Color.new(248,248,248),Color.new(96,96,96)]
  106.     ])
  107.     icon.dispose
  108.     typebitmap.dispose
  109.     return bitmap
  110.   end
  111. end
  112.  
  113.  
  114.  
  115. class TriadSquare
  116.   attr_accessor :owner, :card, :type
  117.  
  118.   def initialize
  119.     @owner=0
  120.     @card=nil
  121.     @type=-1
  122.   end
  123.  
  124.   def attack(panel)
  125.     return @card.attack(panel)
  126.   end
  127.  
  128.   def bonus(square)
  129.     return @card.bonus(square.card)
  130.   end
  131.  
  132.   def defense(panel)
  133.     return @card.defense(panel)
  134.   end
  135. end
  136.  
  137.  
  138.  
  139. # Scene class for handling appearance of the screen
  140. class TriadScene
  141. # Update the scene here, this is called once each frame
  142.   def pbUpdate
  143.     pbUpdateSpriteHash(@sprites)
  144.   end
  145.  
  146. # End the scene here
  147.   def pbEndScene
  148.     pbBGMFade(1.0)
  149.     # Fade out all sprites
  150.     pbFadeOutAndHide(@sprites) { pbUpdate }
  151.     # Dispose all sprites
  152.     pbDisposeSpriteHash(@sprites)
  153.     @bitmaps.each{|bm| bm.dispose }
  154.     # Dispose the viewport
  155.     @viewport.dispose
  156.   end
  157.  
  158.   def pbStartScene(battle)
  159.     # Create sprite hash
  160.     @sprites={}
  161.     @bitmaps=[]
  162.     @battle=battle
  163.     # Allocate viewport
  164.     @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  165.     @viewport.z=99999
  166.     addBackgroundPlane(@sprites,"background","triadbg",@viewport)
  167.     @sprites["helpwindow"]=Window_AdvancedTextPokemon.newWithSize("",
  168.        0,Graphics.height-64,Graphics.width,64,@viewport)
  169.     for i in 0...@battle.width*@battle.height
  170.       @sprites["sprite#{i}"]=SpriteWrapper.new(@viewport)
  171.       cardX=Graphics.width/2 - 126 + (i%3)*84
  172.       cardY=46 + (i/3)*84
  173.       @sprites["sprite#{i}"].z=2
  174.       @sprites["sprite#{i}"].x=cardX
  175.       @sprites["sprite#{i}"].y=cardY
  176.       bm=TriadCard.createBack(@battle.board[i].type,true)
  177.       @bitmaps.push(bm)
  178.       @sprites["sprite#{i}"].bitmap=bm
  179.     end
  180.     @cardBitmaps=[]
  181.     @opponentCardBitmaps=[]
  182.     @cardIndexes=[]
  183.     @opponentCardIndexes=[]
  184.     @boardSprites=[]
  185.     @boardCards=[]
  186.     for i in 0...@battle.maxCards
  187.       @sprites["player#{i}"]=Sprite.new(@viewport)
  188.       @sprites["player#{i}"].z=2
  189.       @sprites["player#{i}"].x=Graphics.width-96
  190.       @sprites["player#{i}"].y=40+16*i
  191.       @cardIndexes.push(i)
  192.     end
  193.     @sprites["overlay"]=Sprite.new(@viewport)
  194.     @sprites["overlay"].bitmap=BitmapWrapper.new(Graphics.width,Graphics.height)
  195.     pbSetSystemFont(@sprites["overlay"].bitmap)
  196.     pbDrawTextPositions(@sprites["overlay"].bitmap,[
  197.        [@battle.opponentName,54,0,2,Color.new(248,248,248),Color.new(96,96,96)],
  198.        [@battle.playerName,Graphics.width-54,0,2,Color.new(248,248,248),Color.new(96,96,96)]
  199.     ])
  200.     @sprites["score"]=Sprite.new(@viewport)
  201.     @sprites["score"].bitmap=BitmapWrapper.new(Graphics.width,Graphics.height)
  202.     pbSetSystemFont(@sprites["score"].bitmap)
  203.     pbBGMPlay("Polemon")
  204.     # Fade in all sprites
  205.     pbFadeInAndShow(@sprites) { pbUpdate }
  206.   end
  207.  
  208.   def pbUpdateScore
  209.     bitmap=@sprites["score"].bitmap
  210.     bitmap.clear
  211.     playerscore=0
  212.     oppscore=0
  213.     for i in 0...@battle.width*@battle.height
  214.       if @boardSprites[i]
  215.         playerscore+=1 if @battle.board[i].owner==1
  216.         oppscore+=1 if @battle.board[i].owner==2
  217.       end
  218.     end
  219.     if @battle.countUnplayedCards
  220.       playerscore+=@cardIndexes.length
  221.       oppscore+=@opponentCardIndexes.length
  222.     end
  223.     pbDrawTextPositions(bitmap,[
  224.        [_INTL("{1}-{2}",oppscore,playerscore),Graphics.width/2,0,2,Color.new(248,248,248),Color.new(96,96,96)]
  225.     ])
  226.   end
  227.  
  228.   def pbNotifyCards(playerCards,opponentCards)
  229.     @playerCards=playerCards
  230.     @opponentCards=opponentCards
  231.   end
  232.  
  233.   def pbDisplay(text)
  234.     @sprites["helpwindow"].text=text
  235.     60.times do
  236.       Graphics.update
  237.       Input.update
  238.       pbUpdate
  239.     end
  240.   end
  241.  
  242.   def pbDisplayPaused(text)
  243.     @sprites["helpwindow"].letterbyletter=true
  244.     @sprites["helpwindow"].text=text+"\1"
  245.     loop do
  246.       Graphics.update
  247.       Input.update
  248.       pbUpdate
  249.       if Input.trigger?(Input::C)
  250.         if @sprites["helpwindow"].busy?
  251.           pbPlayDecisionSE() if @sprites["helpwindow"].pausing?
  252.           @sprites["helpwindow"].resume
  253.         else
  254.           break
  255.         end
  256.       end
  257.     end
  258.     @sprites["helpwindow"].letterbyletter=false
  259.     @sprites["helpwindow"].text=""
  260.   end
  261.  
  262.   def pbShowPlayerCards(cards)
  263.     for i in 0...@battle.maxCards
  264.       @sprites["player#{i}"]=Sprite.new(@viewport)
  265.       @sprites["player#{i}"].z=2
  266.       @sprites["player#{i}"].x=Graphics.width-96
  267.       @sprites["player#{i}"].y=34+48*i
  268.       @sprites["player#{i}"].bitmap=TriadCard.new(cards[i]).createBitmap(1)
  269.       @cardBitmaps.push(@sprites["player#{i}"].bitmap)
  270.     end
  271.   end
  272.  
  273.   def pbShowOpponentCards(cards)
  274.     for i in 0...@battle.maxCards
  275.       @sprites["opponent#{i}"]=Sprite.new(@viewport)
  276.       @sprites["opponent#{i}"].z=2
  277.       @sprites["opponent#{i}"].x=12
  278.       @sprites["opponent#{i}"].y=34+48*i
  279.       @sprites["opponent#{i}"].bitmap=@battle.openHand ? TriadCard.new(cards[i]).createBitmap(2) : TriadCard.createBack(-1)
  280.       @opponentCardBitmaps.push(@sprites["opponent#{i}"].bitmap)
  281.       @opponentCardIndexes.push(i)
  282.     end
  283.   end
  284.  
  285.   def pbViewOpponentCards(numCards)
  286.     @sprites["helpwindow"].text=_INTL("Comprueba las cartas del oponente.")
  287.     choice=0
  288.     lastChoice=-1
  289.     loop do
  290.       if lastChoice!=choice
  291.         y=34
  292.         for i in 0...@opponentCardIndexes.length
  293.           @sprites["opponent#{@opponentCardIndexes[i]}"].bitmap=@opponentCardBitmaps[@opponentCardIndexes[i]]
  294.           @sprites["opponent#{@opponentCardIndexes[i]}"].z=(i==choice) ? 4 : 2
  295.           @sprites["opponent#{@opponentCardIndexes[i]}"].x=(i==choice) ? 34 : 12
  296.           @sprites["opponent#{@opponentCardIndexes[i]}"].y=y
  297.           y+=48
  298.         end
  299.         lastChoice=choice
  300.       end
  301.       if choice==-1
  302.         break
  303.       end
  304.       Graphics.update
  305.       Input.update
  306.       pbUpdate
  307.       if Input.repeat?(Input::DOWN)
  308.         pbPlayCursorSE()
  309.         choice+=1
  310.         choice=0 if choice>=numCards
  311.       elsif Input.repeat?(Input::UP)
  312.         pbPlayCursorSE()
  313.         choice-=1
  314.         choice=numCards-1 if choice<0
  315.       elsif Input.trigger?(Input::B)
  316.         pbPlayCancelSE()
  317.         choice=-1
  318.       end
  319.     end
  320.     return choice
  321.   end
  322.  
  323.   def pbPlayerChooseCard(numCards)
  324.     if @battle.openHand
  325.       @sprites["helpwindow"].text=_INTL("Escoge una carta o comprueba las del oponente con Z.")
  326.     else
  327.       @sprites["helpwindow"].text=_INTL("Escoge una carta.")
  328.     end
  329.     choice=0
  330.     lastChoice=-1
  331.     loop do
  332.       if lastChoice!=choice
  333.         y=34
  334.         for i in 0...@cardIndexes.length
  335.           @sprites["player#{@cardIndexes[i]}"].bitmap=@cardBitmaps[@cardIndexes[i]]
  336.           @sprites["player#{@cardIndexes[i]}"].z=(i==choice) ? 4 : 2
  337.           @sprites["player#{@cardIndexes[i]}"].x=(i==choice) ? Graphics.width-118 : Graphics.width-96
  338.           @sprites["player#{@cardIndexes[i]}"].y=y
  339.           y+=48
  340.         end
  341.         lastChoice=choice
  342.       end
  343.       Graphics.update
  344.       Input.update
  345.       pbUpdate
  346.       if Input.repeat?(Input::DOWN)
  347.         pbPlayCursorSE()
  348.         choice+=1
  349.         choice=0 if choice>=numCards
  350.       elsif Input.repeat?(Input::UP)
  351.         pbPlayCursorSE()
  352.         choice-=1
  353.         choice=numCards-1 if choice<0
  354.       elsif Input.trigger?(Input::C)
  355.         pbPlayDecisionSE()
  356.         break
  357.       elsif Input.trigger?(Input::A) && @battle.openHand
  358.         pbPlayDecisionSE()
  359.         pbViewOpponentCards(numCards)
  360.         @sprites["helpwindow"].text=_INTL("Escoge una carta o comprueba las del oponente con Z.")
  361.         choice=0
  362.         lastChoice=-1
  363.       end
  364.     end
  365.     return choice
  366.   end
  367.  
  368.   def pbRefresh
  369.     for i in 0...@battle.width*@battle.height
  370.       x=i%@battle.width
  371.       y=i/@battle.width
  372.       if @boardSprites[i]
  373.         owner=@battle.getOwner(x,y)
  374.         @boardSprites[i].bitmap.dispose if @boardSprites[i].bitmap
  375.         @boardSprites[i].bitmap=@boardCards[i].createBitmap(owner)
  376.       end
  377.     end
  378.   end
  379.  
  380.   def pbEndPlaceCard(position, cardIndex)
  381.     spriteIndex=@cardIndexes[cardIndex]
  382.     boardIndex=position[1]*@battle.width+position[0]
  383.     @boardSprites[boardIndex]=@sprites["player#{spriteIndex}"]
  384.     @boardCards[boardIndex]=TriadCard.new(@playerCards[spriteIndex])
  385.     pbRefresh
  386.     @cardIndexes.delete_at(cardIndex)
  387.     pbUpdateScore
  388.   end
  389.  
  390.   def pbEndOpponentPlaceCard(position, cardIndex)
  391.     spriteIndex=@opponentCardIndexes[cardIndex]
  392.     boardIndex=position[1]*@battle.width+position[0]
  393.     @boardSprites[boardIndex]=@sprites["opponent#{spriteIndex}"]
  394.     @boardCards[boardIndex]=TriadCard.new(@opponentCards[spriteIndex])
  395.     pbRefresh
  396.     @opponentCardIndexes.delete_at(cardIndex)
  397.     pbUpdateScore
  398.   end
  399.  
  400.   def pbOpponentPlaceCard(triadCard, position, cardIndex)
  401.     y=34
  402.     for i in 0...@opponentCardIndexes.length
  403.       sprite=@sprites["opponent#{@opponentCardIndexes[i]}"]
  404.       if i!=cardIndex
  405.         sprite.z=2
  406.         sprite.y=y
  407.         sprite.x=12
  408.         y+=48
  409.       else
  410.         @opponentCardBitmaps[@opponentCardIndexes[i]]=triadCard.createBitmap(2)
  411.         sprite.bitmap.dispose if sprite.bitmap
  412.         sprite.bitmap=@opponentCardBitmaps[@opponentCardIndexes[i]]
  413.         sprite.z=2
  414.         sprite.x=Graphics.width/2 - 126 + position[0]*84
  415.         sprite.y=46 + position[1]*84
  416.       end
  417.     end
  418.   end
  419.  
  420.   def pbPlayerPlaceCard(card, cardIndex)
  421.     @sprites["helpwindow"].text=_INTL("Place the card.")
  422.     choice=0
  423.     boardX=0
  424.     boardY=0
  425.     doRefresh=true
  426.     loop do
  427.       if doRefresh
  428.         y=34
  429.         for i in 0...@cardIndexes.length
  430.           if i!=cardIndex
  431.             @sprites["player#{@cardIndexes[i]}"].z=2
  432.             @sprites["player#{@cardIndexes[i]}"].y=y
  433.             @sprites["player#{@cardIndexes[i]}"].x=Graphics.width-96
  434.             y+=48
  435.           else
  436.             @sprites["player#{@cardIndexes[i]}"].z=4
  437.             @sprites["player#{@cardIndexes[i]}"].x=Graphics.width/2 - 126 + boardX*84
  438.             @sprites["player#{@cardIndexes[i]}"].y=46 + boardY*84
  439.           end
  440.         end
  441.         doRefresh=false
  442.       end
  443.       Graphics.update
  444.       Input.update
  445.       pbUpdate
  446.       if Input.repeat?(Input::DOWN)
  447.         pbPlayCursorSE()
  448.         boardY+=1
  449.         boardY=0 if boardY>=@battle.height
  450.         doRefresh=true
  451.       elsif Input.repeat?(Input::UP)
  452.         pbPlayCursorSE()
  453.         boardY-=1
  454.         boardY=@battle.height-1 if boardY<0
  455.         doRefresh=true
  456.       elsif Input.repeat?(Input::LEFT)
  457.         pbPlayCursorSE()
  458.         boardX-=1
  459.         boardX=@battle.width-1 if boardX<0
  460.         doRefresh=true
  461.       elsif Input.repeat?(Input::RIGHT)
  462.         pbPlayCursorSE()
  463.         boardX+=1
  464.         boardX=0 if boardX>=@battle.width
  465.         doRefresh=true
  466.       elsif Input.trigger?(Input::B)
  467.         return nil
  468.       elsif Input.trigger?(Input::C)
  469.         if @battle.isOccupied?(boardX,boardY)
  470.           pbPlayBuzzerSE()
  471.         else
  472.           pbPlayDecisionSE()
  473.           @sprites["player#{@cardIndexes[cardIndex]}"].z=2
  474.           break
  475.         end
  476.       end
  477.     end
  478.     return [boardX,boardY]
  479.   end
  480.  
  481.   def pbChooseTriadCard(cardStorage)
  482.     commands=[]
  483.     chosenCards=[]
  484.     for item in cardStorage
  485.       commands.push(_INTL("{1} x{2}",PBSpecies.getName(item[0]),item[1]))
  486.     end
  487.     command=Window_CommandPokemonEx.newWithSize(commands,0,0,256,Graphics.height-64,@viewport)
  488.     @sprites["helpwindow"].text=_INTL("Escoge {1} cartas para usar en esta partida.",@battle.maxCards)
  489.     preview=Sprite.new(@viewport)
  490.     preview.z=4
  491.     preview.x=276
  492.     preview.y=60
  493.     index=-1
  494.     chosenSprites=[]
  495.     for i in 0...@battle.maxCards
  496.       @sprites["player#{i}"]=Sprite.new(@viewport)
  497.       @sprites["player#{i}"].z=2
  498.       @sprites["player#{i}"].x=Graphics.width-96
  499.       @sprites["player#{i}"].y=34+48*i
  500.     end
  501.     loop do
  502.       Graphics.update
  503.       Input.update
  504.       pbUpdate
  505.       command.update
  506.       if command.index!=index
  507.         preview.bitmap.dispose if preview.bitmap
  508.         if command.index<cardStorage.length
  509.           item=cardStorage[command.index]
  510.           preview.bitmap=TriadCard.new(item[0]).createBitmap(1)
  511.         end
  512.         index=command.index
  513.       end
  514.       if Input.trigger?(Input::B)
  515.         if chosenCards.length>0
  516.           item=chosenCards.pop
  517.           @battle.pbAdd(cardStorage,item)
  518.           commands=[]
  519.           for item in cardStorage
  520.             commands.push(_INTL("{1} x{2}",PBSpecies.getName(item[0]),item[1]))
  521.           end
  522.           command.commands=commands
  523.           index=-1
  524.         else
  525.           pbPlayBuzzerSE()
  526.         end
  527.       elsif Input.trigger?(Input::C)
  528.         if chosenCards.length==@battle.maxCards
  529.           break
  530.         end
  531.         item=cardStorage[command.index]
  532.         if !item || (@battle.pbQuantity(cardStorage,item[0])==0)
  533.           pbPlayBuzzerSE()
  534.         else
  535.           pbPlayDecisionSE()
  536.           sprite=@sprites["player#{chosenCards.length}"]
  537.           sprite.bitmap.dispose if sprite.bitmap
  538.           @cardBitmaps[chosenCards.length]=TriadCard.new(item[0]).createBitmap(1)
  539.           sprite.bitmap=@cardBitmaps[chosenCards.length]
  540.           chosenCards.push(item[0])
  541.           @battle.pbSubtract(cardStorage,item[0])
  542.           commands=[]
  543.           for item in cardStorage
  544.             commands.push(_INTL("{1} x{2}",PBSpecies.getName(item[0]),item[1]))
  545.           end
  546.           command.commands=commands
  547.           command.index=commands.length-1 if command.index>=commands.length
  548.           index=-1
  549.         end
  550.       end
  551.       if Input.trigger?(Input::C) || Input.trigger?(Input::B)
  552.         for i in 0...@battle.maxCards
  553.           @sprites["player#{i}"].visible=(i<chosenCards.length)
  554.         end
  555.         if chosenCards.length==@battle.maxCards
  556.           @sprites["helpwindow"].text=_INTL("{1} han sido escogidas.",@battle.maxCards)
  557.           command.visible=false
  558.           command.active=false
  559.           preview.visible=false
  560.         else
  561.           @sprites["helpwindow"].text=_INTL("Escoge {1} cartas para usar en esta partida.",@battle.maxCards)
  562.           command.visible=true
  563.           command.active=true
  564.           preview.visible=true
  565.         end
  566.       end
  567.     end
  568.     command.dispose
  569.     preview.bitmap.dispose if preview.bitmap
  570.     preview.dispose
  571.     return chosenCards
  572.   end
  573. end
  574.  
  575.  
  576.  
  577. # Screen class for handling game logic
  578. class TriadScreen
  579.   attr_accessor :openHand,:countUnplayedCards
  580.   attr_reader :width,:height
  581.  
  582.   def initialize(scene)
  583.     @scene=scene
  584.     @width              = 3
  585.     @height             = 3
  586.     @sameWins           = false
  587.     @openHand           = false
  588.     @wrapAround         = false
  589.     @elements           = false
  590.     @randomHand         = false
  591.     @countUnplayedCards = false
  592.     @trade              = 0
  593.   end
  594.  
  595.   def board
  596.     @board
  597.   end
  598.  
  599.   def playerName
  600.     @playerName
  601.   end
  602.  
  603.   def opponentName
  604.     @opponentName
  605.   end
  606.  
  607.   def maxCards
  608.     numcards=@width*@height
  609.     if numcards%2 == 1
  610.       numcards=numcards/2+1
  611.     else
  612.       numcards=numcards/2
  613.     end
  614.     return numcards
  615.   end
  616.  
  617.   def isOccupied?(x,y)
  618.     return @board[y*@width+x].owner!=0
  619.   end
  620.  
  621.   def getOwner(x,y)
  622.     return @board[y*@width+x].owner
  623.   end
  624.  
  625.   def getPanel(x,y)
  626.     return @board[y*@width+x]
  627.   end
  628.  
  629.   def pbQuantity(items,item)
  630.     return ItemStorageHelper.pbQuantity(items,$PokemonGlobal.triads.maxSize,item)
  631.   end
  632.  
  633.   def pbAdd(items,item)
  634.     return ItemStorageHelper.pbStoreItem(items,$PokemonGlobal.triads.maxSize,
  635.        $PokemonGlobal.triads.maxPerSlot,item,1)
  636.   end
  637.  
  638.   def pbSubtract(items,item)
  639.     return ItemStorageHelper.pbDeleteItem(items,$PokemonGlobal.triads.maxSize,
  640.        item,1)
  641.   end
  642.  
  643.   def flipBoard(x,y,attackerParam=nil,recurse=false)
  644.     panels=[x-1,y,x+1,y,x,y-1,x,y+1]
  645.     panels[0]=(@wrapAround ? @width-1 : 0) if panels[0]<0 # left
  646.     panels[2]=(@wrapAround ? 0 : @width-1) if panels[2]>@width-1 # right
  647.     panels[5]=(@wrapAround ? @height-1 : 0) if panels[5]<0 # top
  648.     panels[7]=(@wrapAround ? 0 : @height-1) if panels[7]>@height-1 # bottom
  649.     attacker=attackerParam!=nil ? attackerParam : @board[y*@width+x]
  650.     flips=[]
  651.     return nil if attackerParam!=nil && @board[y*@width+x].owner!=0
  652.     return nil if !attacker.card || attacker.owner==0
  653.     for i in 0...4
  654.       defenderX=panels[i*2]
  655.       defenderY=panels[i*2+1]
  656.       defender=@board[defenderY*@width+defenderX]
  657.       next if !defender.card
  658.       if attacker.owner!=defender.owner
  659.         attack=attacker.attack(i)
  660.         defense=defender.defense(i)
  661.         if @elements
  662.           # If attacker's type matches the tile's element, add
  663.           # a bonus of 1 (only for original attacker, not combos)
  664.           attack+=1 if !recurse && attacker.type==attacker.card.type
  665.         else
  666.           # Modifier depends on opponent's Pokémon type:
  667.           # +1 - Super effective
  668.           # -1 - Not very effective
  669.           # -2 - Immune
  670. #         attack+=attacker.bonus(defender)
  671.         end
  672. #       p [attacker.card.north,attacker.card.west,
  673. #          attacker.card.east,attacker.card.south],
  674. #          [defender.card.north,defender.card.west,
  675. #          defender.card.east,defender.card.south],
  676. #          [attack,defense,attacker.bonus(defender)] if attackerParam==nil
  677.         if attack>defense || (attack==defense && @sameWins)
  678.           flips.push([defenderX,defenderY])
  679.           if attackerParam==nil
  680.             defender.owner=attacker.owner
  681.             if @sameWins
  682.               # Combo with the "sameWins" rule
  683.               ret=flipBoard(defenderX,defenderY,nil,true)
  684.               flips.concat(ret) if ret
  685.             end
  686.           else
  687.             if @sameWins
  688.               # Combo with the "sameWins" rule
  689.               ret=flipBoard(defenderX,defenderY,attackerParam,true)
  690.               flips.concat(ret) if ret
  691.             end
  692.           end
  693.         end
  694.       end
  695.     end
  696.     return flips
  697.   end
  698.  
  699. # If pbStartScreen includes parameters, it should
  700. # pass the parameters to pbStartScene.
  701.   def pbStartScreen(opponentName,minLevel,maxLevel,rules=nil,oppdeck=nil,prize=nil)
  702.     if minLevel<0 || minLevel>9
  703.       raise _INTL("Minimum level must be 0 through 9.")
  704.     end
  705.     if maxLevel<0 || maxLevel>9
  706.       raise _INTL("Maximum level must be 0 through 9.")
  707.     end
  708.     if maxLevel<minLevel
  709.       raise _INTL("Maximum level shouldn't be less than the minimum level.")
  710.     end
  711.     if rules && rules.is_a?(Array) && rules.length>0
  712.       for rule in rules
  713.         @sameWins           = true if rule=="samewins"
  714.         @openHand           = true if rule=="openhand"
  715.         @wrapAround         = true if rule=="wrap"
  716.         @elements           = true if rule=="elements"
  717.         @randomHand         = true if rule=="randomhand"
  718.         @countUnplayedCards = true if rule=="countunplayed"
  719.         @trade              = 1    if rule=="direct"
  720.         @trade              = 2    if rule=="winall"
  721.       end
  722.     end
  723.     @triadCards=[]
  724.     if !$PokemonGlobal
  725.       $PokemonGlobal=PokemonGlobalMetadata.new
  726.     end
  727.     count=0
  728.     for i in 0...$PokemonGlobal.triads.length
  729.       item=$PokemonGlobal.triads[i]
  730.       ItemStorageHelper.pbStoreItem(@triadCards,
  731.          $PokemonGlobal.triads.maxSize,
  732.          $PokemonGlobal.triads.maxPerSlot,
  733.          item[0],item[1]
  734.       )
  735.       count+=item[1] # Add item count to total count
  736.     end
  737.     @board=[]
  738.     @playerName=$Trainer ? $Trainer.name : "Jugador"
  739.     @opponentName=opponentName
  740.     for i in 0...@width*@height
  741.       square=TriadSquare.new
  742.       if @elements
  743.         begin
  744.           square.type=rand(PBTypes.maxValue+1)
  745.         end until !PBTypes.isPseudoType?(square.type)
  746.       end
  747.       @board.push(square)
  748.     end
  749.     @scene.pbStartScene(self) # (param1, param2)
  750.     # Check whether there are enough cards.
  751.     if count<self.maxCards
  752.       @scene.pbDisplayPaused(_INTL("No tienes cartas suficientes."))
  753.       @scene.pbEndScene
  754.       return 0
  755.     end
  756.     # Set the player's cards.
  757.     cards=[]
  758.     if @randomHand   # Determine hand at random
  759.       self.maxCards.times do
  760.         randCard=@triadCards[rand(@triadCards.length)]
  761.         pbSubtract(@triadCards,randCard[0])
  762.         cards.push(randCard[0])
  763.       end
  764.       @scene.pbShowPlayerCards(cards)
  765.     else
  766.       cards=@scene.pbChooseTriadCard(@triadCards)
  767.     end
  768.     # Set the opponent's cards.
  769.     if oppdeck && oppdeck.is_a?(Array) && oppdeck.length==self.maxCards # Preset
  770.       opponentCards=[]
  771.       for i in oppdeck
  772.         card=getID(PBSpecies,i)
  773.         if card<=0
  774.           @scene.pbDisplayPaused(_INTL("El oponente tiene una carta ilegal, \"{1}\".",i))
  775.           @scene.pbEndScene
  776.           return 0
  777.         end
  778.         opponentCards.push(card)
  779.       end
  780.     else
  781.       candidates=[]
  782.       while candidates.length<200
  783.         card=0
  784.         loop do
  785.           card=rand(PBSpecies.maxValue)+1
  786.           cname=getConstantName(PBSpecies,card) rescue nil
  787.           break if cname
  788.         end
  789.         triad=TriadCard.new(card)
  790.         total=triad.north+triad.south+triad.east+triad.west
  791.         # Add random species and its total point count
  792.         candidates.push([card,total])
  793.         if candidates.length<200 && $Trainer && $Trainer.owned[card]
  794.           # Add again if Trainer owns the species
  795.           candidates.push([card,total])
  796.         end
  797.       end
  798.       # sort by total point count
  799.       candidates.sort!{|a,b| a[1]<=>b[1] }
  800.       minIndex=minLevel*20
  801.       maxIndex=maxLevel*20+20
  802.       opponentCards=[]
  803.       for i in 0...self.maxCards
  804.         # generate random card based on level
  805.         index=minIndex+rand(maxIndex-minIndex)
  806.         opponentCards.push(candidates[index][0])
  807.       end
  808.     end
  809.     originalCards=cards.clone
  810.     originalOpponentCards=opponentCards.clone
  811.     @scene.pbNotifyCards(cards.clone,opponentCards.clone)
  812.     @scene.pbShowOpponentCards(opponentCards)
  813.     @scene.pbDisplay(_INTL("Escogiendo quién va primero..."))
  814.     @scene.pbUpdateScore
  815.     playerTurn=false
  816.     if rand(2)==0
  817.       @scene.pbDisplay(_INTL("{1} irá primero.",@playerName))
  818.       playerTurn=true
  819.     else
  820.       @scene.pbDisplay(_INTL("{1} irá primero.",@opponentName))
  821.       playerTurn=false
  822.     end
  823.     for i in 0...@width*@height
  824.       position=nil
  825.       triadCard=nil
  826.       cardIndex=0
  827.       if playerTurn
  828.         # Player's turn
  829.         while !position
  830.           cardIndex=@scene.pbPlayerChooseCard(cards.length)
  831.           triadCard=TriadCard.new(cards[cardIndex])
  832.           position=@scene.pbPlayerPlaceCard(triadCard,cardIndex)
  833.         end
  834.       else
  835.         # Opponent's turn
  836.         @scene.pbDisplay(_INTL("{1} está pensando su jugada...",@opponentName))    
  837.         scores=[]
  838.         for cardIndex in 0...opponentCards.length
  839.           square=TriadSquare.new
  840.           square.card=TriadCard.new(opponentCards[cardIndex])
  841.           square.owner=2
  842.           for i in 0...@width*@height
  843.             x=i%@width
  844.             y=i/@width
  845.             square.type=@board[i].type
  846.             flips=flipBoard(x,y,square)
  847.             if flips!=nil
  848.               scores.push([cardIndex,x,y,flips.length])
  849.             end
  850.           end
  851.         end
  852.         # Sort by number of flips
  853.         scores.sort!{|a,b|
  854.            if b[3]==a[3]
  855.              next [-1,1,0][rand(3)]
  856.            else
  857.              next b[3]<=>a[3]
  858.            end
  859.         }
  860.         scores=scores[0,opponentCards.length] # Get the best results
  861.         if scores.length==0
  862.           @scene.pbDisplay(_INTL("{1} no puede colocar...",@opponentName))
  863.           playerTurn=!playerTurn
  864.           continue
  865.         end
  866.         result=scores[rand(scores.length)]
  867.         cardIndex=result[0]
  868.         triadCard=TriadCard.new(opponentCards[cardIndex])
  869.         position=[result[1],result[2]]
  870.         @scene.pbOpponentPlaceCard(triadCard,position,cardIndex)
  871.       end
  872.       boardIndex=position[1]*@width+position[0]
  873.       board[boardIndex].card=triadCard
  874.       board[boardIndex].owner=playerTurn ? 1 : 2
  875.       flipBoard(position[0],position[1])
  876.       if playerTurn
  877.         cards.delete_at(cardIndex)
  878.         @scene.pbEndPlaceCard(position,cardIndex)
  879.       else
  880.         opponentCards.delete_at(cardIndex)
  881.         @scene.pbEndOpponentPlaceCard(position,cardIndex)
  882.       end
  883.       playerTurn=!playerTurn
  884.     end
  885.     # Determine the winner
  886.     playerCount=0
  887.     opponentCount=0
  888.     for i in 0...@width*@height
  889.       playerCount+=1 if board[i].owner==1
  890.       opponentCount+=1 if board[i].owner==2
  891.     end
  892.     if @countUnplayedCards
  893.       playerCount+=cards.length
  894.       opponentCount+=opponentCards.length
  895.     end
  896.     result=0
  897.     if playerCount==opponentCount
  898.       @scene.pbDisplayPaused(_INTL("¡El resultado es... Empate!"))
  899.       result=3
  900.       case @trade
  901.       when 1
  902.         # Keep only cards of your color
  903.         for card in originalCards
  904.           $PokemonGlobal.triads.pbDeleteItem(card)
  905.         end
  906.         for i in cards
  907.           $PokemonGlobal.triads.pbStoreItem(i)
  908.         end
  909.         for i in 0...@width*@height
  910.           if board[i].owner==1
  911.             $PokemonGlobal.triads.pbStoreItem(board[i].card.species)
  912.           end
  913.         end
  914.         @scene.pbDisplayPaused(_INTL("Conservas todas tus cartas de tu color."))
  915.       end
  916.     elsif playerCount>opponentCount
  917.       @scene.pbDisplayPaused(_INTL("{1} ha ganado contra {2}.",@playerName,@opponentName))
  918.       result=1
  919.       if prize
  920.         card=getID(PBSpecies,prize)
  921.         if card>0 && $PokemonGlobal.triads.pbStoreItem(card)
  922.           cardname=PBSpecies.getName(card)
  923.           @scene.pbDisplayPaused(_INTL("Conseguiste la carta de {1}.",cardname))
  924.         end
  925.       else
  926.         case @trade
  927.         when 0
  928.           # Gain 1 random card from opponent's deck
  929.           card=originalOpponentCards[rand(originalOpponentCards.length)]
  930.           if $PokemonGlobal.triads.pbStoreItem(card)
  931.             cardname=PBSpecies.getName(card)
  932.             @scene.pbDisplayPaused(_INTL("Conseguiste la carta de {1}.",cardname))
  933.           end
  934.         when 1
  935.           # Keep only cards of your color
  936.           for card in originalCards
  937.             $PokemonGlobal.triads.pbDeleteItem(card)
  938.           end
  939.           for i in cards
  940.             $PokemonGlobal.triads.pbStoreItem(i)
  941.           end
  942.           for i in 0...@width*@height
  943.             if board[i].owner==1
  944.               $PokemonGlobal.triads.pbStoreItem(board[i].card.species)
  945.             end
  946.           end
  947.           @scene.pbDisplayPaused(_INTL("Conservas todas tus cartas de tu color."))
  948.         when 2
  949.           # Gain all opponent's cards
  950.           for card in originalOpponentCards
  951.             $PokemonGlobal.triads.pbStoreItem(card)
  952.           end
  953.           @scene.pbDisplayPaused(_INTL("Conseguiste todas las cartas del oponente."))
  954.         end
  955.       end
  956.     else
  957.       @scene.pbDisplayPaused(_INTL("{1} perdió contra {2}.",@playerName,@opponentName))
  958.       result=2
  959.       case @trade
  960.       when 0
  961.         # Lose 1 random card from your deck
  962.         card=originalCards[rand(originalCards.length)]
  963.         $PokemonGlobal.triads.pbDeleteItem(card)
  964.         cardname=PBSpecies.getName(card)
  965.         @scene.pbDisplayPaused(_INTL("El oponente consiguió tu carta de {1}.",cardname))
  966.       when 1
  967.         # Keep only cards of your color
  968.         for card in originalCards
  969.           $PokemonGlobal.triads.pbDeleteItem(card)
  970.         end
  971.         for i in cards
  972.           $PokemonGlobal.triads.pbStoreItem(i)
  973.         end
  974.         for i in 0...@width*@height
  975.           if board[i].owner==1
  976.             $PokemonGlobal.triads.pbStoreItem(board[i].card.species)
  977.           end
  978.         end
  979.         @scene.pbDisplayPaused(_INTL("Te quedas con todas las cartas de tu color.",cardname))
  980.       when 2
  981.         # Lose all your cards
  982.         for card in originalCards
  983.           $PokemonGlobal.triads.pbDeleteItem(card)
  984.         end
  985.         @scene.pbDisplayPaused(_INTL("Tu oponente consiguió todas tus cartas."))
  986.       end
  987.     end
  988.     @scene.pbEndScene
  989.     return result
  990.   end
  991. end
  992.  
  993.  
  994.  
  995. class PokemonGlobalMetadata
  996.   attr_accessor :triads
  997.  
  998.   def triads
  999.     @triads=TriadStorage.new if !@triads
  1000.     return @triads
  1001.   end
  1002. end
  1003.  
  1004.  
  1005.  
  1006. class TriadStorage
  1007.   def maxSize
  1008.     return PBSpecies.getCount
  1009.   end
  1010.  
  1011.   def maxPerSlot
  1012.     return 99
  1013.   end
  1014.  
  1015.   def initialize
  1016.     @items=[]
  1017.   end
  1018.  
  1019.   def empty?
  1020.     return @items.length==0
  1021.   end
  1022.  
  1023.   def length
  1024.     @items.length
  1025.   end
  1026.  
  1027.   def [](i)
  1028.     @items[i]
  1029.   end
  1030.  
  1031.   def getItem(index)
  1032.     if index<0 || index>=@items.length
  1033.       return 0
  1034.     else
  1035.       return @items[index][0]
  1036.     end
  1037.   end
  1038.  
  1039.   def getCount(index)
  1040.     if index<0 || index>=@items.length
  1041.       return 0
  1042.     else
  1043.       return @items[index][1]
  1044.     end
  1045.   end
  1046.  
  1047.   def pbQuantity(item)
  1048.     return ItemStorageHelper.pbQuantity(@items,self.maxSize,item)
  1049.   end
  1050.  
  1051.   def pbDeleteItem(item,qty=1)
  1052.     return ItemStorageHelper.pbDeleteItem(@items,self.maxSize,item,qty)
  1053.   end
  1054.  
  1055.   def pbCanStore?(item,qty=1)
  1056.     return ItemStorageHelper.pbCanStore?(@items,self.maxSize,self.maxPerSlot,item,qty)
  1057.   end
  1058.  
  1059.   def pbStoreItem(item,qty=1)
  1060.     return ItemStorageHelper.pbStoreItem(@items,self.maxSize,self.maxPerSlot,item,qty)
  1061.   end
  1062. end
  1063.  
  1064.  
  1065.  
  1066. def pbBuyTriads
  1067.   commands=[]
  1068.   realcommands=[]
  1069.   for i in 1..PBSpecies.maxValue
  1070.     if $Trainer.owned[i]
  1071.       speciesname=PBSpecies.getName(i)
  1072.       next if !speciesname
  1073.       price=TriadCard.new(i).price
  1074.       commands.push([price,speciesname,_INTL("{1} {2}",speciesname,price),i])
  1075.     end
  1076.   end
  1077.   if commands.length==0
  1078.     Kernel.pbMessage(_INTL("No puedes comprar ninguna carta."))
  1079.     return
  1080.   end
  1081.   commands.sort!{|a,b|
  1082.      if a[0]==b[0]
  1083.        a[1]<=>b[1] # sort by name
  1084.      else
  1085.        a[0]<=>b[0] # sort by price
  1086.      end
  1087.   }
  1088.   for command in commands
  1089.     realcommands.push(command[2])
  1090.   end
  1091.   # Scroll right before showing screen
  1092.   pbScrollMap(4,3,5)
  1093.   cmdwindow=Window_CommandPokemonEx.newWithSize(realcommands,0,0,256,Graphics.height)
  1094.   cmdwindow.z=99999
  1095.   moneyString=_INTL("{1}",$PokemonGlobal.coins)
  1096.   goldwindow=Window_UnformattedTextPokemon.newWithSize(
  1097.      _INTL("Monedas:\n{1}",moneyString),0,0,32,32)
  1098.   goldwindow.resizeToFit(goldwindow.text,Graphics.width)
  1099.   goldwindow.y=0
  1100.   goldwindow.x=Graphics.width-goldwindow.width
  1101.   goldwindow.z=99999
  1102.   Graphics.frame_reset
  1103.   done=false
  1104.   while !done
  1105.     loop do
  1106.       Graphics.update
  1107.       Input.update
  1108.       cmdwindow.active=true
  1109.       cmdwindow.update
  1110.       goldwindow.update
  1111.       if Input.trigger?(Input::B)
  1112.         done=true
  1113.         break
  1114.       end
  1115.       if Input.trigger?(Input::C)
  1116.         price=commands[cmdwindow.index][0]
  1117.         item=commands[cmdwindow.index][3]
  1118.         itemname=commands[cmdwindow.index][1]
  1119.         cmdwindow.active=false
  1120.         cmdwindow.update
  1121.         if $PokemonGlobal.coins<price
  1122.           Kernel.pbMessage(_INTL("No tienes dinero suficiente."))
  1123.           break
  1124.         end
  1125.         maxafford=(price<=0) ? 99 : $PokemonGlobal.coins/price
  1126.         maxafford=99 if maxafford>99
  1127.         params=ChooseNumberParams.new
  1128.         params.setRange(1,maxafford)
  1129.         params.setInitialValue(1)
  1130.         params.setCancelValue(0)
  1131.         quantity=Kernel.pbMessageChooseNumber(
  1132.            _INTL("¿La carta de {1}?  Por supuesto.\r\n¿Cuantas quieres?",itemname),params)
  1133.         if quantity>0
  1134.           price*=quantity
  1135.           if !Kernel.pbConfirmMessage(_INTL("{1}, y quieres {2}.\r\nEso serán ${3}. ¿Vale?",itemname,quantity,price))
  1136.             break
  1137.           end
  1138.           if $PokemonGlobal.coins<price
  1139.             Kernel.pbMessage(_INTL("No tienes dinero suficiente."))
  1140.             break
  1141.           end
  1142.           if !$PokemonGlobal.triads.pbCanStore?(item,quantity)
  1143.             Kernel.pbMessage(_INTL("No tienes espacio para más cartas."))
  1144.           else
  1145.             $PokemonGlobal.triads.pbStoreItem(item,quantity)
  1146.             $PokemonGlobal.coins-=price
  1147.             moneyString=_INTL("{1}",$PokemonGlobal.coins)
  1148.             goldwindow.text=_INTL("Monedas:\n{1}",moneyString)
  1149.             Kernel.pbMessage(_INTL("¡Aquí tienes!\r\n¡Gracias!"))
  1150.           end
  1151.         end
  1152.       end
  1153.     end
  1154.   end
  1155.   cmdwindow.dispose
  1156.   goldwindow.dispose
  1157.   Graphics.frame_reset
  1158.   # Scroll right before showing screen
  1159.   pbScrollMap(6,3,5)
  1160. end
  1161.  
  1162. def pbSellTriads
  1163.   commands=[]
  1164.   for i in 0...$PokemonGlobal.triads.length
  1165.     item=$PokemonGlobal.triads[i]
  1166.     speciesname=PBSpecies.getName(item[0])
  1167.     commands.push(_INTL("{1} x{2}",speciesname,item[1]))
  1168.   end
  1169.   commands.push(_INTL("CANCEL"))
  1170.   if commands.length==1
  1171.     Kernel.pbMessage(_INTL("No tienes cartas."))
  1172.     return
  1173.   end
  1174.   # Scroll right before showing screen
  1175.   pbScrollMap(4,3,5)
  1176.   cmdwindow=Window_CommandPokemonEx.newWithSize(commands,0,0,256,Graphics.height)
  1177.   cmdwindow.z=99999
  1178.   moneyString=_INTL("{1}",$PokemonGlobal.coins)
  1179.   goldwindow=Window_UnformattedTextPokemon.newWithSize(
  1180.      _INTL("Monedas:\n{1}",moneyString),0,0,32,32)
  1181.   goldwindow.resizeToFit(goldwindow.text,Graphics.width)
  1182.   goldwindow.y=0
  1183.   goldwindow.x=Graphics.width-goldwindow.width
  1184.   goldwindow.z=99999
  1185.   done=false
  1186.   Graphics.frame_reset
  1187.   while !done
  1188.     loop do
  1189.       Graphics.update
  1190.       Input.update
  1191.       cmdwindow.active=true
  1192.       cmdwindow.update
  1193.       goldwindow.update
  1194.       if Input.trigger?(Input::B)
  1195.         done=true
  1196.         break
  1197.       end
  1198.       if Input.trigger?(Input::C)
  1199.         if cmdwindow.index>=$PokemonGlobal.triads.length
  1200.           done=true
  1201.           break
  1202.         end
  1203.         item=$PokemonGlobal.triads.getItem(cmdwindow.index)
  1204.         itemname=PBSpecies.getName(item)
  1205.         quantity=$PokemonGlobal.triads.pbQuantity(item)
  1206.         price=TriadCard.new(item).price
  1207.         if price==0
  1208.           pbDisplayPaused(_INTL("¿La carta de {1}?  Oh, no.\r\nNo puedo comprarla.",itemname))
  1209.           break
  1210.         end
  1211.         cmdwindow.active=false
  1212.         cmdwindow.update
  1213.         if quantity>1
  1214.           params=ChooseNumberParams.new
  1215.           params.setRange(1,quantity)
  1216.           params.setInitialValue(1)
  1217.           params.setCancelValue(0)
  1218.           quantity=Kernel.pbMessageChooseNumber(
  1219.              _INTL("¿La carta de {1}?  ¿Cuántas quieres vender?",itemname),params)
  1220.         end
  1221.         if quantity>0
  1222.           price/=4
  1223.           price*=quantity
  1224.           if Kernel.pbConfirmMessage(_INTL("Puedo pagarte ${1}. ¿Te parece bien?",price))
  1225.             $PokemonGlobal.coins+=price
  1226.             moneyString=_INTL("{1}",$PokemonGlobal.coins)
  1227.             goldwindow.text=_INTL("Monedas:\n{1}",moneyString)
  1228.             $PokemonGlobal.triads.pbDeleteItem(item,quantity)
  1229.             Kernel.pbMessage(_INTL("Vendiste la carta de {1} y recibiste ${2} a cambio.",itemname,price))
  1230.             commands=[]
  1231.             for i in 0...$PokemonGlobal.triads.length
  1232.               item=$PokemonGlobal.triads[i]
  1233.               speciesname=PBSpecies.getName(item[0])
  1234.               commands.push(_INTL("{1} x{2}",speciesname,item[1]))
  1235.             end
  1236.             commands.push(_INTL("CANCEL"))
  1237.             cmdwindow.commands=commands
  1238.             break
  1239.           end
  1240.         end
  1241.       end
  1242.     end
  1243.   end
  1244.   cmdwindow.dispose
  1245.   goldwindow.dispose
  1246.   Graphics.frame_reset
  1247.   # Scroll right before showing screen
  1248.   pbScrollMap(6,3,5)
  1249. end
  1250.  
  1251. def pbTriadList
  1252.   commands=[]
  1253.   for i in 0...$PokemonGlobal.triads.length
  1254.     item=$PokemonGlobal.triads[i]
  1255.     speciesname=PBSpecies.getName(item[0])
  1256.     commands.push(_INTL("{1} x{2}",speciesname,item[1]))
  1257.   end
  1258.   commands.push(_INTL("CANCEL"))
  1259.   if commands.length==1
  1260.     Kernel.pbMessage(_INTL("No tienes cartas."))
  1261.     return
  1262.   end
  1263.   cmdwindow=Window_CommandPokemonEx.newWithSize(commands,0,0,256,Graphics.height)
  1264.   cmdwindow.z=99999
  1265.   sprite=Sprite.new
  1266.   sprite.z=99999
  1267.   sprite.x=256+40
  1268.   sprite.y=48
  1269.   moneyString=_INTL("${1}",$PokemonGlobal.coins)
  1270.   done=false
  1271.   lastIndex=-1
  1272.   while !done
  1273.     loop do
  1274.       Graphics.update
  1275.       Input.update
  1276.       cmdwindow.update
  1277.       if lastIndex!=cmdwindow.index
  1278.         sprite.bitmap.dispose if sprite.bitmap
  1279.         if cmdwindow.index<$PokemonGlobal.triads.length
  1280.           sprite.bitmap=TriadCard.new($PokemonGlobal.triads.getItem(cmdwindow.index)).createBitmap(1)
  1281.         end
  1282.         lastIndex=cmdwindow.index
  1283.       end
  1284.       if Input.trigger?(Input::B)
  1285.         done=true
  1286.         break
  1287.       end
  1288.       if Input.trigger?(Input::C)
  1289.         if cmdwindow.index>=$PokemonGlobal.triads.length
  1290.           done=true
  1291.           break
  1292.         end
  1293.       end
  1294.     end
  1295.   end
  1296.   cmdwindow.dispose
  1297.   sprite.dispose
  1298. end
  1299.  
  1300. def pbTriadDuel(name,minLevel,maxLevel,rules=nil,oppdeck=nil,prize=nil)
  1301.   ret=0
  1302.   pbFadeOutInWithMusic(99999){
  1303.      scene=TriadScene.new
  1304.      screen=TriadScreen.new(scene)
  1305.      ret=screen.pbStartScreen(name,minLevel,maxLevel,rules,oppdeck,prize)
  1306.   }
  1307.   return ret
  1308. end
  1309.  
  1310. def pbGiveTriadCard(species,quantity=1)
  1311.   if species.is_a?(String) || species.is_a?(Symbol)
  1312.     species=getID(PBSpecies,species)
  1313.   end
  1314.   return false if !species || species<=0
  1315.   if $PokemonGlobal.triads.pbCanStore?(species,quantity)
  1316.     $PokemonGlobal.triads.pbStoreItem(species,quantity)
  1317.     return true
  1318.   end
  1319.   return false
  1320. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement