Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

TERG's BS Edit

[COMPLETE] -Glitchfinders RMXP Screen Size Editor

The script itself is brilliant and as it's the only one of its kind I could find, it has to be this one I use. The problem is, the script immediantly focuses on the top left hand corner of the map instead of on the character, something that makes the script really hard to work with. So could someone please edit the script so that it focuses on the character each time, like it should do.


-TERG's Battle System

This battle system is really important to the game I want to make because of the mouse capabilites that are built into the battle system. The problem is, it returns with an error on line 3751 on SystemTERG_System when used with the Screen Size script above. So is it possible for this to be edited to work alongside each other?

New Request

(Thought I'd post this here and save making a new topic) Is there a quick and simple way of adding sprite animations to TERG's script (below) for each weapon used? The game already has animations built in, but is there a way to have sprite animations for them as well? So whenever you attack with a certain weapon, the sprite "[ACTOR NAME]_[WEAPON NAME]" plays the moving animation for the direction the player's facing, like the system in Mr Mo's ABS. So something like:

$data_weapons[1].range = 1
$data_weapons[1].group_id = 1
$data_weapons[1].rap = 8
$data_weapons[1].mouse_face = true
$data_weapons[1].base_accuracy = 100
$data_weapons[1].deterioration = 200
$data_weapons[1].ammo_type = nil
$data_weapons[1].delay = 8
$data_weapons[1].ddelay = 0
$data_weapons[1].spread = 32
$data_weapons[1].animations = [118,119,120,121]
$data_weapons[1].piercing = 7
$data_weapons[1].target_move = [25,-2,0,5]
$data_weapons[1].multihit = 3
$data_weapons[1].zeropoint = "target"
$data_weapons[1].spriteanimation = $actorname + "_weapon1"

Thanks to anyone who can help me out with this new request.

Code:
<div id="{CB}" style="font-family: monospace;"><ol>#==============================================================================

# Keyboard Input Module

#----------------------------------------------------------------------------

# Script by Cybersam

#==============================================================================

 

module Input

  @keys = []

  @pressed = []

  Mouse_Left = 1

  Mouse_Right = 2

  Mouse_Middle = 4

  Back= 8

  Tab = 9

  Enter = 13

  Shift = 16

  Ctrl = 17

  Alt = 18

  Esc = 27

  Space = 32

  Numberkeys = {}

  Numberkeys[0] = 48        # => 0

  Numberkeys[1] = 49        # => 1

  Numberkeys[2] = 50        # => 2

  Numberkeys[3] = 51        # => 3

  Numberkeys[4] = 52        # => 4

  Numberkeys[5] = 53        # => 5

  Numberkeys[6] = 54        # => 6

  Numberkeys[7] = 55        # => 7

  Numberkeys[8] = 56        # => 8

  Numberkeys[9] = 57        # => 9

  Numberpad = {}

  Numberpad[0] = 45

  Numberpad[1] = 35

  Numberpad[2] = 40

  Numberpad[3] = 34

  Numberpad[4] = 37

  Numberpad[5] = 12

  Numberpad[6] = 39

  Numberpad[7] = 36

  Numberpad[8] = 38

  Numberpad[9] = 33

  Letters = {}

  Letters["A"] = 65

  Letters["B"] = 66

  Letters["C"] = 67

  Letters["D"] = 68

  Letters["E"] = 69

  Letters["F"] = 70

  Letters["G"] = 71

  Letters["H"] = 72

  Letters["I"] = 73

  Letters["J"] = 74

  Letters["K"] = 75

  Letters["L"] = 76

  Letters["M"] = 77

  Letters["N"] = 78

  Letters["O"] = 79

  Letters["P"] = 80

  Letters["Q"] = 81

  Letters["R"] = 82

  Letters["S"] = 83

  Letters["T"] = 84

  Letters["U"] = 85

  Letters["V"] = 86

  Letters["W"] = 87

  Letters["X"] = 88

  Letters["Y"] = 89

  Letters["Z"] = 90

  Fkeys = {}

  Fkeys[1] = 112

  Fkeys[2] = 113

  Fkeys[3] = 114

  Fkeys[4] = 115

  Fkeys[5] = 116

  Fkeys[6] = 117

  Fkeys[7] = 118

  Fkeys[8] = 119

  Fkeys[9] = 120

  Fkeys[10] = 121

  Fkeys[11] = 122

  Fkeys[12] = 123

  Collon = 186        # => \ |

  Equal = 187         # => = +

  Comma = 188         # => , <

  Underscore = 189    # => - _

  Dot = 190           # => . >

  Backslash = 191     # => / ?

  Lb = 219

  Rb = 221

  Quote = 222         # => '"

  #-------------------------------------------------------------------------------

  USED_KEYS = [Mouse_Left, Mouse_Right, Mouse_Middle] 

  #-------------------------------------------------------------------------------

  

module_function

  #--------------------------------------------------------------------------

  def triggered?(key)

    Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(key) & 0x01 == 1

  end

  #-------------------------------------------------------------------------- 

  def check(key)

    Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(key) & 0x01 == 1

  end

  #--------------------------------------------------------------------------

  def pressed?(key)

    return true unless Win32API.new("user32","GetKeyState",['i'],'i').call(key).between?(0, 1)

    return false

  end

  #--------------------------------------------------------------------------

  def mouse_update

    @used_i = []

    for i in USED_KEYS

      x = check(i)

      if x == true

        @used_i.push(i)

      end

    end

  end

  #--------------------------------------------------------------------------

  def self.C

    self.trigger?(C)

  end

  #-------------------------------------------------------------------------- 

  def self.B

    self.trigger?(B)

  end

  #-------------------------------------------------------------------------- 

  def self.A

    self.trigger?(A)

  end

  #-------------------------------------------------------------------------- 

  def self.Down

    self.trigger?(DOWN)

  end

  #-------------------------------------------------------------------------- 

  def self.Up

    self.trigger?(UP)

  end

  #-------------------------------------------------------------------------- 

  def self.Right

    self.trigger?(RIGHT)

  end

  #-------------------------------------------------------------------------- 

  def self.Left

    self.trigger?(LEFT)

  end

  #--------------------------------------------------------------------------

  def self.Anykey

    if A or B or C or Down or Up or Right or Left

      return true

    else

      return false

    end

  end

  #--------------------------------------------------------------------------

end

 

#======================================

# ■ Mouse Input

#======================================

#  By: Near Fantastica

#   Date: 06.07.05

#   Version: 1

#======================================

module Mouse

 @position

 GSM = Win32API.new('user32', 'GetSystemMetrics', 'i', 'i')

 Cursor_Pos= Win32API.new('user32', 'GetCursorPos', 'p', 'i')

 Scr2cli = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')

 Client_rect = Win32API.new('user32', 'GetClientRect', %w(l p), 'i')

 Readini = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')

 Findwindow = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')

 #--------------------------------------------------------------------------  

 def Mouse.grid

   return nil if @pos == nil

   x = @pos[0] / 32

   y = @pos[1] / 32

   x = x * 32

   y = y * 32

   return [x, y]

 end

 #--------------------------------------------------------------------------  

 def Mouse.position

   return @pos == nil ? [0, 0] : @pos

 end

 #--------------------------------------------------------------------------  

 def Mouse.global_pos

   pos = [0, 0].pack('ll')

   if Cursor_Pos.call(pos) != 0

     return pos.unpack('ll')

   else

     return nil

   end

 end

 #--------------------------------------------------------------------------  

 def Mouse.pos

   x, y = Mouse.screen_to_client(*Mouse.global_pos)

   width, height = Mouse.client_size

   begin

     if (x >= 0 and y >= 0 and x < width and y < height)

       return x, y

     else

       return nil

     end

   rescue

     return nil

   end

 end

 #--------------------------------------------------------------------------  

 def Mouse.update

   @pos = Mouse.pos

 end

 #--------------------------------------------------------------------------  

 def Mouse.screen_to_client(x, y)

   return nil unless x and y

   pos = [x, y].pack('ll')

   if Scr2cli.call(Mouse.hwnd, pos) != 0

     return pos.unpack('ll')

   else

     return nil

   end

 end

 #--------------------------------------------------------------------------  

 def Mouse.hwnd

   game_name = "\0" * 256

   Readini.call('Game','Title','',game_name,255,".\\Game.ini")

   game_name.delete!("\0")

   return Findwindow.call('RGSS Player',game_name)

 end

 #--------------------------------------------------------------------------  

 def Mouse.client_size

   rect = [0, 0, 0, 0].pack('l4')

   Client_rect.call(Mouse.hwnd, rect)

   right, bottom = rect.unpack('l4')[2..3]

   return right, bottom

 end

end

 

=begin

┌──────────────────────────────────────┐

│●     Display Animations 1.5          │

│                                      │

│            Created By                │

│                                      │

│  Trickster ([email=tricksterguy@hotmail.com]tricksterguy@hotmail.com[/email])│

│                                      │

│                                      │

└──────────────────────────────────────┘

 

►Intro

 

This script will allow you to display an animation at any (x,y) position or

any tile so you will not have to use blank events to display an animation at 

that tile

 

►Instructions

Add this above main.

 

To call just do

  $animations.push(Animation.new(type,x,y,id[,loop,sound,viewport])

  anything within the [] is optional

  type is the type of animation use either 1,2,3,4,5 or 'screen','tile','map','player','event'

  1 or 'screen' follows the player it stays on the screen

  2 or 'tile' stays at a particular tile (x,y)

  3 or 'map' stays at a particular position (x,y) on the map

  4 or 'player' follows the player (x,y) defines the offset

  5 or 'event' follows an event (use x parameter for id and [x,y] for offset)

  id is the animation id to play

  

  Optional

  loop is the number of times to play the animation

    set this to nil an the animation plays forever

    the default value is 1

  sound set to true and you will hear the animation's sounds

    set this to false and the sounds will not play

    the default value is true

  viewport is the animations viewport the default is the whole screen

=end

  

$animations = []

 

class Animation

  @@animations = []

  @@reference_count = {}

  

  attr_reader   :finished

    

  def initialize(type,x,y,id,loop = 1,sound = true,viewport = Viewport.new(0,0,640,480))

    @type = type

    @off_x = 0

    @off_y = 0

    case type

    when 'screen','map',1,3

      @x = x

      @y = y

    when 'tile',2

      @x = (x % $game_map.width) * 128

      @y = (y % $game_map.height) * 128

    when 'player',4

      @battler = $game_player

      @off_x = x

      @off_y = y

    when 'event',5

      event_id = x

      x = y[0]

      y = y[1]

      @battler = $game_map.events[event_id]

      @off_x = x

      @off_y = y

    end

    @animation = $data_animations[id]

    return if @animation.nil?

    @loop = loop    

    @sound = sound

    @viewport = viewport

    @finished = false

    animation

  end

 

  def animation

    dispose_animation

    @animation_duration = @animation.frame_max

    animation_name = @animation.animation_name

    animation_hue = @animation.animation_hue

    bitmap = RPG::Cache.animation(animation_name, animation_hue)

    if @@reference_count.include?(bitmap)

      @@reference_count[bitmap] += 1

    else

      @@reference_count[bitmap] = 1

    end

    @animation_sprites = []

    if @animation.position != 3 or not @@animations.include?(@animation)

      for i in 0..15

        sprite = ::Sprite.new(@viewport)

        sprite.bitmap = bitmap

        sprite.visible = false

        @animation_sprites.push(sprite)

      end

      unless @@animations.include?(@animation)

        @@animations.push(@animation)

      end

    end

    update_animation

  end

  

  def update

    if @animation != nil and (Graphics.frame_count % 2 == 0)

      @animation_duration -= 1

      update_animation

    end

    @@animations.clear

  end

    

  def update_animation

    if @animation_duration > 0  or @loop.nil? or @loop > 1

      if @animation_duration == 0

        @animation_duration = @animation.frame_max

        @loop -= 1 if !@loop.nil?

      end

      frame_index = @animation.frame_max - @animation_duration

      cell_data = @animation.frames[frame_index].cell_data

      position = @animation.position

      animation_set_sprites(@animation_sprites, cell_data, position)

      for timing in @animation.timings

        if timing.frame == frame_index

          animation_process_timing(timing)

        end

      end

    else

      @finished = true

      dispose_animation

    end

  end

 

  def dispose

    dispose_animation

  end

  

  def dispose_animation

    if @animation_sprites != nil

      sprite = @animation_sprites[0]

      if sprite != nil

        @@reference_count[sprite.bitmap] -= 1

        if @@reference_count[sprite.bitmap] == 0

          sprite.bitmap.dispose

        end

      end

      for sprite in @animation_sprites

        sprite.dispose

      end

      @animation_sprites = nil

      @animation = nil

    end

  end

  

  def animation_set_sprites(sprites, cell_data, position)

    for i in 0..15

      sprite = sprites[i]

      pattern = cell_data[i, 0]

      if sprite == nil or pattern == nil or pattern == -1

        sprite.visible = false if sprite != nil

        next

      end

      sprite.visible = true

      sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192)

      case @type

      when 'tile','map',2,3

        sprite.x = (@x - $game_map.display_x + 3) / 4 + 16

        sprite.y = (@y - $game_map.display_y + 3) / 4 + 32

      when 'screen',1

        sprite.x = @x

        sprite.y = @y

      when 'player','event',4,5

        sprite.x = @battler.screen_x + @off_x

        sprite.y = @battler.screen_y + @off_y

      end

      sprite.x += cell_data[i, 1]

      sprite.y += cell_data[i, 2]

      sprite.z = 2000

      sprite.ox = 96

      sprite.oy = 96

      sprite.zoom_x = cell_data[i, 3] / 100.0

      sprite.zoom_y = cell_data[i, 3] / 100.0

      sprite.angle = cell_data[i, 4]

      sprite.mirror = (cell_data[i, 5] == 1)

      sprite.opacity = cell_data[i, 6]

      sprite.blend_type = cell_data[i, 7]

    end

  end

    

  def animation_process_timing(timing)

    if @sound

      if timing.se.name != ""

        se = timing.se

        Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch)

      end

    end

  end

    

  def x=(x)

    sx = x

    if sx != 0

      if @animation_sprites != nil

        for i in 0..15

          @animation_sprites[i].x += sx

        end

      end

    end

  end

    

  def y=(y)

    sy = y

    if sy != 0

      if @animation_sprites != nil

        for i in 0..15

          @animation_sprites[i].y += sy

        end

      end

    end

  end

end

 

#==============================================================================

# ** Game_

#------------------------------------------------------------------------------

#  This class handles managing the various windows/sprites that make up

# the HUD system. You can add as many new HUDs to this as you'd like.

#==============================================================================

class Game_HUDManager

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    @huds = []

  end

  # Update method, runs update on all active HUDs

  def update

    for i in [email=0...@huds.size]0...@huds.size[/email]

      if @huds[i].visible

        @huds[i].update

      end

    end

  end

  # Update method, runs update on all active HUDs

  def set_default_actors

    for i in [email=0...@huds.size]0...@huds.size[/email]

      @huds[i].set_actor

      @huds[i].update

    end

  end

  # Add HUD

  def add_hud(hud)

    @huds.push(hud)

  end

  # Hide HUDs

  def hide_hud

    for i in [email=0...@huds.size]0...@huds.size[/email]

      @huds[i].visible = false

      @huds[i].update

    end

  end

  # Show HUDs

  def show_hud

    for i in [email=0...@huds.size]0...@huds.size[/email]

      @huds[i].visible = true

      @huds[i].update

    end

  end

  # Dipsoe

  def dispose

    for i in [email=0...@huds.size]0...@huds.size[/email]

      @huds[i].dispose

    end

  end

end

 

#==============================================================================

# ** Game_AIManager (part Extra)

#------------------------------------------------------------------------------

#  This class handles the master AI decisions for the Scene_CombatMap class,

# and can be accessed from within $game_system.ai

#==============================================================================

class Game_AIManager

  attr_accessor   :teams

  attr_accessor   :hostiles

  attr_accessor   :update_speed

  attr_accessor   :game_turn

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    @teams = []

    @teams[0] = [0]

    @hostiles = []

    @update_speed = 2

    @update_time = 0

    @game_turn = 60

    @current_turn = @game_turn

  end

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def flush

    @teams = []

    @teams[0] = [0]

    @hostiles = []

    @update_speed = 2

    @update_time = 0

  end

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def init_new_map

    @teams = []

    @teams[0] = [0]

    @update_speed = 2

    @update_time = 0

  end

  #--------------------------------------------------------------------------

  # * Assign Function: Assigns events to a "team"

  #--------------------------------------------------------------------------

  def assign(team_id, event_id)

    if @teams[team_id] == nil

      @teams[team_id] = [event_id]

    else

      @teams[team_id].push(event_id)

    end

  end

  #--------------------------------------------------------------------------

  # * Remove Function: Removes event from a "team"

  #--------------------------------------------------------------------------

  def remove(team_id, event_id)

    if @teams[team_id] != nil

      @teams[team_id].delete(event_id)

    end

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    if @update_time == 0

      if @current_turn > 0

        @current_turn -= 1

      end

      for event in $game_map.events

        action_page = part_of_combat_system(event[1])

        if event[1].battler != nil and not event[1].battler.hp <= 0 and action_page

          make_move(event[0])

          if @current_turn == 0

            event[1].battler.remove_states_auto

          end

        end

      end

      if @current_turn == 0

        for i in 0...$game_party.actors.size

          $game_party.actors[i].remove_states_auto

        end

        @current_turn = @game_turn

      end

      @update_time = @update_speed

    else

      @update_time -= 1

    end

  end

  #--------------------------------------------------------------------------

  # * Assign Hostile: Assigns 2 groups to be hostile to each other

  #--------------------------------------------------------------------------

  def assign_hostile(team1, team2)

    if not @hostiles.include?([team1,team2]) and not @hostiles.include?([team2,team1])

      @hostiles.push([team1,team2])

      return true

    end

  end

  #--------------------------------------------------------------------------

  # * Part of Combat System

  #--------------------------------------------------------------------------

  def part_of_combat_system(event)

    if event.is_a?(Game_Event)

      if event.list != nil

        for item in event.list

          if item.code == 108 and item.parameters[0] == "ACTION"

            return true

          end

        end

      end

    elsif event.is_a?(Game_Player)

      return true

    elsif event != nil and event.actor_id != nil

      return true

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Frozen

  #--------------------------------------------------------------------------

  def frozen?(event)

    if event.is_a?(Game_Event)

      if event.list != nil

        for item in event.list

          if item.code == 108 and item.parameters[0] == "FROZEN"

            return true

          end

        end

      end

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Get all Hostile Targets

  #--------------------------------------------------------------------------

  def get_hostiles(event_id)

    me = []

    against = []

    versus = []

    # Get all teams this event exists in

    for i in [email=0...@teams.size]0...@teams.size[/email]

      if @teams[i] != nil and @teams[i].include?(event_id)

        me.push(i)

      end

    end

    # Get all teams hostile to this one

    for team in me

      for i in [email=0...@hostiles.size]0...@hostiles.size[/email]

        if @hostiles[i].include?(team)

          temp = @hostiles[i].clone

          temp.delete(team)

          against.push(temp[0])

        end

      end

    end

    # Go through all the hostile teams and add all events

    for team in against

      # If not a NIL thing

      if team != nil

        # Add in all events in hostile teams

        if @teams[team] != nil

          versus = versus.concat(@teams[team])

        end

      end

      versus = versus.uniq

      versus.delete(event_id)

    end

    return versus

  end

  #--------------------------------------------------------------------------

  # * Make Move

  #--------------------------------------------------------------------------

  def make_move(event_id)

    # Get a list of targets

    targets = get_hostiles(event_id)

    # If the target list isn't nil or empty

    nearest = 9999

    enemy = nil

    event = $game_map.events[event_id]

    if targets != nil and targets.size > 0

      # For each potential target

      for i in 0...targets.size

        # If it's the player, get player X/Y, else the events X/Y

        if targets[i] == 0 or targets[i] >= 10000

          pocs = true

        else

          pocs = part_of_combat_system($game_map.events[targets[i]])

        end

        if pocs

          if targets[i] == 0

            x = $game_player.x

            y = $game_player.y

            alive = $game_party.actors[0].hp > 0

            testee = $game_player

          elsif targets[i] < 10000 and $game_map.events[targets[i]].battler != nil

            x = $game_map.events[targets[i]].x

            y = $game_map.events[targets[i]].y

            alive = $game_map.events[targets[i]].battler.hp > 0

            testee = $game_map.events[targets[i]]

          elsif targets[i] >= 10000

            id = 10000 - targets[i]

            actor_id = $game_map.player_characters[id].actor_id

            x = $game_map.player_characters[id].x

            y = $game_map.player_characters[id].y

            alive = $game_party.actors[actor_id].hp > 0

            testee = $game_map.player_characters[id]

          end # End getting X/Y coords

          # Get the "range" away from them

          if alive

            range_x = (x.abs) - (event.x.abs)

            range_y = (y.abs) - (event.y.abs)

            range_x = range_x.abs

            range_y = range_y.abs

            range_x = range_x * range_x

            range_y = range_y * range_y

            range = Math.sqrt(range_x + range_y)

            range = range.round

            if range < nearest

              if nearest != nil

                if rand(100) < 90

                  enemy = testee

                  nearest = range

                end

              end

            end

          end

        end

      end

    end # End target list processing

    frozen = frozen?(event)

    event.favored = get_favored_range(event)

    current = get_best_attack(event, nearest)

    difficulty = 0

    if enemy != nil and current != nil

      los = event.line_of_sight(enemy, current)

      difficulty = event.difficulty_of_sight(enemy)

      delay = current.delay

      if delay == nil

        delay = 0

      end

      ddelay = current.ddelay

      if ddelay == nil

        ddelay = 0

      end

    end

    # Move you should move to use favored weapon

    if event != nil and enemy != nil and not event.stuck? and not event.moving? and not frozen

      if range > 15

        event.move_random

      elsif difficulty > 3 and range < 9

        event.move_away_from_target(enemy)

      elsif event.favored < nearest

        if rand(100) < 90

          event.move_toward_target(enemy)

        else

          event.move_random

        end

      elsif event.favored > nearest

        if rand(100) < 90

          event.move_away_from_target(enemy)

        else

          event.move_random

        end

      end

    end # End attack movement decisions

    # Get favored attack and current best attack

    if event.can_act? and los

      event.set_attack(ddelay, event.battler.clone, enemy, delay, current, nearest)

    end

  end

  #--------------------------------------------------------------------------

  # * Get Favored Range

  #--------------------------------------------------------------------------

  def get_favored_range(event)

    battler = event.battler

    # Set the values to hold the highest attack rating

    rating = 0

    action = 0

    # Check each attack to find the highest rating one

    actions = $data_enemies[battler.enemy_id].actions

    for i in 0...actions.size

      # If it's a skill, consider it

      if actions[i].kind == 1

        # If the HP condition is OK!

        if (battler.hp / (battler.maxhp * 1.0) * 100) >= actions[i].condition_hp

          # If the SWITCH check is OK

          if actions[i].condition_switch_id == 0 or $game_switches[actions[i].condition_switch_id] == true

            if $data_skills[actions[i].skill_id].weapon_id == nil

              if actions[i].rating > rating and event.battler.skill_can_use?(actions[i].skill_id)

                rating = actions[i].rating

                action = actions[i].skill_id

              end

            else

              if actions[i].rating > rating

                rating = actions[i].rating

                action = actions[i].skill_id

              end

            end

          end

        end

      end # End skill consider check

    end # Highest rating

    # Return the range

    if action != nil and action > 0

      if $data_skills[action].weapon_id != nil

        event.ideal_attack = $data_weapons[$data_skills[action].weapon_id]

        return $data_weapons[$data_skills[action].weapon_id].range

      elsif $data_skills[action] == nil or $data_skills[action].range == nil

        event.ideal_attack = nil

        return 1

      else

        event.ideal_attack = $data_skills[action]

        return $data_skills[action].range

      end # End return rage

    end

    return -1

  end # Ending get_favored_range funciton

  #--------------------------------------------------------------------------

  # * Get Favored Range

  #--------------------------------------------------------------------------

  def get_best_attack(event, range)

    # Set the values to hold the highest attack rating

    #if range == event.favored

    #  return event.ideal_attack

    #end

    battler = event.battler

    besthit = 0

    action = nil

    # Check each attack to find the highest rating one

    actions = $data_enemies[battler.enemy_id].actions

    for i in 0...actions.size

      #p actions[i]

      # If it's a skill, consider it

      if actions[i].kind == 1

        # If the HP condition is OK!

        if (battler.hp / (battler.maxhp * 1.0) * 100) <= actions[i].condition_hp

          # If the SWITCH check is OK

          if actions[i].condition_switch_id == 0 or $game_switches[actions[i].condition_switch_id] == true

            # If the Skill isn't a dud

            if $data_skills[actions[i].skill_id] != nil

              # If the skill has a weapon ID

              if $data_skills[actions[i].skill_id].weapon_id != nil

                weapon = $data_weapons[$data_skills[actions[i].skill_id].weapon_id]

                diff = range - weapon.range

                hit = weapon.base_accuracy

                if weapon.range < range

                  hit -= diff * weapon.deterioration

                  if hit < 0

                    hit = 0

                  end

                end

                if hit >= besthit and range < (weapon.range * 2) and event.can_act?

                  besthit = hit

                  action = $data_weapons[$data_skills[actions[i].skill_id].weapon_id]

                end

              # Else if the skill has a range

              else

                weapon = $data_skills[actions[i].skill_id]

                diff = range - weapon.range

                hit = weapon.base_accuracy

                if weapon.range < range

                  hit -= diff * weapon.deterioration

                  if hit < 0

                    hit = 0

                  end

                end

                if hit >= besthit and range <= weapon.range and not event.casting? and event.battler.skill_can_use?(actions[i].skill_id)

                  besthit = hit

                  action = $data_skills[actions[i].skill_id]

                  #p event.casting?

                  #p action

                end

              end

            end #End Skill dud testing

          end

        end

      end # End skill consider check

    end # Highest rating

    return action

  end # Ending get_best_attack funciton

end

 

#==============================================================================

# ** Game_AmmoManager (part Extra)

#------------------------------------------------------------------------------

# This class handles ammo and ammo requests.

#==============================================================================

class Game_AmmoManager

  attr_accessor   :pool

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    @pool = []

    @max = []

  end

  #--------------------------------------------------------------------------

  # * Deposit: Adds ammo to a given ammo pool

  #--------------------------------------------------------------------------

  def deposit(pool,amount)

    if @pool[pool] == nil

      @pool[pool] = 0

    end

    if (@pool[pool] + amount) < @max[pool]

      @pool[pool] += amount

    else

      @pool[pool] = @max[pool]

    end

  end

  #--------------------------------------------------------------------------

  # * Balance: Returns amount of ammo in a given pool

  #--------------------------------------------------------------------------

  def withdraw(pool,amount)

    if @pool[pool] == nil

      @pool[pool] = 0

    end

    if @pool[pool] > amount

      @pool[pool] -= amount

      return amount

    else

      ammo = @pool[pool]

      @pool[pool] = 0

      return ammo

    end

  end

  #--------------------------------------------------------------------------

  # * Withdrawl: Returns the amount in the pool of it exists, else 0.

  #--------------------------------------------------------------------------

  def balance(pool)

    if pool != nil

      if @pool[pool] == nil

        @pool[pool] = 0

      end

      if @pool[pool] != nil

        return @pool[pool]

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Withdrawl: Returns either the full requested withdrawl, or max it can give

  #--------------------------------------------------------------------------

  def set_max(pool,max)

    @max[pool] = max

  end

