["寻找圣剑材料",10,
[1,{0=>[[32,5],[33,8],[34,11]]}],
"寻找圣剑所需的三个材料,圣剑材料1,圣剑材料2,圣剑材料3",
[0,{1=>[[33,1]]}],"找到这些可以做圣剑"],
]
module_function
def self.Start(name)
Missions.each do |mission|
Mission.startMission(*mission) if mission[0] == name
end
end
def canMissionList
if Missions.empty? or Missions.nil?
raise "任务没有设置好,请检查"
end
temp = []
Missions.each do |mission|
# if $game_system.missions[mission[0]].nil?
#添加到任务列表 并设置不需要在列表里的任务
temp << mission[0] if mission[0] != "寻找圣剑材料"
# end
end
return temp
end
end
#------------------------------------------------------------------------------
# 内部类定义部分
#------------------------------------------------------------------------------
class Hash < Object
def soft
@temp = []
self.each_pair{|key, value| @temp << [key,value] }
return @temp
end
end
class Integer
def rStar
return "★"*self
end
end
class Bitmap
def auto_line_draw_text(x,y,text,limit,height,align)
lines = text.getLines(limit)
@limit = limit
@n = 0
for i in 0...lines
@t1 = []
if lines == 1
@t1 << text
end
if lines > 1
@t= text.split(//)
while @t1.join.size < @limit
break if @t[@n].nil?
@t1.push(@t[@n])
@n += 1
end
end
draw_text(x,y+i*height,500,height,@t1.join,align)
end
end
end
class String
def getLines(limit)
lines = (self.length/limit).to_i
lines += 1 if self.length%limit != 0
return lines
end
end
#------------------------------------------------------------------------------
# 系统重定义部分
#------------------------------------------------------------------------------
class Game_Battler
def dead?
if (@hp == 0 and not @immortal)
@temp_a = 0 if @temp_a == nil
if self.is_a?(Game_Enemy) and @temp_a == 0
id = self.instance_variable_get enemy_id
now_mission = $game_system.missionEnemyIds #[name][id]
goal_mission = $game_system.missions # [name].kind[1][id]
# 检索是否存在于列表中
$game_system.missionEnemyIds.keys.each do |name|
# return true if $game_system.missionEnemyIds[name] == nil
if now_mission[name][id] != nil and goal_mission[name] != nil and
now_mission[name][id] < goal_mission[name].kind[1][id]
# $game_system.missions[name].stutas == 0
$game_system.missionEnemyIds[name][id] += 1
break
end
end
@temp_a = 1
end
return true
end
end
end
class FinishMission < GetMission
attr_accessor :times
def initialize(times,*args)
new_args = [args[0],args[1],args[2],[args[3],args[4]],args[5]]
super(*new_args)
@times = times
end
end
#----------------------------------------------------------------------------
# 任务核心部分
#----------------------------------------------------------------------------
module Mission
module_function
def startMission(name,level,kind,description,rewards,rewards_des)
unless $game_system.missions.has_key?(name)
# 检查参数合法性
self.getError(name,level,kind,description,rewards,rewards_des)
$game_system.missions[name] = GetMission.new(
level,kind,description,rewards,rewards_des)
$game_system.missionNameSort << name unless $game_system.missionNameSort.include?(name)
case kind[0]
when 0
# 设置开关初始状态
$game_system.missionSwitch[kind[1]] = false
when 1
# 开启了一个获得物品的任务
when 2
# 开启了一个杀敌数的任务并设置列表
# {name1=>{id1=number,id2=number},name2={id1=number,id2=number}}
$game_system.missionEnemyIds[name] = {}
enemies = kind[1].sort
enemies.each{|id| $game_system.missionEnemyIds[name][id[0]] = 0}
end
end
return
end
#返回一种任务结果
def missionReslut(result,name,message)
case result
when 0
# 将任务转移到完成列表
self.missionMove(name)
# 获得报酬
self.getRewards(name)
# 清空任务
$game_system.missionNameSort.delete(name)
$game_system.missions.delete(name)
# 抛出任务成功信息
yield message
when 1
# 抛出未完成信息
yield message
#任务还未完成
return false
when 2
# 抛出未完成信息
yield message
#无此任务
return false
end
return
end
# 转移到任务完成列表
def missionMove(name)
@mission = $game_system.missions[name]
# 保存全部实例变量
@include = ["@level","@kind","@description","@money","@items","@reswards_des"]
@include_value = []
temp = []
@include.each do |a|
if a == "@monney"
temp << a
next
end
if a == "@tiems"
temp << a
a = temp
end
@include_value.push @mission.instance_variable_get eval(":"+a)
end
if $game_system.finishMissionList.include? name
# 任务名称=>完成次数
# 如果包含 完成次数+1
$game_system.finishMissionList[name].times += 1
else
# 如果不包含 建立一个完成任务的列表
$game_system.finishNameSort.push(name) unless $game_system.finishNameSort.include?(name)
$game_system.finishMissionList[name] = FinishMission.new(1,*@include_value)
end
return
end
# 获取报酬
def getRewards(name)
return if $game_system.missions[name] == nil
# [金钱,{种类1=>[[ID1,数量],[ID2,数量]],种类2=>[[ID1,数量],[ID2,数量]]}]
money = $game_system.missions[name].money
items = $game_system.missions[name].items
# 获取赏金
self.get_money(money) if money != 0
# 获得物品
if items[0] != nil
items[0].each{|id,number|
$game_party.send :gain_item,id,number
}
end
# 获得武器
if items[1] != nil
items[1].each{|id,number|
$game_party.send :gain_weapon,id,number
}
end
# 获得防具
if items[2] != nil
items[2].each{|id,number|
$game_party.send :gain_armor,id,number
}
end
return
end
def get_money(n)
$game_party.send :gain_gold,n
end
# *mission 可接收多个任务名称作为参数
def mission_finished?(*missions)
# return $game_system.finishMissionList.keys | missions
missions.each do |mission|
return false unless $game_system.finishMissionList.has_key?(mission)
end
return true
end
# 检查mission是否正在执行
def mission_run?(*missions)
#p missions
#p $game_system.missions
missions.each do |mission|
return false unless $game_system.missions.has_key?(mission)
end
return true
# p $game_system.missions.keys | missions
# return $game_system.missions.keys | missions
end
# 获取当前任务数量
def mission_counts
return $game_system.missions.length
end
end
#-----------------------------------------------------------------------------
# 菜单部分
#-----------------------------------------------------------------------------
# 任务所主菜单
class WindowMissionMain < Window_Selectable
def initialize
if $xiaoming == 1#←xiaoming
y = 100
m = 2
if $xiaoming == 1#←xiaoming
c = ""
d = ""
else
c = "接受任务"
d = "提交任务"
end
#原脚本没有这个判断
self.contents.draw_text(0,0,200,32,"查看任务",0)#←xiaoming
self.contents.draw_text(0,32,200,32,"完成列表",0)
self.contents.draw_text(0,32*2,200,32,c,0)
self.contents.draw_text(0,32*3,200,32,d,0)
# self.contents.draw_text(0,0,200,32,"接受任务",0)
# self.contents.draw_text(0,32,200,32,"提交任务",0)
# self.contents.draw_text(0,32*2,200,32,"查看任务",0)
# self.contents.draw_text(0,32*3,200,32,"完成列表",0)
end
end
# 可接受任务的列表
class WindowCanAcceptList < Window_Selectable
def initialize
super(70,60,500,360)
@width = width
@column_max = 1
self.opacity = 255
self.visible = false
self.index = 0
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh(*list)
self.contents.clear if self.contents != nil
self.contents = Bitmap.new(@width - 32, list.size * 32+32)
@item_max = list.size
for i in list
MissionList::Missions.each do |mission|
if mission[0] == i
@level = mission[1]
@name = i
break
end
end
pos = list.index(i)
if $game_system.missions[@name] != nil
self.contents.font.color = disabled_color
else
self.contents.font.color = normal_color
end
self.contents.draw_text(0,pos*32,200,32,i,0)
self.contents.draw_text(220,pos*32,200,32,@level.rStar,0)
end
end
end
# 任务中的列表
class WindowAccetpedList < Window_Selectable
def initialize
super(70,60,500,360)
@width = width
@column_max = 1
self.opacity = 255
self.visible = false
self.index = 0
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh(*list)
return if list.empty?
self.contents.clear if self.contents != nil
self.contents = Bitmap.new(@width - 32, list.size * 32)
@item_max = list.size
for i in list
levels = $game_system.missions.level.rStar
pos = list.index(i)
self.contents.draw_text(0,pos*32,200,32,i,0)
self.contents.draw_text(220,pos*32,200,32,levels,0)
end
end
end
# 任务完成的列表
class WindowFinishList < Window_Selectable
def initialize
super(70,60,500,360)
@width = width
@column_max = 1
self.visible = false
self.opacity = 255
self.index = 0
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh(*list)
return if list.empty?
self.contents.clear if self.contents != nil
self.contents = Bitmap.new(@width - 32,list.size * 32)
@item_max = list.size
for i in list
level = $game_system.finishMissionList.level.rStar
pos = list.index(i)
self.contents.draw_text(0,pos*32,200,32,i,0)
self.contents.draw_text(220,pos*32,200,32,level,0)
end
end
end
# 任务描述窗口
class WindowMissionDes < Window_Base#
TEXT = ["[任务等级]","[任务条件]","[任务描述]","[任务报酬]","[其他]"]
TEXT2 = "接受任务请按确定键,返回上级菜单按取消键"
def initialize
super(70,40,500,400)
@viewport = Viewport.new(70,40+64,500,400-64)
@viewport.z = self.z + 1
self.visible = false
self.contents = Bitmap.new(width-32,64)
end
def update
super
if self.active
if @text != nil
@text.x > - 300 ? @text.x -= 2 : @text.x = 650
end
case Input.dir4
when 2
move_block(0)
move_bar(1)
when 8
move_block(1)
move_bar(0)
end
end
end
def nVisible
if self.visible == true
@sprite.visible = true if @sprite != nil
@bar.visible = true if @bar != nil
#@text.visible = true if @text != nil
end
if self.visible == false
@sprite.visible = false if @sprite != nil
@bar.visible = false if @bar != nil
@text.visible = false if @text != nil
end
end
def dispose
super
@sprite.dispose if @sprite != nil
@bar.dispose if @bar != nil
@text.dispose if @text != nil
end
def move_block(kind)
if kind == 0
@sprite.y -= 4
end
if kind == 1
@sprite.y += 4
end
end
def move_bar(kind)
if kind == 0
@bar.y -= (4/@rate).to_f if @bar.y > 112
end
if kind == 1
@bar.y += (4/@rate).to_f if @bar.y < 400 - @bar.bitmap.height
end
end
def getColor(n)
if n == 0
return Color.new(255,255,255,255)
elsif n == 1
return Color.new(255,255,0,255)
elsif n == 2
return Color.new(255,0,0,255)
elsif n == 3
return Color.new(128,128,128,255)
else
end
end
def refresh(name,listKind)
raise "listKind参数设置不正确" unless [0,1,2].include? listKind
self.contents.clear
# bitmap.clear if bitmap != nil
@sprite.dispose if @sprite != nil
@bar.dispose if @bar != nil
@name = name
# 可接受列表
if listKind == 0
MissionList::Missions.each do |mission|
if mission[0] == @name
@mission = mission
break
end
end
@sprite.bitmap.draw_text(64,32*3+pos*32,400,32,name,0)
case listKind
when 0,2
@sprite.bitmap.draw_text(300,32*3+pos*32,100,32,"x"+number.to_s,0)
when 1
now_items = $game_party.instance_variable_get :@items
now_number = (now_items[id].nil? ? 0 : now_items[id])
@sprite.bitmap.draw_text(250,32*3+pos*32,100,32,now_number.to_s+"/"+number.to_s,0)
when 2
end
end
tem01 += condition[0].size
end
if condition[1] != nil
condition[1].each do |id,number|
pos = condition[1].index([id,number]) + tem01
name = $data_weapons[id].name
icon_name = $data_weapons[id].icon_name
case listKind
when 0,2
@sprite.bitmap.draw_text(64,32*3+pos*32,400,32,name,0)
@sprite.bitmap.draw_text(300,32*3+pos*32,100,32,"x"+number.to_s,0)
when 1
now_weapons = $game_party.instance_variable_get :@weapons
now_number = (now_weapons[id].nil? ? 0 : now_weapons[id])
@sprite.bitmap.draw_text(300,32*3+pos*32,100,32,now_number.to_s+"/"+number.to_s,0)
when 2
end
end
tem01 += condition[1].size
end
if condition[2] != nil
p condition[2]
condition[2].each do |id,number|
pos = condition[2].index([id,number]) + tem01
name = $data_armors[id].name
icon_name = $data_armors[id].icon_name
case listKind
when 0,2
@sprite.bitmap.draw_text(64,32*3+pos*32,400,32,name,0)
@sprite.bitmap.draw_text(300,32*3+pos*32,100,32,"x"+number.to_s,0)
when 1
now_armors = $game_party.instance_variable_get :@armors
now_number = (now_armors[id].nil? ? 0 : now_armors[id])
@sprite.bitmap.draw_text(300,32*3+pos*32,100,32,now_number.to_s+"/"+number.to_s,0)
when 2
end
end
tem01 += condition[2].size
end
next_line = 32*(3+tem01)
end
# 杀敌的情况
if kind == 2
pos01 = 0
condition.sort.each do |id,number|
pos01 = condition.sort.index([id,number])
name = $data_enemies[id].name
@sprite.bitmap.draw_text(0,32*3+pos01*32,400,32,name,0)
case listKind
when 0,2
@sprite.bitmap.draw_text(300,32*3+pos01*32,100,32,"x"+number.to_s,0)
when 1
if $game_system.missionEnemyIds[@name][id] == nil
now_number = 0
else
now_number = $game_system.missionEnemyIds[@name][id]
end
@sprite.bitmap.draw_text(300,32*3+pos01*32,100,32,now_number.to_s+"/"+number.to_s,0)
end
end
next_line = 32*(3+condition.sort.size)
end
@sprite.bitmap.font.color = getColor(1)
@sprite.bitmap.draw_text(0,next_line,400,32,TEXT[2],0)
@sprite.bitmap.draw_text(64,next_line+pos02*32,400,32,name,0)
@sprite.bitmap.draw_text(300,next_line+pos02*32,100,32,"x"+number.to_s,0)
end
tem02 += item.size
end
next_line += tem02*32
@sprite.bitmap.draw_text(64,next_line+pos03*32,400,32,name,0)
@sprite.bitmap.draw_text(300,next_line+pos03*32,100,32,"x"+number.to_s,0)
end
tem03 += weapon.size
end
next_line += tem03*32
@sprite.bitmap.draw_text(64,next_line+pos04*32,400,32,name,0)
@sprite.bitmap.draw_text(300,next_line+pos04*32,100,32,"x"+number.to_s,0)
end
tem04 += armor.size
end
next_line += tem04*32
@window_des.refresh($game_system.finishNameSort[@finished.index],2)
return
end
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@finished.active = false
@finished.visible = false
@main_window.visible = true
@main_window.active = true
# @main_window.index = 0
return
end
end
def update_window_des
@window_des.update
if Input.trigger?(Input::C)
case @main_window.index
when 2 #←xiaoming
# when 0
$game_system.se_play($data_system.decision_se)
@window_des.active = false
@result.active = true
name = MissionList.canMissionList[@can_accept.index]
MissionList.Start(name)
@result.set_text("接受了任务" + name,1)
when 3 # 提交任务
# when 1
when 0 # 查看任务
# when 2
when 1 # 完成列表
# when 3
end
return
end
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@window_des.visible = false
@window_des.active = false
@window_des.nVisible
case @main_window.index
# 接受
when 0
@can_accept.active = true
@can_accept.visible = true
return
# 提交
when 2
@accepted.active = true
@accepted.visible = true
return
when 3
@finished.active = true
@finished.visible = true
end
end
end
def update_result
if Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)