#----------------------------------------------------------------------------
 # Draws Status menu and Damage Preview
 #----------------------------------------------------------------------------
class Windows_Status_GTBS < Window_Base
 attr_accessor :attacker
 attr_accessor :skill
 def initialize(actor = nil)
  super(640, 370, 550, 480)
  @back = Sprite.new
  self.opacity = GTBS::CONTROL_OPACITY
  if FileTest.exist?('Graphics/Pictures/TBS_Status.png')
   self.opacity = 0
   @back.bitmap = RPG::Cache.picture('TBS_Status')
   @back.visible = false
   @back.opacity = GTBS::CONTROL_OPACITY
  end
  self.contents = Bitmap.new(width-32, height-32)
  @attacker = nil
  @actor = nil
  @skill = nil
  @face = Sprite.new
  refresh
 end
Â
 def act
  return @actor
 end
Â
 def visible=(bool)
  if @face != nil
   @face.visible = bool
  end
  super
 end
Â
Â
 def refresh(actor = nil)
  @actor = actor
  unless actor == nil
   self.visible = true
   file = sprintf("Graphics/Pictures/Faces/%s.png", actor.name)
   if FileTest.exist?(file)
    @face.bitmap = RPG::Cache.picture(sprintf('/Faces/%s',actor.name))
    @face.x = 0 #-@face.bitmap.width-5
    @face.y = 350
    #self.y +#
    @face.z = 1000
    @face.opacity = GTBS::CONTROL_OPACITY + 30
  Â
   else
    @face.bitmap = RPG::Cache.picture('/Faces/Blank')
    @face.x =
640-@face.bitmap.width-5
    @face.y = self.y + 40
    @face.z = 1000
    @face.opacity = GTBS::CONTROL_OPACITY + 30
   end
   x = 0
   y = 0
  Â
   self.contents.clear
   self.contents.font.color = normal_color
   name = actor.name.to_s
   if name.include?("[1]")
    name = name.delete"[1]"
   end
   self.contents.draw_text(x,y,200,32,name)
   unless actor.dead?
    atb = actor.atb/10
    if atb > 100
     atb = 100
    end
    if $game_system.cust_battle != "TEAM"
     self.contents.draw_text(x,y+72,200,32,sprintf("AT    %d",atb))
    end
   end
   self.contents.draw_text(x+80,y,138,32,actor.class_name,2)
   draw_actor_hp(actor, x, y+24)
   draw_actor_sp(actor, x, y+48)
   draw_actor_graphic(actor, x-40, y)
   if @attacker != nil
    if GTBS::PREVIEW_DAMAGE
     dmg_preview(@type, @attacker, @skill)
    end
   end
  else
   self.visible = false
   if @face != nil
    @face.visible = false
   end
   @attacker = nil
   @type = 0
   @skill = nil
  end
 end
Â
 def dmg_preview(type, attacker, skill = nil)
  unless @actor == nil
   @attacker = attacker
   @type = type
   @skill = skill
   case type
   when 1 #attack
    hit = get_attack_result(attacker)
   when 2 #skill
    hit = get_skill_result(skill, attacker)
   when 3 #item
    hit = get_item_result(skill) #skill is actually the item!
   endÂ
   unless hit == nil
    self.contents.draw_text(0, 96, 100, 32, "Hit %: " + hit[0].to_s)
    self.contents.draw_text(0+70, 96, 100, 32, hit[1].to_s + "(+/- " + hit[2].to_s + ")", 2)
   end
  end
 end
 Â
 def move_to(position)
  if position == "right"
   self.x = 640-self.width
  elsif position == "left"
   self.x = 0
  end
 end
  def update(actor = nil)
  @back.visible = self.visible
  @back.x = self.x
  @back.y = self.y
  @back.update
  #if actor != nil
   refresh(actor)
  #end
 end
Â
 def get_attack_result(attacker)
  hit_chance = 0
  hit_damage = 0
  atk = [attacker.atk - @actor.pdef / 2, 0].max
  @actor.damage = atk * (20 + attacker.str) / 20
  @actor.damage *= @actor.elements_correct(attacker.element_set)
  @actor.damage /= 100
  if @actor.damage > 0
   if @actor.guarding?
    @actor.damage /= 2
   end
  end
  eva = 8 * @actor.agi / attacker.dex + @actor.eva
  hit = @actor.damage < 0 ? 100 : attacker.hit - eva
  if @actor.from_back?(attacker)
   hit += 10
  elsif !@actor.from_front?(attacker) #from sides
   hit += 5
  end
  hit = hit > 100 ? 100 : hit
  hit_chance = @actor.cant_evade? ? 100 : hit
  hit_damage =
-@actor.damage
  amp = [@actor.damage.abs * 15 / 100, 1].max
  @actor.damage = nil
  return [hit_chance, hit_damage, amp]
 end
Â
 def get_skill_result(skill, user)
  hit = skill.hit
  if skill.atk_f > 0
   hit *= user.hit / 100
  end
  if ((skill.scope == 3 or skill.scope == 4) and @actor.hp == 0) or
    ((skill.scope == 5 or skill.scope == 6) and @actor.hp >= 1)
   return [0,0]
  end
  power = skill.power + user.atk * skill.atk_f / 100
  if power > 0
   power -= @actor.pdef * skill.pdef_f / 200
   power -= @actor.mdef * skill.mdef_f / 200
   power = [power, 0].max
  end
  rate = 20
  rate += (user.str * skill.str_f / 100)
  rate += (user.dex * skill.dex_f / 100)
  rate += (user.agi * skill.agi_f / 100)
  rate += (user.int * skill.int_f / 100)
  @actor.damage = power * rate / 20
  @actor.damage *= @actor.elements_correct(skill.element_set)
  dmg =
-@actor.damage /= 100
  eva = 8 * @actor.agi / user.dex + @actor.eva
  hit = @actor.damage < 0 ? 100 : hit - eva * skill.eva_f / 100
  hit = @actor.cant_evade? ? 100 : hit
  amp = [@actor.damage.abs * skill.variance / 100, 1].max
  @actor.damage = nil
  return [hit, dmg, amp]
 end
Â
 def get_item_result(item)
  hit = item.hit
  if ((item.scope == 3 or item.scope == 4) and @actor.hp == 0) or
    ((item.scope == 5 or item.scope == 6) and @actor.hp >= 1)
   return [0,0]
  end
  recover_hp = @actor.maxhp * item.recover_hp_rate / 100 + item.recover_hp
  if recover_hp < 0
   recover_hp += @actor.pdef * item.pdef_f / 20
   recover_hp += @actor.mdef * item.mdef_f / 20
   recover_hp = [recover_hp, 0].min
  end
  recover_hp *= @actor.elements_correct(item.element_set)
  recover_hp /= 100
  dmg = recover_hp
  amp = 0
  return [hit, dmg, amp]
 end
end