eugene222

TPS Phases and Weather

Jul 11th, 2014
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 34.06 KB | None | 0 0
  1. #===============================================================================
  2. # ***TPS-Addon: Phases and Weather***
  3. #
  4. # Author:     eugene222 (Evgenij)
  5. # Version:    1.0a
  6. # Date:       21.05.2014
  7. # Requires:   Time and Period System V. 1.2 by eugene222
  8. #===============================================================================
  9. # Changelog:
  10. #
  11. #   21.05.2014 - V. 1.0        - created
  12. #   21.07.2014 - V. 1.0a       - fixed a small bug
  13. #
  14. #===============================================================================
  15. # Terms of Use:
  16. #   You can use this script for free and commercial projects as long as you give
  17. #   credits.
  18. #===============================================================================
  19. # Description:
  20. #  With this script you can create custom weathers and phases
  21. #  You can assign your custom weathers to your phases.
  22. #
  23. #  THIS SCRIPT IS A LITTLE BIT COMPLEX.
  24. #
  25. # Scriptcalls:
  26. #   $game_time.phase_active?(name) # Checks if the phase "name" is active
  27. #   Example:
  28. #     $game_time.phase_active?(:winter) - returns true if the :winter phase is
  29. #                                         active
  30. #
  31. #===============================================================================
  32. module TPS_PHASES
  33.   #-----------------------------------------------------------------------------
  34.   # Show Weather Effects in Battle?
  35.   #-----------------------------------------------------------------------------
  36.   USE_WEATHER_IN_BATTLE = true
  37.  
  38.   #-----------------------------------------------------------------------------
  39.   # How much should the maximum for weather change per day be?
  40.   #  - false if no maximum
  41.   #-----------------------------------------------------------------------------
  42.   MAXIMUM_WEATHER_PER_DAY = false
  43.  
  44.   #-----------------------------------------------------------------------------
  45.   WEATHERS = { # Diese Zeile nicht verändern
  46.   #-----------------------------------------------------------------------------
  47.   # :weather_name =>[:type, power, min-time, max-time, sound, indoor-sound]
  48.   #
  49.   #   - type: :none, :snow, :rain or :storm
  50.   #   - power: 1-9
  51.   #   - min-dauer: min time in ingame minutes
  52.   #   - max-dauer: max time in ingame minutes
  53.   #   - sound: sound for outdoor maps
  54.   #   - indoor-sound: sound for indoor maps
  55.   #
  56.   #  This is how your sound config should look like:
  57.   #  
  58.   #  ["filename", volume, pitch] or nil wenn no sound  
  59.   #  
  60.   #
  61.   #-----------------------------------------------------------------------------
  62.    
  63.     :no_weather => [:none, 0 , 120, 180, nil, nil],
  64.  
  65.    
  66.     :weak_rain   => [:rain, 3,  80, 140, ["Rain", 100, 100], ["Rain", 70, 100]],
  67.     :normal_rain => [:rain, 6,  80, 160, ["Rain", 100, 100], ["Rain", 70, 100]],
  68.     :strong_rain => [:rain, 9, 100, 160, ["Rain", 100, 100], ["Rain", 70, 100]],
  69.    
  70.     :long_rain   => [:rain, 6, 160, 280 ,["Rain", 100, 100], ["Rain", 70, 100]],
  71.    
  72.     :weak_storm   => [:storm, 3, 80, 140, ["Storm", 100, 100], ["Storm", 70, 100]],
  73.     :normal_storm => [:storm, 6, 80, 160, ["Storm", 100, 100], ["Storm", 70, 100]],
  74.     :strong_storm => [:storm, 9,100, 160, ["Storm", 100, 100], ["Storm", 70, 100]],
  75.    
  76.     :long_storm  => [:storm, 6, 160, 280, ["Storm", 100, 100], ["Storm", 70, 100]],
  77.    
  78.     :weak_snow   => [:snow, 3,  80, 140, ["Wind", 20, 100], nil],
  79.     :normal_snow => [:snow, 6,  80, 160, ["Wind", 30, 100], nil],
  80.     :strong_snow => [:snow, 9, 100, 160, ["Wind", 50, 100], nil],
  81.    
  82.     :long_snow   => [:snow, 6,  160, 280, ["Wind", 30, 100], nil],
  83.    
  84.   #-----------------------------------------------------------------------------
  85.   } # Diese Zeile nicht verändern
  86.   #-----------------------------------------------------------------------------
  87.   CONDITIONS = { # Diese Zeile unverändert lassen
  88.   #-----------------------------------------------------------------------------
  89.   # If you dont understand something below, ask me in the forum, I try to explain
  90.   # or help at best.
  91.   #
  92.   # Priority for weather and other things that will come
  93.   #   priorty: zahl  
  94.   #
  95.   # Time when the phase is active:
  96.   #   time: :all oder
  97.   #   time: [starttime..endtime, :periode, etc..]
  98.   #
  99.   # Weekdays:
  100.   #   days: :all or
  101.   #   days: ["Monday", "Thursday", "Friday"]
  102.   #
  103.   # Months:
  104.   #   months: :all or
  105.   #   months: {"January" => [0..10, 12..31, etc..], etc..}  or
  106.   #   months: {"January" => :all, "March" => [0..15, etc..], etc.. }
  107.   #
  108.   # Years:
  109.   #   years: :all or
  110.   #   years: [2004, 2005, 2006, etc..]
  111.   #
  112.   # Switch when is on when the phase is active:
  113.   #   switch: id    
  114.   #
  115.   # Common Event which starts when the phase is active(Optional):
  116.   #   common_event: id
  117.   #
  118.   # Weathers for the phase (Optional):
  119.   #
  120.   #  weathers: {
  121.   #
  122.   #     :wetter => wahrscheinlichkeit,
  123.   #  }
  124.   #
  125.   # Deactivate this phase when other phases are active
  126.   #   exclude: [phase_name, phase_name, phase_name, usw..]
  127.   #
  128.   #
  129.   #  LOOK AT THE EXAMPLES BELOW AND HOPEFULLY YOU WILL UNDERSTAND BETTER
  130.   #
  131.   #-----------------------------------------------------------------------------
  132.   #-----------------------------------------------------------------------------
  133.   # PREDEFINED PHASES:
  134.   #-----------------------------------------------------------------------------
  135.     #---------------------------------------------------------------------------
  136.     # Spring:
  137.     #---------------------------------------------------------------------------
  138.     :spring => {
  139.    
  140.         priority: 1,
  141.         time: :all,
  142.         days: :all,
  143.         months: {"March" => :all, "April" => :all, "May" => :all},
  144.         years: :all,
  145.         switch: 10,
  146.         weathers: { :no_weather   => 80,
  147.                     :weak_rain    => 10,
  148.                     :normal_rain  => 10,
  149.                     :strong_rain  => 5,
  150.                     :weak_storm   => 5,
  151.                     :normal_storm => 5,
  152.                   },
  153.     },
  154.     #---------------------------------------------------------------------------
  155.     # Summer:
  156.     #---------------------------------------------------------------------------
  157.     :summer => {
  158.    
  159.         priority: 1,
  160.         time: :all,
  161.         days: :all,
  162.         months: {"June" => :all, "July" => :all, "August" => :all},
  163.         years: :all,
  164.         switch: 11,
  165.         weathers: { :no_weather  => 100,
  166.                     :weak_rain   => 10,
  167.                     :normal_rain => 5,
  168.                   },
  169.     },
  170.     #---------------------------------------------------------------------------
  171.     # Autumn:
  172.     #---------------------------------------------------------------------------
  173.     :autumn => {
  174.    
  175.         priority: 1,
  176.         time: :all,
  177.         days: :all,
  178.         months: {"September" => :all, "October" => :all, "November" => :all},
  179.         years: :all,
  180.         switch: 12,
  181.         weathers: { :no_weather   => 35,
  182.                     :weak_rain    => 15,
  183.                     :normal_rain  => 10,
  184.                     :strong_rain  => 10,
  185.                     :long_rain    => 10,
  186.                     :weak_storm   => 10,
  187.                     :normal_storm => 5,
  188.                     :strong_storm => 5,
  189.                   },
  190.     },
  191.     #---------------------------------------------------------------------------
  192.     # Winter:
  193.     #---------------------------------------------------------------------------
  194.     :winter => {
  195.    
  196.         priority: 1,
  197.         time: :all,
  198.         days: :all,
  199.         months: {"December" => :all, "January" => :all, "February" => :all},
  200.         years: :all,
  201.         switch: 13,
  202.         weathers: { :no_weather  => 40,
  203.                     :weak_snow   => 20,
  204.                     :normal_snow => 15,
  205.                     :strong_snow => 10,
  206.                     :long_snow   => 5,
  207.                     :weak_rain   => 5,
  208.                     :normal_rain => 5,
  209.                     :strong_rain => 5,
  210.                     :weak_storm  => 5,
  211.                   },
  212.     },
  213.     #---------------------------------------------------------------------------
  214.     # Holiday 1:
  215.     #  - Active at 1st January.
  216.     #---------------------------------------------------------------------------
  217.     :holiday1 => {
  218.    
  219.         priority: 0,
  220.         time: :all,
  221.         days: :all,
  222.         months: {"January" => [1]},
  223.         years: :all,
  224.         switch: 15,
  225.  
  226.     },
  227.     #---------------------------------------------------------------------------
  228.     # Holiday 2:
  229.     #  - Active at 6st January.
  230.     #---------------------------------------------------------------------------
  231.     :holiday2 => {
  232.    
  233.         priority: 0,
  234.         time: :all,
  235.         days: :all,
  236.         months: {"January" => [6]},
  237.         years: :all,
  238.         switch: 16,
  239.     },
  240.     #---------------------------------------------------------------------------
  241.     # Pup Opening Time:
  242.     #  - Every day at evening and night active, deactive at :holiday1
  243.     #---------------------------------------------------------------------------
  244.     :pub_opening_time => {
  245.    
  246.         priority: 0,
  247.         exclude: [:holiday1],
  248.         time: [:evening, :night],
  249.         days: :all,
  250.         months: :all,
  251.         years: :all,
  252.         switch: 17,
  253.     },
  254.     #---------------------------------------------------------------------------
  255.     # Itemshop Opening Phase:
  256.     #  - Every day except weekend from 8:00 AM till 8:00 PM active,
  257.     #    inactive when :holiday1 or :holiday2 is active.
  258.     #---------------------------------------------------------------------------
  259.     :item_shop_opening_time => {
  260.    
  261.         priority: 0,
  262.         exclude: [:holiday1, :holiday2],
  263.         time: [480..1200],
  264.         days: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"],
  265.         months: :all,
  266.         years: :all,
  267.         switch: 18,
  268.     },
  269.  
  270.   #-----------------------------------------------------------------------------
  271.   } # Diese Zeile nicht verändern
  272.   #-----------------------------------------------------------------------------
  273. end
  274. #===============================================================================
  275. # END OF CONFIG
  276. #===============================================================================
  277. $imported ||= {}
  278. $imported[:e222_tps_phases] = 1.0
  279. unless $imported[:e222_tps_core]
  280.   msgbox("\"TBS-Addon: Phases and Weather\" requires the \"TBS-Core\" script.\n"+
  281.          "The \"TBS-Core\" script must be placed above the addon script.")
  282.   exit
  283. end
  284.  
  285. class Game_Time
  286.   #-----------------------------------------------------------------------------
  287.   attr_reader :active_phases
  288.   #-----------------------------------------------------------------------------
  289.   alias :tps_phases_reinitialize           :reinitialize
  290.   #-----------------------------------------------------------------------------
  291.   # Reinitialize
  292.   #-----------------------------------------------------------------------------
  293.   def reinitialize
  294.     tps_phases_reinitialize
  295.     return unless TPS_PHASES::CONDITIONS
  296.     @all_phases ||= {}
  297.     @active_phases ||= {}
  298.     make_all_condition_variables
  299.     make_time_condition_cache
  300.     refresh_conditions
  301.   end
  302.   #-----------------------------------------------------------------------------
  303.   # Sort Active Phases
  304.   #-----------------------------------------------------------------------------
  305.   def sort_active_phases
  306.     @active_phases = @all_phases.select {|name, status| status == true}.keys
  307.     @active_phases.sort_by! {|name| TPS_PHASES::CONDITIONS[name][:priority]}
  308.   end
  309.   #-----------------------------------------------------------------------------
  310.   # Make All Condition Variables
  311.   #-----------------------------------------------------------------------------
  312.   def make_all_condition_variables
  313.     cond = TPS_PHASES::CONDITIONS.clone
  314.     @condition_effects = cond.select {|k, v| v[:effects]}.keys
  315.     @time_conditions = select_and_remove(cond) {|k, v| v[:time] != :all}.keys
  316.     @day_conditions = select_and_remove(cond) {|k, v| v[:days] != :all}.keys
  317.     @day_conditions += select_and_remove(cond) do |k, v|
  318.       v[:months].values.any? {|value| value != :all}
  319.     end.keys
  320.     @month_conditions = select_and_remove(cond) {|k, v| v[:months] != :all}.keys
  321.     @year_conditions = select_and_remove(cond) {|k, v| v[:years] != :all}.keys
  322.   end
  323.   #-----------------------------------------------------------------------------
  324.   # Select and Remove From Hash
  325.   #-----------------------------------------------------------------------------
  326.   def select_and_remove(hash)
  327.     tmp_hash = hash.select {|k, v| yield(k, v)}
  328.     hash = hash.delete_if {|k, v| yield(k, v)}
  329.     return tmp_hash
  330.   end
  331.   #-----------------------------------------------------------------------------
  332.   # Make Time Conditions Cache
  333.   #-----------------------------------------------------------------------------
  334.   def make_time_condition_cache
  335.     @time_conditions = Hash[ @time_conditions.map { |name|
  336.       [name, return_time_hash(TPS_PHASES::CONDITIONS[name][:time])]
  337.     }]
  338.   end
  339.   #-----------------------------------------------------------------------------
  340.   # Make Day Conditions Cache
  341.   #-----------------------------------------------------------------------------
  342.   def make_day_condition_cache
  343.     @day_conditions = {}
  344.     TPS_PHASES::CONDITIONS.each do |key, value|
  345.       @time_conditions[key] = return_time_hash(value[:time])
  346.     end
  347.   end
  348.   #-----------------------------------------------------------------------------
  349.   # Return Time Hash
  350.   #-----------------------------------------------------------------------------
  351.   def return_time_hash(times)
  352.     hash = Hash.new(false)
  353.       times.each do |time_or_period|
  354.         if time_or_period.is_a?(Symbol)
  355.           @period_hash.reject {|k, v| v != time_or_period}.keys.each do |time|
  356.             hash[time] = true
  357.           end
  358.         elsif time_or_period.is_a?(Range)
  359.           time_or_period.each { |time| hash[time] = true }
  360.         else
  361.           hash[time_or_period] = true
  362.         end
  363.       end
  364.     return hash
  365.   end
  366.   #-----------------------------------------------------------------------------
  367.   # Refresh Condition Switches
  368.   #-----------------------------------------------------------------------------
  369.   def refresh_conditions
  370.     refresh_time_conditions
  371.     refresh_day_conditions
  372.     refresh_month_conditions
  373.     refresh_year_conditions
  374.   end
  375.   #-----------------------------------------------------------------------------
  376.   # Next Minute
  377.   #-----------------------------------------------------------------------------
  378.   alias :tps_phases_next_minute          :next_minute
  379.   def next_minute
  380.     tps_phases_next_minute
  381.     refresh_time_conditions
  382.   end
  383.   #-----------------------------------------------------------------------------
  384.   # Next Day
  385.   #-----------------------------------------------------------------------------
  386.   alias :tps_phases_next_day             :next_day
  387.   def next_day
  388.     tps_phases_next_day
  389.     refresh_day_conditions
  390.   end
  391.   #-----------------------------------------------------------------------------
  392.   # Next Month
  393.   #-----------------------------------------------------------------------------
  394.   alias :tps_phases_next_month           :next_month
  395.   def next_month
  396.     tps_phases_next_month
  397.     refresh_month_conditions
  398.   end
  399.   #-----------------------------------------------------------------------------
  400.   # Next Year
  401.   #-----------------------------------------------------------------------------
  402.   alias :tps_phases_next_year            :next_year
  403.   def next_year
  404.     tps_phases_next_year
  405.     refresh_year_conditions
  406.   end
  407.   #-----------------------------------------------------------------------------
  408.   # Refresh Time Conditions
  409.   #-----------------------------------------------------------------------------
  410.   def refresh_time_conditions
  411.     return if @time_conditions.empty?
  412.     @time_conditions.each do |name, value|
  413.       update_condition(name)
  414.     end
  415.   end
  416.   #-----------------------------------------------------------------------------
  417.   # Refresh Day Conditions
  418.   #-----------------------------------------------------------------------------
  419.   def refresh_day_conditions
  420.     return if @day_conditions.empty?
  421.     @day_conditions.each do |name|  
  422.       update_condition(name)
  423.     end
  424.   end
  425.   #-----------------------------------------------------------------------------
  426.   # Refresh Month Conditions
  427.   #-----------------------------------------------------------------------------
  428.   def refresh_month_conditions
  429.     return if @month_conditions.empty?
  430.     @month_conditions.each do |name|
  431.       update_condition(name)  
  432.     end
  433.   end
  434.   #-----------------------------------------------------------------------------
  435.   # Refresh Year Conditions
  436.   #-----------------------------------------------------------------------------
  437.   def refresh_year_conditions
  438.     return if @year_conditions.empty?
  439.     @year_conditions.each do |name|
  440.       update_condition(name)
  441.     end
  442.   end
  443.   #-----------------------------------------------------------------------------
  444.   # Update Condition
  445.   #-----------------------------------------------------------------------------
  446.   def update_condition(name)
  447.     status = check_condition(name)
  448.     return if @all_phases[name] == status
  449.     $game_switches[TPS_PHASES::CONDITIONS[name][:switch]] = status
  450.     status ? add_phase(name) : remove_phase(name)
  451.     start_common_event(name) if status
  452.   end
  453.   #-----------------------------------------------------------------------------
  454.   # Start Common Event
  455.   #-----------------------------------------------------------------------------
  456.   def start_common_event(phase)
  457.     return unless TPS_PHASES::CONDITIONS[phase][:common_event]
  458.     $game_temp.reserve_common_event(TPS_PHASES::CONDITIONS[phase][:common_event])  
  459.   end
  460.   #-----------------------------------------------------------------------------
  461.   # Add Phase
  462.   #-----------------------------------------------------------------------------
  463.   def add_phase(name)
  464.     return if @all_phases[name]
  465.     puts "[TPS: Phases and Weather] Phase added: #{name}"
  466.     @all_phases[name] = true
  467.     sort_active_phases
  468.   end
  469.   #-----------------------------------------------------------------------------
  470.   # Remove Phase
  471.   #-----------------------------------------------------------------------------
  472.   def remove_phase(name)
  473.     return unless @all_phases[name]
  474.     puts "[TPS: Phases and Weather] Phase removed: #{name}"
  475.     @all_phases[name] = false
  476.     sort_active_phases
  477.   end
  478.   #-----------------------------------------------------------------------------
  479.   # Check Condition
  480.   #-----------------------------------------------------------------------------
  481.   def check_condition(name)
  482.     return false unless TPS_PHASES::CONDITIONS[name]
  483.     return false unless check_exclude_condition(name)
  484.     return false unless check_year_condition(name)
  485.     return false unless check_month_condition(name)
  486.     return false unless check_day_condition(name)
  487.     return false unless check_time_condition(name)
  488.     return true
  489.   end
  490.   #-----------------------------------------------------------------------------
  491.   # Check Exclude Condition
  492.   #-----------------------------------------------------------------------------
  493.   def check_exclude_condition(name)
  494.     return true unless TPS_PHASES::CONDITIONS[name][:exclude]
  495.     TPS_PHASES::CONDITIONS[name][:exclude].each do |phase|
  496.       return false if phase_active?(phase)
  497.     end
  498.     return true
  499.   end
  500.   #-----------------------------------------------------------------------------
  501.   # Check Year Condition
  502.   #-----------------------------------------------------------------------------
  503.   def check_year_condition(name)
  504.     return true unless  TPS_PHASES::CONDITIONS[name][:years]
  505.     return true if TPS_PHASES::CONDITIONS[name][:years] == :all
  506.     return true if TPS_PHASES::CONDITIONS[name][:years].include?(@current_year)
  507.     return false
  508.   end
  509.   #-----------------------------------------------------------------------------
  510.   # Check Month Condition
  511.   #-----------------------------------------------------------------------------
  512.   def check_month_condition(name)
  513.     month_conditions = TPS_PHASES::CONDITIONS[name][:months]
  514.     return true if month_conditions == :all
  515.     if month_conditions[:all]
  516.       return true if check_month_days(month_conditions[:all])
  517.     end
  518.     if month_conditions[current_month_vocab]
  519.       return true if month_conditions[current_month_vocab] == :all
  520.       return true if check_month_days(month_conditions[current_month_vocab])
  521.     end
  522.     return false
  523.   end
  524.   #-----------------------------------------------------------------------------
  525.   # Check Month Days
  526.   #-----------------------------------------------------------------------------
  527.   def check_month_days(day_ranges)
  528.     return true if day_ranges.any? { |days|
  529.       (days.is_a?(Range) && days.include?(current_day) || days == current_day)
  530.     }
  531.     return false
  532.   end
  533.   #-----------------------------------------------------------------------------
  534.   # Check Day Condition
  535.   #-----------------------------------------------------------------------------
  536.   def check_day_condition(name)
  537.     return true if TPS_PHASES::CONDITIONS[name][:days] == :all
  538.     return true if TPS_PHASES::CONDITIONS[name][:days].include?(current_day_vocab)
  539.    
  540.     return false
  541.   end
  542.   #-----------------------------------------------------------------------------
  543.   # Check Time Condition
  544.   #-----------------------------------------------------------------------------
  545.   def check_time_condition(name)
  546.     return true if TPS_PHASES::CONDITIONS[name][:time] == :all
  547.     return @time_conditions[name][@current_time]
  548.   end
  549.   #-----------------------------------------------------------------------------
  550.   # Phase Active ?
  551.   #-----------------------------------------------------------------------------
  552.   def phase_active?(name)
  553.     return @active_phases.include?(name)
  554.   end
  555.   #-----------------------------------------------------------------------------
  556. end
  557. #===============================================================================
  558. # Weather:
  559. #===============================================================================
  560. class Game_Time  
  561.   #-----------------------------------------------------------------------------
  562.   # Reinitialize
  563.   #-----------------------------------------------------------------------------
  564.   alias :tps_weather_reinitialize           :reinitialize
  565.   #-----------------------------------------------------------------------------
  566.   def reinitialize
  567.     return unless TPS_PHASES::CONDITIONS
  568.     @current_weather      ||= :none
  569.     @current_abs_weather  ||= nil
  570.     @weather_duration     ||= 0
  571.     @weather_strength     ||= nil
  572.     @current_rolls        ||= 0
  573.     tps_weather_reinitialize
  574.     make_weather_conditions
  575.   end
  576.   #-----------------------------------------------------------------------------
  577.   # Sort Active Phases
  578.   #-----------------------------------------------------------------------------
  579.   alias :tps_weather_sap_e222                 :sort_active_phases
  580.   #-----------------------------------------------------------------------------
  581.   def sort_active_phases
  582.     tps_weather_sap_e222
  583.     make_weather_conditions
  584.   end
  585.   #-----------------------------------------------------------------------------
  586.   # Make Weather Conditions
  587.   #-----------------------------------------------------------------------------
  588.   def make_weather_conditions
  589.     cond = TPS_PHASES::CONDITIONS
  590.     @weather_conditions = cond.select {|k, v| weather_condition?(k, v)}.keys
  591.     @weather_conditions.sort_by! {|k| cond[k][:priority]}
  592.   end
  593.   #-----------------------------------------------------------------------------
  594.   # Next Minute
  595.   #-----------------------------------------------------------------------------
  596.   alias :tps_weather_next_minute          :next_minute
  597.   #-----------------------------------------------------------------------------
  598.   def next_minute
  599.     tps_weather_next_minute
  600.     update_weather
  601.   end
  602.   #-----------------------------------------------------------------------------
  603.   # Next Day
  604.   #-----------------------------------------------------------------------------
  605.   alias :tps_weather_next_day             :next_day
  606.   #-----------------------------------------------------------------------------
  607.   def next_day
  608.     tps_weather_next_day
  609.     @current_rolls = 0 if max_rolls
  610.   end
  611.   #-----------------------------------------------------------------------------
  612.   # Update Weather
  613.   #-----------------------------------------------------------------------------  
  614.   def update_weather
  615.     return unless can_roll?
  616.     @weather_duration > 0 ? @weather_duration -= 1 : roll_weather
  617.   end
  618.   #-----------------------------------------------------------------------------
  619.   # Roll Weather
  620.   #-----------------------------------------------------------------------------
  621.   def roll_weather
  622.     weathers = []
  623.     TPS_PHASES::CONDITIONS[weather_phase][:weathers].each do |weather, chance|
  624.       chance.times { weathers.push(weather) }
  625.     end
  626.     @current_abs_weather = weathers.shuffle.last
  627.     @current_weather = TPS_PHASES::WEATHERS[@current_abs_weather].first
  628.     @weather_duration = weather_duration
  629.     @weather_strength = weather_strength
  630.     @current_rolls += 1
  631.     set_weather
  632.   end
  633.   #-----------------------------------------------------------------------------
  634.   # Set Weather
  635.   #-----------------------------------------------------------------------------
  636.   def set_weather(dur = 60)
  637.     if $game_map.indoor?
  638.       clear_weather
  639.     else
  640.       change_weather(dur)
  641.     end
  642.     start_bgs
  643.   end
  644.   #-----------------------------------------------------------------------------
  645.   # Change Weather
  646.   #-----------------------------------------------------------------------------
  647.   def change_weather(dur)
  648.     $game_map.screen.change_weather(@current_weather, @weather_strength, dur)
  649.   end
  650.   #-----------------------------------------------------------------------------
  651.   # Clear Weather
  652.   #-----------------------------------------------------------------------------
  653.   def clear_weather
  654.     @current_abs_weather = :no_weather
  655.     @weather_duration = 0
  656.     @current_weather = :none
  657.     $game_map.screen.change_weather(:none, 0, 0)
  658.   end
  659.   #-----------------------------------------------------------------------------
  660.   # Start BGS
  661.   #-----------------------------------------------------------------------------
  662.   def start_bgs
  663.     audio = if !$game_map.indoor?
  664.               TPS_PHASES::WEATHERS[@current_abs_weather][4]
  665.             else
  666.               TPS_PHASES::WEATHERS[@current_abs_weather][5]
  667.             end
  668.     return Audio.bgs_stop unless audio
  669.     Audio.bgs_play('Audio/BGS/' + audio[0], audio[1], audio[2])
  670.   end
  671.   #-----------------------------------------------------------------------------
  672.   # Maximum Rolls
  673.   #-----------------------------------------------------------------------------
  674.   def max_rolls
  675.     return TPS_PHASES::MAXIMUM_WEATHER_PER_DAY
  676.   end
  677.   #-----------------------------------------------------------------------------
  678.   # Can Roll ?
  679.   #-----------------------------------------------------------------------------
  680.   def can_roll?
  681.     return true unless max_rolls
  682.     return @current_rolls < max_rolls
  683.   end
  684.   #-----------------------------------------------------------------------------
  685.   # Weather Phase
  686.   #-----------------------------------------------------------------------------
  687.   def weather_phase
  688.     @weather_conditions.last
  689.   end
  690.   #-----------------------------------------------------------------------------
  691.   # Current Weather
  692.   #-----------------------------------------------------------------------------
  693.   def current_weather
  694.     return @current_weather
  695.   end
  696.   #-----------------------------------------------------------------------------
  697.   # Current Abstract Weather
  698.   #-----------------------------------------------------------------------------
  699.   def current_abs_weather
  700.     return @current_abs_weather
  701.   end
  702.   #-----------------------------------------------------------------------------
  703.   # Weather Duration
  704.   #-----------------------------------------------------------------------------
  705.   def weather_duration
  706.     min = TPS_PHASES::WEATHERS[@current_abs_weather][2]
  707.     max = TPS_PHASES::WEATHERS[@current_abs_weather][3]
  708.     return (rand(max-min) + min)
  709.   end
  710.   #-----------------------------------------------------------------------------
  711.   # Weather Strength
  712.   #-----------------------------------------------------------------------------
  713.   def weather_strength
  714.     return TPS_PHASES::WEATHERS[@current_abs_weather][1]
  715.   end
  716.   #-----------------------------------------------------------------------------
  717.   # Weather Condition?
  718.   #-----------------------------------------------------------------------------
  719.   def weather_condition?(key, value)
  720.     value[:weathers] && phase_active?(key)
  721.   end
  722.   #-----------------------------------------------------------------------------
  723.   # Set Time
  724.   #-----------------------------------------------------------------------------
  725.   alias :tps_weather_set_time        :set_time
  726.   #-----------------------------------------------------------------------------
  727.   def set_time(time)
  728.     tps_weather_set_time(time)
  729.     refresh_conditions
  730.     roll_weather
  731.     initialize_period if $imported[:e222_tps_tints]
  732.   end
  733.   #-----------------------------------------------------------------------------
  734.   # Change Time
  735.   #-----------------------------------------------------------------------------
  736.   alias :tps_weather_change_time        :change_time
  737.   #-----------------------------------------------------------------------------
  738.   def change_time(amount)
  739.     tps_weather_change_time(amount)
  740.     refresh_conditions
  741.     roll_weather
  742.     initialize_period if $imported[:e222_tps_tints]
  743.   end
  744.   #-----------------------------------------------------------------------------
  745.   # Change Time
  746.   #-----------------------------------------------------------------------------
  747.   alias :tps_weather_change_day        :change_day
  748.   #-----------------------------------------------------------------------------
  749.   def change_day(amount)
  750.     tps_weather_change_day(amount)
  751.     refresh_conditions
  752.     roll_weather
  753.     initialize_period if $imported[:e222_tps_tints]
  754.   end
  755.   #-----------------------------------------------------------------------------
  756.   # Change Time
  757.   #-----------------------------------------------------------------------------
  758.   alias :tps_weather_change_month        :change_month
  759.   #-----------------------------------------------------------------------------
  760.   def change_month(amount)
  761.     tps_weather_change_month(amount)
  762.     refresh_conditions
  763.     roll_weather
  764.     initialize_period if $imported[:e222_tps_tints]
  765.   end
  766.   #-----------------------------------------------------------------------------
  767.   # Change Year
  768.   #-----------------------------------------------------------------------------
  769.   alias :tps_weather_change_year        :change_year
  770.   #-----------------------------------------------------------------------------
  771.   def change_year(amount)
  772.     tps_weather_change_year(amount)
  773.     refresh_conditions
  774.     roll_weather
  775.     initialize_period if $imported[:e222_tps_tints]
  776.   end
  777.   #-----------------------------------------------------------------------------
  778. end
  779. #===============================================================================
  780. # Spriteset Battle:
  781. #===============================================================================
  782. class Spriteset_Battle
  783.   #-----------------------------------------------------------------------------
  784.   # In create_timer gepackt, da es die letzte methode vor dem Update ist
  785.   #-----------------------------------------------------------------------------
  786.   alias :tps_weather_create_timer_e222      :create_timer
  787.   #-----------------------------------------------------------------------------
  788.   def create_timer
  789.     tps_weather_create_timer_e222
  790.     return unless TPS_PHASES::USE_WEATHER_IN_BATTLE
  791.     create_weather
  792.   end
  793.   #-----------------------------------------------------------------------------
  794.   # Create Weather
  795.   #-----------------------------------------------------------------------------
  796.   def create_weather
  797.     @weather = Spriteset_Weather.new(@viewport3)
  798.   end
  799.   #-----------------------------------------------------------------------------
  800.   # Update
  801.   #-----------------------------------------------------------------------------
  802.   alias :tps_weather_update_e222          :update
  803.   #-----------------------------------------------------------------------------
  804.   def update
  805.     tps_weather_update_e222
  806.     update_weather if @weather
  807.   end
  808.   #-----------------------------------------------------------------------------
  809.   # Update Weather
  810.   #-----------------------------------------------------------------------------
  811.   def update_weather
  812.     @weather.type = $game_map.screen.weather_type
  813.     @weather.power = $game_map.screen.weather_power
  814.     @weather.ox = $game_map.display_x * 32
  815.     @weather.oy = $game_map.display_y * 32
  816.     @weather.update
  817.   end
  818.   #-----------------------------------------------------------------------------
  819.   # Dispose
  820.   #-----------------------------------------------------------------------------
  821.   alias :tps_weather_dispose_e222         :dispose
  822.   def dispose
  823.     @weather.dispose if @weather
  824.     tps_weather_dispose_e222
  825.   end
  826. end
  827. #===============================================================================
  828. # Scene Map:
  829. #===============================================================================
  830. class Scene_Map
  831.   #-----------------------------------------------------------------------------
  832.   # Post Transfer
  833.   #-----------------------------------------------------------------------------
  834.   alias :tps_weather_post_transfer_e222       :post_transfer
  835.   #-----------------------------------------------------------------------------
  836.   def post_transfer
  837.     $game_time.set_weather(0)
  838.     tps_weather_post_transfer_e222
  839.   end
  840.   #-----------------------------------------------------------------------------
  841. end
  842. #===============================================================================
  843. # SCRIPT END
  844. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment