#============================================================================== # ● Numset #------------------------------------------------------------------------------ # ■ 定数を扱うモジュールです。 #============================================================================== module Numset ACTOR_ITEM = 12 # 一人で持てるアイテムの最大数 end #============================================================================== # ■ Game_Actor #------------------------------------------------------------------------------ #  アクターを扱うクラスです。このクラスは Game_Actors クラス ($game_actors) # の内部で使用され、Game_Party クラス ($game_party) からも参照されます。 #============================================================================== class Game_Actor < Game_Battler #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_writer :weapon_id # 武器 ID attr_writer :armor1_id # 盾 ID attr_writer :armor2_id # 頭防具 ID attr_writer :armor3_id # 体防具 ID attr_writer :armor4_id # 装飾品 ID attr_reader :items # 所持アイテム attr_reader :equips # 装備品 #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- alias :base_setup :setup def setup(actor_id) base_setup(actor_id) @items = Array.new(Numset::ACTOR_ITEM){""} @equips = [] $game_party.gain_weapon(@weapon_id, 1, self) if @weapon_id > 0 $game_party.gain_armor(@armor1_id, 1, self) if @armor1_id > 0 $game_party.gain_armor(@armor2_id, 1, self) if @armor2_id > 0 $game_party.gain_armor(@armor3_id, 1, self) if @armor3_id > 0 $game_party.gain_armor(@armor4_id, 1, self) if @armor4_id > 0 @equips[0] = (@items.index("W#{@weapon_id}") == nil ? -1 : @items.index("W#{@weapon_id}")) @equips[1] = (@items.index("A#{@armor1_id}") == nil ? -1 : @items.index("A#{@armor1_id}")) @equips[2] = (@items.index("A#{@armor2_id}") == nil ? -1 : @items.index("A#{@armor2_id}")) @equips[3] = (@items.index("A#{@armor3_id}") == nil ? -1 : @items.index("A#{@armor3_id}")) @equips[4] = (@items.index("A#{@armor4_id}") == nil ? -1 : @items.index("A#{@armor4_id}")) end #-------------------------------------------------------------------------- # ● 装備の変更 # equip_type : 装備タイプ # id : 武器 or 防具 ID (0 なら装備解除) #-------------------------------------------------------------------------- def equip(equip_type, id) case equip_type when 0 # 武器 if id == 0 or @items.include?("W#{id}") @weapon_id = id @equips[0] = (@items.index("W#{id}") == nil ? -1 : @items.index("W#{id}")) end when 1 # 盾 if id == 0 or @items.include?("A#{id}") update_auto_state($data_armors[@armor1_id], $data_armors[id]) @armor1_id = id @equips[1] = (@items.index("A#{id}") == nil ? -1 : @items.index("A#{id}")) end when 2 # 頭 if id == 0 or @items.include?("A#{id}") update_auto_state($data_armors[@armor2_id], $data_armors[id]) @armor2_id = id @equips[2] = (@items.index("A#{id}") == nil ? -1 : @items.index("A#{id}")) end when 3 # 身体 if id == 0 or @items.include?("A#{id}") update_auto_state($data_armors[@armor3_id], $data_armors[id]) @armor3_id = id @equips[3] = (@items.index("A#{id}") == nil ? -1 : @items.index("A#{id}")) end when 4 # 装飾品 if id == 0 or @items.include?("A#{id}") update_auto_state($data_armors[@armor4_id], $data_armors[id]) @armor4_id = id @equips[4] = (@items.index("A#{id}") == nil ? -1 : @items.index("A#{id}")) end end end end #============================================================================== # ■ Game_Party #------------------------------------------------------------------------------ #  パーティを扱うクラスです。ゴールドやアイテムなどの情報が含まれます。このク # ラスのインスタンスは $game_party で参照されます。 #============================================================================== class Game_Party #-------------------------------------------------------------------------- # ● アイテムの所持数取得 # item_id : アイテム ID #-------------------------------------------------------------------------- alias :base_item_number :item_number def item_number(item_id) total = 0 for actor in @actors size = actor.items.select{|item| item == "I#{item_id}" } total += size.size end # ハッシュに個数データがあればその数値を、なければ 0 を返す total += (@items.include?(item_id) ? @items[item_id] : 0) return total end #-------------------------------------------------------------------------- # ● 武器の所持数取得 # weapon_id : 武器 ID #-------------------------------------------------------------------------- alias :base_weapon_number :weapon_number def weapon_number(weapon_id) total = 0 for actor in @actors size = actor.items.select{|item| item == "W#{weapon_id}" } total += size.size end # ハッシュに個数データがあればその数値を、なければ 0 を返す total += (@weapons.include?(weapon_id) ? @weapons[weapon_id] : 0) return total end #-------------------------------------------------------------------------- # ● 防具の所持数取得 # armor_id : 防具 ID #-------------------------------------------------------------------------- alias :base_armor_number :armor_number def armor_number(armor_id) total = 0 for actor in @actors size = actor.items.select{|item| item == "A#{armor_id}" } total += size.size end # ハッシュに個数データがあればその数値を、なければ 0 を返す total += (@armors.include?(armor_id) ? @armors[armor_id] : 0) return total end #-------------------------------------------------------------------------- # ● アイテムの増加 # item_id : アイテム ID # n : 個数 #-------------------------------------------------------------------------- def base_gain_item(item_id, n) # ハッシュの個数データを更新 if item_id > 0 @items[item_id] = [[base_item_number(item_id) + n, 0].max, 99].min end end def gain_item(item_id, n, target = nil) if target != nil size = target.items.select{|item| item == ""}.size while size != 0 and n != 0 target.items[target.items.index("")] = "I#{item_id}" size -= 1 n -= 1 end return if n == 0 else for actor in @actors size = actor.items.select{|item| item == ""}.size while size != 0 and n != 0 actor.items[actor.items.index("")] = "I#{item_id}" size -= 1 n -= 1 end return if n == 0 end end base_gain_item(item_id, n) end #-------------------------------------------------------------------------- # ● 武器の増加 # weapon_id : 武器 ID # n : 個数 #-------------------------------------------------------------------------- def base_gain_weapon(weapon_id, n) # ハッシュの個数データを更新 if weapon_id > 0 @weapons[weapon_id] = [[base_weapon_number(weapon_id) + n, 0].max, 99].min end end def gain_weapon(weapon_id, n, target = nil) if target != nil size = target.items.select{|item| item == ""}.size while size != 0 and n != 0 target.items[target.items.index("")] = "W#{weapon_id}" size -= 1 n -= 1 end return if n == 0 else for actor in @actors size = actor.items.select{|item| item == ""}.size while size != 0 and n != 0 actor.items[actor.items.index("")] = "W#{weapon_id}" size -= 1 n -= 1 end return if n == 0 end end base_gain_weapon(weapon_id, n) end #-------------------------------------------------------------------------- # ● 防具の増加 # armor_id : 防具 ID # n : 個数 #-------------------------------------------------------------------------- def base_gain_armor(armor_id, n) # ハッシュの個数データを更新 if armor_id > 0 @armors[armor_id] = [[base_armor_number(armor_id) + n, 0].max, 99].min end end def gain_armor(armor_id, n, target = nil) if target != nil size = target.items.select{|item| item == ""}.size while size != 0 and n != 0 target.items[target.items.index("")] = "A#{armor_id}" size -= 1 n -= 1 end return if n == 0 else for actor in @actors size = actor.items.select{|item| item == ""}.size while size != 0 and n != 0 actor.items[actor.items.index("")] = "A#{armor_id}" size -= 1 n -= 1 end return if n == 0 end end base_gain_armor(armor_id, n) end #-------------------------------------------------------------------------- # ● アイテムの減少 # item_id : アイテム ID # n : 個数 #-------------------------------------------------------------------------- def base_lose_item(item_id, n) # 数値を逆転して gain_item を呼ぶ base_gain_item(item_id, -n) end def lose_item(item_id, n, target = nil) if target != nil while target.items.include?("I#{item_id}") and n != 0 target.items[target.items.rindex("I#{item_id}")] = "" n -= 1 end # 詰めろとりあえず target.items.delete("") target.items.fill("", target.items.size...Numset::ACTOR_ITEM) return if n == 0 else for actor in @actors while actor.items.include?("I#{item_id}") and n != 0 actor.items[actor.items.rindex("I#{item_id}")] = "" n -= 1 end # 詰めろとりあえず actor.items.delete("") actor.items.fill("", actor.items.size...Numset::ACTOR_ITEM) end return if n == 0 end base_gain_item(item_id, -n) end #-------------------------------------------------------------------------- # ● 武器の減少 # weapon_id : 武器 ID # n : 個数 #-------------------------------------------------------------------------- def base_lose_weapon(weapon_id, n) # 数値を逆転して gain_weapon を呼ぶ base_gain_weapon(weapon_id, -n) end def lose_weapon(weapon_id, n, target = nil) if target != nil while target.items.include?("W#{weapon_id}") and n != 0 target.items[target.items.rindex("W#{weapon_id}")] = "" n -= 1 end # 詰めろとりあえず target.items.delete("") target.items.fill("", target.items.size...Numset::ACTOR_ITEM) return if n == 0 else for actor in @actors while actor.items.include?("W#{weapon_id}") and n != 0 actor.items[actor.items.rindex("W#{weapon_id}")] = "" n -= 1 end # 詰めろとりあえず actor.items.delete("") actor.items.fill("", actor.items.size...Numset::ACTOR_ITEM) end return if n == 0 end base_gain_weapon(weapon_id, -n) end #-------------------------------------------------------------------------- # ● 防具の減少 # armor_id : 防具 ID # n : 個数 #-------------------------------------------------------------------------- def base_lose_armor(armor_id, n) # 数値を逆転して gain_armor を呼ぶ base_gain_armor(armor_id, -n) end def lose_armor(armor_id, n, target) if target != nil while target.items.include?("A#{armor_id}") and n != 0 target.items[target.items.rindex("A#{armor_id}")] = "" n -= 1 end # 詰めろとりあえず target.items.delete("") target.items.fill("", target.items.size...Numset::ACTOR_ITEM) return if n == 0 else for actor in @actors while actor.items.include?("A#{armor_id}") and n != 0 actor.items[actor.items.rindex("A#{armor_id}")] = "" n -= 1 end # 詰めろとりあえず actor.items.delete("") actor.items.fill("", actor.items.size...Numset::ACTOR_ITEM) end return if n == 0 end base_gain_armor(armor_id, -n) end end #============================================================================== # ■ Window_ActorItem #------------------------------------------------------------------------------ #  アイテム画面、バトル画面で、所持アイテムの一覧を表示するウィンドウです。 #============================================================================== class Window_ActorItem < Selectable_Nomove #-------------------------------------------------------------------------- # ● いんくるーでぃんぐ #-------------------------------------------------------------------------- include(Window_Cursor) #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(actor, height, viewport = nil) super(actor.index * 320, 0, 320, height, Item_Nomove, viewport) @actor = actor size = actor.items.select{|item| item != "" } @column_max = 1 if !$scene.is_a?(Scene_Battle) or size.size == 0 @item_max = [size.size + 1, Numset::ACTOR_ITEM].min else @item_max = [size.size, Numset::ACTOR_ITEM].min end self.contents = Bitmap.new(width - 32, row_max * 32) self.active = false self.child.item_max = @item_max self.child.column_max = @column_max refresh self.index = -1 # 戦闘中の場合はウィンドウを画面中央へ移動し、半透明にする if $game_temp.in_battle self.x = 0 self.y = 64 self.height = 256 self.back_opacity = 160 end end #-------------------------------------------------------------------------- # ● アクターの取得 #-------------------------------------------------------------------------- def actor return @actor end #-------------------------------------------------------------------------- # ● サイズの変更 #-------------------------------------------------------------------------- def item_max=(val) super self.child.item_max = @item_max end #-------------------------------------------------------------------------- # ● アイテムの取得 #-------------------------------------------------------------------------- def item return (self.index2 >= 0 ? @data[self.index2] : @data[self.index]) end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh self.contents.clear @data = [] # 戦闘移動を問わず、全てのアイテムを描写 for item in @actor.items if item =~ /I(\d+)/ @data.push($data_items[$1.to_i]) end if item =~ /W(\d+)/ @data.push($data_weapons[$1.to_i]) end if item =~ /A(\d+)/ @data.push($data_armors[$1.to_i]) end end if @item_max > 0 for i in 0...@item_max draw_item(i) end end end #-------------------------------------------------------------------------- # ● 項目の描画 # index : 項目番号 #-------------------------------------------------------------------------- def draw_item(index) return if @data[index] == nil item = @data[index] if item.is_a?(RPG::Item) and $game_party.item_can_use?(item.id) self.contents.font.color = normal_color else self.contents.font.color = disabled_color end x = 4 y = index * 32 rect = Rect.new(x, y, self.width / @column_max - 32, 32) self.contents.fill_rect(rect, Color.new(0, 0, 0, 0)) if @actor.equips.include?(index) if $scene.is_a?(Scene_Battle) opacity = (self.contents.font.color == normal_color ? 255 : 128) else self.contents.font.color = normal_color end rect = Rect.new(0, 0, 24, 24) bitmap = RPG::Cache.text(24, 24, "E", self.system_color, 22) self.contents.blt(x, y + 4, bitmap, rect) bitmap = RPG::Cache.icon(item.icon_name) self.contents.blt(x + 24, y + 4, bitmap, rect) self.contents.draw_text(x + 52, y, 188, 32, item.name, 0) else bitmap = RPG::Cache.icon(item.icon_name) opacity = (self.contents.font.color == normal_color ? 255 : 128) self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity) self.contents.draw_text(x + 28, y, 188, 32, item.name, 0) end end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update(imput = true) super # カーソルの移動が可能な状態の場合 if self.active and @item_max > 0 and @index >= 0 and imput # 方向ボタンの下が押された場合 if Input.repeat?(Input::DOWN) # 列数が 1 かつ 方向ボタンの下の押下状態がリピートでない場合か、 # またはカーソル位置が(項目数 - 列数)より前の場合 if (@column_max == 1 and Input.trigger?(Input::DOWN)) or @index < @item_max - @column_max # カーソルを下に移動 $game_system.se_play($data_system.cursor_se) @index = (@index + @column_max) % @item_max end end # 方向ボタンの上が押された場合 if Input.repeat?(Input::UP) # 列数が 1 かつ 方向ボタンの上の押下状態がリピートでない場合か、 # またはカーソル位置が列数より後ろの場合 if (@column_max == 1 and Input.trigger?(Input::UP)) or @index >= @column_max # カーソルを上に移動 $game_system.se_play($data_system.cursor_se) @index = (@index - @column_max + @item_max) % @item_max end end # 方向ボタンの右が押された場合 if Input.repeat?(Input::RIGHT) and !$scene.is_a?(Scene_Battle) $game_system.se_play($data_system.cursor_se) $scene.active_window += 1 self.active = false act = $scene.windows[$scene.active_window] act.active = true act.index = [act.item_max - 1, self.index].min self.index = -1 self.viewport.ox = [320 * ($scene.active_window - 1), 0].max end # 方向ボタンの左が押された場合 if Input.repeat?(Input::LEFT) and !$scene.is_a?(Scene_Battle) $game_system.se_play($data_system.cursor_se) if $scene.active_window == 0 $scene.active_window = $scene.windows.size - 1 self.active = false act = $scene.windows[$scene.active_window] act.active = true act.index = [act.item_max - 1, self.index].min self.index = -1 else $scene.active_window -= 1 self.active = false act = $scene.windows[$scene.active_window] act.active = true act.index = [act.item_max - 1, self.index].min self.index = -1 end self.viewport.ox = [320 * ($scene.active_window - 1), 0].max end end # ヘルプテキストを更新 (update_help は継承先で定義される) if self.active and @help_window != nil update_help end # カーソルの矩形を更新 update_cursor_rect end #-------------------------------------------------------------------------- # ● ヘルプテキスト更新 #-------------------------------------------------------------------------- def update_help @help_window.set_text(self.item == nil ? "" : self.item.description) end end #============================================================================== # ■ Window_Item #------------------------------------------------------------------------------ #  アイテム画面、バトル画面で、所持アイテムの一覧を表示するウィンドウです。 #============================================================================== class Window_Item < Selectable_Nomove #-------------------------------------------------------------------------- # ● いんくるーでぃんぐ #-------------------------------------------------------------------------- include(Window_Cursor) #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(height, viewport = nil) super($game_party.actors.size * 320, 0, 320, height, Item_Nomove, viewport) @column_max = 1 refresh self.active = false self.index = -1 self.child.item_max = @item_max self.child.column_max = @column_max # 戦闘中の場合はウィンドウを画面中央へ移動し、半透明にする if $game_temp.in_battle self.x = 0 self.y = 64 self.height = 256 self.back_opacity = 160 end end #-------------------------------------------------------------------------- # ● アクターの取得 #-------------------------------------------------------------------------- def actor return true end #-------------------------------------------------------------------------- # ● アイテムの取得 #-------------------------------------------------------------------------- def item return (self.index2 >= 0 ? @data[self.index2] : @data[self.index]) end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh if self.contents != nil self.contents.dispose self.contents = nil end @data = [] # 戦闘移動を問わず、全てのアイテムを追加 for i in 1...$data_items.size if $game_party.base_item_number(i) > 0 @data.push($data_items[i]) end end for i in 1...$data_weapons.size if $game_party.base_weapon_number(i) > 0 @data.push($data_weapons[i]) end end for i in 1...$data_armors.size if $game_party.base_armor_number(i) > 0 @data.push($data_armors[i]) end end @data.push(nil) # 項目数が 0 でなければビットマップを作成し、全項目を描画 @item_max = @data.size self.child.item_max = @item_max self.contents = Bitmap.new(width - 32, row_max * 32) for i in 0...@item_max draw_item(i) end end #-------------------------------------------------------------------------- # ● 項目の描画 # index : 項目番号 #-------------------------------------------------------------------------- def draw_item(index) return if @data[index] == nil item = @data[index] case item when RPG::Item number = $game_party.base_item_number(item.id) when RPG::Weapon number = $game_party.base_weapon_number(item.id) when RPG::Armor number = $game_party.base_armor_number(item.id) end if item.is_a?(RPG::Item) and $game_party.item_can_use?(item.id) self.contents.font.color = normal_color else self.contents.font.color = disabled_color end x = 4 y = index * 32 rect = Rect.new(x, y, self.width / @column_max - 32, 32) self.contents.fill_rect(rect, Color.new(0, 0, 0, 0)) bitmap = RPG::Cache.icon(item.icon_name) opacity = self.contents.font.color == normal_color ? 255 : 128 self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity) self.contents.draw_text(x + 28, y, 212, 32, item.name, 0) self.contents.draw_text(x + 240, y, 16, 32, ":", 1) self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2) end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update(imput = true) super # カーソルの移動が可能な状態の場合 if self.active and @item_max > 0 and @index >= 0 and imput # 方向ボタンの下が押された場合 if Input.repeat?(Input::DOWN) # 列数が 1 かつ 方向ボタンの下の押下状態がリピートでない場合か、 # またはカーソル位置が(項目数 - 列数)より前の場合 if (@column_max == 1 and Input.trigger?(Input::DOWN)) or @index < @item_max - @column_max # カーソルを下に移動 $game_system.se_play($data_system.cursor_se) @index = (@index + @column_max) % @item_max end end # 方向ボタンの上が押された場合 if Input.repeat?(Input::UP) # 列数が 1 かつ 方向ボタンの上の押下状態がリピートでない場合か、 # またはカーソル位置が列数より後ろの場合 if (@column_max == 1 and Input.trigger?(Input::UP)) or @index >= @column_max # カーソルを上に移動 $game_system.se_play($data_system.cursor_se) @index = (@index - @column_max + @item_max) % @item_max end end # 方向ボタンの右が押された場合 if Input.repeat?(Input::RIGHT) $game_system.se_play($data_system.cursor_se) $scene.active_window = 0 self.active = false act = $scene.windows[$scene.active_window] act.active = true act.index = [act.item_max - 1, self.index].min self.index = -1 self.viewport.ox = [320 * ($scene.active_window - 1), 0].max end # 方向ボタンの左が押された場合 if Input.repeat?(Input::LEFT) $game_system.se_play($data_system.cursor_se) $scene.active_window -= 1 self.active = false act = $scene.windows[$scene.active_window] act.active = true act.index = [act.item_max - 1, self.index].min self.index = -1 self.viewport.ox = [320 * ($scene.active_window - 1), 0].max end end # ヘルプテキストを更新 (update_help は継承先で定義される) if self.active and @help_window != nil update_help end # カーソルの矩形を更新 update_cursor_rect end #-------------------------------------------------------------------------- # ● ヘルプテキスト更新 #-------------------------------------------------------------------------- def update_help @help_window.set_text(self.item == nil ? "" : self.item.description) end end #============================================================================== # ■ Item_Nomove #------------------------------------------------------------------------------ #  アイテム画面の第二カーソルウィンドウです。 #============================================================================== class Item_Nomove < Selectable_Nomove #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update(imput = true) super() # カーソルの移動が可能な状態の場合 if self.active and @item_max > 0 and @index >= 0 and imput # 方向ボタンの下が押された場合 if Input.repeat?(Input::DOWN) # 列数が 1 かつ 方向ボタンの下の押下状態がリピートでない場合か、 # またはカーソル位置が(項目数 - 列数)より前の場合 if (@column_max == 1 and Input.trigger?(Input::DOWN)) or @index < @item_max - @column_max # カーソルを下に移動 $game_system.se_play($data_system.cursor_se) @index = (@index + @column_max) % @item_max end end # 方向ボタンの上が押された場合 if Input.repeat?(Input::UP) # 列数が 1 かつ 方向ボタンの上の押下状態がリピートでない場合か、 # またはカーソル位置が列数より後ろの場合 if (@column_max == 1 and Input.trigger?(Input::UP)) or @index >= @column_max # カーソルを上に移動 $game_system.se_play($data_system.cursor_se) @index = (@index - @column_max + @item_max) % @item_max end end # 方向ボタンの右が押された場合 if Input.repeat?(Input::RIGHT) $game_system.se_play($data_system.cursor_se) if $scene.active_window == ($scene.windows.size - 1) $scene.active_window = 0 self.active = false act = $scene.windows[$scene.active_window] act.child.active = true act.index2 = [act.item_max - 1, self.index].min self.index = -1 else $scene.active_window += 1 self.active = false act = $scene.windows[$scene.active_window] act.child.active = true act.index2 = [act.item_max - 1, self.index].min self.index = -1 end self.viewport.ox = [320 * ($scene.active_window - 1), 0].max end # 方向ボタンの左が押された場合 if Input.repeat?(Input::LEFT) $game_system.se_play($data_system.cursor_se) if $scene.active_window == 0 $scene.active_window = $scene.windows.size - 1 self.active = false act = $scene.windows[$scene.active_window] act.child.active = true act.index2 = [act.item_max - 1, self.index].min self.index = -1 else $scene.active_window -= 1 self.active = false act = $scene.windows[$scene.active_window] act.child.active = true act.index2 = [act.item_max - 1, self.index].min self.index = -1 end self.viewport.ox = [320 * ($scene.active_window - 1), 0].max end end # カーソルの矩形を更新 update_cursor_rect end end #============================================================================== # ■ Window_EquipItem #------------------------------------------------------------------------------ #  装備画面で、装備変更の候補となるアイテムの一覧を表示するウィンドウです。 #============================================================================== class Window_EquipItem < Window_Selectable #-------------------------------------------------------------------------- # ● オブジェクト初期化 # actor : アクター # equip_type : 装備部位 (0〜3) #-------------------------------------------------------------------------- def initialize(actor, equip_type) super(0, 256, 640, 224) @actor = actor @equip_type = equip_type self.contents = Bitmap.new(width - 32, (Numset::ACTOR_ITEM / 2.0).ceil * 32) @item_max = (@actor.items.select{|item| item != nil}).size @column_max = 2 refresh self.active = false self.index = -1 end #-------------------------------------------------------------------------- # ● アイテムの取得 #-------------------------------------------------------------------------- def item return @data[self.index] end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh self.contents.clear @data = [] # 装備可能な武器を追加 if @equip_type == 0 weapon_set = $data_classes[@actor.class_id].weapon_set for item in @actor.items if item =~ /W(\d+)/ and weapon_set.include?($1.to_i) @data.push($data_weapons[$1.to_i]) unless @data.include?($data_weapons[$1.to_i]) end end end # 装備可能な防具を追加 if @equip_type != 0 armor_set = $data_classes[@actor.class_id].armor_set for item in @actor.items if item =~ /A(\d+)/ and armor_set.include?($1.to_i) if $data_armors[$1.to_i].kind == @equip_type - 1 @data.push($data_armors[$1.to_i]) unless @data.include?($data_weapons[$1.to_i]) end end end end # 空白を追加 @data.push(nil) # 全項目を描画 @item_max = @data.size for i in 0...@item_max - 1 draw_item(i) end end #-------------------------------------------------------------------------- # ● 項目の描画 # index : 項目番号 #-------------------------------------------------------------------------- def draw_item(index) item = @data[index] x = 4 + index % 2 * (288 + 32) y = index / 2 * 32 bitmap = RPG::Cache.icon(item.icon_name) self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24)) self.contents.font.color = normal_color self.contents.draw_text(x + 28, y, 212, 32, item.name, 0) end #-------------------------------------------------------------------------- # ● ヘルプテキスト更新 #-------------------------------------------------------------------------- def update_help @help_window.set_text(self.item == nil ? "" : self.item.description) end end #============================================================================== # ■ Scene_Item #------------------------------------------------------------------------------ #  アイテム画面の処理を行うクラスです。 #============================================================================== class Scene_Item attr_accessor :active_window attr_reader :windows attr_accessor :save_window #-------------------------------------------------------------------------- # ● メイン処理 #-------------------------------------------------------------------------- def main # ヘルプウィンドウ、アイテムウィンドウを作成 @help_window = Window_Help.new @viewport = Viewport.new(0, 64, 320 * ($game_party.actors.size + 1), 416) @windows = [] for actor in $game_party.actors @windows.push(Window_ActorItem.new(actor, 416, @viewport)) end @windows.push(Window_Item.new(416, @viewport)) @windows[0].active = true @windows[0].index = 0 @active_window = 0 @save_window = -1 # ヘルプウィンドウを関連付け @windows.each{|window| window.help_window = @help_window } # ターゲットウィンドウを作成 (不可視・非アクティブに設定) @target_window = Window_Target.new @target_window.visible = false @target_window.active = false # トランジション実行 Graphics.transition # メインループ loop do # ゲーム画面を更新 Graphics.update # 入力情報を更新 Input.update # フレーム更新 update # 画面が切り替わったらループを中断 if $scene != self break end end # トランジション準備 Graphics.freeze # ウィンドウを解放 @help_window.dispose @windows.each{|window| window.dispose } @viewport.dispose @target_window.dispose end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update # ウィンドウを更新 @help_window.update act = @active_window @windows.each{|window| window.update(@windows.index(window) == act) } @target_window.update # アイテムウィンドウがアクティブの場合: update_item を呼ぶ if (@windows.find{|window| window.active or window.child.active }) != nil update_item return end # ターゲットウィンドウがアクティブの場合: update_target を呼ぶ if @target_window.active update_target return end end #-------------------------------------------------------------------------- # ● フレーム更新 (アイテムウィンドウがアクティブの場合) #-------------------------------------------------------------------------- def update_item # B ボタンが押された場合 if Input.trigger?(Input::B) # キャンセル SE を演奏 $game_system.se_play($data_system.cancel_se) if @save_window >= 0 # 第二カーソルを消す act = @active_window @windows[@active_window].index2 = -1 # 重なった場合でもtrueになるので安心 @windows[@active_window].active = false @windows[@save_window].active = true @active_window = @save_window @save_window = -1 else # メニュー画面に切り替え $scene = Scene_Menu.new(0) end return end # C ボタンが押された場合 if Input.trigger?(Input::C) if @save_window >= 0 change_item else # アイテムウィンドウで現在選択されているデータを取得 @item = @windows[@active_window].item # 使用アイテムではない場合 unless @item.is_a?(RPG::Item) # ブザー SE を演奏 $game_system.se_play($data_system.buzzer_se) return end # 使用できない場合 unless $game_party.item_can_use?(@item.id) # ブザー SE を演奏 $game_system.se_play($data_system.buzzer_se) return end # 決定 SE を演奏 $game_system.se_play($data_system.decision_se) # 効果範囲が味方の場合 if @item.scope >= 3 # ターゲットウィンドウをアクティブ化 @windows[@active_window].active = false @target_window.x = (@windows[@active_window].index + 1) % 2 * 304 @target_window.visible = true @target_window.active = true # 効果範囲 (単体/全体) に応じてカーソル位置を設定 if @item.scope == 4 || @item.scope == 6 @target_window.index = -1 else @target_window.index = 0 end # 効果範囲が味方以外の場合 else # コモンイベント ID が有効の場合 if @item.common_event_id > 0 # コモンイベント呼び出し予約 $game_temp.common_event_id = @item.common_event_id # アイテムの使用時 SE を演奏 $game_system.se_play(@item.menu_se) # 消耗品の場合 if @item.consumable # 使用したアイテムを 1 減らす if @windows[@active_window].is_a?("Window_Item") $game_party.base_lose_item(@item.id, 1) else $game_party.lose_item(@item.id, 1, @windows[@active_window].actor) end # アイテムウィンドウの項目を再描画 @windows[@active_window].draw_item(@windows[@active_window].index) end # マップ画面に切り替え $scene = Scene_Map.new return end end end return end # X ボタンが押された場合 if Input.trigger?(Input::X) if @save_window >= 0 change_item else # 決定 SE を演奏 $game_system.se_play($data_system.decision_se) # 第二カーソルを出す @windows[@active_window].active = false @windows[@active_window].index2 = @windows[@active_window].index @save_window = @active_window end end end #-------------------------------------------------------------------------- # ● フレーム更新 (ターゲットウィンドウがアクティブの場合) #-------------------------------------------------------------------------- def update_target # B ボタンが押された場合 if Input.trigger?(Input::B) # キャンセル SE を演奏 $game_system.se_play($data_system.cancel_se) # アイテム切れなどで使用できなくなった場合 unless $game_party.item_can_use?(@item.id) # アイテムウィンドウの内容を再作成 @windows[@active_window].refresh end # ターゲットウィンドウを消去 @windows[@active_window].active = true @target_window.visible = false @target_window.active = false return end # C ボタンが押された場合 if Input.trigger?(Input::C) # アイテムを使い切った場合 if $game_party.item_number(@item.id) == 0 # ブザー SE を演奏 $game_system.se_play($data_system.buzzer_se) return end # ターゲットが全体の場合 if @target_window.index == -1 # パーティ全体にアイテムの使用効果を適用 used = false for i in $game_party.actors used |= i.item_effect(@item) end end # ターゲットが単体の場合 if @target_window.index >= 0 # ターゲットのアクターにアイテムの使用効果を適用 target = $game_party.actors[@target_window.index] used = target.item_effect(@item) end # アイテムを使った場合 if used # アイテムの使用時 SE を演奏 $game_system.se_play(@item.menu_se) # 消耗品の場合 if @item.consumable # 使用したアイテムを 1 減らす if @windows[@active_window].is_a?("Window_Item") $game_party.base_lose_item(@item.id, 1) else $game_party.lose_item(@item.id, 1, @windows[@active_window].actor) end # アイテムウィンドウの項目を再描画 @windows[@active_window].draw_item(@windows[@active_window].index) end # ターゲットウィンドウの内容を再作成 @target_window.refresh # 全滅の場合 if $game_party.all_dead? # ゲームオーバー画面に切り替え $scene = Scene_Gameover.new return end # コモンイベント ID が有効の場合 if @item.common_event_id > 0 # コモンイベント呼び出し予約 $game_temp.common_event_id = @item.common_event_id # マップ画面に切り替え $scene = Scene_Map.new return end end # アイテムを使わなかった場合 unless used # ブザー SE を演奏 $game_system.se_play($data_system.buzzer_se) end return end end #-------------------------------------------------------------------------- # ● アイテムの交換 #-------------------------------------------------------------------------- def change_item #アイテムウィンドウ同士の場合 if @windows[@active_window].is_a?(Window_Item) and @windows[@save_window].is_a?(Window_Item) # ブザー SE を演奏 $game_system.se_play($data_system.buzzer_se) return else # 決定 SE を演奏 $game_system.se_play($data_system.decision_se) # アイテムを交換 if @windows[@active_window].is_a?(Window_Item) # 共有欄から個別欄 item1 = @windows[@active_window].item case item1 when RPG::Item $game_party.base_lose_item(item1.id, 1) text = "I#{item1.id}" when RPG::Weapon $game_party.base_lose_weapon(item1.id, 1) text = "W#{item1.id}" when RPG::Armor $game_party.base_lose_armor(item1.id, 1) text = "A#{item1.id}" end actor = @windows[@save_window].actor item2 = actor.items[@windows[@save_window].index] # 装備解除 if @windows[@save_window].index == actor.equips[0] actor.weapon_id = 0 actor.equips[0] = -1 elsif @windows[@save_window].index == actor.equips[1] actor.armor1_id = 0 elsif @windows[@save_window].index == actor.equips[2] actor.armor2_id = 0 actor.equips[2] = -1 elsif @windows[@save_window].index == actor.equips[3] actor.armor3_id = 0 actor.equips[3] = -1 elsif @windows[@save_window].index == actor.equips[4] actor.armor4_id = 0 actor.equips[4] = -1 end actor.items[@windows[@save_window].index] = text if item2 =~ /I(\d+)/ $game_party.base_gain_item($1.to_i, 1) elsif item2 =~ /W(\d+)/ $game_party.base_gain_weapon($1.to_i, 1) elsif item2 =~ /A(\d+)/ $game_party.base_gain_armor($1.to_i, 1) end # 詰める if actor.items[@windows[@save_window].index].nil? for i in 1..4 if @windows[@save_window].index < i and actor.equips[i] >= 0 actor.equips[i] -= 1 end end end # 詰めろとりあえず if actor.items.index("") != nil actor.items.compact! actor.items.delete("") actor.items.fill("", actor.items.size...Numset::ACTOR_ITEM) end @windows[@save_window].item_max = [(actor.items.select{|item| item != "" }).size + 1, Numset::ACTOR_ITEM].min @windows[@save_window].refresh @windows[@active_window].refresh elsif @windows[@save_window].is_a?(Window_Item) actor = @windows[@active_window].actor item1 = @windows[@save_window].item case item1 when RPG::Item $game_party.base_lose_item(item1.id, 1) text = "I#{item1.id}" when RPG::Weapon $game_party.base_lose_weapon(item1.id, 1) text = "W#{item1.id}" when RPG::Armor $game_party.base_lose_armor(item1.id, 1) text = "A#{item1.id}" end item2 = @windows[@active_window].actor.items[@windows[@active_window].index2] # 装備解除 if @windows[@active_window].index2 == actor.equips[0] actor.weapon_id = 0 actor.equips[0] = -1 elsif @windows[@active_window].index2 == actor.equips[1] actor.armor1_id = 0 actor.equips[1] = -1 elsif @windows[@active_window].index2 == actor.equips[2] actor.armor2_id = 0 actor.equips[2] = -1 elsif @windows[@active_window].index2 == actor.equips[3] actor.armor3_id = 0 actor.equips[3] = -1 elsif @windows[@active_window].index2 == actor.equips[4] actor.armor4_id = 0 actor.equips[4] = -1 end actor.items[@windows[@active_window].index2] = text if item2 =~ /I(\d+)/ $game_party.base_gain_item($1.to_i, 1) elsif item2 =~ /W(\d+)/ $game_party.base_gain_weapon($1.to_i, 1) elsif item2 =~ /A(\d+)/ $game_party.base_gain_armor($1.to_i, 1) end # 詰める if actor.items[@windows[@active_window].index2].nil? for i in 1..4 if @windows[@active_window].index2 < i and actor.equips[i] >= 0 actor.equips[i] -= 1 end end end p actor.equips # 詰めろとりあえず if actor.items.index("") != nil actor.items.compact! actor.items.delete("") actor.items.fill("", actor.items.size...Numset::ACTOR_ITEM) end @windows[@active_window].item_max = [(actor.items.select{|item| item != "" }).size + 1, Numset::ACTOR_ITEM].min @windows[@save_window].refresh @windows[@active_window].refresh else actor1 = @windows[@active_window].actor actor2 = @windows[@save_window].actor item1 = @windows[@active_window].actor.items[@windows[@active_window].index2] item2 = @windows[@save_window].actor.items[@windows[@save_window].index] # 装備解除 if @windows[@active_window].index2 == actor1.equips[0] if @active_window == @save_window actor1.equips[0] = @windows[@save_window].index else actor1.weapon_id = 0 actor1.equips[0] = -1 end elsif @windows[@active_window].index2 == actor1.equips[1] if @active_window == @save_window actor1.equips[1] = @windows[@save_window].index else actor1.armor1_id = 0 actor1.equips[1] = -1 end elsif @windows[@active_window].index2 == actor1.equips[2] if @active_window == @save_window actor1.equips[2] = @windows[@save_window].index else actor1.armor2_id = 0 actor1.equips[2] = -1 end elsif @windows[@active_window].index2 == actor1.equips[3] if @active_window == @save_window actor1.equips[3] = @windows[@save_window].index else actor1.armor3_id = 0 actor1.equips[3] = -1 end elsif @windows[@active_window].index2 == actor1.equips[4] if @active_window == @save_window actor1.equips[4] = @windows[@save_window].index else actor1.armor4_id = 0 actor1.equips[4] = -1 end end # 装備解除 if @windows[@save_window].index == actor2.equips[0] if @active_window == @save_window actor2.equips[0] = @windows[@active_window].index2 else actor2.weapon_id = 0 actor2.equips[0] = -1 end elsif @windows[@save_window].index == actor2.equips[1] if @active_window == @save_window actor2.equips[1] = @windows[@active_window].index2 else actor2.armor1_id = 0 actor2.equips[1] = -1 end elsif @windows[@save_window].index == actor2.equips[2] if @active_window == @save_window actor2.equips[2] = @windows[@active_window].index2 else actor2.armor2_id = 0 actor2.equips[2] = -1 end elsif @windows[@save_window].index == actor2.equips[3] if @active_window == @save_window actor2.equips[3] = @windows[@active_window].index2 else actor2.armor3_id = 0 actor2.equips[3] = -1 end elsif @windows[@save_window].index == actor2.equips[4] if @active_window == @save_window actor2.equips[4] = @windows[@active_window].index2 else actor2.armor4_id = 0 actor2.equips[4] = -1 end end actor1.items[@windows[@active_window].index2] = item2 actor2.items[@windows[@save_window].index] = item1 # 詰める if actor1.items[@windows[@active_window].index2].nil? for i in 1..4 if @windows[@active_window].index2 < i and actor1.equips[i] >= 0 actor1.equips[i] -= 1 end end end if actor2.items[@windows[@save_window].index].nil? for i in 1..4 if @windows[@save_window].index < i and actor2.equips[i] >= 0 actor2.equips[i] -= 1 end end end # 詰めろとりあえず actor1.items.delete("") actor1.items.fill("", actor1.items.size...Numset::ACTOR_ITEM) @windows[@active_window].item_max = [(actor1.items.select{|item| item != "" }).size + 1, Numset::ACTOR_ITEM].min actor2.items.delete("") actor2.items.fill("", actor2.items.size...Numset::ACTOR_ITEM) @windows[@save_window].item_max = [(actor2.items.select{|item| item != "" }).size + 1, Numset::ACTOR_ITEM].min end # アイテムウィンドウの項目を再描画 @windows[@active_window].refresh @windows[@save_window].refresh if @active_window != @save_window end # 第二カーソルを消す act = @active_window @windows[@active_window].index2 = -1 # 重なった場合でもtrueになるので安心 @windows[@active_window].active = false @windows[@save_window].active = true @active_window = @save_window @save_window = -1 end end #============================================================================== # ■ Window_EquipItem #------------------------------------------------------------------------------ #  装備画面で、装備変更の候補となるアイテムの一覧を表示するウィンドウです。 #============================================================================== class Window_EquipItem < Window_Selectable #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh if self.contents != nil self.contents.dispose self.contents = nil end @data = [] # 装備可能な武器を追加 if @equip_type == 0 weapon_set = $data_classes[@actor.class_id].weapon_set for i in 0...@actor.items.size item = @actor.items[i] num = item[/\d+/].to_i if item.include?("W") and weapon_set.include?(num) and @actor.equips[0] != i @data.push($data_weapons[num]) end end # 装備可能な防具を追加 else armor_set = $data_classes[@actor.class_id].armor_set for i in 0...@actor.items.size item = @actor.items[i] num = item[/\d+/].to_i if item.include?("A") and armor_set.include?(num) and $data_armors[num].kind == (@equip_type - 1) and @actor.equips[@equip_type] != i @data.push($data_armors[num]) end end end # 空白を追加 @data.push(nil) # ビットマップを作成し、全項目を描画 @item_max = @data.size self.contents = Bitmap.new(width - 32, row_max * 32) for i in 0...@item_max-1 draw_item(i) end end end #============================================================================== # ■ Scene_Shop #------------------------------------------------------------------------------ #  ショップ画面の処理を行うクラスです。 #============================================================================== class Scene_Shop attr_accessor :active_window attr_reader :windows #-------------------------------------------------------------------------- # ● メイン処理 #-------------------------------------------------------------------------- def main # ヘルプウィンドウを作成 @help_window = Window_Help.new # コマンドウィンドウを作成 @command_window = Window_ShopCommand.new # ゴールドウィンドウを作成 @gold_window = Window_Gold.new @gold_window.x = 480 @gold_window.y = 64 # ダミーウィンドウを作成 @dummy_window = Window_Base.new(0, 128, 640, 352) # 購入ウィンドウを作成 @buy_window = Window_ShopBuy.new($game_temp.shop_goods) @buy_window.active = false @buy_window.visible = false @buy_window.help_window = @help_window # 売却ウィンドウを作成 @windows = [] @viewport = Viewport.new(0, 128, 640, 352) for actor in $game_party.actors @windows.push(Window_ActorItem.new(actor, 352, @viewport)) end @windows.push(Window_Item.new(352, @viewport)) @viewport.visible = false @windows[0].index = 0 @active_window = 0 # ヘルプウィンドウを関連付け @windows.each{|window| window.help_window = @help_window } # 個数入力ウィンドウを作成 @number_window = Window_ShopNumber.new @number_window.active = false @number_window.visible = false # ステータスウィンドウを作成 @status_window = Window_ShopStatus.new @status_window.visible = false # トランジション実行 Graphics.transition # メインループ loop do # ゲーム画面を更新 Graphics.update # 入力情報を更新 Input.update # フレーム更新 update # 画面が切り替わったらループを中断 if $scene != self break end end # トランジション準備 Graphics.freeze # ウィンドウを解放 @help_window.dispose @command_window.dispose @gold_window.dispose @dummy_window.dispose @buy_window.dispose @windows.each{|window| window.dispose} @viewport.dispose @number_window.dispose @status_window.dispose end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update # ウィンドウを更新 @help_window.update @command_window.update @gold_window.update @dummy_window.update @buy_window.update act = @active_window @windows.each{|window| window.update(@windows.index(window) == act) } @number_window.update @status_window.update # コマンドウィンドウがアクティブの場合: update_command を呼ぶ if @command_window.active update_command return end # 購入ウィンドウがアクティブの場合: update_buy を呼ぶ if @buy_window.active update_buy return end # 売却ウィンドウがアクティブの場合: update_sell を呼ぶ if (@windows.find{|window| window.active or window.child.active }) != nil update_sell return end # 個数入力ウィンドウがアクティブの場合: update_number を呼ぶ if @number_window.active update_number return end end #-------------------------------------------------------------------------- # ● フレーム更新 (コマンドウィンドウがアクティブの場合) #-------------------------------------------------------------------------- def update_command # B ボタンが押された場合 if Input.trigger?(Input::B) # キャンセル SE を演奏 $game_system.se_play($data_system.cancel_se) # マップ画面に切り替え $scene = Scene_Map.new return end # C ボタンが押された場合 if Input.trigger?(Input::C) # コマンドウィンドウのカーソル位置で分岐 case @command_window.index when 0 # 購入する # 決定 SE を演奏 $game_system.se_play($data_system.decision_se) # ウィンドウの状態を購入モードへ @command_window.active = false @dummy_window.visible = false @buy_window.active = true @buy_window.visible = true @buy_window.refresh @status_window.visible = true when 1 # 売却する # 決定 SE を演奏 $game_system.se_play($data_system.decision_se) # ウィンドウの状態を売却モードへ @command_window.active = false @dummy_window.visible = false @windows[@active_window].active = true @viewport.visible = true @windows.each{|window| window.refresh} when 2 # やめる # 決定 SE を演奏 $game_system.se_play($data_system.decision_se) # マップ画面に切り替え $scene = Scene_Map.new end return end end #-------------------------------------------------------------------------- # ● フレーム更新 (売却ウィンドウがアクティブの場合) #-------------------------------------------------------------------------- def update_sell # B ボタンが押された場合 if Input.trigger?(Input::B) # キャンセル SE を演奏 $game_system.se_play($data_system.cancel_se) # ウィンドウの状態を初期モードへ @command_window.active = true @dummy_window.visible = true @windows[@active_window].active = false @viewport.visible = false @status_window.item = nil # ヘルプテキストを消去 @help_window.set_text("") return end # C ボタンが押された場合 if Input.trigger?(Input::C) # アイテムを取得 @item = @windows[@active_window].item # ステータスウィンドウのアイテムを設定 @status_window.item = @item # アイテムが無効の場合、または価格が 0 (売却不可) の場合 if @item == nil or @item.price == 0 # ブザー SE を演奏 $game_system.se_play($data_system.buzzer_se) return end # 決定 SE を演奏 $game_system.se_play($data_system.decision_se) if @windows[@active_window].is_a?(Window_Item) # アイテムの所持数を取得 case @item when RPG::Item number = $game_party.item_number(@item.id) when RPG::Weapon number = $game_party.weapon_number(@item.id) when RPG::Armor number = $game_party.armor_number(@item.id) end # 最大売却個数 = アイテムの所持数 max = number # ウィンドウの状態を個数入力モードへ @windows[@active_window].active = false @viewport.visible = false @number_window.set(@item, max, @item.price / 2) @number_window.active = true @number_window.visible = true @status_window.visible = true else # ショップ SE を演奏 $game_system.se_play($data_system.shop_se) # 売却処理 $game_party.gain_gold(@item.price / 2) actor = @windows[@active_window].actor # 装備解除 if @windows[@active_window].index == actor.equips[0] actor.weapon_id = 0 for i in 0...actor.equips.size actor.equips[i] -= 1 if actor.equips[i] > actor.equips[0] end actor.equips[0] = -1 elsif @windows[@active_window].index == actor.equips[1] actor.armor1_id = 0 for i in 0...actor.equips.size actor.equips[i] -= 1 if actor.equips[i] > actor.equips[1] end actor.equips[1] = -1 elsif @windows[@active_window].index == actor.equips[2] actor.armor2_id = 0 for i in 0...actor.equips.size actor.equips[i] -= 1 if actor.equips[i] > actor.equips[2] end actor.equips[2] = -1 elsif @windows[@active_window].index == actor.equips[3] actor.armor3_id = 0 for i in 0...actor.equips.size actor.equips[i] -= 1 if actor.equips[i] > actor.equips[3] end actor.equips[3] = -1 elsif @windows[@active_window].index == actor.equips[4] actor.armor4_id = 0 for i in 0...actor.equips.size actor.equips[i] -= 1 if actor.equips[i] > actor.equips[4] end actor.equips[4] = -1 end actor.items[@windows[@active_window].index] = "" # 詰めろとりあえず actor.items.delete("") actor.items.fill("", actor.items.size...Numset::ACTOR_ITEM) @windows[@active_window].item_max = [(actor.items.select{|item| item != "" }).size + 1, Numset::ACTOR_ITEM].min # 各ウィンドウをリフレッシュ @gold_window.refresh @windows[@active_window].refresh @status_window.refresh # ウィンドウの状態を売却モードへ @windows[@active_window].active = true @viewport.visible = true @status_window.visible = false end end end #-------------------------------------------------------------------------- # ● フレーム更新 (個数入力ウィンドウがアクティブの場合) #-------------------------------------------------------------------------- def update_number # B ボタンが押された場合 if Input.trigger?(Input::B) # キャンセル SE を演奏 $game_system.se_play($data_system.cancel_se) # 個数入力ウィンドウを非アクティブ・不可視に設定 @number_window.active = false @number_window.visible = false # コマンドウィンドウのカーソル位置で分岐 case @command_window.index when 0 # 購入する # ウィンドウの状態を購入モードへ @buy_window.active = true @buy_window.visible = true when 1 # 売却する # ウィンドウの状態を売却モードへ @windows[@active_window].active = true @viewport.visible = true @status_window.visible = false end return end # C ボタンが押された場合 if Input.trigger?(Input::C) # ショップ SE を演奏 $game_system.se_play($data_system.shop_se) # 個数入力ウィンドウを非アクティブ・不可視に設定 @number_window.active = false @number_window.visible = false # コマンドウィンドウのカーソル位置で分岐 case @command_window.index when 0 # 購入する # 購入処理 $game_party.lose_gold(@number_window.number * @item.price) case @item when RPG::Item $game_party.gain_item(@item.id, @number_window.number) when RPG::Weapon $game_party.gain_weapon(@item.id, @number_window.number) when RPG::Armor $game_party.gain_armor(@item.id, @number_window.number) end # 各ウィンドウをリフレッシュ @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)) case @item when RPG::Item $game_party.base_lose_item(@item.id, @number_window.number) when RPG::Weapon $game_party.base_lose_weapon(@item.id, @number_window.number) when RPG::Armor $game_party.base_lose_armor(@item.id, @number_window.number) end # 各ウィンドウをリフレッシュ @gold_window.refresh @windows.each{|window| window.refresh} @status_window.refresh # ウィンドウの状態を売却モードへ @windows[@active_window].active = true @viewport.visible = true @status_window.visible = false end return end end end #============================================================================== # ■ Scene_Battle #------------------------------------------------------------------------------ #  バトル画面の処理を行うクラスです。 #============================================================================== class Scene_Battle #-------------------------------------------------------------------------- # ● アイテム選択開始 #-------------------------------------------------------------------------- def start_item_select # アイテムウィンドウを作成 @item_window = Window_ActorItem.new(@active_battler, 256) @item_window.index = 0 @item_window.active = true # ヘルプウィンドウを関連付け @item_window.help_window = @help_window # アクターコマンドウィンドウを無効化 @actor_command_window.active = false @actor_command_window.visible = false end #-------------------------------------------------------------------------- # ● フレーム更新 (アクターコマンドフェーズ : アイテム選択) #-------------------------------------------------------------------------- def update_phase3_item_select # アイテムウィンドウを可視状態にする @item_window.visible = true # アイテムウィンドウを更新 @item_window.update # B ボタンが押された場合 if Input.trigger?(Input::B) # キャンセル SE を演奏 $game_system.se_play($data_system.cancel_se) # アイテムの選択を終了 end_item_select return end # C ボタンが押された場合 if Input.trigger?(Input::C) # アイテムウィンドウで現在選択されているデータを取得 @item = @item_window.item # 使用できない場合 if !@item.is_a?(RPG::Item) or !$game_party.item_can_use?(@item.id) # ブザー SE を演奏 $game_system.se_play($data_system.buzzer_se) return end # 決定 SE を演奏 $game_system.se_play($data_system.decision_se) # アクションを設定 @active_battler.current_action.item_id = @item.id # アイテムウィンドウを不可視状態にする @item_window.visible = false # 効果範囲が敵単体の場合 if @item.scope == 1 # エネミーの選択を開始 start_enemy_select # 効果範囲が味方単体の場合 elsif @item.scope == 3 or @item.scope == 5 # アクターの選択を開始 start_actor_select # 効果範囲が単体ではない場合 else # アイテムの選択を終了 end_item_select # 次のアクターのコマンド入力へ phase3_next_actor end return end end #-------------------------------------------------------------------------- # ● アイテムアクション 結果作成 #-------------------------------------------------------------------------- def make_item_action_result # アイテムを取得 @item = $data_items[@active_battler.current_action.item_id] # アイテム切れなどで使用できなくなった場合 unless $game_party.item_can_use?(@item.id) # ステップ 1 に移行 @phase4_step = 1 return end # 消耗品の場合 if @item.consumable # 使用したアイテムを 1 減らす $game_party.lose_item(@item.id, 1, @active_actor) end # ヘルプウィンドウにアイテム名を表示 @help_window.set_text(@item.name, 1) # アニメーション ID を設定 @animation1_id = @item.animation1_id @animation2_id = @item.animation2_id # コモンイベント ID を設定 @common_event_id = @item.common_event_id # 対象を決定 index = @active_battler.current_action.target_index target = $game_party.smooth_target_actor(index) # 対象側バトラーを設定 set_target_battlers(@item.scope) # アイテムの効果を適用 for target in @target_battlers target.item_effect(@item) end end end