end # End the Ammo Manager

 

#==============================================================================

# ** Game_Character (part Extra)

#------------------------------------------------------------------------------

#  This class deals with characters. It's used as a superclass for the

#  Game_Player and Game_Event classes.

#==============================================================================

 

class Game_Character

  attr_accessor :follow_mouse

  attr_accessor :move_route

  attr_accessor :direction_fix

  attr_accessor :dirfix_time

  attr_accessor :move_mods

  attr_accessor :casting

  attr_accessor :damage

  attr_accessor :weapon

  attr_reader   :swing_count

  attr_reader   :weapon_pattern

  attr_reader   :weapon_mode

  attr_reader   :weapon_anime

  attr_accessor :white_flash

  attr_accessor :cast_color

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  alias :normal_init :initialize

  def initialize

    @weapon_anime = 0

    @casting_animation = 0

    @wait_count = 0

    @action_freeze = 0

    @move_freeze = 0

    @move_mods = []

    @original_speed = 0

    @original_frequency = 0

    @follow_mouse = false

    @dirfix_time = 0

    @casting = 0

    @swing_count = 0

    @weapon_pattern = 0

    @weapon = nil

    @weapon_mode = 0

    @white_flash = false

    @cast_color = Color.new(128,192,255,255)

    @damage = []

    normal_init

  end

  #--------------------------------------------------------------------------

  # * Determine if Moving

  #--------------------------------------------------------------------------

  alias :normal_moving? :moving?

  def moving?

    # If logical coordinates differ from real coordinates,

    # movement is occurring.

    if @battler != nil and @battler.hp <= 0

      return false

    else

      normal_moving?

    end

  end

  #--------------------------------------------------------------------------

  # * Set a new character graphic/hue

  #--------------------------------------------------------------------------

  def set_character_graphics(character_name, character_hue)

    # If logical coordinates differ from real coordinates,

    # movement is occurring.

    @character_name = character_name

    @character_hue = character_hue

  end

  #--------------------------------------------------------------------------

  # * 

  #--------------------------------------------------------------------------

  alias :system_terg_passable? :passable?

  def passable?(x, y, d)

    # Get new coordinates

    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)

    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)

    # If coordinates are outside of map

    unless $game_map.valid?(new_x, new_y)

      # impassable

      return false

    end

    # Loop all events

    for event in $game_map.player_characters

      # If event coordinates are consistent with move destination

      if event.x == new_x and event.y == new_y

        # If through is OFF

        unless event.through

          # If self is event

          if self != $game_player

            # impassable

            return false

          end

          # With self as the player and partner graphic as character

          if event.character_name != ""

            # impassable

            return false

          end

        end

      end

    end

    system_terg_passable?(x, y, d)

  end

  #--------------------------------------------------------------------------

  # * Follow Mouse

  #--------------------------------------------------------------------------

  alias :normal_update :update

  def update

    rating = -1

    if @move_mods.size <= 0 and @move_speed != @original_move and @move_frequency != @move_frequency

      if self.is_a?(Game_Event)

        @move_speed = @original_move

        @move_frequency = @original_frequency

      elsif self.is_a?(Game_Player)

        @move_speed = @original_move

        @move_frequency = @original_frequency

      end

    else

      for i in 0...@move_mods.size

        if @move_mods[i][0] <= 0

          @move_mods[i] = nil

          if self.is_a?(Game_Event)

            @move_speed = @original_move

            @move_frequency = @original_frequency

          elsif self.is_a?(Game_Player)

            @move_speed = @original_move

            @move_frequency = @original_frequency

          end

        else

          @move_mods[i][0] -= 1

          if @move_mods[i][3] > rating

            @move_speed = @move_mods[i][1]

            @move_frequency = @move_mods[i][2]

            rating = @move_mods[i][3]

          end

        end

      end

    end

    @move_mods.delete(nil)

    # If animation count exceeds maximum value

    # * Maximum value is move speed * 1 taken from basic value 18

    if @swing_count > 0

      # Update pattern

      if @weapon_mode != 1

        @weapon_mode = 1

      end

      @swing_count -= 1

      if @swing_count % 4 == 0

        @weapon_pattern = (@weapon_pattern + 1) % 4

        if @swing_count % 8 == 0

          @pattern = (@pattern + 1) % 4

        end

      end

      @anime_count = 0

    end

    normal_update

    if not @swing_count > 0

      if @weapon_mode != 0

        @weapon_mode = 0

      end

      if @weapon_anime > 18 - @move_speed * 2

        # If stop animation is OFF when stopping

        if not @step_anime and @stop_count > 0

          # Return to original pattern

          @weapon_pattern = @original_pattern

        # If stop animation is ON when moving

        else

          # Update pattern

          @weapon_pattern = (@weapon_pattern + 1) % 4

        end

        @weapon_anime = 0

      end

    end

  end

  # Aliased update_move to get anime rating

  alias :normal_update_move :update_move

  def update_move

    normal_update_move

    @weapon_anime = @anime_count

  end

  # Aliased update_stop to get anime rating

  alias :normal_update_stop :update_stop

  def update_stop

    normal_update_stop

    @weapon_anime = @anime_count

  end

  #--------------------------------------------------------------------------

  # * Follow Mouse

  #--------------------------------------------------------------------------

  def turn_mouse

    if @dirfix_time <= 0

      pos = Mouse.pos

      if pos == nil

        return

      end

      x_diff = (screen_x.abs) - (pos[0].abs)

      y_diff = (screen_y.abs) - (pos[1].abs)

      x_diff = x_diff.abs

      y_diff = y_diff.abs

      if screen_x > pos[0]

        # -X, -Y

        if screen_y > pos[1]

          if x_diff > y_diff

            @direction = 4

            @stop_count = 0

          else

            @direction = 8

            @stop_count = 0

          end

          # -X, +Y

        else

          if x_diff > y_diff

            @direction = 4

            @stop_count = 0

          else

            @direction = 2

            @stop_count = 0

          end

        end

      else

        # +X, -Y

        if screen_y > pos[1]

          if x_diff > y_diff

            @direction = 6

            @stop_count = 0

          else

            @direction = 8

            @stop_count = 0

          end

          # +X, +Y

        else

          if x_diff > y_diff

            @direction = 6

            @stop_count = 0

          else

            @direction = 2

            @stop_count = 0

          end

        end

      end

    end

  end

  #End of Turn Mouse function

  #--------------------------------------------------------------------------

  # * Move Down

  #     turn_enabled : a flag permits direction change on that spot

  #--------------------------------------------------------------------------

  alias :normal_down :move_down

  def move_down(turn_enabled = true)

    if @dirfix_time > 0

      # If passable

      if passable?(@x, @y, 2)

        # Update coordinates

        @y += 1

        # Increase steps

        increase_steps

      # If impassable

      else

        # Determine if touch event is triggered

        check_event_trigger_touch(@x+1, @y)

      end

    else

      normal_down

    end

  end

  #--------------------------------------------------------------------------

  # * Move Left

  #     turn_enabled : a flag permits direction change on that spot

  #--------------------------------------------------------------------------

  alias :normal_left :move_left

  def move_left(turn_enabled = true)

    if @dirfix_time > 0

      # If passable

      if passable?(@x, @y, 4)

        # Update coordinates

        @x -= 1

        # Increase steps

        increase_steps

      # If impassable

      else

        # Determine if touch event is triggered

        check_event_trigger_touch(@x+1, @y)

      end

    else

      normal_left

    end

  end

  #--------------------------------------------------------------------------

  # * Move Right

  #     turn_enabled : a flag permits direction change on that spot

  #--------------------------------------------------------------------------

  alias :normal_right :move_right

  def move_right(turn_enabled = true)

    # Turn right

    if @dirfix_time > 0

      # If passable

      if passable?(@x, @y, 6)

        # Update coordinates

        @x += 1

        # Increase steps

        increase_steps

      # If impassable

      else

        # Determine if touch event is triggered

        check_event_trigger_touch(@x+1, @y)

      end

    else

      normal_right

    end

  end

  #--------------------------------------------------------------------------

  # * Move up

  #     turn_enabled : a flag permits direction change on that spot

  #--------------------------------------------------------------------------

  alias :normal_up :move_up

  def move_up(turn_enabled = true)

    # Turn up

    if @dirfix_time > 0

      # If passable

      if passable?(@x, @y, 8)

        # Update coordinates

        @y -= 1

        # Increase steps

        increase_steps

      # If impassable

      else

        # Determine if touch event is triggered

        check_event_trigger_touch(@x+1, @y)

      end

    else

      normal_up

    end

  end

  #End of Move Up

  #--------------------------------------------------------------------------

  # * Move toward Player

  #--------------------------------------------------------------------------

  def move_toward_target(target)

    # Get difference in player coordinates

    sx = @x - target.x

    sy = @y - target.y

    if @old_x == @x and @old_y == @y

      @counter += 1

    else

      @counter = 0

    end

    # If coordinates are equal

    if sx == 0 and sy == 0

      return

    end

    # Get absolute value of difference

    abs_sx = sx.abs

    abs_sy = sy.abs

    # If horizontal and vertical distances are equal

    if abs_sx == abs_sy

      # Increase one of them randomly by 1

      rand(2) == 0 ? abs_sx += 1 : abs_sy += 1

    end

    # If horizontal distance is longer

    if abs_sx > abs_sy

      # Move towards player, prioritize left and right directions

      sx > 0 ? move_left : move_right

      if not moving? and sy != 0

        sy > 0 ? move_up : move_down

      end

    # If vertical distance is longer

    else

      # Move towards player, prioritize up and down directions

      sy > 0 ? move_up : move_down

      if not moving? and sx != 0

        sx > 0 ? move_left : move_right

      end

    end

    @old_x = @x

    @old_y = @y

  end

  #--------------------------------------------------------------------------

  # * Move away from Player

  #--------------------------------------------------------------------------

  def move_away_from_target(target)

    # Get difference in player coordinates

    sx = @x - target.x

    sy = @y - target.y

    if @old_x == @x and @old_y == @y

      @counter += 1

    else

      @counter = 0

    end

    # If coordinates are equal

    if sx == 0 and sy == 0

      return

    end

    # Get absolute value of difference

    abs_sx = sx.abs

    abs_sy = sy.abs

    # If horizontal and vertical distances are equal

    if abs_sx == abs_sy

      # Increase one of them randomly by 1

      rand(2) == 0 ? abs_sx += 1 : abs_sy += 1

    end

    # If horizontal distance is longer

    if abs_sx > abs_sy

      # Move away from player, prioritize left and right directions

      sx > 0 ? move_right : move_left

      if not moving? and sy != 0

        sy > 0 ? move_down : move_up

      end

    # If vertical distance is longer

    else

      # Move away from player, prioritize up and down directions

      sy > 0 ? move_down : move_up

      if not moving? and sx != 0

        sx > 0 ? move_right : move_left

      end

    end

    @old_x = @x

    @old_y = @y

    end

  end

  #--------------------------------------------------------------------------

  # * Move toward Player

  #--------------------------------------------------------------------------

  def move_toward_point(x, y)

    # Get difference in player coordinates

    sx = @x - x

    sy = @y - y

    if @old_x == @x and @old_y == @y

      @counter += 1

    else

      @counter = 0

    end

    # If coordinates are equal

    if sx == 0 and sy == 0

      return

    end

    # Get absolute value of difference

    abs_sx = sx.abs

    abs_sy = sy.abs

    # If horizontal and vertical distances are equal

    if abs_sx == abs_sy

      # Increase one of them randomly by 1

      rand(2) == 0 ? abs_sx += 1 : abs_sy += 1

    end

    # If horizontal distance is longer

    if abs_sx > abs_sy

      # Move towards player, prioritize left and right directions

      sx > 0 ? move_left : move_right

      if not moving? and sy != 0

        sy > 0 ? move_up : move_down

      end

    # If vertical distance is longer

    else

      # Move towards player, prioritize up and down directions

      sy > 0 ? move_up : move_down

      if not moving? and sx != 0

        sx > 0 ? move_left : move_right

      end

    end

    @old_x = @x

    @old_y = @y

  end

  #--------------------------------------------------------------------------

  # * Move away from Player

  #--------------------------------------------------------------------------

  def set_move_sf(moves, speed, frequency, rating)

    if self.is_a?(Game_Event)

      self.refresh

    end

    @move_mods.push([moves, speed, frequency, rating])

  end

# End of Game_Character

 

#==============================================================================

# ** Game_PartyMember

#------------------------------------------------------------------------------

#  This class handles the additional party members!

#==============================================================================

 

class Game_PartyMember < Game_Character

  attr_reader     :actor_id

  attr_accessor   :map_event

  attr_accessor   :direction

  #--------------------------------------------------------------------------

  # * Init Game Player

  #--------------------------------------------------------------------------

  def initialize(id, actor_id)

    super()

    @action_reset = 35

    @action_ready = 0

    @action_freeze = 0

    @action_regen = 5

    @regen_now = 1

    @actor_id = actor_id

    @id = 10000 + id

    @original_move = @move_speed

    @original_frequency = @move_frequency

    @original_character_name = ""

  end

  #--------------------------------------------------------------------------

  # * Alias'd update to clear visibility if the person is dead

  #--------------------------------------------------------------------------

  alias :system_terg_normal_update :update

  def update

    if dead? and @character_name != ""

      @original_character_name = @character_name

      @character_name = ""

    elsif not dead? and @character_name == ""

      @character_name = @original_character_name

    end

  end

  #--------------------------------------------------------------------------

  # * Player made an Action

  #--------------------------------------------------------------------------

  def acted(weapon)

    #weapon = $data_weapons[$game_party.actors[@actor_id].weapon_id]

    successful_action = false

    # If there is an ammo type, decrease it's use!

    if casting? or (weapon.rap != nil and weapon.rap > $game_party.actors[@actor_id].ap)

      successful_action = false

      Audio.se_play("Audio/SE/004-System04", 80, 100)

    elsif weapon.ammo_type != nil and $game_party.actors[@actor_id].can_use_current_weapon

      $game_party.actors[@actor_id].decrease_current_ammo

      successful_action = true

    elsif weapon.ammo_type == nil

      successful_action = true

    end

    if successful_action

      if weapon.animations != nil

        index = 0

        case @direction

        when 2

          index = 0

        when 4

          index = 1

        when 6

          index = 2

        when 8

          index = 3

        end

        $animations.push(Animation.new('player',0,-10,weapon.animations[index]))

      else

        $animations.push(Animation.new('player',0,-10,$game_party.actors[@actor_id].animation1_id))

      end

      if weapon.rap != nil

        $game_party.actors[@actor_id].ap -= weapon.rap

      end

      @dirfix_time = @move_speed * 5

      @swing_count = 16

    end

    @action_ready = weapon.delay

    return successful_action

  end

  #--------------------------------------------------------------------------

  # * Generate Enemy

  #--------------------------------------------------------------------------

  def dead?

    if $game_party.actors[@actor_id] != nil and $game_party.actors[@actor_id].hp <= 0

      return true

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Player made a Skill Action

  #--------------------------------------------------------------------------

  def cast(skill)

    successful_action = false

    # If there is an ammo type, decrease it's use!

    # If items are required, mark it as usuable if the reqs are met

    meet_item_reqs = false

    if skill.required_item != nil

      if $game_party.item_number(skill.required_item[0]) >= 1 and $game_party.item_number(skill.required_item[0]) >= skill.required_item[1]

        meet_item_reqs = true

      end

    end

    if casting? or (skill.rap != nil and skill.rap > $game_party.actors[@actor_id].ap) or not meet_item_reqs

      successful_action = false

      Audio.se_play("Audio/SE/004-System04", 80, 100)

    elsif skill.ammo_type != nil and $game_party.actors[@actor_id].skill_can_use?(skill.id)

      if skill.weapon_dependency == nil 

        successful_action = true

      elsif skill.weapon_dependency.include?($game_party.actors[@actor_id].weapon_id)

        successful_action = true

      end

    elsif $game_party.actors[@actor_id].skill_can_use?(skill.id)

      if skill.weapon_dependency == nil 

        successful_action = true

      elsif skill.weapon_dependency.include?($game_party.actors[@actor_id].weapon_id)

        successful_action = true

      end

    end

    if successful_action

      if skill.animations != nil

        index = 0

        case @direction

        when 2

          index = 0

        when 4

          index = 1

        when 6

          index = 2

        when 8

          index = 3

        end

        $animations.push(Animation.new('tile',@x,@y,skill.animations[index]))

      else

        $animations.push(Animation.new('tile',@x,@y,skill.animation1_id))

      end

      @action_ready = skill.delay

      @action_freeze = skill.ddelay

      @move_freeze = skill.delay

      if skill.ddelay > 1

        @cast_color = Color.new(128,192,255,255)

        @casting = skill.ddelay

      end

      $game_party.actors[@actor_id].sp -= skill.sp_cost

      if skill.rap != nil

        $game_party.actors[@actor_id].ap -= skill.rap

      end

      if skill.required_item != nil

        $game_party.lose_item(skill.required_item[0],skill.required_item[1])

        if $game_party.item_number(skill.required_item[0]) <= 0

          for i in 0...$game_party.actors.size

            if $game_party.actors[i].item_id == skill.required_item[0]

              $game_party.actors[i].item_id = nil

            end

          end

        end

      end

      @dirfix_time = @move_speed * 5

    end

    return successful_action

  end

  #--------------------------------------------------------------------------

  # * Can_act? - Returns true if @action_ready == 0

  #--------------------------------------------------------------------------

  def reload

    wid = $game_party.actors[@actor_id].weapon_id

    if wid != 0

      if $data_weapons[wid].ammo_type != nil

        if $game_party.actors[@actor_id].ammo[wid] == nil

          $game_party.actors[@actor_id].ammo[wid] = 0

        end

        if $data_weapons[wid].ammo_type != nil

          reload_amount = $data_weapons[wid].capacity - $game_party.actors[@actor_id].ammo[wid]

          available = $game_system.ammo.withdraw($data_weapons[wid].ammo_type, reload_amount)

          $game_party.actors[@actor_id].ammo[wid] += available

          if $data_weapons[wid].reload_time * available > 0

            @cast_color = Color.new(192,255,128,255)

            @casting = $data_weapons[wid].reload_time * available

          end

          @action_ready = ($data_weapons[wid].reload_time * available)

          if available > 0

            Audio.se_play("Audio/SE/" + $data_weapons[wid].reload_sound, 80, 100)

          else

            Audio.se_play("Audio/SE/004-System04", 80, 100)

          end

        end

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Can_act? - Returns true if @action_ready == 0

  #--------------------------------------------------------------------------

  def can_act?

    if @action_ready <= 0

      return true

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Damage Turn

  #--------------------------------------------------------------------------

  def turn(actor)

    battler = $game_party.actors[@actor_id]

    if battler != nil and battler.damage != nil

      @damage = [battler.damage, battler.critical]

      #if @animation_id = 0

      #  @animation_id = actor.animation2_id

      #end

      battler.damage = nil

      battler.critical = false

      battler.damage_pop = false

    end

    if battler.hp <= 0

      #p "Game Over!"

      Audio.se_play("Audio/SE/011-System11", 80, 100)

      @is_dead = true

    end

  end

  #--------------------------------------------------------------------------

  # * Move away from Player

  #--------------------------------------------------------------------------

  def casting?

    if @action_freeze > 0

      return true

    else

      return false

    end

  end

  #--------------------------------------------------------------------------

  # * Move away from Player

  #--------------------------------------------------------------------------

  def stuck?

    if @move_freeze > 0

      return true

    else

      return false

    end

  end

  #--------------------------------------------------------------------------

  # * Line of Sight Function

  #--------------------------------------------------------------------------

  def line_of_sight(source, weapon)

    if weapon != nil

      sx = source.x

      sy = source.y

      tx = @x

      ty = @y

      x_diff = (sx.abs) - (tx.abs)

      y_diff = (sy.abs) - (ty.abs)

      x_diff = x_diff.abs

      y_diff = y_diff.abs

      if sx > tx

        # -X, -Y

        if sy > ty

          if x_diff > y_diff

            direction = 4

          else

            direction = 8

          end

          # -X, +Y

        else

          if x_diff > y_diff

            direction = 4

          else

            direction = 2

          end

        end

      else

        # +X, -Y

        if sy > ty

          if x_diff > y_diff

            direction = 6

          else

            direction = 8

          end

          # +X, +Y

        else

          if x_diff > y_diff

            direction = 6

          else

            direction = 2

          end

        end

      end

      return rec_los(sx, sy, tx, ty, weapon)

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Calculate Operated Value

  #     x    : X-coordinates

  #     y    : Y-coordinates

  #     tx   : Target X-coordinates, where you want to be

  #     ty   : Target Y-coordinates, where you want to be

  #     dir  : Which direction to finish in before moving on, 0 = x, 1 = y

  #--------------------------------------------------------------------------

  def rec_los(x, y, tx, ty, weapon)

    # For X direction

    if x != tx

      if x < tx

        x += 1

      else

        x -= 1

      end

    end

    # For Y direction

    if y != ty

      if y < ty

        y += 1

      else

        y -= 1

      end

    end

    if $game_map.terrain_tag(x,y) >= weapon.piercing

      return false

    end

    if x == tx and y == ty

      return true

    else

      return rec_los(x, y, tx, ty, weapon)

    end

  end

  # End of rec_los

end

# End Game_PartyMember

 

#==============================================================================

# ** Game_Player

#------------------------------------------------------------------------------

#  This class handles the player. Its functions include event starting

#  determinants and map scrolling. Refer to "$game_player" for the one

#  instance of this class.

#==============================================================================

 

class Game_Player < Game_Character

  attr_accessor   :action_ready

  attr_accessor   :action_reset

  attr_accessor   :sprite

  attr_accessor   :action_regen

  attr_accessor   :original_move

  attr_accessor   :original_frequency

  #--------------------------------------------------------------------------

  # * Init Game Player

  #--------------------------------------------------------------------------

  def initialize

    super()

    @action_reset = 35

    @action_ready = 0

    @action_freeze = 0

    @action_regen = 5

    @regen_now = 1

    @original_move = @move_speed

    @original_frequency = @move_frequency

  end

  #--------------------------------------------------------------------------

  # * Passable Determinants

  #     x : x-coordinate

  #     y : y-coordinate

  #     d : direction (0,2,4,6,8)

  #         * 0 = Determines if all directions are impassable (for jumping)

  #--------------------------------------------------------------------------

  alias :norm_passable :passable?

  def passable?(x, y, d)

    if Input.press?(Input::CTRL)

      # Get new coordinates

      new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)

      new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)

      # If coordinates are outside of map

      unless $game_map.valid?(new_x, new_y)

        # Impassable

        return false

      end

      super

    else

      return norm_passable(x, y, d)

    end

  end

  #--------------------------------------------------------------------------

  # * Player made an Action

  #--------------------------------------------------------------------------

  def acted(weapon)

    #weapon = $data_weapons[$game_party.actors[0].weapon_id]

    successful_action = false

    # If there is an ammo type, decrease it's use!

    if casting? or (weapon.rap != nil and weapon.rap > $game_party.actors[0].ap)

      successful_action = false

      Audio.se_play("Audio/SE/004-System04", 80, 100)

    elsif weapon.ammo_type != nil and $game_party.actors[0].can_use_current_weapon

      $game_party.actors[0].decrease_current_ammo

      successful_action = true

    elsif weapon.ammo_type == nil

      successful_action = true

    end

    if successful_action

      if weapon.animations != nil

        index = 0

        case @direction

        when 2

          index = 0

        when 4

          index = 1

        when 6

          index = 2

        when 8

          index = 3

        end

        $animations.push(Animation.new('player',0,-10,weapon.animations[index]))

      else

        $animations.push(Animation.new('player',0,-10,$game_party.actors[0].animation1_id))

      end

      if weapon.rap != nil

        $game_party.actors[0].ap -= weapon.rap

      end

      #@dirfix_time = @move_speed * 5

      @swing_count = 16

    end

    @action_ready = weapon.delay

    return successful_action

  end

  #--------------------------------------------------------------------------

  # * Generate Enemy

  #--------------------------------------------------------------------------

  def dead?

    if $game_party.actors[0] != nil and $game_party.actors[0].hp <= 0

      return true

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Player made a Skill Action

  #--------------------------------------------------------------------------

  def cast(skill)

    successful_action = false

    # If items are required, mark it as usuable if the reqs are met

    meet_item_reqs = true

    if skill.required_item != nil

      if $game_party.item_number(skill.required_item[0]) >= 1 and $game_party.item_number(skill.required_item[0]) >= skill.required_item[1]

        meet_item_reqs = true

      else

        meet_item_reqs = false

      end

    end

    # If there is an ammo type, decrease it's use

    if casting? or not meet_item_reqs or (skill.rap != nil and skill.rap > $game_party.actors[0].ap)

      successful_action = false

      Audio.se_play("Audio/SE/004-System04", 80, 100)

    elsif skill.ammo_type != nil and $game_party.actors[0].skill_can_use?(skill.id)

      if skill.weapon_dependency == nil 

        successful_action = true

      elsif skill.weapon_dependency.include?($game_party.actors[0].weapon_id)

        successful_action = true

      end

    elsif $game_party.actors[0].skill_can_use?(skill.id)

      if skill.weapon_dependency == nil 

        successful_action = true

      elsif skill.weapon_dependency.include?($game_party.actors[0].weapon_id)

        successful_action = true

      end

    end

    if successful_action

      if skill.animations != nil

        index = 0

        case @direction

        when 2

          index = 0

        when 4

          index = 1

        when 6

          index = 2

        when 8

          index = 3

        end

        $animations.push(Animation.new('player',0,-10,skill.animations[index]))

      else

        $animations.push(Animation.new('player',0,-10,skill.animation1_id))

      end

      @action_ready = skill.delay

      @action_freeze = skill.ddelay

      @move_freeze = skill.delay

      if skill.ddelay > 1

        @cast_color = Color.new(128,192,255,255)

        @casting = skill.ddelay

      end

      $game_party.actors[0].sp -= skill.sp_cost

      if skill.rap != nil

        $game_party.actors[0].ap -= skill.rap

      end

      if skill.required_item != nil

        $game_party.lose_item(skill.required_item[0],skill.required_item[1])

        if $game_party.item_number(skill.required_item[0]) <= 0

          for i in 0...$game_party.actors.size

            if $game_party.actors[i].item_id == skill.required_item[0]

              $game_party.actors[i].item_id = nil

            end

          end

        end

      end

      #@dirfix_time = @move_speed * 5

    end

    return successful_action

  end

  #--------------------------------------------------------------------------

  # * Can_act? - Returns true if @action_ready == 0

  #--------------------------------------------------------------------------

  def reload

    wid = $game_party.actors[0].weapon_id

    if wid != 0

      if $data_weapons[wid].ammo_type != nil

        if $game_party.actors[0].ammo[wid] == nil

          $game_party.actors[0].ammo[wid] = 0

        end

        if $data_weapons[wid].ammo_type != nil

          reload_amount = $data_weapons[wid].capacity - $game_party.actors[0].ammo[wid]

          available = $game_system.ammo.withdraw($data_weapons[wid].ammo_type, reload_amount)

          $game_party.actors[0].ammo[wid] += available

          if $data_weapons[wid].reload_time * available > 0

            @cast_color = Color.new(192,255,128,255)

            @casting = $data_weapons[wid].reload_time * available

          end

          @action_ready = ($data_weapons[wid].reload_time * available)

          if available > 0

            Audio.se_play("Audio/SE/" + $data_weapons[wid].reload_sound, 80, 100)

          else

            Audio.se_play("Audio/SE/004-System04", 80, 100)

          end

        end

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Switch Casting

  #--------------------------------------------------------------------------

  def start_switch(time)

    @cast_color = Color.new(255,192,128,255)

    @action_freeze = time

    @move_freeze = time

    @casting = time

  end

  #--------------------------------------------------------------------------

  # * Can_act? - Returns true if @action_ready == 0

  #--------------------------------------------------------------------------

  def can_act?

    if @action_ready <= 0

      return true

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Damage Turn

  #--------------------------------------------------------------------------

  def turn(actor)

    battler = $game_party.actors[0]

    if battler != nil and battler.damage != nil

      @damage = [battler.damage, battler.critical]

      battler.damage = nil

      battler.critical = false

      battler.damage_pop = false

    end

    if battler.hp <= 0

      #p "Game Over!"

      Audio.se_play("Audio/SE/011-System11", 80, 100)

      if not $game_party.all_dead?

        $scene.force_player_switch

      else

        $game_switches[$game_system.GAME_OVER_SWITCH] = true

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Move away from Player

  #--------------------------------------------------------------------------

  def casting?

    if @action_freeze > 0

      return true

    else

      return false

    end

  end

  #--------------------------------------------------------------------------

  # * Move away from Player

  #--------------------------------------------------------------------------

  def stuck?

    if @move_freeze > 0

      return true

    else

      return false

    end

  end

  #--------------------------------------------------------------------------

  # * Line of Sight Function

  #--------------------------------------------------------------------------

  def line_of_sight(source, weapon)

    if weapon != nil

      sx = source.x

      sy = source.y

      tx = @x

      ty = @y

      x_diff = (sx.abs) - (tx.abs)

      y_diff = (sy.abs) - (ty.abs)

      x_diff = x_diff.abs

      y_diff = y_diff.abs

      if sx > tx

        # -X, -Y

        if sy > ty

          if x_diff > y_diff

            direction = 4

          else

            direction = 8

          end

          # -X, +Y

        else

          if x_diff > y_diff

            direction = 4

          else

            direction = 2

          end

        end

      else

        # +X, -Y

        if sy > ty

          if x_diff > y_diff

            direction = 6

          else

            direction = 8

          end

          # +X, +Y

        else

          if x_diff > y_diff

            direction = 6

          else

            direction = 2

          end

        end

      end

      return rec_los(sx, sy, tx, ty, weapon)

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Calculate Operated Value

  #     x    : X-coordinates

  #     y    : Y-coordinates

  #     tx   : Target X-coordinates, where you want to be

  #     ty   : Target Y-coordinates, where you want to be

  #     dir  : Which direction to finish in before moving on, 0 = x, 1 = y

  #--------------------------------------------------------------------------

  def rec_los(x, y, tx, ty, weapon)

    # For X direction

    if x != tx

      if x < tx

        x += 1

      else

        x -= 1

      end

    end

    # For Y direction

    if y != ty

      if y < ty

        y += 1

      else

        y -= 1

      end

    end

    if $game_map.terrain_tag(x,y) >= weapon.piercing

      return false

    end

    if x == tx and y == ty

      return true

    else

      return rec_los(x, y, tx, ty, weapon)

    end

  end

  # End of rec_los

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # Remember whether or not moving in local variables

    last_moving = moving?

    if @dirfix_time > 0

      @dirfix_time -= 1

    end

    if @action_ready > 0

      @action_ready -= 1

    end

    if @action_freeze > 0

      @action_freeze -= 1

    end

    if @move_freeze > 0

      @move_freeze -= 1

    end

    if @regen_now % 21 == 0

      for i in 0...$game_party.actors.size

        $game_party.actors[i].ap += @action_regen

        if $game_party.actors[i].ap > 100

          $game_party.actors[i].ap = 100

        end

      end

      @regen_now = 1

    else

      @regen_now += 1

    end

    if $game_party.actors[0].weapon_id != 0

      if $data_weapons[$game_party.actors[0].weapon_id].weapon_graphic != nil and $data_weapons[$game_party.actors[0].weapon_id].weapon_graphic != @weapon

        @weapon = $data_weapons[$game_party.actors[0].weapon_id].weapon_graphic

      elsif $data_weapons[$game_party.actors[0].weapon_id].weapon_graphic == nil and @weapon != nil

        @weapon = nil

      end

    end

    # If moving, event running, move route forcing, and message window

    # display are all not occurring

    unless moving? or $game_system.map_interpreter.running? or

           @move_route_forcing or $game_temp.message_window_showing or stuck?

      # Move player in the direction the directional button is being pressed

      #Input.update

      if Input.press?(Input::X) or Input.press?(Input::LEFT)

        move_left

      end

      if Input.press?(Input::Y) or Input.press?(Input::DOWN)

        move_down

      end

      if Input.press?(Input::Z) or Input.press?(Input::RIGHT)

        move_right

      end

      if Input.press?(Input::R) or Input.press?(Input::UP)

        move_up

      end

    end

    # Remember coordinates in local variables

    last_real_x = @real_x

    last_real_y = @real_y

    super

    # If character moves down and is positioned lower than the center

    # of the screen

    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y

      # Scroll map down

      $game_map.scroll_down(@real_y - last_real_y)

    end

    # If character moves left and is positioned more let on-screen than

    # center

    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X

      # Scroll map left

      $game_map.scroll_left(last_real_x - @real_x)

    end

    # If character moves right and is positioned more right on-screen than

    # center

    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X

      # Scroll map right

      $game_map.scroll_right(@real_x - last_real_x)

    end

    # If character moves up and is positioned higher than the center

    # of the screen

    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y

      # Scroll map up

      $game_map.scroll_up(last_real_y - @real_y)

    end

    # If not moving

    unless moving?

      # If player was moving last time

      if last_moving

        # Event determinant is via touch of same position event

        result = check_event_trigger_here([1,2])

        # If event which started does not exist

        if result == false

          # Disregard if debug mode is ON and ctrl key was pressed

        end

      end

      # If C button was pressed

      if Input.trigger?(Input::C) and not $game_player.casting?

        # Same position and front event determinant

        check_event_trigger_here([0])

        check_event_trigger_there([0,1,2])

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Same Position Starting Determinant

  #--------------------------------------------------------------------------

  def check_event_trigger_here(triggers)

    result = false

    # If event is running

    if $game_system.map_interpreter.running?

      return result

    end

    # All event loops

    for event in $game_map.events.values

      # If event coordinates and triggers are consistent

      if event.x == @x and event.y == @y and triggers.include?(event.trigger)

        # If starting determinant is same position event (other than jumping)

        if not event.jumping? and event.over_trigger?

          event.start

          result = true

        end

      end

    end

    return result

  end

  #--------------------------------------------------------------------------

  # * Front Envent Starting Determinant

  #--------------------------------------------------------------------------

  def check_event_trigger_there(triggers)

    result = false

    # If event is running

    if $game_system.map_interpreter.running?

      return result

    end

    # Calculate front event coordinates

    new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)

    new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)

    # All event loops

    for event in $game_map.events.values

      # If event coordinates and triggers are consistent

      if event.x == new_x and event.y == new_y and

         triggers.include?(event.trigger)

        # If starting determinant is front event (other than jumping)

        mouse = false

        if event.list != nil

          for item in event.list

            if item.code == 108 and item.parameters[0] == "ACTION"

              mouse = true

            end

          end

        end

        if not event.jumping? and not event.over_trigger? and not mouse

          event.start

          result = true

        end

      end

    end

    # If fitting event is not found

    if result == false

      # If front tile is a counter

      if $game_map.counter?(new_x, new_y)

        # Calculate 1 tile inside coordinates

        new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)

        new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)

        # All event loops

        for event in $game_map.events.values

          # If event coordinates and triggers are consistent

          if event.x == new_x and event.y == new_y and

             triggers.include?(event.trigger)

            # If starting determinant is front event (other than jumping)

            mouse = false

            for item in event.list

              if item.code == 108 and item.parameters[0] == "ACTION"

                mouse = true

              end

            end

            if not event.jumping? and not event.over_trigger? and not mouse

              event.start

              result = true

            end

          end

        end

      end

    end

    return result

  end

end

#End Game_Player

 

#==============================================================================

# ** Sprite_Cursor

#------------------------------------------------------------------------------

#  This sprite is used to display the picture.It observes the Game_Character

#  class and automatically changes sprite conditions.

#==============================================================================

 

class Sprite_Cursor < Sprite

  attr_accessor   :x

  attr_accessor   :y

  attr_accessor   :icon

  attr_accessor   :lock

  #--------------------------------------------------------------------------

  # * Object Initialization

  #     viewport : viewport

  #     picture  : picture (Game_Picture)

  #--------------------------------------------------------------------------

  def initialize(viewport)

    super(viewport)

    update

    @icon = $game_system.cursor

    @old_icon = $game_system.cursor

    @lock = false

  end

  #--------------------------------------------------------------------------

  # * Dispose

  #--------------------------------------------------------------------------

  def dispose

    if self.bitmap != nil

      self.bitmap.dispose

    end

    super

  end

  #--------------------------------------------------------------------------

  # * Dispose

  #--------------------------------------------------------------------------

  def set_icon(new)

    if not @lock

      @icon = new

    end

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    super

    # If picture file name is different from current one

    if self.bitmap == nil

      self.bitmap = RPG::Cache.picture($game_system.cursor)

    end

    

    if @icon != @old_icon

      if @icon == nil

        self.bitmap = RPG::Cache.picture($game_system.cursor)

        @old_icon = nil

      else

        self.bitmap = RPG::Cache.picture(@icon)

        @old_icon = @icon

      end

    end

    # If file name is empty

    # Set sprite to visible

    self.visible = true

    # Set transfer starting point

    # Set sprite coordinates

    pos = Mouse.pos

    if pos == nil

      if self.x == nil

        self.x = 0

      end

      if self.y == nil

        self.y = 0

      end

    else

      self.x = 0 #pos[0]

      self.ox = pos[0] * -1 + (self.bitmap.width / 2)

      self.y = 0 #pos[1]

      self.oy = pos[1] * -1 + (self.bitmap.height / 2)

    end

  end

end

 

#==============================================================================

# ** Window_PartyCommand

#------------------------------------------------------------------------------

#  This window is used to select whether to fight or escape on the battle

#  screen.

#==============================================================================

 

class Window_PlayerStats < Window_Base

  attr_reader   :actor

  attr_accessor :redraw

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    super(-16, 415, 156, 82)

    self.contents = Bitmap.new(width - 32, height - 32)

    self.windowskin = nil

    #self.windowskin = RPG::Cache.windowskin("comic_skin_dark")

    self.back_opacity = 160

    self.visible = false

    @background = RPG::Cache.picture("HUD-bars")

    @actor = $game_party.actors[0]

    @hp = @actor.hp

    @mp = @actor.sp

    @ap = @actor.ap

    @name = @actor.name

    @redraw = true

  end

  

  def set_actor(actor = nil)

    if actor == nil

      @actor = $game_party.actors[0]

      @hp = @actor.hp

      @mp = @actor.sp

      @ap = @actor.ap

      @name = @actor.name

      @redraw = true

    else

      @actor = actor

      @hp = @actor.hp

      @mp = @actor.sp

      @ap = @actor.ap

      @name = @actor.name

      @redraw = true

    end

  end

  

  def update

    if @actor != nil

      if not (@hp == @actor.hp and @mp == @actor.sp and @name == @actor.name and @ap == @actor.ap) or @redraw

        refresh

      end

    end

  end

  

  def refresh

    self.contents.clear

    self.contents.font.color = Color.new(32,32,32,255)

    self.contents.blt(0, 0, @background, Rect.new(0, 0, 124, 50))

    draw_actor_hp_bar(@actor, 7, -5, 90)

    draw_actor_sp_bar(@actor, 7, 8, 90)

    draw_actor_ap_bar(@actor, 7, 21, 90)

    @hp = @actor.hp

    @mp = @actor.sp

    @ap = @actor.ap

    @name = @actor.name

    @redraw = false

  end

end

 

#==============================================================================

# ** Window_AmmoStatus

#------------------------------------------------------------------------------

#  This window displays ammo.

#==============================================================================

 

class Window_AmmoStatus < Window_Base

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    super(520, 400, 135, 135)

    self.contents = Bitmap.new(width, height)

    self.windowskin = nil

    @old_ammo = 0

    @old_ammo_pool = 0

    @old_pool_id = 0

    @actor = nil

    @background = RPG::Cache.picture("HUD-gun")

    self.opacity = 64

    @already_empty = false

    set_actor

    refresh

  end

  # Set Actor

  def set_actor(actor = nil)

    if actor == nil

      @actor = $game_party.actors[0]

      @redraw

    else

      @actor = actor

    end

  end

  #--------------------------------------------------------------------------

  # * Update

  #--------------------------------------------------------------------------

  def update

    wid = @actor.weapon_id

    if wid != nil or @redraw

      refresh

    end

  end

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def refresh

    wid = @actor.weapon_id

    if wid != 0

      poolid = $data_weapons[wid].ammo_type

      gun_ammo = @actor.ammo[wid]

      ammo_pool = $game_system.ammo.balance(poolid)

      if @old_weapon != wid or @old_ammo != gun_ammo or ammo_pool != @old_ammo_pool or poolid != @old_pool_id

        @old_weapon = wid

        @old_ammo = gun_ammo

        @old_ammo_pool = ammo_pool

        @old_pool_id = poolid

        if poolid == nil

          gun_ammo = "*"

        else

          gun_ammo = gun_ammo.to_s

        end

        if poolid == nil

          ammo_pool = "*"

        else

          ammo_pool = ammo_pool.to_s

        end

        self.contents.clear

        weapon_icon = RPG::Cache.icon($data_weapons[wid].icon_name)

        self.contents.font.size = 20

        self.contents.font.bold = true

        self.contents.blt(0, 0, @background, Rect.new(0, 0, 128, 128))

        self.contents.blt(36, 9, weapon_icon, Rect.new(0, 0, 24, 24))

        self.contents.font.color = Color.new(32, 32, 32, 255)

        self.contents.draw_text(4, 32, 36, 32, gun_ammo, 2)

        self.contents.font.color = system_color

        self.contents.draw_text(40, 32, 8, 32, "/", 2)

        self.contents.draw_text(49, 32, 40, 32, ammo_pool, 2)

        @already_empty = false

      end

    elsif not @already_empty

      self.contents.clear

      self.contents.blt(0, 0, @background, Rect.new(0, 0, 128, 128))

      @already_empty = true

    end

    @redraw = false

  end

end

 

#==============================================================================

# ** Window_ItemStatus

#------------------------------------------------------------------------------

#  This window displays ammo.

#==============================================================================

 

class Window_ItemStatus < Window_Base

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    super(420, 425, 135, 135)

    self.contents = Bitmap.new(width, height)

    self.windowskin = nil

    @old_ammo = 0

    @old_ammo_pool = 0

    @old_pool_id = 0

    @actor = nil

    @background = RPG::Cache.picture("HUD-gun")

    self.opacity = 64

    set_actor

    refresh

  end

  # Set Actor

  def set_actor(actor = nil)

    if actor == nil

      @actor = $game_party.actors[0]

      @redraw

    else

      @actor = actor

    end

  end

  #--------------------------------------------------------------------------

  # * Update

  #--------------------------------------------------------------------------

  def update

    iid = @actor.item_id

    if $game_party.item_number(iid) <= 0

      iid = nil

    end

    if iid != 0 or @redraw

      refresh

    end

  end

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def refresh

    iid = @actor.item_id

    if $game_party.item_number(iid) <= 0

      iid = nil

    end

    if iid != nil and iid > 0

      item = $data_items[iid]

    else

      item = nil

    end

    if item != nil and @old_item != item

      @old_item = item

      self.contents.clear

      if iid > 0

        item_icon = RPG::Cache.icon($data_items[iid].icon_name)

      end

      self.contents.font.size = 20

      self.contents.font.bold = true

      self.contents.blt(0, 0, @background, Rect.new(0, 0, 128, 128))

      if iid > 0

        self.contents.blt(36, 9, item_icon, Rect.new(0, 0, 24, 24))

      end

    elsif item == nil and @old_item != nil

      @old_item = nil

      self.contents.clear

      self.contents.blt(0, 0, @background, Rect.new(0, 0, 128, 128))

    end

    @redraw = false

  end

end

 

#==============================================================================

# ** Window_EquippedSkills

#------------------------------------------------------------------------------

#  This window displays the list of equipped skills.

#==============================================================================

 

class Window_EquippedSkills < Window_Base

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    super(-16, -16, 279, 69)

    self.contents = Bitmap.new(width, height)

    self.windowskin = nil

    @actor = nil

    if $game_system.skill_limit == 4

      @background = RPG::Cache.picture("HUD-skill4")

    elsif $game_system.skill_limit == 6

      @background = RPG::Cache.picture("HUD-skill6")

    elsif $game_system.skill_limit == 8

      @background = RPG::Cache.picture("HUD-skill8")

    end

    @limit = $game_system.skill_limit

    self.opacity = 64

    @redraw = true

    @skills = [-1,-1,-1,-1,-1,-1,-1,-1]

    set_actor

    refresh

  end

  # Set Actor

  def set_actor(actor = nil)

    if actor == nil

      @actor = $game_party.actors[0]

      @redraw = true

    else

      @actor = actor

    end

  end

  #--------------------------------------------------------------------------

  # * Update

  #--------------------------------------------------------------------------

  def update

    if @limit != $game_system.skill_limit

      @limit = $game_system.skill_limit

      refresh

    end

    if not @skills.eql?(@actor.skill_id) or @redraw

      @skills = @actor.skill_id.clone

      refresh

    end

  end

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def refresh

    self.contents.clear

    if $game_system.skill_limit == 4

      @background = RPG::Cache.picture("HUD-skill4")

    elsif $game_system.skill_limit == 6

      @background = RPG::Cache.picture("HUD-skill6")

    elsif $game_system.skill_limit == 8

      @background = RPG::Cache.picture("HUD-skill8")

    end

    self.contents.blt(0, 0, @background, Rect.new(0, 0, 247, 37))

    for i in 0...@limit

      if @skills[i] != nil and @skills[i] >= 0

        skill_icon = RPG::Cache.icon($data_skills[@skills[i]].icon_name)

        self.contents.blt(((i*30)+5), 5, skill_icon, Rect.new(0, 0, 24, 24))

      end

    end

    @redraw = false

  end

end

 

 

#==============================================================================

# ** Scene_CombatMap

#------------------------------------------------------------------------------

#  This class performs map screen processing.

#==============================================================================

 

