Selaa lähdekoodia

新增战令代码

249435196@qq.com 1 vuosi sitten
vanhempi
sitoutus
af854ed6b7

+ 91 - 1
script/common/Util.lua

@@ -538,4 +538,94 @@ function format(...)
 		end
 	end
 	return str
-end
+end
+
+--------------------------------------------------------
+--- 新增table.find函数
+---@param1 array 数组
+---@param2 elem 目标元素
+--------------------------------------------------------
+
+table.find = function(array,elem) 
+	for idx,e in ipairs(array) do 
+		if e == elem then 
+			return idx
+		end
+	end
+	return #array + 1
+end
+
+--------------------------------------------------------
+--- 新增table.shuffle函数
+--- @param1 array 数组
+--------------------------------------------------------
+
+table.shuffle = function(array)
+	for i = 1,#array do 
+		local r = math.random(1,#array)
+		array[i],array[r] = array[r],array[i]
+	end
+	return array
+end
+
+--------------------------------------------------------
+--- 新增table.copy函数
+--- @param1 array 数组
+--------------------------------------------------------
+
+function table.copy(object)
+    -- 已经复制过的table,key为复制源table,value为复制后的table
+    -- 为了防止table中的某个属性为自身时出现死循环
+    -- 避免本该是同一个table的属性,在复制时变成2个不同的table(内容同,但是地址关系和原来的不一样了)
+    local lookup_table = {}
+    local function _copy(object)
+        if type(object) ~= 'table' then -- 非table类型都直接返回
+            return object
+        elseif lookup_table[object] then
+            return lookup_table[object]
+        end 
+        local new_table = {}
+        lookup_table[object] = new_table
+        for k,v in pairs(object) do
+            new_table[_copy(k)] = _copy(v) 
+        end 
+        -- 这里直接拿mt来用是因为一般对table操作不会很粗暴的修改mt的相关内容
+        return setmetatable(new_table, getmetatable(object))
+    end 
+    return _copy(object)                    
+end
+
+--------------------------------------------------------
+--- 新增table.print_lua_table函数
+--- @param1 array 数组
+--------------------------------------------------------
+
+local function print_lua_table(lua_table, indent)
+	indent = indent or 0
+	for k, v in pairs(lua_table) do
+		if type(k) == "string" then
+			k = string.format("%q", k)
+		end
+		local szSuffix = ""
+		if type(v) == "table" then
+			szSuffix = "{"
+		end
+		local szPrefix = string.rep("    ", indent)
+		formatting = szPrefix.."["..k.."]".." = "..szSuffix
+		if type(v) == "table" then
+			print(formatting)
+			print_lua_table(v, indent + 1)
+			print(szPrefix.."},")
+		else
+			local szValue = ""
+			if type(v) == "string" then
+				szValue = string.format("%q", v)
+			else
+				szValue = tostring(v)
+			end
+			print(formatting..szValue..",")
+		end
+	end
+end
+
+table.print_lua_table = print_lua_table

+ 3 - 0
script/core/ObjHuman.lua

@@ -83,6 +83,7 @@ local PfLogic = require("platform.PfLogic")
 local MoshouLogic = require("moshou.MoshouLogic")
 local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
 local LostTempleLogic = require("lostTemple.lostTempleLogic")
+local WarOrder = require("shop.WarOrder")
 
 fds				= fds or {}				-- fd->obj_id,包括创角中+游戏中
 onlineAccount 	= onlineAccount or {} 	-- account->human,包括创角中+游戏中
@@ -610,6 +611,8 @@ function sendHumanInfo(human)
     mm.worldLv = GlobalWorld.getWorldLv()
     mm.openDay = subDay or 0
 	mm.guideState= GuideLogic.checkAllFinish(human)
+	mm.warOrder = WarOrder.getWarOrderInfo(human)
+
 	Msg.send(mm, human.fd)
 end
 

+ 21 - 6
script/module/role/NewLogic.lua

@@ -60,17 +60,32 @@ local GC_QUERY_GIFT = 11    -- 登录推送礼包数据
 
 
 --[[
+    normal = {
+        idx number                      等级
+        process number                  等级对应所需进度
+        content [ItemGrid]array         普通战令等级奖励
+        upgradeContent [ItemGrid]array  升级战令等级奖励
+    }
     GC_WARORDER_INFO = {
-        upgrade = number  -- 是否升级 0表示未升级 1表示升级
-        process =         -- 战令进度
-        conf   =          -- 战令相关奖励
+        orderType = orderType,         -- 战令类型
+        normal = [normal]array,        -- 普通配置
+        language = string              -- 战令描述
+        -- 自身的进度
+        exp = orderData.exp,           -- 当前经验
+        unlock = orderData.unlock,     -- 是否解锁升级版 0 表示未解锁 1 表示解锁
+        finish = [number]array,        -- 已经完成的普通版等级
+        upgradeFinish = [number]array, -- 已经完成的升级版等级
     }
 ]]
 local GC_WARORDER_INFO = 12  -- 战令信息推送
 --[[
-    GC_WARORDER_REWARD = {
-        orderType = number -- 战令类型
-        process =          -- 战令进度
+    GC_WARORDER_CHANGE = {
+        orderType = number            -- 战令类型
+        exp =   number                -- 战令经验
+        unlock = number               -- 是否解锁升级版 0 表示未解锁 1 表示解锁
+        finish = [number]array        -- idx数组
+        upgradeFinish = [number]array -- idx数组
+        isRed = number                -- 是否红点
     }
 ]]
 local GC_WARORDER_CHANGE = 13  -- 战令数据推送

+ 12 - 0
script/module/scene/Proto.lua

@@ -1,4 +1,15 @@
 local RoleBase = require("role.Proto").RoleBase 
+
+
+WarOrder = {
+	{"type", 1,"int"},          -- 1 勇士之证 2 恶魔之证 3 工会之证明 4 竞技之证
+	{"exp",1,"int"},            -- 战令经验
+	{"finish",64,"int"},        -- 战令已经领取idx
+	{"unlock",1,"int"},         -- 战令是否RMB解锁
+	{"upgradeFinish",64,"int"}, -- 高级战令已经领取idx
+	{"isRed",1,"int"},          -- 是否有红点 0表示没有1表示有
+}
+
 CG_AA_DISCONNECT = {
 	{"reason",		1,		"int"},
 	{"realReason",	1,		"int"},
@@ -36,6 +47,7 @@ GC_ZZ_HUMAN_INFO = {
     {"worldLv",			1, "short"},	-- 世界等级
     {"openDay",			1, "short"},	-- 开服天数
 	{"guideState",      1, "byte"},
+	{"warOrder" ,       4, WarOrder},         -- 战令信息
 }
 GC_ENTER_CITY = {}
 

+ 82 - 14
script/module/shop/WarOrder.lua

@@ -33,6 +33,7 @@ local orderNameMap = {
 }
 
 local GC_WARORDER_CHANGE = 13
+local isRed = {}
 ------------------------------------------------------
 -- local 函数
 ------------------------------------------------------
@@ -59,12 +60,60 @@ local function checkRewardByIdx(human,orderType,idx)
     return not orderData.finish[idx] , isUpgradeOk
 end
 
+local function checkRed(human,orderType)
+    if isRed[orderType] then 
+        return true
+    end
+    local orderName = orderNameMap[orderType]
+    local cfg = OrderExcel[orderName]
+    local orderData = human.db.warOrder[orderName]
+
+    local exp = orderData.exp
+    local maxFinishIdx = 0
+    for _,lv in ipairs(orderData.finish) do 
+        if maxFinishIdx <= lv then 
+            maxFinishIdx = lv
+        end
+    end
+    local maxExpIdx = 0
+    for _,cfg in pairs(cfg) do 
+        if cfg.process <= exp and maxExpIdx <= cfg.idx then 
+            maxExpIdx = cfg.idx
+        end
+    end
+    isRed[orderType] = maxFinishIdx < maxExpIdx
+    return (isRed[orderType] == true) and 1 or 0
+end
+
+local function getWarOrderByType(human,orderType)
+    local orderName = orderNameMap[orderType]
+    local orderData = human.db.warOrder[orderName]
+    local finish = {}
+    for lv in pairs(orderData.finish) do 
+        finish[#finish+1] = lv
+    end
+    local upgradeFinish = {}
+    for lv in pairs(orderData.upgradeFinish) do 
+        finish[#finish+1] = lv
+    end
+
+    return {
+        type = orderType,
+        exp = orderData.exp,
+        isRed = checkRed(human,orderType),
+        unlock = orderData.unlock,
+        finish = finish,
+        upgradeFinish = upgradeFinish,
+    }
+end
+
 ------------------------------------------------------
 -- 对外暴露接口
 ------------------------------------------------------
 function warOrderInfo(human,orderType)
     local orderName = orderNameMap[orderType]
     local cfg = OrderExcel[orderName]
+    local langCfg = OrderExcel.desc
     local orderData = human.db.warOrder[orderName]
     if not cfg or not orderData then
         return
@@ -74,8 +123,13 @@ function warOrderInfo(human,orderType)
     local normal = {}
     local upgrade = {}
     for _,v in pairs(cfg) do 
+        local cfgData  = {
+            idx = v.idx,
+            process = v.process,
+        }
+        local content = {}
+        local upgradeContent = {}
         if #v.content ~= 0 then 
-            local content = {}
             for _,item in ipairs(v.content) do 
                 local data = {
                     getway = {},
@@ -88,15 +142,10 @@ function warOrderInfo(human,orderType)
                 end
                 content[#content + 1] = data
             end
-            normal[#normal+1] = {
-                idx = v.idx,
-                process = v.process,
-                content = content
-            }
+            
         end
-        if #v.upgradeContent ~= 0 then 
-            local content = {}
-            for _,item in ipairs(v.content) do 
+        if #v.upgradeContent ~= 0 then   
+            for _,item in ipairs(v.upgradeContent) do 
                 local data = {
                     getway = {},
                     suipian = {},
@@ -106,12 +155,18 @@ function warOrderInfo(human,orderType)
                 if not ItemDefine.isEquip(item[1]) then
                     Grid.makeItem(data, item[1], item[2])
                 end
-                content[#content + 1] = data
+                upgradeContent[#upgradeContent + 1] = data
             end
-            upgrade[#upgrade+1] = {
-                process = v.process,
-                content = content
-            }
+        end
+        cfgData.content = content
+        cfgData.upgradeContent = upgradeContent
+        normal[#normal+1] = cfgData
+    end
+    local language = ""
+    for _,v in pairs(langCfg) do 
+        if v.type == orderType then 
+            language = v.desc
+            break
         end
     end
     -------------------
@@ -126,6 +181,7 @@ function warOrderInfo(human,orderType)
     return {
         orderType = orderType,
         normal = normal,
+        language = language,
         upgrade = upgrade,
         -- 自身的进度问题
         exp = orderData.exp,
@@ -190,12 +246,14 @@ function warOrderReward(human,orderType)
     for lv in pairs(orderData.upgradeFinish) do 
         finish[#finish+1] = lv
     end
+    isRed[orderType] = nil
     return {
         orderType = orderType,
         exp = orderData.exp,
         unlock = orderData.unlock,
         finish = finish,
         upgradeFinish = upgradeFinish,
+        isRed = checkRed(human,orderType),
     }
 end
 
@@ -235,8 +293,18 @@ function trigger(human,orderType)
         unlock = orderData.unlock,
         finish = finish,
         upgradeFinish = upgradeFinish,
+        isRed = checkRed(human,orderType),
     }
     -- 临时require 确保两个文件不会相互引用
     local newLogic = require "role.NewLogic"
     newLogic.PushClient(human,GC_WARORDER_CHANGE,data)
+end
+
+function getWarOrderInfo(human) 
+    local ret = {}
+    -- 用于遍历
+    for orderType in pairs(orderExpMap) do 
+        ret[#ret + 1] = getWarOrderByType(human,orderType)
+    end
+    return ret
 end