Light effect script (Ace)

download Light effect script (Ace)

of 21

Transcript of Light effect script (Ace)

  • 7/27/2019 Light effect script (Ace)

    1/21

    #==============================================================================# ** Victor Engine - Light Effects#------------------------------------------------------------------------------# Author : Victor Sant## Version History:# v 1.00 - 2011.12.21 > First release# v 1.01 - 2011.12.23 > Compatibility with Diagonal Movement# v 1.02 - 2011.12.24 > Better checks for images bigger than screen# v 1.03 - 2011.12.27 > Fixed bug when teleporting to same map# v 1.04 - 2011.12.30 > Faster Regular Expressions# v 1.05 - 2012.01.04 > Fixed lantern direction bug# > Fixed load fail when lights ON# v 1.06 - 2012.01.07 > Fixed light opacity change not updating# v 1.07 - 2012.01.13 > Fixed update delay when exiting the menu# v 1.08 - 2012.01.15 > Fixed the positive sign on some Regular Expressions# > Fixed the Regular Expressions problem with "" and # v 1.09 - 2012.05.21 > Compatibility with Map Turn Battle# v 1.10 - 2012.07.24 > Compatibility with Moving Platform# > Changed actor indexing for lantern (now start at 1)# v 1.11 - 2012.08.02 > Compatibility with Basic Module 1.27# v 1.12 - 2013.01.07 > Fixed issue with actor lantern and map transfer#------------------------------------------------------------------------------# This scripts allow to add varied light effects to the maps. But it works

    # different from other scripts with this function.# Normally, light effect scripts add images above the events, and then the# screen is tone is changed, with the images staying bellow the darker layer.# This script add an new darkened layer, and apply the light effect images# on this layer.#------------------------------------------------------------------------------# Compatibility# Requires the script 'Victor Engine - Basic Module' v 1.27 or higher## * Alias methods# class Game_Map# def setup(map_id)#

    # class Game_CharacterBase# def init_public_members# def update## class Game_Event < Game_Character# def clear_starting_flag## class Spriteset_Map# def initialize# def update# def dispose## class Scene_Map

    # def pre_transfer## class Game_Interpreter# def comment_call##------------------------------------------------------------------------------# Instructions:# To instal the script, open you script editor and paste this script on# a new section bellow the Materials section. This script must also# be bellow the script 'Victor Engine - Basic'

  • 7/27/2019 Light effect script (Ace)

    2/21

    # The lights must be placed on the folder "Graphics/Lights". Create a folder# named "Lights" on the Graphics folder.##------------------------------------------------------------------------------# Comment calls note tags:# Tags to be used in events comment box, works like a script call.## # setting# # Create a shade effect on the map, add the following values to the setting.# opacity: x : opacity (0-255)# red: x : red tone (0-255, can be negative)# green: x : green tone (0-255, can be negative)# blue: x : blue tone (0-255, can be negative)# blend: x : fog blend type (0: normal, 1: add, 2: subtract)## # setting setting setting# # Create a light effect on actor, event or vehicle, add the following# values to the info. The ID, index and name must be added, other values# are optional.# id: x : ligh effect ID

    # name: "x" : ligh effect graphic filename ("filename")# index: x : actor index, event id or (0: boat, 1: ship, 2: airship)# opacity: x : light opacity (0-255)# pos x: x : coordinate X adjust# pos y: x : coordinate Y adjust# var: x : light opacity variation# speed: x : light variation speed# zoom: x : ligh effect zoom (100 = default size)## # setting# # Create a light effect on a specific map postion, add the following

    # values to the info. The ID, map_x, map_y and name must be added, other# values are optional.# id: x : ligh effect ID# name: "x" : ligh effect graphic filename ("filename")# map x: x : map X coordinate# map y: x : map Y coordinate# opacity: x : light opacity (0-255)# pos x: x : coordinate X adjust# pos y: x : coordinate Y adjust# var: x : light opacity variation# speed: x : light variation speed# zoom: x : ligh effect zoom (100 = default size)#

    # # # # Call a lantern on the target character, lanterns are effets that# lights the front of the character# i : actor index, event id or (0: boat, 1: ship, 2: airship)# o : light opacity (0-255)## # This tag allows to change the light opacity gradually

  • 7/27/2019 Light effect script (Ace)

    3/21

    # i : light effect ID# o : new opacity (0-255)# d : wait until complete change (60 frames = 1 second)## # This tag allows to change the shade opacity gradually# o : new opacity (0-255)# d : wait until complete change (60 frames = 1 second)## # This tag allows to change the shade opacity gradually# r : red tone (0-255, can be negative)# g : green tone (0-255, can be negative)# b : blue tone (0-255, can be negative)# d : wait until complete change (60 frames = 1 second)## # This tag allows remove a light effect# id: ligh effect ID##------------------------------------------------------------------------------# Maps note tags:# Tags to be used on the Maps note box in the database#

    # # setting# # Create a shade effect on the map, add the following values to the setting.# opacity: x : opacity (0-255)# red: x : red tone (0-255, can be negative)# green: x : green tone (0-255, can be negative)# blue: x : blue tone (0-255, can be negative)# blend: x : fog blend type (0: normal, 1: add, 2: subtract)## # setting setting setting#

    # Create a light effect on actor, event or vehicle, add the following# values to the info. The ID, index and name must be added, other values# are optional.# id: x : ligh effect ID# name: "x" : ligh effect graphic filename ("filename")# index: x : actor index, event id or (0: boat, 1: ship, 2: airship)# opacity: x : light opacity (0-255)# pos x: x : coordinate X adjust# pos y: x : coordinate Y adjust# var: x : light opacity variation# speed: x : light variation speed# zoom: x : ligh effect zoom (100 = default size)#

    # # setting# # Create a light effect on a specific map postion, add the following# values to the info. The ID, map_x, map_y and name must be added, other# values are optional.# id: x : ligh effect ID# name: "x" : ligh effect graphic filename ("filename")# map x: x : map X coordinate# map y: x : map Y coordinate

  • 7/27/2019 Light effect script (Ace)

    4/21

    # opacity: x : light opacity (0-255)# pos x: x : coordinate X adjust# pos y: x : coordinate Y adjust# var: x : light opacity variation# speed: x : light variation speed# zoom: x : ligh effect zoom (100 = default size)## # # # Call a lantern on the target character, lanterns are effets that# lights the front of the character# i : actor index, event id or (0: boat, 1: ship, 2: airship)# o : light opacity (0-255)##------------------------------------------------------------------------------# Comment boxes note tags:# Tags to be used on events Comment boxes. They're different from the# comment call, they're called always the even refresh.## # settings# # Create a custom light effect on actor, event or vehicle, add the following

    # values to the settings. The name must be added, other values# are optional.# name: "x" : ligh effect graphic filename ("filename")# opacity: x : light opacity (0-255)# pos x: x : coordinate X adjust# pos y: x : coordinate Y adjust# var: x : light opacity variation# speed: x : light variation speed# zoom: x : ligh effect zoom (100 = default size)## # #

    # # # Simple light shortcuts# o : new opacity (0-255)## # # # # # Flashing light shortcuts# o : new opacity (0-255)#

    # # Lanterns shortcut# o : new opacity (0-255)##------------------------------------------------------------------------------# Additional instructions:## The lights are placed on the shade, so you *must* create a shade in order# to display the lights. No shade, no lights.#

  • 7/27/2019 Light effect script (Ace)

    5/21

    # The IDs of the light effects are used as identifiers. Don't use the# same value for different light spots, if you do so, one light will# replace the other. Also the IDs are used as referece to when# removing lights and changing light opacity.## The actor lanter use the actor position in the party, NOT the actor ID.# So the if you want a lantern for the first character, use# (o = opacity)## About the error on line 1062: this is a USER error made by BAD setup.# this happen when you assign a light effect to a event id that don't exist# at the map. So please: DON'T REPORT IT ANYMORE.##==============================================================================

    #==============================================================================# ** Victor Engine#------------------------------------------------------------------------------# Setting module for the Victor Engine#==============================================================================

    module Victor_Engine#--------------------------------------------------------------------------# * required

    # This method checks for the existance of the basic module and other# VE scripts required for this script to work, don't edit this#--------------------------------------------------------------------------def self.required(name, req, version, type = nil)

    if !$imported[:ve_basic_module]msg = "The script '%s' requires the script\n"msg += "'VE - Basic Module' v%s or higher above it to work properly\n"msg += "Go to http://victorscripts.wordpress.com/ to download this script.

    "msgbox(sprintf(msg, self.script_name(name), version))exit

    elseself.required_script(name, req, version, type)

    endend#--------------------------------------------------------------------------# * script_name# Get the script name base on the imported value, don't edit this#--------------------------------------------------------------------------def self.script_name(name, ext = "VE")

    name = name.to_s.gsub("_", " ").upcase.splitname.collect! {|char| char == ext ? "#{char} -" : char.capitalize }name.join(" ")

    endend

    $imported ||= {}$imported[:ve_light_effects] = 1.11Victor_Engine.required(:ve_light_effects, :ve_basic_module, 1.27, :above)Victor_Engine.required(:ve_light_effects, :ve_map_battle, 1.00, :bellow)

    #==============================================================================# ** Cache#------------------------------------------------------------------------------# This module loads each of graphics, creates a Bitmap object, and retains it.# To speed up load times and conserve memory, this module holds the created

  • 7/27/2019 Light effect script (Ace)

    6/21

    # Bitmap object in the internal hash, allowing the program to return# preexisting objects when the same bitmap is requested again.#==============================================================================

    module Cache#--------------------------------------------------------------------------# * New method: lights#--------------------------------------------------------------------------def self.lights(filename)

    self.load_bitmap('Graphics/Lights/', filename)end

    end

    #==============================================================================# ** Game_Screen#------------------------------------------------------------------------------# This class handles screen maintenance data, such as change in color tone,# flashes, etc. It's used within the Game_Map and Game_Troop classes.#==============================================================================

    class Game_Screen#--------------------------------------------------------------------------# * Public Instance Variables#--------------------------------------------------------------------------

    attr_reader :lightsattr_reader :shadeattr_accessor :remove_light#--------------------------------------------------------------------------# * Alias method: clear#--------------------------------------------------------------------------alias :clear_ve_light_effects :cleardef clear

    clear_ve_light_effectsclear_lights

    end#--------------------------------------------------------------------------# * New method: clear_lights

    #--------------------------------------------------------------------------def clear_lights@lights = {}@remove_light = []@shade = Game_ShadeEffect.new

    end#--------------------------------------------------------------------------# * New method: lights#--------------------------------------------------------------------------def lights

    @lights ||= {}end#--------------------------------------------------------------------------

    # * New method: remove_light#--------------------------------------------------------------------------def remove_light

    @remove_light ||= []end#--------------------------------------------------------------------------# * New method: shade#--------------------------------------------------------------------------def shade

    @shade ||= Game_ShadeEffect.new

  • 7/27/2019 Light effect script (Ace)

    7/21

    endend

    #==============================================================================# ** Game_Map#------------------------------------------------------------------------------# This class handles maps. It includes scrolling and passage determination# functions. The instance of this class is referenced by $game_map.#==============================================================================

    class Game_Map#--------------------------------------------------------------------------# * Alias method: setup#--------------------------------------------------------------------------alias :setup_ve_light_effects :setupdef setup(map_id)

    setup_ve_light_effects(map_id)setup_lights_effect

    end#--------------------------------------------------------------------------# * New method: setup_lights_effect#--------------------------------------------------------------------------def setup_lights_effect

    setup_map_shade(note)

    setup_map_lights(:actor, note)setup_map_lights(:event, note)setup_map_lights(:vehicle, note)setup_map_lights(:map, note)setup_map_lantern(:actor, note)setup_map_lantern(:event, note)setup_map_lantern(:vehicle, note)

    end#--------------------------------------------------------------------------# * New method: setup_map_shade#--------------------------------------------------------------------------def setup_map_shade(text)

    if text =~ get_all_values("CREATE SHADE")

    info = $1.dupshade = @screen.shadeshade.showshade.opacity = info =~ /OPACITY: (\d+)/i ? $1.to_i : 192shade.blend = info =~ /BLEND: (\d+)/i ? $1.to_i : 2red = info =~ /RED: (\d+)/i ? $1.to_i : 0green = info =~ /GREEN: (\d+)/i ? $1.to_i : 0blue = info =~ /BLUE: (\d+)/i ? $1.to_i : 0shade.set_color(red, green, blue)

    endend#--------------------------------------------------------------------------# * New method: setup_map_lights

    #--------------------------------------------------------------------------def setup_map_lights(type, text)

    value = get_regexp_value(type)text.scan(get_all_values("#{value} LIGHT")) dolight = setup_light($1.dup, type)@screen.lights[light.id] = light if light.id

    endend#--------------------------------------------------------------------------# * New method: setup_map_lantern

  • 7/27/2019 Light effect script (Ace)

    8/21

    #--------------------------------------------------------------------------def setup_map_lantern(type, text)

    value = get_regexp_value(type)regexp = //itext.scan(regexp) do |index, opacity|target = get_font(type, index.to_i)next unless targettarget.lantern = opacity.to_itarget.update_lantern

    endend#--------------------------------------------------------------------------# * New method: get_regexp_value#--------------------------------------------------------------------------def get_regexp_value(type)

    case typewhen :actor then "ACTOR"when :event then "EVENT"when :vehicle then "VEHICLE"when :map then "MAP"end

    end#--------------------------------------------------------------------------# * New method: setup_light

    #--------------------------------------------------------------------------def setup_light(info, type)light = Game_LightEffect.newlight.name = info =~ /NAME: #{get_filename}/i ? $1.dup : ""light.id = info =~ /ID: (\w+)/i ? $1.to_s : 0light.id = info =~ /ID: (\d+)/i ? $1.to_i : light.idlight.x = info =~ /POS X: ([+-]?\d+)/i ? $1.to_i : 0light.y = info =~ /POS Y: ([+-]?\d+)/i ? $1.to_i : 0light.speed = info =~ /SPEED: (\d+)/i ? $1.to_i : 0light.zoom = info =~ /ZOOM: (\d+)/i ? $1.to_f : 100.0light.opacity = info =~ /OPACITY: (\d+)/i ? $1.to_i : 192light.variance = info =~ /VAR: (\d+)/i ? $1.to_i : 0if type == :map

    map_x = info =~ /MAP X: (\d+)/i ? $1.to_i : 0map_y = info =~ /MAP Y: (\d+)/i ? $1.to_i : 0light.info = {x: map_x, y: map_y}

    elseindex = info =~ /INDEX: (\d+)/i ? $1.to_i : 0light.info = {type => index}

    endlight

    end#--------------------------------------------------------------------------# * New method: set_light#--------------------------------------------------------------------------def set_light(id, name, info, op = 0, x = 0, y = 0, v = 0, s = 0, z = 100)

    light = Game_LightEffect.newlight.id = idlight.name = namelight.info = infolight.opacity = op.to_ilight.x = x.to_ilight.y = y.to_ilight.variance = v.to_ilight.speed = s.to_ilight.zoom = z.to_f

  • 7/27/2019 Light effect script (Ace)

    9/21

    lightend#--------------------------------------------------------------------------# * New method: get_font#--------------------------------------------------------------------------def get_font(type, i)

    case typewhen :actor then actors[i - 1]when :event then events[i]when :vehicle then vehicles[i]end

    endend

    #==============================================================================# ** Game_CharacterBase#------------------------------------------------------------------------------# This class deals with characters. Common to all characters, stores basic# data, such as coordinates and graphics. It's used as a superclass of the# Game_Character class.#==============================================================================

    class Game_CharacterBase#--------------------------------------------------------------------------

    # * Public Instance Variables#--------------------------------------------------------------------------attr_accessor :lantern#--------------------------------------------------------------------------# * Alias method: init_public_members#--------------------------------------------------------------------------alias :init_public_members_ve_light_effects :init_public_membersdef init_public_members

    init_public_members_ve_light_effects@lantern = 0

    end#--------------------------------------------------------------------------# * Alias method: update

    #--------------------------------------------------------------------------alias :update_ve_light_effects :updatedef update

    update_ve_light_effectsupdate_lantern

    end#--------------------------------------------------------------------------# * New method: update_lantern#--------------------------------------------------------------------------def update_lantern(forced = false)

    diag = $imported[:ve_diagonal_move] && diagonal?if @lantern != 0 && ((!diag && @lantern_direction != @direction) ||

    (diag && @lantern_direction != @diagonal) || forced)

    @lantern_direction = (diag ? @diagonal : @direction)light = setup_lantern$game_map.screen.lights[light.id] = light

    elsif @lantern == 0 && @lantern_directionid = event? ? "EL#{@id}" : "AL#{@id}"$game_map.screen.remove_light.push(id) if $game_map.screen.remove_light@lantern_direction = nil

    endend#--------------------------------------------------------------------------

  • 7/27/2019 Light effect script (Ace)

    10/21

    # * New method: setup_lantern#--------------------------------------------------------------------------def setup_lantern

    id = event? ? "EL#{@id}" : "AL#{@id}"type = event? ? :event : :actorcase @lantern_directionwhen 1name = 'lantern_downleft'value = [id, name, {type => @id}, @lantern, -48, 48]

    when 3name = 'lantern_downright'value = [id, name, {type => @id}, @lantern, 48, 48]

    when 2name = 'lantern_down'value = [id, name, {type => @id}, @lantern, 0, 64]

    when 4name = 'lantern_left'value = [id, name, {type => @id}, @lantern, -64, 0]

    when 6name = 'lantern_right'value = [id, name, {type => @id}, @lantern, 64, 0]

    when 7name = 'lantern_upleft'value = [id, name, {type => @id}, @lantern, -48, -48]

    when 8name = 'lantern_up'value = [id, name, {type => @id}, @lantern, 0, -64,]

    when 9name = 'lantern_upright'value = [id, name, {type => @id}, @lantern, 48, -48]

    end$game_map.set_light(*value)

    endend

    #==============================================================================# ** Game_Event

    #------------------------------------------------------------------------------# This class deals with events. It handles functions including event page# switching via condition determinants, and running parallel process events.# It's used within the Game_Map class.#==============================================================================

    class Game_Event < Game_Character#--------------------------------------------------------------------------# * Alias method: clear_starting_flag#--------------------------------------------------------------------------alias :clear_starting_flag_ve_light_effects :clear_starting_flagdef clear_starting_flag

    clear_starting_flag_ve_light_effects

    @lantern = 0$game_map.screen.remove_light.push("EV#{@id}")refresh_lights if @page

    end#--------------------------------------------------------------------------# * New method: refresh_lights#--------------------------------------------------------------------------def refresh_lights

    case notewhen //i

  • 7/27/2019 Light effect script (Ace)

    11/21

    set_light("EV#{@id}", "light", $1 ? $1 : 255)when //iset_light("EV#{@id}", "lamp", $1 ? $1 : 255)

    when //iset_light("EV#{@id}", "torch", $1)

    when //iadj = $1 == "1" ? 0 : 14set_light("EV#{@id}", "window", $2 ? $2 : 255, 0, 0, 0, adj)

    when //iset_light("EV#{@id}", "light", $1 ? $1 : 255, 30, 1)

    when //iset_light("EV#{@id}", "lamp", $1 ? $1 : 255, 30, 1)

    when //iset_light("EV#{@id}", "torch", $1 ? $1 : 255, 30, 1)

    when //iadj = $1 == "1" ? 0 : 14set_light("EV#{@id}", "window", $2 ? $2 : 255, 30, 1, 0, adj)

    when get_all_values("CUSTOM LIGHT")info = $1.dupn = info =~ /NAME: #{get_filename}/i ? $1.dup : ""x = info =~ /POS X: ([+-]?\d+)/i ? $1.to_i : 0y = info =~ /POS Y: ([+-]?\d+)/i ? $1.to_i : 0s = info =~ /SPEED: (\d+)/i ? $1.to_i : 0z = info =~ /ZOOM: (\d+)/i ? $1.to_f : 100.0

    o = info =~ /OPACITY: (\d+)/i ? $1.to_i : 192v = info =~ /VAR: (\d+)/i ? $1.to_i : 0set_light("EV#{@id}", n, o, v, s, x, y, z)

    when //i@lantern = ($1 ? $1.to_i : 255)

    endend#--------------------------------------------------------------------------# * New method: set_light#--------------------------------------------------------------------------def set_light(id, name, op = 255, v = 0, s = 0, x = 0, y = 0, z = 100)

    value = [id, name, {:event => @id}, op, x, y, v, s, z].compact$game_map.screen.lights[id] = $game_map.set_light(*value)

    $game_map.screen.remove_light.delete(id)endend

    #==============================================================================# ** Game_Interpreter#------------------------------------------------------------------------------# An interpreter for executing event commands. This class is used within the# Game_Map, Game_Troop, and Game_Event classes.#==============================================================================

    class Game_Interpreter#--------------------------------------------------------------------------

    # * Alias method: comment_call#--------------------------------------------------------------------------alias :comment_call_ve_light_effects :comment_calldef comment_call

    call_create_lightscall_change_shade_opacitycall_change_shade_tonecall_change_light_opacitycall_remove_lightcomment_call_ve_light_effects

  • 7/27/2019 Light effect script (Ace)

    12/21

    end#--------------------------------------------------------------------------# * New method: create_lights#--------------------------------------------------------------------------def call_create_lights

    $game_map.setup_map_shade(note)$game_map.setup_map_lights(:actor, note)$game_map.setup_map_lights(:event, note)$game_map.setup_map_lights(:vehicle, note)$game_map.setup_map_lights(:map, note)$game_map.setup_map_lantern(:actor, note)$game_map.setup_map_lantern(:event, note)$game_map.setup_map_lantern(:vehicle, note)

    end#--------------------------------------------------------------------------# * New method: call_change_shade_opacity#--------------------------------------------------------------------------def call_change_shade_opacity

    return if !$game_map.screen.shade.visiblenote.scan(//i) doif $1 =~ /(\d+) *,? *(\d+)?/i

    duration = $2 ? $2.to_i : 0$game_map.screen.shade.change_opacity($1.to_i, duration)

    end

    endend#--------------------------------------------------------------------------# * New method: call_change_shade_tone#--------------------------------------------------------------------------def call_change_shade_tone

    return if !$game_map.screen.shade.visiblenote.scan(//i) doif $1 =~ /(\d+) *, *(\d+) *, *(\d+) *, *(\d+)/i

    $game_map.screen.shade.change_color($1.to_i, $2.to_i, $3.to_i, $4.to_i)end

    endend

    #--------------------------------------------------------------------------# * New method: call_change_light_opacity#--------------------------------------------------------------------------def call_change_light_opacity

    return if !$game_map.screen.shade.visiblenote.scan(//i) dolight = $game_map.screen.lights[$1.to_i]if light && $2 =~ /(\d+) *,? *(\d+)?/i

    duration = $2 ? $2.to_i : 0light.change_opacity($1.to_i, duration)

    endend

    end

    #--------------------------------------------------------------------------# * New method: call_remove_light#--------------------------------------------------------------------------def call_remove_light

    note.scan(//i) do$game_map.screen.remove_light.push($1.to_i)

    endend

    end

  • 7/27/2019 Light effect script (Ace)

    13/21

    #==============================================================================# ** Spriteset_Map#------------------------------------------------------------------------------# This class brings together map screen sprites, tilemaps, etc. It's used# within the Scene_Map class.#==============================================================================

    class Spriteset_Map#--------------------------------------------------------------------------# * Alias method: initialize#--------------------------------------------------------------------------alias :initialize_ve_light_effects :initializedef initialize

    initialize_ve_light_effects2.times { update_light(true) }

    end#--------------------------------------------------------------------------# * Alias method: update#--------------------------------------------------------------------------alias :update_ve_light_effects :updatedef update

    update_ve_light_effectsupdate_light

    end

    #--------------------------------------------------------------------------# * Alias method: dispose#--------------------------------------------------------------------------alias :dispose_ve_light_effects :disposedef dispose

    dispose_ve_light_effectsdispose_light unless SceneManager.scene_is?(Scene_Map)

    end#--------------------------------------------------------------------------# * New method: update_light#--------------------------------------------------------------------------def update_light(forced = false)

    return unless Graphics.frame_count % 2 == 0 || forced

    update_shadeupdate_effectsend#--------------------------------------------------------------------------# * New method: dispose_light#--------------------------------------------------------------------------def dispose_light

    if @light_effect@light_effect.dispose@light_effect = nil@screen_shade = nil

    endend

    #--------------------------------------------------------------------------# * New method: update_shade#--------------------------------------------------------------------------def update_shade

    if !@light_effect && $game_map.screen.shade.visiblerefresh_lights

    elsif $game_map.screen.shade.visible && @light_effect@light_effect.update

    elsif @light_effect && !$game_map.screen.shade.visibledispose_light

  • 7/27/2019 Light effect script (Ace)

    14/21

    endend#--------------------------------------------------------------------------# * New method: refresh_lights#--------------------------------------------------------------------------def refresh_lights

    @light_effect.dispose if @light_effect@screen_shade = $game_map.screen.shade@light_effect = Sprite_Light.new(@screen_shade, @viewport2)$game_map.event_list.each {|event| event.refresh_lights }@light_effect.update

    end#--------------------------------------------------------------------------# * New method: update_effects#--------------------------------------------------------------------------def update_effects

    return if !@light_effect || $game_map.screen.lights.empty?$game_map.screen.lights.keys.each {|key| create_light(key) }$game_map.screen.remove_light.clear

    end#--------------------------------------------------------------------------# * New method: create_light#--------------------------------------------------------------------------def create_light(key)

    effect = @light_effect.lights[key]return if remove_light(key)return if effect && effect.light == $game_map.screen.lights[key]@light_effect.create_light($game_map.screen.lights[key])

    end#--------------------------------------------------------------------------# * New method: remove_light#--------------------------------------------------------------------------def remove_light(key)

    return false if !$game_map.screen.remove_light.include?(key)@light_effect.remove_light(key)$game_map.screen.lights.delete(key)return true

    endend

    #==============================================================================# ** Scene_Map#------------------------------------------------------------------------------# This class performs the map screen processing.#==============================================================================

    class Scene_Map#--------------------------------------------------------------------------# * Alias method: pre_transfer#--------------------------------------------------------------------------

    alias :pre_transfer_ve_light_effects :pre_transferdef pre_transfer

    pre_transfer_ve_light_effectsif $game_player.new_map_id != [email protected]_light$game_map.screen.clear_lights

    endend#--------------------------------------------------------------------------# * Alias method: post_transfer

  • 7/27/2019 Light effect script (Ace)

    15/21

    #--------------------------------------------------------------------------alias :post_transfer_ve_light_effects :post_transferdef post_transfer

    $game_map.actors.each {|actor| actor.update_lantern(true) }post_transfer_ve_light_effects

    endend

    #==============================================================================# ** Game_ShadeEffect#------------------------------------------------------------------------------# This class handles the shade layer data#==============================================================================

    class Game_ShadeEffect#--------------------------------------------------------------------------# * Public Instance Variables#--------------------------------------------------------------------------attr_reader :visibleattr_reader :colorattr_accessor :blendattr_accessor :opacity#--------------------------------------------------------------------------# * initialize

    #--------------------------------------------------------------------------def initializeinit_opacityinit_color

    end#--------------------------------------------------------------------------# * init_opacity#--------------------------------------------------------------------------def init_opacity

    @visible = false@opacity = 0@opacity_target = 0@opacity_duration = 0

    end#--------------------------------------------------------------------------# * init_color#--------------------------------------------------------------------------def init_color

    @blend = 0@color = Color.new(0, 0, 0, 0)@color_duration = 0@color_target = Color.new(0, 0, 0, 0)

    end#--------------------------------------------------------------------------# * show#--------------------------------------------------------------------------

    def show@visible = true

    end#--------------------------------------------------------------------------# * hide#--------------------------------------------------------------------------def hide

    @visible = falseend#--------------------------------------------------------------------------

  • 7/27/2019 Light effect script (Ace)

    16/21

    # * set_color#--------------------------------------------------------------------------def set_color(r = 0, g = 0, b = 0)

    @color = get_colors(r, g, b)@color_target = @color.clone

    end#--------------------------------------------------------------------------# * change_opacity#--------------------------------------------------------------------------def change_opacity(op, d)

    @opacity_target = op@opacity_duration = [d, 0].max@opacity = @opacity_target if @opacity_duration == 0

    end#--------------------------------------------------------------------------# * change_color#--------------------------------------------------------------------------def change_color(r, g, b, d)

    @color_target = get_colors(r, g, b)@color_duration = [d, 0].max@color = @color_target.clone if @color_duration == 0

    end#--------------------------------------------------------------------------# * get_colors

    #--------------------------------------------------------------------------def get_colors(r, g, b)color = Color.new(255 - r, 255 - g, 255 - b, 255) if @blend == 2color = Color.new(r, g, b, 255) if @blend != 2color

    end#--------------------------------------------------------------------------# * update#--------------------------------------------------------------------------def update

    update_opacityupdate_color

    end

    #--------------------------------------------------------------------------# * update_opacity#--------------------------------------------------------------------------def update_opacity

    return if @opacity_duration == 0d = @opacity_duration@opacity = (@opacity * (d - 1) + @opacity_target) / d@opacity_duration -= 1

    end#--------------------------------------------------------------------------# * update_color#--------------------------------------------------------------------------def update_color

    return if @color_duration == 0d = @[email protected] = (@color.red * (d - 1) + @color_target.red) / [email protected] = (@color.green * (d - 1) + @color_target.green) / [email protected] = (@color.blue * (d - 1) + @color_target.blue) / d@color_duration -= 1

    endend

    #==============================================================================

  • 7/27/2019 Light effect script (Ace)

    17/21

    # ** Game_LightEffect#------------------------------------------------------------------------------# This class handles the light sprite data#==============================================================================

    class Game_LightEffect#--------------------------------------------------------------------------# * Public Instance Variables#--------------------------------------------------------------------------attr_accessor :idattr_accessor :nameattr_accessor :infoattr_accessor :opacityattr_accessor :xattr_accessor :yattr_accessor :varianceattr_accessor :speedattr_accessor :zoomattr_accessor :opacity_targetattr_accessor :opacity_duration#--------------------------------------------------------------------------# * change_opacity#--------------------------------------------------------------------------def change_opacity(op, d)

    @opacity_target = op@opacity_duration = [d, 0].max@opacity = @opacity_target if @opacity_duration == 0

    endend

    #==============================================================================# ** Game_LightBitmap#------------------------------------------------------------------------------# This class handles the bitmpas of each light spot#==============================================================================

    class Game_LightBitmap

    #--------------------------------------------------------------------------# * Public Instance Variables#--------------------------------------------------------------------------attr_reader :lightattr_reader :bitmapattr_reader :opacityattr_reader :xattr_reader :y#--------------------------------------------------------------------------# * initialize#--------------------------------------------------------------------------def initialize(light)

    @light = light

    init_basicupdate

    end#--------------------------------------------------------------------------# * init_basic#--------------------------------------------------------------------------def init_basic

    @bitmap = Cache.lights(@light.name)@target = set_target@opacity = @light.opacity

  • 7/27/2019 Light effect script (Ace)

    18/21

    @speed = @light.speed@variance = [email protected]_duration = [email protected]_target = 0

    end#--------------------------------------------------------------------------# * width#--------------------------------------------------------------------------def width

    @bitmap.width * @light.zoom / 100.0end#--------------------------------------------------------------------------# * height#--------------------------------------------------------------------------def height

    @bitmap.height * @light.zoom / 100.0end#--------------------------------------------------------------------------# * update#--------------------------------------------------------------------------def update

    update_positionupdate_opacityupdate_variance

    end#--------------------------------------------------------------------------# * update_position#--------------------------------------------------------------------------def update_position

    @target.is_a?(Game_Character) ? character_position : map_positionend#--------------------------------------------------------------------------# * character_position#--------------------------------------------------------------------------def character_position

    @x = $game_map.adjust_x(@target.real_x) * 32 - width / 2 + @light.x + 16@y = $game_map.adjust_y(@target.real_y) * 32 - height / 2 + @light.y + 16

    end#--------------------------------------------------------------------------# * map_position#--------------------------------------------------------------------------def map_position

    @x = $game_map.adjust_x(@target[:x]) * 32 - width / 2 + @light.x + 16@y = $game_map.adjust_y(@target[:y]) * 32 - height / 2 + @light.y + 16

    end#--------------------------------------------------------------------------# * change_opacity#--------------------------------------------------------------------------def change_opacity(op, d)

    @light.opacity_target = op

    @light.opacity_duration = [d, 0][email protected] = @light.opacity_target if @light.opacity_duration == 0

    end#--------------------------------------------------------------------------# * update_opacity#--------------------------------------------------------------------------def update_opacity

    return if @light.opacity_duration == 0d = @[email protected] = (@light.opacity * (d - 1) + @light.opacity_target) / d

  • 7/27/2019 Light effect script (Ace)

    19/21

  • 7/27/2019 Light effect script (Ace)

    20/21

    $game_map.adjust_x($game_map.display_x)end#--------------------------------------------------------------------------# * map_y#--------------------------------------------------------------------------def map_y

    $game_map.adjust_y($game_map.display_y)end#--------------------------------------------------------------------------# * update#--------------------------------------------------------------------------def update

    superself.ox = map_xself.oy = map_yupdate_opacityupdate_lights

    end#--------------------------------------------------------------------------# * update lights#--------------------------------------------------------------------------def update_lights

    rect = Rect.new(map_x, map_y, Graphics.width, Graphics.height)self.bitmap.fill_rect(rect, color)

    draw_light_effectsend#--------------------------------------------------------------------------# * color#--------------------------------------------------------------------------def color

    @shade.colorend#--------------------------------------------------------------------------# * draw_light_effects#--------------------------------------------------------------------------def draw_light_effects

    @lights.values.each do |light|

    light.updatenext if !on_screen?(light)draw_light(light)

    endend#--------------------------------------------------------------------------# * on_sceen?#--------------------------------------------------------------------------def on_screen?(light)

    ax1 = light.xay1 = light.yax2 = light.x + light.widthay2 = light.y + light.height

    bx1 = map_xby1 = map_ybx2 = map_x + Graphics.widthby2 = map_y + Graphics.heightcheck1 = ax1.between?(bx1, bx2) || ax2.between?(bx1, bx2) ||

    ax1 < bx1 && ax2 > bx2check2 = ay1.between?(by1, by2) || ay2.between?(by1, by2) ||

    ay1 < by1 && ay2 > by2check1 && check2

    end

  • 7/27/2019 Light effect script (Ace)

    21/21

    #--------------------------------------------------------------------------# * draw_light#--------------------------------------------------------------------------def draw_light(light)

    img = light.bitmaprect = Rect.new(light.x, light.y, light.width, light.height)self.bitmap.stretch_blt(rect, img, img.rect, light.opacity)

    end#--------------------------------------------------------------------------# * update_opacity#--------------------------------------------------------------------------def update_opacity

    @shade.updateself.opacity = @shade.opacityself.blend_type = @shade.blend

    end#--------------------------------------------------------------------------# * create_light#--------------------------------------------------------------------------def create_light(light)

    remove_light(light.id)@lights[light.id] = Game_LightBitmap.new(light)

    end#--------------------------------------------------------------------------

    # * remove_light#--------------------------------------------------------------------------def remove_light(id)

    @lights.delete(id) if @lights[id]end#--------------------------------------------------------------------------# * dispose#--------------------------------------------------------------------------def dispose

    [email protected] {|light| light.dispose unless light.bitmap.disposed? }

    endend