Project1

标题: 关于一个状态详细说明脚本的BUG【已解决】 [打印本页]

作者: 骷髅岛遗老    时间: 2021-3-6 22:07
标题: 关于一个状态详细说明脚本的BUG【已解决】
本帖最后由 骷髅岛遗老 于 2021-3-7 12:38 编辑
  1. # 状态详细确认窗口
  2. #
  3. # 戦闘時、パーティコマンドに付与されているステートの詳細を確認するためのコマンド
  4. # を追加します。

  5. $imported_yana_scripts ||= {}
  6. $imported_yana_scripts["StateHelpWindow"] = true

  7. module StateHelp
  8.   Buffs = {}
  9.   States = []

  10. # 请按照下面的描写进行备注

  11.   Buffs[[0,:up]] = "HPの強化効果\n最大10段階"
  12.   Buffs[[1,:up]] = "MPの強化効果\n最大10段階"
  13.   Buffs[[2,:up]] = "攻撃力の強化効果\n最大10段階"
  14.   Buffs[[3,:up]] = "防御力の強化効果\n最大10段階"
  15.   Buffs[[4,:up]] = "魔法力の強化効果\n最大10段階"
  16.   Buffs[[5,:up]] = "魔法防御の強化効果\n最大10段階"
  17.   Buffs[[6,:up]] = "敏捷の強化効果\n最大10段階"
  18.   Buffs[[7,:up]] = "運の強化効果\n最大10段階"

  19.   Buffs[[0,:down]] = "HPの弱体効果\n最大5段階"
  20.   Buffs[[1,:down]] = "MPの弱体効果\n最大5段階"
  21.   Buffs[[2,:down]] = "攻撃力の弱体効果\n最大5段階"
  22.   Buffs[[3,:down]] = "防御力の弱体効果\n最大5段階"
  23.   Buffs[[4,:down]] = "魔法力の弱体効果\n最大5段階"
  24.   Buffs[[5,:down]] = "魔法防御の弱体効果\n最大5段階"
  25.   Buffs[[6,:down]] = "敏捷の弱体効果\n最大5段階"
  26.   Buffs[[7,:down]] = "運の弱体効果\n最大5段階"

  27.   States[1]  = "无法战斗:HP为0,无法继续战斗。"
  28.   States[3]  = "挑衅:受到攻击的概率×200%"
  29.   States[4]  = "保护:保护技能发动中,将替代指定队友承受伤害。"
  30.   States[5]  = "被保护:受到保护中,受到的伤害将转移给发动保护的队友。"
  31.   States[7]  = ""
  32.   States[8]  = "不死:不会死亡。"
  33.   States[12]  = "中毒:HP每回合减少50%魔法伤害,同时降低攻击力10%"
  34.   States[13]  = "出血:HP每回合减少50%物理伤害,同时降低防御力10%"
  35.   States[14]  = "灼伤:HP每回合减少50%魔法伤害,同时受到的伤害增加10%。"
  36.   States[15]  = "衰亡:HP每回合减少5%。"
  37.   States[10] = "石化\n行動できない。回避と防御、狙われ率が下がる"
  38.   States[36] = "自身5回合内敏捷+50%,命中率+20%。"
  39.   

  40. end

  41. class Game_BattlerBase
  42.   attr_reader :buffs
  43. end

  44. class Game_BattlerBase
  45.   attr_reader :buffs
  46. end

  47. class Window_State < Window_Selectable
  48.   def initialize(help_window)
  49.     super(0,0,32,32)
  50.     self.x = [Graphics.width / 2 - self.width / 2,0].max
  51.     self.y = [Graphics.height / 2 - self.height / 2,help_window.height].max - 91
  52.     self.openness = 0
  53.     @help_window = help_window
  54.     refresh
  55.   end
  56.   def all_battle_members;($game_party.battle_members + $game_troop.members).select{|m| m.exist? };end
  57.   def row_max;all_battle_members.size;end
  58.   def col_max
  59.     m = all_battle_members.max_by{|a| a.state_icons.size + a.buff_icons.size }
  60.     [m.state_icons.size + m.buff_icons.size,1].max
  61.   end
  62.   def item_max;row_max*col_max;end
  63.   def item_height; line_height + 2 ; end
  64.   def item_width; line_height + 2 ; end

  65.   def fitting_window #位置修正
  66.     self.height = item_height * row_max - standard_padding*4
  67.     self.width = 144+(col_max*item_width) + standard_padding*2
  68.     self.x = [Graphics.width / 2 - self.width / 2,0].max
  69.     self.y = [Graphics.height / 2 - self.height / 2,help_window.height].max - 28
  70.   end
  71.   def refresh
  72.     fitting_window
  73.     make_data
  74.     create_contents
  75.     all_battle_members.each_with_index{|a,i|
  76.       draw_actor_name(a,0,i*item_height+1)
  77.       draw_text(128,i*item_height+1,20,line_height,":")
  78.       draw_icons(a, 144, i*item_height+1, contents.width - 144)
  79.     }
  80.   end

  81.   def draw_icons(subject, x, y, width = 96)
  82.     icons = (subject.state_icons + subject.buff_icons)[0, width / item_width]
  83.     icons.each_with_index {|n, i| draw_icon(n, x + item_width * i, y) }
  84.   end

  85.   def item_rect(index)
  86.     rect = Rect.new
  87.     rect.width = item_width
  88.     rect.height = item_height
  89.     rect.x = index % col_max * item_width + 143
  90.     rect.y = index / col_max * item_height
  91.     rect
  92.   end

  93.   def update_help
  94.     @help_window.set_text(description)
  95.   end

  96.   def make_data
  97.     @data = all_battle_members.inject([]){|r,m|
  98.       a = []
  99.       a += m.states.select{|st| st.icon_index != 0 }
  100.       bf = []
  101.       m.buffs.each_with_index{|b,i| bf.push([i,b > 0 ? :up : :down]) if b != 0}
  102.       a += bf
  103.       a += Array.new(col_max - a.size){nil} if col_max > a.size
  104.       r += a
  105.     }
  106.   end

  107.   def description
  108.     return "" unless @data[index]
  109.     if @data[index].is_a?(Array)
  110.       return StateHelp::Buffs[@data[index]]
  111.     else
  112.       return StateHelp::States[@data[index].id]
  113.     end
  114.   end
  115.   def cursor_down(wrap = false)
  116.     return if @data.compact.empty?
  117.     loop do
  118.       select((index + col_max) % item_max)
  119.       break if @data[index]
  120.     end
  121.   end
  122.   def cursor_up(wrap = false)
  123.     return if @data.compact.empty?
  124.     loop do
  125.       select((index - col_max + item_max) % item_max)
  126.       break if @data[index]
  127.     end
  128.   end
  129.   def cursor_right(wrap = false)
  130.     return if @data.compact.empty?
  131.     loop do
  132.       select((index + 1) % item_max)
  133.       break if @data[index]
  134.     end
  135.   end
  136.   def cursor_left(wrap = false)
  137.     return if @data.compact.empty?
  138.     loop do
  139.       select((index - 1 + item_max) % item_max)
  140.       break if @data[index]
  141.     end
  142.   end
  143.   def smooth_select
  144.     return select(0) if @data.compact.empty?
  145.     @data.each_with_index{|d,i|
  146.       if d
  147.         select(i)
  148.         return
  149.       end
  150.     }
  151.   end
  152. end

  153. class Window_PartyCommand < Window_Command
  154.   alias _ex_state_make_command_list make_command_list
  155.   def make_command_list
  156.     _ex_state_make_command_list
  157.     add_command("状态",  :state)
  158.   end
  159. end

  160. class Scene_Battle < Scene_Base
  161.   alias _ex_state_create_all_windows create_all_windows
  162.   def create_all_windows
  163.     _ex_state_create_all_windows
  164.     create_state_window
  165.   end
  166.   alias _ex_state_create_party_command_window create_party_command_window
  167.   def create_party_command_window
  168.     _ex_state_create_party_command_window
  169.     @party_command_window.set_handler(:state, method(:command_state))
  170.   end

  171.   def create_state_window
  172.     @state_window = Window_State.new(@help_window)
  173.     @state_window.set_handler(:ok,  method(:command_state_cancel))
  174.     @state_window.set_handler(:cancel, method(:command_state_cancel))
  175.     @state_window.unselect
  176.   end

  177.   def command_state
  178.     @party_command_window.deactivate
  179.     @state_window.refresh
  180.     @state_window.open.activate.smooth_select
  181.     @help_window.show
  182.   end

  183.   def command_state_cancel
  184.     @state_window.deactivate.close.unselect
  185.     @party_command_window.activate
  186.     @help_window.hide
  187.   end
  188. end
复制代码


这个脚本会开一个小窗显示敌我双方状态和预设里写的说明,像这样

然而用了几下发现一个奇怪的BUG,就是当我方只有一个角色出战的时候中间的小窗就什么都不显示了,必须有2人以上出战时才正常显示

有没有大佬帮忙看看是哪里出了问题?
作者: KB.Driver    时间: 2021-3-6 22:35
把77行后面的*4改成*2
改完后的样子:
RUBY 代码复制
  1. self.height = item_height * row_max - standard_padding*2

作者: alexncf125    时间: 2021-3-6 22:56
本帖最后由 alexncf125 于 2021-3-6 23:06 编辑

LZ经已接触脚本有一两年了吧...
这种二百行不到的脚本的小问题,
是时候学会找出原因了...

你都知道"只有一个角色出战的时候中间的小窗就什么都不显示了,必须有2人以上出战时才正常显示"
那么关键字明显是member(66行)
咱们的目的是要调高窗口的高度height
之后很容易就搜到原因是出自77行的
self.height = item_height * row_max - standard_padding*4
之后怎改应该知道了吧日厉大佬在LS指出了~~
作者: 骷髅岛遗老    时间: 2021-3-7 12:44
alexncf125 发表于 2021-3-6 22:56
LZ经已接触脚本有一两年了吧...
这种二百行不到的脚本的小问题,
是时候学会找出原因了...

在学了在学了,就是社畜人做东西一阵一阵的,隔俩月回来都忘差不多了




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