Project1

标题: 【ACE】随机行走图\脸图NPC [打印本页]

作者: fux2    时间: 2012-1-11 13:53
标题: 【ACE】随机行走图\脸图NPC
本帖最后由 fux2 于 2012-1-15 13:34 编辑

范例在此
http://115.com/file/be4xpqz5
随机形象NPC范例.rar

由于Dir不能访问加密包,所以要加密的游戏请勿使用此脚本.

脚本如下
  1. #~ 2012.1.11
  2. #~   by Fux2
  3. #~
  4. #~ 随机形象事件设置方法:
  5. #~   1.随意给事件设置一个行走图
  6. #~   2.事件名称后面加上\r
  7. #~ 随机脸图呼出方法:
  8. #~   1.显示文章的内容末尾加上'fs

  9. #~ 脸图拼接时会有需要同步颜色的问题,将同步的文件名末尾加上!同步组编号
  10. #~ 末尾加上?的用途自行揣摩(PIA

  11. module Fux2

  12.   Partres =     ['Cloak','Body','Cloth','Glasses','Head','Kemono']
  13.   FacePartres = ['RearHair!2','Neck','Face!1','Neck?','Eyes?','Eyes','Mouth!1','Nose!1','FrontHair?!2','FrontHair!2']
  14.   
  15.   def self.get_random_character
  16.     bit = Bitmap.new(96,128)
  17.     tbit=[]
  18.     result = [];Partres.size.times{result<<[]}
  19.     Dir["Graphics/rand_cha/*"].each do |i|
  20.       Partres.each_with_index do |j,k|
  21.         result[k] << i if i[/\/#{j}\d*\.png$/]
  22.       end
  23.     end
  24.     result.each_index do |i|
  25.       result[i]=result[i][rand(result[i].size)]
  26.       tbit<<Bitmap.new(result[i])
  27.     end
  28.     tbit.each do |i|
  29.       a=rand(i.width/96)*96
  30.       b=rand(i.height/128)*128
  31.       bit.blt(0,0,i,Rect.new(a,b,96,128))
  32.     end
  33.     return bit
  34.   end
  35.   
  36.   def self.get_random_face
  37.     bit = Bitmap.new(96,96)
  38.     tbit = []
  39.     ext = {};pext = {};rxt = {};pxt = {}
  40.     result = [];FacePartres.size.times{result<<[]}
  41.     Dir["Graphics/rand_face/*"].each do |i|
  42.       FacePartres.each_with_index do |j,k|
  43.         if j[/\?/]
  44.           result[k] << i if i[/\/#{j.gsub(/\?|\!\d+/){''}}\d*[^\d]\.png$/]
  45.           sorts = [k,FacePartres.index(j.gsub('?'){''})].sort!
  46.           ext[sorts[0]] = sorts[1]
  47.           pext[sorts[1]] = sorts[0]
  48.           if j[/\!\d+$/]
  49.             index = j.gsub(/^.*\!(\d+)$/){$1}.to_i
  50.             rxt[index] ||= []
  51.             rxt[index] << k unless rxt[index].include?(k)
  52.           end
  53.         elsif j[/\!\d+$/]
  54.           result[k] << i if i[/\/#{j.gsub(/\!\d+/){''}}\d*\.png$/]
  55.           index = j.gsub(/^.*\!(\d+)$/){$1}.to_i
  56.           rxt[index] ||= []
  57.           rxt[index] << k unless rxt[index].include?(k)
  58.         else
  59.           result[k] << i if i[/\/#{j}\d*\.png$/]
  60.         end
  61.       end
  62.     end
  63.     rxt.each_value{|i| i.sort!;[*1...i.size].each{|j| pxt[i[j]] = i[0]}}
  64.     result.each_index do |i|
  65.       if ext[i]
  66.         num=rand(result[i].size)
  67.         result[i]=result[i][num]
  68.         result[ext[i]]=result[ext[i]][num]
  69.       else
  70.         result[i]=result[i][rand(result[i].size)] if result[i].is_a?(Array)
  71.       end
  72.       tbit<<Bitmap.new(result[i]) if result[i]
  73.     end
  74.     posiarr = []
  75.     tbit.each_with_index do |i,j|
  76.       if pext[j]
  77.         a = posiarr[pext[j]][0]
  78.         b = posiarr[pext[j]][1]
  79.         bit.blt(-16,-16,i,Rect.new(a,b,128,128))
  80.       elsif pxt[j]
  81.         a = posiarr[pxt[j]][0]
  82.         b = posiarr[pxt[j]][1]
  83.         bit.blt(-16,-16,i,Rect.new(a,b,128,128))
  84.       else
  85.         a=rand(i.width/128)*128
  86.         b=rand(i.height/128)*128
  87.         bit.blt(-16,-16,i,Rect.new(a,b,128,128))
  88.       end
  89.       posiarr << [a,b]
  90.     end
  91.     return bit
  92.   end
  93.   
  94. end

  95. class Game_Event < Game_Character
  96.   
  97.   alias ini initialize unless $@
  98.   def initialize(map_id, event)
  99.     ini(map_id, event)
  100.   end
  101.   
  102.   def randc
  103.     return @event.name[/\\r/]
  104.   end

  105.   def name
  106.     return @event.name.gsub(/\\r/){""}
  107.   end
  108.   
  109. end

  110. class Sprite_Character < Sprite_Base
  111.   
  112.   def set_character_bitmap
  113.     if @character.is_a?(Game_Event) && @character.randc
  114.       self.bitmap = Fux2.get_random_character
  115.       sign = 66
  116.     else
  117.       self.bitmap = Cache.character(@character_name)
  118.       sign = @character_name[/^[\!\$]./]
  119.     end
  120.     if sign == 66 or (sign && sign.include?('))
  121.       @cw = bitmap.width / 3
  122.       @ch = bitmap.height / 4
  123.     else
  124.       @cw = bitmap.width / 12
  125.       @ch = bitmap.height / 8
  126.     end
  127.     self.ox = @cw / 2
  128.     self.oy = @ch
  129.   end
  130.   
  131. end

  132. class Window_Message < Window_Base

  133.   def new_page(text, pos)
  134.     contents.clear
  135.     if text[/'fs/]
  136.       fux2randface = true
  137.       text.gsub!(/'fs/){''}
  138.       $game_message.face_name = "?"
  139.     else
  140.       fux2randface = false
  141.     end
  142.     draw_face($game_message.face_name, $game_message.face_index, 0, 0,true,fux2randface)
  143.     reset_font_settings
  144.     pos[:x] = new_line_x
  145.     pos[:y] = 0
  146.     pos[:new_x] = new_line_x
  147.     pos[:height] = calc_line_height(text)
  148.     clear_flags
  149.   end
  150.   
  151. end

  152. class Window_Base < Window

  153.   def draw_face(face_name, face_index, x, y, enabled = true, randface = false)
  154.     bitmap = randface ? Fux2.get_random_face : Cache.face(face_name)
  155.     rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
  156.     contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
  157.     bitmap.dispose
  158.   end
  159.   
  160. end
复制代码

作者: Sonic1997    时间: 2012-1-11 13:59
本帖最后由 Sonic1997 于 2012-1-10 22:03 编辑

沙发{:nm_6:}的确是一个很实用的功能,这样NPC就不用每次都一模一样了{:nm_7:}
作者: xuzhengchi    时间: 2012-1-11 16:19
对同一个NPC对话两次脸也随机了
作者: fux2    时间: 2012-1-11 18:09
xuzhengchi 发表于 2012-1-11 16:19
对同一个NPC对话两次脸也随机了

当然啦,不然为什么脸图和行走图在编辑器里要分开编辑呢.
作者: xiangelt    时间: 2012-1-12 02:47
可以用來創作變臉高手
作者: 越前リョーマ    时间: 2012-1-13 19:17
xiangelt 发表于 2012-1-12 02:47
可以用來創作變臉高手

根本就是槽点嘛我了个去 = =
作者: zeldafd    时间: 2012-1-16 07:30
樓主腳本的效果讓我又爱又恨...是,npc的样子更多元化,但,在对話时…同一劇情中的数次对話也不同样-_-:
作者: jessekiss    时间: 2012-1-28 21:16
楼主的脚本稍微改动一下实现了同步,但是貌似衣服无法对应?
作者: 垨護Satr婞諨    时间: 2012-2-6 17:04
谢谢楼主~




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1