| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497 |
- ----------------------------------------------------------
- -- 道具使用
- ----------------------------------------------------------
- local Lang = require("common.Lang")
- local Msg = require("core.Msg")
- local ObjHuman = require("core.ObjHuman")
- local Grid = require("bag.Grid")
- local ItemDefine = require("bag.ItemDefine")
- local BagLogic = require("bag.BagLogic")
- local BoxLogic = require("bag.BoxLogic")
- local Broadcast = require("broadcast.Broadcast")
- local FundLogic = require("present.FundLogic")
- local SuperFundLogic = require("present.SuperFundLogic")
- local TopupLogic = require("topup.TopupLogic")
- local VipLogic = require("vip.VipLogic")
- local RoleHeadLogic = require("role.RoleHeadLogic")
- local BarTaskLogic = require("bar.BarTaskLogic")
- local YjTreasureLogic = require("yjTreasure.YjTreasureLogic")
- local ItemComonBuyExcel = require("excel.item").commonBuy
- local UnionLogic = require("union.UnionLogic")
- local RoleDBLogic = require("role.RoleDBLogic")
- local EquipLogic = require("equip.EquipLogic")
- local FuwenGrid = require("fuwen.FuwenGrid")
- local Util = require("common.Util")
- local XingYaoGongMing = require("xingYaoMen.XingYaoGongMing")
- local DropExchangeLogic = require("absAct.DropExchangeLogic")
- local HeroGrowUp = require("absAct.HeroGrowUp")
- local BuyExcel = require("excel.buy")
- local LostTempleLogic = require("lostTemple.lostTempleLogic")
- cmd = {}
- FUWEN_BAG_TYPE = 1
- NORMAL_BAG_TYPE = 2
- EQUIP_BAG_TYPE = 3
- -- 所使用道具的相关信息
- local function createData(id, cnt, itemConfig, logType, isAuto)
- local data = {}
- data.id = id -- 道具id
- data.cnt = cnt -- 使用道具数量
- data.left = cnt -- 剩余要使用的数量
- data.config = itemConfig -- 道具配置
- data.logType = logType -- 日志类型
- data.isAuto = isAuto -- 是否自动使用
- return data
- end
- -- 金币
- function cmd.jinbi(data, human, value)
- if data.left < 1 then return end
- local sumJinbi = value * data.left
- data.left = 0
- ObjHuman.updateJinbi(human, sumJinbi, data.logType)
- end
- -- 钻石
- function cmd.zuanshi(data, human, value)
- if data.left < 1 then return end
- local sumZuanshi = value * data.left
- data.left = 0
- ObjHuman.addZuanshi(human, sumZuanshi, data.logType)
- end
- -- 经验
- function cmd.exp(data, human, value)
- if data.left < 1 then return end
- local sumExp = value * data.left
- data.left = 0
- ObjHuman.addExp(human, sumExp)
- end
- -- 自选宝箱
- function cmd.box(data, human, list)
- BoxLogic.sendBoxList(human, list)
- end
- -- 随机宝箱
- function cmd.boxRand(data, human, list)
- if data.left < 1 then return end
- local itemLen = list and #list or 0
- if itemLen < 1 then
- return Broadcast.sendErr(human, Lang.ITEM_USE_ERR_CONFIG)
- end
- local weightSum = 0
- for i = 1, itemLen do
- local weight = list[i][3]
- weightSum = weightSum + weight
- end
- if weightSum < 1 then
- return Broadcast.sendErr(human, Lang.ITEM_USE_ERR_CONFIG)
- end
- -- 检测数量
- local equipCnt = 0
- local fuWenCnt = 0
- BagLogic.cleanMomentItemList()
- local mathRandom = math.random
- for i = 1, data.left do
- local r = mathRandom(1, weightSum)
- for j = 1, itemLen do
- local itemID = list[j][1]
- local itemCnt = list[j][2]
- local weight = list[j][3]
- local quality = list[j][4]
- if r <= weight then
- BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, itemID, itemCnt, quality)
- -- 计算装备数量
- if ItemDefine.isEquip(itemID) then
- equipCnt = equipCnt + itemCnt
- end
-
- if ItemDefine.isFuwen(itemID) then
- fuWenCnt = fuWenCnt + itemCnt
- end
- break
- end
- r = r - weight
- end
- end
- -- 检测装备背包空间
- if not EquipLogic.checkEmptyCnt(human, equipCnt) then
- BagLogic.cleanMomentItemList()
- return
- end
- if not FuwenGrid.checkEmptyCnt(human, fuWenCnt) then
- BagLogic.cleanMomentItemList()
- return
- end
- data.left = 0
- BagLogic.addMomentItemList(human, "useBox")
- end
- -- 固定箱子
- function cmd.boxAll(data, human, list)
- if data.left < 1 then return end
- local cnt = data.left
- local oustList = {}
- local len = 0
- local equipCnt = 0
- local fuWenCnt = 0
- for i = 1, #list do
- local itemID = list[i][1]
- local itemCnt = list[i][2] * cnt
- local quality = list[i][3]
-
- oustList[i] = {}
- oustList[i][1] = itemID
- oustList[i][2] = itemCnt
- oustList[i][3] = quality
-
- -- 计算装备数量
- if ItemDefine.isEquip(itemID) then
- equipCnt = equipCnt + itemCnt
- end
- if ItemDefine.isFuwen(itemID) then
- fuWenCnt = fuWenCnt + itemCnt
- end
- end
- -- 检测装备背包空间
- if not EquipLogic.checkEmptyCnt(human, equipCnt) then
- return
- end
- if not FuwenGrid.checkEmptyCnt(human, fuWenCnt) then
- return
- end
- data.left = 0
- BagLogic.addItemList(human, oustList, "useBox")
- end
- -- 获得称号
- function cmd.chenghao(data, human)
- RoleHeadLogic.active(human, RoleHeadLogic.HEAD_TYPE_4, data.config.icon)
- return true
- end
- -- 头像
- function cmd.head(data, human)
- RoleHeadLogic.active(human, RoleHeadLogic.HEAD_TYPE_1, data.config.icon)
- return true
- end
- -- 头像框
- function cmd.headFrame(data, human)
- RoleHeadLogic.active(human, RoleHeadLogic.HEAD_TYPE_2, data.config.icon)
- return true
- end
- -- 小基金/大基金
- function cmd.superfund(data, human, ftype)
- SuperFundLogic.buySuperFund(human, ftype)
- return true
- end
- -- 钻石基金
- function cmd.fundbuy(data, human, ftype)
- FundLogic.fundBuy(human, ftype)
- return true
- end
- -- 扫荡特权
- function cmd.tequanmopup(data, human, day)
- local time = os.time()
- if human.db.tequanMopup and human.db.tequanMopup > time then
- time = human.db.tequanMopup
- end
- human.db.tequanMopup = time + day * 86400
- return true
- end
- -- 民生/悬赏高级特权
- function cmd.tequanbar1(data, human)
- BarTaskLogic.activateBarVip(human, 1)
- return true
- end
- -- 民生/悬赏豪华特权
- function cmd.tequanbar2(data, human)
- BarTaskLogic.activateBarVip(human, 2)
- return true
- end
- -- 模拟充值
- function cmd.chargemoney(data, human, value, noAddYb)
- if data.left < 1 then return end
- local price = value * data.left
- data.left = 0
- TopupLogic.clacTopupAcount(human, price)
- if noAddYb ~= 1 then
- VipLogic.addExp(human, price*10)
- ObjHuman.addZuanshi(human, price*10, data.logType)
- end
- end
- -- 大月卡
- function cmd.fundbig(data, human)
-
- return true
- end
- -- 小月卡
- function cmd.fundsmall(data, human)
-
- return true
- end
- -- 友情值
- function cmd.friendheart(data, human, value)
- if data.left < 1 then return end
- local sum = data.left * value
- data.left = 0
- ObjHuman.updateFriendHeart(human, sum, data.logType)
- end
- -- vip经验
- function cmd.vipexp(data, human, value)
- if data.left < 1 then return end
- local sum = data.left * value
- data.left = 0
- VipLogic.addExp(human, sum)
- end
- --民生任务 情报值
- function cmd.qingbao(data, human, value)
- if data.left < 1 then return end
- local sum = value * data.left
- data.left = 0
- BarTaskLogic.addBarQingBao(human,sum)
- end
- --遗迹探宝
- function cmd.yjtreasureYJ(data, human, yaojiType)
- YjTreasureLogic.yjYaoJiAdd(human,data.left,yaojiType)
- end
- --遗迹探宝
- function cmd.heroGrowUp(data, human)
- HeroGrowUp.addJifen(human, data.cnt)
- end
- function cmd.guildexp(data, human, value)
- if data.left < 1 then return end
- local sum = value * data.left
- data.left = 0
- UnionLogic.addUnionExpByItem(human, sum)
- end
- function cmd.absDrop(data, human, value)
- if data.left < 1 then return end
- local sum = data.left * value
- data.left = 0
- DropExchangeLogic.addJifen(human, sum)
- end
- function cmd.zhigou(data, human, value)
- if data.left < 1 then return end
- local buyConf = BuyExcel.buy[value]
- if not buyConf then
- return
- end
- local msg = {}
- msg.logintype = 2
- msg.openid = "oCD-L5RxAtfRe8-aiezdY-Ccla5U"
- msg.openkey = "VsBJf2DKah7QhzU5xuzLNA=="
- msg.yuanbao = buyConf.CN * 10
- msg.buyID = value
- msg.account = human.db.account
- msg.transaction_id = "transaction_id1"
- msg.pf = "android"
- msg.money = buyConf.CN
- require("platform.ApiLogic").CHARGE_CODE_HIS = {}
- require("AdminLogic").adminFunction.tencentPay(msg)
- end
- function cmd.lostRevice(data, human, value)
- if data.left < 1 then return end
- LostTempleLogic.lostTempleRevice(human)
- return true
- end
- -----------------------------------------------------------------------------
- -- 仅使用道具,不扣道具
- function onlyuse(human, id, cnt, logType, isAuto)
- if cnt < 1 then return end
- local itemConfig = ItemDefine.getConfig(id)
- if not itemConfig or not itemConfig.cmd then
- return Broadcast.sendErr(human, Lang.ITEM_USE_ERR_CANT_USE)
- end
- local command = itemConfig.cmd
- local cmdName = command[1]
- if not cmdName or not cmd[cmdName] then
- return Broadcast.sendErr(human, Lang.ITEM_USE_ERR_CANT_USE)
- end
- local data = createData(id, cnt, itemConfig, logType, isAuto)
- while 0 < data.left do
- local isok = cmd[cmdName](data, human, command[2], command[3], command[4])
- if isok then
- data.left = data.left - 1
- else
- break
- end
- end
- return true, data.left
- end
- -- 使用并扣道具
- function use(human, id, cnt)
- if cnt < 1 then return end
- if id < 1 then return end
- local bagCnt = BagLogic.getItemCnt(human, id, true)
- if bagCnt < cnt then
- return Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
- end
- local success, left = onlyuse(human, id, cnt, "item_use")
- if not success then
- return
- end
- local delCnt = cnt - left
- if delCnt > 0 then
- BagLogic.delItem(human, id, delCnt, "item_use")
- end
- end
- --
- function sendItemUse(human, id)
- local msgRet = Msg.gc.GC_ITEM_USE
- msgRet.id = id
- Msg.send(msgRet, human.fd)
- end
- -- 根据id获取item
- function sendItemDateByID(human,type,index,id,uuid)
- local msgRet = Msg.gc.GC_ITEM_GET_BY_ID
- if type == FUWEN_BAG_TYPE then
- -- 取出背包
- local bagFileds = {fuwenBag = 1}
- local db = nil
-
- -- 玩家在线直接取缓存
- local tempHuman = ObjHuman.onlineUuid[uuid]
- if tempHuman == nil then
- db = RoleDBLogic.getDb(uuid,bagFileds)
- else
- db = tempHuman.db
- end
- -- 玩家不存在,返回
- if db == nil then
- return
- end
- local fuwenGrid = db.fuwenBag[index]
- -- 符文背包id对不上,返回
- if fuwenGrid == nil or fuwenGrid.id ~= id then
- return
- end
- Grid.makeItem(msgRet.item,id,1,nil,fuwenGrid,index,0)
- elseif type == NORMAL_BAG_TYPE then
- Grid.makeItem(msgRet.item,id,1)
- elseif type == EQUIP_BAG_TYPE then
- -- 取出背包
- local bagFileds = {equipBag = 1}
- local db = nil
-
- -- 玩家在线直接取缓存
- local tempHuman = ObjHuman.onlineUuid[uuid]
- if tempHuman == nil then
- db = RoleDBLogic.getDb(uuid,bagFileds)
- else
- db = tempHuman.db
- end
- -- 玩家不存在,返回
- if db == nil then
- return
- end
- local equipGrid = db.equipBag[index]
- -- 符文背包id对不上,返回
- if equipGrid == nil or equipGrid.id ~= id then
- return
- end
- Grid.makeItem(msgRet.item,id,1,nil,equipGrid,index,0)
- end
- Msg.send(msgRet,human.fd)
- end
- -- 根据id获取item
- function sendItemData(human,itemID)
- local msgRet = Msg.gc.GC_ITEM_GET_BY_ITEM_ID
- local itemCnt = BagLogic.getItemCnt(human,itemID)
- Grid.makeItem(msgRet.item,itemID,itemCnt)
- Msg.send(msgRet,human.fd)
- end
- function itemBuyQuery(human,itemID)
- local config = ItemComonBuyExcel[itemID]
- if config == nil then
- return
- end
- local msgRet = Msg.gc.GC_ITEM_BUY_QUERY
- Grid.makeItem(msgRet.need,config.price[1],config.price[2])
- Grid.makeItem(msgRet.get,itemID,config.cnt)
- Msg.send(msgRet,human.fd)
- end
- function itemBuyDo(human,itemID,itemCnt)
- local msgRet = Msg.gc.GC_ITEM_BUY_DO
- msgRet.ret = 0
- local config = ItemComonBuyExcel[itemID]
- if config == nil then
- Msg.send(msgRet,human.fd)
- return
- end
- local needID = config.price[1]
- local needCnt = config.price[2] * itemCnt
- local costCnt = BagLogic.getItemCnt(human,needID)
- if costCnt < needCnt then
- Msg.send(msgRet,human.fd)
- return
- end
- BagLogic.delItem(human, needID, needCnt, "buy_item")
- BagLogic.cleanMomentItemList()
- BagLogic.updateMomentItem(1, itemID, itemCnt*config.cnt)
- BagLogic.addMomentItemList(human, "buy_item")
- msgRet.ret = 1
- Msg.send(msgRet,human.fd)
- end
|