Advertisement
Guest User

Verus Tempus Proelium Kernel

a guest
May 16th, 2010
904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.99 KB | None | 0 0
  1. #==============================================================================
  2. # Vampyr Kernel 1.5
  3. #==============================================================================
  4. # This module is necessary to activate and enhance compatibility of all Vampyr's Scripts
  5. #------------------------------------------------------------------------------
  6. module Vampyr_Kernel
  7.  
  8.   @scripts = {}
  9.   @warnings = {}
  10.  
  11.   Print_Errors = false
  12.  
  13.   def self.register(script, version, date)
  14.     @scripts[script] = [version, date]
  15.   end
  16.  
  17.   def self.enabled?(script, version=nil)
  18.     if @scripts.has_key?(script)
  19.       if version.nil?
  20.         return true
  21.       elsif @scripts[script][0] >= version
  22.         return true
  23.       else
  24.         if @warnings[script].nil? and Print_Errors
  25.           print "'#{script}' is obsolete.\r\nSome functions won't work correctly"
  26.           @warnings[script] = ["is obsolete"]
  27.           self.write_log
  28.         end
  29.         return false
  30.       end
  31.     else
  32.       if $TEST and @warnings[script].nil? and Print_Errors
  33.         print "Unable to find script '#{script}' or it is placed in wrong place.\r\nSome functions won't work correctly"
  34.         @warnings[script] = ["Unable to find"]
  35.         self.write_log
  36.       end
  37.       return false
  38.     end
  39.   end
  40.  
  41.   def self.show_scripts(alert=true)
  42.     list = "Vampyr Scripts [#{@scripts.size}]:\r\n\r\n"
  43.     @scripts.each { |key, value| list += "#{key.gsub("Vampyr ", "")}  #{value[0]}  #{value[1]}\r\n" }
  44.     list += "\r\nWarnings:\r\n" if @warnings != {}
  45.     @warnings.each { |key, value| list += "#{key} #{value}\r\n" }
  46.     return print list if alert
  47.     return list
  48.   end
  49.  
  50.   def self.write_log
  51.     file = File.new("Vampyr_Log-#{Time.now.strftime("%m_%d_%Y")}.txt", "wb")
  52.     file.write(self.show_scripts(false))
  53.     file.close
  54.   end
  55.  
  56. end
  57.  
  58. #------------------------------------------------------------------------------
  59. class Object
  60.  
  61.   def to_b
  62.     return true if self == "true"
  63.     return true if self.to_i > 0
  64.     return false
  65.   end
  66.  
  67.   def getw
  68.     bitmap = Bitmap.new(1, 1)
  69.     size = bitmap.text_size(self.to_s).width
  70.     bitmap.dispose
  71.     return size
  72.   end
  73.  
  74.   def to_rgb
  75.     x = self.delete("#").scan(/../).map { |i| i.to_i(16) }
  76.     return Color.new(x[0].to_f, x[1].to_f, x[2].to_f)
  77.   end
  78.  
  79.   def number?
  80.     return true unless self.scan(/\d/).empty?
  81.     return false
  82.   end
  83.  
  84.   def transform
  85.     return self.to_i if self.number?
  86.     return self.to_s
  87.   end
  88.  
  89. end
  90.  
  91. #------------------------------------------------------------------------------
  92. class Sprite
  93.  
  94.   def draw_icon(index, x, y, o=255)
  95.     bitmap = Cache.system("Iconset")
  96.     rect = Rect.new(index%16*24, index/16*24, 24, 24)
  97.     self.bitmap.blt(x, y, bitmap, rect, o)
  98.   end
  99.  
  100. end
  101.  
  102. #------------------------------------------------------------------------------
  103. class Color
  104.  
  105.   def self.index(i)
  106.     return Cache.system("Window").get_pixel(64+(i%8)*8, 96+(i/8)*8)
  107.   end
  108.  
  109.   def self.get(x, y)
  110.     return Cache.system("Window").get_pixel(x, y)
  111.   end
  112.  
  113. end
  114.  
  115. #------------------------------------------------------------------------------
  116. class Bitmap
  117.  
  118.   def draw_outlined_text(*args)
  119.     if args[0].is_a?(Rect)
  120.       x = args[0].x
  121.       y = args[0].y
  122.       w = args[0].width
  123.       h = args[0].height
  124.       s = args[1]
  125.       a = (args[2].nil? ? 0 : args[2])
  126.     else
  127.       x = args[0]; y = args[1]
  128.       w = args[2]; h = args[3]
  129.       s = args[4]
  130.       a = (args[5].nil? ? 0 : args[5])
  131.     end
  132.     font.shadow = false
  133.     color = font.color.clone
  134.     font.color = Color.new(0,0,0)
  135.     draw_text(x-1, y-1, w, h, s, a)
  136.     draw_text(x+1, y-1, w, h, s, a)
  137.     draw_text(x-1, y+1, w, h, s, a)
  138.     draw_text(x+1, y+1, w, h, s, a)
  139.     font.color = color
  140.     draw_text(x, y, w, h, s, a)
  141.   end
  142.  
  143. end
  144.  
  145. #------------------------------------------------------------------------------
  146. class Game_Map
  147.  
  148.   def in_range?(object)
  149.     return true if object.is_a?(Game_Event) and object.comment_exists?("Force Update")
  150.     return false if object.real_x < (@display_x-(256*3))
  151.     return false if object.real_x > (@display_x+((Graphics.width/32*256)+(256*3)))
  152.     return false if object.real_y < (@display_y-(256*3))
  153.     return false if object.real_y > (@display_y+((Graphics.height/32*256)+(256*3)))
  154.     return true
  155.   end
  156.  
  157.   def update_events
  158.     for event in @events.values
  159.       if in_range?(event) or event.trigger == 3 or
  160.         event.trigger == 4 or event.comment_exists?("Forse Update")
  161.         event.update
  162.       end
  163.     end
  164.     for common_event in @common_events.values
  165.       common_event.update
  166.     end
  167.   end
  168.  
  169.   def map_name
  170.     map = load_data("Data/MapInfos.rvdata")
  171.     return map[@map_id].name
  172.   end
  173.  
  174. end
  175.  
  176. #------------------------------------------------------------------------------
  177. class Game_Character
  178.  
  179.   attr_accessor :character_name
  180.   attr_accessor :character_index
  181.   attr_accessor :move_type
  182.   attr_accessor :move_route
  183.   attr_accessor :direction_fix
  184.   attr_accessor :walk_anime
  185.   attr_accessor :step_anime
  186.   attr_accessor :through
  187.   attr_accessor :pattern
  188.   attr_accessor :direction
  189.   attr_accessor :bush_depth
  190.   attr_accessor :blend_type
  191.   attr_accessor :opacity
  192.   attr_accessor :move_speed
  193.   attr_accessor :priority_type
  194.   attr_accessor :width
  195.   attr_accessor :height
  196.  
  197.   def in_range?(target, range)
  198.     x = (@x - target.x) * (@x - target.x)
  199.     y = (@y - target.y) * (@y - target.y)
  200.     return true if (x + y) <= (range * range)
  201.     return false
  202.   end
  203.  
  204.   def in_front?(target)
  205.     return true if @direction == 2 and @x == target.x and (@y+1) == target.y
  206.     return true if @direction == 4 and (@x-1) == target.x and @y == target.y
  207.     return true if @direction == 6 and (@x+1) == target.x and @y == target.y
  208.     return true if @direction == 8 and @x == target.x and (@y-1) == target.y
  209.     return false
  210.   end
  211.  
  212.   def in_direction?(target)
  213.     return true if @direction == 2 and target.y >= @y and target.x == @x
  214.     return true if @direction == 4 and target.x <= @x and target.y == @y
  215.     return true if @direction == 6 and target.x >= @x and target.y == @y
  216.     return true if @direction == 8 and target.y <= @y and target.x == @x
  217.     return false
  218.   end
  219.  
  220.   def in_behind?(target)
  221.     return true if @direction == 2 and @x == target.x and @y < target.y
  222.     return true if @direction == 4 and @x > target.x and @y == target.y
  223.     return true if @direction == 6 and @x < target.x and @y == target.y
  224.     return true if @direction == 8 and @x == target.x and @y > target.y
  225.     return false
  226.   end
  227.  
  228.   def in_beside?(target)
  229.     return true if target.direction == 2 and @direction == 4 and target.x == (@x-1) and target.y == @y
  230.     return true if target.direction == 2 and @direction == 6 and target.x == (@x+1) and target.y == @y
  231.     return true if target.direction == 4 and @direction == 2 and target.x == @x and target.y == (@y+1)
  232.     return true if target.direction == 4 and @direction == 8 and target.x == @x and target.y == (@y-1)
  233.     return true if target.direction == 6 and @direction == 2 and target.x == @x and target.y == (@y+1)
  234.     return true if target.direction == 6 and @direction == 8 and target.x == @x and target.y == (@y-1)
  235.     return true if target.direction == 8 and @direction == 4 and target.x == (@x-1) and target.y == @y
  236.     return true if target.direction == 8 and @direction == 6 and target.x == (@x+1) and target.y == @y
  237.     return false
  238.   end
  239.  
  240.   def face_to_face?(target)
  241.     return true if @direction == 2 and target.direction == 8
  242.     return true if @direction == 4 and target.direction == 6
  243.     return true if @direction == 6 and target.direction == 4
  244.     return true if @direction == 8 and target.direction == 2
  245.     return false
  246.   end
  247.  
  248.   def over?(target)
  249.     return true if @x == target.x and @y == target.y
  250.     return false
  251.   end
  252.  
  253.   def jump_to(x, y)
  254.     xx = (x < @x ? -(@x-x) : x > @x ? x-@x : 0)
  255.     yy = (y < @y ? -(@y-y) : y > @y ? y-@y : 0)
  256.     jump(xx, yy)
  257.   end
  258.  
  259.   def move_toward(*params)
  260.     if params[0].is_a?(Numeric)
  261.       x = params[0]
  262.       y = params[1]
  263.     else
  264.       x = params[0].x
  265.       y = params[0].y
  266.     end
  267.     sx = distance_x(x)
  268.     sy = distance_y(y)
  269.     if sx != 0 or sy != 0
  270.       if sx.abs > sy.abs
  271.         sx > 0 ? move_left : move_right
  272.         if @move_failed and sy != 0
  273.           sy > 0 ? move_up : move_down
  274.         end
  275.       else
  276.         sy > 0 ? move_up : move_down
  277.         if @move_failed and sx != 0
  278.           sx > 0 ? move_left : move_right
  279.         end
  280.       end
  281.     end
  282.   end
  283.  
  284.   def move_type_toward(target)
  285.     case rand(6)
  286.       when 0..3; move_toward(target)
  287.       when 4;    move_random
  288.       when 5;    move_forward
  289.     end
  290.   end
  291.  
  292.   def move_away_from(*params)
  293.     if params[0].is_a?(Numeric)
  294.       x = params[0]
  295.       y = params[1]
  296.     else
  297.       x = params[0].x
  298.       y = params[0].y
  299.     end
  300.     sx = distance_x(x)
  301.     sy = distance_y(y)
  302.     if sx != 0 or sy != 0
  303.       if sx.abs > sy.abs
  304.         sx > 0 ? move_right : move_left
  305.         if @move_failed and sy != 0
  306.           sy > 0 ? move_down : move_up
  307.         end
  308.       else
  309.         sy > 0 ? move_down : move_up
  310.         if @move_failed and sx != 0
  311.           sx > 0 ? move_right : move_left
  312.         end
  313.       end
  314.     end
  315.   end
  316.  
  317.   def turn_toward(*params)
  318.     if params[0].is_a?(Numeric)
  319.       x = params[0]
  320.       y = params[1]
  321.     else
  322.       x = params[0].x
  323.       y = params[0].y
  324.     end
  325.     sx = distance_x(x)
  326.     sy = distance_y(y)
  327.     if sx.abs > sy.abs
  328.       sx > 0 ? turn_left : turn_right
  329.     elsif sx.abs < sy.abs
  330.       sy > 0 ? turn_up : turn_down
  331.     end
  332.   end
  333.  
  334.   def distance_x(x)
  335.     sx = @x - x
  336.     if $game_map.loop_horizontal?
  337.       if sx.abs > $game_map.width / 2
  338.         sx -= $game_map.width
  339.       end
  340.     end
  341.     return sx
  342.   end
  343.  
  344.   def distance_y(y)
  345.     sy = @y - y
  346.     if $game_map.loop_vertical?
  347.       if sy.abs > $game_map.height / 2
  348.         sy -= $game_map.height
  349.       end
  350.     end
  351.     return sy
  352.   end
  353.  
  354.   def animation_id=(i)
  355.     @animation_id = (i < 0 ? 1 : i)
  356.   end
  357.  
  358.   def check_event_trigger_touch(x, y)
  359.   end
  360.  
  361. end
  362.  
  363. #------------------------------------------------------------------------------
  364. class Game_Event < Game_Character
  365.  
  366.   attr_reader :id
  367.  
  368.   def name
  369.     return @event.name
  370.   end
  371.  
  372.   def check_comment(param)
  373.     return nil if @list == nil or @list.size <= 0
  374.     for item in @list
  375.       next unless item.code == 108 or item.code == 408
  376.       if item.parameters[0] =~ /#{param} (.*)/i
  377.         return $1.to_s
  378.       end
  379.     end
  380.     return nil
  381.   end
  382.  
  383.   def comment_exists?(param)
  384.     return false if @list == nil or @list.size <= 0
  385.     for item in @list
  386.       if item.code == 108 or item.code == 408
  387.         if item.parameters[0] =~ /#{param}/i
  388.           return true
  389.         end
  390.       end
  391.     end
  392.     return false
  393.   end
  394.  
  395. end
  396.  
  397. #------------------------------------------------------------------------------
  398. class Game_Interpreter
  399.  
  400.   attr_reader :id
  401.  
  402.   alias vampyr_kernel_ginterpreter_setup setup
  403.  
  404.   def setup(list, event_id = 0)
  405.     vampyr_kernel_ginterpreter_setup(list, event_id)
  406.     @id = @original_event_id
  407.   end
  408.  
  409.   def self_event
  410.     return $game_map.events[@id]
  411.   end
  412.  
  413.   def selfswitch(switch, status=nil, event_id=@id)
  414.     key = [$game_map.map_id, event_id, switch]
  415.     if status == nil
  416.       $game_self_switches[key] = !$game_self_switches[key]
  417.     else
  418.       $game_self_switches[key] = status
  419.     end
  420.     $game_map.need_refresh = true
  421.   end
  422.  
  423. end
  424.  
  425. #------------------------------------------------------------------------------
  426. class Sprite_Character < Sprite_Base
  427.  
  428.   alias vampyr_kernel_spchar_update_bitmap update_bitmap
  429.  
  430.   def update_bitmap
  431.     vampyr_kernel_spchar_update_bitmap
  432.     @character.width = @cw if @character.width != @cw
  433.     @character.height = @ch if @character.height != @ch
  434.   end
  435.  
  436. end
  437.  
  438. #------------------------------------------------------------------------------
  439. Win32API.new("kernel32", "SetPriorityClass", "pi", "i").call(-1, 0x80)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement