赞 | 0 |
VIP | 0 |
好人卡 | 1 |
积分 | 1 |
经验 | 978 |
最后登录 | 2014-2-21 |
在线时间 | 28 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 28 小时
- 注册时间
- 2011-1-12
- 帖子
- 42
|
本帖最后由 爱丽丝·玛格特罗依德 于 2011-3-18 07:14 编辑
- #===============================================================================
- # ■ 简易时间系统
- #-------------------------------------------------------------------------------
- # 脚本说明及使用方法
- #
- #-------------------------------------------------------------------------------
- # 更新作者: 蕾米莉亚·斯卡雷特
- # 许可协议: NCP NAM STS
- # 项目版本: 1.0.20110309
- # 引用网址:
- #-------------------------------------------------------------------------------
- # - 3.0.20110316 By 蕾米莉亚·斯卡雷特
- # * 重写核心.
- # * 改写 alias 定义, 提高兼容性.
- # - 3.1.20110316 By 蕾米莉亚·斯卡雷特
- # * 优化 Remilia_Time 类计算方式.
- # - 3.2.20110317 By 蕾米莉亚·斯卡雷特
- # * 优化 Remilia_Time 类部分方法.
- # * 添加 Remilia_Time 类部分方法以兼容 Time 类
- # * 修改原脚本遗留下来的部分问题.
- #
- #===============================================================================
- $fscript = {} if $fscript == nil
- $fscript["Remilia Time"] = "3.2.20110317"
- #-------------------------------------------------------------------------------
- # ▼ 通用配置模块
- #-------------------------------------------------------------------------------
- module FSL
- module Time_byz
- #--------------初始化定义---------------
- # 起始时间 [秒,分,时,日,月, 年, 星期]
- INIT_TIME = [55,58,23,28,02,1000, 2]
- #--------------时间格式定义-------------
- # 时间流失方式
- # true.. 按帧数的倍数流失;false.. 按现实时间流失
- TIME_MODULE = true
- #---------------速度定义----------------
- # 流失速度(越大速度越慢)
- TIME_SPEED = 60
- # 流失速度单位
- # 1..时;2..分;3..秒;4..日
- TIME_UNIT = 3
-
- #---------------事件定义----------------
- TIME_EVENT = {
- # 事件的起始条件就是时间,但是时间的格式要与起始时间的相同。
- # 事件使用的是 公共事件,为了避免使用太多的公共事件,所以增加变量操作,
- # 以便于在相同的公共事件里可以使用条件分歧。
- # [秒,分,时,日,月, 年] => [变量ID,变量改变后的值,公共事件ID],
- [00,59,23,28,02,1000] => [1, 1, 1],
- } # 这个不要去掉
-
- #---------------窗口定义----------------
- WINDOW_X = 0
- WINDOW_Y = 0
-
- #-------------睡眠时间定义----------------
- # 小时
- SLEEP_TIME_HOUR = 8
- # 分
- SLEEP_TIME_MIN = 0
- # 秒
- SLEEP_TIME_SEC = 0
- =begin
- ---------------------------------------
- 时间间隔的判断
- ---------------------------------------
- 1. 首先需要先定义一个计时器
- $game_system.set_byz_timer(id)
- 其中的 id 可以是任何数字,字符串。
- 2. 然后在需要计算时间间隔的地方使用 条件分歧 里的脚本, 里面可以写上
- $game_system.after_time(id) > 5
- 这里的 id 要和定义的时候一致。 这个的意思是 时间经过 5秒后.....
-
- =end
- end
- end
- class Remilia_Time
- #--------------------------------------------------------------------------
- # ● 常量定义
- #--------------------------------------------------------------------------
- BIG_MON = [1, 3, 5, 7, 8, 10, 12]
- SMALL_MON = [4, 6, 9, 11]
- WDAY_VOCAB = [nil, "一", "二", "三", "四", "五", "六", "日"]
- WDAY = 6
- SEC = 5
- MIN = 4
- HOUR = 3
- DAY = 2
- MON = 1
- YEAR = 0
- #--------------------------------------------------------------------------
- # ● 初始化
- #--------------------------------------------------------------------------
- def initialize(year, mon, day, hour, min, sec, wday)
- set_time(year, mon, day, hour, min, sec, wday)
- end
- #--------------------------------------------------------------------------
- # ● 接口
- #--------------------------------------------------------------------------
- def sec; @time[SEC]; end
- def min; @time[MIN]; end
- def hour; @time[HOUR]; end
- def mday; @time[DAY]; end
- def mon; @time[MON]; end
- def wday; @time[WDAY]; end
- def year; @time[YEAR]; end
- #--------------------------------------------------------------------------
- # ● 调整
- #--------------------------------------------------------------------------
- def to_a
- [@time[SEC], @time[MIN], @time[HOUR], @time[DAY], @time[MON], @time[YEAR]]
- end
- #--------------------------------------------------------------------------
- # ● 设定时间
- #--------------------------------------------------------------------------
- def set_time(year, mon, day, hour, min, sec, wday)
- @time = [year, mon, day, hour, min, sec, wday]
- improve
- end
- #--------------------------------------------------------------------------
- # ● 重定义 +
- #--------------------------------------------------------------------------
- def +(number)
- add_time(number, SEC)
- return self
- end
- #--------------------------------------------------------------------------
- # ● 类型转换
- #--------------------------------------------------------------------------
- def to_time
- return Time.local(@time[YEAR], @time[MON], @time[DAY], @time[HOUR], @time[MIN], @time[SEC])
- end
- #--------------------------------------------------------------------------
- # ● 复制
- #--------------------------------------------------------------------------
- def clone
- return Remilia_Time.new(@time[YEAR], @time[MON], @time[DAY], @time[HOUR], @time[MIN], @time[SEC], @time[WDAY])
- end
- #--------------------------------------------------------------------------
- # ● 重定义 -
- #--------------------------------------------------------------------------
- def -(time)
- min_year = self.year >= time.year ? time.year : self.year
- gap = min_year < 1980 ? (1980 - min_year) : 0
- save_time1 = self.clone
- save_time1.add_time(gap, YEAR)
- save_time = time.clone
- save_time.add_time(gap, YEAR)
- return save_time1.to_time - save_time.to_time
- end
- #--------------------------------------------------------------------------
- # ● 增加时间
- #--------------------------------------------------------------------------
- def add_time(number, type)
- @time[type] += number
- improve
- end
- #--------------------------------------------------------------------------
- # ● 判断闰年
- #--------------------------------------------------------------------------
- def leap_year?
- year = @time[YEAR]
- return (year % 4 == 0 and (year % 100 != 0 or year % 400 == 0))
- end
- #--------------------------------------------------------------------------
- # ● 计算该月的总天数
- #--------------------------------------------------------------------------
- def total_day
- day = 0
- if SMALL_MON.include?(@time[MON])
- day = 30
- elsif BIG_MON.include?(@time[MON])
- day = 31
- elsif @time[MON] == 2 and leap_year?
- day = 29
- else
- day = 28
- end
- return day
- end
- #--------------------------------------------------------------------------
- # ● 调整时间
- #--------------------------------------------------------------------------
- def improve
- if @time[SEC] >= 60
- @time[MIN] += @time[SEC] / 60
- @time[SEC] %= 60
- end
- if @time[MIN] >= 60
- @time[HOUR] += @time[MIN] / 60
- @time[MIN] %= 60
- end
- if @time[HOUR] >= 24
- n = @time[HOUR] / 24
- @time[HOUR] %= 24
- @time[DAY] += n
- @time[WDAY] = (@time[WDAY] + n) % 7
- end
- while @time[DAY] > 28
- day = total_day
- if @time[DAY] > day
- @time[DAY] -= day
- @time[MON] += 1
- end
- end
- if @time[MON] > 12
- @time[MON] -= 12
- @time[YEAR] += 1
- end
- end
- #--------------------------------------------------------------------------
- # ● 格式化时间
- #--------------------------------------------------------------------------
- def strftime(format)
- format_time = format.clone
- format_time.gsub!(/%Y/i) do |s|
- s = @time[YEAR].to_s
- end
- format_time.gsub!(/%(|\d\d)M/i) do |s|
- s = $1 ? sprintf("%#{$1}d", @time[MON]) : @time[MON].to_s
- end
- format_time.gsub!(/%(|\d\d)D/i) do |s|
- s = $1 ? sprintf("%#{$1}d", @time[DAY]) : @time[DAY].to_s
- end
- format_time.gsub!(/%(|\d\d)H/i) do |s|
- s = $1 ? sprintf("%#{$1}d", @time[HOUR]) : @time[HOUR].to_s
- end
- format_time.gsub!(/%(|\d\d)MI/i) do |s|
- s = $1 ? sprintf("%#{$1}d", @time[MIN]) : @time[MIN].to_s
- end
- format_time.gsub!(/%(|\d\d)S/i) do |s|
- s = $1 ? sprintf("%#{$1}d", @time[SEC]) : @time[SEC].to_s
- end
- format_time.gsub!(/%X/i) do |s|
- s = sprintf("%02d:%02d:%02d", @time[HOUR], @time[MIN], @time[SEC])
- end
- format_time.gsub!(/%W/i) do |s|
- s = "星期#{WDAY_VOCAB[@time[WDAY] + 1]}"
- end
- return format_time
- end
- end
-
- #==============================================================================
- # ■ Game_System
- #------------------------------------------------------------------------------
- # 处理系统附属数据的类。也可执行诸如交通工具、 BGM 等管理之类的功能。
- # 本类的实例请参考$game_system 。
- #==============================================================================
- class Game_System
- include FSL
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_accessor :time_now
- attr_accessor :byz_timer
- attr_accessor :run_time
- #--------------------------------------------------------------------------
- # ● 初始化对像
- #--------------------------------------------------------------------------
- alias old_initialize initialize
- def initialize
- if Time_byz::TIME_MODULE
- wday = Time_byz::INIT_TIME[6];
- year = Time_byz::INIT_TIME[5];
- mon = Time_byz::INIT_TIME[4];
- day = Time_byz::INIT_TIME[3];
- hour = Time_byz::INIT_TIME[2];
- min = Time_byz::INIT_TIME[1];
- sec = Time_byz::INIT_TIME[0];
- @time_now = Remilia_Time.new(year, mon, day, hour, min, sec, wday);
- else
- @time_now = Time.new;
- end
- @byz_timer = {};
- @run_time = true;
- old_initialize
- end
- #--------------------------------------------------------------------------
- # ● 增加时间
- #--------------------------------------------------------------------------
- def add_time(unit)
- case unit
- when 4
- @time_now += 3600 * 24;
- when 3
- @time_now += 1;
- when 2
- @time_now += 60;
- when 1
- @time_now += 3600;
- end
- end
- #--------------------------------------------------------------------------
- # ● 设定时间计时器
- #--------------------------------------------------------------------------
- def set_byz_timer(id)
- @byz_timer[id] = @time_now.clone;
- end
- #--------------------------------------------------------------------------
- # ● 计算时间 (秒数)
- #--------------------------------------------------------------------------
- def after_time(id)
- return 0 if @byz_timer[id] == nil;
- return @time_now - @byz_timer[id];
- end
- #--------------------------------------------------------------------------
- # ● 返回时间[秒,分,时,日,月, 年, 星期]
- #--------------------------------------------------------------------------
- def return_time(type, array_time)
- logo = 6;
- now_time = [];
- loop do
- counts_the_power = type /(10 ** logo);
- type %= 10 ** logo;
- if counts_the_power == 1;
- case logo
- when 6
- times = @time_now.sec;
- when 5
- times = @time_now.min;
- when 4
- times = @time_now.hour;
- when 3
- times = @time_now.mday;
- when 2
- times = @time_now.mon;
- when 1
- times = @time_now.year;
- when 0
- times = @time_now.wday;
- end
- now_time.push(times);
- end
- logo -= 1;
- break if logo < 0;
- end
- return now_time == array_time;
- end
- #--------------------------------------------------------------------------
- # ● 时间跳跃 1..时;2..分;3..秒
- #--------------------------------------------------------------------------
- def bound_times(type, number)
- case type
- when 3
- @time_now += number;
- when 2
- @time_now += 60 * number;
- when 1
- @time_now += 3600 * number;
- end
- end
- #--------------------------------------------------------------------------
- # ● 睡眠
- #--------------------------------------------------------------------------
- def sleep_time
- hour = Time_byz::SLEEP_TIME_HOUR % 24;
- min = Time_byz::SLEEP_TIME_MIN % 60;
- sec = Time_byz::SLEEP_TIME_SEC % 60;
- @time_now += 3600 * 24;
- year = @time_now.year
- mon = @time_now.mon
- day = @time_now.mday
- wday = @time_now.wday
- if Time_byz::TIME_MODULE
- @time_now = Remilia_Time.new(year, mon, day, hour, min, sec, wday)
- else
- @time_now = Time.local(year, mon, day, hour, min, sec)
- end
- end
-
- end
- #==============================================================================
- # ■ Window_Byz_Time
- #------------------------------------------------------------------------------
- # 调试画面、个别显示开关及变量的窗口。
- #==============================================================================
- class Window_Byz_Time < Window_Base
- include FSL
- #--------------------------------------------------------------------------
- # ● 初始化对像
- # x : 窗口 X 座标
- # y : 窗口 Y 座标
- #--------------------------------------------------------------------------
- def initialize(x, y)
- super(x, y, 170, 87);
- if Time_byz::TIME_MODULE
- @time_speed = Time_byz::TIME_SPEED;
- else
- @time_speed = 60;
- end
- @time = @time_speed - 1;
- refresh;
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- return unless $game_system.run_time;
- @time += 1;
- if @time_speed == @time;
- $game_system.add_time(Time_byz::TIME_UNIT);
- draw_time($game_system.time_now);
- event_run;
- @time = 0;
- end
- end
- #--------------------------------------------------------------------------
- # ● 描绘
- #--------------------------------------------------------------------------
- def draw_time(time)
- self.contents.clear;
- text = $game_system.time_now.strftime("%X")
- self.contents.draw_text(0, 0, 105, WLH, text, 2);
- text = $game_system.time_now.strftime("%Y年%m月%d日");
- self.contents.draw_text(0, 32, 170, WLH, text);
- end
- #--------------------------------------------------------------------------
- # ● 启动事件
- #--------------------------------------------------------------------------
- def event_run
- array = ($game_system.time_now.to_a)[0,6];
- if Time_byz::TIME_EVENT[array] != nil
- unless !$scene.is_a?(Scene_Map) or $game_message.visible or $game_temp.in_battle
- variables_id = Time_byz::TIME_EVENT[array][0];
- variables_number = Time_byz::TIME_EVENT[array][1];
- commonevent_id = Time_byz::TIME_EVENT[array][2];
- $game_variables[variables_id] = variables_number;
- $game_temp.common_event_id = commonevent_id;
- end
- end
- end
- end
- #==============================================================================
- # ■ Scene_Map
- #------------------------------------------------------------------------------
- # 处理地图画面的类。
- #==============================================================================
- class Scene_Map < Scene_Base
- include FSL
- alias :remilia_time_start :start
- #--------------------------------------------------------------------------
- # ● 开始处理
- #--------------------------------------------------------------------------
- def start
- remilia_time_start;
- @time_window = Window_Byz_Time.new(Time_byz::WINDOW_X, Time_byz::WINDOW_Y);
- end
- alias remilia_time_terminate terminate
- #--------------------------------------------------------------------------
- # ● 结束处理
- #--------------------------------------------------------------------------
- def terminate
- remilia_time_terminate;
- @time_window.dispose;
- end
- alias remilia_time_update update
- #--------------------------------------------------------------------------
- # ● 更新画面
- #--------------------------------------------------------------------------
- def update
- remilia_time_update;
- @time_window.refresh;
- end
- end
-
复制代码 已修改. 用法和以前的一样.
只是使用这个新版本的话, 就需要删除旧的脚本.
唯一的一个插件就是咱之前的那个回帖. 脚本可以单独运行 |
|