スポンサーサイト

上記の広告は1ヶ月以上更新のないブログに表示されています。
新しい記事を書く事で広告が消せます。

web拍手 by FC2   

[RGSS]バトルテスター

使い方は → こちら

※このスクリプトは一応使用できますがまだまだ戦闘テストとは言えないレベルです。

[RGSS]バトルテスター
最終更新:2011/06/07

通常の戦闘テストでは実際のプレイと異なる場合があったりします。
(戦闘関係のスクリプトが入っている場合特に)
そういった際に、マップやメニューより呼び出せる戦闘テストです。

スクリーンショット サムネイルクリックで拡大画像が見られます。
rgss_btest.jpg

プログラムは続きにあります。

=begin
===============================================================================
  ☆★☆★☆★☆★ バトルテスター ★☆★☆★☆★☆
=============================================================================== 

 製作・開発:STERS

  Page::http://gamemaking.web.fc2.com/

導入方法------------------------------------------------------------------

    このスクリプトを Scene_Debug より下 Main より上に
   新しく作ったセクションにコピペして入れてください。
    
--------------------------------------------------------------------------

これを導入することで
バトルテスト(戦闘テスト)
ができるようになります。

使い方--------------------------------------------------------------------
1.まずはこのスクリプトを導入してください。

2.戦闘テストを呼び出したいところで、
    battle_tester と記述してください。
                  (イベントの「スクリプト」です。)

--------------------------------------------------------------------------
--------------------------------------------------------------------------
「何でこんなものを作ったんだ?普通の戦闘テストでいいじゃないか!」
という人がいると思うので、一応書いておきます。

いろんなRGSS素材が出回っていますが、
どうしても「標準の戦闘テスト」では、実行されないような、部分があります。

「標準の戦闘テスト」では、データをロードしてそのまま戦闘へといってしまうので、
一部のRGSSは実行されません。
それに、テストプレイ中に戦闘テストなども無理です。

しかし、このRGSSでは、マップなどからいつでも呼び出せるため、
どんな状況下でもできます。

現段階では、
標準の戦闘テストとは違い、武具の指定ができません。

--------------------------------------------------------------------------
=end
class BattleTester
  #
  #  パーティ最大人数
  #
  PARTY_MAX = 4
  #
  # Result を表示するか?
  #
  SHOW_RESULT = true
end
#=========================================================================
#=========================================================================
def battle_tester
  $game_player.straighten
  $scene = BattleTester.new
end
class Game_Temp
  attr_accessor :battle_test_turn, :battle_test_time, :battle_test_add_damage
  attr_accessor :battle_test_me_damage, :battle_tester_start, :battle_test_effect_count
  attr_accessor :battle_test_actor, :battle_test_last_actor
  alias battle_tester_initialize initialize unless $@
  def initialize
    @battle_test_turn = 0
    @battle_test_time = 0
    @battle_test_add_damage = 0
    @battle_test_me_damage = 0
    @battle_test_effect_count = {"attack"=>0,"guard"=>0,"skill"=>0,"item"=>0}
    @battle_tester_start = false
    @battle_test_actor = []
    @battle_test_last_actor = []
    battle_tester_initialize
  end
end
class Enemy_Sprite < RPG::Sprite
  attr_accessor :battler
  def initialize(viewport,y,x,battler=nil)
    super(viewport)
    @battler = battler
    @battler_visible = true
    @x = x
    @y = y
  end
  def dispose
    if self.bitmap != nil
      self.bitmap.dispose
    end
    super
  end
  def update
    super
    if @battler.battler_name != @battler_name or
       @battler.battler_hue != @battler_hue
      @battler_name = @battler.battler_name
      @battler_hue = @battler.battler_hue
      self.bitmap = RPG::Cache.battler(@battler_name, @battler_hue)
      @width = bitmap.width
      @height = bitmap.height
      self.ox = 0
      self.oy = 0
    end
    self.x = @x
    self.y = @y
    self.z = 9999
  end
end
class Game_Actor
  #--------------------------------------------------------------------------
  # ● 通常攻撃の効果適用
  #--------------------------------------------------------------------------
  def attack_effect(attacker)
    e = super(attacker)
    if $game_temp.battle_tester_start
      $game_temp.battle_test_me_damage += self.damage if self.damage != "Miss"
    end
    return e
  end
  #--------------------------------------------------------------------------
  # ● スキルの効果適用
  #--------------------------------------------------------------------------
  def skill_effect(user, skill)
    e = super(user,skill)
    if $game_temp.battle_tester_start
      $game_temp.battle_test_me_damage += self.damage if self.damage != "Miss"
    end
    return e
  end
  #--------------------------------------------------------------------------
  # ● アイテムの効果適用
  #--------------------------------------------------------------------------
  def item_effect(item)
    e = super(item)
    if $game_temp.battle_tester_start
      $game_temp.battle_test_me_damage += self.damage if self.damage != "Miss"
    end
    return e
  end
