Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
- # ** Plow Land Add-on for Ra Gardening/Farming
- #~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
- # Author: Eshra
- # Release Date: 8 March 2013
- # Dependencies: Ra Gardening/Farming
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Setup:
- # Place this script underneath the Ra Gardening/Farming Script.
- #
- # This addon requires you to have a spritesheet named "$plowedland" in the
- # character folder of your project.
- #
- # Usage:
- #
- # Items can now be used to plow land. Use the notetag:
- # <seed plow 1,2,3>
- # to specify an item which can "plow" map tiles with a terrain tag of 1,2,
- # and 3 (the numbers can be replaced with others or you can only use one #, etc.)
- #
- # Seeds can now be specified such that they can only be planted on plowed
- # terrain. Use the notetag:
- # <plowed land only>
- # to specify a seed which can only be planted on land that has been plowed.
- #
- # See the demo at rascripts.wordpress.com for more examples.
- #~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
- ($imported ||= {})["Ra Gardening Plow Addon"] = 0.1
- raise "Plow addon reqs Ra Gardening" if ($imported["Ra Gardening"]||=-1) < 0.1
- raise "Plow addon reqs Era" if ($imported["Era Module"]||=-1) < 0.1
- # Add new 'plow' related constants to GardenRa
- module GardenRa
- PlowName = '$plowedland'
- PlowIndex = 0
- PlowRow = 0
- ShowPlowedLand = true
- PlowSym = :ara_plow_addon_hls
- CE_Plow_Land = 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)
- $game_map.plow_land_era(1,[xy])
- }
- class << self
- alias plant_seed_plow_addon_era plant_seed
- end
- #----------------------------------------------------------------------------
- # * Alias plant_seed, remove the plow data after planting
- #----------------------------------------------------------------------------
- def self.plant_seed(*args)
- plant_seed_plow_addon_era(*args)
- sys = $game_system
- opts = (args[3] ||= {})
- options = {:x => $game_player.x, :y => $game_player.y}.merge(opts)
- x,y = options[:x], options[:y]
- # remove plow highlight and sys data
- spm = SceneManager.scene.instance_eval("@spriteset")
- spm.remove_highlight(x, y, GardenRa::PlowSym)
- sys.remove_saved_highlight(x,y, nil, GardenRa::PlowSym)
- spm.refresh_highlights
- sys.unplow_era(x,y)
- end # plant_seed
- module RE
- # Terrain tags an item can plow
- PlowTerrain = /<\s*seed\s*plow\s*(\d+\s*(?:,\s*\d+\s*)*)\s*>/i
- # Seed plow requirements
- SeedPlowReqs = /<plowed land only>/i
- end
- end
- module DataManager
- #----------------------------------------------------------------------------
- # * Loading Notetags using Ra DB notetag methods
- #----------------------------------------------------------------------------
- class << self; alias eval_note_era_mar82013_plow eval_note_era; end
- def self.eval_note_era(data, line)
- eval_note_era_mar82013_plow(data,line)
- case line
- when GardenRa::RE::PlowTerrain
- data.garden_item_default_values # only sets once unless param is true
- data.plow_era= true
- data.set_plow_terrains($1)
- when GardenRa::RE::SeedPlowReqs
- data.garden_item_default_values # only sets once unless param is true
- data.requires_plow = true
- end
- end
- end
- class RPG::UsableItem < RPG::BaseItem
- attr_reader :plow_era
- attr_accessor :plowable_terrains # hash of terrain tags this item can plow
- attr_reader :requires_plow
- alias garden_item_default_values_mar82013558_era garden_item_default_values
- def garden_item_default_values
- garden_item_default_values_mar82013558_era
- @plow_era = false
- @plowable_terrains = {}
- @fertillizer_terrain = {}
- @requires_plow = false
- end
- def plow_era=(v); @plow_era = v; end
- def is_plow?; @plow_era == true; end # compare to true for encapsulation
- def requires_plow=(v); @requires_plow = v; end
- # Alias garden_terrains
- alias garden_terrains_era_plow_addon garden_terrains
- def garden_terrains(tag)
- return true if @plow_era && plowable_terrains[tag]
- garden_terrains_era_plow_addon(tag)
- end
- def set_plow_terrains(tags)
- split_tags_era(tags, @plowable_terrains={})
- end
- alias garden_item_default_values_plow_addon garden_item_default_values
- def garden_item_default_values(force = false)
- return if @set_default_values && !force
- garden_item_default_values_plow_addon
- @set_default_values = true
- end
- end # RPG::UsableItem
- # Data organization class for future use. Stores data about what type of
- # Gardening/Farming related events have happened at a certain location on
- # the map.
- class FarmMapDataXY
- attr_reader :x, :y, :plow_value
- IS_PLOWED = 1 # location has been plowed if plow_value > this const
- INIT_PLOW_VALUE = 0 # initial plow value upon obj initialization
- UNPLOW = 0
- def initialize(x,y)
- @x,@y = x,y
- @plow_value = INIT_PLOW_VALUE
- end
- def x=(v); @x = v; end
- def y=(v); @y = v; end
- def plow_value=(v); @plow_value = v; end
- def mod_plow_val(v); @plow_value ||= 0; @plow_value += v; end
- def hash; hash_string_xy(@x, @y).hash; end
- def plowed?; @plow_value >= IS_PLOWED; end
- def unplow; @plow_value = UNPLOW; end
- # Converts an x,y coordinate to the hash value of the corresponding
- # FarmMapDataXY obj.
- def self.hash_string_xy(x,y); "#{x},#{y}"; end
- def to_s
- "FarmMapDataXY: (#{x},#{y}) plow val: #{plow_value} plowed: #{plowed?}"
- end
- end
- # New methods to access plowed terrain data
- class Game_System
- # hash of FarmMapDataXY objects
- def farm_data_xys
- (@farm_data_xys ||= {})[$game_map.map_id] ||= {}
- end
- def pos_plowed?(x,y)
- data = farm_data_xys[FarmMapDataXY.hash_string_xy(x,y)]
- data ? data.plowed? : false
- end
- def unplow_era(x,y)
- data = farm_data_xys[FarmMapDataXY.hash_string_xy(x,y)]
- data.unplow if data
- end
- end
- class Game_Map
- # param range is a list of [x,y] arrays, times is how many times the locations
- # have been plowed.
- def plow_land_era(times, range)
- plow_data = $game_system.farm_data_xys
- range.each do |xy|
- x,y = xy[0], xy[1]
- hashstr = FarmMapDataXY.hash_string_xy(x,y)
- md_obj = plow_data[hashstr]
- # case no data for the location yet
- if !md_obj
- md_obj = FarmMapDataXY.new(x,y)
- plow_data[hashstr] = md_obj
- end
- md_obj.mod_plow_val(times)
- sh = nil
- if GardenRa::ShowPlowedLand
- sh = Sheet_Data.new(GardenRa::PlowName,GardenRa::PlowIndex,GardenRa::PlowRow)
- end
- # add plowed land graphic
- spm = SceneManager.scene.instance_eval("@spriteset")
- spm.add_highlight(:x => x, :y => y, :sh => sh, :retain => true,
- :opacity => 255, :sym => GardenRa::PlowSym)
- end
- end
- end
- # new methods for handling when an item that can plow land has been used.
- class Game_BattlerBase
- alias usable_gdra_plow_addon_era usable?
- def usable?(item)
- return garden_area_valid?(item) if item && item.is_plow?
- usable_gdra_plow_addon_era(item)
- end
- # Alias garden_area_valid?, add checks for seeds requiring plowed land
- alias garden_area_valid_plow_addon_era? garden_area_valid?
- def garden_area_valid?(item)
- garden_area_valid_plow_addon_era?(item) && otrogd_checks_plow(item)
- end # garden_area_valid?
- # assumes data is stored in $game_temp.temp_seed_data
- def otrogd_checks_plow(item)
- sys = $game_system
- hash = $game_temp.temp_seed_data[item.id]
- if item.is_garden_seed? && item.requires_plow
- # check to make stored locations are plowed if the seed requires plowed
- # terrain to be planted.
- sx,sy = hash[:sx], hash[:sy]
- px,py = hash[:px], hash[:py]
- (hash[:px],hash[:py] = nil, nil) if !sys.pos_plowed?(px,py)
- (hash[:sx],hash[:sy] = nil, nil) if !sys.pos_plowed?(sx,sy)
- end
- hash && ((hash[:px] && hash[:py]) || (hash[:sx] && hash[:sy]))
- end
- end
- class Game_Battler < Game_BattlerBase
- alias usitm_addon_mar82013_era use_item
- def use_item(item)
- if item.is_plow?
- strsym = "GardenRa::CE_Plow_Land"
- $game_temp.reserve_internal_ce(strsym.to_sym, item.id, item.is_a?(RPG::Item))
- end
- usitm_addon_mar82013_era(item)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment