FriendLogic.lua 25 KB

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