Если найдешь на XP - давай на XP, перепишу под VX.
В общем то да, надо. Если сможешь закомментить по строчкам на русском - хвала тебе.
Спойлер KGC:Код:#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
#_/ ◆ Day/Night System - KGC_DayNight ◆ VX ◆
#_/ ◇ Last update : 2008/02/01 ◇
#_/----------------------------------------------------------------------------
#_/ Making Day and Night in your game.
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
#==============================================================================
# ★ Customize ★
#==============================================================================
module KGC
module DayNight
# ◆ Day/Night System
# 0 - Time runs based on your elapsed game time.
# 1 - Time runs based on the number of steps you've taken.
# 2 - Time runs based off real time. (Sensitive/Experimental)
METHOD = 1
# ◆ This is the number of the variable for the phases.
# In this variable, the present phase will be housed.
# ◆ Translator's note: in other words, when making your
# game, I would either set it to a variable you're not
# using or avoid the default variable it uses.
PHASE_VARIABLE = 11
# ◆ This is the number of the variable that keeps the
# information for the days.
# Days are kept here as they elapse.
PASS_DAYS_VARIABLE = 12
# ◆ Stopping script behavior during an event.
STOP_ON_EVENT = true
# ◆ In a battle, the following will make only the
# background change tone.
# Setting this to "false" will tone everything.
TONE_BACK_ONLY_IN_BATTLE = true
# ◆ Setting the phases.
# Each phases uses the following setup.
# ["name", color tone (Tone), duration]
# It's possible to increase phases, but the other
# phases will not just automatically adjust.
# You'll have to set them yourself so they fit
# within the day's time frame.
#
# [name]
# The name of the phase.
# The name has no significance over performance.
# [color tone]
# Color of the screen or background.
# If you don't know much about this, you'd be
# better off not editing.
# ***Translator's note for beginners***
# The way the tones are listed below are by the
# amount of red, green, and blue, the fourth number
# being saturation. If you go into the event
# command for changing the screen tint, you can
# mess around with the tint until you find something
# you like. When you okay it, the event window will
# show you the actual numeric values for the tone you
# want. You can simply copy those numbers below into
# the phase you want them for.
#
# [Duration]
# The time before the next phase occurs.
# If you chose for phases to change according to
# number of steps, the duration number is the number
# of steps before the phase change.
# In the case of a real-time system, it's changed to
# a 24 hour system.
PHASE = [
["noon", Tone.new( 0, 0, 0), 300], # Phase 0
["evening", Tone.new( -32, -96, -96), 100], # Phase 1
["night", Tone.new(-128, -128, -32), 250], # Phase 2
["morning", Tone.new( -48, -48, -16), 100], # Phase 3
] # ← Do not delete PHASE!
# If you want a more realistic tone for your real-time setting...
# ["noon", Tone.new( 0, 0, 0), 16], # Phase 0
# ["evening", Tone.new( 0, -96, -96), 20], # Phase 1
# ["night", Tone.new(-96, -96, -64), 6], # Phase 2
# ["morning", Tone.new(-48, -48, -16), 10], # Phase 3
# ...is an alternative to your tones.
# ◆ The phase where the day changes.
# When the appointed phase comes into play, a new day is started.
# The default settings are as follows:
# 0 - noon
# 1 - evening
# 2 - night
# 3 - morning
# ※ If using actual time, keep in mind that this script cannot
# keep track of the actual days.
PASS_DAY_PHASE = 3
# ◆ Fade time between phases in frames.
# 60 frames is the default used.
PHASE_DURATION = 60
# ◆ Day of the week name.
# Starts from the first day, goes to the last day, then loops.
# The name of the day has no significance to how the script
# performs, so name them as you wish.
# ※ When actual time is used, make sure to use 7 days.
WEEK_NAME = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
$imported = {} if $imported == nil
$imported["DayNight"] = true
if $data_mapinfos == nil
$data_mapinfos = load_data("Data/MapInfos.rvdata")
end
module KGC::DayNight
METHOD_TIME = 0 # Elapsed Time
METHOD_STEP = 1 # Number of Steps
METHOD_RTIME = 2 # Real-time
# Regular Expression
module Regexp
# Map Information
module MapInfo
# Stop transition
DAYNIGHT_STOP = /\[DN_STOP\]/i
# Disable night/day effect.
DAYNIGHT_VOID = /\[DN_VOID\]/i
end
# Enemy Group
module Troop
# Appearance in phase
APPEAR_PHASE = /\[DN((?:[ ]*[\-]?\d+(?:[ ]*,)?)+)\]/i
end
end
#--------------------------------------------------------------------------
# ○ Enemy group appearance.
# troop : decide per troup
# phase : decide per phase
#--------------------------------------------------------------------------
def self.troop_appear?(troop, phase = $game_system.daynight_phase)
# Appearance decision.
unless troop.appear_daynight_phase.empty?
return false unless troop.appear_daynight_phase.include?(phase)
end
# Non-Appearance decision.
unless troop.nonappear_daynight_phase.empty?
return false if troop.nonappear_daynight_phase.include?(phase)
end
return true
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# □ KGC::Commands
#==============================================================================
module KGC::Commands
module_function
#--------------------------------------------------------------------------
# ○ Stopping day/night change.
#--------------------------------------------------------------------------
def stop_daynight
$game_system.daynight_change_enabled = false
end
#--------------------------------------------------------------------------
# ○ Starting day/night change.
#--------------------------------------------------------------------------
def start_daynight
$game_system.daynight_change_enabled = true
end
#--------------------------------------------------------------------------
# ○ Acquiring present phase name.
#--------------------------------------------------------------------------
def get_daynight_name
return KGC::DayNight::PHASE[get_daynight_phase][0]
end
#--------------------------------------------------------------------------
# ○ Acquiring present day of the week.
# variable_id : the ID of the variable it replaces.
#--------------------------------------------------------------------------
def get_daynight_week(variable_id = 0)
if KGC::DayNight::METHOD == KGC::DayNight::METHOD_RTIME
week = Time.now.wday
else
days = $game_variables[KGC::DayNight::PASS_DAYS_VARIABLE]
week = (days % KGC::DayNight::WEEK_NAME.size)
end
if variable_id > 0
$game_variables[variable_id] = week
end
return week
end
#--------------------------------------------------------------------------
# ○ Acquiring the name of the present day of the week.
#--------------------------------------------------------------------------
def get_daynight_week_name
return KGC::DayNight::WEEK_NAME[get_daynight_week]
end
#--------------------------------------------------------------------------
# ○ Phase Change
# phase : the phase after phase transition.
# duration : time in frames for phase transition
# pass_days : the days that have elapsed initially (Default: 0)
#--------------------------------------------------------------------------
def change_daynight_phase(phase,
duration = KGC::DayNight::PHASE_DURATION,
pass_days = 0)
$game_temp.manual_daynight_duration = duration
$game_system.daynight_counter = 0
$game_system.daynight_phase = phase
$game_variables[KGC::DayNight::PASS_DAYS_VARIABLE] += pass_days
end
#--------------------------------------------------------------------------
# ○ Transitioning to the next phase.
# duration : time in frames for phase transition
#--------------------------------------------------------------------------
def transit_daynight_phase(duration = KGC::DayNight::PHASE_DURATION)
$game_screen.transit_daynight_phase(duration)
end
#--------------------------------------------------------------------------
# ○ Reseting the color tone to default.
# duration : time in frames for transition
#--------------------------------------------------------------------------
def set_daynight_default(duration = KGC::DayNight::PHASE_DURATION)
$game_screen.set_daynight_default(duration)
end
#--------------------------------------------------------------------------
# ○ Re-creating present phase.
# duration : time in frames for transition
#--------------------------------------------------------------------------
def restore_daynight_phase(duration = KGC::DayNight::PHASE_DURATION)
$game_screen.restore_daynight_phase(duration)
end
end
class Game_Interpreter
include KGC::Commands
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ RPG::MapInfo
#==============================================================================
class RPG::MapInfo
#--------------------------------------------------------------------------
# ● Acquiring Map Name
#--------------------------------------------------------------------------
def name
return @name.gsub(/\[.*\]/) { "" }
end
#--------------------------------------------------------------------------
# ○ Acquring Original Map Name
#--------------------------------------------------------------------------
def original_name
return @name
end
#--------------------------------------------------------------------------
# ○ Stopping Day/Night change.
#--------------------------------------------------------------------------
def daynight_stop
return @name =~ KGC::DayNight::Regexp::MapInfo::DAYNIGHT_STOP
end
#--------------------------------------------------------------------------
# ○ Turning off Day/Night effect.
#--------------------------------------------------------------------------
def daynight_void
return @name =~ KGC::DayNight::Regexp::MapInfo::DAYNIGHT_VOID
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ RPG::Area
#==============================================================================
unless $@
class RPG::Area
#--------------------------------------------------------------------------
# ○ Acquiring Encounter List
#--------------------------------------------------------------------------
alias encounter_list_KGC_DayNight encounter_list
def encounter_list
list = encounter_list_KGC_DayNight.clone
# Appearance conditional choice.
list.each_index { |i|
list[i] = nil unless KGC::DayNight.troop_appear?($data_troops[list[i]])
}
return list.compact
end
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ RPG::Troop
#==============================================================================
class RPG::Troop
#--------------------------------------------------------------------------
# ○ Cache formation of day/night change.
#--------------------------------------------------------------------------
def create_daynight_cache
@__appear_daynight_phase = []
@__nonappear_daynight_phase = []
# Phase Appearance
if @name =~ KGC::DayNight::Regexp::Troop::APPEAR_PHASE
$1.scan(/[\-]?\d+/).each { |num|
phase = num.to_i
if phase < 0
# If the phase doesn't appear
@__nonappear_daynight_phase << phase.abs
else
# If the phase does appear
@__appear_daynight_phase << phase
end
}
end
end
#--------------------------------------------------------------------------
# ○ Phase Appearance
#--------------------------------------------------------------------------
def appear_daynight_phase
create_daynight_cache if @__appear_daynight_phase == nil
return @__appear_daynight_phase
end
#--------------------------------------------------------------------------
# ○ Phase Non-Appearance
#--------------------------------------------------------------------------
def nonappear_daynight_phase
create_daynight_cache if @__nonappear_daynight_phase == nil
return @__nonappear_daynight_phase
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ Game_Temp
#==============================================================================
class Game_Temp
#--------------------------------------------------------------------------
# ● Open instance variable
#--------------------------------------------------------------------------
attr_accessor :manual_daynight_duration # Manual phase modification flag
#--------------------------------------------------------------------------
# ● Object initialization
#--------------------------------------------------------------------------
alias initialize_KGC_DayNight initialize
def initialize
initialize_KGC_DayNight
@manual_daynight_duration = nil
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ Game_System
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# ● Open instance variable
#--------------------------------------------------------------------------
attr_writer :daynight_counter # Phase transition counter
attr_writer :daynight_change_enabled # Day and night change validation
#--------------------------------------------------------------------------
# ● Object initialization
#--------------------------------------------------------------------------
alias initialize_KGC_DayNight initialize
def initialize
initialize_KGC_DayNight
@daynight_counter = 0
@daynight_change_enabled = true
end
#--------------------------------------------------------------------------
# ○ Acquiring the phase transition counter
#--------------------------------------------------------------------------
def daynight_counter
@daynight_counter = 0 if @daynight_counter == nil
return @daynight_counter
end
#--------------------------------------------------------------------------
# ○ Acquiring present phase
#--------------------------------------------------------------------------
def daynight_phase
return $game_variables[KGC::DayNight::PHASE_VARIABLE]
end
#--------------------------------------------------------------------------
# ○ Modifying present phase
#--------------------------------------------------------------------------
def daynight_phase=(value)
$game_variables[KGC::DayNight::PHASE_VARIABLE] = value
end
#--------------------------------------------------------------------------
# ○ Acquiring the day and night change effective flag
#--------------------------------------------------------------------------
def daynight_change_enabled
@daynight_change_enabled = 0 if @daynight_change_enabled == nil
return @daynight_change_enabled
end
#--------------------------------------------------------------------------
# ○ Phase advance
#--------------------------------------------------------------------------
def progress_daynight_phase
self.daynight_phase += 1
if self.daynight_phase >= KGC::DayNight::PHASE.size
self.daynight_phase = 0
end
end
#--------------------------------------------------------------------------
# ○ Acquiring present phase object
#--------------------------------------------------------------------------
def daynight_phase_object
return KGC::DayNight::PHASE[daynight_phase]
end
#--------------------------------------------------------------------------
# ○ Acquiring previous phase object
#--------------------------------------------------------------------------
def previous_daynight_phase_object
return KGC::DayNight::PHASE[daynight_phase - 1]
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ Game_Screen
#==============================================================================
class Game_Screen
#--------------------------------------------------------------------------
# ● Open instance variable
#--------------------------------------------------------------------------
attr_reader :daynight_tone # Color tone of day and night
#--------------------------------------------------------------------------
# ● Clear
#--------------------------------------------------------------------------
alias clear_KGC_DayNight clear
def clear
clear_KGC_DayNight
clear_daynight
end
#--------------------------------------------------------------------------
# ○ Clearing the variable for day and night change
#--------------------------------------------------------------------------
def clear_daynight
@default_tone = Tone.new(0, 0, 0)
# Coordinate initialization for movement decision
@daynight_x = 0
@daynight_y = 0
# Count initialization for frame renewal
@frame_count = Graphics.frame_count
@daynight_tone_duration = 0
apply_daynight
end
#--------------------------------------------------------------------------
# ○ Applying the color tone of day and night
#--------------------------------------------------------------------------
def apply_daynight
return if $game_map == nil
# In the case of a map with day/night changes disabled
if $game_map.daynight_void?
if @daynight_tone_changed
# You reset to the default color tone
@tone = @default_tone.clone
@daynight_tone_changed = false
end
@daynight_tone = @tone.clone
return
end
# If phase isn't correct, restore default
if $game_system.daynight_phase_object == nil
$game_system.daynight_phase = 0
end
# Applying the present color tone
@tone = $game_system.daynight_phase_object[1].clone
@daynight_tone = @tone.clone
# In case of real-time transition
if KGC::DayNight::METHOD == KGC::DayNight::METHOD_RTIME
time = Time.now
# Transition to the correct phase
KGC::DayNight::PHASE.each_with_index { |phase, i|
if phase[2] <= time.hour
start_tone_change(phase[1], 1)
$game_system.daynight_phase = i
break
end
}
end
@daynight_tone_changed = true
end
#--------------------------------------------------------------------------
# ○ Acquisition of color tone
#--------------------------------------------------------------------------
def tone
if $game_temp.in_battle && KGC::DayNight::TONE_BACK_ONLY_IN_BATTLE
return @default_tone
else
return @tone
end
end
#--------------------------------------------------------------------------
# ● Start of color tone modification
# tone : Color tone
# duration : Transition time
#--------------------------------------------------------------------------
alias start_tone_change_KGC_DayNight start_tone_change
def start_tone_change(tone, duration)
duration = [duration, 1].max
start_tone_change_KGC_DayNight(tone, duration)
@daynight_tone_target = tone.clone
@daynight_tone_duration = duration
end
#--------------------------------------------------------------------------
# ● Frame update
#--------------------------------------------------------------------------
alias update_KGC_DayNight update
def update
update_KGC_DayNight
update_daynight_transit
end
#--------------------------------------------------------------------------
# ● Color tone update
#--------------------------------------------------------------------------
alias update_tone_KGC_DayNight update_tone
def update_tone
update_tone_KGC_DayNight
if @daynight_tone_duration >= 1
d = @daynight_tone_duration
target = @daynight_tone_target
@daynight_tone.red = (@daynight_tone.red * (d - 1) + target.red) / d
@daynight_tone.green = (@daynight_tone.green * (d - 1) + target.green) / d
@daynight_tone.blue = (@daynight_tone.blue * (d - 1) + target.blue) / d
@daynight_tone.gray = (@daynight_tone.gray * (d - 1) + target.gray) / d
@daynight_tone_duration -= 1
end
end
#--------------------------------------------------------------------------
# ○ Phase transition update
#--------------------------------------------------------------------------
def update_daynight_transit
# When manual change was done
if $game_temp.manual_daynight_duration
start_tone_change($game_system.daynight_phase_object[1],
$game_temp.manual_daynight_duration)
$game_temp.manual_daynight_duration = nil
@daynight_tone_changed = true
end
return unless $game_system.daynight_change_enabled # Replace current phase
return if $game_map.daynight_stop? # In process of stopping
if KGC::DayNight::STOP_ON_EVENT
interpreter = ($game_temp.in_battle ? $game_troop.interpreter :
$game_map.interpreter)
return if interpreter.running? # event executing
end
case KGC::DayNight::METHOD
when KGC::DayNight::METHOD_TIME # Elapsed time
update_daynight_pass_time
when KGC::DayNight::METHOD_STEP # Number of steps
update_daynight_step
when KGC::DayNight::METHOD_RTIME # Real-time
update_daynight_real_time
end
end
#--------------------------------------------------------------------------
# ○ Transition: Elapsed Time
#--------------------------------------------------------------------------
def update_daynight_pass_time
# Count growth calculation
inc_count = Graphics.frame_count - @frame_count
# If the result is off, return.
if inc_count >= 100
@frame_count = Graphics.frame_count
return
end
# Count addition
$game_system.daynight_counter += inc_count
@frame_count = Graphics.frame_count
# State transition decision
count = $game_system.daynight_counter / Graphics.frame_rate
if count >= $game_system.daynight_phase_object[2]
transit_daynight_next
end
end
#--------------------------------------------------------------------------
# ○ Transition: Number of Steps
#--------------------------------------------------------------------------
def update_daynight_step
# If it's not active, it returns.
return if @daynight_x == $game_player.x && @daynight_y == $game_player.y
@daynight_x = $game_player.x
@daynight_y = $game_player.y
# Count addition
$game_system.daynight_counter += 1
# State transition decision
count = $game_system.daynight_counter
if count >= $game_system.daynight_phase_object[2]
transit_daynight_next
end
end
#--------------------------------------------------------------------------
# ○ Transition: Real-time
#--------------------------------------------------------------------------
def update_daynight_real_time
time = Time.now
# State transition decision
time1 = $game_system.daynight_phase_object[2]
transit = (time1 <= time.hour)
if $game_system.previous_daynight_phase_object != nil
time2 = $game_system.previous_daynight_phase_object[2]
if time1 < time2
transit &= (time.hour < time2)
end
end
if transit
transit_daynight_next
end
end
#--------------------------------------------------------------------------
# ○ Transitioning to the next state
# duration : Transition duration
#--------------------------------------------------------------------------
def transit_daynight_next(duration = KGC::DayNight::PHASE_DURATION)
$game_system.daynight_counter = 0
$game_system.progress_daynight_phase
# Days lapse decision
if $game_system.daynight_phase == KGC::DayNight::PASS_DAY_PHASE
$game_variables[KGC::DayNight::PASS_DAYS_VARIABLE] += 1
end
# Color tone change
start_tone_change($game_system.daynight_phase_object[1], duration)
@daynight_tone_changed = true
end
#--------------------------------------------------------------------------
# ○ Default tone to fall back on (0, 0, 0)
# duration : Transition duration
#--------------------------------------------------------------------------
def set_daynight_default(duration)
start_tone_change(@default_tone, duration)
end
#--------------------------------------------------------------------------
# ○ Restoring present phase
# duration : Transition duration
#--------------------------------------------------------------------------
def restore_daynight_phase(duration)
start_tone_change($game_system.daynight_phase_object[1], duration)
@daynight_tone_changed = true
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ Game_Map
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# ● Setup
# map_id : Map ID
#--------------------------------------------------------------------------
alias setup_KGC_DayNight setup
def setup(map_id)
setup_KGC_DayNight(map_id)
@screen.apply_daynight
end
#--------------------------------------------------------------------------
# ○ Is day and night change stopped?
#--------------------------------------------------------------------------
def daynight_stop?
info = $data_mapinfos[map_id]
return false if info == nil
return (info.daynight_stop || info.daynight_void)
end
#--------------------------------------------------------------------------
# ○ Day and night change invalidity?
#--------------------------------------------------------------------------
def daynight_void?
info = $data_mapinfos[map_id]
return false if info == nil
return info.daynight_void
end
#--------------------------------------------------------------------------
# ● Acquisition of encounter list
#--------------------------------------------------------------------------
alias encounter_list_KGC_DayNight encounter_list
def encounter_list
list = encounter_list_KGC_DayNight.clone
# Appearance of conditional decision
list.each_index { |i|
list[i] = nil unless KGC::DayNight.troop_appear?($data_troops[list[i]])
}
return list.compact
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ Spriteset_Battle
#==============================================================================
if KGC::DayNight::TONE_BACK_ONLY_IN_BATTLE
class Spriteset_Battle
#--------------------------------------------------------------------------
# ● Compilation of battleback sprite
#--------------------------------------------------------------------------
alias create_battleback_KGC_DayNight create_battleback
def create_battleback
create_battleback_KGC_DayNight
if @battleback_sprite.wave_amp == 0
@battleback_sprite.tone = $game_troop.screen.daynight_tone
end
end
#--------------------------------------------------------------------------
# ● Compilation of battle floor sprite
#--------------------------------------------------------------------------
alias create_battlefloor_KGC_DayNight create_battlefloor
def create_battlefloor
create_battlefloor_KGC_DayNight
@battlefloor_sprite.tone = $game_troop.screen.daynight_tone
end
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ Scene_Map
#==============================================================================
class Scene_Map < Scene_Base
#--------------------------------------------------------------------------
# ● Start processing
#--------------------------------------------------------------------------
alias start_KGC_DayNight start
def start
$game_map.screen.clear_daynight
start_KGC_DayNight
end
end