FriendLogic.lua 25 KB

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