FriendLogic.lua 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  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. function fight(human, args)
  381. if not checkCombatPos(human, args) then
  382. return
  383. end
  384. -- 开打
  385. local targetUuid = args[1]
  386. CombatLogic.combatBegin(human, 1001, args, CombatDefine.COMBAT_TYPE14, targetUuid)
  387. end
  388. function onFightEnd(human, result, combatType, cbParam, combatInfo, isSaodang)
  389. local videoUuid = CombatVideo.saveCombatVideo(human, true)
  390. if videoUuid then
  391. local msgRet = Msg.gc.GC_COMBAT_RETURN_RECORD
  392. msgRet.videoUuid = videoUuid
  393. msgRet.type = combatType
  394. Msg.send(msgRet,human.fd)
  395. end
  396. local jjcRank = JjcDB.getRank(human.db._id)
  397. if jjcRank >= WarReportLogic.WAR_FRIEND_RANK then return end
  398. -- 添加战报
  399. local targetUuid = cbParam
  400. local jjcTargetRank = JjcDB.getRank(targetUuid)
  401. WarReportLogic.add(WarReportLogic.WAR_REPORT_4, combatInfo, jjcRank, jjcTargetRank)
  402. end
  403. function checkDelRole(human)
  404. local blackList = human.db.friendBlack
  405. if blackList then
  406. for uuid, _ in pairs(blackList) do
  407. local targetDB, online = RoleDBLogic.getDb(uuid, fields)
  408. if targetDB == nil then
  409. human.db.friendBlack[uuid] = nil
  410. end
  411. end
  412. end
  413. end
  414. -- 登录
  415. function onLogin(human)
  416. checkDelRole(human)
  417. sendFriendList(human)
  418. sendRequestList(human, true)
  419. end
  420. -- 每日刷新
  421. function refreshDailyTask(human)
  422. human.db.sendHeart = nil
  423. -- 清空赠送记录
  424. human.db.getHeartCnt = nil
  425. -- 清空已领取过的状态
  426. human.db.sendHeartCnt = nil
  427. -- 清空已赠送过的次数
  428. FriendDBLogic.delAllFriendHeart(human.db._id)
  429. end
  430. -- 刷新单个好友的信息 todo
  431. function refreshFriendInfo(human, uuid)
  432. -- 获取好友信息
  433. local isFriend, friendData = FriendDBLogic.isFriend(human.db._id, uuid)
  434. if not isFriend or friendData == nil then
  435. return
  436. end
  437. -- 自己对好友是否有赠送记录
  438. local giveStatus = nil
  439. if human.db.sendHeart ~= nil then
  440. giveStatus = human.db.sendHeart[uuid]
  441. end
  442. -- 自己对好友的领取记录
  443. local getStatus = nil
  444. if human.db._id > uuid then
  445. getStatus = friendData.isGetRedHeart2
  446. else
  447. getStatus = friendData.isGetRedHeart1
  448. end
  449. local msgRet = Msg.gc.GC_FRIEND_UPDATE
  450. makeFriendNet(msgRet.friend, uuid, human, getStatus, giveStatus)
  451. Msg.send(msgRet, human.fd)
  452. end
  453. -- 赠送好友红心值
  454. function sendFriendHeart(human, uuid)
  455. -- local flag = RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_205)
  456. -- if flag ~= true then
  457. -- return Broadcast.sendErr(human, Lang.FRIEND_OPEN_NEED_LV)
  458. -- end
  459. ObjHuman.updateDaily(human)
  460. local itemList = {}
  461. local send = nil
  462. if uuid ~= "" then
  463. -- 判定是否是好友
  464. if not FriendDBLogic.isFriend(human.db._id, uuid) then
  465. -- 不是好友不能赠送
  466. return Broadcast.sendErr(human, Lang.FRIEND_GIFT_ERR_FRIEND)
  467. end
  468. local sendResult = sendFriendHeartdo(human, uuid, nil, nil, itemList)
  469. if sendResult == 1 then
  470. return Broadcast.sendErr(human, Lang.FRIEND_HEART_SEND_CNTERR)
  471. end
  472. if sendResult == 2 then
  473. -- 赠送过了
  474. return Broadcast.sendErr(human, Lang.FRIEND_HEART_ERR_HAD)
  475. end
  476. send = true
  477. else
  478. local sendDo = {0}
  479. local sendResult = 0
  480. local cnt, list = FriendDBLogic.getFriendUuids(human.db._id)
  481. for i = 1, cnt do
  482. sendResult = sendFriendHeartdo(human, list[i].uuid, sendDo,nil,itemList)
  483. end
  484. if sendResult == 2 then
  485. Broadcast.sendErr(human, Lang.FRIEND_HEART_ERR_HAD)
  486. end
  487. if sendResult == 1 then
  488. Broadcast.sendErr(human, Lang.FRIEND_HEART_SEND_CNTERR)
  489. end
  490. local sendNum = sendDo[1]
  491. if sendNum > 0 then
  492. sendFriendList(human)
  493. send = true
  494. end
  495. end
  496. if send then
  497. local sendItems = {}
  498. local index = 0
  499. for id,cnt in pairs(itemList) do
  500. sendItems[index+1] = {}
  501. sendItems[index+1][1] = id
  502. sendItems[index+1][2] = cnt
  503. index = index + 1
  504. end
  505. BagLogic.sendItemGetList(human,sendItems, "givebyfriend")
  506. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_205)
  507. end
  508. end
  509. function sendFriendHeartdo(human, uuid, sendNum, yjGetDo, itemList)
  510. -- 封印之章特权
  511. local dayMax = FriendDefine.FRIEND_SENDHEART_MAX
  512. local cjPrivilege = ChengjiuLogic.checkPrivilege(human,ChengjiuDefine.PRIVILEGE_TYPE_3)
  513. if cjPrivilege then
  514. dayMax = dayMax + cjPrivilege
  515. end
  516. -- 每天可赠送
  517. if human.db.sendHeartCnt and human.db.sendHeartCnt >= dayMax then
  518. return 1
  519. end
  520. -- 已经赠送过
  521. if human.db.sendHeart ~= nil then
  522. if human.db.sendHeart[uuid] ~= nil then
  523. return 2
  524. end
  525. else
  526. human.db.sendHeart={}
  527. end
  528. -- 标识已经赠送过此玩家
  529. human.db.sendHeart[uuid] = 1
  530. human.db.sendHeartCnt = (human.db.sendHeartCnt or 0) + 1
  531. -- 提高友情值
  532. ObjHuman.updateFriendHeart(human, 10, "givebyfriend")
  533. BagLogic.addItem(human, ItemDefine.ITEM_JINBI_ID, 10000, "givebyfriend")
  534. itemList[ItemDefine.ITEM_FRIEND_ID] = (itemList[ItemDefine.ITEM_FRIEND_ID] or 0) + 10
  535. itemList[ItemDefine.ITEM_JINBI_ID] = (itemList[ItemDefine.ITEM_JINBI_ID] or 0) + 10000
  536. -- 新增红心可领取记录
  537. FriendDBLogic.setFriendHeart(human.db._id, uuid, 1, true)
  538. -- 推送成功消息
  539. if not sendNum then
  540. refreshFriendInfo(human, uuid)
  541. end
  542. -- 推送RoleSystem 红标签
  543. RoleSystemLogic.onDotByUuid(uuid, RoleSystemDefine.ROLE_SYS_ID_205)
  544. if sendNum then
  545. sendNum[1] = sendNum[1] + 1
  546. end
  547. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_2, 1)
  548. end
  549. -- 领取好友红心值
  550. function getFriendHeart(human, uuid)
  551. ObjHuman.updateDaily(human)
  552. local itemList = {}
  553. local getResult = getFriendHeartdo(human,uuid,false,itemList)
  554. if getResult == 1 then
  555. Broadcast.sendErr(human, Lang.FRIEND_HEART_GET_NOTFRIEND)
  556. elseif getResult == 2 then
  557. Broadcast.sendErr(human, Lang.FRIEND_HEART_GET_HAD)
  558. elseif getResult == 3 then
  559. Broadcast.sendErr(human, Lang.FRIEND_HEART_GET_CNTERR)
  560. end
  561. local sendItems = {}
  562. local index = 0
  563. for id,cnt in pairs(itemList) do
  564. sendItems[index+1] = {}
  565. sendItems[index+1][1] = id
  566. sendItems[index+1][2] = cnt
  567. index = index + 1
  568. end
  569. BagLogic.sendItemGetList(human,sendItems, "givebyfriend")
  570. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_205)
  571. end
  572. function getFriendHeartdo(human, uuid, yjGetDo, itemList)
  573. -- 判定是否是好友
  574. local isFriend, friendData = FriendDBLogic.isFriend(human.db._id, uuid)
  575. if not isFriend or friendData == nil then
  576. return 1
  577. end
  578. -- 判定每日限制次数
  579. if human.db.getHeartCnt and human.db.getHeartCnt >= FriendDefine.REDHEART_CNT_MAX then
  580. return 3
  581. end
  582. -- 判定领取状态
  583. if human.db._id > uuid then
  584. if friendData.isGetRedHeart2 ~= 1 then
  585. return 2
  586. end
  587. else
  588. if friendData.isGetRedHeart1 ~= 1 then
  589. return 2
  590. end
  591. end
  592. if human.db.getHeartCnt == nil then
  593. human.db.getHeartCnt=0
  594. end
  595. -- 标识状态已领取状态
  596. FriendDBLogic.setFriendHeart(human.db._id, uuid, 2, false)
  597. -- 增加次数
  598. human.db.getHeartCnt = human.db.getHeartCnt + 1
  599. -- 提高友情值
  600. ObjHuman.updateFriendHeart(human, 10, "givebyfriend")
  601. BagLogic.addItem(human, ItemDefine.ITEM_JINBI_ID, 10000, "givebyfriend")
  602. itemList[ItemDefine.ITEM_FRIEND_ID] = (itemList[ItemDefine.ITEM_FRIEND_ID] or 0) + 10
  603. itemList[ItemDefine.ITEM_JINBI_ID] = (itemList[ItemDefine.ITEM_JINBI_ID] or 0) + 10000
  604. -- 推送成功消息
  605. if not yjGetDo then
  606. refreshFriendInfo(human, uuid)
  607. end
  608. -- 关闭自己提示
  609. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_205)
  610. --
  611. --Broadcast.sendErr(human, Lang.FRIEND_HEART_GET_SUCESS)
  612. end
  613. -- 一键领取赠送友情值
  614. function getHeartOneTouch(human)
  615. ObjHuman.updateDaily(human)
  616. local touchUuidList = {}
  617. local cnt, list = FriendDBLogic.getFriendUuids(human.db._id)
  618. for i = 1, cnt do
  619. touchUuidList[i] = list[i].uuid
  620. end
  621. local sendDo = {0}
  622. local itemList = {}
  623. local sendResult = 0
  624. for _, v in ipairs(touchUuidList) do
  625. -- 领取
  626. sendResult = getFriendHeartdo(human, v, true, itemList)
  627. end
  628. if sendResult == 2 then
  629. --Broadcast.sendErr(human, Lang.FRIEND_HEART_GET_HAD)
  630. end
  631. if sendResult == 3 then
  632. Broadcast.sendErr(human, Lang.FRIEND_HEART_GET_CNTERR)
  633. end
  634. local sendItems = {}
  635. local index = 0
  636. for id,cnt in pairs(itemList) do
  637. sendItems[index+1] = {}
  638. sendItems[index+1][1] = id
  639. sendItems[index+1][2] = cnt
  640. index = index + 1
  641. end
  642. BagLogic.sendItemGetList(human,sendItems, "givebyfriend")
  643. sendFriendList(human)
  644. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_205)
  645. end
  646. -- 好友红心提醒判定
  647. function isDot(human)
  648. local cnt, list = FriendDBLogic.getFriendUuids(human.db._id)
  649. for i = 1, cnt do
  650. local getStatus = list[i].getStatus or 0
  651. if not human.db.getHeartCnt or (human.db.getHeartCnt and human.db.getHeartCnt < FriendDefine.REDHEART_CNT_MAX) then
  652. -- 有可领取的
  653. if getStatus == 1 then
  654. return true
  655. end
  656. end
  657. -- if human.db.sendHeart == nil or human.db.sendHeart[list[i].uuid] == nil then
  658. -- -- 有可以赠送的
  659. -- return true
  660. -- end
  661. end
  662. local questNum = FriendDBLogic.haveRequest(human.db._id)
  663. if questNum > 0 then
  664. return true
  665. end
  666. return false
  667. end
  668. function findFriend(human,val)
  669. local net = nil
  670. local len = 0
  671. local msgRet = Msg.gc.GC_FRIEND_FIND
  672. net,len = RoleDBLogic.getDbByNameRegex(val,fields)
  673. msgRet.friendList[0] = 0
  674. for i = 1,len do
  675. local uuid = net[i].uuid
  676. if isBlackFriendCanDo(human.db._id,uuid) then
  677. makeFriendNet(msgRet.friendList[i], uuid, human)
  678. msgRet.friendList[0] = msgRet.friendList[0] + 1
  679. end
  680. end
  681. Msg.send(msgRet,human.fd)
  682. end
  683. --黑名单
  684. function CG_FRIEND_BLACK_QUERY(human)
  685. local msgRet = Msg.gc.GC_FRIEND_BLACK_QUERY
  686. local blackList = human.db.friendBlack
  687. msgRet.lists[0] = 0
  688. if blackList then
  689. for uuid, _ in pairs(blackList) do
  690. msgRet.lists[0] = msgRet.lists[0] + 1
  691. makeFriendNet(msgRet.lists[msgRet.lists[0]], uuid, human)
  692. end
  693. end
  694. --Msg.trace(msgRet)
  695. Msg.send(msgRet,human.fd)
  696. end
  697. --加入黑名单
  698. function CG_FRIEND_BLACK_ADD(human,uuid)
  699. if human.db.friendBlack and human.db.friendBlack[uuid] then
  700. return Broadcast.sendErr(human, Lang.FRIEND_IN_BLACK)
  701. end
  702. human.db.friendBlack = human.db.friendBlack or {}
  703. local cnt = 0
  704. for _,uuid in pairs(human.db.friendBlack) do
  705. cnt = cnt + 1
  706. end
  707. if cnt >= FriendDefine.FRIEND_BLACK_MAX then
  708. return Broadcast.sendErr(human,Lang.FRIEND_BLACK_MAX)
  709. end
  710. human.db.friendBlack[uuid] = true
  711. -- 删除申请
  712. delRequest(human.db._id, uuid)
  713. delRequest(uuid, human.db._id)
  714. delFriend(human, uuid)
  715. local msgRet = Msg.gc.GC_FRIEND_BLACK_ADD
  716. makeFriendNet(msgRet.add, uuid, human)
  717. Msg.send(msgRet,human.fd)
  718. Broadcast.sendErr(human, Lang.FRIEND_GOTO_BLACK)
  719. end
  720. --移除黑名单
  721. function CG_FRIEND_BLACK_DEL(human,uuid)
  722. if uuid ~= "" then
  723. if not human.db.friendBlack or not human.db.friendBlack[uuid] then return end
  724. human.db.friendBlack[uuid] = nil
  725. else
  726. human.db.friendBlack = nil
  727. end
  728. local msgRet = Msg.gc.GC_FRIEND_BLACK_DEL
  729. msgRet.uuid = uuid
  730. Msg.send(msgRet,human.fd)
  731. end
  732. --是否存在于黑名单内决定下一步操作
  733. function isBlackFriendCanDo(uuid1,uuid2,sendErr)
  734. if FriendDBLogic.isBlackFriend(uuid1,uuid2) then
  735. if sendErr then
  736. --Broadcast.sendErr(human,Lang.FRIEND_BLACK_ERR1)
  737. end
  738. return
  739. end
  740. if FriendDBLogic.isBlackFriend(uuid2,uuid1) then
  741. if sendErr then
  742. --Broadcast.sendErr(human,Lang.FRIEND_BLACK_ERR2)
  743. end
  744. return
  745. end
  746. return true
  747. end