|
|
@@ -10,9 +10,16 @@ local lib_battle_redis = require("lib_battle_redis")
|
|
10
|
10
|
local timeUtil = require("utils.timeUtil")
|
|
11
|
11
|
local redisBattleUtil = require("redisBattleUtil")
|
|
12
|
12
|
local util_player = require("utils.util_player")
|
|
|
13
|
+local util_box = require("utils.util_box")
|
|
|
14
|
+local gameConst = require("const.gameConst")
|
|
|
15
|
+local util_user = require("utils.util_user")
|
|
|
16
|
+local nodeMgr = require("nodeMgr")
|
|
|
17
|
+local util_battle = require("utils.util_battle")
|
|
13
|
18
|
|
|
14
|
19
|
local battleData = require("data.battle")
|
|
|
20
|
+local bagData = require("data.bag")
|
|
15
|
21
|
local boxAdapt = require("adapt.boxAdapt")
|
|
|
22
|
+local resAdapt = require("adapt.resAdapt")
|
|
16
|
23
|
|
|
17
|
24
|
local root = {}
|
|
18
|
25
|
|
|
|
@@ -349,12 +356,15 @@ function root:is_wait_battle_end(roomId)
|
|
349
|
356
|
end
|
|
350
|
357
|
local currTime = timeUtil.now()
|
|
351
|
358
|
local createTime = redisBattleUtil.hget_int(key, "createTime")
|
|
352
|
|
- local waitSeconds = 10
|
|
|
359
|
+ local waitSeconds = boxAdapt:battle_const("no_full_close_room_time") or 10
|
|
353
|
360
|
if currTime < createTime + waitSeconds then
|
|
354
|
361
|
return false
|
|
355
|
362
|
end
|
|
356
|
363
|
return true
|
|
357
|
364
|
end
|
|
|
365
|
+----------------------------------------
|
|
|
366
|
+-- 战斗
|
|
|
367
|
+---------------------------------------
|
|
358
|
368
|
-- 房间是否开始战斗
|
|
359
|
369
|
function root:is_room_start_battle(roomId)
|
|
360
|
370
|
local status = self:get_room_status(roomId)
|
|
|
@@ -372,8 +382,123 @@ function root:is_room_start_battle(roomId)
|
|
372
|
382
|
local playCount = redisBattleUtil.hget_int(key, "playCount")
|
|
373
|
383
|
return seatCount >= playCount
|
|
374
|
384
|
end
|
|
|
385
|
+-- 生成战斗编号
|
|
|
386
|
+function root:gen_battle_id(roomId)
|
|
|
387
|
+ local currTime = timeUtil.now()
|
|
|
388
|
+ return string.format("BT%s%08d", os.date("%Y%m%d", currTime), roomId)
|
|
|
389
|
+end
|
|
|
390
|
+-- 战斗
|
|
|
391
|
+function root:start_battle(roomId)
|
|
|
392
|
+ if is_empty(roomId) then
|
|
|
393
|
+ return false
|
|
|
394
|
+ end
|
|
|
395
|
+ local key = _get_room_key(roomId)
|
|
|
396
|
+ -- 房间是否存在
|
|
|
397
|
+ local isExist = lib_battle_redis:exists(key)
|
|
|
398
|
+ if not isExist then
|
|
|
399
|
+ -- 从活跃房间集合删除
|
|
|
400
|
+ lib_battle_redis:sismerber(_get_active_room_id_key(), roomId)
|
|
|
401
|
+ return false
|
|
|
402
|
+ end
|
|
|
403
|
+ -- 更新状态
|
|
|
404
|
+ redisBattleUtil.hset(key, "status", 1)
|
|
|
405
|
+ local battleId = self:gen_battle_id(roomId)
|
|
|
406
|
+ local battleBoxList = redisBattleUtil.hget_json(key, "boxIdList")
|
|
|
407
|
+ local playerList = redisBattleUtil.hget_json(key, "playerList")
|
|
|
408
|
+ -- 射击轮次
|
|
|
409
|
+ local rounds = {}
|
|
|
410
|
+ local totalPrice = 0
|
|
|
411
|
+ for k, v in ipairs(battleBoxList) do
|
|
|
412
|
+ local roundInfo = {round = k, shotList = {}}
|
|
|
413
|
+ for _, _v in ipairs(playerList) do
|
|
|
414
|
+ if _v.seatId and _v.seatId > 0 then
|
|
|
415
|
+ local itemId = util_box:battle_get_box_drop_item_and_count(v)
|
|
|
416
|
+ local price = resAdapt:get_item_price(itemId)
|
|
|
417
|
+ local shotInfo = {
|
|
|
418
|
+ uid = _v.uid,
|
|
|
419
|
+ itemId = itemId,
|
|
|
420
|
+ price = price
|
|
|
421
|
+ }
|
|
|
422
|
+ table.insert(roundInfo.shotList, shotInfo)
|
|
|
423
|
+
|
|
|
424
|
+ totalPrice = totalPrice + price
|
|
|
425
|
+ end
|
|
|
426
|
+ end
|
|
|
427
|
+ table.insert(rounds, roundInfo)
|
|
|
428
|
+ end
|
|
|
429
|
+ -- 胜利玩家
|
|
|
430
|
+ local mapUidPrice = {}
|
|
|
431
|
+ for _, v in ipairs(rounds) do
|
|
|
432
|
+ for _, _v in ipairs(v.shotList) do
|
|
|
433
|
+ mapUidPrice[_v.uid] = (mapUidPrice[_v.uid] or 0) + _v.price
|
|
|
434
|
+ end
|
|
|
435
|
+ end
|
|
|
436
|
+ local winUid = nil
|
|
|
437
|
+ local maxPrice = nil
|
|
|
438
|
+ for uid, price in pairs(mapUidPrice) do
|
|
|
439
|
+ if maxPrice == nil or price > maxPrice then
|
|
|
440
|
+ winUid = uid
|
|
|
441
|
+ end
|
|
|
442
|
+ end
|
|
|
443
|
+ -- 战斗玩家列表
|
|
|
444
|
+ local n1Price = resAdapt:get_item_price(gameConst.ITEM_ID.N1)
|
|
|
445
|
+ local battlePlayerList = {}
|
|
|
446
|
+ for _, v in ipairs(playerList) do
|
|
|
447
|
+ if v.seatId and v.seatId > 0 then
|
|
|
448
|
+ if v.uid == winUid then
|
|
|
449
|
+ -- 收集所有玩家射击
|
|
|
450
|
+ local info = {uid = v.uid, seatId = v.seatId, shotList = {}}
|
|
|
451
|
+ for _, _v in ipairs(rounds) do
|
|
|
452
|
+ for _, __v in ipairs(_v.shotList) do
|
|
|
453
|
+ table.insert(info.shotList, {itemId = __v.itemId, price = __v.price})
|
|
|
454
|
+ end
|
|
|
455
|
+ end
|
|
|
456
|
+ table.insert(battlePlayerList, info)
|
|
|
457
|
+ else
|
|
|
458
|
+ -- 安慰奖
|
|
|
459
|
+ local info = {
|
|
|
460
|
+ uid = v.uid,
|
|
|
461
|
+ seatId = v.seatId,
|
|
|
462
|
+ shotList = {{itemId = gameConst.ITEM_ID.N1, price = n1Price}}
|
|
|
463
|
+ }
|
|
|
464
|
+ table.insert(battlePlayerList, info)
|
|
|
465
|
+ end
|
|
|
466
|
+ end
|
|
|
467
|
+ end
|
|
|
468
|
+ -- 发放奖励
|
|
|
469
|
+ for _, v in ipairs(battleBoxList) do
|
|
|
470
|
+ local items = {}
|
|
|
471
|
+ for _, _v in ipairs(v.shotList) do
|
|
|
472
|
+ table.insert(items, {id = v.itemId, count = 1})
|
|
|
473
|
+ end
|
|
|
474
|
+ local keyEvent = string.format("battle-settle-%s-%s", battleId, tostring(v.uid == winUid and 1 or 0))
|
|
|
475
|
+ bagData:add_items(v.uid, items, keyEvent)
|
|
|
476
|
+ end
|
|
|
477
|
+
|
|
|
478
|
+ redisBattleUtil.hset(key, "status", 2)
|
|
|
479
|
+ local settle = {
|
|
|
480
|
+ roomInfo = self:pack_room_info(roomId),
|
|
|
481
|
+ winUid = winUid,
|
|
|
482
|
+ battleId = battleId,
|
|
|
483
|
+ rounds = rounds,
|
|
|
484
|
+ battlePlayerList = battlePlayerList
|
|
|
485
|
+ }
|
|
|
486
|
+ -- 通知所有房间玩家
|
|
|
487
|
+ for _, v in ipairs(playerList) do
|
|
|
488
|
+ util_user:user_proto_notify(v.uid, "on_room_battle_settle", {settle = settle})
|
|
|
489
|
+ end
|
|
|
490
|
+ -- 新增战斗记录
|
|
|
491
|
+ util_battle:add_battle_record(settle, totalPrice)
|
|
|
492
|
+ -- 关闭房间
|
|
|
493
|
+ -- 删除房间信息
|
|
|
494
|
+ lib_battle_redis:del(key)
|
|
|
495
|
+ -- 从活跃房间集合删除
|
|
|
496
|
+ lib_battle_redis:sismerber(_get_active_room_id_key(), roomId)
|
|
|
497
|
+ -- 通知在线玩家 - 销毁房间
|
|
|
498
|
+ nodeMgr.broadcast_proto_notify("on_room_destroy", {roomId = roomId})
|
|
|
499
|
+end
|
|
375
|
500
|
----------------------------------------
|
|
|
501
|
+-- 玩家战斗信息
|
|
376
|
502
|
----------------------------------------
|
|
377
|
503
|
local bagData = require("data.bag")
|
|
378
|
504
|
-- 绑定房间
|