情节

--[[
 file name .    GameList.lua
 author  .      Clark/陈泽丹
 created .      8.13.2011
 purpose .      双向队列
--]]


--module("GameList", package.seeall)

--双向队列
function list_newList()
    local first = 1
    local last = 0
    local list = {}
	local listManager = {}
    function listManager.pushFront(_tempObj)
        first = first - 1
        list[first] = _tempObj
    end
    function listManager.pushBack(_tempObj)
        last = last + 1
        list[last] = _tempObj
    end
    function listManager.temp_getFront()
        if listManager.bool_isEmpty() then
            return nil
        else
            local val = list[first]
            return val
        end
    end
    function listManager.temp_getBack()
        if listManager.bool_isEmpty() then
            return nil
        else
            local val = list[last]
            return val
        end
    end
    function listManager.popFront()
		if listManager.bool_isEmpty() then
            return
		end
        list[first] = nil
        first = first + 1
    end
    function listManager.popBack()
		if listManager.bool_isEmpty() then
            return
		end
        list[last] = nil
        last = last - 1
    end
    function listManager.clear()
        while false == listManager.bool_isEmpty() do
        listManager.popFront()
    end
    end
    function listManager.bool_isEmpty()
        if first > last then
			first = 1
			last = 0
            return true
        else
            return false
        end
    end
    function listManager.d_getSize()
        if  listManager.bool_isEmpty() then
            return 0
        else
            return last - first + 1
        end
    end
    return listManager
end


 

 

--[[
 file name :    GameEvents.lua
 author  :      Clark/陈泽丹
 created :      8:13:2011
 purpose :      故事情节线
--]]

--module("GameEvents", package.seeall)
--pakList = require "GameList"

function manager_newEventManager()
	--事件流
	function events_newEvents(_ID)
		local ID = _ID or os.time()
		local cmdpars = list_newList()          		--隐藏数据
		local events = {}                               --公开数据
		function events.id_getID()
			return ID
		end
		--添加事件
		function events.push(_trigger, _tTgrPar, _fun, _tFunPar, _szName)
			local t = { szName = _szName or "", trigger = _trigger, tTgrPar = _tTgrPar or {}, fun = _fun, tFunPar = _tFunPar or {}}
			cmdpars.pushBack(t)
		end
		--清空事件
		function events.clear()
			cmdpars.clear()
		end
		--创建事件
		function events.setEvent()
			local tVal = cmdpars.temp_getFront()
			if nil ~= tVal then
				if nil ~= tVal.trigger then
					API_TraceError(tVal.szName .. " setEvent")
					tVal.trigger(events.id_getID(), tVal.tTgrPar)
				end
			end
		end
		--处理事件
		function events.onEvent(tEventPar)
			local tEventPar = tEventPar or {}
			local tVal = cmdpars.temp_getFront()
			cmdpars.popFront()
			if nil ~= tVal then
				if nil ~= tVal.fun then
					tVal.fun(events.id_getID(), tVal.tFunPar, tEventPar)
					API_TraceError(tVal.szName .. " onEvent")
				end
			end
		end
		--是否还有事件
		function events.bool_isEmpty()
			local val = cmdpars.bool_isEmpty()
			return val
		end
		return events                   --返回公开数据
	end

	--事件流的管理
	local et = {}
	local manager = {}
	function manager.events_newEvents(_ID)
		et[_ID] = events_newEvents(_ID)
		return et[_ID]
	end
	function manager.events_getEvents(_ID)
		return et[_ID]
	end
	function manager.deleteEvents(_ID)
		if nil ~= et[_ID] then
			et[_ID].clear()
		end
		et[_ID] = nil
	end
	return manager
end


 

EVENT_MANAGER = manager_newEventManager()
--API_TraceError
--API_Trace


--监视器基类(语法所限, 未把相关函数实现为虚函数)
local function trigger_newGTrigger(_eventID)
	local triggerThis =
	{
		pTrigger = nil,																	--监视器指针为空
		m_eventID = _eventID
	}
	--API_TraceError("-> ------------------- newTrigger ------------------ " .. triggerThis.m_eventID)
	--删除全局触发器
	function triggerThis.nil_deleteTrigger()
		API_DestroyTriggerG(triggerThis.pTrigger)
		--API_TraceError("<- ----------------- deleteTrigger ----------------- " .. triggerThis.m_eventID)
		return nil
	end
	return triggerThis
end




--死亡回调函数
function onDieCallBack(_tEventPar, param2, Type, FastID, KillerType, KillerID, MonsterID, MapID, PosX, PosY)
	API_TraceError("onDieCallBack " .. _tEventPar .. " Kill: " .. MonsterID)
	local et = EVENT_MANAGER.events_getEvents(_tEventPar)
	if nil ~= et then
		et.onEvent()
		et.setEvent()
	end
end
--时间的全局触发函数
function onTimeCallBack(_tEventPar)
	API_TraceError("onTimeCallBack " .. _tEventPar)
	local et = EVENT_MANAGER.events_getEvents(_tEventPar)
	if nil ~= et then
		et.onEvent()
		et.setEvent()
	end
end
--区域监听生物的全局触发器个人角色版
function onAreaCallBack(_dTeamID, _tEventPar, _param3, _param4)
	API_TraceError("onAreaCallBack " .. _tEventPar)
	local et = EVENT_MANAGER.events_getEvents(_tEventPar)
	if nil ~= et then
		et.onEvent()
		et.setEvent()
	end
end

TestEventID = 0
function onAreaSigleCallBack(_dTeamID, _tEventPar, _param3, _param4)
	API_TraceError("onAreaSigleCallBack " .. _dTeamID)
	local et = EVENT_MANAGER.events_getEvents(TestEventID)
	if nil ~= et then
		et.onEvent()
		et.setEvent()
	end
end







--生成死亡的全局触发器
function trigger_newGDieTrigger(_tEventPar, _pSomething)
	local triggerThis = trigger_newGTrigger(_tEventPar)
	triggerThis.pTrigger = API_CreateDieTriggerG(_tEventPar, 0, 0, _pSomething, "onDieCallBack")
	if 0 == triggerThis.pTrigger then
		API_TraceError("Failed in trigger_newGDieTrigger:  API_CreateDieTriggerG ")
	end
	return triggerThis
end
--生成时间的全局触发器
function trigger_newGTimerTrigger(_tEventPar, _timeStep)
	local triggerThis = trigger_newGTrigger(_tEventPar)
	triggerThis.pTrigger = API_CreateTimerTriggerG(_tEventPar, os.time(), _timeStep, 1, "onTimeCallBack")
	if 0 == triggerThis.pTrigger then
		API_TraceError("Failed in trigger_newGTimerTrigger:  API_CreateTimerTriggerG ")
	end
	return triggerThis
end
--生成监听生物的全局触发器
function trigger_newGSigleAreaTrigger(_tEventPar, _dTeamID, _dMapObj, _dPosX, _dPosY, _dRadius)
	local triggerThis = trigger_newGTrigger(_tEventPar)
	triggerThis.pTrigger = API_CreateAreaCreatureTriggerG(0, _dTeamID, _dMapObj, _dPosX, _dPosY, _dRadius, "onAreaSigleCallBack")
	if 0 == triggerThis.pTrigger then
		API_TraceError("Failed in trigger_newGAreaTrigger:  API_CreateAreaCreatureTriggerG ")
	end
	return triggerThis
end


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值