end
class Game_Enemy
  #--------------------------------------------------------------------------
  # ● 通常攻撃の効果適用
  #--------------------------------------------------------------------------
  def attack_effect(attacker)
    e = super(attacker)
    if $game_temp.battle_tester_start
      $game_temp.battle_test_add_damage += self.damage if self.damage != "Miss"
    end
    return e
  end
  #--------------------------------------------------------------------------
  # ● スキルの効果適用
  #--------------------------------------------------------------------------
  def skill_effect(user, skill)
    e = super(user,skill)
    if $game_temp.battle_tester_start
      $game_temp.battle_test_add_damage += self.damage if self.damage != "Miss"
    end
    return e
  end
  #--------------------------------------------------------------------------
  # ● アイテムの効果適用
  #--------------------------------------------------------------------------
  def item_effect(item,user=$game_party.actors[0])
    e = super(item,user)
    if $game_temp.battle_tester_start
      $game_temp.battle_test_add_damage += self.damage if self.damage != "Miss"
    end
    return e
  end
end
class Game_Party
  attr_accessor :actors
end
class Window_TroopSelect < Window_Selectable
  def initialize
    super(0, 0, 240, 480)
    self.index = 0
    refresh
  end
  def item
    $data_troops.each{|a|
      next if a == nil
      return a if @data[self.index] == a.name
    }
  end
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    for i in $data_troops
      next if i == nil or i.name == nil or i.name == ""
      @data.push(i.name)
    end
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      self.contents.font.color = normal_color
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  def draw_item(index)
    troop = @data[index]
    x = 4
    y = index * 32
    rect = Rect.new(x, y, self.width - 40, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(x, y, self.width - 40, 32, "#{troop}")
  end
end
class Window_ActorSelect < Window_Selectable
  def initialize
    super(0, 0, 480, 240)
    @ok = Sprite.new
    @ok.bitmap = Bitmap.new(240,240)
    @ok.z = self.z
    @ok_chara = []
    refresh
    self.index = 0
    self.z = 99999
    @ok.x = self.x = 240 - 240 / 2
    @ok.y = self.y = 240 - 240 / 2
    @ok.x += 240
    @ok.y += 32
    self.visible = self.active = false
  end
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
      return
    end
    row = @index / @column_max
    if row < self.top_row
      self.top_row = row
    end
    if row > self.top_row + (self.page_row_max - 1)
      self.top_row = row - (self.page_row_max - 1)
    end
    cursor_width = 240
    x = @index % @column_max * (cursor_width + 32)
    y = @index / @column_max * 32 - self.oy
    self.cursor_rect.set(x, y, cursor_width, 32)
  end
  def dispose
    @ok.bitmap.dispose
    @ok.dispose
    super
  end
  def update
    @ok.visible = self.visible
    @ok.z = self.z
    super
  end
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    for i in $data_actors
      next if i == nil or i.name == nil or i.name == ""
      @data.push(i.name)
    end
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(240, row_max * 32)
      self.contents.font.color = normal_color
      for i in 0...@item_max
        draw_item(i)
      end
    end
    @ok.bitmap.clear
    c = -1
    @ok_chara.each{|a|
      c += 1
      x = 0
      y = c * 32
      @ok.bitmap.draw_text(x, y, self.width - 40, 32, "#{a}")
    }
  end
  def draw_item(index)
    actor = @data[index]
    x = 0
    y = index * 32
    rect = Rect.new(x, y, self.width - 40, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(x, y, self.width - 40, 32, "#{actor}")
  end
  def decide
    @ok_chara.push(@data[self.index])
    @ok.bitmap.clear
    c = -1
    @ok_chara.each{|a|
      c += 1
      x = 0
      y = c * 32
      @ok.bitmap.draw_text(x, y, self.width - 40, 32, "#{a}")
    }
  end
  def cansel
    @ok_chara.pop
    @ok.bitmap.clear
    c = -1
    @ok_chara.each{|a|
      c += 1
      x = 0
      y = c * 32
      @ok.bitmap.draw_text(x, y, self.width - 40, 32, "#{a}")
    }
  end
  def chara_get
    c = []
    $data_actors.each{|a|
      @ok_chara.each{|b|
        next if a == nil
        c.push($game_actors[a.id]) if b == a.name
      }
    }
    return c
  end
end
class BattleTester
  def main
    Graphics.freeze
    @viewport = Viewport.new(240,0,640-240,640-240-50)
    @enemy_sprites = []
    c = -1
    @troop_name = Window_TroopSelect.new
    @actor_name = Window_ActorSelect.new
    @help = Window_Base.new(240,350,400,130)
    @help.z = 999999
    @help.contents = Bitmap.new(368,98)
    @help_text = {"a"=>["C:キャラ決定 B:キャラキャンセル X:戦闘開始",
                        "C:キャラ決定 B:前の状態へ戻る"],
                  "t"=> "C:トループ決定 B:前の画面へ戻る"}
    @help.contents.clear
    @help.contents.draw_text(0,0,@help.contents.width,@help.contents.height,@help_text["t"])
    @dammy = Window_Base.new(240,0,640-240,640-240-50)
    $game_troop.setup(@troop_name.item.id)
    for enemy in $game_troop.enemies.reverse
      c += 1
      @enemy_sprites.push(Enemy_Sprite.new(@viewport,c%2*100,c/2*100,enemy))
    end
    @troop_name.z = 10000
    @actor_name.z = 100000
    @dammy.z = 10000
    @viewport.z = 99999
    $game_temp.battle_test_turn = 0
    $game_temp.battle_test_time = 0
    $game_temp.battle_test_add_damage = 0
    $game_temp.battle_test_me_damage = 0
    $game_temp.battle_test_effect_count = {"attack"=>0,"guard"=>0,"skill"=>0,"item"=>0}
    $game_temp.battle_tester_start = false
    $game_temp.battle_test_actor = []
    $game_temp.battle_test_last_actor = []
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      break if $scene != self
    end
    Graphics.freeze
    sprite_dispose
    @viewport.dispose
    @troop_name.dispose
    @actor_name.dispose
    @dammy.dispose
    @help.contents.dispose
    @help.dispose
  end
  def update
    @help.update
    if @actor_name.active
      @actor_name.update
      if Input.trigger?(Input::C)
        unless @actor_name.chara_get.size == PARTY_MAX
          @actor_name.decide
        else
          $game_system.se_play($data_system.buzzer_se)          
        end
        @help.contents.clear
        i  = @actor_name.chara_get.size == 0 ? 1 : 0
        @help.contents.draw_text(0,0,@help.contents.width,@help.contents.height,@help_text["a"][i])
      elsif Input.trigger?(Input::X)
        if @actor_name.chara_get.size == 0
          $game_system.se_play($data_system.buzzer_se)          
        else
          decide2
        end
      elsif Input.trigger?(Input::B)
        $game_system.se_play($data_system.cancel_se)
        if @actor_name.chara_get.size == 0
          cansel
        else
          @actor_name.cansel
          @help.contents.clear
          i = @actor_name.chara_get.size == 0 ? 1 : 0
          @help.contents.draw_text(0,0,@help.contents.width,@help.contents.height,@help_text["a"][i])
        end
      end
      return
    end
    @troop_name.update
    @enemy_sprites.each{|a|a.update}
    if Input.repeat?(Input::UP) or Input.repeat?(Input::DOWN)
      $game_troop.setup(@troop_name.item.id)
      sprite_dispose
      @enemy_sprites = []
      c = -1
      for enemy in $game_troop.enemies.reverse
        c += 1
        @enemy_sprites.push(Enemy_Sprite.new(@viewport,c%2*100,c/2*100,enemy))
      end
    end
    if Input.trigger?(Input::C)
      decide1
      return
    end
    if Input.trigger?(Input::B)
      $scene = Scene_Map.new
      return
    end
  end
  def cansel
    $game_temp.battle_troop_id = 0
    @actor_name.active = @actor_name.visible = false
    @troop_name.active = true
    @actor_name.update
    @help.contents.clear
    @help.contents.draw_text(0,0,@help.contents.width,@help.contents.height,@help_text["t"])
  end
  def decide1
    @actor_name.active = @actor_name.visible = true
    @troop_name.active = false
    $game_system.se_play($data_system.decision_se)
    @help.contents.clear
    i = @actor_name.chara_get.size == 0 ? 1 : 0
    @help.contents.draw_text(0,0,@help.contents.width,@help.contents.height,@help_text["a"][i])
  end
  def decide2
    $game_system.se_play($data_system.decision_se)
    $game_temp.battle_tester_start = true
    $game_temp.battle_test_last_actor = $game_party.actors
    @actor_name.chara_get.each{|a|
      $game_temp.battle_test_actor.push(a) 
    }
    $game_party.actors = $game_temp.battle_test_actor
    $game_temp.map_bgm = $game_system.playing_bgm
    $game_system.bgm_stop
    $game_system.se_play($data_system.battle_start_se)
    $game_system.bgm_play($game_system.battle_bgm)
    $game_player.straighten
    $game_temp.battle_troop_id = @troop_name.item.id
    $scene = Scene_Battle.new
  end
  def sprite_dispose
    for s in @enemy_sprites
      s.dispose
    end
  end
  def self.s?
    return SHOW_RESULT
  end
end
class Scene_Battle
  #--------------------------------------------------------------------------
  # ● メイン処理
  #--------------------------------------------------------------------------
  alias battle_tester_main main unless $@
  def main
    $game_temp.battle_test_turn = 0
    $game_temp.battle_test_time = 0
    battle_tester_main
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  alias battle_tester_update update unless $@
  def update
    $game_temp.battle_test_time += 1 if $game_temp.battle_tester_start
    battle_tester_update
  end
  #--------------------------------------------------------------------------
  # ● バトル終了
  #--------------------------------------------------------------------------
  alias battle_tester_battle_end battle_end unless $@
  def battle_end(result)
    battle_tester_battle_end(result)
    if $game_temp.battle_tester_start && BattleTester.s?
      time = $game_temp.battle_test_time / Graphics.frame_rate
      m = time / 60
      s = time % 60
      turn = $game_temp.battle_test_turn
      add = $game_temp.battle_test_add_damage
      me = $game_temp.battle_test_me_damage
      atk = $game_temp.battle_test_effect_count["attack"]
      gua = $game_temp.battle_test_effect_count["guard"]
      ski = $game_temp.battle_test_effect_count["skill"]
      ite = $game_temp.battle_test_effect_count["item"]
      print(sprintf("戦闘時間 : %p分%p秒\n\nターン数 : %p\n\n"+
                    "与えた総ダメージ : %p\n\n食らった総ダメージ : %p\n\n"+
                    "攻撃回数 : %p\n\n防御回数 : %p\n\n"+
                    "スキル使用回数 : %p\n\nアイテム使用回数 : %p\n\n",
            m,s,turn,add,me,atk,gua,ski,ite))
      $game_party.actors = $game_temp.battle_test_last_actor
      $game_temp.battle_tester_start = false
      $game_player.refresh
    end
  end
  #--------------------------------------------------------------------------
  # ● パーティコマンドフェーズ開始
  #--------------------------------------------------------------------------
  alias battle_tester_start_phase2 start_phase2 unless $@
  def start_phase2
    $game_temp.battle_test_turn += 1 if $game_temp.battle_tester_start
    battle_tester_start_phase2
  end
  #--------------------------------------------------------------------------
  # ● 次のアクターへ
  #--------------------------------------------------------------------------
  alias battle_tester_phase3_next_actor phase3_next_actor unless $@
  def phase3_next_actor
    if @active_actor == nil
      battle_tester_phase3_next_actor
      return
    end
    case @active_actor.current_action.kind
    when 0
      case @active_actor.current_action.basic
      when 0
        $game_temp.battle_test_effect_count["attack"] += 1
      when 1
        $game_temp.battle_test_effect_count["guard"] += 1
      end
    when 1
      $game_temp.battle_test_effect_count["skill"] += 1
    when 2
      $game_temp.battle_test_effect_count["item"] += 1
    end
    battle_tester_phase3_next_actor
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新 (メインフェーズ)
  #--------------------------------------------------------------------------
  alias battle_tester_update_phase4 update_phase4 unless $@
  def update_phase4
    battle_tester_update_phase4
  end
end


web拍手 by FC2   

コメントの投稿


非公開コメント

コメント

STERS's Development Room

STERSの開発室っぽい何か。


プロフィール

Name:STERS
Unity3D/C#/PHP/js/C++/VB
などを勉強中です

[STERS's Room]
[ファイル置き場]

カテゴリー
最近の記事
最近のコメント
カレンダー
08 ≪│2017/09│≫ 10
- - - - - 1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
RSSリンクの表示
ブログ内Google検索
Google
上記広告は1ヶ月以上更新のないブログに表示されています。新しい記事を書くことで広告を消せます。