-- ------------------------------------
-- 任务项
-- ------------------------------------
function TaskBuilder()
local function Task()
local public = {}
local task_state_list = {}
local old_state = nil
local cur_state = nil
--设置状态
function public.setState( _state_index )
--API_Trace( "_state_index" .. _state_index )
if nil == _state_index or cur_state == _state_index then
return
end
old_state = cur_state
cur_state = _state_index
if G_TASK_STATE.DELETE ~= cur_state then
public.DBData.CUR_STATE = cur_state
end
if nil ~= old_state and nil ~= task_state_list[old_state] then
task_state_list[old_state].exitState( cur_state )
end
if nil ~= cur_state and nil ~= task_state_list[cur_state] then
task_state_list[cur_state].enterState( old_state )
end
end
--获得当前状态
function public.getState()
return task_state_list[cur_state]
end
--获得当前数据库数据
function public.getDBData()
return public.DBData
end
return public, task_state_list
end
--任务建造者
local task_pub, task_state_list = Task()
local builder = {}
--建立数据
function builder.BuilderData( _role, _TYPE, _SCP_ID, _EXT_DATA, _t_data )
task_pub.ROLE = _role
task_pub.DBData = { TYPE = _TYPE, SCP_ID = _SCP_ID, EXT_DATA = _EXT_DATA, CUR_STATE = cur_state, SUB_DATA = {}, UID = API_GetTaskUID(task_pub), }
if nil ~= _t_data.STORY_TASK_INDEX then
task_pub.DBData.STORY_TASK_INDEX = _t_data.STORY_TASK_INDEX
end
if nil ~= _t_data.SKIN then
task_pub.DBData.SKIN = _t_data.SKIN
end
if nil ~= _t_data.SUB_DATA then
task_pub.DBData.SUB_DATA = _t_data.SUB_DATA
end
end
--建立状态
function builder.BuilderState( _state_index, _state )
task_state_list[ _state_index ] = _state
end
--设置状态
function builder.SetState( _t_data )
local cur_state = _t_data.CUR_STATE
if nil == cur_state or G_TASK_STATE.UNKNOW == cur_state or G_TASK_STATE.ACCEPT == cur_state then
task_pub.setState( G_TASK_STATE.ACCEPT )
elseif G_TASK_STATE.PROCEED == cur_state then
task_pub.setState( G_TASK_STATE.PROCEED )
elseif G_TASK_STATE.DELIVER == cur_state then
task_pub.setState( G_TASK_STATE.DELIVER )
elseif G_TASK_STATE.FINISH == cur_state then
task_pub.setState( G_TASK_STATE.FINISH )
elseif G_TASK_STATE.FAILED == cur_state then
task_pub.setState( G_TASK_STATE.FAILED )
else
task_pub.setState( G_TASK_STATE.UNKNOW )
end
end
--获得任务
function builder.GetTask()
return task_pub
end
return builder
end
任务
最新推荐文章于 2024-10-06 23:22:29 发布