Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # CARDGAME SKILL/BATTLE SYSTEM
- # Author: pencilcase27
- # Version: v1.09
- #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # v1.00 - Script released
- # v1.01 - Added stack, skills now can't revive themself.
- # - Added CardHelp_Window, normal help window is no longer used to draw cards
- # - Item Window is back to normal
- # v1.02 - reworked card effects
- # - added deck count and toggle actor to deck build scene
- # - simplified scriptcalls to add and remove cards from collection
- # - Added max_card limit exception
- # v1.03 - reworked card effects (again)
- # - added card cost effects
- # - added custom images
- # v1.04 - added more script calls
- # - changed card costs slightly
- # - bugfixes
- # v1.05 - bugfixes
- # v1.06 - added initial decks for actors
- # v1.07 - fixed a bug with item canceling
- # - fixed a bug with the draw card effect
- # v1.08 - added Attack and Guard command
- # - added two notetags for equip
- # v1.09 - fixed an issue with attack and guard
- # - added limitations on how many cards can be played each turn
- # - added a feature to instantly empty your deck
- #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- #
- # Description
- #
- # This script changes the way actors aquire and use skills. Instead of each
- # actor having an own set of skills, the party now has a card collection of
- # different cards, each card representing a skill. Out of this collection, each
- # actor can now create a custom deck.
- # In battle, actors will act in turns. They draw cards and, while an actor is
- # active, he can play as many cards and items as he wants, as long as he has
- # the recources to do so. Once he is done, he can end his turn and the next
- # actor becomes active. When every actor finished his or her turn, the enemys
- # use their skills normal.
- #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- #
- # Script Calls
- #
- # add_card_to_coll(id1, id2, id3, ...)
- # Adds cards of the given skill ids to your collection
- #
- # remove_card?(id)
- # Tries to remove a single card of the given skill id from your collection.
- # Returns true if successfull and false otherwise.
- #
- # remove_all_cards(id1, id2, ...)
- # Removes all cards of the given skill ids from both the players decks and
- # from the collection
- #
- # has_card?(id)
- # Checks if the player has a specific card in his collection or in his deck
- #
- # count_actor_deck(id)
- # Returns the amount of cards in this actors deck
- #
- # count_all_decks
- # Returns the combined deck size of all actors
- #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- #
- # Skill Notetags
- #
- # <card id: x>
- # The card id of the skill. Each card must have a unique id.
- # Important: Every time this script uses the word id, it refers to the skills
- # id, not the card id! The card id is only used to sort cards.
- #
- # <card type: x>
- # The type of the card. Different types can be defined below.
- #
- # <card rarity: x>
- # The rarity of the card. Different raritys can be defined below.
- #
- # <card cost: effect_name>
- # Adds the given cost effect to the card. Please read about card effects
- # down below.
- #
- # <card impact: effect_name>
- # Adds the given impact effect to the card. Please read about card effects
- # down below.
- #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- #
- # Armor/Weapon Notetags
- #
- # <extra start cards: x>
- # Draws x extra cards at the begin of each battle
- #
- # <extra turn cards: x>
- # Draws x extra cards at the begin of each turn
- #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- #
- # Damage Formula
- #
- # Those commands can be used for a skills damage formula. Make sure they
- # always target an actor, since they won't have any effect on enemys. Minor
- # scripting knowlegde is required to make the most out of those methods.
- #
- # a/b.revive_grave(true/false)
- # Shuffles your grave in your deck without penalty. If the argumet is true,
- # a message will be shown.
- #
- # a/b.revive_penalty
- # Causes the revive penalty to happen.
- #
- # a/b.shuffle_deck(true/false)
- # Shuffles the actors deck. If the argument is true, a sound will be played.
- #
- # a/b.card_to_grave?(skill_id)
- # Tries to throw the skill with the given ID to the grave. Returns true, if it's
- # successfull and false otherwise.
- #
- # a/b.throw_cards(n)
- # Throws n random cards to the grave. If n = 0, the actor will loose all cards.
- # Returns how many cards were thrown away.
- #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- #
- # Card Effects
- #
- # Card effects are special, card related effects like "draw x cards" or
- # "discard a fire spell to play this card" or "look at the top 5 cards of your
- # deck and put them back in any order". Every card effect can be played both as
- # a card cost or as a card impact. Costs are handled before the player plays the
- # cards, impacts after.
- # To set up a card effect, scroll to the end of Options where you will find an
- # option called CARD_EFFECT. There you can add a effect name and the effects
- # arguments. Then add the effect either as cost or as impact via note tag to
- # a skill.
- # Each skill can have one cost effect and one impact effect.
- # Each item can have one impact effect.
- # WARNING: This is not trivial. Read carefully!
- #
- # Type: Draw
- # Simply draws cards
- # "effect_name" => [:draw, a, b, c]
- # a -> how many cards do you want to draw?
- # b -> chance the effect is successfull (between 0 and 100)
- # c -> :self to make only the user draw a card, :target to apply the effect to
- # each target.
- # Example:
- # "draw2" => [:draw, 2, 100, :self]
- # -> The user of this skill will draw 2 cards.
- #
- # Type: View (impact only)
- # Looks at a certain number of cards taken from location a, and then puts them
- # back to location b. Locations can be :deck, :hand and :grave.
- # "effect_name" => [ :view, a, b, c]
- # a -> how many cards do you want to view? 0 for the entire location.
- # b -> from where do you want to take those cards?
- # c -> where do you want to put them when you're done?
- # Example:
- # "view_effect" => [:view, 10, :deck, :deck]
- # -> look at the top 10 cards of your deck.
- #
- # Type: Sort
- # Same as view but allows to sort the cards.
- # Example:
- # "stupid_effect" => [:sort, 0, :hand, :deck]
- # -> Put your entire hand ontop of your deck in any order.
- #
- # Type: Take
- # This one is a little bit harder. It allows to take some of the viewed cards
- # from one location to another.
- # "effect_name" => [:take, a, b, c, d, e, f]
- # a, b, c -> same as above
- # d -> filter that determines which cards can be choosen,
- # [element_id, type_id, rarity_id], 0 for all id's allowed.
- # e -> the location to put the choosen cards.
- # f -> how many cards can be choosen.
- # Example:
- # "search_for_element2" => [:take, 0, :deck, :deck, [2,0,0], :hand, 1]
- # -> Search your deck for one card of element 2 and take it to your hand.
- # Another Example:
- # "discard_cost" => [:take, 0, :hand, :hand, [0,0,0], :grave, 2]
- # -> If this is added as a cost effect, the player has to discard two cards
- # from his or her hand to play this card.
- #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- module PC27
- module CG
- #-------------------------------------------------------------------------------
- #
- # Options
- #
- #-------------------------------------------------------------------------------
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Vocab
- #------------------------------------------------------------------------------
- # DECK - Name of the actors Deck
- # GRAVE - Name of the actors Grave
- # COLLECTION - Name of the Card Collection
- # END_TURN - Name of the command that will end a players turn
- # DRAW_MESSAGE - Text that appears when an actor draws a card. Displayed
- # as "Actor Name" + DRAW_MESSAGE + "Skill Name"
- # REVIVE_MSG - Text that appears when you revive your grave
- # CARD_HELP_WINDOW - Help text shown in the deck scene (Use \n to break line)
- # FILTER_TEXT - First part of the text inside of the filter window
- # F_... - Second part of the text inside of the filter window
- # EMPTY_DECK - Text in filter window that allows to empty the entire deck
- # CONFIRM - Confirmation for EMPTY_DECK
- # CARD_EFF_TEXT - Text displayed when a card effect is evaluated.
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- DECK = "Deck"
- GRAVE = "Grave"
- COLLECTION = "Collection"
- END_TURN = "End Turn"
- DRAW_MESSAGE = "draws"
- REVIVE_MSG = "'s grave was revived"
- CARD_HELP_WINDOW = "Select: move card\nX(A): open filter"
- FILTER_TEXT = "Filter by "
- F_ELEMENT = "element: "
- F_TYPE = "type: "
- F_RARITY = "rarity: "
- EMPTY_DECK = "Remove all cards from Deck"
- CONFIRM = "Are you sure?"
- CARD_EFF_TEXT = "Choose cards:"
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Gameplay
- #------------------------------------------------------------------------------
- # USE_ATTACK - Enables the regular attack command in battle.
- # USE_GUARD - Enables the regular guard command in battle.
- # USE_ITEMS - Are items in battle enabeld?
- # START_CARDS - Cards drawn in Turn 1
- # MAX_DECK_SIZE - Maximum size of a players deck
- # MAX_SAME_CARDS - Maximum amount of same cards in each deck
- # MAX_ACTIONS - Maximum amount of cards an actor can use each turn
- # DECK_EMPTY - What happens if an actor tries to draw a card but has an
- # empty deck?
- # 1 -> The actor dies
- # 2 -> The actor dies if his grave is empty, too. If it
- # isn't, he revives his grave, meaning he shuffles his
- # grave back into his deck. Revive penalty is applied
- # 3 -> Like 2, but the actor won't die if the grave is empty
- # REVIVE_PENALTY - The revive penalty. Types are :hp, :mhp, :mp and :mmp.
- # The actor will lose either hp or mp, based on its current
- # or maximum value
- # MAX_SAME_EXCEP - Exceptions to MAX_SAME_CARDS
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- USE_ATTACK = true
- USE_GUARD = true
- USE_ITEMS = true
- START_CARDS = 5
- MAX_DECK_SIZE = 30
- MAX_SAME_CARDS = 4
- MAX_ACTIONS = 0 # if this is 0, an actor can play infinite cards
- # (until he's out of mana or cards)
- DECK_EMPTY = 1
- # [percent, type]
- REVIVE_PENALTY = [ 50, :hp]
- MAX_SAME_EXCEP = {
- # skill id => max. amount,
- 5 => 2,
- 7 => 1,
- } # do not remove this
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Icons and Sound
- #------------------------------------------------------------------------------
- # DRAW_SOUND - Sound that will play when you draw a card
- # PENALTY_SOUND - Sound that will play when the revive penalty is applied
- # DECK_ICON - Icon that displays an actors deck size in battle
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # ["filename", volume, pitch] -> ["", 0, 0] means no sound
- DRAW_SOUND = [ "Book1", 100, 150]
- PENALTY_SOUND = [ "Attack1", 100, 50]
- DECK_ICON = 228
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Cards
- #------------------------------------------------------------------------------
- # To add custom card images, add an image with the name Card + skill id to your
- # graphics folder (example: Card2). The script will use every picture it can
- # find. Card0 is used when no card is selected. If you choose to do this, most
- # of those options are irrelevant.
- #
- # CUSTOM_CARD_BG - Name of the windowskin used for cards (in Graphics/System)
- # CARD_BACK_OP - Background opacity of cards (0-255)
- # CARD_NAME_UP - If true, card names will be written in capital letters
- # MP_COLOR - Textcolor the mana costs are drawn in
- # TP_COLOR - Textcolor the tp costs are drawn in
- # RARITY - Name and icon index of the raritys your cards have
- # TYPES - Different types your cards can have
- # ELEMENT_COLOR - Background color of your cards based on their element ID
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- CUSTOM_CARD_BG = "Window" # RPG Maker default is "Window"
- CARD_BACK_OP = 255
- CARD_NAME_UP = true
- MP_COLOR = 4
- TP_COLOR = 3
- RARITY = {
- # ID => [ icon, "name"]
- 1 => [ 127, "common"],
- 2 => [ 126, "uncommon"],
- 3 => [ 125, "rare"],
- } # do not remove this
- TYPE = {
- # ID => "name"
- 1 => "Spell",
- 2 => "Support",
- 3 => "Buff",
- } # do not remove this
- ELEMENT_COLOR = {
- # ID => [red, grn, blu]
- 0 => [ 0, 0, 0], # 0 is used for skills without an element
- 1 => [100, 100, 100],
- 2 => [200, 0, 0],
- 3 => [200, 200, 0],
- 4 => [ 0, 0, 200],
- } # do not remove this
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Start Decks
- #------------------------------------------------------------------------------
- # Those are the initial decks for each actor. If an actors id is not listed
- # below, his initial deck will be empty.
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- START_DECKS = {
- 1 => [3,3,3,7,9,8,6,12,12,12,14,15,16,3,3,3],
- 2 => [4,4,4,8,9,9,9,9,10,10,10],
- } # do not remove this
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Card Effects
- #------------------------------------------------------------------------------
- # The first effect called "grave" is available as a command in battle and
- # usually used to view your grave. You can change this effect if you wish, but
- # keep in mind that the player can use this effect as many times as he wants.
- # Please add all other effects below. Do not forget that every effect needs its
- # own name. You can name them however you want, as long as you dont use the
- # same name twice.
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- CARD_EFFECT = {
- "grave" => [:view, 0, :grave, :grave], # Grave command effect
- "foresight" => [:view, 10, :deck, :deck] ,
- "2" => [:draw, 2, 100, :target],
- "intervention" => [:sort, 5, :deck, :deck],
- "rise" => [:take, 0, :grave, :grave, [0,0,0], :hand, 1],
- "emp" => [:take, 0, :hand, :hand, [0,0,0], :grave, 2],
- "forestfire" => [:take, 0, :deck, :deck, [2,0,0], :hand, 1],
- "test" => [:take, 0, :hand, :hand, [0,0,0], :deck, 1],
- } # do not remove this
- #-------------------------------------------------------------------------------
- #
- # End Options
- #
- #-------------------------------------------------------------------------------
- end #CG
- end #PC27
- ################################################################################
- # Start of script #
- ################################################################################
- $imported = {} if $imported.nil?
- $imported["PC27: CardGame System"] = true
- #===============================================================================
- # Load notetags
- #===============================================================================
- module DataManager
- class <<self; alias load_database_pc27_cardgame load_database; end
- def self.load_database
- load_database_pc27_cardgame
- load_notetags_pc27_cardgame
- end
- def self.load_notetags_pc27_cardgame
- for skill in $data_skills
- next if skill.nil?
- skill.load_notetags_pc27_cardgame_skill
- end
- for item in $data_items
- next if item.nil?
- item.load_notetags_pc27_cardgame_item
- end
- for state in $data_states
- next if state.nil?
- state.load_notetags_pc27_cardgame_states
- end
- for equip_type in [$data_weapons, $data_armors]
- for obj in equip_type
- next if obj.nil?
- obj.load_notetags_pc27_cardgame_equip
- end
- end
- end
- end
- class RPG::UsableItem < RPG::BaseItem
- attr_accessor :card_id
- attr_accessor :type
- attr_accessor :rarity
- attr_accessor :cost
- attr_accessor :impact
- #-----------------------------------------------------------------------------
- # Add card attributes
- #-----------------------------------------------------------------------------
- def load_notetags_pc27_cardgame_skill
- @description = wordwrap(@description)
- @card_id = 0
- @type = 1
- @rarity = 1
- @cost = false
- @impact = false
- self.note.split(/[\r\n]+/).each { |line|
- if /<card[ -_]id: +(?<inr>\d+)>/i =~ line
- @card_id = inr.to_i
- elsif /<card[ -_]type: +(?<tnr>\d+)>/i =~ line
- @type = tnr.to_i
- elsif /<card[ -_]rarity: +(?<rnr>\d+)>/i =~ line
- @rarity = rnr.to_i
- elsif /<card[ -_]cost: +(?<cst>.+)>/i =~ line
- @cost = cst
- elsif /<card[ -_]impact: +(?<imp>.+)>/i =~ line
- @impact = imp
- end
- }
- end
- def load_notetags_pc27_cardgame_item
- @impact = false
- self.note.split(/[\r\n]+/).each { |line|
- if /<card[ -_]impact: +(?<imp>.+)>/i =~ line
- @impact = imp
- end
- }
- end
- #-----------------------------------------------------------------------------
- # Method to rearange text so it fits inside a window
- #-----------------------------------------------------------------------------
- def wordwrap(desc_text, window = nil, default_max_chars = 16)
- max_chars = (window ? (window.width - 2 * window.padding) / 10 : default_max_chars)
- text, line= "", ""
- desc_text.split(/[\r\n ]+/).each { |word|
- if word.size + line.size > max_chars
- text += line+"\n"
- line = word
- else
- line += word
- end
- line += " "
- }
- text += line
- return text
- end
- end
- class RPG::EquipItem < RPG::BaseItem
- attr_accessor :extra_turn_cards
- attr_accessor :extra_start_cards
- def load_notetags_pc27_cardgame_equip
- @extra_turn_cards = 0
- @extra_start_cards = 0
- self.note.split(/[\r\n]+/).each { |line|
- if /<extra[ -_]turn[ -_]cards: +(?<tnr>\d+)>/i =~ line
- @extra_turn_cards = tnr.to_i
- elsif /<extra[ -_]start[ -_]cards: +(?<snr>\d+)>/i =~ line
- @extra_start_cards = snr.to_i
- end
- }
- end
- end
- class RPG::State < RPG::BaseItem
- attr_reader :limited_actions
- def load_notetags_pc27_cardgame_states
- @limited_actions = 0
- self.note.split(/[\r\n]+/).each { |line|
- if /<limited[ -_]actions: +(?<lnr>\d+)>/i =~ line
- @limited_actions = lnr.to_i
- end
- }
- end
- end
- #===============================================================================
- # Game_Interpreter
- #===============================================================================
- class Game_Interpreter
- def add_card_to_coll(*args)
- for id in args
- $game_party.coll.push($data_skills[id])
- end
- end
- def remove_card?(id)
- for i in (0...$game_party.coll.length)
- if $game_party.coll[i].id == id
- $game_party.coll.delete_at(i)
- return true
- end
- end
- return false
- end
- def remove_all_cards(*args)
- for id in args
- $game_party.coll -= [$data_skills[id]]
- for actor in $game_party.members
- actor.deck -= [$data_skills[id]]
- end
- end
- end
- def has_card?(id)
- for card in $game_party.coll
- return true if card.id == id
- end
- for actor in $game_party.members
- for card in actor.deck
- return true if card.id == id
- end
- end
- return false
- end
- def count_actor_deck(id)
- return $game_actors[id].deck.size
- end
- def count_all_decks
- nr = 0
- for actor in $game_party.members
- nr += actor.deck.size
- end
- return nr
- end
- end
- #===============================================================================
- # Game_Battler
- #===============================================================================
- class Game_Battler < Game_BattlerBase
- #-----------------------------------------------------------------------------
- # defines card actions for non actors, in case the user messes up
- #-----------------------------------------------------------------------------
- def revive_grave(show = true) ;end
- def revive_penalty ;end
- def shuffle_deck(sound = true);end
- def card_to_grave?(id) ;end
- def throw_cards(n) ;end
- def draw_cards(n) ;end
- end
- #===============================================================================
- # Game_Actor
- #===============================================================================
- class Game_Actor < Game_Battler
- #-----------------------------------------------------------------------------
- # Attributes
- #-----------------------------------------------------------------------------
- attr_accessor :deck
- attr_accessor :grave
- attr_accessor :hand
- attr_accessor :stack
- attr_accessor :turn_actions
- #-----------------------------------------------------------------------------
- # Adds Hand, Deck, Grave and Stack to an Actor (alias)
- #-----------------------------------------------------------------------------
- alias pc27_cardgame_gameactor_setup setup
- def setup(actor_id)
- pc27_cardgame_gameactor_setup(actor_id)
- setup_start_deck(actor_id)
- @hand = []
- @grave = []
- @stack = []
- @turn_actions = { :can_attack => true,
- :can_guard => true,
- :actions => 0, }
- end
- #-----------------------------------------------------------------------------
- # Setup for the initial deck (new)
- #-----------------------------------------------------------------------------
- def setup_start_deck(actor_id)
- @deck = []
- if PC27::CG::START_DECKS.has_key?(actor_id)
- PC27::CG::START_DECKS[actor_id].each { |card| @deck.push($data_skills[card]) }
- end
- end
- #-----------------------------------------------------------------------------
- # Draws n cards from the deck (new)
- #-----------------------------------------------------------------------------
- def draw_cards(n, show = true, sound = true)
- n.times do
- if @deck.length == 0
- add_state(1) if PC27::CG::DECK_EMPTY == 1
- return if PC27::CG::DECK_EMPTY == 1
- if @grave.length == 0
- add_state(1) if PC27::CG::DECK_EMPTY == 2
- return
- else
- revive_grave
- revive_penalty if PC27::CG::REVIVE_PENALTY[0] > 0
- end
- end
- RPG::SE.new(*PC27::CG::DRAW_SOUND).play and 30.times { Graphics.update; Input.update } if sound
- skill = @deck.shift
- @hand.push(skill)
- if show
- $game_message.background = 1
- $game_message.position = 1
- text = @name + " " + PC27::CG::DRAW_MESSAGE + " " + skill.name
- $game_message.add(text)
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Puts all cards from your grave back into your deck (new)
- #-----------------------------------------------------------------------------
- def revive_grave(show = true)
- @deck += @grave
- @grave = []
- shuffle_deck(false)
- if show
- $game_message.background = 1
- $game_message.position = 1
- text = @name + PC27::CG::REVIVE_MSG
- $game_message.add(text)
- end
- end
- #-----------------------------------------------------------------------------
- # Revive penalty (new)
- #-----------------------------------------------------------------------------
- def revive_penalty
- percent = PC27::CG::REVIVE_PENALTY[0] * 0.01
- case PC27::CG::REVIVE_PENALTY[1]
- when :hp
- @hp -= (@hp * percent).round
- when :mhp
- @hp -= (@mhp * percent).round
- when :mp
- @mp -= (@mp * percent).round
- when :mmp
- @mp -= (@mmp * percent).round
- end
- RPG::SE.new(*PC27::CG::PENALTY_SOUND).play
- end
- #-----------------------------------------------------------------------------
- # Shuffles the deck (new)
- #-----------------------------------------------------------------------------
- def shuffle_deck(sound = true)
- if sound
- 5.times do
- RPG::SE.new(PC27::CG::DRAW_SOUND[0], 100, 150).play
- 20.times { Graphics.update; Input.update }
- RPG::SE.new(PC27::CG::DRAW_SOUND[0], 100, 100).play
- 10.times { Graphics.update; Input.update }
- end
- end
- @deck = @deck.shuffle
- end
- #-----------------------------------------------------------------------------
- # Sorts Hand, Deck or Grave (new)
- #-----------------------------------------------------------------------------
- def sort_cards(location)
- case location
- when :deck
- @deck.sort!{|a,b| a.card_id <=> b.card_id}
- when :hand
- @hand.sort!{|a,b| a.card_id <=> b.card_id}
- when :grave
- @grave.sort!{|a,b| a.card_id <=> b.card_id}
- end
- end
- #-----------------------------------------------------------------------------
- # Tries to put a specific card from your hand to your grave (new)
- #-----------------------------------------------------------------------------
- def card_to_grave?(id)
- for i in (0...@hand.length)
- if @hand[i].id == id
- @grave.push(@hand[i])
- @hand.delete_at(i)
- return true
- end
- end
- return false
- end
- #-----------------------------------------------------------------------------
- # Tries to put a specific card from your hand to your stack (new)
- #-----------------------------------------------------------------------------
- def card_to_stack?(id)
- for i in (0...@hand.length)
- if @hand[i].id == id
- @stack.push(@hand[i])
- @hand.delete_at(i)
- return true
- end
- end
- return false
- end
- #-----------------------------------------------------------------------------
- # Puts n random cards from your hand to your grave (new)
- #-----------------------------------------------------------------------------
- def throw_cards(n)
- amount_thrown_cards = 0
- if n == 0
- amount_thrown_cards += @hand.size
- @grave += @hand
- @hand = []
- else
- n.times do
- break if @hand.size == 0
- @grave.push(@hand.slice!(rand(@hand.size-1)))
- amount_thrown_cards += 1
- end
- end
- return amount_thrown_cards
- end
- #-----------------------------------------------------------------------------
- # Shuffles Deck and draws cards at the begin of each battle (new)
- #-----------------------------------------------------------------------------
- def on_battle_start
- super()
- shuffle_deck(false)
- draw_cards(starting_cards, false, false)
- @turn_actions[:can_attack] = true
- @turn_actions[:can_guard] = true
- @turn_actions[:actions] = available_actions
- end
- #-----------------------------------------------------------------------------
- # Starting Cards (new)
- #-----------------------------------------------------------------------------
- def starting_cards
- x = PC27::CG::START_CARDS
- @equips.each { |equip|
- next unless equip
- next unless equip.object
- x += equip.object.extra_start_cards
- }
- return x
- end
- #-----------------------------------------------------------------------------
- # Draws a card at the end of each turn (new)
- #-----------------------------------------------------------------------------
- def on_turn_end
- super()
- if $game_party.in_battle && !death_state?
- draw_cards(turn_cards, true, true)
- @turn_actions[:can_attack] = true
- @turn_actions[:can_guard] = true
- @turn_actions[:actions] = available_actions
- end
- end
- #-----------------------------------------------------------------------------
- # Determines the amount of actions an actor can make (new)
- #-----------------------------------------------------------------------------
- def available_actions
- for id in @states
- state = $data_states[id]
- if state.limited_actions != 0
- x = state.limited_actions if x.nil? || x > state.limited_actions
- end
- end
- if PC27::CG::MAX_ACTIONS <= 0
- return (x ? x : -1)
- else
- return (x ? [x, PC27::CG::MAX_ACTIONS].min : PC27::CG::MAX_ACTIONS)
- end
- end
- #-----------------------------------------------------------------------------
- # Turn Cards(new)
- #-----------------------------------------------------------------------------
- def turn_cards
- x = 1
- @equips.each { |equip|
- next unless equip
- next unless equip.object
- x += equip.object.extra_turn_cards
- }
- return x
- end
- #-----------------------------------------------------------------------------
- # Restore deck at the end of battle (new)
- #-----------------------------------------------------------------------------
- def on_battle_end
- @deck += @hand + @grave
- @hand, @grave = [],[]
- super()
- end
- #--------------------------------------------------------------------------
- # * Determine Usability of Attack
- #--------------------------------------------------------------------------
- def attack_usable?
- super && @turn_actions[:can_attack]
- end
- #--------------------------------------------------------------------------
- # * Determine Usability of Guard
- #--------------------------------------------------------------------------
- def guard_usable?
- super && @turn_actions[:can_guard]
- end
- end
- #===============================================================================
- # Game_Party
- #===============================================================================
- class Game_Party < Game_Unit
- #-----------------------------------------------------------------------------
- # Attributes
- #-----------------------------------------------------------------------------
- attr_accessor :coll
- #-----------------------------------------------------------------------------
- # Adds a card collection to the party (alias)
- #-----------------------------------------------------------------------------
- alias pc27_gameparty_initialize initialize
- def initialize
- pc27_gameparty_initialize
- @coll = []
- end
- end
- #===============================================================================
- # Window_SkillList
- #===============================================================================
- class Window_SkillList < Window_Selectable
- #--------------------------------------------------------------------------
- # Make skill list from @hand, not from @skills (overwrite)
- #--------------------------------------------------------------------------
- def make_item_list
- @actor.sort_cards(:hand)
- @data = @actor.hand
- end
- #--------------------------------------------------------------------------
- # Prevents the costs from beeing drawn (overwrite)
- #--------------------------------------------------------------------------
- def draw_item(index)
- skill = @data[index]
- if skill
- rect = item_rect(index)
- draw_item_name(skill, rect.x, rect.y, enable?(skill))
- end
- end
- end
- #===============================================================================
- # Window_ActorCommand
- #===============================================================================
- class Window_ActorCommand < Window_Command
- #--------------------------------------------------------------------------
- # Add "End Turn" command (new)
- #--------------------------------------------------------------------------
- def add_turn_end_command
- add_command(PC27::CG::END_TURN, :end_turn)
- end
- #--------------------------------------------------------------------------
- # Add "Grave" command (new)
- #--------------------------------------------------------------------------
- def add_look_at_grave_command
- add_command(PC27::CG::GRAVE, :look_grave)
- end
- #--------------------------------------------------------------------------
- # Make new command List (overwrite)
- #--------------------------------------------------------------------------
- def make_command_list
- return unless @actor
- add_attack_command if PC27::CG::USE_ATTACK
- add_guard_command if PC27::CG::USE_GUARD
- add_skill_commands
- add_item_command if PC27::CG::USE_ITEMS
- add_look_at_grave_command
- add_turn_end_command
- end
- end
- #===============================================================================
- # Window_BattleStatus
- #===============================================================================
- class Window_BattleStatus < Window_Selectable
- #--------------------------------------------------------------------------
- # Add deck to Draw Item (alias)
- #--------------------------------------------------------------------------
- alias pc27_cardgame_wndbttlstat_draw_item draw_item
- def draw_item(index)
- pc27_cardgame_wndbttlstat_draw_item(index)
- actor = $game_party.battle_members[index]
- draw_deck_area(deck_area_rect(index), actor)
- end
- #--------------------------------------------------------------------------
- # Shrink basic rect (overwrite)
- #--------------------------------------------------------------------------
- def basic_area_rect(index)
- rect = item_rect_for_text(index)
- rect.width -= gauge_area_width + deck_area_width + 10
- rect
- end
- #--------------------------------------------------------------------------
- # Get Deck rect (new)
- #--------------------------------------------------------------------------
- def deck_area_rect(index)
- rect = item_rect_for_text(index)
- rect.x += rect.width - gauge_area_width - deck_area_width
- rect.width = deck_area_width
- rect
- end
- #--------------------------------------------------------------------------
- # Get Deck Area Width (new)
- #--------------------------------------------------------------------------
- def deck_area_width
- return 48
- end
- #--------------------------------------------------------------------------
- # Draw Deck Area (new)
- #--------------------------------------------------------------------------
- def draw_deck_area(rect, actor)
- draw_text(rect.x + 24, rect.y, 24, rect.height, actor.deck.size.to_s)
- draw_icon(PC27::CG::DECK_ICON, rect.x, rect.y)
- end
- end
- #===============================================================================
- # Window_BattleSkill
- #===============================================================================
- class Window_BattleSkill < Window_SkillList
- #-----------------------------------------------------------------------------
- # changes the BattleSkillList Window layout (overwrite)
- #-----------------------------------------------------------------------------
- def initialize(help_window, info_viewport)
- y = 0
- super(0, 0, (Graphics.width - 210) * 0.7, info_viewport.rect.y)
- self.visible = false
- @help_window = help_window
- @info_viewport = info_viewport
- end
- #-----------------------------------------------------------------------------
- # changes the max. amount of collums to 1 (overwrite)
- #-----------------------------------------------------------------------------
- def col_max
- return 1
- end
- #--------------------------------------------------------------------------
- # * Display Skill in Active State?
- #--------------------------------------------------------------------------
- def enable?(item)
- super && @actor.turn_actions[:actions] != 0
- end
- end
- #===============================================================================
- # Window CardHelp (new)
- #===============================================================================
- class Window_CardHelp < Window_Base
- include PC27::CG
- #-----------------------------------------------------------------------------
- # Enables the Window to draw cards
- #-----------------------------------------------------------------------------
- def draw_card_pic(item)
- if item
- begin
- draw_card_illustration(item)
- rescue
- draw_card_text(item)
- end
- else
- begin
- draw_card_illustration_no_card
- rescue
- draw_card_text_no_card
- end
- end
- end
- def draw_horz_line(y)
- line_color = normal_color
- line_color.alpha = 48
- line_y = y + line_height / 2 - 1
- contents.fill_rect(0, line_y, self.width, 2, line_color)
- end
- def make_cost_text(mp_cost, tp_cost)
- if mp_cost == 0
- if tp_cost == 0
- cost = "-"
- cost_size = 1
- else
- cost = "\\c[" + TP_COLOR.to_s + "]" + tp_cost.to_s
- cost_size = tp_cost.to_s.size
- end
- else
- if tp_cost == 0
- cost = "\\c[" + MP_COLOR.to_s + "]" + mp_cost.to_s
- cost_size = mp_cost.to_s.size
- else
- cost = "\\c[" + MP_COLOR.to_s + "]" + mp_cost.to_s + "\\c[0]/" + "\\c[" + TP_COLOR.to_s + "]" + tp_cost.to_s
- cost_size = 1 + mp_cost.to_s.size + tp_cost.to_s.size
- end
- end
- draw_text_ex(158-cost_size* 10, 48, cost)
- end
- def set_background(element)
- tone.set(*ELEMENT_COLOR[element])
- self.back_opacity = CARD_BACK_OP
- end
- def draw_all_lines
- draw_horz_line(36)
- draw_horz_line(60)
- draw_horz_line(204)
- end
- def draw_card_text_no_card
- create_contents
- tone.set(*ELEMENT_COLOR[0])
- self.back_opacity = CARD_BACK_OP
- end
- def draw_card_text(item)
- create_contents
- self.padding = standard_padding
- id = item.card_id.to_s
- draw_text_ex(148 - id.size * 10, height - 48, "#" + id)
- make_cost_text(item.mp_cost, item.tp_cost)
- set_background(item.damage ? item.damage.element_id : 0)
- name = (CARD_NAME_UP ? item.name.upcase : item.name)
- icon = "\\I[" + RARITY[item.rarity][0].to_s + "]"
- type = TYPE[item.type]
- name_x = 0.5 * width - padding - item.name.size * 5
- draw_all_lines
- draw_text_ex(name_x, 9, name)
- draw_text_ex(0,48, type)
- draw_text_ex(0,83, item.description)
- draw_text_ex(0, height - 48, icon)
- end
- def draw_card_illustration_no_card
- contents.dispose
- self.contents = Bitmap.new(190, 264)
- bitmap = Cache.picture("Card0")
- self.padding = 0
- rect = Rect.new(0, 0, 190, 264)
- contents.blt(0, 0, bitmap, rect, 255)
- bitmap.dispose
- end
- def draw_card_illustration(item)
- contents.dispose
- self.contents = Bitmap.new(190, 264)
- bitmap = Cache.picture("Card" + item.id.to_s)
- self.padding = 0
- rect = Rect.new(0, 0, 190, 264)
- contents.blt(0, 0, bitmap, rect, 255)
- bitmap.dispose
- end
- #--------------------------------------------------------------------------
- # Object Initialization
- #--------------------------------------------------------------------------
- def initialize()
- super(Graphics.width - 200, 10, 190, 264)
- self.windowskin = Cache.system(PC27::CG::CUSTOM_CARD_BG) if PC27::CG::CUSTOM_CARD_BG
- end
- #--------------------------------------------------------------------------
- # Set Text
- #--------------------------------------------------------------------------
- def set_text(card)
- if card != @card
- @card = card
- refresh
- end
- end
- #--------------------------------------------------------------------------
- # Set Item
- #--------------------------------------------------------------------------
- def set_item(item)
- set_text(item)
- end
- #--------------------------------------------------------------------------
- # Refresh
- #--------------------------------------------------------------------------
- def refresh
- contents.clear
- draw_card_pic(@card)
- end
- def update_tone; end
- def update_padding; end
- end
- #===============================================================================
- # Window_CardSelect (new)
- #===============================================================================
- class Window_CardSelect < Window_SkillList
- attr_accessor :actor
- attr_accessor :cards
- attr_accessor :sort_index
- attr_accessor :filter
- def initialize(help_window, info_viewport)
- super(0, 0, (Graphics.width - 210) * 0.7, info_viewport.rect.y)
- self.visible = false
- @help_window = help_window
- @info_viewport = info_viewport
- @filter = [0,0,0]
- @cards = []
- @sort_index = -1
- end
- def col_max
- return 1
- end
- def make_item_list
- @data = @cards
- end
- def enable?(item)
- return false unless item
- return false unless item.damage.element_id == @filter[0] || @filter[0] == 0
- return false unless item.type == @filter[1] || @filter[1] == 0
- return false unless item.rarity == @filter[2] || @filter[2] == 0
- return @actor
- end
- #--------------------------------------------------------------------------
- # Show Window
- #--------------------------------------------------------------------------
- def show
- select(0)
- @help_window.show
- super
- end
- #--------------------------------------------------------------------------
- # Hide Window
- #--------------------------------------------------------------------------
- def hide
- @help_window.hide
- super
- end
- end
- #===============================================================================
- # Scene_Battle
- #===============================================================================
- class Scene_Battle < Scene_Base
- #--------------------------------------------------------------------------
- # Add end turn command and remove prior command (overwrite)
- #--------------------------------------------------------------------------
- def create_actor_command_window
- @actor_command_window = Window_ActorCommand.new
- @actor_command_window.viewport = @info_viewport
- @actor_command_window.set_handler(:attack, method(:command_attack))
- @actor_command_window.set_handler(:skill, method(:command_skill))
- @actor_command_window.set_handler(:guard, method(:command_guard))
- @actor_command_window.set_handler(:item, method(:command_item))
- @actor_command_window.set_handler(:look_grave, method(:command_look_grave))
- @actor_command_window.set_handler(:end_turn, method(:command_end_turn))
- @actor_command_window.x = Graphics.width
- end
- #--------------------------------------------------------------------------
- # Handles the Look Grave command
- #--------------------------------------------------------------------------
- def command_look_grave
- array = PC27::CG::CARD_EFFECT["grave"]
- @temp_effect_data = [] unless @temp_effect_data
- @temp_effect_data[0] = :impact
- prepare_select_window(:impact, array[0])
- process_select_cards("grave")
- end
- #--------------------------------------------------------------------------
- # Clears actions and ends the actors turn
- #--------------------------------------------------------------------------
- def command_end_turn
- BattleManager.actor.clear_actions
- next_command
- end
- #--------------------------------------------------------------------------
- # Prevents messages from closing windows (overwrite)
- #--------------------------------------------------------------------------
- def update_message_open
- end
- #--------------------------------------------------------------------------
- # Shows a different Help Window in Battle (alias)
- #--------------------------------------------------------------------------
- alias pc27_cardgame_scenebattle_create_help_window create_help_window
- def create_help_window
- pc27_cardgame_scenebattle_create_help_window
- @cardhelp_window = Window_CardHelp.new
- @cardhelp_window.visible = false
- end
- #--------------------------------------------------------------------------
- # Create Skill Window with card help window instead of normal help window (overwrite)
- #--------------------------------------------------------------------------
- def create_skill_window
- @skill_window = Window_BattleSkill.new(@cardhelp_window, @info_viewport)
- @skill_window.set_handler(:ok, method(:on_skill_ok))
- @skill_window.set_handler(:cancel, method(:on_skill_cancel))
- end
- #--------------------------------------------------------------------------
- # Creates the window needed to select cards (new)
- #--------------------------------------------------------------------------
- def create_card_select_window
- @card_select_window = Window_CardSelect.new(@cardhelp_window, @info_viewport)
- end
- #--------------------------------------------------------------------------
- # Adds the select window to the scene (alias)
- #--------------------------------------------------------------------------
- alias pc27_cardgame_scenebattle_create_all_windows create_all_windows
- def create_all_windows
- pc27_cardgame_scenebattle_create_all_windows
- create_card_select_window
- end
- #--------------------------------------------------------------------------
- # On Skill Ok checks for card costs
- #--------------------------------------------------------------------------
- alias pc27_cardgame_scene_battle_on_skill_ok on_skill_ok
- def on_skill_ok
- @skill = @skill_window.item
- BattleManager.actor.card_to_stack?(@skill.id)
- if @skill.cost
- invoke_card_cost(@skill.cost)
- @skill_window.hide
- else
- BattleManager.actor.input.set_skill(@skill.id)
- BattleManager.actor.last_skill.object = @skill
- if !@skill.need_selection?
- @skill_window.hide
- next_command
- elsif @skill.for_opponent?
- select_enemy_selection
- else
- select_actor_selection
- end
- end
- end
- def on_enemy_cancel
- restore_taken_cards(:cancel)
- BattleManager.actor.hand += BattleManager.actor.stack
- BattleManager.actor.stack = []
- @enemy_window.hide
- @skill_window.hide
- @item_window.hide
- @actor_command_window.activate
- end
- def on_actor_cancel
- restore_taken_cards(:cancel)
- BattleManager.actor.hand += BattleManager.actor.stack
- BattleManager.actor.stack = []
- @actor_window.hide
- @skill_window.hide
- @item_window.hide
- @actor_command_window.activate
- end
- #-----------------------------------------------------------------------------
- # Changes Next Command so it performs Actions (alias)
- #-----------------------------------------------------------------------------
- alias pc27_cardgame_scenebattle_next_command next_command
- def next_command
- return if @card_select_window.active
- if action?
- evaluate_item(BattleManager.actor, BattleManager.actor.input.item)
- perform_action
- else
- pc27_cardgame_scenebattle_next_command
- end
- end
- #-----------------------------------------------------------------------------
- # Disables stuff based on used skill (new)
- #-----------------------------------------------------------------------------
- def evaluate_item(actor, item)
- case item.id
- when actor.attack_skill_id
- actor.turn_actions[:can_attack] = false
- actor.turn_actions[:can_guard] = false
- actor.turn_actions[:actions] = 0
- when actor.guard_skill_id
- actor.turn_actions[:can_attack] = false
- actor.turn_actions[:can_guard] = false
- actor.turn_actions[:actions] = 0
- else
- actor.turn_actions[:can_attack] = false
- actor.turn_actions[:can_guard] = false
- actor.turn_actions[:actions] -= 1 unless actor.turn_actions[:actions] == -1
- end
- end
- #--------------------------------------------------------------------------
- # Checks if there is an Action to use (new)
- #--------------------------------------------------------------------------
- def action?
- return false if BattleManager.actor.nil?
- return false if BattleManager.actor.input.nil?
- action = BattleManager.actor.input.item
- return false if action.nil?
- return true
- end
- #--------------------------------------------------------------------------
- # Performs Action (new)
- #--------------------------------------------------------------------------
- def perform_action
- @subject = BattleManager.actor
- hide_instant_action_windows
- if @subject.current_action.valid?
- execute_action
- end
- process_event
- loop do
- @subject.remove_current_action
- break if $game_troop.all_dead?
- break unless @subject.current_action
- @subject.current_action.prepare
- execute_action if @subject.current_action.valid?
- end
- process_action_end
- @subject.make_actions
- @subject = nil
- show_instant_action_windows
- end
- #--------------------------------------------------------------------------
- # From Yanflys Instantcast (new)
- #--------------------------------------------------------------------------
- def hide_instant_action_windows
- if $imported["YEA-BattleEngine"]
- @info_viewport.visible = true
- @status_aid_window.hide
- @status_window.show
- @actor_command_window.show
- end
- end
- #--------------------------------------------------------------------------
- # Activates actor (new)
- #--------------------------------------------------------------------------
- def show_instant_action_windows
- if $imported["YEA-BattleEngine"]
- @info_viewport.visible = true
- end
- start_actor_command_selection unless @card_select_window.active
- status_redraw_target(BattleManager.actor)
- next_command unless BattleManager.actor.inputable?
- end
- #--------------------------------------------------------------------------
- # Redrawas target after action (new)
- #--------------------------------------------------------------------------
- def status_redraw_target(target)
- return unless target.actor?
- @status_window.draw_item($game_party.battle_members.index(target))
- end
- #--------------------------------------------------------------------------
- # Handles card costs
- #--------------------------------------------------------------------------
- def invoke_card_cost(effect_name)
- effect_array = PC27::CG::CARD_EFFECT[effect_name]
- if effect_array[0] == :draw
- card_effect_draw_cards(effect_array[1], effect_array[2], effect_array[3])
- BattleManager.actor.input.set_skill(@skill.id)
- BattleManager.actor.last_skill.object = @skill
- if !@skill.need_selection?
- @skill_window.hide
- next_command
- elsif @skill.for_opponent?
- select_enemy_selection
- else
- select_actor_selection
- end
- else
- $game_message.background = 1
- $game_message.position = 1
- $game_message.add(PC27::CG::CARD_EFF_TEXT)
- wait_for_message
- prepare_select_window(:cost, effect_array[0])
- @temp_effect_data = [] unless @temp_effect_data
- @temp_effect_data[0] = :cost
- process_select_cards(effect_name)
- end
- end
- #-----------------------------------------------------------------------------
- # Evaluates card effects and puts the stack to the grave (alias)
- #-----------------------------------------------------------------------------
- alias pc27_cardgame_scenebattle_use_item use_item
- def use_item
- pc27_cardgame_scenebattle_use_item
- if @subject.is_a?(Game_Actor)
- effect_name = @subject.current_action.item.impact
- invoke_card_impact(effect_name) if effect_name
- @subject.grave += @subject.stack
- @subject.stack = []
- restore_taken_cards(:proceed)
- end
- end
- #-----------------------------------------------------------------------------
- # Card effects
- #-----------------------------------------------------------------------------
- def invoke_card_impact(effect_name)
- array = PC27::CG::CARD_EFFECT[effect_name]
- if array[0] == :draw
- card_effect_draw_cards(array[1], array[2], array[3])
- else
- $game_message.background = 1
- $game_message.position = 1
- $game_message.add(PC27::CG::CARD_EFF_TEXT)
- wait_for_message
- prepare_select_window(:impact, array[0])
- @temp_effect_data = [] unless @temp_effect_data
- @temp_effect_data[0] = :impact
- process_select_cards(effect_name)
- end
- end
- #-----------------------------------------------------------------------------
- def card_effect_draw_cards(nr, prob, trg)
- if trg == :self
- if rand(100) < prob
- @subject.draw_cards(nr)
- need_wait = true
- end
- elsif trg == :target
- targets = @subject.current_action.make_targets.compact
- for target in targets
- if rand(100) < prob
- target.draw_cards(nr)
- need_wait = true
- end
- end
- end
- wait_for_message if need_wait
- end
- #-----------------------------------------------------------------------------
- def process_select_cards(effect_name)
- @card_select_window.actor = BattleManager.actor
- array = PC27::CG::CARD_EFFECT[effect_name]
- case array[2]
- when :deck
- (array[1] == 0 ? amn = @card_select_window.actor.deck.size : amn = array[1])
- amn.times do
- next if @card_select_window.actor.deck.size == 0
- @card_select_window.cards.push(@card_select_window.actor.deck.shift)
- end
- when :hand
- (array[1] == 0 ? amn = @card_select_window.actor.hand.size : amn = array[1])
- amn.times do
- next if @card_select_window.actor.hand.size == 0
- @card_select_window.cards.push(@card_select_window.actor.hand.shift)
- end
- when :grave
- (array[1] == 0 ? amn = @card_select_window.actor.grave.size : amn = array[1])
- amn.times do
- next if @card_select_window.actor.grave.size == 0
- @card_select_window.cards.push(@card_select_window.actor.grave.shift)
- end
- end
- @temp_effect_data[1] = effect_name
- @temp_effect_data[2] = 0
- set_select_filter(array)
- @card_select_window.refresh
- @card_select_window.show.activate
- end
- #-----------------------------------------------------------------------------
- def set_select_filter(array)
- if array[4]
- @card_select_window.filter = array[4]
- elsif array[0] == :view
- @card_select_window.filter = [-1,-1,-1]
- else
- @card_select_window.filter = [0,0,0]
- end
- end
- #-----------------------------------------------------------------------------
- def select_cards_ok_sort
- if @card_select_window.cards.size == 0
- select_cancel
- return
- end
- if @card_select_window.sort_index != -1
- swap_cards(@card_select_window.sort_index, @card_select_window.index)
- @card_select_window.sort_index = -1
- @card_select_window.refresh
- else
- @card_select_window.sort_index = @card_select_window.index
- end
- @card_select_window.activate
- end
- #-----------------------------------------------------------------------------
- def select_cards_ok_take
- if @card_select_window.cards.size == 0
- select_cancel
- return
- end
- card = @card_select_window.item
- @temp_effect_data[3] = [] unless @temp_effect_data[3]
- @temp_effect_data[3].push(card)
- @card_select_window.cards.delete_at(@card_select_window.cards.index(card))
- @temp_effect_data[2] += 1
- if PC27::CG::CARD_EFFECT[@temp_effect_data[1]][6] != @temp_effect_data[2]
- @card_select_window.refresh
- @card_select_window.activate
- else
- proceed_selection
- end
- end
- #-----------------------------------------------------------------------------
- def proceed_selection
- @card_select_window.hide.deactivate
- @card_select_window.sort_index = -1
- restore_selected_cards
- if @temp_effect_data[0] == :cost
- BattleManager.actor.input.set_skill(@skill.id)
- BattleManager.actor.last_skill.object = @skill
- if !@skill.need_selection?
- @skill_window.hide
- next_command
- elsif @skill.for_opponent?
- select_enemy_selection
- else
- select_actor_selection
- end
- elsif @temp_effect_data[0] == :impact
- restore_taken_cards(:proceed)
- start_actor_command_selection
- end
- end
- def select_cancel
- @card_select_window.hide.deactivate
- @card_select_window.sort_index = -1
- restore_taken_cards(:cancel)
- restore_selected_cards
- if @temp_effect_data[0] == :cost
- BattleManager.actor.hand += BattleManager.actor.stack
- BattleManager.actor.stack = []
- on_skill_cancel
- elsif @temp_effect_data[0] == :impact
- start_actor_command_selection
- end
- end
- def restore_taken_cards(target)
- return unless @temp_effect_data && @temp_effect_data[3] && @temp_effect_data[3] != []
- if target == :proceed
- case PC27::CG::CARD_EFFECT[@temp_effect_data[1]][5]
- when :hand
- @card_select_window.actor.hand += @temp_effect_data[3]
- when :deck
- @card_select_window.actor.deck += @temp_effect_data[3]
- @card_select_window.actor.shuffle_deck(false)
- when :grave
- @card_select_window.actor.grave += @temp_effect_data[3]
- end
- elsif target == :cancel
- case PC27::CG::CARD_EFFECT[@temp_effect_data[1]][2]
- when :hand
- @card_select_window.actor.hand += @temp_effect_data[3]
- when :deck
- @card_select_window.actor.deck += @temp_effect_data[3]
- when :grave
- @card_select_window.actor.grave += @temp_effect_data[3]
- end
- end
- @temp_effect_data[3] = []
- end
- #-----------------------------------------------------------------------------
- def restore_selected_cards
- array = PC27::CG::CARD_EFFECT[@temp_effect_data[1]]
- case array[3]
- when :deck
- @card_select_window.cards.reverse.each { |card|
- @card_select_window.actor.deck.unshift(card)
- }
- @card_select_window.actor.shuffle_deck if array[0] == :take && @card_select_window.actor.deck.size != 0
- @status_window.refresh
- when :hand
- @card_select_window.cards.reverse.each { |card|
- @card_select_window.actor.hand.unshift(card)
- }
- when :grave
- @card_select_window.cards.reverse.each { |card|
- @card_select_window.actor.grave.unshift(card)
- }
- end
- @card_select_window.cards = []
- end
- #-----------------------------------------------------------------------------
- def prepare_select_window(moment, type)
- if moment == :impact
- if type == :view
- @card_select_window.set_handler(:ok, method(:no_method))
- @card_select_window.set_handler(:cancel, method(:select_cancel))
- elsif type == :sort
- @card_select_window.set_handler(:ok, method(:select_cards_ok_sort))
- @card_select_window.set_handler(:cancel, method(:select_cancel))
- elsif type == :take
- @card_select_window.set_handler(:ok, method(:select_cards_ok_take))
- @card_select_window.set_handler(:cancel, method(:select_cancel))
- end
- elsif moment == :cost
- if type == :view
- @card_select_window.set_handler(:ok, method(:no_method))
- @card_select_window.set_handler(:cancel, method(:proceed_selection))
- elsif type == :sort
- @card_select_window.set_handler(:ok, method(:select_cards_ok_sort))
- @card_select_window.set_handler(:cancel, method(:proceed_selection))
- elsif type == :take
- @card_select_window.set_handler(:ok, method(:select_cards_ok_take))
- @card_select_window.set_handler(:cancel, method(:select_cancel))
- end
- end
- end
- def no_method
- @card_select_window.activate
- end
- #-----------------------------------------------------------------------------
- def swap_cards(index1, index2)
- @card_select_window.cards[index1], @card_select_window.cards[index2] =
- @card_select_window.cards[index2], @card_select_window.cards[index1]
- end
- end
- #===============================================================================
- # Scene_Deck
- #===============================================================================
- class Scene_Deck < Scene_MenuBase
- include PC27::CG
- #-----------------------------------------------------------------------------
- # Start
- #-----------------------------------------------------------------------------
- def start
- super()
- create_filter_window
- create_deck_window
- create_coll_window
- create_text_window
- create_card_window
- create_info_window
- end
- #-----------------------------------------------------------------------------
- # Creates a window to display deck cards
- #-----------------------------------------------------------------------------
- def create_deck_window
- @deck_window = Window_Deck.new(0,64)
- @deck_window.set_handler(:cancel, method(:return_scene))
- @deck_window.set_handler(:ok, method(:deck_to_coll))
- end
- #-----------------------------------------------------------------------------
- # Creates a window to display collection cards
- #-----------------------------------------------------------------------------
- def create_coll_window
- @coll_window = Window_Coll.new((Graphics.width - 210)*0.5, 64)
- @coll_window.set_handler(:cancel, method(:return_scene))
- @coll_window.set_handler(:ok, method(:coll_to_deck))
- @coll_window.deactivate
- end
- #-----------------------------------------------------------------------------
- # Creates the window that shows where you are
- #-----------------------------------------------------------------------------
- def create_text_window
- @text_window = Window_Base.new(0 ,0, Graphics.width - 210, 64)
- update_text_window
- end
- #-----------------------------------------------------------------------------
- # Creates the window that shows the currently selected card
- #-----------------------------------------------------------------------------
- def create_card_window
- @card_window = Window_CardHelp.new()
- @card_window.windowskin = Cache.system(CUSTOM_CARD_BG) if CUSTOM_CARD_BG
- @card_window.tone.set(*PC27::CG::ELEMENT_COLOR[0])
- @card_window.back_opacity = PC27::CG::CARD_BACK_OP
- end
- #-----------------------------------------------------------------------------
- # Creates a info window
- #-----------------------------------------------------------------------------
- def create_info_window
- height = Graphics.height - 284
- @info_window = Window_Base.new(
- Graphics.width - 210, Graphics.height - height, 210, height)
- @info_window.draw_text_ex(0,0,CARD_HELP_WINDOW)
- end
- #-----------------------------------------------------------------------------
- # Creates a window to filter cards
- #-----------------------------------------------------------------------------
- def create_filter_window
- @filter_window = Window_Filter.new(0,Graphics.height * 0.5 - 48)
- @filter_window.set_handler(:cancel, method(:close_filter))
- @filter_window.set_handler(:ok, method(:change_filter))
- @filter_window.z = 150
- @filter_window.hide
- @filter_window.deactivate
- end
- #-----------------------------------------------------------------------------
- # Changes between collection and deck window
- #-----------------------------------------------------------------------------
- def change_to_coll
- @coll_window.activate
- @deck_window.deactivate
- Sound.play_cursor
- Input.update
- end
- def change_to_deck
- @deck_window.activate
- @coll_window.deactivate
- Sound.play_cursor
- Input.update
- end
- #-----------------------------------------------------------------------------
- # Adds commands to exchange cards
- #-----------------------------------------------------------------------------
- def coll_to_deck
- if $game_party.menu_actor.deck.size >= MAX_DECK_SIZE
- RPG::SE.new("Buzzer1", 80, 100).play
- return
- end
- /coll(?<skill_id>\d+)/ =~ @coll_window.current_symbol.to_s
- skill_id = skill_id.to_i
- max_cards = (MAX_SAME_EXCEP.has_key?(skill_id) ? MAX_SAME_EXCEP[skill_id] : MAX_SAME_CARDS)
- if $game_party.menu_actor.deck.count{ |skill| skill.id == skill_id } >= max_cards
- RPG::SE.new("Buzzer1", 80, 100).play
- return
- end
- for skill in $game_party.coll
- if skill.id == skill_id
- $game_party.menu_actor.deck.push(
- $game_party.coll.slice!($game_party.coll.index(skill)))
- break
- end
- end
- RPG::SE.new("Cursor1", 80, 100).play
- @deck_window.refresh
- @coll_window.refresh
- update_text_window
- end
- def deck_to_coll
- /deck(?<skill_id>\d+)/ =~ @deck_window.current_symbol.to_s
- skill_id = skill_id.to_i
- for skill in $game_party.menu_actor.deck
- if skill.id == skill_id
- $game_party.coll.push(
- $game_party.menu_actor.deck.slice!($game_party.menu_actor.deck.index(skill)))
- break
- end
- end
- RPG::SE.new("Cursor1", 80, 100).play
- @deck_window.refresh
- @coll_window.refresh
- update_text_window
- end
- #-----------------------------------------------------------------------------
- # Activates filter
- #-----------------------------------------------------------------------------
- def activate_filter
- @filter_window.show
- @filter_window.activate
- @deck_window.deactivate
- @coll_window.deactivate
- end
- #-----------------------------------------------------------------------------
- # Changes filter settings
- #-----------------------------------------------------------------------------
- def change_filter
- case @filter_window.current_symbol
- when :filter_element
- @coll_window.filter[0] += 1
- @filter_window.filter[0] += 1
- @coll_window.filter[0] = 0 if $data_system.elements.size == @coll_window.filter[0]
- @filter_window.filter[0] = 0 if $data_system.elements.size == @filter_window.filter[0]
- when :filter_type
- @coll_window.filter[1] += 1
- @filter_window.filter[1] += 1
- @coll_window.filter[1] = 0 unless TYPE.has_key?(@coll_window.filter[1])
- @filter_window.filter[1] = 0 unless TYPE.has_key?(@filter_window.filter[1])
- when :filter_rarity
- @coll_window.filter[2] += 1
- @filter_window.filter[2] += 1
- @coll_window.filter[2] = 0 unless RARITY.has_key?(@coll_window.filter[2])
- @filter_window.filter[2] = 0 unless RARITY.has_key?(@filter_window.filter[2])
- when :confirm
- $game_party.coll += $game_party.menu_actor.deck
- $game_party.menu_actor.deck = []
- @filter_window.confirm = false
- @filter_window.refresh
- when :call_confirm
- @filter_window.confirm = true
- @filter_window.refresh
- end
- @filter_window.refresh
- @coll_window.refresh
- @deck_window.refresh
- update_text_window
- end
- #-----------------------------------------------------------------------------
- # Deativates filter
- #-----------------------------------------------------------------------------
- def close_filter
- @filter_window.hide
- @filter_window.deactivate
- @coll_window.activate
- @coll_window.select(0)
- end
- #-----------------------------------------------------------------------------
- # * Frame Update
- #-----------------------------------------------------------------------------
- def update
- super()
- #---------------------------------------------------------------------------
- # Handles input
- #---------------------------------------------------------------------------
- if @filter_window.visible == false
- change_to_coll if Input.trigger?(:RIGHT)
- change_to_deck if Input.trigger?(:LEFT)
- activate_filter if Input.trigger?(:X)
- next_actor if Input.trigger?(:R)
- prev_actor if Input.trigger?(:L)
- end
- #---------------------------------------------------------------------------
- # Redraws card, if neccessary
- #---------------------------------------------------------------------------
- if @coll_window.active
- symbol = @coll_window.current_symbol
- elsif @deck_window.active
- symbol = @deck_window.current_symbol
- end
- if symbol != @symbol
- @symbol = symbol
- /[kl](?<id>\d+)/ =~ @symbol.to_s
- skill = ( id ? $data_skills[id.to_i] : nil)
- @card_window.set_item(skill)
- end
- end
- def on_actor_change
- RPG::SE.new("Cursor2", 80, 100).play
- @deck_window.refresh
- @deck_window.select(0)
- @coll_window.select(0)
- update_text_window
- end
- def update_text_window
- @text_window.contents.clear
- text_name = $game_party.menu_actor.name + "s " + DECK
- @text_window.draw_text_ex(0, 8, text_name)
- text_deck = $game_party.menu_actor.deck.size.to_s + "/" + MAX_DECK_SIZE.to_s
- xpos = @text_window.width - 10*(text_deck.size+1) - @text_window.padding
- @text_window.draw_text_ex(xpos, 8, text_deck)
- end
- end
- class Window_Deck < Window_Command
- #--------------------------------------------------------------------------
- # Makes Command List
- #--------------------------------------------------------------------------
- def make_command_list
- add_deck_commands
- end
- #--------------------------------------------------------------------------
- # Add Card Commands to List
- #--------------------------------------------------------------------------
- def add_deck_commands
- $game_party.menu_actor.sort_cards(:deck)
- deck = $game_party.menu_actor.deck
- if deck.empty?
- add_command("---", :nothing)
- return
- end
- hash = {}
- for skill in deck
- if hash.has_key?(skill.id)
- hash[skill.id] += 1
- else
- hash[skill.id] = 1
- end
- end
- hash.each_key do |id|
- add_command(hash[id].to_s + "x " + $data_skills[id].name, ("deck" + id.to_s).to_sym)
- end
- end
- #--------------------------------------------------------------------------
- # Get Window Height
- #--------------------------------------------------------------------------
- def window_height
- Graphics.height - 64
- end
- #--------------------------------------------------------------------------
- # Get Window width
- #--------------------------------------------------------------------------
- def window_width
- (Graphics.width - 210) * 0.5
- end
- #--------------------------------------------------------------------------
- # Overwrite process_ok so the window won't be disabled
- #--------------------------------------------------------------------------
- def process_ok
- if current_item_enabled?
- Input.update
- call_ok_handler
- select(index - 1) unless current_symbol
- else
- Sound.play_buzzer
- end
- end
- end
- class Window_Coll < Window_Command
- attr_accessor :filter
- def initialize(width, heigth)
- @filter = [0,0,0]
- super(width, heigth)
- end
- #--------------------------------------------------------------------------
- # Makes Command List
- #--------------------------------------------------------------------------
- def make_command_list
- add_coll_commands
- end
- #--------------------------------------------------------------------------
- # Add Collection Commands to List
- #--------------------------------------------------------------------------
- def add_coll_commands
- $game_party.coll.sort!{|a,b| a.id <=> b.id}
- coll = $game_party.coll
- if coll.empty?
- add_command("---", :nothing)
- return
- end
- hash = {}
- for skill in coll
- next unless match_filter?(skill)
- if hash.has_key?(skill.id)
- hash[skill.id] += 1
- else
- hash[skill.id] = 1
- end
- end
- hash.each_key do |id|
- add_command(hash[id].to_s + "x " + $data_skills[id].name, ("coll" + id.to_s).to_sym)
- end
- end
- #--------------------------------------------------------------------------
- # Checks if a card meets the specified filter criteria
- #--------------------------------------------------------------------------
- def match_filter?(skill)
- return false unless skill.damage.element_id == @filter[0] || @filter[0] == 0
- return false unless skill.type == @filter[1] || @filter[1] == 0
- return false unless skill.rarity == @filter[2] || @filter[2] == 0
- return true
- end
- #--------------------------------------------------------------------------
- # Get Window Height
- #--------------------------------------------------------------------------
- def window_height
- Graphics.height - 64
- end
- #--------------------------------------------------------------------------
- # Get Window width
- #--------------------------------------------------------------------------
- def window_width
- (Graphics.width - 210) * 0.5
- end
- def process_ok
- if current_item_enabled?
- Input.update
- call_ok_handler
- select(index - 1) unless current_symbol
- else
- Sound.play_buzzer
- end
- end
- end
- class Window_Filter < Window_Command
- include PC27::CG
- attr_accessor :filter
- attr_accessor :confirm
- def initialize(width, heigth)
- @filter = [0,0,0]
- @confirm = false
- super(width, heigth)
- hide
- end
- #--------------------------------------------------------------------------
- # Makes Command List
- #--------------------------------------------------------------------------
- def make_command_list
- add_filter_commands
- end
- #--------------------------------------------------------------------------
- # Add Collection Commands to List
- #--------------------------------------------------------------------------
- def add_filter_commands
- add_command(FILTER_TEXT + F_ELEMENT + (@filter[0]==0 ? "---" : $data_system.elements[@filter[0]] ), :filter_element)
- add_command(FILTER_TEXT + F_TYPE + (@filter[1]==0 ? "---" : TYPE[@filter[1]]), :filter_type)
- add_command(FILTER_TEXT + F_RARITY + (@filter[2]==0 ? "---" : RARITY[@filter[2]][1]), :filter_rarity)
- add_empty_deck_command
- end
- #--------------------------------------------------------------------------
- # Get Window Height
- #--------------------------------------------------------------------------
- def window_height
- 96
- end
- #--------------------------------------------------------------------------
- # Get Window width
- #--------------------------------------------------------------------------
- def window_width
- Graphics.width
- end
- def process_ok
- if current_item_enabled?
- RPG::SE.new("Cursor1", 80, 100)
- Input.update
- call_ok_handler
- else
- Sound.play_buzzer
- end
- end
- def add_empty_deck_command
- if @confirm
- add_command(CONFIRM, :confirm)
- else
- add_command(EMPTY_DECK, :call_confirm)
- end
- end
- def hide
- @confirm = false
- super
- end
- end
- class Window_MenuCommand < Window_Command
- #--------------------------------------------------------------------------
- # Replaces skills with Deck (overwrite)
- #--------------------------------------------------------------------------
- def add_main_commands
- add_command(Vocab::item, :item, main_commands_enabled)
- add_command(PC27::CG::DECK, :deck, main_commands_enabled)
- add_command(Vocab::equip, :equip, main_commands_enabled)
- add_command(Vocab::status, :status, main_commands_enabled)
- end
- end
- class Scene_Menu < Scene_MenuBase
- #--------------------------------------------------------------------------
- # Adds a handler to access the deck scene (alias)
- #--------------------------------------------------------------------------
- alias pc27_cardgame_scenemenu_create_cmd_wdw create_command_window
- def create_command_window
- pc27_cardgame_scenemenu_create_cmd_wdw
- @command_window.set_handler(:deck, method(:command_personal))
- end
- #--------------------------------------------------------------------------
- # Adds :deck to the personal command process (alias)
- #--------------------------------------------------------------------------
- alias pc27_cardgame_scenemenu_on_personal_ok on_personal_ok
- def on_personal_ok
- pc27_cardgame_scenemenu_on_personal_ok
- case @command_window.current_symbol
- when :deck
- SceneManager.call(Scene_Deck)
- end
- end
- end
- ################################################################################
- # End of script #
- ################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement