#============================================================================== # ■ VXAce-RGSS3-16 鍛冶屋 [基本クラス] by Claimh #============================================================================== #============================================================================== # ■ 基本クラス #============================================================================== module Blacksmith DBG = false # 全て表示 C_W=0;C_A=1;S_W=2;S_A=3 T = ["生成", "強化", "やめる"] # メッセージタイプ module MesCmd M_S_C = 0 # 生成成功 M_S_S = 1 # 強化成功 M_N_P = 10 # お金足りない M_N_I = 11 # アイテム足りない M_N_N = 12 # アイテムいっぱい M_E_N = 20 # 装備できない M_E_D = 21 # 装備外した M_E_C = 22 # 装備変更した M_O_I = 30 # 所持品に入れた #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def self.conv_text(type, item=nil) case type when M_S_C; text = "#{item.name}を生成しました" when M_S_S; text = "#{item.name}に強化しました" when M_N_P; text = "所持金が足りません" when M_N_I; text = "素材が足りません" when M_N_N; text = "これ以上、持てません" when M_E_N; text = "装備できません" when M_E_D; text = "#{item.name}の装備を外しました" when M_E_C; text = "#{item.name}の装備を変更しました" when M_O_I; text = "所持品に入れました" else; p "bad arg", type; return "" end return text end end #-------------------------------------------------------------------------- # ● コマンド #-------------------------------------------------------------------------- def self.sys_cmd SYS_CMD.collect { |d| T[d] } end def self.mod_cmd(s) text = ["武器#{T[s]}", "防具#{T[s]}", "やめる"] MOD_CMD.collect { |d| text[d] } end #-------------------------------------------------------------------------- # ● シンボル #-------------------------------------------------------------------------- def self.sys_symbol(i) [:create, :pwup, :exit][i] end def self.mod_symbol(i) [:weapon, :armor, :exit][i] end #-------------------------------------------------------------------------- # ● 設定情報参照 #-------------------------------------------------------------------------- def self.data(t) [C_WEAPON, C_ARMOR, S_WEAPON, S_ARMOR][t] end #-------------------------------------------------------------------------- # ● カテゴリ設定情報参照 #-------------------------------------------------------------------------- def self.ctg(t) ids = [] ids.push(CT_ALL) if ADD_ALL if t % 2 == 0 # weapon $data_system.weapon_types.each_index do |i| ids.push(i) if i > 0 and !WT_NOT_USE.include?(i) end else # armor if A_TYPE $data_system.armor_types.each_index do |i| ids.push(i) if i > 0 and !AT_NOT_USE.include?(i) end else ids += [1, 2, 3, 4] end end ids end #-------------------------------------------------------------------------- # ● データソート #-------------------------------------------------------------------------- def self.sort(list, t) return [] if list.nil? return list unless SORT case t # 攻撃力・防御力でソートする when C_W, S_W; list.sort! {|a,b| b.obj.params[2] - a.obj.params[2] } when C_A, S_A; list.sort! {|a,b| b.obj.params[3] - a.obj.params[3] } end return list end #-------------------------------------------------------------------------- # ● データPush #-------------------------------------------------------------------------- def self.push(list, d, t, c) return list.push(d) if c == CT_ALL if t % 2 == 0 # weapon list.push(d) if d.obj.wtype_id == c else # armor if A_TYPE list.push(d) if d.obj.atype_id == c else list.push(d) if d.obj.etype_id == c end end return list end # 条件クラス class Condition attr_reader :id # 条件ID attr_reader :num # 条件値 attr_reader :enable def initialize(prm) if prm.empty? @id = 0 @num = 0 @enable = true else @id = prm[0] @num = prm[1] end end def update_status enable? end def enable? return (@enable = true) if @id == 0 or @num == 0 @enable = (pt_num >= @num) end def lose return if @id == 0 or @num == 0 $game_party.lose_item(obj, @num) if obj.consumable # 消耗 end def obj $data_items[@id] end def pt_num $game_party.item_number(obj) end end # 個別データクラス class CommonData attr_writer :visible attr_reader :price attr_reader :cond attr_reader :status #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(b_id, a_id, data) @b_id = b_id @a_id = a_id @price = data[0] @cond = data[1].collect {|d| Condition.new(d) } @visible = data[2].nil? ? false : data[2] @status = 0xFF end def id @a_id end def size @cond.size end def num $game_party.item_number(obj) end def gain $game_party.gain_item(obj, 1) end def lose $game_party.lose_item(b_obj, 1) end def equip(actor) actor.change_equip(equip_slot(actor), obj) end def equip_slot(actor) if @b_id != 0 # 強化 return actor.equips.index(b_obj) if actor.equips.include?(b_obj) else # 生成 if obj.is_a?(RPG::Weapon) and actor.dual_wield? weapons = actor.weapons if weapons.size > 1 w = weapons.collect {|a| (a.params[2]+a.params[4])} slot = 0 min = w.max w.each_with_index do |a, i| if min > a slot = i min = a end end return slot end end end actor.empty_slot(obj.etype_id) end #-------------------------------------------------------------------------- # ● 表示状態 #-------------------------------------------------------------------------- def visible @visible or DBG end #-------------------------------------------------------------------------- # ● ステータス更新 #-------------------------------------------------------------------------- ST_P = 0b001 ST_C = 0b010 ST_N = 0b100 def update_status @status = 0 @status |= ST_P unless price? @status |= ST_C unless cond_enable? @status |= ST_N unless num? visible # @statusではなくvisibleを返す end def enable? (@status == 0) end def message return MesCmd::M_N_P if (@status & ST_P) == ST_P return MesCmd::M_N_I if (@status & ST_C) == ST_C return MesCmd::M_N_N end #-------------------------------------------------------------------------- # ● 鍛冶可否判定 #-------------------------------------------------------------------------- def cond_enable? return true if @cond.empty? @cond.each {|c| c.update_status}.all? {|c| c.enable} end def price? @price <= $game_party.gold end def num?(n=1) (self.num + n) <= $game_party.max_item_number(obj) end #-------------------------------------------------------------------------- # ● 鍛冶実行 #-------------------------------------------------------------------------- def execute(change=false, actor=nil) $game_party.lose_gold(@price) @cond.each { |c| c.lose } gain equip(actor) if change lose if @b_id != 0 end #-------------------------------------------------------------------------- # ● 装備判定 #-------------------------------------------------------------------------- def equippable?(actor) actor.equippable?(obj) and actor.slot_list(obj.etype_id).all? {|slot| actor.equip_change_ok?(slot)} end #-------------------------------------------------------------------------- # ● 装備可能メンバー #-------------------------------------------------------------------------- def equippable_members actors = $game_party.members.select { |a| equippable?(a) } actors.collect { |a| a.index } end end # 武器・防具クラス class CommonWeapon < CommonData def obj $data_weapons[@a_id] end def b_obj $data_weapons[@b_id] end end class CommonArmor < CommonData def obj $data_armors[@a_id] end def b_obj $data_armors[@b_id] end end # リストクラス class CreateList attr_reader :equip_actors #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(type, b_id=0) @type = type @b_id = b_id reset_all end #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def reset_all @list = {} @equip_actors = [] end #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def reset(id) case @type when C_W; @list[id] = CommonWeapon.new(0, id, C_WEAPON[id]) when C_A; @list[id] = CommonArmor.new(0, id, C_ARMOR[id]) when S_W; @list[id] = CommonWeapon.new(@b_id, id, S_WEAPON[@b_id][id]) when S_A; @list[id] = CommonArmor.new(@b_id, id, S_ARMOR[@b_id][id]) end return @list[id] end #-------------------------------------------------------------------------- # ● オブジェクト参照 #-------------------------------------------------------------------------- def [](id) (@list[id].nil? ? reset(id) : @list[id]) end #-------------------------------------------------------------------------- # ● カテゴリ別リスト生成(生成用) #-------------------------------------------------------------------------- def make_list mlist = [] ids = ::Blacksmith.data(@type).keys.sort ct = ::Blacksmith.ctg(@type) ids.each do |id| d = self.[](id) next unless d.update_status # リスト作るときにステータス更新 ct.each_index do |i| mlist[i] = [] if mlist[i].nil? mlist[i] = ::Blacksmith.push(mlist[i], d, @type, ct[i]) end end ct.each_index do |i| mlist[i] = ::Blacksmith.sort(mlist[i], @type) end mlist end #-------------------------------------------------------------------------- # ● 強化用メソッド #-------------------------------------------------------------------------- def obj case @type when S_W; return $data_weapons[@b_id] when S_A; return $data_armors[@b_id] end end def enable? true end def num $game_party.item_number(obj) end #-------------------------------------------------------------------------- # ● アイテム所持判定(装備品含む) #-------------------------------------------------------------------------- def has_item? flag = (self.num > 0) @equip_actors = [] $game_party.members.each do |actor| @equip_actors.push(actor.index) if equip_item?(actor) end (flag or (@equip_actors.size > 0)) end #-------------------------------------------------------------------------- # ● アイテム装備判定 #-------------------------------------------------------------------------- def equip_item?(actor) actor.equips.include?(obj) and actor.slot_list(obj.etype_id).all? {|slot| actor.equip_change_ok?(slot)} end #-------------------------------------------------------------------------- # ● リスト生成(強化用) ※カテゴリ不要 #-------------------------------------------------------------------------- def make_slist slist = [] ids = ::Blacksmith.data(@type)[@b_id].keys.sort ids.each do |id| d = self.[](id) slist.push(d) if d.update_status # リスト作るときにステータス更新 end ::Blacksmith.sort(slist, @type) end end # リストクラス class StrengthenList #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(type) @type = type reset_all end #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def reset_all @list = {} end #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def reset(b_id) @list[b_id] = CreateList.new(@type, b_id) end #-------------------------------------------------------------------------- # ● オブジェクト参照 #-------------------------------------------------------------------------- def [](b_id) reset(b_id) if @list[b_id].nil? return @list[b_id] end #-------------------------------------------------------------------------- # ● カテゴリ別リスト生成 #-------------------------------------------------------------------------- def make_list mlist = [] ids = ::Blacksmith.data(@type).keys.sort ct = ::Blacksmith.ctg(@type) ids.each do |id| d = self.[](id) next unless d.has_item? # 所持アイテムのみ有効 ct.each_index do |i| mlist[i] = [] if mlist[i].nil? num = 0 a_ids = ::Blacksmith.data(@type)[id].keys a_ids.each do |a_id| if d[a_id].update_status # リスト作るときにステータス更新 num = 1; break end end next if num == 0 # 全て非表示なら除外 mlist[i] = ::Blacksmith.push(mlist[i], d, @type, ct[i]) end end ct.each_index do |i| mlist[i] = ::Blacksmith.sort(mlist[i], @type) end return mlist end end # Blacksmithクラス class Blacksmith attr_reader :c_w attr_reader :c_a attr_reader :s_w attr_reader :s_a def initialize reset_all end def reset_all @c_w = CreateList.new(C_W) @c_a = CreateList.new(C_A) @s_w = StrengthenList.new(S_W) @s_a = StrengthenList.new(S_A) end end end ## module Blacksmith #============================================================================== # ■ Game_System #============================================================================== class Game_System attr_reader :bs alias initialize_blacksmith initialize def initialize initialize_blacksmith @bs = Blacksmith::Blacksmith.new end end