CrowMakerVX

GridWars1_0

Aug 7th, 2014
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 79.08 KB | None | 0 0
  1. ################################################################################
  2. #                           GRID WARS v1.0
  3. #                            By: IXfuru
  4. ################################################################################
  5. #
  6. # This script adds a mini-game called GridWars to your project.  The game is a
  7. # simulated battlefield board, where the side with the most occupied spaces at
  8. # the end of the battle wins.   The game is played between the player and an
  9. # event.  The system tracks GridWars record and GridPoints, which can then be
  10. # used to buy more 'monster tokens' for use on the battlefield board.
  11. #
  12. # In order to use the script, you must at least set up a few of the Settings
  13. # constants.  And it is highly recommended that you create or find an iconset
  14. # graphic which has a good number of icons which can represent the tokens of the
  15. # GridWars System.
  16. #
  17. # First, set up the RANDOM_MONSTERS[:icon_pool] hash in section 1.  You can
  18. # ignore the naming arrays, but it is imperative that you set up the icon
  19. # pool to select random icons from your own Iconset graphic.  If you take the
  20. # Iconset from the demo, you don't have to change the array at all, as it is
  21. # set up to coordinate with that Iconset.
  22. #
  23. # Then, set up the OWNERS hash.  This is the single most important setting
  24. # in the game.  It's important because it is where you will set up the
  25. # AI opponents for the game.  
  26. #
  27. # Whatever you do, make sure to follow the directions in the section you wish
  28. # to edit carefully.
  29. #
  30. #*******************************************************************************
  31. # As of now, there are two scenes, the manager and the GridWars battle scene.
  32. # The next version will feature the ability to rename the tokens, the ability
  33. # to buy/sell tokens, and perhaps the ability to level up the tokens
  34. # you have.
  35. #*******************************************************************************
  36. #
  37. ################################################################################
  38. # This script is not for commercial use without first gaining permission from
  39. # Ixfuru, the author.  It is shared under the Creative Commons Non-Commercial
  40. # license.  If you wish to use the script in your project, and intend it to
  41. # be commercial, you can post in the topic where you found this, or contact Ixfuru
  42. # via RpgMakerVX.net, Rpgmaker.net, Rpgmakerweb.com, Rmrk.net
  43. ################################################################################
  44. module Ixfuru
  45.   module GridWars
  46.    
  47.     #===========================================================================
  48.     # Section 1:
  49.     #
  50.     # RANDOM MONSTERS
  51.     #
  52.     # (A)
  53.     #
  54.     # This section is used to create 'pools' which can be used to generate the
  55.     # properties of a random monster (or Token).  The first four hashes are
  56.     # used in the creation of random names:
  57.     #
  58.     #                 :first_letters : holds capital letters for being the first
  59.     #                                   letter in the random token's name.  This
  60.     #                                  array is also drawn from in the middle of
  61.     #                                  the name for mid-name letters as well,
  62.     #                                   so the name is a little misleading.  FOr
  63.     #                                   the most part, this array is set up the
  64.     #                                   way it should be. With every letter of the
  65.     #                                 English language as a possible.
  66.     #
  67.     #                  :vowels : holds the vowels of the English language.  These
  68.     #                           are also drawn from when creating names.
  69.     #
  70.     #                  :vowel_groupings : this holds vowels paired with other
  71.     #                                      letters.
  72.     #
  73.     #                  :const_groupings : this stores consanants of the alphabet
  74.     #                                  grouped with two or more other letters to
  75.     #                                form common English combinations.
  76.     #
  77.     # For all of the above arrays, you can add to them by simply adding a
  78.     # letter or letter in string form ("") double-quoted.
  79.     #
  80.     # (B)
  81.     #
  82.     # The last key in this hash, :icon_pool, is an important part of the settings
  83.     # and will most often need modified.  Basically, the array here consists
  84.     # of icon indices from the Iconset graphic in your system folder.  As tokens
  85.     # (monsters) are represented in the game by icons, you will need an Iconset
  86.     # graphic which contains images you want to use as tokens. Once you have
  87.     # the graphic you want, you then need to find and list each icon's index on
  88.     # the graphic which is used for representation.  There are quite a few
  89.     # programs/scripts for finding the index of an icon out there.  Omegas7 and
  90.     # Woratana both made one. Search them out.
  91.     #
  92.     # As a tip, you could arrange all the 'token' icons on the Iconset sheet
  93.     # together and then find the index of the first and the index of the last
  94.     # respectively.  Then you could use my NumericListBetwixter here:
  95.     #
  96.     #           http://www.rpgmakervx.net/index.php?showtopic=53111
  97.     #
  98.     # With that tool, you are able to input the first and last numbers of a long
  99.     # list of numbers, and it will write them as common separated values perfect
  100.     # for use in arrays.  Then you just import/copy/paste to your project.
  101.     #
  102.     # However you do it, just make sure you fill the :icon_pool array with
  103.     # many different token-representing icon_ids.  The more you add, the larger
  104.     # number of random tokens will appear on your GridWars battlefield.
  105.     #
  106.     #===========================================================================
  107.    
  108.     RANDOM_MONSTERS = {
  109.    
  110.     :first_letters => ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L",
  111.                       "M", "N", "O", "P", "Qu", "R", "S", "T", "U", "V", "W",
  112.                       "X", "Y", "Z"],
  113.                      
  114.     :vowels => ["a", "e", "i", "o", "u"],
  115.    
  116.     :vowel_groupings => ["ar", "er", "ir", "or", "ur", "ai", "ee", "ae", "au",
  117.                         "ao", "eo", "ea", "aa", "eu", "ia", "ie", "io", "oo",
  118.                         "oa", "oe", "ou", "oi", "ua", "ue", "ui", "uo"],
  119.    
  120.     :const_groupings => ["br", "bl", "bb", "ch", "cl", "cr", "chr", "ck",
  121.                          "dr", "dd", "dw", "ff", "fr", "fl", "ft",
  122.                          "gr", "gl", "gg", "kr", "kl", "ll", "mm", "nn",
  123.                          "ph", "pl", "pr", "pp", "qu", "rr", "st", "sch", "sh",
  124.                          "sc", "str", "sl", "shr", "sm", "sn", "sp", "spr",
  125.                          "sk", "skr", "sw", "tr", "th", "thr", "ss", "tt",
  126.                          "xx", "zz", "mp", "nk", "nt", "mb", "nc", "nd", "ng",
  127.                          "ny", "my", "cy", "dy", "fy", "ly", "ry"],
  128.                          
  129.     :icon_pool => [368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379,
  130.     380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394,
  131.     395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409,
  132.     410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424,
  133.     425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439,
  134.     440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454,
  135.     455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469,
  136.     470, 471, 472, 473, 474, 475, 476, 477, 478, 479],
  137.    
  138.     }
  139.    
  140.     #===========================================================================
  141.     # Section 2:
  142.     #
  143.     # MONSTERS
  144.     #
  145.     # This section allows you to create SPECIFIC monsters.  Those that you will
  146.     # use in your project and give to certain characters, or the player.  These
  147.     # are monsters which you intend to be unique tokens in the project.
  148.     #
  149.     # For these, you get to set the properties by linking them in the hash
  150.     # to a unique token_ID.
  151.     #
  152.     # Here are the properties:
  153.     #
  154.     #         :name : string used as the name of the token
  155.     #         :atk : integer Preferaby form 1-10
  156.     #         :def, :dodge, :accuracy : same as :atk
  157.     #
  158.     # Refer to Section 7 (SCRIPT CALLS) for information pertaining to how to
  159.     # give a specific card from the hash to the player or another character.
  160.     #
  161.     #
  162.     #===========================================================================
  163.                          
  164.    
  165.     MONSTERS = {
  166.    
  167.       #token_id => {:name => string,
  168.       #               :icon_id => integer,
  169.       #               :atk => integer,
  170.       #               :def => integer,
  171.       #               :dodge => integer,
  172.       #               :accuracy => integer}
  173.      
  174.       0 => {:name => "Ofert",
  175.             :icon_id => 413,
  176.             :atk => 4,
  177.             :def => 6,
  178.             :dodge => 7,
  179.             :accuracty => 2},
  180.            
  181.     }
  182.    
  183.     #===========================================================================
  184.     # Section 3:
  185.     #
  186.     # OWNERS
  187.     #
  188.     # This section is crucial to using the script.  Owners are the events which
  189.     # possess tokens of their own and are therefor able to duel against the
  190.     # player in GridWars matches.  
  191.     #
  192.     # In order to set up for an event to be used, you need to provide a
  193.     # listing of it in the OWNERS hash.  
  194.     #
  195.     # For starters, for every map which has an event capable of GridWars
  196.     # participation, you need to have an outer hash_key of the map's ID.
  197.     #
  198.     # Each of these IDS are subsequently linked to an inner hash, which consists
  199.     # of every ID on the said map which is able to participate in GridWars.
  200.     #
  201.     # So you have:
  202.     #
  203.     #   7 => {3 => [],
  204.     #         8 => [],
  205.     #         28 => []},
  206.     #
  207.     # So in the above example, you have events 3, 8 and 28 on map 7 able to
  208.     # participate.  This means that if you are not on map # 7 and you try to
  209.     # battle event 28, you will receive an error message. You must be on the
  210.     # right map to call a GridWars match.
  211.     #
  212.     # Once you have this set up, you need to fill in the arrays '[]' associated
  213.     # with each event_id. To do this, you will be using three elements.
  214.     #
  215.     #        [stars, name, start_record]
  216.     #
  217.     # stars : this number is given to represent how strong the character's
  218.     #          token set will be.  This number should NOT exceed 5, preferably
  219.     #         and not be below 1.  A five star token set, will hold tokens
  220.     #        with ATK, DEF, DDG and ACC of up to 10, as the max for each
  221.     #       parameter is calculated by multiplying the 'stars' rating by 2.
  222.     #
  223.     # :name : This is the name you wish to be displayed when the GridWars
  224.     #         battle is taking place.
  225.     #
  226.     # :start_record : This is a three-element array [wins, losses, ties]
  227.     #                 This tells what you want the character's GridWars record
  228.     #                when the game starts.  
  229.     #
  230.     #============================================================================
  231.    
  232.     OWNERS = {
  233.    
  234.     #map_id => {event_id => [stars, name, start_record]}
  235.     1 => {2 => [1, "Whinny", [13, 12, 2]],
  236.           3 => [3, "Nancy", [4, 5, 0]],
  237.           5 => [5, "Ixfuru", [18, 2, 1]]},
  238.    
  239.     }
  240.    
  241.     #===========================================================================
  242.     # Section 4:
  243.     #
  244.     # SOUNDS
  245.     #
  246.     # This hash is used to store the sound_effects you wish to use inside the
  247.     # GridWars system.   For each entry, you need to add a three-element array.
  248.     #
  249.     #       [filename, volume, pitch]
  250.     #
  251.     #===========================================================================
  252.    
  253.     SOUNDS = {
  254.    
  255.     :place_card => ["Ice9", 80, 150], # sound played when a card is placed
  256.     :selection => ["Decision2", 80, 100], # sound played when selection is made
  257.     :attacking => ["Attack1", 80, 100], # sound played when attack is made
  258.     :defending => ["Flash1", 80, 100], # sound played when a defense is made
  259.     :dodging => ["Sword3", 80, 100], # sound played when dodge is made
  260.     :quickset => ["Raise3", 80, 100], # sound played when the quickset is called
  261.     :missing => ["Miss", 80, 100], # sound played when an attack misses
  262.    
  263.     }
  264.    
  265.     #===========================================================================
  266.     # Section 5:
  267.     #
  268.     # Musics
  269.     #
  270.     # This is the same as the hash from section 4, however, its used to store
  271.     # Music Effects, not sound effects.
  272.     #
  273.     #===========================================================================
  274.    
  275.     MUSICS = {
  276.    
  277.     :victory => ["Fanfare1", 80, 100],
  278.     :defeat => ["Item", 80, 100],
  279.     :tie => ["Gag", 80, 100],
  280.    
  281.    
  282.     }
  283.    
  284.     #===========================================================================
  285.     # Section 6:
  286.     #
  287.     # MISCELLANEOUS
  288.     #
  289.     # The following are a handful of other non-specific values which are used
  290.     # by the system and which can be altered here.
  291.     #
  292.     #===========================================================================
  293.    
  294.     ATTACK_ANIMATION = 40  # The database animation ID run when Attack is made
  295.    
  296.     PLAYER_FIELD_COLOR = 5 # # The color representing a player's token on the field
  297.     OPPONENT_FIELD_COLOR = 2 # The color representing an event's token on the field
  298.     QUICK_SET_TAG_COLOR = 14 # The color used to represent a token is in the quick set
  299.    
  300.     HIDDEN_OPPONENT_ICON_INDEX = 240 # the icon_index of the icon used to represent
  301.     #                                  an event's token before it is revealed
  302.    
  303.     BASE_VALUE = 100  # This is the gold value which is multiplied by the
  304.     #                   'star's of a given token to determine a price
  305.    
  306.     WAIT_COUNT = 90  # This is how long in frames the AI takes to make specific
  307.     #                   decisions
  308.    
  309.     TARGET_COLOR = 3 # This is the color shown representing a token which can be
  310.     #                  a target
  311.    
  312.     QUICKSET_COLOR = 23 # This is the color that denotes a card is in the Quickset
  313.    
  314.     GWBGM = ["Battle8", 80, 100] # This will be the music played during GridWars Matches
  315.    
  316.     #===========================================================================
  317.     # Section 7:
  318.     #
  319.     # SCRIPT CALLS
  320.     #
  321.     # The following section is used for a reference to the creator of the project
  322.     # to illustrate in detail how the script can be used.  Use of the script
  323.     # requires the creator to make 'script calls' from the third page of
  324.     # an event's commands, or a common event's commands.  Enter the
  325.     # following script calls.
  326.     #
  327.     ##---------------------------------------------------------------------------
  328.     #
  329.     # 1. Call the GridWars Battle Scene:
  330.     #
  331.     #             $scene = Scene_GridWars.new(owner_id)
  332.     #
  333.     #     In this call, you need to replace the 'owner_id' deal with an ID of
  334.     # an OWNER you set up in the OWNERS hash.  
  335.     #       -don't call this scene unless the owner_id exists
  336.     #  
  337.     ##---------------------------------------------------------------------------
  338.     #
  339.     # 2. Call the TokenManager Scene:
  340.     #
  341.     #           $scene = Scene_TokenManager.new(owner_id)
  342.     #
  343.     # This call the will take the player to the scene where he/she can set up,
  344.     # delete and otherwise manage their tokens.
  345.     #
  346.     ##---------------------------------------------------------------------------
  347.     #
  348.     # 3. Check to see if the Player won the last match
  349.     #
  350.     #           $game_system.won_last_grid?
  351.     #
  352.     #     This is a great call for a conditional branch.  As it will return
  353.     #      true if the player won the last match they were part of.  This
  354.     #   makes it so that the creator can make things happen upon victory.
  355.     #
  356.     #           !$game_system.won_last_grid?
  357.     #
  358.     #     Use that to check if the player DID NOT win the last GridWars match
  359.     #
  360.     ##---------------------------------------------------------------------------
  361.     #
  362.     # 4. Create a Token set for the player/event
  363.     #
  364.     #             $game_player.new_grid_tokens(stars)
  365.     #                         or
  366.     #           $game_events[x].new_grid_tokens(stars)
  367.     #
  368.     #    These calls will render a new deck to the player or the event in question
  369.     #  respectively.  This gives 45 randomly generated tokens to the said
  370.     #   target.   It is very important that you DO NOT GIVE THE PLAYER A NEW
  371.     #   TOKEN SET twice.  This can cause bad problems with the script.
  372.     #
  373.     ##---------------------------------------------------------------------------
  374.     #
  375.     # 5. Check Wins/Losses/Ties
  376.     #
  377.     #       $game_player.grid_wins
  378.     #               or
  379.     #      $game_map.events[x].grid_wins
  380.     #
  381.     #            .grid_losses
  382.     #            .grid_ties    
  383.     #            .grid_matches
  384.     #
  385.     #    These calls will return the value of whatever part of the GridWars
  386.     # record you specify.  Say you want to set up an event for when a player
  387.     # wins 10 matches, these calls enable you to do that.
  388.     #                    -the .grid_matches call will return total matches played
  389.     #
  390.     ##---------------------------------------------------------------------------
  391.     #
  392.     # 6. Give a new token
  393.     #
  394.     #                  $game_player.add_token(stars)
  395.     #                            or
  396.     #                $game_map.events[x].add_token(stars)
  397.     #
  398.     #     These are the calls you place in order to add a new token to the
  399.     # player or event in question.   This gives a randomly generated token.
  400.     #
  401.     #---------------------------------------------------------------------------
  402.     #
  403.     # 7. Give a specific token from those found in the MONSTERS hash
  404.     #
  405.     #              $game_player.add_special_token(stars, token_id)
  406.     #
  407.     #          This does the exact same thing as #6, however, it creates a
  408.     #   token based on the one in the MONSTERS hash whose token_id matches
  409.     #   that given to the method as a second argument.  The 'stars' part
  410.     # here can be passed as any value 1-5.
  411.     #
  412.     #----------------------------------------------------------------------------
  413.     # 8. Give the event/player a new pack of tokens
  414.     #
  415.     #            $game_player.new_token_pack(stars)
  416.     #                          or
  417.     #            $game_map.events[x].new_token_pack(stars)
  418.     #
  419.     #===========================================================================
  420.  
  421.   end
  422. end
  423.  
  424. ################################################################################
  425. #                              GAME SYSTEM
  426. ################################################################################
  427. class Game_System
  428.  
  429.   attr_accessor :grid_monsters
  430.   attr_accessor :last_grid_result
  431.  
  432.   #------------------------------------------------------------------------------
  433.   # Initialize (Aliased)
  434.   #-----------------------------------------------------------------------------
  435.   alias ixgwgsini initialize unless $@
  436.   def initialize
  437.     ixgwgsini
  438.     @grid_monsters = {}
  439.     @last_grid_result = -1
  440.   end
  441.  
  442.   #-----------------------------------------------------------------------------
  443.   # Won Last Grid?
  444.   #-----------------------------------------------------------------------------
  445.   def won_last_grid?
  446.     return @last_grid_result == 0
  447.   end
  448.  
  449.   #------------------------------------------------------------------------------
  450.   # Update ( Aliased)
  451.   #-----------------------------------------------------------------------------
  452.   alias ixgwgsupdate update unless $@
  453.   def update
  454.     ixgwgsupdate
  455.     @grid_monsters = {} if @grid_monsters.nil?
  456.     @last_grid_result = -1 if @last_grid_result.nil?
  457.   end
  458.  
  459. end
  460.  
  461.  
  462. ################################################################################
  463. #                   GAME PLAYER
  464. ################################################################################
  465. class Game_Player < Game_Character
  466.  
  467.   attr_accessor :grid_monsters
  468.   attr_accessor :token_points
  469.   attr_accessor :grid_record
  470.   attr_accessor :quick_tokens # A set of grid monsters that can be called quickly
  471.  
  472.   #-----------------------------------------------------------------------------
  473.   # Initialize (Aliased)
  474.   #-----------------------------------------------------------------------------
  475.   alias ixgwarsgmplyrini initialize unless $@
  476.   def initialize
  477.     ixgwarsgmplyrini
  478.     @grid_monsters = {}
  479.     @quick_tokens = {}
  480.     @token_points = 0
  481.     @grid_record = [0, 0, 0]
  482.   end
  483.  
  484.   #-----------------------------------------------------------------------------
  485.   # Grid Wins
  486.   #-----------------------------------------------------------------------------
  487.   def grid_wins
  488.     return @grid_record[0]
  489.   end
  490.  
  491.   #-----------------------------------------------------------------------------
  492.   # Grid Losses
  493.   #-----------------------------------------------------------------------------
  494.   def grid_losses
  495.     return @grid_record[1]
  496.   end
  497.  
  498.   #-----------------------------------------------------------------------------
  499.   # Grid Ties
  500.   #-----------------------------------------------------------------------------
  501.   def grid_ties
  502.     return @grid_record[2]
  503.   end
  504.  
  505.   #-----------------------------------------------------------------------------
  506.   # Grid Matches
  507.   #-----------------------------------------------------------------------------
  508.   def grid_matches
  509.     return @grid_record[0] + @grid_record[1] + @grid_record[2]
  510.   end
  511.  
  512.   #------------------------------------------------------------------------------
  513.   # New Special Token
  514.   #-----------------------------------------------------------------------------
  515.   def new_special_token(stars, token_id)
  516.     @grid_monsters[@grid_monsters.size] = GridMonster.new(1, token_id)
  517.   end
  518.  
  519.   #-----------------------------------------------------------------------------
  520.   # New Token
  521.   #-----------------------------------------------------------------------------
  522.   def add_token(stars)
  523.     @grid_monsters[@grid_monsters.size] = GridMonster.new(stars)
  524.   end
  525.  
  526.   #-----------------------------------------------------------------------------
  527.   # Get Grid Monsters
  528.   #-----------------------------------------------------------------------------
  529.   def get_grid_monsters(stars)
  530.     @grid_monsters = {} if @grid_monsters.nil?
  531.     new_grid_tokens(stars) if @grid_monsters = {}
  532.   end
  533.  
  534.   #-----------------------------------------------------------------------------
  535.   # New Grid Tokens
  536.   #-----------------------------------------------------------------------------
  537.   def new_grid_tokens(stars)
  538.     for i in 0...45
  539.       @grid_monsters[i] = GridMonster.new(stars)
  540.     end
  541.   end
  542.  
  543.   #-----------------------------------------------------------------------------
  544.   # Grid Name
  545.   #-----------------------------------------------------------------------------
  546.   def grid_name
  547.     return $game_party.members[0].name
  548.   end
  549.  
  550.   #-----------------------------------------------------------------------------
  551.   # New Token Pack
  552.   #-----------------------------------------------------------------------------
  553.   def new_token_pack(token_count, stars)
  554.     gmi = @grid_monsters.size
  555.     for i in 0...token_count
  556.       @grid_monsters[gmi] = GridMonster.new(stars)
  557.       gmi += 1
  558.     end
  559.   end
  560.  
  561.   #-----------------------------------------------------------------------------
  562.   # Renumerate Tokens
  563.   #-----------------------------------------------------------------------------
  564.   def renumerate_tokens
  565.     new_monsters = {}
  566.     i = 0
  567.     @grid_monsters.each { |index, monster|
  568.     next if monster.nil?
  569.     new_monsters[i] = monster
  570.     i += 1
  571.     }
  572.     @grid_monsters = new_monsters
  573.     @grid_monsters = new_monsters
  574.     unless @quick_tokens.nil?
  575.       new_quicks = {}
  576.       i = 0
  577.       @quick_tokens.each { |index, monster|
  578.       next if monster.nil?
  579.       new_quicks[i] = monster
  580.       i += 1
  581.       }
  582.     end
  583.     @quick_tokens = new_quicks
  584.   end
  585.      
  586.  
  587. end
  588.  
  589. ################################################################################
  590. #                         GAME EVENT
  591. ################################################################################
  592. class Game_Event < Game_Character
  593.  
  594.   attr_accessor :grid_monsters
  595.   attr_accessor :grid_record
  596.  
  597.   #-----------------------------------------------------------------------------
  598.   # Initialize (Aliased)
  599.   #-----------------------------------------------------------------------------
  600.   alias ixgwarsgmeventini initialize unless $@
  601.   def initialize(map_id, event)
  602.     ixgwarsgmeventini(map_id, event)
  603.     @grid_record = []
  604.   end
  605.  
  606.   #-----------------------------------------------------------------------------
  607.   # Get Grid Monsters
  608.   #-----------------------------------------------------------------------------
  609.   def get_grid_monsters
  610.     @grid_monsters = {} if @grid_monsters.nil?
  611.     @grid_monsters = {} if !Ixfuru::GridWars::OWNERS.include?(@map_id)
  612.     @grid_monsters = {} if !Ixfuru::GridWars::OWNERS[@map_id].include?(@event.id)
  613.     new_grid_tokens(Ixfuru::GridWars::OWNERS[@map_id][@event.id][0]) if @grid_monsters.empty?
  614.     rec = Ixfuru::GridWars::OWNERS[@map_id][@event.id][2]
  615.     @grid_record = [rec[0], rec[1], rec[2]] if @grid_record.empty?
  616.   end
  617.  
  618.   #-----------------------------------------------------------------------------
  619.   # Grid Name
  620.   #-----------------------------------------------------------------------------
  621.   def grid_name
  622.     return "" if !Ixfuru::GridWars::OWNERS.include?(@map_id)
  623.     return "" if !Ixfuru::GridWars::OWNERS[@map_id].include?(@event.id)
  624.     return Ixfuru::GridWars::OWNERS[@map_id][@event.id][1]
  625.   end
  626.  
  627.   #-----------------------------------------------------------------------------
  628.   # New Grid Tokens
  629.   #-----------------------------------------------------------------------------
  630.   def new_grid_tokens(stars)
  631.     for i in 0...45
  632.       @grid_monsters[i] = GridMonster.new(stars)
  633.     end
  634.   end
  635.  
  636.    #-----------------------------------------------------------------------------
  637.   # Grid Wins
  638.   #-----------------------------------------------------------------------------
  639.   def grid_wins
  640.     return @grid_record[0]
  641.   end
  642.  
  643.   #-----------------------------------------------------------------------------
  644.   # Grid Losses
  645.   #-----------------------------------------------------------------------------
  646.   def grid_losses
  647.     return @grid_record[1]
  648.   end
  649.  
  650.   #-----------------------------------------------------------------------------
  651.   # Grid Ties
  652.   #-----------------------------------------------------------------------------
  653.   def grid_ties
  654.     return @grid_record[2]
  655.   end
  656.  
  657.   #-----------------------------------------------------------------------------
  658.   # Grid Matches
  659.   #-----------------------------------------------------------------------------
  660.   def grid_matches
  661.     return @grid_record[0] + @grid_record[1] + @grid_record[2]
  662.   end
  663.  
  664.   #------------------------------------------------------------------------------
  665.   # New Special Token
  666.   #-----------------------------------------------------------------------------
  667.   def new_special_token(stars, token_id)
  668.     @grid_monsters[@grid_monsters.size] = GridMonster.new(1, token_id)
  669.   end
  670.  
  671.   #-----------------------------------------------------------------------------
  672.   # New Token
  673.   #-----------------------------------------------------------------------------
  674.   def add_token(stars)
  675.     @grid_monsters[@grid_monsters.size] = GridMonster.new(stars)
  676.   end
  677.  
  678.   #-----------------------------------------------------------------------------
  679.   # New Token Pack
  680.   #-----------------------------------------------------------------------------
  681.   def new_token_pack(token_count, stars)
  682.     gmi = @grid_monsters.size
  683.     for i in 0...token_count
  684.       @grid_monsters[gmi] = GridMonster.new(stars)
  685.       gmi += 1
  686.     end
  687.   end
  688.  
  689.   #-----------------------------------------------------------------------------
  690.   # Renumerate Tokens
  691.   #-----------------------------------------------------------------------------
  692.   def renumerate_tokens
  693.     new_monsters = {}
  694.     i = 0
  695.     @grid_monsters.each { |index, monster|
  696.     next if monster.nil?
  697.     new_monsters[i] = monster
  698.     i += 1
  699.     }
  700.     @grid_monsters = new_monsters
  701.   end
  702.  
  703. end
  704.  
  705. ################################################################################
  706. #                            GRID MONSTERS
  707. ################################################################################
  708. class GridMonster
  709.  
  710.   attr_reader :name
  711.   attr_reader :grid_id
  712.   attr_reader :icon_id
  713.   attr_accessor :atk
  714.   attr_accessor :def
  715.   attr_accessor :acc
  716.   attr_accessor :ddg
  717.   attr_accessor :attacking
  718.   attr_accessor :defending
  719.   attr_accessor :dodging
  720.   attr_accessor :set
  721.   attr_reader :stars
  722.   attr_accessor :target
  723.   attr_accessor :boost
  724.  
  725.   #-----------------------------------------------------------------------------
  726.   #    Initialize
  727.   #-----------------------------------------------------------------------------
  728.   def initialize(stars = 1, monster_id = nil)
  729.     @stars = stars
  730.     if monster_id.nil?
  731.       @name = generated_monster_name
  732.       @icon_id = generated_monster_icon
  733.       @atk = rand(@stars * 2) + 1
  734.       @def = rand(@stars * 2) + 1
  735.       @acc = rand(@stars * 2) + 1
  736.       @ddg = rand(@stars * 2) + 1
  737.     else
  738.       monsters = Ixfuru::GridWars::MONSTERS
  739.       @name = monsters[monster_id][:name]
  740.       @icon_id = monsters[monster_id][:icon_id]
  741.       @atk = monsters[monster_id][:atk]
  742.       @def = monsters[monster_id][:def]
  743.       @acc = monsters[monster_id][:accuracy]
  744.       @ddg = monsters[monster_id][:dodge]
  745.     end
  746.     @grid_id = generated_grid_id
  747.     @value = generated_monster_value
  748.     reset
  749.     save_monster
  750.   end
  751.    
  752.   #-----------------------------------------------------------------------------
  753.   # Save Monster
  754.   #-----------------------------------------------------------------------------
  755.   def save_monster
  756.     $game_system.grid_monsters[@grid_id] = self
  757.   end
  758.  
  759.   #-----------------------------------------------------------------------------
  760.   # Reset
  761.   #-----------------------------------------------------------------------------
  762.   def reset
  763.     @attacking = false
  764.     @dodging = false
  765.     @defending = false
  766.     @set = false
  767.     @target = nil
  768.     @boost = 0
  769.   end
  770.  
  771.   #-----------------------------------------------------------------------------
  772.   # Generated Monster Value
  773.   #-----------------------------------------------------------------------------
  774.   def generated_monster_value
  775.     n = @atk + @def + acc + ddg
  776.     return (n / 4) * Ixfuru::GridWars::BASE_VALUE
  777.   end
  778.  
  779.   #-----------------------------------------------------------------------------
  780.   # Generated Grid ID
  781.   #-----------------------------------------------------------------------------
  782.   def generated_grid_id
  783.     return $game_system.grid_monsters.size
  784.   end
  785.  
  786.   #-----------------------------------------------------------------------------
  787.   # Generated Monster Icon
  788.   #-----------------------------------------------------------------------------
  789.   def generated_monster_icon
  790.     icons = Ixfuru::GridWars::RANDOM_MONSTERS[:icon_pool]
  791.     return icons[rand(icons.size)]
  792.   end
  793.  
  794.   #-----------------------------------------------------------------------------
  795.   # Generated Monster Name
  796.   #-----------------------------------------------------------------------------
  797.   def generated_monster_name
  798.     parts = rand(5) + 1
  799.     firsts = Ixfuru::GridWars::RANDOM_MONSTERS[:first_letters]
  800.     vowels = Ixfuru::GridWars::RANDOM_MONSTERS[:vowels]
  801.     vowel_groupings = Ixfuru::GridWars::RANDOM_MONSTERS[:vowel_groupings]
  802.     groups = Ixfuru::GridWars::RANDOM_MONSTERS[:const_groupings]
  803.     fl = firsts[rand(firsts.size)]
  804.     if vowels.include?(fl.downcase)
  805.       g = rand(2)
  806.       case g
  807.       when 0
  808.         sl = firsts[rand(firsts.size)] + vowels[rand(vowels.size)]
  809.       when 1
  810.         sl = groups[rand(groups.size)] + vowels[rand(vowels.size)]
  811.       end
  812.     else
  813.       vg = rand(12)
  814.       if vg <= 10
  815.         sl = vowels[rand(vowels.size)]
  816.       else
  817.         sl = vowel_groupings[rand(vowel_groupings.size)]
  818.       end
  819.     end
  820.     ending = []
  821.     for i in 0...parts
  822.       case i
  823.       when 0, 2
  824.         vg = rand(12)
  825.         if vg <= 10
  826.           ending.push(vowels[rand(vowels.size)])
  827.         else
  828.           ending.push(vowel_groupings[rand(vowel_groupings.size)])
  829.         end
  830.       when 1, 3, 4
  831.         g = rand(2)
  832.         case g
  833.         when 0
  834.           ending.push(firsts[rand(firsts.size)].downcase)
  835.         when 1
  836.           ending.push(groups[rand(groups.size)])
  837.         end
  838.       end
  839.     end
  840.     n = fl + sl + ending.to_s
  841.     return n
  842.   end
  843.  
  844. end
  845.  
  846. ################################################################################
  847. #                         WINDOW MONSTER PREVIEW
  848. ################################################################################
  849. class Window_GW_MonsterPreview < Window_Base
  850.  
  851.   attr_accessor :monster
  852.  
  853.   def initialize(monster)
  854.     super(180, 273, 184, 144)
  855.     @monster = monster
  856.     refresh
  857.     self.visible = false
  858.     self.z = 160
  859.   end
  860.  
  861.   def refresh
  862.     self.contents.clear
  863.     return if @monster.nil?
  864.     self.contents.font.size = 20
  865.     self.contents.font.color = power_up_color
  866.     self.contents.draw_text(0, 0, self.width - 32, WLH, @monster.name, 1)
  867.     draw_icon(@monster.icon_id, 56, WLH)
  868.     self.contents.font.size = 12
  869.     lh = 16
  870.     self.contents.font.color = system_color
  871.     tags = ["ATK", "DEF", "ACC", "DDG"]
  872.     ly = WLH * 2
  873.     for tag in tags
  874.       self.contents.draw_text(30, ly, self.width - 32, lh, tag)
  875.       ly += lh
  876.     end
  877.     self.contents.font.color = normal_color
  878.     pars = [@monster.atk, @monster.def, @monster.acc, @monster.ddg]
  879.     ly = WLH * 2
  880.     for par in pars
  881.       self.contents.draw_text(90, ly, self.width - 32, lh, par.to_s)
  882.       ly += lh
  883.     end
  884.   end
  885.  
  886. end
  887.  
  888. ################################################################################
  889. #                                  WINDOW MONSTER LIST
  890. ################################################################################
  891. class Window_GW_MonsterList < Window_Selectable
  892.  
  893.   attr_accessor :monsters
  894.  
  895.   def initialize(owner_id)
  896.     if owner_id == 0
  897.       @owner = $game_player
  898.       super(0, 56, 180, 304)
  899.     elsif owner_id.nil?
  900.       super(364, 56, 180, 304)
  901.       @owner = nil
  902.     elsif owner_id > 0
  903.       @owner = $game_map.events[owner_id]
  904.       super(364, 56, 180, 304)
  905.     end
  906.     refresh
  907.     self.index = 0
  908.     self.active = false
  909.   end
  910.  
  911.   def refresh
  912.     if !@owner.nil?
  913.       @monsters = @owner.grid_monsters
  914.     else
  915.       @monsters = $game_player.quick_tokens
  916.     end
  917.     @item_max = @monsters.size
  918.     create_contents
  919.     return if @item_max == 0
  920.     for i in 0...@item_max
  921.       next if @monsters[i].nil?
  922.       draw_monster(i)
  923.     end
  924.   end
  925.  
  926.   def enabled?(index)
  927.     return true if @owner.nil?
  928.     return false if @owner.grid_monsters[index].set
  929.     return true
  930.   end
  931.  
  932.   def draw_monster(index)
  933.     rect = item_rect(index)
  934.     if !@owner.nil?
  935.       draw_icon(@owner.grid_monsters[index].icon_id, rect.x, rect.y, enabled?(index))
  936.       self.contents.font.color.alpha = enabled?(index) ? 255 : 128
  937.       self.contents.draw_text(rect.x + 26, rect.y, self.width - 32, WLH,
  938.       @owner.grid_monsters[index].name)
  939.       if @owner.is_a?(Game_Player) &&
  940.        $game_player.quick_tokens.has_value?(@owner.grid_monsters[index])
  941.         fc = Ixfuru::GridWars::QUICKSET_COLOR
  942.         self.contents.fill_rect((self.width - 32) - 12, rect.y, 12, 12, text_color(fc))
  943.       end
  944.     else
  945.       draw_icon($game_player.quick_tokens[index].icon_id, rect.x, rect.y, enabled?(index))
  946.       self.contents.font.color.alpha = enabled?(index) ? 255 : 128
  947.       self.contents.draw_text(rect.x + 26, rect.y, self.width - 32, WLH,
  948.       $game_player.quick_tokens[index].name)
  949.     end
  950.   end
  951.    
  952.  
  953. end
  954.  
  955. ################################################################################
  956. #                          WINDOW SCORE
  957. ################################################################################
  958. class Window_GW_Score < Window_Base
  959.  
  960.   attr_accessor :owner
  961.   attr_accessor :points
  962.  
  963.   def initialize(owner_id = 0)
  964.     case owner_id
  965.     when 0
  966.       super(0, 360, 180, 56)
  967.       @owner = $game_player
  968.     when 1
  969.       super(364, 360, 180, 56)
  970.       @owner = $game_map.events[owner_id]
  971.     end
  972.     @points = 0
  973.     refresh
  974.   end
  975.  
  976.   def refresh
  977.     self.contents.clear
  978.     self.contents.draw_text(0, 0, self.width - 32, WLH, @points.to_s, 1)
  979.   end
  980.  
  981. end
  982.  
  983. ################################################################################
  984. #                           WINDOW FIELD
  985. ################################################################################
  986. class Window_GW_Field < Window_Selectable
  987.  
  988.   attr_accessor :field_monsters
  989.   attr_accessor :target_indices
  990.   # field_monsters : {index = [monster, owner, moved?, x, y]}
  991.  
  992.   def initialize
  993.     super(181, 0, 184, 272)
  994.     @field_monsters = {}
  995.     @target_indices = []
  996.     @item_max = 60
  997.     @column_max = 6
  998.     @spacing = 0
  999.     refresh
  1000.     self.index = 0
  1001.     self.active = false
  1002.   end
  1003.  
  1004.   def refresh
  1005.     create_contents
  1006.     for i in 0...@item_max
  1007.       draw_field_monsters(i)
  1008.     end
  1009.   end
  1010.  
  1011.   def enabled?(index)
  1012.     return false if @field_monsters[index][2]
  1013.     return true
  1014.   end
  1015.  
  1016.   def draw_field_monsters(index)
  1017.     rect = item_rect(index)
  1018.     return if @field_monsters[index].nil?
  1019.     @field_monsters[index][3] = rect.x
  1020.     @field_monsters[index][4] = rect.y
  1021.     monster = @field_monsters[index][0]
  1022.     return if monster.nil?
  1023.     if @field_monsters[index][1].is_a?(Game_Player)
  1024.       fc = Ixfuru::GridWars::PLAYER_FIELD_COLOR
  1025.       self.contents.fill_rect(rect.x + 2, rect. y + 2, rect.width - 4, rect.height - 4, text_color(fc))
  1026.       draw_icon(monster.icon_id, rect.x, rect.y, enabled?(index))
  1027.     else
  1028.       fc = Ixfuru::GridWars::OPPONENT_FIELD_COLOR
  1029.       self.contents.fill_rect(rect.x + 2, rect. y + 2, rect.width - 4, rect.height - 4, text_color(fc))
  1030.       if @field_monsters[index][2]
  1031.         draw_icon(monster.icon_id, rect.x, rect.y, false)
  1032.       else
  1033.         draw_icon(Ixfuru::GridWars::HIDDEN_OPPONENT_ICON_INDEX, rect.x, rect.y)
  1034.       end
  1035.     end
  1036.     self.contents.font.size = 12
  1037.     lh = 16
  1038.     if monster.attacking
  1039.       self.contents.font.color = text_color(10)
  1040.       self.contents.draw_text(rect.x + 12, rect.y, self.width - 32, lh, "A")
  1041.     elsif monster.defending
  1042.       self.contents.font.color = text_color(16)
  1043.       self.contents.draw_text(rect.x + 12, rect.y, self.width - 32, lh, "D")
  1044.     elsif monster.dodging
  1045.       self.contents.font.color = text_color(27)
  1046.       self.contents.draw_text(rect.x + 12, rect.y, self.width - 32, lh, "E")
  1047.     end
  1048.     if @target_indices.include?(index)
  1049.       tc = text_color(Ixfuru::GridWars::TARGET_COLOR)
  1050.       self.contents.fill_rect(rect.x + 6, rect.y + 6, 12, 12, tc)
  1051.     end
  1052.     self.contents.font.color = normal_color
  1053.   end
  1054.  
  1055. end
  1056.  
  1057. ################################################################################
  1058. #                          WINDOW TOKEN COMMANDS
  1059. ################################################################################
  1060. class Window_GW_TokenCommands < Window_Selectable
  1061.  
  1062.   def initialize
  1063.     super(180, 273, 184, 144)
  1064.     @commands = ["ATTACK", "DEFEND", "DODGE"]
  1065.     @item_max = 3
  1066.     refresh
  1067.     self.visible = false
  1068.     self.active = false
  1069.     self.index = 0
  1070.   end
  1071.  
  1072.   def refresh
  1073.     create_contents
  1074.     for i in 0...@item_max
  1075.       draw_command(i)
  1076.     end
  1077.   end
  1078.  
  1079.   def draw_command(index)
  1080.     rect = item_rect(index)
  1081.     self.contents.draw_text(rect, @commands[index], 1)
  1082.   end
  1083.  
  1084. end
  1085.  
  1086. ################################################################################
  1087. #                        WINDOW TOKEN COUNT
  1088. ################################################################################
  1089. class Window_GW_TokenCount < Window_Base
  1090.  
  1091.   attr_accessor :required_amount
  1092.  
  1093.   def initialize
  1094.     super(180, 273, 184, 144)
  1095.     @required_amount = 30
  1096.     refresh
  1097.   end
  1098.  
  1099.   def refresh
  1100.     self.contents.clear
  1101.     self.contents.draw_text(0, 0, self.width - 32, WLH, "Select " + required_amount.to_s + " more tokens.")
  1102.   end
  1103.  
  1104.  
  1105. end
  1106.  
  1107. ################################################################################
  1108. #                      WINDOW SIMULATION
  1109. ################################################################################
  1110. class Window_GW_Simulation < Window_Base
  1111.  
  1112.   attr_accessor :monster
  1113.   attr_accessor :action
  1114.  
  1115.   def initialize
  1116.     super(180, 273, 184, 144)
  1117.     @monster = nil
  1118.     @action = 0 # 0 for attack, 1 for defend, 2 for dodge
  1119.     refresh
  1120.     self.visible = false
  1121.   end
  1122.  
  1123.   def refresh
  1124.     self.contents.clear
  1125.     return if @monster.nil?
  1126.     draw_icon(@monster[0].icon_id, 0, 0)
  1127.     case @action
  1128.     when 0
  1129.       act_string = "attacking"
  1130.     when 1
  1131.       act_string = "defending"
  1132.     when 2
  1133.       act_string = "dodging"
  1134.     end
  1135.     lines = [@monster[0].name, "is", act_string]
  1136.     ly = 0
  1137.     for i in 0...lines.size
  1138.       self.contents.draw_text(26,ly, self.width - 32, WLH, lines[i], 1)
  1139.       ly += WLH
  1140.     end
  1141.   end
  1142.    
  1143.    
  1144. end
  1145.  
  1146. ################################################################################
  1147. #                                 WINDOW RESULTS
  1148. ################################################################################
  1149. class Window_GW_Results < Window_Base
  1150.  
  1151.   attr_accessor :string
  1152.  
  1153.   def initialize
  1154.     super(180, 273, 184, 144)
  1155.     @string = []
  1156.     refresh
  1157.     self.visible = false
  1158.   end
  1159.  
  1160.   def refresh
  1161.     self.contents.clear
  1162.     ly = 0
  1163.     lh = 20
  1164.     self.contents.font.size = 16
  1165.     for str in @string
  1166.       self.contents.draw_text(0, ly, self.width - 32, lh, str, 1)
  1167.       ly += lh
  1168.     end
  1169.   end
  1170.  
  1171. end
  1172.  
  1173. ################################################################################
  1174. #                              WINDOW COMPETITOR
  1175. ################################################################################
  1176. class Window_GW_Competitor < Window_Base
  1177.  
  1178.   attr_accessor :competitor
  1179.  
  1180.   def initialize(player = true, opponent_id = nil)
  1181.     if player
  1182.       super(0, 0, 180, 56)
  1183.       @competitor = $game_player
  1184.     else
  1185.       super(364, 0, 180, 56)
  1186.       @competitor = $game_map.events[opponent_id]
  1187.     end
  1188.     refresh
  1189.   end
  1190.  
  1191.   def refresh
  1192.     self.contents.clear
  1193.     draw_character(@competitor.character_name, @competitor.character_index, 16, 32)
  1194.     self.contents.draw_text(0, 0, self.width - 32, WLH, @competitor.grid_name, 2)
  1195.   end
  1196.  
  1197. end
  1198.    
  1199.    
  1200. ################################################################################
  1201. #                        SCENE GRID WARS
  1202. ################################################################################
  1203. class Scene_GridWars < Scene_Base
  1204.  
  1205.   #-----------------------------------------------------------------------------
  1206.   # Initialize
  1207.   #-----------------------------------------------------------------------------
  1208.   def initialize(opponent_id, player_first = true)
  1209.     bgm = Ixfuru::GridWars::GWBGM
  1210.     RPG::BGM.new(bgm[0], bgm[1], bgm[2]).play
  1211.     @opponent_id = opponent_id
  1212.     @opponent = $game_map.events[opponent_id]
  1213.     @opponent.get_grid_monsters
  1214.     reset_monsters
  1215.     @turn = player_first ? 0 : 1
  1216.     @phase = 0
  1217.     @presetting = true
  1218.     @setting = false
  1219.     @finish_match = false
  1220.     @winner = nil
  1221.     @wait_count = Ixfuru::GridWars::WAIT_COUNT
  1222.     @active_monster = nil
  1223.     @active_index = 0
  1224.     @targetting = false
  1225.     @simulation = false
  1226.     @sim_count = 0
  1227.     @take_count = 0
  1228.     @match_end = false
  1229.   end
  1230.  
  1231.   #-----------------------------------------------------------------------------
  1232.   # Start
  1233.   #-----------------------------------------------------------------------------
  1234.   def start
  1235.     super
  1236.     create_menu_background
  1237.     @win_plyr = Window_GW_Competitor.new
  1238.     @win_opp = Window_GW_Competitor.new(false, @opponent_id)
  1239.     @win_plyr_monsters = Window_GW_MonsterList.new(0)
  1240.     @win_opp_monsters = Window_GW_MonsterList.new(@opponent_id)
  1241.     @win_plyr_score = Window_GW_Score.new(0)
  1242.     @win_opp_score = Window_GW_Score.new(1)
  1243.     @win_field = Window_GW_Field.new
  1244.     @win_commands = Window_GW_TokenCommands.new
  1245.     @win_token_count = Window_GW_TokenCount.new
  1246.     @win_preview = Window_GW_MonsterPreview.new(nil)
  1247.     @win_simulation = Window_GW_Simulation.new
  1248.     @win_result = Window_GW_Results.new
  1249.     create_anisprite
  1250.   end
  1251.  
  1252.   #-----------------------------------------------------------------------------
  1253.   # Reset Monsters
  1254.   #------------------------------------------------------------------------------
  1255.   def reset_monsters
  1256.     $game_player.grid_monsters.each { |index, monster|
  1257.     monster.reset
  1258.     }
  1259.     @opponent.grid_monsters.each { |index, monster|
  1260.     monster.reset
  1261.     }
  1262.   end
  1263.  
  1264.   #-----------------------------------------------------------------------------
  1265.   # Create Anisprite
  1266.   #-----------------------------------------------------------------------------
  1267.   def create_anisprite
  1268.     @viewport = Viewport.new(0, 0, 544, 416)
  1269.     @viewport.z = 160
  1270.     @anisprite = Sprite_Base.new(@viewport)
  1271.   end
  1272.  
  1273.   #-----------------------------------------------------------------------------
  1274.   # Set Anisprite Location
  1275.   #-----------------------------------------------------------------------------
  1276.   def set_anisprite_location(x, y)
  1277.     @anisprite.x = @win_field.x + x
  1278.     @anisprite.y = @win_field.y + y
  1279.   end
  1280.  
  1281.   #-----------------------------------------------------------------------------
  1282.   # Update
  1283.   #-----------------------------------------------------------------------------
  1284.   def update
  1285.     super
  1286.     if @win_result.visible
  1287.       update_result
  1288.     elsif @win_preview.visible
  1289.       update_preview
  1290.     elsif @match_end
  1291.       if @winner.is_a?(Game_Player)
  1292.         $game_system.last_grid_result = 0
  1293.       elsif @winner.is_a?(Game_Event)
  1294.         $game_system.last_grid_result = 1
  1295.       else
  1296.         $game_system.last_grid_result = 2
  1297.       end
  1298.       $game_player.renumerate_tokens
  1299.       @opponent.renumerate_tokens
  1300.       $scene = Scene_Map.new
  1301.     elsif @taking
  1302.       update_taking
  1303.     elsif @presetting
  1304.       update_presetting
  1305.     elsif @setting
  1306.       update_setting
  1307.     elsif @finish_match
  1308.       update_finishing
  1309.     elsif @animating
  1310.       update_animating
  1311.     elsif @simulating
  1312.       update_simulation
  1313.     else
  1314.       update_turn
  1315.     end
  1316.   end
  1317.  
  1318.   #-----------------------------------------------------------------------------
  1319.   # Jumbled
  1320.   #-----------------------------------------------------------------------------
  1321.   def jumbled(ary)
  1322.     return unless ary.is_a?(Array)
  1323.     new_ary = []
  1324.     until ary.empty?
  1325.       n = ary[rand(ary.size)]
  1326.       new_ary.push(n)
  1327.       ary.delete(n)
  1328.     end
  1329.     return new_ary
  1330.   end
  1331.  
  1332.   #-----------------------------------------------------------------------------
  1333.   # Update Setting
  1334.   #-----------------------------------------------------------------------------
  1335.   def update_setting
  1336.     sz = 60
  1337.     fpool = []
  1338.     for i in 0...sz
  1339.       fpool.push(i)
  1340.     end
  1341.     fpool = jumbled(fpool)
  1342.     ptokens = []
  1343.     $game_player.grid_monsters.each { |index, monster|
  1344.     if monster.set
  1345.       ptokens.push(monster)
  1346.     end
  1347.     }
  1348.     otokens = []
  1349.     @opponent.grid_monsters.each { |index, monster|
  1350.     if monster.set
  1351.       otokens.push(monster)
  1352.     end
  1353.     }
  1354.     pool_id = 0
  1355.     for f in fpool
  1356.       case pool_id
  1357.       when 0 # Set Players Token
  1358.         token = ptokens[rand(ptokens.size)]
  1359.         @win_field.field_monsters[f] = [token, $game_player, false]
  1360.         ptokens.delete(@win_field.field_monsters[f][0])
  1361.         pool_id = 1
  1362.       when 1 # Set Opponents Token
  1363.         token = otokens[rand(otokens.size)]
  1364.         @win_field.field_monsters[f] = [token, @opponent, false]
  1365.         otokens.delete(@win_field.field_monsters[f][0])
  1366.         pool_id = 0
  1367.       end
  1368.       @win_field.refresh
  1369.     end
  1370.     @setting = false
  1371.     @win_field.active = true
  1372.     update_scores
  1373.   end
  1374.  
  1375.   #-----------------------------------------------------------------------------
  1376.   # Update Scores
  1377.   #-----------------------------------------------------------------------------
  1378.   def update_scores
  1379.     ps = 0
  1380.     os = 0
  1381.     for i in 0...60
  1382.       if @win_field.field_monsters[i][1].is_a?(Game_Player)
  1383.         ps += 1
  1384.       else
  1385.         os += 1
  1386.       end
  1387.     end
  1388.     @win_plyr_score.points = ps
  1389.     @win_opp_score.points = os
  1390.     @win_plyr_score.refresh
  1391.     @win_opp_score.refresh
  1392.   end
  1393.  
  1394.   #-----------------------------------------------------------------------------
  1395.   # Update Presetting
  1396.   #-----------------------------------------------------------------------------
  1397.   def update_presetting
  1398.     case @turn
  1399.     when 0 # Player's
  1400.       @win_plyr_monsters.active = true
  1401.       @win_plyr_monsters.update
  1402.       if Input.trigger?(Input::C)
  1403.         monster = @win_plyr_monsters.monsters[@win_plyr_monsters.index]
  1404.         if monster.set
  1405.           Sound.play_decision
  1406.           @win_token_count.required_amount += 1
  1407.           monster.set = false
  1408.         else
  1409.           play_grid_sound(:selection)
  1410.           @win_token_count.required_amount -= 1
  1411.           monster.set = true
  1412.         end
  1413.         @win_plyr_monsters.refresh
  1414.         @win_token_count.refresh
  1415.       elsif Input.trigger?(Input::B)
  1416.         Sound.play_cancel
  1417.         $scene = Scene_Map.new
  1418.       elsif Input.trigger?(Input::Y)
  1419.         Sound.play_decision
  1420.         @win_preview.monster = @win_plyr_monsters.monsters[@win_plyr_monsters.index]
  1421.         @win_preview.refresh
  1422.         @win_preview.visible = true
  1423.       elsif Input.trigger?(Input::X)
  1424.         if $game_player.quick_tokens.empty?
  1425.           Sound.play_buzzer
  1426.         elsif $game_player.quick_tokens.size < 30
  1427.           Sound.play_buzzer
  1428.         else
  1429.           play_grid_sound(:quickset)
  1430.           $game_player.grid_monsters.each { |index, monster|
  1431.           monster.reset
  1432.           }
  1433.           @win_plyr_monsters.refresh
  1434.           add_quickset
  1435.         end
  1436.       end
  1437.       if @win_token_count.required_amount <= 0
  1438.         @win_plyr_monsters.active = false
  1439.         @win_token_count.visible = false
  1440.         @turn = 1
  1441.       end
  1442.     when 1 # Opponent
  1443.       update_opponent_presetting
  1444.     end
  1445.   end
  1446.  
  1447.   #-----------------------------------------------------------------------------
  1448.   # Quick Select Token
  1449.   #-----------------------------------------------------------------------------
  1450.   def quick_select_token
  1451.     moveables = []
  1452.     @win_field.field_monsters.each { |index, monster|
  1453.     if monster[1].is_a?(Game_Player) && !monster[2]
  1454.       moveables.push([index, monster])
  1455.     end
  1456.     }
  1457.     m = moveables[rand(moveables.size)]
  1458.     return m
  1459.   end
  1460.  
  1461.  
  1462.   #-----------------------------------------------------------------------------
  1463.   # Add QuickSet
  1464.   #-----------------------------------------------------------------------------
  1465.   def add_quickset
  1466.     $game_player.quick_tokens.each { |index, monster|
  1467.     Sound.play_cursor
  1468.     $game_player.grid_monsters[$game_player.grid_monsters.index(monster)].set = true
  1469.     @win_token_count.required_amount -= 1
  1470.     @win_token_count.refresh
  1471.     }
  1472.     @win_plyr_monsters.refresh
  1473.   end
  1474.  
  1475.   #-----------------------------------------------------------------------------
  1476.   # Update Opponent Presetting
  1477.   #-----------------------------------------------------------------------------
  1478.   def update_opponent_presetting
  1479.     update_waiting
  1480.     return if @wait_count > 0
  1481.     set_otokens = 0
  1482.     until set_otokens == 30
  1483.       rm = rand(@win_opp_monsters.monsters.size)
  1484.       unless @win_opp_monsters.monsters[rm].set
  1485.         @win_opp_monsters.monsters[rm].set = true
  1486.         set_otokens += 1
  1487.       end
  1488.     end
  1489.     @turn = 0
  1490.     @setting = true
  1491.     @win_opp_monsters.refresh
  1492.     @wait_count = Ixfuru::GridWars::WAIT_COUNT
  1493.     @presetting = false
  1494.   end
  1495.  
  1496.   #-----------------------------------------------------------------------------
  1497.   # Update Simulating
  1498.   #-----------------------------------------------------------------------------
  1499.   def update_simulation
  1500.     update_scores
  1501.     @wait_count -= 1
  1502.     return if @wait_count > 0
  1503.     @win_field.index = @sim_count
  1504.     monster = @win_field.field_monsters[@sim_count]
  1505.     if monster[0].target != nil
  1506.       set_anisprite_location(@win_field.cursor_rect.x, @win_field.cursor_rect.y)
  1507.       @anisprite.start_animation($data_animations[Ixfuru::GridWars::ATTACK_ANIMATION])
  1508.       @animating = true
  1509.       retrieve_result(monster, @win_field.field_monsters[monster[0].target])
  1510.       @wait_count = 5
  1511.     else
  1512.       @wait_count = 5
  1513.       @win_field.refresh
  1514.       @sim_count += 1
  1515.       if @sim_count == 60
  1516.         @finish_match = true
  1517.         @simulating = false
  1518.       end
  1519.     end
  1520.   end
  1521.  
  1522.   #-----------------------------------------------------------------------------
  1523.   # Retrieve Result
  1524.   #-----------------------------------------------------------------------------
  1525.   def retrieve_result(attacker, target)
  1526.     atk = attacker[0].atk + attacker[0].boost
  1527.     dfd = target[0].def + target[0].boost
  1528.     acc = attacker[0].acc + attacker[0].boost
  1529.     ddg = target[0].ddg + target[0].ddg
  1530.     dfd += 1 if target[0].defending
  1531.     ddg += 1 if target[0].dodging
  1532.     atk_hit = rand(acc)
  1533.     dfd_evd = rand(ddg)
  1534.     if atk_hit >= dfd_evd
  1535.       if atk >= dfd
  1536.         play_grid_sound(:attacking)
  1537.         @win_field.field_monsters[attacker[0].target][1] = attacker[1]
  1538.       else
  1539.         play_grid_sound(:defending)
  1540.         attacker[1] = target[1]
  1541.       end
  1542.     else
  1543.       if target[0].dodging
  1544.         play_grid_sound(:dodging)
  1545.         attacker[1] = target[1]
  1546.       else
  1547.         play_grid_sound(:missing)
  1548.       end
  1549.     end
  1550.     @win_field.refresh
  1551.     update_scores
  1552.     @sim_count += 1
  1553.     if @sim_count >= 60
  1554.       @finish_match = true
  1555.       @simulating = false
  1556.     end
  1557.   end
  1558.  
  1559.   #-----------------------------------------------------------------------------
  1560.   # Result String Width
  1561.   #-----------------------------------------------------------------------------
  1562.   def result_string_width(string)
  1563.     return @win_result.contents.text_size(string).width
  1564.   end
  1565.  
  1566.   #-----------------------------------------------------------------------------
  1567.   # Show Result
  1568.   #-----------------------------------------------------------------------------
  1569.   def show_result(string_array)
  1570.     @win_result.string.clear
  1571.     for i in string_array
  1572.       @win_result.string.push(i)
  1573.     end
  1574.     @win_result.refresh
  1575.     @win_result.visible = true
  1576.   end
  1577.  
  1578.   #-----------------------------------------------------------------------------
  1579.   # Update Result
  1580.   #-----------------------------------------------------------------------------
  1581.   def update_result
  1582.     if Input.trigger?(Input::C) || Input.trigger?(Input::B)
  1583.       Sound.play_cancel
  1584.       unless @finish_match
  1585.         @sim_count += 1
  1586.         if @sim_count == 60
  1587.           @finish_match = true
  1588.           @simulating = false
  1589.         end
  1590.       end
  1591.       @win_result.visible = false
  1592.     end
  1593.     @win_field.refresh
  1594.     update_scores
  1595.   end
  1596.  
  1597.   #-----------------------------------------------------------------------------
  1598.   # Update Taking
  1599.   #-----------------------------------------------------------------------------
  1600.   def update_taking
  1601.     if @winner.is_a?(Game_Player)
  1602.       @win_opp_monsters.update
  1603.       if Input.trigger?(Input::C)
  1604.         if @win_opp_monsters.enabled?(@win_opp_monsters.index)
  1605.           play_grid_sound(:selection)
  1606.           token_points = @win_plyr_score.points - @win_opp_score.points
  1607.           lost_token = @win_opp_monsters.monsters[@win_opp_monsters.index]
  1608.           new_token = Marshal.load(Marshal.dump(@win_opp_monsters.monsters[@win_opp_monsters.index]))
  1609.           $game_player.grid_monsters[$game_player.grid_monsters.size] = new_token
  1610.           $game_player.token_points += token_points
  1611.           @opponent.grid_monsters.delete(lost_token)
  1612.           show_result([$game_party.members[0].name, "was victorious!", lost_token.name,
  1613.           "token was received!"])
  1614.           @win_opp_monsters.active = false
  1615.           @match_end = true
  1616.         else
  1617.           Sound.play_buzzer
  1618.         end
  1619.       elsif Input.trigger?(Input::Y)
  1620.         monster = @win_opp_monsters.monsters[@win_opp_monsters.index]
  1621.         @win_preview.monster = monster
  1622.         @win_preview.refresh
  1623.         @win_preview.visible = true
  1624.       end
  1625.     else
  1626.       @take_count -= 1
  1627.       Sound.play_cursor
  1628.       new_index = @win_plyr_monsters.index + 1
  1629.       if new_index >= @win_plyr_monsters.monsters.size
  1630.         new_index = 0
  1631.       end
  1632.       @win_plyr_monsters.index = new_index
  1633.       if @take_count <= 0
  1634.         if @win_plyr_monsters.enabled?(@win_plyr_monsters.index)
  1635.           lost_token = @win_plyr_monsters.monsters[@win_plyr_monsters.index]
  1636.           new_token = Marshal.load(Marshal.dump(@win_plyr_monsters.monsters[@win_plyr_monsters.index]))
  1637.           @opponent.grid_monsters[@opponent.grid_monsters.size] = new_token
  1638.           $game_player.grid_monsters.delete(lost_token)
  1639.           show_result([$game_party.members[0].name, "was defeated!", lost_token.name,
  1640.           "token was lost!"])
  1641.           @match_end = true
  1642.         end
  1643.       end
  1644.     end
  1645.   end
  1646.    
  1647.   #-----------------------------------------------------------------------------
  1648.   # Update Finishing
  1649.   #-----------------------------------------------------------------------------
  1650.   def update_finishing
  1651.     update_scores
  1652.     @winner = player_with_highest_score
  1653.     @win_result.visible = false
  1654.     if @winner.is_a?(Game_Player)
  1655.       play_grid_music(:victory)
  1656.       @taking = true
  1657.       @win_opp_monsters.active = true
  1658.     elsif @winner.is_a?(Game_Event)
  1659.       play_grid_music(:defeat)
  1660.       @taking = true
  1661.       @take_count = ($game_player.grid_monsters.size * rand(4)) +
  1662.        rand($game_player.grid_monsters.size)
  1663.     else
  1664.       play_grid_music(:tie)
  1665.       show_result("The Match was a tie!")
  1666.       @taking = true
  1667.       @match_end = true
  1668.     end
  1669.   end
  1670.  
  1671.   #------------------------------------------------------------------------------
  1672.   # Play Grid Music
  1673.   #-----------------------------------------------------------------------------
  1674.   def play_grid_music(music_name)
  1675.     me = Ixfuru::GridWars::MUSICS[music_name]
  1676.     RPG::ME.new(me[0], me[1], me[2]).play
  1677.   end
  1678.  
  1679.   #-----------------------------------------------------------------------------
  1680.   # Player With Highest Score
  1681.   #-----------------------------------------------------------------------------
  1682.   def player_with_highest_score
  1683.     if @win_plyr_score.points > @win_opp_score.points
  1684.       win = $game_player
  1685.     elsif @win_opp_score.points > @win_plyr_score.points
  1686.       win = @opponent
  1687.     else
  1688.       win = nil
  1689.     end
  1690.     return win
  1691.   end    
  1692.  
  1693.   #-----------------------------------------------------------------------------
  1694.   # Update Waiting
  1695.   #-----------------------------------------------------------------------------
  1696.   def update_waiting
  1697.     return if @turn == 0
  1698.     @wait_count -= 1
  1699.     if @wait_count <= 0
  1700.       @wait_count = 0
  1701.     end
  1702.   end
  1703.  
  1704.   #-----------------------------------------------------------------------------
  1705.   # Update Animating
  1706.   #-----------------------------------------------------------------------------
  1707.   def update_animating
  1708.     if @anisprite.animation?
  1709.       @anisprite.update
  1710.       @animating = true
  1711.     else
  1712.       @animating = false
  1713.     end
  1714.   end
  1715.  
  1716.   #-----------------------------------------------------------------------------
  1717.   # Update Preview
  1718.   #-----------------------------------------------------------------------------
  1719.   def update_preview
  1720.     if Input.trigger?(Input::C) || Input.trigger?(Input::B)
  1721.       Sound.play_cancel
  1722.       @win_preview.visible = false
  1723.     end
  1724.   end
  1725.  
  1726.   #-----------------------------------------------------------------------------
  1727.   # Update Turn
  1728.   #-----------------------------------------------------------------------------
  1729.   def update_turn
  1730.     update_waiting
  1731.     case @phase
  1732.     when 0 # Choose token
  1733.       update_token_selection
  1734.     when 1 # Choose Command
  1735.       update_commands
  1736.     when 2 # Choose Target
  1737.       update_targetting
  1738.     when 3 # Finish Up Turn
  1739.       update_end_turn
  1740.     end
  1741.   end
  1742.  
  1743.   #-----------------------------------------------------------------------------
  1744.   # Battle Ready?
  1745.   #------------------------------------------------------------------------------
  1746.   def battle_ready?
  1747.     for i in 0...60
  1748.       return false if !@win_field.field_monsters[i][2] # A monster hasn't moved
  1749.     end
  1750.     return true
  1751.   end
  1752.  
  1753.   #-----------------------------------------------------------------------------
  1754.   # Update End Turn
  1755.   #-----------------------------------------------------------------------------
  1756.   def update_end_turn
  1757.     @win_field.field_monsters[@active_index][2] = true
  1758.     @win_field.target_indices = []
  1759.     @win_field.refresh
  1760.     if battle_ready?
  1761.       set_boosts
  1762.       @simulating = true
  1763.     else
  1764.       case @turn
  1765.       when 0 # Player's
  1766.         @phase = 0
  1767.         @turn = 1
  1768.       when 1 # Opponent's
  1769.         @phase = 0
  1770.         @turn = 0
  1771.         @win_field.active = true
  1772.       end
  1773.     end
  1774.   end
  1775.  
  1776.   #-----------------------------------------------------------------------------
  1777.   # Update Token Selection
  1778.   #-----------------------------------------------------------------------------
  1779.   def update_token_selection
  1780.     case @turn
  1781.     when 0 # Player's
  1782.       @win_field.update
  1783. #~       m = moveables
  1784.       if Input.trigger?(Input::C)
  1785.         monster = @win_field.field_monsters[@win_field.index]
  1786.         if monster[1].is_a?(Game_Player) && !monster[2] #Player's monster and hasn't moved
  1787.           play_grid_sound(:selection)
  1788.           @active_monster = monster[0]
  1789.           @active_index = @win_field.index
  1790.           @phase = 1
  1791.           @win_field.active = false
  1792.           @win_commands.index = 0
  1793.           @win_commands.visible = true
  1794.           @win_commands.active = true
  1795.           @win_field.active = false
  1796.         else
  1797.           Sound.play_buzzer
  1798.         end
  1799.       elsif Input.trigger?(Input::Y)
  1800.         monster = @win_field.field_monsters[@win_field.index]
  1801.         if monster[1].is_a?(Game_Player) || monster[2]
  1802.           @win_preview.monster = monster[0]
  1803.           @win_preview.refresh
  1804.           @win_preview.visible = true
  1805.         else
  1806.           Sound.play_buzzer
  1807.         end
  1808.       end
  1809.     when 1 # Opponent's
  1810.       return if @wait_count > 0
  1811.       monster = random_selected_monster
  1812.       play_grid_sound(:selection)
  1813.       @win_field.index = monster[0]
  1814.       @active_monster = monster[1][0]
  1815.       @active_index = @win_field.index
  1816.       @win_commands.index = 0
  1817. #~       @win_commands.visible = true
  1818.       @wait_count = Ixfuru::GridWars::WAIT_COUNT
  1819.       @phase = 1
  1820.     end
  1821.   end
  1822.  
  1823.   #-----------------------------------------------------------------------------0
  1824.   # Random Selected Monster
  1825.   #-----------------------------------------------------------------------------
  1826.   def random_selected_monster
  1827.     moveables = []
  1828.     @win_field.field_monsters.each { |index, monster|
  1829.     if monster[1].is_a?(Game_Event) && !monster[2]
  1830.       moveables.push([index, monster])
  1831.     end
  1832.     }
  1833.     m = moveables[rand(moveables.size)]
  1834.     return m
  1835.   end
  1836.  
  1837.   #-----------------------------------------------------------------------------
  1838.   # Play Grid Sound
  1839.   #-----------------------------------------------------------------------------
  1840.   def play_grid_sound(sound_name)
  1841.     se = Ixfuru::GridWars::SOUNDS[sound_name]
  1842.     RPG::SE.new(se[0], se[1], se[2]).play
  1843.   end
  1844.  
  1845.   #-----------------------------------------------------------------------------
  1846.   # Update Commands
  1847.   #-----------------------------------------------------------------------------
  1848.   def update_commands
  1849.     case @turn
  1850.     when 0 # Player's
  1851.       @win_commands.update
  1852.       if Input.trigger?(Input::C)
  1853.         case @win_commands.index
  1854.         when 0 # Attack
  1855.           if targets.empty?
  1856.             Sound.play_buzzer
  1857.           else
  1858.             play_grid_sound(:attacking)
  1859.             @active_monster.attacking = true
  1860.             @phase = 2
  1861.             @win_commands.visible = false
  1862.             @win_commands.active = false
  1863.             @win_field.active = true
  1864.           end
  1865.         when 1 # Defend
  1866.           @active_monster.defending = true
  1867.           play_grid_sound(:defending)
  1868.           @phase = 3
  1869.           @win_commands.visible = false
  1870.           @win_commands.active = false
  1871.         when 2 # Dodge
  1872.           @active_monster.dodging = true
  1873.           play_grid_sound(:dodging)
  1874.           @phase = 3
  1875.           @win_commands.visible = false
  1876.           @win_commands.active = false
  1877.         end
  1878.       elsif Input.trigger?(Input::B)
  1879.         Sound.play_cancel
  1880.         @active_monster.reset
  1881.         @win_commands.visible = false
  1882.         @win_commands.active = false
  1883.         @win_field.active = true
  1884.         @phase = 0
  1885.       end
  1886.     when 1 # Opponent's
  1887.       return if @wait_count > 0
  1888.       rc = rand(12)
  1889.       if rc <= 6
  1890.         if !targets.empty?
  1891.           @win_commands.index = 0
  1892.           play_grid_sound(:attacking)
  1893.           @active_monster.attacking = true
  1894.           @phase = 2
  1895.           @wait_count = Ixfuru::GridWars::WAIT_COUNT
  1896.         else
  1897.           @win_commands.index = 1
  1898.           play_grid_sound(:defending)
  1899.           @active_monster.defending = true
  1900.           @phase = 3
  1901.           @wait_count = Ixfuru::GridWars::WAIT_COUNT
  1902.         end
  1903.       elsif rc <= 9
  1904.         @win_commands.index = 1
  1905.         play_grid_sound(:defending)
  1906.         @active_monster.defending = true
  1907.         @phase = 3
  1908.         @wait_count = Ixfuru::GridWars::WAIT_COUNT
  1909.       else
  1910.         @win_commands.index = 0
  1911.         play_grid_sound(:dodging)
  1912.         @active_monster.dodging = true
  1913.         @phase = 3
  1914.         @wait_count = Ixfuru::GridWars::WAIT_COUNT
  1915.       end
  1916.       @win_commands.visible = false
  1917.     end
  1918.   end
  1919.  
  1920.   #-----------------------------------------------------------------------------
  1921.   # Update Targetting
  1922.   #-----------------------------------------------------------------------------
  1923.   def update_targetting
  1924.     case @turn
  1925.     when 0 # PLayer's
  1926.       @win_field.update
  1927.       if Input.trigger?(Input::C)
  1928.         ti = @win_field.index
  1929.         if targets.include?(ti)
  1930.           @active_monster.target = @win_field.index
  1931.           play_grid_sound(:selection)
  1932.           @phase = 3
  1933.           @win_field.active = false
  1934.         else
  1935.           Sound.play_buzzer
  1936.         end
  1937.       elsif Input.trigger?(Input::Y)
  1938.         monster = @win_field.field_monsters[@win_field.index]
  1939.         if monster[1].is_a?(Game_Player) || monster[2]
  1940.           @win_preview.monster = monster[0]
  1941.           @win_preview.refresh
  1942.           @win_preview.visible = true
  1943.         else
  1944.           Sound.play_buzzer
  1945.         end
  1946.       elsif Input.trigger?(Input::B)
  1947.         Sound.play_cancel
  1948.         @win_commands.index = 0
  1949.         @win_commands.active = true
  1950.         @win_commands.visible = true
  1951.         @win_field.active = false
  1952.         @active_monster.reset
  1953.         @phase = 1
  1954.       end
  1955.     when 1 # Opponents
  1956.       return if @wait_count > 0
  1957.       ti = targets[rand(targets.size)]
  1958.       @win_field.index = ti
  1959.       @active_monster.target = @win_field.index
  1960.       play_grid_sound(:selection)
  1961.       @phase = 3
  1962.     end
  1963.   end
  1964.  
  1965.   #-----------------------------------------------------------------------------
  1966.   # Set Boost
  1967.   #-----------------------------------------------------------------------------
  1968.   def set_boosts
  1969.     for i in 0...60
  1970.       monster = @win_field.field_monsters[i][0]
  1971.       owner = @win_field.field_monsters[i][1]
  1972.       index = i
  1973.       for n in 0...4
  1974.         case n
  1975.         when 0
  1976.           bindex = i + 1
  1977.         when 1
  1978.           bindex = i - 1
  1979.         when 2
  1980.           bindex = i - 6
  1981.         when 3
  1982.           bindex = i + 6
  1983.         end
  1984.         next if bindex > 59 || bindex < 0
  1985.         if owner.is_a?(Game_Player)
  1986.           if @win_field.field_monsters[bindex][1].is_a?(Game_Player)
  1987.             monster.boost += 1
  1988.           end
  1989.         else
  1990.           if @win_field.field_monsters[bindex][1].is_a?(Game_Event)
  1991.             monster.boost -= 1
  1992.           end
  1993.         end
  1994.       end
  1995.     end
  1996.   end
  1997.  
  1998.   #-----------------------------------------------------------------------------
  1999.   # Targets
  2000.   #-----------------------------------------------------------------------------
  2001.   def targets
  2002.     am_index = @active_index
  2003.     target_indices = []
  2004.     for i in 0...4
  2005.       case i
  2006.       when 0
  2007.         target_index = am_index + 1
  2008.       when 1
  2009.         target_index = am_index - 1
  2010.       when 2
  2011.         target_index = am_index - 6
  2012.       when 3
  2013.         target_index = am_index + 6
  2014.       end
  2015.       case @turn
  2016.       when 0 # Players Turn
  2017.         if @win_field.field_monsters.has_key?(target_index) &&
  2018.            @win_field.field_monsters[target_index][1].is_a?(Game_Event)
  2019.           target_indices.push(target_index)
  2020.         end
  2021.       when 1 # Opponents Turn
  2022.         if @win_field.field_monsters.has_key?(target_index) &&
  2023.            @win_field.field_monsters[target_index][1].is_a?(Game_Player)
  2024.           target_indices.push(target_index)
  2025.         end
  2026.       end
  2027.     end
  2028.     @win_field.target_indices = target_indices
  2029.     @win_field.refresh
  2030.     return target_indices
  2031.   end
  2032.  
  2033.   #-----------------------------------------------------------------------------
  2034.   # Terminate
  2035.   #-----------------------------------------------------------------------------
  2036.   def terminate
  2037.     super
  2038.     dispose_menu_background
  2039.     windows = [@win_plyr_monsters, @win_opp_monsters, @win_plyr_score,
  2040.     @win_opp_score, @win_field, @win_preview, @win_token_count,
  2041.     @win_simulation, @win_result, @win_opp, @win_plyr]
  2042.     for window in windows
  2043.       window.dispose
  2044.     end
  2045.     @anisprite.dispose
  2046.   end
  2047.  
  2048.  
  2049. end    
  2050.  
  2051. ################################################################################
  2052. #                            WINDOW OPTIONS
  2053. ################################################################################
  2054. class Window_GW_Options < Window_Selectable
  2055.  
  2056.   attr_accessor :option_strings
  2057.  
  2058.   def initialize
  2059.     super(180, 0, 184, 80)
  2060.     @option_strings = ["", ""]
  2061.     refresh
  2062.     self.active = false
  2063.     self.index = 0
  2064.   end
  2065.  
  2066.   def refresh
  2067.     @item_max = @option_strings.size
  2068.     create_contents
  2069.     for i in 0...@item_max
  2070.       draw_option(i)
  2071.     end
  2072.   end
  2073.  
  2074.   def draw_option(index)
  2075.     rect = item_rect(index)
  2076.     rect.width += 8
  2077.     rect.x -= 4
  2078.     self.contents.draw_text(rect, @option_strings[index], 1)
  2079.   end
  2080.  
  2081. end
  2082.  
  2083. ################################################################################
  2084. #                           WINDOW INSTRUCTIONS
  2085. ################################################################################
  2086. class Window_GW_Instructions < Window_Base
  2087.  
  2088.   def initialize
  2089.     super(180, 80, 184, 192)
  2090.     @string_id = 0
  2091.     refresh
  2092.   end
  2093.  
  2094.   def refresh
  2095.     self.contents.clear
  2096.     lines = instruction_lines
  2097.     ly = 0
  2098.     lh = 16
  2099.     self.contents.font.size = 12
  2100.     for line in lines
  2101.       self.contents.draw_text(0, ly, self.width - 32, lh, line, 1)
  2102.       ly += lh
  2103.     end
  2104.   end
  2105.  
  2106.   def instruction_lines
  2107.     case @string_id
  2108.     when 0
  2109.       return ["Select a token to", "add to the QuickSet", "or Delete.",
  2110.       "Press X to Exit", "Press S to preview", "Press <> to change",
  2111.       "sides"]
  2112.     end
  2113.   end
  2114.  
  2115.  
  2116. end
  2117.  
  2118.  
  2119. ################################################################################
  2120. #                           WINDOW TOKEN AMOUNTS
  2121. ################################################################################
  2122. class Window_GW_TokenAmounts < Window_Base
  2123.  
  2124.  
  2125.   def initialize(amount_type)
  2126.     @atype = amount_type
  2127.     case @atype
  2128.     when 0
  2129.       super(0, 360, 180, 56)
  2130.     when 1
  2131.       super(364, 360, 180, 56)
  2132.     end
  2133.     refresh
  2134.   end
  2135.  
  2136.   def refresh
  2137.     self.contents.clear
  2138.     amount = @atype == 0 ? $game_player.grid_monsters.size : $game_player.quick_tokens.size
  2139.     self.contents.draw_text(0, 0, self.width - 32, WLH, amount.to_s, 1)
  2140.   end
  2141.  
  2142.  
  2143. end
  2144.  
  2145. ################################################################################
  2146. #                           WINDOW GRID RECORD
  2147. ################################################################################
  2148. class Window_GW_Record < Window_Base
  2149.  
  2150.   def initialize
  2151.     super(364, 0, 180, 56)
  2152.     @record = $game_player.grid_record
  2153.     refresh
  2154.   end
  2155.  
  2156.   def refresh
  2157.     self.contents.clear
  2158.     self.contents.draw_text(0, 0, self.width - 32, WLH, @record[0].to_s + "-" +
  2159.     @record[1].to_s + "-" + @record[2].to_s)
  2160.   end
  2161.  
  2162. end
  2163.  
  2164. ################################################################################
  2165. #                            SCENE TOKEN MANAGER
  2166. ################################################################################
  2167. class Scene_TokenManager < Scene_Base
  2168.  
  2169.   #-----------------------------------------------------------------------------
  2170.   # Initialize
  2171.   #------------------------------------------------------------------------------
  2172.   def initialize
  2173.     @quick = false # Options for Quick Set side of the scene?
  2174.     $game_player.renumerate_tokens
  2175.     $game_player.grid_monsters.each { |index, monster|
  2176.     monster.reset
  2177.     }
  2178.   end
  2179.  
  2180.   #-----------------------------------------------------------------------------
  2181.   # Start
  2182.   #-----------------------------------------------------------------------------
  2183.   def start
  2184.     super
  2185.     @win_player = Window_GW_Competitor.new
  2186.     @win_record = Window_GW_Record.new
  2187.     @win_monsterlist = Window_GW_MonsterList.new(0)
  2188.     @win_quicksetlist = Window_GW_MonsterList.new(nil)
  2189.     @win_allsize = Window_GW_TokenAmounts.new(0)
  2190.     @win_quicksize = Window_GW_TokenAmounts.new(1)
  2191.     @win_instructions = Window_GW_Instructions.new
  2192.     @win_options = Window_GW_Options.new
  2193.     @win_preview = Window_GW_MonsterPreview.new(nil)
  2194.     @win_monsterlist.active = true
  2195.     @win_preview.visible = true
  2196.   end
  2197.  
  2198.   #-----------------------------------------------------------------------------
  2199.   # Update
  2200.   #-----------------------------------------------------------------------------
  2201.   def update
  2202.     super
  2203.     update_preview
  2204.     if @win_options.active
  2205.       update_options
  2206.     elsif @win_monsterlist.active
  2207.       update_monsterlist
  2208.     elsif @win_quicksetlist.active
  2209.       update_quickset
  2210.     end
  2211.   end
  2212.  
  2213.   #-----------------------------------------------------------------------------
  2214.   # Update Preview
  2215.   #-----------------------------------------------------------------------------
  2216.   def update_preview
  2217.     if @quick
  2218.       @monster = @win_quicksetlist.monsters[@win_quicksetlist.index]
  2219.     else
  2220.       @monster = @win_monsterlist.monsters[@win_monsterlist.index]
  2221.     end
  2222.     @win_preview.monster = @monster
  2223.     @win_preview.refresh
  2224.   end
  2225.  
  2226.   #-----------------------------------------------------------------------------
  2227.   # Update Monster List
  2228.   #-----------------------------------------------------------------------------
  2229.   def update_monsterlist
  2230.     @win_monsterlist.update
  2231.     if Input.trigger?(Input::C)
  2232.       @monster = @win_monsterlist.monsters[@win_monsterlist.index]
  2233.       if !@monster.nil?
  2234.         Sound.play_decision
  2235.         @win_options.option_strings = active_option_strings
  2236.         @win_options.refresh
  2237.         @win_options.visible = true
  2238.         @win_options.active = true
  2239.       else
  2240.         Sound.play_buzzer
  2241.       end
  2242.     elsif Input.trigger?(Input::RIGHT)
  2243.       Sound.play_decision
  2244.       @win_quicksetlist.active = true
  2245.       @win_monsterlist.active = false
  2246.       @quick = true
  2247.     elsif Input.trigger?(Input::B)
  2248.       Sound.play_cancel
  2249.       $scene = Scene_Map.new
  2250.     end
  2251.   end
  2252.  
  2253.   #-----------------------------------------------------------------------------
  2254.   # Update Quickset List
  2255.   #-----------------------------------------------------------------------------
  2256.   def update_quickset
  2257.     @win_quicksetlist.update
  2258.     if Input.trigger?(Input::C)
  2259.       @monster = @win_quicksetlist.monsters[@win_quicksetlist.index]
  2260.       if !@monster.nil?
  2261.         Sound.play_decision
  2262.         @win_options.option_strings = active_option_strings
  2263.         @win_options.refresh
  2264.         @win_options.visible = true
  2265.         @win_options.active = true
  2266.       else
  2267.         Sound.play_buzzer
  2268.       end
  2269.     elsif Input.trigger?(Input::LEFT)
  2270.       Sound.play_decision
  2271.       @win_monsterlist.active = true
  2272.       @win_quicksetlist.active = false
  2273.       @quick = false
  2274.     end
  2275.   end
  2276.  
  2277.   #-----------------------------------------------------------------------------
  2278.   # Active Option Strings
  2279.   #----------------------------------------------------------------------------
  2280.   def active_option_strings
  2281.     return ["Remove Token", "Delete Token"] if @quick
  2282.     return ["Add Quick Token", "Delete Token"]
  2283.   end
  2284.  
  2285.   #-----------------------------------------------------------------------------
  2286.   # Update Options
  2287.   #-----------------------------------------------------------------------------
  2288.   def update_options
  2289.     @win_options.update
  2290.     if Input.trigger?(Input::C)
  2291.       case @win_options.index
  2292.       when 0 # Add/Remove from quickset
  2293.         if @quick
  2294.           Sound.play_cancel
  2295.           $game_player.quick_tokens.delete(@win_quicksetlist.monsters.index(@monster))
  2296.           $game_player.renumerate_tokens
  2297.           @win_options.active = false
  2298.           @win_options.visible = false
  2299.           @win_quicksetlist.refresh
  2300.           @win_quicksetlist.active = true
  2301.         else
  2302.           if $game_player.quick_tokens.has_value?(@monster) ||
  2303.              @win_quicksetlist.monsters.size == 30
  2304.             Sound.play_buzzer
  2305.           else
  2306.             Sound.play_decision
  2307.             $game_player.quick_tokens[$game_player.quick_tokens.size] = @monster
  2308.             $game_player.renumerate_tokens
  2309.             @win_options.active = false
  2310.             @win_options.visible = false
  2311.             @win_quicksetlist.refresh
  2312.             @win_quicksetlist.active = true
  2313.           end
  2314.         end
  2315.       when 1 # Delete The Token
  2316.         if @quick
  2317.           Sound.play_buzzer
  2318.         else
  2319.           Sound.play_cancel
  2320.           $game_player.grid_monsters.delete(@win_monsterlist.monsters.index(@monster))
  2321.           if $game_player.quick_tokens.has_value?(@monster)
  2322.             $game_player.quick_tokens.delete(@win_quicksetlist.monsters.index(@monster))
  2323.           end
  2324.           $game_player.renumerate_tokens
  2325.           @win_monsterlist.refresh
  2326.           @win_quicksetlist.refresh
  2327.           @win_options.active = false
  2328.           @win_options.visible = false
  2329.           @win_monsterlist.active = true
  2330.         end
  2331.       end
  2332.     elsif Input.trigger?(Input::B)
  2333.       Sound.play_cancel
  2334.       @win_options.visible = false
  2335.       @win_options.active = false
  2336.       if @quick
  2337.         @win_quicksetlist.active = true
  2338.       else
  2339.         @win_monsterlist.active = true
  2340.       end
  2341.     end
  2342.     @win_allsize.refresh
  2343.     @win_quicksize.refresh
  2344.   end
  2345.  
  2346.   #-----------------------------------------------------------------------------
  2347.   # Terminate
  2348.   #-----------------------------------------------------------------------------
  2349.   def terminate
  2350.     super
  2351.     windows = [@win_monsterlist, @win_quicksetlist, @win_options, @win_preview,
  2352.     @win_instructions, @win_allsize, @win_quicksize, @win_record, @win_player]
  2353.     for window in windows
  2354.       window.dispose
  2355.     end
  2356.   end
  2357.  
  2358. end
Advertisement
Add Comment
Please, Sign In to add comment