PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/TGame/TServerMS/scene.lua

http://awoe.googlecode.com/
Lua | 148 lines | 116 code | 23 blank | 9 comment | 24 complexity | c7ba0111f5467699dd9bf5d204170fee MD5 | raw file
  1if not Scene then
  2	Scene = {}
  3end
  4
  5function getSceneData(cid, did, sid)
  6	if not cid or not did or not sid then
  7		return
  8	end
  9
 10	local country = world[cid]
 11	if not country then
 12		return
 13	end
 14
 15	local district = country[did]
 16	if not district then
 17		return
 18	end
 19	return district[sid]
 20end
 21
 22function Scene.onCheckDistrict(cid, did, lvl)
 23	print("try to enter disctrict:", cid, did)
 24	local country = world[cid]
 25	if not country then
 26		return false
 27	end
 28
 29	local district = country[did]
 30	if not district then
 31		return false
 32	end
 33
 34	--
 35	--	add some logic of check level
 36	--
 37	return true
 38end
 39
 40function Scene.onCreate(cid, did, sid, scnmgr, progress)
 41	if not scnmgr then
 42		log.error("failed to create scene, null scene manager")
 43		return 0
 44	end
 45	if not progress then
 46		log.error("failed to create scene, null progress")
 47		return 0
 48	end
 49
 50	local sd = getSceneData(cid, did, sid)
 51	if not sd then
 52		log.error("failed to create scene, null static scene data")
 53		return 0
 54	end
 55
 56	--
 57	--	add some dependency checking here, such as:
 58	--	level requirement
 59	--	scene dependency
 60	--	progress data
 61	--
 62
 63	local scene = scnmgr:addScene(cid, did, sid, sd.type)
 64	if not scene then
 65		log.error("failed to create scene, manager error")
 66	end
 67end
 68
 69function Scene.onLoad(scene)
 70	log.info("loading scene ...")
 71end
 72
 73function Scene.onLoadCity(scene)
 74	log.info("loading scene for city ...")
 75	local cid, did, sid = scene:getStaticID()
 76	local sd = getSceneData(cid, did, sid)
 77	if not sd then
 78		log.error("failed to load combat scene")
 79		return
 80	end
 81	
 82	local m = scene:addN(10001)
 83	if m then
 84		m:setPosition(1, 1, 0)
 85	end
 86
 87	m = scene:addN(10002)
 88	if m then
 89		m:setPosition(1, 2, 0)
 90	end
 91	
 92	m = scene:addN(10003)
 93	if m then
 94		m:setPosition(3, 2, 0)
 95	end
 96
 97end
 98
 99function Scene.onLoadCombat(scene)
100	log.info("loading scene for combat ...")
101	local cid, did, sid = scene:getStaticID()
102	local sd = getSceneData(cid, did, sid)
103	if not sd then
104		log.error("failed to load combat scene")
105		return
106	end
107	
108end
109
110function Scene.onStartCombat(scene, datamgr, wid)
111	log.info("scene start combatting: ", wid)
112	local cid, did, sid = scene:getStaticID()
113	local prev_wid = datamgr:get(cid, did, sid)
114	if prev_wid+1<wid then
115		log.error("failed to start combat, required wave not complete")
116		return false
117	end
118	local sd = getSceneData(cid, did, sid)
119	if not sd then
120		log.error("failed to start combat, invalid static data")
121		return false
122	end
123
124	local wave = sd[wid]
125	if not wave then
126		log.error("failed to start combat, invalid wave id")
127		return false
128	end
129
130	local wd = monstergroups[wave]
131	if not wd then
132		log.error("failed to start combat, invalid wave data, no form found")
133		return false
134	end
135
136	for fpos, mid in ipairs(wd) do
137		if mid>0 then
138			local m = scene:addM(mid)
139			if m then
140				m:setPosition(1, 1, fpos)
141			end
142		end
143	end
144end
145
146function Scene.onEndCombat(scene)
147	log.info("scene end combatting: ")
148end