class Game_Party < Game_Unit
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
alias old_init initialize
def initialize
old_init
@tasks = {}
@sub_tasks= {}
#定义了一个任务列表,提前把所有的任务都写进去了
@task_list=TaskList.new
@sub = false
end
#--------------------------------------------------------------------------
# ● 是否存在子任务
#--------------------------------------------------------------------------
def is_sub
@sub
end
#--------------------------------------------------------------------------
# ● 启用子任务
#--------------------------------------------------------------------------
def set_sub
@sub = true
end
#--------------------------------------------------------------------------
# ● 添加新的任务
#--------------------------------------------------------------------------
def new_task(i, name, desc, type, father_task = -1)
if !is_sub
@tasks = tmp if !have_task?(i)
return
end
tmp = Task.new(i, name, desc, type, father_task)
if father_task < 0
@tasks = tmp if !have_task?(i)
else
@sub_tasks = tmp if father_task?(father_task) && !sub_task?(i)
end
end
#--------------------------------------------------------------------------
# ● 从已定义好的任务列表中添加新的任务
#--------------------------------------------------------------------------
def set_task(index)
temp = @task_list.get_task(index)
if !is_sub
@tasks[index] = temp if !have_task?(index)
return
end
if temp.has_father_task?
@sub_tasks[index] = temp if father_task?(temp.father_task) && !sub_task?(index)
else
@tasks[index] = temp if !have_task?(index)
end
end
#--------------------------------------------------------------------------
# ● 查询任务是否存在
#--------------------------------------------------------------------------
def have_task?(i)
return father_task?(i) || sub_task?(i)
end
#--------------------------------------------------------------------------
# ● 查询父任务是否存在
#--------------------------------------------------------------------------
def father_task?(i)
@tasks != nil
end
#--------------------------------------------------------------------------
# ● 查询子任务是否存在
#--------------------------------------------------------------------------
def sub_task?(i)
@sub_tasks != nil
end
#--------------------------------------------------------------------------
# ● 完成已有的任务,如果该任务有没有完成的子任务,则不能完成
#--------------------------------------------------------------------------
def finish_task(i)
@tasks.finish if father_task?(i) && sub_tasks_finished?(i)
@sub_tasks.finish if sub_task?(i)
end
#--------------------------------------------------------------------------
# ● 查询父任务序号为i的子任务,返回一个数组
#--------------------------------------------------------------------------
def get_sub_tasks(i)
return [] if !is_sub
tmp = []
for j in @sub_tasks.values
next if j.father_task != i
tmp.push(j)
end
return tmp
end
#--------------------------------------------------------------------------
# ● 查询父任务序号为i的子任务是否都已完成
#--------------------------------------------------------------------------
def sub_tasks_finished?(i)
return true if !is_sub
for j in @sub_tasks.values
next if j.father_task != i
return false if !j.finished
end
return true
end
#--------------------------------------------------------------------------
# ● 获取任务类型为cat的任务集合
#--------------------------------------------------------------------------
def all_tasks(cat)
n = []
m = []
for i in @tasks.values
next if i.key_task? != cat
tmp = get_sub_tasks(i.index)
if i.finished
n.push(i)
n += tmp
else
m.push(i)
m += tmp
end
end
return m + n
end