#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
#_/ ◆昼夜切り替え - KGC_DayNight◆
#_/----------------------------------------------------------------------------
#_/ ゲーム中に昼夜の概念を作成します。
#_/ Makes the concept of day and night in the game.
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
#==============================================================================
# ★ カスタマイズ項目 - Customize ★
#==============================================================================
module KGC
# ◆旧式のメソッドを使用可能にする
# どうしても昔のまま使いたい場合だけ true。
DAYNIGHT_ENABLE_OLD_METHOD = false
# ◆昼夜切り替え方式
# 0:時間経過 1:歩数 2:現実時間(微妙)
DAYNIGHT_METHOD = 1
# ◆イベント中は時間を止める
# DAYNIGHT_METHOD で「時間経過」使用時のみ有効
DAYNIGHT_EVENT_STOP = true
# ◆戦闘時は、背景のみ色調を適用する
DAYNIGHT_TONE_BACK_ONLY = true
# ◆日付が変わる状態
# ここで指定した状態になったとき、日数を加算する。
# 初期状態の場合 0:昼 1:夕方 2:夜 3:朝
# ※現実時間の場合、現実と同じ日数にはならないので注意。
DAYNIGHT_PASS_PHASE = 3
# ◆状態切り替え時のフェード時間【単位:フレーム】
# 省略時もこの値を使用します。
DAYNIGHT_DURATION = 40
# ◆曜日名(あまり意味は無い)
DAYNIGHT_WEEK_NAME = ["日", "月", "火", "水", "木", "金", "土"]
# ★☆以下の3項目は全て同じ要素数にしてください☆★
# 処理の都合上、最初を昼にするとベター
### ** Please make all of the following 3 items the same number. **
# ◆昼夜の名称(あまり意味は無い)
DAYNIGHT_NAME = ["昼", "夕方", "夜", "朝"]
# ◆昼夜の色調(よく分からない場合はこのまま)
DAYNIGHT_TONE = [Tone.new(0, 0, 0),
Tone.new(-32, -96, -96),
Tone.new(-128, -128, -32),
Tone.new(-48, -48, -16)]
# ◆昼夜切り替え時間(次の状態へ移るまでの期間)
# 切り替え方式が時間の場合は秒、歩数の場合は歩数そのまま。
# 戦闘中は切り替え時間が10倍(1/10の速度)
# 現実時間の場合、次の状態へ切り替える時刻(24時間方式)
DAYNIGHT_TIME = [30, 10, 25, 10]
# DAYNIGHT_TIME = [16, 20, 6, 10]
# ↑現実時間用のサンプル。試す場合はコメントを解除。
# The sample of Real time.
end
#### DAYNIGHT_METHOD
### Method of change day and night.
# 0..Passage of time. 1..Number of steps. 2..Real time.(imperfection)
#### DAYNIGHT_EVENT_STOP
### Time is stopped when event is running.
# When DAYNIGHT_METHOD is 0, this is effective.
#### DAYNIGHT_PASS_PHASE
### Phase which date is changed.
# 0..Day 1..Evening 2..Night 3..Morning
#### DAYNIGHT_DURATION
### Duration which phase is changed. {Unit : frame}
# When duration is omitted, this value is applied.
#### DAYNIGHT_WEEK_NAME
### The day of the week names. (Not so significant.)
#DAYNIGHT_WEEK_NAME = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
#### DAYNIGHT_NAME
### Day and night name. (Not so significant.)
#DAYNIGHT_NAME = ["Day", "Evening", "Night", "Morning"]
#### DAYNIGHT_TONE
### Tone of day and night.
# (If you don't understanding well, please leave this as it is.)
#### DAYNIGHT_TONE_BACK_ONLY
### In battle, it applies tone of day and night to background.
#### DAYNIGHT_TIME
### Necessary period until changing for the next phase.
# Passage of time -- sec.
# Number of steps -- steps.
# Real time -------- time when phase is changed.
# In battle, time progress speed becomes 1/10.
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
$imported = {} if $imported == nil
$imported["DayNight"] = true
module DayNight
#--------------------------------------------------------------------------
# ● 変数初期化
#--------------------------------------------------------------------------
def self._init_var_
$game_system.daynight_count = 0 if $game_system.daynight_count == nil
$game_system.daynight_phase = 0 if $game_system.daynight_phase == nil
$game_system.daynight_pass_days = 0 if $game_system.daynight_pass_days == nil
end
#--------------------------------------------------------------------------
# ● 現在の状態
#--------------------------------------------------------------------------
def self.now
# 現在の状態を返す
return $game_system.daynight_phase
end
#--------------------------------------------------------------------------
# ● 状態名取得
#--------------------------------------------------------------------------
def self.now_name
# 現在の状態名を返す
return KGC::DAYNIGHT_NAME[self.now]
end
#--------------------------------------------------------------------------
# ● 昼夜手動切り替え
# phase : 切り替え後の状態INDEX
# duration : 切り替え時間(フレーム) (省略時 : KGC::DAYNIGHT_DURATION)
# pass_days : 経過させる日数 (省略時:0)
#--------------------------------------------------------------------------
def self.change(phase, duration = KGC::DAYNIGHT_DURATION, pass_days = 0)
# カウント初期化
$game_system.daynight_count = 0
# フェーズ更新
$game_system.daynight_phase = phase
# 手動切り替え有効
$game_temp.manual_daynight_change = duration
# 日数経過
$game_system.daynight_pass_days += pass_days
end
#--------------------------------------------------------------------------
# ● 次の状態へ移行
# duration : 切り替え時間(フレーム) (省略時 : KGC::DAYNIGHT_DURATION)
#--------------------------------------------------------------------------
def self.change_next(duration = KGC::DAYNIGHT_DURATION)
$game_screen.change_daynight_next(duration)
end
#--------------------------------------------------------------------------
# ● 現在の曜日
#--------------------------------------------------------------------------
def self.now_week
# 現在の曜日を返す
if KGC::DAYNIGHT_METHOD == 2
return Time.now.wday
else
return $game_system.daynight_pass_days % KGC::DAYNIGHT_WEEK_NAME.size
end
end
#--------------------------------------------------------------------------
# ● 曜日名取得
#--------------------------------------------------------------------------
def self.now_week_name
# 現在の曜日名を返す
return KGC::DAYNIGHT_WEEK_NAME[self.now_week]
end
#--------------------------------------------------------------------------
# ● デフォルトの状態(0, 0, 0)に戻す
# duration : 切り替え時間(フレーム) (省略時 : KGC::DAYNIGHT_DURATION)
#--------------------------------------------------------------------------
def self.set_default(duration = KGC::DAYNIGHT_DURATION)
$game_screen.set_daynight_default(duration)
end
#--------------------------------------------------------------------------
# ● 現在の状態を適用
# duration : 切り替え時間(フレーム) (省略時 : KGC::DAYNIGHT_DURATION)
#--------------------------------------------------------------------------
def self.apply(duration = KGC::DAYNIGHT_DURATION)
$game_screen.apply_daynight(duration)
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ Game_Temp
#==============================================================================
class Game_Temp
attr_accessor :manual_daynight_change
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
alias initialize_KGC_DayNight initialize
def initialize
# 元の処理を実行
initialize_KGC_DayNight
@manual_daynight_change = false
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ Game_System
#==============================================================================
class Game_System
attr_accessor :daynight_count, :daynight_phase, :daynight_pass_days,
:daynight_change, :daynight_change_battle
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
alias initialize_KGC_DayNight initialize
def initialize
initialize_KGC_DayNight
@daynight_count = @daynight_phase = @daynight_pass_days = 0
@daynight_change = true
@daynight_change_battle = true
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ Game_Screen
#==============================================================================
class Game_Screen
attr_reader :daynight_tone
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
alias initialize_KGC_DayNight initialize
def initialize
# 元の処理を実行
initialize_KGC_DayNight
# とりあえず現在の状態に設定
@default_tone = Tone.new(0, 0, 0)
@tone = KGC::DAYNIGHT_TONE[$game_system.daynight_phase].clone
@daynight_tone = @tone.clone
# 移動判定用座標
@x = @y = 0
# フレーム更新用カウント初期化
@frame_count = Graphics.frame_count
@daynight_tone_duration = 0
end
#--------------------------------------------------------------------------
# ● 色調の取得
#--------------------------------------------------------------------------
def tone
if $game_temp.in_battle && KGC::DAYNIGHT_TONE_BACK_ONLY
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)
start_tone_change_KGC_DayNight(tone, duration)
@daynight_tone_target = tone.clone
@daynight_tone_duration = duration
if @daynight_tone_duration == 0
@daynight_tone = @daynight_tone_target.clone
end
end
#--------------------------------------------------------------------------
# ● フレーム更新
#--------------------------------------------------------------------------
alias update_KGC_DayNight update
def update
update_KGC_DayNight
if @daynight_tone_duration >= 1
d = @daynight_tone_duration
@daynight_tone.red =
(@daynight_tone.red * (d - 1) + @daynight_tone_target.red) / d
@daynight_tone.green =
(@daynight_tone.green * (d - 1) + @daynight_tone_target.green) / d
@daynight_tone.blue =
(@daynight_tone.blue * (d - 1) + @daynight_tone_target.blue) / d
@daynight_tone.gray =
(@daynight_tone.gray * (d - 1) + @daynight_tone_target.gray) / d
@daynight_tone_duration -= 1
end
# 昼夜切り替え判定
if (!$game_temp.in_battle && $game_system.daynight_change) ||
($game_temp.in_battle && $game_system.daynight_change &&
$game_system.daynight_change_battle)
case KGC::DAYNIGHT_METHOD
when 0 # 時間判定
update_daynight_pass_time
when 1 # 歩数判定
update_daynight_step
when 2 # 現実時間
update_daynight_real_time
end
end
# 手動切り替えが行われた場合
if $game_temp.manual_daynight_change != nil
# 色調切り替え
start_tone_change(KGC::DAYNIGHT_TONE[$game_system.daynight_phase],
KGC::DAYNIGHT_DURATION)
# 手動切り替え解除
$game_temp.manual_daynight_change = nil
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
# イベント中は戻る
if KGC::DAYNIGHT_EVENT_STOP && $game_system.map_interpreter.running?
@frame_count = Graphics.frame_count
return
end
# カウント加算
if $game_temp.in_battle
inc_count /= 10.0
$game_system.daynight_count += inc_count
else
$game_system.daynight_count += inc_count
end
# カウントを戻す
@frame_count = Graphics.frame_count
# 状態移行判定
count = $game_system.daynight_count / Graphics.frame_rate
if count >= KGC::DAYNIGHT_TIME[$game_system.daynight_phase]
# 次の状態へ移行
change_daynight_next
end
end
private :update_daynight_pass_time
#--------------------------------------------------------------------------
# ● 更新 : 歩数
#--------------------------------------------------------------------------
def update_daynight_step
# 移動判定
if @x != $game_player.x || @y != $game_player.y
# 座標更新
@x = $game_player.x
@y = $game_player.y
# カウント加算
$game_system.daynight_count += 1
# 状態移行判定
count = $game_system.daynight_count
if count >= KGC::DAYNIGHT_TIME[$game_system.daynight_phase]
# 次の状態へ移行
change_daynight_next
end
end
end
private :update_daynight_step
#--------------------------------------------------------------------------
# ● 更新 : 現実時間
#--------------------------------------------------------------------------
def update_daynight_real_time
# 現在の時間を取得
time = Time.now
# 状態移行判定
time1 = KGC::DAYNIGHT_TIME[$game_system.daynight_phase]
time2 = KGC::DAYNIGHT_TIME[$game_system.daynight_phase - 1]
if time2 != nil && time1 < time2
change = time.hour < time2 && time1 <= time.hour
else
change = time1 <= time.hour
end
if change
# 次の状態へ移行
change_daynight_next
end
end
private :update_daynight_real_time
#--------------------------------------------------------------------------
# ● 次の状態へ移行
#--------------------------------------------------------------------------
def change_daynight_next(duration = KGC::DAYNIGHT_DURATION)
$game_system.daynight_count = 0
$game_system.daynight_phase += 1
# 最後の状態に達した場合
if $game_system.daynight_phase >= KGC::DAYNIGHT_TONE.size
# 最初の状態に戻す
$game_system.daynight_phase = 0
end
# 日数経過判定
if $game_system.daynight_phase == KGC::DAYNIGHT_PASS_PHASE
$game_system.daynight_pass_days += 1
end
# 色調切り替え
start_tone_change(KGC::DAYNIGHT_TONE[$game_system.daynight_phase],
duration)
end
#--------------------------------------------------------------------------
# ● デフォルトの状態(0, 0, 0)に戻す
#--------------------------------------------------------------------------
def set_daynight_default(duration)
start_tone_change(Tone.new(0, 0, 0), duration)
end
#--------------------------------------------------------------------------
# ● 現在の状態を適用
#--------------------------------------------------------------------------
def apply_daynight(duration)
start_tone_change(KGC::DAYNIGHT_TONE[$game_system.daynight_phase], duration)
end
if KGC::DAYNIGHT_ENABLE_OLD_METHOD
#--------------------------------------------------------------------------
# ● デフォルトの状態(0, 0, 0)に戻す
# duration : 切り替え時間(フレーム) (省略時:40)
#--------------------------------------------------------------------------
def daynight_default(duration = KGC::DAYNIGHT_DURATION)
start_tone_change(Tone.new(0, 0, 0), duration)
end
#--------------------------------------------------------------------------
# ● 現在の状態を適用
# duration : 切り替え時間(フレーム) (省略時:40)
#--------------------------------------------------------------------------
def daynight_apply(duration = KGC::DAYNIGHT_DURATION)
start_tone_change(KGC::DAYNIGHT_TONE[$game_system.daynight_phase], duration)
end
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ Game_Map
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# ● エンカウントリストの取得
#--------------------------------------------------------------------------
alias encounter_list_KGC_DayNight encounter_list
def encounter_list
# 元の処理を実行
list = encounter_list_KGC_DayNight.dup
# 出現条件判定
list.each_index { |i|
appear = false
troop = $data_troops[list[i]]
# 出現条件が無い場合は次へ
next unless troop.name =~ /\[DN((?:[ ]*[\-]?\d+(?:,[ ]*)?)+)\]/i
# 出現条件を適用
$1.split(/,/).each { |dn|
dn.gsub!(/[ ]/) {""}
appear |= dn[0, 1] == "-" ?
$game_system.daynight_phase != dn.to_i.abs :
$game_system.daynight_phase == dn.to_i
}
list[i] = nil unless appear
}
return list.compact
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ Spriteset_Battle
#==============================================================================
if KGC::DAYNIGHT_TONE_BACK_ONLY
class Spriteset_Battle
#--------------------------------------------------------------------------
# ● フレーム更新
#--------------------------------------------------------------------------
alias update_KGC_DayNight update
def update
update_KGC_DayNight
@battleback_sprite.tone = $game_screen.daynight_tone
end
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
#==============================================================================
# ■ Scene_Map
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# ● メイン処理
#--------------------------------------------------------------------------
alias main_KGC_DayNight main
def main
DayNight._init_var_
main_KGC_DayNight
end
end