Project1
标题:
HYN 任务系统脚本
[打印本页]
作者:
英顺的马甲
时间:
2011-2-7 21:42
标题:
HYN 任务系统脚本
本帖最后由 英顺的马甲 于 2011-2-7 21:57 编辑
使用方法:插入main之前,Scene_Title
def command_new_game下面插入$game_mission = Game_Mission.new
Scene_Save,Marshal.dump($game_player, file)下面插入Marshal.dump($game_mission, file)
Scene_Load,$game_player = Marshal.load(file)的下面插入$game_mission = Marshal.load(file)
调用方法:$scene = Scene_Mission.new
#==============================================================================#
# 任务系统 by EngShun #
# #
# 简单说明: #
# 调用方法:$scene = Scene_Mission.new #
# 用$game_mission.get_mission(任务名,说明)得到任务 #
# 用$game_mission.done_mission(任务名)完成任务 #
# 用$game_mission.delete_mission(任务名)删除任务 #
# 用$game_mission.done_all完成所有任务 #
# 用$game_mission.delete_all删除所有任务 #
#==============================================================================#
class Game_Mission
attr_accessor :mission
attr_accessor :mission_info
attr_accessor :mission_done
def initialize
@mission = ["没有任务"]
@mission_info = ["没有任何的任务"]
@mission_done = []
end
def get_mission(mission,info)
unless @mission.include?(mission)
@mission.push(mission)
@mission_info.push(info)
delete_mission("没有任务") if @mission.include?("没有任务")
end
end
def done_mission(done_mission)
for i in
[email protected]
if @mission[i] == done_mission
@mission_done.delete(i) if @mission_done.include?(i)
@mission_done.push(i)
end
end
end
def delete_mission(delete_mission)
for i in
[email protected]
if @mission[i] == delete_mission
@mission.delete(delete_mission)
delete_info = @mission_info[i]
@mission_info.delete(delete_info)
@mission_done.delete(i) if @mission_done.include?(i)
end
end
$game_mission = Game_Mission.new if @mission.size == 0
end
def done_all
for i in
[email protected]
@mission_done.delete(i) if @mission_done.include?(i)
@mission_done.push(i)
end
end
def delete_all
$game_mission = Game_Mission.new
end
end
class Window_Mission < Window_Selectable
def initialize
super(0, 64, 200, 416)
self.index = 0
@item_max = $game_mission.mission.size
if self.contents != nil
self.contents.dispose
self.contents = nil
end
self.contents = Bitmap.new(width - 32, @item_max * 32)
for i in 0..$game_mission.mission.size
if $game_mission.mission_done.include?(i)
self.contents.font.color = disabled_color
text = $game_mission.mission[i] + "(√)"
else
self.contents.font.color = normal_color
text = $game_mission.mission[i]
end
self.contents.draw_text(4, i * 32, 160, 32, text.to_s)
end
end
end
class Scene_Mission
def main
@window1 = Window_Base.new(0,0,200,64)
@window1.contents = Bitmap.new(168,32)
@window1.contents.draw_text(0,0,168,32,"任务",1)
@window2 = Window_Base.new(200,0,440,64)
@window2.contents = Bitmap.new(408,32)
@window2.contents.draw_text(0,0,408,32,"任务说明",1)
@mission_window = Window_Mission.new
@mission_window.index = $game_mission.mission.size - 1
@info_window = Window_Base.new(200,64,440,416)
@info_window.contents = Bitmap.new(408, 384)
info = $game_mission.mission_info[@mission_window.index]
draw_mission_info(info)
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@window1.dispose
@window2.dispose
@mission_window.dispose
@info_window.dispose
end
def update
@mission_window.update
@info_window.update
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
return
end
if Input.repeat?(Input::UP) or
Input.repeat?(Input::DOWN)
info = $game_mission.mission_info[@mission_window.index]
draw_mission_info(info)
end
end
# 引用他人的脚本
def draw_mission_info(task)
@info_window.contents.clear
# 记录文字x坐标
x = 0
# 记录文字y坐标
y = 0
# 记录换行时y坐标最小加值
min_y = 0
@info_window.contents.font.color = @info_window.normal_color
# 描绘任务简介
text = task.clone
# 限制文字处理
begin
last_text = text.clone
text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
end until text == last_text
text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
$game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
end
# 为了方便、将 "\\\\" 变换为 "\000"
text.gsub!(/\\\\/) { "\000" }
# "\C" 变为 "\001"
text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
# "\I" 变为 "\002"
text.gsub!(/\\[Ii]/) { "\002" }
# "\P" 变为 "\003"
text.gsub!(/\\[Pp]/) { "\003" }
# c 获取 1 个字 (如果不能取得文字就循环)
while ((c = text.slice!(/./m)) != nil)
# \\ 的情况下
if c == "\000"
# 还原为本来的文字
c = "\\"
end
# \C[n] 的情况下
if c == "\001"
# 更改文字色
text.sub!(/\[([0-9]+)\]/, "")
color = $1.to_i
if color >= 0 and color <= 7
@info_window.contents.font.color = @info_window.text_color(color)
elsif color == 8
@info_window.contents.font.color = @info_window.disabled_color
elsif color == 9
@info_window.contents.font.color = @info_window.system_color
end
# 下面的文字
next
end
# 图标的情况下
if c == "\002"
icon_name = ''
while ((cha = text.slice!(/./m)) != ']')
next if cha == '['
icon_name += cha
end
icon = RPG::Cache.icon(icon_name)
if x + icon.width > @info_window.contents.width
x = 0
y += [32, min_y].max
min_y = 0
end
@info_window.contents.blt(x + 4, y + 4, icon, Rect.new(0, 0, 24, 24))
x += 28
next
end
# 图片的情况下
if c == "\003"
pic_name = ''
while ((cha = text.slice!(/./m)) != ']')
next if cha == '['
pic_name += cha
end
pic = RPG::Cache.picture(pic_name)
if x + pic.width > @info_window.contents.width
x = 0
y += [32, min_y].max
min_y = 0
end
@info_window.contents.blt(x + 4, y, pic, Rect.new(0, 0, pic.width, pic.height))
x += pic.width
min_y = [pic.height, 32].max
next
end
# 另起一行文字的情况下
if c == "\n"
y += [32, min_y].max
min_y = 0
x = 0
# 下面的文字
next
end
# 自动换行处理
if x + @info_window.contents.text_size(c).width > @info_window.contents.width
y += [32, min_y].max
min_y = 0
x = 0
end
# 描绘文字
@info_window.contents.draw_text(4 + x, y, 40, 32, c)
# x 为要描绘文字的加法运算
x += @info_window.contents.text_size(c).width
end
end
# 引用结束
end
复制代码
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1