class Scene_Map

  attr_reader   :spriteset

  attr_reader   :huds

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    # Make sprite set

    @spriteset = Spriteset_Map.new

    # Make message window

    @message_window = Window_Message.new

    

    @command_window = Window_PopCommand.new(200,[nil])

    @command_window.active = false

    @command_window.visible = false

    

    @ammo_window = Window_AmmoStatus.new

    @ammo_window.visible = true

    @item_window = Window_ItemStatus.new

    @item_window.visible = true

    @status_window = Window_PlayerStats.new

    @status_window.visible = true

    @skills_window = Window_EquippedSkills.new

    @skills_window.visible = true

    @huds = Game_HUDManager.new

    

    # Add the windows for the HUD into the HUD Manager

    @huds.add_hud(@status_window)

    @huds.add_hud(@ammo_window)

    @huds.add_hud(@skills_window)

    @huds.add_hud(@item_window)

    @x_mouse = 0

    @y_mouse = 0

    @wait_time = 3

    @frame_rate = 5

    @update_interface = 0

    @char_switch_timer = -1

    @anim_update = @frame_rate

    @attacks = []

    @cycle = 0

    @skill_target = false

    @skill_index = -1

    # Transition run

    Graphics.transition

    # Main loop

    loop do

      # Update game screen

      Graphics.update

      # Update input information

      Input.update

      Input.mouse_update

      # Frame update

      update

      # Abort loop if screen is changed

      if $scene != self

        break

      end

    end

    # Prepare for transition

    Graphics.freeze

    # Dispose of sprite set

    @spriteset.dispose

    # Dispose of message window

    @message_window.dispose

    @huds.dispose

    @command_window.dispose

    if $animations != nil

      for animation in $animations

        animation.dispose

      end

    end

    $animations.clear

    # If switching to title screen

    if $scene.is_a?(Scene_Title)

      # Fade out screen

      Graphics.transition

      Graphics.freeze

    end

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # Loop

    loop do

      # Update map, interpreter, and player order

      # (this update order is important for when conditions are fulfilled 

      # to run any event, and the player isn't provided the opportunity to

      # move in an instant)

      $game_map.update

      $game_system.map_interpreter.update

      $game_player.update

      # Update system (timer), screen

      $game_system.update

      $game_screen.update

      # Abort loop if player isn't place moving

      unless $game_temp.player_transferring

        break

      end

      # Run place move

      transfer_player

      # Abort loop if transition processing

      if $game_temp.transition_processing

        break

      end

    end

    # Update sprite set

    @spriteset.update

    # Update message window

    @message_window.update

    @command_window.update

    @huds.update

    #Update the mouse

    mouse_interface_update

    if $game_system.ai != nil

      $game_system.ai.update

    end

    # Run animations and clean up the animations array

    if $animations != nil

      for animation in $animations

        animation.update

      end

      for i in 0...$animations.size

        if $animations[i].finished

          $animations[i] = nil

        end

      end

      $animations.delete(nil)

    end

    # If game over

    if $game_temp.gameover

      # Switch to game over screen

      $scene = Scene_Gameover.new

      return

    end

    # If returning to title screen

    if $game_temp.to_title

      # Change to title screen

      $scene = Scene_Title.new

      return

    end

    # If transition processing

    if $game_temp.transition_processing

      # Clear transition processing flag

      $game_temp.transition_processing = false

      # Execute transition

      if $game_temp.transition_name == ""

        Graphics.transition(20)

      else

        Graphics.transition(40, "Graphics/Transitions/" +

          $game_temp.transition_name)

      end

    end

    # If showing message window

    if $game_temp.message_window_showing

      return

    end

    

    # If B button was pressed

    if Input.trigger?(Input::B)

      # If event is running, or menu is not forbidden

      unless $game_system.map_interpreter.running? or

             $game_system.menu_disabled

        # Set menu calling flag or beep flag

        $game_temp.menu_calling = true

        $game_temp.menu_beep = true

      end

    end

    

    # If the char timer is done, teleport the player

    if @char_switch_timer == 0

      @char_switch_timer = -1

      switch_active_player

    elsif @char_switch_timer > 0

      @char_switch_timer -= 1

    end

    

    # If L key is pressed, switch characters.

    if Input.trigger?(Input::L) and not $game_player.casting? and $game_player.can_act? and $game_switches[$game_system.SWITCH_CHARS_OK_SWITCH] and not $game_temp.transition_processing

      @char_switch_timer = $game_system.SWITCH_CHAR_TIMER

      #$game_switches[$game_system.SWITCH_CHARS_OK_SWITCH] = false

      $game_player.start_switch($game_system.SWITCH_CHAR_TIMER)

      @skill_target = false

      @skill_index = -1

      @spriteset.cursor.lock = false

      @spriteset.cursor.set_icon(nil)

    end

    

    # If R key was pressed

    if Input.pressed?(Input::Letters["R"]) and $game_player.can_act?

      $game_player.reload

    end

    

    # Check Number key Input

    if Input.triggered?(Input::Numberkeys[1])

      if Input.pressed?(Input::Shift)

        menu_use_update(1)

      else

        skill_use_update(1)

      end

    elsif Input.triggered?(Input::Numberkeys[2])

      if Input.pressed?(Input::Shift)

        menu_use_update(2)

      else

        skill_use_update(2)

      end

    elsif Input.triggered?(Input::Numberkeys[3])

      if Input.pressed?(Input::Shift)

        menu_use_update(3)

      else

        skill_use_update(3)

      end

    elsif Input.triggered?(Input::Numberkeys[4])

      if Input.pressed?(Input::Shift)

        menu_use_update(4)

      else

        skill_use_update(4)

      end

    elsif Input.triggered?(Input::Numberkeys[5]) and $game_system.skill_limit >= 6

      if Input.pressed?(Input::Shift)

        menu_use_update(5)

      else

        skill_use_update(5)

      end

    elsif Input.triggered?(Input::Numberkeys[6]) and $game_system.skill_limit >= 6

      if Input.pressed?(Input::Shift)

        menu_use_update(6)

      else

        skill_use_update(6)

      end

    elsif Input.triggered?(Input::Numberkeys[7]) and $game_system.skill_limit == 8

      if Input.pressed?(Input::Shift)

        menu_use_update(7)

      else

        skill_use_update(7)

      end

    elsif Input.triggered?(Input::Numberkeys[8]) and $game_system.skill_limit == 8

      if Input.pressed?(Input::Shift)

        menu_use_update(8)

      else

        skill_use_update(8)

      end

    end

    

    # Turn off mouse follow if your weapon is set to be a non-follower

    if $game_party.actors[0].weapon_id != 0 and $data_weapons[$game_party.actors[0].weapon_id].mouse_face == true and $game_player.follow_mouse != $data_weapons[$game_party.actors[0].weapon_id].mouse_face

      $game_player.follow_mouse = true

    else

      $game_player.follow_mouse = false

    end

    

    # Left Clicky!

    if (Input.pressed?(Input::Mouse_Left) or Input.pressed?(Input::Ctrl)) and @update_interface <= 0

      mouse_left_click

    elsif @update_interface > 0

      @update_interface -= 1

    end

    

    # Right Clicky!

    if Input.triggered?(Input::Tab)

      if @command_window != nil

        @command_window.increase_index

      end

    end

    

    # Right Clicky!

    if Input.pressed?(Input::Mouse_Right)

      mouse_right_click

    end

    

    # Check all events to see if they have an attack!

    for event in $game_map.events.values

      attack = event.get_attack

      if attack != false

        @attacks.push(attack)

      end

    end

    # PERFORM ATTACKS!

    perform_attacks

    # Remove all attacks that were compelted

    @attacks.delete(nil)

    # Reduce all attack counters greater than zero

    for i in [email=0...@attacks.size]0...@attacks.size[/email]

      if @attacks[i][0] > 0

        @attacks[i][0] -= 1

      end

    end

    

    # If player is not moving

    unless $game_player.moving?

      # Run calling of each screen

      if $game_temp.battle_calling

        call_battle

      elsif $game_temp.shop_calling

        call_shop

      elsif $game_temp.name_calling

        call_name

      elsif $game_temp.menu_calling

        call_menu

      elsif $game_temp.save_calling

        call_save

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Force a switch of characters

  #--------------------------------------------------------------------------

  def force_player_switch

    @char_switch_timer = 1

    @skill_target = false

    @skill_index = -1

    @spriteset.cursor.lock = false

    @spriteset.cursor.set_icon(nil)

  end

  #--------------------------------------------------------------------------

  # * Do actions that are related to the left click

  #--------------------------------------------------------------------------

  def menu_use_update(input_key)

    data = []

    weapon_set = $data_classes[$game_party.actors[0].class_id].weapon_set

    for i in 1...$data_weapons.size

      if $game_party.weapon_number(i) > 0 and weapon_set.include?(i) and $data_weapons[i].group_id == input_key

        data.push($data_weapons[i])

      end

    end

    if data.size > 0

      @command_window.dispose

      @command_window = Window_PopCommand.new(200,data)

      @command_window.visible = true

      @command_window.active = true

    end

  end

  #--------------------------------------------------------------------------

  # * Do actions that are related to the left click

  #--------------------------------------------------------------------------

  def skill_use_update(input_key)

    if @skill_target and @skill_index == (input_key - 1)

      @skill_target = false

      @skill_index = -1

      @spriteset.cursor.lock = false

      @spriteset.cursor.set_icon(nil)

    elsif $game_party.actors[0].skill_id[(input_key - 1)] > 0

      @skill_target = true

      @spriteset.cursor.lock = false

      @skill_index = (input_key - 1)

      @spriteset.cursor.set_icon($data_skills[$game_party.actors[0].skill_id[@skill_index]].cursor)

      @spriteset.cursor.lock = true

    end

  end

  #--------------------------------------------------------------------------

  # * Do actions that are related to the right click

  #--------------------------------------------------------------------------

  def mouse_right_click

    if @command_window != nil

      # Update the Command Window

      @command_window.visible = false

      @command_window.active = false

    end

    if @skill_target

      @skill_target = false

      @skill_index = -1

      @spriteset.cursor.lock = false

      @spriteset.cursor.set_icon(nil)

    end #If then else

  end

  #--------------------------------------------------------------------------

  # * Do actions that are related to the left click

  #--------------------------------------------------------------------------

  def mouse_left_click

    # If Mouse POS not nil

    pos = Mouse.pos

    if pos != nil

      x = pos[0]

      y = pos[1]

      result = false

      target = nil

      # If Command Window is active, try to update it

      if @command_window.active

        # Update the Command Window

        @command_window.update

        @command_window.active = false

        @command_window.visible = false

        weapon = @command_window.get_data

        if weapon != nil

          $game_party.actors[0].equip(0, weapon.id)

        end

        @update_interface = 10

      else

        # Set activated to false, but change it if you run at least one event

        activated = false

        x2 = x / 32

        y2 = y / 32

        if $game_map.display_x != 0

          x2 += ($game_map.display_x / 4) / 32

        end

        if $game_map.display_y != 0

          y2 += ($game_map.display_y / 4) / 32

        end

        if not @skill_target

          if $game_system.DEFAULT_SKILL_EVENT != nil

            used_skill = $data_skills[$game_system.DEFAULT_SKILL_EVENT]

            if used_skill.iid != nil

              activated = activate_event_processing(x, y, used_skill)

              if activated

                @update_interface = 10

              end

            end

          else

            activated = activate_event(x, y)

            if activated

              @update_interface = 10

            end

          end

        end

        # If not activated, try an attack

        if @skill_target and $game_player.can_act? and not activated

          used_skill = $data_skills[$game_party.actors[0].skill_id[@skill_index]]

          if used_skill.iid != nil

            activated = activate_event_processing(x, y, used_skill)

            if activated

              @update_interface = 10

            end

          else

            create_skill_attack(x,y)

          end

        elsif $game_player.can_act? and not activated

          create_weapon_attack(x,y)

        end

      end #End Command Window versus Attack check

    end # End POS != nil statement

  end

  #--------------------------------------------------------------------------

  # * Use a skill to activate an event

  #--------------------------------------------------------------------------

  def activate_event_processing(x, y, skill)

    meet_item_reqs = false

    if skill.required_item != nil

      if $game_party.item_number(skill.required_item[0]) >= 1 and $game_party.item_number(skill.required_item[0]) >= skill.required_item[1]

        meet_item_reqs = true

      end

    else

      meet_item_reqs = true

    end

    event_run = false

    active_event = @spriteset.get_affected_event(@x_mouse, @y_mouse)

    if active_event > 0 and active_event < 10000

      event = $game_map.events[active_event]

      range = get_object_range($game_player, event)

      run_it = part_of_event_system(event)

      # Check if it has a cursor set, if not ignore it

      if run_it != false and run_it >= range

        if event.list != nil

          for item in event.list

            if item.code == 108 and item.parameters[0] == "SKILL" and meet_item_reqs

              $game_variables[$game_system.SKILL_EVENT_USE_VAR] = skill.action_id

              if skill.required_item != nil

                $game_party.lose_item(skill.required_item[0],skill.required_item[1])

                if $game_party.item_number(skill.required_item[0]) <= 0

                  for i in 0...$game_party.actors.size

                    if $game_party.actors[i].item_id == skill.required_item[0]

                      $game_party.actors[i].item_id = nil

                    end

                  end

                end

              end

              event.update

              event.refresh

              event.start

              event_run = true

            end

          end

        end

        if not event_run and run_it != false and run_it >= range

          event.update

          event.refresh

          event.start

          event_run = true

        end

      end #End the "run_it" check

    elsif active_event >= 10000

      event = $game_map.player_characters[(active_event - 10000)].map_event

      if event != nil

        event_run = true

        range = get_range($game_player.x, $game_player.y, $game_map.player_characters[(active_event - 10000)].x, $game_map.player_characters[(active_event - 10000)].y)

        run_it = part_of_event_system(event)

        # Check if it has a cursor set, if not ignore it

        if run_it != false and run_it >= range

          if event.list != nil

            for item in event.list

              if item.code == 108 and item.parameters[0] == "SKILL" and meet_item_reqs

                $game_variables[$game_system.SKILL_EVENT_USE_VAR] = skill.action_id

                if skill.required_item != nil

                  $game_party.lose_item(skill.required_item[0],skill.required_item[1])

                  if $game_party.item_number(skill.required_item[0]) <= 0

                    for i in 0...$game_party.actors.size

                      if $game_party.actors[i].item_id == skill.required_item[0]

                        $game_party.actors[i].item_id = nil

                      end

                    end

                  end

                end

                event.update

                event.refresh

                event.start

              end

            end

          end

        end

        if not event_run and run_it != false and run_it >= range

          event.update

          event.refresh

          event.start

        end

      end #End the "run_it" check

    else

      # Go through the list of events and see if any match

      x = x / 32

      y = y / 32

      if $game_map.display_x != 0

        x += ($game_map.display_x / 4) / 32

      end

      if $game_map.display_y != 0

        y += ($game_map.display_y / 4) / 32

      end

      for event in $game_map.events.values

        # If the mouse's x and y are identical to an events...

        if event.x == x and event.y == y and (event.character_name == "" and event.tile_id <= 0)

          event_run = true

          range = get_object_range($game_player, event)

          run_it = part_of_event_system(event)

          # Check if it has a cursor set, if not ignore it

          if run_it != false and run_it >= range and 

            if event.list != nil

              for item in event.list

                if item.code == 108 and item.parameters[0] == "SKILL" and meet_item_reqs

                  $game_variables[$game_system.SKILL_EVENT_USE_VAR] = skill.action_id

                  if skill.required_item != nil

                    $game_party.lose_item(skill.required_item[0],skill.required_item[1])

                    if $game_party.item_number(skill.required_item[0]) <= 0

                      for i in 0...$game_party.actors.size

                        if $game_party.actors[i].item_id == skill.required_item[0]

                          $game_party.actors[i].item_id = nil

                        end

                      end

                    end

                  end

                  event.update

                  event.refresh

                  event.start

                end

              end

            end

            if not event_run and run_it != false and run_it >= range

              event.update

              event.refresh

              event.start

            end

          end #End the "run_it" check

        end #End the event check for the x/y coordinates

      end #end the for loop

    end

    return event_run

  end

  #--------------------------------------------------------------------------

  # * Use a skill to activate an event

  #--------------------------------------------------------------------------

  def activate_event(x, y)

    event_run = false

    active_event = @spriteset.get_affected_event(@x_mouse, @y_mouse)

    if active_event > 0 and active_event < 10000

      event = $game_map.events[active_event]

      range = get_object_range($game_player, event)

      run_it = part_of_event_system(event)

      # Check if it has a cursor set, if not ignore it

      if run_it != false and run_it >= range

        event.update

        event.refresh

        event.start

        event_run = true

      elsif run_it != false

        event_run = true

      end #End the "run_it" check

    elsif active_event >= 10000

      event = $game_map.player_characters[(active_event - 10000)].map_event

      if event != nil

        range = get_range($game_player.x, $game_player.y, $game_map.player_characters[(active_event - 10000)].x, $game_map.player_characters[(active_event - 10000)].y)

        run_it = part_of_event_system(event)

        # Check if it has a cursor set, if not ignore it

        if run_it != false and run_it >= range

          event.update

          event.refresh

          event.start

          event_run = true

        elsif run_it != false

          event_run = true

        end

      end #End the "run_it" check

    else

      # Go through the list of events and see if any match

      x = x / 32

      y = y / 32

      if $game_map.display_x != 0

        x += ($game_map.display_x / 4) / 32

      end

      if $game_map.display_y != 0

        y += ($game_map.display_y / 4) / 32

      end

      for event in $game_map.events.values

        # If the mouse's x and y are identical to an events...

        if event.x == x and event.y == y and (event.character_name == "" and event.tile_id <= 0)

          range = get_object_range($game_player, event)

          run_it = part_of_event_system(event)

          # Check if it has a cursor set, if not ignore it

          if run_it != false and run_it >= range

            event.update

            event.refresh

            event.start

            event_run = true

          elsif run_it != false

            event_run = true

          end #End the "run_it" check

        end #End the event check for the x/y coordinates

      end #end the for loop

    end

    return event_run

  end

  #--------------------------------------------------------------------------

  # * Get 4 point range

  #--------------------------------------------------------------------------

  def get_range(x, y, x2, y2)

    range_x = (x.abs) - (x2.abs)

    range_y = (y.abs) - (y2.abs)

    range_x = range_x.abs

    range_y = range_y.abs

    range_x = range_x * range_x

    range_y = range_y * range_y

    range = Math.sqrt(range_x + range_y)

    return range.round

  end

  #--------------------------------------------------------------------------

  # * Push a potential weapon attack to the attack list

  #--------------------------------------------------------------------------

  def create_skill_attack(x,y)

    if $game_player.follow_mouse and not $game_player.casting? and not $game_player.moving?

      $game_player.turn_mouse

    end

    # Set up the range of X/Y coordinates to check

    if @skill_index >= 0

      used_skill = $data_skills[$game_party.actors[0].skill_id[@skill_index]]

      # Figure out the base X,Y zero point (ground zero)

      target = [x,y]

      range = get_range($game_player.screen_x, $game_player.screen_y, x, y)

      case used_skill.zeropoint

      when "enemy"

        event_id = @spriteset.get_affected_event(x, y)

        if event_id >= 1 and event_id < 10000

          target = $game_map.events[event_id]

          range = get_range($game_player.screen_x, $game_player.screen_y, target.screen_x, target.screen_y)

        elsif event_id >= 10000

          target = $game_map.player_characters[(10000 - event_id)]

          range = get_range($game_player.screen_x, $game_player.screen_y, target.screen_x, target.screen_y)

        end

      when "self"

        target = $game_player

        range = 0

        @update_interface = 5

      end

      successful = $game_player.cast(used_skill)

      if successful

        # If an attack delay, set the delay, get the coordinates, and wait

        #p [used_weapon.ddelay, zerox, zeroy, $game_party.actors[0].clone, used_skill, range, $game_player]

        $game_player.white_flash = true

        @attacks.push([used_skill.ddelay, target, $game_party.actors[0].clone, used_skill, (range / 32), $game_player.clone])

        @skill_target = false

        @skill_index = -1

        @spriteset.cursor.lock = false

        @spriteset.cursor.set_icon(nil)

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Push a potential weapon attack to the attack list

  #--------------------------------------------------------------------------

  def create_weapon_attack(x,y)

    if $game_player.follow_mouse and not $game_player.casting? and not $game_player.moving?

      $game_player.turn_mouse

    end

    if $game_party.actors[0].weapon_id != 0

      # Set up the range of X/Y coordinates to check

      used_weapon = $data_weapons[$game_party.actors[0].weapon_id]

      # Figure out the base X,Y zero point (ground zero)

      target = [x,y]

      range = get_range($game_player.screen_x, $game_player.screen_y, x, y)

      case used_weapon.zeropoint

      when "enemy"

        event_id = @spriteset.get_affected_event(x, y)

        if event_id >= 1

          target = $game_map.events[event_id]

          range = get_range($game_player.screen_x, $game_player.screen_y, target.screen_x, target.screen_y)

        end

      when "self"

        target = $game_player

        range = 0

      end

      successful = $game_player.acted(used_weapon)

      if successful

        # If an attack delay, set the delay, get the coordinates, and wait

        $game_player.white_flash = true

        @attacks.push([used_weapon.ddelay, target, $game_party.actors[0].clone, used_weapon, (range / 32), $game_player.clone])

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Perform all ready attacks

  #--------------------------------------------------------------------------

  def perform_attacks

    for i in [email=0...@attacks.size]0...@attacks.size[/email]

      if @attacks[i] != nil and @attacks[i][0] <= 0 and not @attacks[i][2].dead?

        if @attacks[i][3].is_a?(RPG::Weapon)

          weapon_attack(@attacks[i])

        elsif @attacks[i][3].is_a?(RPG::Skill)

          skill_attack(@attacks[i])

        end

        @attacks[i] = nil

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Weapon Attack

  #--------------------------------------------------------------------------

  def weapon_attack(attack)

    # Set the values to be used

    weapon = attack[3]

    attack_ok = true

    anim_id = weapon.animation2_id

    if attack[1].is_a?(Array)

      if attack[1][2] != nil

        attack_ok = false

        for event in $game_map.events.values

          if event.x == attack[1][0] and event.y == attack[1][1] and part_of_combat_system(event) and ((event.id == attack[5].id and weapon.hurt_self == true) or event.id != attack[5].id)

            zerox = event.x

            zeroy = event.y

            target = event

            attack_ok = true

          end

        end

        for character in $game_map.player_characters

          if character.x == attack[1][0] and character.y == attack[1][1] and not character.dead?

            zerox = character.x

            zeroy = character.y

            target = character

            attack_ok = true

          end

        end

        if $game_player.x == attack[1][0] and $game_player.y == attack[1][1]

          zerox = $game_player.x

          zeroy = $game_player.y

          target = $game_player

          attack_ok = true

        end

        if target != nil

          attack[1] = target

        else

          zerox = attack[1][0]

          zeroy = attack[1][1]

        end

      else

        zerox = attack[1][0] / 32

        zeroy = attack[1][1] / 32

      end

    else

      zerox = attack[1].x

      zeroy = attack[1].y

    end

    if attack_ok

      if not attack[1].is_a?(Game_Character)

        if $game_map.display_x != 0

          zerox += ($game_map.display_x / 4) / 32

        end

        if $game_map.display_y != 0

          zeroy += ($game_map.display_y / 4) / 32

        end

      end

      los = line_of_sight(attack[5], zerox, zeroy, weapon)

      if anim_id != 0 and (((los and weapon.ddelay <= 5) or weapon.ddelay > 5) or attack[5].is_a?(Game_Enemy))

        new_anim = Animation.new('tile',zerox,zeroy,anim_id)

        $animations.push(new_anim)

      end

      # Hit all the targets!

      hit_targets(weapon, attack[5], attack[2], attack[4], attack[1])

    end

  end

  

  #--------------------------------------------------------------------------

  # * Weapon Attack

  #--------------------------------------------------------------------------

  def skill_attack(attack)

    # Set the values to be used

    weapon = attack[3]

    attack_ok = true

    anim_id = weapon.animation2_id

    if attack[1].is_a?(Array)

      if attack[1][2] != nil

        attack_ok = false

        for event in $game_map.events.values

          if event.x == attack[1][0] and event.y == attack[1][1] and part_of_combat_system(event) and ((event.id == attack[5].id and weapon.hurt_self == true) or event.id != attack[5].id)

            zerox = event.x

            zeroy = event.y

            target = event

            attack_ok = true

          end

        end

        for character in $game_map.player_characters

          if character.x == attack[1][0] and character.y == attack[1][1] and not character.dead?

            zerox = character.x

            zeroy = character.y

            target = character

            attack_ok = true

          end

        end

        if $game_player.x == attack[1][0] and $game_player.y == attack[1][1]

          zerox = $game_player.x

          zeroy = $game_player.y

          target = $game_player

          attack_ok = true

        end

        if target != nil

          attack[1] = target

        else

          zerox = attack[1][0]

          zeroy = attack[1][1]

        end

      else

        zerox = attack[1][0] / 32

        zeroy = attack[1][1] / 32

      end

    else

      zerox = attack[1].x

      zeroy = attack[1].y

    end

    if attack_ok

      if not attack[1].is_a?(Game_Character)

        if $game_map.display_x != 0

          zerox += ($game_map.display_x / 4) / 32

        end

        if $game_map.display_y != 0

          zeroy += ($game_map.display_y / 4) / 32

        end

      end

      los = line_of_sight(attack[5], zerox, zeroy, weapon)

      if anim_id != 0 and (((los and weapon.ddelay <= 5) or weapon.ddelay > 5) or attack[5].is_a?(Game_Enemy))

        new_anim = Animation.new('tile',zerox,zeroy,anim_id)

        $animations.push(new_anim)

      end

      # Hit all the targets!

      hit_targets(weapon, attack[5], attack[2], attack[4], attack[1])

    end

  end

  #--------------------------------------------------------------------------

  # * Hit all Targets of an Attack

  #--------------------------------------------------------------------------

  def hit_targets(attack, user, user_actor, range_at_use, target)

    # Set the line of sight to false

    los = false

    # First get the target if someone was hit directly

    if target.is_a?(Array)

      direct_target = @spriteset.get_affected_event(target[0], target[1])

    else

      direct_target = target

    end

    # If someone was hit "directly" check Line of Sight to be sure

    if direct_target.is_a?(Game_Character)

      the_target = direct_target

      los = the_target.line_of_sight(user, attack)

    elsif direct_target > 0 and direct_target < 10000 and (direct_target != user.id or attack.hurt_self == true)

      the_target = $game_map.events[direct_target]

      los = the_target.line_of_sight(user, attack)

    elsif direct_target > 0 and direct_target > 10000 and (direct_target != user.id or attack.hurt_self == true)

      the_target = $game_map.player_characters[(10000 - direct_target)]

      los = the_target.line_of_sight(user, attack)

    elsif direct_target == 0  and (direct_target != user.id or attack.hurt_self == true)

      the_target = $game_player

      los = the_target.line_of_sight(user, attack)

    end

    # If the Line of Sight is true (attacker can see the target)

    remove_target = nil

    this_target_damage = false

    if los

      # If it's a game player, do one thing, otherwise do something else

      if the_target.is_a?(Game_Player) and not the_target.dead?

        if attack.is_a?(RPG::Weapon)

          this_target_damage = $game_party.actors[0].attack_effect(user_actor, attack, range_at_use)

        elsif attack.is_a?(RPG::Skill)

          this_target_damage = $game_party.actors[0].skill_effect(user_actor, attack, range_at_use)

        end

        the_target.turn(user_actor)

        if this_target_damage

          set_char_move(attack, the_target, user)

        end

      elsif the_target.is_a?(Game_Event)

        # Get whether it's attackable, runnable, or both!

        attack_it = part_of_combat_system(the_target)

        # If it's in the combat system, try to damage it

        if attack_it and not the_target.dead?

          if attack.is_a?(RPG::Weapon)

            this_target_damage = the_target.battler.attack_effect(user_actor, attack, range_at_use)

          elsif attack.is_a?(RPG::Skill)

            this_target_damage = the_target.battler.skill_effect(user_actor, attack, range_at_use)

          end          

          the_target.turn(user_actor)

          if this_target_damage

            set_char_move(attack, the_target, user)

          end

          remove_target = the_target.id

        end

      elsif the_target.id >= 10000

        if not the_target.dead?

          if attack.is_a?(RPG::Weapon)

            this_target_damage = $game_party.actors[the_target.actor_id].attack_effect(user_actor, attack, range_at_use)

          elsif attack.is_a?(RPG::Skill)

            this_target_damage = $game_party.actors[the_target.actor_id].skill_effect(user_actor, attack, range_at_use)

          end

          the_target.turn(user_actor)

          if this_target_damage

            set_char_move(attack, the_target, user)

          end

        end

      end #End the Player or Event? If

    end #End the if LOS if

    # -----------------------------------------------

    # Now go through and attack and every possible target

    #------------------------------------------------

    # If the target is a character, get the screen position for the AoE effect

    if target.is_a?(Game_Character)

      target = [(target.screen_x + 16), (target.screen_y - 16)]

    end

    # Get an array of all possible targets for the attack spread attack (spread is in pixels!)

    targets = @spriteset.get_included_events(target[0], target[1], attack.spread)

    # Remove the user if the weapon isn't a Hurt_Self type

    if remove_target != nil

      targets.delete(remove_target)

    end

    targets.delete(the_target.id)

    if attack.hurt_self != true

      targets.delete(user.id)

    end

    # Declare the variable to hold our punishment so far

    punished = 0

    # Now go through all the targets and hurt them if necessary

    for target in targets

      if attack.multihit != nil and punished < attack.multihit

        this_target_damage = false

        if target == 0

          if attack.is_a?(RPG::Weapon)

            this_target_damage = $game_party.actors[0].attack_effect(user_actor, attack, range_at_use)

          elsif attack.is_a?(RPG::Skill)

            this_target_damage = $game_party.actors[0].skill_effect(user_actor, attack, range_at_use)

          end

          $game_player.turn(user_actor)

          if this_target_damage

            set_char_move(attack, $game_player, user)

          end

          punished += 1

        elsif target > 0 and target < 10000

          a_target = $game_map.events[target]

          attack_it = part_of_combat_system(a_target)

          if attack_it and not a_target.dead?

            if attack.is_a?(RPG::Weapon)

              this_target_damage = a_target.battler.attack_effect(user_actor, attack, range_at_use)

            elsif attack.is_a?(RPG::Skill)

              this_target_damage = a_target.battler.skill_effect(user_actor, attack, range_at_use)

            end

            a_target.turn(user_actor)

            if this_target_damage

              set_char_move(attack, a_target, user)

            end

            punished += 1

          end

        elsif a_target.id >= 10000

          if not the_target.dead?

            if attack.is_a?(RPG::Weapon)

              this_target_damage = $game_party.actors[the_target.actor_id].attack_effect(user_actor, attack, range_at_use)

            elsif attack.is_a?(RPG::Skill)

              this_target_damage = $game_party.actors[the_target.actor_id].skill_effect(user_actor, attack, range_at_use)

            end

            a_target.turn(user_actor)

            if this_target_damage

              set_char_move(attack, a_target, user)

            end

            punished += 1

          end

        end # End if player or event

      end

    end

  end # End hit_targets

  #--------------------------------------------------------------------------

  # * Update Mouse position and cursor

  #--------------------------------------------------------------------------

  def mouse_interface_update

    pos = Mouse.pos

    if pos != nil and (pos[0] != @x_mouse or pos[1] != @y_mouse)

      if pos != nil

        #if $game_player.follow_mouse and not $game_player.casting? and not $game_player.moving?

        #  $game_player.turn_mouse

        #end

        @x_mouse = pos[0]

        @y_mouse = pos[1]

        x = pos[0] / 32

        y = pos[1] / 32

        if $game_map.display_x != 0

          x += ($game_map.display_x / 4) / 32

        end

        if $game_map.display_y != 0

          y += ($game_map.display_y / 4) / 32

        end

        hover_over = @spriteset.get_affected_event(@x_mouse, @y_mouse)

        set_icon = false

        if hover_over > 0 and hover_over < 10000

          event = $game_map.events[hover_over]

          if event.list != nil

            for item in event.list

              if item.code == 108 and item.parameters[0].include?("CURSOR=")

                id = item.parameters[0].split('=')

                @spriteset.cursor.set_icon(id[1])

                set_icon = true

              end

            end

          end

        elsif hover_over >= 10000

          event = $game_map.player_characters[(hover_over-10000)].map_event

          if event != nil and event.list != nil

            for item in event.list

              if item.code == 108 and item.parameters[0].include?("CURSOR=")

                id = item.parameters[0].split('=')

                @spriteset.cursor.set_icon(id[1])

                set_icon = true

              end

            end

          end

        else

          # Go through the list of events and see if any match

          for event in $game_map.events.values

            # If the mouse's x and y are identical to an events...

            if event.x == x and event.y == y and (event.character_name == "" and event.tile_id <= 0)

              # Check if it has a cursor set, if not ignore it

              if event.list != nil

                for item in event.list

                  if item.code == 108 and item.parameters[0].include?("CURSOR=")

                    id = item.parameters[0].split('=')

                    @spriteset.cursor.set_icon(id[1])

                    set_icon = true

                  end

                end

              end

            end

          end

        end

        if not set_icon and @spriteset.cursor.icon != nil

          @spriteset.cursor.set_icon(nil)

        end

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Switches the player

  #--------------------------------------------------------------------------

  def switch_active_player

    for i in 0...$game_party.actors.size

      $game_party.actors[0].map_location[0] = $game_map.map_id

      $game_party.actors[0].map_location[1] = $game_player.x

      $game_party.actors[0].map_location[2] = $game_player.y

      temp = $game_party.actors.shift

      $game_party.actors.push(temp)

      $game_temp.player_new_map_id = $game_party.actors[0].map_location[0]

      $game_temp.player_new_x = $game_party.actors[0].map_location[1]

      $game_temp.player_new_y = $game_party.actors[0].map_location[2]

      if $game_map.map_id != $game_party.actors[0].map_location[0]

        @attacks = []

      end

      if $game_party.actors[0] != nil and not $game_party.actors[0].dead? and $game_party.actors[0].map_location[0] != 0

        $game_map.switch_transfer = true

        $game_temp.player_transferring = true

        $game_temp.player_new_direction = 2

        Audio.se_play("Audio/SE/013-Move01", 80, 100)

        $game_map.need_refresh = true

        $game_player.update

        $game_player.refresh

        $game_map.reset_players

        $game_map.load_update

        @huds.set_default_actors

        @huds.update

        $game_switches[$game_system.MAP_INIT_COMPLETE_SWITCH] = false

        break

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Line of Sight Function

  #--------------------------------------------------------------------------

  def line_of_sight(source, weapon)

    if weapon != nil

      sx = source.x

      sy = source.y

      tx = @x

      ty = @y

      x_diff = (sx.abs) - (tx.abs)

      y_diff = (sy.abs) - (ty.abs)

      x_diff = x_diff.abs

      y_diff = y_diff.abs

      if sx > tx

        # -X, -Y

        if sy > ty

          if x_diff > y_diff

            direction = 4

          else

            direction = 8

          end

          # -X, +Y

        else

          if x_diff > y_diff

            direction = 4

          else

            direction = 2

          end

        end

      else

        # +X, -Y

        if sy > ty

          if x_diff > y_diff

            direction = 6

          else

            direction = 8

          end

          # +X, +Y

        else

          if x_diff > y_diff

            direction = 6

          else

            direction = 2

          end

        end

      end

      return rec_los(sx, sy, tx, ty, weapon)

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Line of Sight Function

  #--------------------------------------------------------------------------

  def line_of_sight(source, x, y, weapon)

    sx = source.x

    sy = source.y

    tx = x

    ty = y

    x_diff = (sx.abs) - (tx.abs)

    y_diff = (sy.abs) - (ty.abs)

    x_diff = x_diff.abs

    y_diff = y_diff.abs

    if sx > tx

      # -X, -Y

      if sy > ty

        if x_diff > y_diff

          direction = 4

        else

          direction = 8

        end

        # -X, +Y

      else

        if x_diff > y_diff

          direction = 4

        else

          direction = 2

        end

      end

    else

      # +X, -Y

      if sy > ty

        if x_diff > y_diff

          direction = 6

        else

          direction = 8

        end

        # +X, +Y

      else

        if x_diff > y_diff

          direction = 6

        else

          direction = 2

        end

      end

    end

    return rec_los(sx, sy, tx, ty, weapon)

  end

  #--------------------------------------------------------------------------

  # * Calculate Operated Value

  #     x    : X-coordinates

  #     y    : Y-coordinates

  #     tx   : Target X-coordinates, where you want to be

  #     ty   : Target Y-coordinates, where you want to be

  #     dir  : Which direction to finish in before moving on, 0 = x, 1 = y

  #--------------------------------------------------------------------------

  def rec_los(x, y, tx, ty, weapon)

    # For X direction

    if x != tx

      if x < tx

        x += 1

      else

        x -= 1

      end

    end

    # For Y direction

    if y != ty

      if y < ty

        y += 1

      else

        y -= 1

      end

    end

    if $game_map.terrain_tag(x,y) >= weapon.piercing

      return false

    end

    if x == tx and y == ty

      return true

    else

      return rec_los(x, y, tx, ty, weapon)

    end

  end

  # End of rec_los

  #--------------------------------------------------------------------------

  # * Get Range from Point1 to Point2

  #--------------------------------------------------------------------------

  def get_object_range(point1, point2)

    range_x = (point1.x.abs) - (point2.x.abs)

    range_y = (point1.y.abs) - (point2.y.abs)

    range_x = range_x.abs

    range_y = range_y.abs

    range_x = range_x * range_x

    range_y = range_y * range_y

    range = Math.sqrt(range_x + range_y)

    range = range.round

    return range

  end

  #--------------------------------------------------------------------------

  # * Part of Combat System

  #--------------------------------------------------------------------------

  def part_of_combat_system(event)

    if event.is_a?(Game_Event)

      if event.list != nil

        for item in event.list

          if item.code == 108 and item.parameters[0] == "ACTION"

            return true

          end

        end

      end

    elsif event.is_a?(Game_Player)

      return true

    elsif event.actor_id != nil

      return true

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Part of Combat System

  #--------------------------------------------------------------------------

  def part_of_event_system(event)

    if event.is_a?(Game_Event)

      if event.list != nil

        for item in event.list

          if item.code == 108 and item.parameters[0].include?("RUN=")

            id = item.parameters[0].split('=')

            return (id[1].to_i)

          end

        end

      end

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Set Character Moves based on weapon

  #--------------------------------------------------------------------------

  def set_char_move(weapon, target, user)

    # Set the move mods

    if weapon.target_move != nil

      target.set_move_sf(weapon.target_move[0], weapon.target_move[1], weapon.target_move[2], weapon.target_move[3])

    end

    if weapon.user_move != nil

      if user.is_a?(Game_Event)

        $game_map.events[user.id].set_move_sf(weapon.user_move[0], weapon.user_move[1], weapon.user_move[2], weapon.target_move[3])

      elsif user.is_a?(Game_Player)

        $game_player.set_move_sf(weapon.user_move[0], weapon.user_move[1], weapon.user_move[2], weapon.target_move[3])

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Perform Kickback

  #--------------------------------------------------------------------------

  def perform_kickback(weapon, target)

    #Knock and Kickback functions

    if weapon.kickback != nil

      for j in 0...weapon.kickback[0]

        if target.is_a?(Game_Event)

          #$game_map.events[target.id].move_route = nil

          $game_map.events[target.id].move_backward

        elsif target.is_a?(Game_Player)

          #$game_player.move_route = nil

          $game_player.move_backward

        end

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Perform Knockback

  #--------------------------------------------------------------------------

  def perform_knockback(weapon, target, user)

    if weapon.knockback != nil

      target.direction_fix = true

      for j in 0...weapon.knockback[0]

        #target.move_route = nil

        target.move_away_from_target(user)

      end

      target.direction_fix = false

    end #End the Knock/Kick back functions

  end

  #--------------------------------------------------------------------------

  # * Battle Call

  #--------------------------------------------------------------------------

  def call_battle

    # Clear battle calling flag

    $game_temp.battle_calling = false

    # Clear menu calling flag

    $game_temp.menu_calling = false

    $game_temp.menu_beep = false

    # Make encounter count

    $game_player.make_encounter_count

    # Memorize map BGM and stop BGM

    $game_temp.map_bgm = $game_system.playing_bgm

    $game_system.bgm_stop

    # Play battle start SE

    $game_system.se_play($data_system.battle_start_se)

    # Play battle BGM

    $game_system.bgm_play($game_system.battle_bgm)

    # Straighten player position

    $game_player.straighten

    # Switch to battle screen

    $scene = Scene_Battle.new

  end

  #--------------------------------------------------------------------------

  # * Shop Call

  #--------------------------------------------------------------------------

  def call_shop

    # Clear shop call flag

    $game_temp.shop_calling = false

    # Straighten player position

    $game_player.straighten

    # Switch to shop screen

    $scene = Scene_Shop.new

  end

  #--------------------------------------------------------------------------

  # * Name Input Call

  #--------------------------------------------------------------------------

  def call_name

    # Clear name input call flag

    $game_temp.name_calling = false

    # Straighten player position

    $game_player.straighten

    # Switch to name input screen

    $scene = Scene_Name.new

  end

  #--------------------------------------------------------------------------

  # * Menu Call

  #--------------------------------------------------------------------------

  def call_menu

    # Clear menu call flag

    $game_temp.menu_calling = false

    # If menu beep flag is set

    if $game_temp.menu_beep

      # Play decision SE

      $game_system.se_play($data_system.decision_se)

      # Clear menu beep flag

      $game_temp.menu_beep = false

    end

    # Straighten player position

    $game_player.straighten

    # Switch to menu screen

    $scene = Scene_Menu.new

  end

  #--------------------------------------------------------------------------

  # * Save Call

  #--------------------------------------------------------------------------

  def call_save

    # Straighten player position

    $game_player.straighten

    # Switch to save screen

    $scene = Scene_Save.new

  end

  #--------------------------------------------------------------------------

  # * Debug Call

  #--------------------------------------------------------------------------

  def call_debug

    # Clear debug call flag

    $game_temp.debug_calling = false

    # Play decision SE

    $game_system.se_play($data_system.decision_se)

    # Straighten player position

    $game_player.straighten

    # Switch to debug screen

    $scene = Scene_Debug.new

  end

  #--------------------------------------------------------------------------

  # * Player Place Move

  #--------------------------------------------------------------------------

  def transfer_player

    for event in $game_map.events.values

      remembered = false

      if event.list != nil

        for item in event.list

          if item.code == 108 and item.parameters[0] == "REMEMBER"

            key = $game_map.map_id.to_s + "+" + event.id.to_s

            $game_event_locations[key] = [event.x, event.y]

            remembered = true

          end

        end

      end

    end

    # Clear player place move call flag

    $game_temp.player_transferring = false

    # If move destination is different than current map

    if $game_map.map_id != $game_temp.player_new_map_id

      # Set up a new map

      $game_map.setup($game_temp.player_new_map_id)

    end

    # Set up player position

    $game_player.moveto($game_temp.player_new_x, $game_temp.player_new_y)

    # Set player direction

    case $game_temp.player_new_direction

    when 2  # down

      $game_player.turn_down

    when 4  # left

      $game_player.turn_left

    when 6  # right

      $game_player.turn_right

    when 8  # up

      $game_player.turn_up

    end

    # Straighten player position

    $game_player.straighten

    # Update map (run parallel process event)

    $game_map.update

    # Remake sprite set

    @spriteset.dispose

    @spriteset = Spriteset_Map.new

    # If processing transition

    if $game_temp.transition_processing

      # Clear transition processing flag

      $game_temp.transition_processing = false

      # Execute transition

      Graphics.transition(20)

    end

    # Run automatic change for BGM and BGS set on the map

    $game_map.autoplay

    # Set the map flag on as defined in game custom

    # Frame reset

    Graphics.frame_reset

    # Update input information

    Input.update

  end

