# 设置
module Task
# 章的变量 ID
CHAPTER_ID = 1
# 章设置
# 有序章第 0 项为序章内容,否则为 ""
CHAPTERS = ["3", "第一章:测试3"]
CHAPTERS = ["2", "第一章:测试2"]
CHAPTERS = ["1", "第一章:测试1"]
CHAPTERS = ["0", "第一章:测试0"]
# 任务返回的画面
BACK_SCENE = Scene_Map.new
end
# Game_Temp
class Game_Temp
attr_accessor :new_task_name # 新任务 名称
attr_accessor :new_task_help # 新任务 帮助文字
attr_accessor :new_task_gold # 新任务 奖励金钱
attr_accessor :new_task_items # 新任务 奖励物品
attr_accessor :new_task_weapons # 新任务 奖励武器
attr_accessor :new_task_armors # 新任务 奖励防具
attr_accessor :new_task_difficulty # 新任务 难度
alias task_initialize initialize
def initialize
task_initialize
@new_task_name = ""
@new_task_help = ""
@new_task_gold = ""
@new_task_items = nil
@new_task_weapons = nil
@new_task_armors = nil
@new_task_difficulty = 1
end
#--------------------------------------------------------------------------
# ● 生成新任务(在Scene_Task的内部使用)
# gold : 赏金
# items : { 物品 id 1 => 数量, 物品 id 2 => 数量 ... }
# weapons : { 武器 id 1 => 数量, 武器 id 2 => 数量 ... }
# armors : { 防具 id 1 => 数量, 防具 id 2 => 数量 ... }
# 若不设置请留 {} 。
#--------------------------------------------------------------------------
def new_task(name, help, difficulty = 1, gold = 0, items = {}, weapons = {}, armors = {})
# 实例变量的改变
@new_task_name = name
@new_task_help = help
@new_task_gold = gold
@new_task_items = items
@new_task_weapons = weapons
@new_task_armors = armors
@new_task_difficulty = difficulty
@new_task_chapter = $game_variables[Task::CHAPTER_ID]
$game_taskdata.tasks += 1
# 保存数据(载入数组)
if $game_taskdata.task_name[0] == ""
$game_taskdata.task_name = [@new_task_name]
$game_taskdata.task_command_name = [@new_task_name]
$game_taskdata.task_help = [@new_task_help]
$game_taskdata.task_gold = [@new_task_gold]
$game_taskdata.task_items = [@new_task_items]
$game_taskdata.task_weapons = [@new_task_weapons]
$game_taskdata.task_armors = [@new_task_armors]
$game_taskdata.task_difficulty = [@new_task_difficulty]
$game_taskdata.task_chapter = [@new_task_chapter]
else
$game_taskdata.task_name.push(@new_task_name)
$game_taskdata.task_command_name.push(@new_task_name)
$game_taskdata.task_help.push(@new_task_help)
$game_taskdata.task_gold.push(@new_task_gold)
$game_taskdata.task_items.push(@new_task_items)
$game_taskdata.task_weapons.push(@new_task_weapons)
$game_taskdata.task_armors.push(@new_task_armors)
$game_taskdata.task_difficulty.push(@new_task_difficulty)
$game_taskdata.task_chapter.push(@new_task_chapter)
end
end
#--------------------------------------------------------------------------
# ● 完成任务(在Scene_Task的内部使用)
#--------------------------------------------------------------------------
def final_task(id)
new_line = true
# 算出数组中的id
id = id - 1
unless $game_taskdata.lose_tasks.include?(id)
# 修改数组数据
$game_taskdata.task_command_name[id] = $game_taskdata.task_command_name[id] + "(已完成)"
$game_taskdata.task_help[id] = new_line == true ? $game_taskdata.task_help[id] + "\n(已完成)" : $game_taskdata.task_help[id] + "(已完成)"
# 获得任务奖励
unless $game_taskdata.task_gold[id] == 0
$game_party.gain_gold($game_taskdata.task_gold[id])
end
unless $game_taskdata.task_items[id] == {}
for i in $game_taskdata.task_items[id].keys
$game_party.gain_item(i, $game_taskdata.task_items[id][i])
end
end
unless $game_taskdata.task_weapons[id] == {}
for i in $game_taskdata.task_weapons[id].keys
$game_party.gain_weapon(i, $game_taskdata.task_weapons[id][i])
end
end
unless $game_taskdata.task_armors[id] == {}
for i in $game_taskdata.task_armors[id].keys
$game_party.gain_armor(i, $game_taskdata.task_armors[id][i])
end
end
end
end
#------------------------------------------------------------------------
# 失败任务(啊啊啊!)
#------------------------------------------------------------------------
def lose_task(id)
new_line = true
id = id - 1
$game_taskdata.task_command_name[id] = $game_taskdata.task_command_name[id] + "(已失败)"
$game_taskdata.task_help[id] = new_line = true ? $game_taskdata.task_help[id] + "\n(已失败)" : $game_taskdata.task_help[id] + "(已失败)"
$game_taskdata.lose_tasks.push(id)
end
#------------------------------------------------------------------------
# 有任务判定
#------------------------------------------------------------------------
def has_task?(id)
return $game_taskdata.tasks >= id
end
end
# Game_TaskData
class Game_TaskData
attr_accessor :task_name
attr_accessor :task_command_name
attr_accessor :task_help
attr_accessor :task_gold
attr_accessor :task_items
attr_accessor :task_weapons
attr_accessor :task_armors
attr_accessor :task_item_num
attr_accessor :task_weapon_num
attr_accessor :task_armor_num
attr_accessor :task_difficulty
attr_accessor :tasks
attr_accessor :lose_tasks
attr_accessor :task_chapter
def initialize
@task_name = [""]
@task_command_name = [""]
@task_help = [""]
@task_gold = [0]
@task_items = [{}]
@task_weapons = [{}]
@task_armors = [{}]
@task_difficulty = [0]
@task_chapter = [0]
@tasks = 0
@lose_tasks = []
end
end
# Window_Base
class Window_Base < Window
#--------------------------------------------------------------------------
# ● 清空内容
#--------------------------------------------------------------------------
def empty
self.contents.clear
end
end
# Window_TaskLeft
class Window_TaskLift < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize
super(0, 64, 320, 480 - 64)
@item_max = [$game_taskdata.tasks, 1].max
self.contents = Bitmap.new(width - 32, @item_max * 25 + $game_variables[Task::CHAPTER_ID] * 25 + (Task::CHAPTERS[0] == "" ? 0 : 25))
self.contents.font.size = 15
@setting = false
$f = true
@chapter = Task::CHAPTERS
@drawing_chapter = 0
@chapter_oy = 0
@command_ys = []
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
@old_max = @item_max
@command_ys = []
@drawing_chapter = 0
@chapter_oy = 0
if $game_taskdata.task_command_name[0] == ""
$f = true
else
$f = false
end
for i in 0...@item_max
draw_item(i, normal_color)
end
end
#--------------------------------------------------------------------------
# ● 描绘项目
# index : 项目编号
# color : 文字色
#--------------------------------------------------------------------------
def draw_item(index, color)
self.contents.font.color = color
if $game_taskdata.task_chapter[$game_taskdata.tasks - index - 1] != @drawing_chapter
@drawing_chapter = $game_taskdata.task_chapter[$game_taskdata.tasks - index - 1]
self.contents.font.color = Color.new(0, 0, 0, 255)
self.contents.draw_text(2, 25 * index + @chapter_oy + 2, 640 / 2 - 8, 25, @chapter[@drawing_chapter])
self.contents.font.color = system_color
self.contents.draw_text(0, 25 * index + @chapter_oy, 640 / 2 - 8, 25, @chapter[@drawing_chapter])
self.contents.font.color = color
@chapter_oy += 25
end
name = $game_taskdata.task_command_name[$game_taskdata.tasks - index - 1]
suf = ""
if name.include?("(已失败)")
suf = "(已失败)"
elsif name.include?("(已完成)")
suf = "(已完成)"
end
name = $game_taskdata.task_name[$game_taskdata.tasks - index - 1]
rect = Rect.new(4, 25 * index + @chapter_oy, 640 / 2 - 8, 25)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
width = self.contents.text_size(name).width
self.contents.draw_text(rect, name)
case suf
when "(已失败)"
self.contents.font.color = knockout_color
when "(已完成)"
self.contents.font.color = Color.new(176, 255, 144, 255)
end
self.contents.draw_text(4 + width, 25 * index + @chapter_oy, 128, 25, suf)
@command_ys.push(25 * index + @chapter_oy)
end
#--------------------------------------------------------------------------
# ● 更新光标矩形
#--------------------------------------------------------------------------
def update_cursor_rect
if @index < 0
self.cursor_rect.empty
return
end
# 获取当前的行
row = @index
# 当前行被显示开头行前面的情况下
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
self.cursor_rect.set(0, @command_ys[@index], 640 / 2 - 32, 25)
end
#--------------------------------------------------------------------------
# ● 获取开头行
#--------------------------------------------------------------------------
def top_row
row = @command_ys.index(self.oy)
if row == nil
ary = @command_ys.sort
for i in [email]0...@command_ys.size[/email]
if ary[i] > self.oy
row = i
break
end
end
end
return row
end
#--------------------------------------------------------------------------
# ● 设置开头行
# row : 显示开头的行
#--------------------------------------------------------------------------
def top_row=(row)
# row 未满 0 的场合更正为 0
if row < 0
row = 0
end
# row 超过 row_max - 1 的情况下更正为 row_max - 1
if row > row_max - 1
row = row_max - 1
end
self.oy = @command_ys[row]
end
#--------------------------------------------------------------------------
# ● 获取 1 页可以显示的行数
#--------------------------------------------------------------------------
def page_row_max
rows = 0
for i in @command_ys
if i - self.oy > 0 and i - self.oy < 480 - 96
rows += 1
end
end
return rows
end
end
# Window_TaskRight
class Window_TaskRight < Window_Base
#--------------------------------------------------------------------------
# ● 初始化窗口
#--------------------------------------------------------------------------
def initialize
super(320, 64, 320, 480 - 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.size = 15
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def set_task_list(id)
if id != @id
self.contents.clear
x = 0
self.contents.font.color = system_color
self.contents.draw_text(x, 0, 100, 25, "任务名:")
self.contents.draw_text(x, 50, 100, 25, "难度:")
self.contents.draw_text(x, 75, 100, 25, "说明:")
if $game_taskdata.task_gold[id] != 0
self.contents.draw_text(x, 150, 100, 25, "奖励金钱:")
self.contents.draw_text(x + 75, 175, 100, 25, $data_system.words.gold)
y = 200
else
y = 150
end
items = {}
for i in $game_taskdata.task_items[id].keys
items[$data_items[i]] = $game_taskdata.task_items[id][i]
end
for i in $game_taskdata.task_weapons[id].keys
items[$data_weapons[i]] = $game_taskdata.task_weapons[id][i]
end
for i in $game_taskdata.task_armors[id].keys
items[$data_armors[i]] = $game_taskdata.task_armors[id][i]
end
if items != {}
self.contents.draw_text(x, y, 100, 25, "奖励物品:")
end
self.contents.font.color = normal_color
self.contents.draw_text(x, 25, 320 - 25, 25, $game_taskdata.task_name[id])
self.contents.draw_text(x, 100, 288, 25, $game_taskdata.task_help[id].split(/\n/)[0])
if $game_taskdata.task_help[id].split(/\n/)[1] != nil
if $game_taskdata.task_help[id].split(/\n/)[1] == "(已失败)"
self.contents.font.color = knockout_color
elsif $game_taskdata.task_help[id].split(/\n/)[1] == "(已完成)"
self.contents.font.color = Color.new(176, 255, 144, 255)
end
self.contents.draw_text(x, 125, 288, 25, $game_taskdata.task_help[id].split(/\n/)[1])
end
self.contents.font.color = normal_color
if $game_taskdata.task_gold[id] != 0
self.contents.draw_text(x, 175, 100, 25, $game_taskdata.task_gold[id].to_s)
end
for i in 0...items.keys.size
draw_item_name(items.keys[i], x + i % 2 * 144, y + 22 + i / 2 * 25)
self.contents.draw_text(x + 75 + i % 2 * 144, y + 25 + i / 2 * 25, 280, 25, " × " + items[items.keys[i]].to_s)
end
text1 = "★" * $game_taskdata.task_difficulty[id]
text2 = "☆" * (5 - $game_taskdata.task_difficulty[id])
text = text1 + text2
self.contents.draw_text(x + 60, 50, 280, 25, text)
@id = id
end
end
#--------------------------------------------------------------------------
# ● 清除
#--------------------------------------------------------------------------
def empty
super
@id = nil
end
end
# Window_TaskAssist
class Window_TaskAssist < Window_Base
#--------------------------------------------------------------------------
# ● 初始化窗口
#--------------------------------------------------------------------------
def initialize
super(0, 0, 640, 64)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = normal_color
self.contents.draw_text(0, 0, 640 - 32, 32, "任务", 1)
end
end
# Scene_Title
class Scene_Title
alias task_new_game command_new_game
def command_new_game
$game_taskdata = Game_TaskData.new
task_new_game
$f = false
end
end
# Scene_Task
class Scene_Task
#--------------------------------------------------------------------------
# ● 主处理
#--------------------------------------------------------------------------
def main
# 生成任务单窗口
@task_right_window = Window_TaskRight.new
# 生成等待时间 & 步骤
@wait_count = 0
@step = 1
# 生成任务活动窗口
@task_left_window = Window_TaskLift.new
if @task_left_window.active == false
@task_left_window.active = true
end
# 生成任务辅助窗口
@taskassist_window = Window_TaskAssist.new
# 执行过渡
Graphics.transition
# 主循环
loop do
# 刷新游戏画面
Graphics.update
# 刷新输入信息
Input.update
# 刷新画面
update
# 如果切换画面就中断循环
if $scene != self
break
end
end
# 准备过渡
Graphics.freeze
# 释放各个窗口
@task_left_window.dispose
@taskassist_window.dispose
@task_right_window.dispose
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
# 刷新各个窗口
@task_left_window.update
@task_right_window.update
@taskassist_window.update
# 步骤分支
case @step
when 1
update_step1
return
when 2
update_step2
return
end
end
#--------------------------------------------------------------------------
# ● 刷新画面 第一步
#--------------------------------------------------------------------------
def update_step1
# 按下 B 键的情况下
if Input.trigger?(Input::B)
# 切换到菜单界面
$scene = Task::BACK_SCENE
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
return
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
if $game_taskdata.tasks > 0
@task_right_window.set_task_list($game_taskdata.tasks - @task_left_window.index - 1)
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
@step = 2
else
# 演奏无效 SE
$game_system.se_play($data_system.buzzer_se)
end
return
end
end
#--------------------------------------------------------------------------
# ● 刷新画面 第二步
#--------------------------------------------------------------------------
def update_step2
if Input.repeat?(Input::UP) or Input.repeat?(Input::DOWN) or Input.trigger?(Input::B)
@task_right_window.empty
if Input.trigger?(Input::B)
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
end
@step = 1
return
end
end
#--------------------------------------------------------------------------
# ● 显示任务单判定
#--------------------------------------------------------------------------
def setting?
return (@step == 2)
end
end
# Scene_Save
class Scene_Save
def write_save_data(file)
# 生成描绘存档文件用的角色图形
characters = []
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
characters.push([actor.character_name, actor.character_hue])
end
# 写入描绘存档文件用的角色数据
Marshal.dump(characters, file)
# 写入测量游戏时间用画面计数
Marshal.dump(Graphics.frame_count, file)
# 增加 1 次存档次数
$game_system.save_count += 1
# 保存魔法编号
# (将编辑器保存的值以随机值替换)
$game_system.magic_number = $data_system.magic_number
# 写入各种游戏对像
Marshal.dump($game_system, file)
Marshal.dump($game_switches, file)
Marshal.dump($game_variables, file)
Marshal.dump($game_self_switches, file)
Marshal.dump($game_screen, file)
Marshal.dump($game_actors, file)
Marshal.dump($game_party, file)
Marshal.dump($game_troop, file)
Marshal.dump($game_map, file)
Marshal.dump($game_player, file)
Marshal.dump($game_taskdata, file)
end
end
# Scene_Load
class Scene_Load
def read_save_data(file)
# 读取描绘存档文件用的角色数据
characters = Marshal.load(file)
# 读取测量游戏时间用画面计数
Graphics.frame_count = Marshal.load(file)
# 读取各种游戏对像
$game_system = Marshal.load(file)
$game_switches = Marshal.load(file)
$game_variables = Marshal.load(file)
$game_self_switches = Marshal.load(file)
$game_screen = Marshal.load(file)
$game_actors = Marshal.load(file)
$game_party = Marshal.load(file)
$game_troop = Marshal.load(file)
$game_map = Marshal.load(file)
$game_player = Marshal.load(file)
$game_taskdata = Marshal.load(file)
# 魔法编号与保存时有差异的情况下
# (加入编辑器的编辑过的数据)
if $game_system.magic_number != $data_system.magic_number
# 重新装载地图
$game_map.setup($game_map.map_id)
$game_player.center($game_player.x, $game_player.y)
end
# 刷新同伴成员
$game_party.refresh
end
end