| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
- local BuffEntity = require("buff/BuffEntity")
- local BuffEntityAnim = class("BuffEntityAnim", BuffEntity)
- function BuffEntityAnim:ctor(data)
- BuffEntityAnim.super.ctor(self, data)
- self._rootNodeB = global.sceneGraphCtl:GetSceneNode(global.MMO.NODE_SKILL_BEHIND)
- self._rootNodeF = global.sceneGraphCtl:GetSceneNode(global.MMO.NODE_SKILL)
- self._sceneAnims = {}
- local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
- self._sfxOffset = BuffProxy:GetSfxOffset(self._buffID)
- self._sfxSpeed = BuffProxy:GetSfxSpeed(self._buffID)
- self._unOffset = nil
- self._horseOffset = cc.p(0,0)
- self._audioID = BuffProxy:GetAudio(self._buffID)
- end
- function BuffEntityAnim:OnEnter()
- BuffEntityAnim.super.OnEnter(self)
- self:setVisible( true )
- self:updatePosition()
- self:PlayBuffAnim()
- if self._audioID then
- global.Facade:sendNotification( global.NoticeTable.Audio_Play, {type=global.MMO.SND_TYPE_SSR_UI, index=self._audioID} )
- end
- end
- function BuffEntityAnim:OnExit()
- BuffEntityAnim.super.OnExit(self)
- self:HideAnim()
- self:HideAnimStuck()
- end
- function BuffEntityAnim:PlayBuffAnim()
- local buffid = self._buffID
- if self._data.replaceId and self._data.replaceId > 0 then
- buffid = self._data.replaceId
- end
- local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
- local sfxConfig = BuffProxy:GetBuffSfxByID(buffid)
- if sfxConfig then
- local playSfx = sfxConfig.play_sfx
- if playSfx.sfxID then
- local sfxID = playSfx.sfxID
- local loop = playSfx.loop
- local data =
- {
- actorID = self._actorID,
- sfxID = tonumber(sfxID),
- frame = 0,
- speed = self._sfxSpeed or 1,
- count = loop or 1,
- front = true,
- offsetX = 0,
- offsetY = 0,
- }
- global.ActorEffectManager:AddEffect(data)
- end
- end
- end
- function BuffEntityAnim:ShowAnim(needCheck)
- local buffid = self._buffID
- if self._data.replaceId and self._data.replaceId > 0 then
- buffid = self._data.replaceId
- end
- local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
- local sfxConfig = BuffProxy:GetBuffSfxByID(buffid)
- if sfxConfig then
- if sfxConfig.front then
- local sfxID = sfxConfig.front.sfxID
- local loop = sfxConfig.front.loop
- local is8dir = sfxConfig.front.is8dir
- local dirfollow = sfxConfig.front.dirfollow
- self._unOffset = sfxConfig.front.unOffset
- self:addBuffSfx(sfxID, true, loop, is8dir, dirfollow)
- end
-
- if sfxConfig.behind then
- local sfxID = sfxConfig.behind.sfxID
- local loop = sfxConfig.behind.loop
- local is8dir = sfxConfig.behind.is8dir
- local dirfollow = sfxConfig.behind.dirfollow
- self:addBuffSfx(sfxID, false, loop, is8dir, dirfollow)
- end
- end
-
- if needCheck then
- local actor = global.actorManager:GetActor(self._actorID)
- if not actor then
- return
- end
- if (actor:IsMonster() or actor:IsHumanoid()) and (actor:IsDeath() or actor:IsDie()) then
- local isHide = tonumber(SL:GetMetaValue("GAME_DATA", "MonsterDieHideAnim")) == 1
- if isHide then
- self:HideAnim()
- end
- end
- end
- end
- function BuffEntityAnim:HideAnim()
- local buffid = self._buffID
- if self._data.replaceId and self._data.replaceId > 0 then
- buffid = self._data.replaceId
- end
- local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
- local sfxConfig = BuffProxy:GetBuffSfxByID(buffid)
- if sfxConfig then
- if sfxConfig.front then
- local sfxID = sfxConfig.front.sfxID
- self:removeBuffSfx(sfxID)
- end
-
- if sfxConfig.behind then
- local sfxID = sfxConfig.behind.sfxID
- self:removeBuffSfx(sfxID)
- end
- if sfxConfig.play_sfx then
- local sfxID = sfxConfig.play_sfx.sfxID
- self:removeBuffSfx(sfxID)
- end
- end
- end
- function BuffEntityAnim:IsShowStuckAnim( ... )
- local buffid = self._buffID
- if self._data.replaceId and self._data.replaceId > 0 then
- buffid = self._data.replaceId
- end
- local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
- local sfxConfig = BuffProxy:GetBuffSfxByID(buffid)
- local hasSfx = false
- if sfxConfig then
- if sfxConfig.front_stuck and sfxConfig.front_stuck.sfxID and sfxConfig.front_stuck.sfxID ~= 0 then
- hasSfx = true
- end
-
- if sfxConfig.behind_stuck and sfxConfig.behind_stuck.sfxID and sfxConfig.behind_stuck.sfxID ~= 0 then
- hasSfx = true
- end
- end
- return hasSfx
- end
- function BuffEntityAnim:ShowAnimStuck()
- local actor = global.actorManager:GetActor(self._actorID)
- if not actor then
- return nil
- end
- local buffid = self._buffID
- if self._data.replaceId and self._data.replaceId > 0 then
- buffid = self._data.replaceId
- end
- local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
- local sfxConfig = BuffProxy:GetBuffSfxByID(buffid)
- if sfxConfig then
- local falg = false
- local function callback()
- if self:IsInvalid() then
- return
- end
- if falg then
- return
- end
- falg = true
- self:HideAnimStuck()
- self:ShowAnim(true)
- end
- if sfxConfig.front_stuck then
- local sfxID = sfxConfig.front_stuck.sfxID
- local loop = sfxConfig.front_stuck.loop
- local is8dir = sfxConfig.front_stuck.is8dir
- local dirfollow = sfxConfig.front_stuck.dirfollow
- self:addBuffSfx(sfxID, true, loop, is8dir, dirfollow, callback)
- end
-
- if sfxConfig.behind_stuck then
- local sfxID = sfxConfig.behind_stuck.sfxID
- local loop = sfxConfig.behind_stuck.loop
- local is8dir = sfxConfig.behind_stuck.is8dir
- local dirfollow = sfxConfig.behind_stuck.dirfollow
- self:addBuffSfx(sfxID, false, loop, is8dir, dirfollow, callback)
- end
- end
- end
- function BuffEntityAnim:HideAnimStuck()
- local actor = global.actorManager:GetActor(self._actorID)
- if not actor then
- return nil
- end
- local buffid = self._buffID
- if self._data.replaceId and self._data.replaceId > 0 then
- buffid = self._data.replaceId
- end
- local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
- local sfxConfig = BuffProxy:GetBuffSfxByID(buffid)
- if sfxConfig then
- if sfxConfig.front_stuck then
- local sfxID = sfxConfig.front_stuck.sfxID
- self:removeBuffSfx(sfxID)
- end
-
- if sfxConfig.behind_stuck then
- local sfxID = sfxConfig.behind_stuck.sfxID
- self:removeBuffSfx(sfxID)
- end
- end
- end
- function BuffEntityAnim:addBuffSfx(sfxID, front, loop, is8dir, dirfollow, callback)
- if not sfxID then
- return nil
- end
- local actor = global.actorManager:GetActor(self._actorID)
- if not actor then
- return nil
- end
- -- create sfx
- if nil == self._sceneAnims[sfxID] and not actor:GetValueByKey(global.MMO.HUD_SNEAK) then
- local dir = (dirfollow or is8dir) and actor:GetDirection() or 0
- local sfx = global.FrameAnimManager:CreateSFXAnim(sfxID)
- sfx:SetGlobalElapseEnable(loop == 0)
- local root = front and self._rootNodeF or self._rootNodeB
- root:addChild(sfx, sfxID)
- local visible = CHECK_SETTING(global.MMO.SETTING_IDX_EFFECT_SHOW) ~= 1
- sfx:setVisible(visible)
- sfx:Play(0, dir, true, self._sfxSpeed or 1)
- self._sceneAnims[sfxID] = sfx
- sfx._dirfollow_ = dirfollow
- local count = 0
- local function overCB()
- if self:IsInvalid() then
- return
- end
- if loop > 0 then
- count = count + 1
- if loop == count then
- sfx:Stop()
- sfx:setVisible(false)
- end
- end
-
- if callback then
- callback()
- end
- end
- sfx:SetAnimEventCallback(overCB)
- end
- local position = actor:getPosition()
- self:setPosition(position.x, position.y)
- end
- function BuffEntityAnim:removeBuffSfx(sfxID)
- if not sfxID then
- return nil
- end
-
- if self._sceneAnims[sfxID] then
- self._sceneAnims[sfxID]:removeFromParent()
- self._sceneAnims[sfxID] = nil
- end
- end
- function BuffEntityAnim:OnActorStuck()
- if not self:IsShowStuckAnim() then
- return false
- end
- self:HideAnim()
- self:HideAnimStuck()
- self:ShowAnimStuck()
- return true
- end
- function BuffEntityAnim:setPosition(x, y)
- local actor = global.actorManager:GetActor(self._actorID)
- if not actor then
- return nil
- end
- local notOffset = self._unOffset and self._unOffset == 1
- local horseOffset = self._horseOffset or cc.p(0,0)
- for animID, anim in pairs(self._sceneAnims) do
- if actor:IsDropItem() then
- anim:setPosition(cc.pAdd(cc.pAdd(cc.p(x+horseOffset.x, y+horseOffset.y), notOffset and global.MMO.PLAYER_AVATAR_OFFSET or cc.p(0,0)), self._sfxOffset))
- else
- anim:setPosition(cc.pAdd(cc.pAdd(cc.p(x+horseOffset.x, y+horseOffset.y), global.MMO.PLAYER_AVATAR_OFFSET), self._sfxOffset))
- end
- end
- end
- function BuffEntityAnim:setVisible(visible)
- local actor = global.actorManager:GetActor(self._actorID)
- if not actor then
- return
- end
- if actor:IsPlayer() and actor:IsHoreseCopilot() then
- self:HideAnim()
- return
- end
- if actor:IsPlayer() and actor:GetHorseMasterID() and global.actorManager:GetActor(actor:GetHorseMasterID()) then
- local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
- if not BuffProxy:IsHorseShow(self._buffID) then
- self:HideAnim()
- return
- end
- end
- -- 潜行
- if visible and actor:GetValueByKey(global.MMO.HUD_SNEAK) then
- visible = false
- end
- if visible then
- self:ShowAnim()
- else
- self:HideAnim()
- end
- end
- function BuffEntityAnim:updatePosition()
- local actor = global.actorManager:GetActor(self._actorID)
- if actor and self._buffID == global.MMO.BUFF_ID_MAGIC_SHIELD then
- -- 检测是不是副驾的玩家 副驾玩家的buff特效都不显示出来
- self._horseOffset.y = 0
- local position = actor:getPosition()
- if actor and actor:IsPlayer() and actor:GetHorseMasterID() then
- self._horseOffset.y = 10
- end
- self:setPosition(position.x, position.y)
- elseif actor and actor:IsPlayer() then
- local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
- local offset = BuffProxy:GetHorseOffset(self._buffID)
- if offset.x ~= 0 or offset.y ~= 0 then
- if actor:GetHorseMasterID() and global.actorManager:GetActor(actor:GetHorseMasterID()) then
- else
- offset.x = 0
- offset.y = 0
- end
- self._horseOffset = offset
- local position = actor:getPosition()
- self:setPosition(position.x, position.y)
- end
-
- end
- end
- function BuffEntityAnim:UpdateSfxDir()
- local actor = global.actorManager:GetActor(self._actorID)
- if not actor then
- return false
- end
- if not actor.GetDirection then
- return false
- end
- for _, sfx in pairs(self._sceneAnims) do
- if sfx and sfx._dirfollow_ then
- sfx:Stop()
- sfx:Play(0, actor:GetDirection(), true)
- end
- end
- end
- return BuffEntityAnim
|