Advertisement
CrowMakerVX

GridWars2_0

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