end

#End Scene_Map

 

#==============================================================================

# ** Window_Selectable

#------------------------------------------------------------------------------

#  This window class contains cursor movement and scroll functions.

#==============================================================================

 

class Window_MouseSelectable < Window_Base

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_reader   :index                    # cursor position

  attr_reader   :help_window              # help window

  #--------------------------------------------------------------------------

  # * Object Initialization

  #     x      : window x-coordinate

  #     y      : window y-coordinate

  #     width  : window width

  #     height : window height

  #--------------------------------------------------------------------------

  def initialize(x, y, width, height)

    super(x, y, width, height)

    @item_max = 1

    @column_max = 1

    @index = -1

  end

  #--------------------------------------------------------------------------

  # * Set Cursor Position

  #     index : new cursor position

  #--------------------------------------------------------------------------

  def index=(index)

    @index = index

    # Update Help Text (update_help is defined by the subclasses)

    if self.active and @help_window != nil

      update_help

    end

    # Update cursor rectangle

    update_cursor_rect

  end

  #--------------------------------------------------------------------------

  # * Get Row Count

  #--------------------------------------------------------------------------

  def row_max

    # Compute rows from number of items and columns

    return (@item_max + @column_max - 1) / @column_max

  end

  #--------------------------------------------------------------------------

  # * Get Top Row

  #--------------------------------------------------------------------------

  def top_row

    # Divide y-coordinate of window contents transfer origin by 1 row

    # height of 32

    return self.oy / 32

  end

  #--------------------------------------------------------------------------

  # * Set Top Row

  #     row : row shown on top

  #--------------------------------------------------------------------------

  def top_row=(row)

    # If row is less than 0, change it to 0

    if row < 0

      row = 0

    end

    # If row exceeds row_max - 1, change it to row_max - 1

    if row > row_max - 1

      row = row_max - 1

    end

    # Multiply 1 row height by 32 for y-coordinate of window contents

    # transfer origin

    self.oy = row * 32

  end

  #--------------------------------------------------------------------------

  # * Get Number of Rows Displayable on 1 Page

  #--------------------------------------------------------------------------

  def page_row_max

    # Subtract a frame height of 32 from the window height, and divide it by

    # 1 row height of 32

    return (self.height - 32) / 32

  end

  #--------------------------------------------------------------------------

  # * Get Number of Items Displayable on 1 Page

  #--------------------------------------------------------------------------

  def page_item_max

    # Multiply row count (page_row_max) times column count (@column_max)

    return page_row_max * @column_max

  end

  #--------------------------------------------------------------------------

  # * Set Help Window

  #     help_window : new help window

  #--------------------------------------------------------------------------

  def help_window=(help_window)

    @help_window = help_window

    # Update help text (update_help is defined by the subclasses)

    if self.active and @help_window != nil

      update_help

    end

  end

  #--------------------------------------------------------------------------

  # * Update Cursor Rectangle

  #--------------------------------------------------------------------------

  def update_cursor_rect

    # If cursor position is less than 0

    if @index < 0

      self.cursor_rect.empty

      return

    end

    # Get current row

    row = @index / @column_max

    # If current row is before top row

    if row < self.top_row

      # Scroll so that current row becomes top row

      self.top_row = row

    end

    # If current row is more to back than back row

    if row > self.top_row + (self.page_row_max - 1)

      # Scroll so that current row becomes back row

      self.top_row = row - (self.page_row_max - 1)

    end

    # Calculate cursor width

    cursor_width = self.width / @column_max - 32

    # Calculate cursor coordinates

    x = @index % @column_max * (cursor_width + 32)

    y = @index / @column_max * 32 - self.oy

    # Update cursor rectangle

    self.cursor_rect.set(x, y, cursor_width, 32)

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    super

    # If cursor is movable

    if self.active and @item_max > 0 and @index >= 0

      # If pressing down on the directional buttons

      pos = Mouse.pos

      if pos != nil

        relative_x = pos[0] - x

        relative_y = pos[1] - y

        if relative_x > 0 and relative_x < width and relative_y > 0 and relative_y < height

          @index = (relative_y-16) / 32

          if @index >= @commands.size

            @index = @commands.size-1

          elsif @index < 0

            @index = 0

          end

        end

      end

    end

    # Update help text (update_help is defined by the subclasses)

    if self.active and @help_window != nil

      update_help

    end

    # Update cursor rectangle

    update_cursor_rect

  end

end

 

#==============================================================================

# ** Window_Command

#------------------------------------------------------------------------------

#  This window deals with general command choices.

#==============================================================================

 

class Window_PopCommand < Window_MouseSelectable

  #--------------------------------------------------------------------------

  # * Object Initialization

  #     width    : window width

  #     commands : command text string array

  #--------------------------------------------------------------------------

  def initialize(width, commands)

    # Compute window height from command quantity

    super(440, 0, width, commands.size * 32 + 32)

    @commands = commands

    @item_max = commands.size

    if @item_max >= 1

      self.contents = Bitmap.new(width - 32, @item_max * 32)

    else

      return false

    end

    refresh

    self.index = 0

  end

  #--------------------------------------------------------------------------

  # * Return data

  #--------------------------------------------------------------------------

  def get_data

    return @commands[@index]

  end

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def refresh

    self.contents.clear

    for i in 0...@item_max

      draw_item(i, normal_color)

    end

  end

  #--------------------------------------------------------------------------

  # * Increases index or brings it back to front if next one is too much

  #--------------------------------------------------------------------------

  def increase_index

    @index += 1

    if @index % @commands.size == 0

      @index = 0

    end

  end

  #--------------------------------------------------------------------------

  # * Draw Item

  #     index : item number

  #     color : text color

  #--------------------------------------------------------------------------

  def draw_item(index, color)

    if @commands[index] != nil

      self.contents.font.color = color

      rect = Rect.new(32, 32 * index, self.contents.width - 8, 32)

      self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))

      item = @commands[index].name

      weapon_icon = RPG::Cache.icon(@commands[index].icon_name)

      self.contents.blt(4, (32 * index)+4, weapon_icon, Rect.new(0, 0, 24, 24))

      self.contents.draw_text(rect, item)

    end

  end

  #--------------------------------------------------------------------------

  # * Disable Item

  #     index : item number

  #--------------------------------------------------------------------------

  def disable_item(index)

    draw_item(index, disabled_color)

  end

end

 

#==============================================================================

# ** Spriteset_Map

#------------------------------------------------------------------------------

#  This class brings together map screen sprites, tilemaps, etc.

#  It's used within the Scene_Map class.

#==============================================================================

 

class Spriteset_Map

  attr_accessor   :cursor

  attr_reader     :character_sprites

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  alias :normal_init :initialize

  def initialize

    normal_init

    for i in 0...$game_map.player_characters.size

      sprite = Sprite_Character.new(@viewport1, $game_map.player_characters[i])

      @character_sprites.push(sprite)

    end

    @cursor = Sprite_Cursor.new(@viewport3)

  end

  #--------------------------------------------------------------------------

  # * Dispose

  #--------------------------------------------------------------------------

  alias :normal_dispose :dispose

  def dispose

    if @cursor != nil

      @cursor.dispose

    end

    normal_dispose

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  alias :normal_update :update

  def update

    normal_update

    if @cursor != nil

      @cursor.update

    end

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update_party

    for i in 0...$game_map.player_characters.size

      sprite = Sprite_Character.new(@viewport1, $game_map.player_characters[i])

      if not @character_sprites.include?(sprite)

        @character_sprites.push(sprite)

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Get Event under a Click Point

  #--------------------------------------------------------------------------

  def get_affected_event(true_x, true_y)

    data = []

    for sprite in @character_sprites

      x = true_x - sprite.x

      y = true_y - sprite.y

      if sprite.tile_id == 0

        if x.abs < (sprite.cw / 2) and y.abs < sprite.ch and y < 0

          bx = (sprite.cw / 2) + x

          by = sprite.ch + y

          sx = sprite.character.pattern * sprite.cw

          sy = (sprite.character.direction - 2) / 2 * sprite.ch

          if sprite.bitmap.get_pixel((bx+sx),(by+sy)).alpha > 0.0

            data.push(sprite.character)

          end

        end

      else

        if x.abs <= 16 and y.abs <= 32 and y < 0

          bx = 16 + x

          by = 32 + y

          if sprite.bitmap.get_pixel(bx, by).alpha > 0.0

            data.push(sprite.character)

          end

        end

      end

    end

    if data.size > 1

      event = data[0]

      for i in 0...data.size

        if data[i].y > event.y

          event = data[i]

        end

      end

      return event.id

    elsif data.size > 0

      return data[0].id

    else

      return -1

    end

  end

  #--------------------------------------------------------------------------

  # * Get all Events in a Range from a Point in pixels

  #--------------------------------------------------------------------------

  def get_included_events(x, y, radius)

    data = []

    for sprite in @character_sprites

      range_x = (x.abs) - (sprite.x.abs)

      range_y = (y.abs) - (sprite.y.abs)

      range_x = range_x.abs

      range_y = range_y.abs

      range_x = range_x * range_x

      range_y = range_y * range_y

      range = Math.sqrt(range_x + range_y)

      range = range.round

      if range <= radius

        data.push(sprite.character.id)

      end

    end

    return data

  end

 

# End the Spriteset_Map

end

 

#==============================================================================

# ** Sprite_Character

#------------------------------------------------------------------------------

#  This sprite is used to display the character.It observes the Game_Character

#  class and automatically changes sprite conditions.

#==============================================================================

 

class Sprite_Character < RPG::Sprite

  attr_reader   :cw

  attr_reader   :ch

  attr_reader   :tile_id

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  alias :normal_update :update

  def update

    # White flash

    if @character.white_flash

      whiten

      @character.white_flash = false

    end

    normal_update

    if @character.casting > 0

      casting(@character.casting)

      @character.casting = 0

    elsif @character.casting == -1

      dispose_casting

      @character.casting = 0

    end

    if @character.damage.size == 2

      self.damage(@character.damage[0], @character.damage[1])

      @character.damage = []

    end

    if @character.weapon != nil and @weapon == nil

      @weapon = ::Sprite_Weapon.new(self.viewport, @character)

    elsif @character.weapon == nil and @weapon != nil

      @weapon.dispose

      @weapon = nil

    elsif @weapon != nil

      @weapon.update

    end

  end

end

 

#==============================================================================

# ** Sprite_Weapon

#------------------------------------------------------------------------------

#  This sprite is used to display the a weapon on a character.

#==============================================================================

 

class Sprite_Weapon < RPG::Sprite

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_accessor :character                # character

  attr_accessor :mode

  #--------------------------------------------------------------------------

  # * Object Initialization

  #     viewport  : viewport

  #     character : character (Game_Character)

  #--------------------------------------------------------------------------

  def initialize(viewport, character = nil)

    super(viewport)

    @character = character

    @mode = 0

    update

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    super

    # If tile ID, file name, or hue are different from current ones

    if @tile_id != @character.tile_id or

       @character_name != @character.character_name or

       @character_hue != @character.character_hue

      # Remember tile ID, file name, and hue

      @tile_id = @character.tile_id

      @character_name = @character.character_name

      @character_hue = @character.character_hue

      # If tile ID value is valid

      if @tile_id >= 384

        self.bitmap = RPG::Cache.tile($game_map.tileset_name,

          @tile_id, @character.character_hue)

        self.src_rect.set(0, 0, 32, 32)

        self.ox = 16

        self.oy = 32

      # If tile ID value is invalid

      else

        self.bitmap = RPG::Cache.character(@character.weapon,

          @character.character_hue)

        @cw = bitmap.width / 4

        @ch = bitmap.height / 8

        self.ox = @cw / 2

        self.oy = @ch

      end

    end

    # Set visible situation

    self.visible = (not @character.transparent)

    # If graphic is character

    if @tile_id == 0

      # Set rectangular transfer

      if @character.weapon_mode == 0

        sx = @character.weapon_pattern * @cw

        sy = (@character.direction - 2) / 2 * @ch

        self.src_rect.set(sx, sy, @cw, @ch)

      elsif @character.weapon_mode == 1

        sx = @character.weapon_pattern * @cw

        sy = (@character.direction - 2) / 2 * @ch + (@ch * 4)

        self.src_rect.set(sx, sy, @cw, @ch)

      end

    end

    # Set sprite coordinates

    self.x = @character.screen_x

    self.y = @character.screen_y

    self.z = @character.screen_z(@ch)

    # Set opacity level, blend method, and bush depth

    self.opacity = @character.opacity

    self.blend_type = @character.blend_type

    self.bush_depth = @character.bush_depth

    # Animation

    if @character.animation_id != 0

      animation = $data_animations[@character.animation_id]

      animation(animation, true)

      @character.animation_id = 0

    end

  end

end

 

#==============================================================================

# ** Window_Base

#------------------------------------------------------------------------------

#  This class is for all in-game windows.

#==============================================================================

 

class Window_Base < Window

  #--------------------------------------------------------------------------

  # * Draw AP

  #     actor : actor

  #     x     : draw spot x-coordinate

  #     y     : draw spot y-coordinate

  #     width : draw spot width

  #--------------------------------------------------------------------------

  def draw_actor_ap(actor, x, y, width = 144)

    # Draw "SP" text string

    self.contents.font.color = system_color

    self.contents.draw_text(x, y, 32, 32, "AP")

    # Calculate if there is draw space for MaxHP

    if width - 32 >= 108

      ap_x = x + width - 108

      flag = true

    elsif width - 32 >= 48

      ap_x = x + width - 48

      flag = false

    end

    # Draw SP

    self.contents.font.color = actor.ap == 0 ? knockout_color :

      actor.ap <= 100 / 4 ? crisis_color : normal_color

    self.contents.draw_text(ap_x, y, 48, 32, actor.ap.to_s, 2)

  end

  #--------------------------------------------------------------------------

  # * Draw AP

  #     actor : actor

  #     x     : draw spot x-coordinate

  #     y     : draw spot y-coordinate

  #     width : draw spot width

  #--------------------------------------------------------------------------

  def draw_actor_hp_bar(actor, x, y, width = 144)

    x = x+16

    y = y+16

    width = width * @actor.hp / @actor.maxhp

    color1 = Color.new(192, 255, 192, 255)

    color2 = Color.new(144, 192, 144, 255)

    color3 = Color.new(96, 128, 96, 255)

    self.contents.fill_rect(x, y, width, 1, color1)

    self.contents.fill_rect(x, y+1, width, 1, color2)

    self.contents.fill_rect(x, y+2, width, 3, color3)

  end

  #--------------------------------------------------------------------------

  # * Draw SP

  #     actor : actor

  #     x     : draw spot x-coordinate

  #     y     : draw spot y-coordinate

  #     width : draw spot width

  #--------------------------------------------------------------------------

  def draw_actor_sp_bar(actor, x, y, width = 144)

    x = x+16

    y = y+16

    width = width * @actor.sp / (@actor.maxsp * 1.0)

    color1 = Color.new(192, 192, 255, 255)

    color2 = Color.new(144, 144, 192, 255)

    color3 = Color.new(96, 96, 128, 255)

    self.contents.fill_rect(x, y, width, 1, color1)

    self.contents.fill_rect(x, y+1, width, 1, color2)

    self.contents.fill_rect(x, y+2, width, 3, color3)

  end

  #--------------------------------------------------------------------------

  # * Draw AP

  #     actor : actor

  #     x     : draw spot x-coordinate

  #     y     : draw spot y-coordinate

  #     width : draw spot width

  #--------------------------------------------------------------------------

  def draw_actor_ap_bar(actor, x, y, width = 144)

    x = x+16

    y = y+16

    width = width * @actor.ap / 100.0

    color1 = Color.new(255, 192, 255, 255)

    color2 = Color.new(192, 144, 192, 255)

    color3 = Color.new(128, 96, 128, 255)

    self.contents.fill_rect(x, y, width, 1, color1)

    self.contents.fill_rect(x, y+1, width, 1, color2)

    self.contents.fill_rect(x, y+2, width, 3, color3)

  end

end

#END Window Base

 

#==============================================================================

# ** Game_Event

#------------------------------------------------------------------------------

#  This class deals with events. It handles functions including event page 

#  switching via condition determinants, and running parallel process events.

#  It's used within the Game_Map class.

#==============================================================================

 

class Game_Event < Game_Character

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_reader   :id

  attr_accessor :sprite

  attr_accessor :battler

  attr_accessor :delay

  attr_accessor :actor

  attr_accessor :waiting

  attr_accessor :favored

  attr_accessor :ideal_attack

  attr_accessor :through

  attr_accessor :old_x

  attr_accessor :old_y

  attr_reader   :self_action

  attr_reader   :event

  #--------------------------------------------------------------------------

  # * Object Initialization

  #     map_id : map ID

  #     event  : event (RPG::Event)

  #--------------------------------------------------------------------------

  def initialize(map_id, event)

    super()

    @map_id = map_id

    @event = event

    @id = @event.id

    @erased = false

    @starting = false

    @through = true

    @battler = nil

    @delay = 0

    @actor = nil

    @self_actor = nil

    @self_delay = 0

    @self_target = nil

    @self_action = nil

    @self_range = 0

    @waiting = 0

    @favored = nil

    @ideal_attack = nil

    @action_freeze = 0

    @self_through = 0

    @old_x = 0

    @old_y = 0

    @counter = 0

    @thinking = 0

    # Move to starting position

    moveto(@event.x, @event.y)

    refresh

  end

  #--------------------------------------------------------------------------

  # * Generate Enemy

  #--------------------------------------------------------------------------

  def set_enemy(id)

    @battler = Game_Enemy.new(id, 0)

  end

  #--------------------------------------------------------------------------

  # * Generate Enemy

  #--------------------------------------------------------------------------

  def can_act?

    if @waiting <= 0

      return true

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Generate Enemy

  #--------------------------------------------------------------------------

  def stuck?

    if @move_freeze > 0

      return true

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Generate Enemy

  #--------------------------------------------------------------------------

  def dead?

    if @battler != nil and @battler.hp <= 0

      return true

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Generate Enemy

  #--------------------------------------------------------------------------

  def set_attack(delay, battler, target, wait, action, range)

    if @thinking <= 0

      @thinking = rand(5) + @battler.atk

      @self_actor = battler

      @self_delay = delay

      @self_target = target.clone

      @self_target_natural = target

      @self_action = action

      @self_range = range

      if delay > 5

        @casting = delay

      end

      if action.is_a?(RPG::Weapon)

        @waiting = wait

      elsif action.is_a?(RPG::Skill)

        @battler.sp -= action.sp_cost

        @action_freeze = delay

        @move_freeze = wait

        @waiting = wait

      end

    else

      @thinking -= 1

    end

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def turn(actor)

    if @delay <= 0

      if @battler != nil and @battler.damage != nil

        @damage = [@battler.damage, @battler.critical]

        @battler.damage = nil

        @battler.critical = false

        @battler.damage_pop = false

      end

      @actor = nil

      if @battler.hp <= 0

        key = [$game_map.map_id, @id, "D"]

        for i in 0...$game_party.actors.size

          if i != 0

             exp = @battler.exp * $game_system.PARTY_PERCENT_EXP / 100.0

             exp = exp.round

             $game_party.actors[i].exp += exp

          else

            $game_party.actors[i].exp += @battler.exp

          end

        end

        if $game_system.GAIN_COMBAT_GOLD

          $game_party.gain_gold(@battler.gold)

        end

        @casting = -1

        $game_self_switches[key] = true

        reset_move

        refresh

      end

    else

      @actor = actor

    end

  end

  #--------------------------------------------------------------------------

  # * Move away from Player

  #--------------------------------------------------------------------------

  def casting?

    if @action_freeze > 0

      return true

    else

      return false

    end

  end

  #--------------------------------------------------------------------------

  # * Move away from Player

  #--------------------------------------------------------------------------

  def reset_move

    @move_mods = []

    @move_speed = @original_move

    @move_frequency = @original_frequency

  end

  #--------------------------------------------------------------------------

  # * Start Event

  #--------------------------------------------------------------------------

  def start

    # If list of event commands is not empty

    if @list.size > 1

      @starting = true

      for item in @list

        if item.code == 108 and item.parameters[0] == "ACTION"

          return true

        end

      end

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Start Event

  #--------------------------------------------------------------------------

  def get_attack

    # If list of event commands is not empty

    if @self_action != nil# and @thinking <= 0

      case @self_action.zeropoint

      when "enemy"

        target = @self_target_natural

      when "self"

        target = @self

      else

        target = [@self_target.x, @self_target.y, "x-y"]

      end

      self.white_flash = true

      attack = [@self_delay, target, @battler.clone, @self_action.clone, @self_range, $game_map.events[self.id].clone]

      @self_target.turn(@self_actor)

      if @self_action.animations != nil

        index = 0

        case @direction

        when 2

          index = 0

        when 4

          index = 1

        when 6

          index = 2

        when 8

          index = 3

        end

        $animations.push(Animation.new('event',self.id,[0,-15],@self_action.animations[index]))

      else

        $animations.push(Animation.new('event',self.id,[0,-15],@self_action.animation1_id))

      end

      @self_target = nil

      @self_actor = nil

      @self_action = nil

      @self_delay = 0

      @self_range = 0

      return attack

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    super

    if @counter > 60

      #@through = true

      #@self_through = 5

      @counter = 0

      #@move_route = nil

    end

    # Lower Waiting

    if @waiting > 0

      @waiting -= 1

    end

    if @action_freeze > 0

      @action_freeze -= 1

    end

    if @move_freeze > 0

      @move_freeze -= 1

    end

    # Lower Delay

    if @delay > 0

      @delay -= 1

      if @delay == 0

        turn(@actor)

      end

    end

    # Automatic event starting determinant

    check_event_trigger_auto

    # If parallel process is valid

    if @interpreter != nil

      # If not running

      unless @interpreter.running?

        # Set up event

        @interpreter.setup(@list, @event.id)

      end

      # Update interpreter

      @interpreter.update

    end

  end

  #--------------------------------------------------------------------------

  # * Line of Sight Function

  #--------------------------------------------------------------------------

  def line_of_sight(source, weapon)

    if weapon != nil

      sx = source.x

      sy = source.y

      tx = @x

      ty = @y

      #p event

      x_diff = (sx.abs) - (tx.abs)

      y_diff = (sy.abs) - (ty.abs)

      x_diff = x_diff.abs

      y_diff = y_diff.abs

      if sx > tx

        # -X, -Y

        if sy > ty

          if x_diff > y_diff

            direction = 4

          else

            direction = 8

          end

          # -X, +Y

        else

          if x_diff > y_diff

            direction = 4

          else

            direction = 2

          end

        end

      else

        # +X, -Y

        if sy > ty

          if x_diff > y_diff

            direction = 6

          else

            direction = 8

          end

          # +X, +Y

        else

          if x_diff > y_diff

            direction = 6

          else

            direction = 2

          end

        end

      end

      return rec_los(sx, sy, tx, ty, weapon)

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Line of Sight Function

  #--------------------------------------------------------------------------

  def difficulty_of_sight(source)

    sx = source.x

    sy = source.y

    tx = @x

    ty = @y

    #p event

    x_diff = (sx.abs) - (tx.abs)

    y_diff = (sy.abs) - (ty.abs)

    x_diff = x_diff.abs

    y_diff = y_diff.abs

    if sx > tx

      # -X, -Y

      if sy > ty

        if x_diff > y_diff

          direction = 4

        else

          direction = 8

        end

        # -X, +Y

      else

        if x_diff > y_diff

          direction = 4

        else

          direction = 2

        end

      end

    else

      # +X, -Y

      if sy > ty

        if x_diff > y_diff

          direction = 6

        else

          direction = 8

        end

        # +X, +Y

      else

        if x_diff > y_diff

          direction = 6

        else

          direction = 2

        end

      end

    end

    return rec_dos(sx, sy, tx, ty, 0)

  end

  #--------------------------------------------------------------------------

  # * Calculate Operated Value

  #     x    : X-coordinates

  #     y    : Y-coordinates

  #     tx   : Target X-coordinates, where you want to be

  #     ty   : Target Y-coordinates, where you want to be

  #     dir  : Which direction to finish in before moving on, 0 = x, 1 = y

  #--------------------------------------------------------------------------

  def rec_los(x, y, tx, ty, weapon)

    # For X direction

    if x != tx

      if x < tx

        x += 1

      else

        x -= 1

      end

    end

    # For Y direction

    if y != ty

      if y < ty

        y += 1

      else

        y -= 1

      end

    end

    if $game_map.terrain_tag(x,y) >= weapon.piercing

      return false

    end

    if x == tx and y == ty

      return true

    else

      return rec_los(x, y, tx, ty, weapon)

    end

  end

  # End of rec_los

  #--------------------------------------------------------------------------

  # * Calculate Operated Value

  #     x    : X-coordinates

  #     y    : Y-coordinates

  #     tx   : Target X-coordinates, where you want to be

  #     ty   : Target Y-coordinates, where you want to be

  #     dir  : Which direction to finish in before moving on, 0 = x, 1 = y

  #--------------------------------------------------------------------------

  def rec_dos(x, y, tx, ty, dos)

    # For X direction

    if x != tx

      if x < tx

        x += 1

      else

        x -= 1

      end

    end

    # For Y direction

    if y != ty

      if y < ty

        y += 1

      else

        y -= 1

      end

    end

    if x == tx and y == ty

      return dos

    elsif not $game_map.passable?(x,y,@direction)

      return rec_dos(x, y, tx, ty, (dos+1))

    else

      return rec_dos(x, y, tx, ty, dos)

    end

  end

  # End of dos_los

  # Refresh

  alias :normal_refresh :refresh

  def refresh

    normal_refresh

    if @page != nil

      @original_move = @page.move_speed

      @original_frequency = @page.move_frequency

    end

  end

end

 

#==============================================================================

# ** Game_Enemy

#------------------------------------------------------------------------------

#  This class handles enemies. It's used within the Game_Troop class

#  ($game_troop).

#==============================================================================

 

class Game_Enemy < Game_Battler

  attr_reader   :enemy_id

  #--------------------------------------------------------------------------

  # * Object Initialization

  #     troop_id     : troop ID

  #     member_index : troop member index

  #--------------------------------------------------------------------------

  def initialize(enemy_id, member_index)

    super()

    @enemy_id = enemy_id

    enemy = $data_enemies[@enemy_id]

    @battler_name = enemy.battler_name

    @battler_hue = enemy.battler_hue

    @hp = maxhp

    @sp = maxsp

  end

  #--------------------------------------------------------------------------

  # Can use the currently equipped weapon

  #--------------------------------------------------------------------------

  def can_use_current_weapon

    return true

  end

end

 

#==============================================================================

# ** Game_Party

#------------------------------------------------------------------------------

#  This class handles the party. It includes information on amount of gold 

#  and items. Refer to "$game_party" for the instance of this class.

#==============================================================================

 

class Game_Party

  #--------------------------------------------------------------------------

  # * Slip Damage Check (for map)

  #--------------------------------------------------------------------------

  def check_map_slip_damage

    actor = @actors[0]

    if actor.hp > 0 and actor.slip_damage?

      actor.hp -= [actor.maxhp / 100, 1].max

      $game_player.turn(nil)

      if actor.hp == 0

        $game_system.se_play($data_system.actor_collapse_se)

        if not $game_party.all_dead?

          $scene.force_player_switch

        end

      end

      $game_screen.start_flash(Color.new(255,0,0,128), 4)

      $game_temp.gameover = $game_party.all_dead?

    end

  end

 

end

 

#==============================================================================

# ** Game_Map

#------------------------------------------------------------------------------

#  This class handles the map. It includes scrolling and passable determining

#  functions. Refer to "$game_map" for the instance of this class.

#==============================================================================

class Game_Map

  attr_accessor   :player_characters

  attr_accessor   :switch_transfer

  attr_accessor   :run_init

  attr_accessor   :attacks

  # Alias the changes to the normal setup for map resetting and player

  # character additions.

  alias :normal_setup :setup

  def setup(map_id)

    $game_system.ai.init_new_map

    $game_system.init_hostilities

    normal_setup(map_id)

    @player_characters = []

    current_id = 0

    people_there_already = false

    for i in 1...$game_party.actors.size

      if $game_party.actors[i].map_location[0] == map_id

        character = Game_PartyMember.new(current_id, i)

        character.set_character_graphics($game_party.actors[i].character_name, $game_party.actors[i].character_hue)

        character.moveto($game_party.actors[i].map_location[1], $game_party.actors[i].map_location[2])

        @player_characters.push(character.clone)

        $game_system.ai.assign(0, (10000 + current_id))

        if not $game_party.actors[i].dead?

          people_there_already = true

        end

        current_id += 1

      end

    end

    # RESET and RESPAWN enemies with RESPAWN on the current page

    for event in $game_map.events.values

      # Find events set to respawn

      if event.list != nil

        for item in event.list

          if item.code == 108 and item.parameters[0] == "RESPAWN" and not @switch_transfer and not people_there_already

            key = [$game_map.map_id, event.id, "A"]

            $game_self_switches[key] = false

            key = [$game_map.map_id, event.id, "B"]

            $game_self_switches[key] = false

            key = [$game_map.map_id, event.id, "C"]

            $game_self_switches[key] = false

            key = [$game_map.map_id, event.id, "D"]

            $game_self_switches[key] = false

          end

          if item.code == 108 and item.parameters[0] == "MAP_INIT"

            event.start

          end

          if item.code == 108 and item.parameters[0] == "REMEMBER"

            key = $game_map.map_id.to_s + "+" + event.id.to_s

            loc = $game_event_locations[key]

            if loc != nil

              event.moveto(loc[0],loc[1])

            end

            #$game_event_locations.delete(key)

          end

        end

      end

      event.update

      event.refresh

      # Take the last page and init the enemies IF they aren't dead

      last_page = event.event.pages.reverse

      last_page = last_page[0]

      if last_page != nil

        for item in last_page.list

          key = [$game_map.map_id, event.id, "D"]

          dead = $game_self_switches[key]

          if not dead

            if item.code == 108 and item.parameters[0].include?("ENEMY=")

              id = item.parameters[0].split('=')

              event.set_enemy(id[1].to_i)

            end

            if item.code == 108 and item.parameters[0].include?("TEAM=")

              id = item.parameters[0].split('=')

              $game_system.ai.assign(id[1].to_i,event.id)

            end

            if item.code == 108 and item.parameters[0].include?("ACTOR=")

              id = item.parameters[0].split('=')

              for i in 0...@player_characters.size

                id = id[1].to_i

                actor = $game_actors[id]

                if actor == $game_party.actors[@player_characters[i].actor_id]

                  @player_characters[i].map_event = event

                end

              end

            end

          end

        end

      end

    end

    @switch_transfer = false

    $game_switches[$game_system.MAP_INIT_COMPLETE_SWITCH] = true

  end

  #--------------------------------------------------------------------------

  # * Applying Normal Attack Effects

  #     attacker : battler

  #--------------------------------------------------------------------------

  def load_update

    for event in $game_map.events.values

      # Take the last page and init the enemies IF they aren't dead

      last_page = event.event.pages.reverse

      last_page = last_page[0]

      if last_page != nil

        for item in last_page.list

          key = [$game_map.map_id, event.id, "D"]

          dead = $game_self_switches[key]

          if not dead

            if item.code == 108 and item.parameters[0].include?("ENEMY=")

              id = item.parameters[0].split('=')

              event.set_enemy(id[1].to_i)

            end

            if item.code == 108 and item.parameters[0].include?("TEAM=")

              id = item.parameters[0].split('=')

              $game_system.ai.assign(id[1].to_i,event.id)

            end

            if item.code == 108 and item.parameters[0].include?("ACTOR=")

              id = item.parameters[0].split('=')

              for i in 0...@player_characters.size

                id = id[1].to_i

                actor = $game_actors[id]

                if actor == $game_party.actors[@player_characters[i].actor_id]

                  @player_characters[i].map_event = event

                end

              end

            end

          end #end if not dead

        end #end for item in last_page.list

      end #end if last_page != nil

    end #end for

  end

  #--------------------------------------------------------------------------

  # An alias-revised update so that if the character moves so the sprite moves.

  #--------------------------------------------------------------------------

  alias :system_terg_normal_update :update

  def update

    system_terg_normal_update

    for char in @player_characters

      char.update

    end

    if @run_init

      run_map_init

    end

  end

  

  # Reset the players for a map transfer

  def reset_players

    @player_characters = []

    $game_system.ai.teams[0] = [0]

    current_id = 0

    for i in 1...$game_party.actors.size

      if $game_party.actors[i].map_location[0] == map_id

        character = Game_PartyMember.new(current_id, i)

        character.set_character_graphics($game_party.actors[i].character_name, $game_party.actors[i].character_hue)

        character.moveto($game_party.actors[i].map_location[1], $game_party.actors[i].map_location[2])

        @player_characters.push(character.clone)

        $game_system.ai.assign(0, (10000 + current_id))

        current_id += 1

      end

    end

  end

  

  # Map Init Run - To be called manually on a map if you want it re-init

  def run_map_init

    for event in $game_map.events.values

      # Find the Map_init events

      if event.list != nil

        for item in event.list

          if item.code == 108 and item.parameters[0] == "MAP_INIT"

            event.start

          end

        end

      end

    end

    @run_init = false

  end

  

end # End of Game Map

 

#==============================================================================

# ** Game_Battler (part 3)

#------------------------------------------------------------------------------

#  This class deals with battlers. It's used as a superclass for the Game_Actor

#  and Game_Enemy classes.

#==============================================================================

 

class Game_Battler

  attr_accessor   :invul

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  alias :system_terg_init :initialize

  def initialize

    @invul = [false, false]

    system_terg_init

  end

  #--------------------------------------------------------------------------

  # * Applying Normal Attack Effects

  #     attacker : battler

  #--------------------------------------------------------------------------

  def attack_effect(attacker, weapon = nil, range = nil)

    # Clear critical flag

    self.critical = false

    # First hit detection

    if attacker.is_a?(Game_Actor)

      diff = range - weapon.range

      hit = weapon.base_accuracy

      if weapon.range < range

        hit -= diff.abs * weapon.deterioration

        if hit < 0

          hit = 0

        end

      end

    elsif attacker.is_a?(Game_Enemy)

      diff = range - weapon.range

      hit = weapon.base_accuracy

      if weapon.range < range

        hit -= diff.abs * weapon.deterioration

        if hit < 0

          hit = 0

        end

      end

    end

    hit_result = (rand(100) < hit)

    attack_hit = hit_result

    # If hit occurs

    if hit_result == true

      # Calculate basic damage

      atk = [weapon.atk, 0].max

      self.damage = atk

      self.damage *= ((100.0 - self.pdef) / 100.0)

      self.damage = self.damage.round

      # Element correction

      self.damage *= elements_correct(attacker.element_set)

      self.damage /= 100

      # If damage value is strictly positive

      if self.damage > 0

        # Critical correction

        if rand(100) < 4 * attacker.dex / self.agi

          self.damage *= 2

          self.critical = true

        end

        # Guard correction

        if self.guarding?

          self.damage /= 2

        end

      end

      # Dispersion

      if self.damage.abs > 0

        amp = [self.damage.abs * 15 / 100, 1].max

        self.damage += rand(amp+1) + rand(amp+1) - amp

      end

      # Second hit detection

      eva = 8 * self.agi / attacker.dex + self.eva

      hit = self.damage < 0 ? 100 : 100 - eva

      hit = self.cant_evade? ? 100 : hit

      hit_result = (rand(100) < hit)

    end

    # If hit occurs

    if hit_result == true

      # State Removed by Shock

      remove_states_shock

      # Substract damage from HP

      if not @invul[0]

        self.hp -= self.damage

      end

      # State change

      @state_changed = false

      states_plus(weapon.plus_state_set)

      states_minus(weapon.minus_state_set)

    # When missing

    else

      # Set damage to "Miss"

      #if $data_weapons[attacker.weapon_id].range > 1

        self.damage = "Miss"

      #else

      #  self.damage = ""

      #end

      # Clear critical flag

      self.critical = false

    end

    # End Method

    if @invul[0]

      self.damage = "Invulnerable!"

    end

    return attack_hit

  end

  #--------------------------------------------------------------------------

  # * Apply Skill Effects

  #     user  : the one using skills (battler)

  #     skill : skill

  #--------------------------------------------------------------------------

  def skill_effect(user, skill, range = nil)

    # Clear critical flag

    self.critical = false

    hit = 0

    # Do the accuracy calculations

    if user.is_a?(Game_Actor)

      diff = range - skill.range

      hit = skill.base_accuracy

      if skill.range < range

        hit -= diff.abs * skill.deterioration

        if hit < 0

          hit = 0

        end

      end

    elsif user.is_a?(Game_Enemy)

      diff = range - skill.range

      hit = skill.base_accuracy

      if skill.range < range

        hit -= diff.abs * skill.deterioration

        if hit < 0

          hit = 0

        end

      end

    end

    # Clear effective flag

    effective = false

    # Set effective flag if common ID is effective

    effective |= skill.common_event_id > 0

    # First hit detection

    hit_result = (rand(100) < hit)

    # Set effective flag if skill is uncertain

    effective |= hit < 100

    # If hit occurs

    if hit_result == true

      # Calculate power

      power = skill.power + user.atk * skill.atk_f / 100

      if power > 0

        power = [power, 0].max

      end

      power *= ((100.0 - self.mdef) / 100.0)

      power = power.round

      # Calculate basic damage

      self.damage = power

      # Element correction

      self.damage *= elements_correct(skill.element_set)

      self.damage /= 100

      # If damage value is strictly positive

      if self.damage > 0

        # Guard correction

        if self.guarding?

          self.damage /= 2

        end

      end

      # Dispersion

      if skill.variance > 0 and self.damage.abs > 0

        amp = [self.damage.abs * skill.variance / 100, 1].max

        self.damage += rand(amp+1) + rand(amp+1) - amp

      end

      # Second hit detection

      eva = 8 * self.agi / user.dex + self.eva

      hit = self.damage < 0 ? 100 : 100 - eva * skill.eva_f / 100

      hit = self.cant_evade? ? 100 : hit

      hit_result = (rand(100) < hit)

      # Set effective flag if skill is uncertain

      effective |= hit < 100

    end

    # If hit occurs

    if hit_result == true

      # If physical attack has power other than 0

      if skill.power != 0 and skill.atk_f > 0

        # State Removed by Shock

        remove_states_shock

        # Set to effective flag

        effective = true

      end

      # Substract damage from HP

      last_hp = self.hp

      if not @invul[1]

        self.hp -= self.damage

      end

      effective |= self.hp != last_hp

      # State change

      @state_changed = false

      effective |= states_plus(skill.plus_state_set)

      effective |= states_minus(skill.minus_state_set)

      # If power is 0

      if skill.power == 0

        # Set damage to an empty string

        self.damage = ""

        # If state is unchanged

        unless @state_changed

          # Set damage to "Miss"

          self.damage = "Miss"

        end

      end

    # If miss occurs

    else

      # Set damage to "Miss"

      self.damage = "Miss"

    end

    # End Method

    if @invul[1]

      self.damage = "Invulnerable!"

    end

    return effective

  end

end

#==============================================================================

# ** Game_Actor

#------------------------------------------------------------------------------

#  This class handles the actor. It's used within the Game_Actors class

#  ($game_actors) and refers to the Game_Party class ($game_party).

#==============================================================================

 

class Game_Actor < Game_Battler

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_accessor   :ammo

  attr_accessor   :skill_id

  attr_accessor   :item_id

  attr_accessor   :ap

  attr_accessor   :map_location

  #--------------------------------------------------------------------------

  # * Setup

  #     actor_id : actor ID

  #--------------------------------------------------------------------------

  alias :normal_setup :setup

  def setup(actor_id)

    normal_setup(actor_id)

    @map_location = [0, 0, 0]

    @ap = 100

    @ammo = []

    @skill_id = [-1,-1,-1,-1,-1,-1,-1,-1]

    @item_id = -1

  end

  #--------------------------------------------------------------------------

  # * Change Equipment

  #     equip_type : type of equipment

  #     id    : weapon or armor ID (If 0, remove equipment)

  #--------------------------------------------------------------------------

  alias :normal_equip :equip

  def equip(equip_type, id)

    # Save original weapon

    original_weapon = @weapon_id

    # Run the normal equip

    normal_equip(equip_type, id)

    # If it's a new weapon, try to load ammo for it

    if original_weapon != @weapon_id

      if @ammo[@weapon_id] == nil

        @ammo[@weapon_id] = 0

      end

      if @weapon_id != 0 and @ammo[@weapon_id] <= 0 and $data_weapons[@weapon_id].ammo_type != nil

        @ammo[@weapon_id] = $game_system.ammo.withdraw($data_weapons[@weapon_id].ammo_type, $data_weapons[@weapon_id].capacity)

      end

    end

  end

  #--------------------------------------------------------------------------

  # Get the ammo for a weapon

  #--------------------------------------------------------------------------

  def get_ammo(weapon_id)

    return @ammo[weapon_id]

  end

  #--------------------------------------------------------------------------

  # Get the ammo for a weapon

  #--------------------------------------------------------------------------

  def decrease_current_ammo

    @ammo[weapon_id] -= 1

  end

  #--------------------------------------------------------------------------

  # Can use the currently equipped weapon

  #--------------------------------------------------------------------------

  def can_use_current_weapon

    if $data_weapons[@weapon_id].ammo_type == nil

      return true

    end

    if @ammo[@weapon_id] == nil

      @ammo[@weapon_id] = 0

      return false

    elsif @ammo[@weapon_id] > 0

      return true

    else

      return false

    end

  end

end

 

#==============================================================================

# ** Interpreter (part 1)

#------------------------------------------------------------------------------

#  This interpreter runs event commands. This class is used within the

#  Game_System class and the Game_Event class.

#==============================================================================

 

class Interpreter

  attr_reader   :event_id

end

#==============================================================================

# ** Module RPG::Sprite Changes

#------------------------------------------------------------------------------

#==============================================================================

