CrowMakerVX

GridWars1_1

Aug 9th, 2014
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 106.29 KB | None | 0 0
  1. ################################################################################
  2. #                           GRID WARS v1.1
  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.             :accuracy => 2},
  180.            
  181.       1 => {:name => "Rodango",
  182.             :icon_id => 376,
  183.             :atk => 3,
  184.             :def => 4,
  185.             :dodge => 3,
  186.             :accuracy => 5},
  187.            
  188.       2 => {:name => "Crypto",
  189.             :icon_id => 457,
  190.             :atk => 5,
  191.             :def => 5,
  192.             :dodge => 5,
  193.             :accuracy => 5},
  194.            
  195.       3 => {:name => "Flotoger",
  196.             :icon_id => 395,
  197.             :atk => 3,
  198.             :def => 3,
  199.             :dodge => 1,
  200.             :accuracy => 4},
  201.            
  202.     }
  203.    
  204.     #===========================================================================
  205.     # Section 3:
  206.     #
  207.     # OWNERS
  208.     #
  209.     # This section is crucial to using the script.  Owners are the events which
  210.     # possess tokens of their own and are therefor able to duel against the
  211.     # player in GridWars matches.  
  212.     #
  213.     # In order to set up for an event to be used, you need to provide a
  214.     # listing of it in the OWNERS hash.  
  215.     #
  216.     # For starters, for every map which has an event capable of GridWars
  217.     # participation, you need to have an outer hash_key of the map's ID.
  218.     #
  219.     # Each of these IDS are subsequently linked to an inner hash, which consists
  220.     # of every ID on the said map which is able to participate in GridWars.
  221.     #
  222.     # So you have:
  223.     #
  224.     #   7 => {3 => [],
  225.     #         8 => [],
  226.     #         28 => []},
  227.     #
  228.     # So in the above example, you have events 3, 8 and 28 on map 7 able to
  229.     # participate.  This means that if you are not on map # 7 and you try to
  230.     # battle event 28, you will receive an error message. You must be on the
  231.     # right map to call a GridWars match.
  232.     #
  233.     # Once you have this set up, you need to fill in the arrays '[]' associated
  234.     # with each event_id. To do this, you will be using three elements.
  235.     #
  236.     #        [stars, name, start_record]
  237.     #
  238.     # stars : this number is given to represent how strong the character's
  239.     #          token set will be.  This number should NOT exceed 5, preferably
  240.     #         and not be below 1.  A five star token set, will hold tokens
  241.     #        with ATK, DEF, DDG and ACC of up to 10, as the max for each
  242.     #       parameter is calculated by multiplying the 'stars' rating by 2.
  243.     #
  244.     # :name : This is the name you wish to be displayed when the GridWars
  245.     #         battle is taking place.
  246.     #
  247.     # :start_record : This is a three-element array [wins, losses, ties]
  248.     #                 This tells what you want the character's GridWars record
  249.     #                when the game starts.  
  250.     #
  251.     #============================================================================
  252.    
  253.     OWNERS = {
  254.    
  255.     #map_id => {event_id => [stars, name, start_record]}
  256.     1 => {2 => [1, "Whinny", [13, 12, 2]],
  257.           3 => [3, "Nancy", [4, 5, 0]],
  258.           5 => [5, "Ixfuru", [18, 2, 1]]},
  259.    
  260.     }
  261.    
  262.     #===========================================================================
  263.     # Section 4:
  264.     #
  265.     # SOUNDS
  266.     #
  267.     # This hash is used to store the sound_effects you wish to use inside the
  268.     # GridWars system.   For each entry, you need to add a three-element array.
  269.     #
  270.     #       [filename, volume, pitch]
  271.     #
  272.     #===========================================================================
  273.    
  274.     SOUNDS = {
  275.    
  276.     :place_card => ["Ice9", 80, 150], # sound played when a card is placed
  277.     :selection => ["Decision2", 80, 100], # sound played when selection is made
  278.     :attacking => ["Attack1", 80, 100], # sound played when attack is made
  279.     :defending => ["Flash1", 80, 100], # sound played when a defense is made
  280.     :dodging => ["Sword3", 80, 100], # sound played when dodge is made
  281.     :quickset => ["Raise3", 80, 100], # sound played when the quickset is called
  282.     :missing => ["Miss", 80, 100], # sound played when an attack misses
  283.     :gp_threshold => ["Recovery", 80, 150], # sound played when a token reaches gp threshold
  284.     :letter_input => ["Equip", 80, 200], # sound played when a letter is input
  285.     :shiftkey => ["Switch3", 80, 50], # sound played when shifting the letter case
  286.     :eraser => ["Wind7", 80, 100], # sound played when a letter is erased
  287.     :delete_token => ["Collapse1", 80, 220], # sound played when a token deleted
  288.    
  289.     }
  290.    
  291.     #===========================================================================
  292.     # Section 5:
  293.     #
  294.     # Musics
  295.     #
  296.     # This is the same as the hash from section 4, however, its used to store
  297.     # Music Effects, not sound effects.
  298.     #
  299.     #===========================================================================
  300.    
  301.     MUSICS = {
  302.    
  303.     :victory => ["Fanfare1", 80, 100],
  304.     :defeat => ["Item", 80, 100],
  305.     :tie => ["Gag", 80, 100],
  306.    
  307.    
  308.     }
  309.    
  310.     #===========================================================================
  311.     # Section 6:
  312.     #
  313.     # MISCELLANEOUS
  314.     #
  315.     # The following are a handful of other non-specific values which are used
  316.     # by the system and which can be altered here.
  317.     #
  318.     #===========================================================================
  319.    
  320.     ATTACK_ANIMATION = 40  # The database animation ID run when Attack is made
  321.    
  322.     PLAYER_FIELD_COLOR = 5 # # The color representing a player's token on the field
  323.     OPPONENT_FIELD_COLOR = 2 # The color representing an event's token on the field
  324.     QUICK_SET_TAG_COLOR = 14 # The color used to represent a token is in the quick set
  325.    
  326.     HIDDEN_OPPONENT_ICON_INDEX = 240 # the icon_index of the icon used to represent
  327.     #                                  an event's token before it is revealed
  328.    
  329.     BASE_VALUE = 100  # This is the gold value which is multiplied by the
  330.     #                   'star's of a given token to determine a price
  331.    
  332.     WAIT_COUNT = 90  # This is how long in frames the AI takes to make specific
  333.     #                   decisions
  334.    
  335.     TARGET_COLOR = 3 # This is the color shown representing a token which can be
  336.     #                  a target
  337.    
  338.     QUICKSET_COLOR = 23 # This is the color that denotes a card is in the Quickset
  339.    
  340.     GWBGM = ["Battle8", 80, 100] # This will be the music played during GridWars Matches
  341.    
  342.     # Token Points are the 'currency used to purchase new Tokens.  Upon winning a
  343.     # GridWars Match, you are rewarded your score - your opponent's score in
  344.     # Token Points.  These points can be turned in at special shops to purchase
  345.     # new tokens for your playable set.
  346.     # [Displayable name of Token Points, the abbreviation displayed, the icon_id]
  347.     TOKEN_POINTS  = ["Token Points", "TP", 85]
  348.    
  349.     NEW_SHOP_TOKEN_AMOUNT = 20
  350.    
  351.     # The following three colors, referenced by integers (0-32), are used in
  352.     # the drawing of the GP Gauge when viewing the parameters of a token.
  353.     # The 'GP_GAUGE_COLORBACK' is used as the color behind the two colors which
  354.     # make up the gauge bar.
  355.     GP_GAUGE_COLOR1 = 24
  356.     GP_GAUGE_COLOR2 = 17
  357.     GP_GAUGE_COLORBACK = 7
  358.  
  359.    
  360.     #===========================================================================
  361.     # Section 7:
  362.     #
  363.     # SCRIPT CALLS
  364.     #
  365.     # The following section is used for a reference to the creator of the project
  366.     # to illustrate in detail how the script can be used.  Use of the script
  367.     # requires the creator to make 'script calls' from the third page of
  368.     # an event's commands, or a common event's commands.  Enter the
  369.     # following script calls.
  370.     #
  371.     ##---------------------------------------------------------------------------
  372.     #
  373.     # 1. Call the GridWars Battle Scene:
  374.     #
  375.     #             $scene = Scene_GridWars.new(owner_id)
  376.     #
  377.     #     In this call, you need to replace the 'owner_id' deal with an ID of
  378.     # an OWNER you set up in the OWNERS hash.  
  379.     #       -don't call this scene unless the owner_id exists
  380.     #  
  381.     ##---------------------------------------------------------------------------
  382.     #
  383.     # 2. Call the TokenManager Scene:
  384.     #
  385.     #           $scene = Scene_TokenManager.new(owner_id)
  386.     #
  387.     # This call the will take the player to the scene where he/she can set up,
  388.     # delete and otherwise manage their tokens.
  389.     #
  390.     ##---------------------------------------------------------------------------
  391.     #
  392.     # 3. Check to see if the Player won the last match
  393.     #
  394.     #           $game_system.won_last_grid?
  395.     #
  396.     #     This is a great call for a conditional branch.  As it will return
  397.     #      true if the player won the last match they were part of.  This
  398.     #   makes it so that the creator can make things happen upon victory.
  399.     #
  400.     #           !$game_system.won_last_grid?
  401.     #
  402.     #     Use that to check if the player DID NOT win the last GridWars match
  403.     #
  404.     ##---------------------------------------------------------------------------
  405.     #
  406.     # 4. Create a Token set for the player/event
  407.     #
  408.     #             $game_player.new_grid_tokens(stars)
  409.     #                         or
  410.     #           $game_events[x].new_grid_tokens(stars)
  411.     #
  412.     #    These calls will render a new deck to the player or the event in question
  413.     #  respectively.  This gives 45 randomly generated tokens to the said
  414.     #   target.   It is very important that you DO NOT GIVE THE PLAYER A NEW
  415.     #   TOKEN SET twice.  This can cause bad problems with the script.
  416.     #
  417.     ##---------------------------------------------------------------------------
  418.     #
  419.     # 5. Check Wins/Losses/Ties
  420.     #
  421.     #       $game_player.grid_wins
  422.     #               or
  423.     #      $game_map.events[x].grid_wins
  424.     #
  425.     #            .grid_losses
  426.     #            .grid_ties    
  427.     #            .grid_matches
  428.     #
  429.     #    These calls will return the value of whatever part of the GridWars
  430.     # record you specify.  Say you want to set up an event for when a player
  431.     # wins 10 matches, these calls enable you to do that.
  432.     #                    -the .grid_matches call will return total matches played
  433.     #
  434.     ##---------------------------------------------------------------------------
  435.     #
  436.     # 6. Give a new token
  437.     #
  438.     #                  $game_player.add_token(stars)
  439.     #                            or
  440.     #                $game_map.events[x].add_token(stars)
  441.     #
  442.     #     These are the calls you place in order to add a new token to the
  443.     # player or event in question.   This gives a randomly generated token.
  444.     #
  445.     #---------------------------------------------------------------------------
  446.     #
  447.     # 7. Give a specific token from those found in the MONSTERS hash
  448.     #
  449.     #              $game_player.add_special_token(stars, token_id)
  450.     #
  451.     #          This does the exact same thing as #6, however, it creates a
  452.     #   token based on the one in the MONSTERS hash whose token_id matches
  453.     #   that given to the method as a second argument.  The 'stars' part
  454.     # here can be passed as any value 1-5.
  455.     #
  456.     #----------------------------------------------------------------------------
  457.     # 8. Give the event/player a new pack of tokens
  458.     #
  459.     #            $game_player.new_token_pack(stars)
  460.     #                          or
  461.     #            $game_map.events[x].new_token_pack(stars)
  462.     #
  463.     #===========================================================================
  464.    
  465.     #===========================================================================
  466.     # Section 8:
  467.     #
  468.     # TOKEN SHOPS
  469.     #
  470.     #===========================================================================
  471.     TOKEN_SHOPS = {
  472.    
  473.       #shop_id => {:tokens => [token_ids]  # USE "R" for a randomly generated token
  474.       #            :max_stars => maximum stars for tokens generated
  475.       0 => {:tokens => [0, 1, 2, "R", "R", "R", "R", "R", "R", "R"],
  476.             :max_stars => 3},
  477.      
  478.     }
  479.  
  480.     #===========================================================================
  481.     # Section 9:
  482.     #
  483.     # TOKEN GROWTH CHART
  484.     #
  485.     # This section give you complete control over how fast the monster tokens
  486.     # devolop.  Each time a token gets a 'kill' in combat, they are awarded
  487.     # the 'star value' of the token it slays (price value / BASE_VALUE).  These
  488.     # points are added to the token's 'GP' or "Growth Points".  When the token
  489.     # has stored enough GP, they are awarded an "Parameter Point" which can
  490.     # be added, via the Token Manager scene, to the token's parameters.
  491.     #
  492.     #===========================================================================
  493.     TOKEN_GROWTH_CHART = [0, 10, 25, 45, 70, 100, 135, 175, 220, 270, 325, 385,
  494.     450, 520, 595, 675, 760, 850, 945, 1045, 1150]
  495.      
  496.   end
  497. end
  498.  
  499. ################################################################################
  500. #                              GAME SYSTEM
  501. ################################################################################
  502. class Game_System
  503.  
  504.   attr_accessor :grid_monsters
  505.   attr_accessor :last_grid_result
  506.  
  507.   #------------------------------------------------------------------------------
  508.   # Initialize (Aliased)
  509.   #-----------------------------------------------------------------------------
  510.   alias ixgwgsini initialize unless $@
  511.   def initialize
  512.     ixgwgsini
  513.     @grid_monsters = {}
  514.     @last_grid_result = -1
  515.   end
  516.  
  517.   #-----------------------------------------------------------------------------
  518.   # Won Last Grid?
  519.   #-----------------------------------------------------------------------------
  520.   def won_last_grid?
  521.     return @last_grid_result == 0
  522.   end
  523.  
  524.   #------------------------------------------------------------------------------
  525.   # Update ( Aliased)
  526.   #-----------------------------------------------------------------------------
  527.   alias ixgwgsupdate update unless $@
  528.   def update
  529.     ixgwgsupdate
  530.     $gridshops = {} if $gridshops.nil?
  531.     @grid_monsters = {} if @grid_monsters.nil?
  532.     @last_grid_result = -1 if @last_grid_result.nil?
  533.   end
  534.  
  535. end
  536.  
  537.  
  538. ################################################################################
  539. #                   GAME PLAYER
  540. ################################################################################
  541. class Game_Player < Game_Character
  542.  
  543.   attr_accessor :grid_monsters
  544.   attr_accessor :token_points
  545.   attr_accessor :grid_record
  546.   attr_accessor :quick_tokens # A set of grid monsters that can be called quickly
  547.  
  548.   #-----------------------------------------------------------------------------
  549.   # Initialize (Aliased)
  550.   #-----------------------------------------------------------------------------
  551.   alias ixgwarsgmplyrini initialize unless $@
  552.   def initialize
  553.     ixgwarsgmplyrini
  554.     @grid_monsters = {}
  555.     @quick_tokens = {}
  556.     @token_points = 0
  557.     @grid_record = [0, 0, 0]
  558.   end
  559.  
  560.   #-----------------------------------------------------------------------------
  561.   # Grid Wins
  562.   #-----------------------------------------------------------------------------
  563.   def grid_wins
  564.     return @grid_record[0]
  565.   end
  566.  
  567.   #-----------------------------------------------------------------------------
  568.   # Grid Losses
  569.   #-----------------------------------------------------------------------------
  570.   def grid_losses
  571.     return @grid_record[1]
  572.   end
  573.  
  574.   #-----------------------------------------------------------------------------
  575.   # Grid Ties
  576.   #-----------------------------------------------------------------------------
  577.   def grid_ties
  578.     return @grid_record[2]
  579.   end
  580.  
  581.   #-----------------------------------------------------------------------------
  582.   # Grid Matches
  583.   #-----------------------------------------------------------------------------
  584.   def grid_matches
  585.     return @grid_record[0] + @grid_record[1] + @grid_record[2]
  586.   end
  587.  
  588.   #------------------------------------------------------------------------------
  589.   # New Special Token
  590.   #-----------------------------------------------------------------------------
  591.   def new_special_token(stars, token_id)
  592.     @grid_monsters[@grid_monsters.size] = GridMonster.new(1, token_id)
  593.   end
  594.  
  595.   #-----------------------------------------------------------------------------
  596.   # Add Token
  597.   #-----------------------------------------------------------------------------
  598.   def add_token(stars)
  599.     @grid_monsters[@grid_monsters.size] = GridMonster.new(stars)
  600.   end
  601.  
  602.   #-----------------------------------------------------------------------------
  603.   # Add Shop Token
  604.   #-----------------------------------------------------------------------------
  605.   def add_shop_token(token)
  606.     @grid_monsters[@grid_monsters.size] = token
  607.   end
  608.  
  609.   #-----------------------------------------------------------------------------
  610.   # Get Grid Monsters
  611.   #-----------------------------------------------------------------------------
  612.   def get_grid_monsters(stars)
  613.     @grid_monsters = {} if @grid_monsters.nil?
  614.     new_grid_tokens(stars) if @grid_monsters = {}
  615.   end
  616.  
  617.   #-----------------------------------------------------------------------------
  618.   # New Grid Tokens
  619.   #-----------------------------------------------------------------------------
  620.   def new_grid_tokens(stars)
  621.     for i in 0...45
  622.       @grid_monsters[i] = GridMonster.new(stars)
  623.     end
  624.   end
  625.  
  626.   #-----------------------------------------------------------------------------
  627.   # Grid Name
  628.   #-----------------------------------------------------------------------------
  629.   def grid_name
  630.     return $game_party.members[0].name
  631.   end
  632.  
  633.   #-----------------------------------------------------------------------------
  634.   # New Token Pack
  635.   #-----------------------------------------------------------------------------
  636.   def new_token_pack(token_count, stars)
  637.     gmi = @grid_monsters.size
  638.     for i in 0...token_count
  639.       @grid_monsters[gmi] = GridMonster.new(stars)
  640.       gmi += 1
  641.     end
  642.   end
  643.  
  644.   #-----------------------------------------------------------------------------
  645.   # Renumerate Tokens
  646.   #-----------------------------------------------------------------------------
  647.   def renumerate_tokens
  648.     new_monsters = {}
  649.     i = 0
  650.     @grid_monsters.each { |index, monster|
  651.     next if monster.nil?
  652.     new_monsters[i] = monster
  653.     i += 1
  654.     }
  655.     @grid_monsters = new_monsters
  656.     unless @quick_tokens.nil?
  657.       new_quicks = {}
  658.       i = 0
  659.       @quick_tokens.each { |index, monster|
  660.       next if monster.nil?
  661.       new_quicks[i] = monster
  662.       i += 1
  663.       }
  664.     end
  665.     @quick_tokens = new_quicks
  666.   end
  667.      
  668.  
  669. end
  670.  
  671. ################################################################################
  672. #                         GAME EVENT
  673. ################################################################################
  674. class Game_Event < Game_Character
  675.  
  676.   attr_accessor :grid_monsters
  677.   attr_accessor :grid_record
  678.  
  679.   #-----------------------------------------------------------------------------
  680.   # Initialize (Aliased)
  681.   #-----------------------------------------------------------------------------
  682.   alias ixgwarsgmeventini initialize unless $@
  683.   def initialize(map_id, event)
  684.     ixgwarsgmeventini(map_id, event)
  685.     @grid_record = []
  686.   end
  687.  
  688.   #-----------------------------------------------------------------------------
  689.   # Get Grid Monsters
  690.   #-----------------------------------------------------------------------------
  691.   def get_grid_monsters
  692.     @grid_monsters = {} if @grid_monsters.nil?
  693.     @grid_monsters = {} if !Ixfuru::GridWars::OWNERS.include?(@map_id)
  694.     @grid_monsters = {} if !Ixfuru::GridWars::OWNERS[@map_id].include?(@event.id)
  695.     new_grid_tokens(Ixfuru::GridWars::OWNERS[@map_id][@event.id][0]) if @grid_monsters.empty?
  696.     rec = Ixfuru::GridWars::OWNERS[@map_id][@event.id][2]
  697.     @grid_record = [rec[0], rec[1], rec[2]] if @grid_record.empty?
  698.   end
  699.  
  700.   #-----------------------------------------------------------------------------
  701.   # Grid Name
  702.   #-----------------------------------------------------------------------------
  703.   def grid_name
  704.     return "" if !Ixfuru::GridWars::OWNERS.include?(@map_id)
  705.     return "" if !Ixfuru::GridWars::OWNERS[@map_id].include?(@event.id)
  706.     return Ixfuru::GridWars::OWNERS[@map_id][@event.id][1]
  707.   end
  708.  
  709.   #-----------------------------------------------------------------------------
  710.   # New Grid Tokens
  711.   #-----------------------------------------------------------------------------
  712.   def new_grid_tokens(stars)
  713.     for i in 0...45
  714.       @grid_monsters[i] = GridMonster.new(stars)
  715.     end
  716.   end
  717.  
  718.   #-----------------------------------------------------------------------------
  719.   # Grid Wins
  720.   #-----------------------------------------------------------------------------
  721.   def grid_wins
  722.     return @grid_record[0]
  723.   end
  724.  
  725.   #-----------------------------------------------------------------------------
  726.   # Grid Losses
  727.   #-----------------------------------------------------------------------------
  728.   def grid_losses
  729.     return @grid_record[1]
  730.   end
  731.  
  732.   #-----------------------------------------------------------------------------
  733.   # Grid Ties
  734.   #-----------------------------------------------------------------------------
  735.   def grid_ties
  736.     return @grid_record[2]
  737.   end
  738.  
  739.   #-----------------------------------------------------------------------------
  740.   # Grid Matches
  741.   #-----------------------------------------------------------------------------
  742.   def grid_matches
  743.     return @grid_record[0] + @grid_record[1] + @grid_record[2]
  744.   end
  745.  
  746.   #------------------------------------------------------------------------------
  747.   # New Special Token
  748.   #-----------------------------------------------------------------------------
  749.   def new_special_token(stars, token_id)
  750.     @grid_monsters[@grid_monsters.size] = GridMonster.new(1, token_id)
  751.   end
  752.  
  753.   #-----------------------------------------------------------------------------
  754.   # New Token
  755.   #-----------------------------------------------------------------------------
  756.   def add_token(stars)
  757.     @grid_monsters[@grid_monsters.size] = GridMonster.new(stars)
  758.   end
  759.  
  760.   #-----------------------------------------------------------------------------
  761.   # New Token Pack
  762.   #-----------------------------------------------------------------------------
  763.   def new_token_pack(token_count, stars)
  764.     gmi = @grid_monsters.size
  765.     for i in 0...token_count
  766.       @grid_monsters[gmi] = GridMonster.new(stars)
  767.       gmi += 1
  768.     end
  769.   end
  770.  
  771.   #-----------------------------------------------------------------------------
  772.   # Renumerate Tokens
  773.   #-----------------------------------------------------------------------------
  774.   def renumerate_tokens
  775.     new_monsters = {}
  776.     i = 0
  777.     @grid_monsters.each { |index, monster|
  778.     next if monster.nil?
  779.     new_monsters[i] = monster
  780.     i += 1
  781.     }
  782.     @grid_monsters = new_monsters
  783.   end
  784.  
  785. end
  786.  
  787. ################################################################################
  788. #                                  SCENE BASE
  789. ################################################################################
  790. class Scene_Base
  791.  
  792.   #-----------------------------------------------------------------------------
  793.   # Play Grid Sound
  794.   #-----------------------------------------------------------------------------
  795.   def play_grid_sound(sound)
  796.     se = Ixfuru::GridWars::SOUNDS[sound]
  797.     RPG::SE.new(se[0], se[1], se[2]).play
  798.   end
  799.  
  800.   #-----------------------------------------------------------------------------
  801.   # Play Grid Music
  802.   #-----------------------------------------------------------------------------
  803.   def play_grid_music(music)
  804.     se = Ixfuru::GridWars::MUSICS[music]
  805.     RPG::ME.new(se[0], se[1], se[2]).play
  806.   end
  807.  
  808. end
  809.  
  810. ################################################################################
  811. #                            GRID MONSTERS
  812. ################################################################################
  813. class GridMonster
  814.  
  815.   attr_accessor :name
  816.   attr_reader :grid_id
  817.   attr_reader :icon_id
  818.   attr_accessor :atk
  819.   attr_accessor :def
  820.   attr_accessor :acc
  821.   attr_accessor :ddg
  822.   attr_accessor :attacking
  823.   attr_accessor :defending
  824.   attr_accessor :dodging
  825.   attr_accessor :set
  826.   attr_reader :stars
  827.   attr_accessor :target
  828.   attr_accessor :boost
  829.   attr_accessor :value
  830.   attr_reader :gp  # use 'add_gp' method to change gp amounts
  831.  
  832.   #-----------------------------------------------------------------------------
  833.   #    Initialize
  834.   #-----------------------------------------------------------------------------
  835.   def initialize(stars = 1, monster_id = nil)
  836.     @stars = stars
  837.     if monster_id.nil?
  838.       @name = generated_monster_name
  839.       @icon_id = generated_monster_icon
  840.       @atk = (rand(@stars * 2) + 1).to_i
  841.       @def = (rand(@stars * 2) + 1).to_i
  842.       @acc = (rand(@stars * 2) + 1).to_i
  843.       @ddg = (rand(@stars * 2) + 1).to_i
  844.     else
  845.       monsters = Ixfuru::GridWars::MONSTERS
  846.       @name = monsters[monster_id][:name]
  847.       @icon_id = monsters[monster_id][:icon_id]
  848.       @atk = monsters[monster_id][:atk]
  849.       @def = monsters[monster_id][:def]
  850.       @acc = monsters[monster_id][:accuracy]
  851.       @ddg = monsters[monster_id][:dodge]
  852.     end
  853.     @grid_id = generated_grid_id
  854.     @value = generated_monster_value
  855.     @gp = starting_gp
  856.     @parameter_pts = 0
  857.     reset
  858.     save_monster
  859.   end
  860.  
  861.   #-----------------------------------------------------------------------------
  862.   # Starting GP
  863.   #-----------------------------------------------------------------------------
  864.   def starting_gp
  865.     star_value = @value / Ixfuru::GridWars::BASE_VALUE
  866.     return Ixfuru::GridWars::TOKEN_GROWTH_CHART[star_value * 2]
  867.   end
  868.    
  869.   #-----------------------------------------------------------------------------
  870.   # Add GP
  871.   #-----------------------------------------------------------------------------
  872.   def add_gp(amount)
  873.     threshold = next_gp_threshold
  874.     @gp += amount
  875.     if @gp >= threshold
  876.       $scene = play_grid_sound(:gp_threshold)
  877.       @parameter_pts += 1
  878.     end
  879.   end
  880.  
  881.   #-----------------------------------------------------------------------------
  882.   # Next GP Threshold
  883.   #-----------------------------------------------------------------------------
  884.   def next_gp_threshold
  885.     chart = Ixfuru::GridWars::TOKEN_GROWTH_CHART
  886.     for i in 0...chart.size
  887.       break if i + 1 >= chart.size
  888.       if @gp >= chart[i] && @gp < chart[i + 1]
  889.         return chart[i + 1]
  890.       end
  891.     end
  892.   end
  893.    
  894.   #-----------------------------------------------------------------------------
  895.   # Save Monster
  896.   #-----------------------------------------------------------------------------
  897.   def save_monster
  898.     $game_system.grid_monsters[@grid_id] = self
  899.   end
  900.  
  901.   #-----------------------------------------------------------------------------
  902.   # Reset
  903.   #-----------------------------------------------------------------------------
  904.   def reset
  905.     @attacking = false
  906.     @dodging = false
  907.     @defending = false
  908.     @set = false
  909.     @target = nil
  910.     @boost = 0
  911.   end
  912.  
  913.   #-----------------------------------------------------------------------------
  914.   # Generated Monster Value
  915.   #-----------------------------------------------------------------------------
  916.   def generated_monster_value
  917.     n = @atk + @def + @acc + @ddg
  918.     return n * Ixfuru::GridWars::BASE_VALUE / 4
  919.   end
  920.  
  921.   #-----------------------------------------------------------------------------
  922.   # Generated Grid ID
  923.   #-----------------------------------------------------------------------------
  924.   def generated_grid_id
  925.     return $game_system.grid_monsters.size
  926.   end
  927.  
  928.   #-----------------------------------------------------------------------------
  929.   # Generated Monster Icon
  930.   #-----------------------------------------------------------------------------
  931.   def generated_monster_icon
  932.     icons = Ixfuru::GridWars::RANDOM_MONSTERS[:icon_pool]
  933.     return icons[rand(icons.size)]
  934.   end
  935.  
  936.   #-----------------------------------------------------------------------------
  937.   # Generated Monster Name
  938.   #-----------------------------------------------------------------------------
  939.   def generated_monster_name
  940.     parts = rand(5) + 1
  941.     firsts = Ixfuru::GridWars::RANDOM_MONSTERS[:first_letters]
  942.     vowels = Ixfuru::GridWars::RANDOM_MONSTERS[:vowels]
  943.     vowel_groupings = Ixfuru::GridWars::RANDOM_MONSTERS[:vowel_groupings]
  944.     groups = Ixfuru::GridWars::RANDOM_MONSTERS[:const_groupings]
  945.     fl = firsts[rand(firsts.size)]
  946.     if vowels.include?(fl.downcase)
  947.       g = rand(2)
  948.       case g
  949.       when 0
  950.         sl = firsts[rand(firsts.size)] + vowels[rand(vowels.size)]
  951.       when 1
  952.         sl = groups[rand(groups.size)] + vowels[rand(vowels.size)]
  953.       end
  954.     else
  955.       vg = rand(12)
  956.       if vg <= 10
  957.         sl = vowels[rand(vowels.size)]
  958.       else
  959.         sl = vowel_groupings[rand(vowel_groupings.size)]
  960.       end
  961.     end
  962.     ending = []
  963.     for i in 0...parts
  964.       case i
  965.       when 0, 2
  966.         vg = rand(12)
  967.         if vg <= 10
  968.           ending.push(vowels[rand(vowels.size)])
  969.         else
  970.           ending.push(vowel_groupings[rand(vowel_groupings.size)])
  971.         end
  972.       when 1, 3, 4
  973.         g = rand(2)
  974.         case g
  975.         when 0
  976.           ending.push(firsts[rand(firsts.size)].downcase)
  977.         when 1
  978.           ending.push(groups[rand(groups.size)])
  979.         end
  980.       end
  981.     end
  982.     n = fl + sl + ending.to_s
  983.     return n
  984.   end
  985.  
  986. end
  987.  
  988. ################################################################################
  989. #                         WINDOW MONSTER PREVIEW
  990. ################################################################################
  991. class Window_GW_MonsterPreview < Window_Base
  992.  
  993.   attr_accessor :monster
  994.  
  995.   def initialize(monster, dimensions = [])
  996.     if dimensions.empty?
  997.       super(180, 273, 184, 144)
  998.     else
  999.       super(dimensions[0], dimensions[1], dimensions[2], dimensions[3])
  1000.     end
  1001.     @monster = monster
  1002.     refresh
  1003.     self.visible = false
  1004.     self.z = 160
  1005.   end
  1006.  
  1007.   def refresh
  1008.     self.contents.clear
  1009.     return if @monster.nil?
  1010.     self.contents.font.size = 12    
  1011.     lh = 16
  1012.     self.contents.font.color = power_up_color
  1013.     self.contents.draw_text(0, 0, self.width - 32, lh, @monster.name, 1)
  1014.     draw_icon(@monster.icon_id, 0, lh)
  1015.     draw_gp_gauge(26, lh, (self.width - 58), 12)
  1016.     self.contents.font.color = system_color
  1017.     tags = ["ATK", "DEF", "ACC", "DDG"]
  1018.     ly = lh + WLH
  1019.     for tag in tags
  1020.       self.contents.draw_text(30, ly, self.width - 32, lh, tag)
  1021.       ly += lh
  1022.     end
  1023.     self.contents.font.color = normal_color
  1024.     pars = [@monster.atk, @monster.def, @monster.acc, @monster.ddg]
  1025.     ly = lh + WLH
  1026.     for par in pars
  1027.       self.contents.draw_text(90, ly, self.width - 32, lh, par.to_s)
  1028.       ly += lh
  1029.     end
  1030.   end
  1031.  
  1032.   #-----------------------------------------------------------------------------
  1033.   # Draw GP Gauge
  1034.   #-----------------------------------------------------------------------------
  1035.   def draw_gp_gauge(x, y, width, height)
  1036.     c1 = text_color(Ixfuru::GridWars::GP_GAUGE_COLOR1)
  1037.     c2 = text_color(Ixfuru::GridWars::GP_GAUGE_COLOR2)
  1038.     cb = text_color(Ixfuru::GridWars::GP_GAUGE_COLORBACK)
  1039.     gw = (width * @monster.gp) / @monster.next_gp_threshold
  1040.     self.contents.fill_rect(x, y + 6, width, height, cb)
  1041.     self.contents.gradient_fill_rect(x, y + 8, gw, height - 4, c1, c2)
  1042.   end
  1043.  
  1044. end
  1045.  
  1046. ################################################################################
  1047. #                                  WINDOW MONSTER LIST
  1048. ################################################################################
  1049. class Window_GW_MonsterList < Window_Selectable
  1050.  
  1051.   attr_accessor :monsters
  1052.  
  1053.   def initialize(owner_id)
  1054.     if owner_id == 0
  1055.       @owner = $game_player
  1056.       super(0, 56, 180, 304)
  1057.     elsif owner_id.nil?
  1058.       super(364, 56, 180, 304)
  1059.       @owner = nil
  1060.     elsif owner_id > 0
  1061.       @owner = $game_map.events[owner_id]
  1062.       super(364, 56, 180, 304)
  1063.     end
  1064.     refresh
  1065.     self.index = 0
  1066.     self.active = false
  1067.   end
  1068.  
  1069.   def refresh
  1070.     if !@owner.nil?
  1071.       @monsters = @owner.grid_monsters
  1072.     else
  1073.       @monsters = $game_player.quick_tokens
  1074.     end
  1075.     @item_max = @monsters.size
  1076.     create_contents
  1077.     return if @item_max == 0
  1078.     for i in 0...@item_max
  1079.       next if @monsters[i].nil?
  1080.       draw_monster(i)
  1081.     end
  1082.   end
  1083.  
  1084.   def enabled?(index)
  1085.     return true if @owner.nil?
  1086.     return false if @owner.grid_monsters[index].set
  1087.     return true
  1088.   end
  1089.  
  1090.   def draw_monster(index)
  1091.     rect = item_rect(index)
  1092.     if !@owner.nil?
  1093.       draw_icon(@owner.grid_monsters[index].icon_id, rect.x, rect.y, enabled?(index))
  1094.       self.contents.font.color.alpha = enabled?(index) ? 255 : 128
  1095.       self.contents.draw_text(rect.x + 26, rect.y, self.width - 32, WLH,
  1096.       @owner.grid_monsters[index].name)
  1097.       if @owner.is_a?(Game_Player) &&
  1098.        $game_player.quick_tokens.has_value?(@owner.grid_monsters[index])
  1099.         fc = Ixfuru::GridWars::QUICKSET_COLOR
  1100.         self.contents.fill_rect((self.width - 32) - 12, rect.y + 6, 12, 12, text_color(fc))
  1101.       end
  1102.     else
  1103.       draw_icon($game_player.quick_tokens[index].icon_id, rect.x, rect.y, enabled?(index))
  1104.       self.contents.font.color.alpha = enabled?(index) ? 255 : 128
  1105.       self.contents.draw_text(rect.x + 26, rect.y, self.width - 32, WLH,
  1106.       $game_player.quick_tokens[index].name)
  1107.     end
  1108.   end
  1109.    
  1110.  
  1111. end
  1112.  
  1113. ################################################################################
  1114. #                          WINDOW SCORE
  1115. ################################################################################
  1116. class Window_GW_Score < Window_Base
  1117.  
  1118.   attr_accessor :owner
  1119.   attr_accessor :points
  1120.  
  1121.   def initialize(owner_id = 0)
  1122.     case owner_id
  1123.     when 0
  1124.       super(0, 360, 180, 56)
  1125.       @owner = $game_player
  1126.     when 1
  1127.       super(364, 360, 180, 56)
  1128.       @owner = $game_map.events[owner_id]
  1129.     end
  1130.     @points = 0
  1131.     refresh
  1132.   end
  1133.  
  1134.   def refresh
  1135.     self.contents.clear
  1136.     self.contents.draw_text(0, 0, self.width - 32, WLH, @points.to_s, 1)
  1137.   end
  1138.  
  1139. end
  1140.  
  1141. ################################################################################
  1142. #                           WINDOW FIELD
  1143. ################################################################################
  1144. class Window_GW_Field < Window_Selectable
  1145.  
  1146.   attr_accessor :field_monsters
  1147.   attr_accessor :target_indices
  1148.   # field_monsters : {index = [monster, owner, moved?, x, y]}
  1149.  
  1150.   def initialize
  1151.     super(181, 0, 184, 272)
  1152.     @field_monsters = {}
  1153.     @target_indices = []
  1154.     @item_max = 60
  1155.     @column_max = 6
  1156.     @spacing = 0
  1157.     refresh
  1158.     self.index = 0
  1159.     self.active = false
  1160.   end
  1161.  
  1162.   def refresh
  1163.     create_contents
  1164.     for i in 0...@item_max
  1165.       draw_field_monsters(i)
  1166.     end
  1167.   end
  1168.  
  1169.   def enabled?(index)
  1170.     return false if @field_monsters[index][2]
  1171.     return true
  1172.   end
  1173.  
  1174.   def draw_field_monsters(index)
  1175.     rect = item_rect(index)
  1176.     return if @field_monsters[index].nil?
  1177.     @field_monsters[index][3] = rect.x
  1178.     @field_monsters[index][4] = rect.y
  1179.     monster = @field_monsters[index][0]
  1180.     return if monster.nil?
  1181.     if @field_monsters[index][1].is_a?(Game_Player)
  1182.       fc = Ixfuru::GridWars::PLAYER_FIELD_COLOR
  1183.       self.contents.fill_rect(rect.x + 2, rect. y + 2, rect.width - 4, rect.height - 4, text_color(fc))
  1184.       draw_icon(monster.icon_id, rect.x, rect.y, enabled?(index))
  1185.     else
  1186.       fc = Ixfuru::GridWars::OPPONENT_FIELD_COLOR
  1187.       self.contents.fill_rect(rect.x + 2, rect. y + 2, rect.width - 4, rect.height - 4, text_color(fc))
  1188.       if @field_monsters[index][2]
  1189.         draw_icon(monster.icon_id, rect.x, rect.y, false)
  1190.       else
  1191.         draw_icon(Ixfuru::GridWars::HIDDEN_OPPONENT_ICON_INDEX, rect.x, rect.y)
  1192.       end
  1193.     end
  1194.     self.contents.font.size = 12
  1195.     lh = 16
  1196.     if monster.attacking
  1197.       self.contents.font.color = text_color(10)
  1198.       self.contents.draw_text(rect.x + 12, rect.y, self.width - 32, lh, "A")
  1199.     elsif monster.defending
  1200.       self.contents.font.color = text_color(16)
  1201.       self.contents.draw_text(rect.x + 12, rect.y, self.width - 32, lh, "D")
  1202.     elsif monster.dodging
  1203.       self.contents.font.color = text_color(27)
  1204.       self.contents.draw_text(rect.x + 12, rect.y, self.width - 32, lh, "E")
  1205.     end
  1206.     if @target_indices.include?(index)
  1207.       tc = text_color(Ixfuru::GridWars::TARGET_COLOR)
  1208.       self.contents.fill_rect(rect.x + 6, rect.y + 6, 12, 12, tc)
  1209.     end
  1210.     self.contents.font.color = normal_color
  1211.   end
  1212.  
  1213. end
  1214.  
  1215. ################################################################################
  1216. #                          WINDOW TOKEN COMMANDS
  1217. ################################################################################
  1218. class Window_GW_TokenCommands < Window_Selectable
  1219.  
  1220.   def initialize
  1221.     super(180, 273, 184, 144)
  1222.     @commands = ["ATTACK", "DEFEND", "DODGE"]
  1223.     @item_max = 3
  1224.     refresh
  1225.     self.visible = false
  1226.     self.active = false
  1227.     self.index = 0
  1228.   end
  1229.  
  1230.   def refresh
  1231.     create_contents
  1232.     for i in 0...@item_max
  1233.       draw_command(i)
  1234.     end
  1235.   end
  1236.  
  1237.   def draw_command(index)
  1238.     rect = item_rect(index)
  1239.     self.contents.draw_text(rect, @commands[index], 1)
  1240.   end
  1241.  
  1242. end
  1243.  
  1244. ################################################################################
  1245. #                        WINDOW TOKEN COUNT
  1246. ################################################################################
  1247. class Window_GW_TokenCount < Window_Base
  1248.  
  1249.   attr_accessor :required_amount
  1250.  
  1251.   def initialize
  1252.     super(180, 273, 184, 144)
  1253.     @required_amount = 30
  1254.     refresh
  1255.   end
  1256.  
  1257.   def refresh
  1258.     self.contents.clear
  1259.     self.contents.draw_text(0, 0, self.width - 32, WLH, "Select " + required_amount.to_s + " more tokens.")
  1260.   end
  1261.  
  1262.  
  1263. end
  1264.  
  1265. ################################################################################
  1266. #                      WINDOW SIMULATION
  1267. ################################################################################
  1268. class Window_GW_Simulation < Window_Base
  1269.  
  1270.   attr_accessor :monster
  1271.   attr_accessor :action
  1272.  
  1273.   def initialize
  1274.     super(180, 273, 184, 144)
  1275.     @monster = nil
  1276.     @action = 0 # 0 for attack, 1 for defend, 2 for dodge
  1277.     refresh
  1278.     self.visible = false
  1279.   end
  1280.  
  1281.   def refresh
  1282.     self.contents.clear
  1283.     return if @monster.nil?
  1284.     draw_icon(@monster[0].icon_id, 0, 0)
  1285.     case @action
  1286.     when 0
  1287.       act_string = "attacking"
  1288.     when 1
  1289.       act_string = "defending"
  1290.     when 2
  1291.       act_string = "dodging"
  1292.     end
  1293.     lines = [@monster[0].name, "is", act_string]
  1294.     ly = 0
  1295.     for i in 0...lines.size
  1296.       self.contents.draw_text(26,ly, self.width - 32, WLH, lines[i], 1)
  1297.       ly += WLH
  1298.     end
  1299.   end
  1300.    
  1301.    
  1302. end
  1303.  
  1304. ################################################################################
  1305. #                                 WINDOW RESULTS
  1306. ################################################################################
  1307. class Window_GW_Results < Window_Base
  1308.  
  1309.   attr_accessor :string
  1310.  
  1311.   def initialize
  1312.     super(180, 273, 184, 144)
  1313.     @string = []
  1314.     refresh
  1315.     self.visible = false
  1316.   end
  1317.  
  1318.   def refresh
  1319.     self.contents.clear
  1320.     ly = 0
  1321.     lh = 20
  1322.     self.contents.font.size = 16
  1323.     for str in @string
  1324.       self.contents.draw_text(0, ly, self.width - 32, lh, str, 1)
  1325.       ly += lh
  1326.     end
  1327.   end
  1328.  
  1329. end
  1330.  
  1331. ################################################################################
  1332. #                              WINDOW COMPETITOR
  1333. ################################################################################
  1334. class Window_GW_Competitor < Window_Base
  1335.  
  1336.   attr_accessor :competitor
  1337.  
  1338.   def initialize(player = true, opponent_id = nil)
  1339.     if player
  1340.       super(0, 0, 180, 56)
  1341.       @competitor = $game_player
  1342.     else
  1343.       super(364, 0, 180, 56)
  1344.       @competitor = $game_map.events[opponent_id]
  1345.     end
  1346.     refresh
  1347.   end
  1348.  
  1349.   def refresh
  1350.     self.contents.clear
  1351.     draw_character(@competitor.character_name, @competitor.character_index, 16, 32)
  1352.     self.contents.draw_text(0, 0, self.width - 32, WLH, @competitor.grid_name, 2)
  1353.   end
  1354.  
  1355. end
  1356.    
  1357.    
  1358. ################################################################################
  1359. #                        SCENE GRID WARS
  1360. ################################################################################
  1361. class Scene_GridWars < Scene_Base
  1362.  
  1363.   #-----------------------------------------------------------------------------
  1364.   # Initialize
  1365.   #-----------------------------------------------------------------------------
  1366.   def initialize(opponent_id, player_first = true)
  1367.     bgm = Ixfuru::GridWars::GWBGM
  1368.     RPG::BGM.new(bgm[0], bgm[1], bgm[2]).play
  1369.     @opponent_id = opponent_id
  1370.     @opponent = $game_map.events[opponent_id]
  1371.     @opponent.get_grid_monsters
  1372.     reset_monsters
  1373.     @turn = player_first ? 0 : 1
  1374.     @phase = 0
  1375.     @presetting = true
  1376.     @setting = false
  1377.     @finish_match = false
  1378.     @winner = nil
  1379.     @wait_count = Ixfuru::GridWars::WAIT_COUNT
  1380.     @active_monster = nil
  1381.     @active_index = 0
  1382.     @targetting = false
  1383.     @simulation = false
  1384.     @sim_count = 0
  1385.     @take_count = 0
  1386.     @match_end = false
  1387.   end
  1388.  
  1389.   #-----------------------------------------------------------------------------
  1390.   # Start
  1391.   #-----------------------------------------------------------------------------
  1392.   def start
  1393.     super
  1394.     create_menu_background
  1395.     @win_plyr = Window_GW_Competitor.new
  1396.     @win_opp = Window_GW_Competitor.new(false, @opponent_id)
  1397.     @win_plyr_monsters = Window_GW_MonsterList.new(0)
  1398.     @win_opp_monsters = Window_GW_MonsterList.new(@opponent_id)
  1399.     @win_plyr_score = Window_GW_Score.new(0)
  1400.     @win_opp_score = Window_GW_Score.new(1)
  1401.     @win_field = Window_GW_Field.new
  1402.     @win_commands = Window_GW_TokenCommands.new
  1403.     @win_token_count = Window_GW_TokenCount.new
  1404.     @win_preview = Window_GW_MonsterPreview.new(nil)
  1405.     @win_simulation = Window_GW_Simulation.new
  1406.     @win_result = Window_GW_Results.new
  1407.     create_anisprite
  1408.   end
  1409.  
  1410.   #-----------------------------------------------------------------------------
  1411.   # Reset Monsters
  1412.   #------------------------------------------------------------------------------
  1413.   def reset_monsters
  1414.     $game_player.grid_monsters.each { |index, monster|
  1415.     monster.reset
  1416.     }
  1417.     @opponent.grid_monsters.each { |index, monster|
  1418.     monster.reset
  1419.     }
  1420.   end
  1421.  
  1422.   #-----------------------------------------------------------------------------
  1423.   # Create Anisprite
  1424.   #-----------------------------------------------------------------------------
  1425.   def create_anisprite
  1426.     @viewport = Viewport.new(0, 0, 544, 416)
  1427.     @viewport.z = 160
  1428.     @anisprite = Sprite_Base.new(@viewport)
  1429.   end
  1430.  
  1431.   #-----------------------------------------------------------------------------
  1432.   # Set Anisprite Location
  1433.   #-----------------------------------------------------------------------------
  1434.   def set_anisprite_location(x, y)
  1435.     @anisprite.x = @win_field.x + x
  1436.     @anisprite.y = @win_field.y + y
  1437.   end
  1438.  
  1439.   #-----------------------------------------------------------------------------
  1440.   # Update
  1441.   #-----------------------------------------------------------------------------
  1442.   def update
  1443.     super
  1444.     if @win_result.visible
  1445.       update_result
  1446.     elsif @win_preview.visible
  1447.       update_preview
  1448.     elsif @match_end
  1449.       if @winner.is_a?(Game_Player)
  1450.         $game_system.last_grid_result = 0
  1451.       elsif @winner.is_a?(Game_Event)
  1452.         $game_system.last_grid_result = 1
  1453.       else
  1454.         $game_system.last_grid_result = 2
  1455.       end
  1456.       $game_player.renumerate_tokens
  1457.       @opponent.renumerate_tokens
  1458.       $scene = Scene_Map.new
  1459.     elsif @taking
  1460.       update_taking
  1461.     elsif @presetting
  1462.       update_presetting
  1463.     elsif @setting
  1464.       update_setting
  1465.     elsif @finish_match
  1466.       update_finishing
  1467.     elsif @animating
  1468.       update_animating
  1469.     elsif @simulating
  1470.       update_simulation
  1471.     else
  1472.       update_turn
  1473.     end
  1474.   end
  1475.  
  1476.   #-----------------------------------------------------------------------------
  1477.   # Jumbled
  1478.   #-----------------------------------------------------------------------------
  1479.   def jumbled(ary)
  1480.     return unless ary.is_a?(Array)
  1481.     new_ary = []
  1482.     until ary.empty?
  1483.       n = ary[rand(ary.size)]
  1484.       new_ary.push(n)
  1485.       ary.delete(n)
  1486.     end
  1487.     return new_ary
  1488.   end
  1489.  
  1490.   #-----------------------------------------------------------------------------
  1491.   # Update Setting
  1492.   #-----------------------------------------------------------------------------
  1493.   def update_setting
  1494.     sz = 60
  1495.     fpool = []
  1496.     for i in 0...sz
  1497.       fpool.push(i)
  1498.     end
  1499.     fpool = jumbled(fpool)
  1500.     ptokens = []
  1501.     $game_player.grid_monsters.each { |index, monster|
  1502.     if monster.set
  1503.       ptokens.push(monster)
  1504.     end
  1505.     }
  1506.     otokens = []
  1507.     @opponent.grid_monsters.each { |index, monster|
  1508.     if monster.set
  1509.       otokens.push(monster)
  1510.     end
  1511.     }
  1512.     pool_id = 0
  1513.     for f in fpool
  1514.       case pool_id
  1515.       when 0 # Set Players Token
  1516.         token = ptokens[rand(ptokens.size)]
  1517.         @win_field.field_monsters[f] = [token, $game_player, false]
  1518.         ptokens.delete(@win_field.field_monsters[f][0])
  1519.         pool_id = 1
  1520.       when 1 # Set Opponents Token
  1521.         token = otokens[rand(otokens.size)]
  1522.         @win_field.field_monsters[f] = [token, @opponent, false]
  1523.         otokens.delete(@win_field.field_monsters[f][0])
  1524.         pool_id = 0
  1525.       end
  1526.       @win_field.refresh
  1527.     end
  1528.     @setting = false
  1529.     @win_field.active = true
  1530.     update_scores
  1531.   end
  1532.  
  1533.   #-----------------------------------------------------------------------------
  1534.   # Update Scores
  1535.   #-----------------------------------------------------------------------------
  1536.   def update_scores
  1537.     ps = 0
  1538.     os = 0
  1539.     for i in 0...60
  1540.       if @win_field.field_monsters[i][1].is_a?(Game_Player)
  1541.         ps += 1
  1542.       else
  1543.         os += 1
  1544.       end
  1545.     end
  1546.     @win_plyr_score.points = ps
  1547.     @win_opp_score.points = os
  1548.     @win_plyr_score.refresh
  1549.     @win_opp_score.refresh
  1550.   end
  1551.  
  1552.   #-----------------------------------------------------------------------------
  1553.   # Update Presetting
  1554.   #-----------------------------------------------------------------------------
  1555.   def update_presetting
  1556.     case @turn
  1557.     when 0 # Player's
  1558.       @win_plyr_monsters.active = true
  1559.       @win_plyr_monsters.update
  1560.       if Input.trigger?(Input::C)
  1561.         monster = @win_plyr_monsters.monsters[@win_plyr_monsters.index]
  1562.         if monster.set
  1563.           Sound.play_decision
  1564.           @win_token_count.required_amount += 1
  1565.           monster.set = false
  1566.         else
  1567.           play_grid_sound(:selection)
  1568.           @win_token_count.required_amount -= 1
  1569.           monster.set = true
  1570.         end
  1571.         @win_plyr_monsters.refresh
  1572.         @win_token_count.refresh
  1573.       elsif Input.trigger?(Input::B)
  1574.         Sound.play_cancel
  1575.         $scene = Scene_Map.new
  1576.       elsif Input.trigger?(Input::Y)
  1577.         Sound.play_decision
  1578.         @win_preview.monster = @win_plyr_monsters.monsters[@win_plyr_monsters.index]
  1579.         @win_preview.refresh
  1580.         @win_preview.visible = true
  1581.       elsif Input.trigger?(Input::X)
  1582.         if $game_player.quick_tokens.empty?
  1583.           Sound.play_buzzer
  1584.         elsif $game_player.quick_tokens.size < 30
  1585.           Sound.play_buzzer
  1586.         else
  1587.           play_grid_sound(:quickset)
  1588.           $game_player.grid_monsters.each { |index, monster|
  1589.           monster.reset
  1590.           }
  1591.           @win_plyr_monsters.refresh
  1592.           add_quickset
  1593.         end
  1594.       end
  1595.       if @win_token_count.required_amount <= 0
  1596.         @win_plyr_monsters.active = false
  1597.         @win_token_count.visible = false
  1598.         @turn = 1
  1599.       end
  1600.     when 1 # Opponent
  1601.       update_opponent_presetting
  1602.     end
  1603.   end
  1604.  
  1605.   #-----------------------------------------------------------------------------
  1606.   # Quick Select Token
  1607.   #-----------------------------------------------------------------------------
  1608.   def quick_select_token
  1609.     moveables = []
  1610.     @win_field.field_monsters.each { |index, monster|
  1611.     if monster[1].is_a?(Game_Player) && !monster[2]
  1612.       moveables.push([index, monster])
  1613.     end
  1614.     }
  1615.     m = moveables[rand(moveables.size)]
  1616.     return m
  1617.   end
  1618.  
  1619.  
  1620.   #-----------------------------------------------------------------------------
  1621.   # Add QuickSet
  1622.   #-----------------------------------------------------------------------------
  1623.   def add_quickset
  1624.     $game_player.quick_tokens.each { |index, monster|
  1625.     Sound.play_cursor
  1626.     $game_player.grid_monsters[$game_player.grid_monsters.index(monster)].set = true
  1627.     @win_token_count.required_amount -= 1
  1628.     @win_token_count.refresh
  1629.     }
  1630.     @win_plyr_monsters.refresh
  1631.   end
  1632.  
  1633.   #-----------------------------------------------------------------------------
  1634.   # Update Opponent Presetting
  1635.   #-----------------------------------------------------------------------------
  1636.   def update_opponent_presetting
  1637.     update_waiting
  1638.     return if @wait_count > 0
  1639.     set_otokens = 0
  1640.     until set_otokens == 30
  1641.       rm = rand(@win_opp_monsters.monsters.size)
  1642.       unless @win_opp_monsters.monsters[rm].set
  1643.         @win_opp_monsters.monsters[rm].set = true
  1644.         set_otokens += 1
  1645.       end
  1646.     end
  1647.     @turn = 0
  1648.     @setting = true
  1649.     @win_opp_monsters.refresh
  1650.     @wait_count = Ixfuru::GridWars::WAIT_COUNT
  1651.     @presetting = false
  1652.   end
  1653.  
  1654.   #-----------------------------------------------------------------------------
  1655.   # Update Simulating
  1656.   #-----------------------------------------------------------------------------
  1657.   def update_simulation
  1658.     update_scores
  1659.     @wait_count -= 1
  1660.     return if @wait_count > 0
  1661.     @win_field.index = @sim_count
  1662.     monster = @win_field.field_monsters[@sim_count]
  1663.     if monster[0].target != nil
  1664.       set_anisprite_location(@win_field.cursor_rect.x, @win_field.cursor_rect.y)
  1665.       @anisprite.start_animation($data_animations[Ixfuru::GridWars::ATTACK_ANIMATION])
  1666.       @animating = true
  1667.       retrieve_result(monster, @win_field.field_monsters[monster[0].target])
  1668.       @wait_count = 5
  1669.     else
  1670.       @wait_count = 5
  1671.       @win_field.refresh
  1672.       @sim_count += 1
  1673.       if @sim_count == 60
  1674.         @finish_match = true
  1675.         @simulating = false
  1676.       end
  1677.     end
  1678.   end
  1679.  
  1680.   #-----------------------------------------------------------------------------
  1681.   # Retrieve Result
  1682.   #-----------------------------------------------------------------------------
  1683.   def retrieve_result(attacker, target)
  1684.     atk = attacker[0].atk + attacker[0].boost
  1685.     dfd = target[0].def + target[0].boost
  1686.     acc = attacker[0].acc + attacker[0].boost
  1687.     ddg = target[0].ddg + target[0].ddg
  1688.     dfd += 1 if target[0].defending
  1689.     ddg += 1 if target[0].dodging
  1690.     atk_hit = rand(acc)
  1691.     dfd_evd = rand(ddg)
  1692.     if atk_hit >= dfd_evd
  1693.       if atk >= dfd
  1694.         play_grid_sound(:attacking)
  1695.         @win_field.field_monsters[attacker[0].target][1] = attacker[1]
  1696.         attacker[0].add_gp(target[0].value / 100) if attacker[1].is_a?(Game_Player)
  1697.       else
  1698.         play_grid_sound(:defending)
  1699.         attacker[1] = target[1]
  1700.         target[0].add_gp(attacker[0].value / 100) if attacker[1].is_a?(Game_Player)
  1701.       end
  1702.     else
  1703.       if target[0].dodging
  1704.         play_grid_sound(:dodging)
  1705.         attacker[1] = target[1]
  1706.         target[0].add_gp(attacker[0].value / 100) if attacker[1].is_a?(Game_Player)
  1707.       else
  1708.         play_grid_sound(:missing)
  1709.       end
  1710.     end
  1711.     @win_field.refresh
  1712.     update_scores
  1713.     @sim_count += 1
  1714.     if @sim_count >= 60
  1715.       @finish_match = true
  1716.       @simulating = false
  1717.     end
  1718.   end
  1719.  
  1720.   #-----------------------------------------------------------------------------
  1721.   # Result String Width
  1722.   #-----------------------------------------------------------------------------
  1723.   def result_string_width(string)
  1724.     return @win_result.contents.text_size(string).width
  1725.   end
  1726.  
  1727.   #-----------------------------------------------------------------------------
  1728.   # Show Result
  1729.   #-----------------------------------------------------------------------------
  1730.   def show_result(string_array)
  1731.     @win_result.string.clear
  1732.     for i in string_array
  1733.       @win_result.string.push(i)
  1734.     end
  1735.     @win_result.refresh
  1736.     @win_result.visible = true
  1737.   end
  1738.  
  1739.   #-----------------------------------------------------------------------------
  1740.   # Update Result
  1741.   #-----------------------------------------------------------------------------
  1742.   def update_result
  1743.     if Input.trigger?(Input::C) || Input.trigger?(Input::B)
  1744.       Sound.play_cancel
  1745.       unless @finish_match
  1746.         @sim_count += 1
  1747.         if @sim_count == 60
  1748.           @finish_match = true
  1749.           @simulating = false
  1750.         end
  1751.       end
  1752.       @win_result.visible = false
  1753.     end
  1754.     @win_field.refresh
  1755.     update_scores
  1756.   end
  1757.  
  1758.   #-----------------------------------------------------------------------------
  1759.   # Update Taking
  1760.   #-----------------------------------------------------------------------------
  1761.   def update_taking
  1762.     if @winner.is_a?(Game_Player)
  1763.       @win_opp_monsters.update
  1764.       if Input.trigger?(Input::C)
  1765.         if @win_opp_monsters.enabled?(@win_opp_monsters.index)
  1766.           play_grid_sound(:selection)
  1767.           token_points = @win_plyr_score.points - @win_opp_score.points
  1768.           lost_token = @win_opp_monsters.monsters[@win_opp_monsters.index]
  1769.           new_token = Marshal.load(Marshal.dump(@win_opp_monsters.monsters[@win_opp_monsters.index]))
  1770.           $game_player.grid_monsters[$game_player.grid_monsters.size] = new_token
  1771.           $game_player.token_points += token_points
  1772.           @opponent.grid_monsters.delete(lost_token)
  1773.           show_result([$game_party.members[0].name, "was victorious!", lost_token.name,
  1774.           "token was received!"])
  1775.           @win_opp_monsters.active = false
  1776.           @match_end = true
  1777.         else
  1778.           Sound.play_buzzer
  1779.         end
  1780.       elsif Input.trigger?(Input::Y)
  1781.         monster = @win_opp_monsters.monsters[@win_opp_monsters.index]
  1782.         @win_preview.monster = monster
  1783.         @win_preview.refresh
  1784.         @win_preview.visible = true
  1785.       end
  1786.     else
  1787.       @take_count -= 1
  1788.       Sound.play_cursor
  1789.       new_index = @win_plyr_monsters.index + 1
  1790.       if new_index >= @win_plyr_monsters.monsters.size
  1791.         new_index = 0
  1792.       end
  1793.       @win_plyr_monsters.index = new_index
  1794.       if @take_count <= 0
  1795.         if @win_plyr_monsters.enabled?(@win_plyr_monsters.index)
  1796.           lost_token = @win_plyr_monsters.monsters[@win_plyr_monsters.index]
  1797.           new_token = Marshal.load(Marshal.dump(@win_plyr_monsters.monsters[@win_plyr_monsters.index]))
  1798.           @opponent.grid_monsters[@opponent.grid_monsters.size] = new_token
  1799.           $game_player.grid_monsters.delete(lost_token)
  1800.           show_result([$game_party.members[0].name, "was defeated!", lost_token.name,
  1801.           "token was lost!"])
  1802.           @match_end = true
  1803.         end
  1804.       end
  1805.     end
  1806.   end
  1807.    
  1808.   #-----------------------------------------------------------------------------
  1809.   # Update Finishing
  1810.   #-----------------------------------------------------------------------------
  1811.   def update_finishing
  1812.     update_scores
  1813.     @winner = player_with_highest_score
  1814.     @win_result.visible = false
  1815.     if @winner.is_a?(Game_Player)
  1816.       play_grid_music(:victory)
  1817.       @taking = true
  1818.       @win_opp_monsters.active = true
  1819.       $game_system.last_grid_result = 0
  1820.     elsif @winner.is_a?(Game_Event)
  1821.       play_grid_music(:defeat)
  1822.       @taking = true
  1823.       @take_count = ($game_player.grid_monsters.size * rand(4)) +
  1824.        rand($game_player.grid_monsters.size)
  1825.       $game_system.last_grid_result = 1
  1826.     else
  1827.       play_grid_music(:tie)
  1828.       show_result("The Match was a tie!")
  1829.       @taking = true
  1830.       @match_end = true
  1831.       $game_system.last_grid_result = 2
  1832.     end
  1833.   end
  1834.  
  1835.   #------------------------------------------------------------------------------
  1836.   # Play Grid Music
  1837.   #-----------------------------------------------------------------------------
  1838.   def play_grid_music(music_name)
  1839.     me = Ixfuru::GridWars::MUSICS[music_name]
  1840.     RPG::ME.new(me[0], me[1], me[2]).play
  1841.   end
  1842.  
  1843.   #-----------------------------------------------------------------------------
  1844.   # Player With Highest Score
  1845.   #-----------------------------------------------------------------------------
  1846.   def player_with_highest_score
  1847.     if @win_plyr_score.points > @win_opp_score.points
  1848.       win = $game_player
  1849.     elsif @win_opp_score.points > @win_plyr_score.points
  1850.       win = @opponent
  1851.     else
  1852.       win = nil
  1853.     end
  1854.     return win
  1855.   end    
  1856.  
  1857.   #-----------------------------------------------------------------------------
  1858.   # Update Waiting
  1859.   #-----------------------------------------------------------------------------
  1860.   def update_waiting
  1861.     return if @turn == 0
  1862.     @wait_count -= 1
  1863.     if @wait_count <= 0
  1864.       @wait_count = 0
  1865.     end
  1866.   end
  1867.  
  1868.   #-----------------------------------------------------------------------------
  1869.   # Update Animating
  1870.   #-----------------------------------------------------------------------------
  1871.   def update_animating
  1872.     if @anisprite.animation?
  1873.       @anisprite.update
  1874.       @animating = true
  1875.     else
  1876.       @animating = false
  1877.     end
  1878.   end
  1879.  
  1880.   #-----------------------------------------------------------------------------
  1881.   # Update Preview
  1882.   #-----------------------------------------------------------------------------
  1883.   def update_preview
  1884.     if Input.trigger?(Input::C) || Input.trigger?(Input::B)
  1885.       Sound.play_cancel
  1886.       @win_preview.visible = false
  1887.     end
  1888.   end
  1889.  
  1890.   #-----------------------------------------------------------------------------
  1891.   # Update Turn
  1892.   #-----------------------------------------------------------------------------
  1893.   def update_turn
  1894.     update_waiting
  1895.     case @phase
  1896.     when 0 # Choose token
  1897.       update_token_selection
  1898.     when 1 # Choose Command
  1899.       update_commands
  1900.     when 2 # Choose Target
  1901.       update_targetting
  1902.     when 3 # Finish Up Turn
  1903.       update_end_turn
  1904.     end
  1905.   end
  1906.  
  1907.   #-----------------------------------------------------------------------------
  1908.   # Battle Ready?
  1909.   #------------------------------------------------------------------------------
  1910.   def battle_ready?
  1911.     for i in 0...60
  1912.       return false if !@win_field.field_monsters[i][2] # A monster hasn't moved
  1913.     end
  1914.     return true
  1915.   end
  1916.  
  1917.   #-----------------------------------------------------------------------------
  1918.   # Update End Turn
  1919.   #-----------------------------------------------------------------------------
  1920.   def update_end_turn
  1921.     @win_field.field_monsters[@active_index][2] = true
  1922.     @win_field.target_indices = []
  1923.     @win_field.refresh
  1924.     if battle_ready?
  1925.       set_boosts
  1926.       @simulating = true
  1927.     else
  1928.       case @turn
  1929.       when 0 # Player's
  1930.         @phase = 0
  1931.         @turn = 1
  1932.       when 1 # Opponent's
  1933.         @phase = 0
  1934.         @turn = 0
  1935.         @win_field.active = true
  1936.       end
  1937.     end
  1938.   end
  1939.  
  1940.   #-----------------------------------------------------------------------------
  1941.   # Update Token Selection
  1942.   #-----------------------------------------------------------------------------
  1943.   def update_token_selection
  1944.     case @turn
  1945.     when 0 # Player's
  1946.       @win_field.update
  1947. #~       m = moveables
  1948.       if Input.trigger?(Input::C)
  1949.         monster = @win_field.field_monsters[@win_field.index]
  1950.         if monster[1].is_a?(Game_Player) && !monster[2] #Player's monster and hasn't moved
  1951.           play_grid_sound(:selection)
  1952.           @active_monster = monster[0]
  1953.           @active_index = @win_field.index
  1954.           @phase = 1
  1955.           @win_field.active = false
  1956.           @win_commands.index = 0
  1957.           @win_commands.visible = true
  1958.           @win_commands.active = true
  1959.           @win_field.active = false
  1960.         else
  1961.           Sound.play_buzzer
  1962.         end
  1963.       elsif Input.trigger?(Input::Y)
  1964.         monster = @win_field.field_monsters[@win_field.index]
  1965.         if monster[1].is_a?(Game_Player) || monster[2]
  1966.           @win_preview.monster = monster[0]
  1967.           @win_preview.refresh
  1968.           @win_preview.visible = true
  1969.         else
  1970.           Sound.play_buzzer
  1971.         end
  1972.       end
  1973.     when 1 # Opponent's
  1974.       return if @wait_count > 0
  1975.       monster = random_selected_monster
  1976.       play_grid_sound(:selection)
  1977.       @win_field.index = monster[0]
  1978.       @active_monster = monster[1][0]
  1979.       @active_index = @win_field.index
  1980.       @win_commands.index = 0
  1981. #~       @win_commands.visible = true
  1982.       @wait_count = Ixfuru::GridWars::WAIT_COUNT
  1983.       @phase = 1
  1984.     end
  1985.   end
  1986.  
  1987.   #-----------------------------------------------------------------------------0
  1988.   # Random Selected Monster
  1989.   #-----------------------------------------------------------------------------
  1990.   def random_selected_monster
  1991.     moveables = []
  1992.     @win_field.field_monsters.each { |index, monster|
  1993.     if monster[1].is_a?(Game_Event) && !monster[2]
  1994.       moveables.push([index, monster])
  1995.     end
  1996.     }
  1997.     m = moveables[rand(moveables.size)]
  1998.     return m
  1999.   end
  2000.  
  2001.   #-----------------------------------------------------------------------------
  2002.   # Play Grid Sound
  2003.   #-----------------------------------------------------------------------------
  2004.   def play_grid_sound(sound_name)
  2005.     se = Ixfuru::GridWars::SOUNDS[sound_name]
  2006.     RPG::SE.new(se[0], se[1], se[2]).play
  2007.   end
  2008.  
  2009.   #-----------------------------------------------------------------------------
  2010.   # Update Commands
  2011.   #-----------------------------------------------------------------------------
  2012.   def update_commands
  2013.     case @turn
  2014.     when 0 # Player's
  2015.       @win_commands.update
  2016.       if Input.trigger?(Input::C)
  2017.         case @win_commands.index
  2018.         when 0 # Attack
  2019.           if targets.empty?
  2020.             Sound.play_buzzer
  2021.           else
  2022.             play_grid_sound(:attacking)
  2023.             @active_monster.attacking = true
  2024.             @phase = 2
  2025.             @win_commands.visible = false
  2026.             @win_commands.active = false
  2027.             @win_field.active = true
  2028.           end
  2029.         when 1 # Defend
  2030.           @active_monster.defending = true
  2031.           play_grid_sound(:defending)
  2032.           @phase = 3
  2033.           @win_commands.visible = false
  2034.           @win_commands.active = false
  2035.         when 2 # Dodge
  2036.           @active_monster.dodging = true
  2037.           play_grid_sound(:dodging)
  2038.           @phase = 3
  2039.           @win_commands.visible = false
  2040.           @win_commands.active = false
  2041.         end
  2042.       elsif Input.trigger?(Input::B)
  2043.         Sound.play_cancel
  2044.         @active_monster.reset
  2045.         @win_commands.visible = false
  2046.         @win_commands.active = false
  2047.         @win_field.active = true
  2048.         @phase = 0
  2049.       end
  2050.     when 1 # Opponent's
  2051.       return if @wait_count > 0
  2052.       rc = rand(12)
  2053.       if rc <= 6
  2054.         if !targets.empty?
  2055.           @win_commands.index = 0
  2056.           play_grid_sound(:attacking)
  2057.           @active_monster.attacking = true
  2058.           @phase = 2
  2059.           @wait_count = Ixfuru::GridWars::WAIT_COUNT
  2060.         else
  2061.           @win_commands.index = 1
  2062.           play_grid_sound(:defending)
  2063.           @active_monster.defending = true
  2064.           @phase = 3
  2065.           @wait_count = Ixfuru::GridWars::WAIT_COUNT
  2066.         end
  2067.       elsif rc <= 9
  2068.         @win_commands.index = 1
  2069.         play_grid_sound(:defending)
  2070.         @active_monster.defending = true
  2071.         @phase = 3
  2072.         @wait_count = Ixfuru::GridWars::WAIT_COUNT
  2073.       else
  2074.         @win_commands.index = 0
  2075.         play_grid_sound(:dodging)
  2076.         @active_monster.dodging = true
  2077.         @phase = 3
  2078.         @wait_count = Ixfuru::GridWars::WAIT_COUNT
  2079.       end
  2080.       @win_commands.visible = false
  2081.     end
  2082.   end
  2083.  
  2084.   #-----------------------------------------------------------------------------
  2085.   # Update Targetting
  2086.   #-----------------------------------------------------------------------------
  2087.   def update_targetting
  2088.     case @turn
  2089.     when 0 # PLayer's
  2090.       @win_field.update
  2091.       if Input.trigger?(Input::C)
  2092.         ti = @win_field.index
  2093.         if targets.include?(ti)
  2094.           @active_monster.target = @win_field.index
  2095.           play_grid_sound(:selection)
  2096.           @phase = 3
  2097.           @win_field.active = false
  2098.         else
  2099.           Sound.play_buzzer
  2100.         end
  2101.       elsif Input.trigger?(Input::Y)
  2102.         monster = @win_field.field_monsters[@win_field.index]
  2103.         if monster[1].is_a?(Game_Player) || monster[2]
  2104.           @win_preview.monster = monster[0]
  2105.           @win_preview.refresh
  2106.           @win_preview.visible = true
  2107.         else
  2108.           Sound.play_buzzer
  2109.         end
  2110.       elsif Input.trigger?(Input::B)
  2111.         Sound.play_cancel
  2112.         @win_commands.index = 0
  2113.         @win_commands.active = true
  2114.         @win_commands.visible = true
  2115.         @win_field.active = false
  2116.         @active_monster.reset
  2117.         @phase = 1
  2118.       end
  2119.     when 1 # Opponents
  2120.       return if @wait_count > 0
  2121.       ti = targets[rand(targets.size)]
  2122.       @win_field.index = ti
  2123.       @active_monster.target = @win_field.index
  2124.       play_grid_sound(:selection)
  2125.       @phase = 3
  2126.     end
  2127.   end
  2128.  
  2129.   #-----------------------------------------------------------------------------
  2130.   # Set Boost
  2131.   #-----------------------------------------------------------------------------
  2132.   def set_boosts
  2133.     for i in 0...60
  2134.       monster = @win_field.field_monsters[i][0]
  2135.       owner = @win_field.field_monsters[i][1]
  2136.       index = i
  2137.       for n in 0...4
  2138.         case n
  2139.         when 0
  2140.           bindex = i + 1
  2141.         when 1
  2142.           bindex = i - 1
  2143.         when 2
  2144.           bindex = i - 6
  2145.         when 3
  2146.           bindex = i + 6
  2147.         end
  2148.         next if bindex > 59 || bindex < 0
  2149.         if owner.is_a?(Game_Player)
  2150.           if @win_field.field_monsters[bindex][1].is_a?(Game_Player)
  2151.             monster.boost += 1
  2152.           end
  2153.         else
  2154.           if @win_field.field_monsters[bindex][1].is_a?(Game_Event)
  2155.             monster.boost -= 1
  2156.           end
  2157.         end
  2158.       end
  2159.     end
  2160.   end
  2161.  
  2162.   #-----------------------------------------------------------------------------
  2163.   # Targets
  2164.   #-----------------------------------------------------------------------------
  2165.   def targets
  2166.     am_index = @active_index
  2167.     target_indices = []
  2168.     for i in 0...4
  2169.       case i
  2170.       when 0
  2171.         target_index = am_index + 1
  2172.       when 1
  2173.         target_index = am_index - 1
  2174.       when 2
  2175.         target_index = am_index - 6
  2176.       when 3
  2177.         target_index = am_index + 6
  2178.       end
  2179.       case @turn
  2180.       when 0 # Players Turn
  2181.         if @win_field.field_monsters.has_key?(target_index) &&
  2182.            @win_field.field_monsters[target_index][1].is_a?(Game_Event)
  2183.           target_indices.push(target_index)
  2184.         end
  2185.       when 1 # Opponents Turn
  2186.         if @win_field.field_monsters.has_key?(target_index) &&
  2187.            @win_field.field_monsters[target_index][1].is_a?(Game_Player)
  2188.           target_indices.push(target_index)
  2189.         end
  2190.       end
  2191.     end
  2192.     @win_field.target_indices = target_indices
  2193.     @win_field.refresh
  2194.     return target_indices
  2195.   end
  2196.  
  2197.   #-----------------------------------------------------------------------------
  2198.   # Terminate
  2199.   #-----------------------------------------------------------------------------
  2200.   def terminate
  2201.     super
  2202.     dispose_menu_background
  2203.     windows = [@win_plyr_monsters, @win_opp_monsters, @win_plyr_score,
  2204.     @win_opp_score, @win_field, @win_preview, @win_token_count,
  2205.     @win_simulation, @win_result, @win_opp, @win_plyr]
  2206.     for window in windows
  2207.       window.dispose
  2208.     end
  2209.     @anisprite.dispose
  2210.   end
  2211.  
  2212.  
  2213. end    
  2214.  
  2215. ################################################################################
  2216. #                            WINDOW OPTIONS
  2217. ################################################################################
  2218. class Window_GW_Options < Window_Selectable
  2219.  
  2220.   attr_accessor :option_strings
  2221.  
  2222.   def initialize
  2223.     super(180, 0, 184, 104)
  2224.     @option_strings = ["", "", "", "", ""]
  2225.     refresh
  2226.     self.active = false
  2227.     self.index = 0
  2228.   end
  2229.  
  2230.   def refresh
  2231.     @item_max = @option_strings.size
  2232.     create_contents
  2233.     for i in 0...@item_max
  2234.       draw_option(i)
  2235.     end
  2236.   end
  2237.  
  2238.   def draw_option(index)
  2239.     rect = item_rect(index)
  2240.     rect.width += 8
  2241.     rect.x -= 4
  2242.     self.contents.draw_text(rect, @option_strings[index], 1)
  2243.   end
  2244.  
  2245. end
  2246.  
  2247. ################################################################################
  2248. #                           WINDOW INSTRUCTIONS
  2249. ################################################################################
  2250. class Window_GW_Instructions < Window_Base
  2251.  
  2252.   def initialize
  2253.     super(180, 104, 184, 168)
  2254.     @string_id = 0
  2255.     refresh
  2256.   end
  2257.  
  2258.   def refresh
  2259.     self.contents.clear
  2260.     lines = instruction_lines
  2261.     ly = 0
  2262.     lh = 16
  2263.     self.contents.font.size = 12
  2264.     for line in lines
  2265.       self.contents.draw_text(0, ly, self.width - 32, lh, line, 1)
  2266.       ly += lh
  2267.     end
  2268.   end
  2269.  
  2270.   def instruction_lines
  2271.     case @string_id
  2272.     when 0
  2273.       return ["Select a token to", "add to the QuickSet", "or Delete.",
  2274.       "Press X to Exit", "Press S to preview", "Press <> to change",
  2275.       "sides"]
  2276.     end
  2277.   end
  2278.  
  2279.  
  2280. end
  2281.  
  2282.  
  2283. ################################################################################
  2284. #                           WINDOW TOKEN AMOUNTS
  2285. ################################################################################
  2286. class Window_GW_TokenAmounts < Window_Base
  2287.  
  2288.  
  2289.   def initialize(amount_type)
  2290.     @atype = amount_type
  2291.     case @atype
  2292.     when 0
  2293.       super(0, 360, 180, 56)
  2294.     when 1
  2295.       super(364, 360, 180, 56)
  2296.     end
  2297.     refresh
  2298.   end
  2299.  
  2300.   def refresh
  2301.     self.contents.clear
  2302.     amount = @atype == 0 ? $game_player.grid_monsters.size : $game_player.quick_tokens.size
  2303.     self.contents.draw_text(0, 0, self.width - 32, WLH, amount.to_s, 1)
  2304.   end
  2305.  
  2306.  
  2307. end
  2308.  
  2309. ################################################################################
  2310. #                           WINDOW GRID RECORD
  2311. ################################################################################
  2312. class Window_GW_Record < Window_Base
  2313.  
  2314.   def initialize
  2315.     super(364, 0, 180, 56)
  2316.     @record = $game_player.grid_record
  2317.     refresh
  2318.   end
  2319.  
  2320.   def refresh
  2321.     self.contents.clear
  2322.     self.contents.draw_text(0, 0, self.width - 32, WLH, @record[0].to_s + "-" +
  2323.     @record[1].to_s + "-" + @record[2].to_s, 1)
  2324.   end
  2325.  
  2326. end
  2327.  
  2328. ################################################################################
  2329. #                               WINDOW TOKEN POINTS
  2330. ################################################################################
  2331. class Window_GW_TokenPoints < Window_Base
  2332.  
  2333.   def initialize(x, y, width)
  2334.     super(x, y, width, 56)
  2335.     refresh
  2336.   end
  2337.  
  2338.   def refresh
  2339.     self.contents.clear
  2340.     @points = $game_player.token_points
  2341.     draw_icon(Ixfuru::GridWars::TOKEN_POINTS[2], 0, 0)
  2342.     self.contents.draw_text(26, 0, self.width - 58, WLH, @points.to_s, 2)
  2343.   end
  2344.  
  2345. end
  2346.  
  2347. ################################################################################
  2348. #                            SCENE TOKEN MANAGER
  2349. ################################################################################
  2350. class Scene_TokenManager < Scene_Base
  2351.  
  2352.   #-----------------------------------------------------------------------------
  2353.   # Initialize
  2354.   #------------------------------------------------------------------------------
  2355.   def initialize
  2356.     @quick = false # Options for Quick Set side of the scene?
  2357.     $game_player.renumerate_tokens
  2358.     $game_player.grid_monsters.each { |index, monster|
  2359.     monster.reset
  2360.     }
  2361.   end
  2362.  
  2363.   #-----------------------------------------------------------------------------
  2364.   # Start
  2365.   #-----------------------------------------------------------------------------
  2366.   def start
  2367.     super
  2368.     create_menu_background
  2369.     @win_player = Window_GW_Competitor.new
  2370.     @win_record = Window_GW_Record.new
  2371.     @win_monsterlist = Window_GW_MonsterList.new(0)
  2372.     @win_quicksetlist = Window_GW_MonsterList.new(nil)
  2373.     @win_allsize = Window_GW_TokenAmounts.new(0)
  2374.     @win_quicksize = Window_GW_TokenAmounts.new(1)
  2375.     @win_instructions = Window_GW_Instructions.new
  2376.     @win_options = Window_GW_Options.new
  2377.     @win_preview = Window_GW_MonsterPreview.new(nil)
  2378.     @win_nameletters = Window_TokenRenamerLetters.new
  2379.     @win_nameview = Window_TokenRenamerPreview.new
  2380.     @win_confirmation = Window_Confirmation.new(["DELETE THE TOKEN", "CANCEL"])
  2381.     @win_monsterlist.active = true
  2382.     @win_preview.visible = true
  2383.   end
  2384.  
  2385.   #-----------------------------------------------------------------------------
  2386.   # Update
  2387.   #-----------------------------------------------------------------------------
  2388.   def update
  2389.     super
  2390.     update_preview
  2391.     if @win_confirmation.active
  2392.       update_confirmation
  2393.     elsif @win_options.active
  2394.       update_options
  2395.     elsif @win_nameletters.active
  2396.       update_naming
  2397.     elsif @win_monsterlist.active
  2398.       update_monsterlist
  2399.     elsif @win_quicksetlist.active
  2400.       update_quickset
  2401.     end
  2402.   end
  2403.  
  2404.   #-----------------------------------------------------------------------------
  2405.   # Update Preview
  2406.   #-----------------------------------------------------------------------------
  2407.   def update_preview
  2408.     if @quick
  2409.       @monster = @win_quicksetlist.monsters[@win_quicksetlist.index]
  2410.     else
  2411.       @monster = @win_monsterlist.monsters[@win_monsterlist.index]
  2412.     end
  2413.     @win_preview.monster = @monster
  2414.     @win_preview.refresh
  2415.   end
  2416.  
  2417.   #-----------------------------------------------------------------------------
  2418.   # Update Monster List
  2419.   #-----------------------------------------------------------------------------
  2420.   def update_monsterlist
  2421.     @win_monsterlist.update
  2422.     if Input.trigger?(Input::C)
  2423.       @monster = @win_monsterlist.monsters[@win_monsterlist.index]
  2424.       if !@monster.nil?
  2425.         Sound.play_decision
  2426.         @win_options.option_strings = active_option_strings
  2427.         @win_options.refresh
  2428.         @win_options.visible = true
  2429.         @win_options.active = true
  2430.       else
  2431.         Sound.play_buzzer
  2432.       end
  2433.     elsif Input.trigger?(Input::RIGHT)
  2434.       Sound.play_decision
  2435.       @win_quicksetlist.active = true
  2436.       @win_monsterlist.active = false
  2437.       @quick = true
  2438.     elsif Input.trigger?(Input::B)
  2439.       Sound.play_cancel
  2440.       $scene = Scene_Map.new
  2441.     end
  2442.   end
  2443.  
  2444.   #-----------------------------------------------------------------------------
  2445.   # Update Quickset List
  2446.   #-----------------------------------------------------------------------------
  2447.   def update_quickset
  2448.     @win_quicksetlist.update
  2449.     if Input.trigger?(Input::C)
  2450.       @monster = @win_quicksetlist.monsters[@win_quicksetlist.index]
  2451.       if !@monster.nil?
  2452.         Sound.play_decision
  2453.         @win_options.option_strings = active_option_strings
  2454.         @win_options.refresh
  2455.         @win_options.visible = true
  2456.         @win_options.active = true
  2457.       else
  2458.         Sound.play_buzzer
  2459.       end
  2460.     elsif Input.trigger?(Input::LEFT)
  2461.       Sound.play_decision
  2462.       @win_monsterlist.active = true
  2463.       @win_quicksetlist.active = false
  2464.       @quick = false
  2465.     end
  2466.   end
  2467.  
  2468.   #-----------------------------------------------------------------------------
  2469.   # Active Option Strings
  2470.   #----------------------------------------------------------------------------
  2471.   def active_option_strings
  2472.     return ["Remove Token", "Delete Token", "Rename"] if @quick
  2473.     return ["Add Quick Token", "Delete Token", "Rename"]
  2474.   end
  2475.  
  2476.   #-----------------------------------------------------------------------------
  2477.   # Update Options
  2478.   #-----------------------------------------------------------------------------
  2479.   def update_options
  2480.     @win_options.update
  2481.     if Input.trigger?(Input::C)
  2482.       case @win_options.index
  2483.       when 0 # Add/Remove from quickset
  2484.         if @quick
  2485.           Sound.play_cancel
  2486.           $game_player.quick_tokens.delete(@win_quicksetlist.monsters.index(@monster))
  2487.           $game_player.renumerate_tokens
  2488.           @win_options.active = false
  2489. #~           @win_options.visible = false
  2490.           @win_quicksetlist.refresh
  2491.           @win_quicksetlist.active = true
  2492.         else
  2493.           if $game_player.quick_tokens.has_value?(@monster) ||
  2494.              @win_quicksetlist.monsters.size == 30
  2495.             Sound.play_buzzer
  2496.           else
  2497.             Sound.play_decision
  2498.             $game_player.quick_tokens[$game_player.quick_tokens.size] = @monster
  2499.             $game_player.renumerate_tokens
  2500.             @win_options.active = false
  2501. #~             @win_options.visible = false
  2502.             @win_quicksetlist.refresh
  2503.             @win_quicksetlist.active = true
  2504.           end
  2505.         end
  2506.       when 1 # Delete The Token
  2507.         if @quick
  2508.           Sound.play_buzzer
  2509.         else
  2510.           Sound.play_decision
  2511.           @win_options.active = false
  2512.           @win_confirmation.index = 1
  2513.           @win_confirmation.visible = true
  2514.           @win_confirmation.active = true
  2515.         end
  2516.       when 2 # Rename
  2517.         if @quick
  2518.           Sound.play_buzzer
  2519.         else
  2520.           Sound.play_decision
  2521.           @win_monsterlist.active = false
  2522.           @win_nameview.reset_word
  2523.           @win_nameletters.visible = true
  2524.           @win_nameview.visible = true
  2525.           @win_nameview.index = 0
  2526.           @win_nameletters.index = 0
  2527.           @win_nameletters.active = true
  2528.           @win_options.active = false
  2529.         end
  2530.       end
  2531.     elsif Input.trigger?(Input::B)
  2532.       Sound.play_cancel
  2533. #~       @win_options.visible = false
  2534.       @win_options.active = false
  2535.       if @quick
  2536.         @win_quicksetlist.active = true
  2537.       else
  2538.         @win_monsterlist.active = true
  2539.       end
  2540.     end
  2541.     @win_allsize.refresh
  2542.     @win_quicksize.refresh
  2543.   end
  2544.  
  2545.   #-----------------------------------------------------------------------------
  2546.   # Update Naming
  2547.   #-----------------------------------------------------------------------------
  2548.   def update_naming
  2549.     @win_nameletters.update
  2550.     if Input.trigger?(Input::C)
  2551.       if @win_nameletters.index == @win_nameletters.letters.size - 1
  2552.         play_grid_sound(:selection)
  2553.         name = @win_nameview.word.to_s
  2554.         name.scan(/./) { |c| c = "" if c == "" }
  2555.         @monster.name = name
  2556.         @win_monsterlist.refresh
  2557.         @win_quicksetlist.refresh
  2558.         @win_nameletters.active = false
  2559.         @win_nameview.visible = false
  2560.         @win_nameletters.visible = false
  2561.         @win_preview.refresh
  2562.         @win_options.active = true
  2563.       elsif @win_nameletters.index == @win_nameletters.letters.size - 2
  2564.         Sound.play_cancel
  2565.         @win_nameletters.active = false
  2566.         @win_nameview.visible = false
  2567.         @win_nameletters.visible = false
  2568.         @win_options.active = true
  2569.       else
  2570.         play_grid_sound(:letter_input)
  2571.         @win_nameview.word[@win_nameview.index] = @win_nameletters.letters[@win_nameletters.index]
  2572.         @win_nameview.refresh
  2573.         if @win_nameview.index < @win_nameview.max_characters - 1
  2574.           @win_nameview.index += 1
  2575.         end
  2576.       end
  2577.     elsif Input.trigger?(Input::B)
  2578.       play_grid_sound(:eraser)
  2579.       if @win_nameview.index > 0
  2580.         @win_nameview.word[@win_nameview.index - 1] = " "
  2581.         @win_nameview.index -= 1
  2582.         @win_nameview.refresh
  2583.       else
  2584.         Sound.play_buzzer
  2585.       end
  2586.     elsif Input.trigger?(Input::A)
  2587.       play_grid_sound(:shiftkey)
  2588.       toggle = @win_nameletters.lcase == 0
  2589.       @win_nameletters.lcase = toggle ? 1 : 0
  2590.       @win_nameletters.refresh
  2591.     end
  2592.   end
  2593.  
  2594.   #-----------------------------------------------------------------------------
  2595.   # Update Confirmation
  2596.   #-----------------------------------------------------------------------------
  2597.   def update_confirmation
  2598.     @win_confirmation.update
  2599.     if Input.trigger?(Input::C)
  2600.       case @win_confirmation.index
  2601.       when 0
  2602.         play_grid_sound(:delete_token)
  2603.         $game_player.grid_monsters.delete(@win_monsterlist.monsters.index(@monster))
  2604.         if $game_player.quick_tokens.has_value?(@monster)
  2605.           $game_player.quick_tokens.delete(@win_quicksetlist.monsters.index(@monster))
  2606.         end
  2607.         $game_player.renumerate_tokens
  2608.         @win_monsterlist.refresh
  2609.         @win_quicksetlist.refresh
  2610.         @win_confirmation.active = false
  2611.         @win_confirmation.visible = false
  2612.         @win_monsterlist.active = true
  2613.       when 1
  2614.         Sound.play_cancel
  2615.         @win_confirmation.active = false
  2616.         @win_confirmation.visible = false
  2617.         @win_options.active = true
  2618.       end
  2619.     elsif Input.trigger?(Input::B)
  2620.       Sound.play_cancel
  2621.       @win_confirmation.active = false
  2622.       @win_confirmation.visible = false
  2623.       @win_options.active = true
  2624.     end
  2625.   end
  2626.  
  2627.   #-----------------------------------------------------------------------------
  2628.   # Terminate
  2629.   #-----------------------------------------------------------------------------
  2630.   def terminate
  2631.     super
  2632.     dispose_menu_background
  2633.     windows = [@win_monsterlist, @win_quicksetlist, @win_options, @win_preview,
  2634.     @win_instructions, @win_allsize, @win_quicksize, @win_record, @win_player,
  2635.     @win_nameletters, @win_nameview, @win_confirmation]
  2636.     for window in windows
  2637.       window.dispose
  2638.     end
  2639.   end
  2640.  
  2641. end
  2642.  
  2643. ################################################################################
  2644. #                         GRID SHOP
  2645. ################################################################################
  2646. class GridShop
  2647.  
  2648.   attr_reader :shop_id
  2649.   attr_accessor :tokens
  2650.  
  2651.   #-----------------------------------------------------------------------------
  2652.   # Initialize
  2653.   #-----------------------------------------------------------------------------
  2654.   def initialize(shop_id, max_stars = 1)
  2655.     @shop_id = shop_id
  2656.     if Ixfuru::GridWars::TOKEN_SHOPS.has_key?(shop_id)
  2657.       base = Ixfuru::GridWars::TOKEN_SHOPS[shop_id]
  2658.       @max_stars = base[:max_stars]
  2659.       @tokens = preset_shop_tokens(base)
  2660.     else
  2661.       @max_stars = max_stars
  2662.       @tokens = generated_shop_tokens
  2663.     end
  2664.     finalize
  2665.   end
  2666.  
  2667.   #-----------------------------------------------------------------------------
  2668.   # Generated Shop Tokens
  2669.   #-----------------------------------------------------------------------------
  2670.   def generated_shop_tokens
  2671.     result = {}
  2672.     for i in 0...Ixfuru::GridWars::NEW_SHOP_TOKEN_AMOUNT
  2673.       stars = rand(@max_stars).to_i
  2674.       result[i] = GridMonster.new(stars)
  2675.     end
  2676.     return result
  2677.   end
  2678.  
  2679.   #-----------------------------------------------------------------------------
  2680.   # Preset Shop Tokens
  2681.   #-----------------------------------------------------------------------------
  2682.   def preset_shop_tokens(shop_base)
  2683.     result = {}
  2684.     for i in 0...shop_base[:tokens].size
  2685.       t = shop_base[:tokens][i]
  2686.       if t == "R"
  2687.         stars = rand(@max_stars)
  2688.         result[i] = GridMonster.new(stars)
  2689.       else
  2690.         stars = rand(@max_stars)
  2691.         result[i] = GridMonster.new(stars, t)
  2692.       end
  2693.     end
  2694.     return result
  2695.   end
  2696.  
  2697.   #-----------------------------------------------------------------------------
  2698.   # Finalize
  2699.   #
  2700.   # This method adds the new shop to the global hash $gridshops
  2701.   #_----------------------------------------------------------------------------
  2702.   def finalize
  2703.     $gridshops[@shop_id] = self
  2704.   end
  2705.  
  2706.   #-----------------------------------------------------------------------------
  2707.   # New Shop Bundle
  2708.   #
  2709.   # bundle : can be passed as either an array of token ids and "R" for random
  2710.   #          tokens, or can be passed as "RandomX", where X is the amount of
  2711.   #          tokens you wish to add to the shop.
  2712.   #-----------------------------------------------------------------------------
  2713.   def new_shop_bundle(bundle)
  2714.     if bundle.is_a?(Array)
  2715.       for i in 0...bundle.size
  2716.         t = bundle[i]
  2717.         if t == "R"
  2718.           stars = rand(@max_stars)
  2719.           @tokens[@tokens.size] = GridMonster.new(stars)
  2720.         else
  2721.           stars = rand(@max_stars)
  2722.           @tokens[@tokens.size] = GridMonster.new(stars, t)
  2723.         end
  2724.       end
  2725.     elsif /Random(X)/i =~ bundle
  2726.       amount = $1.to_i
  2727.       for i in 0...amount
  2728.         stars = rand(@max_stars)
  2729.         @tokens[@tokens.size] = GridMonster.new(stars)
  2730.       end
  2731.     end
  2732.   end
  2733.  
  2734.   #-----------------------------------------------------------------------------
  2735.   # Add Token
  2736.   #----------------------------------------------------------------------------
  2737.   def add_token(stars, token_id = nil)
  2738.     if token_id.nil?
  2739.       @tokens[@tokens.size] = GridMonster.new(stars)
  2740.     else
  2741.       @tokens[@tokens.size] = GridMonster.new(stars, token_id)
  2742.     end
  2743.   end
  2744.  
  2745.   #-----------------------------------------------------------------------------
  2746.   # Add Sold Token
  2747.   #-----------------------------------------------------------------------------
  2748.   def add_sold_token(token)
  2749.     @tokens[@tokens.size] = token
  2750.   end
  2751.  
  2752.   #-----------------------------------------------------------------------------
  2753.   # Renumerate Tokens
  2754.   #-----------------------------------------------------------------------------
  2755.   def renumerate_tokens
  2756.     new_tokens = {}
  2757.     i = 0
  2758.     @tokens.each { |index,token|
  2759.     next if token.nil?
  2760.     new_tokens[i] = token
  2761.     i += 1
  2762.     }
  2763.     @tokens = new_tokens
  2764.   end
  2765.  
  2766.  
  2767. end
  2768.  
  2769. ################################################################################
  2770. #                      WINDOW GRIDSHOP GOODS
  2771. ################################################################################
  2772. class Window_GridShopGoods < Window_Selectable
  2773.  
  2774.   attr_accessor :tokens
  2775.   attr_accessor :shop
  2776.  
  2777.   def initialize(shop_id)
  2778.     super(0, 56, 366, 360)
  2779.     @shop_id = shop_id
  2780.     if $gridshops.has_key?(shop_id)
  2781.       @shop = $gridshops[@shop_id]
  2782.     else
  2783.       @shop = GridShop.new(shop_id)
  2784.     end
  2785.     refresh
  2786.     self.index = 0
  2787.     self.active = false
  2788.     self.visible = false
  2789.   end
  2790.  
  2791.   def refresh
  2792.     @tokens = $gridshops[@shop_id].tokens
  2793.     @item_max = @tokens.size
  2794.     create_contents
  2795.     for i in 0...@item_max
  2796.       draw_goods(i)
  2797.     end
  2798.   end
  2799.  
  2800.   def draw_goods(index)
  2801.     rect = item_rect(index)
  2802.     rect.width += 8
  2803.     rect.x -= 4
  2804.     e = enabled?(index)
  2805.     self.contents.font.color.alpha = e ? 255 : 128
  2806.     draw_icon(@tokens[index].icon_id, 0, rect.y, e)
  2807.     self.contents.draw_text(rect.x + 26, rect.y, self.width - 32, WLH, @tokens[index].name)
  2808.     nx = ((self.width - 32) - self.contents.text_size(@tokens[index].value.to_s).width) - 26
  2809.     draw_icon(Ixfuru::GridWars::TOKEN_POINTS[2], nx, rect.y, e)
  2810.     self.contents.draw_text(nx + 26, rect.y, self.width - 32, WLH, @tokens[index].value.to_s)
  2811.   end
  2812.  
  2813.   def enabled?(index)
  2814.     return true if $game_player.token_points >= @tokens[index].value
  2815.     return false
  2816.   end
  2817.  
  2818. end
  2819.    
  2820.  
  2821. ################################################################################
  2822. #                        WINDOW GRIDSHOP OPTIONS
  2823. ################################################################################
  2824. class Window_GridShopOptions < Window_Selectable
  2825.  
  2826.   def initialize
  2827.     super(0, 0, 544, 56)
  2828.     @options = ["Purchase", "Sell", "Exit"]
  2829.     @item_max = @options.size
  2830.     @column_max = @item_max
  2831.     refresh
  2832.     self.index = 0
  2833.   end
  2834.  
  2835.   def refresh
  2836.     create_contents
  2837.     for i in 0...@item_max
  2838.       draw_option(i)
  2839.     end
  2840.   end
  2841.  
  2842.   def enabled?(index)
  2843.     case index
  2844.     when 0
  2845.       return true
  2846.     when 1
  2847.       return true if !$game_player.grid_monsters.empty?
  2848.       return false
  2849.     when 2
  2850.       return true
  2851.     end
  2852.   end
  2853.  
  2854.   def draw_option(index)
  2855.     rect = item_rect(index)
  2856.     e = enabled?(index)
  2857.     self.contents.font.color.alpha = e ? 255 : 128
  2858.     self.contents.draw_text(rect, @options[index], 1)
  2859.   end
  2860.  
  2861. end
  2862.  
  2863. ################################################################################
  2864. #                      WINDOW GRIDSHOP SELL LIST
  2865. ################################################################################
  2866. class Window_GridShopSell < Window_Selectable
  2867.  
  2868.   attr_accessor :goods
  2869.  
  2870.   def initialize
  2871.     super(0, 56, 366, 360)
  2872.     refresh
  2873.     self.visible = false
  2874.     self.index = 0
  2875.     self.active = false
  2876.   end
  2877.  
  2878.   def refresh
  2879.     @goods = $game_player.grid_monsters
  2880.     @item_max = @goods.size
  2881.     create_contents
  2882.     for i in 0...@item_max
  2883.       draw_goods(i)
  2884.     end
  2885.   end
  2886.  
  2887.   def draw_goods(index)
  2888.     rect = item_rect(index)
  2889.     rect.width += 8
  2890.     rect.x -= 4
  2891.     draw_icon(@goods[index].icon_id, 0, rect.y)
  2892.     self.contents.draw_text(26, rect.y, self.width - 32, WLH, @goods[index].name)
  2893.     nv = @goods[index].value / 4
  2894.     nx = ((self.width - 32) - self.contents.text_size(nv.to_s).width) - 26
  2895.     draw_icon(Ixfuru::GridWars::TOKEN_POINTS[2], nx, rect.y)
  2896.     self.contents.draw_text(nx + 26, rect.y, self.width - 32, WLH, nv.to_s)
  2897.   end
  2898.    
  2899. end
  2900.  
  2901. ################################################################################
  2902. #                        SCENE GRIDSHOP
  2903. ################################################################################
  2904. class Scene_GridShop < Scene_Base
  2905.  
  2906.   #-----------------------------------------------------------------------------
  2907.   # Initialize
  2908.   #-----------------------------------------------------------------------------
  2909.   def initialize(shop_id)
  2910.     @shop_id = shop_id
  2911.     @monster = nil
  2912.   end
  2913.  
  2914.   #-----------------------------------------------------------------------------
  2915.   # Start
  2916.   #-----------------------------------------------------------------------------
  2917.   def start
  2918.     super
  2919.     create_menu_background
  2920.     @win_options = Window_GridShopOptions.new
  2921.     @win_buy = Window_GridShopGoods.new(@shop_id)
  2922.     @win_sell = Window_GridShopSell.new
  2923.     @win_points = Window_GW_TokenPoints.new(364, 56, 180)
  2924.     @win_preview = Window_GW_MonsterPreview.new(nil, [364, 112, 180, 144])
  2925.   end
  2926.  
  2927.   #-----------------------------------------------------------------------------
  2928.   # Update
  2929.   #-----------------------------------------------------------------------------
  2930.   def update
  2931.     super
  2932.     if @win_buy.active
  2933.       update_buy
  2934.     elsif @win_sell.active
  2935.       update_sell
  2936.     elsif @win_options.active
  2937.       update_options
  2938.     end
  2939.   end
  2940.  
  2941.   #-----------------------------------------------------------------------------
  2942.   # Update Buy
  2943.   #-----------------------------------------------------------------------------
  2944.   def update_buy
  2945.     @win_buy.update
  2946.     @monster = @win_buy.tokens[@win_buy.index]
  2947.     unless @win_preview.monster == @monster
  2948.       @win_preview.monster = @monster
  2949.       @win_preview.refresh
  2950.     end
  2951.     if Input.trigger?(Input::C)
  2952.       if @win_buy.enabled?(@win_buy.index)
  2953.         Sound.play_shop
  2954.         $game_player.token_points -= @monster.value
  2955.         $game_player.add_shop_token(@monster)
  2956.         $gridshops[@shop_id].tokens.delete(@win_buy.index)
  2957.         $gridshops[@shop_id].renumerate_tokens
  2958.         @win_buy.refresh
  2959.         @win_points.refresh
  2960.       else
  2961.         Sound.play_buzzer
  2962.       end
  2963.     elsif Input.trigger?(Input::B)
  2964.       Sound.play_cancel
  2965.       @win_buy.active = false
  2966.       @win_options.active = true
  2967.       @win_buy.visible = false
  2968.       @win_preview.visible = false
  2969.     end
  2970.   end
  2971.  
  2972.   #-----------------------------------------------------------------------------
  2973.   # Update Sell
  2974.   #-----------------------------------------------------------------------------
  2975.   def update_sell
  2976.     @win_sell.update
  2977.     @monster = @win_sell.goods[@win_sell.index]
  2978.     if @win_preview.monster != @monster
  2979.       @win_preview.monster = @monster
  2980.       @win_preview.refresh
  2981.     end
  2982.     if Input.trigger?(Input::C)
  2983.       if !@monster.nil?
  2984.         Sound.play_shop
  2985.         $game_player.token_points += @monster.value / 4
  2986.         $gridshops[@shop_id].add_sold_token(@monster)
  2987.         $game_player.renumerate_tokens
  2988.         @win_buy.refresh
  2989.         @win_sell.refresh
  2990.         @win_points.refresh
  2991.         @win_options.refresh
  2992.       else
  2993.         Sound.play_buzzer
  2994.       end
  2995.     elsif Input.trigger?(Input::B)
  2996.       Sound.play_cancel
  2997.       @win_sell.active = false
  2998.       @win_options.active = true
  2999.       @win_sell.visible = false
  3000.       @win_preview.visible = false
  3001.     end
  3002.   end
  3003.  
  3004.   #-----------------------------------------------------------------------------
  3005.   # Update_Options
  3006.   #-----------------------------------------------------------------------------
  3007.   def update_options
  3008.     @win_options.update
  3009.     if Input.trigger?(Input::C)
  3010.       case @win_options.index
  3011.       when 0 # BUY
  3012.         Sound.play_decision
  3013.         @win_buy.active = true
  3014.         @win_options.active = false
  3015.         @win_buy.visible = true
  3016.         @win_preview.visible = true
  3017.       when 1 # SELL
  3018.         Sound.play_decision
  3019.         @win_sell.active = true
  3020.         @win_options.active = false
  3021.         @win_sell.visible = true
  3022.         @win_preview.visible = true
  3023.       when 2 # EXIT
  3024.         Sound.play_cancel
  3025.         $scene = Scene_Map.new
  3026.       end
  3027.     elsif Input.trigger?(Input::B)
  3028.       Sound.play_cancel
  3029.       $scene = Scene_Map.new
  3030.     end    
  3031.   end
  3032.  
  3033.   #-----------------------------------------------------------------------------
  3034.   # Terminate
  3035.   #-----------------------------------------------------------------------------
  3036.   def terminate
  3037.     super
  3038.     dispose_menu_background
  3039.     windows = [@win_buy, @win_sell, @win_options, @win_points]
  3040.     for window in windows
  3041.       window.dispose
  3042.     end
  3043.   end
  3044.  
  3045. end
  3046.  
  3047. ################################################################################
  3048. #                     WINDOW GRID SHOP MORPH
  3049. ################################################################################
  3050. class Window_GridShopMorph < Window_Base
  3051.  
  3052. end
  3053.  
  3054. ################################################################################
  3055. #                        WINDOW GRID SHOP LEVEL
  3056. ################################################################################
  3057. class Window_GridShopLevel < Window_Selectable
  3058.  
  3059. end
  3060.  
  3061. ################################################################################
  3062. #                    WINDOW TOKEN RENAMER
  3063. ################################################################################
  3064. class Window_TokenRenamerLetters < Window_Selectable
  3065.  
  3066.   RENAMER_LETTERS = {0 => ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
  3067.                            "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
  3068.                            "U", "V", "W", "X", "Y", "Z", " ", "BACK", "KEEP"],
  3069.                            
  3070.                     1 => ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
  3071.                           "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
  3072.                           "u", "v", "w", "x", "y", "z", " ", "BACK", "KEEP"]}
  3073.  
  3074.   attr_accessor :letters
  3075.   attr_accessor :lcase
  3076.  
  3077.   def initialize
  3078.     super(180, 0, 184, 152)
  3079.     @lcase = 0
  3080.     @spacing = 0
  3081.     refresh
  3082.     self.index = 0
  3083.     self.visible = false
  3084.     self.active = false
  3085.   end
  3086.  
  3087.   def refresh
  3088.     @letters = RENAMER_LETTERS[@lcase]
  3089.     @item_max = @letters.size
  3090.     @column_max = 6
  3091.     create_contents
  3092.     for i in 0...@item_max
  3093.       draw_letter(i)
  3094.     end
  3095.   end
  3096.  
  3097.   def draw_letter(index)
  3098.     rect = item_rect(index)
  3099.     self.contents.draw_text(rect, @letters[index])
  3100.   end
  3101.  
  3102. end
  3103.  
  3104.  
  3105. #################################################################################
  3106. #                             WINDOW TOKEN RENAMER PREVIEW
  3107. ################################################################################
  3108. class Window_TokenRenamerPreview < Window_Selectable
  3109.  
  3110.   attr_accessor :word
  3111.   attr_accessor :max_characters
  3112.  
  3113.   def initialize(max_characters = 14)
  3114.     super(180, 152, 184, 56)
  3115.     @word = []
  3116.     @max_characters = max_characters
  3117.     for i in 0...@max_characters
  3118.       @word.push(" ")
  3119.     end
  3120.     @item_max = @max_characters
  3121.     @column_max = @item_max
  3122.     @spacing = 0
  3123.     refresh
  3124.     self.index = 0
  3125.     self.active = false
  3126.     self.visible = false
  3127.   end
  3128.  
  3129.   def refresh
  3130.     create_contents
  3131.     for i in 0...@item_max
  3132.       draw_word_letter(i)
  3133.     end
  3134.   end
  3135.  
  3136.   def reset_word
  3137.     @word.clear
  3138.     for i in 0...@max_characters
  3139.       @word.push(" ")
  3140.     end
  3141.   end
  3142.  
  3143.   def draw_word_letter(index)
  3144.     rect = item_rect(index)
  3145.     self.contents.draw_text(rect, @word[index], 1)
  3146.   end
  3147.  
  3148. end
  3149.  
  3150. ################################################################################
  3151. #                                 WINDOW CONFIRMATION
  3152. ################################################################################
  3153. class Window_Confirmation < Window_Selectable
  3154.  
  3155.   attr_accessor :choices
  3156.  
  3157.   def initialize(choices = ["Yes", "No"])
  3158.     super(180, 148, 184, 80)
  3159.     @choices = choices
  3160.     refresh
  3161.     self.index = 1
  3162.     self.visible = false
  3163.     self.active = false
  3164.   end
  3165.  
  3166.   def refresh
  3167.     create_contents
  3168.     @item_max = @choices.size
  3169.     for i in 0...@item_max
  3170.       draw_choice(i)
  3171.     end
  3172.   end
  3173.  
  3174.   def draw_choice(index)
  3175.     rect = item_rect(index)
  3176.     self.contents.draw_text(rect, @choices[index], 1)
  3177.   end
  3178.  
  3179. end
  3180.  
  3181. ################################################################################
  3182. #                              SCENE FILE
  3183. ################################################################################
  3184. class Scene_File < Scene_Base
  3185.  
  3186.   #-----------------------------------------------------------------------------
  3187.   # Read Save Data(Aliased)
  3188.   #-----------------------------------------------------------------------------
  3189.   alias ixgwscflread read_save_data unless $@
  3190.   def read_save_data(file)
  3191.     ixgwscflread(file)
  3192.     $gridshops = Marshal.load(file)
  3193.   end
  3194.  
  3195.   #-----------------------------------------------------------------------------
  3196.   # Write Save Data(Aliased)
  3197.   #-----------------------------------------------------------------------------
  3198.   alias ixgwscflwrite write_save_data unless $@
  3199.   def write_save_data(file)
  3200.     ixgwscflwrite(file)
  3201.     Marshal.dump($gridshops,         file)
  3202.   end
  3203.  
  3204. end
Advertisement
Add Comment
Please, Sign In to add comment