IceDragon200

ILFX-Env Edition

Jul 10th, 2011
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 18.89 KB | None | 0 0
  1. #==============================================================================#
  2. # ** ILFX - Icy Light Effects ~ ENV Version
  3. #------------------------------------------------------------------------------#
  4. # ** Created by : IceDragon
  5. # ** Script-Status : Addon (ENV)
  6. # ** Date Created : 8/25/2010
  7. # ** Date Modified : 10/14/2010
  8. # ** Version : 1.0
  9. #------------------------------------------------------------------------------#
  10. # This is a fully custom light effects.
  11. # Credit goes to Kylock and BulletX for there light effects scripts.
  12. # Without them I wouldn't be able to write this.
  13. #------------------------------------------------------------------------------#
  14. $imported = {} if $imported == nil
  15. if $imported["IEX_Environment"]
  16.   $ilfx_light_on = IEX::ENVIRONMENT::LIGHT_SYSTEM
  17. else
  18.   $ilfx_light_on = true
  19. end
  20.  
  21. if $ilfx_light_on
  22. $imported["ICY_LightFX"] = true
  23.  
  24. module ICY
  25.   module ILFX
  26.     DEFAULT_IMAGE = "le.png" # Default Image used as light, located in Picture Folder
  27.    
  28.     # This is were you define all the light effects.
  29.     # It follows a basic setting
  30.     # "Name of Light Effect" => {
  31.     #                            :zoom_x => width zoom for light,
  32.     #                            :zoom_y => height zoom for light,
  33.     #                            :opacity => 0 - 255 Opacity of light,
  34.     #                            :tone => Tone used on light. (Use 'Tone.new(0, 0, 0, 255)' as default)
  35.     #                            :blend_type => 0 for normal, 1 for additive, 2 for subtractive
  36.     #                            :flicker_type => Currently there are only 3 types of flickers
  37.     #                                             SML_FLICK, MED_FLICK and LRG_FLICK
  38.     #                            :custom_image => Custom Image used instead of default (Set to nil if you want it to use the default)
  39.     #                           }
  40.     LIGHT_EFFECTS = { # Don't touch this
  41.         "FIRE" => {
  42.               :zoom_x  => 300 / 100.0, # 3
  43.               :zoom_y  => 300 / 100.0, # 3
  44.               :opacity => 100,
  45.               :type => "FIRE",
  46.               :tone  => Tone.new(255,-100,-255, 0),
  47.               :blend_type => 1,
  48.               :flicker_type => "SML_FLICK",
  49.               :custom_image => nil,
  50.               } , # Next Effect
  51.         "LIGHT" => {
  52.               :zoom_x  => 1,
  53.               :zoom_y  => 1,
  54.               :opacity => 150,
  55.               :type => "LIGHT",
  56.               :tone  => Tone.new(0,0,0,0),
  57.               :blend_type => 1,
  58.               :flicker_type => "SML_FLICK",
  59.               :custom_image => nil,
  60.               } , # Next Effect
  61.         "LIGHT2" => {
  62.               :zoom_x  => 6,
  63.               :zoom_y  => 6,
  64.               :opacity => 150,
  65.               :type => "LIGHT",
  66.               :tone  => Tone.new(0,0,0,0),
  67.               :blend_type => 1,
  68.               :flicker_type => "SML_FLICK",
  69.               :custom_image => nil,
  70.               } , # Next Effect  
  71.         "LIGHT3" => {
  72.               :zoom_x  => 1,
  73.               :zoom_y  => 1,
  74.               :opacity => 150,
  75.               :type => "LIGHT",
  76.               :tone  => Tone.new(0,0,0,0),
  77.               :blend_type => 1,
  78.               :flicker_type => "MED_FLICK",
  79.               :custom_image => nil,
  80.               } , # Next Effect
  81.         "TORCH" => {
  82.               :zoom_x  => 6,
  83.               :zoom_y  => 6,
  84.               :opacity => 150,
  85.               :type => "TORCH",
  86.               :tone  => Tone.new(255,-100,-255, 0),
  87.               :blend_type => 1,
  88.               :flicker_type => "LRG_FLICK",
  89.               :custom_image => nil,
  90.               } , # Next Effect  
  91.         "TORCH2" => {
  92.               :zoom_x  => 6,
  93.               :zoom_y  => 6,
  94.               :opacity => 150,
  95.               :type => "TORCH",
  96.               :tone  => Tone.new(255,-100,-255, 0),
  97.               :blend_type => 1,
  98.               :flicker_type => "MED_FLICK",
  99.               :custom_image => nil,
  100.               } , # Next Effect
  101.         "TORCH3" => {
  102.               :zoom_x  => 300 / 100.0,
  103.               :zoom_y  => 300 / 100.0,
  104.               :opacity => 100,
  105.               :type => "TORCH",
  106.               :tone  => Tone.new(0,0,0,0),
  107.               :blend_type => 1,
  108.               :flicker_type => "MED_FLICK",
  109.               :custom_image => nil,
  110.               } , # Next Effect  
  111.         "GROUND" => {
  112.               :zoom_x  => 2,
  113.               :zoom_y  => 2,
  114.               :opacity => 100,
  115.               :type => "GROUND",
  116.               :tone  => Tone.new(0,0,0,0),
  117.               :blend_type => 1,
  118.               :flicker_type => "MED_FLICK",
  119.               :custom_image => nil,
  120.               } , # Next Effect
  121.         "GROUND2" => {
  122.               :zoom_x  => 2,
  123.               :zoom_y  => 2,
  124.               :opacity => 100,
  125.               :type => "GROUND",
  126.               :tone  => Tone.new(0,0,0,0),
  127.               :blend_type => 1,
  128.               :flicker_type => "MED_FLICK",
  129.               :custom_image => nil,
  130.               } , # Next Effect
  131.         "GROUND3" => {
  132.               :zoom_x  => 2,
  133.               :zoom_y  => 2,
  134.               :opacity => 100,
  135.               :type => "GROUND",
  136.               :tone  => Tone.new(255,-255,-255, 255),
  137.               :blend_type => 1,
  138.               :flicker_type => "SML_FLICK",
  139.               :custom_image => nil,
  140.               } , # Next Effect
  141.         "GROUND4" => {
  142.               :zoom_x  => 2,
  143.               :zoom_y  => 2,
  144.               :opacity => 100,
  145.               :type => "GROUND",
  146.               :tone  => Tone.new(-255,255,-255, 100),
  147.               :blend_type => 1,
  148.               :flicker_type => "MED_FLICK",
  149.               :custom_image => nil,
  150.               } , # Next Effect
  151.         "GROUND5" => {
  152.               :zoom_x  => 2,
  153.               :zoom_y  => 2,
  154.               :opacity => 100,
  155.               :type => "GROUND",
  156.               :tone  => Tone.new(-255,255,255, 100),
  157.               :blend_type => 1,
  158.               :flicker_type => "MED_FLICK",
  159.               :custom_image => nil,
  160.               } , # Next Effect
  161.              
  162.               # Added effects
  163.         "GREENGLOW" => {
  164.               :zoom_x  => 2,
  165.               :zoom_y  => 2,
  166.               :opacity => 100,
  167.               :type => "FIRE",
  168.               :tone  => Tone.new(-100, 100,-255, 0),
  169.               :blend_type => 1,
  170.               :flicker_type => "MED_FLICK",
  171.               :custom_image => nil,
  172.               } , # Next Effect
  173.     }  
  174.    
  175.     LIGHT_TYPES_SWITCH = {
  176.             "FIRE" => 131,
  177.             "LIGHT" => 132,
  178.             "TORCH" => 133,
  179.             "GROUND" => 134}
  180.            
  181.     UPDATE_WAIT = 1 # Update only every x frames, higher rates reduce lag but causes light drag
  182.      
  183.     # This switch is tagged along with the $light_switch
  184.     # Even if you try to set this manually In-Game it will forcefully reset
  185.     # Therefore it is only to be used with Day - Night Events
  186.     # If you don't want to use this put 'nil' without quotes.
  187.     GLOBAL_LIGHT_SWITCH = 513
  188.    
  189.     # Should there be Time System Support
  190.     # Currently this will work with Jets Time System and ITS - Icy Time System
  191.     # Just set the corresponding swithces which follow
  192.     # If you set this to false, you can ignore the following stuff.
  193.     TIME_SYSTEM_SUPPORT = true
  194.     # The switch that will turn on when it is Dusk.
  195.     DUSK_SWITCH = 560
  196.     # The switch that will turn on when it is Night.
  197.     NIGHT_SWITCH = 557
  198.     # The switch that will turn on when it is Dawn.
  199.     DAWN_SWITCH = 558
  200.     # The switch that will turn on when it is Day.
  201.     DAY_SWITCH = 559    
  202.   end
  203. end
  204.  
  205. #------------------------------------------------------------------------------#
  206. # BRAKES!!! Where do you think your going!! No Touchie!!
  207. #------------------------------------------------------------------------------#
  208. module ICY
  209.   module REGEXP
  210.     module ILFX
  211.       LFX_OFF_X = /<(?:LFX_OFF_X|lfx off x)[ ]*(\d+)>/i
  212.       LFX_OFF_Y = /<(?:LFX_OFF_Y|lfx off y)[ ]*(\d+)>/i
  213.       LFX_OFF_Z = /<(?:LFX_OFF_Z|lfx off z)[ ]*(\d+)>/i
  214.       LFX_PRIO_LIGHT = /<(?:PRIO_LIGHT|prio light)>/i
  215.      
  216.       SML_FLICK = /(?:SML_FLICK|sml flick)/i
  217.       MED_FLICK = /(?:MED_FLICK|med flick)/i
  218.       LRG_FLICK = /(?:LRG_FLICK|lrg flick)/i
  219.      
  220.       OVERRIDE_MAIN = /<(?:OVERRIDE|ALWAYS_ON|always on)>/i
  221.     end
  222.   end
  223. end
  224.  
  225. #==============================================================================
  226. # ** Spriteset_Map
  227. #------------------------------------------------------------------------------
  228. #  This class brings together map screen sprites, tilemaps, etc. It's used
  229. # within the Scene_Map class.
  230. #==============================================================================
  231. class Spriteset_Map
  232.  
  233.   #--------------------------------------------------------------------------
  234.   # * Object Initialization
  235.   #--------------------------------------------------------------------------
  236.   alias ilfx_light_fx_initialize initialize unless $@
  237.   def initialize(*args)
  238.     @light_effects = []
  239.     ilfx_light_fx_initialize(*args)
  240.     @old_bool = nil
  241.     check_lighting_cond
  242.     initialize_lights
  243.   end
  244.  
  245.   #--------------------------------------------------------------------------
  246.   # * Dispose
  247.   #--------------------------------------------------------------------------
  248.   alias ilfx_light_fx_dispose dispose unless $@
  249.   def dispose(*args)
  250.     dispose_lights
  251.         ilfx_light_fx_dispose(*args)
  252.     end
  253.  
  254.   def dispose_lights
  255.     for effect in @light_effects
  256.             effect.dispose_light
  257.       effect = nil
  258.         end
  259.         @light_effects.clear
  260.     @light_effects = []
  261.     ensure @light_effects.empty?
  262.   end
  263.  
  264.   def check_lighting_cond
  265.     if ICY::ILFX::TIME_SYSTEM_SUPPORT
  266.       if $game_switches[ICY::ILFX::NIGHT_SWITCH]
  267.         bool = true
  268.         $game_map.need_refresh = true
  269.       elsif $game_switches[ICY::ILFX::DUSK_SWITCH]
  270.         bool = true
  271.         $game_map.need_refresh = true
  272.       elsif $game_switches[ICY::ILFX::DAWN_SWITCH]
  273.         bool = false
  274.         $game_map.need_refresh = true
  275.       elsif $game_switches[ICY::ILFX::DAY_SWITCH]
  276.         bool = false
  277.         $game_map.need_refresh = true
  278.       else
  279.         bool = true
  280.         $game_map.need_refresh = true
  281.       end
  282.     else
  283.        bool = true
  284.        $game_map.need_refresh = true
  285.      end
  286.     $light_switch = bool
  287.     if ICY::ILFX::GLOBAL_LIGHT_SWITCH != nil
  288.       $game_switches[ICY::ILFX::GLOBAL_LIGHT_SWITCH] = bool  
  289.     end
  290.     return if @old_bool == bool
  291.       dispose_lights
  292.       @old_bool = bool
  293.       initialize_lights
  294.    end
  295.        
  296.     def ilfx_off_x(event)
  297.       o_o = 0
  298.      if event.list == nil
  299.        o_o = 0
  300.      else
  301.        for i in 0...event.list.size
  302.          if event.list[i].code == 108
  303.            event.list[i].parameters.to_s.split(/[\r\n]+/).each { |line|
  304.            case line
  305.            when ICY::REGEXP::ILFX::LFX_OFF_X
  306.             o_o += $1.to_i
  307.            end }
  308.          end
  309.        end
  310.       end
  311.      return o_o
  312.    end
  313.    
  314.    def ilfx_off_y(event)
  315.       o_o = 0
  316.      if event.list == nil
  317.        o_o = 0
  318.      else
  319.        for i in 0...event.list.size
  320.          if event.list[i].code == 108
  321.            event.list[i].parameters.to_s.split(/[\r\n]+/).each { |line|
  322.            case line
  323.            when ICY::REGEXP::ILFX::LFX_OFF_Y
  324.             o_o += $1.to_i
  325.            end }
  326.          end
  327.        end
  328.       end
  329.      return o_o
  330.   end
  331.    
  332.   def ilfx_prio_z(event)
  333.       o_o = 0
  334.      if event.list == nil
  335.        o_o = 0
  336.      else
  337.        for i in 0...event.list.size
  338.          if event.list[i].code == 108
  339.            event.list[i].parameters.to_s.split(/[\r\n]+/).each { |line|
  340.            case line
  341.            when ICY::REGEXP::ILFX::LFX_OFF_Z
  342.             o_o += $1.to_i
  343.            when ICY::REGEXP::ILFX::LFX_PRIO_LIGHT
  344.             o_o += event.screen_z
  345.            end }
  346.          end
  347.        end
  348.       end
  349.      return o_o
  350.    end
  351.    
  352.    def ilfx_always_on(event)
  353.      if event.list == nil
  354.        return false
  355.      else
  356.        for i in 0...event.list.size
  357.          if event.list[i].code == 108
  358.            event.list[i].parameters.to_s.split(/[\r\n]+/).each { |line|
  359.            case line
  360.            when ICY::REGEXP::ILFX::OVERRIDE_MAIN
  361.             return true
  362.            end }
  363.          end
  364.        end
  365.       end
  366.      return false
  367.    end
  368.    
  369.     def initialize_lights
  370.     icy_lights_fx = ICY::ILFX::LIGHT_EFFECTS
  371.     return if @light_effects.empty? == false
  372.     for event in $game_map.events.values
  373.             next if event.list == nil
  374.                 for i in 0...event.list.size
  375.           for light in icy_lights_fx.keys
  376.             next if light == nil
  377.             if event.list[i].code == 108 and event.list[i].parameters == [light]
  378.               type = icy_lights_fx[light][:type]
  379.                           light_effects = Light_Effect.new(event, type, light)
  380.                           light_effects.light.zoom_x = icy_lights_fx[light][:zoom_x]
  381.                           light_effects.light.zoom_y = icy_lights_fx[light][:zoom_y]
  382.                           light_effects.light.opacity = icy_lights_fx[light][:opacity]
  383.               light_effects.movement = icy_lights_fx[light][:flicker_type]
  384.               light_effects.always_on = ilfx_always_on(event)
  385.                           @light_effects.push(light_effects)
  386.             end
  387.           end
  388.         end
  389.       end
  390.      
  391.     for effect in @light_effects
  392.       next if effect == nil
  393.         eve = effect.event
  394.         x_size = icy_lights_fx[effect.lname][:zoom_x] * 200
  395.         y_size = icy_lights_fx[effect.lname][:zoom_y] * 200
  396.         x_l = (eve.real_x - x_size - $game_map.display_x) / 8
  397.         y_l = (eve.real_y - y_size - $game_map.display_y) / 8
  398.         x_o = ilfx_off_x(effect.event)
  399.         y_o = ilfx_off_y(effect.event)
  400.         effect.light.x = x_l + x_o
  401.         effect.light.y = y_l + y_o
  402.         effect.light.tone = icy_lights_fx[effect.lname][:tone]
  403.               effect.light.blend_type = icy_lights_fx[effect.lname][:blend_type]
  404.         if ICY::REGEXP::ILFX::SML_FLICK =~ effect.movement
  405.          effect.flick_type = 1
  406.          elsif ICY::REGEXP::ILFX::MED_FLICK =~ effect.movement
  407.          effect.flick_type = 2
  408.          elsif ICY::REGEXP::ILFX::LRG_FLICK =~ effect.movement
  409.          effect.flick_type = 3
  410.          else
  411.          effect.flick_type = 0
  412.         end
  413.          z_set = ilfx_prio_z(effect.event)
  414.          if z_set != 0 or z_set != nil
  415.            effect.light.z = z_set
  416.          else
  417.            effect.light.z = 400
  418.          end
  419.          effect.update
  420.       end  
  421.     end # End initialize_lights
  422.    
  423.   def ilfx_flicker(zoom_x, zoom_y, opacity, type, light)
  424.       avg = (zoom_x + zoom_y) / 2
  425.       x_f = 0
  426.       y_f = 0
  427.       op_f = ICY::ILFX::LIGHT_EFFECTS[light][:opacity]
  428.       case type.to_s
  429.       when ICY::REGEXP::ILFX::SML_FLICK # SML_FLICK
  430.         val  = avg / 30
  431.         x_f  = rand(val)
  432.         y_f  = rand(val)
  433.         op_f = ICY::ILFX::LIGHT_EFFECTS[light][:opacity] - rand(10)
  434.       when ICY::REGEXP::ILFX::MED_FLICK # MED_FLICK
  435.         val  = avg / 20
  436.         x_f  = rand(val)
  437.         y_f  = rand(val)
  438.         op_f = ICY::ILFX::LIGHT_EFFECTS[light][:opacity] - rand(18)
  439.       when ICY::REGEXP::ILFX::LRG_FLICK # LRG_FLICK
  440.         val  = avg / 10
  441.         x_f  = rand(val)
  442.         y_f  = rand(val)
  443.         op_f = ICY::ILFX::LIGHT_EFFECTS[light][:opacity] - rand(23)
  444.       else
  445.         x_f  = 0
  446.         y_f  = 0
  447.         op_f = ICY::ILFX::LIGHT_EFFECTS[light][:opacity]
  448.       end
  449.       return [x_f, y_f, op_f]
  450.     end
  451.    
  452.   #--------------------------------------------------------------------------
  453.   # * Frame Update
  454.   #--------------------------------------------------------------------------  
  455.   alias ilfx_light_fx_update update unless $@
  456.   def update
  457.     ilfx_light_fx_update
  458.     check_lighting_cond
  459.     update_light_effects
  460.     update_all_light_types
  461.   end
  462.    
  463.    def update_light_effects
  464.      icy_lights_fx = ICY::ILFX::LIGHT_EFFECTS
  465.      for effect in @light_effects
  466.        next if effect == nil
  467.        if effect.always_on
  468.          effect.light.visible = true
  469.        else
  470.          effect.light.visible = $light_switch
  471.        end
  472.        next if effect.light.visible == false
  473.         effect.up_wait
  474.        next if effect.want_update? == false
  475.        
  476.        lname = effect.lname
  477.        zoom_x = icy_lights_fx[lname][:zoom_x]
  478.        zoom_y = icy_lights_fx[lname][:zoom_y]
  479.        opacity = icy_lights_fx[lname][:opacity]
  480.        flick_type = icy_lights_fx[lname][:flicker_type]
  481.        
  482.        fx_arra = []
  483.        fx_arra = ilfx_flicker(zoom_x, zoom_y, opacity, flick_type, lname)
  484.         eve = effect.event
  485.         x_size = icy_lights_fx[effect.lname][:zoom_x] * 200
  486.         y_size = icy_lights_fx[effect.lname][:zoom_y] * 200
  487.          if icy_lights_fx[effect.lname][:zoom_x] == 1
  488.            x_l = (-0.25 / 2 * $game_map.display_x) + (effect.event.x * 32) - 15
  489.          else
  490.            x_l = (eve.real_x - x_size - $game_map.display_x) / 8
  491.          end
  492.          if icy_lights_fx[effect.lname][:zoom_y] == 1
  493.                  y_l = (-0.25 / 2 * $game_map.display_y) + (effect.event.y * 32) - 15
  494.          else
  495.            y_l = (eve.real_y - y_size - $game_map.display_y) / 8
  496.          end
  497.         x_o = ilfx_off_x(effect.event)
  498.         y_o = ilfx_off_y(effect.event)
  499.         effect.light.x = x_l + x_o - fx_arra[0]
  500.         effect.light.y = y_l + y_o - fx_arra[1]
  501.         effect.light.opacity = fx_arra[2]
  502.         effect.update
  503.      end
  504.      
  505.    end
  506.  
  507.    def update_all_light_types
  508.      for ltype in ICY::ILFX::LIGHT_TYPES_SWITCH.keys
  509.        next if ltype == nil
  510.        for effect in @light_effects
  511.          next if effect == nil
  512.          if effect.type == ltype and $game_switches[ICY::ILFX::LIGHT_TYPES_SWITCH[ltype]]
  513.            effect.light.visible = false
  514.          elsif $light_switch and $game_switches[ICY::ILFX::LIGHT_TYPES_SWITCH[ltype]] == false
  515.            effect.light.visible = true
  516.          end
  517.        end
  518.      end
  519.    end
  520.    
  521. end
  522.  
  523. class Light_Effect
  524.     attr_accessor :light
  525.     attr_accessor :event
  526.     attr_accessor :type
  527.     attr_accessor :lname
  528.   attr_accessor :movement
  529.   attr_accessor :selfwait
  530.   attr_accessor :flick_type
  531.   attr_accessor :always_on
  532.  
  533.     def initialize(event, type, lname)
  534.         @light = Sprite.new
  535.     if ICY::ILFX::LIGHT_EFFECTS[lname].has_key?(:custom_image)
  536.       if ICY::ILFX::LIGHT_EFFECTS[lname][:custom_image] != nil
  537.             @light.bitmap = Cache.picture(ICY::ILFX::LIGHT_EFFECTS[lname][:custom_image])
  538.       else
  539.         @light.bitmap = Cache.picture(ICY::ILFX::DEFAULT_IMAGE)
  540.       end
  541.     else
  542.       @light.bitmap = Cache.picture(ICY::ILFX::DEFAULT_IMAGE)
  543.     end
  544.         @light.visible = true
  545.         @event = event
  546.         @type = type
  547.     @lname = lname
  548.     @selfwait = 0
  549.     @always_on = false
  550.     end
  551.  
  552.   def dispose_light
  553.     if @light != nil
  554.       @light.visible = false
  555.       @light.dispose
  556.       @light = nil
  557.     end
  558.   end
  559.  
  560.   def update
  561.     return if @light == nil
  562.     @light.update
  563.   end
  564.  
  565.   def want_update?
  566.     return true if @selfwait == ICY::ILFX::UPDATE_WAIT
  567.     return false
  568.   end
  569.  
  570.   def up_wait
  571.     @selfwait = (@selfwait + 1) % (ICY::ILFX::UPDATE_WAIT + 1)
  572.   end
  573.  
  574. end
  575.  
  576. end
Advertisement
Add Comment
Please, Sign In to add comment