| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993 |
- -- 英雄装备相关逻辑
- local Lang = require("common.Lang")
- local HeroExcel = require("excel.hero")
- local EquipExcel = require("excel.equip")
- local Msg = require("core.Msg")
- local ObjHuman = require("core.ObjHuman")
- local HeroDefine = require("hero.HeroDefine")
- local HeroLogic = require("hero.HeroLogic")
- local ItemDefine = require("bag.ItemDefine")
- local Grid = require("bag.Grid")
- local BagLogic = require("bag.BagLogic")
- local Broadcast = require("broadcast.Broadcast")
- local RoleAttr = require("role.RoleAttr")
- local Util = require("common.Util")
- local ItemExcel = require("excel.item").item
- local FuwenLogic = require("fuwen.FuwenLogic")
- local EquipLogic = require("equip.EquipLogic")
- local HeroGem = require("hero.HeroGem")
- function query(human, heroID, heroIndex)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if heroGrid == nil then
- return
- end
- local msgRet = Msg.gc.GC_HERO_EQUIP_QUERY
- msgRet.id = heroID
- msgRet.index = heroIndex
- --宝石套装加成
- local suitBonusTbl = HeroGem.suitAttrBonus(heroGrid)
-
- local cnt = 0
- for i = 1, ItemDefine.EQUIP_MAX_CNT do
- local equipGrid = heroGrid.equip and heroGrid.equip[i]
- if equipGrid then
- cnt = cnt + 1
- if i == ItemDefine.EQUIP_SUBTYPE_SHUIJIN then -- 水晶比较特殊
- Grid.makeItem(msgRet.equips[cnt], equipGrid.id, 1, heroGrid.shuijingAttrID)
- else
- Grid.makeItem(msgRet.equips[cnt], equipGrid.id, 1, nil, equipGrid, -1, Grid.getOpflagAtBag(heroGrid.equip[i].id),nil,suitBonusTbl)
- end
- end
- local dot = isEquipDotByPos(human, heroGrid, i)
- msgRet.equipDot[i] = dot or 0
- end
- msgRet.equipDot[0] = ItemDefine.EQUIP_MAX_CNT
- msgRet.equips[0] = cnt
- cnt = 0
- for i = 1, 2 do
- -- 尝试解锁符文
- FuwenLogic.fuwenGridUnlock(human, heroID, heroIndex, i)
- if heroGrid.fuwen and
- heroGrid.fuwen[i] and
- heroGrid.fuwen[i].id ~= nil then
- cnt = cnt + 1
- msgRet.fuwens[cnt].pos = i
- Grid.makeItem(msgRet.fuwens[cnt].fuwen, heroGrid.fuwen[i].id, 1,nil,heroGrid.fuwen[i],-1, Grid.getOpflagAtBag(heroGrid.fuwen[i].id))
- end
- msgRet.fuwenGrid[i] = 1
- if heroGrid.fuwen == nil or
- heroGrid.fuwen[i] == nil then
- msgRet.fuwenGrid[i] = 0
- end
- local dot = FuwenLogic.isFuwenDotByPos(human, heroGrid, i) == true and 1 or 0
- msgRet.fuwenDot[i] = dot
- end
- msgRet.fuwenGrid[0] = 2
- msgRet.fuwenDot[0] = 2
- msgRet.fuwens[0] = cnt
- Msg.send(msgRet, human.fd)
- end
- function putOn(human, heroID, heroIndex, bagIndex, noCalc)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if heroGrid == nil then return end
- if bagIndex == 0 then return end
- local equipGrid = human.db.equipBag[bagIndex]
- if not equipGrid or type(equipGrid) ~= "table" then return end
- local equipID = equipGrid.id
- local equipConfig = EquipExcel.equip[equipID]
- if equipConfig == nil then return end
- if heroGrid.star < equipConfig.star then
- local errDesc = Util.format(Lang.EQUIP_PUT_ON_STAR_ERR, equipConfig.star)
- return Broadcast.sendErr(human, errDesc)
- end
-
- local pos = equipConfig.subType
- if pos == ItemDefine.EQUIP_SUBTYPE_SHUIJIN then return end
- local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
- msgRet.heroID = heroID
- msgRet.heroIndex = heroIndex
- --获取宝石加成
- local suitBonusTbl = HeroGem.suitAttrBonus(heroGrid)
- Grid.makeItem(msgRet.equip, equipID, 1, nil, equipGrid, bagIndex, Grid.getOpflagAtBag(equipID), nil, suitBonusTbl)
- if heroGrid.equip == nil or
- heroGrid.equip[pos] == nil then
- heroGrid.equip = heroGrid.equip or { }
- heroGrid.equip[pos] = equipGrid
- -- 穿戴者
- equipGrid.putUuid = heroGrid.uuid
- -- 新穿装备
- EquipLogic.delEquip(human, bagIndex, "equip_puton")
- else
- -- 同一件装备
- if heroGrid.equip[pos].uuid == equipGrid.uuid then
- return Msg.send(msgRet, human.fd)
- end
- -- 替换装备
- EquipLogic.delEquip(human, bagIndex, "equip_puton")
- local unEquipGrid = heroGrid.equip[pos]
- unEquipGrid.putUuid = nil
- EquipLogic.addByEquipGrid(human, unEquipGrid, "equip_puton", true)
- heroGrid.equip[pos] = equipGrid
- equipGrid.putUuid = heroGrid.uuid
- end
- if noCalc ~= true then
- -- 计算属性
- ObjHuman.doCalcHero(human, heroIndex)
- HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
- HeroLogic.refreshDot(human, heroGrid.uuid)
- end
- -- 通知客户端
- Msg.send(msgRet, human.fd)
- end
- --
- function putOnHero(human, heroID, heroIndex, putHeroID, putHeroIndex, putHeroPos)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if heroGrid == nil then return end
- local putHeroGrid = HeroLogic.getHeroGrid(human, putHeroID, putHeroIndex)
- if putHeroGrid == nil then return end
- -- 同一个英雄
- if heroGrid.uuid == putHeroGrid.uuid then return end
- -- 部位有没有装备
- if putHeroGrid.equip == nil then return end
- local putEquipGrid = putHeroGrid.equip[putHeroPos]
- if not putEquipGrid then return end
- local equipID = putEquipGrid.id
- local equipConfig = EquipExcel.equip[equipID]
- if equipConfig == nil then return end
- if heroGrid.star < equipConfig.star then
- local errDesc = Util.format(Lang.EQUIP_PUT_ON_STAR_ERR, equipConfig.star)
- return Broadcast.sendErr(human, errDesc)
- end
- local pos = equipConfig.subType
- if pos == ItemDefine.EQUIP_SUBTYPE_SHUIJIN then return end
- if heroGrid.equip == nil or
- heroGrid.equip[pos] == nil then
- heroGrid.equip = heroGrid.equip or { }
- -- 穿戴者
- heroGrid.equip[pos] = putEquipGrid
- putEquipGrid.putUuid = heroGrid.uuid
- else
- -- 同一件装备
- if heroGrid.equip[pos].uuid == putHeroGrid.uuid then
- return Msg.send(msgRet, human.fd)
- end
- --放入到背包
- local unEquipGrid = heroGrid.equip[pos]
- unEquipGrid.putUuid = nil
- EquipLogic.addByEquipGrid(human, unEquipGrid, "equip_puton", true)
-
- -- 设置新装备
- heroGrid.equip[pos] = putEquipGrid
- putEquipGrid.putUuid = heroGrid.uuid
- end
- -- 老英雄脱去此装备
- putHeroGrid.equip[putHeroPos] = nil
- -- 计算属性
- ObjHuman.doCalcHero(human, heroIndex)
- HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
- HeroLogic.refreshDot(human, heroGrid.uuid)
- ObjHuman.doCalcHero(human, putHeroIndex)
- HeroLogic.sendHeroBagDynamic(human, putHeroID, putHeroIndex)
- HeroLogic.refreshDot(human, putHeroGrid.uuid)
- -- 通知客户端
- local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
- msgRet.heroID = heroID
- msgRet.heroIndex = heroIndex
-
- --获取宝石加成
- local suitBonusTbl = HeroGem.suitAttrBonus(heroGrid)
- Grid.makeItem(msgRet.equip, equipID, 1, nil, equipGrid, bagIndex, Grid.getOpflagAtBag(equipID), nil, suitBonusTbl)
-
- --Grid.makeItem(msgRet.equip, equipID, 1, nil, equipGrid, 0, Grid.getOpflagAtBag(equipID))
- Msg.send(msgRet, human.fd)
- end
- function putOff(human, heroID, heroIndex, pos, noCalc, noSend)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if heroGrid == nil then
- return
- end
-
- if pos == ItemDefine.EQUIP_SUBTYPE_SHUIJIN then return end
- if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
- return
- end
- -- 判断背包空间
- if not EquipLogic.checkEmptyCnt(human, 1) then
- return
- end
- -- 改db
- local equipGrid = heroGrid.equip[pos]
- heroGrid.equip[pos] = nil
- equipGrid.putUuid = nil
- EquipLogic.addByEquipGrid(human, equipGrid, "equip_putoff", true)
- if noCalc ~= true then
- -- 计算属性
- ObjHuman.doCalcHero(human,heroIndex)
- HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
- HeroLogic.refreshDot(human, heroGrid.uuid)
- end
-
- if not noSend then
- -- 通知客户端
- local msgRet = Msg.gc.GC_HERO_EQUIP_PUTOFF
- msgRet.heroID = heroID
- msgRet.heroIndex = heroIndex
- msgRet.pos = pos
- Msg.send(msgRet, human.fd)
- end
- end
- -- 一键穿装
- function putOnQuick(human, heroID, heroIndex, equipID1, equipID2, equipID3, equipID4, equipID5, equipID6)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if heroGrid == nil then
- return
- end
- putOn(human, heroID, heroIndex, equipID1, true)
- putOn(human, heroID, heroIndex, equipID2, true)
- putOn(human, heroID, heroIndex, equipID3, true)
- putOn(human, heroID, heroIndex, equipID4, true)
- putOn(human, heroID, heroIndex, equipID5, true)
- putOn(human, heroID, heroIndex, equipID6, true)
- ObjHuman.doCalcHero(human,heroIndex)
- HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
- HeroLogic.refreshDot(human, heroGrid.uuid)
- end
- -- 一键脱装
- function putOffQuick(human, heroID, heroIndex, noSendDy)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if heroGrid == nil then
- return
- end
- putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_WEAPON, true)
- putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_CLOTH, true)
- putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_SHOES, true)
- putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_SHIPIN, true)
- -- putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_SHENQI, true)
- putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_RING, true)
- putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_AMULET, true)
-
- if not noSendDy then
- ObjHuman.doCalcHero(human,heroIndex)
- HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
- end
- end
- function doCalcHero(obj,attrs)
- local equip = obj.equip
- if not equip then return end
-
- local suitBonusTbl = HeroGem.suitAttrBonus(obj)
- local mathFloor = math.floor
- local equipSuitCntTable = nil
- for i = 1,ItemDefine.EQUIP_MAX_CNT do
- local equipGrid = equip[i]
- if equipGrid then
- local equipID = equipGrid.id
- local equipConfig = EquipExcel.equip[equipID]
- local baseRate = EquipLogic.getEquipBaseRate(equipGrid.quality)
- local succinctRate = baseRate
- -- 水晶
- if equipConfig.subType == ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
- for _,v in ipairs(EquipExcel.shuijingAttr[obj.shuijingAttrID].attr) do
- RoleAttr.updateValue(v[1],v[2],attrs)
- end
- else
- local baseAttrs = equipConfig.base
- -- 戒指、护符
- if equipConfig.subType == ItemDefine.EQUIP_SUBTYPE_RING or equipConfig.subType == ItemDefine.EQUIP_SUBTYPE_AMULET then
- baseRate = 1
- baseAttrs = equipGrid.baseAttr
- -- 特效
- for effectId in pairs(equipGrid.effectList) do
- local effectAttrs = EquipExcel.texiao[effectId].attrs
- RoleAttr.updateValue(effectAttrs[1][1], effectAttrs[1][2], attrs)
- end
- -- 英雄专属
- if equipGrid.exclusiveHeroId and obj.id == equipGrid.exclusiveHeroId then
- baseRate = 2
- end
- end
- --装备基础属性
- for _,v in ipairs(baseAttrs) do
- if equipConfig.subType == ItemDefine.EQUIP_SUBTYPE_RING or equipConfig.subType == ItemDefine.EQUIP_SUBTYPE_AMULET then
- local val = mathFloor(v[2] * baseRate * (1 + (suitBonusTbl and suitBonusTbl.sp_base or 0)) * (equipGrid.baseRandVal or 1) )
- RoleAttr.updateValue(v[1], val ,attrs)
- else
- local val = mathFloor(v[2] * baseRate * (1 + (suitBonusTbl and suitBonusTbl.base or 0)) * (equipGrid.baseRandVal or 1) )
- RoleAttr.updateValue(v[1], val, attrs)
- end
- end
- -- 洗练属性
- -- for key, value in pairs(equipGrid.attr) do
- -- RoleAttr.updateValue(key, mathFloor(value * baseRate) ,attrs)
- -- end
- for _, attrData in ipairs(equipGrid.attr) do
- RoleAttr.updateValue(attrData[1], mathFloor(attrData[2] * succinctRate) ,attrs)
- end
-
- local heroID = obj.id
- local heroConfig = HeroExcel.hero[heroID]
- if equipConfig.camp == heroConfig.camp then
- -- 阵营专属属性
- for _,v in ipairs(equipConfig.campAttr) do
- RoleAttr.updateValue(v[1],v[2],attrs)
- end
- end
-
- if equipConfig.job == heroConfig.job then
- -- 职业专属属性
- for _,v in ipairs(equipConfig.jobAttr) do
- RoleAttr.updateValue(v[1],v[2],attrs)
- end
- end
-
- if equipConfig.suit ~= 0 then
- equipSuitCntTable = equipSuitCntTable or {}
- equipSuitCntTable[equipConfig.suit] = equipSuitCntTable[equipConfig.suit] or {cnt = 0}
- equipSuitCntTable[equipConfig.suit].equipID = equipID
- equipSuitCntTable[equipConfig.suit].cnt = equipSuitCntTable[equipConfig.suit].cnt + 1
- -- 是否是戒指, 护符
- equipSuitCntTable[equipConfig.suit].isSpEquip = 0
- if equipConfig.subType == ItemDefine.EQUIP_SUBTYPE_RING or equipConfig.subType == ItemDefine.EQUIP_SUBTYPE_AMULET then
- equipSuitCntTable[equipConfig.suit].isSpEquip = 1
- end
- end
- end
- end
- end
-
- -- 套装属性
- if equipSuitCntTable then
- for k, v in pairs(equipSuitCntTable) do
- if v.cnt > 1 then
- local equipIDTemp = v.equipID
- local equipConfigTemp = EquipExcel.equip[equipIDTemp]
- for i = 1, #equipConfigTemp.suitIm do
- local keyTemp = equipConfigTemp.suitIm[i][1]
- local valTemp = equipConfigTemp.suitIm[i][2]
- if v.cnt > i then
- -- 普通套装
- if v.isSpEquip ~= 1 and (suitBonusTbl and suitBonusTbl[i+1]) then
- --这里i+1的原因是,装备套装属性配置suitIm中, idx为1的value是2件套加成, idx为2的是3件套加成,以此类推
- valTemp = valTemp + (suitBonusTbl[i+1] * 10000) --宝石对套装的加成
- end
- -- 戒指,护符套装
- if v.isSpEquip == 1 and (suitBonusTbl and suitBonusTbl.sp_suit) then
- valTemp = valTemp + (suitBonusTbl.sp_suit * 10000)
- end
- RoleAttr.updateValue(keyTemp,valTemp,attrs)
- end
- end
- end
- end
- end
- end
- -- 激活水晶
- function jihuoShuijing(human, heroID, heroIndex)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if heroGrid == nil then
- return
- end
-
- if heroGrid.lv < HeroDefine.JIHUO_SHUIJING_NEEDLV then
- return
- end
-
- local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
- if heroGrid.equip ~= nil and heroGrid.equip[pos] then
- return
- end
-
- --存db
- local equipID = HeroDefine.DEFAULT_SHUIJING_GET -- todo 20011
- local equipConfig = EquipExcel.equip[equipID]
- if not equipConfig then return end
-
- heroGrid.equip = heroGrid.equip or {}
- heroGrid.equip[pos] = equipID
-
- local randIdCnt = #equipConfig.shuijingAttrID
- local indexTemp = math.random(1,randIdCnt)
- local attrID = equipConfig.shuijingAttrID[indexTemp]
- heroGrid.shuijingAttrID = attrID
-
- -- 计算属性
- ObjHuman.doCalcHero(human,heroIndex)
- HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
-
- -- 通知客户端
- local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
- msgRet.heroID = heroID
- msgRet.heroIndex = heroIndex
- Grid.makeItem(msgRet.equip, equipID, 1, heroGrid.shuijingAttrID)
- Msg.send(msgRet, human.fd)
- end
- -- 水晶转换的信息查询
- function shuijingTransQuery(human, heroID, heroIndex)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if heroGrid == nil then
- return
- end
-
- local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
- if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
- return
- end
-
- local equipID = heroGrid.equip[pos]
- local shuijingTransConfig = EquipExcel.shuijingTransNeed[equipID]
- if not shuijingTransConfig then return end
-
- local msgRet = Msg.gc.GC_SHUIJING_TRANS_QUERY
- msgRet.heroID = heroID
- msgRet.heroIndex = heroIndex
- msgRet.needJinbi = shuijingTransConfig.money
- msgRet.needItemCnt = shuijingTransConfig.jinghua
- Msg.send(msgRet, human.fd)
- end
-
- -- 水晶转换
- function shuijingTransDo(human, heroID, heroIndex)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if heroGrid == nil then
- return
- end
-
- local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
- if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
- return
- end
-
- local equipID = heroGrid.equip[pos]
- local shuijingTransConfig = EquipExcel.shuijingTransNeed[equipID]
- if not shuijingTransConfig then return end
-
- -- 材料判断
- local needJinbi = shuijingTransConfig.money
- if human.db.jinbi < needJinbi then
- return Broadcast.sendErr(human, Lang.COMMON_NO_JINBI)
- end
-
- local needItemCnt = shuijingTransConfig.jinghua
- local nowItemCnt = BagLogic.getItemCnt(human, ItemDefine.ITEM_SHUIJING_UPLEVEL_ID)
- if nowItemCnt< needItemCnt then
- local strName = ItemDefine.getValue(ItemDefine.ITEM_SHUIJING_UPLEVEL_ID, "name")
- local strRet = Util.format(Lang.COMMON_NO_ITEM, strName)
- return Broadcast.sendErr(human, strRet)
- end
-
- -- 扣道具
- BagLogic.delItem(human, ItemDefine.ITEM_SHUIJING_UPLEVEL_ID, needItemCnt, "shuijing_change")
- ObjHuman.updateJinbi(human, -needJinbi, "shuijing_change")
-
- local msgRet = Msg.gc.GC_SHUIJING_TRANS_DO
- msgRet.heroID = heroID
- msgRet.heroIndex = heroIndex
-
- -- 存db之前,先随机获得下一个水晶的属性
- local equipConfig = EquipExcel.equip[equipID]
- if not equipConfig then return end
- local randIdCnt = #equipConfig.shuijingAttrID
- local indexTemp = math.random(1,randIdCnt)
- -- todo 单单这样子会有漏洞。。。玩家可以把水晶A洗练出的属性保存到水晶B那里,需要注意!!太忙了,之后修改
- human.tempAttrID = equipConfig.shuijingAttrID[indexTemp]
- -- 通知客户端
- Grid.makeItem(msgRet.equip, equipID, 1, human.tempAttrID)
- Msg.send(msgRet, human.fd)
- end
- -- 水晶转换保存
- function shuijingTransSave(human, heroID, heroIndex)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if heroGrid == nil then
- return
- end
-
- local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
- if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
- return
- end
-
- if human.tempAttrID == nil then
- return
- end
-
- local equipID = heroGrid.equip[pos]
-
- -- 改db
- heroGrid.shuijingAttrID = human.tempAttrID
- human.tempAttrID = nil
-
- -- 计算属性并发送
- ObjHuman.doCalcHero(human,heroIndex)
- HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
- -- 通知客户端
- local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
- msgRet.heroID = heroID
- msgRet.heroIndex = heroIndex
- Grid.makeItem(msgRet.equip, equipID, 1, heroGrid.shuijingAttrID)
- Msg.send(msgRet, human.fd)
-
- local msgRet = Msg.gc.GC_SHUIJING_TRANS_SAVE
- Msg.send(msgRet, human.fd)
- end
- -- 水晶升级查询
- function shuijingUpLvQuery(human, mainType, heroID, heroIndex)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if heroGrid == nil then
- return
- end
-
- local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
- if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
- return
- end
-
- local equipID = heroGrid.equip[pos]
- local shuijingUpNeedConfig = EquipExcel.shuijingUpNeed[equipID]
- if not shuijingUpNeedConfig then return end
-
- -- 上限判断
- local nextID = shuijingUpNeedConfig.nextID
- if nextID == 0 then return end
-
- local msgRet = Msg.gc.GC_SHUIJING_UPLV_QUERY
- msgRet.heroID = heroID
- msgRet.heroIndex = heroIndex
- msgRet.needJinbi = 0
- msgRet.needItemCnt = 0
- msgRet.needZuanshi = 0
- local nextID = shuijingUpNeedConfig.nextID
- if nextID ~= 0 then
- local tempConfig = EquipExcel.shuijingUpNeed[nextID]
- msgRet.needJinbi = tempConfig.money
- msgRet.needItemCnt = tempConfig.jinghua
- msgRet.needZuanshi = tempConfig.zuanshi
- end
-
- msgRet.equip[0] = 1
- local attrID = heroGrid.shuijingAttrID
- local tempAttrID = EquipExcel.shuijingAttr[attrID].lockNextID
- Grid.makeItem(msgRet.equip[1], nextID, 1, tempAttrID)
- Msg.send(msgRet, human.fd)
- end
- -- 水晶升级
- function shuijingUpLvDo(human, mainType, heroID, heroIndex)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if heroGrid == nil then
- return
- end
-
- local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
- if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
- return
- end
-
-
- local equipID = heroGrid.equip[pos]
- local shuijingUpNeedConfig = EquipExcel.shuijingUpNeed[equipID]
- if not shuijingUpNeedConfig then return end
-
- -- 上限判断
- local nextID = shuijingUpNeedConfig.nextID
- if nextID == 0 then return end
- local nextConfig = EquipExcel.shuijingUpNeed[nextID]
- if nextConfig == nil then return end
- -- 材料判断
- local needJinbi = nextConfig.money
- if human.db.jinbi < needJinbi then
- return Broadcast.sendErr(human, Lang.COMMON_NO_JINBI)
- end
-
- local needItemCnt = nextConfig.jinghua
- local nowItemCnt = BagLogic.getItemCnt(human, ItemDefine.ITEM_SHUIJING_UPLEVEL_ID)
- if nowItemCnt< needItemCnt then
- local strName = ItemDefine.getValue(ItemDefine.ITEM_SHUIJING_UPLEVEL_ID, "name")
- local strRet = Util.format(Lang.COMMON_NO_ITEM, strName)
- return Broadcast.sendErr(human, strRet)
- end
-
- if mainType == HeroDefine.SHUIJING_UP_LV_LOCK then
- local needZuanshi = nextConfig.zuanshi
- if not ObjHuman.checkRMB(human, needZuanshi) then
- return
- end
- end
- -- 扣道具
- BagLogic.delItem(human, ItemDefine.ITEM_SHUIJING_UPLEVEL_ID, needItemCnt, "shuijing_change")
- ObjHuman.updateJinbi(human, -needJinbi, "shuijing_change")
- if mainType == HeroDefine.SHUIJING_UP_LV_LOCK then
- local needZuanshi = shuijingUpNeedConfig.zuanshi
- ObjHuman.decZuanshi(human, -needZuanshi, "shuijing_change")
- end
- --改db
- heroGrid.equip[pos] = nextID
- if mainType == HeroDefine.SHUIJING_UP_LV_LOCK then
- local attrID = heroGrid.shuijingAttrID
- heroGrid.shuijingAttrID = EquipExcel.shuijingAttr[attrID].lockNextID
- else
- local equipConfig = EquipExcel.equip[nextID]
- if not equipConfig then return end
- local randIdCnt = #equipConfig.shuijingAttrID
- local indexTemp = math.random(1,randIdCnt)
- heroGrid.shuijingAttrID = equipConfig.shuijingAttrID[indexTemp]
- end
-
- -- 计算属性并发送
- ObjHuman.doCalcHero(human,heroIndex)
- HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
- -- 通知客户端
- local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
- msgRet.heroID = heroID
- msgRet.heroIndex = heroIndex
- Grid.makeItem(msgRet.equip, nextID, 1, heroGrid.shuijingAttrID)
- Msg.send(msgRet, human.fd)
-
- local msgRet = Msg.gc.GC_SHUIJING_UPLV_DO
- msgRet.heroID = heroID
- msgRet.heroIndex = heroIndex
- Grid.makeItem(msgRet.equip, nextID, 1, heroGrid.shuijingAttrID)
- Msg.send(msgRet, human.fd)
- end
- -- 神器升级查询
- function shenqiUpLvQuery(human, heroID, heroIndex)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if heroGrid == nil then
- return
- end
-
- local pos = ItemDefine.EQUIP_SUBTYPE_SHENQI
- if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
- return
- end
-
- local equipID = heroGrid.equip[pos]
- local shenqiUpNeedConfig = EquipExcel.shenqiUpNeed[equipID]
- if not shenqiUpNeedConfig then return end
-
- -- 上限判断
- local nextID = shenqiUpNeedConfig.nextID
- if nextID == 0 then return end
-
- -- 下发信息
- local msgRet = Msg.gc.GC_SHENQI_UPLV_QUERY
- msgRet.heroID = heroID
- msgRet.heroIndex = heroIndex
- msgRet.needExp = shenqiUpNeedConfig.needExp
- Grid.makeItem(msgRet.equip, nextID, 1)
- Msg.send(msgRet, human.fd)
- end
- -- 神器升级
- function shenqiUpLvDo(human, heroID, heroIndex, equipIDList, equipCntList)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if heroGrid == nil then
- return
- end
-
- local pos = ItemDefine.EQUIP_SUBTYPE_SHENQI
- if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
- return
- end
-
- local equipID = heroGrid.equip[pos]
- local shenqiUpNeedConfig = EquipExcel.shenqiUpNeed[equipID]
- if not shenqiUpNeedConfig then return end
-
- -- 上限判断
- local nextID = shenqiUpNeedConfig.nextID
- if nextID == 0 then return end
-
- -- 判断消耗
- if equipIDList[0] ~= equipCntList[0] then
- return
- end
-
- for i=1, equipIDList[0] do
- local needEquipCnt = equipCntList[i]
- local nowEquipCnt = BagLogic.getItemCnt(human, equipIDList[i])
- if nowEquipCnt < needEquipCnt then
- return
- end
- end
-
- local totalExp = 0
- for i=1, equipIDList[0] do
- local id = equipIDList[i]
- local equipConfig = EquipExcel.equip[id]
- if equipConfig then
- local nowExp = equipConfig.shenqiExp
- local nowCnt = equipCntList[i]
- totalExp = totalExp + math.floor(nowExp * nowCnt)
- else
- local itemConfig = ItemExcel[id]
- if not itemConfig or (id ~= ItemDefine.ITEM_SHENQI_EXP_ID1 and
- id ~= ItemDefine.ITEM_SHENQI_EXP_ID2) then
- return
- end
- local nowExp = itemConfig.effect
- local nowCnt = equipCntList[i]
- totalExp = totalExp + math.floor(nowExp * nowCnt)
- end
- end
-
- local needExp = shenqiUpNeedConfig.needExp
- if totalExp < needExp then
- return Broadcast.sendErr(human, Lang.EQUIP_SHENQI_UP_ERR_EXP)
- end
-
- -- 扣道具
- for i=1, equipIDList[0] do
- local needEquipCnt = equipCntList[i]
- BagLogic.delItem(human, equipIDList[i], needEquipCnt, "shenqi_upLv")
- end
-
- -- 改db
- heroGrid.equip[pos] = nextID
- local backExp = totalExp - needExp
- local backCnt = math.floor(backExp/10)
-
- -- 返还物
- if backCnt > 0 then
- BagLogic.addItem(human, HeroDefine.DEFAULT_SHENQI_UPLV_BACK, backCnt, "shenqi_upLv_back", noSend)
- end
-
- -- 计算属性
- ObjHuman.doCalcHero(human,heroIndex)
- HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
-
- -- 通知客户端
- local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
- msgRet.heroID = heroID
- msgRet.heroIndex = heroIndex
- Grid.makeItem(msgRet.equip, nextID, 1)
- Msg.send(msgRet, human.fd)
-
- local msgRet = Msg.gc.GC_SHENQI_UPLV_DO
- msgRet.heroID = heroID
- msgRet.heroIndex = heroIndex
- if backCnt > 0 then
- msgRet.equip[0] = 1
- Grid.makeItem(msgRet.equip[1], HeroDefine.DEFAULT_SHENQI_UPLV_BACK,backCnt)
- else
- msgRet.equip[0] = 0
- end
- Msg.send(msgRet, human.fd)
- end
- -- 比较2件装备信息,返回较好的装备id
- function cmpEquip(tNowequipGrid, tBagEquipGrid, heroConfig)
- if not tNowequipGrid or not tBagEquipGrid then
- return nil
- end
- --print("[cmpEquip] 装备ID ID1 = "..tNowequipGrid.id.." ID2 = "..tBagEquipGrid.id)
- --print("[cmpEquip] 11111")
- local tConfig1 = EquipExcel.equip[tNowequipGrid.id]
- local tConfig2 = EquipExcel.equip[tBagEquipGrid.id]
- if not tConfig1 or not tConfig2 then
- return tNowequipGrid
- end
- local nBaseRate1 = EquipLogic.getEquipBaseRate(tNowequipGrid.quality)
- local nBaseRate2 = EquipLogic.getEquipBaseRate(tBagEquipGrid.quality)
- local nScore1 = math.floor(tConfig1.score * nBaseRate1)
- local nScore2 = math.floor(tConfig2.score * nBaseRate2)
- --print("[cmpEquip] nBaseRate1 = "..nBaseRate1.." nScore1 = "..nScore1.." nBaseRate2 = "..nBaseRate2.." nScore2 = "..nScore2)
- -- 先比较评分
- if nScore1 ~= nScore2 then
- -- print("[cmpEquip] score 不同 score1 = "..nScore1.." score2 = "..nScore2)
- return (nScore1 >= nScore2) and tNowequipGrid or tBagEquipGrid
- end
- --print("[cmpEquip] 333333")
- if tConfig1.level and tConfig2.level and tConfig1.level ~= tConfig2.level then
- -- print("[cmpEquip] level 不同 level1 = "..tConfig1.level.." level2 = "..tConfig2.level)
- return (tConfig1.level >= tConfig2.level) and tNowequipGrid or tBagEquipGrid
- end
- --print("[cmpEquip] 4444")
- if not tNowequipGrid.quality then
- -- print("当前穿戴的装备没有品级 ID1 = "..tNowequipGrid.id)
- end
- if not tBagEquipGrid.quality then
- -- print("当前比较的装备没有品级 ID1 = "..tBagEquipGrid.id)
- end
- if tNowequipGrid.quality and tBagEquipGrid.quality then
- if tNowequipGrid.quality ~= tBagEquipGrid.quality then
- print("[cmpEquip] quality 不同 quality1 = "..tNowequipGrid.quality.." quality2 = "..tBagEquipGrid.quality)
- return (tNowequipGrid.quality >= tBagEquipGrid.quality) and tNowequipGrid or tBagEquipGrid
- else
- -- print("cmpEquip 当前装备品质相同")
- end
- end
- --print("[cmpEquip] 5555")
- return tNowequipGrid
-
- -- if heroConfig then -- 专属装备判断 阵营 职业
- -- -- if config1.camp == heroConfig.camp then return equipID1 end
- -- -- if config2.camp == heroConfig.camp then return equipID2 end
- -- -- if config1.job == heroConfig.job then return equipID1 end
- -- -- if config2.job == heroConfig.job then return equipID2 end
- -- end
- --print("cmpEquip 默认返回装备1 equipID1 = "..equipID1)
- end
- -- 根据部位和伙伴信息获取背包最好的装备id
- function getBagBestEquipID(human, pos, tNowequipGrid, nHeroStar, heroConfig)
- -- 当前最好的装备
- local tChoseEquipGrid = tNowequipGrid
- for k, equipGrid in pairs(human.db.equipBag) do
- local config = EquipExcel.equip[equipGrid.id]
- -- 装备位置相同,星级<=英雄星级,并且装备未穿戴
- if equipGrid and config and config.subType == pos
- and config.star <= nHeroStar and equipGrid.putUuid == nil then
- tChoseEquipGrid = cmpEquip(tChoseEquipGrid, equipGrid, heroConfig)
- if nil == tChoseEquipGrid then
- print("[getBagBestEquipID] 返回的值不正确")
- tChoseEquipGrid = tNowequipGrid
- end
- end
- end
- local nBestEquipID = tChoseEquipGrid.id
- if tNowequipGrid.id == tChoseEquipGrid.id
- and tNowequipGrid.quality == tChoseEquipGrid.quality
- and tNowequipGrid.score == tChoseEquipGrid.score and tNowequipGrid.level == tChoseEquipGrid.level then
- nBestEquipID = nil
- end
- return nBestEquipID
- end
- -- 是否有装备红点
- function isEquipDot(human, heroGrid)
- if human.db.lv < 9 then
- return false
- end
- if not heroGrid then return false end
- local heroConfig = HeroExcel.hero[heroGrid.id]
- if not heroConfig then return false end
- for pos = 1, ItemDefine.EQUIP_MAX_CNT do
- if pos ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
- local equipGrid = heroGrid.equip and heroGrid.equip[pos]
- if equipGrid == nil and EquipLogic.getEquipByPos(human, heroGrid.star, pos) then
- return true
- else
- if equipGrid ~= nil then
- local nEquipID = equipGrid.id
- local nBestEquipID = getBagBestEquipID(human, pos, equipGrid, heroGrid.star)
- if nil ~= nBestEquipID and nBestEquipID ~= nEquipID then
- -- print("[isEquipDot] heroID = "..heroGrid.id.." nEquipID = "..nEquipID.." nBestEquipID = "..nBestEquipID)
- return true
- end
- end
- end
- end
- end
- --print("[isEquipDot] 不存在更好的装备 ")
- return false
- end
- -- 是否有装备红点
- function isEquipDotByPos(human, heroGrid, pos)
- if human.db.lv < 9 then
- return false
- end
- if not heroGrid then return end
- local heroConfig = HeroExcel.hero[heroGrid.id]
- if not heroConfig then return end
- if pos ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
- local equipGrid = heroGrid.equip and heroGrid.equip[pos]
- if equipGrid == nil and EquipLogic.getEquipByPos(human, heroGrid.star, pos) then
- return 1
- end
- end
- end
- function getEquipAndFuwenByHeroIndex(human,heroID,heroIndex)
- local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
- if not heroGrid then return end
- local heroConfig = HeroExcel.hero[heroGrid.id]
- if not heroConfig then return end
- local equipTb = {}
- for pos = 1, ItemDefine.EQUIP_MAX_CNT do
- if pos ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
- local equipID = heroGrid.equip and heroGrid.equip[pos] and heroGrid.equip[pos].id
- equipTb[pos] = equipID
- end
- end
- local fuwenTb = {}
- for pos = 1,2 do
- local fuwenIndex = heroGrid.fuwen and heroGrid.fuwen[pos]
- fuwenTb[pos] = fuwenIndex
- end
- return equipTb,fuwenTb
- end
|