设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1252|回复: 1
打印 上一主题 下一主题

[已经过期] 使用Kahs的灯光脚本后,使用脚本DataManager.setup_new_game崩溃

[复制链接]

Lv3.寻梦者

梦石
0
星屑
966
在线时间
87 小时
注册时间
2022-12-26
帖子
98
跳转到指定楼层
1
发表于 2023-1-24 19:41:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 爱羊真知己 于 2023-1-24 19:46 编辑

我在使用Kahs的灯光脚本后,直接使用脚本DataManager.setup_new_game会崩溃。请问怎么避免这个情况呢?
脚本如下:
RUBY 代码复制
  1. =begin
  2. #-------------------------------------------------------------------------------
  3. # * [ACE] Khas Awesome Light Effects
  4. #-------------------------------------------------------------------------------
  5. # * 作者 Khas Arcthunder - arcthunder.site40.net
  6. # * 版本: 1.0 EN
  7. # * Released on: 17/01/2012
  8. #
  9. #-------------------------------------------------------------------------------
  10. # * Terms of Use
  11. #-------------------------------------------------------------------------------
  12. # When using any Khas script, you agree with the following terms:
  13. # 1. You must give credit to Khas;
  14. # 2. All Khas scripts are licensed under a Creative Commons license;
  15. # 3. All Khas scripts are for non-commercial projects. If you need some script
  16. #    for your commercial project (I accept requests for this type of project),
  17. #    send an email to [email protected] with your request;
  18. # 4. All Khas scripts are for personal use, you can use or edit for your own
  19. #    project, but you are not allowed to post any modified version;
  20. # 5. You can’t give credit to yourself for posting any Khas script;
  21. # 6. If you want to share a Khas script, don’t post the direct download link,
  22. #    please redirect the user to arcthunder.site40.net
  23. #
  24. #-------------------------------------------------------------------------------
  25. # * 特点
  26. #-------------------------------------------------------------------------------
  27. # - 真实的灯光
  28. # - 灯光不会穿过墙、遮挡物和天花板
  29. # - 静态光源
  30. # - 动态光源(角色手电)
  31. # - 多种效果
  32. # - 使用简单 (注释)
  33. #
  34. #-------------------------------------------------------------------------------
  35. # * 警告 - 表现效果
  36. #-------------------------------------------------------------------------------
  37. # 这个脚本对于老人机杀伤力巨大! 本脚本测试于 Core 2 Duo E4500 和 Core i5,
  38. # 以下为会影响表现效果的地方:
  39. #
  40. # 1. 地图大小
  41. # 本脚本会在地图表面搜索,为了剪切灯光图片.大地图会增加表面的读取,影响动态光源
  42.   的表现效果。地图大小不会影响静态灯光的效果。
  43.  
  44. #
  45. # 2. 灯光效果数量
  46. # 本脚本在屏幕上绘制,绘制之前还会判断灯光效果是否在屏幕之外。
  47.  (在地图外的话脚本将不会绘制超出的灯光效果). 太多灯光将会使游戏卡吨,这是我猜的。
  48.  
  49. # 3. 灯光效果图片大小
  50. # 图片越大,将其绘制成动态光源耗时越长,建议图片最大为200x200像素
  51. #-------------------------------------------------------------------------------
  52. # * 注意 - 灯光的图片
  53. #-------------------------------------------------------------------------------
  54. #      1. 图片大小必须是2的倍数 例如: 150x150
  55. #      2. 图片长宽相等,例如: 156x156
  56. #      3. 图片颜色必须要反色
  57. #-------------------------------------------------------------------------------
  58. # * 介绍 - 1. 设定你的效果!
  59. #-------------------------------  ------------------------------------------------
  60. #
  61. # 189行为灯光设定
  62. # 查看默认效果来学习如何使用.
  63. #
  64. #-------------------------------------------------------------------------------
  65. # * 介绍 - 2. 使用你设定的效果!
  66. #-------------------------------------------------------------------------------
  67. # 在事件中添加注释
  68. #
  69. # [light x]
  70. #
  71. # x为效果ID
  72. #
  73. #-------------------------------------------------------------------------------
  74. # * 介绍 - 3. 灯笼效果!
  75. #-------------------------------------------------------------------------------
  76. # 动态光源(灯笼)默认是不可见的,这需要你使用脚本呼出来显示灯笼T:
  77. #
  78. # l = $game_map.lantern
  79. #
  80.    将手灯放入变量
  81.  
  82. # l.set_graphic(i)
  83. #
  84. #   设定灯笼的图片为i,i为在Graphics/Lights  里的灯笼图片名
  85.  
  86. # l.set_multiple_graphics(h)
  87. # 将灯笼的图片设定为 h, h必须在下面的哈希表中填写有
  88. # 结构:
  89. #
  90. # h = {2=>"ld",4=>"ll",6=>"lr",8=>"lu"}
  91. #
  92. # 其中:
  93. # "ld" 当用灯笼的角色向下看时的灯光图片
  94. # "ll" 当用灯笼的角色向左看时的灯光图片
  95. # "lr" 当用灯笼的角色向右看时的灯光图片
  96. # "lu" 当用灯笼的角色向上看时的灯光图片
  97. #
  98. # l.change_owner(角色)
  99. # 将灯笼的主人交给某一角色. 角色必须为以下:
  100.  
  101. # $game_player           <= 玩家
  102. # self_event             <= 事件
  103. # $game_map.events[x]    <= 事件ID
  104. #
  105. # l.set_opacity(o,p)
  106. # 设定灯笼不透明度,
  107. # o 自身的不透明度;
  108. # p 是透明度的变化(闪烁).
  109. #
  110. # l.show
  111. # 以上命令都打完后要以此命令作为结束。
  112. #
  113. # l.hide
  114. # 设定灯笼不可见.
  115. #
  116. #-------------------------------------------------------------------------------
  117. # * 介绍 - 4. 修改画面颜色(黑夜、黄昏效果)!
  118. #-------------------------------------------------------------------------------
  119. # 在灯光之下、游戏画面之上还需要有一层暗暗的画面来突出灯光效果,这层画面默认的
  120.    不透明度为0,你可以用以下脚本来修改画面颜色:
  121. #
  122. # s = $game_map.effect_surface  以这个脚本为开头
  123. #  将画面表面设置变量
  124. #
  125. # s.set_color(r,g,b)
  126. # 立即改变画面颜色, 其中:
  127. # r => 红色含量;
  128. # g => 绿色含量;
  129. # b => 蓝色含量;
  130. #
  131. # s.set_alpha(a)
  132. # 立即改变画面颜色为 a.
  133. #
  134. # s.change_color(时间,r,g,b)
  135. # 在一定时间内逐渐改变画面颜色, 其中:
  136. # 时间 => 变成黑夜的时间 (帧);
  137. # r => 红色含量;
  138. # g => 绿色含量;
  139. # b => 蓝色含量;
  140. #
  141. # s.change_color(时间,r,g,b,a)
  142. # 在一定时间内逐渐改变画面颜色和不透明度, 其中:
  143. # 时间 => 变成黑夜的时间 (帧);
  144. # r => 红色含量;
  145. # g => 绿色含量;
  146. # b => 蓝色含量;
  147. # a => 不透明度
  148. #
  149. # s.change_alpha(时间,a)
  150. # 在一定时间内逐渐改变表面不透明度, where:
  151. # 时间 => 变成黑夜的时间 (帧);
  152. # a => 不透明度
  153. #
  154. #-------------------------------------------------------------------------------
  155. # * 介绍 - 5. 更改画面色调!
  156. #-------------------------------------------------------------------------------
  157. # 你可以使用事件命令中的更改画面色调,请将204行的"Surface_UE" 设定改为 true.
  158. #
  159. # 如果你决定使用这个功能, 请设置一些细节:
  160. # 1. 颜色的数值必须在 0 到 255;
  161. # 2. 时间按帧计算;
  162. # 3. "灰色" 值将等同于不透明度的数值
  163. #
  164. #-------------------------------------------------------------------------------
  165. # * Instructions - 6. 设定你的图块标志!
  166. #-------------------------------------------------------------------------------
  167. # 为了使效果图片有遮挡效果, 地图有三种遮挡效果: 墙, 障碍和屋顶.
  168. #   墙会和真的墙一样有影子, 所以要和障碍与屋顶区分开来.
  169. #
  170. #
  171. #-------------------------------------------------------------------------------
  172. # * Setup Part
  173. #-------------------------------------------------------------------------------
  174. =end
  175. module Light_Core
  176.   Effects = { #  <= 不要碰这个
  177. #-------------------------------------------------------------------------------
  178. # 效果设定
  179. #-------------------------------------------------------------------------------
  180. # 格式:X => [图片,不透明度,变化,裁剪图片],   <= 记得在这里加一个逗号!
  181. #
  182. # X => 在事件中使用,效果的ID.
  183. # 图片 => 在 Graphics/Lights 文件夹里;
  184. # 不透明度 => 灯光效果的不透明度;
  185. # 变化 => 灯光效果的不透明度变化(闪烁);
  186. # 裁剪图片 => true:裁剪,false:不裁剪;(制造光线被墙壁遮挡的效果)
  187.  
  188. # X => [图片,不透明度,变化,裁剪]
  189.   0 => ["light",255,0,true],
  190.   1 => ["torch",200,20,true],
  191.   2 => ["torch_m",180,30,true],
  192.   3 => ["light_s",255,0,true],
  193.  
  194.  
  195. #-------------------------------------------------------------------------------
  196. # 其他设定
  197. #-------------------------------------------------------------------------------
  198.   } #  <= 不要碰这个!
  199.  
  200.   # 灯光效果的z轴坐标
  201.   Surface_Z = 600
  202.  
  203.   # 是否允许使用事件的更改画面色调命令?
  204.   Surface_UE = true
  205.  
  206.   # 屋顶的地形标志
  207.   Roof_Tag = 5
  208.   # 墙壁的地形标志
  209.   Wall_Tag = 6
  210.   # 障碍物的地形标志
  211.   Block_Tag = 7
  212.  
  213.   # 别动它!
  214.   ACC = Math.tan(Math::PI/26)
  215. end
  216. #-------------------------------------------------------------------------------
  217. # Script
  218. #-------------------------------------------------------------------------------
  219. module Cache
  220.   def self.light(filename)
  221.     load_bitmap("Graphics/Lights/", filename)
  222.   end
  223. end
  224. module Light_Bitcore
  225.   include Light_Core
  226.   def self.initialize
  227.     @@buffer = {}
  228.     Effects.values.each { |effect| Light_Bitcore.push(effect[0])}
  229.   end
  230.   def self::[](key)
  231.     return @@buffer[key]
  232.   end
  233.   def self.push(key)
  234.     return if @@buffer.keys.include?(key)
  235.     @@buffer[key] = Cache.light(key)
  236.   end
  237. end
  238. Light_Bitcore.initialize
  239. class Light_SSource
  240.   attr_reader :real_x
  241.   attr_reader :real_y
  242.   attr_reader :range
  243.   attr_accessor :bitmap
  244.   attr_reader :w
  245.   attr_reader :h
  246.   attr_reader :hs
  247.   def initialize(char,bitmap,opacity,plus,hs)
  248.     sync(char)
  249.     @key = bitmap
  250.     @bitmap = Light_Bitcore[@key].clone
  251.     @range = @bitmap.width/2
  252.     @w = @bitmap.width
  253.     @h = @bitmap.height
  254.     @mr = @range - 16
  255.     @opacity = opacity
  256.     @plus = plus
  257.     @hs = hs
  258.     render if @hs
  259.   end
  260.   def render
  261.     tx = x
  262.     ty = y
  263.     tsx = x + @range
  264.     tsy = y + @range
  265.     dr = @range*2
  266.     for s in $game_map.surfaces
  267.       next if !s.visible?(tsx,tsy) || !s.within?(tx,tx+dr,ty,ty+dr)
  268.       s.render_shadow(tx,ty,tsx,tsy,@range,@bitmap)
  269.     end
  270.   end
  271.   def restore
  272.     return unless @bitmap.nil?
  273.     @bitmap = Light_Bitcore[@key].clone
  274.     render if @hs
  275.   end
  276.   def opacity
  277.     @plus == 0 ? @opacity : (@opacity + rand(@plus))
  278.   end
  279.   def sx
  280.     return $game_map.adjust_x(@real_x)*32-@mr
  281.   end
  282.   def sy
  283.     return $game_map.adjust_y(@real_y)*32-@mr
  284.   end
  285.   def sync(char)
  286.     @real_x = char.real_x
  287.     @real_y = char.real_y
  288.   end
  289.   def x
  290.     return (@real_x*32 - @mr).to_f
  291.   end
  292.   def y
  293.     return (@real_y*32 - @mr).to_f
  294.   end
  295.   def dispose
  296.     return if @bitmap.nil?
  297.     @bitmap.dispose
  298.     @bitmap = nil
  299.   end
  300. end
  301. class Light_DSource < Light_SSource
  302.   attr_reader :bitmap
  303.   attr_reader :visible
  304.   def initialize
  305.     @key = nil
  306.     @bitmap = nil
  307.     @opacity = 255
  308.     @plus = 0
  309.     @char = $game_player
  310.     @visible = false
  311.   end
  312.   def set_opacity(o,p)
  313.     @opacity = o
  314.     @plus = p
  315.   end
  316.   def set_graphic(sb)
  317.     dispose
  318.     @key = {2=>sb,4=>sb,6=>sb,8=>sb}
  319.     Light_Bitcore.push(sb)
  320.     @bitmap = {2=>Light_Bitcore[@key[2]].clone,4=>Light_Bitcore[@key[4]].clone,6=>Light_Bitcore[@key[6]].clone,8=>Light_Bitcore[@key[8]].clone}
  321.     @range = @bitmap[2].width/2
  322.     @w = @bitmap[2].width
  323.     @h = @bitmap[2].height
  324.     @mr = @range - 16
  325.   end
  326.   def set_multiple_graphics(ba)
  327.     dispose
  328.     @key = ba
  329.     @key.values.each {|key| Light_Bitcore.push(key)}
  330.     @bitmap = {2=>Light_Bitcore[@key[2]].clone,4=>Light_Bitcore[@key[4]].clone,6=>Light_Bitcore[@key[6]].clone,8=>Light_Bitcore[@key[8]].clone}
  331.     @range = @bitmap[2].width/2
  332.     @w = @bitmap[2].width
  333.     @h = @bitmap[2].height
  334.     @mr = @range - 16
  335.   end
  336.   def get_graphic
  337.     return @bitmap[@char.direction].clone
  338.   end
  339.   def show
  340.     return if @bitmap.nil?
  341.     @visible = true
  342.   end
  343.   def hide
  344.     @visible = false
  345.   end
  346.   def restore
  347.     return if @key.nil?
  348.     @key.values.each {|key| Light_Bitcore.push(key)}
  349.     @bitmap = {2=>Light_Bitcore[@key[2]].clone,4=>Light_Bitcore[@key[4]].clone,6=>Light_Bitcore[@key[6]].clone,8=>Light_Bitcore[@key[8]].clone}
  350.   end
  351.   def dispose
  352.     return if @bitmap.nil?
  353.     @bitmap.values.each { |b| b.dispose }
  354.     @bitmap = nil
  355.   end
  356.   def change_owner(char)
  357.     @char = char
  358.   end
  359.   def render
  360.   end
  361.   def sx
  362.     return $game_map.adjust_x(@char.real_x)*32-@mr
  363.   end
  364.   def sy
  365.     return $game_map.adjust_y(@char.real_y)*32-@mr
  366.   end
  367.   def x
  368.     return (@char.real_x*32 - @mr).to_f
  369.   end
  370.   def y
  371.     return (@char.real_y*32 - @mr).to_f
  372.   end
  373. end
  374. class Light_Surface
  375.   def initialize
  376.     @ta = @a = 0
  377.     @tr = @r = 255
  378.     @tg = @g = 255
  379.     @tb = @b = 255
  380.     @va = @vr = @vg = @vb = 0.0
  381.     @timer = 0
  382.   end
  383.   def refresh
  384.     return if @timer == 0
  385.     @a += @va
  386.     @r += @vr
  387.     @g += @vg
  388.     @b += @vb
  389.     $game_map.light_surface.opacity = @a
  390.     @timer -= 1
  391.   end
  392.   def change_color(time,r,g,b,a=nil)
  393.     r = 0 if r < 0; r = 255 if r > 255
  394.     g = 0 if g < 0; g = 255 if g > 255
  395.     b = 0 if b < 0; b = 255 if b > 255
  396.     unless a.nil?
  397.       a = 0 if a < 0; a = 255 if a > 255
  398.     end
  399.     @timer = time
  400.     @tr = 255-r
  401.     @tg = 255-g
  402.     @tb = 255-b
  403.     @va = (a.nil? ? 0 : (a-@a).to_f/@timer)
  404.     @vr = (@tr - @r).to_f/@timer
  405.     @vg = (@tg - @g).to_f/@timer
  406.     @vb = (@tb - @b).to_f/@timer
  407.   end
  408.   def change_alpha(time,a)
  409.     a = 0 if a < 0; a = 255 if a > 255
  410.     @timer = time
  411.     @ta = a
  412.     @vr = @vg = @vb = 0.0
  413.     @va = (a-@a).to_f/@timer
  414.   end
  415.   def set_color(r,g,b)
  416.     r = 0 if r < 0; r = 255 if r > 255
  417.     g = 0 if g < 0; g = 255 if g > 255
  418.     b = 0 if b < 0; b = 255 if b > 255
  419.     @tr = @r = 255-r
  420.     @tg = @g = 255-g
  421.     @tb = @b = 255-b
  422.     @va = @vr = @vg = @vb = 0.0
  423.     @timer = 0
  424.   end
  425.   def set_alpha(a)
  426.     a = 0 if a < 0; a = 255 if a > 255
  427.     @ta = @a = a
  428.     $game_map.light_surface.opacity = @a
  429.     @va = @vr = @vg = @vb = 0.0
  430.     @timer = 0
  431.   end
  432.   def alpha
  433.     return @a
  434.   end
  435.   def color
  436.     return Color.new(@r,@g,@b)
  437.   end
  438. end
  439. class Game_Map
  440.   include Light_Core
  441.   attr_accessor :light_surface
  442.   attr_accessor :light_sources
  443.   attr_accessor :surfaces
  444.   attr_accessor :effect_surface
  445.   attr_accessor :lantern
  446.   alias kbl_setup_events setup_events
  447.   alias kbl_initialize initialize
  448.   alias kbl_update update
  449.   def initialize
  450.     kbl_initialize
  451.     @effect_surface = Light_Surface.new
  452.     @lantern = Light_DSource.new
  453.   end
  454.   def update(arg)
  455.     @effect_surface.refresh if arg
  456.     kbl_update(arg)
  457.   end
  458.   def first_tag(x,y)
  459.     tag = tileset.flags[tile_id(x,y,0)] >> 12
  460.     return tag > 0 ? tag : 0
  461.   end
  462.   def setup_events
  463.     @light_sources.nil? ? @light_sources = [] : @light_sources.clear
  464.     setup_surfaces
  465.     merge_surfaces
  466.     kbl_setup_events
  467.   end
  468.   def setup_surfaces
  469.     @surfaces = []
  470.     for x in 0..(width-1)
  471.       for y in 0..(height-1)
  472.         tag = first_tag(x,y)
  473.         if tag == Wall_Tag
  474.           i = tile_id(x,y,0)
  475.           if i & 0x02 == 0x02
  476.             @surfaces << Block_SD.new(x*32,y*32,x*32+32,y*32)
  477.           end
  478.           if i & 0x04 == 0x04
  479.             @surfaces << Block_WR.new(x*32+31,y*32,x*32+31,y*32+32)
  480.             @surfaces << Block_IL.new(x*32+32,y*32,x*32+32,y*32+32)
  481.           end
  482.           if i & 0x01 == 0x01
  483.             @surfaces << Block_IR.new(x*32-1,y*32,x*32-1,y*32+32)
  484.             @surfaces << Block_WL.new(x*32,y*32,x*32,y*32+32)
  485.           end
  486.         elsif tag == Roof_Tag
  487.           i = tile_id(x,y,0)
  488.           @surfaces << Block_SU.new(x*32,y*32,x*32+32,y*32) if i & 0x02 == 0x02
  489.           @surfaces << Block_SR.new(x*32+31,y*32,x*32+31,y*32+32) if i & 0x04 == 0x04
  490.           @surfaces << Block_SL.new(x*32,y*32,x*32,y*32+32) if i & 0x01 == 0x01
  491.         elsif tag == Block_Tag
  492.           f = tileset.flags[tile_id(x,y,0)]
  493.           @surfaces << Block_SL.new(x*32,y*32,x*32,y*32+32) if f & 0x02 == 0x02
  494.           @surfaces << Block_SR.new(x*32+31,y*32,x*32+31,y*32+32) if f & 0x04 == 0x04
  495.           @surfaces << Block_SU.new(x*32,y*32,x*32+32,y*32) if f & 0x08 == 0x08
  496.         end
  497.       end
  498.     end
  499.   end
  500.   def merge_surfaces
  501.     new_surfaces = []
  502.     hs = []; vs = []
  503.     ws = []; is = []
  504.     for surface in @surfaces
  505.       if surface.type & 0x05 == 0
  506.         hs << surface
  507.       else
  508.         if surface.type & 0x010 == 0
  509.           vs << surface
  510.         else
  511.           if surface.type & 0x08 == 0
  512.             ws << surface
  513.           else
  514.             is << surface
  515.           end
  516.         end
  517.       end
  518.     end
  519.     for surface in hs
  520.       surface.ready ? next : surface.ready = true
  521.       for s in hs
  522.         next if s.ready || s.y1 != surface.y1 || surface.type != s.type
  523.         if s.x2 == surface.x1
  524.           surface.x1 = s.x1
  525.           s.trash = true
  526.           s.ready = true
  527.           surface.ready = false
  528.         elsif s.x1 == surface.x2
  529.           surface.x2 = s.x2
  530.           s.trash = true
  531.           s.ready = true
  532.           surface.ready = false
  533.         end
  534.       end
  535.     end
  536.     hs.each { |s| @surfaces.delete(s) if s.trash}
  537.     for surface in vs
  538.       surface.ready ? next : surface.ready
  539.       for s in vs
  540.         next if s.ready || s.x1 != surface.x1
  541.         if s.y2 == surface.y1
  542.           surface.y1 = s.y1
  543.           s.trash = true
  544.           s.ready = true
  545.           surface.ready = false
  546.         elsif s.y1 == surface.y2
  547.           surface.y2 = s.y2
  548.           s.trash = true
  549.           s.ready = true
  550.           surface.ready = false
  551.         end
  552.       end
  553.     end
  554.     vs.each { |s| @surfaces.delete(s) if s.trash}
  555.     for surface in ws
  556.       surface.ready ? next : surface.ready
  557.       for s in ws
  558.         next if s.ready || s.x1 != surface.x1
  559.         if s.y2 == surface.y1
  560.           surface.y1 = s.y1
  561.           s.trash = true
  562.           s.ready = true
  563.           surface.ready = false
  564.         elsif s.y1 == surface.y2
  565.           surface.y2 = s.y2
  566.           s.trash = true
  567.           s.ready = true
  568.           surface.ready = false
  569.         end
  570.       end
  571.     end
  572.     ws.each { |s| @surfaces.delete(s) if s.trash}
  573.     for surface in is
  574.       surface.ready ? next : surface.ready
  575.       for s in is
  576.         next if s.ready || s.x1 != surface.x1
  577.         if s.y2 == surface.y1
  578.           surface.y1 = s.y1
  579.           s.trash = true
  580.           s.ready = true
  581.           surface.ready = false
  582.         elsif s.y1 == surface.y2
  583.           surface.y2 = s.y2
  584.           s.trash = true
  585.           s.ready = true
  586.           surface.ready = false
  587.         end
  588.       end
  589.     end
  590.     is.each { |s| @surfaces.delete(s) if s.trash}
  591.   end
  592. end
  593. class Game_Event < Game_Character
  594.   alias kbl_initialize initialize
  595.   alias kbl_setup_page setup_page
  596.   def initialize(m,e)
  597.     @light = nil
  598.     kbl_initialize(m,e)
  599.   end
  600.   def setup_page(np)
  601.     kbl_setup_page(np)
  602.     setup_light(np.nil?)
  603.   end
  604.   def setup_light(dispose)
  605.     unless @light.nil?
  606.       $game_map.light_sources.delete(self)
  607.       @light.dispose
  608.       @light = nil
  609.     end
  610.     unless dispose && @list.nil?
  611.       for command in @list
  612.         if command.code == 108 && command.parameters[0].include?("[light")
  613.           command.parameters[0].scan(/\[light ([0.0-9.9]+)\]/)
  614.           effect = Light_Core::Effects[$1.to_i]
  615.           @light = Light_SSource.new(self,effect[0],effect[1],effect[2],effect[3])
  616.           $game_map.light_sources << self
  617.           return
  618.         end
  619.       end
  620.     end
  621.   end
  622.   def draw_light
  623.     sx = @light.sx
  624.     sy = @light.sy
  625.     w = @light.w
  626.     h = @light.h
  627.     return if sx > 544 && sy > 416 && sx + w < 0 && sy + h < 0
  628.     $game_map.light_surface.bitmap.blt(sx,sy,@light.bitmap,Rect.new(0,0,w,h),@light.opacity)
  629.   end
  630.   def dispose_light
  631.     @light.dispose
  632.   end
  633.   def restore_light
  634.     @light.restore
  635.   end
  636. end
  637. if Light_Core::Surface_UE
  638.   class Game_Interpreter
  639.     def command_223
  640.       $game_map.effect_surface.change_color(@params[1],@params[0].red,@params[0].green,@params[0].blue,@params[0].gray)
  641.       wait(@params[1]) if @params[2]
  642.     end
  643.   end
  644. end
  645. class Game_Interpreter
  646.   def self_event
  647.     return $game_map.events[@event_id]
  648.   end
  649. end
  650. class Block_Surface
  651.   include Light_Core
  652.   attr_accessor :x1
  653.   attr_accessor :y1
  654.   attr_accessor :x2
  655.   attr_accessor :y2
  656.   attr_accessor :ready
  657.   attr_accessor :trash
  658.   def initialize(x1,y1,x2,y2)
  659.     @x1 = x1
  660.     @y1 = y1
  661.     @x2 = x2
  662.     @y2 = y2
  663.     @ready = false
  664.     @trash = false
  665.   end
  666.   def within?(min_x,max_x,min_y,max_y)
  667.     return @x2 > min_x && @x1 < max_x && @y2 > min_y && @y1 < max_y
  668.   end
  669. end
  670. class Block_SL < Block_Surface
  671.   attr_reader :type
  672.   def initialize(x1,y1,x2,y2)
  673.     super(x1,y1,x2,y2)
  674.     @type = 0x01
  675.   end
  676.   def visible?(sx,sy)
  677.     return sx < @x1
  678.   end
  679.   def render_shadow(phx,phy,sx,sy,range,bitmap)
  680.     @m1 = (@y1-sy)/(@x1-sx)
  681.     @n1 = sy - @m1*sx
  682.     @m2 = (@y2-sy)/(@x2-sx)
  683.     @n2 = sy - @m2*sx
  684.     for x in @x1..(sx+range)
  685.       init = shadow_iy(x)
  686.       bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+3)
  687.     end
  688.   end
  689.   def shadow_iy(x)
  690.     return @m1*x+@n1
  691.   end
  692.   def shadow_fy(x)
  693.     return @m2*x+@n2
  694.   end
  695. end
  696. class Block_SR < Block_Surface
  697.   attr_reader :type
  698.   def initialize(x1,y1,x2,y2)
  699.     super(x1,y1,x2,y2)
  700.     @type = 0x04
  701.   end
  702.   def visible?(sx,sy)
  703.     return sx > @x1
  704.   end
  705.   def render_shadow(phx,phy,sx,sy,range,bitmap)
  706.     @m1 = (@y1-sy)/(@x1-sx)
  707.     @n1 = sy - @m1*sx
  708.     @m2 = (@y2-sy)/(@x2-sx)
  709.     @n2 = sy - @m2*sx
  710.     for x in (sx-range).to_i..@x1
  711.       init = shadow_iy(x)
  712.       bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+3)
  713.     end
  714.   end
  715.   def shadow_iy(x)
  716.     return @m1*x+@n1
  717.   end
  718.   def shadow_fy(x)
  719.     return @m2*x+@n2
  720.   end
  721. end
  722. class Block_IL < Block_Surface
  723.   attr_reader :type
  724.   def initialize(x1,y1,x2,y2)
  725.     super(x1,y1,x2,y2)
  726.     @type = 0x019
  727.   end
  728.   def visible?(sx,sy)
  729.     return sx < @x1 && sy > @y1
  730.   end
  731.   def render_shadow(phx,phy,sx,sy,range,bitmap)
  732.     @m1 = (@y1-sy)/(@x1-sx)
  733.     @n1 = @y1 - @m1*@x1
  734.     @m2 = (@y2-sy)/(@x2-sx)
  735.     @m2 = 0 if @m2 > 0
  736.     @n2 = @y2 - @m2*@x2
  737.     for x in @x1..(sx+range)
  738.       init = shadow_iy(x).floor
  739.       bitmap.clear_rect(x-phx,init-3-phy,1,shadow_fy(x)-init+3)
  740.     end
  741.   end
  742.   def shadow_iy(x)
  743.     return @m1*x+@n1
  744.   end
  745.   def shadow_fy(x)
  746.     return @m2*x+@n2
  747.   end
  748. end
  749. class Block_IR < Block_Surface
  750.   attr_reader :type
  751.   def initialize(x1,y1,x2,y2)
  752.     super(x1,y1,x2,y2)
  753.     @type = 0x01c
  754.   end
  755.   def visible?(sx,sy)
  756.     return sx > @x1 && sy > @y1
  757.   end
  758.   def render_shadow(phx,phy,sx,sy,range,bitmap)
  759.     @m1 = (@y1-sy)/(@x1-sx)
  760.     @n1 = @y1 - @m1*@x1
  761.     @m2 = (@y2-sy)/(@x2-sx)
  762.     @m2 = 0 if @m2 < 0
  763.     @n2 = @y2 - @m2*@x2
  764.     for x in (sx-range).to_i..@x1
  765.       init = shadow_iy(x).floor
  766.       bitmap.clear_rect(x-phx,init-3-phy,1,shadow_fy(x)-init+3)
  767.     end
  768.   end
  769.   def shadow_iy(x)
  770.     return @m1*x+@n1
  771.   end
  772.   def shadow_fy(x)
  773.     return @m2*x+@n2
  774.   end
  775. end
  776. class Block_WL < Block_Surface
  777.   attr_reader :type
  778.   def initialize(x1,y1,x2,y2)
  779.     super(x1,y1,x2,y2)
  780.     @type = 0x011
  781.   end
  782.   def visible?(sx,sy)
  783.     return sx < @x1 && sy < @y2
  784.   end
  785.   def render_shadow(phx,phy,sx,sy,range,bitmap)
  786.     @m1 = (@y1-sy)/(@x1-sx)
  787.     @n1 = sy - @m1*sx
  788.     @m2 = (@y2-sy)/(@x2-sx)
  789.     @n2 = sy - @m2*sx
  790.     for x in @x1..(sx+range)
  791.       init = shadow_iy(x)
  792.       bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+2)
  793.     end
  794.   end
  795.   def shadow_iy(x)
  796.     return @m1*x+@n1
  797.   end
  798.   def shadow_fy(x)
  799.     return @m2*x+@n2
  800.   end
  801. end
  802. class Block_WR < Block_Surface
  803.   attr_reader :type
  804.   def initialize(x1,y1,x2,y2)
  805.     super(x1,y1,x2,y2)
  806.     @type = 0x014
  807.   end
  808.   def visible?(sx,sy)
  809.     return sx > @x1 && sy < @y2
  810.   end
  811.   def render_shadow(phx,phy,sx,sy,range,bitmap)
  812.     @m1 = (@y1-sy)/(@x1-sx)
  813.     @n1 = sy - @m1*sx
  814.     @m2 = (@y2-sy)/(@x2-sx)
  815.     @n2 = sy - @m2*sx
  816.     for x in (sx-range).to_i..@x1
  817.       init = shadow_iy(x)
  818.       bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+2)
  819.     end
  820.   end
  821.   def shadow_iy(x)
  822.     return @m1*x+@n1
  823.   end
  824.   def shadow_fy(x)
  825.     return @m2*x+@n2
  826.   end
  827. end
  828. class Block_SU < Block_Surface
  829.   attr_reader :type
  830.   def initialize(x1,y1,x2,y2)
  831.     super(x1,y1,x2,y2)
  832.     @type = 0x02
  833.   end
  834.   def visible?(sx,sy)
  835.     return sy < @y1
  836.   end
  837.   def render_shadow(phx,phy,sx,sy,range,bitmap)
  838.     if @x1 == sx
  839.       @m1 = nil
  840.     else
  841.       @m1 = (@y1-sy)/(@x1-sx)
  842.       @m1 += ACC if @m1 < -ACC
  843.       @n1 = @y1 - @m1*@x1
  844.     end
  845.     if @x2 == sx
  846.       @m2 = nil
  847.     else
  848.       @m2 = (@y2-sy)/(@x2-sx)
  849.       @n2 = sy - @m2*sx
  850.     end
  851.     for y in @y1..(sy+range)
  852.       init = shadow_ix(y)
  853.       bitmap.clear_rect(init-phx,y-phy,shadow_fx(y)-init+1,1)
  854.     end
  855.   end
  856.   def shadow_ix(y)
  857.     return @m1.nil? ? @x1 : (y-@n1)/@m1
  858.   end
  859.   def shadow_fx(y)
  860.     return @m2.nil? ? @x2 : (y-@n2)/@m2
  861.   end
  862. end
  863. class Block_SD < Block_Surface
  864.   attr_reader :type
  865.   def initialize(x1,y1,x2,y2)
  866.     super(x1,y1,x2,y2)
  867.     @type = 0x08
  868.   end
  869.   def visible?(sx,sy)
  870.     return sy > @y1
  871.   end
  872.   def render_shadow(phx,phy,sx,sy,range,bitmap)
  873.     if @x1 == sx
  874.       @m1 = nil
  875.     else
  876.       @m1 = (@y1-sy)/(@x1-sx)
  877.       @m1 -= ACC if @m1 > ACC
  878.       @n1 = sy - @m1*sx
  879.     end
  880.     if x2 == sx
  881.       @m2 = nil
  882.     else
  883.       @m2 = (@y2-sy)/(@x2-sx)
  884.       @n2 = sy - @m2*sx
  885.     end
  886.     for y in (sy-range).to_i..@y1
  887.       init = shadow_ix(y)
  888.       bitmap.clear_rect(init-phx,y-phy,shadow_fx(y)-init+1,1)
  889.     end
  890.   end
  891.   def shadow_ix(y)
  892.     return @m1.nil? ? @x1 : (y-@n1)/@m1
  893.   end
  894.   def shadow_fx(y)
  895.     return @m2.nil? ? @x2 : (y-@n2)/@m2
  896.   end
  897. end
  898. class Spriteset_Map
  899.   include Light_Core
  900.   alias kbl_initialize initialize
  901.   alias kbl_update update
  902.   alias kbl_dispose dispose
  903.   def initialize
  904.     setup_lights
  905.     kbl_initialize
  906.   end
  907.   def update
  908.     kbl_update
  909.     update_lights
  910.   end
  911.   def dispose
  912.     kbl_dispose
  913.     dispose_lights
  914.   end
  915.   def dispose_lights
  916.     $game_map.lantern.dispose
  917.     $game_map.light_sources.each { |source| source.dispose_light }
  918.     $game_map.light_surface.bitmap.dispose
  919.     $game_map.light_surface.dispose
  920.     $game_map.light_surface = nil
  921.   end
  922.   def update_lights
  923.     $game_map.light_surface.bitmap.clear
  924.     $game_map.light_surface.bitmap.fill_rect(0,0,544,416,$game_map.effect_surface.color)
  925.     $game_map.light_sources.each { |source| source.draw_light }
  926.     return unless $game_map.lantern.visible
  927.     @btr = $game_map.lantern.get_graphic
  928.     x = $game_map.lantern.x
  929.     y = $game_map.lantern.y
  930.     r = $game_map.lantern.range
  931.     sx = x + r
  932.     sy = y + r
  933.     dr = r*2
  934.     $game_map.surfaces.each { |s| s.render_shadow(x,y,sx,sy,r,@btr) if s.visible?(sx,sy) && s.within?(x,x+dr,y,y+dr) }
  935.     $game_map.light_surface.bitmap.blt($game_map.lantern.sx,$game_map.lantern.sy,@btr,Rect.new(0,0,dr,dr),$game_map.lantern.opacity)
  936.   end
  937.   def setup_lights
  938.     @btr = nil
  939.     $game_map.lantern.restore
  940.     $game_map.light_sources.each { |source| source.restore_light }
  941.     $game_map.light_surface = Sprite.new
  942.     $game_map.light_surface.bitmap = Bitmap.new(544,416)
  943.     $game_map.light_surface.bitmap.fill_rect(0,0,544,416,$game_map.effect_surface.color)
  944.     $game_map.light_surface.blend_type = 2
  945.     $game_map.light_surface.opacity = $game_map.effect_surface.alpha
  946.     $game_map.light_surface.z = Surface_Z
  947.   end
  948. end
你好!

Lv3.寻梦者

梦石
0
星屑
966
在线时间
87 小时
注册时间
2022-12-26
帖子
98
2
 楼主| 发表于 2023-1-24 19:49:00 | 只看该作者
补充:在第923行发生NoMethodError,和读取其他游戏存档不一致
你好!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-26 15:33

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表