Transaction.lua 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. Transaction = {}
  2. local this = Transaction
  3. local filename = "Transaction"
  4. -- 限制只能对一个人发起交易请求.只有最新的申请会生效.交易申请会有5秒的cd.
  5. SYS_TRANSACTIONS = "R$transaction_transactions"
  6. SYS_TRANSACTIONS_STATUS = "R$transaction_transactions_status"
  7. function Transaction.onLoginEnd(actor)
  8. local info = Transaction.getInfo(actor)
  9. if table.count(info) <= 0 then
  10. return
  11. end
  12. local rid = getbaseinfo(actor, "rid")
  13. local ttInfo = Transaction.getTTInfo(actor)
  14. if table.count(ttInfo) > 0 and tostring(ttInfo.targetId) == tostring(rid) then
  15. local targetActor = getactor(actor, ttInfo.targetId)
  16. if targetActor ~= nil then
  17. -- 重登取消交易
  18. sendluamsg(
  19. targetActor,
  20. LuaMessageIdToSever.TransactionInfo_MsgID,
  21. {
  22. type = 30,
  23. rid = rid
  24. }
  25. )
  26. end
  27. end
  28. end
  29. function Transaction.onReloadScript(actor)
  30. end
  31. function Transaction.CheckStatus(actor, rid, msgid, status)
  32. return true
  33. -- local nowsec = getbaseinfo(actor, "nowsec")
  34. -- local playerTransactionInfo = transactions[rid]
  35. -- if playerTransactionInfo == nil or nowsec - playerTransactionInfo.sec > 30 then
  36. -- sendluamsg(actor, msgid, {
  37. -- type = 101,
  38. -- status = status
  39. -- })
  40. -- return false
  41. -- end
  42. -- local targetTransactionInfo = transactions[playerTransactionInfo.targetId]
  43. -- if targetTransactionInfo == nil or targetTransactionInfo.targetId ~= rid or nowsec - targetTransactionInfo.sec > 30 then
  44. -- local targetActor = getactor(actor, playerTransactionInfo.targetId)
  45. -- sendluamsg(targetActor, msgid, {
  46. -- type = 101,
  47. -- status = status
  48. -- })
  49. -- return false
  50. -- end
  51. -- playerTransactionInfo.sec = nowsec
  52. -- targetTransactionInfo.sec = nowsec
  53. -- return true
  54. end
  55. function Transaction.getItemDataSimple(actor, item)
  56. -- local item2 = getitemattinfo(actor, 1, item.cfgid, item.id)
  57. local data = {
  58. id = item.id,
  59. cfgid = item.cfgid,
  60. isServerStyle = true,
  61. entries = item.entries,
  62. luaextdata = item.luaextdata,
  63. count = item.count,
  64. type = item.type,
  65. basicattr = item.basicattr,
  66. luckyattr = item.luckyattr,
  67. replacerating = item.replacerating
  68. }
  69. return data
  70. end
  71. function Transaction.getInfo(actor)
  72. local info = APIGetTable(actor, SYS_TRANSACTIONS) or {}
  73. return info
  74. end
  75. function Transaction.setInfo(actor, info)
  76. APISetTable(actor, SYS_TRANSACTIONS, info)
  77. end
  78. function Transaction.setStatus(actor, status)
  79. APISetInt(actor, SYS_TRANSACTIONS_STATUS, status)
  80. end
  81. function Transaction.getStatus(actor)
  82. return APIGetInt(actor, SYS_TRANSACTIONS_STATUS)
  83. end
  84. function Transaction.getTTInfo(actor)
  85. local info = Transaction.getInfo(actor)
  86. if info.targetId ~= nil then
  87. local targetActor = getactor(actor, info.targetId)
  88. if targetActor ~= nil then
  89. local ttInfo = Transaction.getInfo(targetActor)
  90. return ttInfo
  91. end
  92. end
  93. return {}
  94. end
  95. function Transaction.clearInfo(actor)
  96. local info = Transaction.getInfo(actor)
  97. if info.targetId ~= nil then
  98. local targetActor = getactor(actor, info.targetId)
  99. if targetActor ~= nil then
  100. Transaction.setInfo(targetActor, {})
  101. sendluamsg(
  102. targetActor,
  103. LuaMessageIdToSever.TransactionInfo_MsgID,
  104. {
  105. type = 30
  106. }
  107. )
  108. end
  109. end
  110. Transaction.setInfo(actor, {})
  111. sendluamsg(
  112. actor,
  113. LuaMessageIdToSever.TransactionInfo_MsgID,
  114. {
  115. type = 30
  116. }
  117. )
  118. end
  119. function Transaction.syncChangeData(actor)
  120. local info = Transaction.getInfo(actor)
  121. if table.count(info) <= 0 then
  122. return
  123. end
  124. sendluamsg(
  125. actor,
  126. LuaMessageIdToSever.TransactionInfo_MsgID,
  127. {
  128. type = 201
  129. }
  130. )
  131. local targetActor = getactor(actor, info.targetId)
  132. if targetActor ~= nil then
  133. sendluamsg(
  134. targetActor,
  135. LuaMessageIdToSever.TransactionInfo_MsgID,
  136. {
  137. type = 201
  138. }
  139. )
  140. end
  141. end
  142. function Transaction.onHandlereQuest(actor, msgid, sMsg)
  143. local type = sMsg.type
  144. local targetId = sMsg.rid
  145. local rid = getbaseinfo(actor, "rid")
  146. local items = sMsg.items
  147. local coin1 = sMsg.coin1
  148. local coin2 = sMsg.coin2
  149. local status = sMsg.status
  150. -- 只能修改自身数据.严谨修改对方数据.只能通过接口.通知对方数据发生了变化
  151. local ppInfo = Transaction.getInfo(actor)
  152. local targetActor = nil
  153. if ppInfo ~= nil and ppInfo.targetId ~= nil then
  154. targetActor = getactor(actor, ppInfo.targetId)
  155. end
  156. if type == 1 then
  157. local targetActor = getactor(actor, targetId)
  158. if rid == targetId then
  159. tipinfo(actor, "无法跟自己交易")
  160. return
  161. end
  162. -- 请求跟其他玩家交易
  163. local name = getbaseinfo(actor, "rolename")
  164. sendluamsg(
  165. targetActor,
  166. msgid,
  167. {
  168. type = 2,
  169. rid = rid,
  170. name = name
  171. }
  172. )
  173. elseif type == 3 then
  174. -- 自己接受交易
  175. local targetActor = getactor(actor, targetId)
  176. -- 判断交易距离
  177. local playerInfo = getplayermaininfo(actor)
  178. local targetInfo = getplayermaininfo(targetActor)
  179. if
  180. playerInfo.mapid ~= targetInfo.mapid or
  181. (math.abs(playerInfo.x - targetInfo.x) >= 4 or math.abs(playerInfo.y - targetInfo.y) >= 4)
  182. then
  183. tipinfo(actor, "距离过远,无法进行交易")
  184. tipinfo(targetActor, "距离过远,无法进行交易")
  185. return
  186. end
  187. -- 判断交易状态
  188. local playerState = getfightstate(actor)
  189. local targetState = getfightstate(actor)
  190. if playerState == 1 or targetState == 1 then
  191. tipinfo(actor, "战斗状态中,无法进行交易")
  192. tipinfo(targetActor, "战斗状态中,无法进行交易")
  193. return
  194. end
  195. local nowsec = getbaseinfo(actor, "nowsec")
  196. local ptInfo = Transaction.getInfo(actor)
  197. local ttInfo = Transaction.getInfo(targetActor)
  198. if
  199. (ptInfo ~= nil and table.count(ptInfo) > 0 and ptInfo.sec ~= nil and nowsec - ptInfo.sec < 30) or
  200. ttInfo ~= nil and table.count(ttInfo) > 0 and ttInfo.sec ~= nil and nowsec - ttInfo.sec < 30
  201. then
  202. tipinfo(actor, "交易中,无法进行交易")
  203. tipinfo(targetActor, "交易中,无法进行交易")
  204. return
  205. end
  206. -- 对方可能跟其他人交易中
  207. if ttInfo ~= nil and table.count(ttInfo) > 0 and ttInfo.targetId ~= rid then
  208. tipinfo(actor, "对方正在交易中,无法进行交易")
  209. return
  210. end
  211. -- 创建交易数据
  212. local d1 = {
  213. rid = tostring(rid),
  214. sec = nowsec,
  215. targetId = targetId,
  216. items = {},
  217. coin1 = 0,
  218. coin2 = 0
  219. }
  220. local d2 = {
  221. rid = tostring(getbaseinfo(targetActor, "rid")),
  222. sec = nowsec,
  223. targetId = rid,
  224. items = {},
  225. coin1 = 0,
  226. coin2 = 0
  227. }
  228. Transaction.setStatus(actor, 5)
  229. Transaction.setStatus(targetActor, 5)
  230. Transaction.setInfo(actor, d1)
  231. Transaction.setInfo(targetActor, d2)
  232. -- 打开交易界面
  233. sendluamsg(
  234. targetActor,
  235. msgid,
  236. {
  237. type = 4,
  238. rid = rid,
  239. name = playerInfo.name
  240. }
  241. )
  242. sendluamsg(
  243. actor,
  244. msgid,
  245. {
  246. type = 4,
  247. rid = targetId,
  248. name = targetInfo.name
  249. }
  250. )
  251. elseif type == 5 then
  252. local ptInfo = Transaction.getInfo(actor)
  253. if table.count(ptInfo) <= 0 then
  254. return
  255. end
  256. local ptstatus = Transaction.getStatus(actor)
  257. if ptstatus ~= 5 then
  258. tipinfo(actor, "当前交易状态无法更换物品")
  259. return
  260. end
  261. -- 检查背包是否有这些道具.没有的直接剔除
  262. local maxCount = 10
  263. local count = 0
  264. local realItem = {}
  265. for key, itemId in ipairs(items) do
  266. local item = getbagiteminfo(actor, itemId, 1)
  267. if item ~= nil and item.isbind ~= true and count < maxCount then
  268. count = count + 1
  269. table.insert(realItem, item)
  270. end
  271. end
  272. local coin1Num = getbagitemcountbyid(actor, 10010001)
  273. local coin2Num = getbagitemcountbyid(actor, 10020001)
  274. if coin1 > coin1Num then
  275. coin1 = coin1Num
  276. end
  277. if coin2 > coin2Num then
  278. coin2 = coin2Num
  279. end
  280. ptInfo.coin1 = coin1
  281. ptInfo.coin2 = coin2
  282. ptInfo.items = realItem
  283. ptInfo.itemCount = table.count(realItem)
  284. Transaction.setInfo(actor, ptInfo)
  285. Transaction.syncChangeData(actor)
  286. elseif type == 6 then
  287. -- 确定锁定
  288. local ptInfo = Transaction.getInfo(actor)
  289. if ptInfo == nil then
  290. tipinfo(actor, "1006#交易出错, 请重新开始交易.")
  291. return
  292. end
  293. -- Transaction.setStatus(actor, 5)
  294. -- Transaction.setStatus(targetActor, 5)
  295. local ptstatus = Transaction.getStatus(actor)
  296. if ptstatus == 7 then
  297. tipinfo(actor, "已确定交易.无法更改交易状态")
  298. return
  299. end
  300. if status ~= nil and (status == 6 or status == 5) then
  301. ptstatus = status
  302. else
  303. if ptstatus == 6 then
  304. ptstatus = 5
  305. local targetActor = getactor(actor, ptInfo.targetId)
  306. if targetActor ~= nil then
  307. Transaction.setStatus(targetActor, 5)
  308. end
  309. else
  310. ptstatus = 6
  311. end
  312. end
  313. Transaction.setStatus(actor, ptstatus)
  314. Transaction.setInfo(actor, ptInfo)
  315. Transaction.syncChangeData(actor)
  316. elseif type == 7 then
  317. -- 判断背包是否有空格
  318. -- 确定交易
  319. local ptInfo = Transaction.getInfo(actor)
  320. if ptInfo == nil then
  321. tipinfo(actor, "1007#交易出错, 请重新开始交易.")
  322. return
  323. end
  324. local ptstatus = Transaction.getStatus(actor)
  325. if ptstatus == 7 then
  326. tipinfo(actor, "交易已锁定,无法修改交易状态.")
  327. return
  328. end
  329. if ptstatus ~= 6 then
  330. tipinfo(actor, "请先锁定交易状态.")
  331. return
  332. end
  333. Transaction.setStatus(actor, 7)
  334. -- local targetActor = getactor(actor, ptInfo.targetId)
  335. -- -- 双方确定交易
  336. -- if ptInfo.status == 7 and ttInfo.status == 7 then
  337. -- Transaction.onConfirm(actor, ptInfo, ttInfo)
  338. -- -- 同步交易状态
  339. -- sendluamsg(targetActor, msgid, {
  340. -- type = 10,
  341. -- rid = rid
  342. -- })
  343. -- sendluamsg(actor, msgid, {
  344. -- type = 10,
  345. -- rid = ptInfo.targetId
  346. -- })
  347. -- return
  348. -- end
  349. Transaction.setInfo(actor, ptInfo)
  350. Transaction.syncChangeData(actor)
  351. elseif type == 30 then
  352. local ptInfo = Transaction.getInfo(actor)
  353. if ptInfo == nil then
  354. return
  355. end
  356. if ptInfo.targetId ~= nil then
  357. local targetActor = getactor(actor, ptInfo.targetId)
  358. tipinfo(targetActor, "对方已取消交易")
  359. Transaction.setInfo(targetActor, {})
  360. -- 同步交易状态
  361. sendluamsg(
  362. targetActor,
  363. msgid,
  364. {
  365. type = 30,
  366. rid = rid
  367. }
  368. )
  369. end
  370. sendluamsg(
  371. actor,
  372. msgid,
  373. {
  374. type = 30,
  375. rid = ptInfo.targetId
  376. }
  377. )
  378. Transaction.setInfo(actor, {})
  379. elseif type == 101 then
  380. -- 这里决定是否交易..因为每个玩家的数据同步都不一样.
  381. local ptInfo = Transaction.getInfo(actor)
  382. if table.count(ptInfo) <= 0 then
  383. return
  384. end
  385. local ttInfo = Transaction.getTTInfo(actor)
  386. if table.count(ttInfo) <= 0 then
  387. return
  388. end
  389. local ptstatus = Transaction.getStatus(actor)
  390. local ttstatus = 0
  391. local targetActor = getactor(actor, ptInfo.targetId)
  392. if targetActor ~= nil then
  393. ttstatus = Transaction.getStatus(targetActor)
  394. end
  395. if ptstatus ~= 7 or ttstatus ~= 7 then
  396. return
  397. end
  398. Transaction.setStatus(actor, 0)
  399. Transaction.setStatus(targetActor, 0)
  400. Transaction.onConfirm(actor, ptInfo, ttInfo)
  401. -- 同步交易状态
  402. sendluamsg(
  403. targetActor,
  404. msgid,
  405. {
  406. type = 10,
  407. rid = rid
  408. }
  409. )
  410. sendluamsg(
  411. actor,
  412. msgid,
  413. {
  414. type = 10,
  415. rid = ptInfo.targetId
  416. }
  417. )
  418. elseif type == 201 then
  419. local ptInfo = Transaction.getInfo(actor)
  420. local ttInfo = Transaction.getTTInfo(actor)
  421. if tostring(ptInfo.targetId) ~= tostring(ttInfo.rid) or table.count(ptInfo) <= 0 then
  422. -- 出错了。可能多人交易。数据错乱了。
  423. sendluamsg(
  424. actor,
  425. msgid,
  426. {
  427. type = 30,
  428. rid = ptInfo.targetId
  429. }
  430. )
  431. tipinfo(actor, "1201#交易出错, 请重新开始交易.")
  432. local targetActor = getactor(actor, ttInfo.targetId)
  433. if targetActor ~= nil then
  434. -- 重登取消交易
  435. sendluamsg(
  436. targetActor,
  437. msgid,
  438. {
  439. type = 30,
  440. rid = rid
  441. }
  442. )
  443. tipinfo(targetActor, "1201#交易出错, 请重新开始交易.")
  444. end
  445. Transaction.setInfo(actor, {})
  446. return
  447. end
  448. local ptstatus = Transaction.getStatus(actor)
  449. local ttstatus = 0
  450. local targetActor = getactor(actor, ptInfo.targetId)
  451. if targetActor ~= nil then
  452. ttstatus = Transaction.getStatus(targetActor)
  453. end
  454. sendluamsg(
  455. actor,
  456. msgid,
  457. {
  458. type = 202,
  459. self = ptInfo,
  460. target = ttInfo,
  461. selfStatus = ptstatus,
  462. targetStatus = ttstatus
  463. }
  464. )
  465. end
  466. end
  467. function Transaction.mailItemsToActor(actor, ptInfo, ttInfo)
  468. local ptRid = ttInfo.targetId
  469. local ptActor = getactor(tonumber(ptRid))
  470. local playerItems = ptInfo.items
  471. local reward1 = {}
  472. local removeItems = {}
  473. for k, v in pairs(playerItems) do
  474. -- local item =
  475. local cfgItem = ConfigDataManager.getById("cfg_item", v.cfgid)
  476. if cfgItem.type == "2" then
  477. local cfgEquip = ConfigDataManager.getById("cfg_equip_entryLib", v.cfgid)
  478. if cfgEquip ~= nil then
  479. local skillInfo = v.skill
  480. if v.luaextdata == nil then
  481. v.luaextdata = {}
  482. end
  483. if v.luaextdata.skillinfo == nil then
  484. v.luaextdata.skillinfo = skillInfo
  485. end
  486. if v.luaextdata.originid == nil then
  487. v.luaextdata.originid = v.id
  488. end
  489. end
  490. end
  491. table.insert(reward1, v)
  492. local bagIdx = gainbagidxbyitemid(ptActor, v.id)
  493. table.insert(removeItems, bagIdx)
  494. end
  495. local desc = string.format("交易扣除")
  496. if table.count(reward1) > 0 then
  497. removeitembyidxlist(ptActor, removeItems, 9999, desc)
  498. sendmailbycompleteitems(ptActor, ptInfo.targetId, string.format("交易完成"), "以下是您在交易中获得的道具,请查收。", reward1)
  499. end
  500. end
  501. function Transaction.onConfirm(actor, ptInfo, ttInfo)
  502. local playerItemCount = ptInfo.itemCount or 0
  503. local targetItemCount = ttInfo.itemCount or 0
  504. local playerItems = ptInfo.items
  505. local targetItems = ttInfo.items
  506. local ptRid = ttInfo.targetId
  507. local ttRid = ptInfo.targetId
  508. if tostring(ptRid) == tostring(ttRid) then
  509. messagebox(actor, "无法跟自己交易")
  510. return
  511. end
  512. local ptActor = getactor(actor, ptRid)
  513. local ttActor = getactor(actor, ttRid)
  514. local playerName = getbaseinfo(ptActor, "rolename")
  515. local targetName = getbaseinfo(ttActor, "rolename")
  516. if table.count(playerItems) ~= playerItemCount or table.count(targetItems) ~= targetItemCount then
  517. messagebox(ptActor, string.format("1100#交易错误", playerName))
  518. messagebox(ttActor, string.format("1100#交易错误", playerName))
  519. Transaction.clearInfo(actor)
  520. return
  521. end
  522. -- 判断道具是否足够
  523. local coin1Num = getbagitemcountbyid(ptActor, 10010001)
  524. local coin2Num = getbagitemcountbyid(ptActor, 10020001)
  525. if ptInfo.coin1 > coin1Num or ptInfo.coin2 > coin2Num then
  526. messagebox(ptActor, string.format("%s道具数量不足", playerName))
  527. messagebox(ttActor, string.format("%s道具数量不足", playerName))
  528. Transaction.clearInfo(actor)
  529. return
  530. end
  531. coin1Num = getbagitemcountbyid(ttActor, 10010001)
  532. coin2Num = getbagitemcountbyid(ttActor, 10020001)
  533. if ttInfo.coin1 > coin1Num or ttInfo.coin2 > coin2Num then
  534. messagebox(ptActor, string.format("%s道具数量不足", targetName))
  535. messagebox(ttActor, string.format("%s道具数量不足", targetName))
  536. Transaction.clearInfo(actor)
  537. return
  538. end
  539. -- 检查物品是否还在背包中
  540. local ptCheckBag = {}
  541. for _, v in pairs(playerItems) do
  542. local paramMap = {}
  543. paramMap["cfgid"] = v.cfgid
  544. paramMap["itemcount"] = 1
  545. table.insert(ptCheckBag, paramMap)
  546. local bagIdx = gainbagidxbyitemid(ptActor, v.id)
  547. local count = getbagitemcountbyid(ptActor, v.cfgid)
  548. if bagIdx == 0 or count < v.count then
  549. messagebox(ptActor, string.format("%s道具出错,交易失败", playerName))
  550. messagebox(ttActor, string.format("%s道具出错,交易失败", playerName))
  551. Transaction.clearInfo(actor)
  552. return
  553. end
  554. end
  555. local canPutBag = checkitemscanputbag(ttActor, ptCheckBag)
  556. if tonumber(canPutBag) == 0 and table.notNullOrEmpty(ptCheckBag) then
  557. messagebox(ptActor, string.format("%s背包已满,交易失败", targetName))
  558. messagebox(ttActor, string.format("%s背包已满,交易失败", targetName))
  559. Transaction.clearInfo(actor)
  560. return
  561. end
  562. ptCheckBag = {}
  563. for _, v in pairs(targetItems) do
  564. local paramMap = {}
  565. paramMap["cfgid"] = v.cfgid
  566. paramMap["itemcount"] = 1
  567. table.insert(ptCheckBag, paramMap)
  568. local bagIdx = gainbagidxbyitemid(ttActor, v.id)
  569. local count = getbagitemcountbyid(ttActor, v.cfgid)
  570. if bagIdx == 0 or count < v.count then
  571. messagebox(ptActor, string.format("%s道具出错,交易失败", targetName))
  572. messagebox(ttActor, string.format("%s道具出错,交易失败", targetName))
  573. Transaction.clearInfo(actor)
  574. return
  575. end
  576. end
  577. local canPutBag1 = checkitemscanputbag(ptActor, ptCheckBag)
  578. if tonumber(canPutBag1) == 0 and table.notNullOrEmpty(ptCheckBag) then
  579. messagebox(ptActor, string.format("%s背包已满,交易失败", playerName))
  580. messagebox(ttActor, string.format("%s背包已满,交易失败", playerName))
  581. Transaction.clearInfo(actor)
  582. return
  583. end
  584. if ptInfo.coin1 > 0 then
  585. removeitemfrombag(ptActor, 10010001, ptInfo.coin1, 1, 9999, "交易消耗")
  586. end
  587. if ptInfo.coin2 > 0 then
  588. removeitemfrombag(ptActor, 10020001, ptInfo.coin2, 1, 9999, "交易消耗")
  589. end
  590. if ttInfo.coin1 > 0 then
  591. removeitemfrombag(ttActor, 10010001, ttInfo.coin1, 1, 9999, "交易消耗")
  592. end
  593. if ttInfo.coin2 > 0 then
  594. removeitemfrombag(ttActor, 10020001, ttInfo.coin2, 1, 9999, "交易消耗")
  595. end
  596. if ptInfo.coin1 > 0 then
  597. Bag.addItemMapToBag(
  598. ttActor,
  599. {
  600. ["10010001"] = ptInfo.coin1
  601. },
  602. 0,
  603. 9999,
  604. "交易获得"
  605. )
  606. end
  607. if ptInfo.coin2 > 0 then
  608. Bag.addItemMapToBag(
  609. ttActor,
  610. {
  611. ["10020001"] = ptInfo.coin2
  612. },
  613. 0,
  614. 9999,
  615. "交易获得"
  616. )
  617. end
  618. if ttInfo.coin1 > 0 then
  619. Bag.addItemMapToBag(
  620. ptActor,
  621. {
  622. ["10010001"] = ttInfo.coin1
  623. },
  624. 0,
  625. 9999,
  626. "交易获得"
  627. )
  628. end
  629. if ttInfo.coin2 > 0 then
  630. Bag.addItemMapToBag(
  631. ptActor,
  632. {
  633. ["10020001"] = ttInfo.coin2
  634. },
  635. 0,
  636. 9999,
  637. "交易获得"
  638. )
  639. end
  640. Transaction.mailItemsToActor(actor, ptInfo, ttInfo)
  641. Transaction.mailItemsToActor(actor, ttInfo, ptInfo)
  642. Transaction.clearInfo(actor)
  643. API.SendCenterMsg(actor, "交易成功", "#00ff00")
  644. API.SendCenterMsg(ttActor, "交易成功", "#00ff00")
  645. end
  646. function Transaction.clear(ptInfo, ttInfo)
  647. local transactions = Transaction.GetTransactions()
  648. transactions[ptInfo.targetId] = nil
  649. transactions[ttInfo.targetId] = nil
  650. Transaction.SetTransactions(transactions)
  651. end
  652. function Transaction.GetTransactions()
  653. local transactions = getsysvar(SYS_TRANSACTIONS)
  654. if transactions == nil then
  655. transactions = {}
  656. end
  657. return transactions
  658. end
  659. function Transaction.SetTransactions(transactions)
  660. setsysvar(SYS_TRANSACTIONS, transactions)
  661. end