Advertisement
Zouzaka

JCC - Cards Game

Jul 17th, 2014
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 28.22 KB | None | 0 0
  1. %Q(
  2.                         JCC -  Cards Game
  3.                         =================
  4. Auteur: Zouzaka
  5. Description: Permet de réaliser un jeu de carte a collection, le principe est
  6. simple, defier, ganger, collectioner.
  7. J'ai fait en sorte de rendre le script le plus personalisable possible autant
  8. pour les debutant que les experimentés, un scripteur peut facilement le modifier
  9. j'ai canaliser toutes les information dans un seul module "JCC"
  10. -----------------------------
  11. Indexs du terrain :
  12. 0,4,8,12,16 ... (Magie du joueur)
  13. 1,5,9,13,17 ... (Monstres du joueur)
  14. 2,6,10,14,18 ... (Monstres de l'ennemi)
  15. 3,7,11,15,19 ... (Magie de l'ennemi)
  16. )
  17. module JCC_Config
  18.   #=============================================================================
  19.   #*Personalisation
  20.   #=============================================================================
  21.   #.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.
  22.   #=============================================================================
  23.   #**Default Defi Type
  24.   # 1 => Defi Standard
  25.   # 2 => Limité (par le nombre de tours)
  26.   #-----------------------------------------------------------------------------
  27.   Default_Defi = 1
  28.   #-----------------------------------------------------------------------------
  29.   #**Condition de Victoire
  30.   # 1 => Nombre de PV = 0
  31.   # 2 => Aucun Monstre sur le terrain
  32.   #-----------------------------------------------------------------------------
  33.   Victory_Condition = 1
  34.   #-----------------------------------------------------------------------------
  35.   #**Condition de Victoire
  36.   # true => le premier qui ne peut plus piocher a perdu
  37.   # false => meme si le deck est vide la partie continu
  38.   #-----------------------------------------------------------------------------
  39.   Empty_Deck_Lose = true
  40.   #-----------------------------------------------------------------------------
  41.   #**Pouvoir regarder les cartes magies de l'ennemi
  42.   # true => Oui, ont peut regarder
  43.   # false => Non, ont ne regarde pas !
  44.   #-----------------------------------------------------------------------------
  45.   Show_ennemy_Spell = true
  46.   #-----------------------------------------------------------------------------
  47.   #**Vie de depart (condition de victoire => 1)
  48.   #-----------------------------------------------------------------------------
  49.   Life_Start = 4000
  50.   #-----------------------------------------------------------------------------
  51.   #**Nombre de cartes dans la main
  52.   #-----------------------------------------------------------------------------
  53.   Hand_Size = 5
  54.   #-----------------------------------------------------------------------------
  55.   #**Nombre de Monstre sur le terrain (Max 5)
  56.   #-----------------------------------------------------------------------------
  57.   MonsterField_Size = 3
  58.   #-----------------------------------------------------------------------------
  59.   #**Nombre de Magie sur le terrain (Max 5)
  60.   #-----------------------------------------------------------------------------
  61.   SpellField_Size = 3
  62.   #-----------------------------------------------------------------------------
  63.   #**Nombre de De Tours Pour abondonner
  64.   #-----------------------------------------------------------------------------
  65.   Exit_Condition = 0
  66.   #-----------------------------------------------------------------------------
  67.   #**Limite d'invocation par tour
  68.   #-----------------------------------------------------------------------------
  69.   Monster_Limit = 2
  70.   #-----------------------------------------------------------------------------
  71.   #**Limite de Carte magie par tour
  72.   #-----------------------------------------------------------------------------
  73.   Spell_Limit = 3
  74.   #-----------------------------------------------------------------------------
  75.   #**Chance d'erreur pour l'id
  76.   #cette valeur est un pourcentage qui reflete les chances que l'IA fasse  
  77.   #un fail (Max 100)
  78.   #-----------------------------------------------------------------------------
  79.   IA_Fail = 0
  80.   #-----------------------------------------------------------------------------
  81.   #**Nombre Max d'attaque par carte
  82.   #-----------------------------------------------------------------------------
  83.   Fight_Per_Card = 1
  84. end
  85. #===============================================================================
  86. #*Data Manager
  87. #===============================================================================
  88. #.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*
  89. #===============================================================================
  90. module DataManager
  91.   class << self
  92.     alias :jcc_load_normal_database :load_normal_database
  93.     def load_normal_database
  94.       jcc_load_normal_database
  95.       $data_jcc      = load_cards
  96.     end
  97.     def load_cards
  98.       contents = {:Cards => [], :Decks => []}
  99.       file = File.new("Data/Cards.rvdata2")
  100.       file.lines do |line|
  101.         contents[:Cards] << eval(line)
  102.       end
  103.       file = File.new("Data/Decks.rvdata2")
  104.       file.lines do |line|
  105.         array = []
  106.         eval(line)[:cards].split("|").each do |item|
  107.           array << eval(item)
  108.         end
  109.         contents[:Decks] << [eval(line)[:name],array]
  110.       end
  111.       contents
  112.     end
  113.   end
  114. end
  115. #===============================================================================
  116. #*Cache
  117. #===============================================================================
  118. #.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*
  119. #===============================================================================
  120. module Cache
  121.   #--------------------------------------------------------------------------
  122.   # * Get Card Graphic
  123.   #--------------------------------------------------------------------------
  124.   def self.card(filename)
  125.     load_bitmap("Graphics/Cards/", filename)
  126.   end
  127. end
  128. #===============================================================================
  129. #*Module JCC
  130. #===============================================================================
  131. #.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*
  132. #===============================================================================
  133. module JCC
  134.   include JCC_Config
  135.   @defi_type = Default_Defi
  136.   @local_deck = []
  137.   @is_monster = false
  138.   def self.start_defi(deck)
  139.     JCC.setup_defi(deck,JCC.defi_type)
  140.     SceneManager.call(Scene_Defi)
  141.   end
  142.   def self.set_deck(deck_name)
  143.     @local_deck = Array.new(JCC.get_deck_cards(deck_name))
  144.   end
  145.   def self.remove_card(card_id)
  146.     @local_deck.slice!(@local_deck.index(card_id))
  147.   end
  148.   def self.remove_hand_card(cible,index)
  149.     eval("@"+cible.to_s+"_hand").slice!(index)
  150.   end
  151.   def self.setup_defi(deck_name,type)
  152.     @ennemy_deck = Array.new(JCC.get_deck_cards(deck_name))
  153.     @defi_type = type
  154.     @life = {:player => Life_Start, :ennemy => Life_Start}
  155.   end
  156.   def self.get_deck_cards(deck_name)
  157.     $data_jcc[:Decks].each do |deck|
  158.       return deck[1] if deck[0]== deck_name
  159.     end
  160.   end
  161.   def self.add_life(sym,value) ; @life[sym] += value ; end
  162.   def self.get_zone ; @zone ; end
  163.   def self.set_zone(zone) ; @zone = zone ; end
  164.   def self.set_defi_type(type) ; @defi_type = type ; end
  165.   def self.set_player_hand(hand) ; @player_hand = hand ; end
  166.   def self.set_ennemy_hand(hand) ; @ennemy_hand = hand ; end
  167.   def self.remove_deck ; @local_deck = [] ; end
  168.   def self.add_card(card_id) ; @local_deck << card_id ; end
  169.   def self.get_deck ; @local_deck ; end
  170.   def self.defi_type ; @defi_type ; end
  171.   def self.player_hand ; @player_hand ; end
  172.   def self.ennemy_hand ; @ennemy_hand ; end
  173.   def self.ennemy_deck ; @ennemy_deck ; end
  174.   def self.defi_type ; @defi_type ; end
  175.   def self.get_life(cible) ; @life[cible] ; end
  176.   def self.is_monster ; @is_monster ; end
  177.   def self.set_is_monster(bool) ; @is_monster = bool ; end
  178.   def self.wait_for(sym) ; @wait_for = sym ; end
  179.   def self.get_wait_for ; @wait_for ; end
  180. end
  181.  
  182. #===============================================================================
  183. #*Class Card
  184. #===============================================================================
  185. class Game_Card
  186.   attr_reader :name
  187.   attr_reader :force
  188.   attr_reader :defense
  189.   attr_reader :type
  190.   attr_reader :cible
  191.   attr_reader :picture
  192.   attr_reader :card_id
  193.   attr_accessor :fight_count
  194.   def initialize(card_id)
  195.     @card_id = card_id
  196.     @name    = $data_jcc[:Cards][card_id][:name]
  197.     @force   = $data_jcc[:Cards][card_id][:force]
  198.     @defense = $data_jcc[:Cards][card_id][:defense]
  199.     @type    = $data_jcc[:Cards][card_id][:type]
  200.     @cible   = $data_jcc[:Cards][card_id][:cible]
  201.     @picture = $data_jcc[:Cards][card_id][:picture]
  202.     @fight_count = 0
  203.   end
  204.   def id ; @card_id ; end
  205.   def add_force(new_frc)
  206.     @force += new_frc
  207.   end
  208.   def add_defense(new_def)
  209.     @defense += new_def
  210.   end
  211. end
  212. #===============================================================================
  213. #.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*
  214. #===============================================================================
  215. #*Scene_Defi
  216. #===============================================================================
  217. class Scene_Defi < Scene_MenuBase
  218.   include JCC_Config
  219.   def start
  220.     @victory = nil
  221.     super
  222.     load_data
  223.     creat_windows
  224.     set_window_handlers
  225.     variables_declaration
  226.     @info_window.set_text("Que le Duel Commence !")
  227.   end
  228.   def variables_declaration
  229.     JCC.wait_for(:nil)
  230.     JCC.set_zone(:home)
  231.     @in_turn = :player
  232.     @turn = 0
  233.     @invok_in_turn = 0
  234.     @spell_in_turn = 0
  235.     #Fighting local variables
  236.     @actual_card = nil
  237.     @actual_index = 0
  238.     @cible_card = nil
  239.     @cible_index = 0
  240.   end
  241.   def load_data
  242.     #Load Decks
  243.     @player_deck = Array.new(JCC.get_deck)
  244.     @ennemy_deck = Array.new(JCC.ennemy_deck)
  245.     #Load hand cards
  246.     JCC.set_player_hand(load_cards(:player))
  247.     JCC.set_ennemy_hand(load_cards(:ennemy))
  248.   end
  249.   def load_cards(sym)
  250.     @hand = []
  251.     var = ("@"+sym.to_s+"_deck")
  252.     Hand_Size.times do
  253.       @index = rand(eval(var).size)
  254.       @hand << eval(var)[@index]
  255.       eval(var).slice!(@index)
  256.     end
  257.     return @hand
  258.   end
  259.   def creat_windows
  260.     @info_window = Window_JCC_Help.new(1)
  261.     @command_jcc = Window_Command_JCC.new(0,370)
  262.     @window_field = JCC_Field.new(0,@info_window.height,Graphics.width,324)
  263.     @cards_list = Window_Card_Select.new(0,@info_window.height)
  264.     @player_life = Window_Life.new(0,0, :player)
  265.     @ennemy_life = Window_Life.new(Graphics.width - 70,0, :ennemy)
  266.     @action_window = Action_Card.new(@info_window.height,@cards_list.width)
  267.   end
  268.   def set_window_handlers
  269.     @command_jcc.set_handler(:hand, method(:open_hand))
  270.     @command_jcc.set_handler(:next, method(:ennemy_turn))
  271.     @command_jcc.set_handler(:field, method(:open_field))
  272.     @command_jcc.set_handler(:exit, method(:abondonner))
  273.     @cards_list.set_handler(:card,      method(:card_choiced))
  274.     @action_window.set_handler(:return,      method(:close_action_window))
  275.   end
  276.   def open_hand
  277.     @cards_list.open
  278.     JCC.set_zone(:hand)
  279.   end
  280.   def open_field
  281.     @window_field.activate
  282.     JCC.set_zone(:field)
  283.   end
  284.   def ennemy_turn
  285.     @in_turn = :ennemy
  286.     @invok_in_turn = 0
  287.     @spell_in_turn = 0
  288.     ia_play
  289.   end
  290.   def next_turn
  291.     @in_turn = :player
  292.     phase_pioche
  293.     @turn += 1
  294.     @command_jcc.activate
  295.     @window_field.reset_fight_count
  296.     @invok_in_turn = 0
  297.     @spell_in_turn = 0
  298.   end
  299.   def phase_pioche
  300.     [:ennemy,:player].each do |cible|
  301.       deck = "@"+cible.to_s+"_deck"
  302.       hand = "@"+cible.to_s+"_hand"
  303.       unless eval(deck) == []
  304.         @hand = eval("JCC."+cible.to_s+"_hand")
  305.         @index = rand(eval(deck).size)
  306.         @hand << eval(deck)[@index]
  307.         eval(deck).slice!(@index)
  308.         eval("JCC.set_"+cible.to_s+"_hand(@hand)")
  309.       else
  310.         if Empty_Deck_Lose
  311.           cible == :ennemy ? @victory = true : @victory = true if @victory==nil
  312.         end
  313.       end
  314.     end
  315.     @cards_list.refresh
  316.   end
  317. =begin
  318. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  319. Cette Zone est pour la gestion de L'IA
  320. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  321. =end
  322. def ia_play
  323.   @info_window.set_text("Tour de l'adversaire")
  324.   Monster_Limit.times{|i| phase_invocation}
  325.   Graphics.wait(20)
  326.   Spell_Limit.times{|i| phase_spell}
  327.   Graphics.wait(20)
  328. #~   phase_activation
  329.   Graphics.wait(20)
  330. #~   phase_attaque
  331.   @info_window.set_text("Votre Tour")
  332.   next_turn
  333. end
  334. def phase_spell
  335.   @local = []
  336.   JCC.ennemy_hand.each do |card_id|
  337.     if $data_jcc[:Cards][card_id][:type] == "Spell" ; @local << card_id ; end
  338.   end
  339.   unless @local == []
  340.     @best_choice = @local[0]  
  341.     @local.each do |card_id|
  342.       @somme1 = $data_jcc[:Cards][card_id][:force].abs + $data_jcc[:Cards][card_id][:defense].abs
  343.       @somme2 = $data_jcc[:Cards][@best_choice][:force].abs + $data_jcc[:Cards][@best_choice][:defense].abs
  344.       @best_choice = card_id if @somme1 > @somme2
  345.     end
  346.     unless @spell_in_turn > Spell_Limit
  347.       SpellField_Size.times do |placement|
  348.         if @window_field.card_id(3 +4*placement) == nil
  349.           JCC.remove_hand_card(:ennemy,JCC.ennemy_hand.index(@best_choice))
  350.           @window_field.set_card(3 +4*placement,@best_choice)
  351.           @spell_in_turn += 1
  352.           break
  353.         end
  354.       end
  355.     end
  356.   end
  357. end
  358. def phase_invocation
  359.   @local = []
  360.   JCC.ennemy_hand.each do |card_id|
  361.     if $data_jcc[:Cards][card_id][:type] == "Monstre" ; @local << card_id ; end
  362.   end
  363.   unless @local == []
  364.     @best_choice = @local[0]  
  365.     @local.each do |card_id|
  366.       @somme1 = $data_jcc[:Cards][card_id][:force] + $data_jcc[:Cards][card_id][:defense]
  367.       @somme2 = $data_jcc[:Cards][@best_choice][:force] + $data_jcc[:Cards][@best_choice][:defense]
  368.       @best_choice = card_id if @somme1 > @somme2
  369.     end
  370.     unless @invok_in_turn > Monster_Limit
  371.       MonsterField_Size.times do |placement|
  372.         if @window_field.card_id(2 +4*placement) == nil
  373.           JCC.remove_hand_card(:ennemy,JCC.ennemy_hand.index(@best_choice))
  374.           @window_field.set_card(2 +4*placement,@best_choice)
  375.           @invok_in_turn += 1
  376.           break
  377.         end
  378.       end
  379.     end
  380.   end
  381. end
  382. =begin
  383. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  384. Cette Zone est pour la gestion de L'IA
  385. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  386. =end
  387.   def abondonner
  388.     if @turn >= Exit_Condition
  389.       @victory = false
  390.     else
  391.       @info_window.set_text("Il vous reste "+(Exit_Condition-@turn).to_s+" pour abondonner")
  392.       @command_jcc.activate
  393.     end
  394.   end
  395.   def choice_place
  396.     @action_window.close
  397.     @cards_list.close
  398.     @window_field.activate
  399.   end
  400.   def action_atk
  401.     unless @actual_card.fight_count >= Fight_Per_Card
  402.       @action_window.close
  403.       @window_field.activate
  404.       p(@actual_card)
  405.       @empty_placements = 0
  406.       MonsterField_Size.times do |placement|
  407.         if @window_field.card_id(2 +4*placement) != nil
  408.           @empty_placements += 1
  409.         end
  410.       end
  411.       if @empty_placements != 0
  412.         JCC.wait_for(:atk_cible)
  413.       else
  414.         direct_dmgs
  415.       end
  416.     else
  417.       @info_window.set_text("Cette Carte a deja combattu")
  418.       @action_window.close
  419.     end
  420.   end
  421.   def direct_dmgs
  422.     if @turn == 0 ; @info_window.set_text("Action non autorisée")
  423.     else
  424.       @info_window.set_text("Attaque DIRECT !!!")
  425.         if @in_turn == :player
  426.           add_life(:ennemy, -@actual_card.force)
  427.         else
  428.           add_life(:player, -@actual_card.force)
  429.         end
  430.     end
  431.     JCC.wait_for(:nil)
  432.     p("cc")
  433.   end
  434.   def action_activate
  435.     @action_window.close
  436.     @window_field.activate
  437.     @actual_card = @window_field.actual_card
  438.     @actual_index = @window_field.index
  439.     JCC.wait_for(:spell_cible)
  440.   end
  441.   def action_window_set_handler
  442.     if JCC.is_monster
  443.       if JCC.get_zone == :field
  444.         @action_window.set_handler(:atk,      method(:action_atk))
  445.         @actual_card = @window_field.actual_card
  446.         @actual_index = @window_field.index
  447.       else
  448.         @action_window.set_handler(:invk,      method(:choice_place))
  449.         JCC.wait_for(:invk)
  450.       end
  451.     else
  452.       if JCC.get_zone == :field
  453.         @action_window.set_handler(:activate,      method(:action_activate))
  454.         @actual_card = @window_field.actual_card
  455.         @actual_index = @window_field.index
  456.       else
  457.         @action_window.set_handler(:placer,      method(:choice_place))
  458.         JCC.wait_for(:placer)
  459.       end
  460.     end
  461.   end
  462.   def open_action_card(card_id)
  463.     if $data_jcc[:Cards][card_id][:type] == "Monstre"
  464.       JCC.set_is_monster(true)
  465.     else
  466.       JCC.set_is_monster(false)
  467.     end
  468.     @action_window.refresh
  469.     action_window_set_handler
  470.     @action_window.activate
  471.     @action_window.select(0)
  472.     @action_window.open
  473.   end
  474.   def card_choiced
  475.     if JCC.get_zone == :hand
  476.       card_id = JCC.player_hand[@cards_list.index]
  477.       open_action_card(card_id)
  478.     end
  479.   end
  480.   def close_action_window
  481.     @action_window.close
  482.     JCC.wait_for(:nil)
  483.     @actual_card = nil
  484.     if JCC.get_zone == :field
  485.       @window_field.activate
  486.     else
  487.       @cards_list.activate
  488.     end
  489.   end
  490.   def add_life(sym, value)
  491.     JCC.add_life(sym, value)
  492.     @player_life.refresh
  493.     @ennemy_life.refresh
  494.   end
  495.  
  496.   def set_battle_results
  497.     @window_field.set_fight_count(@actual_index,@actual_card.fight_count+1)
  498.     diff = @cible_card.defense - @actual_card.force
  499.     if diff < 0
  500.       @window_field.delete_card(@cible_index)
  501.       if @in_turn == :player
  502.         add_life(:ennemy, diff)
  503.       else
  504.         add_life(:player, diff)
  505.       end
  506.     elsif diff > 0
  507.       if @in_turn == :player
  508.         add_life(:player, -diff)
  509.       else
  510.         add_life(:ennemy, -diff)
  511.       end
  512.     end
  513.   end
  514. #===============================================================================
  515. #*Update
  516. #===============================================================================
  517.   def update
  518.     super
  519.     press_c
  520.     verify_life
  521.     verify_victory
  522.     press_b
  523.   end
  524.   def press_c
  525.     if Input.trigger?(:C)
  526.       if JCC.get_zone == :field
  527.         if JCC.get_wait_for == :nil and not @window_field.card_id(@window_field.index) == nil
  528.           if @window_field.col == 0 or @window_field.col == 1
  529.             open_action_card(@window_field.card_id(@window_field.index))
  530.             @window_field.deactivate
  531.           end
  532.         elsif JCC.get_wait_for == :atk_cible
  533.           unless @window_field.col == 2 or @window_field.card_id(@window_field.index) == nil
  534.             @info_window.set_text("Action non autorisée")
  535.           else
  536.             @cible_card = @window_field.actual_card
  537.             @cible_index = @window_field.index
  538.             set_battle_results
  539.             JCC.wait_for(:nil)
  540.           end
  541.         elsif JCC.get_wait_for == :spell_cible
  542.           unless @window_field.col == 2 or @window_field.col == 1 or @window_field.actual_card == nil
  543.             @info_window.set_text("Action non autorisée")
  544.           else
  545.             @window_field.add_card_def(@actual_card.defense)
  546.             @window_field.add_card_atk(@actual_card.force)
  547.             @window_field.delete_card(@actual_index)
  548.             JCC.wait_for(:nil)
  549.           end
  550.         end
  551.       else
  552.         if @window_field.card_id(@window_field.index) == nil
  553.           if JCC.get_wait_for == :invk
  554.             unless @window_field.col == 1
  555.               Sound.play_buzzer
  556.               @info_window.set_text("Action non autorisée")
  557.             else
  558.               unless @invok_in_turn == Monster_Limit
  559.                 @invok_in_turn += 1
  560.                 @info_window.set_text("Invocation réussite")
  561.                 player_place_card
  562.               else
  563.                 @info_window.set_text("Maximum de monstre sur le terrain")
  564.                 Sound.play_buzzer
  565.               end
  566.             end
  567.           elsif JCC.get_wait_for == :placer
  568.             unless @window_field.col == 0
  569.               @info_window.set_text("Action non autorisée")
  570.               Sound.play_buzzer
  571.             else
  572.               unless @spell_in_turn == Spell_Limit
  573.                 @spell_in_turn += 1
  574.                 @info_window.set_text("Carte placée avec succès")
  575.                 player_place_card
  576.               else
  577.                 @info_window.set_text("Maximum de magie sur le terrain")
  578.                 Sound.play_buzzer
  579.               end
  580.             end
  581.           end
  582.         else
  583.           @info_window.set_text("Action non autorisée")
  584.           Sound.play_buzzer
  585.         end
  586.       end
  587.     end
  588.   end
  589.   def player_place_card
  590.     @window_field.set_card(@window_field.index,JCC.player_hand[@cards_list.index])
  591.     JCC.remove_hand_card(:player,@cards_list.index)
  592.     @cards_list.refresh
  593.     @cards_list.select(0)
  594.     JCC.wait_for(:nil)
  595.     @window_field.deactivate
  596.     @cards_list.open
  597.     @cards_list.activate
  598.   end
  599.   def verify_life
  600.     @victory = false if JCC.get_life(:player) <= 0
  601.     @victory = true if JCC.get_life(:ennemy) <= 0
  602.   end
  603.   def verify_victory
  604.     if @victory
  605.       @info_window.set_text("Victoire !!!")
  606.       Graphics.wait(60)
  607.       SceneManager.return
  608.     elsif @victory == false
  609.       @info_window.set_text("Defaite ...")
  610.       Graphics.wait(60)
  611.       SceneManager.return
  612.     end
  613.   end
  614.   def press_b
  615.     if Input.trigger?(:B)
  616.       if JCC.get_zone == :hand
  617.         if JCC.get_wait_for == :invk or JCC.get_wait_for == :placer
  618.           JCC.wait_for(:nil)
  619.           @cards_list.open
  620.           @action_window.open
  621.           @window_field.deactivate
  622.           @action_window.activate
  623.         elsif @action_window.open?
  624.           close_action_window
  625.           @cards_list.activate
  626.         elsif not @action_window.open?
  627.           @cards_list.close
  628.           @command_jcc.activate
  629.           JCC.set_zone(:home)
  630.         end
  631.       elsif JCC.get_zone == :field
  632.         if JCC.get_wait_for == :atk_cible or JCC.get_wait_for == :spell_cible
  633.           @window_field.deactivate
  634.           @action_window.open
  635.           @action_window.activate
  636.         elsif @action_window.open?
  637.           close_action_window
  638.         elsif JCC.get_wait_for == :nil
  639.           @window_field.deactivate
  640.           @command_jcc.activate
  641.           JCC.set_zone(:home)
  642.         end
  643.       end
  644.     end
  645.   end
  646. end
  647. #===============================================================================
  648. #.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*~.~*
  649. #===============================================================================
  650. #*Windows for Scene_Defi
  651. #===============================================================================
  652. class Window_Command_JCC < Window_HorzCommand
  653.   def initialize(x,y)
  654.     super(x,y)
  655.     select(1)
  656.   end
  657.   def make_command_list
  658.     add_command("Mes Cartes", :hand)
  659.     add_command("Terrain", :field)
  660.     add_command("Passer", :next)
  661.     add_command("Abondonner", :exit)
  662.   end
  663.   def window_width ; Graphics.width ; end
  664. end
  665. #===============================================================================
  666. #*Window for Select Cards
  667. #===============================================================================
  668. class Window_Card_Select < Window_Command
  669.   def initialize(x, y)
  670.     super(x, y)
  671.     self.openness = 0
  672.   end
  673.   def make_command_list
  674.     JCC.player_hand.each{|id| add_command("#{id}", :card)}
  675.   end
  676.   def window_width ; 128 ; end
  677.   def item_width ; 100 ; end
  678.   def item_height ; 100 ; end
  679.   def fitting_height(line_number)
  680.     3 * item_height + standard_padding * 2
  681.   end
  682.   def draw_item(index)
  683.     bitmap = Cache.card($data_jcc[:Cards][JCC.player_hand[index]][:picture])
  684.     rect = item_rect(index)
  685.     contents.blt(rect.x,rect.y,bitmap,Rect.new(0, 0, 100, 100),200)
  686.   end
  687. end
  688. #===============================================================================
  689. #*Window for life
  690. #===============================================================================
  691. class Window_Life < Window_Base
  692.   def initialize(x,y, cible)
  693.     super(x,y,70,fitting_height(1))
  694.     @cible = cible
  695.     refresh
  696.   end
  697.   def refresh
  698.     contents.clear
  699.     draw_text_ex(0, 0, JCC.get_life(@cible))
  700.   end
  701. end
  702. #===============================================================================
  703. #*Window for JCC_Help
  704. #===============================================================================
  705. class Window_JCC_Help < Window_Base
  706.   def initialize(line_number = 2)
  707.     super(70, 0, Graphics.width-140, fitting_height(line_number))
  708.   end
  709.   def set_text(text)
  710.     if text != @text
  711.       @text = text
  712.       refresh
  713.     end
  714.   end
  715.   def clear ; set_text("") ; end
  716.   def set_item(item) ; set_text(item ? item.description : "") ; end
  717.   def refresh
  718.     contents.clear
  719.     draw_text_ex(4, 0, @text)
  720.   end
  721. end
  722. #===============================================================================
  723. #*Window for JCC_Field
  724. #===============================================================================
  725. class JCC_Field < Window_Selectable
  726.   include JCC_Config
  727.   def initialize(x, y, width, height)
  728.     super
  729.     @card = Array.new(col_max*row_max)
  730.     refresh
  731.     select(0)
  732.   end
  733.   def item_rect(index)
  734.     rect = Rect.new
  735.     rect.width = item_width
  736.     rect.height = item_height
  737.     if (index % col_max) == 0 or (index % col_max) == 3 and not (index / col_max) >= SpellField_Size
  738.       rect.x = index % col_max * (item_width + spacing)
  739.       rect.y = index / col_max * item_height
  740.     elsif (index % col_max) == 1 or (index % col_max) == 2 and not (index / col_max) >= MonsterField_Size
  741.       rect.x = index % col_max * (item_width + spacing)
  742.       rect.y = index / col_max * item_height
  743.     end
  744.     rect
  745.   end
  746.   def draw_all_items
  747.     item_max.times do |i|
  748.       if (i % col_max) == 0 or (i % col_max) == 3 and not (i / col_max) >= SpellField_Size
  749.         draw_item(i)
  750.       elsif (i % col_max) == 1 or (i % col_max) == 2 and not (i / col_max) >= MonsterField_Size
  751.         draw_item(i)
  752.       end
  753.     end
  754.   end
  755.   def draw_line
  756.     contents.fill_rect((contents.width/2)-3,0,2,contents.height,Color.new(0,0,0,255))
  757.   end
  758.   def col_max ; return 4 ; end
  759.   def item_max ; col_max*row_max ; end
  760.   def col ; index-row*col_max ; end
  761.   def row_max
  762.     if MonsterField_Size >= SpellField_Size
  763.       return MonsterField_Size
  764.     elsif MonsterField_Size <= SpellField_Size
  765.       return SpellField_Size
  766.     else
  767.       return 5
  768.     end
  769.   end
  770.   def item_width ; return 100 ; end
  771.   def item_height ; return 100 ; end
  772.   def spacing ; return 38 ; end
  773.   def draw_item(index)
  774.     unless @card[index] == nil
  775.       bitmap = Cache.card($data_jcc[:Cards][@card[index].id][:picture])
  776.       bitmap = Cache.card("Default.png") if index.modulo(4) == 3 && !Show_ennemy_Spell
  777.     else
  778.       bitmap = Cache.card("Clean.png")
  779.     end
  780.     rect = item_rect(index)
  781.     contents.blt(rect.x,rect.y,bitmap,Rect.new(0, 0, 100, 100),200)
  782.   end
  783.   def refresh
  784.     super
  785.     draw_line
  786.   end
  787.   #Card Managment
  788.   def card_id(index)
  789.     unless @card[index] == nil ; @card[index].id
  790.     else ; return nil
  791.     end
  792.   end
  793.   def actual_card ; @card[index] ; end
  794.   def card(index) ; @card[index] ; end
  795.   def add_card_def(ndef) ; @card[index].add_defense(ndef) ; end
  796.   def add_card_atk(natk) ; @card[index].add_force(natk) ; end
  797.   def set_fight_count(index,value) ; @card[index].fight_count = value ; end
  798.   def set_card(index,id)
  799.     @card[index] = Game_Card.new(id)
  800.     refresh
  801.   end
  802.   def delete_card(index)
  803.     @card[index] = nil
  804.     refresh
  805.   end
  806.   def reset_fight_count
  807.     @card.each do |card|
  808.       card.fight_count = 0 unless card == nil
  809.     end
  810.   end
  811. end
  812. #===============================================================================
  813. #*Window for Action_Card
  814. #===============================================================================
  815. class Action_Card < Window_Command
  816.   def initialize(x, y)
  817.     super(x, y)
  818.     self.openness = 0
  819.   end
  820.   def make_command_list
  821.     if JCC.is_monster
  822.       add_command("Attaquer", :atk) if JCC.get_zone == :field
  823.       add_command("Invoquer", :invk) if JCC.get_zone == :hand
  824.     else
  825.       add_command("Activer", :activate) if JCC.get_zone == :field
  826.       add_command("Placer", :placer) if JCC.get_zone == :hand
  827.     end
  828.     add_command("Retour", :return)
  829.   end
  830.   def window_height ; fitting_height(2) ; end
  831. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement