Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
- # Mouse Controller Enhancement Script by Nathmatt
- # Version: 1.74
- # Type: Add On
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
- #
- # This work is protected by the following license:
- # #----------------------------------------------------------------------------
- # #
- # # Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
- # # ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
- # #
- # # You are free:
- # #
- # # to Share - to copy, distribute and transmit the work
- # # to Remix - to adapt the work
- # #
- # # Under the following conditions:
- # #
- # # Attribution. You must attribute the work in the manner specified by the
- # # author or licensor (but not in any way that suggests that they endorse you
- # # or your use of the work).
- # #
- # # Noncommercial. You may not use this work for commercial purposes.
- # #
- # # Share alike. If you alter, transform, or build upon this work, you may
- # # distribute the resulting work only under the same or similar license to
- # # this one.
- # #
- # # - For any reuse or distribution, you must make clear to others the license
- # # terms of this work. The best way to do this is with a link to this web
- # # page.
- # #
- # # - Any of the above conditions can be waived if you get permission from the
- # # copyright holder.
- # #
- # # - Nothing in this license impairs or restricts the author's moral rights.
- # #
- # #----------------------------------------------------------------------------
- #
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
- # Instructions:
- #
- # To use the event effects in this script you will need to name the following.
- #
- # definitions
- # d = 2 down, 4 left 6, right, or 8 up
- # right click to access an events command list
- #
- # \ignore Use on events you want to be walkable
- #
- # \msg[message] This will add the message above the highlighted event
- #
- # \directionfix[d] If an event has a graphic and needs a specific direction
- # they must be named this d as the open direction
- #
- # \direction[d] If an event has no graphic or isn't direction specific
- # they must be named this d as the open direction
- #
- # \commands This will create a command list for each page with the
- # name of the first avalible comment
- #
- # \curser[graphic] This will change the graphic of the curser while
- # over that event
- #
- # \auto This will start the event as soon as you click it
- #
- # \door[id] This will run the pages of an event as the following
- # id is the item id needed to unlock the door
- # first page when door is locked
- # second page when unlocking the door
- # third page any time after being unlocked
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
- # Script Calls:
- #
- # $MCES.disabled = true/false whether or not this script is disabled
- #
- # $MCES.movement_disabled = true/false whether or not movement is disabled
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
- module MCES
- Version = 1.74
- #============================================================================
- # MCES::Config
- #----------------------------------------------------------------------------
- # The configuration for $MCES
- #============================================================================
- module Config
- No_Walk_Tag = 7 # The terrain tag for unreachable locations
- Text_Size = 20 # The size of the event name text
- Text_Color = [0,0,160] # The color of the event name text
- Click_Graphic = false # The sprite placed for move target
- Range = 30 # The range for allows click movement
- end
- #============================================================================
- # MCES::Cache
- #----------------------------------------------------------------------------
- # Stores data for use throughout $MCES
- #============================================================================
- module Cache
- PathDirs = [[0, 1, 2], [-1, 0, 4], [1, 0, 6], [0, -1, 8]]
- TDirs = [[0, true], [1, true], [2, true], [3, true], [4, true], [5, true],
- [6, true], [7, true], [8, true], [9, true]]
- DirOffsets = [[0, 0], [-1, 1], [0, 1], [1, 1], [-1, 0], [0, 0], [1, 0],
- [-1, -1], [0, -1], [1, -1]]
- Direction = 0
- Commands = 1
- Curser = 2
- Auto = 3
- Door = 4
- Msg = 5
- Ignore = 6
- end
- #============================================================================
- # MCES::Processor
- #----------------------------------------------------------------------------
- # This class performs the $MCES's processing.
- #============================================================================
- class Processor
- attr_accessor :item,:curser_lock,:disabled,:movement_disabled,:location
- attr_reader :event_start
- def initialize
- @disabled,@movement_disabled,@location = false,false,[]
- @lwait,@rwait,curser_lock,@carry_sprite = 0,0,false,Sprite.new
- @carry_sprite.z = 999999;@carry_sprite.bitmap = Bitmap.new(24, 24)
- @mouse_set = true
- end
- def update
- if @lwait > 0;@lwait-= 1;end
- if @rwait > 0;@rwait-= 1;end
- @item = $data_items[@item] if @item.is_a?(Numeric)
- return if @disabled
- if !$scene.is_a?(Scene_Map);@lwait = 5;return;end
- if Input.trigger?(Input::Key['Mouse Left']) &&
- !$game_temp.message_window_showing && @lwait == 0
- @lwait = 5
- check_left
- elsif Input.trigger?(Input::Key['Mouse Right']) && @rwait == 0
- @rwait = 5
- check_right
- end
- check_player
- check_carry
- check_mouse
- if @command_window != nil && !@command_window.disposed?
- @command_window.update
- end
- end
- def check_left
- x,y = mouse_tile
- return if check_event || !$game_map.passable?(x,y,0) || @movement_disabled ||
- check_terrain_tag(x,y) || check_range(x,y,MCES::Config::Range)
- return if @command_window != nil && !@command_window.disposed?
- $game_player.set(x,y)
- end
- def check_event
- $game_map.events.each_value{|event|
- next if event.erased
- if event.mouse_in_area?
- if event.type.include?(MCES::Cache::Ignore)
- return false
- end
- if event.type.include?(MCES::Cache::Auto)
- event.start_event
- return true
- elsif event.type.include?(MCES::Cache::Door)
- event.check_door
- return true
- else
- $game_player.set(event) if !@movement_disabled
- return true
- end
- end}
- return false
- end
- def check_right
- $game_map.events.each_value{|event|
- next if event.erased
- if event.mouse_in_area?
- if event.type.include?(MCES::Cache::Commands)
- return if @command_window != nil && !@command_window.disposed?
- @command_window = Event_Command.new(event)
- return
- end
- end}
- end
- def mouse_tile
- x,y = $mouse.x,$mouse.y
- return (x+$game_map.display_x/4)/32,(y+$game_map.display_y/4)/32
- end
- def check_terrain_tag(x,y)
- return ($game_map.terrain_tag(x,y) == Config::No_Walk_Tag)
- end
- def check_target(x,y=0)
- if x.is_a?(Game_Character)
- c = x
- d = (x.direction_fixed != nil ? x.direction_fixed : x.direction)
- x,y = c.x,c.y
- x += (d == 4 ? -1 : 1) if d != (2 || 8)
- y += (d == 8 ? -1 : 1) if d != (4 || 6)
- end
- return x,y
- end
- def check_player
- return if @request == nil
- count = 4
- characters = [$game_player]
- while characters.size > 0 && count > 0
- char = characters.shift
- result = find_path
- result != nil ? char.force_movement = result : characters.push(char)
- count -= 1
- end
- end
- def check_carry
- @carry_sprite.x,@carry_sprite.y = $mouse.x,$mouse.y
- if @item != nil
- if @carry_curser != @item.icon_name
- @carry_curser = @item.icon_name
- @carry_sprite.bitmap.blt(0, 0, RPG::Cache.icon(@carry_curser),
- Rect.new(0, 0, 24, 24))
- end
- else
- @carry_curser = nil
- @carry_sprite.bitmap.clear
- end
- end
- def check_mouse
- $game_map.events.each_value{|event|
- if event.mouse_in_area?
- next if event.erased
- if event.type.include?(MCES::Cache::Curser)
- $mouse.set_cursor(event.curser)
- @mouse_set = false
- return
- end
- end}
- if !@mouse_set
- return if @curser_lock
- @mouse_set = true
- $mouse.set_cursor(Mouse::MOUSE_ICON)
- end
- end
- def request_path(x, y = nil)
- x,y = check_target(x,y)
- if x != nil && y != nil && @request == nil
- @request = PathRequesting.new(x, y)
- end
- end
- def distance(x,y,tx,ty)
- return Math.hypot((x - tx),(y - ty))
- end
- def check_range(x,y,range)
- pl = $game_player
- return (range <= distance(pl.x,pl.y,x,y))
- end
- def find_path
- request = @request
- if request.open.size == 0;@request = nil;return []end
- found = false
- key = request.open.keys.min {|a, b|
- Math.hypot(a[0] - request.tx, a[1] - request.ty) <=>
- Math.hypot(b[0] - request.tx, b[1] - request.ty)}
- request.closed[key[0], key[1]] = request.open[key]
- request.open.delete(key)
- Cache::PathDirs.each {|dir|
- kx, ky = key[0] + dir[0], key[1] + dir[1]
- if kx == request.tx && ky == request.ty
- request.closed[kx, ky] = dir[2]
- found = true
- break
- elsif request.closed[kx, ky] == 0 &&
- $game_player.passable?(key[0], key[1], dir[2])
- request.open[[kx, ky]] = dir[2]
- end}
- return nil unless found
- @request = nil
- return request.backtrack
- end
- end
- #============================================================================
- # MCES::Msg_Sprite
- #----------------------------------------------------------------------------
- # The msg sprite.
- #============================================================================
- class Msg_Sprite < Sprite
- def initialize(event)
- super()
- @event = event
- self.z,self.opacity = 1000,0
- self.set
- @h = MCES::Config::Text_Size
- @w = event.msg.size*@h
- c = MCES::Config::Text_Color
- self.bitmap = Bitmap.new(@w,@h)
- self.bitmap.font.size = @h
- self.bitmap.font.color = Color.new(c[0],c[1],c[2])
- self.bitmap.draw_text(0,0,@w,@h,event.msg,1)
- end
- def set
- return if !$scene.is_a?(Scene_Map) || @event.erased
- b = @event.get_sprite.inner_bitmap
- xs = @event.get_sprite.x-(@event.get_sprite.cw/2)
- ys = @event.get_sprite.y-@event.get_sprite.ch
- self.x,self.y = xs + (b.width/2)-(@w/2),ys-@h
- end
- def update
- self.set
- return self.opacity = 0 if @event.erased
- if @event.mouse_in_area?
- if self.opacity < 255
- self.opacity += 25
- end
- elsif self.opacity > 0
- self.opacity -= 25
- end
- end
- end
- #============================================================================
- # MCES::Set_Sprite
- #----------------------------------------------------------------------------
- # The set sprite.
- #============================================================================
- class Set_Sprite < Sprite
- def initialize(v)
- super
- self.bitmap = RPG::Cache.picture(MCES::Config::Click_Graphic)
- @x,@y,self.opacity,self.z = 0,0,0,1
- end
- def set(x,y)
- return if MCES::Config::Click_Graphic == false
- @e,x,y = x,x.x,x.y if x.is_a?(Game_Character)
- @x,@y,self.opacity = x,y,255
- end
- def update_screen
- return if self.opacity == 0
- x = ((@x * 128) - $game_map.display_x + 3) / 4
- y = ((@y * 128) - $game_map.display_y + 3) / 4
- self.x,self.y = x,y
- end
- def update
- return if MCES::Config::Click_Graphic == false
- update_screen
- end
- end
- #============================================================================
- # MCES::Event_Command
- #----------------------------------------------------------------------------
- # The event command window.
- #============================================================================
- class Event_Command < Window_Command
- def initialize(event)
- @size = 0
- @event = event
- @main_commands = event.commands
- @array = []
- @main_commands.each{|command|
- @array.push(command) if command != nil
- @size = (command.size * 32) if (command.size * 32) > @size}
- super(@size,@array)
- self.x,self.y = $mouse.position
- end
- def indexes
- return @main_commands.index(@array[self.index])
- end
- def update
- super
- if Input.trigger?(Input::Key['Mouse Left'])
- if self.index >= 0
- @event.start_command(indexes)
- self.dispose
- else
- self.dispose
- end
- end
- end
- end
- #============================================================================
- # MCES::Pathrequest
- #----------------------------------------------------------------------------
- # This class preforms the movement requests.
- #============================================================================
- class PathRequesting
- attr_reader :open,:closed,:sx,:sy,:tx,:ty,:jd
- def initialize(tx, ty, jd = 0)
- pix = ($BlizzABS != nil ? BlizzABS::Config::PIXEL_MOVEMENT_RATE : 1)
- ox,oy = $game_player.location
- @sx, @sy, @tx, @ty, @jd = ox, oy, tx, ty, jd
- @x_off, @y_off = ox - @sx, oy - @sy
- @open = {[@sx, @sy] => -1}
- @closed = Table.new($game_map.width, $game_map.height)
- end
- def backtrack
- cx, cy, x, y, result = @tx, @ty, 0, 0, []
- loop do
- cx, cy = cx - x, cy - y
- break if cx == @sx && cy == @sy
- result.unshift(Cache::TDirs[@closed[cx, cy]])
- x, y = Cache::DirOffsets[@closed[cx, cy]]
- end
- return result
- end
- end
- end
- raise('This script requires Mouse Controller by Blizzard to work') if $mouse == nil
- $MCES = MCES::Processor.new
- #============================================================================
- # Game_Character
- #----------------------------------------------------------------------------
- # Adds a mouse_in_area? method to any instance of this class.
- #============================================================================
- class Game_Character
- attr_reader :type
- attr_accessor :icon_name,:direction_fixed
- alias mces_character_initialize initialize
- def initialize
- @type = []
- mces_character_initialize
- end
- def mouse_in_area?
- return false if get_sprite == nil || get_sprite.is_a?(Array)
- return false if get_sprite.inner_bitmap == nil
- return false if get_sprite.cw == nil || get_sprite.ch == nil
- return true if [$mouse.x/32,$mouse.y/32] == [self.x,self.y]
- b = get_sprite.inner_bitmap
- xs = get_sprite.x-(get_sprite.cw/2)
- ys = get_sprite.y-get_sprite.ch
- return ($mouse.x >= xs && $mouse.x < xs + b.width &&
- $mouse.y >= ys && $mouse.y < ys + b.height &&
- b.get_pixel($mouse.x-xs, $mouse.y-ys) != Color.new(255,255,255,0))
- end
- def get_sprite
- return if !$scene.is_a?(Scene_Map)
- $scene.spriteset.character_sprites.each{|s|return s if s.character == self}
- end
- end
- #============================================================================
- # Game_Event
- #----------------------------------------------------------------------------
- # This class sets the events proccesing for MCES.
- #============================================================================
- class Game_Event < Game_Character
- attr_accessor :event_start
- attr_reader :key,:curser,:msg,:commands,:erased
- alias mces_initialize initialize
- def initialize(id,event)
- mces_initialize(id,event)
- @child_interpeter = Interpreter.new
- @event_start = false
- @type,@commands, = [],[]
- check_name
- end
- alias mces_update update
- def update
- mces_update
- @child_interpeter.update
- @msg_sprite.update if @msg_sprite != nil
- end
- alias mces_start start
- def start
- return if @trigger == 0 && (!@event_start || @commands.size > 0)
- mces_start
- @event_start = false
- end
- def start_event
- @event_start = true
- start
- end
- def check_door
- if @key == $MCES.item
- @child_interpeter.setup(@event.pages[1].list,@id)
- $game_party.gain_item($MCES.item.id, -1)
- $MCES.item = nil
- @key_unlock = true
- elsif @key_unlock
- @child_interpeter.setup(@event.pages[2].list,@id)
- else
- @child_interpeter.setup(@event.pages[0].list,@id)
- end
- return
- end
- def start_command(i)
- @child_interpeter.setup(@event.pages[i].list,@id)
- end
- def check_name
- if @event.name.clone.gsub!(/\\[Ii]gnore/) {''}
- @type.push(MCES::Cache::Ignore)
- end
- if @event.name.clone.gsub!(/\\[Aa]uto/) {''}
- @type.push(MCES::Cache::Auto)
- end
- if @event.name.clone.gsub!(/\\[Cc]ommands/) {''}
- @type.push(MCES::Cache::Commands)
- @interpreter = Interpreter.new
- @event.pages.each{|page|page.list.each{|list|
- @last_list = list if @last_list == nil
- if list.code == 108
- if @last_list.code == 111
- if @interpreter.command_111([@last_list,list])
- @commands[@event.pages.index(page)] = list.parameters[0]
- end
- else
- @commands[@event.pages.index(page)] = list.parameters[0]
- end
- end
- @last_list = list}}
- @interpreter = nil
- end
- if @event.name.clone.gsub!(/\\[Dd]irectionfix\[(\d+)\]/) {"#[$1]"}
- @type.push(MCES::Cache::Direction)
- @direction_fixed = $1.to_i
- end
- if @event.name.clone.gsub!(/\\[Dd]irection\[(\d+)\]/) {"#[$1]"}
- @type.push(MCES::Cache::Direction)
- @direction = $1.to_i
- end
- if @event.name.clone.gsub!(/\\[Ll]ocked\[(\d+)\]/) {"#[$1]"}
- @type.push(MCES::Cache::Door)
- @key = $data_items[$1.to_i]
- end
- if @event.name.clone.gsub!(/\\[Cc]urser\[(.+?)\]/) {"#[$1]"}
- @type.push(MCES::Cache::Curser)
- @curser = $1
- end
- if @event.name.clone.gsub!(/\\[Mm]sg\[(.+?)\]/) {"#[$1]"}
- @type.push(MCES::Cache::Msg)
- @msg = $1
- @msg_sprite = MCES::Msg_Sprite.new(self)
- end
- end
- end
- #============================================================================
- # Game_Player
- #----------------------------------------------------------------------------
- # Adds force movement.
- #============================================================================
- class Game_Player
- attr_accessor :force_movement
- alias mces_update update
- def update
- mces_update
- if @target_x == nil
- @force_movement = []
- $MCES.location = []
- else
- if @force_movement == []
- $MCES.request_path(@target_x, @target_y)
- end
- update_forcemovement if !moving?
- if location == $MCES.check_target(@target_x,@target_y)
- if @target_x.is_a?(Game_Event)
- @target_x.start_event
- face_target
- end
- if $scene.spriteset.set_sprite != nil
- $scene.spriteset.set_sprite.opacity = 0
- end
- @target_x = @target_y = nil
- @force_movement = []
- $MCES.location = []
- end
- end
- end
- def face_target
- sx = @x - @target_x.x
- sy = @y - @target_x.y
- return if sx == 0 and sy == 0
- sx > 0 ? turn_left : turn_right if sx.abs > sy.abs
- sy > 0 ? turn_up : turn_down if sx.abs < sy.abs
- end
- def update_forcemovement
- return if @force_movement.size == 0
- move = @force_movement.shift
- case move[0]
- when 1 then move_lower_left
- when 2 then move_down(move[1])
- when 3 then move_lower_right
- when 4 then move_left(move[1])
- when 6 then move_right(move[1])
- when 7 then move_upper_left
- when 8 then move_up(move[1])
- when 9 then move_upper_right
- end
- end
- def location
- return self.x,self.y
- end
- def click_jump(x,y)
- new_x,new_y = x-self.y,x-self.y
- jump(new_x,new_y)
- end
- def set(x,y=nil)
- @force_movement = []
- @target_x, @target_y = x,y
- $scene.spriteset.set_sprite.set(x,y) if MCES::Config::Click_Graphic != false
- end
- end
- #============================================================================
- # Interpreter
- #----------------------------------------------------------------------------
- # Allows external use of the condition command.
- #============================================================================
- class Interpreter
- alias mces_command_111 command_111
- def command_111(list = nil)
- if list != nil
- @index = 0
- @list = list
- @list.push(RPG::EventCommand.new(412, list[0].indent, []))
- @parameters = list[0].parameters
- end
- mces_command_111
- if list != nil
- return @branch[0] == nil
- end
- end
- end
- #============================================================================
- # Input
- #----------------------------------------------------------------------------
- # Adds the alias methods and updates the processor.
- #============================================================================
- module Input
- class << Input
- alias mces_trigger? trigger?
- alias mces_update update
- end
- def self.update
- $MCES.update
- mces_update
- end
- end
- if ($tons_version || $BlizzABS || $network) == nil
- #============================================================================
- # Input
- #----------------------------------------------------------------------------
- # Adds the mouse trigger commands if not using Blizzards input methods.
- #============================================================================
- module Input
- Key = {'Mouse Left' => 1, 'Mouse Right' => 2}
- C = Key['Mouse Left']
- #======================================
- # |–> Keyboard Input Module
- #======================================
- # By: Near Fantastica
- # Date: 06.07.05
- # Version: 3
- #
- # Cut down by Zeriab
- # Date: 16.08.06
- #======================================
- def self.trigger?(key)
- return false if key == nil
- if !Win32API.new("user32","GetKeyState",['i'],'i').call(key).between?(0, 1)
- return true
- else
- return mces_trigger?(key)
- end
- end
- end
- end
- #============================================================================
- # Sprite_Character
- #----------------------------------------------------------------------------
- # Creats a inner bitmap for use with the mouse_in_area? method.
- #============================================================================
- class Sprite_Character
- attr_reader :ch,:cw,:inner_bitmap
- alias mces_initialize initialize
- def initialize(viewport,character = nil)
- mces_initialize(viewport,character)
- end
- alias mces_update update
- def update
- mces_update
- if $BlizzABS != nil
- return if @sprite == nil
- return if @sprite.cw == nil || @sprite.ch == nil
- @cw,@ch = @sprite.cw, @sprite.ch
- end
- if @character.icon_name != nil || @character.tile_id >= 384
- @inner_bitmap = self.bitmap.clone
- return
- end
- @inner_bitmap = Bitmap.new(@cw,@ch) if @inner_bitmap == nil
- if @pattern != @character.pattern
- @pattern = @character.pattern
- bitmap = ($BlizzABS != nil ? @sprite.bitmap : self.bitmap)
- src_rect = ($BlizzABS != nil ? @sprite.src_rect : self.src_rect)
- @inner_bitmap.clear
- @inner_bitmap.blt(0, 0, bitmap, src_rect)
- end
- end
- end
- #============================================================================
- # Spriteset_Map
- #----------------------------------------------------------------------------
- # Creats the set_sprite
- #============================================================================
- class Spriteset_Map
- attr_reader :character_sprites,:set_sprite
- alias mces_initialize initialize
- def initialize
- mces_initialize
- if MCES::Config::Click_Graphic != false
- @set_sprite = MCES::Set_Sprite.new(@viewport1)
- end
- end
- alias mces_update update
- def update
- mces_update
- @set_sprite.update if @set_sprite != nil
- end
- end
- #============================================================================
- # Adds eternal reading of methods.
- #============================================================================
- class Sprite_Character_ABSEAL_ed; attr_reader :ch,:cw end if $BlizzABS != nil
- class Scene_Map; attr_reader :spriteset end
- if $BlizzABS != nil
- class BlizzABS::Processor
- def pixel
- return 1
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement