Advertisement
luiscesjr

Phases and Weather

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