Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # Vampyr Kernel 1.5
- #==============================================================================
- # This module is necessary to activate and enhance compatibility of all Vampyr's Scripts
- #------------------------------------------------------------------------------
- module Vampyr_Kernel
- @scripts = {}
- @warnings = {}
- Print_Errors = false
- def self.register(script, version, date)
- @scripts[script] = [version, date]
- end
- def self.enabled?(script, version=nil)
- if @scripts.has_key?(script)
- if version.nil?
- return true
- elsif @scripts[script][0] >= version
- return true
- else
- if @warnings[script].nil? and Print_Errors
- print "'#{script}' is obsolete.\r\nSome functions won't work correctly"
- @warnings[script] = ["is obsolete"]
- self.write_log
- end
- return false
- end
- else
- if $TEST and @warnings[script].nil? and Print_Errors
- print "Unable to find script '#{script}' or it is placed in wrong place.\r\nSome functions won't work correctly"
- @warnings[script] = ["Unable to find"]
- self.write_log
- end
- return false
- end
- end
- def self.show_scripts(alert=true)
- list = "Vampyr Scripts [#{@scripts.size}]:\r\n\r\n"
- @scripts.each { |key, value| list += "#{key.gsub("Vampyr ", "")} #{value[0]} #{value[1]}\r\n" }
- list += "\r\nWarnings:\r\n" if @warnings != {}
- @warnings.each { |key, value| list += "#{key} #{value}\r\n" }
- return print list if alert
- return list
- end
- def self.write_log
- file = File.new("Vampyr_Log-#{Time.now.strftime("%m_%d_%Y")}.txt", "wb")
- file.write(self.show_scripts(false))
- file.close
- end
- end
- #------------------------------------------------------------------------------
- class Object
- def to_b
- return true if self == "true"
- return true if self.to_i > 0
- return false
- end
- def getw
- bitmap = Bitmap.new(1, 1)
- size = bitmap.text_size(self.to_s).width
- bitmap.dispose
- return size
- end
- def to_rgb
- x = self.delete("#").scan(/../).map { |i| i.to_i(16) }
- return Color.new(x[0].to_f, x[1].to_f, x[2].to_f)
- end
- def number?
- return true unless self.scan(/\d/).empty?
- return false
- end
- def transform
- return self.to_i if self.number?
- return self.to_s
- end
- end
- #------------------------------------------------------------------------------
- class Sprite
- def draw_icon(index, x, y, o=255)
- bitmap = Cache.system("Iconset")
- rect = Rect.new(index%16*24, index/16*24, 24, 24)
- self.bitmap.blt(x, y, bitmap, rect, o)
- end
- end
- #------------------------------------------------------------------------------
- class Color
- def self.index(i)
- return Cache.system("Window").get_pixel(64+(i%8)*8, 96+(i/8)*8)
- end
- def self.get(x, y)
- return Cache.system("Window").get_pixel(x, y)
- end
- end
- #------------------------------------------------------------------------------
- class Bitmap
- def draw_outlined_text(*args)
- if args[0].is_a?(Rect)
- x = args[0].x
- y = args[0].y
- w = args[0].width
- h = args[0].height
- s = args[1]
- a = (args[2].nil? ? 0 : args[2])
- else
- x = args[0]; y = args[1]
- w = args[2]; h = args[3]
- s = args[4]
- a = (args[5].nil? ? 0 : args[5])
- end
- font.shadow = false
- color = font.color.clone
- font.color = Color.new(0,0,0)
- draw_text(x-1, y-1, w, h, s, a)
- draw_text(x+1, y-1, w, h, s, a)
- draw_text(x-1, y+1, w, h, s, a)
- draw_text(x+1, y+1, w, h, s, a)
- font.color = color
- draw_text(x, y, w, h, s, a)
- end
- end
- #------------------------------------------------------------------------------
- class Game_Map
- def in_range?(object)
- return true if object.is_a?(Game_Event) and object.comment_exists?("Force Update")
- return false if object.real_x < (@display_x-(256*3))
- return false if object.real_x > (@display_x+((Graphics.width/32*256)+(256*3)))
- return false if object.real_y < (@display_y-(256*3))
- return false if object.real_y > (@display_y+((Graphics.height/32*256)+(256*3)))
- return true
- end
- def update_events
- for event in @events.values
- if in_range?(event) or event.trigger == 3 or
- event.trigger == 4 or event.comment_exists?("Forse Update")
- event.update
- end
- end
- for common_event in @common_events.values
- common_event.update
- end
- end
- def map_name
- map = load_data("Data/MapInfos.rvdata")
- return map[@map_id].name
- end
- end
- #------------------------------------------------------------------------------
- class Game_Character
- attr_accessor :character_name
- attr_accessor :character_index
- attr_accessor :move_type
- attr_accessor :move_route
- attr_accessor :direction_fix
- attr_accessor :walk_anime
- attr_accessor :step_anime
- attr_accessor :through
- attr_accessor :pattern
- attr_accessor :direction
- attr_accessor :bush_depth
- attr_accessor :blend_type
- attr_accessor :opacity
- attr_accessor :move_speed
- attr_accessor :priority_type
- attr_accessor :width
- attr_accessor :height
- def in_range?(target, range)
- x = (@x - target.x) * (@x - target.x)
- y = (@y - target.y) * (@y - target.y)
- return true if (x + y) <= (range * range)
- return false
- end
- def in_front?(target)
- return true if @direction == 2 and @x == target.x and (@y+1) == target.y
- return true if @direction == 4 and (@x-1) == target.x and @y == target.y
- return true if @direction == 6 and (@x+1) == target.x and @y == target.y
- return true if @direction == 8 and @x == target.x and (@y-1) == target.y
- return false
- end
- def in_direction?(target)
- return true if @direction == 2 and target.y >= @y and target.x == @x
- return true if @direction == 4 and target.x <= @x and target.y == @y
- return true if @direction == 6 and target.x >= @x and target.y == @y
- return true if @direction == 8 and target.y <= @y and target.x == @x
- return false
- end
- def in_behind?(target)
- return true if @direction == 2 and @x == target.x and @y < target.y
- return true if @direction == 4 and @x > target.x and @y == target.y
- return true if @direction == 6 and @x < target.x and @y == target.y
- return true if @direction == 8 and @x == target.x and @y > target.y
- return false
- end
- def in_beside?(target)
- return true if target.direction == 2 and @direction == 4 and target.x == (@x-1) and target.y == @y
- return true if target.direction == 2 and @direction == 6 and target.x == (@x+1) and target.y == @y
- return true if target.direction == 4 and @direction == 2 and target.x == @x and target.y == (@y+1)
- return true if target.direction == 4 and @direction == 8 and target.x == @x and target.y == (@y-1)
- return true if target.direction == 6 and @direction == 2 and target.x == @x and target.y == (@y+1)
- return true if target.direction == 6 and @direction == 8 and target.x == @x and target.y == (@y-1)
- return true if target.direction == 8 and @direction == 4 and target.x == (@x-1) and target.y == @y
- return true if target.direction == 8 and @direction == 6 and target.x == (@x+1) and target.y == @y
- return false
- end
- def face_to_face?(target)
- return true if @direction == 2 and target.direction == 8
- return true if @direction == 4 and target.direction == 6
- return true if @direction == 6 and target.direction == 4
- return true if @direction == 8 and target.direction == 2
- return false
- end
- def over?(target)
- return true if @x == target.x and @y == target.y
- return false
- end
- def jump_to(x, y)
- xx = (x < @x ? -(@x-x) : x > @x ? x-@x : 0)
- yy = (y < @y ? -(@y-y) : y > @y ? y-@y : 0)
- jump(xx, yy)
- end
- def move_toward(*params)
- if params[0].is_a?(Numeric)
- x = params[0]
- y = params[1]
- else
- x = params[0].x
- y = params[0].y
- end
- sx = distance_x(x)
- sy = distance_y(y)
- if sx != 0 or sy != 0
- if sx.abs > sy.abs
- sx > 0 ? move_left : move_right
- if @move_failed and sy != 0
- sy > 0 ? move_up : move_down
- end
- else
- sy > 0 ? move_up : move_down
- if @move_failed and sx != 0
- sx > 0 ? move_left : move_right
- end
- end
- end
- end
- def move_type_toward(target)
- case rand(6)
- when 0..3; move_toward(target)
- when 4; move_random
- when 5; move_forward
- end
- end
- def move_away_from(*params)
- if params[0].is_a?(Numeric)
- x = params[0]
- y = params[1]
- else
- x = params[0].x
- y = params[0].y
- end
- sx = distance_x(x)
- sy = distance_y(y)
- if sx != 0 or sy != 0
- if sx.abs > sy.abs
- sx > 0 ? move_right : move_left
- if @move_failed and sy != 0
- sy > 0 ? move_down : move_up
- end
- else
- sy > 0 ? move_down : move_up
- if @move_failed and sx != 0
- sx > 0 ? move_right : move_left
- end
- end
- end
- end
- def turn_toward(*params)
- if params[0].is_a?(Numeric)
- x = params[0]
- y = params[1]
- else
- x = params[0].x
- y = params[0].y
- end
- sx = distance_x(x)
- sy = distance_y(y)
- if sx.abs > sy.abs
- sx > 0 ? turn_left : turn_right
- elsif sx.abs < sy.abs
- sy > 0 ? turn_up : turn_down
- end
- end
- def distance_x(x)
- sx = @x - x
- if $game_map.loop_horizontal?
- if sx.abs > $game_map.width / 2
- sx -= $game_map.width
- end
- end
- return sx
- end
- def distance_y(y)
- sy = @y - y
- if $game_map.loop_vertical?
- if sy.abs > $game_map.height / 2
- sy -= $game_map.height
- end
- end
- return sy
- end
- def animation_id=(i)
- @animation_id = (i < 0 ? 1 : i)
- end
- def check_event_trigger_touch(x, y)
- end
- end
- #------------------------------------------------------------------------------
- class Game_Event < Game_Character
- attr_reader :id
- def name
- return @event.name
- end
- def check_comment(param)
- return nil if @list == nil or @list.size <= 0
- for item in @list
- next unless item.code == 108 or item.code == 408
- if item.parameters[0] =~ /#{param} (.*)/i
- return $1.to_s
- end
- end
- return nil
- end
- def comment_exists?(param)
- return false if @list == nil or @list.size <= 0
- for item in @list
- if item.code == 108 or item.code == 408
- if item.parameters[0] =~ /#{param}/i
- return true
- end
- end
- end
- return false
- end
- end
- #------------------------------------------------------------------------------
- class Game_Interpreter
- attr_reader :id
- alias vampyr_kernel_ginterpreter_setup setup
- def setup(list, event_id = 0)
- vampyr_kernel_ginterpreter_setup(list, event_id)
- @id = @original_event_id
- end
- def self_event
- return $game_map.events[@id]
- end
- def selfswitch(switch, status=nil, event_id=@id)
- key = [$game_map.map_id, event_id, switch]
- if status == nil
- $game_self_switches[key] = !$game_self_switches[key]
- else
- $game_self_switches[key] = status
- end
- $game_map.need_refresh = true
- end
- end
- #------------------------------------------------------------------------------
- class Sprite_Character < Sprite_Base
- alias vampyr_kernel_spchar_update_bitmap update_bitmap
- def update_bitmap
- vampyr_kernel_spchar_update_bitmap
- @character.width = @cw if @character.width != @cw
- @character.height = @ch if @character.height != @ch
- end
- end
- #------------------------------------------------------------------------------
- Win32API.new("kernel32", "SetPriorityClass", "pi", "i").call(-1, 0x80)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement