| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678 |
- 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
- 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
- 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
- local function fontSkinNet(data,id)
- if not id or id == 0 then
- data.id = 0
- data.name = ""
- data.desc = ""
- data.head = 0
- data.body = ""
- data.icon = 0
- data.camp = 0
- data.order = 0
- data.type = 0
- data.upID = 0
- data.attrs[0] = 0
- data.fenjie[0] = 0
- data.upAddExp = 0
- data.upNeedExp = 0
- data.ronghe = 0
- data.heroName = ""
- data.quality = 0
- else
- local conf = SkinExcel[id]
- data.id = id
- data.name = conf.name
- data.desc = conf.desc
- data.head = conf.head
- data.body = conf.body
- data.icon = conf.icon
- data.camp = conf.camp
- data.order = conf.order
- data.type = conf.type
- data.upID = conf.upID
- local len = 0
- for k,v in ipairs(conf.attrs) do
- len = len + 1
- data.attrs[len].key = v[1]
- data.attrs[len].value = v[2]
- end
- data.attrs[0] = len
- len = 0
- for k,v in ipairs(conf.fenjie) do
- len = len + 1
- Grid.makeItem(data.fenjie[len],v[1],v[2])
- end
- data.fenjie[0] = len
- data.upAddExp = conf.upAddExp
- data.upNeedExp = conf.upNeedExp
- data.ronghe = conf.ronghe
- data.heroName = HeroExcel[conf.id] and HeroExcel[conf.id].name or ""
- data.quality = conf.quality
- end
- end
- local function fontBagNet(net,human,ind)
- net.ind = ind or 0
- if human.db.skinBag[ind] then
- net.isOn = human.db.skinBag[ind].heroInd and 1 or 0
- fontSkinNet(net.data,human.db.skinBag[ind].id)
- else
- net.isOn = 0
- fontSkinNet(net.data)
- end
- end
- function bag(human)
- local bagDB = getBag(human)
- local msgRet = Msg.gc.GC_SKIN_BAG
- local len = 0
- msgRet.isEnd = 1
- for k in pairs(human.skinBag) do
- len = len + 1
- local net = msgRet.list[len]
- fontBagNet(net,human,k)
- if len >=30 then
- msgRet.list[0] = 30
- Msg.send(msgRet,human.fd)
- len = 0
- msgRet.isEnd = 2
- end
- end
- msgRet.isEnd = 3
- msgRet.list[0] = len
- Msg.send(msgRet,human.fd)
- end
- OP_ADD = 1
- OP_UPDATE = 2
- OP_DEL = 3
- function sendChange(human,changeList)
- if #changeList == 0 then
- return
- end
- table.sort(changeList,function(a,b)
- return a[2] > b[2]
- end)
- local msgRet = Msg.gc.GC_SKIN_UPDATE
- local len = 0
- for _,v in ipairs(changeList) do
- len = len + 1
- local net = msgRet.list[len]
- net.op = v[2]
- fontBagNet(net.data,human,v[1])
- if len >= 30 then
- break
- end
- end
- msgRet.list[0] = len
- Msg.send(msgRet,human.fd)
- end
- function onAddSkin(human,id,list)
- local ind
- for i = 1,human.db.skinBag[0] do
- if not human.db.skinBag[i] then
- ind = i
- break
- end
- end
- local skinConf = SkinExcel[id]
- if ind and skinConf then
- human.db.skinBag[ind] = {id = id}
- human.skinBag = nil
- list[#list + 1] = {ind,OP_ADD}
- RoleHeadLogic.active(human, RoleHeadLogic.HEAD_TYPE_1, skinConf.head)
- return ind
- end
- end
- function onDelSkin(human,ind,list)
- if human.db.skinBag[ind] then
- human.db.skinBag[ind] = nil
- human.skinBag = nil
- list[#list + 1] = {ind,OP_DEL}
- return ind
- end
- end
- function checkDel(human,list)
- if #list == 0 then
- return Broadcast.sendErr(human, "empty checkDel:"..Lang.SKIN_PARAM_ERR)
- end
- local bagDB = getBag(human)
- for _,v in ipairs(list) do
- if not bagDB[v] then
- return Broadcast.sendErr(human, Lang.SKIN_NO_HAS)
- elseif bagDB[v].heroInd then
- return Broadcast.sendErr(human, Lang.SKIN_IS_ON)
- end
- end
- return true
- end
- function delSkin(human,delList,changeList)
- if checkDel(human,delList) then
- for _,v in ipairs(delList) do
- onDelSkin(human,v,changeList)
- end
- return true
- end
- end
- function addSkin(human,id,cnt)
- if not SkinExcel[id] then
- return
- end
- cnt = cnt or 1
- local changeList = {}
- for i = 1,cnt do
- onAddSkin(human,id,changeList)
- end
- sendChange(human,changeList)
- human.db.skinLog[id] = 1
- end
- function fenjie(human,ind)
- local bagDB = getBag(human)
- if not bagDB[ind] then
- return
- end
- local id = bagDB[ind].id
- local conf = SkinExcel[id]
- if not conf.fenjie[1] then
- return
- end
- local changeList = {}
- if not delSkin(human,{ind},changeList) then
- return
- end
- for k,v in ipairs(conf.fenjie) do
- BagLogic.addItem(human, v[1], v[2], "skin")
- end
- sendChange(human,changeList)
- local msgRet = Msg.gc.GC_SKIN_FENJIE
- msgRet.ind = ind
- Msg.send(msgRet,human.fd)
- end
- function upQuery(human,ind,nosend)
- local bagDB = getBag(human)
- if not bagDB[ind] then
- return
- end
- if type(bagDB[ind]) == "number" then
- if nosend then
- Broadcast.sendErr(human, ind..":upQuery:"..Lang.SKIN_PARAM_ERR)
- end
- return
- end
- local id = bagDB[ind].id
- local conf = SkinExcel[id]
- local upConf = SkinExcel[conf.upID]
- if not (upConf and conf.upNeedExp > 0) then
- if not nosend then
- Broadcast.sendErr(human, id..":upQuery:"..Lang.SKIN_CONF_ERR)
- end
- return
- end
- local msgRet = Msg.gc.GC_SKIN_UP_QUERY
- msgRet.ind = ind
- fontSkinNet(msgRet.nowData,id)
- fontSkinNet(msgRet.upData,conf.upID)
- msgRet.maxExp = conf.upNeedExp
- msgRet.nowExp = bagDB[ind].exp or 0
- Msg.send(msgRet,human.fd)
- end
- function up(human,ind,list)
- local bagDB = getBag(human)
- if not bagDB[ind] then
- return
- end
- local id = bagDB[ind].id
- local conf = SkinExcel[id]
- local upConf = SkinExcel[conf.upID]
- if not (upConf and conf.upNeedExp > 0) then
- return Broadcast.sendErr(human, id..":up:"..Lang.SKIN_CONF_ERR)
- end
- local addExp = 0
- for _,v in ipairs(list) do
- if not bagDB[v] then--皮肤不存在
- return Broadcast.sendErr(human, v..":up1:"..Lang.SKIN_PARAM_ERR)
- elseif bagDB[v].heroInd then--被使用
- return Broadcast.sendErr(human, v..":up2:"..Lang.SKIN_PARAM_ERR)
- elseif v == ind then--升级目标和升级皮肤一样
- return Broadcast.sendErr(human, v..":up3:"..Lang.SKIN_PARAM_ERR)
- end
- local costID = bagDB[v].id
- local costConf = SkinExcel[costID]
- if not (costConf and costConf.upAddExp > 0) then
- return Broadcast.sendErr(human, costID..":up3:"..Lang.SKIN_PARAM_ERR)
- else
- addExp = addExp + costConf.upAddExp
- end
- end
- if addExp == 0 then
- return Broadcast.sendErr(human, #list..":up3:"..Lang.SKIN_PARAM_ERR)
- end
- local nowExp = bagDB[ind].exp or 0
- nowExp = nowExp + addExp
- if nowExp > conf.upNeedExp then
- return
- end
- local heroInd = bagDB[ind].heroInd
- local isUp = false
- local changeList = {}
- for _,v in ipairs(list) do
- onDelSkin(human,v,changeList)
- end
- if nowExp == conf.upNeedExp then
- onDelSkin(human,ind,changeList)
- ind = onAddSkin(human,conf.upID,changeList)
- bagDB[ind].exp = nowExp - conf.upNeedExp
- id = conf.upID
- conf = SkinExcel[id]
- upConf = conf.upID and SkinExcel[conf.upID]
- isUp = true
- else
- bagDB[ind].exp = nowExp
- end
- sendChange(human,changeList)
- local msgRet = Msg.gc.GC_SKIN_UP
- msgRet.ind = ind
- fontSkinNet(msgRet.nowData,id)
- fontSkinNet(msgRet.upData,conf.upID)
- msgRet.maxExp = conf.upNeedExp
- msgRet.nowExp = bagDB[ind].exp or 0
- Msg.send(msgRet,human.fd)
-
- upQuery(human,ind,true)
- if isUp and heroInd then
- skinOn(human,heroInd,ind)
- end
- end
- function fontPreviewNet(net,id,weight)
- net.weight = weight
- fontSkinNet(net.data,id)
- end
- function suipianPreview(human,id)
- local itemConf = ItemExcel[id]
- if not (itemConf and itemConf.type == ItemDefine.ITEM_SUBTYPE_SUIPIAN_SKIN) then
- return Broadcast.sendErr(human, id..":suipianPreview:"..Lang.SKIN_PARAM_ERR)
- end
- local msgRet = Msg.gc.GC_SKIN_SUIPIAN_PREVIEW
- msgRet.id = id
- local len = 0
- if itemConf.get[1] == 1 then
- len = len + 1
- fontPreviewNet(msgRet.list[len],itemConf.get[3],10000)
- else
- for _,v in ipairs(OutExcel[itemConf.get[3]].out) do
- len = len + 1
- local weight = math.floor(10000*v[2]/OutExcel[itemConf.get[3]].totalWeight)
- fontPreviewNet(msgRet.list[len],v[1],v[2])
- end
- end
- msgRet.list[0] = len
- Msg.send(msgRet,human.fd)
- end
- SUIPIAN_CNT = 10
- function suipian(human,id,cnt)
- local itemConf = ItemExcel[id]
-
- if cnt > SUIPIAN_CNT then
- return Broadcast.sendErr(human, Util.format(Lang.SKIN_SUIPIAN_LIMIT,SUIPIAN_CNT))
- end
- if not (itemConf and itemConf.type == ItemDefine.ITEM_SUBTYPE_SUIPIAN_SKIN) then
- return Broadcast.sendErr(human, id..":suipian:"..Lang.SKIN_PARAM_ERR)
- end
- if BagLogic.getItemCnt(human,id) < itemConf.fullCnt * cnt then
- return Broadcast.sendErr(human, Util.format(Lang.COMMON_NO_ITEM,itemConf.name))
- end
- local skinIDList = {}
- for i = 1,cnt do
- if itemConf.get[1] == 1 then
- skinIDList[#skinIDList + 1] = itemConf.get[3]
- else
- local outConf = OutExcel[itemConf.get[3]]
- local r = math.random(1,outConf.totalWeight)
- for _,v in ipairs(outConf.out) do
- if r <= v[2] then
- skinIDList[#skinIDList + 1] = v[1]
- break
- else
- r = r - v[2]
- end
- end
- end
- end
- if #skinIDList == 0 then
- return Broadcast.sendErr(human, id..":suipian:"..Lang.SKIN_CONF_ERR)
- end
- BagLogic.delItem(human, id, itemConf.fullCnt * cnt, "skin")
- local msgRet = Msg.gc.GC_SKIN_SUIPIAN
- msgRet.id = id
- local len = 0
- local changeList = {}
- for _,skinID in ipairs(skinIDList) do
- len = len + 1
- onAddSkin(human,skinID,changeList)
- fontSkinNet(msgRet.out[len],skinID)
- end
- msgRet.out[0] = len
- sendChange(human,changeList)
- Msg.send(msgRet,human.fd)
- end
- RONGHE_ID = 1
- RONGHE_CNT = 5
- function ronghePreview(human)
- local outConf = OutExcel[RONGHE_ID]
- local msgRet = Msg.gc.GC_SKIN_RONGHE_PREVIEW
- local len = 0
- for _,v in ipairs(outConf.out) do
- len = len + 1
- local weight = math.floor(10000*v[2]/outConf.totalWeight)
- fontPreviewNet(msgRet.list[len],v[1],weight)
- end
- msgRet.list[0] = len
- Msg.send(msgRet,human.fd)
- end
- function ronghe(human,list)
- if #list ~= RONGHE_CNT then
- return Broadcast.sendErr(human, #list..":ronghe1:"..Lang.SKIN_PARAM_ERR)
- end
- local bagDB = getBag(human)
- for k,v in ipairs(list) do
- local costID = bagDB[v] and bagDB[v].id or 0
- local costConf = SkinExcel[costID]
- if not (costConf and costConf.ronghe == 1) then
- return Broadcast.sendErr(human, v..":"..costID..":ronghe2:"..Lang.SKIN_PARAM_ERR)
- end
- end
- local outConf = OutExcel[RONGHE_ID]
- local r = math.random(1,outConf.totalWeight)
- local skinID = outConf.out[1][1]
- for _,v in ipairs(outConf.out) do
- if r <= v[2] then
- skinID = v[1]
- break
- else
- r = r - v[2]
- end
- end
- local changeList = {}
- if not delSkin(human,list,changeList) then
- return
- end
- onAddSkin(human,skinID,changeList)
- sendChange(human,changeList)
- local msgRet = Msg.gc.GC_SKIN_RONGHE
- msgRet.id = id
- fontSkinNet(msgRet.out,skinID)
- Msg.send(msgRet,human.fd)
- end
- function heroSkin(human,heroInd)
- local bagDB = getBag(human)
- local heroGrid = human.db.heroBag[heroInd]
- local heroID = heroGrid.id
- local heroConf = HeroExcel[heroID]
- local heroSkinInd = human.heroSkin[heroInd] and human.heroSkin[heroInd][1]
- local heroSkinID = heroSkinInd and bagDB[heroSkinInd].id
- local msgRet = Msg.gc.GC_SKIN_HERO
- local len = 0
- for _,v in ipairs(heroConf.skin) do
- len = len + 1
- local net = msgRet.list[len]
- fontSkinNet(net.data,v[1])
- if heroSkinID == v[1] then
- net.ind = heroSkinInd
- net.isOn = 1
- elseif human.hasSkin[v[1]] then
- net.isOn = 1
- net.ind = 0
- for v1 in pairs(human.hasSkin[v[1]]) do
- if not bagDB[v1].heroInd then
- net.ind = v1
- net.isOn = 0
- break
- end
- end
- else
- net.ind = 0
- net.isOn = 0
- end
- end
- msgRet.list[0] = len
- Msg.send(msgRet,human.fd)
- end
- function skinOn(human,heroInd,skinInd)
- local bagDB = getBag(human)
- if not (skinInd == 0 or bagDB[skinInd]) then
- return Broadcast.sendErr(human, skinInd..":skinOn:"..Lang.SKIN_PARAM_ERR)
- end
- local heroGrid = human.db.heroBag[heroInd]
- local heroID = heroGrid.id
- local heroConf = HeroExcel[heroID]
- if skinInd > 0 then
- local skinID = skinInd > 0 and bagDB[skinInd].id
- if bagDB[skinInd].heroInd then
- return Broadcast.sendErr(human, Lang.SKIN_DOUBLE_ON)
- end
- if bagDB[skinInd].heroInd == heroInd then
- return
- end
- isHeroSkin = false
- for k,v in ipairs(heroConf.skin) do
- if v[1] == skinID then
- isHeroSkin = true
- break
- end
- end
- if not isHeroSkin then
- return Broadcast.sendErr(human, Lang.SKIN_NO_HERO)
- end
- end
-
- local changeInd
- for k in pairs(human.skinBag) do
- if bagDB[k].heroInd == heroInd then
- bagDB[k].heroInd = nil
- changeInd = k
- end
- end
- if skinInd > 0 then
- bagDB[skinInd].heroInd = heroInd
- changeInd = skinInd
- end
-
- human.heroSkin = nil
- heroSkin(human,heroInd)
- local msgRet = Msg.gc.GC_SKIN_ON
- msgRet.heroInd = heroInd
- msgRet.skinInd = skinInd
- Msg.send(msgRet,human.fd)
- HeroLogic.sendHeroBagDynamic(human,heroID,heroInd)
- if changeInd then
- sendChange(human,{{changeInd,OP_UPDATE}})
- end
- end
- function book(human)
- local msgRet = Msg.gc.GC_SKIN_BOOK
- local len = 0
- msgRet.isEnd = 1
- for k,v in pairs(SkinExcel) do
- if v.tujian == 1 then
- len = len + 1
- local net = msgRet.list[len]
- net.ind = human.db.skinLog[k] and 1 or 0
- net.isOn = 0
- fontSkinNet(net.data,k)
- if len >=30 then
- msgRet.list[0] = 30
- Msg.send(msgRet,human.fd)
- len = 0
- msgRet.isEnd = 2
- end
- end
- end
- msgRet.isEnd = 3
- msgRet.list[0] = len
- Msg.send(msgRet,human.fd)
- end
- function setSkill(human,heroInd,heroConf,obj)
- 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 then return 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,skillID
- else
- return
- end
-
- end
- function getBody(human,heroInd)
- 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)
- 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
- function onDelHero(human,heroInd)
- local bagDB = getBag(human)
- if human.heroSkin[heroInd] then
- skinOn(human,heroInd,0)
- end
- end
|