Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- # ** Garden System
- # Author: Eshra
- # Beta Release Date: 3 Nov. 2012
- # Full Version Release: 4 Dec. 2012
- # Compatibility: RPG Maker VX Ace
- # Dependencies:
- # 1. Tsuki_CustomDataManager
- # 2. Ra Custom DM add-on v0.1
- # 3. Ra Highlights v0.1
- # 4. Ra Event Spawn v0.1
- #
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- #
- # About:
- #
- # This script provides support for using events to represent plants while
- # in Scene_Map. It creates functionality for somewhat complicated plant
- # growth cycles, plant fertillization, and plant watering systems.
- #
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- #
- #------------------------------------------------------------------------------
- # * How to Use
- #------------------------------------------------------------------------------
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Setting up a plant:
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- #
- # Plants are represented by items (or skills) in the database. To mark an item
- # as a plant you need to give it a growth rate and a maximum stage.
- #
- # You can give the plant a growth rate with this note tag:
- # <seed rate VALUE>
- #
- # You can give the plant a maximum stage with this note tag:
- # <seed stages VALUE>
- #
- # - 'VALUE' should be replaced with an integer in the above two note tags -
- #
- # These are the only two notetags that are required to make a plant. There are
- # many more notetags though that can be used if you want to specify more
- # specific behavior for the plant.
- #
- # Don't forget to give the item a name, this is important!
- # After you have done this, you must now create an associated event for the plant.
- #
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Plant-events:
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # When plants are placed on the map, their associated event is loaded based on
- # an event from another designated map in your project. The default script
- # expects all of these events to be on one map. (The map is used like a proxy
- # its sole purpose should be to store the event data for the plants in your
- # project).
- #
- # The ID of the map that these events are stored in is specified by
- #
- # GardenRa::SeedMap
- #
- # Change the value of this constant to the id number of the map which you will
- # be using to store your plant events.
- #
- # How to create a plant-event:
- # The next step after after creating the plant-item and plant-events-map is
- # creating the plant-event, i.e. the event (or events) that will be associated
- # with the plant. This is what allows the plant to be seen on the map.
- #
- # Plants are associated with events based on the name of the associated item
- # and the name of the associated event.
- # Events can be associated with plants by giving them the name of the plant
- # followed by a space, folled by an integer.
- #
- # For example:
- # We want to make a plant called 'Strawberry'.
- #
- # To do this, we have to make an item named 'Strawberry' and give it the
- # two essential notetags specified above. Make sure the item has no targets and
- # can only be used from the main menu (using the checkboxes in the database).
- #
- # After we've done this we must go to create an event to be associated with
- # the plant.
- #
- # So we go to the designated map in our project and e decide to name the event
- # 'Stawberry 1'.
- # By doing this, we've let the script know that the event with the name
- # 'Strawberry 1' is the first event that will be used to display the stages of
- # the item name 'Strawberry'.
- #
- # Let's say we've specified the strawberry to have 7 stages in the note tag box:
- #
- # <seed stages 7>
- #
- # By default each plant-event can be used to represent 5 growth stages.
- # But what is a stage?
- # A stage is represented by a page of an event. In the default script, once a
- # plant-event is placed on the map, its self switches will be iterated through
- # from 'A' to 'D'. The next self-switch is turned on each time the plant
- # advances a stage in that order (First A, then B, then C, then D).
- #
- # This means that we can represent 5 stages of growth for our strawberry with
- # one event (The first stage has no selfswitches on, the second stage has self-
- # switch 'A' on, the third stage has self-switch 'B' on, etc.)
- #
- # Create the event in your designated plant-events-map and make 4 additional
- # pages for it so that it has five pages total. Use a different picture for
- # each stage so that when the event's self-switches are flipped on it will appear
- # that it is growing.
- #
- # But there is a problem! We specified that we wanted our plant to have 7 stages
- # not 5. How do we handle the extra two stages?
- # Just make another event and associate it with the 'Strawberry' item.
- #
- # The next event we make we name as 'Strawberry 2'.
- # For this event, it's not necessary to create 5 pages for it. We only need two
- # total pages on this event. One for when it has no self-switches on and one for
- # when self-switch 'A' is on.
- # This event will represent stages 6 and 7 in the overall growth of our plant.
- # The script an handle any number of events created this way for any given plant.
- #
- # If we wanted to make a plant with 100 growth stages, we would just have to make
- # 20 different events, set up the 5 pages on each of those events, and name them
- # sequentially so that the script knows which plant-event to choose when it is
- # changing events.
- #
- # We are now done creating our plant. To place the plant on the map all you have
- # to do is use it from your inventory just like you would any other item.
- #
- # If it is not clear how to create plants based on the above instructions I
- # apologize, I have made a video and have a demo as well which might be easier
- # to understand.
- #
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Specifying looping plants:
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- #
- # Use these notetags:
- # <seed loop true>
- # <Seed loop stage VALUE>
- #
- # - Replace 'VALUE' in the above notetags with an integer -
- #
- # To specify a plant that will loop back to a previous stage after it has grown
- # to it's last stage.
- # 'VALUE' is the stage number that it will loop back to.
- #
- # This might be useful if you have a plant that should cycle through stages
- # repetetively, like a tree changing through the seasons.
- #
- # Seeds can be limited to certain terrain tags with this notetag:
- # <Seed terrain VALUE,VALUE,...>
- #
- # - replace 'VALUE' with an integer. each value must be separated by a comma the
- # elipses are there to denote the pattern continues, don't actually put elispses
- # in the notetag -
- # For example, to specify a seed can only be planted on terrain tags 0, 7, 4,
- # and 5, you would use this notetag:
- #
- # <seed terrain 5,7,0,4>
- #
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Fertillizer:
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- #
- # Plants can be fertilliezed by items which are fertillizers. To make a fertillizer
- # use this notetag:
- #
- # <Seed fertillizer FLOAT>
- #
- # - Replace FLOAT with a floating point number between 0 and 1, for example 0.32 -
- # The value you use in this parameter represents the concentration of the fertillizer
- # As the concentration of the fertillizer increases the growth rate of the plant
- # will also increase. Additionally, the yield of a plant will increase based on
- # the amount of fertillizer that has been applied to it.
- #
- # Fertillizer is used by using the associated item from the player's inventory.
- # After you see the fertillizer on the ground, you can plant a seed at that
- # location to apply the fertillizer to the seed. The fertillizer can also be
- # applied after the seed has started growing, as long as the seed is not
- # at its last stage of growth.
- #
- # Limiting the amount of fertillizer that can be applied to a plant:
- #
- # If you want to limit the amount of fertillizer that a plant can applied to a
- # plant use this notetag:
- #
- # <seed max fertillizer FLOAT>
- #
- # - Replace 'FLOAT' with a floating point number between 0 and 1 -
- #
- # Plants can also be given a 'Fertillizer effect ratio'
- # The lower this ratio is, the less of an effect fertillization will have on that
- # plant.
- # To set this value use this notetag:
- #
- # <seed fertile rate FLOAT>
- #
- # - Replace 'FLOAT' with a floating point number between 0 and 1 -
- #
- # You can limit fertillizer to only being planted in certain areas with this
- # notetag:
- # <fertillizer terrain VALUE,VALUE,VALUE...>
- # - replace 'VALUE' with an integer. each value must be separated by a comma the
- # elipses are there to denote the pattern continues, don't actually put elispses
- # in the notetag-
- #
- # For example, to specify a fertillizer can only be placed on terrain tags 0 and
- # 2 use this notetag:
- #
- # <fertillizer terrain 0,2>
- #
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Watering Plants:
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- #
- # Plants can be watered any number of times during each of their growth stages.
- # They can be set to die if they aren't watered enough or if they are watered
- # too much.
- # Plants can also be given an optimal water amount. The optimal water amount is
- # the amount of times the plant should be watered during each stage of growth
- # in order to maximize the harvest for that plant.
- #
- # Set minimum water amounts with this notetag:
- # <seed min water VALUE>
- #
- # Set maximum water amount with this notetag:
- # <seed max water VALUE>
- #
- # Set optimal water amount with this notetag:
- # <seed optimal water VALUE>
- #
- # - Replace 'VALUE' in the above notetags with an integer -
- #
- # Making a water container:
- # Water containers are items that can be used to water plants. Once the party
- # has a water container in their inventory, just walk up to a plant that isn't
- # fully grown and press the interact key to water it
- # You can denote items as water containers with this notetag:
- #
- # <water container VALUE>
- # VALUE is the how much water the container can hold.
- #
- # - Replace 'VALUE' in the above notetag with an integer-
- #
- # Water containers can be refilled using this script call from an event:
- #
- # garden_fill_containers
- #
- # You can also pass in an optional integer value to that method to modify all of
- # the water containers in the parties inventory by that amount.
- #
- # Harvesting and clearing plants
- #
- # Use this notetag:
- # <Seed harvest VALUE>
- #
- # To set the base harvest amount for a plant. The base harvest amount will be
- # achieved at harvest time if the plant was watered optimally at each stage.
- # The base harvest amount can be exceeded if the plant was fertillized.
- #
- # Use this notetag:
- # <seed harvest VALUE - VALUE>
- #
- # To specify a range to use has the base harvest instead of a specific value.
- # When harvesting a value in between the specified range will be used as the base
- #
- # **Note: Do not specifiy both a base value and a range for the same item or
- # skill, use one or the other **
- #
- # - Replace 'VALUE' in the above notetags with an integer -
- # Use this notetag:
- # <clears crops VALUE>
- #
- # to mark an item or skill as being able to clear crops. Once an item is marked
- # with this notetag, you can use it to remove plants. if an integer value
- # is specified, the range of effect of the item will be increased.
- # For example:
- # <clears crops 1> means that the item will clear all of the crops adjacent to
- # the player.
- # <clears crops 2> will clear all of the plants at a distance of 2 from the player
- # <clears crops> without a value specified means the item can only be used to
- # clear crops directly in front of the player.
- #
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Setting up the map:
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- #
- # If you want your fertillizer to erode over time, you need to use these
- # notetags when setting up your map:
- #
- # <Erosion rate VALUE>
- # <Erosion value FLOAT>
- #
- # The erosion rate is specified in frames and is how quickly the fertilizer will
- # erode. The erosion value is how much fertillizer concentration will be
- # decremented by after each tic. A tic being equal to the specified erosion rate.
- #
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Additonal settings
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- #
- # If you are using the same events for multiple skills or items and don't want
- # all of those skills or items to have the same name, use this notetag:
- #
- # <seed name NAME>
- # - replace 'NAME' with the name of the event -
- #
- # To explicitly associate the item with the event of that name.
- #
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Author Notes:
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- #
- # By default, the Shift key can be held down when placing fertillizer or planting
- # a seed to put it infront of the player instead of at the same location the
- # player is standing.
- #
- # Fertillizer is applied at the time the plant is planted or the fertillizer is
- # placed. If the fertillizer concentration at that location changes after this
- # it is not reapplied.
- #
- # Internal common events are created to use the clearing items, the seeds, and
- # the fertillizer. If one of these items is associated with another common event
- # the internal common event will run first, then the event you have specified will
- # run.
- #
- # To do list:
- # There is currently no animation or fading shown when fertillizer is removed
- # from the map. Fix this.
- # There is currently no animation for watering plants.
- # Add a feature to change the precedence of internal common events vs. real
- # events.
- #
- #------------------------------------------------------------------------------
- # Thanks & Acknowledgments:
- #------------------------------------------------------------------------------
- #
- # Tsukihime - Custom DM
- # Celianna - Sprites
- #
- #------------------------------------------------------------------------------
- #
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Original Release Date: 4 Dec. 2012
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- #
- # Update Log
- # 8 Mar. 2013 - Updated Script to version 0.2 for compatibility with the water
- # start add-on.
- # 8 Mar. 2013 - Minor changes in code style added a few @ symbols. No changes in
- # functionality of base script.
- # 8 Dec. 2012 - BaseHarvest amount can now be specified with a constant.
- # A range can now be specified instead of a base harvest amount.
- # Use this notetag:
- #
- # <seed harvest VALUE - VALUE>
- # * replace "VALUE" with an integer value
- #
- # to specify a range to use when generating the base value for
- # harvesting.
- #
- # 7 Dec. 2012 - Fixed crashes when trying to equip items.
- # 5 Dec. 2012 - Fixed improper alias for move_straight inside Game_Characters
- #
- # 3 Nov. 2012 - Added support to clear crops. More options to harvest, fixed
- # fertillization rates, added popups to show how much was
- # harvested.
- #
- # 2 Nov. 2012 - First Version Finished
- #
- # 27 Oct. 2012 - Started work.
- #
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- # Terms of Use
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- # Free to use as you please. Please respect the header though so the dates can
- # be preserved.
- #------------------------------------------------------------------------------
- $imported ||= {}
- raise "Couldn't find: Tsuki_CustomDataManager" if !$imported["Tsuki_CustomDataManager"]
- raise "Couldn't find: Ra Event Spawn v0.1" if ($imported["Ra Event Spawn"] ||=-1) < 0.1
- raise "Couldn't find: Ra Highlights v0.1" if ($imported["Ra Highlights"] ||=-1) < 0.1
- raise "Couldn't find: Ra Custom DM add-on" if ($imported["Ra Custom DM add-on"] ||=-1) < 0.1
- $imported["Ra Gardening"] = 0.2
- #==============================================================================
- # ** RPG::BaseItem
- #==============================================================================
- class RPG::BaseItem
- attr_accessor :clears_crops # this item can be used to clear crops
- def clears_crops?; false; end
- def is_garden_seed?; false; end
- def is_fertillizer?; false; end
- end
- #==============================================================================
- # ** RPG::UsableItem
- #==============================================================================
- class RPG::UsableItem < RPG::BaseItem
- attr_accessor :seed_loop # boolean
- attr_accessor :seed_stages # int
- attr_accessor :seed_rate # int
- attr_accessor :seed_events # array
- attr_accessor :seed_name
- attr_accessor :loop_stage # int
- attr_accessor :seed_terrain # hash
- attr_accessor :fertillizer_rate # float (rate of the fertillizer)
- attr_accessor :fertile_effect # float (modifer, property of seeds)
- attr_accessor :fertillizer_terrain # hash
- attr_accessor :seed_optimal_water # optimal times to water this seed per stage
- attr_accessor :seed_max_water # plant will die if watered more than this many times per stage
- attr_accessor :seed_base_harvest # maximum output from seed when calculating harvest
- attr_accessor :seed_max_fertillizer # dies after this much fertilizer is applied
- attr_accessor :water_amount_uses # amount of times item can be used for water before needing to be refilled
- attr_accessor :water_available_uses # amount of available water
- attr_accessor :seed_water_min # min times seed should be watered per stage
- attr_accessor :seed_base_harvest_min # min harvest specified instead of base amount
- attr_accessor :seed_base_harvest_max # max of harvest range if specified instead of base amount
- def garden_item_default_values
- @seed_loop = false
- @seed_stages = 0
- @seed_rate = 0
- @seed_events = []
- @seed_name = nil
- @loop_stage = 0
- @seed_terrain = nil
- @fertillizer_rate = 0.0
- @fertile_effect = 0.0
- fertillizer_terrain = nil
- @seed_optimal_water = 0
- @seed_max_water = 1<<31
- @seed_base_harvest = GardenRa::BaseHarvest
- @seed_max_fertillizer = 0.8
- @water_amount_uses = -1
- @water_available_uses = 0
- @seed_water_min = 0
- @clears_crops = false
- @seed_base_harvest_min = @seed_base_harvest
- @seed_base_harvest_max = @seed_base_harvest
- end
- #----------------------------------------------------------------------------
- # * Item is a representation of a seed?
- #----------------------------------------------------------------------------
- def is_garden_seed?
- @seed_rate > 0
- end
- #----------------------------------------------------------------------------
- # * Item is a representation of Fertillizer?
- #----------------------------------------------------------------------------
- def is_fertillizer?
- @fertillizer_rate > 0
- end
- #----------------------------------------------------------------------------
- # * Item is a representation of a watering container?
- #----------------------------------------------------------------------------
- def is_waterer?
- @water_amount_uses > -1
- end
- #----------------------------------------------------------------------------
- # * Item clears the crop infront of the player when it's used
- #----------------------------------------------------------------------------
- def clears_crops?
- @clears_crops
- end
- #----------------------------------------------------------------------------
- # * Terrains which this seed/fertillizer can be placed on
- #----------------------------------------------------------------------------
- def garden_terrains(tag)
- if is_garden_seed?
- return true if @seed_terrain.nil?
- return @seed_terrain[tag]
- else
- return true if @fertillizer_terrain.nil?
- return @fertillizer_terrain[tag]
- end
- end
- #----------------------------------------------------------------------------
- # * The seed/fertillizer can be placed anywhere?
- #----------------------------------------------------------------------------
- def garden_ok_anywhere?
- @fertillizer_terrain.nil? && @seed_terrain.nil?
- end
- #----------------------------------------------------------------------------
- # * Set the Terrain Tags for a Seed
- #----------------------------------------------------------------------------
- def set_seed_terrains(tags)
- split_tags_era(tags, @seed_terrain={})
- end
- #----------------------------------------------------------------------------
- # * Set the Terrain Tags for Fertillizer
- #----------------------------------------------------------------------------
- def set_fertillizer_terrains(tags)
- split_tags_era(tags, @fertillizer_terrain={})
- end
- #----------------------------------------------------------------------------
- # * Split Tags - Helper method to reduce repetitive code when loading in
- # terrain tag data
- #----------------------------------------------------------------------------
- def split_tags_era(tags, v)
- tags.split(",").each{ |tag|
- v[tag.strip.to_i] = true
- }
- end
- #----------------------------------------------------------------------------
- # * Update Waterer Description - modify the description of water containers
- # to show the currently available water and the maximum amount of water.
- #----------------------------------------------------------------------------
- def update_waterer_description(orig = false)
- @org_desc_gd = @description if orig
- lines = @org_desc_gd.split(/[\r\n]+/)
- lpos = lines.length-1
- carrying = "Current Water: #{@water_available_uses}"
- capacity = "Max: #{@water_amount_uses}"
- return @description = @org_desc_gd+carrying<<" "<<capacity if lpos < 0
- last = lines[lpos]
- last = "#{last} #{carrying} #{capacity}\n"
- lines[lpos] = last
- accum = ""
- lines.each{ |line|
- accum<<line<<"\r\n"
- }
- @description = accum
- end
- #----------------------------------------------------------------------------
- # * Modify the water available in a watering container
- #----------------------------------------------------------------------------
- def mod_waterer_available_uses(mod)
- @water_available_uses += mod
- if @water_available_uses < 0
- @water_available_uses = 0
- elsif @water_available_uses > @water_amount_uses
- @water_available_uses = @water_amount_uses
- end
- update_waterer_description
- end # mod_waterer_available_uses
- end # RPG::UsableItem
- #==============================================================================
- # ** RPG::MapInfo
- #==============================================================================
- class RPG::MapInfo
- attr_accessor :erosion_rate
- attr_accessor :erosion_value
- end # RPG::MapInfo
- #==============================================================================
- # ** GardenRa
- # Module containing script settings as well as the helper method plant_seed
- # which will plant a seed on the map.
- #==============================================================================
- module GardenRa
- # The default map to pull events from
- SeedMap = 2
- # Default growth rate
- DefGrowRate = 70
- # Default stages per event
- StagesPerEvent = 5
- # Will show the fertillized locations when map loaded
- ShowFertillizer = true
- # Ignore the next 'n' commands when turning if TurnFirst
- TurnDelay = 4
- # Plant seeds even if theres an event at the position
- PlantOntop = false
- # Symbol for key which allows planting/fertillizing infront of the player
- Front = :A
- # False if you want to hide the text popups that show up when harvesting
- ShowTextPopups = true
- # True if you want to use an image from a file for fertillizer
- UseSheetData = true
- # Default amount the will be harvested from plants with no base amount specified
- BaseHarvest = 7
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Specify the Graphic you want to use as fertillizer here. The graphic should
- # be stored inside Graphics/Characters.
- #
- # FertName is the name of the file with the Fertillizer graphic in it.
- #
- # Index is the index of the set of images you want to use from the file you
- # specified (for example, in the default spritesheets 8 sets of images are
- # specified per file). The index sould range from 0 - 7
- #
- # FertRow is the row you want to use as the animation for the fertillizer.
- #
- # FertFreq is how quickly the animation should iterate.
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Name of the file with the fertillizer image, the file should be stored in
- # Graphics/Characters
- FertName = '$Fertillizer'
- # The index of the set of images you want to use from the file specified above
- # can be 0 - 7 in the default engine
- FertIndex = 0
- # The row of the set of images to use based on the specifed file.
- # with the default engine this value should range from 0 - 3
- FertRow = 0
- # How quickly the graphic for the fertillizer should change.
- FertFreq = 24
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # SS is a hash representing the self switches in the game, add addtional keys
- # if you're using additional self switches for your game. I.e. if you were
- # using a self switch 'E' in your project you would change the hash to look
- # like:
- # SS = { 0 => false, 1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D', 5 => 'E' }
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- SS = { 0 => false, 1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D' }
- # The internal common event for using fertillizer
- CE_Place_Fertillizer = Proc.new{ |id, is_item|
- front = Input.press?(GardenRa::Front)
- xy = $game_temp.garden_seed_temp_xy_helper(id, front)
- rate = $data_items[id].fertillizer_rate
- $game_map.add_fertillizer(rate, [[xy[0],xy[1]]])
- }
- # The internal common event for using a seed
- CE_Plant_Seeds = Proc.new{ |id, is_item|
- item = is_item ? $data_items[id] : $data_skills[id]
- front = Input.press?(GardenRa::Front)
- xy = $game_temp.garden_seed_temp_xy_helper(id, front)
- GardenRa.plant_seed(item, $game_system.add_plant, true, {:x=>xy[0],:y=>xy[1]})
- }
- Harvest_Crop = Proc.new{ |item_id, intp, destroy|
- h=intp.harvest_garden_plant(destroy)
- item = $data_items[item_id]
- $game_party.gain_item(item, as_int = h.to_i)
- return unless (scene = SceneManager.scene).is_a?(Scene_Map) && GardenRa::ShowTextPopups
- spm = scene.instance_eval('@spriteset')
- plms= as_int < 0 ? "" : "+"
- spm.add_spgt_to_spm("#{plms}#{as_int} #{item.name}") # Add a spiggot to a spim!
- }
- Clear_Crop = Proc.new{
- map = $game_map
- seeds_to_clear = $game_temp.temp_seed_clear
- seeds_to_clear.each{ |ev|
- plant_id = ev.plant.plant_id #~*
- $game_system.destroy_plant(ev.plant.plant_id)
- }
- $game_temp.temp_seed_clear = [] # reset temp data after access
- }
- #----------------------------------------------------------------------------
- # ** Regular Expressions
- # Be sure to maintain the parenthesis if you're goint to modify specific
- # words in the regular expressions (unless you're making the changes
- # intentionally making of course).
- #----------------------------------------------------------------------------
- module RE
- # number stages of growth
- Stages = /<Seed stages (\d+)>/i
- # do stages loop?
- Loop = /<Seed loop (true|false|t|f)>/i
- # growth rate, larger means slower
- Rate = /<Seed rate (\d+)>/i
- # Can specify the name of the seed per item
- SeedName = /<Seed name (.+)>/i
- # The stage to be looped back to
- LoopStage = /<Seed loop stage (\d+)>/i
- # The terrain tags a seed can be planted on
- SeedTerrain = /<\s*Seed\s*terrain\s*(\d+\s*(?:,\s*\d+\s*)*)\s*>/i
- # Use to set an item as a fertillizer and give it a fertillizer concentration
- Fertillizer = /<\s*Seed\s*Fertillizer\s*((?:\d+|)\.(?:\d+))\s*>/i
- # The effect that fertillizer has on this specific seed. The lower the value
- # provided, the more resistant the seed is to being fertillized.
- FertileEffect = /<\s*Seed\s*Fertile\s*rate\s*((?:\d+|)\.(?:\d+))\s*>/i
- # Terrain where fertillizer can be placed
- FertTerrain = /<\s*Seed\s*Fertillizer\s*terrain\s*(\d+\s*(?:,\s*\d+\s*)*)\s*>/i
- # The maximum concentration of fertillizer a plant can grow in.
- MaxFertillizer = /<\s*Seed\s*max\s*fertillizer\s*((?:\d+|)\.(?:\d+))\s*>/i
- # The optimal amount of times that a plant should be watered during each
- # growth stage
- OptimalWaterPerStage = /<\s*Seed\s*optimal\s*water\s*(\d+)\s*>/i
- # The plant will die if it is watered more than this many times on one stage
- OverWatered = /<\s*Seed\s*max\s*water\s*(\d+)\s*>/i
- # Maximum base output from this plant, this value can be exceeded if the
- # plant is fertillized.
- MaxHarvest = /<\s*Seed\s*harvest\s*(\d+)\s*>/i
- # Harvest range can be specified instead of a base harvest amount
- HarvestRange = /<\s*Seed\s*harvest\s*(\d+)\s*-\s*(\d+)\s*>/i
- # The maximum amount of water a container can hold
- SeedWatering = /<\s*water\s*container\s*(\d+)\s*>/i #
- # The minimum amount of times a seed must be watered per growth stage
- SeedWateringMin = /<\s*Seed\s*min\s*water\s*(\d+)\s*>/i # minimum times a seedmust be watered per growth stage
- # How much the fertillizer will be reduced on this map when it is eroding
- FertillizerErodeAmt = /<\s*Erosion\s*Value\s*((?:\d+|)\.(?:\d+))>/i
- # How quickly the map will erode, specified in frames
- FertillizerErodeRate = /<\s*Erosion\s*Rate\s*(\d+)>/i
- # Item can be used to clear crops out of the way
- ClearCrops = /<\s*clears\s*crops\s*(\d+|)\s*>/i
- end # RE
- #----------------------------------------------------------------------------
- # * Plant Seed
- # param: args[0] is the item (the seed) that is being planted
- # param: args[1] is the id of the plant
- # param: args[2] is true if the seed is being planted for the first time
- # param: args[3] is an options hash to be given to the EventEng script
- # param: args[4] is the position in item.seed_events which will be accessed to
- # get the event's id for the new seed.
- # param: args[5] is a numeric representation of what stage the plants growth
- # is on.
- #----------------------------------------------------------------------------
- def self.plant_seed(*args)
- item = args[0]
- plant_id = args[1] # the unique plant id this event is associated with
- planting = args[2]
- opts = (t = args[3]) ? t : {} # optional
- pos = (t = args[4]) ? t : 0 # optional
- stage = (t = args[5]) ? t : 1 # optional
- options = {
- :map_id => GardenRa::SeedMap,
- :x => $game_player.x,
- :y => $game_player.y,
- :persist => false,
- :dir => 2,
- :SS => {} # hash of self switches can be passed ({:A => true...})
- }.merge(opts)
- t = $game_system.plant_info(plant_id)
- t[:item] = item
- t[:pos] = pos
- t[:cur_stage] = stage
- t[:max_fertile] ||= item.seed_max_fertillizer
- t[:grow_frames] ||= item.seed_rate
- t[:loop] ||= item.seed_loop
- t[:loop_stage] ||= item.loop_stage
- t[:fertile_effect] ||= item.fertile_effect
- e_id = item.seed_events[t[:pos]]
- event = EventSpawn.spawn_event(options[:map_id], e_id, options[:x],
- options[:y], options[:persist], options[:dir], options[:SS])
- event.start_plant(plant_id, planting) unless event.nil?# Only time a garden object is created
- end # plant_seed
- #----------------------------------------------------------------------------
- # Self switch which corresponds to param: stage
- #----------------------------------------------------------------------------
- def self.stage_to_ss(stage)
- SS[(stage-1) % GardenRa::StagesPerEvent]
- end # stage_to_ss
- end # GardenRa
- #==============================================================================
- # ** DataManager
- # Loads item data for fertillizers and seeds
- #==============================================================================
- module DataManager
- #----------------------------------------------------------------------------
- # * Alias - load_database
- #----------------------------------------------------------------------------
- class <<self
- alias load_garden_seed_pl_ntags load_database
- end
- #----------------------------------------------------------------------------
- # * Load Database
- #----------------------------------------------------------------------------
- def self.load_database
- load_garden_seed_pl_ntags
- load_tags_garden_seed_itm
- end
- #----------------------------------------------------------------------------
- # * Load Tags
- #----------------------------------------------------------------------------
- def self.load_tags_garden_seed_itm
- iter = [$data_items, $data_skills]
- @tmp_map = load_data(sprintf("Data/Map%03d.rvdata2", GardenRa::SeedMap))
- hv_err_msg = "A harvest base amount and harvest range was specified for"
- iter.each do |set|
- set.each_with_index do |item, i|
- next unless item
- item.garden_item_default_values
- item.note.split(/[\r\n]+/).each do |line|
- case line
- when GardenRa::RE::Stages
- item.seed_stages = $1.to_i
- when GardenRa::RE::Loop
- item.seed_loop = $1.eql?("true") || $1.eql?("t")
- when GardenRa::RE::Rate
- item.seed_rate = $1.to_i
- when GardenRa::RE::SeedName
- item.seed_name = $1
- when GardenRa::RE::LoopStage
- item.loop_stage = $1.to_i
- when GardenRa::RE::SeedTerrain
- item.set_seed_terrains($1)
- when GardenRa::RE::Fertillizer
- item.fertillizer_rate = $1.to_f
- when GardenRa::RE::FertileEffect
- item.fertile_effect = $1.to_f
- when GardenRa::RE::FertTerrain
- item.set_fertillizer_terrains($1)
- when GardenRa::RE::OptimalWaterPerStage
- item.seed_optimal_water = $1.to_i
- when GardenRa::RE::OverWatered
- item.seed_max_water = $1.to_i
- when GardenRa::RE::MaxHarvest
- if item.seed_base_harvest_min != item.seed_base_harvest_max
- dt = " #{item.is_a?(RPG::Skill) ? "skill" : "item"} #{item.id}"
- raise hv_err_msg << dt
- end
- item.seed_base_harvest = $1.to_i
- when GardenRa::RE::HarvestRange
- if item.seed_base_harvest != GardenRa::BaseHarvest
- dt = " #{item.is_a?(RPG::Skill) ? "skill" : "item"} #{item.id}"
- raise hv_err_msg << dt
- end
- item.seed_base_harvest_min = $1.to_i
- item.seed_base_harvest_max = $2.to_i
- when GardenRa::RE::MaxFertillizer
- item.seed_max_fertillizer = $1.to_f
- when GardenRa::RE::SeedWatering
- item.water_available_uses = item.water_amount_uses = $1.to_i
- item.update_waterer_description(true)
- item.is_unique_rpgbi = true
- when GardenRa::RE::SeedWateringMin
- item.seed_water_min = $1.to_i
- when GardenRa::RE::ClearCrops
- item.clears_crops = $1.to_i
- end
- end
- load_seed_events(i,item.instance_of?(RPG::Item))
- end # set.each_with_index
- end # iter.each
- end # load_tags_garden_seed_itm
- #----------------------------------------------------------------------------
- # * Load seed events - store the event data
- #----------------------------------------------------------------------------
- def self.load_seed_events(i, is_item)
- item = is_item ? $data_items[i] : $data_skills[i]
- temp_hash = {}
- item.seed_events = []
- events = @tmp_map.events
- name = !(s = item.seed_name).nil? ? s : item.name
- events.values.each do |ev|
- next unless ev
- case ev.name
- when /^#{name} (\d+)\s*$/i
- temp_hash[$1.to_i] = ev.id # temporarily store the events in a hash
- end
- end
- keys = temp_hash.keys.sort! # order the events
- keys.each{ |k| item.seed_events.push(temp_hash[k]) } # store events in order
- end # load_seed_events
- end # DataManager
- #==============================================================================
- # ** Garden_Object
- # The representation of a plant.
- #==============================================================================
- class Garden_Object
- attr_reader :low
- attr_reader :plant_id
- attr_reader :fertillized
- #----------------------------------------------------------------------------
- # * Initialize
- #----------------------------------------------------------------------------
- def initialize(plant_id, ev_id, planting = false)
- @low = true
- @ev_id = ev_id
- @plant_id = plant_id
- @p_info = $game_system.plant_info(@plant_id)
- load_grow_data
- apply_fertillizer if planting
- store_init_data
- store_xy
- end
- #----------------------------------------------------------------------------
- # * Apply Fertillizer
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # The Fertillizer's effect is calculated by multplying the fertile_effect of
- # the seed with the fertilizer_rate of the of its location on the map and
- # then applying that value to @grow_frames.
- # Example:
- # A spot on the map with a fertillizer concentration of .5 applied to a
- # seed which grows every 50 frames with a "fertile_effect" of .9 would
- # end up with a grow_rate of 0.9*0.5*50 = 22.5.
- #----------------------------------------------------------------------------
- def apply_fertillizer
- f_data = $game_system.fertillizer_data
- ev = $game_map.events[@ev_id]
- x,y = ev.x, ev.y
- f_rate = f_data[[x,y]]
- return if !f_rate
- f_effect = @p_info[:item].fertile_effect
- f_effect = !f_effect.nil? ? f_effect : (@p_info[:item].fertile_effect = 1)
- f_rate = !f_rate.nil? ? f_rate + (f_rate * f_effect) : 1
- update_fertile_input(f_rate)
- new_gf = [@grow_frames * (1-f_rate),1].max.to_i
- @p_info[:grow_frames] = @grow_frames = new_gf
- end
- #----------------------------------------------------------------------------
- # * Update Fertillizer Input
- #----------------------------------------------------------------------------
- def update_fertile_input(rate)
- @p_info[:fertile_input] = rate
- end
- #----------------------------------------------------------------------------
- # * Store position
- #----------------------------------------------------------------------------
- def store_xy
- event = $game_map.events[@ev_id]
- @p_info[:x], @p_info[:y] = event.x, event.y
- end
- #----------------------------------------------------------------------------
- # * Plant id should be added to the game system before making a garden object
- #----------------------------------------------------------------------------
- def load_grow_data
- update_grow_frame((t = @p_info[:base_frame]) ? t : $game_system.garden_timer)
- @grow_frames = (t = @p_info[:grow_frames]) ? t : GardenRa::DefGrowRate
- @simple = (t = @p_info[:simple]) ? t : true # literal
- @loop = (t = @p_info[:loop]) ? t : false # literal
- @loop_stage = (t = @p_info[:loop_stage]) ? t : 1 #literal
- end
- #----------------------------------------------------------------------------
- # * Update Grow Frame
- #----------------------------------------------------------------------------
- def update_grow_frame(frame = @base_frame)
- @p_info[:base_frame] = @base_frame = frame
- end
- #----------------------------------------------------------------------------
- # * Store Init Data
- #----------------------------------------------------------------------------
- def store_init_data
- @p_info[:grow_frames] = @grow_frames
- @p_info[:simple] = @simple
- @p_info[:loop] = @loop
- @p_info[:loop_stage] = @loop_stage
- @p_info[:event_id] = @ev_id
- end
- #----------------------------------------------------------------------------
- # * Loop Stage
- #----------------------------------------------------------------------------
- def loop_stage
- @p_info[:loop_stage]
- end
- #----------------------------------------------------------------------------
- # * Last Stage
- #----------------------------------------------------------------------------
- def last_stage
- @p_info[:item].seed_stages
- end
- #----------------------------------------------------------------------------
- # * Update
- #----------------------------------------------------------------------------
- def update
- check_should_die
- return if @p_info[:dead]
- return if (needs_to_loop = stage == item.seed_stages) && !@loop
- return if !@loop && stage == last_stage
- if need_jump?
- jump_ahead
- else
- update_grow(needs_to_loop)
- end
- end
- #----------------------------------------------------------------------------
- # * Modify the times the plant has been watered
- #----------------------------------------------------------------------------
- def mod_times_watered(st,fn,reset=true,mod=0)
- $game_system.mod_times_watered(@plant_id, loop_stage, last_stage, reset, mod)
- end
- #----------------------------------------------------------------------------
- # * Does the plant need to 'jump' to the correct stage after not having been
- # updated for awhile. (Not on scene map or the map is being reloaded
- # after the player was transferred to it for the first time in some time)
- #----------------------------------------------------------------------------
- def need_jump?
- ($game_system.garden_timer - @p_info[:base_frame]) > @grow_frames
- end
- #----------------------------------------------------------------------------
- # * Update grow
- #----------------------------------------------------------------------------
- def update_grow(should_loop = false)
- if (gt = $game_system.garden_timer) - @p_info[:base_frame] == @grow_frames
- mod_times_watered(loop_stage, last_stage) if should_loop
- update_grow_frame(gt)
- if should_loop && @loop
- old_stage = @p_info[:cur_stage]
- st_per = GardenRa::StagesPerEvent
- old_pos = pos
- update_stage(@p_info[:loop_stage])
- nxt_ev
- else
- on_grow
- end
- $game_map.refresh
- end
- end
- #----------------------------------------------------------------------------
- # * Are Any Selfswitches On? - Currently only used for debugging,
- # can be removed
- #----------------------------------------------------------------------------
- def any_ss_on?
- EventSpawn::Constants::SS.each{|l|
- return true if $game_self_switches[[$game_map.map_id, @ev_id, l]]
- }
- return false
- end
- #----------------------------------------------------------------------------
- # * Update Stage
- #----------------------------------------------------------------------------
- def update_stage(new_stage)
- @p_info[:cur_stage] = new_stage
- @p_info[:pos] = (@p_info[:cur_stage] - 1)/GardenRa::StagesPerEvent
- end
- #----------------------------------------------------------------------------
- # * On Last Stage
- #----------------------------------------------------------------------------
- def on_last_stage
- stage == last_stage
- end
- #----------------------------------------------------------------------------
- # * Stage
- #----------------------------------------------------------------------------
- def stage
- @p_info[:cur_stage]
- end
- #----------------------------------------------------------------------------
- # * Pos
- #----------------------------------------------------------------------------
- def pos
- @p_info[:pos]
- end
- #----------------------------------------------------------------------------
- # * Times Watered
- #----------------------------------------------------------------------------
- def times_watered(st = stage)
- (@p_info[:watered_vals]||={})[st]||=0
- end
- #----------------------------------------------------------------------------
- # * Max Water
- #----------------------------------------------------------------------------
- def max_water
- item.seed_max_water
- end
- #----------------------------------------------------------------------------
- # * On plant grow by default all plants are 'simple' but feel free to write
- # more complicated growth patterns for plants.
- #----------------------------------------------------------------------------
- def on_grow
- grow_simple if @simple
- end
- #----------------------------------------------------------------------------
- # * Kill the plant
- #----------------------------------------------------------------------------
- def kill_plant(should_kill=true)
- @p_info[:dead] = true
- end
- #----------------------------------------------------------------------------
- # * Minimum number of times the plant should be watered per stage
- #----------------------------------------------------------------------------
- def min_water
- item.seed_water_min
- end
- #----------------------------------------------------------------------------
- # * Should the plant advance to the next stage?
- #----------------------------------------------------------------------------
- def is_at_stage_tic
- $game_system.garden_timer - @p_info[:base_frame] == @grow_frames
- end
- #----------------------------------------------------------------------------
- # * Check if the plant should still be alive
- #----------------------------------------------------------------------------
- def check_should_die(about_to_jump = false)
- # can't dry up once on the last stage
- dried_up = (is_at_stage_tic || about_to_jump) && !(min = min_water).nil? &&
- times_watered < min && !on_last_stage
- roots_molded = !(max = max_water).nil? && times_watered > max
- if dried_up || roots_molded
- return kill_plant
- end
- # if fertillizer is too concentrated or if watered too many times, @p_info[:dead] = true
- return unless (cur=@p_info[:fertile_input]) && (max = @p_info[:max_fertile])
- if cur > max
- return kill_plant
- end
- end
- #----------------------------------------------------------------------------
- # * Dead?
- #----------------------------------------------------------------------------
- def dead?
- @p_info[:dead]
- end
- #----------------------------------------------------------------------------
- # * Harvest
- # Returns an integer value calculated from the amount of times the plant
- # was watered at each stage, the optimal amount of times for it to be
- # watered, and the amount of fertillizer that was applied to it.
- #----------------------------------------------------------------------------
- def harvest
- return 0 if dead?
- min=min_harvest_range
- max=max_harvest_range
- base_output = min == max && min == GardenRa::BaseHarvest ? base_harvest : rand(max-min) + min + 1
- fertillizer = fertillizer_concentration
- offset_output = base_output * fertillizer + base_output
- offset = 1-((t=number_stages_not_watered_optimally.to_f)/last_stage)
- total_harvest = offset_output * offset
- print "harvest: \n"
- print " base_output = #{base_output}\n"
- print " number_stages_not_watered_optimally = #{t}\n"
- print " fertillizer = #{fertillizer}\n"
- print " offset_output = #{offset_output}\n"
- print " offset = #{offset}\n"
- print " total harvest = #{total_harvest}\n"
- return total_harvest.to_i
- end
- #----------------------------------------------------------------------------
- # * Fertillizer concentration
- #----------------------------------------------------------------------------
- def fertillizer_concentration
- @p_info[:fertile_input] ||= 0
- end
- #----------------------------------------------------------------------------
- # * Not including the last stage
- #----------------------------------------------------------------------------
- def number_stages_not_watered_optimally
- count = 0
- optimal_water_per_st = optimal_water
- (1...last_stage).each{ |st|
- count += 1 if times_watered(st) != optimal_water_per_st
- }
- count
- end
- #----------------------------------------------------------------------------
- # * Optimal times the plant should be watered on each stage
- #----------------------------------------------------------------------------
- def optimal_water
- item.seed_optimal_water
- end
- #----------------------------------------------------------------------------
- # * Base harvest amount
- #----------------------------------------------------------------------------
- def base_harvest
- item.seed_base_harvest
- end
- #----------------------------------------------------------------------------
- # * Minimum of harvest range
- #----------------------------------------------------------------------------
- def min_harvest_range
- item.seed_base_harvest_min
- end
- #----------------------------------------------------------------------------
- # * Maximum of harvest range
- #----------------------------------------------------------------------------
- def max_harvest_range
- item.seed_base_harvest_max
- end
- #----------------------------------------------------------------------------
- # The default garden plant will grow by turning its selfswitches on
- # sequentially from A to D and then turning them all off and repeating.
- #----------------------------------------------------------------------------
- def grow_simple
- stage = (@p_info[:cur_stage] += 1)
- map_id = $game_map.map_id
- ch = GardenRa.stage_to_ss(stage)
- if !ch
- handle_last_page
- else
- turn_on_ss(ch)
- end
- e = $game_map.events[@ev_id]
- e.refresh unless e.nil? # nil when queuing a new event for the plant
- end
- #----------------------------------------------------------------------------
- # * The item associated with this plant
- #----------------------------------------------------------------------------
- def item
- @p_info[:item]
- end
- #----------------------------------------------------------------------------
- # * The last stage that the current event has stored for this plant. I.e.
- # the next event for this plants growth cycle will need to be placed on
- # the map.
- #----------------------------------------------------------------------------
- def handle_last_page
- nxt_ev if item.seed_events[@p_info[:pos]+1]
- end # handle_last_page
- #----------------------------------------------------------------------------
- # * Replace the plants event, removes the current event associated with the
- # plant and queues a new one to be placed on the map.
- #----------------------------------------------------------------------------
- def replace_plant_event(opts={})
- map = $game_map
- p_info = $game_system.plant_info(@plant_id)
- event = map.events[@ev_id]
- options = { :x => event.x, :y => event.y, :persist => false }.merge(opts)
- map.destroy_event_any(@ev_id)
- map.add_seed_to_plant(p_info[:item], @plant_id, false, options, p_info[:pos],
- p_info[:cur_stage])
- end
- #----------------------------------------------------------------------------
- # * Jump to the proper stage when reloading the plant on the map.
- #----------------------------------------------------------------------------
- def jump_ahead
- dead = check_should_die(true) # param just tells method the plant wants to jump
- return if dead
- map, sys = $game_map, $game_system
- st_per = GardenRa::StagesPerEvent
- jump = ((gt = sys.garden_timer) - @p_info[:base_frame]) / @grow_frames # stages to skip
- update_grow_frame(@p_info[:base_frame]+jump*@grow_frames)#((gt-@grow_frames) + ((gt - @base_frame) % @grow_frames))
- old_stage = @p_info[:cur_stage]
- # calculate roll over if @loop
- loop_back = @loop && (n_st = jump + old_stage) > @p_info[:item].seed_stages
- mod_times_watered(loop_stage, last_stage) if loop_back
- new_stage = false
- excess = 0
- if loop_back
- # loop in between:
- loop_btw = @p_info[:item].seed_stages - (@p_info[:loop_stage]-1)
- excess = n_st - @p_info[:item].seed_stages
- new_stage = (@p_info[:loop_stage]-1) + (excess % loop_btw)
- end
- # store updated plant data
- old_pos = (pos-1)/st_per
- update_stage(new_stage ? new_stage : [old_stage + jump, item.seed_stages].min)
- nxt_ev
- end
- #----------------------------------------------------------------------------
- # * Queue up a new plant('seed to be planted') when the current plant has
- # moved through all of the stages for its the current event
- #----------------------------------------------------------------------------
- def nxt_ev
- @p_info[:pos] = (@p_info[:cur_stage]-1)/GardenRa::StagesPerEvent
- ch = GardenRa.stage_to_ss(@p_info[:cur_stage])
- opts = !ch ? {} : {:SS => {ch.to_sym => true}}
- replace_plant_event(opts)
- end
- #----------------------------------------------------------------------------
- # * Turn on Selfswich
- #----------------------------------------------------------------------------
- def turn_on_ss(ch, is_on = true)
- $game_self_switches[[$game_map.map_id, @ev_id, ch]] = is_on unless !ch
- end
- #----------------------------------------------------------------------------
- # * Reset Selfswitches
- #----------------------------------------------------------------------------
- def reset_ss
- EventSpawn::Constants::SS.each{|l| turn_on_ss(l,false)}
- end
- #----------------------------------------------------------------------------
- # *
- #----------------------------------------------------------------------------
- #def destroy_self
- # $game_system.destroy_plant(@plant_id)
- # map.destroy_event_any(@ev_id)
- #end
- #----------------------------------------------------------------------------
- # * Print what memory looks like
- #----------------------------------------------------------------------------
- def debug
- print "\n"
- print "debug data:"
- print " plant_id = #{@plant_id} event_id = #{@ev_id}\n"
- print " @p_info = #{@p_info}\n"
- print " garden timer = #{$game_system.garden_timer}\n"
- print " current stage = #{@p_info[:cur_stage]}\n"
- print " pos = #{pos}\n"
- print " self switches A = #{$game_self_switches[[$game_map.map_id, @ev_id, "A"]]}\n"
- print " self switches B = #{$game_self_switches[[$game_map.map_id, @ev_id, "B"]]}\n"
- print " self switches C = #{$game_self_switches[[$game_map.map_id, @ev_id, "C"]]}\n"
- print " self switches D = #{$game_self_switches[[$game_map.map_id, @ev_id, "D"]]}\n"
- end
- end # Garden_Object
- #==============================================================================
- # ** Game_System
- #==============================================================================
- class Game_System
- attr_accessor :garden_timer
- attr_accessor :garden_plants # map_id => event_id => :sym => value
- Epsilon_GS_Era = 0.00001 # Fertillizer removed if concentration is < this value
- #----------------------------------------------------------------------------
- # * Alias - Initialize
- #----------------------------------------------------------------------------
- alias init_g_plt_hash_get_data_on_reload initialize
- def initialize
- @garden_timer, @plant_ids = 0, 0
- @garden_plants, @garden_fertillizer = {},{} # maps ids to base frames
- init_g_plt_hash_get_data_on_reload
- end
- #----------------------------------------------------------------------------
- # * Alias - on_after_load
- #----------------------------------------------------------------------------
- alias on_after_ld_add_evs_garden_to_m on_after_load
- def on_after_load
- on_after_ld_add_evs_garden_to_m
- $game_map.place_all_plants
- end
- #----------------------------------------------------------------------------
- # * Update Garden Timer
- #----------------------------------------------------------------------------
- def update_garden(erode = true)
- @garden_timer += 1 unless @garden_timer.nil?
- update_erosion if erode
- end
- #----------------------------------------------------------------------------
- # * Erode the fertillizer away from all of the maps in the game.
- #----------------------------------------------------------------------------
- def update_erosion
- @garden_fertillizer.keys.each{ |map_id| # ids for each map with fertillizer
- minfo = $data_mapinfos[map_id]
- map_erode_rate = minfo.erosion_rate
- map_erode_val = minfo.erosion_value
- valid = !map_erode_rate.nil? && !map_erode_val.nil?
- next unless valid && @garden_timer % map_erode_rate == 0
- fert_xys = @garden_fertillizer[map_id]
- fert_xys.keys.each{ |xy| # fertillizer values for each xy
- next unless !fert_xys[xy].nil?
- fert_xys[xy] = [fert_xys[xy]-map_erode_val,0.0].max
- if fert_xys[xy] < Epsilon_GS_Era
- fert_xys.delete(xy)
- remove_saved_highlight(xy[0],xy[1],map_id)
- $game_map.setup_map_highlights_era(map_id)
- update_erosion_helper_del_hl(map_id)
- end
- }
- }
- end
- #----------------------------------------------------------------------------
- # * Update the highlights if current map is $game_map
- #----------------------------------------------------------------------------
- def update_erosion_helper_del_hl(map_id)
- return unless $game_map.map_id == map_id
- return unless (scene = SceneManager.scene).is_a?(Scene_Map)
- spm = scene.instance_eval('@spriteset')
- spm.refresh_highlights unless spm.nil?
- end
- #----------------------------------------------------------------------------
- # * Plant Info
- # @garden_plants[map_id][:fertillized] is a hash mapping x,y values to
- # booleans. True if that location is fertillized.
- #----------------------------------------------------------------------------
- def plant_info(plant_id = nil)
- map_id = $game_map.map_id
- !plant_id.nil? ? (return @garden_plants[map_id][plant_id]) : (return @garden_plants[map_id])
- end
- #----------------------------------------------------------------------------
- # * Removes a plants information from the game_system
- #----------------------------------------------------------------------------
- def destroy_plant(plant_id, map_id = nil)
- map = $game_map
- map_id = map_id.nil? ? map.map_id : map_id
- gpm = @garden_plants[map_id]
- ev_id = gpm[plant_id][:event_id]
- map.destroy_event_any(ev_id) if map_id == map.map_id
- gpm.delete(plant_id)
- end
- #----------------------------------------------------------------------------
- # * Get the Fertillizer Data For the Current Map
- #----------------------------------------------------------------------------
- def fertillizer_data
- map_id = $game_map.map_id
- return @garden_fertillizer[map_id]||={}
- end
- #----------------------------------------------------------------------------
- # * Next Plant Id
- #----------------------------------------------------------------------------
- def next_plant_id
- @plant_ids + 1
- end
- #----------------------------------------------------------------------------
- # * Add Plant
- #----------------------------------------------------------------------------
- def add_plant(map_id=nil)
- map_id = map_id.nil? && $game_map.nil? ? map_id : $game_map.map_id
- return if map_id.nil?
- @garden_plants[map_id][@plant_ids+=1] = {}
- return @plant_ids
- end
- #----------------------------------------------------------------------------
- # * Plant Added
- #----------------------------------------------------------------------------
- def plant_added?(id)
- @plant_ids + 1 > id
- end
- #----------------------------------------------------------------------------
- # * Water the Plant with id = param: plant_id
- #----------------------------------------------------------------------------
- def water_plant_era(plant_id, times=1)
- p_info = plant_info(plant_id)
- stage = p_info[:cur_stage]
- p_info[:watered_vals] ||= {}
- p_info[:watered_vals][stage] ||= 0
- p_info[:watered_vals][stage] += times
- end
- #----------------------------------------------------------------------------
- # * Modify the amount of times a plant has been watered
- # param: first, the stage to start modifying at
- # param: last, the last stage in the range to modify
- #----------------------------------------------------------------------------
- def mod_times_watered(plant_id, first, last, reset = true, mod=0)
- p_info = plant_info(plant_id)
- w_vals = p_info[:watered_vals] ||= {}
- (first..last).each{ |stage|
- w_vals[stage] = reset ? 0 : (w_vals[stage] ? [w_vals[stage]+mod,0].min : 0)
- }
- end # mod_times_watered
- end # Game_System
- #==============================================================================
- # ** Game_Map
- # Load plant and fertillizer data for the current map when setting up.
- # Allow plants to be queue
- #==============================================================================
- class Game_Map
- #----------------------------------------------------------------------------
- # * Alias - setup
- #----------------------------------------------------------------------------
- alias set_up_garden_ch_for_old_hash setup
- def setup(map_id)
- $game_system.garden_plants[map_id] ||= {}
- @era_seeds_to_plant = []
- # redraw spriteset for scene map
- set_up_garden_ch_for_old_hash(map_id)
- setup_erosion_vals
- end
- #----------------------------------------------------------------------------
- # * Alias - update
- #----------------------------------------------------------------------------
- alias upd_pl_seeds_af_update_hash_new_item update
- def update(*args)
- upd_pl_seeds_af_update_hash_new_item(*args)
- plant_seeds_after_update
- place_all_plants if @want_to_place_plants
- end
- #----------------------------------------------------------------------------
- # * Alias - setup_events
- #----------------------------------------------------------------------------
- alias setup_evs_add_plant_evs_for_map setup_events
- def setup_events
- setup_evs_add_plant_evs_for_map
- # make plant events from data inside Game_System
- place_all_plants
- end
- #----------------------------------------------------------------------------
- # * Place all plants back on the map when reloading
- #----------------------------------------------------------------------------
- def place_all_plants
- return !(@want_to_place_plants = true) if !SceneManager.scene.is_a?(Scene_Map)
- plant_data = $game_system.plant_info
- plant_data.keys.each{ |plant_id|
- p_info = plant_data[plant_id]
- x, y = p_info[:x], p_info[:y]
- ch = GardenRa.stage_to_ss(cur_stage = p_info[:cur_stage])
- ss = !ch ? {} : {ch.to_sym => true}
- GardenRa.plant_seed(p_info[:item], plant_id, false, {:x=>x, :y=>y, :SS=>ss}, p_info[:pos],
- cur_stage)
- }
- refresh
- @want_to_place_plants = false
- end
- #----------------------------------------------------------------------------
- # * Plant the queued seeds
- #----------------------------------------------------------------------------
- def plant_seeds_after_update
- @era_seeds_to_plant.each{ |args| GardenRa.plant_seed(*args) }
- @era_seeds_to_plant = []
- end
- #----------------------------------------------------------------------------
- # * Add Seed to Plant - Queue up planting a seed
- #----------------------------------------------------------------------------
- def add_seed_to_plant(*args)
- @era_seeds_to_plant.push(args) # Order is not checked but shouldn't be modified
- end
- #----------------------------------------------------------------------------
- # * Setup Erosion Values
- #----------------------------------------------------------------------------
- def setup_erosion_vals
- dmap = $data_mapinfos[@map_id]
- if dmap.erosion_rate.nil? || dmap.erosion_value.nil?
- @map.note.split(/[\r\n+]/).each{ |line|
- case line
- when GardenRa::RE::FertillizerErodeAmt
- dmap.erosion_value = $1.to_f
- when GardenRa::RE::FertillizerErodeRate
- dmap.erosion_rate = $1.to_i
- end
- }
- end
- end
- #----------------------------------------------------------------------------
- # * Seed Location Ok?
- #----------------------------------------------------------------------------
- def seed_location_ok?(x,y)
- if !GardenRa::PlantOntop # Don't plant ontop of non erased events
- events_xy(x,y).each{ |ev| return false if ev && !ev.instance_eval('@erase')}
- end
- return true
- end
- #----------------------------------------------------------------------------
- # * Add Fertillizer
- #----------------------------------------------------------------------------
- def add_fertillizer(rate, range)
- map_info = $game_system.fertillizer_data
- range.each{ |xy|
- x,y = xy[0], xy[1]
- t = map_info[xy]
- map_info[xy] = t ? t + (t * rate) : rate
- events_xy(x,y).each{ |ev| ev.apply_fertillizer} #update plants w/ fertillizer
- if GardenRa::UseSheetData
- sh = Sheet_Data.new(GardenRa::FertName,GardenRa::FertIndex,GardenRa::FertRow)
- end
- spm = SceneManager.scene.instance_eval("@spriteset")
- spm.add_highlight(:x => x, :y => y, :sh => sh, :retain => true, :opacity => 255) if GardenRa::ShowFertillizer
- }
- end # add_fertillizer
- end # Game_Map
- #==============================================================================
- # ** Game_Event
- # Associates an event with a plant.
- #==============================================================================
- class Spriteset_Map
- attr_accessor :map_id
- end
- class Game_Event
- attr_accessor :plant
- attr_accessor :opacity
- #----------------------------------------------------------------------------
- # * Alias - Initialize
- #----------------------------------------------------------------------------
- alias initialize_gard_ev__grow initialize
- def initialize(*args)
- initialize_gard_ev__grow(*args)
- #create_garden_obj
- end
- # show plant under player? (for use when planting)
- def low; @plant ? @plant.low : false; end
- #----------------------------------------------------------------------------
- # * Alias - Screen Z
- #----------------------------------------------------------------------------
- alias garden_plant_screen_z_ed screen_z
- def screen_z
- return garden_plant_screen_z_ed if @plant.nil?
- ls = @plant.stage == @plant.last_stage
- if !ls && (p=$game_player).real_x.to_i == @x && p.real_y.to_i == @y
- return garden_plant_screen_z_ed - 1 #show under player when planting
- else
- return garden_plant_screen_z_ed
- end
- end
- #----------------------------------------------------------------------------
- # * Alias - Update
- #----------------------------------------------------------------------------
- alias update_ch_garden_obj_ud update
- def update
- update_ch_garden_obj_ud
- @plant.update unless @plant.nil?
- end
- #----------------------------------------------------------------------------
- # * Start Plant
- #----------------------------------------------------------------------------
- def start_plant(plant_id, planting = false)
- @plant = Garden_Object.new(plant_id, @id, planting)
- end
- #----------------------------------------------------------------------------
- # * Plant Dead?
- #----------------------------------------------------------------------------
- def garden_plant_dead?
- return !@plant.nil? && @plant.dead?
- end
- #--------------------------------------------------------------------------
- # * Alias move_straight - update the location of the plant in game_system
- #--------------------------------------------------------------------------
- alias mve_strght_mod_edit_upd_str_gard_upd move_straight
- def move_straight(dir, turn_ok = true)
- mve_strght_mod_edit_upd_str_gard_upd(dir)
- update_garden_plant_xy if @plant
- end
- #--------------------------------------------------------------------------
- # * Alias move_diagonal- update the location of the plant in game_system
- #--------------------------------------------------------------------------
- alias mv_diag_gard_upd_pl_posit_upd move_diagonal
- def move_diagonal(horz, vert)
- mv_diag_gard_upd_pl_posit_upd(horz, vert)
- update_garden_plant_xy if @plant.plant_id
- end
- #----------------------------------------------------------------------------
- # * Update plant position if the event moves
- #----------------------------------------------------------------------------
- def update_garden_plant_xy
- p_info = $game_system.plant_info(@plant.plant_id)
- p_info[:x], p_info[:y] = @x, @y
- end
- #----------------------------------------------------------------------------
- # * Apply Fertillizer
- #----------------------------------------------------------------------------
- def apply_fertillizer
- return unless @plant
- return if @plant.dead? || @plant.stage == @plant.last_stage # on last stage or dead
- @plant.apply_fertillizer # applier fertillizer from current location to growth rate
- end # apply_fertillizer
- end # Game_Event
- #==============================================================================
- # ** Scene_Base
- # * Update the garden timer when inside any scene.
- #==============================================================================
- class Scene_Base
- #----------------------------------------------------------------------------
- # * Alias - update
- #----------------------------------------------------------------------------
- alias upd_timer_for_farm_evs update
- def update
- upd_timer_for_farm_evs
- update_garden_timer
- end
- #----------------------------------------------------------------------------
- # * Update Garden Timer
- #----------------------------------------------------------------------------
- def update_garden_timer
- $game_system.update_garden
- end
- end # Scene_Base
- #==============================================================================
- # ** Scene_Map
- # Add gui for selecting a watering container.
- #==============================================================================
- class Scene_Map < Scene_Base
- #----------------------------------------------------------------------------
- # * Start
- #----------------------------------------------------------------------------
- alias st_add_cd_draw_sp_highl_era start
- def start
- st_add_cd_draw_sp_highl_era
- end
- #----------------------------------------------------------------------------
- # * Create Waterer Options Window
- #----------------------------------------------------------------------------
- def create_window_waterer_opts
- @waterer_opts_window = Window_ShowOptsEra.new(300,200,82,79)
- @waterer_opts_window.viewport = @viewport
- @waterer_opts_window.set_handler(:ok, method(:process_choice_era))
- @waterer_opts_window.set_handler(:cancel, method(:on_ch_cancel_era))
- @waterer_opts_window.hide
- end
- #----------------------------------------------------------------------------
- # * Create Water Question Window
- #----------------------------------------------------------------------------
- def create_window_water_question
- x,y = Graphics.width * 0.2, Graphics.height * 0.7
- w,h = 300, 55
- @waterer_question_window = Window_WatererText.new(x,y,w,h)
- @waterer_question_window.viewport = @viewport
- @waterer_question_window.hide
- end
- #----------------------------------------------------------------------------
- # * Create Water Container Selection Window
- #----------------------------------------------------------------------------
- def create_waterer_window
- @waterer_window = Window_SelectWaterer.new(0,100,230,210)
- @waterer_window.viewport = @viewport
- @waterer_window.set_handler(:ok, method(:on_waterer_ok))
- @waterer_window.set_handler(:cancel, method(:on_waterer_cancel))
- @waterer_window.hide
- end
- #----------------------------------------------------------------------------
- # * Create Water Container Data Window
- #----------------------------------------------------------------------------
- def create_waterer_data_window
- x,y = Graphics.width * 0.2, Graphics.height * 0.7
- w,h = 380, 55
- @waterer_data_window = Window_WatererData.new(0,Graphics.height-45,w,47)
- @waterer_data_window.give_item_window(@waterer_window)
- @waterer_data_window.hide
- @waterer_data_window.deactivate
- end
- #----------------------------------------------------------------------------
- # * Create Water Number Window
- #----------------------------------------------------------------------------
- def create_waterer_amount_window
- @waterer_number_window = Window_WaterAmt.new(300,200,100,65)
- @waterer_number_window.viewport = @viewport
- @waterer_number_window.hide
- @waterer_number_window.set_handler(:ok, method(:waterer_number_ok))
- @waterer_number_window.set_handler(:cancel, method(:waterer_number_cancel))
- end
- #----------------------------------------------------------------------------
- # * Create Water Number Text Window
- #----------------------------------------------------------------------------
- def create_waterer_amount_help_window
- x,y = Graphics.width * 0.2, Graphics.height * 0.7
- w,h = 300, 55
- @waterer_amount_text_window = Window_WatererText.new(x,y,w,h)
- @waterer_amount_text_window.viewport = @viewport
- @waterer_amount_text_window.hide
- end
- #----------------------------------------------------------------------------
- # * Create Select Name Text Window
- #----------------------------------------------------------------------------
- def create_select_name_waterer_window
- w = @waterer_window.width
- @waterer_selection_name = Window_WatererText.new(0,50,w,47)
- @waterer_selection_name.viewport = @viewport
- @waterer_selection_name.hide
- end
- #----------------------------------------------------------------------------
- # * Reorient Watering Windows
- #----------------------------------------------------------------------------
- def waterer_reorient_windows_era
- @waterer_window.y = @waterer_selection_name.y + @waterer_selection_name.height
- @waterer_data_window.width = @waterer_window.width
- @waterer_data_window.height = @waterer_selection_name.height
- @waterer_question_window.x = Graphics.width - @waterer_question_window.width
- @waterer_question_window.y = @waterer_opts_window.y + @waterer_opts_window.height
- @waterer_opts_window.x = Graphics.width - @waterer_opts_window.width
- @waterer_number_window.x = Graphics.width - @waterer_number_window.width
- @waterer_amount_text_window.x = @waterer_question_window.x
- @waterer_amount_text_window.y = @waterer_number_window.y + @waterer_number_window.height
- end
- #----------------------------------------------------------------------------
- # * Process Choice
- #----------------------------------------------------------------------------
- def process_choice_era
- if @waterer_opts_window.index == 0
- want_to_water_era
- else
- on_ch_cancel_era
- end
- end
- #----------------------------------------------------------------------------
- # * On Number Selection 'OK'
- #----------------------------------------------------------------------------
- def waterer_number_ok
- @waterer_item_era.mod_waterer_available_uses(-(n=@waterer_number_window.number))
- $game_system.water_plant_era(@target_plant_id_era,n)
- hide_waterers_number
- $game_player.freeze_era(false)
- end
- #----------------------------------------------------------------------------
- # * Number Selection 'CANCEL'
- #----------------------------------------------------------------------------
- def waterer_number_cancel
- hide_waterers_number
- $game_player.freeze_era(false)
- end
- #----------------------------------------------------------------------------
- # * Water Container Selection 'CANCEL'
- #----------------------------------------------------------------------------
- def waterer_number_cancel
- hide_waterers_number
- $game_player.freeze_era(false)
- end
- #----------------------------------------------------------------------------
- # * Hide Water Number Windows
- #----------------------------------------------------------------------------
- def hide_waterers_number
- @waterer_number_window.hide
- @waterer_amount_text_window.hide
- end
- #----------------------------------------------------------------------------
- # * Water Container Selection 'OK'
- #----------------------------------------------------------------------------
- def on_waterer_ok
- @waterer_item_era = @waterer_window.item
- @waterer_number_window.give_waterer(@waterer_item_era)
- uses = @waterer_item_era.water_available_uses
- @waterer_window.deactivate
- hide_secondary_waterer_windows
- @waterer_number_window.show
- @waterer_number_window.activate
- @waterer_amount_text_window.give_text("How many times do you want to water it?")
- @waterer_amount_text_window.show
- end
- #----------------------------------------------------------------------------
- # * Water Selection 'CANCEL'
- #----------------------------------------------------------------------------
- def on_waterer_cancel
- hide_secondary_waterer_windows
- $game_player.freeze_era(false)
- end
- #----------------------------------------------------------------------------
- # * Yes-No Selection 'CANCEL'
- #----------------------------------------------------------------------------
- def on_ch_cancel_era
- @waterer_opts_window.hide
- @waterer_question_window.hide
- @waterer_opts_window.deactivate
- $game_player.freeze_era(false)
- end
- #----------------------------------------------------------------------------
- # * Hide Specific Watering Windows
- #----------------------------------------------------------------------------
- def hide_secondary_waterer_windows
- @waterer_selection_name.hide
- @waterer_data_window.hide
- @waterer_window.hide
- end
- #----------------------------------------------------------------------------
- # * Water the Plant with param: plant_id
- #----------------------------------------------------------------------------
- def water_plant(plant_id)
- $game_player.freeze_era(true)
- @target_plant_id_era = plant_id
- create_waterer_window
- create_waterer_data_window
- create_window_water_question
- create_window_waterer_opts
- create_waterer_amount_window
- create_waterer_amount_help_window
- create_select_name_waterer_window
- waterer_reorient_windows_era
- @waterer_question_window.show
- @waterer_opts_window.show
- @waterer_opts_window.select(0)
- @waterer_opts_window.activate
- end
- #----------------------------------------------------------------------------
- # * Decided to water the plant
- #----------------------------------------------------------------------------
- def want_to_water_era
- @waterer_question_window.hide
- @waterer_opts_window.hide
- @waterer_opts_window.deactivate
- @waterer_selection_name.show
- @waterer_selection_name.give_text("Choose a Watering Container")
- @waterer_window.select(0)
- @waterer_window.show
- @waterer_window.activate#@w = Window_MenuCommand.new#Window_SelectWaterer.new(0,0,300,200)
- @waterer_window.refresh
- @waterer_data_window.show
- end
- #----------------------------------------------------------------------------
- # * Dispose Windows
- #----------------------------------------------------------------------------
- def disp_wins_era(clean = true)
- $game_player.freeze_era(false)
- @waterer_window.dispose unless @waterer_window.nil?
- @waterer_opts_window.dispose unless @waterer_opts_window.nil?
- @waterer_data_window.dispose unless @waterer_data_window.nil?
- @waterer_question_window.dispose unless @waterer_question_window.nil?
- @waterer_number_window.dispose unless @waterer_number_window.nil?
- @waterer_amount_text_window.dispose unless @waterer_amount_text_window.nil?
- @waterer_selection_name.dispose unless @waterer_selection_name.nil?
- clean_wins_era if clean
- end
- #----------------------------------------------------------------------------
- # * Set windows to nil, called after disposing just to be safe
- #----------------------------------------------------------------------------
- def clean_wins_era
- @waterer_window = nil
- @waterer_opts_window = nil
- @waterer_data_window = nil
- @waterer_question_window = nil
- @waterer_number_window = nil
- @waterer_amount_text_window = nil
- @waterer_selection_name = nil
- end
- #----------------------------------------------------------------------------
- # * Update
- #----------------------------------------------------------------------------
- alias update_need_to_pl_seed_era update
- def update
- update_need_to_pl_seed_era
- disp_wins_era if scene_changing?
- end # update
- end # Scene_Map
- #==============================================================================
- # ** Sprite_Character
- #==============================================================================
- class Sprite_Character < Sprite_Base
- #----------------------------------------------------------------------------
- # * Alias - Update
- #----------------------------------------------------------------------------
- alias update_pr_tone_garden_debug update
- def update
- update_pr_tone_garden_debug
- color_dead_garden_plant if garden_plant_dead_era?
- end
- #----------------------------------------------------------------------------
- # * Check if the Associated Plant Event is Dead
- #----------------------------------------------------------------------------
- def garden_plant_dead_era?
- return unless (c=@character).is_a?(Game_Event)
- c.garden_plant_dead?
- end
- #----------------------------------------------------------------------------
- # * Get the Color of a Dead Plant
- #----------------------------------------------------------------------------
- def color_dead_garden_plant
- tone.gray = 205
- tone.blue = -160
- tone.red = -160
- tone.green = -130
- end # color_dead_garden_plant
- end # Sprite_Character
- #==============================================================================
- # ** Game_Player
- #==============================================================================
- class Game_Player < Game_Character
- #----------------------------------------------------------------------------
- # * Initialize
- #----------------------------------------------------------------------------
- alias init_add_t_del_var_for_more_nat_w initialize
- def initialize
- init_add_t_del_var_for_more_nat_w
- @turn_delay_era = 0
- end
- #----------------------------------------------------------------------------
- # * Alias, Check Event Triger There
- #----------------------------------------------------------------------------
- alias chk_ev_trigs_chk_to_water_first check_event_trigger_there
- def check_event_trigger_there(triggers)
- try_to_water_plants
- chk_ev_trigs_chk_to_water_first(triggers)
- end
- #----------------------------------------------------------------------------
- # * Alias - move_straight
- #----------------------------------------------------------------------------
- alias mov_straight_don_move_when_frozen move_straight
- def move_straight(*args)
- return if @frozen_era
- mov_straight_don_move_when_frozen(*args)
- end
- #----------------------------------------------------------------------------
- # * Try to Water Plants - ask player if they want to water a plant when
- # checking for event triggers if the event is a plant.
- #----------------------------------------------------------------------------
- def try_to_water_plants
- return unless party_has_waterer_era?
- map = $game_map
- rx = map.round_x_with_direction(@x,@direction)
- ry = map.round_y_with_direction(@y,@direction)
- $game_map.events_xy(rx,ry).each{ |ev|
- next unless ev
- plant = ev.plant
- if plant && !ev.garden_plant_dead? && (plant.stage != plant.last_stage)
- SceneManager.scene.water_plant(ev.plant.plant_id)
- end
- }
- end
- #----------------------------------------------------------------------------
- # * Check if the party has a watering container
- #----------------------------------------------------------------------------
- def party_has_waterer_era?(full = false)
- items = $game_party.items
- items.each{|item|
- next unless is_waterer = item.is_waterer?
- curr, max = item.water_available_uses, item.water_amount_uses
- valid = full ? curr < max : curr > 0
- return true if is_waterer && valid
- }
- return false
- end
- #----------------------------------------------------------------------------
- # * Freeze the player when displying water container selection windows
- #----------------------------------------------------------------------------
- def freeze_era(stop = true)
- @frozen_era = stop
- end # freeze_era
- end # Game_Player
- #==============================================================================
- # ** Game_BattlerBase
- # Add code to handle internal common events. The arguments are
- # being converted to strings when they're passed
- #==============================================================================
- class Game_BattlerBase
- #----------------------------------------------------------------------------
- # * Alias usable? - add checks looking for seeds, fertillizer, or clearer
- #----------------------------------------------------------------------------
- alias usa_elbasu_ube_garden_seed usable?
- def usable?(item)
- return can_clear_crop(item) if !item.nil? && item.clears_crops?
- return garden_area_valid?(item) if !item.nil? && item.is_garden_seed?
- return garden_area_valid?(item) if !item.nil? && item.is_fertillizer?
- usa_elbasu_ube_garden_seed(item)
- end
- #----------------------------------------------------------------------------
- # * Garden Area Valid - Check if a seed can be planted or if fertillizer can
- # be placed based on the players current position.
- #----------------------------------------------------------------------------
- def garden_area_valid?(item)
- xy = []
- map, player = $game_map, $game_player
- px, py, d = player.x, player.y, player.direction
- sx,sy = map.round_x_with_direction(px, d), map.round_y_with_direction(py, d)
- is_fertillizer = item.is_fertillizer?
- f_ok = map.seed_location_ok?(sx,sy) || is_fertillizer
- c_ok = map.seed_location_ok?(px,py) || is_fertillizer
- front_ok = item.garden_terrains(map.terrain_tag(sx, sy)) && f_ok
- cent_ok = item.garden_terrains(map.terrain_tag(px, py)) && c_ok
- anywhere_ok = item.garden_ok_anywhere?
- id = item.id
- $game_temp.temp_seed_data[id] = {}
- hash = $game_temp.temp_seed_data[id]
- hash[:sx], hash[:sy] = sx, sy if front_ok
- hash[:px], hash[:py] = px, py if cent_ok || anywhere_ok
- front_ok || cent_ok || anywhere_ok
- end # garden_area_valid?
- #----------------------------------------------------------------------------
- # * Check if there are any crop close enough to be cleared.
- #----------------------------------------------------------------------------
- def can_clear_crop(item)
- map, player, gtemp = $game_map, $game_player, $game_temp
- dir = player.direction
- front_x = map.round_x_with_direction(player.x, dir)
- front_y = map.round_y_with_direction(player.y, dir)
- front_evs = map.events_xy(front_x, front_y) # getting events, may want to get
- # plant ids and delete the plants current
- # event if it turns out the plant can grow
- # a stage while trying to harvest.
- gtemp.temp_seed_clear = [] # erase previously stored events
- if (amt = item.clears_crops) <= 0
- pushed = false
- front_evs.each{ |ev|
- if !ev.plant.nil?
- gtemp.temp_seed_clear.push(ev)
- pushed = true
- end
- }
- # only check the front position unless a distance is specified
- else
- # calculate additional locations
- pushed = store_adjsdiag_temp_clearer(amt) || pushed
- end
- return pushed
- end
- #----------------------------------------------------------------------------
- # * Store plants at a distance of dist from game_player for removal.
- #----------------------------------------------------------------------------
- def store_adjsdiag_temp_clearer(dist)
- map, player, gtemp = $game_map, $game_player, $game_temp
- x, y = player.x, player.y
- need_check = []
- (0...dist).each{ |d|
- need_check = p_at_dist_plants_clear(need_check, d, x, y)
- }
- pushed = false
- # get all events within range that are plants
- need_check.each do |xy|
- evs = map.events_xy(xy[0], xy[1])
- evs.each{ |ev|
- next unless ev
- if !ev.plant.nil?
- gtemp.temp_seed_clear.push(ev)
- pushed = true
- end
- }
- end # need_check.each
- return pushed
- end # store_adjsdiag_temp_clearer
- #----------------------------------------------------------------------------
- # * Points in a circle at distsance: dist from x,y
- #----------------------------------------------------------------------------
- def p_at_dist_plants_clear(points, dist, x, y, opts = {})
- max = dist+1
- (0..dist).each{ |i|
- points.push([ x+i, y-(max-i)])
- points.push([x-i, y+(max-i)])
- points.push([x+(max-i), y+i])
- points.push([x-(max-i), y-i])
- }
- points
- end
- end # Game_BattlerBase
- #==============================================================================
- # ** Game_Battler - Add support for when using items that are fertillizers or
- # seeds.
- #==============================================================================
- class Game_Battler < Game_BattlerBase
- #----------------------------------------------------------------------------
- # * Alias use_item - set up appropriate internal common events when
- # fertillizer or seeds are used.
- #----------------------------------------------------------------------------
- alias usitm_use_ce_seed_mod_meti use_item
- def use_item(item)
- # Seed
- if item.is_garden_seed?
- strsym = "GardenRa::CE_Plant_Seeds"
- $game_temp.reserve_internal_ce(strsym.to_sym, item.id, item.is_a?(RPG::Item))
- end
- # Fertillizer
- if item.is_fertillizer?
- strsym = "GardenRa::CE_Place_Fertillizer"
- $game_temp.reserve_internal_ce(strsym.to_sym, item.id, item.is_a?(RPG::Item))
- end
- # Clearer
- if item.clears_crops?
- strsym = "GardenRa::Clear_Crop"
- $game_temp.reserve_internal_ce(strsym.to_sym)
- end
- usitm_use_ce_seed_mod_meti(item)
- end # use_item
- end # Game_Battler
- #==============================================================================
- # ** Game_Temp
- # Functionality is added to support internal common events.
- #==============================================================================
- class Game_Temp
- attr_accessor :temp_seed_data
- attr_accessor :temp_seed_clear
- #----------------------------------------------------------------------------
- # * Alias initialize - added a helper hash
- #----------------------------------------------------------------------------
- alias init_gt_tini_gme_temp_tia initialize
- def initialize
- init_gt_tini_gme_temp_tia
- @temp_seed_data = {} # data stored when trying to plant a seed to prevent
- # calculating the seeds placement location twice (once
- # when checking if plantable and again when planting)
- @temp_seed_clear = [] # data stored when trying to clear a plant to prevent
- # recalculation of the same information.
- end
- #----------------------------------------------------------------------------
- # * Alias - Clear Common Event, clear internal common events as well
- #----------------------------------------------------------------------------
- alias cce_cle_com_even_inter clear_common_event
- def clear_common_event
- # Only clear out the internal common event if one is found. This will allow
- # the real common event that was reserved to be used next time.
- if @internal_ce_sym
- @internal_ce_sym = false
- return @last_internal_ce = nil
- end
- cce_cle_com_even_inter
- end
- #----------------------------------------------------------------------------
- # * Alias - Common Event Reserved, reserve internal common events
- #----------------------------------------------------------------------------
- alias cer_comm_eve_reser_comresv common_event_reserved?
- def common_event_reserved?
- cer_comm_eve_reser_comresv || @internal_ce_sym
- end
- #----------------------------------------------------------------------------
- # * Alias method - Reserved Common Event, add functionality to return
- # internal common events if one has been reserved.
- #----------------------------------------------------------------------------
- alias rescomev_rce_res_com_ev reserved_common_event
- def reserved_common_event
- if @internal_ce_sym # play the internal common event first, then the real one.
- return make_internal_ce
- else
- return rescomev_rce_res_com_ev
- end
- end
- #----------------------------------------------------------------------------
- # * Reserve Internal Common Event
- #----------------------------------------------------------------------------
- def reserve_internal_ce(sym, *args)
- @internal_ce_sym = sym
- @internal_ce_args = args
- end
- #----------------------------------------------------------------------------
- # * Make Internal Common Event
- #----------------------------------------------------------------------------
- def make_internal_ce
- return @last_internal_ce unless @last_internal_ce.nil?
- ce = RPG::CommonEvent.new
- ce.list = []
- ce.give_script(@internal_ce_sym.to_s, @internal_ce_args)
- ce.list.push(RPG::EventCommand.new)
- @last_internal_ce = ce
- end
- #----------------------------------------------------------------------------
- # * Garden Seed Placement-Position-Checking Helper
- # Helper method to reduce repetitive similar code in the internal common
- # events. Returns the xy position that the fertillizer or seed should be
- # placed at.
- #----------------------------------------------------------------------------
- def garden_seed_temp_xy_helper(id, front)
- seed_data = @temp_seed_data.delete(id)
- sx, sy = seed_data[:sx], seed_data[:sy]
- px, py = seed_data[:px], seed_data[:py]
- fx, fy = nil, nil
- if front # want to plant in front of player
- if sx.nil? && sy.nil? # wanted to plant in front but couldn't
- fx,fy = px, py # so place at players x,y instead
- else
- fx,fy = sx, sy # plant in front
- end
- else # want to plant at player's location
- if px.nil? && py.nil? # wanted to plant at player's location but was blocked
- fx, fy = sx, sy
- else
- fx, fy = px, py
- end
- end # if front
- [fx, fy]
- end # garden_seed_temp_xy_helper
- end # Game_Temp
- #==============================================================================
- # ** RPG::CommonEvent
- #==============================================================================
- class RPG::CommonEvent
- #----------------------------------------------------------------------------
- # * Give Script - Only pass in one line for now
- #----------------------------------------------------------------------------
- def give_script(proc_name, args)
- accum = ""
- args.each{ |v| accum.eql?("") ? accum<<"#{v}" : accum<<",#{v}" }
- proc_name<<".call("<<accum<<")"
- @list.push(RPG::EventCommand.new(355,0,[proc_name]))
- end # give_script
- end # RPG::CommonEvent
- #==============================================================================
- # ** Window_SelectWaterer
- # A window shown in Scene_Map when selecting a water container to use when
- # watering a plant.
- #==============================================================================
- class Window_SelectWaterer < Window_ItemList
- #--------------------------------------------------------------------------
- # * Get Digit Count
- #--------------------------------------------------------------------------
- def col_max
- return 1
- end
- #--------------------------------------------------------------------------
- # * Include in Item List?
- #--------------------------------------------------------------------------
- def include?(item)
- item.is_a?(RPG::Item) && item.is_waterer? && item.water_available_uses > 0
- end
- #----------------------------------------------------------------------------
- # * Update
- #----------------------------------------------------------------------------
- def update
- super
- self.opacity += 25
- end
- #----------------------------------------------------------------------------
- # * Show
- #----------------------------------------------------------------------------
- def show
- super
- self.opacity = 0
- end # show
- end # Window_SelectWaterer
- #==============================================================================
- # ** Window_WatererData
- # Displays how much water is left in the currently selected container when
- # choosing one to use to water a plant.
- #==============================================================================
- class Window_WatererData < Window_Base
- #----------------------------------------------------------------------------
- # * Initialize
- #----------------------------------------------------------------------------
- def initialize(*args)
- super(*args)
- self.opacity = 0
- self.windowskin = Bitmap.new(Graphics.width,300)
- end
- #----------------------------------------------------------------------------
- # * Give Item Window
- #----------------------------------------------------------------------------
- def give_item_window(w)
- @item_window = w
- @old = nil
- end
- #----------------------------------------------------------------------------
- # * Update
- #----------------------------------------------------------------------------
- def update
- super
- self.opacity += 25
- refresh if @old != item
- end
- #----------------------------------------------------------------------------
- # * Help Text
- #----------------------------------------------------------------------------
- def help_text
- return unless item
- e_str = "#{item.water_available_uses}/#{item.water_amount_uses}"
- "#{item.name}: #{e_str}"
- end
- #----------------------------------------------------------------------------
- # * Item
- #----------------------------------------------------------------------------
- def item
- return unless @item_window
- @item_window.item
- end
- #----------------------------------------------------------------------------
- # * Show
- #----------------------------------------------------------------------------
- def show
- super
- self.opacity = 0
- end
- #----------------------------------------------------------------------------
- # * Refresh
- #----------------------------------------------------------------------------
- def refresh
- @old = item
- contents.clear
- contents.font.size = 22
- draw_background(Rect.new(0,0,width,height))
- draw_text(0,0,width,line_height,help_text)
- end
- #----------------------------------------------------------------------------
- # * Draw Background
- #----------------------------------------------------------------------------
- def draw_background(rect)
- temp_rect = rect.clone
- temp_rect.width /= 2
- contents.gradient_fill_rect(temp_rect, back_color2, back_color1)
- temp_rect.x = temp_rect.width
- contents.gradient_fill_rect(temp_rect, back_color1, back_color2)
- end
- #--------------------------------------------------------------------------
- # * Get Background Color 1
- #--------------------------------------------------------------------------
- def back_color1
- Color.new(0, 0, 0, 192)
- end
- #--------------------------------------------------------------------------
- # * Get Background Color 2
- #--------------------------------------------------------------------------
- def back_color2
- Color.new(0, 0, 0, 0)
- end # back_color2
- end # Window_WatererData
- #==============================================================================
- # ** Window_ShowOptsEra
- # Window displayed when the player is selecting whether or not they want
- # to water a plant.
- #==============================================================================
- class Window_ShowOptsEra < Window_Selectable
- #----------------------------------------------------------------------------
- # * Initialize
- #----------------------------------------------------------------------------
- def initialize(*args)
- super(*args)
- draw_text(7,0,70,line_height, "Yes")
- draw_text(7,25,70,line_height, "No")
- end
- #----------------------------------------------------------------------------
- # * Item Max
- #----------------------------------------------------------------------------
- def item_max
- return 2
- end
- def update
- super
- self.opacity += 25
- end
- #----------------------------------------------------------------------------
- # * Show
- #----------------------------------------------------------------------------
- def show
- super
- self.opacity = 0
- end
- #----------------------------------------------------------------------------
- # * Draw Item
- #----------------------------------------------------------------------------
- def draw_item(index)
- case index
- when 0
- return "Yes"
- when 1
- return "No"
- end
- end # draw_item
- end # Window_ShowOptsEra
- #==============================================================================
- # ** Window_WatererText
- # Used to show windowed during Scene_Map
- #==============================================================================
- class Window_WatererText < Window_Base
- #----------------------------------------------------------------------------
- # * Initialize
- #----------------------------------------------------------------------------
- def initialize(*args)
- super(*args)
- self.opacity = 0
- refresh
- end
- #----------------------------------------------------------------------------
- # * Give Text
- #----------------------------------------------------------------------------
- def give_text(text)
- @text = text
- refresh
- end
- #----------------------------------------------------------------------------
- # * Update
- #----------------------------------------------------------------------------
- def update
- super
- self.opacity += 25
- end
- #----------------------------------------------------------------------------
- # * Help text - default text shown if none is given to this window.
- #----------------------------------------------------------------------------
- def help_text
- @text ? @text : "Would you like to water it?"
- end
- #----------------------------------------------------------------------------
- # * Show
- #----------------------------------------------------------------------------
- def show
- super
- self.opacity = 0
- end
- #----------------------------------------------------------------------------
- # * Refresh
- #----------------------------------------------------------------------------
- def refresh
- contents.clear
- draw_text(0,0,width,line_height+10,help_text)
- end # Refresh
- end # Window_WatererText
- #==============================================================================
- # ** Window_WaterAmt
- # Used to select the number of times the plant should be watered.
- #==============================================================================
- class Window_WaterAmt < Window_Selectable
- #--------------------------------------------------------------------------
- # * Initialize
- #--------------------------------------------------------------------------
- def initialize(*args)
- super(*args)
- @number = 1
- refresh
- end
- #--------------------------------------------------------------------------
- # * Item Max
- #--------------------------------------------------------------------------
- def item_max
- 1
- end
- #--------------------------------------------------------------------------
- # * Number
- #--------------------------------------------------------------------------
- def number
- @number
- end
- #--------------------------------------------------------------------------
- # * Give Water Container
- #--------------------------------------------------------------------------
- def give_waterer(item)
- @item = item
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- super
- if active
- last_number = @number
- update_number
- if @number != last_number
- Sound.play_cursor
- refresh
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Update Quantity
- #--------------------------------------------------------------------------
- def update_number
- change_number(10) if Input.repeat?(:RIGHT)
- change_number(-10) if Input.repeat?(:LEFT)
- change_number(1) if Input.repeat?(:UP)
- change_number(-1) if Input.repeat?(:DOWN)
- end
- #--------------------------------------------------------------------------
- # * Change Number
- #--------------------------------------------------------------------------
- def change_number(mod)
- @number = [@number+mod,0].max
- if @number > (n=@item.water_available_uses)
- @number = n
- end
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- contents.clear
- draw_number
- end
- #--------------------------------------------------------------------------
- # * Draw Number
- #--------------------------------------------------------------------------
- def draw_number
- change_color(normal_color)
- draw_text(0, 0, 80, line_height, @number,2)
- draw_text(0,0, 80, line_height, "x")
- end
- #--------------------------------------------------------------------------
- # * Activate
- #--------------------------------------------------------------------------
- def activate
- super
- select(0)
- end # Activate
- end # Window_WaterAmt
- #==============================================================================
- # ** Game_Interpreter
- #==============================================================================
- class Game_Interpreter
- #----------------------------------------------------------------------------
- # * Garden Fill Containers
- # Pass an integer to modifer the containers by a specified amount,
- # otherwise the containers will be completely refilled
- #----------------------------------------------------------------------------
- def garden_fill_containers(mod = :max)
- return false unless $game_player.party_has_waterer_era?(mod == :max || mod > 0)
- $game_party.items.each do |item|
- if item.is_waterer?
- if mod == :max
- item.mod_waterer_available_uses(item.water_amount_uses)
- else
- item.mod_waterer_available_uses(mod)
- end
- end # item.is_waterer?
- scene=SceneManager.scene
- return unless scene.is_a?(Scene_Map)
- spm = scene.instance_eval('@spriteset')
- if mod == :max
- spm.add_spgt_to_spm("Water containers maxed")
- else
- spm.add_spgt_to_spm("Water containers #{mod < 0 ? "-" : "+"}#{mod}")
- end
- end # $game_party.items.each
- return true
- end # garden_fill_containers
- #----------------------------------------------------------------------------
- # * Destroy a garden plant from its event's interpreter.
- #----------------------------------------------------------------------------
- def harvest_garden_plant(should_destroy)
- ev = (map = $game_map).events[@event_id]
- return unless !ev.plant.nil?
- harvest = ev.plant.harvest
- if should_destroy
- $game_system.destroy_plant(ev.plant.plant_id)
- @event_id = 0
- end
- return harvest
- end
- end # Game_Interpreter
- #==============================================================================
- # ** Spriteset_Map
- # Add methods to support adding instances of Sprite_GardenText to the spm
- #==============================================================================
- class Spriteset_Map
- #----------------------------------------------------------------------------
- # * Alias - initialize
- #----------------------------------------------------------------------------
- alias init_spgt_teserir_pam_spm_ali_era initialize
- def initialize
- init_spgt_teserir_pam_spm_ali_era
- create_spgt_arr
- end
- #----------------------------------------------------------------------------
- # * Alias - Dispose
- #----------------------------------------------------------------------------
- alias dis_sprmt_esopsi_disp_b_chars dispose
- def dispose
- dis_sprmt_esopsi_disp_b_chars
- dispose_spgdtext
- end
- #----------------------------------------------------------------------------
- # * Alias - Update
- #----------------------------------------------------------------------------
- alias etad_upd_sprm_txtbm_disp_era update
- def update
- etad_upd_sprm_txtbm_disp_era
- update_spgdtext
- end
- #----------------------------------------------------------------------------
- # * Create Sprite Garden Text Array
- #----------------------------------------------------------------------------
- def create_spgt_arr
- @spgt_text_era = []
- end
- #----------------------------------------------------------------------------
- # * Update Sprite Garden Text
- #----------------------------------------------------------------------------
- def update_spgdtext
- return unless @spgt_text_era
- @spgt_text_era.each{|spgt| spgt.update}
- end
- #----------------------------------------------------------------------------
- # * Dispose Sprite Garden Text
- #----------------------------------------------------------------------------
- def dispose_spgdtext
- @spgt_text_era.each{|spgt| spgt.dispose}
- end
- #----------------------------------------------------------------------------
- # * Add Sprite Garden to Spritesetmap
- #----------------------------------------------------------------------------
- def add_spgt_to_spm(text)
- @spgt_text_era.push(Sprite_GardenText.new(@viewport3).give(text))
- end
- end # Spriteset_Map
- #==============================================================================
- # ** Sprite_GardenText
- # Displays bouncing text on the screen.
- #==============================================================================
- class Sprite_GardenText < Sprite_Base
- #----------------------------------------------------------------------------
- # * Initialize
- #----------------------------------------------------------------------------
- def initialize(*args)
- super(*args)
- self
- end
- #----------------------------------------------------------------------------
- # * Give
- #----------------------------------------------------------------------------
- def give(text = "!")
- @bounce_min = 23
- @bounce_min_count = 0
- @val = -4
- self.bitmap = Bitmap.new(200,35)
- self.bitmap.font.color.set(200,220,100)
- self.bitmap.font.size = 24
- self.bitmap.draw_text(0,0,200,35,text)
- self.y = $game_player.x * 32 - $game_map.display_x
- self.x = $game_player.y * 32 - $game_map.display_y
- self.ox = bitmap.width/5
- self.oy = bitmap.height/3
- self
- end
- #----------------------------------------------------------------------------
- # * Update
- #----------------------------------------------------------------------------
- def update
- return if self.bitmap.disposed?
- if @bounce_min <= 0
- self.opacity -= 5.5
- self.bitmap.dispose if self.opacity < 0
- return
- end
- self.x += 1
- self.y+=@val
- self.zoom_x+=0.004
- self.zoom_y+=0.004
- @bounce_min_count += 5.5
- return if @val > 0 && @bounce_min_count/2 < @bounce_min
- if @bounce_min_count >= @bounce_min || (@val < 0 ? @bounce_min_count >= @bounce_min/2 : false)
- @val *= -1
- @bounce_min -= 7 if @val < 0
- @bounce_min_count = -@bounce_min_count/2
- end
- end
- #----------------------------------------------------------------------------
- # * Dispose
- #----------------------------------------------------------------------------
- def dispose
- self.bitmap.dispose
- end # dispose
- end # Sprite_GardenText
- # End of File
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement