/TGame/TServerMS/scene.lua

http://awoe.googlecode.com/ · Lua · 148 lines · 116 code · 23 blank · 9 comment · 26 complexity · c7ba0111f5467699dd9bf5d204170fee MD5 · raw file

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