ObjCollect.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. --------------------------------------------
  2. -- 采集物
  3. --------------------------------------------
  4. local CollectExcel = require("excel.Collect")
  5. local Obj = require("core.Obj")
  6. local Msg = require("core.Msg")
  7. local Broadcast = require("broadcast.Broadcast")
  8. local Status = require("scene.Status")
  9. local MapCallback = require("scene.MapCallback")
  10. function create(collectId, ownerUuid)
  11. local cf = CollectExcel.collect[collectId]
  12. if not cf then
  13. assert(nil, collectId)
  14. end
  15. local collect = {}
  16. Obj.create(collect, Obj.TYPE_COLLECT)
  17. collect.collectId = collectId
  18. collect.ownerUuid = ownerUuid
  19. collect.way = cf.way
  20. return collect
  21. end
  22. function destroy(collect)
  23. Obj.destroy(collect)
  24. end
  25. function getObjAdd(collect)
  26. local collectId = collect.collectId
  27. local msgRet = Msg.gc.GC_COLLECT_ADD
  28. msgRet.obj_id = collect.id
  29. msgRet.collectId = collectId
  30. msgRet.x = collect.x
  31. msgRet.y = collect.y
  32. msgRet.way = collect.way
  33. return msgRet
  34. end
  35. function getSpeed()
  36. return 0
  37. end
  38. function enterScene(collect, sceneID, x, y)
  39. Obj.enterScene(collect, sceneID, x, y)
  40. end
  41. function collectStart(human, obj_id, x, y, way)
  42. local collect = Obj.objs[obj_id]
  43. -- 不存在
  44. if not collect or
  45. collect.obj_type ~= Obj.TYPE_COLLECT or
  46. collect.sceneID ~= human.sceneID then
  47. return
  48. end
  49. human.collect = human.collect or {}
  50. human.collect.startTime = os.time()
  51. human.collect.obj_id = obj_id
  52. human.x = x
  53. human.y = y
  54. human.way = way
  55. Status.doHumanControlStatusChange(human, Status.HUMAN_STATUS_COLLECT)
  56. local cf = CollectExcel.collect[collect.collectId]
  57. if cf and cf.tip1 ~= "" then
  58. Broadcast.sendErr(human, cf.tip1)
  59. end
  60. local msgRet = Msg.gc.GC_COLLECT_START
  61. msgRet.obj_id = obj_id
  62. msgRet.leftTime = cf.CollectTime
  63. Msg.send(msgRet, human.fd)
  64. end
  65. function collectFinish(human, obj_id)
  66. local collect = Obj.objs[obj_id]
  67. -- 不存在
  68. if not collect or
  69. collect.obj_type ~= Obj.TYPE_COLLECT or
  70. collect.sceneID ~= human.sceneID then
  71. Status.doHumanControlStatusChange(human, Status.HUMAN_STATUS_NORMAL)
  72. return
  73. end
  74. local cf = CollectExcel.collect[collect.collectId]
  75. if not human.collect or
  76. human.collect.obj_id ~= obj_id or
  77. human.collect.startTime + cf.CollectTime > os.time() then
  78. Status.doHumanControlStatusChange(human, Status.HUMAN_STATUS_NORMAL)
  79. return
  80. end
  81. human.collect = nil
  82. if cf and cf.tip2 ~= "" then
  83. Broadcast.sendErr(human, cf.tip2)
  84. end
  85. Obj.leaveScene(collect)
  86. destroy(collect)
  87. Status.doHumanControlStatusChange(human, Status.HUMAN_STATUS_NORMAL)
  88. MapCallback.onCollectFinish(human, collect)
  89. local msgRet = Msg.gc.GC_COLLECT_FINISH
  90. msgRet.obj_id = obj_id
  91. Msg.send(msgRet, human.fd)
  92. end