任务

-- ------------------------------------
-- 任务项
-- ------------------------------------
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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值