Trade.lua 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286
  1. Trade = {}
  2. local this = {}
  3. MINUTE_SECOND = 60 * 1000
  4. TRADE_WAY = {
  5. GARD_BOSS = 1, -- 战盟boss
  6. SIEGE = 2, -- 攻城战
  7. UNION = 3, -- 战盟
  8. WORLD_UP = 4, -- 世界上架
  9. SYSTEM_UP = 5, -- 系统上架
  10. UNION_FLOW = 6, -- 战盟流拍
  11. STALL = 7; -- 面对面商店
  12. }
  13. TRADE_GOODS_TIPS = {
  14. SHOW = 1, -- 显示tips
  15. NO_SHOW = 0, -- 不显示
  16. }
  17. TRADE_RECORD_TYPE = {
  18. PREORDER = 0, -- 预购
  19. PURCHASE = 1, -- 购买
  20. SALE = 2, -- 售出
  21. }
  22. SORT_TYPE = {
  23. DEFAULT = 0, --默认
  24. ASC_BY_TIME = 1, --按照时间升序
  25. DESC_BY_TIME = 2, --按照时间降序
  26. ASC_BY_PRICE = 3, --按照价格升序
  27. DESC_BY_PRICE = 4, --按照价格降序
  28. }
  29. TRADE_CAPACITY_GLOBAL_ID = 8001
  30. SYS_TRADE_WORLD_GOODS = "R$tradeWorldGoods"
  31. ROLE_TRADE_WORLD_GOODS = "T$tradeWorldGoods"
  32. ROLE_TRADE_GOODS_RECORD = "T$tradeWorldRecord"
  33. ROLE_TRADE_PRE_GOODS = "T$tradeWorldPre"
  34. ---@class Trade.GoodInfo 世界商品信息
  35. ---@field itemcfgid number 商品配置id
  36. ---@field itemid number 商品id
  37. ---@field itemname string 商品名字
  38. ---@field entrysize number 词条属性数量
  39. ---@field garde number 品质
  40. ---@field ownid string 商品所属人id
  41. ---@field count number 商品数量
  42. ---@field unitPrice number 商品单价
  43. ---@field totalprice number 商品总价
  44. ---@field job table 职业
  45. ---@field cointype number 货币类型
  46. ---@field publicitytime number 公示时间
  47. ---@field upshelfduration number 竞拍时间
  48. ---@field tax table 税率
  49. ---@field subtype number 商品子类型
  50. ---@field type number 商量类型
  51. ---@field peroreder table 预购人员id
  52. ---@field publicitystatue boolean 是不是公示期间
  53. ---@field listingtime number 上架时间
  54. -- 世界交易行上架
  55. -- msgData 中要包含 itemcfgid,bagindex,count,listingprice,totalprice,id
  56. function Trade.worldTradeListing(actor, msgData)
  57. --local isOpen, _ = PrivilegeMonth.hasPrivilege(actor, PrivilegeMonth.PrivilegeType.TRADE_SALE)
  58. --if not isOpen then
  59. -- noticeTip.noticeinfo(actor, StringIdConst.TEXT491)
  60. -- return
  61. --end
  62. local itemCfgId = msgData["itemcfgid"]
  63. local stallInfo = ConfigDataManager.getTable("cfg_stall", "id", itemCfgId, "way", TRADE_WAY.WORLD_UP)
  64. if not stallInfo and table.isEmpty(stallInfo) then
  65. noticeTip.noticeinfo(actor, StringIdConst.TEXT383)
  66. return
  67. end
  68. local have = this.checkCapacity(actor)
  69. if not have then
  70. noticeTip.noticeinfo(actor, StringIdConst.TEXT370)
  71. return
  72. end
  73. local itemStall = stallInfo[1]
  74. local jobTable = itemStall["job"]
  75. if not jobTable then
  76. jobTable = { 0 }
  77. elseif jobTable then
  78. jobTable = string.split(jobTable, "#")
  79. end
  80. local money = itemStall["money"]
  81. local ready = itemStall["ready"]
  82. local readyTime = tonumber(ready) * MINUTE_SECOND
  83. local time = itemStall["time"]
  84. local shellTime = tonumber(time) * MINUTE_SECOND
  85. local tax = itemStall["tax"]
  86. local taxTable = {}
  87. if not tax then
  88. taxTable = { 0, 0 }
  89. elseif tax then
  90. local taxInfo = string.split(tax, "|")
  91. for index, value in ipairs(taxInfo) do
  92. local taxDetail = string.split(value, "#")
  93. table.insert(taxTable, tonumber(taxDetail[2]))
  94. end
  95. end
  96. local subtypeItem = tonumber(itemStall["subtype"])
  97. local typeItem = tonumber(itemStall["type"])
  98. local itemInfo = getotheritemattinfo(actor,1,actor:toString(),msgData["id"])
  99. jprint("上架道具信息",itemInfo)
  100. if table.isNullOrEmpty(itemInfo) then
  101. noticeTip.noticeinfo(actor, StringIdConst.TEXT371)
  102. return
  103. end
  104. local entries = itemInfo["entries"]
  105. local entryCount = 0
  106. if not table.isNullOrEmpty(entries) then
  107. entryCount = table.count(entries)
  108. end
  109. ---type Trade.GoodInfo 世界商品信息
  110. local goods = {
  111. itemcfgid = tonumber(msgData["itemcfgid"]),
  112. itemid = tonumber(itemInfo["itemid"]),
  113. garde = itemInfo["garde"] or 0,
  114. itemname = itemStall["name"],
  115. entrysize = entryCount,
  116. ownid = actor:toString(),
  117. count = tonumber(msgData["count"]),
  118. unitPrice = tonumber(msgData["listingprice"]),
  119. totalprice = tonumber(msgData["totalprice"]),
  120. job = jobTable,
  121. cointype = money,
  122. publicitytime = readyTime,
  123. upshelfduration = shellTime,
  124. tax = taxTable,
  125. subtype = subtypeItem,
  126. type = typeItem,
  127. peroreder = nil,
  128. publicitystatue = true,
  129. listingtime = getbaseinfo(actor,"now")
  130. }
  131. this.worldGoodsSave(actor, goods)
  132. local result = bagtoshell(actor, msgData)
  133. sendluamsg(actor, LuaMessageIdToClient.RES_TRADE_LISTING_GOODS, true)
  134. TaskHandler.TriggerTaskGoal(actor, TaskTargetType.TRADE_LINE_UP_GOODS, itemCfgId)
  135. end
  136. function clearqianghua(actor)
  137. -- jprint("开始执行清除数据")
  138. Trade.clearQiangHua()
  139. end
  140. function Trade.clearQiangHua()
  141. local allWorldGoods = getsysvar(SYS_TRADE_WORLD_GOODS)
  142. -- jprint("allWorldGoods",allWorldGoods)
  143. if table.isNullOrEmpty(allWorldGoods) then
  144. return
  145. end
  146. for actorString, roleAllGoods in pairs(allWorldGoods) do
  147. local actor = getactor(actorString)
  148. -- jprint("actor",actor)
  149. if actor ~= nil then
  150. local allequip = getplaydef(actor, "T$luaitemextdata")
  151. -- jprint("allequip",allequip)
  152. if not table.isNullOrEmpty(allequip) then
  153. for itemId, goods in pairs(roleAllGoods) do
  154. -- jprint("itemId",itemId)
  155. local itemInfo = allequip[tonumber(itemId)]
  156. -- jprint("itemInfo",itemInfo)
  157. if not table.isNullOrEmpty(itemInfo) then
  158. -- 下架商品
  159. shelltobag(actor, actor:toString(), itemId, goods.count, actor:toString(), 0, "")
  160. roleAllGoods[tostring(itemId)] = nil
  161. end
  162. end
  163. end
  164. end
  165. allWorldGoods[actorString] = roleAllGoods
  166. end
  167. -- jprint("allWorldGoods",allWorldGoods)
  168. setsysvar(SYS_TRADE_WORLD_GOODS,allWorldGoods)
  169. end
  170. -- 保存上架商品
  171. function this.worldGoodsSave(actor, goods)
  172. --local roleWorld = getplaydef(actor, ROLE_TRADE_WORLD_GOODS)
  173. --if not roleWorld then
  174. -- roleWorld = {}
  175. --end
  176. --roleWorld[tostring(goods.itemid)] = goods
  177. --setplaydef(actor, ROLE_TRADE_WORLD_GOODS, roleWorld)
  178. jprint("上架商品信息",goods)
  179. local allWorldGoods = getsysvar(actor, SYS_TRADE_WORLD_GOODS)
  180. if not allWorldGoods then
  181. allWorldGoods = {}
  182. end
  183. local roleAllGoods = allWorldGoods[actor:toString()]
  184. if not roleAllGoods then
  185. roleAllGoods = {}
  186. allWorldGoods[actor:toString()] = roleAllGoods
  187. end
  188. roleAllGoods[tostring(goods.itemid)] = goods
  189. jprint("全服玩家全部数据",roleAllGoods)
  190. setsysvar(actor, SYS_TRADE_WORLD_GOODS, allWorldGoods)
  191. end
  192. -- 交易行检查格子是否够用
  193. function this.checkCapacity(actor)
  194. local capacity = ConfigDataManager.getTableValue("cfg_global", "value", "id", TRADE_CAPACITY_GLOBAL_ID)
  195. local is_has, count = PrivilegeMonth.hasPrivilege(actor, PrivilegeMonth.PrivilegeType.TRADE_LINE_UP_COUNT_INCREASE)
  196. capacity = capacity + count
  197. local allWorldGoods = getsysvar(actor, SYS_TRADE_WORLD_GOODS)
  198. if not allWorldGoods then
  199. return true
  200. end
  201. local count = 0
  202. local roleAllGoods = allWorldGoods[actor:toString()]
  203. if roleAllGoods then
  204. count = table.count(roleAllGoods)
  205. end
  206. if count >= capacity then
  207. return false
  208. end
  209. return true
  210. end
  211. -- 下架商品
  212. -- msgData 中要包含 itemcfgid,itemId
  213. function Trade.worldOffShelfGoods(actor, msgData)
  214. local itemId = msgData[2]
  215. local allWorldGoods = getsysvar(actor, SYS_TRADE_WORLD_GOODS)
  216. if not allWorldGoods then
  217. noticeTip.noticeinfo(actor, StringIdConst.TEXT372)
  218. return
  219. end
  220. local roleAllGoods = allWorldGoods[actor:toString()]
  221. local goodsDetail = roleAllGoods[tostring(itemId)]
  222. if not goodsDetail then
  223. noticeTip.noticeinfo(actor, StringIdConst.TEXT373)
  224. return
  225. end
  226. local publicityTime = goodsDetail.listingtime + goodsDetail.publicitytime
  227. local now = getbaseinfo("now")
  228. if now < publicityTime then
  229. noticeTip.noticeinfo(actor, StringIdConst.TEXT374)
  230. return
  231. end
  232. local ownid = goodsDetail.ownid
  233. if actor:toString() ~= tostring(ownid) then
  234. noticeTip.noticeinfo(actor, StringIdConst.TEXT375)
  235. return
  236. end
  237. local count = goodsDetail.count
  238. shelltobag(actor, actor:toString(), itemId, count, actor:toString(), 0, "")
  239. this.changeGoodsInfo(actor, itemId, count, count)
  240. sendluamsg(actor, LuaMessageIdToClient.RES_TRADE_OFF_GOODS, true)
  241. end
  242. -- lua中保存商品信息改变
  243. function this.changeGoodsInfo(ownActor, goodId, itemCount, buyCount)
  244. local allWorldGoods = getsysvar(ownActor, SYS_TRADE_WORLD_GOODS)
  245. -- local tradeWorldGoodsInfo = getplaydef(ownActor, ROLE_TRADE_WORLD_GOODS)
  246. if itemCount == buyCount then
  247. local roleAllGoods = allWorldGoods[ownActor:toString()]
  248. roleAllGoods[tostring(goodId)] = nil
  249. setsysvar(ownActor, SYS_TRADE_WORLD_GOODS, allWorldGoods)
  250. elseif itemCount < buyCount then
  251. noticeTip.noticeinfo(actor, StringIdConst.TEXT376)
  252. return
  253. elseif itemCount > buyCount then
  254. local roleAllGoods = allWorldGoods[ownActor:toString()]
  255. local sysGoodDetail = roleAllGoods[tostring(goodId)]
  256. sysGoodDetail.count = itemCount - buyCount
  257. sysGoodDetail.totalprice = sysGoodDetail.count * sysGoodDetail.unitPrice
  258. setsysvar(ownActor, SYS_TRADE_WORLD_GOODS, allWorldGoods)
  259. end
  260. end
  261. -- 获取世界商品
  262. function Trade.getTradeWorldGoods(actor, msgData)
  263. local allWorldGoods = getsysvar(actor, SYS_TRADE_WORLD_GOODS)
  264. Trade.flushWorldGoods()
  265. allWorldGoods = getsysvar(actor, SYS_TRADE_WORLD_GOODS)
  266. if not allWorldGoods then
  267. sendluamsg(actor, LuaMessageIdToClient.RES_GET_TRADE_GOODS, allWorldGoods)
  268. -- Trade.sendRecharge(actor)
  269. return
  270. end
  271. local goods = this.filterGoods(actor, allWorldGoods, msgData)
  272. -- local goods = getworldtradegoods(actor, msgData[1],msgData[2], msgData[3], msgData[4], msgData[5],msgData[6],TRADE_WAY.WORLD_UP)
  273. sendluamsg(actor, LuaMessageIdToClient.RES_GET_TRADE_GOODS, goods)
  274. -- Trade.sendRecharge(actor)
  275. end
  276. -- 过滤商品
  277. function this.filterGoods(actor, allWorldGoods, msgData)
  278. local goods = {}
  279. if msgData[1] == 100 then
  280. this.publicityGoods(goods, msgData, allWorldGoods)
  281. return goods
  282. elseif msgData[1] == 200 then
  283. this.myPreGoods(actor, goods, msgData, allWorldGoods)
  284. -- Trade.getPreBuyGoods(actor,msgData)
  285. return goods
  286. end
  287. this.arrangeGoods(goods, msgData, allWorldGoods)
  288. return goods
  289. end
  290. -- 获取公示商品
  291. function this.publicityGoods(goods, msgData, allWorldGoods)
  292. local now = getbaseinfo("now")
  293. for index, roleAllGoods in pairs(allWorldGoods) do
  294. for goodIndex, good in pairs(roleAllGoods) do
  295. local listingTime = good.listingtime
  296. local time = listingTime + good.publicitytime
  297. if now < time then
  298. local itemRank = ConfigDataManager.getTableValue("cfg_item", "rank", "id", good.itemCfgId)
  299. if (msgData[5] == 0 or itemRank == msgData[5]) and (msgData[6] == 0 or good.garde == msgData[6]) then
  300. if msgData[4] == 0 or good.job[1] == 0 or table.contains(good.job, tostring(msgData[4])) then
  301. good["publicity"] = 1
  302. good["timename"] = "公示中"
  303. good["time"] = (time - now) / 1000
  304. table.insert(goods, good)
  305. end
  306. end
  307. end
  308. end
  309. end
  310. end
  311. -- 预购商品
  312. function this.myPreGoods(actor, goods, msgData, allWorldGoods)
  313. local preGoodInfo = getplaydef(actor, ROLE_TRADE_PRE_GOODS)
  314. if not preGoodInfo or not allWorldGoods then
  315. return
  316. end
  317. for index, preGood in pairs(preGoodInfo) do
  318. local roleAllGoods = allWorldGoods[preGood.rid]
  319. if roleAllGoods then
  320. local good = roleAllGoods[tostring(preGood.goodId)]
  321. if good then
  322. local itemRank = ConfigDataManager.getTableValue("cfg_item", "rank", "id", good.itemCfgId)
  323. if (msgData[1] == 0 or good.type == msgData[1]) and (msgData[2] == 0 or msgData[2] == good.subtype) and (msgData[5] == 0 or itemRank == msgData[5]) and (msgData[6] == 0 or good.garde == msgData[6]) then
  324. if msgData[4] == 0 or good.job[1] == 0 or table.contains(good.job, tostring(msgData[4])) then
  325. good["publicity"] = 1
  326. good["timename"] = "公示中"
  327. good["time"] = (publicityTime - now) / 1000
  328. table.insert(goods, good)
  329. end
  330. end
  331. end
  332. end
  333. end
  334. end
  335. -- 获取分类商品
  336. function this.arrangeGoods(goods, msgData, allWorldGoods)
  337. local now = getbaseinfo("now")
  338. for index, roleAllGoods in pairs(allWorldGoods) do
  339. for index, good in pairs(roleAllGoods) do
  340. local itemRank = ConfigDataManager.getTableValue("cfg_item", "rank", "id", good.itemcfgid)
  341. if good and good.listingtime and good.publicitytime then
  342. local publicityTime = good.listingtime + good.publicitytime
  343. local offShelfTime = publicityTime + good.upshelfduration
  344. if (msgData[1] == 0 or good.type == msgData[1]) and (msgData[2] == 0 or msgData[2] == good.subtype) and (msgData[5] == 0 or tonumber(itemRank) == msgData[5]) and (msgData[6] == 0 or good.garde == msgData[6]) then
  345. if msgData[4] == 0 or good.job[1] == 0 or table.contains(good.job, tostring(msgData[4])) then
  346. -- local have = this.checkGood(allWorldGoods,good)
  347. if publicityTime > now then
  348. good["publicity"] = 1
  349. good["timename"] = "公示中"
  350. good["time"] = (publicityTime - now) / 1000
  351. elseif publicityTime < now and offShelfTime > now then
  352. good["publicity"] = 0
  353. good["timename"] = "下架时间"
  354. good["time"] = (offShelfTime - now) / 1000
  355. end
  356. table.insert(goods, good)
  357. end
  358. end
  359. end
  360. end
  361. end
  362. Trade.sortGoods(goods, msgData[3])
  363. end
  364. -- 检查商品是否还在
  365. function this.checkGood(allWorldGoods, good)
  366. local ownId = good.ownid
  367. local ownActor = getactor(ownId)
  368. local myListingGoods = getplaydef(ownActor, ROLE_TRADE_WORLD_GOODS)
  369. if not myListingGoods then
  370. shelltobag(ownActor, ownActor:toString(), good.itemid, good.count, ownActor:toString())
  371. allWorldGoods[tostring(good.itemid)] = nil
  372. setsysvar(SYS_TRADE_WORLD_GOODS, allWorldGoods)
  373. return false
  374. end
  375. local myGood = myListingGoods[tostring(good.itemid)]
  376. if not myGood then
  377. shelltobag(ownActor, ownActor:toString(), good.itemid, good.count, ownActor:toString())
  378. allWorldGoods[tostring(good.itemid)] = nil
  379. setsysvar(SYS_TRADE_WORLD_GOODS, allWorldGoods)
  380. return false
  381. end
  382. return true
  383. end
  384. -- 商品排序
  385. function Trade.sortGoods(goods, type)
  386. if type == 0 then
  387. table.sort(goods, function(a, b)
  388. return a.listingtime < b.listingtime
  389. end)
  390. elseif type == SORT_TYPE.ASC_BY_TIME then
  391. table.sort(goods, function(a, b)
  392. return a.listingtime < b.listingtime
  393. end)
  394. elseif type == SORT_TYPE.DESC_BY_TIME then
  395. table.sort(goods, function(a, b)
  396. return a.listingtime > b.listingtime
  397. end)
  398. elseif type == SORT_TYPE.ASC_BY_PRICE then
  399. table.sort(goods, function(a, b)
  400. return a.totalprice < b.totalprice
  401. end)
  402. elseif type == SORT_TYPE.DESC_BY_PRICE then
  403. table.sort(goods, function(a, b)
  404. return a.totalprice > b.totalprice
  405. end)
  406. end
  407. end
  408. -- 购买世界交易行商品
  409. -- msgData 中要包含 itemcfgid,itemId,type,count
  410. function Trade.bugWorldGoods(actor, msgData)
  411. local buyCount = msgData[4]
  412. local itemId = msgData[2]
  413. local goodRid = msgData[5]
  414. local goodActor = getactor(actor, goodRid)
  415. local allWorldGoods = getsysvar(goodActor, SYS_TRADE_WORLD_GOODS)
  416. if not allWorldGoods then
  417. noticeTip.noticeinfo(actor, StringIdConst.TEXT372)
  418. return
  419. end
  420. local roleAllGoods = allWorldGoods[tostring(goodRid)]
  421. if not roleAllGoods then
  422. noticeTip.noticeinfo(actor, StringIdConst.TEXT372)
  423. return
  424. end
  425. local goodsDetail = roleAllGoods[tostring(itemId)]
  426. if not goodsDetail then
  427. noticeTip.noticeinfo(actor, StringIdConst.TEXT373)
  428. return
  429. end
  430. local publicityTime = goodsDetail.listingtime + goodsDetail.publicitytime
  431. local now = getbaseinfo("now")
  432. if now < publicityTime then
  433. noticeTip.noticeinfo(actor, StringIdConst.TEXT377)
  434. return
  435. end
  436. local ownid = goodsDetail.ownid
  437. if actor:toString() == tostring(ownid) then
  438. noticeTip.noticeinfo(actor, StringIdConst.TEXT378)
  439. return
  440. end
  441. local unitPrice = goodsDetail.unitPrice
  442. local price = unitPrice * buyCount
  443. local cointype = goodsDetail.cointype
  444. local ownActor = getactor(actor, ownid)
  445. local itemCount = goodsDetail.count
  446. if tonumber(cointype) == 30030305 then
  447. local delete = MonthCard.deleteTime(actor, price)
  448. if not delete then
  449. return
  450. end
  451. else
  452. local haveCount = getbagitemcountbyid(actor, cointype)
  453. if haveCount < price then
  454. noticeTip.noticeinfo(actor, StringIdConst.TEXT379)
  455. return
  456. end
  457. removeitemfrombag(actor, cointype, price,0,9999,'交易行')
  458. end
  459. shelltobag(ownActor, ownid, itemId, buyCount, actor:toString(), 106004, goodsDetail.itemname)
  460. this.changeGoodsInfo(ownActor, itemId, itemCount, buyCount)
  461. local afterTaxPrice = this.calculationTax(ownActor, goodsDetail, buyCount)
  462. sendconfigmailbyrid(ownActor, ownid, 106011, { [tonumber(cointype)] = tonumber(afterTaxPrice) }, goodsDetail.itemname)
  463. this.saveTradeHistory(actor, TRADE_RECORD_TYPE.PURCHASE, goodsDetail, price)
  464. this.saveTradeHistory(ownActor, TRADE_RECORD_TYPE.SALE, goodsDetail, afterTaxPrice)
  465. sendluamsg(actor, LuaMessageIdToClient.RES_TRADE_BUY_GOODS, true)
  466. Trade.changeItemInfo(actor, ownid, itemId)
  467. end
  468. -- 计算税率
  469. function this.calculationTax(ownActor, goodsDetail, count)
  470. local unitPrice = goodsDetail.unitPrice
  471. local totalPrice = unitPrice * count
  472. local table = goodsDetail.tax
  473. local tax = tonumber(table[1])
  474. local has_vip, vip_rate = VipGiftPack.hasPrivilege(ownActor, VipPrivilege.Type.tax)
  475. if has_vip and string.tonumber(vip_rate) > 0 then
  476. tax = tax * (100 - tonumber(vip_rate)) / 100
  477. tax = math.round(tax)
  478. end
  479. totalPrice = totalPrice * (100 - tax) / 100
  480. totalPrice = math.round(totalPrice)
  481. local deleteCount = tonumber(table[2])
  482. if has_vip then
  483. local addCount = math.round((deleteCount * tonumber(vip_rate)) / 100)
  484. deleteCount = deleteCount - addCount
  485. end
  486. totalPrice = totalPrice - deleteCount
  487. return totalPrice
  488. end
  489. -- 保存交易记录
  490. function this.saveTradeHistory(actor, type, goodsDetail, totalPrice)
  491. local tradeRecorde = getplaydef(actor, ROLE_TRADE_GOODS_RECORD)
  492. if not tradeRecorde then
  493. tradeRecorde = {}
  494. end
  495. ---type Trade.Recorde 交易记录
  496. local goodRecord = {
  497. itemname = goodsDetail.itemname,
  498. time = getbaseinfo("now"),
  499. tradetype = type,
  500. cointype = goodsDetail.cointype,
  501. price = totalPrice
  502. }
  503. if type == 2 then
  504. end
  505. table.insert(tradeRecorde, goodRecord)
  506. setplaydef(actor, ROLE_TRADE_GOODS_RECORD, tradeRecorde)
  507. end
  508. function cleartradehistory(actor)
  509. local tradeRecorde = getplaydef(actor, ROLE_TRADE_GOODS_RECORD)
  510. tradeRecorde = {}
  511. setplaydef(actor, tradeRecorde)
  512. end
  513. ---@class Trade.Recorde 交易记录
  514. ---@field itemname string 商品名字
  515. ---@field time number 成交时间
  516. ---@field tradetype number 成交类型
  517. ---@field cointype number 货币类型
  518. ---@field price number 成交价格
  519. -- 获取我的交易记录
  520. function Trade.getWorldTradeRecord(actor)
  521. local tradeRecorde = getplaydef(actor, ROLE_TRADE_GOODS_RECORD)
  522. sendluamsg(actor, LuaMessageIdToClient.RES_TRADE_RECORD, tradeRecorde)
  523. end
  524. -- 获取我上架商品
  525. function Trade.getWorldMyListing(actor)
  526. local listingGood = {}
  527. local capacity = ConfigDataManager.getTableValue("cfg_global", "value", "id", TRADE_CAPACITY_GLOBAL_ID)
  528. local is_has, count = PrivilegeMonth.hasPrivilege(actor, PrivilegeMonth.PrivilegeType.TRADE_LINE_UP_COUNT_INCREASE)
  529. capacity = capacity + count
  530. listingGood["capacity"] = capacity
  531. local allgoods = {}
  532. local stallInfo = Stall.getStallTimeInfo(actor)
  533. if not stallInfo then
  534. stallInfo = {}
  535. end
  536. sendluamsg(actor, LuaMessageIdToClient.RES_STALL_INFO, stallInfo)
  537. local allWorldGoods = getsysvar(actor, SYS_TRADE_WORLD_GOODS)
  538. if not allWorldGoods then
  539. local roleWorld = {}
  540. listingGood["number"] = 0
  541. listingGood["allgoods"] = roleWorld
  542. sendluamsg(actor, LuaMessageIdToClient.RES_TRADE_MY_SHELVES, listingGood)
  543. -- noticeTip.noticeinfo(actor, StringIdConst.TEXT372)
  544. return
  545. end
  546. local roleWorld = allWorldGoods[actor:toString()]
  547. -- local roleWorld = getplaydef(actor, ROLE_TRADE_WORLD_GOODS)
  548. if not roleWorld then
  549. roleWorld = {}
  550. listingGood["number"] = 0
  551. listingGood["allgoods"] = roleWorld
  552. sendluamsg(actor, LuaMessageIdToClient.RES_TRADE_MY_SHELVES, listingGood)
  553. return
  554. end
  555. local now = getbaseinfo("now")
  556. for index, good in pairs(roleWorld) do
  557. local publicityTime = good.listingtime + good.publicitytime
  558. local offShelfTime = publicityTime + good.upshelfduration
  559. if publicityTime > now then
  560. good["publicity"] = 1
  561. good["timename"] = "公示中"
  562. good["time"] = (publicityTime - now) / 1000
  563. elseif publicityTime < now and offShelfTime > now then
  564. good["publicity"] = 0
  565. good["timename"] = "下架时间"
  566. good["time"] = (offShelfTime - now) / 1000
  567. end
  568. table.insert(allgoods, good)
  569. end
  570. if allgoods then
  571. Trade.sortGoods(allgoods, 0)
  572. end
  573. listingGood["number"] = #allgoods
  574. listingGood["allgoods"] = allgoods
  575. jprint("listingGood",listingGood)
  576. sendluamsg(actor, LuaMessageIdToClient.RES_TRADE_MY_SHELVES, listingGood)
  577. end
  578. -- 预购商品
  579. -- msgData 中要包含 itemcfgid,itemId,type
  580. function Trade.preWorldGoods(actor, msgData)
  581. local itemId = msgData[2]
  582. local goodRid = msgData[4]
  583. local goodActor = getactor(actor, goodRid)
  584. local allWorldGoods = getsysvar(goodActor, SYS_TRADE_WORLD_GOODS)
  585. if not allWorldGoods then
  586. noticeTip.noticeinfo(actor, StringIdConst.TEXT372)
  587. return
  588. end
  589. local roleAllGoods = allWorldGoods[tostring(goodRid)]
  590. if not roleAllGoods then
  591. noticeTip.noticeinfo(actor, StringIdConst.TEXT372)
  592. return
  593. end
  594. local goodsDetail = roleAllGoods[tostring(itemId)]
  595. if not goodsDetail then
  596. noticeTip.noticeinfo(actor, StringIdConst.TEXT373)
  597. return
  598. end
  599. local publicityTime = goodsDetail.listingtime + goodsDetail.publicitytime
  600. local now = getbaseinfo("now")
  601. if now > publicityTime then
  602. noticeTip.noticeinfo(actor, StringIdConst.TEXT380)
  603. return
  604. end
  605. local ownid = goodsDetail.ownid
  606. if actor:toString() == tostring(ownid) then
  607. noticeTip.noticeinfo(actor, StringIdConst.TEXT381)
  608. return
  609. end
  610. local peroreder = goodsDetail.peroreder
  611. if peroreder then
  612. for index, preRid in pairs(peroreder) do
  613. if tostring(preRid) == actor:toString() then
  614. noticeTip.noticeinfo(actor, StringIdConst.TEXT382)
  615. return
  616. end
  617. end
  618. end
  619. local totalprice = goodsDetail.totalprice
  620. local cointype = goodsDetail.cointype
  621. if tonumber(cointype) == 30030305 then
  622. local delete = MonthCard.deleteTime(actor, totalprice)
  623. if not delete then
  624. return
  625. end
  626. else
  627. local haveCount = getbagitemcountbyid(actor, cointype)
  628. if haveCount < totalprice then
  629. noticeTip.noticeinfo(actor, StringIdConst.TEXT379)
  630. return
  631. end
  632. removeitemfrombag(actor, cointype, totalprice,0,9999,'交易行')
  633. end
  634. this.addPre(goodActor, itemId, goodRid, actor)
  635. local preGoodInfo = getplaydef(actor, ROLE_TRADE_PRE_GOODS)
  636. if not preGoodInfo then
  637. preGoodInfo = {}
  638. end
  639. local perGoodInfo = {
  640. rid = goodRid,
  641. goodId = itemId
  642. }
  643. table.insert(preGoodInfo, perGoodInfo)
  644. setplaydef(actor, ROLE_TRADE_PRE_GOODS, preGoodInfo)
  645. this.saveTradeHistory(actor, TRADE_RECORD_TYPE.PREORDER, goodsDetail, totalprice)
  646. sendluamsg(actor, LuaMessageIdToClient.RES_TRADE_PRE_ORDER, true)
  647. end
  648. -- 商品中添加预购信息
  649. function this.addPre(actor, goodId, goodRid, preActor)
  650. local allWorldGoods = getsysvar(actor, SYS_TRADE_WORLD_GOODS)
  651. local roleAllGoods = allWorldGoods[tostring(goodRid)]
  652. local goodsDetail = roleAllGoods[tostring(goodId)]
  653. local peroreder = goodsDetail.peroreder
  654. if not peroreder then
  655. peroreder = {}
  656. end
  657. table.insert(peroreder, preActor:toString())
  658. goodsDetail.peroreder = peroreder
  659. -- allWorldGoods[tostring(goodId)] = goodsDetail
  660. setsysvar(actor, SYS_TRADE_WORLD_GOODS, allWorldGoods)
  661. --local ownid = goodsDetail.ownid
  662. --local ownActor = getactor(actor, ownid)
  663. --local myListingGoods = getplaydef(ownActor, ROLE_TRADE_WORLD_GOODS)
  664. --local detail = myListingGoods[tostring(goodId)]
  665. --local goodPre = detail.peroreder
  666. --if not goodPre then
  667. -- goodPre = {}
  668. --end
  669. --table.insert(goodPre, actor:toString())
  670. --detail.peroreder = goodPre
  671. --myListingGoods[tostring(goodId)] = detail
  672. --setplaydef(ownActor, ROLE_TRADE_WORLD_GOODS, myListingGoods)
  673. end
  674. -- 交易行刷新
  675. function Trade.flushWorldGoods()
  676. local serverType = getbaseinfo("servertype")
  677. if serverType == 2 then
  678. -- 跨服服务器不执行
  679. return
  680. end
  681. local allWorldGoods = getsysvar(SYS_TRADE_WORLD_GOODS)
  682. if not allWorldGoods then
  683. return
  684. end
  685. local now = getbaseinfo("now")
  686. for index, roleAllGoods in pairs(allWorldGoods) do
  687. for index, good in pairs(roleAllGoods) do
  688. if good and good.listingtime and good.publicitytime then
  689. local publicityTime = good.listingtime + good.publicitytime
  690. local offShelfTime = publicityTime + good.upshelfduration
  691. if now > publicityTime and now < offShelfTime and good.publicitystatue then
  692. local peroreder = good.peroreder
  693. if not peroreder then
  694. this.changeGoodState(good, roleAllGoods)
  695. elseif peroreder then
  696. this.handlePre(good, roleAllGoods)
  697. end
  698. elseif offShelfTime < now then
  699. this.flowFilming(good, roleAllGoods)
  700. end
  701. end
  702. end
  703. end
  704. setsysvar(SYS_TRADE_WORLD_GOODS, allWorldGoods)
  705. end
  706. -- 合服时下架所有商品
  707. function Trade.combineglobalvar(varName,varData)
  708. gameDebug.print("合服时交易行全部商品信息", varData)
  709. for index, allWorldGoods in pairs(varData) do
  710. if not table.isEmpty(allWorldGoods) then
  711. for index, roleAllGoods in pairs(allWorldGoods) do
  712. for index, good in pairs(roleAllGoods) do
  713. if not table.isEmpty(good) then
  714. local peroreder = good.peroreder
  715. if table.isEmpty(peroreder) then
  716. this.flowFilming(good, roleAllGoods)
  717. else
  718. this.handlePre(good, roleAllGoods)
  719. end
  720. end
  721. end
  722. end
  723. end
  724. end
  725. setsysvar(SYS_TRADE_WORLD_GOODS, {})
  726. end
  727. -- 清理交易行脏数据
  728. function cleartradedata(actor)
  729. setsysvar(actor, SYS_TRADE_WORLD_GOODS,{})
  730. end
  731. -- 改变商品状态(公示状态改成竞拍)
  732. function this.changeGoodState(good, allWorldGoods)
  733. local ownId = good.ownid
  734. local ownActor = getactor(ownId)
  735. local allWorldGood = getsysvar(ownActor, SYS_TRADE_WORLD_GOODS)
  736. local myListingGoods = allWorldGood[ownActor:toString()]
  737. if not myListingGoods then
  738. return
  739. end
  740. local myGoodInfo = myListingGoods[tostring(good.itemid)]
  741. myGoodInfo.publicitystatue = false
  742. myListingGoods[tostring(good.itemid)] = myGoodInfo
  743. allWorldGood[ownActor:toString()] = myListingGoods
  744. setsysvar(ownActor, SYS_TRADE_WORLD_GOODS, allWorldGood)
  745. end
  746. -- 处理预购商品
  747. function this.handlePre(good, roleAllGoods)
  748. local peroreder = good.peroreder
  749. local successIndex = math.random(1, #peroreder)
  750. local successRid = peroreder[successIndex]
  751. local ownActor = getactor(good.ownid)
  752. local goodId = good.itemid
  753. -- 清理预购人员存储的信息
  754. for index, preRid in pairs(peroreder) do
  755. if tostring(successRid) ~= tostring(preRid) then
  756. local preActor = getactor(preRid)
  757. local myPreInfo = getplaydef(preActor, ROLE_TRADE_PRE_GOODS)
  758. if not table.isEmpty(myPreInfo) then
  759. local preIndex = this.findPreInfo(myPreInfo, tostring(goodId), tostring(good.ownid))
  760. if preIndex then
  761. table.remove(myPreInfo, preIndex)
  762. setplaydef(preActor, ROLE_TRADE_PRE_GOODS, myPreInfo)
  763. end
  764. end
  765. if tonumber(good.cointype) == 30030305 then
  766. MonthCard.addTime(ownActor, good.totalprice)
  767. else
  768. sendconfigmailbyrid(ownActor, preRid, 106006, { [tonumber(good.cointype)] = tonumber(good.totalprice) }, good.itemname .. "#" .. "货币")
  769. end
  770. end
  771. end
  772. local successActor = getactor(successRid)
  773. -- this.changeGoodsInfo(ownActor,itemId,itemCount,buyCount)
  774. local afterTaxPrice = this.calculationTax(ownActor, good, good.count)
  775. sendconfigmailbyrid(ownActor, good.ownid, 106011, { [tonumber(good.cointype)] = tonumber(afterTaxPrice) }, good.itemname)
  776. shelltobag(ownActor, good.ownid, goodId, good.count, successRid, 106004, good.itemname)
  777. roleAllGoods[tostring(good.itemid)] = nil
  778. -- this.saveTradeHistory(actor,TRADE_RECORD_TYPE.PURCHASE,goodsDetail,price)
  779. this.saveTradeHistory(ownActor, TRADE_RECORD_TYPE.SALE, good, afterTaxPrice)
  780. Trade.changeItemInfo(successActor, good.ownid, goodId)
  781. end
  782. -- 获取预购商品索引
  783. function this.findPreInfo(myPreInfo, goodId, rid)
  784. for index, preInfo in pairs(myPreInfo) do
  785. if tostring(preInfo.goodId) == tostring(goodId) and tostring(preInfo.rid) == tostring(rid) then
  786. return index
  787. end
  788. end
  789. end
  790. -- 商品流拍
  791. function this.flowFilming(good, roleAllGoods)
  792. local ownId = good.ownid
  793. local ownActor = getactor(ownId)
  794. if not roleAllGoods then
  795. return
  796. end
  797. shelltobag(ownActor, ownActor:toString(), good.itemid, good.count, ownActor:toString())
  798. roleAllGoods[tostring(good.itemid)] = nil
  799. end
  800. -- 发送充值消息
  801. function Trade.sendRecharge(actor)
  802. local allRechargeInfo = getsysvar(actor, SYS_RECHARGE_INFO)
  803. if table.isEmpty(allRechargeInfo) then
  804. allRechargeInfo = {}
  805. end
  806. local rechargeInfo = allRechargeInfo[actor:toString()]
  807. sendluamsg(actor, LuaMessageIdToClient.RES_RECHARGE_TRADE_INFO, rechargeInfo)
  808. end
  809. -- 午夜刷新重置记录
  810. function Trade.serverMiddleNight()
  811. local allRechargeInfo = getsysvar(SYS_RECHARGE_INFO)
  812. if table.isEmpty(allRechargeInfo) then
  813. return
  814. end
  815. local now = getbaseinfo("now")
  816. for index, roleRechargeInfo in pairs(allRechargeInfo) do
  817. local actor = getactor(index)
  818. local rechargeGear = ConfigDataManager.getTable("cfg_lines", "id", roleRechargeInfo.gearPosition)
  819. if rechargeGear then
  820. local currentGearInfo = rechargeGear[1]
  821. local decayTime = tonumber(currentGearInfo.decaytime)
  822. local lsatGearChangeTime = roleRechargeInfo.lsatGearChangeTime
  823. local decay = lsatGearChangeTime + decayTime * 24 * 60 * MINUTE_SECOND
  824. if decay < now then
  825. -- 降档处理
  826. local decayGears = tonumber(currentGearInfo.decaygears)
  827. if roleRechargeInfo.gearPosition ~= 1 then
  828. roleRechargeInfo.gearPosition = decayGears
  829. roleRechargeInfo.lsatGearChangeTime = now
  830. local limit = this.calculationGearMaxLimit(nil, decayGears)
  831. roleRechargeInfo.upperLimit = limit
  832. end
  833. roleRechargeInfo.quit = true
  834. roleRechargeInfo.gearRecharge = 0
  835. if tonumber(currentGearInfo.decaytime) > 1 then
  836. roleRechargeInfo.bubble = false
  837. else
  838. roleRechargeInfo.bubble = true
  839. end
  840. else
  841. -- 不降档位检查是否要显示气泡
  842. local time = lsatGearChangeTime + (decayTime - 1) * 24 * 60 * MINUTE_SECOND
  843. if time < now then
  844. roleRechargeInfo.bubble = true
  845. else
  846. roleRechargeInfo.bubble = false
  847. end
  848. end
  849. roleRechargeInfo.cost = 0
  850. allRechargeInfo[index] = roleRechargeInfo
  851. end
  852. sendluamsg(actor, LuaMessageIdToClient.RES_RECHARGE_TRADE_INFO, roleRechargeInfo)
  853. end
  854. setsysvar(SYS_RECHARGE_INFO, allRechargeInfo)
  855. end
  856. ---@class recharge 充值记录
  857. ---@field totalRecharge number 总共充值金额
  858. ---@field lastRechargeTime number 上次充值时间(毫秒时间戳)
  859. ---@field gearPosition number 当前档位
  860. ---@field gearRecharge number 档位充值金额
  861. ---@field quit boolean 是否退档
  862. ---@field lsatGearChangeTime number 重置档位时间
  863. ---@field cost number 花费额度
  864. ---@field upperLimit number 额度上限
  865. ---@field bubble boolean 是否显示气泡
  866. SYS_RECHARGE_INFO = "R$rechargeInfo"
  867. function tsetrechargegear(actor)
  868. Trade.recharge(actor, 1)
  869. end
  870. -- 检查当前额度是否够
  871. function Trade.checkCost(actor, price)
  872. local allRechargeInfo = getsysvar(actor, SYS_RECHARGE_INFO)
  873. if table.isEmpty(allRechargeInfo) then
  874. allRechargeInfo = {}
  875. end
  876. local rechargeInfo = allRechargeInfo[actor:toString()]
  877. if table.isEmpty(rechargeInfo) then
  878. noticeTip.noticeinfo(actor, StringIdConst.TEXT462)
  879. return false
  880. end
  881. local cost = rechargeInfo.cost
  882. local upperLimit = rechargeInfo.upperLimit
  883. if upperLimit >= cost + price then
  884. return true
  885. else
  886. noticeTip.noticeinfo(actor, StringIdConst.TEXT462)
  887. return false
  888. end
  889. end
  890. -- 增加花费
  891. function Trade.addCost(actor, price)
  892. local allRechargeInfo = getsysvar(actor, SYS_RECHARGE_INFO)
  893. if table.isEmpty(allRechargeInfo) then
  894. allRechargeInfo = {}
  895. end
  896. local rechargeInfo = allRechargeInfo[actor:toString()]
  897. if table.isEmpty(rechargeInfo) then
  898. return
  899. end
  900. rechargeInfo.cost = rechargeInfo.cost + price
  901. allRechargeInfo[actor:toString()] = rechargeInfo
  902. setsysvar(actor, SYS_RECHARGE_INFO, allRechargeInfo)
  903. end
  904. -- 减少花费
  905. function Trade.deleteCost(actor, price)
  906. local allRechargeInfo = getsysvar(actor, SYS_RECHARGE_INFO)
  907. if table.isEmpty(allRechargeInfo) then
  908. allRechargeInfo = {}
  909. end
  910. local rechargeInfo = allRechargeInfo[actor:toString()]
  911. if table.isEmpty(rechargeInfo) then
  912. return
  913. end
  914. if rechargeInfo.cost > price then
  915. rechargeInfo.cost = rechargeInfo.cost - price
  916. else
  917. rechargeInfo.cost = 0
  918. end
  919. allRechargeInfo[actor:toString()] = rechargeInfo
  920. setsysvar(actor, SYS_RECHARGE_INFO, allRechargeInfo)
  921. end
  922. -- 更新充值信息
  923. function Trade.recharge(actor, cfg, count, amount, ext, outRewards)
  924. local allRechargeInfo = getsysvar(actor, SYS_RECHARGE_INFO)
  925. if table.isEmpty(allRechargeInfo) then
  926. allRechargeInfo = {}
  927. end
  928. local rechargeInfo = allRechargeInfo[actor:toString()]
  929. if table.isEmpty(rechargeInfo) then
  930. rechargeInfo = {
  931. totalRecharge = amount,
  932. lastRechargeTime = getbaseinfo(actor, "now"),
  933. gearPosition = this.getRechargeGear(actor, amount),
  934. gearRecharge = 0,
  935. quit = false,
  936. lsatGearChangeTime = getbaseinfo(actor, "now"),
  937. cost = 0,
  938. upperLimit = 0,
  939. bubble = false
  940. }
  941. local upperLimit = this.calculationUpperLimit(actor, rechargeInfo.gearPosition, rechargeInfo.totalRecharge, rechargeInfo.quit)
  942. rechargeInfo.upperLimit = upperLimit
  943. allRechargeInfo[actor:toString()] = rechargeInfo
  944. setsysvar(actor, SYS_RECHARGE_INFO, allRechargeInfo)
  945. sendluamsg(actor, LuaMessageIdToClient.RES_RECHARGE_TRADE_INFO, rechargeInfo)
  946. return
  947. end
  948. -- 已经充值过逻辑处理
  949. rechargeInfo.totalRecharge = rechargeInfo.totalRecharge + amount
  950. rechargeInfo.lastRechargeTime = getbaseinfo(actor, "now")
  951. local gearPosition = rechargeInfo.gearPosition
  952. local rechargeGear = ConfigDataManager.getTable("cfg_lines", "id", gearPosition)
  953. if not rechargeGear then
  954. -- error("当前充值档位出现错误")
  955. return
  956. end
  957. local gearInfo = rechargeGear[1]
  958. local activationRecharge = tonumber(gearInfo.activationrecharge)
  959. local allRecharge = rechargeInfo.gearRecharge + amount
  960. if rechargeInfo.quit then
  961. -- 有退档现象,检查是否可以提升档位
  962. if allRecharge >= activationRecharge then
  963. -- 可以提升档位
  964. local maxGear = this.getRechargeGear(actor, rechargeInfo.totalRecharge)
  965. rechargeInfo.gearPosition = maxGear
  966. rechargeInfo.gearRecharge = 0
  967. rechargeInfo.quit = false
  968. local upperLimit = this.calculationUpperLimit(actor, maxGear, rechargeInfo.totalRecharge, false)
  969. rechargeInfo.upperLimit = upperLimit
  970. else
  971. -- 不能提升档位
  972. rechargeInfo.gearRecharge = rechargeInfo.gearRecharge + amount
  973. end
  974. else
  975. -- 没有发生过退档
  976. if allRecharge >= activationRecharge then
  977. -- 可以提升档位
  978. local maxGear = this.getRechargeGear(actor, rechargeInfo.totalRecharge)
  979. rechargeInfo.gearPosition = maxGear
  980. rechargeInfo.gearRecharge = 0
  981. rechargeInfo.quit = false
  982. else
  983. -- 不能提升档位
  984. rechargeInfo.gearRecharge = rechargeInfo.gearRecharge + amount
  985. end
  986. local upperLimit = this.calculationUpperLimit(actor, rechargeInfo.gearPosition, rechargeInfo.totalRecharge, false)
  987. rechargeInfo.upperLimit = upperLimit
  988. end
  989. rechargeInfo.lsatGearChangeTime = getbaseinfo(actor, "now")
  990. rechargeInfo.bubble = false
  991. allRechargeInfo[actor:toString()] = rechargeInfo
  992. setsysvar(actor, SYS_RECHARGE_INFO, allRechargeInfo)
  993. -- 发送lua信息
  994. sendluamsg(actor, LuaMessageIdToClient.RES_RECHARGE_TRADE_INFO, rechargeInfo)
  995. end
  996. -- 获取充值最高档位
  997. function this.getRechargeGear(actor, totalRecharge)
  998. local rechargeGear = ConfigDataManager.getTable("cfg_lines")
  999. if table.isEmpty(rechargeGear) then
  1000. return 0
  1001. end
  1002. local maxGear = 0
  1003. for index, gear in pairs(rechargeGear) do
  1004. local interval = gear.interval
  1005. local intervalTable = string.split(interval, "#")
  1006. local minRecharge = tonumber(intervalTable[1])
  1007. local maxRecharge = tonumber(intervalTable[2])
  1008. if tonumber(gear.id) > maxGear then
  1009. maxGear = tonumber(gear.id)
  1010. end
  1011. if totalRecharge >= minRecharge and totalRecharge <= maxRecharge then
  1012. return tonumber(gear.id)
  1013. end
  1014. end
  1015. return maxGear
  1016. end
  1017. -- 计算额度上限.
  1018. function this.calculationUpperLimit(actor, gear, totalRecharge, quit)
  1019. if quit then
  1020. return this.calculationGearMaxLimit(actor, gear)
  1021. else
  1022. return this.calculationAllMaxLimit(actor, gear, totalRecharge)
  1023. end
  1024. end
  1025. -- 计算档位的最大限额
  1026. function this.calculationGearMaxLimit(actor, currentGear)
  1027. if currentGear < 1 then
  1028. return 0
  1029. end
  1030. local rechargeGear = ConfigDataManager.getTable("cfg_lines")
  1031. if table.isEmpty(rechargeGear) then
  1032. return 0
  1033. end
  1034. local limit = 0
  1035. for index, gear in pairs(rechargeGear) do
  1036. if currentGear >= tonumber(gear.id) then
  1037. local interval = gear.interval
  1038. local intervalTable = string.split(interval, "#")
  1039. local minRecharge = tonumber(intervalTable[1])
  1040. local maxRecharge = tonumber(intervalTable[2])
  1041. local each = tonumber(gear.each)
  1042. local quotaLimit = tonumber(gear.quotalimit)
  1043. local gearLimit = math.ceil((maxRecharge - minRecharge + 1) / each) * quotaLimit
  1044. limit = limit + gearLimit
  1045. end
  1046. end
  1047. return limit
  1048. end
  1049. -- 计算总共充值的最大额度
  1050. function this.calculationAllMaxLimit(actor, currentGear, totalRecharge)
  1051. local rechargeGear = ConfigDataManager.getTable("cfg_lines", "id", currentGear)
  1052. if table.isEmpty(rechargeGear) then
  1053. -- error("当前充值档位出现错误")
  1054. end
  1055. local currentGearInfo = rechargeGear[1]
  1056. local interval = currentGearInfo.interval
  1057. local intervalTable = string.split(interval, "#")
  1058. local minRecharge = tonumber(intervalTable[1])
  1059. local each = tonumber(currentGearInfo.each)
  1060. local quotaLimit = tonumber(currentGearInfo.quotalimit)
  1061. local currentPrice = totalRecharge - minRecharge + 1
  1062. local gearLimit = math.ceil(currentPrice / each) * quotaLimit
  1063. local gear = currentGear - 1
  1064. local allLimit = this.calculationGearMaxLimit(actor, gear)
  1065. return gearLimit + allLimit
  1066. end
  1067. -- ------------------------------旧方法------------------------------------------------------------------------
  1068. -- 战盟boss上架交易行
  1069. function Trade.unionListGoods(actor, activityId, closetDay, listingGoods, myHurtMember, allianceId)
  1070. for index, goods in pairs(listingGoods) do
  1071. local itemCfgId = goods["itemcfgid"]
  1072. local stallInfo = ConfigDataManager.getTable("cfg_stall", "id", itemCfgId, "startday", closetDay, "way", TRADE_WAY.GARD_BOSS)
  1073. if not stallInfo then
  1074. noticeTip.noticeinfo(actor, StringIdConst.TEXT383)
  1075. return
  1076. end
  1077. local itemStall = stallInfo[1]
  1078. local job = itemStall["job"]
  1079. goods["job"] = job
  1080. local time = itemStall["time"]
  1081. goods["time"] = time
  1082. local money = itemStall["money"]
  1083. goods["money"] = money
  1084. local fixedPrice = itemStall["fixedprice"]
  1085. goods["fixedPrice"] = fixedPrice
  1086. local startingPrice = itemStall["startingprice"]
  1087. goods["startingPrice"] = startingPrice
  1088. local auction = itemStall["auction"]
  1089. goods["auction"] = auction
  1090. local type = itemStall["type"]
  1091. local subtype = itemStall["subtype"]
  1092. goods["type"] = type
  1093. goods["subtype"] = subtype
  1094. goods["position"] = tostring(TRADE_WAY.GARD_BOSS)
  1095. end
  1096. uniontradelisting(actor, activityId, listingGoods, myHurtMember, allianceId)
  1097. end
  1098. -- 战盟boss竞价
  1099. function unionListGoods(actor, activityId, listingGoods)
  1100. for index, goods in pairs(listingGoods) do
  1101. local itemCfgId = goods["itemcfgid"]
  1102. local stallInfo = ConfigDataManager.getTable("cfg_stall", "id", itemCfgId, "way", TRADE_WAY.GARD_BOSS)
  1103. if not stallInfo then
  1104. noticeTip.noticeinfo(actor, StringIdConst.TEXT383)
  1105. return
  1106. end
  1107. local itemStall = stallInfo[1]
  1108. local job = itemStall["job"]
  1109. goods["job"] = job
  1110. local money = itemStall["money"]
  1111. goods["money"] = money
  1112. local fixedPrice = itemStall["fixedPrice"]
  1113. goods["fixedPrice"] = fixedPrice
  1114. local startingPrice = itemStall["startingPrice"]
  1115. goods["startingPrice"] = startingPrice
  1116. local auction = itemStall["auction"]
  1117. goods["auction"] = auction
  1118. local type = itemStall["type"]
  1119. local subtype = itemStall["subtype"]
  1120. goods["type"] = type
  1121. goods["subtype"] = subtype
  1122. goods["position"] = tostring(TRADE_WAY.GARD_BOSS)
  1123. end
  1124. uniontradelisting(actor, activityId, listingGoods)
  1125. end
  1126. -- 获取世界商品 商品配置id 商品id
  1127. function Trade.getGoodsInfo(actor, msgData)
  1128. -- jprint("msgData",msgData)
  1129. local ownActor = getactor(actor, msgData[2])
  1130. goodsdetailinfo(ownActor, msgData[1], TRADE_WAY.WORLD_UP, actor:toString())
  1131. end
  1132. -- 购买成功后交换lua中存储的道具信息
  1133. function Trade.changeItemInfo(actor, ownId, itemId)
  1134. local ownActor = getactor(actor, ownId)
  1135. local allequip = getplaydef(ownActor, "T$luaitemextdata")
  1136. if not allequip then
  1137. return
  1138. end
  1139. local equipext = allequip[itemId]
  1140. if not equipext then
  1141. return
  1142. end
  1143. local allEquipActor = getplaydef(actor, "T$luaitemextdata")
  1144. if not allEquipActor then
  1145. allEquipActor = {}
  1146. end
  1147. allEquipActor[itemId] = equipext
  1148. -- EquipAndAppear.SetItemExtData(actor, itemId, equipext)
  1149. setplaydef(actor, "T$luaitemextdata", allEquipActor)
  1150. allequip[itemId] = nil
  1151. setplaydef(ownActor, "T$luaitemextdata", allequip)
  1152. end
  1153. function getroletet(actor)
  1154. local actorId = getactor(actor,"18023607160522752")
  1155. local name = getbaseinfo(actorId,"rolename")
  1156. jprint("name",name)
  1157. end
  1158. local TRADE_DATA_REPAIR = "T$_TRADE_DATA_REPAIR"
  1159. function Trade.login(actor)
  1160. RepairRoleData.action(actor, TRADE_DATA_REPAIR, 20250115, this.TradeDataRepair_2025_01_15, actor)
  1161. end
  1162. function this.TradeDataRepair_2025_01_15(actor)
  1163. local allWorldGoods = getsysvar(actor, SYS_TRADE_WORLD_GOODS)
  1164. if table.isNullOrEmpty(allWorldGoods) then
  1165. shellclean(actor)
  1166. return
  1167. end
  1168. local roleWorld = allWorldGoods[actor:toString()]
  1169. if table.isNullOrEmpty(roleWorld) then
  1170. shellclean(actor)
  1171. return
  1172. end
  1173. local allItemId = {}
  1174. for index, good in pairs(roleWorld) do
  1175. local itemId = good.itemid
  1176. table.insert(allItemId, itemId)
  1177. end
  1178. shellclean(actor,allItemId)
  1179. end
  1180. --TODO 一定要放到文件最后
  1181. --注册充值事件
  1182. -- RechargeEventListerTable:eventLister("0", "交易行", Trade.recharge)