local BuffEntityAnim = require("buff/BuffEntityAnim") local BuffEntityAvatar = class("BuffEntityAvatar",BuffEntityAnim) local player_bound_box = cc.rect( 0, 0, 48, 64 ) local monster_bound_box = cc.rect( 0, 0, 60, 84 ) function BuffEntityAvatar:ctor(data) BuffEntityAvatar.super.ctor(self,data) local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff) self._cfgColor = BuffProxy:GetBuffColorByID( self._buffID ) self._cfgSacle = BuffProxy:GetBuffScaleByID( self._buffID ) self._cfgAvatar = BuffProxy:GetBuffAvatarByID( self._buffID ) self._avatarScales = {} end function BuffEntityAvatar:OnEnter() BuffEntityAvatar.super.OnEnter(self) self:FeatureActor() end function BuffEntityAvatar:OnExit() BuffEntityAvatar.super.OnExit(self) self:UnFeatureActor() end function BuffEntityAvatar:updatePosition() BuffEntityAvatar.super.updatePosition(self) end function BuffEntityAvatar:FeatureActor() local actor = global.actorManager:GetActor(self._actorID) if not actor then return end if self._cfgAvatar then if actor:IsMonster() and self._cfgAvatar.avatarType == 1 and self._cfgAvatar.avatarID then self._originClothID = actor:GetAnimationID() actor:SetClothID(self._cfgAvatar.avatarID) actor:dirtyFeature() elseif actor:IsPlayer() and not actor:GetHorseMasterID() and not actor:IsHoreseCopilot() then if global.BuffManager:CheckRmvBuffAvatar(actor:GetID(), self._cfgAvatar) then actor:SetMonsterFeatureID(0) actor:updateMonster(0) end if self._cfgAvatar.avatarType == 1 then actor:SetKeyValue("IS_MON_AVATAR_ONLY_WALK", true) end actor:SetMonsterFeatureID( self._cfgAvatar.avatarID ) actor:dirtyFeature() end end self._cfgColor = global.BuffManager:CheckBuffColorByID(self._actorID, self._buffID) self._cfgSacle = global.BuffManager:CheckBuffScale(self._actorID, self._buffID) self:OnRefreshFeature( self._cfgColor, self._cfgSacle ) local defaultHeight = player_bound_box.height if actor:IsMonster() then defaultHeight = monster_bound_box.height end -- 调整hud位置 local hudTop = defaultHeight * (self._cfgSacle-1) local actorpos = actor:getPosition() local defaultHudTop = actor.GetHUDTop and actor:GetHUDTop() or 0 actor:SetKeyValue(global.MMO.BUFF_SACLE_OFFSET, {x=0, y=hudTop}) global.HUDManager:setPosition(self._actorID, actorpos.x, actorpos.y + defaultHudTop) end function BuffEntityAvatar:UnFeatureActor() local actor = global.actorManager:GetActor(self._actorID) if not actor then return end actor:SetKeyValue("IS_MON_AVATAR_ONLY_WALK", nil) local cfgAvatar = global.BuffManager:CheckBuffAvatar(self._actorID,self._buffID) if actor:IsMonster() then if cfgAvatar and cfgAvatar.avatarType == 1 and cfgAvatar.avatarID then actor:SetClothID(cfgAvatar.avatarID) actor:dirtyFeature() elseif self._originClothID then actor:SetClothID(self._originClothID) actor:dirtyFeature() self._originClothID = nil end elseif actor:IsPlayer() and not actor:GetHorseMasterID() and not actor:IsHoreseCopilot() then local id = cfgAvatar and cfgAvatar.avatarID if global.BuffManager:CheckRmvBuffAvatar(actor:GetID(), cfgAvatar) or not id then actor:SetMonsterFeatureID(0) actor:updateMonster(0) end if id and id > 0 then if cfgAvatar.avatarType == 1 then actor:SetKeyValue("IS_MON_AVATAR_ONLY_WALK", true) end actor:SetMonsterFeatureID( id ) actor:dirtyFeature() end end self._avatarScales = {} self._cfgColor = global.BuffManager:CheckBuffColorByID(self._actorID, self._buffID) self._cfgSacle = global.BuffManager:CheckBuffScale(self._actorID, self._buffID) self:OnRefreshFeature( self._cfgColor, self._cfgSacle, true ) -- 调整hud位置 local hudTop = actor:GetHUDTop() * (self._cfgSacle-1) local actorpos = actor:getPosition() local defaultHudTop = actor.GetHUDTop and actor:GetHUDTop() or 0 actor:SetKeyValue(global.MMO.BUFF_SACLE_OFFSET, {x=0, y=hudTop}) global.HUDManager:setPosition(self._actorID, actorpos.x, actorpos.y + defaultHudTop) end function BuffEntityAvatar:OnRefreshFeature( color, scale, isUnFeat ) if not color and not scale then return end local actor = global.actorManager:GetActor(self._actorID) if not actor then return end if actor:IsPlayer() and (actor:GetHorseMasterID() or actor:IsHoreseCopilot()) then scale = 1 end local function featureColor( anim ) if not color then return end local p = global.GLProgramCache:getGLProgram("ShaderPositionTextureColor_noMVP") anim:setGLProgram(p) anim:setColor( color ) end local function featureScale( anim ) if not scale then return end local animID = anim:GetID() local enlarge = anim:GetEnlarge() local avatarScale = enlarge * scale if self._avatarScales[animID] == avatarScale then return end local aScale = anim:getScale() self._avatarScales[animID] = avatarScale anim:setScale( avatarScale ) local avatarOffset = global.MMO.PLAYER_AVATAR_OFFSET local offx = (scale * enlarge - aScale) * avatarOffset.x local offy = (scale * enlarge - aScale) * avatarOffset.y local pos = anim:getTurePosition() anim:setPosition(pos.x + offx, pos.y + offy) end local function featureShader( anim ) featureColor( anim ) featureScale( anim ) end local anim = actor:GetAnimation() if anim then featureShader(anim) end if actor.GetAnimationShield then anim = actor:GetAnimationShield() if anim then featureShader(anim) end end if actor.GetAnimationShieldEff then anim = actor:GetAnimationShieldEff() if anim then featureShader(anim) end end if actor.GetAnimationWings then anim = actor:GetAnimationWings() if anim then featureShader(anim) end end if actor.GetAnimationMount then anim = actor:GetAnimationMount() if anim then featureShader(anim) end end if actor.GetAnimationHair then anim = actor:GetAnimationHair() if anim then featureShader(anim) end end if actor.GetAnimationWeapon then anim = actor:GetAnimationWeapon() if anim then featureShader(anim) end end if actor.GetAnimationWeaponEff then anim = actor:GetAnimationWeaponEff() if anim then featureShader(anim) end end if actor.GetAnimationLeftWeapon then anim = actor:GetAnimationLeftWeapon() if anim then featureShader(anim) end end if actor.GetAnimationLeftWeaponEff then anim = actor:GetAnimationLeftWeaponEff() if anim then featureShader(anim) end end if actor.GetAnimationMonster then anim = actor:GetAnimationMonster() if anim then featureShader(anim) end end end function BuffEntityAvatar:UpdatePresent() self:OnRefreshFeature( self._cfgColor, self._cfgSacle ) end return BuffEntityAvatar