标题: 脚本里面的参数传递 [打印本页] 作者: kvkv97 时间: 2023-11-17 21:05 标题: 脚本里面的参数传递 module Mercenaries
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
#$game_party.actors和@actors是不同的
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)
self.contents = Bitmap.new(width - 32, height - 32)
@column_max=1
@mercenaries=mercenaries
refresh
self.index=0
end
def id
@actors[self.index]
end
def refresh
self.contents.clear
@actors=[]
for actor in $game_party.actors_1
@actors.push(actor.id)
end
@item_max = $game_party.actors_1.size
#$game_party.actors和@actors是不同的
for i in 0...$game_party.actors_1.size
x = 64
y = i * 116
actor = $game_party.actors_1[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_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_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
@window_mercenaries.index=-1
@window_menustatus.index=-1
end
if Input.trigger?(Input::C)
case @window_shopcommand.index
when 0 #雇佣
@window_mercenaries.active=true
@window_menustatus.active=false
@window_shopcommand.active=false
@window_menustatus.index=-1
@window_mercenaries.index=0
return
when 1 #解雇
@window_mercenaries.active=false
@window_menustatus.active=true
@window_shopcommand.active=false
@window_mercenaries.index=-1
@window_menustatus.index=0
return
when 2 #取消
$scene=Scene_Map.new
return
end
end
end#w_s_update
def w_merc_update
if Input.trigger?(Input::B)
@window_shopcommand.active=true
@window_mercenaries.active=false
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)
#雇佣
@tmp=@window_mercenaries.id
$game_party.remove_actor_1(@window_mercenaries.id)#左窗口
@window_mercenaries.refresh
$game_party.add_actor(@tmp)#右窗口
@window_menustatus.refresh
end
end
end
@window_gold.refresh
end#w_merc_update
def w_menu_update
if Input.trigger?(Input::B)
@window_shopcommand.active=true
@window_menustatus.active=false
end
if Input.trigger?(Input::C)
if @window_menustatus.id !=1
$game_party.gain_gold($game_actors[@window_mercenaries.id].price/2)
#解雇
@tmp_1=@window_menustatus.id
$game_party.remove_actor(@window_menustatus.id)#右窗口
@window_menustatus.refresh
$game_party.add_actor_1(@tmp_1)#左窗口
@window_mercenaries.refresh
end
end
@window_gold.refresh
end#w_menu_update
end #Scene_Mercenaries
end #module Mercenaries
class Game_Party
attr_reader :actors_1
#--------------------------------------------------------------------------
# ● 设置初期角色
#--------------------------------------------------------------------------
def setup_starting_members_1
@actors_1 = []
@window_mercenaries=Mercenaries::Window_Mercenaries.new(@mercenaries)
for i in @mercenaries#●●●●
@actors_1.push($game_actors[i])
end
end
#--------------------------------------------------------------------------
# ● 加入同伴
# actor_id : 角色 ID
#--------------------------------------------------------------------------
def add_actor_1(actor_id)
# 获取角色
actor = $game_actors[actor_id]
# 同伴人数未满 4 人、本角色不在队伍中的情况下
if @actors.size < 4 and not @actors.include?(actor)
# 添加角色
@actors_1.push(actor)
end
end
#--------------------------------------------------------------------------
# ● 角色离开
# actor_id : 角色 ID
#--------------------------------------------------------------------------
def remove_actor_1(actor_id)
# 删除角色
@actors_1.delete($game_actors[actor_id])
end
end
class Scene_Title
alias command_new_game_old command_new_game
def command_new_game
command_new_game_old
$game_party.setup_starting_members_1
end
end
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