SHARE
TWEET

CardGame Script v1.09

PencilCase27 Oct 11th, 2014 2,464 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. #                           CARDGAME SKILL/BATTLE SYSTEM
  3. #                               Author: pencilcase27
  4. #                               Version:       v1.09
  5. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  6. # v1.00 - Script released
  7. # v1.01 - Added stack, skills now can't revive themself.
  8. #       - Added CardHelp_Window, normal help window is no longer used to draw cards
  9. #       - Item Window is back to normal
  10. # v1.02 - reworked card effects
  11. #       - added deck count and toggle actor to deck build scene
  12. #       - simplified scriptcalls to add and remove cards from collection
  13. #       - Added max_card limit exception
  14. # v1.03 - reworked card effects (again)
  15. #       - added card cost effects
  16. #       - added custom images
  17. # v1.04 - added more script calls
  18. #       - changed card costs slightly
  19. #       - bugfixes
  20. # v1.05 - bugfixes
  21. # v1.06 - added initial decks for actors
  22. # v1.07 - fixed a bug with item canceling
  23. #       - fixed a bug with the draw card effect
  24. # v1.08 - added Attack and Guard command
  25. #       - added two notetags for equip
  26. # v1.09 - fixed an issue with attack and guard
  27. #       - added limitations on how many cards can be played each turn
  28. #       - added a feature to instantly empty your deck
  29. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  30. #
  31. #                                  Description
  32. #
  33. # This script changes the way actors aquire and use skills. Instead of each
  34. # actor having an own set of skills, the party now has a card collection of
  35. # different cards, each card representing a skill. Out of this collection, each
  36. # actor can now create a custom deck.
  37. # In battle, actors will act in turns. They draw cards and, while an actor is
  38. # active, he can play as many cards and items as he wants, as long as he has
  39. # the recources to do so. Once he is done, he can end his turn and the next
  40. # actor becomes active. When every actor finished his or her turn, the enemys
  41. # use their skills normal.
  42. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  43. #
  44. #                                  Script Calls
  45. #
  46. # add_card_to_coll(id1, id2, id3, ...)
  47. # Adds cards of the given skill ids to your collection
  48. #
  49. # remove_card?(id)
  50. # Tries to remove a single card of the given skill id from your collection.
  51. # Returns true if successfull and false otherwise.
  52. #
  53. # remove_all_cards(id1, id2, ...)
  54. # Removes all cards of the given skill ids from both the players decks and
  55. # from the collection
  56. #
  57. # has_card?(id)
  58. # Checks if the player has a specific card in his collection or in his deck
  59. #
  60. # count_actor_deck(id)
  61. # Returns the amount of cards in this actors deck
  62. #
  63. # count_all_decks
  64. # Returns the combined deck size of all actors
  65. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  66. #
  67. #                                Skill Notetags
  68. #
  69. #           <card id: x>
  70. # The card id of the skill. Each card must have a unique id.
  71. # Important: Every time this script uses the word id, it refers to the skills
  72. # id, not the card id! The card id is only used to sort cards.
  73. #
  74. #           <card type: x>
  75. # The type of the card. Different types can be defined below.
  76. #
  77. #           <card rarity: x>
  78. # The rarity of the card. Different raritys can be defined below.
  79. #
  80. #           <card cost: effect_name>
  81. # Adds the given cost effect to the card. Please read about card effects
  82. # down below.
  83. #
  84. #           <card impact: effect_name>
  85. # Adds the given impact effect to the card. Please read about card effects
  86. # down below.
  87. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  88. #
  89. #                             Armor/Weapon Notetags
  90. #
  91. #           <extra start cards: x>
  92. # Draws x extra cards at the begin of each battle
  93. #
  94. #           <extra turn cards: x>
  95. # Draws x extra cards at the begin of each turn
  96. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  97. #
  98. #                                Damage Formula
  99. #
  100. # Those commands can be used for a skills damage formula. Make sure they
  101. # always target an actor, since they won't have any effect on enemys. Minor
  102. # scripting knowlegde is required to make the most out of those methods.
  103. #
  104. # a/b.revive_grave(true/false)  
  105. # Shuffles your grave in your deck without penalty. If the argumet is true,
  106. # a message will be shown.
  107. #
  108. # a/b.revive_penalty
  109. # Causes the revive penalty to happen.
  110. #
  111. # a/b.shuffle_deck(true/false)
  112. # Shuffles the actors deck. If the argument is true, a sound will be played.
  113. #
  114. # a/b.card_to_grave?(skill_id)
  115. # Tries to throw the skill with the given ID to the grave. Returns true, if it's
  116. # successfull and false otherwise.
  117. #
  118. # a/b.throw_cards(n)
  119. # Throws n random cards to the grave. If n = 0, the actor will loose all cards.
  120. # Returns how many cards were thrown away.
  121. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  122. #
  123. #                                Card Effects
  124. #
  125. # Card effects are special, card related effects like "draw x cards" or
  126. # "discard a fire spell to play this card" or "look at the top 5 cards of your
  127. # deck and put them back in any order". Every card effect can be played both as
  128. # a card cost or as a card impact. Costs are handled before the player plays the
  129. # cards, impacts after.
  130. # To set up a card effect, scroll to the end of Options where you will find an
  131. # option called CARD_EFFECT. There you can add a effect name and the effects
  132. # arguments. Then add the effect either as cost or as impact via note tag to
  133. # a skill.
  134. # Each skill can have one cost effect and one impact effect.
  135. # Each item can have one impact effect.
  136. # WARNING: This is not trivial. Read carefully!
  137. #
  138. # Type: Draw
  139. # Simply draws cards
  140. # "effect_name" => [:draw, a, b, c]
  141. # a -> how many cards do you want to draw?
  142. # b -> chance the effect is successfull (between 0 and 100)
  143. # c -> :self to make only the user draw a card, :target to apply the effect to
  144. #      each target.
  145. # Example:
  146. # "draw2" => [:draw, 2, 100, :self]
  147. # -> The user of this skill will draw 2 cards.
  148. #
  149. # Type: View (impact only)
  150. # Looks at a certain number of cards taken from location a, and then puts them
  151. # back to location b. Locations can be :deck, :hand and :grave.
  152. # "effect_name" => [ :view, a, b, c]
  153. # a -> how many cards do you want to view? 0 for the entire location.
  154. # b -> from where do you want to take those cards?
  155. # c -> where do you want to put them when you're done?
  156. # Example:
  157. # "view_effect" => [:view, 10, :deck, :deck]
  158. # -> look at the top 10 cards of your deck.
  159. #
  160. # Type: Sort
  161. # Same as view but allows to sort the cards.
  162. # Example:
  163. # "stupid_effect" => [:sort, 0, :hand, :deck]
  164. # -> Put your entire hand ontop of your deck in any order.
  165. #
  166. # Type: Take
  167. # This one is a little bit harder. It allows to take some of the viewed cards
  168. # from one location to another.
  169. # "effect_name" => [:take, a, b, c, d, e, f]
  170. # a, b, c -> same as above
  171. # d -> filter that determines which cards can be choosen,
  172. #      [element_id, type_id, rarity_id], 0 for all id's allowed.
  173. # e -> the location to put the choosen cards.
  174. # f -> how many cards can be choosen.
  175. # Example:
  176. # "search_for_element2" => [:take, 0, :deck, :deck, [2,0,0], :hand, 1]
  177. # -> Search your deck for one card of element 2 and take it to your hand.
  178. # Another Example:
  179. # "discard_cost" => [:take, 0, :hand, :hand, [0,0,0], :grave, 2]
  180. # -> If this is added as a cost effect, the player has to discard two cards
  181. #    from his or her hand to play this card.
  182. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  183. module PC27
  184.   module CG
  185. #-------------------------------------------------------------------------------
  186. #
  187. #                                   Options
  188. #
  189. #-------------------------------------------------------------------------------
  190.  
  191.  
  192.  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  193.  #                                   Vocab
  194.  #------------------------------------------------------------------------------
  195.  # DECK             - Name of the actors Deck
  196.  # GRAVE            - Name of the actors Grave
  197.  # COLLECTION       - Name of the Card Collection
  198.  # END_TURN         - Name of the command that will end a players turn
  199.  # DRAW_MESSAGE     - Text that appears when an actor draws a card. Displayed
  200.  #                    as "Actor Name" + DRAW_MESSAGE + "Skill Name"
  201.  # REVIVE_MSG       - Text that appears when you revive your grave
  202.  # CARD_HELP_WINDOW - Help text shown in the deck scene (Use \n to break line)
  203.  # FILTER_TEXT      - First part of the text inside of the filter window
  204.  # F_...            - Second part of the text inside of the filter window
  205.  # EMPTY_DECK       - Text in filter window that allows to empty the entire deck
  206.  # CONFIRM          - Confirmation for EMPTY_DECK
  207.  # CARD_EFF_TEXT    - Text displayed when a card effect is evaluated.
  208.  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  209.   DECK              = "Deck"
  210.   GRAVE             = "Grave"
  211.   COLLECTION        = "Collection"
  212.   END_TURN          = "End Turn"
  213.   DRAW_MESSAGE      = "draws"
  214.   REVIVE_MSG        = "'s grave was revived"
  215.   CARD_HELP_WINDOW  = "Select: move card\nX(A): open filter"
  216.   FILTER_TEXT       = "Filter by "
  217.   F_ELEMENT         = "element: "
  218.   F_TYPE            = "type:    "
  219.   F_RARITY          = "rarity:  "
  220.   EMPTY_DECK        = "Remove all cards from Deck"
  221.   CONFIRM           = "Are you sure?"
  222.   CARD_EFF_TEXT     = "Choose cards:"
  223.  
  224.  
  225.  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  226.  #                                  Gameplay
  227.  #------------------------------------------------------------------------------
  228.  # USE_ATTACK       - Enables the regular attack command in battle.
  229.  # USE_GUARD        - Enables the regular guard command in battle.
  230.  # USE_ITEMS        - Are items in battle enabeld?
  231.  # START_CARDS      - Cards drawn in Turn 1
  232.  # MAX_DECK_SIZE    - Maximum size of a players deck
  233.  # MAX_SAME_CARDS   - Maximum amount of same cards in each deck
  234.  # MAX_ACTIONS      - Maximum amount of cards an actor can use each turn
  235.  # DECK_EMPTY       - What happens if an actor tries to draw a card but has an
  236.  #                    empty deck?
  237.  #                    1 -> The actor dies
  238.  #                    2 -> The actor dies if his grave is empty, too. If it
  239.  #                         isn't, he revives his grave, meaning he shuffles his
  240.  #                         grave back into his deck. Revive penalty is applied
  241.  #                    3 -> Like 2, but the actor won't die if the grave is empty
  242.  # REVIVE_PENALTY   - The revive penalty. Types are :hp, :mhp, :mp and :mmp.
  243.  #                    The actor will lose either hp or mp, based on its current
  244.  #                    or maximum value
  245.  # MAX_SAME_EXCEP   - Exceptions to MAX_SAME_CARDS
  246.  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  247.   USE_ATTACK        = true
  248.   USE_GUARD         = true
  249.   USE_ITEMS         = true
  250.   START_CARDS       = 5
  251.   MAX_DECK_SIZE     = 30
  252.   MAX_SAME_CARDS    = 4
  253.   MAX_ACTIONS       = 0  # if this is 0, an actor can play infinite cards
  254.                          # (until he's out of mana or cards)
  255.   DECK_EMPTY        = 1
  256.  
  257.  #                    [percent, type]
  258.   REVIVE_PENALTY    = [     50,  :hp]
  259.  
  260.   MAX_SAME_EXCEP    = {
  261.  #                    skill id => max. amount,
  262.                              5 => 2,
  263.                              7 => 1,
  264.   } # do not remove this
  265.  
  266.  
  267.  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  268.  #                              Icons and Sound
  269.  #------------------------------------------------------------------------------
  270.  # DRAW_SOUND       - Sound that will play when you draw a card
  271.  # PENALTY_SOUND    - Sound that will play when the revive penalty is applied
  272.  # DECK_ICON        - Icon that displays an actors deck size in battle
  273.  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  274.  #                    ["filename", volume, pitch]  -> ["", 0, 0] means no sound
  275.   DRAW_SOUND        = [   "Book1",    100,   150]
  276.   PENALTY_SOUND     = [ "Attack1",    100,    50]
  277.   DECK_ICON         = 228
  278.  
  279.  
  280.  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  281.  #                                   Cards
  282.  #------------------------------------------------------------------------------
  283.  # To add custom card images, add an image with the name Card + skill id to your
  284.  # graphics folder (example: Card2). The script will use every picture it can
  285.  # find. Card0 is used when no card is selected. If you choose to do this, most
  286.  # of those options are irrelevant.
  287.  #
  288.  # CUSTOM_CARD_BG   - Name of the windowskin used for cards (in Graphics/System)
  289.  # CARD_BACK_OP     - Background opacity of cards (0-255)
  290.  # CARD_NAME_UP     - If true, card names will be written in capital letters
  291.  # MP_COLOR         - Textcolor the mana costs are drawn in
  292.  # TP_COLOR         - Textcolor the tp costs are drawn in
  293.  # RARITY           - Name and icon index of the raritys your cards have
  294.  # TYPES            - Different types your cards can have
  295.  # ELEMENT_COLOR    - Background color of your cards based on their element ID
  296.  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  297.   CUSTOM_CARD_BG    = "Window"   # RPG Maker default is "Window"
  298.   CARD_BACK_OP      = 255
  299.   CARD_NAME_UP      = true
  300.   MP_COLOR          = 4
  301.   TP_COLOR          = 3
  302.  
  303.   RARITY = {
  304.  #      ID => [ icon,     "name"]
  305.          1 => [  127,   "common"],
  306.          2 => [  126, "uncommon"],
  307.          3 => [  125,     "rare"],
  308.   } # do not remove this
  309.  
  310.   TYPE = {
  311.  #      ID => "name"
  312.          1 => "Spell",
  313.          2 => "Support",
  314.          3 => "Buff",
  315.   } # do not remove this
  316.  
  317.   ELEMENT_COLOR = {
  318.  #      ID => [red, grn, blu]
  319.          0 => [  0,   0,   0],   # 0 is used for skills without an element
  320.          1 => [100, 100, 100],
  321.          2 => [200,   0,   0],
  322.          3 => [200, 200,   0],
  323.          4 => [  0,   0, 200],
  324.   } # do not remove this
  325.  
  326.  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  327.  #                              Start Decks
  328.  #------------------------------------------------------------------------------
  329.  # Those are the initial decks for each actor. If an actors id is not listed
  330.  # below, his initial deck will be empty.
  331.  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  332.   START_DECKS = {
  333.          1 => [3,3,3,7,9,8,6,12,12,12,14,15,16,3,3,3],
  334.          2 => [4,4,4,8,9,9,9,9,10,10,10],
  335.   } # do not remove this
  336.  
  337.  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  338.  #                              Card Effects
  339.  #------------------------------------------------------------------------------
  340.  # The first effect called "grave" is available as a command in battle and
  341.  # usually used to view your grave. You can change this effect if you wish, but
  342.  # keep in mind that the player can use this effect as many times as he wants.
  343.  # Please add all other effects below. Do not forget that every effect needs its
  344.  # own name. You can name them however you want, as long as you dont use the
  345.  # same name twice.
  346.  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  347.   CARD_EFFECT = {
  348.             "grave" => [:view, 0, :grave, :grave],        # Grave command effect
  349.         "foresight" => [:view, 10, :deck, :deck] ,
  350.                 "2" => [:draw, 2, 100, :target],
  351.      "intervention" => [:sort, 5, :deck, :deck],
  352.              "rise" => [:take, 0, :grave, :grave, [0,0,0], :hand, 1],
  353.               "emp" => [:take, 0, :hand, :hand, [0,0,0], :grave, 2],
  354.        "forestfire" => [:take, 0, :deck, :deck, [2,0,0], :hand, 1],
  355.        "test"       => [:take, 0, :hand, :hand, [0,0,0], :deck, 1],
  356.   } # do not remove this
  357.  
  358. #-------------------------------------------------------------------------------
  359. #
  360. #                                 End Options
  361. #
  362. #-------------------------------------------------------------------------------
  363.  
  364.   end #CG
  365. end #PC27
  366.  
  367. ################################################################################
  368. #                          Start of script                                     #
  369. ################################################################################
  370.  
  371. $imported = {} if $imported.nil?
  372. $imported["PC27: CardGame System"] = true
  373.  
  374.  
  375. #===============================================================================
  376. # Load notetags
  377. #===============================================================================
  378.  
  379. module DataManager
  380.  
  381.   class <<self; alias load_database_pc27_cardgame load_database; end
  382.    
  383.   def self.load_database
  384.     load_database_pc27_cardgame
  385.     load_notetags_pc27_cardgame
  386.   end
  387.  
  388.   def self.load_notetags_pc27_cardgame
  389.     for skill in $data_skills
  390.       next if skill.nil?
  391.       skill.load_notetags_pc27_cardgame_skill
  392.     end
  393.     for item in $data_items
  394.       next if item.nil?
  395.       item.load_notetags_pc27_cardgame_item
  396.     end
  397.     for state in $data_states
  398.       next if state.nil?
  399.       state.load_notetags_pc27_cardgame_states
  400.     end
  401.     for equip_type in [$data_weapons, $data_armors]
  402.       for obj in equip_type
  403.         next if obj.nil?
  404.         obj.load_notetags_pc27_cardgame_equip
  405.       end
  406.     end
  407.    
  408.   end
  409.  
  410. end
  411.  
  412. class RPG::UsableItem < RPG::BaseItem
  413.   attr_accessor :card_id
  414.   attr_accessor :type
  415.   attr_accessor :rarity
  416.   attr_accessor :cost
  417.   attr_accessor :impact
  418.  
  419.   #-----------------------------------------------------------------------------
  420.   # Add card attributes
  421.   #-----------------------------------------------------------------------------
  422.   def load_notetags_pc27_cardgame_skill
  423.     @description = wordwrap(@description)
  424.     @card_id = 0
  425.     @type    = 1
  426.     @rarity  = 1
  427.     @cost    = false
  428.     @impact  = false
  429.     self.note.split(/[\r\n]+/).each { |line|
  430.       if /<card[ -_]id: +(?<inr>\d+)>/i =~ line
  431.         @card_id = inr.to_i
  432.       elsif /<card[ -_]type: +(?<tnr>\d+)>/i =~ line
  433.         @type = tnr.to_i
  434.       elsif /<card[ -_]rarity: +(?<rnr>\d+)>/i =~ line
  435.         @rarity = rnr.to_i
  436.       elsif /<card[ -_]cost: +(?<cst>.+)>/i =~ line
  437.         @cost = cst
  438.       elsif /<card[ -_]impact: +(?<imp>.+)>/i =~ line
  439.         @impact = imp
  440.       end
  441.       }
  442.     end
  443.    
  444.     def load_notetags_pc27_cardgame_item
  445.       @impact = false
  446.       self.note.split(/[\r\n]+/).each { |line|
  447.         if /<card[ -_]impact: +(?<imp>.+)>/i =~ line
  448.           @impact = imp
  449.         end
  450.         }
  451.     end
  452.    
  453.   #-----------------------------------------------------------------------------
  454.   # Method to rearange text so it fits inside a window
  455.   #-----------------------------------------------------------------------------
  456.   def wordwrap(desc_text, window = nil, default_max_chars = 16)
  457.     max_chars = (window ? (window.width - 2 * window.padding) / 10 : default_max_chars)
  458.     text, line= "", ""
  459.     desc_text.split(/[\r\n ]+/).each { |word|
  460.     if word.size + line.size > max_chars
  461.       text += line+"\n"
  462.       line = word
  463.     else
  464.       line += word
  465.     end
  466.     line += " "
  467.     }
  468.     text += line
  469.     return text
  470.   end
  471.  
  472. end
  473.  
  474. class RPG::EquipItem < RPG::BaseItem
  475.   attr_accessor :extra_turn_cards
  476.   attr_accessor :extra_start_cards
  477.  
  478.   def load_notetags_pc27_cardgame_equip
  479.     @extra_turn_cards = 0
  480.     @extra_start_cards = 0
  481.     self.note.split(/[\r\n]+/).each { |line|
  482.       if /<extra[ -_]turn[ -_]cards: +(?<tnr>\d+)>/i =~ line
  483.         @extra_turn_cards = tnr.to_i
  484.       elsif /<extra[ -_]start[ -_]cards: +(?<snr>\d+)>/i =~ line
  485.         @extra_start_cards = snr.to_i
  486.       end
  487.     }
  488.   end
  489. end
  490.  
  491. class RPG::State < RPG::BaseItem
  492.   attr_reader :limited_actions
  493.  
  494.   def load_notetags_pc27_cardgame_states
  495.     @limited_actions = 0
  496.     self.note.split(/[\r\n]+/).each { |line|
  497.       if /<limited[ -_]actions: +(?<lnr>\d+)>/i =~ line
  498.         @limited_actions = lnr.to_i
  499.       end
  500.     }
  501.   end
  502. end
  503.  
  504.  
  505. #===============================================================================
  506. # Game_Interpreter
  507. #===============================================================================
  508.  
  509. class Game_Interpreter
  510.  
  511.   def add_card_to_coll(*args)
  512.     for id in args
  513.       $game_party.coll.push($data_skills[id])
  514.     end
  515.   end
  516.  
  517.   def remove_card?(id)
  518.     for i in (0...$game_party.coll.length)
  519.       if $game_party.coll[i].id == id
  520.         $game_party.coll.delete_at(i)
  521.         return true
  522.       end
  523.     end
  524.     return false
  525.   end
  526.  
  527.   def remove_all_cards(*args)
  528.     for id in args
  529.       $game_party.coll -= [$data_skills[id]]
  530.       for actor in $game_party.members
  531.         actor.deck -= [$data_skills[id]]
  532.       end
  533.     end
  534.   end
  535.  
  536.   def has_card?(id)
  537.     for card in $game_party.coll
  538.       return true if card.id == id
  539.     end
  540.     for actor in $game_party.members
  541.       for card in actor.deck
  542.         return true if card.id == id
  543.       end
  544.     end
  545.     return false
  546.   end
  547.  
  548.   def count_actor_deck(id)
  549.     return $game_actors[id].deck.size
  550.   end
  551.  
  552.   def count_all_decks
  553.     nr = 0
  554.     for actor in $game_party.members
  555.       nr += actor.deck.size
  556.     end
  557.     return nr
  558.   end
  559.  
  560. end
  561.    
  562. #===============================================================================
  563. # Game_Battler
  564. #===============================================================================
  565.  
  566. class Game_Battler < Game_BattlerBase
  567.  
  568.   #-----------------------------------------------------------------------------
  569.   # defines card actions for non actors, in case the user messes up
  570.   #-----------------------------------------------------------------------------
  571.   def revive_grave(show = true) ;end
  572.   def revive_penalty            ;end
  573.   def shuffle_deck(sound = true);end
  574.   def card_to_grave?(id)        ;end
  575.   def throw_cards(n)            ;end
  576.   def draw_cards(n)             ;end
  577.  
  578. end
  579.    
  580. #===============================================================================
  581. # Game_Actor
  582. #===============================================================================
  583.  
  584. class Game_Actor < Game_Battler
  585.  
  586.   #-----------------------------------------------------------------------------
  587.   # Attributes
  588.   #-----------------------------------------------------------------------------
  589.   attr_accessor :deck
  590.   attr_accessor :grave
  591.   attr_accessor :hand
  592.   attr_accessor :stack
  593.   attr_accessor :turn_actions
  594.  
  595.   #-----------------------------------------------------------------------------
  596.   # Adds Hand, Deck, Grave and Stack to an Actor (alias)
  597.   #-----------------------------------------------------------------------------
  598.   alias pc27_cardgame_gameactor_setup                                      setup
  599.   def setup(actor_id)
  600.     pc27_cardgame_gameactor_setup(actor_id)
  601.     setup_start_deck(actor_id)
  602.     @hand  = []
  603.     @grave = []
  604.     @stack = []
  605.     @turn_actions = { :can_attack => true,
  606.                       :can_guard  => true,
  607.                       :actions    =>    0, }
  608.   end
  609.  
  610.   #-----------------------------------------------------------------------------
  611.   # Setup for the initial deck (new)
  612.   #-----------------------------------------------------------------------------
  613.   def setup_start_deck(actor_id)
  614.     @deck  = []
  615.     if PC27::CG::START_DECKS.has_key?(actor_id)
  616.       PC27::CG::START_DECKS[actor_id].each { |card| @deck.push($data_skills[card]) }
  617.     end
  618.   end
  619.  
  620.   #-----------------------------------------------------------------------------
  621.   # Draws n cards from the deck (new)
  622.   #-----------------------------------------------------------------------------
  623.   def draw_cards(n, show = true, sound = true)
  624.     n.times do
  625.       if @deck.length == 0
  626.         add_state(1) if PC27::CG::DECK_EMPTY == 1
  627.         return if PC27::CG::DECK_EMPTY == 1
  628.         if @grave.length == 0
  629.           add_state(1) if PC27::CG::DECK_EMPTY == 2
  630.           return
  631.         else
  632.           revive_grave
  633.           revive_penalty if PC27::CG::REVIVE_PENALTY[0] > 0
  634.         end
  635.       end
  636.       RPG::SE.new(*PC27::CG::DRAW_SOUND).play and 30.times { Graphics.update; Input.update } if sound
  637.       skill = @deck.shift
  638.       @hand.push(skill)
  639.       if show
  640.         $game_message.background = 1
  641.         $game_message.position   = 1
  642.         text = @name + " " + PC27::CG::DRAW_MESSAGE + " " + skill.name
  643.         $game_message.add(text)
  644.       end
  645.     end
  646.   end
  647.  
  648.   #-----------------------------------------------------------------------------
  649.   # Puts all cards from your grave back into your deck (new)
  650.   #-----------------------------------------------------------------------------
  651.   def revive_grave(show = true)
  652.     @deck += @grave
  653.     @grave = []
  654.     shuffle_deck(false)
  655.     if show
  656.       $game_message.background = 1
  657.       $game_message.position = 1
  658.       text = @name + PC27::CG::REVIVE_MSG
  659.       $game_message.add(text)
  660.     end
  661.   end
  662.  
  663.   #-----------------------------------------------------------------------------
  664.   # Revive penalty (new)
  665.   #-----------------------------------------------------------------------------
  666.   def revive_penalty
  667.     percent = PC27::CG::REVIVE_PENALTY[0] * 0.01
  668.     case PC27::CG::REVIVE_PENALTY[1]
  669.     when :hp
  670.       @hp  -= (@hp  * percent).round
  671.     when :mhp
  672.       @hp  -= (@mhp * percent).round
  673.     when :mp
  674.       @mp  -= (@mp  * percent).round
  675.     when :mmp
  676.       @mp  -= (@mmp * percent).round
  677.     end
  678.     RPG::SE.new(*PC27::CG::PENALTY_SOUND).play
  679.   end
  680.  
  681.   #-----------------------------------------------------------------------------
  682.   # Shuffles the deck (new)
  683.   #-----------------------------------------------------------------------------
  684.   def shuffle_deck(sound = true)
  685.     if sound
  686.       5.times do
  687.         RPG::SE.new(PC27::CG::DRAW_SOUND[0], 100, 150).play
  688.         20.times { Graphics.update; Input.update }
  689.         RPG::SE.new(PC27::CG::DRAW_SOUND[0], 100, 100).play
  690.         10.times { Graphics.update; Input.update }
  691.       end
  692.     end
  693.     @deck = @deck.shuffle
  694.   end
  695.  
  696.   #-----------------------------------------------------------------------------
  697.   # Sorts Hand, Deck or Grave (new)
  698.   #-----------------------------------------------------------------------------
  699.   def sort_cards(location)
  700.     case location
  701.     when :deck
  702.       @deck.sort!{|a,b| a.card_id <=> b.card_id}
  703.     when :hand
  704.       @hand.sort!{|a,b| a.card_id <=> b.card_id}
  705.     when :grave
  706.       @grave.sort!{|a,b| a.card_id <=> b.card_id}
  707.     end
  708.   end
  709.  
  710.   #-----------------------------------------------------------------------------
  711.   # Tries to put a specific card from your hand to your grave (new)
  712.   #-----------------------------------------------------------------------------
  713.   def card_to_grave?(id)
  714.     for i in (0...@hand.length)
  715.       if @hand[i].id == id
  716.         @grave.push(@hand[i])
  717.         @hand.delete_at(i)
  718.         return true
  719.       end
  720.     end
  721.     return false
  722.   end
  723.  
  724.   #-----------------------------------------------------------------------------
  725.   # Tries to put a specific card from your hand to your stack (new)
  726.   #-----------------------------------------------------------------------------
  727.   def card_to_stack?(id)
  728.     for i in (0...@hand.length)
  729.       if @hand[i].id == id
  730.         @stack.push(@hand[i])
  731.         @hand.delete_at(i)
  732.         return true
  733.       end
  734.     end
  735.     return false
  736.   end
  737.  
  738.   #-----------------------------------------------------------------------------
  739.   # Puts n random cards from your hand to your grave (new)
  740.   #-----------------------------------------------------------------------------
  741.   def throw_cards(n)
  742.     amount_thrown_cards = 0
  743.     if n == 0
  744.       amount_thrown_cards += @hand.size
  745.       @grave += @hand
  746.       @hand = []
  747.     else
  748.       n.times do
  749.         break if @hand.size == 0
  750.         @grave.push(@hand.slice!(rand(@hand.size-1)))
  751.         amount_thrown_cards += 1
  752.       end
  753.     end
  754.     return amount_thrown_cards
  755.   end
  756.  
  757.   #-----------------------------------------------------------------------------
  758.   # Shuffles Deck and draws cards at the begin of each battle (new)
  759.   #-----------------------------------------------------------------------------
  760.   def on_battle_start
  761.     super()
  762.     shuffle_deck(false)
  763.     draw_cards(starting_cards, false, false)
  764.     @turn_actions[:can_attack] = true
  765.     @turn_actions[:can_guard]  = true
  766.     @turn_actions[:actions]    = available_actions
  767.   end
  768.  
  769.   #-----------------------------------------------------------------------------
  770.   # Starting Cards (new)
  771.   #-----------------------------------------------------------------------------
  772.   def starting_cards
  773.     x = PC27::CG::START_CARDS
  774.     @equips.each { |equip|
  775.       next unless equip
  776.       next unless equip.object
  777.       x += equip.object.extra_start_cards
  778.     }
  779.     return x
  780.   end
  781.  
  782.   #-----------------------------------------------------------------------------
  783.   # Draws a card at the end of each turn (new)
  784.   #-----------------------------------------------------------------------------
  785.   def on_turn_end
  786.     super()
  787.     if $game_party.in_battle && !death_state?
  788.       draw_cards(turn_cards, true, true)
  789.       @turn_actions[:can_attack] = true
  790.       @turn_actions[:can_guard]  = true
  791.       @turn_actions[:actions]    = available_actions
  792.     end
  793.   end
  794.  
  795.   #-----------------------------------------------------------------------------
  796.   # Determines the amount of actions an actor can make (new)
  797.   #-----------------------------------------------------------------------------
  798.   def available_actions
  799.     for id in @states
  800.       state = $data_states[id]
  801.       if state.limited_actions != 0
  802.         x = state.limited_actions if x.nil? || x > state.limited_actions
  803.       end
  804.     end
  805.     if PC27::CG::MAX_ACTIONS <= 0
  806.       return (x ? x : -1)
  807.     else
  808.       return (x ? [x, PC27::CG::MAX_ACTIONS].min : PC27::CG::MAX_ACTIONS)
  809.     end
  810.   end
  811.  
  812.   #-----------------------------------------------------------------------------
  813.   # Turn Cards(new)
  814.   #-----------------------------------------------------------------------------
  815.   def turn_cards
  816.     x = 1
  817.     @equips.each { |equip|
  818.       next unless equip
  819.       next unless equip.object
  820.       x += equip.object.extra_turn_cards
  821.     }
  822.     return x
  823.   end
  824.  
  825.   #-----------------------------------------------------------------------------
  826.   # Restore deck at the end of battle (new)
  827.   #-----------------------------------------------------------------------------
  828.   def on_battle_end
  829.     @deck += @hand + @grave
  830.     @hand, @grave = [],[]
  831.     super()
  832.   end
  833.  
  834.   #--------------------------------------------------------------------------
  835.   # * Determine Usability of Attack
  836.   #--------------------------------------------------------------------------
  837.   def attack_usable?
  838.     super && @turn_actions[:can_attack]
  839.   end
  840.  
  841.   #--------------------------------------------------------------------------
  842.   # * Determine Usability of Guard
  843.   #--------------------------------------------------------------------------
  844.   def guard_usable?
  845.     super && @turn_actions[:can_guard]
  846.   end
  847.  
  848. end
  849.  
  850. #===============================================================================
  851. # Game_Party
  852. #===============================================================================
  853.  
  854. class Game_Party < Game_Unit
  855.  
  856.   #-----------------------------------------------------------------------------
  857.   # Attributes
  858.   #-----------------------------------------------------------------------------
  859.   attr_accessor :coll
  860.    
  861.   #-----------------------------------------------------------------------------
  862.   # Adds a card collection to the party (alias)
  863.   #-----------------------------------------------------------------------------
  864.   alias pc27_gameparty_initialize                                     initialize
  865.   def initialize
  866.     pc27_gameparty_initialize
  867.     @coll = []
  868.   end
  869.  
  870. end
  871.  
  872. #===============================================================================
  873. # Window_SkillList
  874. #===============================================================================
  875.  
  876. class Window_SkillList < Window_Selectable
  877.  
  878.   #--------------------------------------------------------------------------
  879.   # Make skill list from @hand, not from @skills (overwrite)
  880.   #--------------------------------------------------------------------------
  881.   def make_item_list
  882.     @actor.sort_cards(:hand)
  883.     @data = @actor.hand
  884.   end
  885.  
  886.   #--------------------------------------------------------------------------
  887.   # Prevents the costs from beeing drawn (overwrite)
  888.   #--------------------------------------------------------------------------
  889.   def draw_item(index)
  890.     skill = @data[index]
  891.     if skill
  892.       rect = item_rect(index)
  893.       draw_item_name(skill, rect.x, rect.y, enable?(skill))
  894.     end
  895.   end
  896.  
  897. end
  898.  
  899. #===============================================================================
  900. # Window_ActorCommand
  901. #===============================================================================
  902.  
  903. class Window_ActorCommand < Window_Command
  904.    
  905.   #--------------------------------------------------------------------------
  906.   # Add "End Turn" command (new)
  907.   #--------------------------------------------------------------------------
  908.   def add_turn_end_command
  909.     add_command(PC27::CG::END_TURN, :end_turn)
  910.   end
  911.  
  912.   #--------------------------------------------------------------------------
  913.   # Add "Grave" command (new)
  914.   #--------------------------------------------------------------------------
  915.   def add_look_at_grave_command
  916.     add_command(PC27::CG::GRAVE, :look_grave)
  917.   end
  918.  
  919.   #--------------------------------------------------------------------------
  920.   # Make new command List (overwrite)
  921.   #--------------------------------------------------------------------------
  922.   def make_command_list
  923.     return unless @actor
  924.     add_attack_command if PC27::CG::USE_ATTACK
  925.     add_guard_command if PC27::CG::USE_GUARD
  926.     add_skill_commands
  927.     add_item_command if PC27::CG::USE_ITEMS
  928.     add_look_at_grave_command
  929.     add_turn_end_command
  930.   end
  931.  
  932. end
  933.  
  934. #===============================================================================
  935. # Window_BattleStatus
  936. #===============================================================================
  937.  
  938. class Window_BattleStatus < Window_Selectable
  939.  
  940.   #--------------------------------------------------------------------------
  941.   # Add deck to Draw Item (alias)
  942.   #--------------------------------------------------------------------------
  943.   alias pc27_cardgame_wndbttlstat_draw_item                            draw_item
  944.   def draw_item(index)
  945.     pc27_cardgame_wndbttlstat_draw_item(index)
  946.     actor = $game_party.battle_members[index]
  947.     draw_deck_area(deck_area_rect(index), actor)
  948.   end
  949.  
  950.   #--------------------------------------------------------------------------
  951.   # Shrink basic rect (overwrite)
  952.   #--------------------------------------------------------------------------
  953.   def basic_area_rect(index)
  954.     rect = item_rect_for_text(index)
  955.     rect.width -= gauge_area_width + deck_area_width + 10
  956.     rect
  957.   end
  958.  
  959.   #--------------------------------------------------------------------------
  960.   # Get Deck rect (new)
  961.   #--------------------------------------------------------------------------
  962.   def deck_area_rect(index)
  963.     rect = item_rect_for_text(index)
  964.     rect.x += rect.width - gauge_area_width - deck_area_width
  965.     rect.width = deck_area_width
  966.     rect
  967.   end
  968.  
  969.   #--------------------------------------------------------------------------
  970.   # Get Deck Area Width (new)
  971.   #--------------------------------------------------------------------------
  972.   def deck_area_width
  973.     return 48
  974.   end
  975.  
  976.   #--------------------------------------------------------------------------
  977.   # Draw Deck Area (new)
  978.   #--------------------------------------------------------------------------
  979.   def draw_deck_area(rect, actor)
  980.     draw_text(rect.x + 24, rect.y, 24, rect.height, actor.deck.size.to_s)
  981.     draw_icon(PC27::CG::DECK_ICON, rect.x, rect.y)
  982.   end
  983.  
  984. end
  985.  
  986. #===============================================================================
  987. # Window_BattleSkill
  988. #===============================================================================
  989.  
  990. class Window_BattleSkill < Window_SkillList
  991.  
  992.   #-----------------------------------------------------------------------------
  993.   # changes the BattleSkillList Window layout (overwrite)
  994.   #-----------------------------------------------------------------------------
  995.   def initialize(help_window, info_viewport)
  996.     y = 0
  997.     super(0, 0, (Graphics.width - 210) * 0.7, info_viewport.rect.y)
  998.     self.visible = false
  999.     @help_window = help_window
  1000.     @info_viewport = info_viewport
  1001.   end
  1002.  
  1003.   #-----------------------------------------------------------------------------
  1004.   # changes the max. amount of collums to 1 (overwrite)
  1005.   #-----------------------------------------------------------------------------
  1006.   def col_max
  1007.     return 1
  1008.   end
  1009.  
  1010.   #--------------------------------------------------------------------------
  1011.   # * Display Skill in Active State?
  1012.   #--------------------------------------------------------------------------
  1013.   def enable?(item)
  1014.     super && @actor.turn_actions[:actions] != 0
  1015.   end
  1016.  
  1017. end
  1018.  
  1019. #===============================================================================
  1020. # Window CardHelp (new)
  1021. #===============================================================================
  1022.  
  1023. class Window_CardHelp < Window_Base
  1024.   include PC27::CG
  1025.  
  1026.   #-----------------------------------------------------------------------------
  1027.   # Enables the Window to draw cards
  1028.   #-----------------------------------------------------------------------------
  1029.   def draw_card_pic(item)
  1030.     if item
  1031.       begin
  1032.         draw_card_illustration(item)
  1033.       rescue
  1034.         draw_card_text(item)
  1035.       end
  1036.     else
  1037.       begin
  1038.         draw_card_illustration_no_card
  1039.       rescue
  1040.         draw_card_text_no_card
  1041.       end
  1042.     end
  1043.   end
  1044.  
  1045.   def draw_horz_line(y)
  1046.     line_color       = normal_color
  1047.     line_color.alpha = 48
  1048.     line_y           = y + line_height / 2 - 1
  1049.     contents.fill_rect(0, line_y, self.width, 2, line_color)
  1050.   end
  1051.  
  1052.   def make_cost_text(mp_cost, tp_cost)
  1053.     if mp_cost == 0
  1054.       if tp_cost == 0
  1055.         cost = "-"
  1056.         cost_size = 1
  1057.       else
  1058.         cost = "\\c[" + TP_COLOR.to_s + "]" + tp_cost.to_s
  1059.         cost_size = tp_cost.to_s.size
  1060.       end
  1061.     else
  1062.       if tp_cost == 0
  1063.         cost = "\\c[" + MP_COLOR.to_s + "]" + mp_cost.to_s
  1064.         cost_size = mp_cost.to_s.size
  1065.       else
  1066.         cost = "\\c[" + MP_COLOR.to_s + "]"  + mp_cost.to_s + "\\c[0]/" + "\\c[" + TP_COLOR.to_s + "]" + tp_cost.to_s
  1067.         cost_size = 1 + mp_cost.to_s.size + tp_cost.to_s.size
  1068.       end
  1069.     end
  1070.     draw_text_ex(158-cost_size* 10, 48, cost)
  1071.   end
  1072.  
  1073.   def set_background(element)
  1074.     tone.set(*ELEMENT_COLOR[element])
  1075.     self.back_opacity = CARD_BACK_OP
  1076.   end
  1077.  
  1078.   def draw_all_lines
  1079.     draw_horz_line(36)
  1080.     draw_horz_line(60)
  1081.     draw_horz_line(204)
  1082.   end
  1083.    
  1084.   def draw_card_text_no_card
  1085.     create_contents
  1086.     tone.set(*ELEMENT_COLOR[0])
  1087.     self.back_opacity = CARD_BACK_OP
  1088.   end
  1089.  
  1090.   def draw_card_text(item)
  1091.     create_contents
  1092.     self.padding = standard_padding
  1093.     id          = item.card_id.to_s
  1094.     draw_text_ex(148 - id.size * 10, height - 48, "#" + id)
  1095.     make_cost_text(item.mp_cost, item.tp_cost)
  1096.     set_background(item.damage ? item.damage.element_id : 0)
  1097.     name        = (CARD_NAME_UP ? item.name.upcase : item.name)
  1098.     icon        = "\\I[" + RARITY[item.rarity][0].to_s + "]"
  1099.     type        = TYPE[item.type]
  1100.     name_x      = 0.5 * width - padding - item.name.size * 5
  1101.     draw_all_lines
  1102.     draw_text_ex(name_x, 9, name)
  1103.     draw_text_ex(0,48, type)
  1104.     draw_text_ex(0,83, item.description)
  1105.     draw_text_ex(0, height - 48, icon)
  1106.   end
  1107.  
  1108.   def draw_card_illustration_no_card
  1109.     contents.dispose
  1110.     self.contents = Bitmap.new(190, 264)
  1111.     bitmap = Cache.picture("Card0")
  1112.     self.padding = 0
  1113.     rect = Rect.new(0, 0, 190, 264)
  1114.     contents.blt(0, 0, bitmap, rect, 255)
  1115.     bitmap.dispose
  1116.   end
  1117.  
  1118.   def draw_card_illustration(item)
  1119.     contents.dispose
  1120.     self.contents = Bitmap.new(190, 264)
  1121.     bitmap = Cache.picture("Card" + item.id.to_s)
  1122.     self.padding = 0
  1123.     rect = Rect.new(0, 0, 190, 264)
  1124.     contents.blt(0, 0, bitmap, rect, 255)
  1125.     bitmap.dispose
  1126.   end
  1127.  
  1128.   #--------------------------------------------------------------------------
  1129.   # Object Initialization
  1130.   #--------------------------------------------------------------------------
  1131.   def initialize()
  1132.     super(Graphics.width - 200, 10, 190, 264)
  1133.     self.windowskin = Cache.system(PC27::CG::CUSTOM_CARD_BG) if PC27::CG::CUSTOM_CARD_BG
  1134.   end
  1135.  
  1136.   #--------------------------------------------------------------------------
  1137.   # Set Text
  1138.   #--------------------------------------------------------------------------
  1139.   def set_text(card)
  1140.     if card != @card
  1141.       @card = card
  1142.       refresh
  1143.     end
  1144.   end
  1145.  
  1146.   #--------------------------------------------------------------------------
  1147.   # Set Item
  1148.   #--------------------------------------------------------------------------
  1149.   def set_item(item)
  1150.     set_text(item)
  1151.   end
  1152.  
  1153.   #--------------------------------------------------------------------------
  1154.   # Refresh
  1155.   #--------------------------------------------------------------------------
  1156.   def refresh
  1157.     contents.clear
  1158.     draw_card_pic(@card)
  1159.   end
  1160.  
  1161.   def update_tone;    end
  1162.   def update_padding; end
  1163.  
  1164. end
  1165.  
  1166.  
  1167. #===============================================================================
  1168. # Window_CardSelect (new)
  1169. #===============================================================================
  1170.  
  1171. class Window_CardSelect < Window_SkillList
  1172.  
  1173.   attr_accessor :actor
  1174.   attr_accessor :cards
  1175.   attr_accessor :sort_index
  1176.   attr_accessor :filter
  1177.  
  1178.   def initialize(help_window, info_viewport)
  1179.     super(0, 0, (Graphics.width - 210) * 0.7, info_viewport.rect.y)
  1180.     self.visible = false
  1181.     @help_window = help_window
  1182.     @info_viewport = info_viewport
  1183.     @filter = [0,0,0]
  1184.     @cards  = []
  1185.     @sort_index = -1
  1186.   end
  1187.  
  1188.   def col_max
  1189.     return 1
  1190.   end
  1191.  
  1192.   def make_item_list
  1193.     @data = @cards
  1194.   end
  1195.  
  1196.   def enable?(item)
  1197.     return false unless item
  1198.     return false unless item.damage.element_id == @filter[0] || @filter[0] == 0
  1199.     return false unless item.type              == @filter[1] || @filter[1] == 0
  1200.     return false unless item.rarity            == @filter[2] || @filter[2] == 0
  1201.     return @actor
  1202.   end
  1203.  
  1204.   #--------------------------------------------------------------------------
  1205.   # Show Window
  1206.   #--------------------------------------------------------------------------
  1207.   def show
  1208.     select(0)
  1209.     @help_window.show
  1210.     super
  1211.   end
  1212.   #--------------------------------------------------------------------------
  1213.   # Hide Window
  1214.   #--------------------------------------------------------------------------
  1215.   def hide
  1216.     @help_window.hide
  1217.     super
  1218.   end
  1219.  
  1220. end
  1221.  
  1222.  
  1223. #===============================================================================
  1224. # Scene_Battle
  1225. #===============================================================================
  1226. class Scene_Battle < Scene_Base
  1227.  
  1228.   #--------------------------------------------------------------------------
  1229.   # Add end turn command and remove prior command (overwrite)
  1230.   #--------------------------------------------------------------------------
  1231.   def create_actor_command_window
  1232.     @actor_command_window = Window_ActorCommand.new
  1233.     @actor_command_window.viewport = @info_viewport
  1234.     @actor_command_window.set_handler(:attack,     method(:command_attack))
  1235.     @actor_command_window.set_handler(:skill,      method(:command_skill))
  1236.     @actor_command_window.set_handler(:guard,      method(:command_guard))
  1237.     @actor_command_window.set_handler(:item,       method(:command_item))
  1238.     @actor_command_window.set_handler(:look_grave, method(:command_look_grave))
  1239.     @actor_command_window.set_handler(:end_turn,   method(:command_end_turn))
  1240.     @actor_command_window.x = Graphics.width
  1241.   end
  1242.  
  1243.   #--------------------------------------------------------------------------
  1244.   # Handles the Look Grave command
  1245.   #--------------------------------------------------------------------------
  1246.   def command_look_grave
  1247.     array = PC27::CG::CARD_EFFECT["grave"]
  1248.     @temp_effect_data = [] unless @temp_effect_data
  1249.     @temp_effect_data[0] = :impact
  1250.     prepare_select_window(:impact, array[0])
  1251.     process_select_cards("grave")
  1252.   end
  1253.    
  1254.   #--------------------------------------------------------------------------
  1255.   # Clears actions and ends the actors turn
  1256.   #--------------------------------------------------------------------------
  1257.   def command_end_turn
  1258.     BattleManager.actor.clear_actions
  1259.     next_command
  1260.   end
  1261.      
  1262.   #--------------------------------------------------------------------------
  1263.   # Prevents messages from closing windows (overwrite)
  1264.   #--------------------------------------------------------------------------
  1265.   def update_message_open
  1266.   end
  1267.  
  1268.   #--------------------------------------------------------------------------
  1269.   # Shows a different Help Window in Battle (alias)
  1270.   #--------------------------------------------------------------------------
  1271.   alias pc27_cardgame_scenebattle_create_help_window          create_help_window
  1272.   def create_help_window
  1273.     pc27_cardgame_scenebattle_create_help_window
  1274.     @cardhelp_window = Window_CardHelp.new
  1275.     @cardhelp_window.visible = false
  1276.   end
  1277.  
  1278.   #--------------------------------------------------------------------------
  1279.   # Create Skill Window with card help window instead of normal help window (overwrite)
  1280.   #--------------------------------------------------------------------------
  1281.   def create_skill_window
  1282.     @skill_window = Window_BattleSkill.new(@cardhelp_window, @info_viewport)
  1283.     @skill_window.set_handler(:ok,     method(:on_skill_ok))
  1284.     @skill_window.set_handler(:cancel, method(:on_skill_cancel))
  1285.   end
  1286.  
  1287.  
  1288.   #--------------------------------------------------------------------------
  1289.   # Creates the window needed to select cards (new)
  1290.   #--------------------------------------------------------------------------
  1291.   def create_card_select_window
  1292.     @card_select_window = Window_CardSelect.new(@cardhelp_window, @info_viewport)
  1293.   end
  1294.  
  1295.   #--------------------------------------------------------------------------
  1296.   # Adds the select window to the scene (alias)
  1297.   #--------------------------------------------------------------------------
  1298.   alias pc27_cardgame_scenebattle_create_all_windows          create_all_windows
  1299.   def create_all_windows
  1300.     pc27_cardgame_scenebattle_create_all_windows
  1301.     create_card_select_window
  1302.   end
  1303.  
  1304.   #--------------------------------------------------------------------------
  1305.   # On Skill Ok checks for card costs
  1306.   #--------------------------------------------------------------------------
  1307.   alias pc27_cardgame_scene_battle_on_skill_ok                       on_skill_ok
  1308.   def on_skill_ok
  1309.     @skill = @skill_window.item
  1310.     BattleManager.actor.card_to_stack?(@skill.id)
  1311.     if @skill.cost
  1312.       invoke_card_cost(@skill.cost)
  1313.       @skill_window.hide
  1314.     else
  1315.       BattleManager.actor.input.set_skill(@skill.id)
  1316.       BattleManager.actor.last_skill.object = @skill
  1317.       if !@skill.need_selection?
  1318.         @skill_window.hide
  1319.         next_command
  1320.       elsif @skill.for_opponent?
  1321.         select_enemy_selection
  1322.       else
  1323.         select_actor_selection
  1324.       end
  1325.     end
  1326.   end
  1327.  
  1328.   def on_enemy_cancel
  1329.     restore_taken_cards(:cancel)
  1330.     BattleManager.actor.hand += BattleManager.actor.stack
  1331.     BattleManager.actor.stack = []
  1332.     @enemy_window.hide
  1333.     @skill_window.hide
  1334.     @item_window.hide
  1335.     @actor_command_window.activate
  1336.   end
  1337.  
  1338.   def on_actor_cancel
  1339.     restore_taken_cards(:cancel)
  1340.     BattleManager.actor.hand += BattleManager.actor.stack
  1341.     BattleManager.actor.stack = []
  1342.     @actor_window.hide
  1343.     @skill_window.hide
  1344.     @item_window.hide
  1345.     @actor_command_window.activate
  1346.   end
  1347.  
  1348.   #-----------------------------------------------------------------------------
  1349.   # Changes Next Command so it performs Actions (alias)
  1350.   #-----------------------------------------------------------------------------
  1351.   alias pc27_cardgame_scenebattle_next_command                      next_command
  1352.   def next_command
  1353.     return if @card_select_window.active
  1354.     if action?
  1355.       evaluate_item(BattleManager.actor, BattleManager.actor.input.item)
  1356.       perform_action
  1357.     else
  1358.       pc27_cardgame_scenebattle_next_command
  1359.     end
  1360.   end
  1361.  
  1362.   #-----------------------------------------------------------------------------
  1363.   # Disables stuff based on used skill (new)
  1364.   #-----------------------------------------------------------------------------
  1365.   def evaluate_item(actor, item)
  1366.     case item.id
  1367.     when actor.attack_skill_id
  1368.       actor.turn_actions[:can_attack] = false
  1369.       actor.turn_actions[:can_guard]  = false
  1370.       actor.turn_actions[:actions]    = 0
  1371.     when actor.guard_skill_id
  1372.       actor.turn_actions[:can_attack] = false
  1373.       actor.turn_actions[:can_guard]  = false
  1374.       actor.turn_actions[:actions]    = 0
  1375.     else
  1376.       actor.turn_actions[:can_attack] = false
  1377.       actor.turn_actions[:can_guard]  = false
  1378.       actor.turn_actions[:actions]   -= 1 unless actor.turn_actions[:actions] == -1
  1379.     end
  1380.   end
  1381.  
  1382.   #--------------------------------------------------------------------------
  1383.   # Checks if there is an Action to use (new)
  1384.   #--------------------------------------------------------------------------
  1385.   def action?
  1386.     return false if BattleManager.actor.nil?
  1387.     return false if BattleManager.actor.input.nil?
  1388.     action = BattleManager.actor.input.item
  1389.     return false if action.nil?
  1390.     return true
  1391.   end
  1392.    
  1393.   #--------------------------------------------------------------------------
  1394.   # Performs Action (new)
  1395.   #--------------------------------------------------------------------------
  1396.   def perform_action
  1397.     @subject = BattleManager.actor
  1398.     hide_instant_action_windows
  1399.     if @subject.current_action.valid?
  1400.       execute_action
  1401.     end
  1402.     process_event
  1403.     loop do
  1404.       @subject.remove_current_action
  1405.       break if $game_troop.all_dead?
  1406.       break unless @subject.current_action
  1407.       @subject.current_action.prepare
  1408.       execute_action if @subject.current_action.valid?
  1409.     end
  1410.     process_action_end
  1411.     @subject.make_actions
  1412.     @subject = nil
  1413.     show_instant_action_windows
  1414.   end
  1415.  
  1416.   #--------------------------------------------------------------------------
  1417.   # From Yanflys Instantcast (new)
  1418.   #--------------------------------------------------------------------------
  1419.   def hide_instant_action_windows
  1420.     if $imported["YEA-BattleEngine"]
  1421.       @info_viewport.visible = true
  1422.       @status_aid_window.hide
  1423.       @status_window.show
  1424.       @actor_command_window.show
  1425.     end
  1426.   end
  1427.  
  1428.   #--------------------------------------------------------------------------
  1429.   # Activates actor (new)
  1430.   #--------------------------------------------------------------------------
  1431.   def show_instant_action_windows
  1432.     if $imported["YEA-BattleEngine"]
  1433.       @info_viewport.visible = true
  1434.     end
  1435.     start_actor_command_selection unless @card_select_window.active
  1436.     status_redraw_target(BattleManager.actor)
  1437.     next_command unless BattleManager.actor.inputable?
  1438.   end
  1439.  
  1440.   #--------------------------------------------------------------------------
  1441.   # Redrawas target after action (new)
  1442.   #--------------------------------------------------------------------------
  1443.   def status_redraw_target(target)
  1444.     return unless target.actor?
  1445.     @status_window.draw_item($game_party.battle_members.index(target))
  1446.   end
  1447.  
  1448.   #--------------------------------------------------------------------------
  1449.   # Handles card costs
  1450.   #--------------------------------------------------------------------------
  1451.   def invoke_card_cost(effect_name)
  1452.     effect_array = PC27::CG::CARD_EFFECT[effect_name]
  1453.     if effect_array[0] == :draw
  1454.       card_effect_draw_cards(effect_array[1], effect_array[2], effect_array[3])
  1455.       BattleManager.actor.input.set_skill(@skill.id)
  1456.       BattleManager.actor.last_skill.object = @skill
  1457.       if !@skill.need_selection?
  1458.         @skill_window.hide
  1459.         next_command
  1460.       elsif @skill.for_opponent?
  1461.         select_enemy_selection
  1462.       else
  1463.         select_actor_selection
  1464.       end
  1465.     else
  1466.       $game_message.background = 1
  1467.       $game_message.position   = 1
  1468.       $game_message.add(PC27::CG::CARD_EFF_TEXT)
  1469.       wait_for_message
  1470.       prepare_select_window(:cost, effect_array[0])
  1471.       @temp_effect_data = [] unless @temp_effect_data
  1472.       @temp_effect_data[0] = :cost
  1473.       process_select_cards(effect_name)
  1474.     end
  1475.   end
  1476.  
  1477.   #-----------------------------------------------------------------------------
  1478.   # Evaluates card effects and puts the stack to the grave (alias)
  1479.   #-----------------------------------------------------------------------------
  1480.   alias pc27_cardgame_scenebattle_use_item                              use_item
  1481.   def use_item
  1482.     pc27_cardgame_scenebattle_use_item
  1483.     if @subject.is_a?(Game_Actor)
  1484.       effect_name = @subject.current_action.item.impact
  1485.       invoke_card_impact(effect_name) if effect_name
  1486.       @subject.grave += @subject.stack
  1487.       @subject.stack = []
  1488.       restore_taken_cards(:proceed)
  1489.     end
  1490.   end
  1491.  
  1492.   #-----------------------------------------------------------------------------
  1493.   # Card effects
  1494.   #-----------------------------------------------------------------------------
  1495.   def invoke_card_impact(effect_name)
  1496.     array = PC27::CG::CARD_EFFECT[effect_name]
  1497.     if array[0] == :draw
  1498.       card_effect_draw_cards(array[1], array[2], array[3])
  1499.     else
  1500.       $game_message.background = 1
  1501.       $game_message.position   = 1
  1502.       $game_message.add(PC27::CG::CARD_EFF_TEXT)
  1503.       wait_for_message
  1504.       prepare_select_window(:impact, array[0])
  1505.       @temp_effect_data = [] unless @temp_effect_data
  1506.       @temp_effect_data[0] = :impact
  1507.       process_select_cards(effect_name)
  1508.     end
  1509.   end
  1510.  
  1511.   #-----------------------------------------------------------------------------
  1512.   def card_effect_draw_cards(nr, prob, trg)
  1513.     if trg == :self
  1514.       if rand(100) < prob
  1515.         @subject.draw_cards(nr)
  1516.         need_wait = true
  1517.       end
  1518.     elsif trg == :target
  1519.       targets = @subject.current_action.make_targets.compact
  1520.       for target in targets
  1521.         if rand(100) < prob
  1522.           target.draw_cards(nr)
  1523.           need_wait = true
  1524.         end
  1525.       end
  1526.     end
  1527.     wait_for_message if need_wait
  1528.   end
  1529.    
  1530.   #-----------------------------------------------------------------------------
  1531.   def process_select_cards(effect_name)
  1532.     @card_select_window.actor = BattleManager.actor
  1533.     array = PC27::CG::CARD_EFFECT[effect_name]
  1534.     case array[2]
  1535.     when :deck
  1536.       (array[1] == 0 ? amn = @card_select_window.actor.deck.size : amn = array[1])
  1537.       amn.times do
  1538.         next if @card_select_window.actor.deck.size == 0
  1539.         @card_select_window.cards.push(@card_select_window.actor.deck.shift)
  1540.       end
  1541.     when :hand
  1542.       (array[1] == 0 ? amn = @card_select_window.actor.hand.size : amn = array[1])
  1543.       amn.times do
  1544.         next if @card_select_window.actor.hand.size == 0
  1545.         @card_select_window.cards.push(@card_select_window.actor.hand.shift)
  1546.       end
  1547.     when :grave
  1548.       (array[1] == 0 ? amn = @card_select_window.actor.grave.size : amn = array[1])
  1549.       amn.times do
  1550.         next if @card_select_window.actor.grave.size == 0
  1551.         @card_select_window.cards.push(@card_select_window.actor.grave.shift)
  1552.       end
  1553.     end
  1554.     @temp_effect_data[1] = effect_name
  1555.     @temp_effect_data[2] = 0
  1556.     set_select_filter(array)
  1557.     @card_select_window.refresh
  1558.     @card_select_window.show.activate
  1559.   end
  1560.  
  1561.   #-----------------------------------------------------------------------------
  1562.   def set_select_filter(array)
  1563.     if array[4]
  1564.       @card_select_window.filter = array[4]
  1565.     elsif array[0] == :view
  1566.       @card_select_window.filter = [-1,-1,-1]
  1567.     else
  1568.       @card_select_window.filter = [0,0,0]
  1569.     end
  1570.   end
  1571.  
  1572.   #-----------------------------------------------------------------------------
  1573.   def select_cards_ok_sort
  1574.     if @card_select_window.cards.size == 0
  1575.       select_cancel
  1576.       return
  1577.     end
  1578.     if @card_select_window.sort_index != -1
  1579.     swap_cards(@card_select_window.sort_index, @card_select_window.index)
  1580.       @card_select_window.sort_index = -1
  1581.       @card_select_window.refresh
  1582.     else
  1583.       @card_select_window.sort_index = @card_select_window.index
  1584.     end
  1585.     @card_select_window.activate
  1586.   end
  1587.  
  1588.   #-----------------------------------------------------------------------------
  1589.   def select_cards_ok_take
  1590.     if @card_select_window.cards.size == 0
  1591.       select_cancel
  1592.       return
  1593.     end
  1594.     card = @card_select_window.item
  1595.     @temp_effect_data[3] = [] unless @temp_effect_data[3]
  1596.     @temp_effect_data[3].push(card)
  1597.     @card_select_window.cards.delete_at(@card_select_window.cards.index(card))
  1598.     @temp_effect_data[2] += 1
  1599.     if PC27::CG::CARD_EFFECT[@temp_effect_data[1]][6] != @temp_effect_data[2]
  1600.       @card_select_window.refresh
  1601.       @card_select_window.activate
  1602.     else
  1603.       proceed_selection
  1604.     end
  1605.   end
  1606.  
  1607.   #-----------------------------------------------------------------------------
  1608.   def proceed_selection
  1609.     @card_select_window.hide.deactivate
  1610.     @card_select_window.sort_index = -1
  1611.     restore_selected_cards
  1612.     if @temp_effect_data[0] == :cost
  1613.       BattleManager.actor.input.set_skill(@skill.id)
  1614.       BattleManager.actor.last_skill.object = @skill
  1615.       if !@skill.need_selection?
  1616.         @skill_window.hide
  1617.         next_command
  1618.       elsif @skill.for_opponent?
  1619.         select_enemy_selection
  1620.       else
  1621.         select_actor_selection
  1622.       end
  1623.     elsif @temp_effect_data[0] == :impact
  1624.       restore_taken_cards(:proceed)
  1625.       start_actor_command_selection
  1626.     end
  1627.   end
  1628.  
  1629.   def select_cancel
  1630.     @card_select_window.hide.deactivate
  1631.     @card_select_window.sort_index = -1
  1632.     restore_taken_cards(:cancel)
  1633.     restore_selected_cards
  1634.     if @temp_effect_data[0] == :cost
  1635.       BattleManager.actor.hand += BattleManager.actor.stack
  1636.       BattleManager.actor.stack = []
  1637.       on_skill_cancel
  1638.     elsif @temp_effect_data[0] == :impact
  1639.       start_actor_command_selection
  1640.     end
  1641.   end
  1642.  
  1643.  
  1644.   def restore_taken_cards(target)
  1645.     return unless @temp_effect_data && @temp_effect_data[3] && @temp_effect_data[3] != []
  1646.     if target == :proceed
  1647.       case PC27::CG::CARD_EFFECT[@temp_effect_data[1]][5]
  1648.       when :hand
  1649.         @card_select_window.actor.hand += @temp_effect_data[3]
  1650.       when :deck
  1651.         @card_select_window.actor.deck += @temp_effect_data[3]
  1652.         @card_select_window.actor.shuffle_deck(false)
  1653.       when :grave
  1654.         @card_select_window.actor.grave += @temp_effect_data[3]
  1655.       end
  1656.     elsif target == :cancel
  1657.       case PC27::CG::CARD_EFFECT[@temp_effect_data[1]][2]
  1658.       when :hand
  1659.         @card_select_window.actor.hand += @temp_effect_data[3]
  1660.       when :deck
  1661.         @card_select_window.actor.deck += @temp_effect_data[3]
  1662.       when :grave
  1663.         @card_select_window.actor.grave += @temp_effect_data[3]
  1664.       end
  1665.     end
  1666.     @temp_effect_data[3] = []
  1667.   end
  1668.  
  1669.   #-----------------------------------------------------------------------------
  1670.   def restore_selected_cards
  1671.     array = PC27::CG::CARD_EFFECT[@temp_effect_data[1]]
  1672.     case array[3]
  1673.     when :deck
  1674.       @card_select_window.cards.reverse.each { |card|
  1675.         @card_select_window.actor.deck.unshift(card)
  1676.       }
  1677.       @card_select_window.actor.shuffle_deck if array[0] == :take && @card_select_window.actor.deck.size != 0
  1678.       @status_window.refresh
  1679.     when :hand
  1680.       @card_select_window.cards.reverse.each { |card|
  1681.         @card_select_window.actor.hand.unshift(card)
  1682.       }
  1683.     when :grave
  1684.       @card_select_window.cards.reverse.each { |card|
  1685.         @card_select_window.actor.grave.unshift(card)
  1686.       }
  1687.     end
  1688.     @card_select_window.cards = []
  1689.   end
  1690.  
  1691.   #-----------------------------------------------------------------------------
  1692.   def prepare_select_window(moment, type)
  1693.     if moment == :impact
  1694.       if    type == :view
  1695.         @card_select_window.set_handler(:ok,   method(:no_method))
  1696.         @card_select_window.set_handler(:cancel, method(:select_cancel))
  1697.       elsif type == :sort
  1698.         @card_select_window.set_handler(:ok,   method(:select_cards_ok_sort))
  1699.         @card_select_window.set_handler(:cancel, method(:select_cancel))
  1700.       elsif type == :take
  1701.         @card_select_window.set_handler(:ok,   method(:select_cards_ok_take))
  1702.         @card_select_window.set_handler(:cancel, method(:select_cancel))
  1703.       end
  1704.     elsif moment == :cost
  1705.       if    type == :view
  1706.         @card_select_window.set_handler(:ok,   method(:no_method))
  1707.         @card_select_window.set_handler(:cancel, method(:proceed_selection))
  1708.       elsif type == :sort
  1709.         @card_select_window.set_handler(:ok,   method(:select_cards_ok_sort))
  1710.         @card_select_window.set_handler(:cancel, method(:proceed_selection))
  1711.       elsif type == :take
  1712.         @card_select_window.set_handler(:ok,   method(:select_cards_ok_take))
  1713.         @card_select_window.set_handler(:cancel, method(:select_cancel))
  1714.       end
  1715.     end
  1716.   end
  1717.  
  1718.   def no_method
  1719.     @card_select_window.activate
  1720.   end
  1721.        
  1722.   #-----------------------------------------------------------------------------
  1723.   def swap_cards(index1, index2)
  1724.     @card_select_window.cards[index1], @card_select_window.cards[index2] =
  1725.     @card_select_window.cards[index2], @card_select_window.cards[index1]
  1726.   end
  1727.  
  1728. end
  1729.  
  1730. #===============================================================================
  1731. # Scene_Deck
  1732. #===============================================================================
  1733.  
  1734. class Scene_Deck < Scene_MenuBase
  1735.   include PC27::CG
  1736.   #-----------------------------------------------------------------------------
  1737.   # Start
  1738.   #-----------------------------------------------------------------------------
  1739.   def start
  1740.     super()
  1741.     create_filter_window
  1742.     create_deck_window
  1743.     create_coll_window
  1744.     create_text_window
  1745.     create_card_window
  1746.     create_info_window
  1747.   end
  1748.  
  1749.   #-----------------------------------------------------------------------------
  1750.   # Creates a window to display deck cards
  1751.   #-----------------------------------------------------------------------------
  1752.   def create_deck_window
  1753.     @deck_window = Window_Deck.new(0,64)
  1754.     @deck_window.set_handler(:cancel,   method(:return_scene))
  1755.     @deck_window.set_handler(:ok,       method(:deck_to_coll))
  1756.   end
  1757.  
  1758.   #-----------------------------------------------------------------------------
  1759.   # Creates a window to display collection cards
  1760.   #-----------------------------------------------------------------------------
  1761.   def create_coll_window
  1762.     @coll_window = Window_Coll.new((Graphics.width - 210)*0.5, 64)
  1763.     @coll_window.set_handler(:cancel,   method(:return_scene))
  1764.     @coll_window.set_handler(:ok,       method(:coll_to_deck))
  1765.     @coll_window.deactivate
  1766.   end
  1767.  
  1768.   #-----------------------------------------------------------------------------
  1769.   # Creates the window that shows where you are
  1770.   #-----------------------------------------------------------------------------
  1771.   def create_text_window
  1772.     @text_window = Window_Base.new(0 ,0, Graphics.width - 210, 64)
  1773.     update_text_window
  1774.   end
  1775.  
  1776.   #-----------------------------------------------------------------------------
  1777.   # Creates the window that shows the currently selected card
  1778.   #-----------------------------------------------------------------------------
  1779.   def create_card_window
  1780.     @card_window = Window_CardHelp.new()
  1781.     @card_window.windowskin = Cache.system(CUSTOM_CARD_BG) if CUSTOM_CARD_BG
  1782.     @card_window.tone.set(*PC27::CG::ELEMENT_COLOR[0])
  1783.     @card_window.back_opacity = PC27::CG::CARD_BACK_OP
  1784.   end
  1785.  
  1786.   #-----------------------------------------------------------------------------
  1787.   # Creates a info window
  1788.   #-----------------------------------------------------------------------------
  1789.   def create_info_window
  1790.     height = Graphics.height - 284
  1791.     @info_window = Window_Base.new(
  1792.     Graphics.width - 210, Graphics.height - height, 210, height)
  1793.     @info_window.draw_text_ex(0,0,CARD_HELP_WINDOW)
  1794.   end
  1795.  
  1796.   #-----------------------------------------------------------------------------
  1797.   # Creates a window to filter cards
  1798.   #-----------------------------------------------------------------------------
  1799.   def create_filter_window
  1800.     @filter_window = Window_Filter.new(0,Graphics.height * 0.5 - 48)
  1801.     @filter_window.set_handler(:cancel,   method(:close_filter))
  1802.     @filter_window.set_handler(:ok,       method(:change_filter))
  1803.     @filter_window.z = 150
  1804.     @filter_window.hide
  1805.     @filter_window.deactivate
  1806.   end
  1807.  
  1808.   #-----------------------------------------------------------------------------
  1809.   # Changes between collection and deck window
  1810.   #-----------------------------------------------------------------------------    
  1811.   def change_to_coll
  1812.     @coll_window.activate
  1813.     @deck_window.deactivate
  1814.     Sound.play_cursor
  1815.     Input.update
  1816.   end
  1817.      
  1818.   def change_to_deck
  1819.     @deck_window.activate
  1820.     @coll_window.deactivate
  1821.     Sound.play_cursor
  1822.     Input.update
  1823.   end
  1824.  
  1825.   #-----------------------------------------------------------------------------
  1826.   # Adds commands to exchange cards
  1827.   #-----------------------------------------------------------------------------
  1828.   def coll_to_deck
  1829.     if $game_party.menu_actor.deck.size >= MAX_DECK_SIZE
  1830.       RPG::SE.new("Buzzer1", 80, 100).play
  1831.       return
  1832.     end
  1833.     /coll(?<skill_id>\d+)/ =~ @coll_window.current_symbol.to_s
  1834.     skill_id  = skill_id.to_i
  1835.     max_cards = (MAX_SAME_EXCEP.has_key?(skill_id) ? MAX_SAME_EXCEP[skill_id] : MAX_SAME_CARDS)
  1836.     if $game_party.menu_actor.deck.count{ |skill| skill.id == skill_id } >= max_cards
  1837.       RPG::SE.new("Buzzer1", 80, 100).play
  1838.       return
  1839.     end
  1840.     for skill in $game_party.coll
  1841.       if skill.id == skill_id
  1842.         $game_party.menu_actor.deck.push(
  1843.         $game_party.coll.slice!($game_party.coll.index(skill)))
  1844.         break
  1845.       end
  1846.     end
  1847.     RPG::SE.new("Cursor1", 80, 100).play
  1848.     @deck_window.refresh
  1849.     @coll_window.refresh
  1850.     update_text_window
  1851.   end
  1852.  
  1853.   def deck_to_coll
  1854.     /deck(?<skill_id>\d+)/ =~ @deck_window.current_symbol.to_s
  1855.     skill_id = skill_id.to_i
  1856.     for skill in $game_party.menu_actor.deck
  1857.       if skill.id == skill_id
  1858.         $game_party.coll.push(
  1859.         $game_party.menu_actor.deck.slice!($game_party.menu_actor.deck.index(skill)))
  1860.         break
  1861.       end
  1862.     end
  1863.     RPG::SE.new("Cursor1", 80, 100).play
  1864.     @deck_window.refresh
  1865.     @coll_window.refresh
  1866.     update_text_window
  1867.   end
  1868.  
  1869.   #-----------------------------------------------------------------------------
  1870.   # Activates filter
  1871.   #-----------------------------------------------------------------------------
  1872.   def activate_filter
  1873.     @filter_window.show
  1874.     @filter_window.activate
  1875.     @deck_window.deactivate
  1876.     @coll_window.deactivate
  1877.   end
  1878.  
  1879.   #-----------------------------------------------------------------------------
  1880.   # Changes filter settings
  1881.   #-----------------------------------------------------------------------------
  1882.   def change_filter
  1883.     case @filter_window.current_symbol
  1884.     when :filter_element
  1885.       @coll_window.filter[0]   += 1
  1886.       @filter_window.filter[0] += 1
  1887.       @coll_window.filter[0]    = 0 if $data_system.elements.size == @coll_window.filter[0]
  1888.       @filter_window.filter[0]  = 0 if $data_system.elements.size == @filter_window.filter[0]
  1889.     when :filter_type
  1890.       @coll_window.filter[1]   += 1
  1891.       @filter_window.filter[1] += 1
  1892.       @coll_window.filter[1]    = 0 unless TYPE.has_key?(@coll_window.filter[1])
  1893.       @filter_window.filter[1]  = 0 unless TYPE.has_key?(@filter_window.filter[1])
  1894.     when :filter_rarity
  1895.       @coll_window.filter[2]   += 1
  1896.       @filter_window.filter[2] += 1
  1897.       @coll_window.filter[2]    = 0 unless RARITY.has_key?(@coll_window.filter[2])
  1898.       @filter_window.filter[2]  = 0 unless RARITY.has_key?(@filter_window.filter[2])
  1899.     when :confirm
  1900.       $game_party.coll += $game_party.menu_actor.deck
  1901.       $game_party.menu_actor.deck = []
  1902.       @filter_window.confirm = false
  1903.       @filter_window.refresh
  1904.     when :call_confirm
  1905.       @filter_window.confirm = true
  1906.       @filter_window.refresh
  1907.     end
  1908.     @filter_window.refresh
  1909.     @coll_window.refresh
  1910.     @deck_window.refresh
  1911.     update_text_window
  1912.   end
  1913.  
  1914.   #-----------------------------------------------------------------------------
  1915.   # Deativates filter
  1916.   #-----------------------------------------------------------------------------
  1917.   def close_filter
  1918.     @filter_window.hide
  1919.     @filter_window.deactivate
  1920.     @coll_window.activate
  1921.     @coll_window.select(0)
  1922.   end
  1923.  
  1924.  
  1925.   #-----------------------------------------------------------------------------
  1926.   # * Frame Update
  1927.   #-----------------------------------------------------------------------------
  1928.   def update
  1929.     super()
  1930.  
  1931.     #---------------------------------------------------------------------------
  1932.     # Handles input
  1933.     #---------------------------------------------------------------------------
  1934.     if @filter_window.visible == false
  1935.       change_to_coll  if Input.trigger?(:RIGHT)
  1936.       change_to_deck  if Input.trigger?(:LEFT)
  1937.       activate_filter if Input.trigger?(:X)
  1938.       next_actor      if Input.trigger?(:R)
  1939.       prev_actor      if Input.trigger?(:L)
  1940.     end
  1941.    
  1942.     #---------------------------------------------------------------------------
  1943.     # Redraws card, if neccessary
  1944.     #---------------------------------------------------------------------------
  1945.     if @coll_window.active
  1946.       symbol = @coll_window.current_symbol
  1947.     elsif @deck_window.active
  1948.       symbol = @deck_window.current_symbol
  1949.     end
  1950.    
  1951.     if symbol != @symbol
  1952.       @symbol = symbol
  1953.       /[kl](?<id>\d+)/ =~ @symbol.to_s
  1954.       skill = ( id ? $data_skills[id.to_i] : nil)
  1955.       @card_window.set_item(skill)
  1956.     end
  1957.    
  1958.   end
  1959.  
  1960.   def on_actor_change
  1961.     RPG::SE.new("Cursor2", 80, 100).play
  1962.     @deck_window.refresh
  1963.     @deck_window.select(0)
  1964.     @coll_window.select(0)
  1965.     update_text_window
  1966.   end
  1967.  
  1968.   def update_text_window
  1969.     @text_window.contents.clear
  1970.     text_name = $game_party.menu_actor.name + "s " + DECK
  1971.     @text_window.draw_text_ex(0, 8, text_name)
  1972.     text_deck = $game_party.menu_actor.deck.size.to_s + "/" + MAX_DECK_SIZE.to_s
  1973.     xpos = @text_window.width - 10*(text_deck.size+1) - @text_window.padding
  1974.     @text_window.draw_text_ex(xpos, 8, text_deck)
  1975.   end
  1976.  
  1977. end
  1978.  
  1979.  
  1980. class Window_Deck < Window_Command
  1981.  
  1982.   #--------------------------------------------------------------------------
  1983.   # Makes Command List
  1984.   #--------------------------------------------------------------------------
  1985.   def make_command_list
  1986.     add_deck_commands
  1987.   end
  1988.  
  1989.   #--------------------------------------------------------------------------
  1990.   # Add Card Commands to List
  1991.   #--------------------------------------------------------------------------
  1992.   def add_deck_commands
  1993.     $game_party.menu_actor.sort_cards(:deck)
  1994.     deck = $game_party.menu_actor.deck
  1995.     if deck.empty?
  1996.       add_command("---", :nothing)
  1997.       return
  1998.     end
  1999.     hash = {}
  2000.     for skill in deck
  2001.       if hash.has_key?(skill.id)
  2002.         hash[skill.id] += 1
  2003.       else
  2004.         hash[skill.id] = 1
  2005.       end
  2006.     end
  2007.     hash.each_key do |id|
  2008.       add_command(hash[id].to_s + "x " + $data_skills[id].name, ("deck" + id.to_s).to_sym)
  2009.     end
  2010.   end
  2011.  
  2012.   #--------------------------------------------------------------------------
  2013.   # Get Window Height
  2014.   #--------------------------------------------------------------------------
  2015.   def window_height
  2016.     Graphics.height - 64
  2017.   end
  2018.  
  2019.   #--------------------------------------------------------------------------
  2020.   # Get Window width
  2021.   #--------------------------------------------------------------------------
  2022.   def window_width
  2023.     (Graphics.width - 210) * 0.5
  2024.   end
  2025.  
  2026.   #--------------------------------------------------------------------------
  2027.   # Overwrite process_ok so the window won't be disabled
  2028.   #--------------------------------------------------------------------------
  2029.   def process_ok
  2030.     if current_item_enabled?
  2031.       Input.update
  2032.       call_ok_handler
  2033.       select(index - 1) unless current_symbol
  2034.     else
  2035.       Sound.play_buzzer
  2036.     end
  2037.   end
  2038.  
  2039. end
  2040.  
  2041.  
  2042. class Window_Coll < Window_Command
  2043.  
  2044.   attr_accessor :filter
  2045.    
  2046.   def initialize(width, heigth)
  2047.     @filter = [0,0,0]
  2048.     super(width, heigth)
  2049.   end
  2050.  
  2051.   #--------------------------------------------------------------------------
  2052.   # Makes Command List
  2053.   #--------------------------------------------------------------------------
  2054.   def make_command_list
  2055.     add_coll_commands
  2056.   end
  2057.  
  2058.   #--------------------------------------------------------------------------
  2059.   # Add Collection Commands to List
  2060.   #--------------------------------------------------------------------------
  2061.   def add_coll_commands
  2062.     $game_party.coll.sort!{|a,b| a.id <=> b.id}
  2063.     coll = $game_party.coll
  2064.     if coll.empty?
  2065.       add_command("---", :nothing)
  2066.       return
  2067.     end
  2068.     hash = {}
  2069.     for skill in coll
  2070.       next unless match_filter?(skill)
  2071.       if hash.has_key?(skill.id)
  2072.         hash[skill.id] += 1
  2073.       else
  2074.         hash[skill.id] = 1
  2075.       end
  2076.     end
  2077.     hash.each_key do |id|
  2078.       add_command(hash[id].to_s + "x " + $data_skills[id].name, ("coll" + id.to_s).to_sym)
  2079.     end
  2080.   end
  2081.  
  2082.   #--------------------------------------------------------------------------
  2083.   # Checks if a card meets the specified filter criteria
  2084.   #--------------------------------------------------------------------------
  2085.   def match_filter?(skill)
  2086.     return false unless skill.damage.element_id  == @filter[0] || @filter[0] == 0
  2087.     return false unless skill.type               == @filter[1] || @filter[1] == 0
  2088.     return false unless skill.rarity             == @filter[2] || @filter[2] == 0
  2089.     return true
  2090.   end
  2091.  
  2092.  
  2093.   #--------------------------------------------------------------------------
  2094.   # Get Window Height
  2095.   #--------------------------------------------------------------------------
  2096.   def window_height
  2097.     Graphics.height - 64
  2098.   end
  2099.  
  2100.   #--------------------------------------------------------------------------
  2101.   # Get Window width
  2102.   #--------------------------------------------------------------------------
  2103.   def window_width
  2104.     (Graphics.width - 210) * 0.5
  2105.   end
  2106.  
  2107.   def process_ok
  2108.     if current_item_enabled?
  2109.       Input.update
  2110.       call_ok_handler
  2111.       select(index - 1) unless current_symbol
  2112.     else
  2113.       Sound.play_buzzer
  2114.     end
  2115.   end
  2116.  
  2117. end
  2118.  
  2119.  
  2120. class Window_Filter < Window_Command
  2121.   include PC27::CG
  2122.  
  2123.   attr_accessor :filter
  2124.   attr_accessor :confirm
  2125.  
  2126.   def initialize(width, heigth)
  2127.     @filter = [0,0,0]
  2128.     @confirm = false
  2129.     super(width, heigth)
  2130.     hide
  2131.   end
  2132.    
  2133.   #--------------------------------------------------------------------------
  2134.   # Makes Command List
  2135.   #--------------------------------------------------------------------------
  2136.   def make_command_list
  2137.     add_filter_commands
  2138.   end
  2139.  
  2140.   #--------------------------------------------------------------------------
  2141.   # Add Collection Commands to List
  2142.   #--------------------------------------------------------------------------
  2143.   def add_filter_commands
  2144.     add_command(FILTER_TEXT + F_ELEMENT + (@filter[0]==0 ? "---" : $data_system.elements[@filter[0]] ), :filter_element)
  2145.     add_command(FILTER_TEXT + F_TYPE    + (@filter[1]==0 ? "---" : TYPE[@filter[1]]),        :filter_type)
  2146.     add_command(FILTER_TEXT + F_RARITY  + (@filter[2]==0 ? "---" : RARITY[@filter[2]][1]),   :filter_rarity)
  2147.     add_empty_deck_command
  2148.   end
  2149.  
  2150.   #--------------------------------------------------------------------------
  2151.   # Get Window Height
  2152.   #--------------------------------------------------------------------------
  2153.   def window_height
  2154.     96
  2155.   end
  2156.   #--------------------------------------------------------------------------
  2157.   # Get Window width
  2158.   #--------------------------------------------------------------------------
  2159.   def window_width
  2160.     Graphics.width
  2161.   end
  2162.  
  2163.   def process_ok
  2164.     if current_item_enabled?
  2165.       RPG::SE.new("Cursor1", 80, 100)
  2166.       Input.update
  2167.       call_ok_handler
  2168.     else
  2169.       Sound.play_buzzer
  2170.     end
  2171.   end
  2172.  
  2173.   def add_empty_deck_command
  2174.     if @confirm
  2175.       add_command(CONFIRM, :confirm)
  2176.     else
  2177.       add_command(EMPTY_DECK, :call_confirm)
  2178.     end
  2179.   end
  2180.  
  2181.   def hide
  2182.     @confirm = false
  2183.     super
  2184.   end
  2185. end
  2186.  
  2187.  
  2188. class Window_MenuCommand < Window_Command
  2189.  
  2190.   #--------------------------------------------------------------------------
  2191.   # Replaces skills with Deck (overwrite)
  2192.   #--------------------------------------------------------------------------
  2193.  
  2194.   def add_main_commands
  2195.     add_command(Vocab::item,    :item,   main_commands_enabled)
  2196.     add_command(PC27::CG::DECK, :deck,   main_commands_enabled)
  2197.     add_command(Vocab::equip,   :equip,  main_commands_enabled)
  2198.     add_command(Vocab::status,  :status, main_commands_enabled)
  2199.   end
  2200.  
  2201. end
  2202.  
  2203.  
  2204. class Scene_Menu < Scene_MenuBase  
  2205.  
  2206.   #--------------------------------------------------------------------------
  2207.   # Adds a handler to access the deck scene (alias)
  2208.   #--------------------------------------------------------------------------
  2209.   alias pc27_cardgame_scenemenu_create_cmd_wdw             create_command_window
  2210.   def create_command_window
  2211.     pc27_cardgame_scenemenu_create_cmd_wdw
  2212.     @command_window.set_handler(:deck,    method(:command_personal))
  2213.   end
  2214.  
  2215.  
  2216.   #--------------------------------------------------------------------------
  2217.   # Adds :deck to the personal command process (alias)
  2218.   #--------------------------------------------------------------------------
  2219.   alias pc27_cardgame_scenemenu_on_personal_ok                    on_personal_ok
  2220.   def on_personal_ok
  2221.     pc27_cardgame_scenemenu_on_personal_ok
  2222.     case @command_window.current_symbol
  2223.     when :deck
  2224.       SceneManager.call(Scene_Deck)
  2225.     end
  2226.   end
  2227.  
  2228. end
  2229.  
  2230. ################################################################################
  2231. #                            End of script                                     #
  2232. ################################################################################
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top