Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # Hunger and Thirst
- # Version: 1.07
- # Author: ForeverZer0, LiTTleDRAgo
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- #
- # Explanations:
- #
- # Based on ForeverZer0's Hunger/Thirst script
- # This script adds another parameter to actors, hunger and thirst
- # If hunger or thirst fall to certain amount, actor gets a state
- #
- # Instructions:
- #
- # - The following script calls can be used in game:
- #
- # ► $game_party.hunger = (true/false)
- # - If false, hunger/thirst rates will not decrease. Good for long scenes
- # where the player is not in control, etc.
- # The system will remain ON/OFF until it is changed.
- #
- # ► $game_actors[ACTOR_ID].hunger = AMOUNT
- # ► $game_actors[ACTOR_ID].thirst = AMOUNT
- # ► $game_party.members[ACTOR_POS].hunger = AMOUNT
- # ► $game_party.members[ACTOR_POS].thirst = AMOUNT
- # - Sets the hunger/thirst of actor in your database with ACTOR_ID or
- # ACTOR_POS to the number specified by AMOUNT
- #
- # ► $game_actors[ACTOR_ID].max_hunger = AMOUNT
- # ► $game_actors[ACTOR_ID].max_thirst = AMOUNT
- # ► $game_party.members[ACTOR_POS].max_hunger = AMOUNT
- # ► $game_party.members[ACTOR_POS].max_thirst = AMOUNT
- # - Sets the MAX hunger/thirst of actor in your database with ACTOR_ID or
- # ACTOR_POS to the number specified by AMOUNT
- #
- # ► $game_actors[ACTOR_ID].recover_hunger
- # ► $game_party.members[ACTOR_POS].recover_hunger
- # - Will recover all hunger to actor with ACTOR_ID or ACTOR_POS.
- #
- # ► $game_actors[ACTOR_ID].recover_thirst
- # ► $game_party.members[ACTOR_POS].recover_thirst
- # - Will recover all hunger to actor with ACTOR_ID or ACTOR_POS.
- #
- # ► $game_party.recover_hunger
- # ► $game_party.recover_thirst
- # ► $game_party.recover_hunger_thirst
- # - Will recover all hunger/thirst to party.
- #
- # ► $game_party.hunger_debugger
- # - Displays info on-screen of each characters hunger/thirst, current
- # count for steps and time, and shows which features are currently ON.
- #
- # For VXA :
- #
- # If you want to use this on damage formula, do it like this example :
- #
- # (a.atk + a.mat * 4) * ((a.hunger / a.max_hunger.to_f) * 100).round *
- # ((a.thirst / a.max_thirst.to_f) * 100).round - b.def - b.mdf * 2
- #
- # (a.atk + a.mat * 4) * a.hunger_percent *
- # a.thirst_percent - b.def - b.mdf * 2
- #
- # Special Thanks:
- # - ForeverZer0 for the original script
- #
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # NOTETAGS
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # For VX and VXA user can use notetags at Item Tabs to determine
- # food / drink recovery rates
- # (notetags configuration will be prioritized):
- #
- #-------------------------------------------------------------------------------
- # ** Notetags for Items
- #-------------------------------------------------------------------------------
- #
- # <recover hunger by percent>
- # <recover thirst by percent>
- # <hunger: x>
- # <thirst: x>
- # <increase max hunger: x> # fixed value only
- # <increase max thirst: x> # fixed value only
- #
- # I believe the tags were self explanationed.
- #
- #-------------------------------------------------------------------------------
- # ** Notetags for Actor
- #-------------------------------------------------------------------------------
- #
- # Below is tags for Actor
- #
- # <hunger lv up increase: x> # This one will increase max hunger on lvup
- # <thirst lv up increase: x> # This one will increase max thirst on lvup
- # <hunger max: x> # This one will initialize max hunger
- # <thirst max: x> # This one will initialize max thirst
- #
- # Note that hunger_max and thirst_max is cannot be lower than 1
- #
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # BEGIN CONFIGURATION
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- module LiTTleDRAgo
- # Enable hunger system at the start of the game?
- # Hunger system can be enabled with script call
- # $game_party.hunger = (true/false)
- ENABLE_HUNGER_AT_START = true
- DEFAULT_HUNGER = 100
- DEFAULT_THIRST = 100
- # Default max hunger/thirst players will begin with. This can be increased as
- # the player becomes more powerful, through items, etc. if desired.
- BY_TIME = true
- BY_STEPS = true
- # There are two ways hunger and thirst can be calculated; one by just how many
- # seconds pass, and the other by how many steps have been taken. You can use
- # both if you like, but I would suggest that if you do to try to keep it more
- # skewed to one or the other as the main method of decreasing, and use the
- # other as a minor added dynamic.
- STEPS_HUNGER_DOWN = 100
- STEPS_THIRST_DOWN = 80
- # Only if using 'BY_STEPS', otherwise ignore these. These are the amount
- # of steps before hunger/thirst decrease.
- SECS_HUNGER_DOWN = 10
- SECS_THIRST_DOWN = 10
- # Only if using 'BY_TIME', otherwise ignore these. These are the amount
- # of seconds before hunger/thirst decrease.
- LVL_UP_INCREASE = [:hunger, :thirst]
- LVL_UP_INCREASE = [ 5, 5]
- # Increase max hunger/thirst at each level up,
- # To disable it, set to 0 or false or nil
- #-------------------------------------------------------------------------------
- # * Food / Drink Items
- #-------------------------------------------------------------------------------
- ITEM_RECOVER_HUNGER_THIRST = {
- # Food/Drink Items:
- # Set up your food/drink items recovery rates here. Recovery can be by either
- # absolute value, or by percent. Setting :percent to true will make it
- # by percent.
- :id => [:hunger, :thirst, :percent],
- 1 => [ 1, 0, true],
- # For lazy user who wants to set every unconfigured item.
- # You can disable some items (such as key items) by setting the value to 0
- # 0 => [ 10, 0, false],
- # 99 => [ 0, 0, false],
- }
- #-------------------------------------------------------------------------------
- # * Hunger/Thirst States
- #
- # Set up states that will be applied when an actors hunger/thirst fall within
- # a defined range, such as 'Starvation', 'Dehydration', etc.
- # Negative values will remove its states
- # Configure like this:
- #
- # when MIN..MAX then return [STATE_ID, -STATE_ID, .....]
- #
- # If actor's hunger/thirst is equal to or between MIN and MAX, the state with
- # STATE_ID will be applied. This method is refreshed everytime the system
- # decreases hunger/thirst.
- #
- # Keep in mind that these states will NOT be automatically cured if the
- # actor's hunger/thirst rise above.
- # Create your food/drink items to cure these states.
- #
- #-------------------------------------------------------------------------------
- def self.hunger_states(current_hunger)
- case current_hunger
- when 0 then return 1 # Death
- when 1..9 then return 2
- when 10..15 then return [3,4,5]
- end
- end
- def self.thirst_states(current_thirst)
- case current_thirst
- when 0 then return 1 # Death
- when 1..9 then return 2
- when 10..15 then return [3,4,5]
- end
- end
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # END CONFIGURATION
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- #----------------------------------------------------------------------------
- # Don't Edit
- HUNGER_THIRST_TAGS = {
- :hunger => /<hunger:\s*([-]?\d+)\s*>/i,
- :thirst => /<thirst:\s*([-]?\d+)\s*>/i,
- :incmaxhunger => /<increase[-_ ]?max[-_ ]?hunger:\s*([-]?\d+)\s*>/i,
- :incmaxthirst => /<increase[-_ ]?max[-_ ]?thirst:\s*([-]?\d+)\s*>/i,
- :hungerpercent => /<recover[-_ ]?hunger[-_ ]?by[-_ ]?percent>/i,
- :thirstpercent => /<recover[-_ ]?thirst[-_ ]?by[-_ ]?percent>/i,
- :hungerlvup => /<hunger[-_ ]?lvl[-_ ]?up[-_ ]?increase:\s*([-]?\d+)\s*>/i,
- :thirstlvup => /<thirst[-_ ]?lvl[-_ ]?up[-_ ]?increase:\s*([-]?\d+)\s*>/i,
- :hunger_max => /<hunger[-_ ]?max:\s*([-]?\d+)\s*>/,
- :thirst_max => /<thirst[-_ ]?max:\s*([-]?\d+)\s*>/,
- }
- #----------------------------------------------------------------------------
- end
- ($imported||={})[:drg_hunger_thirst] = 1.07
- core_engine = "This script needs Drago - Core Engine ver 1.48 or above"
- ($imported[:drg_core_engine] || 0) >= 1.48 || raise(core_engine)
- #==============================================================================
- # ** Game_Actor
- #------------------------------------------------------------------------------
- # This class handles actors. It is used within the Game_Actors class
- # ($game_actors) and is also referenced from the Game_Party class ($game_party).
- #==============================================================================
- class Game_Actor
- #--------------------------------------------------------------------------
- # ● Class Variables
- #--------------------------------------------------------------------------
- @@lvup_defined = method_defined?(:level_up) ? :level_up : :exp=
- #--------------------------------------------------------------------------
- # ● Aliased method: setup
- #--------------------------------------------------------------------------
- define_third_method(:setup, :drg_hunger_setup) do |*args|
- drg_hunger_setup(*args)
- @max_hunger = LiTTleDRAgo::DEFAULT_HUNGER
- @max_thirst = LiTTleDRAgo::DEFAULT_THIRST
- @max_hunger = $1.to_i if actor.get_note =~ hunger_tags[:hunger_max]
- @max_thirst = $1.to_i if actor.get_note =~ hunger_tags[:thirst_max]
- inc = hunger_and_thirst_increment_level_up
- if @level > 1
- @max_hunger += ((@level-1) * inc.at(0)).round if inc.at(0).is_a?(Numeric)
- @max_thirst += ((@level-1) * inc.at(1)).round if inc.at(1).is_a?(Numeric)
- end
- recover_hunger
- recover_thirst
- end
- #--------------------------------------------------------------------------
- # ● Aliased method: level_up
- #--------------------------------------------------------------------------
- define_third_method(:drg_hunger_level_up, :"#{@@lvup_defined}") do |*exp|
- level = @level
- drg_hunger_level_up(*exp)
- inc = hunger_and_thirst_increment_level_up
- if level != @level
- lvls = @level - level
- self.max_hunger += (inc.at(0) * lvls).round if inc.at(0).is_a?(Numeric)
- self.max_thirst += (inc.at(1) * lvls).round if inc.at(1).is_a?(Numeric)
- end
- end
- #--------------------------------------------------------------------------
- # ● New method: hunger_and_thirst_increment_level_up
- #--------------------------------------------------------------------------
- def hunger_and_thirst_increment_level_up
- increase = []
- increase[0] = LiTTleDRAgo::LVL_UP_INCREASE[0]
- increase[1] = LiTTleDRAgo::LVL_UP_INCREASE[1]
- increase[0] = $1.to_i if actor.get_note =~ hunger_tags[:hungerlvup]
- increase[1] = $1.to_i if actor.get_note =~ hunger_tags[:thirstlvup]
- return increase
- end
- end
- #==============================================================================
- # ** Game_Battler
- #------------------------------------------------------------------------------
- # A battler class with methods for sprites and actions added. This class
- # is used as a super class of the Game_Actor class and Game_Enemy class.
- #==============================================================================
- Klass = $BlizzABS ? Map_Battler : Game_Battler
- class Klass
- #--------------------------------------------------------------------------
- # ● Class Variable
- #--------------------------------------------------------------------------
- @@item_hunger_effect = (VXA = LiTTleDRAgo::VXA) ? :use_item : :item_effect
- @@item_effect_test = (VX = LiTTleDRAgo::VX) ? :item_test : :item_effect_test
- #--------------------------------------------------------------------------
- # ● Alias Listing
- #--------------------------------------------------------------------------
- alias_sec_method :drg_ht_item_effect, :"#{@@item_hunger_effect}"
- alias_sec_method :drg_ht_item_effect_test, :"#{@@item_effect_test}"
- #--------------------------------------------------------------------------
- # ● Public Instance Variables
- #--------------------------------------------------------------------------
- attr_sec_accessor :hunger, :max_hunger, 'LiTTleDRAgo::DEFAULT_HUNGER'
- attr_sec_accessor :thirst, :max_thirst, 'LiTTleDRAgo::DEFAULT_THIRST'
- attr_sec_reader :hunger_tags, 'LiTTleDRAgo::HUNGER_THIRST_TAGS'
- #--------------------------------------------------------------------------
- # ● New method: hunger=
- #--------------------------------------------------------------------------
- def hunger=(value)
- @hunger = [[value, 0].max, max_hunger].min
- end
- #--------------------------------------------------------------------------
- # ● New method: thirst=
- #--------------------------------------------------------------------------
- def thirst=(value)
- @thirst = [[value, 0].max, max_thirst].min
- end
- #--------------------------------------------------------------------------
- # ● New method: max_hunger=
- #--------------------------------------------------------------------------
- def max_hunger=(value)
- @max_hunger = [value, 1].max
- @hunger = [[hunger, 0].max, @max_hunger].min
- end
- #--------------------------------------------------------------------------
- # ● New method: max_thirst=
- #--------------------------------------------------------------------------
- def max_thirst=(value)
- @max_thirst = [value, 1].max
- @thirst = [[thirst, 0].max, @max_thirst].min
- end
- #--------------------------------------------------------------------------
- # ● New method: recover_hunger
- #--------------------------------------------------------------------------
- def recover_hunger
- self.hunger = self.max_hunger
- end
- #--------------------------------------------------------------------------
- # ● New method: recover_thirst
- #--------------------------------------------------------------------------
- def recover_thirst
- self.thirst = self.max_thirst
- end
- #--------------------------------------------------------------------------
- # ● New method: recover_hunger_thirst
- #--------------------------------------------------------------------------
- def recover_hunger_thirst
- recover_hunger
- recover_thirst
- end
- #--------------------------------------------------------------------------
- # ● New method: hunger_percent
- #--------------------------------------------------------------------------
- def hunger_percent
- ((self.hunger / self.max_hunger.to_f) * 100).round
- end
- #--------------------------------------------------------------------------
- # ● New method: thirst_percent
- #--------------------------------------------------------------------------
- def thirst_percent
- ((self.thirst / self.max_thirst.to_f) * 100).round
- end
- #--------------------------------------------------------------------------
- # * Application of Item Effects
- #--------------------------------------------------------------------------
- define_method(:"#{@@item_hunger_effect}") do |*args|
- result = drg_ht_item_effect(*args)
- item = args.find {|s| s.is_a?(RPG::Item)}
- user = args.find {|s| s.is_a?(Game_Battler)}
- user ||= $BlizzABS ? self.battler : self
- if item.is_a?(RPG::Item) && user.is_a?(Game_Actor)
- food_item = false
- rec = LiTTleDRAgo::ITEM_RECOVER_HUNGER_THIRST
- hunger_plus = (rec = rec[item.id] || rec[0] || [])[0]
- thirst_plus = rec[1]
- hunger_plus = $1.to_i if item.get_note =~ user.hunger_tags[:hunger]
- thirst_plus = $1.to_i if item.get_note =~ user.hunger_tags[:thirst]
- user.max_hunger += $1.to_i if item.get_note =~ user.hunger_tags[:incmaxhunger]
- user.max_thirst += $1.to_i if item.get_note =~ user.hunger_tags[:incmaxthirst]
- if hunger_plus.is_a?(Numeric) && hunger_plus != 0
- a = rec[2] == true || item.get_note =~ user.hunger_tags[:hungerpercent]
- hunger_plus = (user.max_hunger * (hunger_plus * 0.01)).ceil if a
- user.hunger += hunger_plus
- food_item = true
- end
- if thirst_plus.is_a?(Numeric) && thirst_plus != 0
- a = rec[2] == true || item.get_note =~ user.hunger_tags[:thirstpercent]
- thirst_plus = (user.max_thirst * (thirst_plus * 0.01)).ceil if a
- user.thirst += thirst_plus
- food_item = true
- end
- if food_item && !VXA
- if LiTTleDRAgo::VX
- apply_state_changes(item)
- else
- states_plus(item.plus_state_set)
- states_minus(item.minus_state_set)
- end
- result ||= true
- end
- end
- return result
- end
- #--------------------------------------------------------------------------
- # * Test Effect
- #--------------------------------------------------------------------------
- define_method("#{@@item_effect_test}") do |*args|
- item_effect_hunger?(*args[0..1]) || drg_ht_item_effect_test(*args)
- end
- #--------------------------------------------------------------------------
- # * Effect Hunger?
- #--------------------------------------------------------------------------
- def item_effect_hunger?(a,item)
- recover = LiTTleDRAgo::ITEM_RECOVER_HUNGER_THIRST
- hunger = (recover = recover[item.id] || recover[0] || [])[0]
- thirst = recover[1]
- hunger = $1.to_i if item.get_note =~ a.hunger_tags[:hunger]
- thirst = $1.to_i if item.get_note =~ a.hunger_tags[:thirst]
- hunger = a.hunger < a.max_hunger && hunger.is_a?(Numeric) && hunger != 0
- thirst = a.thirst < a.max_thirst && thirst.is_a?(Numeric) && thirst != 0
- a.alive? && (hunger || thirst)
- end
- end
- #==============================================================================
- # ** Game_Party
- #------------------------------------------------------------------------------
- # This class handles parties. Information such as gold and items is included.
- # Instances of this class are referenced by $game_party.
- #==============================================================================
- class Game_Party
- #--------------------------------------------------------------------------
- # ● Public Instance Variables
- #--------------------------------------------------------------------------
- attr_sec_accessor :hunger, 'LiTTleDRAgo::ENABLE_HUNGER_AT_START'
- attr_sec_accessor :step_hunger, 'LiTTleDRAgo::STEPS_HUNGER_DOWN'
- attr_sec_accessor :step_thirst, 'LiTTleDRAgo::STEPS_THIRST_DOWN'
- #--------------------------------------------------------------------------
- # ● New method: check_hunger_states
- #--------------------------------------------------------------------------
- def check_hunger_states
- members.each do |actor|
- state_id = [LiTTleDRAgo.hunger_states(actor.hunger)].flatten.compact
- state_id.each do |id|
- actor.add_state(id.to_i.abs) if id.is_a?(Numeric) && id.to_i > 0
- actor.remove_state(id.to_i.abs) if id.is_a?(Numeric) && id.to_i < 0
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● New method: check_thirst_states
- #--------------------------------------------------------------------------
- def check_thirst_states
- members.each do |actor|
- state_id = [LiTTleDRAgo.thirst_states(actor.thirst)].flatten.compact
- state_id.each do |id|
- actor.add_state(id.to_i.abs) if id.is_a?(Numeric) && id.to_i > 0
- actor.remove_state(id.to_i.abs) if id.is_a?(Numeric) && id.to_i < 0
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● New method: update_hunger_by_time
- #--------------------------------------------------------------------------
- def update_hunger_by_time
- @time_hunger = (@time_hunger || 0) + 1
- @time_thirst = (@time_thirst || 0) + 1
- if @time_hunger >= (LiTTleDRAgo::SECS_HUNGER_DOWN * Graphics.frame_rate)
- actor = members.find_all {|actor| actor.alive? && actor.hunger > 0 }
- actor.each {|s| s.hunger -= 1 }
- check_hunger_states
- @time_hunger = 0
- end
- if @time_thirst >= (LiTTleDRAgo::SECS_THIRST_DOWN * Graphics.frame_rate)
- actor = members.find_all {|actor| actor.alive? && actor.thirst > 0 }
- actor.each {|s| s.thirst -= 1 }
- check_thirst_states
- @time_thirst = 0
- end
- end
- #--------------------------------------------------------------------------
- # ● New method: update_hunger_by_steps
- #--------------------------------------------------------------------------
- def update_hunger_by_steps
- if steps >= step_hunger
- actor = members.find_all {|actor| actor.alive? && actor.hunger > 0 }
- actor.each {|s| s.hunger -= 1 }
- check_hunger_states
- @step_hunger = steps + LiTTleDRAgo::STEPS_HUNGER_DOWN
- end
- if steps >= step_thirst
- actor = members.find_all {|actor| actor.alive? && actor.thirst > 0 }
- actor.each {|s| s.thirst -= 1 }
- check_thirst_states
- @step_thirst = steps + LiTTleDRAgo::STEPS_THIRST_DOWN
- end
- end
- #--------------------------------------------------------------------------
- # ● New method: hunger_debugger
- #--------------------------------------------------------------------------
- def hunger_debugger
- sys = "System ON: #{$game_party.hunger}\n\n" +
- "By Time: #{LiTTleDRAgo::BY_TIME}\n" +
- "By Steps: #{LiTTleDRAgo::BY_STEPS}\n\n"
- actors = ''
- time_hunger = $game_party.time_hunger / Graphics.frame_rate
- time_thirst = $game_party.time_thirst / Graphics.frame_rate
- $game_party.members.each {|actor| actors +=
- "#{actor.name}\nHunger: #{actor.hunger}\\#{actor.max_hunger}\n" +
- "Thirst: #{actor.thirst}\\#{actor.max_thirst}\n\n"}
- ht = "HungerTime: #{time_hunger}\\#{LiTTleDRAgo::SECS_HUNGER_DOWN}\n"
- tt = "ThirstTime: #{time_thirst}\\#{LiTTleDRAgo::SECS_THIRST_DOWN}\n"
- hs = "HungerStep: #{$game_party.steps}\\#{$game_party.step_hunger}\n"
- ts = "ThirstStep: #{$game_party.steps}\\#{$game_party.step_thirst}\n"
- print(sys + actors + ht + tt + hs + ts)
- end
- #--------------------------------------------------------------------------
- # ● New method: recover_hunger
- #--------------------------------------------------------------------------
- def recover_hunger
- members.recover_hunger
- end
- #--------------------------------------------------------------------------
- # ● New method: recover_hunger
- #--------------------------------------------------------------------------
- def recover_thirst
- members.recover_thirst
- end
- #--------------------------------------------------------------------------
- # ● New method: recover_hunger_thirst
- #--------------------------------------------------------------------------
- def recover_hunger_thirst
- members.recover_hunger_thirst
- end
- end
- #==============================================================================
- # ** Scene_Map
- #------------------------------------------------------------------------------
- # This class performs the map screen processing.
- #==============================================================================
- class Scene_Map
- #--------------------------------------------------------------------------
- # ● Aliased method: Update
- #--------------------------------------------------------------------------
- define_third_method(:update, :drg_hunger_map_upd) do |*args|
- drg_hunger_map_upd(*args)
- update_hunger if $game_party.hunger
- end
- #--------------------------------------------------------------------------
- # ● New method: update_hunger
- #--------------------------------------------------------------------------
- def update_hunger
- $game_party.update_hunger_by_time if LiTTleDRAgo::BY_TIME
- $game_party.update_hunger_by_steps if LiTTleDRAgo::BY_STEPS
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement