Przeglądaj źródła

更新战斗选取目标以及开服问题

mafei 1 rok temu
rodzic
commit
e3a8866c44

+ 173 - 0
script/common/CDK.lua

@@ -0,0 +1,173 @@
+
+local DB = require("common.DB")
+local CommonDB = require("common.CommonDB")
+local CdkFixExcel = require("excel.cdkFix")
+local LuaMongo = _G.lua_mongo
+local Lang = require("common.Lang")
+
+local Code = {  "0","c","e","u","m",
+                "k","d","7","x","f",
+                "9","j","w","6","8",
+                "t","1","h","4","p",
+                "y","3","2","b","5","n"}
+local batchList = {6,7,8} -- 批次位置 
+local idxList = {3,4,5} -- 序号位置
+
+local CodeMap = {
+    ["0"] = 1,["c"] = 2,["e"] = 3,["u"] = 4,["m"] = 5,
+    ["k"] = 6,["d"] = 7,["7"] = 8,["x"] = 9,["f"] = 10,
+    ["9"] = 11,["j"] = 12,["w"] = 13,["6"] = 14,["8"] = 15,
+    ["t"] = 16,["1"] = 17,["h"] = 18,["4"] = 19,["p"] = 20,
+    ["y"] = 21,["3"] = 22,["2"] = 23,["b"] = 24,["5"] = 25,["n"] = 26
+}
+
+local unit = 20
+local bit = unit
+local bit2 = unit * unit
+
+local function checkCDKParam(finishTime,cdkID)
+    local now = os.time()
+    if now > finishTime then 
+        return
+    end
+    return true
+end
+
+local function genCDKBatch(cnt,useCnt,cdkID)
+    local bat = assert(CommonDB.getCDKBatch(),"assert : cdk batch not found")
+    local db = {
+        batch = bat + 1,
+        cnt = cnt,
+        useCnt = useCnt,
+        info = cdkID,
+        useCDKList = {},
+    }
+    LuaMongo.insert(DB.db_cdk, db)
+    CommonDB.setCDKBatch(bat + 1) -- 将最新的cdkBatch保存
+    return bat + 1
+end
+
+local function transNumber(num)
+    local first,second = 0,0
+    if num >= bit2 then
+        first = math.floor(num / bit2)
+    end
+    if num >= bit then
+        local t = num - (first * bit2)
+        second = math.floor(t / bit)
+    end
+    local third = num - (first * bit2) - (second * bit)
+    --return Code[first + 1] .. Code[second + 1] .. Code[thrid + 1]
+    return first,second,third
+end
+
+local function calcNumber(first,second,third)
+    if first > unit or second > unit  or third > unit  then 
+        return -1
+    end
+    return first * bit2 + second * bit + third
+end
+
+local function transNum2Code(num)
+    local f,s,t = transNumber(num)
+    return Code[f + 1]..Code[s + 1]..Code[t + 1]
+end
+
+local function genCDKCode(batch,index)
+    return Code[math.random(2,#Code)] .. Code[math.random(#Code)] ..transNum2Code(index) .. transNum2Code(batch) .. Code[math.random(#Code)] .. Code[math.random(#Code)]
+end
+
+
+
+local function deCDKCode(cdk)
+    local num_f_code,num_s_code,num_t_code = CodeMap[string.sub(cdk,3,3) ],CodeMap[string.sub(cdk,4,4) ],CodeMap[string.sub(cdk,5,5) ]
+    if not num_f_code or not num_s_code or not num_t_code then
+        return false
+    end
+    num_f_code = num_f_code - 1
+    num_s_code = num_s_code - 1
+    num_t_code = num_t_code - 1
+    local bat_f_code,bat_s_code,bat_t_code = CodeMap[string.sub(cdk,6,6) ],CodeMap[string.sub(cdk,7,7) ],CodeMap[string.sub(cdk,8,8) ]
+    if not bat_f_code or not bat_s_code or not bat_t_code then
+        return false
+    end
+    bat_f_code = bat_f_code - 1
+    bat_s_code = bat_s_code - 1
+    bat_t_code = bat_t_code - 1
+    local num = calcNumber(num_f_code,num_s_code,num_t_code)
+    if num < 0 then 
+        return false
+    end
+    local batch = calcNumber(bat_f_code,bat_s_code,bat_t_code)
+    if batch < 0 then 
+        return false
+    end
+    --local num =  (CodeMap[string.sub(cdk,3,3) ] - 1) * 100 +  (CodeMap[string.sub(cdk,4,4)] - 1) * 10 + (CodeMap[string.sub(cdk,5,5) ] - 1)
+    --local batch = (CodeMap[string.sub(cdk,6,6) ] - 1) * 100 +  (CodeMap[string.sub(cdk,7,7) ] - 1) * 10 + (CodeMap[string.sub(cdk,8,8) ] - 1)
+    return true , num,batch
+end
+
+-- 生成一个批次的激活码
+-- 批次最大999 ,每次最多生成999个激活码
+--[[
+    param1 = cnt 生成CDK数量
+    param2 = useCnt 当前批次能够使用最大数量
+    param3 = cdkId 道具信息
+]]
+function genCDK(cnt,useCnt,cdkId)
+    useCnt = useCnt or 1
+    cnt = cnt < 1000 and cnt or 999
+    local bat = genCDKBatch(cnt,useCnt,cdkId)
+    local fileName = "cdk"..bat
+    local f,err = io.open(fileName,"w")
+    if not f then
+        print("open file failed ",err)
+        return
+    end
+    local idx = 0
+    local data = "cdk : \n"
+    while true do 
+        if idx > cnt then 
+            break
+        end
+        local cdk = genCDKCode(bat,idx)
+        data = data .. cdk .. "\n"
+        idx = idx + 1
+    end
+    f:write(data)
+end
+
+-- 使用cdk
+function useCDK(cdkBatchData,cdk)
+    local ok,_,batch = deCDKCode(cdk)
+    QueryCDK = { batch = { ["$eq"] = batch}}
+    LuaMongo.update(DB.db_cdk,QueryCDK,{
+        ["$set"] = {
+            ["useCDKList"] = cdkBatchData.useCDKList
+        },
+        ["$unset"] = nil
+    })
+end
+
+-- 检查CDK
+function checkCDK(cdk)
+    local ok,num,batch = deCDKCode(cdk)
+    if not ok then 
+        return Lang.CDK_INVALID_ERR
+    end
+    local curBatch = assert(CommonDB.getCDKBatch(),"assert : cdk batch not found")
+    if curBatch < batch then
+        return Lang.CDK_BATCH_ERR
+    end
+    QueryCDK = { batch = { ["$eq"] = batch} }
+    LuaMongo.find(DB.db_cdk,QueryCDK)
+    local cdkBatchData = {}
+    LuaMongo.next(cdkBatchData)
+    if cdkBatchData.cnt < num then 
+        return Lang.CDK_INVALID_ERR
+    end
+    if cdkBatchData.useCDKList[num] then 
+        return Lang.CDK_ERR4
+    end
+    return nil, cdkBatchData
+end

+ 16 - 2
script/common/CommonDB.lua

@@ -33,6 +33,7 @@ KEY_WORK_MAN = "workMan"                                -- 打工人活动
 KEY_OPEN_SERVER_TOPUP_TOP = "openServerTopupTop"		-- 开服充值排名活动
 KEY_CIYUAN_MOZHU = "ciyuanMoZhu"                        -- 次元魔蛛
 KEY_YJ_TIME = "yjTreasureTime"                          -- 遗迹探险时间
+KEY_CDK_BATCH = "cdkBatchIdx"                           -- CDK批次序号
 
 db = db or {
 	serverStartTime = nil,								-- 开服时间
@@ -52,7 +53,8 @@ db = db or {
 	dragonNestCiTiao = {},                              -- 冰龙巢穴词条
 	workMan = {},                                       -- 打工人活动
 	ciyuanMoZhu = nil,                                  -- 次元魔蛛 
-    yjTreasureTime = nil,                               -- 遗迹探险时间 
+    yjTreasureTime = nil,                               -- 遗迹探险时间
+	cdkBatchIdx = nil,
 }
 
 function init()
@@ -78,6 +80,18 @@ function updateValue(key, value)
 	LuaMongo.update(DB.db_common, DBUpdate, DBUpdateField)
 end
 
+function getCDKBatch()
+	if not db  then 
+		return
+	end
+	return db[KEY_CDK_BATCH] or 0
+end
+
+function setCDKBatch(idx)
+	idx = idx + 1
+	updateValue(KEY_CDK_BATCH,idx)
+end
+
 function getValueByKey(key)
 	if not db then return end
 	return db[key]
@@ -102,7 +116,7 @@ function setServerOpenTime(time)
 end
 
 function getServerOpenTime()
-	return db.serverStartTime or 1680851535
+	return db.serverStartTime or Util.getDayStartTime()
 end
 
 -- 获得当前是开服第几天(如果是开服第一天返回1)

+ 1 - 1
script/module/chat/Gm.lua

@@ -1770,7 +1770,7 @@ function d3.buyItem(human, value)
    require("shop.ShopLogic").buy(human, 9, 405007, 1, 1)
 end
 
-function d3.test(human)
+function d3.test1(human)
 	require("absAct.MangHeLogic").draw(human, 1)
 end
 

+ 6 - 6
script/module/combat/TargetMode.lua

@@ -286,7 +286,7 @@ local function handler28(attacker,targetMode)
 	local rowList = targetMode[4] or {1,2,3}
 	local targetPosList = {}
 	-- 待优化@mafei
-	for row,list in pairs(CombatDefine.ROW2POS[targetSide]) do 
+	for row,list in pairs(CombatDefine.ROW2POS[targetSide]) do
 		if table.find(rowList,row) then 
 			for _,pos in pairs(list) do 
 				table.insert(targetPosList,pos)
@@ -483,7 +483,7 @@ end
 	end	
 	for _,obj in ipairs(targetList) do 
 		targets[#targets+1] = obj
-		if #targets > cnt then 
+		if #targets >= cnt then 
 			break
 		end
 	end
@@ -702,9 +702,9 @@ local function handler24(attacker,targetMode)
 		local a_attr = CombatObj.getValue(a,attr)
 		local b_attr = CombatObj.getValue(b,attr) 
 		local ret = a_attr > b_attr
-		if a_attr== b_attr and #jobs > 0  then 
-			local a_idx = table.find(jobs,a.job)
-			local b_idx = table.find(jobs,b.job)
+		if a_attr== b_attr then 
+			local a_idx = table.find(jobs,a.job) or (#jobs+1)
+			local b_idx = table.find(jobs,b.job) or (#jobs+1)
 			if a_idx ~= b_idx then 
 				return a_idx < b_idx
 			end
@@ -713,7 +713,7 @@ local function handler24(attacker,targetMode)
 	end)
 	for _,obj in ipairs(targetList) do 
 		targets[#targets+1] = obj
-		if (#targets) >= cnt then 
+		if #targets >= cnt then 
 			break
 		end
 	end

+ 3 - 2
webServer/src/controller/ApiController.ts

@@ -704,10 +704,11 @@ class ApiController {
         // 测试是否可以调用过去
         // 通知给服务器,发放道具
         // "ws://43.143.193.23:18192"
-        Msg.connect(url, Account);
+        let msg = new Msg()
+        msg.connect(url, Account);
         new Promise((resolve) => {
             setTimeout(async () => {
-                Msg.CG_TEST_PROTO(data.account,param)
+                msg.CG_TEST_PROTO(data.account,param)
             }, 500);
         });
         ctx.body = {