#==============================================================================
# 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
#============================================================================== 
 
# 作者:桜雅 在土
 
#==============================================================================
# □ 根据打击次数显示HITS
#==============================================================================
class XRXS_BP19
 #
 # 两次连击最大时间差(单位:帧)
 #
 COMBOHIT_DURATION = 150
end
class Game_Battler
 #
 # 连击攻击力增大[単位:%]
 #
 DAMAGE_INCREASE_PER_HIT = -15
end
class Window_ComboHit < Window_Base
 #
 # 连技显示的字体和颜色 (255,140,0, 255)
 #
 COMBOHIT_FONTNAME  = "Arial Black"  
 COMBOHIT_FONTCOLOR = Color.new(255,140,0, 255)
end
 
#==============================================================================
# □ Window_ComboHit
#------------------------------------------------------------------------------
#     是战斗中显示连击数的透明窗口。  
#==============================================================================
class Window_ComboHit < Window_Base
 #--------------------------------------------------------------------------
 # ○ 对象初始化
 #--------------------------------------------------------------------------
 def initialize
   super(500+50, 64, 130+50, 512)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.opacity = 0
   self.visible = false
   @active = false
   @show_duration = 0
   @sliding_duration = 0
   self.contents.clear
 end
 #--------------------------------------------------------------------------
 # ○ 透明
 #--------------------------------------------------------------------------
 def clear
   self.contents.clear
   self.visible = false
 end
 #--------------------------------------------------------------------------
 # ○ リフレッシュ
 #--------------------------------------------------------------------------
def refresh(hit_combo, duration)
   # 可視化
   self.contents_opacity = 250
   self.visible = true
   # 設定
   @show_duration    = duration
   @sliding_duration = 0
   # 描写(縁取り仕様)
   self.contents.clear
   self.contents.font.name = "Arial Black" 
   self.contents.font.italic = false #斜体
   self.contents.font.bold = false
   text = hit_combo.to_s + " " #最主要的一句話
 
     hits_string = hit_combo.to_s
     bitmap = Bitmap.new(320, 64)
     bitmap.font.name = "Arial Black"
     bitmap.font.size = 32
     # 分割伤害值字符串
     hits_array =   hits_string.scan(/./)
     hits_x = - 36.2#hits_string.size * 18.1 # 81 - hits_string.size * 18.1
     rect_y = 0
     # 循环伤害值字符串
     for char in hits_array
       # 后移一位
       hits_x += 36.2
       number = char.to_i
       # 显示伤害数字
       bitmap.blt(hits_x, 0, RPG::Cache.picture("String/" + "Number"), 
       Rect.new(number * 36.2, rect_y, 36.2, 50))
     end
     hits_x += 18.1
     bitmap.blt(hits_x, 0, RPG::Cache.picture("String/" + "HITS"), 
                Rect.new(0, -21, 90, 50))
     # 伤害值定位
     @_hits_sprite = ::Sprite.new(self.viewport)
     @_hits_sprite.bitmap = bitmap
     @_hits_sprite.x =  self.x#560 - hits_string.size * 36.2
     @_hits_sprite.y = self.y - self.oy / 2
     @_hits_sprite.z = 3000
     @_hits_duration = 40
 
 end
 
 #--------------------------------------------------------------------------
 # ○帧更新
 #--------------------------------------------------------------------------
 def update
   if @sliding_duration > 0
     @sliding_duration -= 1
     self.contents_opacity -= 32
     self.x += 1
     if @sliding_duration == 0
       self.visible = false
     end
   elsif @show_duration > 0
     @show_duration -= 1
     if @show_duration == 0
        @sliding_duration = 8
     end
   end
 end
end
 
