#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
#_/ ◆ 昼夜交替 - KGC_DayNight ◆ VX ◆
#_/ ◇ Last update : 2008/03/08 ◇
#_/ 汉化 by 约束
#_/
#_/----------------------------------------------------------------------------
#_/ 在游戏中加入了昼夜交替。
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
#==============================================================================
# ★ 指导项目 - Customize ★
#==============================================================================
module KGC
module DayNight
# ◆ 昼夜切换方式
# 0..根据时间的经过 1..根据行走步数 2..根据现实时间(微妙)
METHOD = 1
# ◆ 保存天色阶段的变量号码
# 在这里被设定的变量中、存入现在的天色阶段。
PHASE_VARIABLE = 11
# ◆ 保存日期的变量号码
# 在这里被设定的变量中、存入经过日数的阶段。
PASS_DAYS_VARIABLE = 12
# ◆ 在事件中不变更天色阶段
STOP_ON_EVENT = true
# ◆ 在战斗中、只有背景使用当前色调
# 改成 false 时、夜晚时会变的不合常理。
TONE_BACK_ONLY_IN_BATTLE = true
# ◆ 各个天色阶段的设置
# 将各个天色阶段
# ["名称", 色调(Tone), 切换时间],
# 像如上设置。
# 可以增加天色阶段、但是在不习惯时不推荐增加。
#
# [名称]
# 天色阶段的名字。
# 名字自身没有意义。
# [色调]
# 画面全体的颜色。
# 并不是很明白时请不要轻易变更。
# [切换时间]
# 到下个天色阶段的间隔时间。
# 切换方式是 使用时间经过方式为秒、步数方式为步数。
# 现实时间方式时、到下个状态切换的时刻 (24小时方式)。
PHASE = [
["白日", Tone.new( 0, 0, 0), 300], # 天色阶段 0
["傍晚", Tone.new( -32, -96, -96), 100], # 天色阶段 1
["夜晚", Tone.new(-128, -128, -32), 250], # 天色阶段 2
["早晨", Tone.new( -48, -48, -16), 100], # 天色阶段 3
] # ← 这里不要消去!
# 现实时间时、
# ["白日", Tone.new( 0, 0, 0), 16], # 天色阶段 0 (现实为16点时傍晚)
# ["傍晚", Tone.new( 0, -96, -96), 20], # 天色阶段 1 (现实为20点时夜晚)
# ["夜晚", Tone.new(-96, -96, -64), 6], # 天色阶段 2 (现实为6点时早上)
# ["早晨", Tone.new(-48, -48, -16), 10], # 天色阶段 3 (现实为10点时白日)
# 像这样的。
# ◆ 变换日期的天色阶段
# 到了这里设定过的天色阶段时、日数增加。
# 初期状况 0..白日 1..傍晚 2..夜晚 3..早上
# ※ 现实时间时、并不能与现实使用相同日数,请注意。
PASS_DAY_PHASE = 3
# ◆ 切换状态是的天色阶段时间 (画面)
# 省略时也会使用这个数值。
PHASE_DURATION = 60
# ◆ 日期名
# 从最初开始、到最后一个日期然后再从第一个循环开始。
# 日期名自身没有任何意义。
# ※ 使用现实时间时 请设置为7个日期。
WEEK_NAME = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]
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 # 时间经过
METHOD_STEP = 1 # 步数
METHOD_RTIME = 2 # 现实时间
# 正规表现
module Regexp
# 地图情报
module MapInfo
# 停止变换
DAYNIGHT_STOP = /\[DN_STOP\]/i
# 使昼夜系统无效
DAYNIGHT_VOID = /\[DN_VOID\]/i
end
# 敌人队伍
module Troop
# 出现天色阶段
APPEAR_PHASE = /\[DN((?:[ ]*[\-]?\d+(?:[ ]*,)?)+)\]/i
end
end
#--------------------------------------------------------------------------
# ○ 确认敌人队伍的出现
# troop : 确认对象的敌人队伍
# phase : 确认天色阶段
#--------------------------------------------------------------------------
def self.troop_appear?(troop, phase = $game_system.daynight_phase)
# 确认出现
unless troop.appear_daynight_phase.empty?
return false unless troop.appear_daynight_phase.include?(phase)
end
# 确认没出现
unless troop.nonappear_daynight_phase.empty?
return false if troop.nonappear_daynight_phase.include?(phase)
end
return true
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# □ KGC::Commands
#==============================================================================
module KGC
module Commands
module_function
#--------------------------------------------------------------------------
# ○ 停止昼夜切换
#--------------------------------------------------------------------------
def stop_daynight
$game_system.daynight_change_enabled = false
end
#--------------------------------------------------------------------------
# ○ 启动昼夜却换
#--------------------------------------------------------------------------
def start_daynight
$game_system.daynight_change_enabled = true
end
#--------------------------------------------------------------------------
# ○ 获取现在的天色阶段名
#--------------------------------------------------------------------------
def get_daynight_name
return KGC::DayNight::PHASE[get_daynight_phase][0]
end
#--------------------------------------------------------------------------
# ○ 获取现在的日期名
# variable_id : 代入变量 ID
#--------------------------------------------------------------------------
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
#--------------------------------------------------------------------------
# ○获取现在的日期名
#--------------------------------------------------------------------------
def get_daynight_week_name
return KGC::DayNight::WEEK_NAME[get_daynight_week]
end
#--------------------------------------------------------------------------
# ○ 天色阶段的切换
# phase : 切换后的天色阶段
# duration : 切换时间(画面)
# pass_days : 经过日数 (省略时: 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
$game_map.need_refresh = true
end
#--------------------------------------------------------------------------
# ○ 转移到下一个天色阶段
# duration : 切换时间(画面)
#--------------------------------------------------------------------------
def transit_daynight_phase(duration = KGC::DayNight::PHASE_DURATION)
$game_screen.transit_daynight_phase(duration)
$game_map.need_refresh = true
end
#--------------------------------------------------------------------------
# ○ 返回到默认的色调
# duration : 切换时间(画面)
#--------------------------------------------------------------------------
def set_daynight_default(duration = KGC::DayNight::PHASE_DURATION)
$game_screen.set_daynight_default(duration)
$game_map.need_refresh = true
end
#--------------------------------------------------------------------------
# ○ 还原现在的天色阶段
# duration : 切换时间(画面)
#--------------------------------------------------------------------------
def restore_daynight_phase(duration = KGC::DayNight::PHASE_DURATION)
$game_screen.restore_daynight_phase(duration)
$game_map.need_refresh = true
end
end
end
class Game_Interpreter
include KGC::Commands
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ RPG::MapInfo
#==============================================================================
class RPG::MapInfo
#--------------------------------------------------------------------------
# ● 获取地图名
#--------------------------------------------------------------------------
def name
return @name.gsub(/\[.*\]/) { "" }
end
#--------------------------------------------------------------------------
# ○ 获取自制地图名
#--------------------------------------------------------------------------
def original_name
return @name
end
#--------------------------------------------------------------------------
# ○ 停止昼夜交替
#--------------------------------------------------------------------------
def daynight_stop
return @name =~ KGC::DayNight::Regexp::MapInfo::DAYNIGHT_STOP
end
#--------------------------------------------------------------------------
# ○ 使昼夜效果无效
#--------------------------------------------------------------------------
def daynight_void
return @name =~ KGC::DayNight::Regexp::MapInfo::DAYNIGHT_VOID
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ RPG::Area
#==============================================================================
unless $@
class RPG::Area
#--------------------------------------------------------------------------
# ○ 获取遇敌
#--------------------------------------------------------------------------
alias encounter_list_KGC_DayNight encounter_list
def encounter_list
list = encounter_list_KGC_DayNight.clone
# 确认出现条件
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
#--------------------------------------------------------------------------
# ○ 作成昼夜交替的存储
#--------------------------------------------------------------------------
def create_daynight_cache
@__appear_daynight_phase = []
@__nonappear_daynight_phase = []
# 出现的天色阶段
if @name =~ KGC::DayNight::Regexp::Troop::APPEAR_PHASE
$1.scan(/[\-]?\d+/).each { |num|
phase = num.to_i
if phase < 0
# 不出现
@__nonappear_daynight_phase << phase.abs
else
# 出现
@__appear_daynight_phase << phase
end
}
end
end
#--------------------------------------------------------------------------
# ○ 出现的天色阶段
#--------------------------------------------------------------------------
def appear_daynight_phase
create_daynight_cache if @__appear_daynight_phase == nil
return @__appear_daynight_phase
end
#--------------------------------------------------------------------------
# ○ 不出现的天色阶段
#--------------------------------------------------------------------------
def nonappear_daynight_phase
create_daynight_cache if @__nonappear_daynight_phase == nil
return @__nonappear_daynight_phase
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ Game_Temp
#==============================================================================
class Game_Temp
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_accessor :manual_daynight_duration # 手动改变天色阶段的标志
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
alias initialize_KGC_DayNight initialize
def initialize
initialize_KGC_DayNight
@manual_daynight_duration = nil
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ Game_System
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_writer :daynight_counter # 天色阶段转换的计数器
attr_writer :daynight_change_enabled # 使昼夜交替有效
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
alias initialize_KGC_DayNight initialize
def initialize
initialize_KGC_DayNight
@daynight_counter = 0
@daynight_change_enabled = true
end
#--------------------------------------------------------------------------
# ○ 获取天色阶段转换的计数器
#--------------------------------------------------------------------------
def daynight_counter
@daynight_counter = 0 if @daynight_counter == nil
return @daynight_counter
end
#--------------------------------------------------------------------------
# ○ 获取现在的天色阶段
#--------------------------------------------------------------------------
def daynight_phase
return $game_variables[KGC::DayNight::PHASE_VARIABLE]
end
#--------------------------------------------------------------------------
# ○ 变换现在的天色阶段
#--------------------------------------------------------------------------
def daynight_phase=(value)
$game_variables[KGC::DayNight::PHASE_VARIABLE] = value
end
#--------------------------------------------------------------------------
# ○ 获取使昼夜交替有效的标志
#--------------------------------------------------------------------------
def daynight_change_enabled
@daynight_change_enabled = 0 if @daynight_change_enabled == nil
return @daynight_change_enabled
end
#--------------------------------------------------------------------------
# ○ 进行天色阶段
#--------------------------------------------------------------------------
def progress_daynight_phase
self.daynight_phase += 1
if self.daynight_phase >= KGC::DayNight::PHASE.size
self.daynight_phase = 0
end
$game_map.need_refresh = true
end
#--------------------------------------------------------------------------
# ○ 获取现在的天色阶段对象
#--------------------------------------------------------------------------
def daynight_phase_object
return KGC::DayNight::PHASE[daynight_phase]
end
#--------------------------------------------------------------------------
# ○ 获取以前的天色阶段对象
#--------------------------------------------------------------------------
def previous_daynight_phase_object
return KGC::DayNight::PHASE[daynight_phase - 1]
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ Game_Screen
#==============================================================================
class Game_Screen
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :daynight_tone # 昼夜的色调
#--------------------------------------------------------------------------
# ● 清除
#--------------------------------------------------------------------------
alias clear_KGC_DayNight clear
def clear
clear_KGC_DayNight
clear_daynight
end
#--------------------------------------------------------------------------
# ○ 清除昼夜交替的变量
#--------------------------------------------------------------------------
def clear_daynight
@default_tone = Tone.new(0, 0, 0)
# 初期化用于确认移动的坐标
@daynight_x = 0
@daynight_y = 0
# 初期化用于更新天色阶段的计数器
@frame_count = Graphics.frame_count
@daynight_tone_duration = 0
apply_daynight
end
#--------------------------------------------------------------------------
# ○ 使用昼夜的色调
#--------------------------------------------------------------------------
def apply_daynight
return if $game_map == nil
# 切换成无效的地图时
if $game_map.daynight_void?
if @daynight_tone_changed
# 返回到处起的色调
@tone = @default_tone.clone
@daynight_tone_changed = false
end
@daynight_tone = @tone.clone
return
end
# 天色阶段奇怪时修复它
if $game_system.daynight_phase_object == nil
$game_system.daynight_phase = 0
end
# 使用现在的色调
@tone = $game_system.daynight_phase_object[1].clone
@daynight_tone = @tone.clone
# 现实时间经过时
if KGC::DayNight::METHOD == KGC::DayNight::METHOD_RTIME
time = Time.now
# 变换到调和的天色阶段
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
#--------------------------------------------------------------------------
# ○ 色调的获取
#--------------------------------------------------------------------------
def tone
if $game_temp.in_battle && KGC::DayNight::TONE_BACK_ONLY_IN_BATTLE
return @default_tone
else
return @tone
end
end
#--------------------------------------------------------------------------
# ● 色调更改的开始
# tone : 色调
# duration : 时间
#--------------------------------------------------------------------------
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
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
alias update_KGC_DayNight update
def update
update_KGC_DayNight
update_daynight_transit
end
#--------------------------------------------------------------------------
# ● 色调的更新
#--------------------------------------------------------------------------
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
#--------------------------------------------------------------------------
# ○ 天色阶段变换的更新
#--------------------------------------------------------------------------
def update_daynight_transit
# 不能手动切换时
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 # 将切换
return if $game_map.daynight_stop? # 停止
if KGC::DayNight::STOP_ON_EVENT
interpreter = ($game_temp.in_battle ? $game_troop.interpreter :
$game_map.interpreter)
return if interpreter.running? # 事件进行中
end
case KGC::DayNight::METHOD
when KGC::DayNight::METHOD_TIME # 时间
update_daynight_pass_time
when KGC::DayNight::METHOD_STEP # 步数
update_daynight_step
when KGC::DayNight::METHOD_RTIME # 现实时间
update_daynight_real_time
end
end
#--------------------------------------------------------------------------
# ○ 转换 : 时间切换
#--------------------------------------------------------------------------
def update_daynight_pass_time
# 计算出计算器的增加量
inc_count = Graphics.frame_count - @frame_count
# 加算量很奇怪时,取消
if inc_count >= 100
@frame_count = Graphics.frame_count
return
end
# 计算器的加算
$game_system.daynight_counter += inc_count
@frame_count = Graphics.frame_count
# 确认状态转换
count = $game_system.daynight_counter / Graphics.frame_rate
if count >= $game_system.daynight_phase_object[2]
transit_daynight_next
end
end
#--------------------------------------------------------------------------
# ○ 转换 : 步数
#--------------------------------------------------------------------------
def update_daynight_step
# 没有移动时 取消
return if @daynight_x == $game_player.x && @daynight_y == $game_player.y
@daynight_x = $game_player.x
@daynight_y = $game_player.y
# 计算器的加算
$game_system.daynight_counter += 1
# 确认状态转换
count = $game_system.daynight_counter
if count >= $game_system.daynight_phase_object[2]
transit_daynight_next
end
end
#--------------------------------------------------------------------------
# ○ 转换 : 现实时间
#--------------------------------------------------------------------------
def update_daynight_real_time
time = Time.now
# 确认状态的转换
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
#--------------------------------------------------------------------------
# ○ 转换到下一个状态
# duration : 转换时间
#--------------------------------------------------------------------------
def transit_daynight_next(duration = KGC::DayNight::PHASE_DURATION)
$game_system.daynight_counter = 0
$game_system.progress_daynight_phase
# 确认日数的经过
if $game_system.daynight_phase == KGC::DayNight::PASS_DAY_PHASE
$game_variables[KGC::DayNight::PASS_DAYS_VARIABLE] += 1
end
# 色调的切换
start_tone_change($game_system.daynight_phase_object[1], duration)
@daynight_tone_changed = true
end
#--------------------------------------------------------------------------
# ○ 还原到画面的状态(0, 0, 0)
# duration : 转换时间
#--------------------------------------------------------------------------
def set_daynight_default(duration)
start_tone_change(@default_tone, duration)
end
#--------------------------------------------------------------------------
# ○ 复原现在的天色阶段
# 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
#--------------------------------------------------------------------------
# ● 组合地图
# map_id : 地图 ID
#--------------------------------------------------------------------------
alias setup_KGC_DayNight setup
def setup(map_id)
setup_KGC_DayNight(map_id)
@screen.apply_daynight
end
#--------------------------------------------------------------------------
# ○ 是否停止昼夜交替
#--------------------------------------------------------------------------
def daynight_stop?
info = $data_mapinfos[map_id]
return false if info == nil
return (info.daynight_stop || info.daynight_void)
end
#--------------------------------------------------------------------------
# ○ 是否让昼夜交替无效
#--------------------------------------------------------------------------
def daynight_void?
info = $data_mapinfos[map_id]
return false if info == nil
return info.daynight_void
end
#--------------------------------------------------------------------------
# ● 遇敌的获取
#--------------------------------------------------------------------------
alias encounter_list_KGC_DayNight encounter_list
def encounter_list
list = encounter_list_KGC_DayNight.clone
# 确认出现条件
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
#--------------------------------------------------------------------------
# ● 袭击的精灵的作成
#--------------------------------------------------------------------------
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
#--------------------------------------------------------------------------
# ● 战斗层精灵的作成
#--------------------------------------------------------------------------
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
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
alias start_KGC_DayNight start
def start
$game_map.screen.clear_daynight
start_KGC_DayNight
end
end