module RPG

  class Sprite < ::Sprite

    def dispose

      dispose_damage

      dispose_animation

      dispose_loop_animation

      dispose_casting

      super

    end

    

    def damage(value, critical)

      dispose_damage

      if value.is_a?(Numeric)

        damage_string = value.abs.to_s

      else

        damage_string = value.to_s

      end

      bitmap = Bitmap.new(160, 48)

      bitmap.font.name = "Arial Black"

      bitmap.font.size = 20

      bitmap.font.color.set(0, 0, 0)

      bitmap.draw_text(-1, 6-1, 160, 36, damage_string, 1)

      bitmap.draw_text(+1, 6-1, 160, 36, damage_string, 1)

      bitmap.draw_text(-1, 6+1, 160, 36, damage_string, 1)

      bitmap.draw_text(+1, 6+1, 160, 36, damage_string, 1)

      if value.is_a?(Numeric) and value < 0

        bitmap.font.color.set(176, 255, 144)

      else

        bitmap.font.color.set(255, 196, 196)

      end

      bitmap.draw_text(0, 6, 160, 36, damage_string, 1)

      if critical

        bitmap.font.size = 16

        bitmap.font.color.set(0, 0, 0)

        bitmap.draw_text(-1, -1, 160, 20, "CRITICAL", 1)

        bitmap.draw_text(+1, -1, 160, 20, "CRITICAL", 1)

        bitmap.draw_text(-1, +1, 160, 20, "CRITICAL", 1)

        bitmap.draw_text(+1, +1, 160, 20, "CRITICAL", 1)

        bitmap.font.color.set(255, 255, 255)

        bitmap.draw_text(0, 0, 160, 20, "CRITICAL", 1)

      end

      @_damage_sprite = ::Sprite.new(self.viewport)

      @_damage_sprite.bitmap = bitmap

      @_damage_sprite.ox = 80

      @_damage_sprite.oy = 20

      @_damage_sprite.x = self.x

      @_damage_sprite.y = self.y - self.oy / 2

      @_damage_sprite.z = 3500

      @_damage_duration = 40

    end

     

    def casting(time)

      dispose_casting

      bitmap = Bitmap.new(35, 8)

      black = Color.new(0,0,0,255)

      white = Color.new(255,255,255,255)

      cast = @character.cast_color

      bitmap.fill_rect(0,0,35,8,white)

      bitmap.fill_rect(1,1,33,6,black)

      @_casting_sprite = ::Sprite.new(self.viewport)

      @_casting_sprite.bitmap = bitmap

      @_casting_sprite.ox = 17

      @_casting_sprite.oy = -15

      @_casting_sprite.x = self.x

      @_casting_sprite.y = self.y - self.oy / 2

      @_casting_sprite.z = 3000

      @_casting_duration = time

      @_casting_max = time

    end

    

    def update_casting_bar(value)

      dispose_casting_bar

      if @casting != value

        bitmap = Bitmap.new(35, 8)

        cast = @character.cast_color

        bitmap.fill_rect(2,2,value,4,cast)

        @_casting_bar_sprite = ::Sprite.new(self.viewport)

        @_casting_bar_sprite.bitmap = bitmap

        @_casting_bar_sprite.ox = 17

        @_casting_bar_sprite.oy = -15

        @_casting_bar_sprite.x = self.x

        @_casting_bar_sprite.y = self.y - self.oy / 2

        @_casting_bar_sprite.z = 3000

        @casting = value

      end

    end

  

    def dispose_casting

      if @_casting_sprite != nil

        @_casting_sprite.bitmap.dispose

        @_casting_sprite.dispose

        @_casting_sprite = nil

        @_casting_duration = 0

        dispose_casting_bar

      end

    end

    

    def dispose_casting_bar

      if @_casting_bar_sprite != nil

        @_casting_bar_sprite.bitmap.dispose

        @_casting_bar_sprite.dispose

        @_casting_bar_sprite = nil

      end

    end

    

    def update

      super

      if @_whiten_duration > 0

        @_whiten_duration -= 1

        self.color.alpha = 128 - (16 - @_whiten_duration) * 10

      end

      if @_appear_duration > 0

        @_appear_duration -= 1

        self.opacity = (16 - @_appear_duration) * 16

      end

      if @_escape_duration > 0

        @_escape_duration -= 1

        self.opacity = 256 - (32 - @_escape_duration) * 10

      end

      if @_collapse_duration > 0

        @_collapse_duration -= 1

        self.opacity = 256 - (48 - @_collapse_duration) * 6

      end

      if @_damage_duration > 0

        @_damage_duration -= 1

        case @_damage_duration

        when 38..39

          @_damage_sprite.y -= 4

        when 36..37

          @_damage_sprite.y -= 2

        when 34..35

          @_damage_sprite.y += 2

        when 28..33

          @_damage_sprite.y += 4

        end

        @_damage_sprite.opacity = 256 - (12 - @_damage_duration) * 32

        if @_damage_duration == 0

          dispose_damage

        end

      end

      if @_casting_duration != nil and @_casting_duration > 0

        @_casting_duration -= 1

        value = (@_casting_duration / (@_casting_max * 1.0)) * 100.0

        value = value * 31.0 / 100.0

        update_casting_bar(value)

        if @_casting_sprite.x != self.x or @_casting_sprite.y != self.y

          @_casting_sprite.x = self.x

          @_casting_sprite.y = self.y - self.oy / 2

        end

        if @_casting_duration == 0

          dispose_casting

        end

      end

      if @_animation != nil and (Graphics.frame_count % 2 == 0)

        @_animation_duration -= 1

        update_animation

      end

      if @_loop_animation != nil and (Graphics.frame_count % 2 == 0)

        update_loop_animation

        @_loop_animation_index += 1

        @_loop_animation_index %= @_loop_animation.frame_max

      end

      if @_blink

        @_blink_count = (@_blink_count + 1) % 32

        if @_blink_count < 16

          alpha = (16 - @_blink_count) * 6

        else

          alpha = (@_blink_count - 16) * 6

        end

        self.color.set(255, 255, 255, alpha)

      end

      @@_animations.clear

    end

  end

end

 

#==============================================================================

# ** Game_EventLocations

#------------------------------------------------------------------------------

#  This class handles event locations that get memorized for only certain events.

#==============================================================================

 

class Game_EventLocations

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    @data = {}

  end

  #--------------------------------------------------------------------------

  # * Get Self Switch 

  #     key : key

  #--------------------------------------------------------------------------

  def record(key, x, y)

    @data[key] = [x, y]

  end

  #--------------------------------------------------------------------------

  # * Get Self Switch 

  #     key : key

  #--------------------------------------------------------------------------

  def [](key)

    return @data[key]

  end

  #

  def []=(key, value)

    @data[key] = value

  end

end

 

#==============================================================================

# ** Scene_Title

#------------------------------------------------------------------------------

#  This class performs title screen processing.

#==============================================================================

 

class Scene_Title

  #--------------------------------------------------------------------------

  # * Command: New Game

  #--------------------------------------------------------------------------

  alias :system_terg_new_game :command_new_game

  def command_new_game

    $game_event_locations   = Game_EventLocations.new

    system_terg_new_game

  end

end

 

#==============================================================================

# ** Scene_Load

#------------------------------------------------------------------------------

#  This class performs load screen processing.

#==============================================================================

 

class Scene_Load < Scene_File

  alias :system_terg_read_save :read_save_data

  def read_save_data(file)

    $game_event_locations = Marshal.load(file)

    system_terg_read_save(file)

  end

end

 

#==============================================================================

# ** Scene_Save

#------------------------------------------------------------------------------

#  This class performs save screen processing.

#==============================================================================

 

class Scene_Save < Scene_File

  alias :system_terg_write_data :write_save_data

  def write_save_data(file)

    Marshal.dump($game_event_locations, file)

    system_terg_write_data(file)

  end

end

 

#==============================================================================

# ** Window_SaveFile

#------------------------------------------------------------------------------

#  This window displays save files on the save and load screens.

#==============================================================================

 

class Window_SaveFile < Window_Base

  #--------------------------------------------------------------------------

  # * Object Initialization

  #     file_index : save file index (0-3)

  #     filename   : file name

  #--------------------------------------------------------------------------

  def initialize(file_index, filename)

    super(0, 64 + file_index % 4 * 104, 640, 104)

    self.contents = Bitmap.new(width - 32, height - 32)

    @file_index = file_index

    @filename = "Save#{@file_index + 1}.rxdata"

    @time_stamp = Time.at(0)

    @file_exist = FileTest.exist?(@filename)

    if @file_exist

      file = File.open(@filename, "r")

      @time_stamp = file.mtime

      @game_event_locations = Marshal.load(file)

      @characters = Marshal.load(file)

      @frame_count = Marshal.load(file)

      @game_system = Marshal.load(file)

      @game_switches = Marshal.load(file)

      @game_variables = Marshal.load(file)

      @total_sec = @frame_count / Graphics.frame_rate

      file.close

    end

    refresh

    @selected = false

  end

end

 

#==============================================================================

# ** Game_System

#------------------------------------------------------------------------------

#  This class handles data surrounding the system. Backround music, etc.

#  is managed here as well. Refer to "$game_system" for the instance of 

#  this class.

#==============================================================================

 

class Game_System

  attr_accessor     :ai

  attr_accessor     :ammo

  attr_accessor     :cursor

  attr_accessor     :skill_limit

  attr_accessor     :GAME_OVER_SWITCH

  attr_accessor     :PARTY_PERCENT_EXP

  attr_accessor     :GAIN_COMBAT_GOLD

  attr_accessor     :MAP_INIT_COMPLETE_SWITCH

  attr_accessor     :SKILL_EVENT_USE_VAR

  attr_accessor     :SWITCH_CHARS_OK_SWITCH

  attr_accessor     :SWITCH_CHAR_TIMER

  attr_accessor     :DEFAULT_SKILL_EVENT

end

Code:
<div id="{CB}" style="font-family: monospace;"><ol>#==============================================================================

# ** Scene_Item

#------------------------------------------------------------------------------

#  This class performs item screen processing.

#==============================================================================

 

class Scene_Item

  # Item equipping code

  alias :system_terg_item_update_item :update_item

  def update_item

    # If E button was pressed

    if Input.triggered?(Input::Letters['E']) and @item_window.item != nil

      if $game_party.actors[0].item_id == @item_window.item.id

        $game_party.actors[0].item_id = -1

        Audio.se_play("Audio/SE/005-System05", 80, 100)

      else

        $game_party.actors[0].item_id = @item_window.item.id

        Audio.se_play("Audio/SE/005-System05", 80, 100)

      end

    end

    system_terg_item_update_item

  end

end

 

#==============================================================================

# ** Scene_Skill

#------------------------------------------------------------------------------

#  This class performs skill screen processing.

#==============================================================================

 

class Scene_Skill

  #--------------------------------------------------------------------------

  # * Frame Update (if skill window is active)

  #--------------------------------------------------------------------------

  alias :system_terg_update_skill :update_skill

  def update_skill

    # Equipping skills

    if Input.triggered?(Input::Numberkeys[1])

      @skill = @skill_window.skill

      @actor.skill_id[0] = @skill.id

      Audio.se_play("Audio/SE/005-System05", 80, 100)

    elsif Input.triggered?(Input::Numberkeys[2])

      @skill = @skill_window.skill

      @actor.skill_id[1] = @skill.id

      Audio.se_play("Audio/SE/005-System05", 80, 100)

    elsif Input.triggered?(Input::Numberkeys[3])

      @skill = @skill_window.skill

      @actor.skill_id[2] = @skill.id

      Audio.se_play("Audio/SE/005-System05", 80, 100)

    elsif Input.triggered?(Input::Numberkeys[4])

      @skill = @skill_window.skill

      @actor.skill_id[3] = @skill.id

      Audio.se_play("Audio/SE/005-System05", 80, 100)

    elsif Input.triggered?(Input::Numberkeys[5])

      @skill = @skill_window.skill

      @actor.skill_id[4] = @skill.id

      Audio.se_play("Audio/SE/005-System05", 80, 100)

    elsif Input.triggered?(Input::Numberkeys[6])

      @skill = @skill_window.skill

      @actor.skill_id[5] = @skill.id

      Audio.se_play("Audio/SE/005-System05", 80, 100)

    elsif Input.triggered?(Input::Numberkeys[7])

      @skill = @skill_window.skill

      @actor.skill_id[6] = @skill.id

      Audio.se_play("Audio/SE/005-System05", 80, 100)

    elsif Input.triggered?(Input::Numberkeys[8])

      @skill = @skill_window.skill

      @actor.skill_id[7] = @skill.id

      Audio.se_play("Audio/SE/005-System05", 80, 100)

    end

    system_terg_update_skill

  end

end

Code:
<div id="{CB}" style="font-family: monospace;"><ol>#==============================================================================

# ** Game_System

#------------------------------------------------------------------------------

#  This class handles data surrounding the system. Backround music, etc.

#  is managed here as well. Refer to "$game_system" for the instance of 

#  this class.

#==============================================================================

 

class Game_System

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  alias :normal_init :initialize

  def initialize

    normal_init

    @ai = Game_AIManager.new

    @ammo = Game_AmmoManager.new

    @cursor = "cursor"

    @skill_limit = 8

    @SKILL_EVENT_USE_VAR = 25

    @GAME_OVER_SWITCH = 1

    @SWITCH_CHARS_OK_SWITCH = 4

    @MAP_INIT_COMPLETE_SWITCH = 2

    @PARTY_PERCENT_EXP = 75

    @GAIN_COMBAT_GOLD = true

    @SWITCH_CHAR_TIMER = 1

    init_weapons

    init_skills

    init_ammo

    init_hostilities

  end

end

 

#==============================================================================

# ** Module RPG::Sprite Changes

#------------------------------------------------------------------------------

#==============================================================================

module RPG

  # WEAPON CHANGES

  class Weapon

    # It's Group ID, chooses which menu to display the weapon in

    # ie. group_id = 1 -> When the Shift+1 menu is brought up, this weapon

    # would show up if the player owned at least one and it wasn't equipped.

    # ********** REQUIRED ************

    attr_accessor   :group_id

    # It's ideal range

    # ********** REQUIRED ************

    attr_accessor   :range

    # How good it's accuracy is at or before it's range

    # ********** REQUIRED ************

    attr_accessor   :base_accuracy

    # How fast accuracy drops AFTER it's range is exceeded (per square)

    # ********** REQUIRED ************

    attr_accessor   :deterioration

    # How long after using this weapon must the user wait to use another

    # action of ANY kind

    # ********** REQUIRED ************

    attr_accessor   :delay

    # Ammo Pool ID = If two weapons have the same ammo_type, they will both draw

    # ammo from that pool of ammo. No declaration means no ammo type and 

    # it will have no costs.

    attr_accessor   :ammo_type

    # Zeropoint is an important piece of information, it decides how the attack

    # is calculated.

    # "enemy" = Will only hit an enemy if they are clicked on

    # "target" = Will hit whoever is on the square when the weapon's ddelay is done

    # "self" = Will only work on the player themselves

    # ********** REQUIRED ************

    attr_accessor   :zeropoint

    # How big the AoE area is, used as a radius, so spread = 5, 

    # means that anyone within 5 squares from the zeropoint will get a hit check

    # ********** REQUIRED ************

    attr_accessor   :spread

    # Delay before damage is done in frames

    # ********** REQUIRED ************

    attr_accessor   :ddelay

    # Any terrain ID higher than this will "block" this weapon, ie. it won't shoot

    # through. Setting a wall to terrain tag = 7 will make no weapons able to go

    # THROUGH a wall.

    # ********** REQUIRED ************

    attr_accessor   :piercing

    # If set to true, this attack will hit as many people as it can, if not set

    # or set to false, it will hit the best target, usually the one you clicked on

    # or the system will pick one

    attr_accessor   :multihit

    # [Down,Left,Right,Up] animation IDs to play for use of skill

    # ie. [10,11,12,13] => when player is facing down, animation 10 is played.

    attr_accessor   :animations

    # If set on, any attack with this weapon, if used so that the player would

    # be within the spread range, or is the target, can hurt the player as well

    attr_accessor   :hurt_self

    # Squares target gets pushed back (NOT IN USE)

    #attr_accessor   :knockback

    # Squares user gets pushed back (NOT IN USE)

    #attr_accessor   :kickback

    # Ammo capacity per load, ie. reloading a handgun with capacity would

    # fill the gun from it's current ammo to this capacity level.

    # ********** REQUIRED ************ (if ammo_type is declared)

    attr_accessor   :capacity

    # Move speed/frequency [frames,speed,frequency,rating]

    # Frames = duration in frames

    # Speed = Move speed of the target

    # Frequency = Move frequency of the target

    # Rating = How it stacks up in importance, the highest rating move

    #          modifaction active will be the one effecting them until it wears off

    attr_accessor   :target_move

    attr_accessor   :user_move

    # Time per ammo to take reloading, calculated by:

    # ammo_refilled * reload_time (ie. refilling 50 ammo with a reload_time of 2

    # frames would mean 100 frames of waiting (you can move during this time)

    # ********** REQUIRED ************ (if ammo_type is declared)

    attr_accessor   :reload_time

    # The sound to play when a reload is initiated (only plays once)

    attr_accessor   :reload_sound

    # If this is set to true, then you WILL face the mouse when equipped

    # otherwise, you will NOT!

    attr_accessor   :mouse_face

    # Action points required to use this attack once, if it cannot be payed,

    # the weapon will be unusable until there are enough Action Points

    # If not set, the Action Cost will be zero.

    attr_accessor   :rap

    # This is a character graphic that is actually just a weapon that

    # should fit the default size of the sprites in use.

    attr_accessor   :weapon_graphic

  end

  

  # SKILL CHANGES

  class Skill

    attr_accessor   :iid

    attr_accessor   :action_id

    attr_accessor   :weapon_id

    attr_accessor   :range

    attr_accessor   :rap

    attr_accessor   :base_accuracy

    attr_accessor   :deterioration

    attr_accessor   :delay

    attr_accessor   :ddelay

    attr_accessor   :zeropoint

    attr_accessor   :animations

    attr_accessor   :ammo_type

    attr_accessor   :piercing

    attr_accessor   :multihit

    attr_accessor   :hurt_self

    attr_accessor   :spread

    attr_accessor   :cursor

    attr_accessor   :target_move

    attr_accessor   :user_move

    attr_accessor   :weapon_dependency

    attr_accessor   :required_item

  end

end

 

#==============================================================================

# ** Game_System

#------------------------------------------------------------------------------

#  This class handles data surrounding the system. Backround music, etc.

#  is managed here as well. Refer to "$game_system" for the instance of 

#  this class.

#==============================================================================

 

class Game_System

 

  def init_weapons

    #========= Custom Weapon Inits ==========

    # Knife

    $data_weapons[1].range = 1

    $data_weapons[1].group_id = 1

    $data_weapons[1].rap = 8

    $data_weapons[1].mouse_face = true

    $data_weapons[1].base_accuracy = 100

    $data_weapons[1].deterioration = 200

    $data_weapons[1].ammo_type = nil

    $data_weapons[1].delay = 8

    $data_weapons[1].ddelay = 0

    $data_weapons[1].spread = 32

    $data_weapons[1].animations = [118,119,120,121]

    $data_weapons[1].piercing = 7

    $data_weapons[1].target_move = [25,-2,0,5]

    $data_weapons[1].multihit = 3

    $data_weapons[1].zeropoint = "target"

    

    # Sword

    $data_weapons[4].range = 1

    $data_weapons[4].group_id = 1

    $data_weapons[4].rap = 11

    $data_weapons[4].mouse_face = true

    $data_weapons[4].base_accuracy = 100

    $data_weapons[4].deterioration = 100

    $data_weapons[4].ammo_type = nil

    $data_weapons[4].delay = 12

    $data_weapons[4].ddelay = 0

    $data_weapons[4].spread = 32

    $data_weapons[4].animations = [110,111,112,113]

    $data_weapons[4].piercing = 7

    $data_weapons[4].target_move = [50,-2,0,5]

    $data_weapons[4].multihit = 3

    $data_weapons[4].zeropoint = "target"

    

    # Lightsaber

    $data_weapons[2].range = 1

    $data_weapons[2].group_id = 1

    $data_weapons[2].rap = 10

    $data_weapons[2].mouse_face = true

    $data_weapons[2].base_accuracy = 100

    $data_weapons[2].deterioration = 50

    $data_weapons[2].ammo_type = nil

    $data_weapons[2].delay = 20

    $data_weapons[2].ddelay = 0

    $data_weapons[2].spread = 0

    $data_weapons[2].piercing = 7

    $data_weapons[2].weapon_graphic = "saber"

    $data_weapons[2].target_move = [50,0,0,5]

    

    # Crossbow

    $data_weapons[3].range = 5

    $data_weapons[3].group_id = 3

    $data_weapons[3].rap = 50

    $data_weapons[3].mouse_face = true

    $data_weapons[3].base_accuracy = 90

    $data_weapons[3].deterioration = 10

    $data_weapons[3].ammo_type = 2

    $data_weapons[3].capacity = 1

    $data_weapons[3].delay = 15

    $data_weapons[3].ddelay = 10

    $data_weapons[3].zeropoint = "target"

    $data_weapons[3].spread = 1

    $data_weapons[3].piercing = 6

    $data_weapons[3].animations = [123,124,125,126]

    $data_weapons[3].hurt_self = true

    $data_weapons[3].reload_time = 100

    $data_weapons[3].reload_sound = "005-System05"

    

    # Old Revolver

    $data_weapons[5].range = 4

    $data_weapons[5].group_id = 2

    $data_weapons[5].rap = 9

    $data_weapons[5].mouse_face = true

    $data_weapons[5].base_accuracy = 80

    $data_weapons[5].deterioration = 20

    $data_weapons[5].ammo_type = 1

    $data_weapons[5].capacity = 6

    $data_weapons[5].delay = 15

    $data_weapons[5].ddelay = 0

    $data_weapons[5].zeropoint = "target"

    $data_weapons[5].spread = 1

    $data_weapons[5].piercing = 6

    $data_weapons[5].animations = [114,115,116,117]

    $data_weapons[5].hurt_self = true

    $data_weapons[5].reload_time = 15

    $data_weapons[5].reload_sound = "005-System05"

    

    # 6-Shooter

    $data_weapons[6].range = 4

    $data_weapons[6].group_id = 2

    $data_weapons[6].rap = 13

    $data_weapons[6].mouse_face = true

    $data_weapons[6].base_accuracy = 90

    $data_weapons[6].deterioration = 15

    $data_weapons[6].ammo_type = 1

    $data_weapons[6].capacity = 6

    $data_weapons[6].delay = 20

    $data_weapons[6].ddelay = 0

    $data_weapons[6].zeropoint = "target"

    $data_weapons[6].spread = 1

    $data_weapons[6].piercing = 6

    $data_weapons[6].animations = [114,115,116,117]

    $data_weapons[6].hurt_self = true

    $data_weapons[6].reload_time = 10

    $data_weapons[6].reload_sound = "005-System05"

    

    # Desert Eagle

    $data_weapons[7].range = 5

    $data_weapons[7].group_id = 2

    $data_weapons[7].rap = 18

    $data_weapons[7].mouse_face = true

    $data_weapons[7].base_accuracy = 90

    $data_weapons[7].deterioration = 8

    $data_weapons[7].ammo_type = 1

    $data_weapons[7].capacity = 8

    $data_weapons[7].delay = 25

    $data_weapons[7].ddelay = 2

    $data_weapons[7].zeropoint = "target"

    $data_weapons[7].spread = 1

    $data_weapons[7].piercing = 6

    $data_weapons[7].animations = [114,115,116,117]

    $data_weapons[7].reload_time = 15

    $data_weapons[7].reload_sound = "005-System05"

    

    # Machine gun

    $data_weapons[8].range = 3

    $data_weapons[8].group_id = 3

    $data_weapons[8].rap = 2

    $data_weapons[8].mouse_face = true

    $data_weapons[8].base_accuracy = 90

    $data_weapons[8].deterioration = 10

    $data_weapons[8].ammo_type = 3

    $data_weapons[8].capacity = 32

    $data_weapons[8].delay = 6

    $data_weapons[8].ddelay = 0

    $data_weapons[8].zeropoint = "target"

    $data_weapons[8].spread = 1

    $data_weapons[8].animations = [114,115,116,117]

    $data_weapons[8].piercing = 6

    $data_weapons[8].reload_time = 2

    $data_weapons[8].reload_sound = "005-System05"

    

    # Shotgun

    $data_weapons[9].range = 4

    $data_weapons[9].group_id = 3

    $data_weapons[9].rap = 20

    $data_weapons[9].mouse_face = true

    $data_weapons[9].base_accuracy = 90

    $data_weapons[9].deterioration = 25

    $data_weapons[9].ammo_type = 4

    $data_weapons[9].capacity = 12

    $data_weapons[9].delay = 45

    $data_weapons[9].ddelay = 5

    $data_weapons[9].zeropoint = "target"

    $data_weapons[9].spread = 48

    $data_weapons[9].piercing = 4

    $data_weapons[9].animations = [114,115,116,117]

    $data_weapons[9].multihit = 3

    $data_weapons[9].reload_time = 10

    $data_weapons[9].reload_sound = "005-System05"

    

    # Grenade Launcher

    $data_weapons[10].range = 6

    $data_weapons[10].group_id = 4

    $data_weapons[10].rap = 33

    $data_weapons[10].mouse_face = true

    $data_weapons[10].base_accuracy = 100

    $data_weapons[10].deterioration = 10

    $data_weapons[10].ammo_type = 5

    $data_weapons[10].capacity = 1

    $data_weapons[10].delay = 20

    $data_weapons[10].ddelay = 80

    $data_weapons[10].zeropoint = "target"

    $data_weapons[10].spread = 78

    $data_weapons[10].piercing = 6

    $data_weapons[10].multihit = 99

    $data_weapons[10].hurt_self = true

    $data_weapons[10].reload_time = 100

    $data_weapons[10].reload_sound = "005-System05"

    

    # Dual Blades

    $data_weapons[11].range = 1

    $data_weapons[11].group_id = 1

    $data_weapons[11].rap = 16

    $data_weapons[11].mouse_face = true

    $data_weapons[11].base_accuracy = 100

    $data_weapons[11].deterioration = 100

    $data_weapons[11].ammo_type = nil

    $data_weapons[11].capacity = 1

    $data_weapons[11].delay = 17

    $data_weapons[11].ddelay = 0

    $data_weapons[11].spread = 32

    $data_weapons[11].piercing = 6

    $data_weapons[11].animations = [127,128,129,130]

    $data_weapons[11].multihit = 3

    $data_weapons[11].zeropoint = "target"

    

    # Weak Zombie Bite

    $data_weapons[15].range = 1

    $data_weapons[15].group_id = 1

    $data_weapons[15].rap = 16

    $data_weapons[15].mouse_face = true

    $data_weapons[15].base_accuracy = 100

    $data_weapons[15].deterioration = 150

    $data_weapons[15].ammo_type = nil

    $data_weapons[15].capacity = 1

    $data_weapons[15].delay = 5

    $data_weapons[15].ddelay = 0

    $data_weapons[15].zeropoint = "target"

    $data_weapons[15].spread = 0

    $data_weapons[15].piercing = 6

    

    # Zombie Bite

    $data_weapons[17].range = 1

    $data_weapons[17].group_id = 1

    $data_weapons[17].rap = 16

    $data_weapons[17].mouse_face = true

    $data_weapons[17].base_accuracy = 100

    $data_weapons[17].deterioration = 150

    $data_weapons[17].ammo_type = nil

    $data_weapons[17].capacity = 1

    $data_weapons[17].delay = 5

    $data_weapons[17].ddelay = 0

    $data_weapons[17].zeropoint = "target"

    $data_weapons[17].spread = 0

    $data_weapons[17].piercing = 6

    

    # Zombie Spew

    $data_weapons[16].range = 3

    $data_weapons[16].group_id = 1

    $data_weapons[16].rap = 16

    $data_weapons[16].mouse_face = true

    $data_weapons[16].base_accuracy = 75

    $data_weapons[16].deterioration = 8

    $data_weapons[16].ammo_type = nil

    $data_weapons[16].capacity = 1

    $data_weapons[16].delay = 60

    $data_weapons[16].ddelay = 25

    $data_weapons[16].zeropoint = "target"

    $data_weapons[16].spread = 64

    $data_weapons[16].piercing = 6

    

    # Bronze Mace (For zombies!)

    $data_weapons[25].range = 1

    $data_weapons[25].group_id = 2

    $data_weapons[25].rap = 25

    $data_weapons[25].base_accuracy = 100

    $data_weapons[25].deterioration = 100

    $data_weapons[25].ammo_type = nil

    $data_weapons[25].delay = 30

    $data_weapons[25].ddelay = 0

    $data_weapons[25].zeropoint = "direction"

    $data_weapons[25].spread = 24

    $data_weapons[25].piercing = 7

    #========== End Weapon Inits ============

  end

  

  #Init Skills

  def init_skills

    $data_skills[15].weapon_id = 15

    $data_skills[16].weapon_id = 16

    $data_skills[17].weapon_id = 17

    

    $data_skills[6].iid = 1

    $data_skills[6].action_id = 0

    $data_skills[6].cursor = "lens"

    

    $data_skills[7].iid = 1

    $data_skills[7].action_id = 1

    $data_skills[7].cursor = "magic"

    

    $data_skills[8].iid = 1

    $data_skills[8].action_id = 2

    $data_skills[8].cursor = "gauntlet_007"

    

    $data_skills[9].iid = 1

    $data_skills[9].action_id = 3

    $data_skills[9].cursor = "skill_016"

    

    $data_skills[10].iid = 1

    $data_skills[10].action_id = 4

    $data_skills[10].cursor = "up"

    

    $data_skills[11].iid = 1

    $data_skills[11].action_id = 5

    $data_skills[11].cursor = "down"

    

    $data_skills[12].iid = 1

    $data_skills[12].action_id = 6

    $data_skills[12].cursor = "glasses"

    

    $data_skills[13].iid = 1

    $data_skills[13].action_id = 7

    $data_skills[13].cursor = "strike"

    

    # Ghostly Wail

    $data_skills[19].range = 3

    $data_skills[19].rap = 35

    $data_skills[19].base_accuracy = 100

    $data_skills[19].deterioration = 25

    $data_skills[19].delay = 150

    $data_skills[19].ddelay = 150

    $data_skills[19].zeropoint = "target"

    $data_skills[19].spread = 128

    $data_skills[19].piercing = 6

    

    # Ghostly Wail 2

    $data_skills[20].range = 2

    $data_skills[20].rap = 35

    $data_skills[20].base_accuracy = 100

    $data_skills[20].deterioration = 25

    $data_skills[20].delay = 50

    $data_skills[20].ddelay = 50

    $data_skills[20].zeropoint = "target"

    $data_skills[20].spread = 32

    $data_skills[20].piercing = 6

    

    # Ghostly Wail 3

    $data_skills[21].range = 10

    $data_skills[21].rap = 35

    $data_skills[21].base_accuracy = 100

    $data_skills[21].deterioration = 5

    $data_skills[21].delay = 75

    $data_skills[21].ddelay = 75

    $data_skills[21].zeropoint = "target"

    $data_skills[21].spread = 0

    $data_skills[21].piercing = 6

    

    # Ghostly Wail 4

    $data_skills[22].range = 10

    $data_skills[22].rap = 35

    $data_skills[22].base_accuracy = 100

    $data_skills[22].deterioration = 5

    $data_skills[22].delay = 20

    $data_skills[22].ddelay = 20

    $data_skills[22].zeropoint = "target"

    $data_skills[22].spread = 0

    $data_skills[22].piercing = 6

    

    # Ghostly Wail 5

    $data_skills[23].range = 10

    $data_skills[23].rap = 35

    $data_skills[23].base_accuracy = 100

    $data_skills[23].deterioration = 5

    $data_skills[23].delay = 55

    $data_skills[23].ddelay = 55

    $data_skills[23].zeropoint = "target"

    $data_skills[23].spread = 64

    $data_skills[23].piercing = 6

    

    # Knife Combo

    $data_skills[30].range = 1

    $data_skills[30].rap = 25

    $data_skills[30].base_accuracy = 100

    $data_skills[30].deterioration = 200

    $data_skills[30].ddelay = 25

    $data_skills[30].delay = 25

    $data_skills[30].piercing = 7

    $data_skills[30].multihit = 5

    $data_skills[30].cursor = "magic"

    $data_skills[30].zeropoint = "target"

    $data_skills[30].spread = 48

    $data_skills[30].weapon_dependency = [1,4,11]

    

    # Dash

    $data_skills[31].range = 1

    $data_skills[31].rap = 75

    $data_skills[31].base_accuracy = 100

    $data_skills[31].deterioration = 50

    $data_skills[31].ddelay = 0

    $data_skills[31].delay = 0

    $data_skills[31].piercing = 7

    $data_skills[31].cursor = "skill_015"

    $data_skills[31].zeropoint = "self"

    $data_skills[31].spread = 0

    $data_skills[31].target_move = [200,5,0,10]

    

    # Fireball

    $data_skills[33].range = 6

    $data_skills[33].rap = 25

    $data_skills[33].base_accuracy = 100

    $data_skills[33].deterioration = 20

    $data_skills[33].ddelay = 60

    $data_skills[33].delay = 20

    $data_skills[33].piercing = 7

    $data_skills[33].multihit = 5

    $data_skills[33].cursor = "magic"

    $data_skills[33].zeropoint = "enemy"

    $data_skills[33].spread = 0

    

    # IceBolt

    $data_skills[34].range = 6

    $data_skills[34].rap = 25

    $data_skills[34].base_accuracy = 100

    $data_skills[34].deterioration = 20

    $data_skills[34].ddelay = 120

    $data_skills[34].delay = 120

    $data_skills[34].piercing = 7

    $data_skills[34].multihit = 5

    $data_skills[34].cursor = "magic"

    $data_skills[34].zeropoint = "enemy"

    $data_skills[34].spread = 0

    

    # Fireball (Enemy)

    $data_skills[35].range = 6

    $data_skills[35].rap = 25

    $data_skills[35].base_accuracy = 100

    $data_skills[35].deterioration = 20

    $data_skills[35].ddelay = 50

    $data_skills[35].delay = 50

    $data_skills[35].piercing = 7

    $data_skills[35].multihit = 5

    $data_skills[35].cursor = "magic"

    $data_skills[35].zeropoint = "target"

    $data_skills[35].spread = 0

    

  end

  #Init Ammo Types

  def init_ammo

    # Handgun Bullets

    @ammo.set_max(1,150)

    # Crossbow Bolts

    @ammo.set_max(2,25)

    # Auto-ammo (machine guns, etc)

    @ammo.set_max(3,650)

    # Shotgun Ammo

    @ammo.set_max(4,75)

    # Grenades

    @ammo.set_max(5,10)

  end

  

  #Init Hostilies

  def init_hostilities

    @ai.assign_hostile(0,1)

    @ai.assign_hostile(0,2)

    @ai.assign_hostile(2,3)

    @ai.assign_hostile(3,4)

    @ai.assign_hostile(4,5)

  end

  

