123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- ---@class MountInfo
- ---@field isHasOwnerMount boolean
- MountInfo = class()
- local this = MountInfo
- function this:ctor()
- end
- function this:Reset()
- end
- function this:Init()
- self:InitData()
- self:RegistMessages()
- end
- function this:InitData()
- self.ride_mount_id = 0
- self.fightTime = Time.time
- self.exit_fight_time = 0
- if SL:HasConfig("cfg_global",810) then
- ---@type cfg_global_column
- local tbl = SL:GetConfig("cfg_global",810)
- self.exit_fight_time =tonumber(tbl.value)
- end
- ---@type cfg_mount_column
- local tbl = SL:GetConfig("cfg_mount",1)
- if tbl then
- self.effectId = tonumber(tbl.ridingEffect)
- end
- end
- function this:RegistMessages()
- SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_CURRENT_RIDE_MOUNT,self.RES_CURRENT_RIDE_MOUNT,self)
- SL:RegisterLUAEvent(LUA_EVENT_MOUNT_ISON,self.LUA_EVENT_MOUNT_ISON,self)
- SL:RegisterLUAEvent(LUA_EVENT_PLAYER_MAPPOS_CHANGE,self.OnPlayerMapPosChange,self)
- SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_MOUNT_LOGO,self.RES_MOUNT_LOGO,self)
- SL:RegisterLUAEvent(LUA_EVENT_FIGHT_RESULT, self.LUA_EVENT_FIGHT_RESULT, self)
- SL:RegisterLUAEvent(LUA_EVENT_MOUNTID_CHANGE, self.LUA_EVENT_MOUNTID_CHANGE, self)
- SL:RegisterLUAEvent(LUA_EVENT_ROLE_ACTION_CHANGE, self.LUA_EVENT_ROLE_ACTION_CHANGE, self)
- end
- function this:RES_CURRENT_RIDE_MOUNT(id,mountId)
- self.ride_mount_id = mountId
- end
- function this:LUA_EVENT_MOUNT_ISON(id,stateInfo)
- local rid = SL:GetMetaValue("MAIN_ACTOR_ID")
- if stateInfo.role.data.id == rid then
- local isDie = SL:GetMetaValue(EMetaVarGetKey.USER_IS_DIE)
- if not isDie then
- local isSafe = SL:GetMetaValue(EMetaVarGetKey.IN_SAFE_AREA)
- SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_SET_MOUNT_IS_SHOW,(stateInfo.state and not isSafe) and 1 or 0)
- end
- end
- if self.effectId then
- if stateInfo.state then
- SL:SetMetaValue(EMetaVarSetKey.SET_EFFECT_ON_ROLE, stateInfo.role.data.id, tonumber(self.effectId), nil, true, EPlayEffectOverType.Loop)
- else
- SL:SetMetaValue(EMetaVarSetKey.RECYCLE_EFFECT_ON_ROLE,stateInfo.role.data.id, tonumber(self.effectId))
- end
- end
- end
- function this:OnPlayerMapPosChange()
- local isDie = SL:GetMetaValue(EMetaVarGetKey.USER_IS_DIE)
- local isSafe = SL:GetMetaValue(EMetaVarGetKey.IN_SAFE_AREA)
- if not isSafe and self.lastIsSafe and self.ride_mount_id ~= 0 and not isDie then
- SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_SET_MOUNT_IS_SHOW,isSafe and 0 or 1)
- end
- self.lastIsSafe = isSafe
- end
- function this:RES_MOUNT_LOGO(id,message)
- self.isHasOwnerMount = message.logo == 1
- self.isRankShowMount = message.rank ~= 0
- end
- function this:LUA_EVENT_FIGHT_RESULT(id,message)
- if self.ride_mount_id ~= 0 then
- local rid = SL:GetMetaValue("MAIN_ACTOR_ID")
- rid = tonumber(rid)
- local isFight = message.targetId == rid or message.attackerId == rid
- if not isFight then
- for i, v in pairs(message.target) do
- if v.targetId == rid then
- isFight = true
- break
- end
- end
- end
- if isFight then
- local isOn = SL:GetMetaValue(EMetaVarGetKey.GET_PLAYER_IS_ON_MOUNTID,rid)
- local role = SL:GetRoleById(rid)
- if isOn or (role and role.data.MountId~=0) then
- SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_SET_MOUNT_IS_SHOW,0)
- end
- self.fightTime = Time.time
- if self.timer then
- SL:UnSchedule(self.timer)
- self.timer = nil
- end
- self.timer = SL:Schedule(self.timer,0,1,self.exit_fight_time,function()
- if Time.time - self.fightTime >= self.exit_fight_time then--脱战
- local isDie = SL:GetMetaValue(EMetaVarGetKey.USER_IS_DIE)
- local isSafe = SL:GetMetaValue(EMetaVarGetKey.IN_SAFE_AREA)
- if not isDie and not isSafe then
- SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_SET_MOUNT_IS_SHOW,1)
- end
- end
- end)
- end
- end
- end
- function this:LUA_EVENT_MOUNTID_CHANGE(id,data)
- if data.new ~= 0 then
- ---@type cfg_mount_column
- local tbl = SL:GetConfig("cfg_mount",data.new)
- if tbl then
- self.effectId = tbl.ridingEffect
- SL:SetMetaValue(EMetaVarSetKey.SET_EFFECT_ON_ROLE, data.role.data.id, tonumber(self.effectId), nil, true, EPlayEffectOverType.Loop)
- end
- elseif self.effectId then
- SL:SetMetaValue(EMetaVarSetKey.RECYCLE_EFFECT_ON_ROLE,data.role.data.id, tonumber(self.effectId))
- end
- end
- ---@param role Role
- function this:LUA_EVENT_ROLE_ACTION_CHANGE(id,role)
- local isSafe = SL:GetMetaValue(EMetaVarGetKey.IN_SAFE_AREA)
- if role.data.mountId and role.data.mountId ~= 0 then
- if role.data.action == EAction.Walk or role.data.action == EAction.Run then
- if not isSafe then
- ---@type cfg_mount_column
- local tbl = SL:GetConfig("cfg_mount",role.data.mountId)
- if tbl then
- self.effectId = tbl.ridingEffect
- SL:SetMetaValue(EMetaVarSetKey.SET_EFFECT_ON_ROLE, role.data.id, tonumber(self.effectId), nil, true, EPlayEffectOverType.Loop)
- end
- end
- elseif self.effectId then
- --SL:SetMetaValue(EMetaVarSetKey.RECYCLE_EFFECT_ON_ROLE,role.data.id, tonumber(self.effectId))
- end
- end
- end
- function this:Reset()
- self.lastIsSafe = false
- self.ride_mount_id = 0
- if self.timer then
- SL:UnSchedule(self.timer)
- self.timer = nil
- end
- end
|