TheoAllen

AMA - Weather System

Apr 12th, 2013
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.56 KB | None | 0 0
  1. # =============================================================================
  2. # ALUMNEA MAGIC ACADEMY - WEATHER SYSTEM ~
  3. # REQUIRE : AMA - Day Nite System
  4. # AUTHOR : TheoAllen
  5. # =============================================================================
  6. =begin
  7.  
  8.   Script ini ngebikin weather terjadi secara random.
  9.  
  10.   Note :
  11.   Segala hal soal kompatibilitas, error, kerusakan edit, dan semacamnya
  12.   ditanggung oleh pencomot script.
  13.  
  14. =end
  15. # =============================================================================
  16. # ♫ Module AMA ~ ♫
  17. # =============================================================================
  18. module AMA
  19.   module WEATHER
  20.   # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  21.   # DEFAULT_CHANCE  >> [1,24] kemungkinan hujan per jam adalah 1/24
  22.   # WET_STATUS_ID   >> Status ID yg bakal di-add kalo ujan
  23.   # RANGE_MAX       >> Maksimal ujannya berapa jam lamanya
  24.   # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  25.  
  26.     DEFAULT_CHANCE  = [1,24]
  27.     WET_STATUS_ID   = 4
  28.     RANGE_MAX       = 24
  29.    
  30.   # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  31.   # Panggil dalam script call :
  32.   # - AMA::WEATHER.chance(chance,dice)  >> ganti kemungkinan
  33.   # - AMA::WEATHER.range_max(max)       >> ganti maksimal ujannya
  34.   # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  35.   # Setelah line ini kalo ada kerusakan edit tanggung sendiri :v
  36.   # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  37.     def self.chance(chance = 1,dice = 10)
  38.       $game_system.weather_chance = chance
  39.       $game_system.weather_dice = dice
  40.     end
  41.    
  42.     def self.range_max(max = 24)
  43.       $game_system.weather_range_max(max)
  44.     end
  45.    
  46.   end
  47. end
  48. # =============================================================================
  49. # ♫ Game System ~ ♫
  50. # =============================================================================
  51. class Game_System
  52.   attr_accessor :weather
  53.   attr_accessor :weather_start
  54.   attr_accessor :weather_chance
  55.   attr_accessor :weather_range_max
  56.   attr_accessor :weather_dice
  57.   attr_reader :weather_range
  58.   #--------------------------------------------------------------------------
  59.   # ♫ Inisialisasi
  60.   #--------------------------------------------------------------------------    
  61.   alias ama_weather_init initialize
  62.   def initialize
  63.     ama_weather_init
  64.     @weather = :none
  65.     @weather_range = 0
  66.     @weather_start = 0
  67.     @weather_chance = AMA::WEATHER::DEFAULT_CHANCE[0]
  68.     @weather_dice = AMA::WEATHER::DEFAULT_CHANCE[1]
  69.     @weather_range_max = AMA::WEATHER::RANGE_MAX
  70.   end
  71.   #--------------------------------------------------------------------------
  72.   # ♫ Ngebersihin cuaca
  73.   #--------------------------------------------------------------------------
  74.   def clear_weather
  75.     @weather = :none
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # ♫ Ngecek cuaca per jam
  79.   #--------------------------------------------------------------------------
  80.   alias ama_weather_update update_hour
  81.   def update_hour
  82.     ama_weather_update
  83.     chance = (rand * weather_dice).round
  84.     if chance <= weather_chance
  85.       update_weather unless weather_selected?
  86.     end
  87.   end
  88.   #--------------------------------------------------------------------------
  89.   # ♫ Ada ga cuacanya?
  90.   #--------------------------------------------------------------------------
  91.   def weather_selected?
  92.     return self.weather != :none
  93.   end
  94.   #--------------------------------------------------------------------------
  95.   # ♫ Ngeupdate cuaca
  96.   #--------------------------------------------------------------------------
  97.   def update_weather
  98.     select_weather
  99.     determine_range
  100.   end
  101.   #--------------------------------------------------------------------------
  102.   # ♫ Milih cuaca
  103.   #--------------------------------------------------------------------------
  104.   def select_weather
  105.     weather = rand.round
  106.     if weather == 1
  107.       @weather = :rain
  108.     else
  109.       @weather = :storm
  110.     end
  111.   end
  112.   #--------------------------------------------------------------------------
  113.   # ♫ Nentuin berapa lamanya
  114.   #--------------------------------------------------------------------------
  115.   def determine_range
  116.     @weather_range = (rand * weather_range_max).round
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   # ♫ Nentuin kuat ngganya
  120.   #--------------------------------------------------------------------------
  121.   def weather_power
  122.     return (rand * 9).round
  123.   end
  124.  
  125. end
  126. # =============================================================================
  127. # ♫ Scene Map ~ ♫
  128. # =============================================================================
  129. class Scene_Map < Scene_Base
  130.   #--------------------------------------------------------------------------
  131.   # ♫ Nyisipin update cuaca di update per frame
  132.   #--------------------------------------------------------------------------
  133.   alias ama_weather_update update
  134.   def update
  135.     ama_weather_update
  136.     update_weather
  137.   end
  138.   #--------------------------------------------------------------------------
  139.   # ♫ Ngambil game system
  140.   #--------------------------------------------------------------------------
  141.   def system
  142.     $game_system
  143.   end
  144.   #--------------------------------------------------------------------------
  145.   # ♫ Ngambil game party
  146.   #--------------------------------------------------------------------------
  147.   def party
  148.     $game_party
  149.   end
  150.   #--------------------------------------------------------------------------
  151.   # ♫ Update cuaca di map
  152.   #--------------------------------------------------------------------------
  153.   def update_weather
  154.     if interior?
  155.       screen.change_weather(:none,0,0) if screen.weather_type != :none
  156.       return
  157.     end
  158.     apply_weather unless weather_set?
  159.     update_weather_status
  160.     clear_weather if weather_expired?
  161.   end
  162.   #--------------------------------------------------------------------------
  163.   # ♫ Bersihin cuaca di map
  164.   #--------------------------------------------------------------------------
  165.   def clear_weather
  166.     screen.clear_weather
  167.     system.clear_weather
  168.     Audio.bgs_fade(Graphics.frame_rate)
  169.   end
  170.   #--------------------------------------------------------------------------
  171.   # ♫ Pasang cuaca di map
  172.   #--------------------------------------------------------------------------
  173.   def apply_weather
  174.     return unless system.weather_selected?
  175.     weather = system.weather
  176.     power = system.weather_power
  177.     system.weather_start = system.dns_hours + system.weather_range
  178.     case weather
  179.       when :rain
  180.         Audio.bgs_play("Audio/BGS/Rain",power*10)
  181.       when :storm
  182.         Audio.bgs_play("Audio/BGS/Storm",power*10)
  183.       end
  184.     screen.change_weather(weather,power,60)
  185.   end
  186.   #--------------------------------------------------------------------------
  187.   # ♫ Update status berdasar cuaca
  188.   #--------------------------------------------------------------------------
  189.   def update_weather_status
  190.     if weather_set?
  191.       apply_weather_status
  192.       return
  193.     end
  194.     clear_weather_status
  195.   end
  196.   #--------------------------------------------------------------------------
  197.   # ♫ Pasang status
  198.   #--------------------------------------------------------------------------
  199.   def apply_weather_status
  200.     party.all_members.each do |actor|
  201.       actor.add_state(AMA::WEATHER::WET_STATUS_ID)
  202.     end
  203.   end
  204.   #--------------------------------------------------------------------------
  205.   # ♫ Ilangin status
  206.   #--------------------------------------------------------------------------
  207.   def clear_weather_status
  208.     party.all_members.each do |actor|
  209.       actor.remove_state(AMA::WEATHER::WET_STATUS_ID)
  210.     end
  211.   end
  212.   #--------------------------------------------------------------------------
  213.   # ♫ Ngecek dah beres belom ujannya?
  214.   #--------------------------------------------------------------------------
  215.   def weather_expired?
  216.     return system.weather_start <= system.dns_hours
  217.   end
  218.   #--------------------------------------------------------------------------
  219.   # ♫ Cuacanya ada g di map?
  220.   #--------------------------------------------------------------------------
  221.   def weather_set?
  222.     screen.weather_type != :none
  223.   end
  224. end
  225. # =============================================================================
  226. #
  227. #                           ♫  End of Script ♫
  228. #
  229. # =============================================================================
Advertisement
Add Comment
Please, Sign In to add comment