end

I really need this. I'll be incrediably greatful to anyone who can take up this request. Thanks in advance :)
 
In response to your first question, I think you may have a version of my script with some bugs in it. Try the version I have posted here, and it should work. I just tested it with the screen size you had the script working with, and it seemed to work perfectly.
 
Looks like the second script error is a direct result of the fact that I overwrote the Spriteset_Map initialize method. You should have mentioned that my script was below theirs. Go to lines 4403-4414 of the first script you posted, and cut them out. Then, replace lines 268-315 of my script with this:

Code:
  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    width = Screen_Data::Screen_Data[2].to_s.to_i

    height = Screen_Data::Screen_Data[3].to_s.to_i

    # Make viewports

    @viewport1 = Viewport.new(0, 0, width, height)

    @viewport2 = Viewport.new(0, 0, width, height)

    @viewport3 = Viewport.new(0, 0, width, height)

    @viewport2.z = 200

    @viewport3.z = 5000

    # Make tilemap

    @tilemap = Tilemap.new(@viewport1)

    @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)

    for i in 0..6

      autotile_name = $game_map.autotile_names[i]

      @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)

    end

    @tilemap.map_data = $game_map.data

    @tilemap.priorities = $game_map.priorities

    # Make panorama plane

    @panorama = Plane.new(@viewport1)

    @panorama.z = -1000

    # Make fog plane

    @fog = Plane.new(@viewport1)

    @fog.z = 3000

    # Make character sprites

    @character_sprites = []

    for i in $game_map.events.keys.sort

      sprite = Sprite_Character.new(@viewport1, $game_map.events[i])

      @character_sprites.push(sprite)

    end

    @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))

    # Make weather

    @weather = RPG::Weather.new(@viewport1)

    # Make picture sprites

    @picture_sprites = []

    for i in 1..50

      @picture_sprites.push(Sprite_Picture.new(@viewport2,

        $game_screen.pictures[i]))

    end

    # Make timer sprite

    @timer_sprite = Sprite_Timer.new

    # Frame update

    update

    for i in 0...$game_map.player_characters.size

      sprite = Sprite_Character.new(@viewport1, $game_map.player_characters[i])

      @character_sprites.push(sprite)

    end

    @cursor = Sprite_Cursor.new(@viewport3)

  end

end

Also, based on the version count, it looks like I may have ninja'd an edit into the script when I posted it onto my site. Another thing to note is that it needs an update so that it will display properly in Win7 and Vista. (Which have different window sizes.) To fix this, replace lines 109-125 of my script with the following:

Code:
#--------------------------------------------------------------------------

  # * Handle Window Size Changes

  #--------------------------------------------------------------------------

  def resize_window(width, height)

    getSystemMetrics = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')

    moveWindow = Win32API.new('user32','MoveWindow',

      ['l','i','i','i','i','l'],'l')

    findWindowEx = Win32API.new('user32','FindWindowEx',['l','l','p','p'],'i')

    window = findWindowEx.call(0,0,"RGSS Player",0)

    screenwidth = getSystemMetrics.call(0)

    screenheight = getSystemMetrics.call(1)

    border_width = getSystemMetrics.call(5) + getSystemMetrics.call(45)

    windowwidth = width + (border_width * 2)

    border_height = getSystemMetrics.call(6) + getSystemMetrics.call(46)

    windowheight = height + (border_height * 2) + getSystemMetrics.call(4)

    moveWindow.call(window,(screenwidth - windowwidth) / 2,

      (screenheight - windowheight) / 2,windowwidth,windowheight, 2)

  end
 
Thats awesome, it almost works. Even though the scripts now run fine together, the battle system has a problem. Removing lines 4403-4414 (although it does solve the conflicting scripts) only allows you to attack anything once, and other things like the 8 directional walking and reloading don't work at all. I tried putting the lines back in and removing the screen size script and it worked fine. But as soon as you remove the lines it doesn't. To show you what I mean, I've uploaded a demo of it. Click anywhere to attack. As soon as you remove the '#' from lines 4403-4414 and remove your script you'll see how it should work. Any ideas?:

http://rapidshare.com/files/423676460/Script_Problem.exe

(Oh, and I swear last time you helped me out on LMS I said I wouldn't bother you again. Sorry :/ )

(Oh, and one final question, any way to disable the 'real' mouse from being visible when you mouse over the window when it's not in full screen?)
 
All right, I found the problem for this, I think. Go to lines 182-256 of my script, and replace them with the following:

[Removed. See below]

I'd tell you to remove the code I took from the other script, but it doesn't matter, since this overwrites it anyway.

Actually, it looks like you didn't add the second edit I mentioned last night, which means that there is a black bar on the bottom of the map and battle screens in Vista and Win7, as well as many versions of XP with custom themes. So, just replace my script with this one, below, and it should work fine.

Code:
#≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

# ** Glitchfinder's Screen Size Editor                           [RPG Maker XP]

#    Version 1.00

#------------------------------------------------------------------------------

#  This script is meant to allow the programmer to change the screen size of

#  the RPG Maker XP window.

#==============================================================================

# * Version History

#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#   Version 1.00 ------------------------------------------------- (????-??-??)

#     - Initial version

#     - Author: Glitchfinder

#==============================================================================

# * Instructions

#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#  Place this script above Main, and below the default scripts. (I

#  realize this is obvious to most, but some people don't get it.)

#

#  To change the default screen size, simply edit the Screen_Data module, which

#  uses the following format:

#  [width (in tiles), height (in tiles), width, height]

#

#  To edit the size of the screen in game, simply use the following function:

#  Screen_Size.change_screen_size(width, height)

#  The width and height must be the number of tiles that you want the screen to

#  display in each direction.

#==============================================================================

# * Glitchfinder's Advice

#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#  This script is meant for people with a medium to high level of scripting

#  knowledge and ability. If you are unsure of your abilities, or don't know

#  how to script, then it would be a good idea to avoid this script.

#

#  If you are editing the default screen size in the Screen_Data module, the

#  second width and height should be the same as the first width and height

#  multiplied by 32, so that the player will display properly on the map.

#

#  If you make the screen size larger than the default, you must make sure that

#  all of your maps are at least that large, or you will get a fatal error.

#

#  If you use this script, you must be prepared to create your own custom

#  menus, titles, gameovers, etc. to fit the new screen size.

#==============================================================================

# * Contact

#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#  Glitchfinder, the author of this script, may be contacted through his

#  website, found at [url=http://www.glitchkey.com]http://www.glitchkey.com[/url]

#

#  You may also find Glitchfinder at [url=http://www.hbgames.org]http://www.hbgames.org[/url]

#==============================================================================

# * Usage

#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#  This script may be used with the following terms and conditions:

#

#    1. This script is free to use in any noncommercial project. If you wish to

#       use this script in a commercial (paid) project, please contact

#       Glitchfinder at his website.

#    2. This script may only be hosted at the following domains:

#         [url=http://www.glitchkey.com]http://www.glitchkey.com[/url]

#         [url=http://www.hbgames.org]http://www.hbgames.org[/url]

#    3. If you wish to host this script elsewhere, please contact Glitchfinder.

#    4. If you wish to translate this script, please contact Glitchfinder. He

#       will need the web address that you plan to host the script at, as well

#       as the language this script is being translated to.

#    5. This header must remain intact at all times.

#    6. Glitchfinder remains the sole owner of this code. He may modify or

#       revoke this license at any time, for any reason.

#    7. Any code derived from code within this script is owned by Glitchfinder,

#       and you must have his permission to publish, host, or distribute his

#       code.

#    8. This license applies to all code derived from the code within this

#       script.

#    9. If you use this script within your project, you must include visible

#       credit to Glitchfinder, within reason.

#≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

 

#==============================================================================

# ** Screen_Size

#------------------------------------------------------------------------------

#  This module handles the information regarding screen size. It is used within

#  the Screen_Size, Game_Map, Game_Player, Spriteset_Map, and Spriteset_Battle

#  classes.

#==============================================================================

 

module Screen_Data

    Screen_Data = [15, 10, 480, 320]

end

 

#==============================================================================

# ** Screen_Size

#------------------------------------------------------------------------------

#  This class handles the screen size. It is used within the Game_Map,

#  Game_Actor, Spriteset_Map, and Spriteset_Battle classes.

#==============================================================================

 

class Screen_Size

  #--------------------------------------------------------------------------

  # * Change Screen Size

  #--------------------------------------------------------------------------

  def change_screen_size(width, height)

    window_width = width * 32

    window_height = height * 32

    Screen_Data::Screen_Data[0] = width

    Screen_Data::Screen_Data[1] = height

    Screen_Data::Screen_Data[2] = window_width

    Screen_Data::Screen_Data[3] = window_height

    self.resize_window((width * 32), (height * 32))

  end

  #--------------------------------------------------------------------------

  # * Handle Window Size Changes

  #--------------------------------------------------------------------------

  def resize_window(width, height)

    getSystemMetrics = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')

    moveWindow = Win32API.new('user32','MoveWindow',

      ['l','i','i','i','i','l'],'l')

    findWindowEx = Win32API.new('user32','FindWindowEx',['l','l','p','p'],'i')

    window = findWindowEx.call(0,0,"RGSS Player",0)

    screenwidth = getSystemMetrics.call(0)

    screenheight = getSystemMetrics.call(1)

    border_width = getSystemMetrics.call(5) + getSystemMetrics.call(45)

    windowwidth = width + (border_width * 2)

    border_height = getSystemMetrics.call(6) + getSystemMetrics.call(46)

    windowheight = height + (border_height * 2) + getSystemMetrics.call(4)

    moveWindow.call(window,(screenwidth - windowwidth) / 2,

      (screenheight - windowheight) / 2,windowwidth,windowheight, 2)

  end

end

 

#==============================================================================

# ** Game_Map

#------------------------------------------------------------------------------

#  This class handles the map. It includes scrolling and passable determining

#  functions. Refer to "$game_map" for the instance of this class.

#==============================================================================

 

class Game_Map

  #--------------------------------------------------------------------------

  # * Scroll Down

  #     distance : scroll distance

  #--------------------------------------------------------------------------

  def scroll_down(distance)

    @display_y = [@display_y + distance,

      (self.height - Screen_Data::Screen_Data[1].to_s.to_i) * 128].min

  end

  #--------------------------------------------------------------------------

  # * Scroll Right

  #     distance : scroll distance

  #--------------------------------------------------------------------------

  def scroll_right(distance)

    screen = Screen_Size.new

    @display_x = [@display_x + distance,

      (self.width - Screen_Data::Screen_Data[0].to_s.to_i) * 128].min

    end

  end

#==============================================================================

# ** Game_Player

#------------------------------------------------------------------------------

#  This class handles the player. Its functions include event starting

#  determinants and map scrolling. Refer to "$game_player" for the one

#  instance of this class.

#==============================================================================

 

class Game_Player < Game_Character

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  alias glitchfinder_screen_resizer_initialize initialize

  def initialize

    width = (Screen_Data::Screen_Data[2].to_s.to_i / 2)

    height = (Screen_Data::Screen_Data[3].to_s.to_i / 2)

    @center_x = (width - 16) * 4

    @center_y = (height - 16) * 4

    glitchfinder_screen_resizer_initialize

  end

  #--------------------------------------------------------------------------

  # * Set Map Display Position to Center of Screen

  #--------------------------------------------------------------------------

  def center(x, y)

    max_x = ($game_map.width - Screen_Data::Screen_Data[0].to_s.to_i) * 128

    max_y = ($game_map.height - Screen_Data::Screen_Data[1].to_s.to_i) * 128

    $game_map.display_x = [0, [x * 128 - @center_x, max_x].min].max

    $game_map.display_y = [0, [y * 128 - @center_y, max_y].min].max

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # Remember whether or not moving in local variables

    last_moving = moving?

    if @dirfix_time > 0

      @dirfix_time -= 1

    end

    if @action_ready > 0

      @action_ready -= 1

    end

    if @action_freeze > 0

      @action_freeze -= 1

    end

    if @move_freeze > 0

      @move_freeze -= 1

    end

    if @regen_now % 21 == 0

      for i in 0...$game_party.actors.size

        $game_party.actors[i].ap += @action_regen

        if $game_party.actors[i].ap > 100

          $game_party.actors[i].ap = 100

        end

      end

      @regen_now = 1

    else

      @regen_now += 1

    end

    if $game_party.actors[0].weapon_id != 0

      if $data_weapons[$game_party.actors[0].weapon_id].weapon_graphic != nil and $data_weapons[$game_party.actors[0].weapon_id].weapon_graphic != @weapon

        @weapon = $data_weapons[$game_party.actors[0].weapon_id].weapon_graphic

      elsif $data_weapons[$game_party.actors[0].weapon_id].weapon_graphic == nil and @weapon != nil

        @weapon = nil

      end

    end

    # If moving, event running, move route forcing, and message window

    # display are all not occurring

    unless moving? or $game_system.map_interpreter.running? or

           @move_route_forcing or $game_temp.message_window_showing or stuck?

      # Move player in the direction the directional button is being pressed

      #Input.update

      if Input.press?(Input::X) or Input.press?(Input::LEFT)

        move_left

      end

      if Input.press?(Input::Y) or Input.press?(Input::DOWN)

        move_down

      end

      if Input.press?(Input::Z) or Input.press?(Input::RIGHT)

        move_right

      end

      if Input.press?(Input::R) or Input.press?(Input::UP)

        move_up

      end

    end

    # Remember coordinates in local variables

    last_real_x = @real_x

    last_real_y = @real_y

    super

    # If character moves down and is positioned lower than the center

    # of the screen

    if @real_y > last_real_y and @real_y - $game_map.display_y > @center_y

      # Scroll map down

      $game_map.scroll_down(@real_y - last_real_y)

    end

    # If character moves left and is positioned more let on-screen than

    # center

    if @real_x < last_real_x and @real_x - $game_map.display_x < @center_x

      # Scroll map left

      $game_map.scroll_left(last_real_x - @real_x)

    end

    # If character moves right and is positioned more right on-screen than

    # center

    if @real_x > last_real_x and @real_x - $game_map.display_x > @center_x

      # Scroll map right

      $game_map.scroll_right(@real_x - last_real_x)

    end

    # If character moves up and is positioned higher than the center

    # of the screen

    if @real_y < last_real_y and @real_y - $game_map.display_y < @center_y

      # Scroll map up

      $game_map.scroll_up(last_real_y - @real_y)

    end    

    # If not moving

    unless moving?

      # If player was moving last time

      if last_moving

        # Event determinant is via touch of same position event

        result = check_event_trigger_here([1,2])

        # If event which started does not exist

        if result == false

          # Disregard if debug mode is ON and ctrl key was pressed

          unless $DEBUG and Input.press?(Input::CTRL)

            # Encounter countdown

            if @encounter_count > 0

              @encounter_count -= 1

            end

          end

        end

      end

      # If C button was pressed

      if Input.trigger?(Input::C) and not $game_player.casting?

        # Same position and front event determinant

        check_event_trigger_here([0])

        check_event_trigger_there([0,1,2])

      end

    end

  end

end

 

#==============================================================================

# ** Spriteset_Map

#------------------------------------------------------------------------------

#  This class brings together map screen sprites, tilemaps, etc.

#  It's used within the Scene_Map class.

#==============================================================================

 

class Spriteset_Map

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    width = Screen_Data::Screen_Data[2].to_s.to_i

    height = Screen_Data::Screen_Data[3].to_s.to_i

    # Make viewports

    @viewport1 = Viewport.new(0, 0, width, height)

    @viewport2 = Viewport.new(0, 0, width, height)

    @viewport3 = Viewport.new(0, 0, width, height)

    @viewport2.z = 200

    @viewport3.z = 5000

    # Make tilemap

    @tilemap = Tilemap.new(@viewport1)

    @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)

    for i in 0..6

      autotile_name = $game_map.autotile_names[i]

      @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)

    end

    @tilemap.map_data = $game_map.data

    @tilemap.priorities = $game_map.priorities

    # Make panorama plane

    @panorama = Plane.new(@viewport1)

    @panorama.z = -1000

    # Make fog plane

    @fog = Plane.new(@viewport1)

    @fog.z = 3000

    # Make character sprites

    @character_sprites = []

    for i in $game_map.events.keys.sort

      sprite = Sprite_Character.new(@viewport1, $game_map.events[i])

      @character_sprites.push(sprite)

    end

    @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))

    # Make weather

    @weather = RPG::Weather.new(@viewport1)

    # Make picture sprites

    @picture_sprites = []

    for i in 1..50

      @picture_sprites.push(Sprite_Picture.new(@viewport2,

        $game_screen.pictures[i]))

    end

    # Make timer sprite

    @timer_sprite = Sprite_Timer.new

    # Frame update

    update

    for i in 0...$game_map.player_characters.size

      sprite = Sprite_Character.new(@viewport1, $game_map.player_characters[i])

      @character_sprites.push(sprite)

    end

    @cursor = Sprite_Cursor.new(@viewport3)

  end

end

#==============================================================================

# ** Spriteset_Battle

#------------------------------------------------------------------------------

#  This class brings together battle screen sprites. It's used within

#  the Scene_Battle class.

#==============================================================================

 

class Spriteset_Battle

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    width = Screen_Data::Screen_Data[2].to_s.to_i

    height = Screen_Data::Screen_Data[3].to_s.to_i

    # Make viewports

    @viewport1 = Viewport.new(0, 0, width, ((height * 2) / 3).to_i)

    @viewport2 = Viewport.new(0, 0, width, height)

    @viewport3 = Viewport.new(0, 0, width, height)

    @viewport4 = Viewport.new(0, 0, width, height)

    @viewport2.z = 101

    @viewport3.z = 200

    @viewport4.z = 5000

    # Make battleback sprite

    @battleback_sprite = Sprite.new(@viewport1)

    # Make enemy sprites

    @enemy_sprites = []

    for enemy in $game_troop.enemies.reverse

      @enemy_sprites.push(Sprite_Battler.new(@viewport1, enemy))

    end

    # Make actor sprites

    @actor_sprites = []

    @actor_sprites.push(Sprite_Battler.new(@viewport2))

    @actor_sprites.push(Sprite_Battler.new(@viewport2))

    @actor_sprites.push(Sprite_Battler.new(@viewport2))

    @actor_sprites.push(Sprite_Battler.new(@viewport2))

    # Make weather

    @weather = RPG::Weather.new(@viewport1)

    # Make picture sprites

    @picture_sprites = []

    for i in 51..100

      @picture_sprites.push(Sprite_Picture.new(@viewport3,

        $game_screen.pictures[i]))

    end

    # Make timer sprite

    @timer_sprite = Sprite_Timer.new

    # Frame update

    update

  end

end

 

#==============================================================================

# ** Scene_Title

#------------------------------------------------------------------------------

#  This class performs title screen processing.

#==============================================================================

 

class Scene_Title

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    # If battle test

    if $BTEST

      battle_test

      return

    end

    # Load database

    $data_actors        = load_data("Data/Actors.rxdata")

    $data_classes       = load_data("Data/Classes.rxdata")

    $data_skills        = load_data("Data/Skills.rxdata")

    $data_items         = load_data("Data/Items.rxdata")

    $data_weapons       = load_data("Data/Weapons.rxdata")

    $data_armors        = load_data("Data/Armors.rxdata")

    $data_enemies       = load_data("Data/Enemies.rxdata")

    $data_troops        = load_data("Data/Troops.rxdata")

    $data_states        = load_data("Data/States.rxdata")

    $data_animations    = load_data("Data/Animations.rxdata")

    $data_tilesets      = load_data("Data/Tilesets.rxdata")

    $data_common_events = load_data("Data/CommonEvents.rxdata")

    $data_system        = load_data("Data/System.rxdata")

    @continue_enabled = false

    for i in 0..3

      if FileTest.exist?("Save#{i+1}.rxdata")

        @continue_enabled = true

      end

    end

    command_new_game

  end

end

 

#==============================================================================

# ** Screen_Resizer

#------------------------------------------------------------------------------

#  This will begin the screen size change.

#==============================================================================

begin

  width = Screen_Data::Screen_Data[0].to_s.to_i

  height = Screen_Data::Screen_Data[1].to_s.to_i

  screen = Screen_Size.new

  screen.change_screen_size(width, height)

end

As for hiding the mouse , it's tough. You have to set up a check to detect fullscreen, which is inaccurate at best. Plus, if you press f1 while in windowed mode, you can't see the mouse when you use that menu. You're better off just modding the actual mouse, using a custom-made .ico file. Check the mouse API in Win32API if you're interested in that.
 
Ah, thats perfect thanks. Really helped me out there. However, editing the mouse itself won't work for this game, as TERG's script changes the picture used for the mouse depending on what you mouse over and what skill you're using. So that wouldn't be any good. Is there no other way of doing it?

On a totally unrelated note (thought I'd post this here and save making a new topic) is there a quick and simple way of adding sprite animations to this script for each weapon? The game already has animations built in, but is there a way to have sprite animations for them as well? So whenever you attack with a certain weapon, the sprite "[ACTOR NAME]_[WEAPON NAME]" plays the moving animation for the direction the player's facing, like the system in Mr Mo's ABS. So something like:

$data_weapons[1].range = 1
$data_weapons[1].group_id = 1
$data_weapons[1].rap = 8
$data_weapons[1].mouse_face = true
$data_weapons[1].base_accuracy = 100
$data_weapons[1].deterioration = 200
$data_weapons[1].ammo_type = nil
$data_weapons[1].delay = 8
$data_weapons[1].ddelay = 0
$data_weapons[1].spread = 32
$data_weapons[1].animations = [118,119,120,121]
$data_weapons[1].piercing = 7
$data_weapons[1].target_move = [25,-2,0,5]
$data_weapons[1].multihit = 3
$data_weapons[1].zeropoint = "target"
$data_weapons[1].spriteanimation = $actorname + "_weapon1"

Thanks to anyone who can help me out with this new request.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top