| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- --------------------------------------------
- -- 采集物
- --------------------------------------------
- local CollectExcel = require("excel.Collect")
- local Obj = require("core.Obj")
- local Msg = require("core.Msg")
- local Broadcast = require("broadcast.Broadcast")
- local Status = require("scene.Status")
- local MapCallback = require("scene.MapCallback")
- function create(collectId, ownerUuid)
- local cf = CollectExcel.collect[collectId]
- if not cf then
- assert(nil, collectId)
- end
- local collect = {}
- Obj.create(collect, Obj.TYPE_COLLECT)
- collect.collectId = collectId
- collect.ownerUuid = ownerUuid
- collect.way = cf.way
- return collect
- end
- function destroy(collect)
- Obj.destroy(collect)
- end
- function getObjAdd(collect)
- local collectId = collect.collectId
- local msgRet = Msg.gc.GC_COLLECT_ADD
- msgRet.obj_id = collect.id
- msgRet.collectId = collectId
- msgRet.x = collect.x
- msgRet.y = collect.y
- msgRet.way = collect.way
- return msgRet
- end
- function getSpeed()
- return 0
- end
- function enterScene(collect, sceneID, x, y)
- Obj.enterScene(collect, sceneID, x, y)
- end
- function collectStart(human, obj_id, x, y, way)
- local collect = Obj.objs[obj_id]
- -- 不存在
- if not collect or
- collect.obj_type ~= Obj.TYPE_COLLECT or
- collect.sceneID ~= human.sceneID then
- return
- end
- human.collect = human.collect or {}
- human.collect.startTime = os.time()
- human.collect.obj_id = obj_id
- human.x = x
- human.y = y
- human.way = way
- Status.doHumanControlStatusChange(human, Status.HUMAN_STATUS_COLLECT)
- local cf = CollectExcel.collect[collect.collectId]
- if cf and cf.tip1 ~= "" then
- Broadcast.sendErr(human, cf.tip1)
- end
- local msgRet = Msg.gc.GC_COLLECT_START
- msgRet.obj_id = obj_id
- msgRet.leftTime = cf.CollectTime
- Msg.send(msgRet, human.fd)
- end
- function collectFinish(human, obj_id)
- local collect = Obj.objs[obj_id]
- -- 不存在
- if not collect or
- collect.obj_type ~= Obj.TYPE_COLLECT or
- collect.sceneID ~= human.sceneID then
- Status.doHumanControlStatusChange(human, Status.HUMAN_STATUS_NORMAL)
- return
- end
- local cf = CollectExcel.collect[collect.collectId]
- if not human.collect or
- human.collect.obj_id ~= obj_id or
- human.collect.startTime + cf.CollectTime > os.time() then
- Status.doHumanControlStatusChange(human, Status.HUMAN_STATUS_NORMAL)
- return
- end
- human.collect = nil
- if cf and cf.tip2 ~= "" then
- Broadcast.sendErr(human, cf.tip2)
- end
- Obj.leaveScene(collect)
- destroy(collect)
- Status.doHumanControlStatusChange(human, Status.HUMAN_STATUS_NORMAL)
- MapCallback.onCollectFinish(human, collect)
- local msgRet = Msg.gc.GC_COLLECT_FINISH
- msgRet.obj_id = obj_id
- Msg.send(msgRet, human.fd)
- end
|