Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ################################################################################
- # GRID WARS v1.1
- # By: IXfuru
- ################################################################################
- #
- # This script adds a mini-game called GridWars to your project. The game is a
- # simulated battlefield board, where the side with the most occupied spaces at
- # the end of the battle wins. The game is played between the player and an
- # event. The system tracks GridWars record and GridPoints, which can then be
- # used to buy more 'monster tokens' for use on the battlefield board.
- #
- # In order to use the script, you must at least set up a few of the Settings
- # constants. And it is highly recommended that you create or find an iconset
- # graphic which has a good number of icons which can represent the tokens of the
- # GridWars System.
- #
- # First, set up the RANDOM_MONSTERS[:icon_pool] hash in section 1. You can
- # ignore the naming arrays, but it is imperative that you set up the icon
- # pool to select random icons from your own Iconset graphic. If you take the
- # Iconset from the demo, you don't have to change the array at all, as it is
- # set up to coordinate with that Iconset.
- #
- # Then, set up the OWNERS hash. This is the single most important setting
- # in the game. It's important because it is where you will set up the
- # AI opponents for the game.
- #
- # Whatever you do, make sure to follow the directions in the section you wish
- # to edit carefully.
- #
- #*******************************************************************************
- # As of now, there are two scenes, the manager and the GridWars battle scene.
- # The next version will feature the ability to rename the tokens, the ability
- # to buy/sell tokens, and perhaps the ability to level up the tokens
- # you have.
- #*******************************************************************************
- #
- ################################################################################
- # This script is not for commercial use without first gaining permission from
- # Ixfuru, the author. It is shared under the Creative Commons Non-Commercial
- # license. If you wish to use the script in your project, and intend it to
- # be commercial, you can post in the topic where you found this, or contact Ixfuru
- # via RpgMakerVX.net, Rpgmaker.net, Rpgmakerweb.com, Rmrk.net
- ################################################################################
- module Ixfuru
- module GridWars
- #===========================================================================
- # Section 1:
- #
- # RANDOM MONSTERS
- #
- # (A)
- #
- # This section is used to create 'pools' which can be used to generate the
- # properties of a random monster (or Token). The first four hashes are
- # used in the creation of random names:
- #
- # :first_letters : holds capital letters for being the first
- # letter in the random token's name. This
- # array is also drawn from in the middle of
- # the name for mid-name letters as well,
- # so the name is a little misleading. FOr
- # the most part, this array is set up the
- # way it should be. With every letter of the
- # English language as a possible.
- #
- # :vowels : holds the vowels of the English language. These
- # are also drawn from when creating names.
- #
- # :vowel_groupings : this holds vowels paired with other
- # letters.
- #
- # :const_groupings : this stores consanants of the alphabet
- # grouped with two or more other letters to
- # form common English combinations.
- #
- # For all of the above arrays, you can add to them by simply adding a
- # letter or letter in string form ("") double-quoted.
- #
- # (B)
- #
- # The last key in this hash, :icon_pool, is an important part of the settings
- # and will most often need modified. Basically, the array here consists
- # of icon indices from the Iconset graphic in your system folder. As tokens
- # (monsters) are represented in the game by icons, you will need an Iconset
- # graphic which contains images you want to use as tokens. Once you have
- # the graphic you want, you then need to find and list each icon's index on
- # the graphic which is used for representation. There are quite a few
- # programs/scripts for finding the index of an icon out there. Omegas7 and
- # Woratana both made one. Search them out.
- #
- # As a tip, you could arrange all the 'token' icons on the Iconset sheet
- # together and then find the index of the first and the index of the last
- # respectively. Then you could use my NumericListBetwixter here:
- #
- # http://www.rpgmakervx.net/index.php?showtopic=53111
- #
- # With that tool, you are able to input the first and last numbers of a long
- # list of numbers, and it will write them as common separated values perfect
- # for use in arrays. Then you just import/copy/paste to your project.
- #
- # However you do it, just make sure you fill the :icon_pool array with
- # many different token-representing icon_ids. The more you add, the larger
- # number of random tokens will appear on your GridWars battlefield.
- #
- #===========================================================================
- RANDOM_MONSTERS = {
- :first_letters => ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L",
- "M", "N", "O", "P", "Qu", "R", "S", "T", "U", "V", "W",
- "X", "Y", "Z"],
- :vowels => ["a", "e", "i", "o", "u"],
- :vowel_groupings => ["ar", "er", "ir", "or", "ur", "ai", "ee", "ae", "au",
- "ao", "eo", "ea", "aa", "eu", "ia", "ie", "io", "oo",
- "oa", "oe", "ou", "oi", "ua", "ue", "ui", "uo"],
- :const_groupings => ["br", "bl", "bb", "ch", "cl", "cr", "chr", "ck",
- "dr", "dd", "dw", "ff", "fr", "fl", "ft",
- "gr", "gl", "gg", "kr", "kl", "ll", "mm", "nn",
- "ph", "pl", "pr", "pp", "qu", "rr", "st", "sch", "sh",
- "sc", "str", "sl", "shr", "sm", "sn", "sp", "spr",
- "sk", "skr", "sw", "tr", "th", "thr", "ss", "tt",
- "xx", "zz", "mp", "nk", "nt", "mb", "nc", "nd", "ng",
- "ny", "my", "cy", "dy", "fy", "ly", "ry"],
- :icon_pool => [368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379,
- 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394,
- 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409,
- 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424,
- 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439,
- 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454,
- 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469,
- 470, 471, 472, 473, 474, 475, 476, 477, 478, 479],
- }
- #===========================================================================
- # Section 2:
- #
- # MONSTERS
- #
- # This section allows you to create SPECIFIC monsters. Those that you will
- # use in your project and give to certain characters, or the player. These
- # are monsters which you intend to be unique tokens in the project.
- #
- # For these, you get to set the properties by linking them in the hash
- # to a unique token_ID.
- #
- # Here are the properties:
- #
- # :name : string used as the name of the token
- # :atk : integer Preferaby form 1-10
- # :def, :dodge, :accuracy : same as :atk
- #
- # Refer to Section 7 (SCRIPT CALLS) for information pertaining to how to
- # give a specific card from the hash to the player or another character.
- #
- #
- #===========================================================================
- MONSTERS = {
- #token_id => {:name => string,
- # :icon_id => integer,
- # :atk => integer,
- # :def => integer,
- # :dodge => integer,
- # :accuracy => integer}
- 0 => {:name => "Ofert",
- :icon_id => 413,
- :atk => 4,
- :def => 6,
- :dodge => 7,
- :accuracy => 2},
- 1 => {:name => "Rodango",
- :icon_id => 376,
- :atk => 3,
- :def => 4,
- :dodge => 3,
- :accuracy => 5},
- 2 => {:name => "Crypto",
- :icon_id => 457,
- :atk => 5,
- :def => 5,
- :dodge => 5,
- :accuracy => 5},
- 3 => {:name => "Flotoger",
- :icon_id => 395,
- :atk => 3,
- :def => 3,
- :dodge => 1,
- :accuracy => 4},
- }
- #===========================================================================
- # Section 3:
- #
- # OWNERS
- #
- # This section is crucial to using the script. Owners are the events which
- # possess tokens of their own and are therefor able to duel against the
- # player in GridWars matches.
- #
- # In order to set up for an event to be used, you need to provide a
- # listing of it in the OWNERS hash.
- #
- # For starters, for every map which has an event capable of GridWars
- # participation, you need to have an outer hash_key of the map's ID.
- #
- # Each of these IDS are subsequently linked to an inner hash, which consists
- # of every ID on the said map which is able to participate in GridWars.
- #
- # So you have:
- #
- # 7 => {3 => [],
- # 8 => [],
- # 28 => []},
- #
- # So in the above example, you have events 3, 8 and 28 on map 7 able to
- # participate. This means that if you are not on map # 7 and you try to
- # battle event 28, you will receive an error message. You must be on the
- # right map to call a GridWars match.
- #
- # Once you have this set up, you need to fill in the arrays '[]' associated
- # with each event_id. To do this, you will be using three elements.
- #
- # [stars, name, start_record]
- #
- # stars : this number is given to represent how strong the character's
- # token set will be. This number should NOT exceed 5, preferably
- # and not be below 1. A five star token set, will hold tokens
- # with ATK, DEF, DDG and ACC of up to 10, as the max for each
- # parameter is calculated by multiplying the 'stars' rating by 2.
- #
- # :name : This is the name you wish to be displayed when the GridWars
- # battle is taking place.
- #
- # :start_record : This is a three-element array [wins, losses, ties]
- # This tells what you want the character's GridWars record
- # when the game starts.
- #
- #============================================================================
- OWNERS = {
- #map_id => {event_id => [stars, name, start_record]}
- 1 => {2 => [1, "Whinny", [13, 12, 2]],
- 3 => [3, "Nancy", [4, 5, 0]],
- 5 => [5, "Ixfuru", [18, 2, 1]]},
- }
- #===========================================================================
- # Section 4:
- #
- # SOUNDS
- #
- # This hash is used to store the sound_effects you wish to use inside the
- # GridWars system. For each entry, you need to add a three-element array.
- #
- # [filename, volume, pitch]
- #
- #===========================================================================
- SOUNDS = {
- :place_card => ["Ice9", 80, 150], # sound played when a card is placed
- :selection => ["Decision2", 80, 100], # sound played when selection is made
- :attacking => ["Attack1", 80, 100], # sound played when attack is made
- :defending => ["Flash1", 80, 100], # sound played when a defense is made
- :dodging => ["Sword3", 80, 100], # sound played when dodge is made
- :quickset => ["Raise3", 80, 100], # sound played when the quickset is called
- :missing => ["Miss", 80, 100], # sound played when an attack misses
- :gp_threshold => ["Recovery", 80, 150], # sound played when a token reaches gp threshold
- :letter_input => ["Equip", 80, 200], # sound played when a letter is input
- :shiftkey => ["Switch3", 80, 50], # sound played when shifting the letter case
- :eraser => ["Wind7", 80, 100], # sound played when a letter is erased
- :delete_token => ["Collapse1", 80, 220], # sound played when a token deleted
- }
- #===========================================================================
- # Section 5:
- #
- # Musics
- #
- # This is the same as the hash from section 4, however, its used to store
- # Music Effects, not sound effects.
- #
- #===========================================================================
- MUSICS = {
- :victory => ["Fanfare1", 80, 100],
- :defeat => ["Item", 80, 100],
- :tie => ["Gag", 80, 100],
- }
- #===========================================================================
- # Section 6:
- #
- # MISCELLANEOUS
- #
- # The following are a handful of other non-specific values which are used
- # by the system and which can be altered here.
- #
- #===========================================================================
- ATTACK_ANIMATION = 40 # The database animation ID run when Attack is made
- PLAYER_FIELD_COLOR = 5 # # The color representing a player's token on the field
- OPPONENT_FIELD_COLOR = 2 # The color representing an event's token on the field
- QUICK_SET_TAG_COLOR = 14 # The color used to represent a token is in the quick set
- HIDDEN_OPPONENT_ICON_INDEX = 240 # the icon_index of the icon used to represent
- # an event's token before it is revealed
- BASE_VALUE = 100 # This is the gold value which is multiplied by the
- # 'star's of a given token to determine a price
- WAIT_COUNT = 90 # This is how long in frames the AI takes to make specific
- # decisions
- TARGET_COLOR = 3 # This is the color shown representing a token which can be
- # a target
- QUICKSET_COLOR = 23 # This is the color that denotes a card is in the Quickset
- GWBGM = ["Battle8", 80, 100] # This will be the music played during GridWars Matches
- # Token Points are the 'currency used to purchase new Tokens. Upon winning a
- # GridWars Match, you are rewarded your score - your opponent's score in
- # Token Points. These points can be turned in at special shops to purchase
- # new tokens for your playable set.
- # [Displayable name of Token Points, the abbreviation displayed, the icon_id]
- TOKEN_POINTS = ["Token Points", "TP", 85]
- NEW_SHOP_TOKEN_AMOUNT = 20
- # The following three colors, referenced by integers (0-32), are used in
- # the drawing of the GP Gauge when viewing the parameters of a token.
- # The 'GP_GAUGE_COLORBACK' is used as the color behind the two colors which
- # make up the gauge bar.
- GP_GAUGE_COLOR1 = 24
- GP_GAUGE_COLOR2 = 17
- GP_GAUGE_COLORBACK = 7
- #===========================================================================
- # Section 7:
- #
- # SCRIPT CALLS
- #
- # The following section is used for a reference to the creator of the project
- # to illustrate in detail how the script can be used. Use of the script
- # requires the creator to make 'script calls' from the third page of
- # an event's commands, or a common event's commands. Enter the
- # following script calls.
- #
- ##---------------------------------------------------------------------------
- #
- # 1. Call the GridWars Battle Scene:
- #
- # $scene = Scene_GridWars.new(owner_id)
- #
- # In this call, you need to replace the 'owner_id' deal with an ID of
- # an OWNER you set up in the OWNERS hash.
- # -don't call this scene unless the owner_id exists
- #
- ##---------------------------------------------------------------------------
- #
- # 2. Call the TokenManager Scene:
- #
- # $scene = Scene_TokenManager.new(owner_id)
- #
- # This call the will take the player to the scene where he/she can set up,
- # delete and otherwise manage their tokens.
- #
- ##---------------------------------------------------------------------------
- #
- # 3. Check to see if the Player won the last match
- #
- # $game_system.won_last_grid?
- #
- # This is a great call for a conditional branch. As it will return
- # true if the player won the last match they were part of. This
- # makes it so that the creator can make things happen upon victory.
- #
- # !$game_system.won_last_grid?
- #
- # Use that to check if the player DID NOT win the last GridWars match
- #
- ##---------------------------------------------------------------------------
- #
- # 4. Create a Token set for the player/event
- #
- # $game_player.new_grid_tokens(stars)
- # or
- # $game_events[x].new_grid_tokens(stars)
- #
- # These calls will render a new deck to the player or the event in question
- # respectively. This gives 45 randomly generated tokens to the said
- # target. It is very important that you DO NOT GIVE THE PLAYER A NEW
- # TOKEN SET twice. This can cause bad problems with the script.
- #
- ##---------------------------------------------------------------------------
- #
- # 5. Check Wins/Losses/Ties
- #
- # $game_player.grid_wins
- # or
- # $game_map.events[x].grid_wins
- #
- # .grid_losses
- # .grid_ties
- # .grid_matches
- #
- # These calls will return the value of whatever part of the GridWars
- # record you specify. Say you want to set up an event for when a player
- # wins 10 matches, these calls enable you to do that.
- # -the .grid_matches call will return total matches played
- #
- ##---------------------------------------------------------------------------
- #
- # 6. Give a new token
- #
- # $game_player.add_token(stars)
- # or
- # $game_map.events[x].add_token(stars)
- #
- # These are the calls you place in order to add a new token to the
- # player or event in question. This gives a randomly generated token.
- #
- #---------------------------------------------------------------------------
- #
- # 7. Give a specific token from those found in the MONSTERS hash
- #
- # $game_player.add_special_token(stars, token_id)
- #
- # This does the exact same thing as #6, however, it creates a
- # token based on the one in the MONSTERS hash whose token_id matches
- # that given to the method as a second argument. The 'stars' part
- # here can be passed as any value 1-5.
- #
- #----------------------------------------------------------------------------
- # 8. Give the event/player a new pack of tokens
- #
- # $game_player.new_token_pack(stars)
- # or
- # $game_map.events[x].new_token_pack(stars)
- #
- #===========================================================================
- #===========================================================================
- # Section 8:
- #
- # TOKEN SHOPS
- #
- #===========================================================================
- TOKEN_SHOPS = {
- #shop_id => {:tokens => [token_ids] # USE "R" for a randomly generated token
- # :max_stars => maximum stars for tokens generated
- 0 => {:tokens => [0, 1, 2, "R", "R", "R", "R", "R", "R", "R"],
- :max_stars => 3},
- }
- #===========================================================================
- # Section 9:
- #
- # TOKEN GROWTH CHART
- #
- # This section give you complete control over how fast the monster tokens
- # devolop. Each time a token gets a 'kill' in combat, they are awarded
- # the 'star value' of the token it slays (price value / BASE_VALUE). These
- # points are added to the token's 'GP' or "Growth Points". When the token
- # has stored enough GP, they are awarded an "Parameter Point" which can
- # be added, via the Token Manager scene, to the token's parameters.
- #
- #===========================================================================
- TOKEN_GROWTH_CHART = [0, 10, 25, 45, 70, 100, 135, 175, 220, 270, 325, 385,
- 450, 520, 595, 675, 760, 850, 945, 1045, 1150]
- end
- end
- ################################################################################
- # GAME SYSTEM
- ################################################################################
- class Game_System
- attr_accessor :grid_monsters
- attr_accessor :last_grid_result
- #------------------------------------------------------------------------------
- # Initialize (Aliased)
- #-----------------------------------------------------------------------------
- alias ixgwgsini initialize unless $@
- def initialize
- ixgwgsini
- @grid_monsters = {}
- @last_grid_result = -1
- end
- #-----------------------------------------------------------------------------
- # Won Last Grid?
- #-----------------------------------------------------------------------------
- def won_last_grid?
- return @last_grid_result == 0
- end
- #------------------------------------------------------------------------------
- # Update ( Aliased)
- #-----------------------------------------------------------------------------
- alias ixgwgsupdate update unless $@
- def update
- ixgwgsupdate
- $gridshops = {} if $gridshops.nil?
- @grid_monsters = {} if @grid_monsters.nil?
- @last_grid_result = -1 if @last_grid_result.nil?
- end
- end
- ################################################################################
- # GAME PLAYER
- ################################################################################
- class Game_Player < Game_Character
- attr_accessor :grid_monsters
- attr_accessor :token_points
- attr_accessor :grid_record
- attr_accessor :quick_tokens # A set of grid monsters that can be called quickly
- #-----------------------------------------------------------------------------
- # Initialize (Aliased)
- #-----------------------------------------------------------------------------
- alias ixgwarsgmplyrini initialize unless $@
- def initialize
- ixgwarsgmplyrini
- @grid_monsters = {}
- @quick_tokens = {}
- @token_points = 0
- @grid_record = [0, 0, 0]
- end
- #-----------------------------------------------------------------------------
- # Grid Wins
- #-----------------------------------------------------------------------------
- def grid_wins
- return @grid_record[0]
- end
- #-----------------------------------------------------------------------------
- # Grid Losses
- #-----------------------------------------------------------------------------
- def grid_losses
- return @grid_record[1]
- end
- #-----------------------------------------------------------------------------
- # Grid Ties
- #-----------------------------------------------------------------------------
- def grid_ties
- return @grid_record[2]
- end
- #-----------------------------------------------------------------------------
- # Grid Matches
- #-----------------------------------------------------------------------------
- def grid_matches
- return @grid_record[0] + @grid_record[1] + @grid_record[2]
- end
- #------------------------------------------------------------------------------
- # New Special Token
- #-----------------------------------------------------------------------------
- def new_special_token(stars, token_id)
- @grid_monsters[@grid_monsters.size] = GridMonster.new(1, token_id)
- end
- #-----------------------------------------------------------------------------
- # Add Token
- #-----------------------------------------------------------------------------
- def add_token(stars)
- @grid_monsters[@grid_monsters.size] = GridMonster.new(stars)
- end
- #-----------------------------------------------------------------------------
- # Add Shop Token
- #-----------------------------------------------------------------------------
- def add_shop_token(token)
- @grid_monsters[@grid_monsters.size] = token
- end
- #-----------------------------------------------------------------------------
- # Get Grid Monsters
- #-----------------------------------------------------------------------------
- def get_grid_monsters(stars)
- @grid_monsters = {} if @grid_monsters.nil?
- new_grid_tokens(stars) if @grid_monsters = {}
- end
- #-----------------------------------------------------------------------------
- # New Grid Tokens
- #-----------------------------------------------------------------------------
- def new_grid_tokens(stars)
- for i in 0...45
- @grid_monsters[i] = GridMonster.new(stars)
- end
- end
- #-----------------------------------------------------------------------------
- # Grid Name
- #-----------------------------------------------------------------------------
- def grid_name
- return $game_party.members[0].name
- end
- #-----------------------------------------------------------------------------
- # New Token Pack
- #-----------------------------------------------------------------------------
- def new_token_pack(token_count, stars)
- gmi = @grid_monsters.size
- for i in 0...token_count
- @grid_monsters[gmi] = GridMonster.new(stars)
- gmi += 1
- end
- end
- #-----------------------------------------------------------------------------
- # Renumerate Tokens
- #-----------------------------------------------------------------------------
- def renumerate_tokens
- new_monsters = {}
- i = 0
- @grid_monsters.each { |index, monster|
- next if monster.nil?
- new_monsters[i] = monster
- i += 1
- }
- @grid_monsters = new_monsters
- unless @quick_tokens.nil?
- new_quicks = {}
- i = 0
- @quick_tokens.each { |index, monster|
- next if monster.nil?
- new_quicks[i] = monster
- i += 1
- }
- end
- @quick_tokens = new_quicks
- end
- end
- ################################################################################
- # GAME EVENT
- ################################################################################
- class Game_Event < Game_Character
- attr_accessor :grid_monsters
- attr_accessor :grid_record
- #-----------------------------------------------------------------------------
- # Initialize (Aliased)
- #-----------------------------------------------------------------------------
- alias ixgwarsgmeventini initialize unless $@
- def initialize(map_id, event)
- ixgwarsgmeventini(map_id, event)
- @grid_record = []
- end
- #-----------------------------------------------------------------------------
- # Get Grid Monsters
- #-----------------------------------------------------------------------------
- def get_grid_monsters
- @grid_monsters = {} if @grid_monsters.nil?
- @grid_monsters = {} if !Ixfuru::GridWars::OWNERS.include?(@map_id)
- @grid_monsters = {} if !Ixfuru::GridWars::OWNERS[@map_id].include?(@event.id)
- new_grid_tokens(Ixfuru::GridWars::OWNERS[@map_id][@event.id][0]) if @grid_monsters.empty?
- rec = Ixfuru::GridWars::OWNERS[@map_id][@event.id][2]
- @grid_record = [rec[0], rec[1], rec[2]] if @grid_record.empty?
- end
- #-----------------------------------------------------------------------------
- # Grid Name
- #-----------------------------------------------------------------------------
- def grid_name
- return "" if !Ixfuru::GridWars::OWNERS.include?(@map_id)
- return "" if !Ixfuru::GridWars::OWNERS[@map_id].include?(@event.id)
- return Ixfuru::GridWars::OWNERS[@map_id][@event.id][1]
- end
- #-----------------------------------------------------------------------------
- # New Grid Tokens
- #-----------------------------------------------------------------------------
- def new_grid_tokens(stars)
- for i in 0...45
- @grid_monsters[i] = GridMonster.new(stars)
- end
- end
- #-----------------------------------------------------------------------------
- # Grid Wins
- #-----------------------------------------------------------------------------
- def grid_wins
- return @grid_record[0]
- end
- #-----------------------------------------------------------------------------
- # Grid Losses
- #-----------------------------------------------------------------------------
- def grid_losses
- return @grid_record[1]
- end
- #-----------------------------------------------------------------------------
- # Grid Ties
- #-----------------------------------------------------------------------------
- def grid_ties
- return @grid_record[2]
- end
- #-----------------------------------------------------------------------------
- # Grid Matches
- #-----------------------------------------------------------------------------
- def grid_matches
- return @grid_record[0] + @grid_record[1] + @grid_record[2]
- end
- #------------------------------------------------------------------------------
- # New Special Token
- #-----------------------------------------------------------------------------
- def new_special_token(stars, token_id)
- @grid_monsters[@grid_monsters.size] = GridMonster.new(1, token_id)
- end
- #-----------------------------------------------------------------------------
- # New Token
- #-----------------------------------------------------------------------------
- def add_token(stars)
- @grid_monsters[@grid_monsters.size] = GridMonster.new(stars)
- end
- #-----------------------------------------------------------------------------
- # New Token Pack
- #-----------------------------------------------------------------------------
- def new_token_pack(token_count, stars)
- gmi = @grid_monsters.size
- for i in 0...token_count
- @grid_monsters[gmi] = GridMonster.new(stars)
- gmi += 1
- end
- end
- #-----------------------------------------------------------------------------
- # Renumerate Tokens
- #-----------------------------------------------------------------------------
- def renumerate_tokens
- new_monsters = {}
- i = 0
- @grid_monsters.each { |index, monster|
- next if monster.nil?
- new_monsters[i] = monster
- i += 1
- }
- @grid_monsters = new_monsters
- end
- end
- ################################################################################
- # SCENE BASE
- ################################################################################
- class Scene_Base
- #-----------------------------------------------------------------------------
- # Play Grid Sound
- #-----------------------------------------------------------------------------
- def play_grid_sound(sound)
- se = Ixfuru::GridWars::SOUNDS[sound]
- RPG::SE.new(se[0], se[1], se[2]).play
- end
- #-----------------------------------------------------------------------------
- # Play Grid Music
- #-----------------------------------------------------------------------------
- def play_grid_music(music)
- se = Ixfuru::GridWars::MUSICS[music]
- RPG::ME.new(se[0], se[1], se[2]).play
- end
- end
- ################################################################################
- # GRID MONSTERS
- ################################################################################
- class GridMonster
- attr_accessor :name
- attr_reader :grid_id
- attr_reader :icon_id
- attr_accessor :atk
- attr_accessor :def
- attr_accessor :acc
- attr_accessor :ddg
- attr_accessor :attacking
- attr_accessor :defending
- attr_accessor :dodging
- attr_accessor :set
- attr_reader :stars
- attr_accessor :target
- attr_accessor :boost
- attr_accessor :value
- attr_reader :gp # use 'add_gp' method to change gp amounts
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize(stars = 1, monster_id = nil)
- @stars = stars
- if monster_id.nil?
- @name = generated_monster_name
- @icon_id = generated_monster_icon
- @atk = (rand(@stars * 2) + 1).to_i
- @def = (rand(@stars * 2) + 1).to_i
- @acc = (rand(@stars * 2) + 1).to_i
- @ddg = (rand(@stars * 2) + 1).to_i
- else
- monsters = Ixfuru::GridWars::MONSTERS
- @name = monsters[monster_id][:name]
- @icon_id = monsters[monster_id][:icon_id]
- @atk = monsters[monster_id][:atk]
- @def = monsters[monster_id][:def]
- @acc = monsters[monster_id][:accuracy]
- @ddg = monsters[monster_id][:dodge]
- end
- @grid_id = generated_grid_id
- @value = generated_monster_value
- @gp = starting_gp
- @parameter_pts = 0
- reset
- save_monster
- end
- #-----------------------------------------------------------------------------
- # Starting GP
- #-----------------------------------------------------------------------------
- def starting_gp
- star_value = @value / Ixfuru::GridWars::BASE_VALUE
- return Ixfuru::GridWars::TOKEN_GROWTH_CHART[star_value * 2]
- end
- #-----------------------------------------------------------------------------
- # Add GP
- #-----------------------------------------------------------------------------
- def add_gp(amount)
- threshold = next_gp_threshold
- @gp += amount
- if @gp >= threshold
- $scene = play_grid_sound(:gp_threshold)
- @parameter_pts += 1
- end
- end
- #-----------------------------------------------------------------------------
- # Next GP Threshold
- #-----------------------------------------------------------------------------
- def next_gp_threshold
- chart = Ixfuru::GridWars::TOKEN_GROWTH_CHART
- for i in 0...chart.size
- break if i + 1 >= chart.size
- if @gp >= chart[i] && @gp < chart[i + 1]
- return chart[i + 1]
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Save Monster
- #-----------------------------------------------------------------------------
- def save_monster
- $game_system.grid_monsters[@grid_id] = self
- end
- #-----------------------------------------------------------------------------
- # Reset
- #-----------------------------------------------------------------------------
- def reset
- @attacking = false
- @dodging = false
- @defending = false
- @set = false
- @target = nil
- @boost = 0
- end
- #-----------------------------------------------------------------------------
- # Generated Monster Value
- #-----------------------------------------------------------------------------
- def generated_monster_value
- n = @atk + @def + @acc + @ddg
- return n * Ixfuru::GridWars::BASE_VALUE / 4
- end
- #-----------------------------------------------------------------------------
- # Generated Grid ID
- #-----------------------------------------------------------------------------
- def generated_grid_id
- return $game_system.grid_monsters.size
- end
- #-----------------------------------------------------------------------------
- # Generated Monster Icon
- #-----------------------------------------------------------------------------
- def generated_monster_icon
- icons = Ixfuru::GridWars::RANDOM_MONSTERS[:icon_pool]
- return icons[rand(icons.size)]
- end
- #-----------------------------------------------------------------------------
- # Generated Monster Name
- #-----------------------------------------------------------------------------
- def generated_monster_name
- parts = rand(5) + 1
- firsts = Ixfuru::GridWars::RANDOM_MONSTERS[:first_letters]
- vowels = Ixfuru::GridWars::RANDOM_MONSTERS[:vowels]
- vowel_groupings = Ixfuru::GridWars::RANDOM_MONSTERS[:vowel_groupings]
- groups = Ixfuru::GridWars::RANDOM_MONSTERS[:const_groupings]
- fl = firsts[rand(firsts.size)]
- if vowels.include?(fl.downcase)
- g = rand(2)
- case g
- when 0
- sl = firsts[rand(firsts.size)] + vowels[rand(vowels.size)]
- when 1
- sl = groups[rand(groups.size)] + vowels[rand(vowels.size)]
- end
- else
- vg = rand(12)
- if vg <= 10
- sl = vowels[rand(vowels.size)]
- else
- sl = vowel_groupings[rand(vowel_groupings.size)]
- end
- end
- ending = []
- for i in 0...parts
- case i
- when 0, 2
- vg = rand(12)
- if vg <= 10
- ending.push(vowels[rand(vowels.size)])
- else
- ending.push(vowel_groupings[rand(vowel_groupings.size)])
- end
- when 1, 3, 4
- g = rand(2)
- case g
- when 0
- ending.push(firsts[rand(firsts.size)].downcase)
- when 1
- ending.push(groups[rand(groups.size)])
- end
- end
- end
- n = fl + sl + ending.to_s
- return n
- end
- end
- ################################################################################
- # WINDOW MONSTER PREVIEW
- ################################################################################
- class Window_GW_MonsterPreview < Window_Base
- attr_accessor :monster
- def initialize(monster, dimensions = [])
- if dimensions.empty?
- super(180, 273, 184, 144)
- else
- super(dimensions[0], dimensions[1], dimensions[2], dimensions[3])
- end
- @monster = monster
- refresh
- self.visible = false
- self.z = 160
- end
- def refresh
- self.contents.clear
- return if @monster.nil?
- self.contents.font.size = 12
- lh = 16
- self.contents.font.color = power_up_color
- self.contents.draw_text(0, 0, self.width - 32, lh, @monster.name, 1)
- draw_icon(@monster.icon_id, 0, lh)
- draw_gp_gauge(26, lh, (self.width - 58), 12)
- self.contents.font.color = system_color
- tags = ["ATK", "DEF", "ACC", "DDG"]
- ly = lh + WLH
- for tag in tags
- self.contents.draw_text(30, ly, self.width - 32, lh, tag)
- ly += lh
- end
- self.contents.font.color = normal_color
- pars = [@monster.atk, @monster.def, @monster.acc, @monster.ddg]
- ly = lh + WLH
- for par in pars
- self.contents.draw_text(90, ly, self.width - 32, lh, par.to_s)
- ly += lh
- end
- end
- #-----------------------------------------------------------------------------
- # Draw GP Gauge
- #-----------------------------------------------------------------------------
- def draw_gp_gauge(x, y, width, height)
- c1 = text_color(Ixfuru::GridWars::GP_GAUGE_COLOR1)
- c2 = text_color(Ixfuru::GridWars::GP_GAUGE_COLOR2)
- cb = text_color(Ixfuru::GridWars::GP_GAUGE_COLORBACK)
- gw = (width * @monster.gp) / @monster.next_gp_threshold
- self.contents.fill_rect(x, y + 6, width, height, cb)
- self.contents.gradient_fill_rect(x, y + 8, gw, height - 4, c1, c2)
- end
- end
- ################################################################################
- # WINDOW MONSTER LIST
- ################################################################################
- class Window_GW_MonsterList < Window_Selectable
- attr_accessor :monsters
- def initialize(owner_id)
- if owner_id == 0
- @owner = $game_player
- super(0, 56, 180, 304)
- elsif owner_id.nil?
- super(364, 56, 180, 304)
- @owner = nil
- elsif owner_id > 0
- @owner = $game_map.events[owner_id]
- super(364, 56, 180, 304)
- end
- refresh
- self.index = 0
- self.active = false
- end
- def refresh
- if !@owner.nil?
- @monsters = @owner.grid_monsters
- else
- @monsters = $game_player.quick_tokens
- end
- @item_max = @monsters.size
- create_contents
- return if @item_max == 0
- for i in 0...@item_max
- next if @monsters[i].nil?
- draw_monster(i)
- end
- end
- def enabled?(index)
- return true if @owner.nil?
- return false if @owner.grid_monsters[index].set
- return true
- end
- def draw_monster(index)
- rect = item_rect(index)
- if !@owner.nil?
- draw_icon(@owner.grid_monsters[index].icon_id, rect.x, rect.y, enabled?(index))
- self.contents.font.color.alpha = enabled?(index) ? 255 : 128
- self.contents.draw_text(rect.x + 26, rect.y, self.width - 32, WLH,
- @owner.grid_monsters[index].name)
- if @owner.is_a?(Game_Player) &&
- $game_player.quick_tokens.has_value?(@owner.grid_monsters[index])
- fc = Ixfuru::GridWars::QUICKSET_COLOR
- self.contents.fill_rect((self.width - 32) - 12, rect.y + 6, 12, 12, text_color(fc))
- end
- else
- draw_icon($game_player.quick_tokens[index].icon_id, rect.x, rect.y, enabled?(index))
- self.contents.font.color.alpha = enabled?(index) ? 255 : 128
- self.contents.draw_text(rect.x + 26, rect.y, self.width - 32, WLH,
- $game_player.quick_tokens[index].name)
- end
- end
- end
- ################################################################################
- # WINDOW SCORE
- ################################################################################
- class Window_GW_Score < Window_Base
- attr_accessor :owner
- attr_accessor :points
- def initialize(owner_id = 0)
- case owner_id
- when 0
- super(0, 360, 180, 56)
- @owner = $game_player
- when 1
- super(364, 360, 180, 56)
- @owner = $game_map.events[owner_id]
- end
- @points = 0
- refresh
- end
- def refresh
- self.contents.clear
- self.contents.draw_text(0, 0, self.width - 32, WLH, @points.to_s, 1)
- end
- end
- ################################################################################
- # WINDOW FIELD
- ################################################################################
- class Window_GW_Field < Window_Selectable
- attr_accessor :field_monsters
- attr_accessor :target_indices
- # field_monsters : {index = [monster, owner, moved?, x, y]}
- def initialize
- super(181, 0, 184, 272)
- @field_monsters = {}
- @target_indices = []
- @item_max = 60
- @column_max = 6
- @spacing = 0
- refresh
- self.index = 0
- self.active = false
- end
- def refresh
- create_contents
- for i in 0...@item_max
- draw_field_monsters(i)
- end
- end
- def enabled?(index)
- return false if @field_monsters[index][2]
- return true
- end
- def draw_field_monsters(index)
- rect = item_rect(index)
- return if @field_monsters[index].nil?
- @field_monsters[index][3] = rect.x
- @field_monsters[index][4] = rect.y
- monster = @field_monsters[index][0]
- return if monster.nil?
- if @field_monsters[index][1].is_a?(Game_Player)
- fc = Ixfuru::GridWars::PLAYER_FIELD_COLOR
- self.contents.fill_rect(rect.x + 2, rect. y + 2, rect.width - 4, rect.height - 4, text_color(fc))
- draw_icon(monster.icon_id, rect.x, rect.y, enabled?(index))
- else
- fc = Ixfuru::GridWars::OPPONENT_FIELD_COLOR
- self.contents.fill_rect(rect.x + 2, rect. y + 2, rect.width - 4, rect.height - 4, text_color(fc))
- if @field_monsters[index][2]
- draw_icon(monster.icon_id, rect.x, rect.y, false)
- else
- draw_icon(Ixfuru::GridWars::HIDDEN_OPPONENT_ICON_INDEX, rect.x, rect.y)
- end
- end
- self.contents.font.size = 12
- lh = 16
- if monster.attacking
- self.contents.font.color = text_color(10)
- self.contents.draw_text(rect.x + 12, rect.y, self.width - 32, lh, "A")
- elsif monster.defending
- self.contents.font.color = text_color(16)
- self.contents.draw_text(rect.x + 12, rect.y, self.width - 32, lh, "D")
- elsif monster.dodging
- self.contents.font.color = text_color(27)
- self.contents.draw_text(rect.x + 12, rect.y, self.width - 32, lh, "E")
- end
- if @target_indices.include?(index)
- tc = text_color(Ixfuru::GridWars::TARGET_COLOR)
- self.contents.fill_rect(rect.x + 6, rect.y + 6, 12, 12, tc)
- end
- self.contents.font.color = normal_color
- end
- end
- ################################################################################
- # WINDOW TOKEN COMMANDS
- ################################################################################
- class Window_GW_TokenCommands < Window_Selectable
- def initialize
- super(180, 273, 184, 144)
- @commands = ["ATTACK", "DEFEND", "DODGE"]
- @item_max = 3
- refresh
- self.visible = false
- self.active = false
- self.index = 0
- end
- def refresh
- create_contents
- for i in 0...@item_max
- draw_command(i)
- end
- end
- def draw_command(index)
- rect = item_rect(index)
- self.contents.draw_text(rect, @commands[index], 1)
- end
- end
- ################################################################################
- # WINDOW TOKEN COUNT
- ################################################################################
- class Window_GW_TokenCount < Window_Base
- attr_accessor :required_amount
- def initialize
- super(180, 273, 184, 144)
- @required_amount = 30
- refresh
- end
- def refresh
- self.contents.clear
- self.contents.draw_text(0, 0, self.width - 32, WLH, "Select " + required_amount.to_s + " more tokens.")
- end
- end
- ################################################################################
- # WINDOW SIMULATION
- ################################################################################
- class Window_GW_Simulation < Window_Base
- attr_accessor :monster
- attr_accessor :action
- def initialize
- super(180, 273, 184, 144)
- @monster = nil
- @action = 0 # 0 for attack, 1 for defend, 2 for dodge
- refresh
- self.visible = false
- end
- def refresh
- self.contents.clear
- return if @monster.nil?
- draw_icon(@monster[0].icon_id, 0, 0)
- case @action
- when 0
- act_string = "attacking"
- when 1
- act_string = "defending"
- when 2
- act_string = "dodging"
- end
- lines = [@monster[0].name, "is", act_string]
- ly = 0
- for i in 0...lines.size
- self.contents.draw_text(26,ly, self.width - 32, WLH, lines[i], 1)
- ly += WLH
- end
- end
- end
- ################################################################################
- # WINDOW RESULTS
- ################################################################################
- class Window_GW_Results < Window_Base
- attr_accessor :string
- def initialize
- super(180, 273, 184, 144)
- @string = []
- refresh
- self.visible = false
- end
- def refresh
- self.contents.clear
- ly = 0
- lh = 20
- self.contents.font.size = 16
- for str in @string
- self.contents.draw_text(0, ly, self.width - 32, lh, str, 1)
- ly += lh
- end
- end
- end
- ################################################################################
- # WINDOW COMPETITOR
- ################################################################################
- class Window_GW_Competitor < Window_Base
- attr_accessor :competitor
- def initialize(player = true, opponent_id = nil)
- if player
- super(0, 0, 180, 56)
- @competitor = $game_player
- else
- super(364, 0, 180, 56)
- @competitor = $game_map.events[opponent_id]
- end
- refresh
- end
- def refresh
- self.contents.clear
- draw_character(@competitor.character_name, @competitor.character_index, 16, 32)
- self.contents.draw_text(0, 0, self.width - 32, WLH, @competitor.grid_name, 2)
- end
- end
- ################################################################################
- # SCENE GRID WARS
- ################################################################################
- class Scene_GridWars < Scene_Base
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize(opponent_id, player_first = true)
- bgm = Ixfuru::GridWars::GWBGM
- RPG::BGM.new(bgm[0], bgm[1], bgm[2]).play
- @opponent_id = opponent_id
- @opponent = $game_map.events[opponent_id]
- @opponent.get_grid_monsters
- reset_monsters
- @turn = player_first ? 0 : 1
- @phase = 0
- @presetting = true
- @setting = false
- @finish_match = false
- @winner = nil
- @wait_count = Ixfuru::GridWars::WAIT_COUNT
- @active_monster = nil
- @active_index = 0
- @targetting = false
- @simulation = false
- @sim_count = 0
- @take_count = 0
- @match_end = false
- end
- #-----------------------------------------------------------------------------
- # Start
- #-----------------------------------------------------------------------------
- def start
- super
- create_menu_background
- @win_plyr = Window_GW_Competitor.new
- @win_opp = Window_GW_Competitor.new(false, @opponent_id)
- @win_plyr_monsters = Window_GW_MonsterList.new(0)
- @win_opp_monsters = Window_GW_MonsterList.new(@opponent_id)
- @win_plyr_score = Window_GW_Score.new(0)
- @win_opp_score = Window_GW_Score.new(1)
- @win_field = Window_GW_Field.new
- @win_commands = Window_GW_TokenCommands.new
- @win_token_count = Window_GW_TokenCount.new
- @win_preview = Window_GW_MonsterPreview.new(nil)
- @win_simulation = Window_GW_Simulation.new
- @win_result = Window_GW_Results.new
- create_anisprite
- end
- #-----------------------------------------------------------------------------
- # Reset Monsters
- #------------------------------------------------------------------------------
- def reset_monsters
- $game_player.grid_monsters.each { |index, monster|
- monster.reset
- }
- @opponent.grid_monsters.each { |index, monster|
- monster.reset
- }
- end
- #-----------------------------------------------------------------------------
- # Create Anisprite
- #-----------------------------------------------------------------------------
- def create_anisprite
- @viewport = Viewport.new(0, 0, 544, 416)
- @viewport.z = 160
- @anisprite = Sprite_Base.new(@viewport)
- end
- #-----------------------------------------------------------------------------
- # Set Anisprite Location
- #-----------------------------------------------------------------------------
- def set_anisprite_location(x, y)
- @anisprite.x = @win_field.x + x
- @anisprite.y = @win_field.y + y
- end
- #-----------------------------------------------------------------------------
- # Update
- #-----------------------------------------------------------------------------
- def update
- super
- if @win_result.visible
- update_result
- elsif @win_preview.visible
- update_preview
- elsif @match_end
- if @winner.is_a?(Game_Player)
- $game_system.last_grid_result = 0
- elsif @winner.is_a?(Game_Event)
- $game_system.last_grid_result = 1
- else
- $game_system.last_grid_result = 2
- end
- $game_player.renumerate_tokens
- @opponent.renumerate_tokens
- $scene = Scene_Map.new
- elsif @taking
- update_taking
- elsif @presetting
- update_presetting
- elsif @setting
- update_setting
- elsif @finish_match
- update_finishing
- elsif @animating
- update_animating
- elsif @simulating
- update_simulation
- else
- update_turn
- end
- end
- #-----------------------------------------------------------------------------
- # Jumbled
- #-----------------------------------------------------------------------------
- def jumbled(ary)
- return unless ary.is_a?(Array)
- new_ary = []
- until ary.empty?
- n = ary[rand(ary.size)]
- new_ary.push(n)
- ary.delete(n)
- end
- return new_ary
- end
- #-----------------------------------------------------------------------------
- # Update Setting
- #-----------------------------------------------------------------------------
- def update_setting
- sz = 60
- fpool = []
- for i in 0...sz
- fpool.push(i)
- end
- fpool = jumbled(fpool)
- ptokens = []
- $game_player.grid_monsters.each { |index, monster|
- if monster.set
- ptokens.push(monster)
- end
- }
- otokens = []
- @opponent.grid_monsters.each { |index, monster|
- if monster.set
- otokens.push(monster)
- end
- }
- pool_id = 0
- for f in fpool
- case pool_id
- when 0 # Set Players Token
- token = ptokens[rand(ptokens.size)]
- @win_field.field_monsters[f] = [token, $game_player, false]
- ptokens.delete(@win_field.field_monsters[f][0])
- pool_id = 1
- when 1 # Set Opponents Token
- token = otokens[rand(otokens.size)]
- @win_field.field_monsters[f] = [token, @opponent, false]
- otokens.delete(@win_field.field_monsters[f][0])
- pool_id = 0
- end
- @win_field.refresh
- end
- @setting = false
- @win_field.active = true
- update_scores
- end
- #-----------------------------------------------------------------------------
- # Update Scores
- #-----------------------------------------------------------------------------
- def update_scores
- ps = 0
- os = 0
- for i in 0...60
- if @win_field.field_monsters[i][1].is_a?(Game_Player)
- ps += 1
- else
- os += 1
- end
- end
- @win_plyr_score.points = ps
- @win_opp_score.points = os
- @win_plyr_score.refresh
- @win_opp_score.refresh
- end
- #-----------------------------------------------------------------------------
- # Update Presetting
- #-----------------------------------------------------------------------------
- def update_presetting
- case @turn
- when 0 # Player's
- @win_plyr_monsters.active = true
- @win_plyr_monsters.update
- if Input.trigger?(Input::C)
- monster = @win_plyr_monsters.monsters[@win_plyr_monsters.index]
- if monster.set
- Sound.play_decision
- @win_token_count.required_amount += 1
- monster.set = false
- else
- play_grid_sound(:selection)
- @win_token_count.required_amount -= 1
- monster.set = true
- end
- @win_plyr_monsters.refresh
- @win_token_count.refresh
- elsif Input.trigger?(Input::B)
- Sound.play_cancel
- $scene = Scene_Map.new
- elsif Input.trigger?(Input::Y)
- Sound.play_decision
- @win_preview.monster = @win_plyr_monsters.monsters[@win_plyr_monsters.index]
- @win_preview.refresh
- @win_preview.visible = true
- elsif Input.trigger?(Input::X)
- if $game_player.quick_tokens.empty?
- Sound.play_buzzer
- elsif $game_player.quick_tokens.size < 30
- Sound.play_buzzer
- else
- play_grid_sound(:quickset)
- $game_player.grid_monsters.each { |index, monster|
- monster.reset
- }
- @win_plyr_monsters.refresh
- add_quickset
- end
- end
- if @win_token_count.required_amount <= 0
- @win_plyr_monsters.active = false
- @win_token_count.visible = false
- @turn = 1
- end
- when 1 # Opponent
- update_opponent_presetting
- end
- end
- #-----------------------------------------------------------------------------
- # Quick Select Token
- #-----------------------------------------------------------------------------
- def quick_select_token
- moveables = []
- @win_field.field_monsters.each { |index, monster|
- if monster[1].is_a?(Game_Player) && !monster[2]
- moveables.push([index, monster])
- end
- }
- m = moveables[rand(moveables.size)]
- return m
- end
- #-----------------------------------------------------------------------------
- # Add QuickSet
- #-----------------------------------------------------------------------------
- def add_quickset
- $game_player.quick_tokens.each { |index, monster|
- Sound.play_cursor
- $game_player.grid_monsters[$game_player.grid_monsters.index(monster)].set = true
- @win_token_count.required_amount -= 1
- @win_token_count.refresh
- }
- @win_plyr_monsters.refresh
- end
- #-----------------------------------------------------------------------------
- # Update Opponent Presetting
- #-----------------------------------------------------------------------------
- def update_opponent_presetting
- update_waiting
- return if @wait_count > 0
- set_otokens = 0
- until set_otokens == 30
- rm = rand(@win_opp_monsters.monsters.size)
- unless @win_opp_monsters.monsters[rm].set
- @win_opp_monsters.monsters[rm].set = true
- set_otokens += 1
- end
- end
- @turn = 0
- @setting = true
- @win_opp_monsters.refresh
- @wait_count = Ixfuru::GridWars::WAIT_COUNT
- @presetting = false
- end
- #-----------------------------------------------------------------------------
- # Update Simulating
- #-----------------------------------------------------------------------------
- def update_simulation
- update_scores
- @wait_count -= 1
- return if @wait_count > 0
- @win_field.index = @sim_count
- monster = @win_field.field_monsters[@sim_count]
- if monster[0].target != nil
- set_anisprite_location(@win_field.cursor_rect.x, @win_field.cursor_rect.y)
- @anisprite.start_animation($data_animations[Ixfuru::GridWars::ATTACK_ANIMATION])
- @animating = true
- retrieve_result(monster, @win_field.field_monsters[monster[0].target])
- @wait_count = 5
- else
- @wait_count = 5
- @win_field.refresh
- @sim_count += 1
- if @sim_count == 60
- @finish_match = true
- @simulating = false
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Retrieve Result
- #-----------------------------------------------------------------------------
- def retrieve_result(attacker, target)
- atk = attacker[0].atk + attacker[0].boost
- dfd = target[0].def + target[0].boost
- acc = attacker[0].acc + attacker[0].boost
- ddg = target[0].ddg + target[0].ddg
- dfd += 1 if target[0].defending
- ddg += 1 if target[0].dodging
- atk_hit = rand(acc)
- dfd_evd = rand(ddg)
- if atk_hit >= dfd_evd
- if atk >= dfd
- play_grid_sound(:attacking)
- @win_field.field_monsters[attacker[0].target][1] = attacker[1]
- attacker[0].add_gp(target[0].value / 100) if attacker[1].is_a?(Game_Player)
- else
- play_grid_sound(:defending)
- attacker[1] = target[1]
- target[0].add_gp(attacker[0].value / 100) if attacker[1].is_a?(Game_Player)
- end
- else
- if target[0].dodging
- play_grid_sound(:dodging)
- attacker[1] = target[1]
- target[0].add_gp(attacker[0].value / 100) if attacker[1].is_a?(Game_Player)
- else
- play_grid_sound(:missing)
- end
- end
- @win_field.refresh
- update_scores
- @sim_count += 1
- if @sim_count >= 60
- @finish_match = true
- @simulating = false
- end
- end
- #-----------------------------------------------------------------------------
- # Result String Width
- #-----------------------------------------------------------------------------
- def result_string_width(string)
- return @win_result.contents.text_size(string).width
- end
- #-----------------------------------------------------------------------------
- # Show Result
- #-----------------------------------------------------------------------------
- def show_result(string_array)
- @win_result.string.clear
- for i in string_array
- @win_result.string.push(i)
- end
- @win_result.refresh
- @win_result.visible = true
- end
- #-----------------------------------------------------------------------------
- # Update Result
- #-----------------------------------------------------------------------------
- def update_result
- if Input.trigger?(Input::C) || Input.trigger?(Input::B)
- Sound.play_cancel
- unless @finish_match
- @sim_count += 1
- if @sim_count == 60
- @finish_match = true
- @simulating = false
- end
- end
- @win_result.visible = false
- end
- @win_field.refresh
- update_scores
- end
- #-----------------------------------------------------------------------------
- # Update Taking
- #-----------------------------------------------------------------------------
- def update_taking
- if @winner.is_a?(Game_Player)
- @win_opp_monsters.update
- if Input.trigger?(Input::C)
- if @win_opp_monsters.enabled?(@win_opp_monsters.index)
- play_grid_sound(:selection)
- token_points = @win_plyr_score.points - @win_opp_score.points
- lost_token = @win_opp_monsters.monsters[@win_opp_monsters.index]
- new_token = Marshal.load(Marshal.dump(@win_opp_monsters.monsters[@win_opp_monsters.index]))
- $game_player.grid_monsters[$game_player.grid_monsters.size] = new_token
- $game_player.token_points += token_points
- @opponent.grid_monsters.delete(lost_token)
- show_result([$game_party.members[0].name, "was victorious!", lost_token.name,
- "token was received!"])
- @win_opp_monsters.active = false
- @match_end = true
- else
- Sound.play_buzzer
- end
- elsif Input.trigger?(Input::Y)
- monster = @win_opp_monsters.monsters[@win_opp_monsters.index]
- @win_preview.monster = monster
- @win_preview.refresh
- @win_preview.visible = true
- end
- else
- @take_count -= 1
- Sound.play_cursor
- new_index = @win_plyr_monsters.index + 1
- if new_index >= @win_plyr_monsters.monsters.size
- new_index = 0
- end
- @win_plyr_monsters.index = new_index
- if @take_count <= 0
- if @win_plyr_monsters.enabled?(@win_plyr_monsters.index)
- lost_token = @win_plyr_monsters.monsters[@win_plyr_monsters.index]
- new_token = Marshal.load(Marshal.dump(@win_plyr_monsters.monsters[@win_plyr_monsters.index]))
- @opponent.grid_monsters[@opponent.grid_monsters.size] = new_token
- $game_player.grid_monsters.delete(lost_token)
- show_result([$game_party.members[0].name, "was defeated!", lost_token.name,
- "token was lost!"])
- @match_end = true
- end
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Update Finishing
- #-----------------------------------------------------------------------------
- def update_finishing
- update_scores
- @winner = player_with_highest_score
- @win_result.visible = false
- if @winner.is_a?(Game_Player)
- play_grid_music(:victory)
- @taking = true
- @win_opp_monsters.active = true
- $game_system.last_grid_result = 0
- elsif @winner.is_a?(Game_Event)
- play_grid_music(:defeat)
- @taking = true
- @take_count = ($game_player.grid_monsters.size * rand(4)) +
- rand($game_player.grid_monsters.size)
- $game_system.last_grid_result = 1
- else
- play_grid_music(:tie)
- show_result("The Match was a tie!")
- @taking = true
- @match_end = true
- $game_system.last_grid_result = 2
- end
- end
- #------------------------------------------------------------------------------
- # Play Grid Music
- #-----------------------------------------------------------------------------
- def play_grid_music(music_name)
- me = Ixfuru::GridWars::MUSICS[music_name]
- RPG::ME.new(me[0], me[1], me[2]).play
- end
- #-----------------------------------------------------------------------------
- # Player With Highest Score
- #-----------------------------------------------------------------------------
- def player_with_highest_score
- if @win_plyr_score.points > @win_opp_score.points
- win = $game_player
- elsif @win_opp_score.points > @win_plyr_score.points
- win = @opponent
- else
- win = nil
- end
- return win
- end
- #-----------------------------------------------------------------------------
- # Update Waiting
- #-----------------------------------------------------------------------------
- def update_waiting
- return if @turn == 0
- @wait_count -= 1
- if @wait_count <= 0
- @wait_count = 0
- end
- end
- #-----------------------------------------------------------------------------
- # Update Animating
- #-----------------------------------------------------------------------------
- def update_animating
- if @anisprite.animation?
- @anisprite.update
- @animating = true
- else
- @animating = false
- end
- end
- #-----------------------------------------------------------------------------
- # Update Preview
- #-----------------------------------------------------------------------------
- def update_preview
- if Input.trigger?(Input::C) || Input.trigger?(Input::B)
- Sound.play_cancel
- @win_preview.visible = false
- end
- end
- #-----------------------------------------------------------------------------
- # Update Turn
- #-----------------------------------------------------------------------------
- def update_turn
- update_waiting
- case @phase
- when 0 # Choose token
- update_token_selection
- when 1 # Choose Command
- update_commands
- when 2 # Choose Target
- update_targetting
- when 3 # Finish Up Turn
- update_end_turn
- end
- end
- #-----------------------------------------------------------------------------
- # Battle Ready?
- #------------------------------------------------------------------------------
- def battle_ready?
- for i in 0...60
- return false if !@win_field.field_monsters[i][2] # A monster hasn't moved
- end
- return true
- end
- #-----------------------------------------------------------------------------
- # Update End Turn
- #-----------------------------------------------------------------------------
- def update_end_turn
- @win_field.field_monsters[@active_index][2] = true
- @win_field.target_indices = []
- @win_field.refresh
- if battle_ready?
- set_boosts
- @simulating = true
- else
- case @turn
- when 0 # Player's
- @phase = 0
- @turn = 1
- when 1 # Opponent's
- @phase = 0
- @turn = 0
- @win_field.active = true
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Update Token Selection
- #-----------------------------------------------------------------------------
- def update_token_selection
- case @turn
- when 0 # Player's
- @win_field.update
- #~ m = moveables
- if Input.trigger?(Input::C)
- monster = @win_field.field_monsters[@win_field.index]
- if monster[1].is_a?(Game_Player) && !monster[2] #Player's monster and hasn't moved
- play_grid_sound(:selection)
- @active_monster = monster[0]
- @active_index = @win_field.index
- @phase = 1
- @win_field.active = false
- @win_commands.index = 0
- @win_commands.visible = true
- @win_commands.active = true
- @win_field.active = false
- else
- Sound.play_buzzer
- end
- elsif Input.trigger?(Input::Y)
- monster = @win_field.field_monsters[@win_field.index]
- if monster[1].is_a?(Game_Player) || monster[2]
- @win_preview.monster = monster[0]
- @win_preview.refresh
- @win_preview.visible = true
- else
- Sound.play_buzzer
- end
- end
- when 1 # Opponent's
- return if @wait_count > 0
- monster = random_selected_monster
- play_grid_sound(:selection)
- @win_field.index = monster[0]
- @active_monster = monster[1][0]
- @active_index = @win_field.index
- @win_commands.index = 0
- #~ @win_commands.visible = true
- @wait_count = Ixfuru::GridWars::WAIT_COUNT
- @phase = 1
- end
- end
- #-----------------------------------------------------------------------------0
- # Random Selected Monster
- #-----------------------------------------------------------------------------
- def random_selected_monster
- moveables = []
- @win_field.field_monsters.each { |index, monster|
- if monster[1].is_a?(Game_Event) && !monster[2]
- moveables.push([index, monster])
- end
- }
- m = moveables[rand(moveables.size)]
- return m
- end
- #-----------------------------------------------------------------------------
- # Play Grid Sound
- #-----------------------------------------------------------------------------
- def play_grid_sound(sound_name)
- se = Ixfuru::GridWars::SOUNDS[sound_name]
- RPG::SE.new(se[0], se[1], se[2]).play
- end
- #-----------------------------------------------------------------------------
- # Update Commands
- #-----------------------------------------------------------------------------
- def update_commands
- case @turn
- when 0 # Player's
- @win_commands.update
- if Input.trigger?(Input::C)
- case @win_commands.index
- when 0 # Attack
- if targets.empty?
- Sound.play_buzzer
- else
- play_grid_sound(:attacking)
- @active_monster.attacking = true
- @phase = 2
- @win_commands.visible = false
- @win_commands.active = false
- @win_field.active = true
- end
- when 1 # Defend
- @active_monster.defending = true
- play_grid_sound(:defending)
- @phase = 3
- @win_commands.visible = false
- @win_commands.active = false
- when 2 # Dodge
- @active_monster.dodging = true
- play_grid_sound(:dodging)
- @phase = 3
- @win_commands.visible = false
- @win_commands.active = false
- end
- elsif Input.trigger?(Input::B)
- Sound.play_cancel
- @active_monster.reset
- @win_commands.visible = false
- @win_commands.active = false
- @win_field.active = true
- @phase = 0
- end
- when 1 # Opponent's
- return if @wait_count > 0
- rc = rand(12)
- if rc <= 6
- if !targets.empty?
- @win_commands.index = 0
- play_grid_sound(:attacking)
- @active_monster.attacking = true
- @phase = 2
- @wait_count = Ixfuru::GridWars::WAIT_COUNT
- else
- @win_commands.index = 1
- play_grid_sound(:defending)
- @active_monster.defending = true
- @phase = 3
- @wait_count = Ixfuru::GridWars::WAIT_COUNT
- end
- elsif rc <= 9
- @win_commands.index = 1
- play_grid_sound(:defending)
- @active_monster.defending = true
- @phase = 3
- @wait_count = Ixfuru::GridWars::WAIT_COUNT
- else
- @win_commands.index = 0
- play_grid_sound(:dodging)
- @active_monster.dodging = true
- @phase = 3
- @wait_count = Ixfuru::GridWars::WAIT_COUNT
- end
- @win_commands.visible = false
- end
- end
- #-----------------------------------------------------------------------------
- # Update Targetting
- #-----------------------------------------------------------------------------
- def update_targetting
- case @turn
- when 0 # PLayer's
- @win_field.update
- if Input.trigger?(Input::C)
- ti = @win_field.index
- if targets.include?(ti)
- @active_monster.target = @win_field.index
- play_grid_sound(:selection)
- @phase = 3
- @win_field.active = false
- else
- Sound.play_buzzer
- end
- elsif Input.trigger?(Input::Y)
- monster = @win_field.field_monsters[@win_field.index]
- if monster[1].is_a?(Game_Player) || monster[2]
- @win_preview.monster = monster[0]
- @win_preview.refresh
- @win_preview.visible = true
- else
- Sound.play_buzzer
- end
- elsif Input.trigger?(Input::B)
- Sound.play_cancel
- @win_commands.index = 0
- @win_commands.active = true
- @win_commands.visible = true
- @win_field.active = false
- @active_monster.reset
- @phase = 1
- end
- when 1 # Opponents
- return if @wait_count > 0
- ti = targets[rand(targets.size)]
- @win_field.index = ti
- @active_monster.target = @win_field.index
- play_grid_sound(:selection)
- @phase = 3
- end
- end
- #-----------------------------------------------------------------------------
- # Set Boost
- #-----------------------------------------------------------------------------
- def set_boosts
- for i in 0...60
- monster = @win_field.field_monsters[i][0]
- owner = @win_field.field_monsters[i][1]
- index = i
- for n in 0...4
- case n
- when 0
- bindex = i + 1
- when 1
- bindex = i - 1
- when 2
- bindex = i - 6
- when 3
- bindex = i + 6
- end
- next if bindex > 59 || bindex < 0
- if owner.is_a?(Game_Player)
- if @win_field.field_monsters[bindex][1].is_a?(Game_Player)
- monster.boost += 1
- end
- else
- if @win_field.field_monsters[bindex][1].is_a?(Game_Event)
- monster.boost -= 1
- end
- end
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Targets
- #-----------------------------------------------------------------------------
- def targets
- am_index = @active_index
- target_indices = []
- for i in 0...4
- case i
- when 0
- target_index = am_index + 1
- when 1
- target_index = am_index - 1
- when 2
- target_index = am_index - 6
- when 3
- target_index = am_index + 6
- end
- case @turn
- when 0 # Players Turn
- if @win_field.field_monsters.has_key?(target_index) &&
- @win_field.field_monsters[target_index][1].is_a?(Game_Event)
- target_indices.push(target_index)
- end
- when 1 # Opponents Turn
- if @win_field.field_monsters.has_key?(target_index) &&
- @win_field.field_monsters[target_index][1].is_a?(Game_Player)
- target_indices.push(target_index)
- end
- end
- end
- @win_field.target_indices = target_indices
- @win_field.refresh
- return target_indices
- end
- #-----------------------------------------------------------------------------
- # Terminate
- #-----------------------------------------------------------------------------
- def terminate
- super
- dispose_menu_background
- windows = [@win_plyr_monsters, @win_opp_monsters, @win_plyr_score,
- @win_opp_score, @win_field, @win_preview, @win_token_count,
- @win_simulation, @win_result, @win_opp, @win_plyr]
- for window in windows
- window.dispose
- end
- @anisprite.dispose
- end
- end
- ################################################################################
- # WINDOW OPTIONS
- ################################################################################
- class Window_GW_Options < Window_Selectable
- attr_accessor :option_strings
- def initialize
- super(180, 0, 184, 104)
- @option_strings = ["", "", "", "", ""]
- refresh
- self.active = false
- self.index = 0
- end
- def refresh
- @item_max = @option_strings.size
- create_contents
- for i in 0...@item_max
- draw_option(i)
- end
- end
- def draw_option(index)
- rect = item_rect(index)
- rect.width += 8
- rect.x -= 4
- self.contents.draw_text(rect, @option_strings[index], 1)
- end
- end
- ################################################################################
- # WINDOW INSTRUCTIONS
- ################################################################################
- class Window_GW_Instructions < Window_Base
- def initialize
- super(180, 104, 184, 168)
- @string_id = 0
- refresh
- end
- def refresh
- self.contents.clear
- lines = instruction_lines
- ly = 0
- lh = 16
- self.contents.font.size = 12
- for line in lines
- self.contents.draw_text(0, ly, self.width - 32, lh, line, 1)
- ly += lh
- end
- end
- def instruction_lines
- case @string_id
- when 0
- return ["Select a token to", "add to the QuickSet", "or Delete.",
- "Press X to Exit", "Press S to preview", "Press <> to change",
- "sides"]
- end
- end
- end
- ################################################################################
- # WINDOW TOKEN AMOUNTS
- ################################################################################
- class Window_GW_TokenAmounts < Window_Base
- def initialize(amount_type)
- @atype = amount_type
- case @atype
- when 0
- super(0, 360, 180, 56)
- when 1
- super(364, 360, 180, 56)
- end
- refresh
- end
- def refresh
- self.contents.clear
- amount = @atype == 0 ? $game_player.grid_monsters.size : $game_player.quick_tokens.size
- self.contents.draw_text(0, 0, self.width - 32, WLH, amount.to_s, 1)
- end
- end
- ################################################################################
- # WINDOW GRID RECORD
- ################################################################################
- class Window_GW_Record < Window_Base
- def initialize
- super(364, 0, 180, 56)
- @record = $game_player.grid_record
- refresh
- end
- def refresh
- self.contents.clear
- self.contents.draw_text(0, 0, self.width - 32, WLH, @record[0].to_s + "-" +
- @record[1].to_s + "-" + @record[2].to_s, 1)
- end
- end
- ################################################################################
- # WINDOW TOKEN POINTS
- ################################################################################
- class Window_GW_TokenPoints < Window_Base
- def initialize(x, y, width)
- super(x, y, width, 56)
- refresh
- end
- def refresh
- self.contents.clear
- @points = $game_player.token_points
- draw_icon(Ixfuru::GridWars::TOKEN_POINTS[2], 0, 0)
- self.contents.draw_text(26, 0, self.width - 58, WLH, @points.to_s, 2)
- end
- end
- ################################################################################
- # SCENE TOKEN MANAGER
- ################################################################################
- class Scene_TokenManager < Scene_Base
- #-----------------------------------------------------------------------------
- # Initialize
- #------------------------------------------------------------------------------
- def initialize
- @quick = false # Options for Quick Set side of the scene?
- $game_player.renumerate_tokens
- $game_player.grid_monsters.each { |index, monster|
- monster.reset
- }
- end
- #-----------------------------------------------------------------------------
- # Start
- #-----------------------------------------------------------------------------
- def start
- super
- create_menu_background
- @win_player = Window_GW_Competitor.new
- @win_record = Window_GW_Record.new
- @win_monsterlist = Window_GW_MonsterList.new(0)
- @win_quicksetlist = Window_GW_MonsterList.new(nil)
- @win_allsize = Window_GW_TokenAmounts.new(0)
- @win_quicksize = Window_GW_TokenAmounts.new(1)
- @win_instructions = Window_GW_Instructions.new
- @win_options = Window_GW_Options.new
- @win_preview = Window_GW_MonsterPreview.new(nil)
- @win_nameletters = Window_TokenRenamerLetters.new
- @win_nameview = Window_TokenRenamerPreview.new
- @win_confirmation = Window_Confirmation.new(["DELETE THE TOKEN", "CANCEL"])
- @win_monsterlist.active = true
- @win_preview.visible = true
- end
- #-----------------------------------------------------------------------------
- # Update
- #-----------------------------------------------------------------------------
- def update
- super
- update_preview
- if @win_confirmation.active
- update_confirmation
- elsif @win_options.active
- update_options
- elsif @win_nameletters.active
- update_naming
- elsif @win_monsterlist.active
- update_monsterlist
- elsif @win_quicksetlist.active
- update_quickset
- end
- end
- #-----------------------------------------------------------------------------
- # Update Preview
- #-----------------------------------------------------------------------------
- def update_preview
- if @quick
- @monster = @win_quicksetlist.monsters[@win_quicksetlist.index]
- else
- @monster = @win_monsterlist.monsters[@win_monsterlist.index]
- end
- @win_preview.monster = @monster
- @win_preview.refresh
- end
- #-----------------------------------------------------------------------------
- # Update Monster List
- #-----------------------------------------------------------------------------
- def update_monsterlist
- @win_monsterlist.update
- if Input.trigger?(Input::C)
- @monster = @win_monsterlist.monsters[@win_monsterlist.index]
- if !@monster.nil?
- Sound.play_decision
- @win_options.option_strings = active_option_strings
- @win_options.refresh
- @win_options.visible = true
- @win_options.active = true
- else
- Sound.play_buzzer
- end
- elsif Input.trigger?(Input::RIGHT)
- Sound.play_decision
- @win_quicksetlist.active = true
- @win_monsterlist.active = false
- @quick = true
- elsif Input.trigger?(Input::B)
- Sound.play_cancel
- $scene = Scene_Map.new
- end
- end
- #-----------------------------------------------------------------------------
- # Update Quickset List
- #-----------------------------------------------------------------------------
- def update_quickset
- @win_quicksetlist.update
- if Input.trigger?(Input::C)
- @monster = @win_quicksetlist.monsters[@win_quicksetlist.index]
- if !@monster.nil?
- Sound.play_decision
- @win_options.option_strings = active_option_strings
- @win_options.refresh
- @win_options.visible = true
- @win_options.active = true
- else
- Sound.play_buzzer
- end
- elsif Input.trigger?(Input::LEFT)
- Sound.play_decision
- @win_monsterlist.active = true
- @win_quicksetlist.active = false
- @quick = false
- end
- end
- #-----------------------------------------------------------------------------
- # Active Option Strings
- #----------------------------------------------------------------------------
- def active_option_strings
- return ["Remove Token", "Delete Token", "Rename"] if @quick
- return ["Add Quick Token", "Delete Token", "Rename"]
- end
- #-----------------------------------------------------------------------------
- # Update Options
- #-----------------------------------------------------------------------------
- def update_options
- @win_options.update
- if Input.trigger?(Input::C)
- case @win_options.index
- when 0 # Add/Remove from quickset
- if @quick
- Sound.play_cancel
- $game_player.quick_tokens.delete(@win_quicksetlist.monsters.index(@monster))
- $game_player.renumerate_tokens
- @win_options.active = false
- #~ @win_options.visible = false
- @win_quicksetlist.refresh
- @win_quicksetlist.active = true
- else
- if $game_player.quick_tokens.has_value?(@monster) ||
- @win_quicksetlist.monsters.size == 30
- Sound.play_buzzer
- else
- Sound.play_decision
- $game_player.quick_tokens[$game_player.quick_tokens.size] = @monster
- $game_player.renumerate_tokens
- @win_options.active = false
- #~ @win_options.visible = false
- @win_quicksetlist.refresh
- @win_quicksetlist.active = true
- end
- end
- when 1 # Delete The Token
- if @quick
- Sound.play_buzzer
- else
- Sound.play_decision
- @win_options.active = false
- @win_confirmation.index = 1
- @win_confirmation.visible = true
- @win_confirmation.active = true
- end
- when 2 # Rename
- if @quick
- Sound.play_buzzer
- else
- Sound.play_decision
- @win_monsterlist.active = false
- @win_nameview.reset_word
- @win_nameletters.visible = true
- @win_nameview.visible = true
- @win_nameview.index = 0
- @win_nameletters.index = 0
- @win_nameletters.active = true
- @win_options.active = false
- end
- end
- elsif Input.trigger?(Input::B)
- Sound.play_cancel
- #~ @win_options.visible = false
- @win_options.active = false
- if @quick
- @win_quicksetlist.active = true
- else
- @win_monsterlist.active = true
- end
- end
- @win_allsize.refresh
- @win_quicksize.refresh
- end
- #-----------------------------------------------------------------------------
- # Update Naming
- #-----------------------------------------------------------------------------
- def update_naming
- @win_nameletters.update
- if Input.trigger?(Input::C)
- if @win_nameletters.index == @win_nameletters.letters.size - 1
- play_grid_sound(:selection)
- name = @win_nameview.word.to_s
- name.scan(/./) { |c| c = "" if c == "" }
- @monster.name = name
- @win_monsterlist.refresh
- @win_quicksetlist.refresh
- @win_nameletters.active = false
- @win_nameview.visible = false
- @win_nameletters.visible = false
- @win_preview.refresh
- @win_options.active = true
- elsif @win_nameletters.index == @win_nameletters.letters.size - 2
- Sound.play_cancel
- @win_nameletters.active = false
- @win_nameview.visible = false
- @win_nameletters.visible = false
- @win_options.active = true
- else
- play_grid_sound(:letter_input)
- @win_nameview.word[@win_nameview.index] = @win_nameletters.letters[@win_nameletters.index]
- @win_nameview.refresh
- if @win_nameview.index < @win_nameview.max_characters - 1
- @win_nameview.index += 1
- end
- end
- elsif Input.trigger?(Input::B)
- play_grid_sound(:eraser)
- if @win_nameview.index > 0
- @win_nameview.word[@win_nameview.index - 1] = " "
- @win_nameview.index -= 1
- @win_nameview.refresh
- else
- Sound.play_buzzer
- end
- elsif Input.trigger?(Input::A)
- play_grid_sound(:shiftkey)
- toggle = @win_nameletters.lcase == 0
- @win_nameletters.lcase = toggle ? 1 : 0
- @win_nameletters.refresh
- end
- end
- #-----------------------------------------------------------------------------
- # Update Confirmation
- #-----------------------------------------------------------------------------
- def update_confirmation
- @win_confirmation.update
- if Input.trigger?(Input::C)
- case @win_confirmation.index
- when 0
- play_grid_sound(:delete_token)
- $game_player.grid_monsters.delete(@win_monsterlist.monsters.index(@monster))
- if $game_player.quick_tokens.has_value?(@monster)
- $game_player.quick_tokens.delete(@win_quicksetlist.monsters.index(@monster))
- end
- $game_player.renumerate_tokens
- @win_monsterlist.refresh
- @win_quicksetlist.refresh
- @win_confirmation.active = false
- @win_confirmation.visible = false
- @win_monsterlist.active = true
- when 1
- Sound.play_cancel
- @win_confirmation.active = false
- @win_confirmation.visible = false
- @win_options.active = true
- end
- elsif Input.trigger?(Input::B)
- Sound.play_cancel
- @win_confirmation.active = false
- @win_confirmation.visible = false
- @win_options.active = true
- end
- end
- #-----------------------------------------------------------------------------
- # Terminate
- #-----------------------------------------------------------------------------
- def terminate
- super
- dispose_menu_background
- windows = [@win_monsterlist, @win_quicksetlist, @win_options, @win_preview,
- @win_instructions, @win_allsize, @win_quicksize, @win_record, @win_player,
- @win_nameletters, @win_nameview, @win_confirmation]
- for window in windows
- window.dispose
- end
- end
- end
- ################################################################################
- # GRID SHOP
- ################################################################################
- class GridShop
- attr_reader :shop_id
- attr_accessor :tokens
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize(shop_id, max_stars = 1)
- @shop_id = shop_id
- if Ixfuru::GridWars::TOKEN_SHOPS.has_key?(shop_id)
- base = Ixfuru::GridWars::TOKEN_SHOPS[shop_id]
- @max_stars = base[:max_stars]
- @tokens = preset_shop_tokens(base)
- else
- @max_stars = max_stars
- @tokens = generated_shop_tokens
- end
- finalize
- end
- #-----------------------------------------------------------------------------
- # Generated Shop Tokens
- #-----------------------------------------------------------------------------
- def generated_shop_tokens
- result = {}
- for i in 0...Ixfuru::GridWars::NEW_SHOP_TOKEN_AMOUNT
- stars = rand(@max_stars).to_i
- result[i] = GridMonster.new(stars)
- end
- return result
- end
- #-----------------------------------------------------------------------------
- # Preset Shop Tokens
- #-----------------------------------------------------------------------------
- def preset_shop_tokens(shop_base)
- result = {}
- for i in 0...shop_base[:tokens].size
- t = shop_base[:tokens][i]
- if t == "R"
- stars = rand(@max_stars)
- result[i] = GridMonster.new(stars)
- else
- stars = rand(@max_stars)
- result[i] = GridMonster.new(stars, t)
- end
- end
- return result
- end
- #-----------------------------------------------------------------------------
- # Finalize
- #
- # This method adds the new shop to the global hash $gridshops
- #_----------------------------------------------------------------------------
- def finalize
- $gridshops[@shop_id] = self
- end
- #-----------------------------------------------------------------------------
- # New Shop Bundle
- #
- # bundle : can be passed as either an array of token ids and "R" for random
- # tokens, or can be passed as "RandomX", where X is the amount of
- # tokens you wish to add to the shop.
- #-----------------------------------------------------------------------------
- def new_shop_bundle(bundle)
- if bundle.is_a?(Array)
- for i in 0...bundle.size
- t = bundle[i]
- if t == "R"
- stars = rand(@max_stars)
- @tokens[@tokens.size] = GridMonster.new(stars)
- else
- stars = rand(@max_stars)
- @tokens[@tokens.size] = GridMonster.new(stars, t)
- end
- end
- elsif /Random(X)/i =~ bundle
- amount = $1.to_i
- for i in 0...amount
- stars = rand(@max_stars)
- @tokens[@tokens.size] = GridMonster.new(stars)
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Add Token
- #----------------------------------------------------------------------------
- def add_token(stars, token_id = nil)
- if token_id.nil?
- @tokens[@tokens.size] = GridMonster.new(stars)
- else
- @tokens[@tokens.size] = GridMonster.new(stars, token_id)
- end
- end
- #-----------------------------------------------------------------------------
- # Add Sold Token
- #-----------------------------------------------------------------------------
- def add_sold_token(token)
- @tokens[@tokens.size] = token
- end
- #-----------------------------------------------------------------------------
- # Renumerate Tokens
- #-----------------------------------------------------------------------------
- def renumerate_tokens
- new_tokens = {}
- i = 0
- @tokens.each { |index,token|
- next if token.nil?
- new_tokens[i] = token
- i += 1
- }
- @tokens = new_tokens
- end
- end
- ################################################################################
- # WINDOW GRIDSHOP GOODS
- ################################################################################
- class Window_GridShopGoods < Window_Selectable
- attr_accessor :tokens
- attr_accessor :shop
- def initialize(shop_id)
- super(0, 56, 366, 360)
- @shop_id = shop_id
- if $gridshops.has_key?(shop_id)
- @shop = $gridshops[@shop_id]
- else
- @shop = GridShop.new(shop_id)
- end
- refresh
- self.index = 0
- self.active = false
- self.visible = false
- end
- def refresh
- @tokens = $gridshops[@shop_id].tokens
- @item_max = @tokens.size
- create_contents
- for i in 0...@item_max
- draw_goods(i)
- end
- end
- def draw_goods(index)
- rect = item_rect(index)
- rect.width += 8
- rect.x -= 4
- e = enabled?(index)
- self.contents.font.color.alpha = e ? 255 : 128
- draw_icon(@tokens[index].icon_id, 0, rect.y, e)
- self.contents.draw_text(rect.x + 26, rect.y, self.width - 32, WLH, @tokens[index].name)
- nx = ((self.width - 32) - self.contents.text_size(@tokens[index].value.to_s).width) - 26
- draw_icon(Ixfuru::GridWars::TOKEN_POINTS[2], nx, rect.y, e)
- self.contents.draw_text(nx + 26, rect.y, self.width - 32, WLH, @tokens[index].value.to_s)
- end
- def enabled?(index)
- return true if $game_player.token_points >= @tokens[index].value
- return false
- end
- end
- ################################################################################
- # WINDOW GRIDSHOP OPTIONS
- ################################################################################
- class Window_GridShopOptions < Window_Selectable
- def initialize
- super(0, 0, 544, 56)
- @options = ["Purchase", "Sell", "Exit"]
- @item_max = @options.size
- @column_max = @item_max
- refresh
- self.index = 0
- end
- def refresh
- create_contents
- for i in 0...@item_max
- draw_option(i)
- end
- end
- def enabled?(index)
- case index
- when 0
- return true
- when 1
- return true if !$game_player.grid_monsters.empty?
- return false
- when 2
- return true
- end
- end
- def draw_option(index)
- rect = item_rect(index)
- e = enabled?(index)
- self.contents.font.color.alpha = e ? 255 : 128
- self.contents.draw_text(rect, @options[index], 1)
- end
- end
- ################################################################################
- # WINDOW GRIDSHOP SELL LIST
- ################################################################################
- class Window_GridShopSell < Window_Selectable
- attr_accessor :goods
- def initialize
- super(0, 56, 366, 360)
- refresh
- self.visible = false
- self.index = 0
- self.active = false
- end
- def refresh
- @goods = $game_player.grid_monsters
- @item_max = @goods.size
- create_contents
- for i in 0...@item_max
- draw_goods(i)
- end
- end
- def draw_goods(index)
- rect = item_rect(index)
- rect.width += 8
- rect.x -= 4
- draw_icon(@goods[index].icon_id, 0, rect.y)
- self.contents.draw_text(26, rect.y, self.width - 32, WLH, @goods[index].name)
- nv = @goods[index].value / 4
- nx = ((self.width - 32) - self.contents.text_size(nv.to_s).width) - 26
- draw_icon(Ixfuru::GridWars::TOKEN_POINTS[2], nx, rect.y)
- self.contents.draw_text(nx + 26, rect.y, self.width - 32, WLH, nv.to_s)
- end
- end
- ################################################################################
- # SCENE GRIDSHOP
- ################################################################################
- class Scene_GridShop < Scene_Base
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize(shop_id)
- @shop_id = shop_id
- @monster = nil
- end
- #-----------------------------------------------------------------------------
- # Start
- #-----------------------------------------------------------------------------
- def start
- super
- create_menu_background
- @win_options = Window_GridShopOptions.new
- @win_buy = Window_GridShopGoods.new(@shop_id)
- @win_sell = Window_GridShopSell.new
- @win_points = Window_GW_TokenPoints.new(364, 56, 180)
- @win_preview = Window_GW_MonsterPreview.new(nil, [364, 112, 180, 144])
- end
- #-----------------------------------------------------------------------------
- # Update
- #-----------------------------------------------------------------------------
- def update
- super
- if @win_buy.active
- update_buy
- elsif @win_sell.active
- update_sell
- elsif @win_options.active
- update_options
- end
- end
- #-----------------------------------------------------------------------------
- # Update Buy
- #-----------------------------------------------------------------------------
- def update_buy
- @win_buy.update
- @monster = @win_buy.tokens[@win_buy.index]
- unless @win_preview.monster == @monster
- @win_preview.monster = @monster
- @win_preview.refresh
- end
- if Input.trigger?(Input::C)
- if @win_buy.enabled?(@win_buy.index)
- Sound.play_shop
- $game_player.token_points -= @monster.value
- $game_player.add_shop_token(@monster)
- $gridshops[@shop_id].tokens.delete(@win_buy.index)
- $gridshops[@shop_id].renumerate_tokens
- @win_buy.refresh
- @win_points.refresh
- else
- Sound.play_buzzer
- end
- elsif Input.trigger?(Input::B)
- Sound.play_cancel
- @win_buy.active = false
- @win_options.active = true
- @win_buy.visible = false
- @win_preview.visible = false
- end
- end
- #-----------------------------------------------------------------------------
- # Update Sell
- #-----------------------------------------------------------------------------
- def update_sell
- @win_sell.update
- @monster = @win_sell.goods[@win_sell.index]
- if @win_preview.monster != @monster
- @win_preview.monster = @monster
- @win_preview.refresh
- end
- if Input.trigger?(Input::C)
- if !@monster.nil?
- Sound.play_shop
- $game_player.token_points += @monster.value / 4
- $gridshops[@shop_id].add_sold_token(@monster)
- $game_player.renumerate_tokens
- @win_buy.refresh
- @win_sell.refresh
- @win_points.refresh
- @win_options.refresh
- else
- Sound.play_buzzer
- end
- elsif Input.trigger?(Input::B)
- Sound.play_cancel
- @win_sell.active = false
- @win_options.active = true
- @win_sell.visible = false
- @win_preview.visible = false
- end
- end
- #-----------------------------------------------------------------------------
- # Update_Options
- #-----------------------------------------------------------------------------
- def update_options
- @win_options.update
- if Input.trigger?(Input::C)
- case @win_options.index
- when 0 # BUY
- Sound.play_decision
- @win_buy.active = true
- @win_options.active = false
- @win_buy.visible = true
- @win_preview.visible = true
- when 1 # SELL
- Sound.play_decision
- @win_sell.active = true
- @win_options.active = false
- @win_sell.visible = true
- @win_preview.visible = true
- when 2 # EXIT
- Sound.play_cancel
- $scene = Scene_Map.new
- end
- elsif Input.trigger?(Input::B)
- Sound.play_cancel
- $scene = Scene_Map.new
- end
- end
- #-----------------------------------------------------------------------------
- # Terminate
- #-----------------------------------------------------------------------------
- def terminate
- super
- dispose_menu_background
- windows = [@win_buy, @win_sell, @win_options, @win_points]
- for window in windows
- window.dispose
- end
- end
- end
- ################################################################################
- # WINDOW GRID SHOP MORPH
- ################################################################################
- class Window_GridShopMorph < Window_Base
- end
- ################################################################################
- # WINDOW GRID SHOP LEVEL
- ################################################################################
- class Window_GridShopLevel < Window_Selectable
- end
- ################################################################################
- # WINDOW TOKEN RENAMER
- ################################################################################
- class Window_TokenRenamerLetters < Window_Selectable
- RENAMER_LETTERS = {0 => ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
- "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
- "U", "V", "W", "X", "Y", "Z", " ", "BACK", "KEEP"],
- 1 => ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
- "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
- "u", "v", "w", "x", "y", "z", " ", "BACK", "KEEP"]}
- attr_accessor :letters
- attr_accessor :lcase
- def initialize
- super(180, 0, 184, 152)
- @lcase = 0
- @spacing = 0
- refresh
- self.index = 0
- self.visible = false
- self.active = false
- end
- def refresh
- @letters = RENAMER_LETTERS[@lcase]
- @item_max = @letters.size
- @column_max = 6
- create_contents
- for i in 0...@item_max
- draw_letter(i)
- end
- end
- def draw_letter(index)
- rect = item_rect(index)
- self.contents.draw_text(rect, @letters[index])
- end
- end
- #################################################################################
- # WINDOW TOKEN RENAMER PREVIEW
- ################################################################################
- class Window_TokenRenamerPreview < Window_Selectable
- attr_accessor :word
- attr_accessor :max_characters
- def initialize(max_characters = 14)
- super(180, 152, 184, 56)
- @word = []
- @max_characters = max_characters
- for i in 0...@max_characters
- @word.push(" ")
- end
- @item_max = @max_characters
- @column_max = @item_max
- @spacing = 0
- refresh
- self.index = 0
- self.active = false
- self.visible = false
- end
- def refresh
- create_contents
- for i in 0...@item_max
- draw_word_letter(i)
- end
- end
- def reset_word
- @word.clear
- for i in 0...@max_characters
- @word.push(" ")
- end
- end
- def draw_word_letter(index)
- rect = item_rect(index)
- self.contents.draw_text(rect, @word[index], 1)
- end
- end
- ################################################################################
- # WINDOW CONFIRMATION
- ################################################################################
- class Window_Confirmation < Window_Selectable
- attr_accessor :choices
- def initialize(choices = ["Yes", "No"])
- super(180, 148, 184, 80)
- @choices = choices
- refresh
- self.index = 1
- self.visible = false
- self.active = false
- end
- def refresh
- create_contents
- @item_max = @choices.size
- for i in 0...@item_max
- draw_choice(i)
- end
- end
- def draw_choice(index)
- rect = item_rect(index)
- self.contents.draw_text(rect, @choices[index], 1)
- end
- end
- ################################################################################
- # SCENE FILE
- ################################################################################
- class Scene_File < Scene_Base
- #-----------------------------------------------------------------------------
- # Read Save Data(Aliased)
- #-----------------------------------------------------------------------------
- alias ixgwscflread read_save_data unless $@
- def read_save_data(file)
- ixgwscflread(file)
- $gridshops = Marshal.load(file)
- end
- #-----------------------------------------------------------------------------
- # Write Save Data(Aliased)
- #-----------------------------------------------------------------------------
- alias ixgwscflwrite write_save_data unless $@
- def write_save_data(file)
- ixgwscflwrite(file)
- Marshal.dump($gridshops, file)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment