- #============================================================================== 
- # RGSS2_SRPG2拡張 ユニット画像拡張 ver1.02 
- # 2012/03/26「歩行画像変化ステート」公開 
- # 2012/04/29「ユニット画像拡張」公開 ver1.00 
- #            敵メモ欄からのユニット画像指定機能を追加 
- #            行動時のユニット画像変更機能を追加 
- #            描画時の不具合を修正 
- # 2012/05/07 通常マップでタイル画像のイベントがあるとエラーが出る不具合を修正 
- # 2012/05/11 パターン数拡張機能を追加 
- #            パターンのループ設定機能を追加 
- # C Winter ([url]http://ccwinter.blog.fc2.com/[/url]) 
- # 
- # ・「行動回数拡張 統合版」より上に入れてください 
- #============================================================================== 
-   
- #============================================================================== 
- # ■ 設定項目 
- #============================================================================== 
- module TSRPG 
-   #↓変更しないでください 
-   ACTORS_ATTACK_GRAPHIC = [] 
-   ACTORS_GUARD_GRAPHIC = [] 
-   ACTORS_ITEM_GRAPHIC = [] 
-   for i in 1...1000 do ACTORS_ITEM_GRAPHIC[i] = [] end 
-   #↑変更しないでください 
-   
-   #「援軍用ユニット増殖」を併用するかどうか 
-   USE_DUMMY_UNIT = false 
-   
-   #アクター通常攻撃時の画像 
-   ACTORS_ATTACK_GRAPHIC[1] = [nil]          #変更しない 
-   ACTORS_ATTACK_GRAPHIC[999] = ["", 0]      #画像無し(透明)にする 
-   
-   #アクター防御時の画像 
-   ACTORS_GUARD_GRAPHIC[1] = [nil]           #変更しない 
-   ACTORS_GUARD_GRAPHIC[999] = ["Actor1", 2] #画像変更 
-   
-   #アクターアイテム使用時の画像 
-   ACTORS_ITEM_GRAPHIC[1][1] = [nil]         #変更しない 
-   ACTORS_ITEM_GRAPHIC[1][2] = ["", 0]       #画像無し(透明)にする 
-   ACTORS_ITEM_GRAPHIC[1][3] = ["Actor1", 2] #画像変更 
-   #997番のアクターがどのアイテムを使っても["Actor1", 2] 
-   ACTORS_ITEM_GRAPHIC[997] = ["Actor1", 2] 
-   #998番のアクターが1番のアイテムを使った時に["Actor1", 2] 
-   ACTORS_ITEM_GRAPHIC[998][1] = ["Actor1", 2] 
-   #999番のアクターが3番のアイテムを使った時は["Actor1", 2] それ以外なら["", 0] 
-   for item_id in 1...1000 do ACTORS_ITEM_GRAPHIC[999][item_id] = ["", 0] end 
-   ACTORS_ITEM_GRAPHIC[999][3] = ["Actor1", 2]     
- end 
-   
- #============================================================================== 
- # ■ Game_SrpgEvent 
- #============================================================================== 
- class Game_SrpgEvent < Game_Character 
-   #-------------------------------------------------------------------------- 
-   # ● 公開インスタンス変数 
-   #-------------------------------------------------------------------------- 
-   attr_reader   :state_character_name 
-   attr_reader   :state_character_index 
-   attr_reader   :skill_character_name 
-   attr_reader   :skill_character_index 
-   #-------------------------------------------------------------------------- 
-   # ● オブジェクト初期化 
-   #-------------------------------------------------------------------------- 
-   alias change_graphic_initialize initialize 
-   def initialize(map_id, event) 
-     change_graphic_initialize(map_id, event) 
-     @state_character_name  = "" 
-     @state_character_index = -1 
-     @skill_character_name  = nil 
-     @skill_character_index = -1 
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● ステート画像、自動エネミー画像の適用 
-   #-------------------------------------------------------------------------- 
-   def state_change_graphic? 
-     for state in unit.states 
-       if state.note =~ /<ユニット画像=(\S+?),(\d+)>/i 
-         @state_character_name  = $1 
-         @state_character_index = $2.to_i 
-         return true 
-       end 
-     end 
-     if unit.is_a?(Game_Enemy) and $data_enemies[unit.enemy_id].note =~ /<ユニット画像=(\S+?),(\d+)>/i 
-       @state_character_name  = $1 
-       @state_character_index = $2.to_i 
-       return true 
-     end 
-     @state_character_name  = "" 
-     @state_character_index = -1 
-     return false 
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● スキル画像の適用 
-   #-------------------------------------------------------------------------- 
-   def set_skill_graphic 
-     #通常攻撃 
-     if unit.action.attack? 
-       if unit.is_a?(Game_Actor) 
-         if TSRPG::ACTORS_ATTACK_GRAPHIC[unit.id] != nil 
-           @skill_character_name = TSRPG::ACTORS_ATTACK_GRAPHIC[unit.id][0] 
-           @skill_character_index = TSRPG::ACTORS_ATTACK_GRAPHIC[unit.id][1] 
-         end 
-       elsif unit.is_a?(Game_Enemy) 
-         if $data_enemies[unit.enemy_id].note =~ /<攻撃画像=(\S+?),(\d+)>/i 
-           @skill_character_name = $1 == "\"\"" ? "" : $1 
-           @skill_character_index = $2.to_i 
-         end 
-       end 
-     #防御かスキル 
-     elsif unit.action.skill? 
-       #防御 
-       if unit.action.skill_id == 3 
-         if unit.is_a?(Game_Actor) 
-           if TSRPG::ACTORS_GUARD_GRAPHIC[unit.id] != nil 
-             @skill_character_name = TSRPG::ACTORS_GUARD_GRAPHIC[unit.id][0] 
-             @skill_character_index = TSRPG::ACTORS_GUARD_GRAPHIC[unit.id][1] 
-           end 
-         elsif unit.is_a?(Game_Enemy) 
-           if $data_enemies[unit.enemy_id].note =~ /<防御画像=(\S+?),(\d+)>/i 
-             @skill_character_name = $1 == "\"\"" ? "" : $1 
-             @skill_character_index = $2.to_i 
-           end 
-         end 
-       #スキル 
-       elsif unit.action.obj.note =~ /<スキル画像=(\S+?),(\d+)>/i 
-         @skill_character_name = $1 == "\"\"" ? "" : $1 
-         @skill_character_index = $2.to_i 
-       end 
-     #味方のみ アイテム 
-     elsif unit.action.item? 
-       list = TSRPG::ACTORS_ITEM_GRAPHIC[unit.id] 
-       if list[0].is_a?(String)              #サンプル アクター998 
-         @skill_character_name = list[0] 
-         @skill_character_index = list[1] 
-       elsif list[unit.action.obj.id] != nil #サンプル アクター999 
-         @skill_character_name = list[unit.action.obj.id][0] 
-         @skill_character_index = list[unit.action.obj.id][1] 
-       end 
-     end 
-     @pattern = 0 if @skill_character_name != nil #コマ数をリセット 
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● スキル画像の終了 
-   #-------------------------------------------------------------------------- 
-   def reset_skill_graphic 
-     @skill_character_name = nil 
-     @skill_character_index = -1 
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● 歩行画像の変更 
-   #-------------------------------------------------------------------------- 
-   def graphic_mode 
-     return 0 if unit == nil #ユニットではない場合 
-     if TSRPG::USE_DUMMY_UNIT and @dummy           #ダミーユニット 
-       return 3 if @dummy_dead                     #死亡後の場合 
-       return 2 if @skill_character_name != nil    #生存中・スキル画像の場合 
-       return 1 if state_change_graphic?           #生存中・変更ステートの場合 
-       return 0  #生存中・非スキル画像・非変更ステートの場合 
-     else                                          #真ユニット 
-       return 0 if $game_self_switches[[@map_id, @id, "D"]] == true #死亡後の場合 
-       return 2 if @skill_character_name != nil    #生存中・スキル画像の場合 
-       return 1 if state_change_graphic?           #生存中・変更ステートの場合 
-       return 0  #生存中・非スキル画像・非変更ステートの場合 
-     end 
-   end 
- end 
- #============================================================================== 
- # ■ Scene_Srpg 
- #============================================================================== 
- class Scene_Srpg < Scene_Base 
-   #-------------------------------------------------------------------------- 
-   # ● 行動の実行 
-   #update1.003 
-   #update1.012 
-   #update1.0121 
-   #-------------------------------------------------------------------------- 
-   def execute_action(x, y) 
-     # 攻撃可能セルが選択されていなければ終了 
-     unless @attack_cell.include?([x, y]) 
-       Sound.play_buzzer 
-       return 
-     end 
-     # 現在の効果範囲上に生きている誰かがいれば実行 
-     @action_result_exp = 0 
-     @action_result_item.clear 
-     @action_result_gold = 0 
-     targets = []                        # ターゲットの配列を作成 
-     @coop_unit_list = [] 
-     for pos in @effect_cell 
-       event = $game_srpg.target_xy(x + pos[0], y + pos[1])[0] 
-       targets.push(event) if event != nil 
-     end 
-     obj = @event.unit.action.obj 
-     if obj.is_a?(RPG::BaseItem) and obj.dual? # 連続攻撃なら同じターゲットを追加 
-       targets += targets 
-     end 
-     if targets.empty?   # ターゲットがいない 
-       Sound.play_buzzer 
-       @message_mini_window.refresh("ターゲットが見つかりません", 60) 
-       return 
-     end 
-     @event.turn_cell(x, y)              # 攻撃する方向を向く 
-   
-     @event.set_skill_graphic 
-     if @event.unit.action.attack?       # 通常攻撃 
-       level = execute_action_attack(targets) 
-     elsif @event.unit.action.skill?     # スキル 
-       if @event.unit.action.skill_id == 3 # 防御 
-         wait(30)  #画像変更を見やすくするためウェイト 
-         $game_srpg.add_popup(@event.real_x, @event.real_y, sprintf("防御"), Color.new(255, 255, 255), 1) 
-       end 
-       level = execute_action_obj(targets) 
-     elsif @event.unit.action.item?      # アイテム 
-       level = execute_action_obj(targets) 
-     end 
-     @event.reset_skill_graphic 
-   
-     @event.action_end = true              # 行動済みフラグを立てる 
-     unless $game_srpg.enemy_turn?         # 味方ターン限定の処理 
-       $game_srpg.scene_state = 0            # ニュートラルへ移行する 
-       @status_window.refresh($game_srpg.alive_unit_xy(x, y))  # ステータスウィンドウの再描画 
-     end 
-     unless @event.enemy_flag              # 味方行動時限定の処理 
-       for event in @coop_unit_list          # 協力攻撃者も経験値取得 
-         next if event.enemy_flag 
-         exp = @action_result_exp + event.unit.action_exp 
-         exp = [exp + exp * (level - event.unit.level) * 10 / 100, 1].max 
-         event.unit.gain_exp(exp / 2 + 1, true) 
-         event.unit.gain_job_exp(exp, true) if $include_tjex 
-         text = sprintf("EXP+%d", exp / 2 + 1) 
-         $game_srpg.add_popup(event.real_x, event.real_y, text, Color.new(255, 255, 255), 1) 
-       end 
-       exp = @action_result_exp + @event.unit.action_exp 
-       exp = [exp + exp * (level - @event.unit.level) * 10 / 100, 1].max 
-       @event.unit.gain_exp(exp, true) 
-       @event.unit.gain_job_exp(exp, true) if $include_tjex 
-       text = sprintf("EXP+%d", exp) 
-       $game_srpg.add_popup(@event.real_x, @event.real_y, text, Color.new(255, 255, 255), 1) 
-     end 
-     if @action_result_gold > 0        # お金の取得 
-       $game_party.gain_gold(@action_result_gold) 
-       text = sprintf(Vocab::ObtainGold, @action_result_gold, Vocab::gold) 
-       $game_message.texts.push(text) 
-     end 
-     if @action_result_item.size > 0   # アイテムの取得 
-       for item in @action_result_item 
-         $game_party.gain_item(item, 1) 
-         text = sprintf(Vocab::ObtainItem, item.name) 
-         $game_message.texts.push(text) 
-       end 
-     end 
-     wait_for_message 
-   end 
- end 
- #============================================================================== 
- # ■ Sprite_Character 
- #============================================================================== 
- class Sprite_Character < Sprite_Base 
-   #-------------------------------------------------------------------------- 
-   # ● 転送元ビットマップの更新 
-   #-------------------------------------------------------------------------- 
-   def update_bitmap 
-     if @character.is_a?(Game_SrpgEvent) 
-       if @character.graphic_mode > 0 
-         case @character.graphic_mode 
-         when 3  #ダミーユニット死亡後の場合 
-           if @character_name != "" 
-             @character_name = "" 
-             self.bitmap = Cache.character("") 
-           end 
-           return 
-         when 2  #スキル画像変更中の場合 
-           name = @character.skill_character_name 
-           index = @character.skill_character_index 
-         when 1  #ステート画像変更中の場合 
-           name = @character.state_character_name 
-           index = @character.state_character_index 
-         end 
-         if @character_name != name or @character_index != index 
-           @character_name = name 
-           @character_index = index 
-           self.bitmap = Cache.character(@character_name) 
-           sign = @character_name[/^[\!\$]./] 
-           max_pattern = @character_name =~ /{p=(\d+)}/i ? $1.to_i : 3 
-           if sign != nil and sign.include?('$') 
-             @cw = bitmap.width / max_pattern 
-             @ch = bitmap.height / 4 
-           else 
-             @cw = bitmap.width / (max_pattern * 4) 
-             @ch = bitmap.height / 8 
-           end 
-           self.ox = @cw / 2 
-           self.oy = @ch 
-         end 
-         return 
-       end 
-     end 
-   
-     if @tile_id != @character.tile_id or 
-        @character_name != @character.character_name or 
-        @character_index != @character.character_index 
-       @tile_id = @character.tile_id 
-       @character_name = @character.character_name 
-       @character_index = @character.character_index 
-       if @tile_id > 0 
-         sx = (@tile_id / 128 % 2 * 8 + @tile_id % 8) * 32; 
-         sy = @tile_id % 256 / 8 % 16 * 32; 
-         self.bitmap = tileset_bitmap(@tile_id) 
-         self.src_rect.set(sx, sy, 32, 32) 
-         self.ox = 16 
-         self.oy = 32 
-       else 
-         self.bitmap = Cache.character(@character_name) 
-         sign = @character_name[/^[\!\$]./] 
-         max_pattern = @character_name =~ /{p=(\d+)}/i ? $1.to_i : 3 
-         if sign != nil and sign.include?('$') 
-           @cw = bitmap.width / max_pattern 
-           @ch = bitmap.height / 4 
-         else 
-           @cw = bitmap.width / (max_pattern * 4) 
-           @ch = bitmap.height / 8 
-         end 
-         self.ox = @cw / 2 
-         self.oy = @ch 
-       end 
-     end 
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● 転送元矩形の更新 
-   #-------------------------------------------------------------------------- 
-   def update_src_rect 
-     return if @tile_id != 0 and 
-               (@character.is_a?(Game_Event) or @character.graphic_mode == 0) 
-     index = @character_index 
-     if @character.set_graphic_option? 
-       pattern = @character.pattern 
-     else 
-       pattern = @character.pattern < 3 ? @character.pattern : 1 
-     end 
-     sx = (index % 4 * 3 + pattern) * @cw 
-     sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch 
-     self.src_rect.set(sx, sy, @cw, @ch) 
-   end 
- end 
- #============================================================================== 
- # ■ Scene_Map 
- #============================================================================== 
- class Scene_Map < Scene_Base 
-   #-------------------------------------------------------------------------- 
-   # ● 開始処理 
-   #-------------------------------------------------------------------------- 
-   alias graphic_option_start start 
-   def start 
-     graphic_option_start 
-     $game_player.refresh 
-     $game_player.straighten 
-   end 
- end 
-   
- #============================================================================== 
- # ■ Game_Player 
- #============================================================================== 
- class Game_Player 
-   #-------------------------------------------------------------------------- 
-   # ● リフレッシュ 
-   #-------------------------------------------------------------------------- 
-   alias ex_pattern_refresh refresh 
-   def refresh 
-     ex_pattern_refresh 
-     @original_pattern = set_graphic_option? ? 0 : 1 
-   end 
- end 
- #============================================================================== 
- # ■ Game_Character 
- #============================================================================== 
- class Game_Character 
-   #-------------------------------------------------------------------------- 
-   # ● どちらかの処理が設定されているかどうか 
-   #-------------------------------------------------------------------------- 
-   def set_graphic_option? 
-     return true if @character_name =~ /{p=(\d+)}/i 
-     return true if @character_name =~ /{l=(\d+)}/i 
-     return false 
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● 姿勢の矯正 
-   #-------------------------------------------------------------------------- 
-   def straighten 
-     if @walk_anime or @step_anime 
-       @pattern = set_graphic_option? ? 0 : 1 
-     end 
-     @anime_count = 0 
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● アニメカウントの更新 
-   #-------------------------------------------------------------------------- 
-   def update_animation 
-     speed = @move_speed + (dash? ? 1 : 0) 
-     if @anime_count > 18 - speed * 2 
-       if not @step_anime and @stop_count > 0 
-         @pattern = @original_pattern 
-       else 
-         if @character_name =~ /{l=(\d+)}/i 
-           loop = $1.to_i 
-           max_pattern = @character_name =~ /{p=(\d+)}/i ? $1.to_i : 3 
-         else 
-           loop = 1 
-           max_pattern = @character_name =~ /{p=(\d+)}/i ? $1.to_i : 4 
-         end 
-         if (@pattern + 1) >= max_pattern 
-           @pattern = loop - 1 
-         else 
-           @pattern = @pattern + 1 
-         end 
-       end 
-       @anime_count = 0 
-     end 
-   end 
- end 
- #============================================================================== 
- # ■ Game_SrpgEvent 
- #============================================================================== 
- class Game_SrpgEvent < Game_Character 
-   #-------------------------------------------------------------------------- 
-   # ● どちらかの処理が設定されているかどうか 
-   #-------------------------------------------------------------------------- 
-   def set_graphic_option? 
-     case graphic_mode 
-     when 0 
-       name = @character_name 
-     when 1 
-       name = @state_character_name 
-     when 2 
-       name = @skill_character_name 
-     when 3 
-       name = "" 
-     end 
-     return true if name =~ /{p=(\d+)}/i 
-     return true if name =~ /{l=(\d+)}/i 
-     return false 
-   end 
-   #-------------------------------------------------------------------------- 
-   # ● アニメカウントの更新 
-   #-------------------------------------------------------------------------- 
-   def update_animation 
-     speed = @move_speed + (dash? ? 1 : 0) 
-     if @anime_count > 18 - speed * 2 
-       if not @step_anime and @stop_count > 0 
-         @pattern = @original_pattern 
-       else 
-         case graphic_mode 
-         when 0 
-           name = @character_name 
-         when 1 
-           name = @state_character_name 
-         when 2 
-           name = @skill_character_name 
-         when 3 
-           name = "" 
-         end 
-         if name =~ /{l=(\d+)}/i 
-           loop = $1.to_i 
-           max_pattern = name =~ /{p=(\d+)}/i ? $1.to_i : 3 
-         else 
-           loop = 1 
-           max_pattern = name =~ /{p=(\d+)}/i ? $1.to_i : 4 
-         end 
-         if (@pattern + 1) >= max_pattern 
-           @pattern = loop - 1 
-         else 
-           @pattern = @pattern + 1 
-         end 
-       end 
-       @anime_count = 0 
-     end 
-   end 
- end