IceDragon200

Kappa

Mar 30th, 2011
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.77 KB | None | 0 0
  1. # 03/19/2011
  2. #==============================================================================#
  3. # IEO::REGEX::KAPPA
  4. #==============================================================================#
  5. module IEO
  6.   module REGEXP
  7.     module KAPPA
  8.       module EVENT
  9.         PAT_RATE   = /<(?:PATTERN_RATE|PATTERN RATE|PATTERNRATE):[ ]*(\d+)>/i
  10.         ORIG_PAT   = /<(?:DEFAULT_FRAME|DEFAULT FRAME|DEFAULTFRAME):[ ]*(\d+)>/i
  11.         ICON_INDEX = /<(?:ICON_INDEX|ICON INDEX|ICONINDEX):[ ]*(.*)>/i
  12.         PATTERN    = /<PATTERN:[ ]*(.*)>/i
  13.         ZOOM       = /<ZOOM[ ](.*):[ ]*(.*)>/i
  14.       end
  15.       module GENERAL
  16.         FRAMES     = /\#\[(\d+)\]/i
  17.       end  
  18.     end
  19.   end
  20. end
  21.  
  22. #==============================================================================#
  23. # Game_Character
  24. #==============================================================================#
  25. class Game_Character
  26.  
  27.   #--------------------------------------------------------------------------#
  28.   # * Public Instance Variables
  29.   #--------------------------------------------------------------------------#
  30.   attr_accessor :cwidth_div
  31.   attr_accessor :cheight_div
  32.   attr_accessor :icon_index
  33.   # // ------------------------------------------------------ // #
  34.   attr_accessor :zoom_x
  35.   attr_accessor :zoom_y
  36.  
  37.   #--------------------------------------------------------------------------#
  38.   # * alias method :initialize
  39.   #--------------------------------------------------------------------------#
  40.   alias ieo0aa_initialize initialize unless $@
  41.   def initialize
  42.     @defpattern = [0, 1, 2, 1]
  43.     @patternbld = :bf # :bf (Back-Forth), :ln(Linear), :cus(Custom)
  44.     @patpos     = 0   # The internal pattern counter
  45.     @cwidth_div = 3
  46.     @cheight_div= 4
  47.     @icon_index = 0
  48.     @patternrate= 2   # Default pattern rate is 2
  49.     # // ------------------------------------------------------ // #
  50.     @zoom_x = 1.00
  51.     @zoom_y = 1.00
  52.     ieo0aa_initialize
  53.   end  
  54.  
  55.   #--------------------------------------------------------------------------#
  56.   # * overwrite method :update_animation
  57.   #--------------------------------------------------------------------------#
  58.   def update_animation
  59.     speed = @move_speed + (dash? ? 1 : 0)
  60.     if @anime_count > 18 - speed * @patternrate
  61.       if not @step_anime and @stop_count > 0
  62.         @pattern = @original_pattern
  63.       else
  64.         @patpos = (@patpos + 1) % @defpattern.size
  65.         @pattern = @defpattern[@patpos]
  66.       end  
  67.       @anime_count = 0
  68.     end
  69.   end
  70.  
  71.   #--------------------------------------------------------------------------#
  72.   # * alias method :set_graphic
  73.   #--------------------------------------------------------------------------#
  74.   alias ieo0aa_set_graphic set_graphic unless $@
  75.   def set_graphic(character_name, character_index)
  76.     ieo0aa_set_graphic(character_name, character_index)
  77.     setup_defpattern
  78.   end
  79.  
  80.   #--------------------------------------------------------------------------#
  81.   # * new method :ieo0aa_eventcache
  82.   #--------------------------------------------------------------------------#
  83.   def setup_defpattern
  84.     framecount = 3
  85.     # // ------------------------------------------------------------------ // #
  86.     @character_name.scan(IEO::REGEXP::KAPPA::GENERAL::FRAMES).each { |fr| framecount = fr.to_s.to_i}
  87.     @cwidth_div = framecount
  88.     # // ------------------------------------------------------------------ // #
  89.     case @patternbld
  90.     when :bf # // Back-Forth
  91.       @defpattern = []
  92.       framecount.times { |i| @defpattern << i unless i == framecount }
  93.       af = @defpattern.clone; af.reverse!; af.pop; af.shift; @defpattern += af
  94.     when :ln # // Linear
  95.       @defpattern = []
  96.       framecount.times { |i| @defpattern << i unless i == framecount}
  97.     end  
  98.     # // ------------------------------------------------------------------ // #
  99.   end
  100.  
  101. end
  102.  
  103. #==============================================================================#
  104. # Game_Event
  105. #==============================================================================#
  106. class Game_Event < Game_Character
  107.  
  108.   #--------------------------------------------------------------------------#
  109.   # * alias method :setup
  110.   #--------------------------------------------------------------------------#
  111.   alias ieo0aa_setup setup unless $@
  112.   def setup(new_page)
  113.     ieo0aa_setup(new_page)
  114.     ieo0aa_eventcache
  115.   end
  116.  
  117.   #--------------------------------------------------------------------------#
  118.   # * new method :ieo0aa_eventcache
  119.   #--------------------------------------------------------------------------#
  120.   def ieo0aa_eventcache
  121.     return if @list == nil
  122.     for i in 0..@list.size
  123.       next if @list[i] == nil
  124.       if @list[i].code == 108
  125.         @list[i].parameters.to_s.split(/[\r\n]+/).each { |line|
  126.         case line
  127.         when IEO::REGEXP::KAPPA::EVENT::ICON_INDEX
  128.           val = $1
  129.           case val
  130.           when /(?:ITE|I):[ ](\d+)/i
  131.             @icon_index = $data_items[$1.to_i]
  132.           when /(?:WEP|W):[ ](\d+)/i
  133.             @icon_index = $data_weapons[$1.to_i]
  134.           when /(?:ARM|A):[ ](\d+)/i  
  135.             @icon_index = $data_armors[$1.to_i]
  136.           when /(?:SKI|S):[ ](\d+)/i  
  137.             @icon_index = $data_skills[$1.to_i]
  138.           when /(?:STE|T):[ ](\d+)/i
  139.             @icon_index = $data_states[$1.to_i]
  140.           else
  141.             @icon_index = val.to_i
  142.           end
  143.         when IEO::REGEXP::KAPPA::EVENT::PATTERN
  144.           val = $1
  145.           case val.upcase
  146.           when "LINEAR", "LN"
  147.             @patternbld = :ln
  148.           when "BACKFORTH", "BF"
  149.             @patternbld = :bf
  150.           else
  151.             @patternbld = :cus ; @defpattern = []
  152.             val.scan(/\d+/).each { |n| @defpattern << n.abs }
  153.           end  
  154.         when IEO::REGEXP::KAPPA::EVENT::ORIG_PAT
  155.           @original_pattern = $1.to_i
  156.         when IEO::REGEXP::KAPPA::EVENT::PAT_RATE
  157.           @patternrate = $1.to_i
  158.         when IEO::REGEXP::KAPPA::EVENT::ZOOM
  159.           val = $2.to_f * 1.00
  160.           case $1.upcase
  161.           when "X"
  162.             @zoom_x = val
  163.           when "Y"  
  164.             @zoom_y = val
  165.           end  
  166.         end
  167.         }
  168.       end
  169.     end
  170.     setup_defpattern
  171.   end
  172.  
  173. end
  174.  
  175. #==============================================================================#
  176. # Sprite_Character
  177. #==============================================================================#
  178. class Sprite_Character < Sprite_Base
  179.  
  180.   #--------------------------------------------------------------------------#
  181.   # * new method :iconset_bitmap
  182.   #--------------------------------------------------------------------------#
  183.   def iconset_bitmap(iconindex)
  184.     return Cache.system("Iconset")
  185.   end  
  186.  
  187.   #--------------------------------------------------------------------------#
  188.   # * alias method :update
  189.   #--------------------------------------------------------------------------#
  190.   alias ieo0aa_update update unless $@
  191.   def update
  192.     ieo0aa_update
  193.     update_zoom
  194.   end
  195.  
  196.   #--------------------------------------------------------------------------#
  197.   # * new method :update_zoom
  198.   #--------------------------------------------------------------------------#
  199.   def update_zoom
  200.     unless @character.nil?
  201.       self.zoom_x = @character.zoom_x
  202.       self.zoom_y = @character.zoom_y
  203.     end  
  204.   end
  205.  
  206.   #--------------------------------------------------------------------------#
  207.   # * overwrite method :update_src_rect
  208.   #--------------------------------------------------------------------------#
  209.   def update_src_rect
  210.     if @tile_id == 0 && @icon_index == 0
  211.       index = @character.character_index
  212.       pattern = @character.pattern < @character.cwidth_div ? @character.pattern : 1
  213.       sx = (index % 4 * @character.cwidth_div + pattern) * @cw
  214.       sy = (index / 4 * @character.cheight_div + (@character.direction - 2) / 2) * @ch
  215.       self.src_rect.set(sx, sy, @cw, @ch)
  216.     end
  217.   end
  218.  
  219.   #--------------------------------------------------------------------------#
  220.   # * overwrite method :update_bitmap
  221.   #--------------------------------------------------------------------------#
  222.   def update_bitmap
  223.     if (@tile_id != @character.tile_id ||
  224.         @icon_index != @character.icon_index ||
  225.         @character_name  != @character.character_name ||
  226.         @character_index != @character.character_index)
  227.       # //  
  228.       @character.setup_defpattern
  229.       @tile_id         = @character.tile_id
  230.       @icon_index      = @character.icon_index
  231.       @character_name  = @character.character_name
  232.       @character_index = @character.character_index
  233.       if @tile_id > 0
  234.         sx = (@tile_id / 128 % 2 * 8 + @tile_id % 8) * 32;
  235.         sy = @tile_id % 256 / 8 % 16 * 32;
  236.         self.bitmap = tileset_bitmap(@tile_id)
  237.         self.src_rect.set(sx, sy, 32, 32)
  238.         self.ox = 16
  239.         self.oy = 32
  240.       elsif @icon_index > 0  
  241.         irect = Rect.new(@icon_index % 16 * 24, @icon_index / 16 * 24, 24, 24)
  242.         self.bitmap = iconset_bitmap(@icon_index)
  243.         self.src_rect.set(irect.x, irect.y, irect.width, irect.height)
  244.         self.ox = irect.width / 2
  245.         self.oy = irect.height + (32 - irect.height) / 2
  246.       else
  247.         self.bitmap = Cache.character(@character_name)
  248.         sign = @character_name[/^[\!\$]./]
  249.         if sign != nil and sign.include?('$')
  250.           @cw = bitmap.width / @character.cwidth_div
  251.           @ch = bitmap.height / @character.cheight_div
  252.         else
  253.           @cw = bitmap.width / (@character.cwidth_div*4)
  254.           @ch = bitmap.height / (@character.cheight_div*2)
  255.         end
  256.         self.ox = @cw / 2
  257.         self.oy = @ch
  258.       end
  259.     end
  260.   end
  261.  
  262. end  
  263.  
  264. #=*==========================================================================*=#
  265. # ** END OF FILE
  266. #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment