标题: 。请高手给改一下脚本,为什么一解雇角色会雇佣错误? [打印本页] 作者: kvkv97 时间: 2023-10-23 21:12 标题: 。请高手给改一下脚本,为什么一解雇角色会雇佣错误? module Mercenaries
class Window_Help < ::Window_Base
def initialize
super(0,0,196,256)
self.contents = Bitmap.new(width - 32, height - 32)
self.z += 10
end
def draw_actor(actor)
self.contents.clear
bitmap=RPG::Cache.battler(actor.battler_name, actor.battler_hue)
self.contents.blt(0,0,bitmap,bitmap.rect)
self.contents.draw_text(0,0,64,32,actor.price.to_s)
self.contents.draw_text(0,32,64,32,actor.name)
self.contents.draw_text(0,64,64,32,actor.class_name)
self.contents.draw_text(0,96,64,32,"武器:#{$data_weapons[actor.weapon_id].name}")
self.contents.draw_text(0,128,64,32,"铠甲:#{$data_armors[actor.armor3_id].name}")
self.contents.draw_text(0,160,64,32,"攻击力:#{actor.atk}")
self.contents.draw_text(0,192,64,32,"防御力:#{actor.pdef}")
self.contents.draw_text(0,224,64,32,"魔御力:#{actor.mdef}")
end
end #class Window_Help
class Window_Shopcommand < ::Window_Selectable
def initialize
super(0,0,480,64)
self.contents=Bitmap.new(self.width-32,self.height-32)
@command=["雇佣","解雇","取消"]
@item_max = 3
@column_max = 3
refresh
self.index=0
end
def refresh
for i in [email protected]
x=i%@command.size*160
self.contents.draw_text(x,0,self.width-32,32,@command[i])
end
end
end #Window_Shopcommand
class Window_MenuStatus < ::Window_Selectable
attr_reader :actors
#--------------------------------------------------------------------------
# ● 初始化目标
#--------------------------------------------------------------------------
def initialize
super(320, 64, 320, 480-64)
self.contents = Bitmap.new(width - 32, height - 32)
@column_max=1
refresh
self.active = false
self.index = 0
end
def id
@actors[self.index]
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
@actors=[]
for actor in $game_party.actors
@actors.push(actor.id)
end
@item_max = $game_party.actors.size
for i in 0...$game_party.actors.size
x = 64
y = i * 116
actor = $game_party.actors[i]
draw_actor_graphic(actor, x - 40, y + 80)
draw_actor_name(actor, x, y)
draw_actor_class(actor, x + 144, y)
draw_actor_level(actor, x, y + 32)
draw_actor_state(actor, x + 90, y + 32)
draw_actor_exp(actor, x, y + 64)
draw_actor_hp(actor, x + 236, y + 32)
draw_actor_sp(actor, x + 236, y + 64)
end
end
#--------------------------------------------------------------------------
# ● 刷新光标矩形
#--------------------------------------------------------------------------
def update_cursor_rect
if @index < 0
self.cursor_rect.empty
else
self.cursor_rect.set(0, @index * 116, self.width - 32, 96)
end
end
end#Window_MenuStatus
class Window_Mercenaries < ::Window_Selectable
attr_reader :column_max
attr_reader :mercenaries
def initialize(mercenaries)
super(0,64,320,480-64)
@column_max=5
@mercenaries=mercenaries
refresh
self.index=0
end
def id
@mercenaries[self.index]
end
def refresh
@[email protected]
if @item_max>0
self.contents=Bitmap.new(width-32,row_max*80)
for i in 0...@item_max
draw_actor(i)
end
end
end
def draw_actor(index)
x=index%@column_max*64
y=index/@column_max*80
actor=$game_actors[@mercenaries[index]]
bitmap=RPG::Cache.character(actor.character_name, actor.character_hue)
rect=bitmap.rect
rect.width=rect.width/4
rect.height=rect.height/4
self.contents.blt(x,y,bitmap,rect)
end
#--------------------------------------------------------------------------
# ● 更新光标举行
#--------------------------------------------------------------------------
def update_cursor_rect
# 光标位置不满 0 的情况下
if @index < 0
self.cursor_rect.empty
return
end
# 获取当前的行
row = @index / @column_max
# 当前行被显示开头行前面的情况下
if row < self.top_row
# 从当前行向开头行滚动
self.top_row = row
end
# 当前行被显示末尾行之后的情况下
if row > self.top_row + (self.page_row_max - 1)
# 从当前行向末尾滚动
self.top_row = row - (self.page_row_max - 1)
end
# 计算光标的宽
cursor_width = self.width / @column_max - 32
# 计算光标坐标
x = @index % @column_max * 64
y = @index / @column_max * 80 - self.oy
# 更新国标矩形
self.cursor_rect.set(x, y, 64, 80)
end
end #Window_Mercenaries
class Scene_Mercenaries
def initialize(mercenaries)
@mercenaries=mercenaries
end
def main
@window_shopcommand=Window_Shopcommand.new #最上左角窗口
@window_gold=Window_Gold.new #最上右角窗口
@window_gold.x=480
@window_gold.y=0
@window_mercenaries=Window_Mercenaries.new(@mercenaries)#左下角窗口
@window_mercenaries.active = false
@window_menustatus=Window_MenuStatus.new#右下角窗口
@window_help=Window_Help.new
@window_help.visible=false
Graphics.transition
loop do
Graphics.update
Input.update
update
if self != $scene
break
end
end
@window_mercenaries.dispose
end
def update
@window_shopcommand.update
@window_mercenaries.update
@window_menustatus.update
if @window_mercenaries.active
@window_help.visible=true
cw=@window_mercenaries.index%@window_mercenaries.column_max*64
ch=@window_mercenaries.index/@window_mercenaries.column_max*80
@window_help.x=cw+@window_mercenaries.x+64
@window_help.y=ch+@window_mercenaries.y+80
if @window_help.x+@window_help.width>640
@window_help.x=640-@window_help.width
end
if @window_help.y+@window_help.height>480
@window_help.y=480-@window_help.height
end
@window_help.draw_actor($game_actors[@window_mercenaries.id])
else
@window_help.visible=false
end
if @window_shopcommand.active #商店操作界面
w_s_update
return
end
if @window_mercenaries.active #雇佣操作界面
w_merc_update
return
end
if @window_menustatus.active #解雇操作界面
w_menu_update
end
end#update
def w_s_update
if Input.trigger?(Input::B)
@window_mercenaries.active=false
@window_menustatus.active=false
@window_shopcommand.active=true
end
if Input.trigger?(Input::C)
case @window_shopcommand.index
when 0 #雇佣
@window_mercenaries.active=true
@window_menustatus.active=false
@window_shopcommand.active=false
return
when 1 #解雇
@window_mercenaries.active=false
@window_menustatus.active=true
@window_shopcommand.active=false
return
when 2 #取消
$scene=Scene_Map.new
return
end
end
end#w_s_update
def w_merc_update
if Input.trigger?(Input::B)
@window_mercenaries.active=false
@window_shopcommand.active=true
end
if Input.trigger?(Input::C)
if $game_party.gold>=$game_actors[@window_mercenaries.id].price
if $game_party.actors.size<4
$game_party.lose_gold($game_actors[@window_mercenaries.id].price)
#雇佣
$game_party.add_actor(@window_mercenaries.id)
@window_menustatus.refresh
@window_mercenaries.mercenaries.delete(@window_mercenaries.id)
@window_mercenaries.refresh
if @window_mercenaries.index>@window_mercenaries.mercenaries.size-1
@window_mercenaries.index=@window_mercenaries.mercenaries.size-1
end
end
end
end
@window_gold.refresh
end#w_merc_update
def w_menu_update
if Input.trigger?(Input::B)
@window_menustatus.active=false
@window_shopcommand.active=true
end
if Input.trigger?(Input::C)
if @window_menustatus.id !=1
$game_party.gain_gold($game_actors[@window_mercenaries.id].price/2)
#解雇
$game_party.remove_actor(@window_menustatus.id)
@window_menustatus.refresh
@window_mercenaries.mercenaries.push(@window_mercenaries.id)
@window_mercenaries.refresh
if @window_menustatus.index>@window_menustatus.actors.size-1
@window_menustatus.index=@window_menustatus.actors.size-1
end
end
end
@window_gold.refresh
end#w_menu_update
end #Scene_Mercenaries
end #module Mercenaries
class Game_Actor
def price [email protected](/,/)[1].nil? ? 0 : @name.split(/,/)[1]
return price*self.level
end
def name [email protected](/,/)[0]
end
end
在地图上建一事件,用脚本:
a=[2,3,4,5,6,7,8]
$scene=\
Mercenaries::\
Scene_Mercenaries.new(a)
把数据库的系统中的初期同伴改成1号角色,然后雇佣2号角色,然后解雇2号角色,出现雇佣3号的错误。
。请高手给改一下脚本,为什么一解雇角色会雇佣错误?作者: qq634488405 时间: 2023-10-25 08:44
意思是雇佣A再解雇A后,雇佣列表新增的不是A吧
window_mercenaries的@mercenaries,在雇佣了2以后变为[3,4,5,6,7,8],就和上一帖说的那样,这时候@window_mercenaries.id会返回3
所以解雇后,@window_mercenaries.mercenaries.push(@window_mercenaries.id)就会把3加入到雇佣列表。
解雇的时候用一个变量记录下被解雇的ID,然后添加到@window_mercenaries.mercenaries即可