#==============================================================================
# ■ Game_Battler
#==============================================================================
class Game_Battler
 #--------------------------------------------------------------------------
 # ● 公开实例变量
 #--------------------------------------------------------------------------
 def combohit
   @combohit = 0 if @combohit.nil?
   return @combohit
 end
 def combohit_duration
   @combohit_duration = 0 if @combohit_duration.nil?
   return @combohit_duration
 end
 #--------------------------------------------------------------------------
 # ○ 更新组合安打
 #--------------------------------------------------------------------------  
 def combohit_update
   # 例外補正
   @combohit_duration = 0 if @combohit_duration.nil?
   # 计数,
   if @combohit_duration > 0
     @combohit_duration -= 1
     # 后仰时间结束时,重置连击数
 
     @combohit = 0 if @combohit_duration == 0
 
 
   end
 end
 #--------------------------------------------------------------------------
 # ○ コンボヒットをカウント
 #--------------------------------------------------------------------------  
 def combohit_count
   # 例外補正
   @combohit = 0 if @combohit.nil?
   # カウント
   @combohit += 1
   @combohit_duration = XRXS_BP19::COMBOHIT_DURATION
   #unless @motion.nil?
   #  # ちとFMBS仕様
   #  @combohit_duration = @motion.knock_back_duration
   #end
 end
 #--------------------------------------------------------------------------
 # ○ コンボヒットをクリア
 #--------------------------------------------------------------------------  
 def combohit_clear
   @combohit = nil
   @combohit_duration = nil
 end
 #--------------------------------------------------------------------------
 # ● 通常攻撃の効果適用
 #--------------------------------------------------------------------------
 alias xrxs_bp19_attack_effect attack_effect
 def attack_effect(attacker)
   # 呼び戻す
   bool = xrxs_bp19_attack_effect(attacker)
   # 攻撃成功時( 行動有効 & ダメージあり )
   if bool and self.damage.to_i > 0
     # ヒット補正
     add_damage   = self.damage * ([self.combohit * DAMAGE_INCREASE_PER_HIT,-100].max)/100
     self.hp     -= add_damage
     self.damage += add_damage
     # コンボヒット+1
     self.combohit_count
   end
   return bool
 end
 #--------------------------------------------------------------------------
 # ● スキルの効果適用
 #--------------------------------------------------------------------------
 alias xrxs_bp19_skill_effect skill_effect
 def skill_effect(user, skill)
   # ダメージスキルではない場合
   if skill.power <= 0
     # 呼び戻す
     return xrxs_bp19_skill_effect(user, skill)
   end
   # ヒット補正( ダメージスキルのみ )
   skill = skill.dup
   skill.power = skill.power * (100 + [self.combohit * DAMAGE_INCREASE_PER_HIT,-100].max)/100
   # 呼び戻す
   bool = xrxs_bp19_skill_effect(user, skill)
   # 攻撃成功時( 行動有効 & ダメージあり )
   #if bool and self.damage.to_i > 0
   if self.damage.to_i > 0
     # コンボヒット+1
     self.combohit_count
   end
   return bool
 end
 #--------------------------------------------------------------------------
 # ● アイテムの効果適用 项目的效果应用
 #--------------------------------------------------------------------------
 alias xrxs_bp19_item_effect item_effect
 def item_effect(item)
   # ダメージアイテムではない場合 不是损害条款的情况
   unless (item.recover_hp < 0 or item.recover_hp_rate  < 0)
     # 呼び戻す
     return xrxs_bp19_item_effect(item)
   end
   # 複製
   item = item.dup
   # ヒット補正
   rate = (100 + [self.combohit * DAMAGE_INCREASE_PER_HIT,-100].max)
   item.recover_hp      = item.recover_hp      * rate / 100
   item.recover_hp_rate = item.recover_hp_rate * rate / 100
   # 呼び戻す
   bool = xrxs_bp19_item_effect(item)
   # 攻撃成功時( 行動有効 & ダメージあり )
   if bool and self.damage.to_i > 0
     # コンボヒット+1
     self.combohit_count
   end
   return bool
 end
end
#==============================================================================
# ■ Scene_Battle
#==============================================================================
class Scene_Battle
 #--------------------------------------------------------------------------
 # ● 主处理
 #--------------------------------------------------------------------------
 alias xrxs_bp19_main main
 def main
   # 创建组合热窗口
   @combohit_window = Window_ComboHit.new
   # 唤回
   xrxs_bp19_main
   # 打开窗口
   @combohit_window.dispose
   #组合通关
   $game_party.actors.each {|actor| actor.combohit_clear}
 end
 #--------------------------------------------------------------------------
 # ● フレーム更新 帧更新
 #--------------------------------------------------------------------------
 alias xrxs_bp19_update update
 def update
   # フレーム更新
   @combohit_window.update
   $game_party.actors.each {|actor| actor.combohit_update}
   $game_troop.enemies.each{|enemy| enemy.combohit_update}
   # 呼び戻す
   xrxs_bp19_update
 end
 #--------------------------------------------------------------------------
 # ●帧更新(主阶段步骤5:伤害表示)  
 #--------------------------------------------------------------------------
 alias xrxs_bp19_update_phase4_step5 update_phase4_step5
 def update_phase4_step5
   # 呼び戻す
   xrxs_bp19_update_phase4_step5
   # 寻找组合数最高的目标
   max = 0
   hit_target = nil
   for target in @target_battlers
     if target.combohit > max
       max = target.combohit
       hit_target = target
     end
   end
   # 组合数2以上的目标存在时,表示  
   if max >= 2 and !hit_target.nil?
      @combohit_window.x = hit_target.is_a?(Game_Enemy) ? 512 : 0
      #目标是敌人位置512 如果不是敌人0
      @combohit_window.refresh(max, hit_target.combohit_duration)
   end
 end
end