local Msg = require("core.Msg") local Grid = require("bag.Grid") local BagLogic = require("bag.BagLogic") local Broadcast = require("broadcast.Broadcast") local Lang = require("common.Lang") local Util = require("common.Util") local ItemDefine = require("bag.ItemDefine") local BeSkill = require("combat.BeSkill") local HeroLogic = require("hero.HeroLogic") local RoleHeadLogic = require("role.RoleHeadLogic") local SkinExcel = require("excel.skin").skin local HeroExcel = require("excel.hero").hero local SkillExcel = require("excel.skin").skill local OutExcel = require("excel.skin").out local ItemExcel = require("excel.item").item local RoleAttr = require("role.RoleAttr") local function getBag(human) if not (human.skinBag and human.heroSkin) then human.skinBag = {} human.heroSkin = {} human.hasSkin = {} for i = 1,human.db.skinBag[0] do local data = human.db.skinBag[i] if data then if data.heroInd then local skinSkillID local heroGrid = human.db.heroBag[data.heroInd] if not heroGrid then data.heroInd = nil else local heroID = heroGrid.id local heroConf = HeroExcel[heroID] for _,v in ipairs(heroConf.skin) do if v[1] == data.id then human.heroSkin[data.heroInd] = {i,tonumber(v[2])} end end end end human.skinBag[i] = data.id human.hasSkin[data.id] = human.hasSkin[data.id] or {} human.hasSkin[data.id][i] = 1 end end end return human.db.skinBag end --[[ skin = { ttl = number -- 有效时长 -1表示永久 state = number -- 0表示未穿戴 1 表示穿戴 } -- skin 拥有唯一性 ]] -- 获取所有皮肤信息 local function skinListQuery(human) local skinBag = human.db.skinBag local ret = {} for i = 1,#skinBag do ret[data.id] = { idx = i, id = data.id, ttl = data.ttl, state = data.state, } end return ret end -- 获取皮肤为skinId的皮肤 local function skinQueryById(human,skinId) local skin = human.db.skinBag[skinId] if skin then return { id = skinId, ttl = skin.ttl, state = skin.state, } end end -- 生成发送给客户端的皮肤数据 local function skinNetGen(human,net,id) local skinCfg = assert(SkinExcel[id],"invalid skinId is ",id) net.id = id net.name = skinCfg.name data.desc = skinCfg.desc data.head = skinCfg.head data.body = skinCfg.body data.icon = skinCfg.icon data.camp = skinCfg.camp data.order = skinCfg.order data.type = skinCfg.type local attrLen = 0 for k,v in ipairs(skinCfg.attrs) do attrLen = attrLen + 1 data.attrs[attrLen].key = v[1] data.attrs[attrLen].value = v[2] end data.attrs[0] = attrLen data.heroName = HeroExcel[skinCfg.heroId] and HeroExcel[skinCfg.heroId].name or "" end -- 皮肤穿戴 --[[ @param2 = id -- 皮肤Id @param3 = heroIdx -- 对应英雄存档的idx ]] local function skinOn(human,skinIdx,heroIdx) local skin = human.db.skinBag[skinIdx] -- 当前skin不存在 或者 皮肤已经穿戴 if not skin or skin.state == 1 then return Broadcast.sendErr(human, skinIdx..":skinOn:"..Lang.SKIN_PARAM_ERR) end local heroId = HeroLogic.getHeroIdByIndex(human,heroIdx) local heroGrid = HeroLogic.getHeroGrid(human,heroId,heroIdx) -- 英雄不存在 或者 英雄已经装备当前皮肤 if not heroGrid then return Broadcast.sendErr(human, heroIdx..":heroIdx:"..Lang.SKIN_PARAM_ERR) end if heroGrid.skinOn == skin.id then return Broadcast.sendErr(human, Lang.SKIN_DOUBLE_ON) end human.db.skinBag[skinIdx].state = 1 -- 对所有heroId相同的英雄操作 local heroIdxList = HeroLogic.getHeroListById(human,heroId) for _,idx in ipairs(heroIdxList) do human.db.heroBag[idx].skinOn = skin.id end -- 回复给客户端 local msgRet = Msg.gc.GC_SKIN_UPDATE local data = msgRet.list[1].data data.ind = skinIdx data.isOn = 1 skinNetGen(human,data.data,skin.id) msgRet.list[1].op = 3 msgRet.list[0] = 1 Msg.send(msgRet,human.fd) end -- 皮肤脱下 --[[ @param2 = heroIdx -- 对应英雄存档的idx ]] local function skinOff(human,heroIdx) local heroId = HeroLogic.getHeroIdByIndex(human,heroIdx) local heroGrid = HeroLogic.getHeroGrid(human,heroId,heroIdx) local skinId = heroGrid.skinOn -- 英雄不存在 或者 英雄未穿戴皮肤 if not heroGrid or not skinId then return Broadcast.sendErr(human, heroIdx..":heroIdx:"..Lang.SKIN_PARAM_ERR) end local skinIdx = nil for idx,skin in pairs(human.db.skinBag) do if skin.id == skinId then skinIdx = idx human.db.skinBag[idx].state = 0 break end end -- 对所有heroId相同的英雄操作 local heroIdxList = HeroLogic.getHeroListById(human,heroId) for _,idx in ipairs(heroIdxList) do human.db.heroBag[idx].skinOn = nil end -- 回复给客户端 local msgRet = Msg.gc.GC_SKIN_UPDATE local data = msgRet.list[1].data data.ind = skinIdx data.isOn = 0 skinNetGen(human,data.data,skinId) msgRet.list[1].op = 3 msgRet.list[0] = 1 Msg.send(msgRet,human.fd) end -------------------------------------------------------------- function initAfterHot() for _,outConf in pairs(OutExcel) do outConf.totalWeight = 0 for _,v in ipairs(outConf.out) do outConf.totalWeight = outConf.totalWeight + v[2] end end end -- 优先使用皮肤的技能,新版本没有默认返回false function setSkill(human,heroInd,heroConf,obj) return false --[[if not human then return end if not human.db.skinBag then --假人 return end local bagDB = getBag(human) local skinSkillID = human.heroSkin[heroInd] and human.heroSkin[heroInd][2] if not skinSkillID then return end local skillConf = SkillExcel[skinSkillID] Skill.setSkill(obj, heroConfig,skillConf) BeSkill.setBeSkill(obj,heroConf,skillConf) return true]] end function checkHeroSkin(human, heroInd) if not heroInd then return end if not human or not human.db or not human.db.heroBag then return end local heroId = HeroLogic.getHeroIdByIndex(human,heroInd) local heroGrid = HeroLogic.getHeroGrid(human,heroId,heroInd) if heroGrid.skinOn then return heroGrid.skinOn,true end --[[if not human.db.skinBag then return end local bagDB = getBag(human) if human.heroSkin[heroInd] then local skinInd = human.heroSkin[heroInd][1] local skinID = bagDB[skinInd].id --local skillID = human.heroSkin[heroInd][2] return skinID,true else return end]] end -- 检查是否有皮肤body function getBody(human,heroInd) local heroId = HeroLogic.getHeroIdByIndex(human,heroInd) local heroGrid = HeroLogic.getHeroGrid(human,heroId,heroInd) local skinId = heroGrid.skinOn if not skinId then return end return SkinExcel[skinId].body,SkinExcel[skinId].head --[[if not human.db.skinBag then return end local bagDB = getBag(human) if human.heroSkin[heroInd] then local skinInd = human.heroSkin[heroInd][1] local skinID = bagDB[skinInd].id return SkinExcel[skinID].body,SkinExcel[skinID].head end]] end function getHeroSkin(human,heroInd) local heroId = HeroLogic.getHeroIdByIndex(human,heroInd) local heroGrid = HeroLogic.getHeroGrid(human,heroId,heroInd) local skinId = heroGrid.skinOn if not skinId then return end return SkillExcel[skinId] --[=[if not human or not human.db.skinBag then return end local bagDB = getBag(human) if human.heroSkin[heroInd] then local skinInd = human.heroSkin[heroInd][1] local skinID = bagDB[skinInd].id local skinConf = SkinExcel[skinID] local skillConf = SkillExcel[human.heroSkin[heroInd][2]] return skinConf,skillConf end]=] end -------------------------- protocol -------------------------- -- 皮肤信息查询 function skinQuery(human) local msgRet = Msg.gc.GC_SKIN_BAG local data = skinListQuery(human) local maxLen = #msgRet.list -- 每次最多只能传30个 local cnt = 0 for id in pairs(SkinExcel) do cnt = cnt + 1 if data[id] then msgRet.list[cnt].ind = data[id].idx msgRet.list[cnt].isOn = data[id].state end skinNetGen(human,msgRet.list[cnt].data,id) if cnt >= maxLen then msgRet.list[0] = maxLen cnt = 0 msgRet.isEnd = 1 Msg.send(msgRet,human.fd) end end msgRet.list[0] = cnt msgRet.isEnd = 2 Msg.send(msgRet,human.fd) end -- 皮肤穿戴功能 function skinOp(human,heroIdx,skinIdx) if skinIdx == 0 then return skinOff(human,heroIdx) end return skinOn(human,skinIdx,heroIdx) end -- 皮肤解锁 function skinUnlock(human,id) local skinCfg = assert(SkinExcel[id],"invalid skinId is ",id) local isUnlock = false for _,skin in pairs(human.db.skinBag) do if skin.id == id then isUnlock =true break end end -- 皮肤已经解锁 if isUnlock then -- 发放皮肤重复物品 local itemList = {} for _,item in pairs(skinCfg.repeated) do itemList[#itemList+1] = { item[1],item[2] } end return BagLogic.addItemList(human,itemList,"skin") end local now = os.time() human.db.skinBag[#human.db.skinBag + 1] = { id = id, ttl = -1, state = 0, getTime = now, } RoleHeadLogic.active(human, RoleHeadLogic.HEAD_TYPE_1, skinCfg.head) -- 所有角色属性提升 -- 回复给客户端 local msgRet = Msg.gc.GC_SKIN_UPDATE local data = msgRet.list[1].data data.ind = id data.isOn = 0 skinNetGen(human,data.data,id) msgRet.list[1].op = 1 msgRet.list[0] = 1 Msg.send(msgRet,human.fd) end -- 计算皮肤属性 function doCalcSkinHero(human,attrs) local skinBag = human.db.skinBag local attrMap = {} for id in pairs(skinBag) do local skinCfg = SkinExcel[id] for _,attr in pairs(skinCfg.attrs) do attrMap[attr[1]] = attrMap[attr[1]] or 0 attrMap[attr[1]] = attrMap[attr[1]] + attr[2] end end for attr,cnt in pairs(attrMap) do RoleAttr.updateValue(attr,cnt, attrs) end end