FriendLogic.lua 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. ----------------------------------
  2. -- 好友逻辑
  3. ----------------------------------
  4. local Lang = require("common.Lang")
  5. local Msg = require("core.Msg")
  6. local ObjHuman = require("core.ObjHuman")
  7. local Broadcast = require("broadcast.Broadcast")
  8. local Grid = require("bag.Grid")
  9. local BagLogic = require("bag.BagLogic")
  10. local ItemDefine = require("bag.ItemDefine")
  11. local FriendDBLogic = require("friend.FriendDBLogic")
  12. local FriendDefine = require("friend.FriendDefine")
  13. local RoleDBLogic = require("role.RoleDBLogic")
  14. local CombatLogic = require("combat.CombatLogic")
  15. local CombatDefine = require("combat.CombatDefine")
  16. local CombatPosLogic = require("combat.CombatPosLogic")
  17. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  18. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  19. local Util = require("common.Util")
  20. local MailExcel = require("excel.mail")
  21. local MailManager = require("mail.MailManager")
  22. local DailyTaskLogic = require("dailyTask.DailyTaskLogic")
  23. local RoleDefine = require("role.RoleDefine")
  24. local RoleLogic = require("role.RoleLogic")
  25. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  26. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  27. local WarReportLogic = require("warReport.WarReportLogic")
  28. local JjcDB = require("jjc.JjcDB")
  29. local ChatRecord = require("chat.ChatRecord")
  30. local CombatVideo = require("combat.CombatVideo")
  31. local Log = require("common.Log")
  32. local fields = { name = 1, lv = 1, lastLogoutTime = 1, head = 1, headFrame = 1, chenghao = 1, zhandouli = 1}
  33. local tempHuman = { }
  34. function makeFriendNet(net, uuid, human, getStatus, giveStatus)
  35. if net == nil then return end
  36. local targetDB, online = RoleDBLogic.getDb(uuid, fields)
  37. if not targetDB then return end
  38. RoleLogic.makeRoleBase(targetDB,net.roleBase,CombatDefine.COMBAT_TYPE1)
  39. if online then
  40. net.logoutSecond = 0
  41. net.online = 1
  42. else
  43. local lastTs = targetDB.lastLogoutTime or 0
  44. net.logoutSecond = os.time() - lastTs
  45. net.online = 0
  46. end
  47. net.getStatus = getStatus or 0
  48. net.giveStatus = giveStatus or 0
  49. return true
  50. end
  51. function sendFriendList(human)
  52. ObjHuman.updateDaily(human)
  53. local cnt, list = FriendDBLogic.getFriendUuids(human.db._id)
  54. local msgRet = Msg.gc.GC_FRIEND_LIST
  55. local questNum = FriendDBLogic.haveRequest(human.db._id)
  56. msgRet.questNum = questNum or 0
  57. msgRet.heartCnt = human.db.getHeartCnt and human.db.getHeartCnt > 0 and 1 or 0
  58. msgRet.friends[0] = 0
  59. local sendLen = 0
  60. for i = 1, cnt do
  61. sendLen = sendLen + 1
  62. local net = msgRet.friends[sendLen]
  63. local giveStatus = nil
  64. if human.db.sendHeart ~= nil then
  65. giveStatus = human.db.sendHeart[list[i].uuid]
  66. end
  67. makeFriendNet(net, list[i].uuid, human, list[i].getStatus, giveStatus)
  68. if sendLen >= FriendDefine.RECOMMEND_CNT then
  69. msgRet.isEnd = 0
  70. msgRet.friends[0] = sendLen
  71. Msg.send(msgRet, human.fd)
  72. sendLen = 0
  73. end
  74. end
  75. msgRet.isEnd = 1
  76. msgRet.friends[0] = sendLen
  77. Msg.send(msgRet, human.fd)
  78. end
  79. local recommendList = {}
  80. function sendRecommend(human, uuid)
  81. for i = 1, #recommendList do
  82. recommendList[i] = nil
  83. end
  84. if uuid then
  85. recommendList[1] = uuid
  86. else
  87. local humanCnt = ObjHuman.getOnlineCnt()
  88. human.recommendTotal = math.ceil(humanCnt / 10)
  89. human.recommendIndex = human.recommendIndex or 0
  90. if human.recommendIndex >= human.recommendTotal then
  91. human.recommendIndex = 1
  92. else
  93. human.recommendIndex = human.recommendIndex + 1
  94. end
  95. local index = 0
  96. local cnt = 0
  97. for uuid, target in pairs(ObjHuman.onlineUuid) do
  98. if cnt >= 10 then
  99. break
  100. end
  101. index = index + 1
  102. if index >= (human.recommendIndex - 1) * 10 then
  103. if uuid ~= human.db._id and
  104. not FriendDBLogic.isFriend(human.db._id, uuid) and
  105. not FriendDBLogic.hasRequest(human.db._id, uuid) and
  106. isBlackFriendCanDo(human.db._id,uuid) and
  107. target.fd then
  108. cnt = cnt + 1
  109. recommendList[cnt] = uuid
  110. end
  111. end
  112. end
  113. end
  114. local msgRet = Msg.gc.GC_FRIEND_RECOMMEND_LIST
  115. msgRet.friends[0] = 0
  116. local recommendCnt = #recommendList
  117. for i = 1, recommendCnt do
  118. if i > FriendDefine.RECOMMEND_CNT then
  119. break
  120. end
  121. local r = math.random(i, recommendCnt)
  122. recommendList[i], recommendList[r] = recommendList[r], recommendList[i]
  123. local net = msgRet.friends[msgRet.friends[0] + 1]
  124. if makeFriendNet(net, recommendList[i], human) then
  125. msgRet.friends[0] = msgRet.friends[0] + 1
  126. end
  127. end
  128. --Msg.trace(msgRet)
  129. Msg.send(msgRet, human.fd)
  130. end
  131. function sendRequestList(human, isLogin)
  132. local list = FriendDBLogic.getRequests(human.db._id)
  133. local msgRet = Msg.gc.GC_FRIEND_REQUEST_LIST
  134. msgRet.friends[0] = 0
  135. if list then
  136. for uuid in pairs(list) do
  137. local net = msgRet.friends[msgRet.friends[0] + 1]
  138. if makeFriendNet(net, uuid, human) then
  139. msgRet.friends[0] = msgRet.friends[0] + 1
  140. end
  141. end
  142. end
  143. if isLogin and msgRet.friends[0] < 1 then
  144. return
  145. end
  146. --Msg.trace(msgRet)
  147. Msg.send(msgRet, human.fd)
  148. end
  149. local function getLen(tb)
  150. if not tb then return 0 end
  151. local len = 0
  152. for _ in pairs(tb) do
  153. len = len + 1
  154. end
  155. return len
  156. end
  157. function addFriend(human, uuid)
  158. -- 自己不能加自己为好友
  159. local targetDB = nil
  160. if human.db._id == uuid then
  161. Broadcast.sendErr(human,Lang.FRIEND_ADD_BENREN)
  162. return
  163. end
  164. targetDB = RoleDBLogic.getDb(uuid, fields)
  165. -- 判断这个人是否存在
  166. if not targetDB then
  167. Broadcast.sendErr(human, Lang.FRIEND_ADD_ERR_NOTHAD)
  168. return
  169. end
  170. --是否拉黑
  171. if not isBlackFriendCanDo(human.db._id,uuid,true) then return end
  172. -- 是否已经是好友了
  173. if FriendDBLogic.isFriend(human.db._id, uuid) then
  174. Broadcast.sendErr(human, Lang.FRIEND_ADD_ERR_HAD)
  175. return
  176. end
  177. -- 是否已经申请好友
  178. if FriendDBLogic.hasRequest(human.db._id, uuid) then
  179. Broadcast.sendErr(human, Lang.FRIEND_ADD_ERR_REQUEST)
  180. return
  181. end
  182. -- 对方的申请列表是否已满
  183. local list = FriendDBLogic.getRequests(uuid)
  184. local cnt = getLen(list)
  185. if cnt >= FriendDefine.REQUEST_CNT_MAX then
  186. Broadcast.sendErr(human, Lang.FRIEND_ADD_ERR_REQUEST_MAX)
  187. return
  188. end
  189. local cnt2 = FriendDBLogic.getFriendUuids(human.db._id)
  190. if cnt2 >= FriendDefine.FRIEND_MAX_CNT then
  191. Broadcast.sendErr(human, Lang.FRIEND_ADD_ERR_CNT)
  192. return
  193. end
  194. FriendDBLogic.addRequest(human.db._id, uuid)
  195. -- 通知对方有人申请
  196. local targetHuman = ObjHuman.onlineUuid[uuid]
  197. if targetHuman and targetHuman.fd then
  198. local msgRet = Msg.gc.GC_FRIEND_ADD_NOTIFY
  199. makeFriendNet(msgRet.friend, human.db._id, human)
  200. Msg.send(msgRet, targetHuman.fd)
  201. RoleSystemLogic.onDot(targetHuman, RoleSystemDefine.ROLE_SYS_ID_205)
  202. end
  203. -- 申请成功提示
  204. Broadcast.sendErr(human, Lang.FRIEND_ADD_OK)
  205. local msgRet = Msg.gc.GC_FRIEND_ADD_OK
  206. msgRet.uuid = uuid
  207. Msg.send(msgRet, human.fd)
  208. end
  209. function agreeFriend(human, uuid)
  210. --是否拉黑
  211. if not isBlackFriendCanDo(human.db._id,uuid,true) then return end
  212. -- 是否有申请
  213. if not FriendDBLogic.hasRequest(uuid, human.db._id) then
  214. return
  215. end
  216. -- 好友已满了,不能继续添加
  217. local cnt = FriendDBLogic.getFriendUuids(human.db._id)
  218. if cnt >= FriendDefine.FRIEND_MAX_CNT then
  219. Broadcast.sendErr(human, Lang.FRIEND_ADD_ERR_CNT)
  220. return
  221. end
  222. -- 对方的好友已满
  223. local cnt2 = FriendDBLogic.getFriendUuids(uuid)
  224. if cnt2 >= FriendDefine.FRIEND_MAX_CNT then
  225. Broadcast.sendErr(human, Lang.FRIEND_ADD_ERR_CNT2)
  226. return
  227. end
  228. -- 删除申请
  229. delRequest(human.db._id, uuid)
  230. delRequest(uuid, human.db._id)
  231. if FriendDBLogic.addFriendData(human.db._id, uuid) then
  232. -- 添加成功
  233. local msgRet = Msg.gc.GC_FRIEND_ADD
  234. makeFriendNet(msgRet.friend, uuid, human)
  235. Msg.send(msgRet, human.fd)
  236. Broadcast.sendErr(human, Lang.FRIEND_ADD_OK2)
  237. local target = ObjHuman.onlineUuid[uuid]
  238. if target and target.fd then
  239. msgRet = Msg.gc.GC_FRIEND_ADD
  240. makeFriendNet(msgRet.friend, human.db._id, target)
  241. Broadcast.sendErr(target, Util.format(Lang.FRIEND_ADD_OK3,human.db.name) )
  242. Msg.send(msgRet, target.fd)
  243. end
  244. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_205)
  245. RoleSystemLogic.onDotByUuid(uuid, RoleSystemDefine.ROLE_SYS_ID_205)
  246. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_13,cnt + 1)
  247. ChengjiuLogic.onCallbackByUuid(uuid,ChengjiuDefine.CJ_TASK_TYPE_13,cnt2 + 1)
  248. else
  249. -- 已经是好友的时候要提示
  250. Broadcast.sendErr(human, Lang.FRIEND_ADD_ERR_HAD)
  251. end
  252. end
  253. function refuseFriend(human, uuid)
  254. -- 是否有申请
  255. if not FriendDBLogic.hasRequest(uuid, human.db._id) then
  256. return
  257. end
  258. -- 删除申请
  259. delRequest(uuid, human.db._id)
  260. sendRequestList(human)
  261. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_205)
  262. end
  263. -- 删除uuid1向uuid2的好友申请
  264. function delRequest(uuid1, uuid2, nosend)
  265. local list = FriendDBLogic.getRequests(uuid2)
  266. if list and list[uuid1] then
  267. list[uuid1] = nil
  268. local target = ObjHuman.onlineUuid[uuid2]
  269. if target and target.fd and not nosend then
  270. local msgRet = Msg.gc.GC_FRIEND_REQUEST_DEL
  271. msgRet.uuid = uuid1
  272. Msg.send(msgRet, target.fd)
  273. end
  274. end
  275. end
  276. function refuseFriendAll(human)
  277. local msgRet = Msg.gc.GC_FRIEND_REQUEST_DEL
  278. local list = FriendDBLogic.getRequests(human.db._id)
  279. if list then
  280. for uuid in pairs(list) do
  281. msgRet.uuid = uuid
  282. Msg.send(msgRet, human.fd)
  283. list[uuid] = nil
  284. end
  285. end
  286. sendRequestList(human)
  287. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_205)
  288. end
  289. local function agreeAllDo(uuid,human)
  290. --是否拉黑
  291. if not isBlackFriendCanDo(human.db._id,uuid) then return end
  292. -- 好友已满了,不能继续添加
  293. local cnt = FriendDBLogic.getFriendUuids(human.db._id)
  294. if cnt >= FriendDefine.FRIEND_MAX_CNT then
  295. return
  296. end
  297. -- 对方的好友已满
  298. local cnt2 = FriendDBLogic.getFriendUuids(uuid)
  299. if cnt2 >= FriendDefine.FRIEND_MAX_CNT then
  300. return
  301. end
  302. -- 删除申请
  303. delRequest(human.db._id, uuid, true)
  304. delRequest(uuid, human.db._id)
  305. if FriendDBLogic.addFriendData(human.db._id, uuid) then
  306. local target = ObjHuman.onlineUuid[uuid]
  307. if target and target.fd then
  308. msgRet = Msg.gc.GC_FRIEND_ADD
  309. makeFriendNet(msgRet.friend, human.db._id, target)
  310. Msg.send(msgRet, target.fd)
  311. end
  312. RoleSystemLogic.onDotByUuid(uuid, RoleSystemDefine.ROLE_SYS_ID_205)
  313. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_13,cnt + 1)
  314. ChengjiuLogic.onCallbackByUuid(uuid,ChengjiuDefine.CJ_TASK_TYPE_13,cnt2 + 1)
  315. return true
  316. else
  317. end
  318. end
  319. function CG_FRIEND_AGREE_ALL(human)
  320. local list = FriendDBLogic.getRequests(human.db._id)
  321. local agreeOK = nil
  322. if list then
  323. for uuid in pairs(list) do
  324. if agreeAllDo(uuid,human) then
  325. agreeOK = true
  326. end
  327. end
  328. end
  329. if agreeOK then
  330. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_205)
  331. end
  332. sendRequestList(human)
  333. end
  334. function delFriend(human, uuid)
  335. -- 是否已经是好友了
  336. if not FriendDBLogic.isFriend(human.db._id, uuid) then
  337. return
  338. end
  339. FriendDBLogic.delFriendData(human.db._id, uuid)
  340. local msgRet = Msg.gc.GC_FRIEND_DEL_NOTIFY
  341. msgRet.uuid = uuid
  342. Msg.send(msgRet, human.fd)
  343. local target = ObjHuman.onlineUuid[uuid]
  344. if target and target.fd then
  345. msgRet.uuid = human.db._id
  346. Msg.send(msgRet, target.fd)
  347. end
  348. Broadcast.sendErr(human, Lang.FRIEND_DEL_OK)
  349. ChatRecord.delFriendChatRecordDouble(human.db._id,uuid)
  350. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_205)
  351. RoleSystemLogic.onDotByUuid(uuid, RoleSystemDefine.ROLE_SYS_ID_205)
  352. end
  353. -- 检查可否挑战
  354. function checkCombatPos(human, args)
  355. local uuid = args[1]
  356. -- 判断是不是好友,不是好友也能切磋
  357. --if not uuid or not FriendDBLogic.isFriend(human.db._id, uuid) then
  358. -- return Broadcast.sendErr(human, Lang.FRIEND_COMBAT_ERR_NOT_FRIEND)
  359. --end
  360. local fakeHuman = CombatLogic.createCombatFakeHuman(uuid)
  361. if not fakeHuman then return end
  362. local combatHero = CombatPosLogic.getCombatHeros(fakeHuman, CombatDefine.COMBAT_TYPE1, nil, true)
  363. if not combatHero or not next(combatHero) then
  364. return Broadcast.sendErr(human, Lang.FRIEND_COMBAT_ERR_NO_DEFENCE)
  365. end
  366. return true
  367. end
  368. -- 获取战斗目标
  369. function getCombatObjList(human, side, args)
  370. if side ~= CombatDefine.DEFEND_SIDE then
  371. return
  372. end
  373. local uuid = args[1]
  374. if not uuid then return end
  375. local fakeHuman = CombatLogic.createCombatFakeHuman(uuid)
  376. if not fakeHuman then return end
  377. return CombatLogic.getHumanObjList(fakeHuman, CombatDefine.COMBAT_TYPE1)
  378. end
  379. -- 好友切磋
  380. --[[
  381. @param2 = {
  382. uuid -- 目标角色uuid
  383. ......
  384. }
  385. ]]
  386. function fight(human, args)
  387. if not checkCombatPos(human, args) then
  388. return
  389. end
  390. -- 开打
  391. local targetUuid = args[1]
  392. CombatLogic.combatBegin(human, 1001, args, CombatDefine.COMBAT_TYPE14, targetUuid)
  393. end
  394. function onFightEnd(human, result, combatType, cbParam, combatInfo, param, isSaodang)
  395. local videoUuid = CombatVideo.saveCombatVideo(human, true)
  396. if videoUuid then
  397. local msgRet = Msg.gc.GC_COMBAT_RETURN_RECORD
  398. msgRet.videoUuid = videoUuid
  399. msgRet.type = combatType
  400. Msg.send(msgRet,human.fd)
  401. end
  402. local jjcRank = JjcDB.getRank(human.db._id)
  403. if jjcRank >= WarReportLogic.WAR_FRIEND_RANK then return end
  404. -- 添加战报
  405. local targetUuid = cbParam
  406. local jjcTargetRank = JjcDB.getRank(targetUuid)
  407. WarReportLogic.add(WarReportLogic.WAR_REPORT_4, combatInfo, jjcRank, jjcTargetRank)
  408. end
  409. function checkDelRole(human)
  410. local blackList = human.db.friendBlack
  411. if blackList then
  412. for uuid, _ in pairs(blackList) do
  413. local targetDB, online = RoleDBLogic.getDb(uuid, fields)
  414. if targetDB == nil then
  415. human.db.friendBlack[uuid] = nil
  416. end
  417. end
  418. end
  419. end
  420. -- 登录
  421. function onLogin(human)
  422. checkDelRole(human)
  423. sendFriendList(human)
  424. sendRequestList(human, true)
  425. end
  426. -- 每日刷新
  427. function refreshDailyTask(human)
  428. human.db.sendHeart = nil
  429. -- 清空赠送记录
  430. human.db.getHeartCnt = nil
  431. -- 清空已领取过的状态
  432. human.db.sendHeartCnt = nil
  433. -- 清空已赠送过的次数
  434. FriendDBLogic.delAllFriendHeart(human.db._id)
  435. end
  436. -- 刷新单个好友的信息 todo
  437. function refreshFriendInfo(human, uuid)
  438. -- 获取好友信息
  439. local isFriend, friendData = FriendDBLogic.isFriend(human.db._id, uuid)
  440. if not isFriend or friendData == nil then
  441. return
  442. end
  443. -- 自己对好友是否有赠送记录
  444. local giveStatus = nil
  445. if human.db.sendHeart ~= nil then
  446. giveStatus = human.db.sendHeart[uuid]
  447. end
  448. -- 自己对好友的领取记录
  449. local getStatus = nil
  450. if human.db._id > uuid then
  451. getStatus = friendData.isGetRedHeart2
  452. else
  453. getStatus = friendData.isGetRedHeart1
  454. end
  455. local msgRet = Msg.gc.GC_FRIEND_UPDATE
  456. makeFriendNet(msgRet.friend, uuid, human, getStatus, giveStatus)
  457. Msg.send(msgRet, human.fd)
  458. end
  459. -- 赠送好友红心值
  460. function sendFriendHeart(human, uuid)
  461. -- local flag = RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_205)
  462. -- if flag ~= true then
  463. -- return Broadcast.sendErr(human, Lang.FRIEND_OPEN_NEED_LV)
  464. -- end
  465. ObjHuman.updateDaily(human)
  466. local itemList = {}
  467. local send = nil
  468. if uuid ~= "" then
  469. -- 判定是否是好友
  470. if not FriendDBLogic.isFriend(human.db._id, uuid) then
  471. -- 不是好友不能赠送
  472. return Broadcast.sendErr(human, Lang.FRIEND_GIFT_ERR_FRIEND)
  473. end
  474. local sendResult = sendFriendHeartdo(human, uuid, nil, nil, itemList)
  475. if sendResult == 1 then
  476. return Broadcast.sendErr(human, Lang.FRIEND_HEART_SEND_CNTERR)
  477. end
  478. if sendResult == 2 then
  479. -- 赠送过了
  480. return Broadcast.sendErr(human, Lang.FRIEND_HEART_ERR_HAD)
  481. end
  482. send = true
  483. else
  484. local sendDo = {0}
  485. local sendResult = 0
  486. local cnt, list = FriendDBLogic.getFriendUuids(human.db._id)
  487. for i = 1, cnt do
  488. sendResult = sendFriendHeartdo(human, list[i].uuid, sendDo,nil,itemList)
  489. end
  490. if sendResult == 2 then
  491. Broadcast.sendErr(human, Lang.FRIEND_HEART_ERR_HAD)
  492. end
  493. if sendResult == 1 then
  494. Broadcast.sendErr(human, Lang.FRIEND_HEART_SEND_CNTERR)
  495. end
  496. local sendNum = sendDo[1]
  497. if sendNum > 0 then
  498. sendFriendList(human)
  499. send = true
  500. end
  501. end
  502. if send then
  503. local sendItems = {}
  504. local index = 0
  505. for id,cnt in pairs(itemList) do
  506. sendItems[index+1] = {}
  507. sendItems[index+1][1] = id
  508. sendItems[index+1][2] = cnt
  509. index = index + 1
  510. end
  511. BagLogic.sendItemGetList(human,sendItems, "givebyfriend")
  512. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_205)
  513. end
  514. end
  515. function sendFriendHeartdo(human, uuid, sendNum, yjGetDo, itemList)
  516. -- 封印之章特权
  517. local dayMax = FriendDefine.FRIEND_SENDHEART_MAX
  518. local cjPrivilege = ChengjiuLogic.checkPrivilege(human,ChengjiuDefine.PRIVILEGE_TYPE_3)
  519. if cjPrivilege then
  520. dayMax = dayMax + cjPrivilege
  521. end
  522. -- 每天可赠送
  523. if human.db.sendHeartCnt and human.db.sendHeartCnt >= dayMax then
  524. return 1
  525. end
  526. -- 已经赠送过
  527. if human.db.sendHeart ~= nil then
  528. if human.db.sendHeart[uuid] ~= nil then
  529. return 2
  530. end
  531. else
  532. human.db.sendHeart={}
  533. end
  534. -- 标识已经赠送过此玩家
  535. human.db.sendHeart[uuid] = 1
  536. human.db.sendHeartCnt = (human.db.sendHeartCnt or 0) + 1
  537. -- 提高友情值
  538. ObjHuman.updateFriendHeart(human, 10, "givebyfriend")
  539. BagLogic.addItem(human, ItemDefine.ITEM_JINBI_ID, 10000, "givebyfriend")
  540. itemList[ItemDefine.ITEM_FRIEND_ID] = (itemList[ItemDefine.ITEM_FRIEND_ID] or 0) + 10
  541. itemList[ItemDefine.ITEM_JINBI_ID] = (itemList[ItemDefine.ITEM_JINBI_ID] or 0) + 10000
  542. -- 新增红心可领取记录
  543. FriendDBLogic.setFriendHeart(human.db._id, uuid, 1, true)
  544. -- 推送成功消息
  545. if not sendNum then
  546. refreshFriendInfo(human, uuid)
  547. end
  548. -- 推送RoleSystem 红标签
  549. RoleSystemLogic.onDotByUuid(uuid, RoleSystemDefine.ROLE_SYS_ID_205)
  550. if sendNum then
  551. sendNum[1] = sendNum[1] + 1
  552. end
  553. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_2, 1)
  554. end
  555. -- 领取好友红心值
  556. function getFriendHeart(human, uuid)
  557. ObjHuman.updateDaily(human)
  558. local itemList = {}
  559. local getResult = getFriendHeartdo(human,uuid,false,itemList)
  560. if getResult == 1 then
  561. Broadcast.sendErr(human, Lang.FRIEND_HEART_GET_NOTFRIEND)
  562. elseif getResult == 2 then
  563. Broadcast.sendErr(human, Lang.FRIEND_HEART_GET_HAD)
  564. elseif getResult == 3 then
  565. Broadcast.sendErr(human, Lang.FRIEND_HEART_GET_CNTERR)
  566. end
  567. local sendItems = {}
  568. local index = 0
  569. for id,cnt in pairs(itemList) do
  570. sendItems[index+1] = {}
  571. sendItems[index+1][1] = id
  572. sendItems[index+1][2] = cnt
  573. index = index + 1
  574. end
  575. BagLogic.sendItemGetList(human,sendItems, "givebyfriend")
  576. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_205)
  577. end
  578. function getFriendHeartdo(human, uuid, yjGetDo, itemList)
  579. -- 判定是否是好友
  580. local isFriend, friendData = FriendDBLogic.isFriend(human.db._id, uuid)
  581. if not isFriend or friendData == nil then
  582. return 1
  583. end
  584. -- 判定每日限制次数
  585. if human.db.getHeartCnt and human.db.getHeartCnt >= FriendDefine.REDHEART_CNT_MAX then
  586. return 3
  587. end
  588. -- 判定领取状态
  589. if human.db._id > uuid then
  590. if friendData.isGetRedHeart2 ~= 1 then
  591. return 2
  592. end
  593. else
  594. if friendData.isGetRedHeart1 ~= 1 then
  595. return 2
  596. end
  597. end
  598. if human.db.getHeartCnt == nil then
  599. human.db.getHeartCnt=0
  600. end
  601. -- 标识状态已领取状态
  602. FriendDBLogic.setFriendHeart(human.db._id, uuid, 2, false)
  603. -- 增加次数
  604. human.db.getHeartCnt = human.db.getHeartCnt + 1
  605. -- 提高友情值
  606. ObjHuman.updateFriendHeart(human, 10, "givebyfriend")
  607. BagLogic.addItem(human, ItemDefine.ITEM_JINBI_ID, 10000, "givebyfriend")
  608. itemList[ItemDefine.ITEM_FRIEND_ID] = (itemList[ItemDefine.ITEM_FRIEND_ID] or 0) + 10
  609. itemList[ItemDefine.ITEM_JINBI_ID] = (itemList[ItemDefine.ITEM_JINBI_ID] or 0) + 10000
  610. -- 推送成功消息
  611. if not yjGetDo then
  612. refreshFriendInfo(human, uuid)
  613. end
  614. -- 关闭自己提示
  615. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_205)
  616. --
  617. --Broadcast.sendErr(human, Lang.FRIEND_HEART_GET_SUCESS)
  618. end
  619. -- 一键领取赠送友情值
  620. function getHeartOneTouch(human)
  621. ObjHuman.updateDaily(human)
  622. local touchUuidList = {}
  623. local cnt, list = FriendDBLogic.getFriendUuids(human.db._id)
  624. for i = 1, cnt do
  625. touchUuidList[i] = list[i].uuid
  626. end
  627. local sendDo = {0}
  628. local itemList = {}
  629. local sendResult = 0
  630. for _, v in ipairs(touchUuidList) do
  631. -- 领取
  632. sendResult = getFriendHeartdo(human, v, true, itemList)
  633. end
  634. if sendResult == 2 then
  635. --Broadcast.sendErr(human, Lang.FRIEND_HEART_GET_HAD)
  636. end
  637. if sendResult == 3 then
  638. Broadcast.sendErr(human, Lang.FRIEND_HEART_GET_CNTERR)
  639. end
  640. local sendItems = {}
  641. local index = 0
  642. for id,cnt in pairs(itemList) do
  643. sendItems[index+1] = {}
  644. sendItems[index+1][1] = id
  645. sendItems[index+1][2] = cnt
  646. index = index + 1
  647. end
  648. BagLogic.sendItemGetList(human,sendItems, "givebyfriend")
  649. sendFriendList(human)
  650. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_205)
  651. end
  652. -- 好友红心提醒判定
  653. function isDot(human)
  654. local cnt, list = FriendDBLogic.getFriendUuids(human.db._id)
  655. for i = 1, cnt do
  656. local getStatus = list[i].getStatus or 0
  657. if not human.db.getHeartCnt or (human.db.getHeartCnt and human.db.getHeartCnt < FriendDefine.REDHEART_CNT_MAX) then
  658. -- 有可领取的
  659. if getStatus == 1 then
  660. return true
  661. end
  662. end
  663. -- if human.db.sendHeart == nil or human.db.sendHeart[list[i].uuid] == nil then
  664. -- -- 有可以赠送的
  665. -- return true
  666. -- end
  667. end
  668. local questNum = FriendDBLogic.haveRequest(human.db._id)
  669. if questNum > 0 then
  670. return true
  671. end
  672. return false
  673. end
  674. function findFriend(human,val)
  675. local net = nil
  676. local len = 0
  677. local msgRet = Msg.gc.GC_FRIEND_FIND
  678. net,len = RoleDBLogic.getDbByNameRegex(val,fields)
  679. msgRet.friendList[0] = 0
  680. for i = 1,len do
  681. local uuid = net[i].uuid
  682. if isBlackFriendCanDo(human.db._id,uuid) then
  683. makeFriendNet(msgRet.friendList[i], uuid, human)
  684. msgRet.friendList[0] = msgRet.friendList[0] + 1
  685. end
  686. end
  687. Msg.send(msgRet,human.fd)
  688. end
  689. --黑名单
  690. function CG_FRIEND_BLACK_QUERY(human)
  691. local msgRet = Msg.gc.GC_FRIEND_BLACK_QUERY
  692. local blackList = human.db.friendBlack
  693. msgRet.lists[0] = 0
  694. if blackList then
  695. for uuid, _ in pairs(blackList) do
  696. msgRet.lists[0] = msgRet.lists[0] + 1
  697. makeFriendNet(msgRet.lists[msgRet.lists[0]], uuid, human)
  698. end
  699. end
  700. --Msg.trace(msgRet)
  701. Msg.send(msgRet,human.fd)
  702. end
  703. --加入黑名单
  704. function CG_FRIEND_BLACK_ADD(human,uuid)
  705. if human.db.friendBlack and human.db.friendBlack[uuid] then
  706. return Broadcast.sendErr(human, Lang.FRIEND_IN_BLACK)
  707. end
  708. human.db.friendBlack = human.db.friendBlack or {}
  709. local cnt = 0
  710. for _,uuid in pairs(human.db.friendBlack) do
  711. cnt = cnt + 1
  712. end
  713. if cnt >= FriendDefine.FRIEND_BLACK_MAX then
  714. return Broadcast.sendErr(human,Lang.FRIEND_BLACK_MAX)
  715. end
  716. human.db.friendBlack[uuid] = true
  717. -- 删除申请
  718. delRequest(human.db._id, uuid)
  719. delRequest(uuid, human.db._id)
  720. delFriend(human, uuid)
  721. local msgRet = Msg.gc.GC_FRIEND_BLACK_ADD
  722. makeFriendNet(msgRet.add, uuid, human)
  723. Msg.send(msgRet,human.fd)
  724. Broadcast.sendErr(human, Lang.FRIEND_GOTO_BLACK)
  725. end
  726. --移除黑名单
  727. function CG_FRIEND_BLACK_DEL(human,uuid)
  728. if uuid ~= "" then
  729. if not human.db.friendBlack or not human.db.friendBlack[uuid] then return end
  730. human.db.friendBlack[uuid] = nil
  731. else
  732. human.db.friendBlack = nil
  733. end
  734. local msgRet = Msg.gc.GC_FRIEND_BLACK_DEL
  735. msgRet.uuid = uuid
  736. Msg.send(msgRet,human.fd)
  737. end
  738. --是否存在于黑名单内决定下一步操作
  739. function isBlackFriendCanDo(uuid1,uuid2,sendErr)
  740. if FriendDBLogic.isBlackFriend(uuid1,uuid2) then
  741. if sendErr then
  742. --Broadcast.sendErr(human,Lang.FRIEND_BLACK_ERR1)
  743. end
  744. return
  745. end
  746. if FriendDBLogic.isBlackFriend(uuid2,uuid1) then
  747. if sendErr then
  748. --Broadcast.sendErr(human,Lang.FRIEND_BLACK_ERR2)
  749. end
  750. return
  751. end
  752. return true
  753. end