赞 | 0 |
VIP | 0 |
好人卡 | 2 |
积分 | 1 |
经验 | 952 |
最后登录 | 2013-12-27 |
在线时间 | 336 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 336 小时
- 注册时间
- 2010-8-26
- 帖子
- 428
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 巧克力猫咪 于 2010-11-27 22:27 编辑
- module Kernel
- #----------------------------------------------------------------------------
- # 随机返回 0 到 n 范围内的 m 个不同数 (n>0)
- #----------------------------------------------------------------------------
- def different_rand(n, m)
- return [] if m == 0
- result = different_rand(n-1, m-1)
- temp = rand(n)
- result.concat result.include?(temp) ? [n] : [temp]
- end
- #----------------------------------------------------------------------------
- # 以线性概率返回 0 到 n 范围内的某数 (n>0)
- # downto: 降序,否则升序
- #----------------------------------------------------------------------------
- def linear_rand(n, downto = true)
- rd = rand((n + 1) * n / 2)
- sum = 0
- for i in 0...n
- sum += downto ? n - i : i + 1
- return i if sum > rd
- end
- return downto ? 0 : n - 1
- end
- #----------------------------------------------------------------------------
- # 随机返回 n 到 m 范围内的某数 (允许负值)
- #----------------------------------------------------------------------------
- def range_rand(n, m = 0)
- min,max = n,m
- min,max = m,n if n > m
- return min + rand(max-min)
- end
- end
复制代码- #==============================================================================
- # 复杂装备系统之随机属性 by 沉影不器
- #------------------------------------------------------------------------------
- # 说明: 让装备类似暗黑那样附加随机属性,目前有17种属性元素可供组合,允许按
- # 能力百分比加成.
- #
- # 附加属性的名称允许多个(按能力从小大到排列),用英文逗号隔开,自动按
- # 附加能力大小选择词缀
- #
- # 极品爆率不影响物品掉落机率,而是指掉落的物品带附加属性的机率
- #
- # 获得随机属性装备的方法:
- # 事件脚本中输入 get_weapon(母版武器id, 数量, 附加属性1, 附加属性2...)
- # 或者直接指定附加属性数 get_weapon(母版武器id, 数量, 附加属性数)
- # 将随机生成指定附加属性数的装备
- # 获得防具方法是 get_armor() 参数含义同上
- #
- # 获得普通装备的方法:
- # 事件脚本中输入 get_weapon(母版武器id, 数量)
- # 获得防具方法是 get_armor() 参数含义同上
- #==============================================================================
- # 参数设定
- #==============================================================================
- module Game_Equip
- ## 最大附加属性数
- GiftMax = 5
- ## 附加属性影响价格基数
- GiftPrice = 10
- ## 极品爆率最低值和最高值(0到100)
- Equip_Chance = [30, 50]
-
- ## 附加属性各参数:
- ## name 添加到装备前的修饰词
- ## max 该属性最大值
- ## weight 权重(最大值的权重,用于计算价值,用于计算颜色也行)
- ## percent 是否按百分比计算
- Gift = Struct.new(:name, :max, :weight, :percent)
- Gifts = [
- # 攻击
- Gift.new("噩", 25, 15, false),
- Gift.new("兽", 25, 10, true),
- # 防御
- Gift.new("武", 25, 10, false),
- Gift.new("神", 25, 5, true),
- # 精神
- Gift.new("风", 25, 8, false),
- Gift.new("光", 25, 12, true),
- # 敏捷
- Gift.new("皇", 25, 10, false),
- Gift.new("黑", 25, 15, true),
- # hp
- Gift.new("血", 80, 20, false),
- Gift.new("燃", 15, 20, true),
- # mp
- Gift.new("雷", 80, 15, false),
- Gift.new("月", 15, 15, true),
- # 命中
- Gift.new("幻", 10, 5,false),
- # 闪避
- Gift.new("影", 10, 5, false),
- # 暴击
- Gift.new("暴", 5, 5, false),
- # 经验
- Gift.new("魔", 20, 10, true),
- # 极品爆率 ###(待定)
- Gift.new("暗", 30, 10, false)
- ]
- end
- #==============================================================================
- # ■ Game_Equip 自定义装备模块
- #==============================================================================
- module Game_Equip
- #--------------------------------------------------------------------------
- # ● 物品(装备)重生
- # item: 物品
- # *gift: 附加属性(留空表示无属性,数字表示指定数量随机属性)
- #--------------------------------------------------------------------------
- def self.reini(item, *gift)
- return if item.nil?
- result = item.clone
- gifts = *gift
- gifts.flatten! if gifts.is_a? Array
- ## 附加属性为空或指定为(0)时,直接返回母版
- return self.result(result) if gifts.nil? or gifts == 0
- ## 指定附加属性数量时
- if gifts.is_a? Integer
- ## 控制数量
- num = [gifts, GiftMax].min
- gifts = []
- ## 随机生成指定数量的附加属性
- rd = different_rand(Gifts.size-1, num)
- rd.each{|n| gifts.push Game_Gift.new(n)}
- end
- gifts = [gifts].flatten
- return self.result(result) if gifts.empty?
- ## 处理数据
- result.gifts = gifts
- name = ""
- price = 0
- for gift in gifts
- name += gift.name
- price += gift.weight * GiftPrice
- end
- ## 设定名称
- result.name = name + '' + result.name
- ## 设定价格
- result.price += price.round
- ## 设定颜色
- result.text_color = gifts.size
- return self.result(result)
- end
- #--------------------------------------------------------------------------
- # ● 返回结果
- # item: 物品
- #--------------------------------------------------------------------------
- def self.result(item)
- case item
- when RPG::Item
-
- when RPG::Weapon
- item.base_id = item.id
- item.id = $data_weapons.size
- $data_weapons << item
- when RPG::Armor
- item.base_id = item.id
- item.id = $data_armors.size
- $data_armors << item
- end
- return item
- end
- #--------------------------------------------------------------------------
- # ● 物品(装备)重生
- # item_id: 物品id
- # type: 类型
- # *gift: 附加属性(留空表示无属性,数字表示指定数量随机属性)
- #--------------------------------------------------------------------------
- def self.reini_id(item_id, type, *gift)
- ## 排除装备id为零的情况
- return 0 if item_id == 0
- case type
- when 0
- item = $base_weapons[item_id]
- when 1
- item = $base_armors[item_id]
- end
- return self.reini(item, *gift).id
- end
- end
- #==============================================================================
- # ■ Game_Gift 装备附加能力
- #==============================================================================
- class Game_Gift
- include Game_Equip
- #--------------------------------------------------------------------------
- # ● 读取口
- #--------------------------------------------------------------------------
- attr_reader :type
- attr_reader :value
- attr_reader :name
- #--------------------------------------------------------------------------
- # ● 初始化
- #--------------------------------------------------------------------------
- def initialize(type = nil, value = nil)
- get_type(type)
- get_value(value)
- get_name
- end
- #--------------------------------------------------------------------------
- # ● 获取属性
- #--------------------------------------------------------------------------
- def get_type(type)
- unless type.nil? or type > Gifts.size or type < 0
- @type = type
- else
- @type = rand(Gifts.size - 1)
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取品质值
- #--------------------------------------------------------------------------
- def get_value(value)
- unless value.nil? or value.abs > max
- @value = value
- else
- @value = linear_rand(max) + 1
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取名称
- #--------------------------------------------------------------------------
- def get_name
- names = Gifts[@type].name.split(/,/)
- n = (@value.abs-1)/(max.to_f/names.size)
- @name = names[n.truncate]
- end
- #--------------------------------------------------------------------------
- # ● 获取最大值
- #--------------------------------------------------------------------------
- def max
- return Gifts[@type].max
- end
- #--------------------------------------------------------------------------
- # ● 获取权重
- #--------------------------------------------------------------------------
- def weight
- return @value > 0 ? @value / max.to_f * Gifts[@type].weight : 0
- end
- #--------------------------------------------------------------------------
- # ● 获取是否百分比
- #--------------------------------------------------------------------------
- def percent
- return Gifts[@type].percent
- end
-
- #--------------------------------------------------------------------------
- # ● 攻击力
- #--------------------------------------------------------------------------
- def atk(actor_id)
- # 无角色信息时返回
- return 0 unless actor_id
- # 数据类型不符时返回
- return 0 if @type != 0 and @type != 1
- if percent
- return $game_actors[actor_id].self_atk * @value / 100
- else
- return @value
- end
- end
- #--------------------------------------------------------------------------
- # ● 防御力
- #--------------------------------------------------------------------------
- def def(actor_id)
- # 无角色信息时返回
- return 0 unless actor_id
- # 数据类型不符时返回
- return 0 if @type != 2 and @type != 3
- if percent
- return $game_actors[actor_id].self_def * @value / 100
- else
- return @value
- end
- end
- #--------------------------------------------------------------------------
- # ● 精神
- #--------------------------------------------------------------------------
- def spi(actor_id)
- # 无角色信息时返回
- return 0 unless actor_id
- # 数据类型不符时返回
- return 0 if @type != 4 and @type != 5
- if percent
- return $game_actors[actor_id].self_spi * @value / 100
- else
- return @value
- end
- end
- #--------------------------------------------------------------------------
- # ● 敏捷
- #--------------------------------------------------------------------------
- def agi(actor_id)
- # 无角色信息时返回
- return 0 unless actor_id
- # 数据类型不符时返回
- return 0 if @type != 6 and @type != 7
- if percent
- return $game_actors[actor_id].self_agi * @value / 100
- else
- return @value
- end
- end
- #--------------------------------------------------------------------------
- # ● maxhp
- #--------------------------------------------------------------------------
- def maxhp(actor_id)
- # 无角色信息时返回
- return 0 unless actor_id
- # 数据类型不符时返回
- return 0 if @type != 8 and @type != 9
- if percent
- return $game_actors[actor_id].self_maxhp * @value / 100
- else
- return @value
- end
- end
- #--------------------------------------------------------------------------
- # ● maxmp
- #--------------------------------------------------------------------------
- def maxmp(actor_id)
- # 无角色信息时返回
- return 0 unless actor_id
- # 数据类型不符时返回
- return 0 if @type != 10 and @type != 11
- if percent
- return $game_actors[actor_id].self_maxmp * @value / 100
- else
- return @value
- end
- end
- #--------------------------------------------------------------------------
- # ● 命中
- #--------------------------------------------------------------------------
- def hit
- # 数据类型不符时返回
- return 0 if @type != 12
- return @value
- end
- #--------------------------------------------------------------------------
- # ● 闪避
- #--------------------------------------------------------------------------
- def eva
- # 数据类型不符时返回
- return 0 if @type != 13
- return @value
- end
- #--------------------------------------------------------------------------
- # ● 暴击
- #--------------------------------------------------------------------------
- def cri
- # 数据类型不符时返回
- return 0 if @type != 14
- return @value
- end
- #--------------------------------------------------------------------------
- # ● 经验(百分比)
- #--------------------------------------------------------------------------
- def exp
- # 数据类型不符时返回
- return 0 if @type != 15
- return @value
- end
- #--------------------------------------------------------------------------
- # ● 高级装备暴率(百分比)
- #--------------------------------------------------------------------------
- def equip_chance
- # 数据类型不符时返回
- return 0 if @type != 16
- return @value
- end
- end
- #==============================================================================
- # ■ RPG::BaseItem
- #==============================================================================
- module RPG
- class BaseItem
- ## 颜色
- attr_accessor :text_color
- end
- end
- #==============================================================================
- # ■ RPG::Weapon
- #==============================================================================
- module RPG
- class Weapon < BaseItem
- #------------------------------------------------------------------------
- # 附加属性
- #------------------------------------------------------------------------
- attr_accessor :base_id
- attr_accessor :actor_id
- attr_accessor :gifts
- #------------------------------------------------------------------------
- # 攻击力(合)
- #------------------------------------------------------------------------
- def atk
- n = @atk
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.atk(actor_id) end
- return n
- end
- #------------------------------------------------------------------------
- # 防御力(合)
- #------------------------------------------------------------------------
- def def
- n = @def
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.def(actor_id) end
- return n
- end
- #------------------------------------------------------------------------
- # 魔力(合)
- #------------------------------------------------------------------------
- def spi
- n = @spi
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.spi(actor_id) end
- return n
- end
- #------------------------------------------------------------------------
- # 敏捷(合)
- #------------------------------------------------------------------------
- def agi
- n = @agi
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.agi(actor_id) end
- return n
- end
- #------------------------------------------------------------------------
- # 最大hp(合)
- #------------------------------------------------------------------------
- def maxhp
- n = 0
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.maxhp(actor_id) end
- return n
- end
- #------------------------------------------------------------------------
- # 最大mp(合)
- #------------------------------------------------------------------------
- def maxmp
- n = 0
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.maxmp(actor_id) end
- return n
- end
- #------------------------------------------------------------------------
- # 命中率(合)
- #------------------------------------------------------------------------
- def hit
- n = @hit
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.hit end
- return n
- end
- #------------------------------------------------------------------------
- # 闪避率(合)
- #------------------------------------------------------------------------
- def eva
- n = 0
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.eva end
- return n
- end
- #------------------------------------------------------------------------
- # 暴击率(合)
- #------------------------------------------------------------------------
- def cri
- n = 0
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.cri end
- return n
- end
- #--------------------------------------------------------------------------
- # ● 经验(百分比)
- #--------------------------------------------------------------------------
- def exp
- n = 0
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.exp end
- return n
- end
- #--------------------------------------------------------------------------
- # ● 高级装备暴率(百分比)
- #--------------------------------------------------------------------------
- def equip_chance
- n = 0
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.equip_chance end
- return n
- end
- end
- end
- #==============================================================================
- # ■ RPG::Armor
- #==============================================================================
- module RPG
- class Armor < BaseItem
- #------------------------------------------------------------------------
- # 附加属性
- #------------------------------------------------------------------------
- attr_accessor :base_id
- attr_accessor :actor_id
- attr_accessor :gifts
- #------------------------------------------------------------------------
- # 攻击力(合)
- #------------------------------------------------------------------------
- def atk
- n = @atk
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.atk(actor_id) end
- return n
- end
- #------------------------------------------------------------------------
- # 防御力(合)
- #------------------------------------------------------------------------
- def def
- n = @def
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.def(actor_id) end
- return n
- end
- #------------------------------------------------------------------------
- # 魔力(合)
- #------------------------------------------------------------------------
- def spi
- n = @spi
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.spi(actor_id) end
- return n
- end
- #------------------------------------------------------------------------
- # 敏捷(合)
- #------------------------------------------------------------------------
- def agi
- n = @agi
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.agi(actor_id) end
- return n
- end
- #------------------------------------------------------------------------
- # 最大hp(合)
- #------------------------------------------------------------------------
- def maxhp
- n = 0
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.maxhp(actor_id) end
- return n
- end
- #------------------------------------------------------------------------
- # 最大mp(合)
- #------------------------------------------------------------------------
- def maxmp
- n = 0
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.maxmp(actor_id) end
- return n
- end
- #------------------------------------------------------------------------
- # 命中率(合)
- #------------------------------------------------------------------------
- def hit
- n = 0
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.hit end
- return n
- end
- #------------------------------------------------------------------------
- # 闪避率(合)
- #------------------------------------------------------------------------
- def eva
- n = @eva
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.eva end
- return n
- end
- #------------------------------------------------------------------------
- # 暴击率(合)
- #------------------------------------------------------------------------
- def cri
- n = 0
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.cri end
- return n
- end
- #--------------------------------------------------------------------------
- # ● 经验(百分比)
- #--------------------------------------------------------------------------
- def exp
- n = 0
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.exp end
- return n
- end
- #--------------------------------------------------------------------------
- # ● 高级装备暴率(百分比)
- #--------------------------------------------------------------------------
- def equip_chance
- n = 0
- @gifts = [] if @gifts.nil?
- for g in @gifts.compact do n += g.equip_chance end
- return n
- end
- end
- end
- #==============================================================================
- # ■ Game_Actor
- #==============================================================================
- class Game_Actor < Game_Battler
- #--------------------------------------------------------------------------
- # ● 基本 MaxHP の取得
- #--------------------------------------------------------------------------
- def base_maxhp
- n = actor.parameters[0, @level]
- for item in equips.compact do n += item.maxhp end
- return n
- end
- #--------------------------------------------------------------------------
- # ● 获取基本 MaxMP
- #--------------------------------------------------------------------------
- def base_maxmp
- n = actor.parameters[1, @level]
- for item in equips.compact do n += item.maxmp end
- return n
- end
- #--------------------------------------------------------------------------
- # ● 获取自身 MaxHP
- #--------------------------------------------------------------------------
- def self_maxhp
- return actor.parameters[0, @level]
- end
- #--------------------------------------------------------------------------
- # ● 获取自身 MaxMP
- #--------------------------------------------------------------------------
- def self_maxmp
- return actor.parameters[1, @level]
- end
- #--------------------------------------------------------------------------
- # ● 获取自身攻击力
- #--------------------------------------------------------------------------
- def self_atk
- return actor.parameters[2, @level]
- end
- #--------------------------------------------------------------------------
- # ● 获取自身防御力
- #--------------------------------------------------------------------------
- def self_def
- return actor.parameters[3, @level]
- end
- #--------------------------------------------------------------------------
- # ● 获取自身精神力
- #--------------------------------------------------------------------------
- def self_spi
- return actor.parameters[4, @level]
- end
- #--------------------------------------------------------------------------
- # ● 获取自身敏捷性
- #--------------------------------------------------------------------------
- def self_agi
- return actor.parameters[5, @level]
- end
- #--------------------------------------------------------------------------
- # ● 获取命中率
- #--------------------------------------------------------------------------
- def hit
- n = 95
- for e in equips.compact do n += e.hit end
- return n
- end
- #--------------------------------------------------------------------------
- # ● 获取回避率
- #--------------------------------------------------------------------------
- def eva
- n = 5
- for e in equips.compact do n += e.eva end
- return n
- end
- #--------------------------------------------------------------------------
- # ● 获取会心一击概率
- #--------------------------------------------------------------------------
- def cri
- n = 4
- n += 4 if actor.critical_bonus
- for e in equips.compact do n += e.cri end
- return n
- end
- #--------------------------------------------------------------------------
- # ● 获取更多经验值
- #--------------------------------------------------------------------------
- def exp_added
- exp = 1
- for equip in equips.compact
- exp += equip.exp
- end
- return exp
- end
- #--------------------------------------------------------------------------
- # ● 获取高级物品暴率
- #--------------------------------------------------------------------------
- def equip_chance
- equip_chance = 0
- for equip in equips.compact
- equip_chance += equip.equip_chance
- end
- return equip_chance
- end
- #--------------------------------------------------------------------------
- # ● 获得经验值 (考虑到附加经验值)
- # exp : 经验值增加量
- # show : 显示升级标志
- #--------------------------------------------------------------------------
- def gain_exp(exp, show)
- change_exp(@exp + exp * exp_added, show)
- end
- end
- #==============================================================================
- # ■ Game_Actor
- #==============================================================================
- class Game_Actor < Game_Battler
- #--------------------------------------------------------------------------
- # ● 初始化对象
- # actor_id : 角色 ID
- #--------------------------------------------------------------------------
- def initialize(actor_id)
- super()
- setup(actor_id)
- @last_skill_id = 0
- end
- #--------------------------------------------------------------------------
- # ● 设置
- # actor_id : 角色 ID
- #--------------------------------------------------------------------------
- def setup(actor_id)
- actor = $data_actors[actor_id]
- @actor_id = actor_id
- @name = actor.name
- @character_name = actor.character_name
- @character_index = actor.character_index
- @face_name = actor.face_name
- @face_index = actor.face_index
- @class_id = actor.class_id
- @weapon_id = actor.weapon_id
- @armor1_id = actor.armor1_id
- @armor2_id = actor.armor2_id
- @armor3_id = actor.armor3_id
- @armor4_id = actor.armor4_id
- @level = actor.initial_level
- @exp_list = Array.new(101)
- make_exp_list
- @exp = @exp_list[@level]
- @skills = []
- for i in self.class.learnings
- learn_skill(i.skill_id) if i.level <= @level
- end
- clear_extra_values
- recover_all
- ## 生成新装备id
- reset_equip_id
- end
- #--------------------------------------------------------------------------
- # ● 装备重设
- #--------------------------------------------------------------------------
- def reset_equip_id
- @weapon_id = Game_Equip.reini_id(@weapon_id, 0)
- @armor1_id = Game_Equip.reini_id(@armor1_id, two_hands_legal? ? 0 : 1)
- @armor2_id = Game_Equip.reini_id(@armor2_id, 1)
- @armor3_id = Game_Equip.reini_id(@armor3_id, 1)
- @armor4_id = Game_Equip.reini_id(@armor4_id, 1)
- end
- #--------------------------------------------------------------------------
- # ● 判断是否可以装备
- # item : 物品
- # base : 是否读取母版数据
- #--------------------------------------------------------------------------
- def equippable?(item, base = true)
- return true if item == nil
- id = base ? item.base_id : item.id
- if item.is_a?(RPG::Weapon)
- return self.class.weapon_set.include?(id)
- elsif item.is_a?(RPG::Armor)
- return false if two_swords_style and item.kind == 0
- return self.class.armor_set.include?(id)
- end
- return false
- end
- #--------------------------------------------------------------------------
- # ● 更改装备 (指定对象)
- # equip_type : 装备部位 (0..4)
- # item : 武器 or 防具 (nil 为解除装备)
- # test : 测试标志 (战斗测试、以及装备画面的临时装备)
- #--------------------------------------------------------------------------
- def change_equip(equip_type, item, test = false)
- last_item = equips[equip_type]
- unless test
- return if $game_party.item_number(item) == 0 if item != nil
- $game_party.gain_item(last_item, 1)
- $game_party.lose_item(item, 1)
- last_item.actor_id = nil unless last_item.nil?
- end
- item_id = item == nil ? 0 : item.id
- case equip_type
- when 0 # 武器
- @weapon_id = item_id
- unless two_hands_legal? # 违反双手拿取的情况下
- change_equip(1, nil, test) # 解除反手的装备
- end
- when 1 # 盾
- @armor1_id = item_id
- unless two_hands_legal? # 违反双手拿取的情况下
- change_equip(0, nil, test) # 解除反手的装备
- end
- when 2 # 头
- @armor2_id = item_id
- when 3 # 身体
- @armor3_id = item_id
- when 4 # 装饰品
- @armor4_id = item_id
- end
- item.actor_id = self.id unless item.nil?
- end
- end
- #==============================================================================
- # ■ Game_Party
- #==============================================================================
- class Game_Party < Game_Unit
- #--------------------------------------------------------------------------
- # ● 判断持有的物品
- # item : 物品
- # include_equip : 包括装备品
- #--------------------------------------------------------------------------
- def has_item_by_base_id?(item, include_equip = false)
- for i in items
- return true if i.base_id == item.id
- end
- if include_equip
- for actor in members
- for e in actor.equips
- return true if e.base_id == item.id
- end
- end
- end
- return false
- end
- #--------------------------------------------------------------------------
- # ● 获得物品
- # item : 物品
- # n : 个数
- #--------------------------------------------------------------------------
- def gain_reini(item, n, include_equip = false, *gift)
- if n < 0
- lose_item(item, -n, include_equip = false)
- else
- case item
- when RPG::Item
- number = item_number(item)
- @items[item.id] = [[number + n, 0].max, 99].min
- when RPG::Weapon
- for i in 0...n
- w = Game_Equip.reini(item, *gift)
- @weapons[w.id] = 1
- end
- when RPG::Armor
- for i in 0...n
- a = Game_Equip.reini(item, *gift)
- @armors[a.id] = 1
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 减少物品 (减少)
- # item : 物品
- # n : 个数
- # include_equip : 包括装备品
- #--------------------------------------------------------------------------
- def lose_reini(item, n, include_equip = false)
- number = item_number(item)
- case item
- when RPG::Item
- @items[item.id] = [[number - n, 0].max, 99].min
- when RPG::Weapon
- @weapons[item.id] = [[number - n, 0].max, 99].min
- when RPG::Armor
- @armors[item.id] = [[number - n, 0].max, 99].min
- end
- n -= number
- if include_equip and n > 0
- for actor in members
- while n > 0 and actor.equips.include?(item)
- actor.discard_equip(item)
- n -= 1
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 获得物品
- # item_id : 物品id
- # type : 类型(0物品, 1武器, 2防具)
- # n : 个数
- #--------------------------------------------------------------------------
- def gain_reini_byid(item_id, type, n, include_equip = false, *gift)
- case type
- when 0
- item = $data_items[item_id]
- when 1
- item = $base_weapons[item_id]
- when 2
- item = $base_armors[item_id]
- end
- gain_reini(item, n, include_equip, *gift)
- end
- #--------------------------------------------------------------------------
- # ● 极品爆率
- #--------------------------------------------------------------------------
- def equip_chance
- chance = Game_Equip::Equip_Chance[0]
- members.each {|actor| chance += actor.equip_chance}
- return chance
- end
- end
- #==============================================================================
- # ■ Game_Troop
- #==============================================================================
- class Game_Troop < Game_Unit
- #--------------------------------------------------------------------------
- # ● 敌人角色名称后的文字表
- #--------------------------------------------------------------------------
- LETTER_TABLE = [ 'A','B','C','D','E','F','G','H','I','J',
- 'K','L','M','N','O','P','Q','R','S','T',
- 'U','V','W','X','Y','Z']
- #--------------------------------------------------------------------------
- # ● 生成掉落物品队列
- #--------------------------------------------------------------------------
- def make_drop_items
- drop_items = []
- for enemy in dead_members
- for di in [enemy.drop_item1, enemy.drop_item2]
- next if di.kind == 0
- next if rand(di.denominator) != 0
- if di.kind == 1
- drop_items.push($data_items[di.item_id])
- elsif di.kind == 2
- item = reini_chance($base_weapons[di.weapon_id], $game_party.equip_chance)
- drop_items.push(item)
- elsif di.kind == 3
- item = reini_chance($base_armors[di.armor_id], $game_party.equip_chance)
- drop_items.push(item)
- end
- end
- end
- return drop_items
- end
- #--------------------------------------------------------------------------
- # ● 处理极品爆率
- #--------------------------------------------------------------------------
- def reini_chance(item, chance)
- @item = item
- @chance = [chance/100.0, Game_Equip::Equip_Chance[1]/100.0].min
- @gifts = []
- loop do
- if rand(0) < @chance and @gifts.size < Game_Equip::GiftMax
- @gifts << Game_Gift.new
- @chance /= 2
- else
- return Game_Equip.reini(@item, @gifts)
- end
- end
- end
- end
- #==============================================================================
- # ■ Game_Interpreter
- #==============================================================================
- class Game_Interpreter
- #--------------------------------------------------------------------------
- # ● 计算操作的值
- # operation : 操作 (0:增加 1:减少)
- # operand_type : 运算域类型 (0:常量 1:变量)
- # operand : 运算域 (数值为变量 ID)
- #--------------------------------------------------------------------------
- def operate_value(operation, operand_type, operand)
- if operand_type == 0
- value = operand
- else
- value = $game_variables[operand]
- end
- if operation == 1
- value = -value
- end
- return value
- end
- #--------------------------------------------------------------------------
- # ● 条件分歧
- #--------------------------------------------------------------------------
- def command_111
- result = false
- case @params[0]
- when 0 # 开关
- result = ($game_switches[@params[1]] == (@params[2] == 0))
- when 1 # 变量
- value1 = $game_variables[@params[1]]
- if @params[2] == 0
- value2 = @params[3]
- else
- value2 = $game_variables[@params[3]]
- end
- case @params[4]
- when 0 # 相等
- result = (value1 == value2)
- when 1 # 大于等于
- result = (value1 >= value2)
- when 2 # 小于等于
- result = (value1 <= value2)
- when 3 # 大于
- result = (value1 > value2)
- when 4 # 小于
- result = (value1 < value2)
- when 5 # 不等于
- result = (value1 != value2)
- end
- when 2 # 自我开关
- if @original_event_id > 0
- key = [@map_id, @original_event_id, @params[1]]
- if @params[2] == 0
- result = ($game_self_switches[key] == true)
- else
- result = ($game_self_switches[key] != true)
- end
- end
- when 3 # 计时器
- if $game_system.timer_working
- sec = $game_system.timer / Graphics.frame_rate
- if @params[2] == 0
- result = (sec >= @params[1])
- else
- result = (sec <= @params[1])
- end
- end
- when 4 # 角色
- actor = $game_actors[@params[1]]
- if actor != nil
- case @params[2]
- when 0 # 是同伴
- result = ($game_party.members.include?(actor))
- when 1 # 姓名
- result = (actor.name == @params[3])
- when 2 # 特技
- result = (actor.skill_learn?($data_skills[@params[3]]))
- when 3 # 武器
- ## 判断是否符合母版id
- actor.weapons.each do |weapon|
- next if weapon.nil?
- if weapon.base_id == @params[3]
- result = true
- break
- end
- end
- when 4 # 防具
- ## 判断是否符合母版id
- actor.armors.each do |armor|
- next if armor.nil?
- if armor.base_id == @params[3]
- result = true
- break
- end
- end
- when 5 # 状态
- result = (actor.state?(@params[3]))
- end
- end
- when 5 # 敌方角色
- enemy = $game_troop.members[@params[1]]
- if enemy != nil
- case @params[2]
- when 0 # 出现
- result = (enemy.exist?)
- when 1 # 状态
- result = (enemy.state?(@params[3]))
- end
- end
- when 6 # 角色
- character = get_character(@params[1])
- if character != nil
- result = (character.direction == @params[2])
- end
- when 7 # 金钱
- if @params[2] == 0
- result = ($game_party.gold >= @params[1])
- else
- result = ($game_party.gold <= @params[1])
- end
- when 8 # 物品
- result = $game_party.has_item?($data_items[@params[1]])
- when 9 # 武器
- result = $game_party.has_item_by_base_id?($base_weapons[@params[1]], @params[2])
- when 10 # 防具
- result = $game_party.has_item_by_base_id?($base_armors[@params[1]], @params[2])
- when 11 # 按钮
- result = Input.press?(@params[1])
- when 12 # 脚本
- result = eval(@params[1])
- when 13 # 交通工具
- result = ($game_player.vehicle_type == @params[1])
- end
- @branch[@indent] = result # 将判断结果放置在缓存中
- if @branch[@indent] == true
- @branch.delete(@indent)
- return true
- end
- return command_skip
- end
-
-
- #--------------------------------------------------------------------------
- # ● 计算装备操作的值
- # operand_type : 运算域类型 (0:常量 1:变量)
- # operand : 运算域 (数值为变量 ID)
- #--------------------------------------------------------------------------
- def opera_equip_value(operation, operand_type, operand)
- if operand_type == 0
- value = operand
- else
- value = $game_variables[operand]
- end
- return value
- end
- #--------------------------------------------------------------------------
- # ● 增减武器
- #--------------------------------------------------------------------------
- def command_127
- value = operate_value(@params[1], @params[2], @params[3])
- if @params[1] == 0
- $game_party.gain_reini($base_weapons[@params[0]], value.abs, @params[4])
- else
- $game_party.lose_reini($base_weapons[@params[0]], value.abs, @params[4])
- end
- return true
- end
- #--------------------------------------------------------------------------
- # ● 增减防具
- #--------------------------------------------------------------------------
- def command_128
- value = operate_value(@params[1], @params[2], @params[3])
- if @params[1] == 0
- $game_party.gain_reini($base_armors[@params[0]], value.abs, @params[4])
- else
- $game_party.lose_reini($base_armors[@params[0]], value.abs, @params[4])
- end
- return true
- end
- #--------------------------------------------------------------------------
- # ● 更改装备
- #--------------------------------------------------------------------------
- def command_319
- actor = $game_actors[@params[0]]
- if actor != nil
- actor.change_equip_by_id(@params[1], @params[2])
- end
- return true
- end
- #--------------------------------------------------------------------------
- # ● 增减武器
- #--------------------------------------------------------------------------
- def get_weapon(id, n, *gift)
- $game_party.gain_reini($base_weapons[id], n, false, *gift)
- end
- #--------------------------------------------------------------------------
- # ● 增减防具
- #--------------------------------------------------------------------------
- def get_armor(id, n, *gift)
- $game_party.gain_reini($base_armors[id], n, false, *gift)
- end
- end
- #==============================================================================
- # ■ Window_Base
- #==============================================================================
- class Window_Base < Window
- def draw_item_name(item, x, y, enabled = true)
- if item != nil
- draw_icon(item.icon_index, x, y, enabled)
- self.contents.font.color = text_color(item.text_color.to_i)
- self.contents.font.color.alpha = enabled ? 255 : 128
- self.contents.draw_text(x + 24, y, 172, WLH, item.name)
- end
- end
- end
- #==============================================================================
- # ■ Window_ShopBuy
- #==============================================================================
- class Window_ShopBuy < Window_Selectable
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- @data = []
- for goods_item in @shop_goods
- case goods_item[0]
- when 0
- item = $data_items [goods_item[1]]
- when 1
- item = $base_weapons[goods_item[1]]
- when 2
- item = $base_armors[goods_item[1]]
- end
- if item != nil
- @data.push(item)
- end
- end
- @item_max = @data.size
- create_contents
- for i in 0...@item_max
- draw_item(i)
- end
- end
- end
- #==============================================================================
- # ■ Window_ShopStatus
- #==============================================================================
- class Window_ShopStatus < Window_Base
- #--------------------------------------------------------------------------
- # ● 描绘角色现在装备的能力值变化
- # actor : 角色
- # x : 描画目标 X 坐标
- # y : 描画目标 Y 坐标
- #--------------------------------------------------------------------------
- def draw_actor_parameter_change(actor, x, y)
- return if @item.is_a?(RPG::Item)
- enabled = actor.equippable?(@item, false)
- self.contents.font.color = normal_color
- self.contents.font.color.alpha = enabled ? 255 : 128
- self.contents.draw_text(x, y, 200, WLH, actor.name)
- if @item.is_a?(RPG::Weapon)
- item1 = weaker_weapon(actor)
- elsif actor.two_swords_style and @item.kind == 0
- item1 = nil
- else
- item1 = actor.equips[1 + @item.kind]
- end
- if enabled
- if @item.is_a?(RPG::Weapon)
- atk1 = item1 == nil ? 0 : item1.atk
- atk2 = @item == nil ? 0 : @item.atk
- change = atk2 - atk1
- else
- def1 = item1 == nil ? 0 : item1.def
- def2 = @item == nil ? 0 : @item.def
- change = def2 - def1
- end
- self.contents.draw_text(x, y, 200, WLH, sprintf("%+d", change), 2)
- end
- draw_item_name(item1, x, y + WLH, enabled)
- end
- end
- #==============================================================================
- # ■ Scene_File
- #==============================================================================
- class Scene_File < Scene_Base
- #--------------------------------------------------------------------------
- # ● 写入存档数据
- # file : 写入文件用对象 (已经打开)
- #--------------------------------------------------------------------------
- def write_save_data(file)
- characters = []
- for actor in $game_party.members
- characters.push([actor.character_name, actor.character_index])
- end
- $game_system.save_count += 1
- $game_system.version_id = $data_system.version_id
- @last_bgm = RPG::BGM::last
- @last_bgs = RPG::BGS::last
- Marshal.dump(characters, file)
- Marshal.dump(Graphics.frame_count, file)
- Marshal.dump(@last_bgm, file)
- Marshal.dump(@last_bgs, file)
- Marshal.dump($game_system, file)
- Marshal.dump($game_message, file)
- Marshal.dump($game_switches, file)
- Marshal.dump($game_variables, file)
- Marshal.dump($game_self_switches, file)
- Marshal.dump($game_actors, file)
- Marshal.dump($game_party, file)
- Marshal.dump($game_troop, file)
- Marshal.dump($game_map, file)
- Marshal.dump($game_player, file)
- Marshal.dump($data_weapons, file)
- Marshal.dump($data_armors, file)
- end
- #--------------------------------------------------------------------------
- # ● 读取存档数据
- # file : 读取文件用对象 (已经打开)
- #--------------------------------------------------------------------------
- def read_save_data(file)
- characters = Marshal.load(file)
- Graphics.frame_count = Marshal.load(file)
- @last_bgm = Marshal.load(file)
- @last_bgs = Marshal.load(file)
- $game_system = Marshal.load(file)
- $game_message = Marshal.load(file)
- $game_switches = Marshal.load(file)
- $game_variables = Marshal.load(file)
- $game_self_switches = Marshal.load(file)
- $game_actors = Marshal.load(file)
- $game_party = Marshal.load(file)
- $game_troop = Marshal.load(file)
- $game_map = Marshal.load(file)
- $game_player = Marshal.load(file)
- $data_weapons = Marshal.load(file)
- $data_armors = Marshal.load(file)
- if $game_system.version_id != $data_system.version_id
- $game_map.setup($game_map.map_id)
- $game_player.center($game_player.x, $game_player.y)
- end
- end
- end
- #==============================================================================
- # ■ Scene_Shop
- #==============================================================================
- class Scene_Shop < Scene_Base
- #--------------------------------------------------------------------------
- # ● 确定输入个数
- #--------------------------------------------------------------------------
- def decide_number_input
- Sound.play_shop
- @number_window.active = false
- @number_window.visible = false
- case @command_window.index
- when 0 # 购买
- $game_party.lose_gold(@number_window.number * @item.price)
- $game_party.gain_reini(@item, @number_window.number)
- @gold_window.refresh
- @buy_window.refresh
- # @status_window.refresh
- @buy_window.active = true
- @buy_window.visible = true
- when 1 # 卖出
- $game_party.gain_gold(@number_window.number * (@item.price / 2))
- $game_party.lose_reini(@item, @number_window.number)
- @gold_window.refresh
- @sell_window.refresh
- # @status_window.refresh
- @sell_window.active = true
- @sell_window.visible = true
- # @status_window.visible = false
- end
- end
- end
- #==============================================================================
- # ■ Scene_Title
- #==============================================================================
- class Scene_Title < Scene_Base
- #--------------------------------------------------------------------------
- # ● 载入数据库
- #--------------------------------------------------------------------------
- def load_database
- $data_actors = load_data("Data/Actors.rvdata")
- $data_classes = load_data("Data/Classes.rvdata")
- $data_skills = load_data("Data/Skills.rvdata")
- $data_items = load_data("Data/Items.rvdata")
- $base_weapons = load_data("Data/Weapons.rvdata")
- $base_armors = load_data("Data/Armors.rvdata")
- $data_enemies = load_data("Data/Enemies.rvdata")
- $data_troops = load_data("Data/Troops.rvdata")
- $data_states = load_data("Data/States.rvdata")
- $data_animations = load_data("Data/Animations.rvdata")
- $data_common_events = load_data("Data/CommonEvents.rvdata")
- $data_system = load_data("Data/System.rvdata")
- $data_areas = load_data("Data/Areas.rvdata")
- $data_weapons = [nil]
- $data_armors = [nil]
- end
- #--------------------------------------------------------------------------
- # ● 载入战斗测试用的数据库
- #--------------------------------------------------------------------------
- def load_bt_database
- $data_actors = load_data("Data/BT_Actors.rvdata")
- $data_classes = load_data("Data/BT_Classes.rvdata")
- $data_skills = load_data("Data/BT_Skills.rvdata")
- $data_items = load_data("Data/BT_Items.rvdata")
- $data_weapons = load_data("Data/BT_Weapons.rvdata")
- $data_armors = load_data("Data/BT_Armors.rvdata")
- $data_enemies = load_data("Data/BT_Enemies.rvdata")
- $data_troops = load_data("Data/BT_Troops.rvdata")
- $data_states = load_data("Data/BT_States.rvdata")
- $data_animations = load_data("Data/BT_Animations.rvdata")
- $data_common_events = load_data("Data/BT_CommonEvents.rvdata")
- $data_system = load_data("Data/BT_System.rvdata")
- $base_weapons = $data_weapons
- $base_armors = $data_armors
- end
- end
复制代码 我加了VX新截图存档脚本和随机属性脚本,发现能存档但无法读档,发的时候无法上传附件,抱歉啊,脚本66上有,我就不发了,太长了 # 无角色信息时返回- #==============================================================================
- # vx新截图存档 by 沉影不器
- #------------------------------------------------------------------------------
- # ☆ 核心部分是内存位图的输入输出
- # (快速存储Bitmap的Marshal 作者: 柳之一) 强大啊
- #------------------------------------------------------------------------------
- # ▼ 相比rmxp正版截图存档(作者: 柳柳),主要变动如下:
- # ① 省去了 screenshot.dll 文件 (因快速存储Bitmap的Marshal的存在)
- # ② 无须人工新建存档文件夹,脚本将自建
- # ③ 方便地更改最大存档数,只需设置最大值
- #==============================================================================
- MAX_SAVE_ID = 5 # 最大存档数
- SAVE_DIR = "Saves/" # 改变的存档目录(不希望改变目录请删)
- #==============================================================================
- # (快速存储Bitmap的Marshal 作者: 柳之一) 强大啊
- #==============================================================================
- class Font
- def marshal_dump
- end
- def marshal_load(obj)
- end
- end
- class Bitmap
- # 传送到内存的API函数
- RtlMoveMemory_pi = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')
- RtlMoveMemory_ip = Win32API.new('kernel32', 'RtlMoveMemory', 'ipi', 'i')
- def _dump(limit)
- data = "rgba" * width * height
- RtlMoveMemory_pi.call(data, address, data.length)
- [width, height, Zlib::Deflate.deflate(data)].pack("LLa*") # 压缩
- end
- def self._load(str)
- w, h, zdata = str.unpack("LLa*")
- b = self.new(w, h)
- RtlMoveMemory_ip.call(b.address, Zlib::Inflate.inflate(zdata), w * h * 4)
- return b
- end
- # [[[bitmap.object_id * 2 + 16] + 8] + 16] == 数据的开头
- def address
- buffer, ad = "rgba", object_id * 2 + 16
- RtlMoveMemory_pi.call(buffer, ad, 4)
- ad = buffer.unpack("L")[0] + 8
- RtlMoveMemory_pi.call(buffer, ad, 4)
- ad = buffer.unpack("L")[0] + 16
- RtlMoveMemory_pi.call(buffer, ad, 4)
- return buffer.unpack("L")[0]
- end
- end
- #==============================================================================
- # ■ Game_Temp
- #==============================================================================
- class Game_Temp
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_accessor :save_bitmap # 存档位图
- #--------------------------------------------------------------------------
- # ● 初始化对象
- #--------------------------------------------------------------------------
- alias ini initialize
- def initialize
- ini
- @save_bitmap = Bitmap.new(1, 1)
- end
- end
- #==============================================================================
- # ■ Window_SaveFile
- #==============================================================================
- class Window_SaveFile < Window_Base
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :filename # 文件名
- attr_reader :file_exist # 文件存在标志
- #--------------------------------------------------------------------------
- # ● 初始化对象
- # file_index : 存档文件索引 (0~3)
- # filename : 文件名
- #--------------------------------------------------------------------------
- def initialize(file_index, filename)
- super(160, 56, 384, 360)
- @file_index = file_index
- @filename = filename
- make_dir(SAVE_DIR) if SAVE_DIR != nil
- load_gamedata
- refresh(@file_index)
- end
- #--------------------------------------------------------------------------
- # ● 读取部分游戏数据
- #--------------------------------------------------------------------------
- def load_gamedata
- @file_exist = FileTest.exist?(SAVE_DIR + @filename)
- if @file_exist
- file = File.open(SAVE_DIR + @filename, "r")
- begin
- @characters = Marshal.load(file)
- @frame_count = Marshal.load(file)
- @last_bgm = Marshal.load(file)
- @last_bgs = Marshal.load(file)
- @game_system = Marshal.load(file)
- @game_message = Marshal.load(file)
- @game_switches = Marshal.load(file)
- @game_variables = Marshal.load(file)
- @game_self_switches = Marshal.load(file)
- @game_actors = Marshal.load(file)
- @game_party = Marshal.load(file)
- @game_troop = Marshal.load(file)
- @game_map = Marshal.load(file)
- @game_player = Marshal.load(file)
- # 读取截图
- @file_bitmap = Marshal.load(file)
- @total_sec = @frame_count / Graphics.frame_rate
- rescue
- @file_exist = false
- ensure
- file.close
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- # index : 索引
- #--------------------------------------------------------------------------
- def refresh(index)
- file_index = index
- self.contents.clear
- self.contents.font.color = normal_color
- if @file_exist
- # 描绘底部阴影
- self.contents.fill_rect(12+3, 4+3, 326,249, Color.new(0,0,64))
- # 描绘截图
- draw_snap_bitmap(12, 4)
- draw_party_characters(152, 296)
- draw_playtime(0, 296+8, contents.width - 40, 2)
- else
- self.contents.draw_text(0, 296, 384-32, 24, "无此存档!", 1)
- end
- end
- #--------------------------------------------------------------------------
- # ◎ 更改索引
- # index : 索引
- #--------------------------------------------------------------------------
- def file_index=(file_index)
- @file_index = file_index
- end
- #--------------------------------------------------------------------------
- # ● 描绘游戏人物
- # x : 描画先 X 座標
- # y : 描画先 Y 座標
- #--------------------------------------------------------------------------
- def draw_party_characters(x, y)
- for i in [email protected]
- name = @characters[i][0]
- index = @characters[i][1]
- draw_character(name, index, x + i * 48, y)
- end
- end
- #--------------------------------------------------------------------------
- # ◎ 生成保存路径
- # path : 路径
- #--------------------------------------------------------------------------
- def make_dir(path)
- dir = path.split("/")
- for i in 0...dir.size
- unless dir == "."
- add_dir = dir[0..i].join("/")
- begin
- Dir.mkdir(add_dir)
- rescue
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # ◎ 生成文件名
- # file_index : 存档文件索引 (0~3)
- #--------------------------------------------------------------------------
- def make_filename(file_index)
- return "Save#{file_index + 1}.rvdata"
- end
- #--------------------------------------------------------------------------
- # ◎ 描绘截图
- # x : 描画先 X 座標
- # y : 描画先 Y 座標
- #--------------------------------------------------------------------------
- def draw_snap_bitmap(x, y)
- bitmap = @file_bitmap
- if bitmap == nil
- self.contents.draw_text(0, 112, 384-32, 24, "找不到截图文件!", 1)
- else
- self.contents.blur
- rect = Rect.new(0, 0, 0, 0)
- # rect.width = bitmap.width
- # rect.height = bitmap.height
- # self.contents.blt(x, y, bitmap, rect)
- end
- end
- #--------------------------------------------------------------------------
- # ● 描绘游戏时间
- # x : 描绘目标 X 坐标
- # y : 描绘目标 Y 坐标
- # width : 宽
- # align : 配置
- #--------------------------------------------------------------------------
- def draw_playtime(x, y, width, align)
- hour = @total_sec / 60 / 60
- min = @total_sec / 60 % 60
- sec = @total_sec % 60
- time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
- self.contents.font.color = normal_color
- self.contents.draw_text(x, y, width, WLH, time_string, 2)
- end
- end
- #==============================================================================
- # ■ Scene_Base
- #==============================================================================
- class Scene_Base
- #--------------------------------------------------------------------------
- # ◎ 生成存档位图快照
- #--------------------------------------------------------------------------
- def snapshot_for_save
- d_rect = Rect.new(0, 0, 326, 249)
- s_rect = Rect.new(0, 0, 544, 416)
- save_bitmap = Graphics.snap_to_bitmap
- $game_temp.save_bitmap.dispose
- $game_temp.save_bitmap = Bitmap.new(326, 249)
- $game_temp.save_bitmap.stretch_blt(d_rect, save_bitmap, s_rect)
- end
- end
- #==============================================================================
- # ■ Scene_Map
- #==============================================================================
- class Scene_Map < Scene_Base
- #--------------------------------------------------------------------------
- # ● 结束处理
- #--------------------------------------------------------------------------
- alias save_terminate terminate
- def terminate
- snapshot_for_save
- save_terminate
- end
- end
- #==============================================================================
- # ■ Scene_Title
- #==============================================================================
- class Scene_Title < Scene_Base
- #--------------------------------------------------------------------------
- # ● 判断继续是否有效
- #--------------------------------------------------------------------------
- def check_continue
- @continue_enabled = (Dir.glob(SAVE_DIR + 'Save*.rvdata').size > 0)
- end
- end
- #==============================================================================
- # ■ Scene_File
- #------------------------------------------------------------------------------
- # 处理文件的类。
- #==============================================================================
- class Scene_File < Scene_Base
- #--------------------------------------------------------------------------
- # ● 初始化对象
- # saving : 存档标志 (false 为载入画面)
- # from_title : 调用标题画面的 "继续" 标志
- # from_event : 事件的 "调用存档画面" 的调用标志
- #--------------------------------------------------------------------------
- def initialize(saving, from_title, from_event)
- @saving = saving
- @from_title = from_title
- @from_event = from_event
- end
- #--------------------------------------------------------------------------
- # ● 开始处理
- #--------------------------------------------------------------------------
- def start
- super
- create_menu_background
- @help_window = Window_Help.new
- create_command_window
- if @saving
- @index = $game_temp.last_file_index
- @help_window.set_text(Vocab::SaveMessage)
- else
- @index = self.latest_file_index
- @help_window.set_text(Vocab::LoadMessage)
- end
- @refresh_index = @command_window.index = @index
- @item_max = MAX_SAVE_ID
- create_savefile_window
- end
- #--------------------------------------------------------------------------
- # ● 结束处理
- #--------------------------------------------------------------------------
- def terminate
- super
- dispose_menu_background
- @help_window.dispose
- dispose_item_windows
- end
- #--------------------------------------------------------------------------
- # ● 还原至原先的画面
- #--------------------------------------------------------------------------
- def return_scene
- if @from_title
- $scene = Scene_Title.new
- elsif @from_event
- $scene = Scene_Map.new
- else
- $scene = Scene_Menu.new(4)
- end
- end
- #--------------------------------------------------------------------------
- # ● 更新画面
- #--------------------------------------------------------------------------
- def update
- super
- update_menu_background
- @help_window.update
- update_savefile_windows
- update_savefile_selection
- end
- #--------------------------------------------------------------------------
- # ◎ 生成存档文件列表窗口
- #--------------------------------------------------------------------------
- def create_command_window
- file_names = []
- digit = MAX_SAVE_ID.to_s.size
- str_f = ""
- digit.times{|n| str_f += "0"}
- str_f[str_f.size-1, 1] = digit.to_s
- for i in 0...MAX_SAVE_ID
- id = sprintf("%#{str_f}d", i+1)
- file_names.push(Vocab::File + "\s" + id)
- end
- @command_window = Window_Command.new(160, file_names)
- @command_window.height = 360
- @command_window.y = 56
- end
- #--------------------------------------------------------------------------
- # ● 生成存档文件窗口
- #--------------------------------------------------------------------------
- def create_savefile_window
- @savefile_window = Window_SaveFile.new(@command_window.index, make_filename(@command_window.index))
- end
- #--------------------------------------------------------------------------
- # ● 释放存档文件
- #--------------------------------------------------------------------------
- def dispose_item_windows
- @command_window.dispose
- @savefile_window.dispose
- end
- #--------------------------------------------------------------------------
- # ● 更新存档文件窗口
- #--------------------------------------------------------------------------
- def update_savefile_windows
- @command_window.update
- @savefile_window.update
- end
- #--------------------------------------------------------------------------
- # ● 更新存档文件选择
- #--------------------------------------------------------------------------
- def update_savefile_selection
- if Input.trigger?(Input::C)
- determine_savefile
- end
- if Input.trigger?(Input::B)
- Sound.play_cancel
- return_scene
- end
- if @refresh_index != @command_window.index
- @refresh_index = @command_window.index
- @savefile_window.dispose
- create_savefile_window
- end
- end
- #--------------------------------------------------------------------------
- # ● 确定存档文件
- #--------------------------------------------------------------------------
- def determine_savefile
- if @saving
- Sound.play_save
- do_save
- else
- if @savefile_window.file_exist
- Sound.play_load
- do_load
- else
- Sound.play_buzzer
- return
- end
- end
- $game_temp.last_file_index = @index
- end
- #--------------------------------------------------------------------------
- # ◎ 生成文件名
- # file_index : 存档文件索引
- #--------------------------------------------------------------------------
- def make_filename(file_index)
- return "Save#{file_index + 1}.rvdata"
- end
- #--------------------------------------------------------------------------
- # ● 按时间戳选择最新的文件
- #--------------------------------------------------------------------------
- def latest_file_index
- index = 0
- latest_time = Time.at(0) # 时间戳
- for i in 0...MAX_SAVE_ID
- file_name = make_filename(i)
- if FileTest.exist?(SAVE_DIR + file_name)
- file = File.open(SAVE_DIR + file_name, "r")
- if file.mtime > latest_time
- latest_time = file.mtime
- index = i
- end
- end
- end
- return index
- end
- #--------------------------------------------------------------------------
- # ● 执行存档
- #--------------------------------------------------------------------------
- def do_save
- file_name = make_filename(@command_window.index)
- file = File.open(SAVE_DIR + file_name, "wb")
- write_save_data(file)
- # 保存位图
- $file_bitmap = $game_temp.save_bitmap
- Marshal.dump($file_bitmap, file)
- file.close
- return_scene
- end
- #--------------------------------------------------------------------------
- # ● 执行载入
- #--------------------------------------------------------------------------
- def do_load
- file_name = make_filename(@command_window.index)
- file = File.open(SAVE_DIR + file_name, "rb")
- read_save_data(file)
- file.close
- $scene = Scene_Map.new
- RPG::BGM.fade(1500)
- Graphics.fadeout(60)
- Graphics.wait(40)
- @last_bgm.play
- @last_bgs.play
- end
- end
复制代码 |
|