diff --git a/lua/app/bf/unity/character_spine_object.lua b/lua/app/bf/unity/character_spine_object.lua index 0a922993..155f0b82 100644 --- a/lua/app/bf/unity/character_spine_object.lua +++ b/lua/app/bf/unity/character_spine_object.lua @@ -44,9 +44,9 @@ function CharacterSpineObject:initWithCharacterHelper(characterSpineHelper, inde end function CharacterSpineObject:refreshSkeletonDataAsset(dataAsset) - local skeletonAnimation = self:getSkeletonAnimation() - skeletonAnimation.skeletonDataAsset = dataAsset - skeletonAnimation:Initialize(true) + local skeletonGraphic = self:getSkeletonGraphic() + skeletonGraphic.skeletonDataAsset = dataAsset + skeletonGraphic:Initialize(true) self.characterSpineHelper:Reload() end @@ -192,18 +192,11 @@ function CharacterSpineObject:removeAnimationCompleteCallback() end end -function CharacterSpineObject:getSkeletonAnimation() - if self.skeletonAnimation == nil then - self.skeletonAnimation = self.characterSpineHelper:GetSkeletonAnimation() +function CharacterSpineObject:getSkeletonGraphic() + if self.skeletonGraphic == nil then + self.skeletonGraphic = self.characterSpineHelper:GetSkeletonGraphic() end - return self.skeletonAnimation -end - -function CharacterSpineObject:setSortingOrder(order) - if self.mainSpineMeshRenderer == nil then - self.mainSpineMeshRenderer = self.mainSpine:BFGetComponent(GConst.TYPEOF_UNITY_CLASS.MESH_RENDERER) - end - self.mainSpineMeshRenderer.sortingOrder = order + return self.skeletonGraphic end diff --git a/lua/app/common/data_manager.lua b/lua/app/common/data_manager.lua index c55d5f17..ddd8ba45 100644 --- a/lua/app/common/data_manager.lua +++ b/lua/app/common/data_manager.lua @@ -10,6 +10,7 @@ function DataManager:init() self:initManager("HeroData", "app/userdata/hero/hero_data") self:initManager("BagData", "app/userdata/bag/bag_data") self:initManager("BattleData", "app/userdata/battle/battle_data") + self:initManager("FormationData", "app/userdata/formation/formation_data") end function DataManager:initManager(name, path) @@ -68,6 +69,7 @@ function DataManager:clear() self.ChapterData:clear() self.HeroData:clear() self.BagData:clear() + self.FormationData:clear() ModuleManager.TaskManager:clear() end @@ -85,6 +87,7 @@ function DataManager:initWithServerData(data) self.ChapterData:init(data.ChapterData) self.HeroData:init(data.HeroData) self.BagData:init(data) + self.FormationData:init(data.FormationData) self:scheduleGlobal() self:checkDataBind() diff --git a/lua/app/common/local_data.lua b/lua/app/common/local_data.lua index c2e3dc9f..511c5b5b 100644 --- a/lua/app/common/local_data.lua +++ b/lua/app/common/local_data.lua @@ -11,8 +11,6 @@ local LOCAL_DATA_KEY = { MESSAGE_BOX_SHOW_TODAY = "MESSAGE_BOX_SHOW_TODAY", GAME_QUALITY_LEVEL = "GAME_QUALITY_LEVEL", -- 游戏设置品质等级 LAST_LOGIN_URL = "LAST_LOGIN_URL", - LAST_LOGIN_INFO = "LAST_LOGIN_INFO", -- 上一次登录成功的信息 - LAST_LOGIN_TYPE = "LAST_LOGIN_TYPE", -- 上次登录类型 token不记录 LAST_LOGIN_NAME = "LAST_LOGIN_NAME", LAST_LOGIN_IP = "LAST_LOGIN_IP", ACCOUNT_INFO = "ACCOUNT_INFO", @@ -201,44 +199,6 @@ function LocalData:getIosOrders() end end -function LocalData:setLastLoginInfo(loginType, id, token) - local str = json.encode({ - type = loginType, - id = id, - token = token - }) - if not loginType then - self:setString(LOCAL_DATA_KEY.LAST_LOGIN_TYPE, "") - elseif loginType ~= "token" then - self:setString(LOCAL_DATA_KEY.LAST_LOGIN_TYPE, loginType) - end - self:setString(LOCAL_DATA_KEY.LAST_LOGIN_INFO, str) -end - -function LocalData:getLastLoginInfo() - local str = self:getString(LOCAL_DATA_KEY.LAST_LOGIN_INFO, "{}") - local info = json.decode(str) - info.type = info.type or NetManager.LOGIN_TYPE.ANONYMOUS - info.id = info.id or DeviceHelper:getDeviceId() - info.token = info.token - return info -end - -function LocalData:getLastLoginType() - local str = self:getString(LOCAL_DATA_KEY.LAST_LOGIN_TYPE, "") - if str == "" then - str = NetManager.LOGIN_TYPE.ANONYMOUS - end - if str ~= NetManager.LOGIN_TYPE.ANONYMOUS and - str ~= NetManager.LOGIN_TYPE.APPLE and - str ~= NetManager.LOGIN_TYPE.GOOGLE and - str ~= NetManager.LOGIN_TYPE.FACEBOOK - then - str = NetManager.LOGIN_TYPE.ANONYMOUS - end - return str -end - function LocalData:setLastLoginName(name) name = name or "" self:setString(LOCAL_DATA_KEY.LAST_LOGIN_NAME, name) diff --git a/lua/app/common/module_manager.lua b/lua/app/common/module_manager.lua index 638f3341..438cd95e 100644 --- a/lua/app/common/module_manager.lua +++ b/lua/app/common/module_manager.lua @@ -11,6 +11,7 @@ local MODULE_PATHS = { ToastManager = "app/ui/common/toast", TaskManager = "app/module/task/task_manager", BattleManager = "app/module/battle/battle_manager", + FormationManager = "app/module/formation/formation_manager", } -- 这里的key对应func_open里的id diff --git a/lua/app/common/scheduler_manager.lua b/lua/app/common/scheduler_manager.lua index d23049b8..3fbb4b23 100644 --- a/lua/app/common/scheduler_manager.lua +++ b/lua/app/common/scheduler_manager.lua @@ -157,8 +157,6 @@ if NOT_PUBLISH then [SDKManager.tryLoadRewardedAdDelay] = true, [ScrollRectBase.refillCells] = true, [DataManager.scheduleGlobal] = true, - [NetManager.performWithDelayGlobal] = true, - [NetManager.scheduleGlobal] = true, } end end diff --git a/lua/app/common/sdk_manager.lua b/lua/app/common/sdk_manager.lua index 8c0ecce4..f4b8e9de 100644 --- a/lua/app/common/sdk_manager.lua +++ b/lua/app/common/sdk_manager.lua @@ -280,15 +280,15 @@ function SDKManager:showFullScreenAds(adsClickType, adCallback) return true end - if NetManager:isNotReachable() then - -- 没有网 - GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.NO_NETWORK)) - return false - end - if NetManager:getIsBusy() then - GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.NETWORK_ERROE_1)) - return false - end + -- if NetManager:isNotReachable() then + -- -- 没有网 + -- GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.NO_NETWORK)) + -- return false + -- end + -- if NetManager:getIsBusy() then + -- GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.NETWORK_ERROE_1)) + -- return false + -- end if DataManager.MallActData:skipAd() then self:adRewradAd(true) if adCallback then diff --git a/lua/app/common/sdk_pay_google_manager.lua b/lua/app/common/sdk_pay_google_manager.lua index 59615ad9..a935bb5a 100644 --- a/lua/app/common/sdk_pay_google_manager.lua +++ b/lua/app/common/sdk_pay_google_manager.lua @@ -377,9 +377,9 @@ function SDKPayGoogleManager:doUncompletePay(callback) if not DataManager:getLoginSuccess() then return end - if NetManager:getIsBusy() then - return - end + -- if NetManager:getIsBusy() then + -- return + -- end if self:_getIsGoogleStoreConnected() then -- google商店是否初始化 self.alreadyFinishUncompletePay = true diff --git a/lua/app/common/sdk_pay_ios_manager.lua b/lua/app/common/sdk_pay_ios_manager.lua index 0baea03f..66857fd8 100644 --- a/lua/app/common/sdk_pay_ios_manager.lua +++ b/lua/app/common/sdk_pay_ios_manager.lua @@ -277,9 +277,9 @@ function SDKPayiOSManager:doUncompletePay(callback) if not DataManager:getLoginSuccess() then return end - if NetManager:getIsBusy() then - return - end + -- if NetManager:getIsBusy() then + -- return + -- end if self:_getIsIosInitialized() then self.alreadyFinishUncompletePay = true diff --git a/lua/app/common/server_push_manager.lua b/lua/app/common/server_push_manager.lua deleted file mode 100644 index e7c85d90..00000000 --- a/lua/app/common/server_push_manager.lua +++ /dev/null @@ -1,27 +0,0 @@ -local ServerPushManager = {} - ----- 注册推送监听 -function ServerPushManager:addServerPushListener(msgName, module, callback) - NetManager:registerMsgCallback(msgName, module, callback) -end - ----- 移除推送监听 -function ServerPushManager:removeServerPushListener(msgName, module) - NetManager:unRegisterMsgCallback(msgName, module) -end - ----- 初始化全局推送监听 -function ServerPushManager:initWhenLogin() - self:addServerPushListener(ProtoMsgType.FromMsgEnum.KickOutNtf, UIManager, UIManager.showKickOut) - self:addServerPushListener(ProtoMsgType.FromMsgEnum.MallActTriggerGiftNtf, ModuleManager.MallManager, ModuleManager.MallManager.MallActTriggerGiftNtf) - self:addServerPushListener(ProtoMsgType.FromMsgEnum.BattlePassBoughtNtf, ModuleManager.BountyManager, ModuleManager.BountyManager.buyCardFinish) - self:addServerPushListener(ProtoMsgType.FromMsgEnum.SummonPoolLevelNtf, ModuleManager.SummonManager, ModuleManager.SummonManager.SummonPoolLevelNtf) - self:addServerPushListener(ProtoMsgType.FromMsgEnum.NewMailNtf, ModuleManager.MailManager, ModuleManager.MailManager.needUpdateMail) -end - ----- 移除全局推送监听 -function ServerPushManager:removeWhenLoginOut() - self:removeServerPushListener(ProtoMsgType.FromMsgEnum.KickOutNtf, UIManager) -end - -return ServerPushManager \ No newline at end of file diff --git a/lua/app/common/spine_manager.lua b/lua/app/common/spine_manager.lua index 43263597..faf647b9 100644 --- a/lua/app/common/spine_manager.lua +++ b/lua/app/common/spine_manager.lua @@ -60,7 +60,7 @@ function SpineManager:loadUISpinePrefabAsync(parent, spineAssetPath, spineAsset, end function SpineManager:loadHeroAsync(id, parent, callback) - local path = "assets/prefabs/spine/mesh/characters/" .. id .. ".prefab" + local path = "assets/prefabs/spine/ui/characters/" .. id .. ".prefab" ResourceManager:loadAsync(path, TYPE_OF_GAME_OBJECT, function(assetPath, prefab) if parent and parent:isDestroyed() then ResourceManager:destroyPrefab(prefab) diff --git a/lua/app/config/skill_hero.lua b/lua/app/config/skill_hero.lua index 4a5a2e98..b0d9340c 100644 --- a/lua/app/config/skill_hero.lua +++ b/lua/app/config/skill_hero.lua @@ -1,6 +1,6 @@ local skill_hero = { [10]={ - ["energy"]=3, + ["energy"]=10, ["position"]=3, ["method"]=2, ["skill_type"]=1, @@ -18,7 +18,7 @@ local skill_hero = { ["battle_icon"]=1 }, [20]={ - ["energy"]=3, + ["energy"]=10, ["position"]=2, ["method"]=2, ["skill_type"]=0, @@ -35,7 +35,7 @@ local skill_hero = { ["battle_icon"]=2 }, [21]={ - ["energy"]=3, + ["energy"]=10, ["position"]=2, ["method"]=1, ["skill_type"]=2, @@ -70,7 +70,7 @@ local skill_hero = { ["battle_icon"]=2 }, [30]={ - ["energy"]=3, + ["energy"]=10, ["position"]=4, ["method"]=2, ["skill_type"]=1, @@ -84,7 +84,7 @@ local skill_hero = { ["battle_icon"]=3 }, [40]={ - ["energy"]=3, + ["energy"]=10, ["position"]=5, ["method"]=2, ["skill_type"]=0, @@ -101,7 +101,7 @@ local skill_hero = { ["battle_icon"]=4 }, [50]={ - ["energy"]=3, + ["energy"]=10, ["position"]=1, ["method"]=2, ["skill_type"]=1, @@ -119,7 +119,7 @@ local skill_hero = { ["battle_icon"]=5 }, [60]={ - ["energy"]=3, + ["energy"]=10, ["position"]=3, ["method"]=2, ["skill_type"]=0, @@ -136,7 +136,7 @@ local skill_hero = { ["battle_icon"]=6 }, [70]={ - ["energy"]=3, + ["energy"]=10, ["position"]=2, ["method"]=2, ["skill_type"]=0, @@ -153,7 +153,7 @@ local skill_hero = { ["battle_icon"]=7 }, [71]={ - ["energy"]=3, + ["energy"]=10, ["position"]=2, ["method"]=1, ["skill_type"]=2, @@ -189,7 +189,7 @@ local skill_hero = { ["battle_icon"]=7 }, [72]={ - ["energy"]=3, + ["energy"]=10, ["position"]=2, ["method"]=1, ["skill_type"]=2, @@ -232,7 +232,7 @@ local skill_hero = { ["battle_icon"]=7 }, [80]={ - ["energy"]=3, + ["energy"]=10, ["position"]=4, ["method"]=2, ["skill_type"]=0, @@ -254,7 +254,7 @@ local skill_hero = { ["battle_icon"]=8 }, [81]={ - ["energy"]=3, + ["energy"]=10, ["position"]=4, ["method"]=2, ["skill_type"]=1, diff --git a/lua/app/game.lua b/lua/app/game.lua index cd6d6415..93e283fd 100644 --- a/lua/app/game.lua +++ b/lua/app/game.lua @@ -73,13 +73,11 @@ function Game:initOther() BF.exports.EffectManager = require "app/common/effect_manager" BF.exports.SpineManager = require "app/common/spine_manager" BF.exports.WebRequestManager = require "app/common/webrequest_manager" - BF.exports.NetManager = require "app/net/net_manager" BF.exports.I18N = require "app/common/i18n_manager" BF.exports.CellManager = require "app/common/cell_manager" BF.exports.Time = require "app/common/time" BF.exports.BaseData = require "app/userdata/base_data" BF.exports.BaseObject = require "app/bf/unity/base_object" - BF.exports.ServerPushManager = require "app/common/server_push_manager" BF.exports.SafeAreaManager = require "app/common/safe_area_manager" BF.exports.BaseModule = require "app/module/base_module" BF.exports.ModuleManager = require "app/common/module_manager" @@ -95,7 +93,6 @@ function Game:initOther() CameraManager:init() WebRequestManager:init() - NetManager:init() I18N:init() ServerDataManager:init() DataManager:init() @@ -143,13 +140,11 @@ function Game:specialForIdea() EffectManager = EffectManager or require "app/common/effect_manager" SpineManager = SpineManager or require "app/common/spine_manager" WebRequestManager = WebRequestManager or require "app/common/webrequest_manager" - NetManager = NetManager or require "app/net/net_manager" I18N = I18N or require "app/common/i18n_manager" CellManager = CellManager or require "app/common/cell_manager" Time = Time or require "app/common/time" BaseData = BaseData or require "app/userdata/base_data" BaseObject = BaseObject or require "app/bf/unity/base_object" - ServerPushManager = ServerPushManager or require "app/module/login/server_push_manager" SafeAreaManager = SafeAreaManager or require "app/common/safe_area_manager" BaseModule = BaseModule or require "app/module/base_module" ModuleManager = ModuleManager or require "app/common/module_manager" diff --git a/lua/app/global/global_const.lua b/lua/app/global/global_const.lua index ae2c65e0..b7adc1a9 100644 --- a/lua/app/global/global_const.lua +++ b/lua/app/global/global_const.lua @@ -10,6 +10,7 @@ local CONST_PATHS = { TutorialConst = "app/module/tutorial/tutorial_const", BattleConst = "app/module/battle/battle_const", HeroConst = "app/module/hero/hero_const", + FormationConst = "app/module/formation/formation_const", } if EDITOR_MODE then @@ -366,6 +367,16 @@ GConst.HERO_FRAME_QLT = { [7] = "frame_7", } +GConst.HERO_FRAME_GRAY_QLT = { + [1] = "frame_gray_1", + [2] = "frame_gray_2", + [3] = "frame_gray_3", + [4] = "frame_gray_4", + [5] = "frame_gray_5", + [6] = "frame_gray_6", + [7] = "frame_gray_7", +} + GConst.QLT_LABLE = { DEFAULT = "equip_quality_1", GRAY = "equip_quality_1", diff --git a/lua/app/global/global_func.lua b/lua/app/global/global_func.lua index 38bad6fe..6e7918b2 100644 --- a/lua/app/global/global_func.lua +++ b/lua/app/global/global_func.lua @@ -1535,25 +1535,6 @@ function GFunc.getRewardTable(type, id, count) } end -function GFunc.formatRewardsToServerStruct(rewardList) - local rewards = {} - for _, reward in ipairs(rewardList) do - local serverReward = GFunc.getServerRewardTable(reward.type, reward.id, reward.count) - table.insert(rewards, serverReward) - end - return rewards -end - -function GFunc.getServerRewardTable(type, id, count) - if type == GConst.REWARD_TYPE.ITEM then - return GFunc.getServerItemRewardTable(id, count) - elseif type == GConst.REWARD_TYPE.RUNES then - return GFunc.getServerRuneRewardTable(id, BigNumOpt.bigNum2Num(count)) - elseif type == GConst.REWARD_TYPE.EQUIP then - return GFunc.getServerEquipRewardTable(id, count) - end -end - function GFunc.getServerRuneRewardTable(id, level) return { type = GConst.REWARD_TYPE.RUNES, diff --git a/lua/app/module/base_module.lua b/lua/app/module/base_module.lua index 270b1017..23a1ee55 100644 --- a/lua/app/module/base_module.lua +++ b/lua/app/module/base_module.lua @@ -72,19 +72,6 @@ function BaseModule:removeAllEventListeners() end end --- 阻塞式,等待服务器回复以后再回调callback -function BaseModule:sendMessage(msgName, params, responseData, callback, getType, lockGame) - if lockGame == nil then - lockGame = true - end - NetManager:send(self, msgName, params, responseData, callback, lockGame, nil, getType) -end - --- 阻塞式,等待所有指令完成以后再发送此消息,并且锁界面,等待服务器回复以后再回调callback -function BaseModule:sendMessageTillBeforeOver(msgName, params, responseData, callback, getType) - NetManager:sendTillBeforeOver(self, msgName, params, responseData, callback, true, nil, getType) -end - -- 各个模块的manager按各自需求来重写clear即可 function BaseModule:clear() end diff --git a/lua/app/module/battle/battle_const.lua b/lua/app/module/battle/battle_const.lua index 8adf99ba..e55cf3e6 100644 --- a/lua/app/module/battle/battle_const.lua +++ b/lua/app/module/battle/battle_const.lua @@ -13,10 +13,20 @@ BattleConst.ELEMENT_WIGHT = 100 BattleConst.MAX_ELEMENT_WIGHT = 500 BattleConst.SIDE_ATK = 1 BattleConst.SIDE_DEF = 2 +BattleConst.SKILL_TYPE_ACTIVE = 1 BattleConst.SKILL_SELECT_COUNT = 3 +BattleConst.DEFAULT_FACTOR = 10000 +BattleConst.INIT_POS_X = 200 +BattleConst.UNIT_BODY_WIDTH = 100 +-- 为方便存储,这里使用字符串 BattleConst.BATTLE_TYPE = { - STAGE = 1, + STAGE = "1", +} + +BattleConst.TYPEOF_LUA_COMP = { + BATTLE_HERO_COMPONENT = "app/module/battle/component/battle_hero_comp", + BATTLE_MONSTER_COMPONENT = "app/module/battle/component/battle_monster_comp", } BattleConst.UNIT_STATE = { @@ -27,6 +37,10 @@ BattleConst.UNIT_STATE = { DEAD = 4, -- 死亡 } +BattleConst.SPINE_ANIMATION_NAME = { + IDLE = "idle", +} + ---- 格子类型 BattleConst.GRID_TYPE = { EMPTY = 0, diff --git a/lua/app/module/battle/component/battle_hero_comp.lua b/lua/app/module/battle/component/battle_hero_comp.lua new file mode 100644 index 00000000..efa66e27 --- /dev/null +++ b/lua/app/module/battle/component/battle_hero_comp.lua @@ -0,0 +1,17 @@ +local BattleConst = require "app/module/battle/battle_const" +local BattleUnitComp = require "app/module/battle/component/battle_unit_comp" + +local BattleHeroComp = class("BattleHeroComp", BattleUnitComp) + +local UNIT_STATE = BattleConst.UNIT_STATE + +function BattleHeroComp:init() + self.battleMgr = CS.BF.BFMain.Instance.BattleMgr +end + +function BattleHeroComp:initBase() + self.isDead = false + self.currState = UNIT_STATE.INIT +end + +return BattleHeroComp \ No newline at end of file diff --git a/lua/app/net/net_manager.lua.meta b/lua/app/module/battle/component/battle_hero_comp.lua.meta similarity index 86% rename from lua/app/net/net_manager.lua.meta rename to lua/app/module/battle/component/battle_hero_comp.lua.meta index fee86fd5..cc33f0f3 100644 --- a/lua/app/net/net_manager.lua.meta +++ b/lua/app/module/battle/component/battle_hero_comp.lua.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: bc2318d7940bb8e41b78633f73e985e8 +guid: 2de8b968215b6754d98014fe8d8feedf ScriptedImporter: internalIDToNameTable: [] externalObjects: {} diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index 66d9b36f..2863958c 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -3,12 +3,22 @@ local BattleConst = require "app/module/battle/battle_const" local BattleUnitComp = class("BattleUnitComp", LuaComponent) local UNIT_STATE = BattleConst.UNIT_STATE +local SIDE_ATK = BattleConst.SIDE_ATK +local SPINE_ANIMATION_NAME = BattleConst.SPINE_ANIMATION_NAME function BattleUnitComp:ctor() end -function BattleUnitComp:init() - self:_initBase() +function BattleUnitComp:initPosition() + if self.unitEntity:getSide() == SIDE_ATK then + self.baseObject:setLocalPosition(-BattleConst.INIT_POS_X, 0, 0) + else + self.baseObject:setLocalPosition(BattleConst.INIT_POS_X, 0, 0) + end +end + +function BattleUnitComp:playBorn() + self:playAnimation(SPINE_ANIMATION_NAME.IDLE, true, false) end function BattleUnitComp:_initBase() @@ -16,21 +26,44 @@ function BattleUnitComp:_initBase() self.isDead = false end -function BattleUnitComp:tick(dt) - if self.isClear then - return - end - if self.isDead then - self:updateDead(dt) - return - end - if self.currState == UNIT_STATE.IDLE then - self:updateIdle(dt) - return - end - if self.currState == UNIT_STATE.ATTACK then - self:updateAttack(dt) +function BattleUnitComp:initWithEntity(modelId, entity, battleController, target) + self.modelId = modelId + self.unitEntity = entity + self.battleController = battleController + self.target = target + self:_initBase() + self:initPosition() + self:playBorn() +end + +function BattleUnitComp:hideOutsideScreen() + if self.unitEntity:getSide() == SIDE_ATK then + self.baseObject:setLocalPosition(-GConst.UI_SCREEN_WIDTH/2 - BattleConst.UNIT_BODY_WIDTH, 0, 0) + else + self.baseObject:setLocalPosition(GConst.UI_SCREEN_WIDTH/2 + BattleConst.UNIT_BODY_WIDTH, 0, 0) end end +function BattleUnitComp:playAnimation(name, loop, forceRefresh) + self.currAnimationName = name + self.baseObject:playAnimation(name, loop, forceRefresh) +end + +function BattleUnitComp:tick(dt) + -- if self.isClear then + -- return + -- end + -- if self.isDead then + -- self:updateDead(dt) + -- return + -- end + -- if self.currState == UNIT_STATE.IDLE then + -- self:updateIdle(dt) + -- return + -- end + -- if self.currState == UNIT_STATE.ATTACK then + -- self:updateAttack(dt) + -- end +end + return BattleUnitComp \ No newline at end of file diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index 945fa369..dfc731c0 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -1,3 +1,5 @@ +local BattleHelper = require "app/module/battle/helper/battle_helper" + local BattleController = class("BattleController") local BATTLE_BOARD_SKILL_HANDLE = require "app/module/battle/skill/battle_board_skill_handle" @@ -32,6 +34,11 @@ end function BattleController:initOther() end +-- 需要额外加载的资源 +function BattleController:loadOtherRes(callback) + return callback() +end + function BattleController:onLinkChange() for posId, entity in pairs(DataManager.BattleData:getGridEnties()) do if entity:getCell() then @@ -85,12 +92,59 @@ end function BattleController:init(params) params = params or {} DataManager.BattleData:init(self:getInitBoard()) + BattleHelper:init() + self:prepareFight() +end +function BattleController:prepareFight() + local count = 0 + local totalCount = 2 + local function onPreloadFinished() + count = count + 1 + if count == totalCount then + self:onLoadComplete() + end + end UIManager:closeAllUI() - self.battleUI = UIManager:showUI(self:getBattleUIPath()) + self.battleUI = UIManager:showUI(self:getBattleUIPath()) self.battleUI:setController(self) self.battleUI:addLoadUICompleteListener(function() + self:initAllUnits(onPreloadFinished) end) + self:loadOtherRes(onPreloadFinished) +end + +function BattleController:initAllUnits(callback) + self.atkUnits = {} + self.defUnits = {} + local atkTeam = DataManager.BattleData:getAtkTeam() + local count = 0 + local totalCount = atkTeam:getMembersCount() + local function onloadFinished() + count = count + 1 + if count == totalCount then + callback() + end + end + local members = atkTeam:getAllMembers() + for k, v in pairs(members) do + local modelId = v:getModelId() + BattleHelper:loadBattleHeroModel(modelId, self.battleUI:getBattleNode(), function(spineObject) + local heroComp = spineObject:addLuaComponent(BattleConst.TYPEOF_LUA_COMP.BATTLE_HERO_COMPONENT) + heroComp:initWithEntity(modelId, v, self) + self.atkUnits[v:getMatchType()] = heroComp + if not v:getIsMainUnit() then + heroComp:hideOutsideScreen() + end + onloadFinished() + end) + end + if totalCount == 0 then + callback() + end +end + +function BattleController:onLoadComplete() end function BattleController:onTouchEvent(eventType, posId) @@ -755,7 +809,7 @@ function BattleController:snapshotBoard() end function BattleController:clear() - + BattleHelper:clear() end function BattleController:endBattleAndExit() diff --git a/lua/app/common/server_push_manager.lua.meta b/lua/app/module/battle/helper.meta similarity index 67% rename from lua/app/common/server_push_manager.lua.meta rename to lua/app/module/battle/helper.meta index e4acbbde..6279aa3d 100644 --- a/lua/app/common/server_push_manager.lua.meta +++ b/lua/app/module/battle/helper.meta @@ -1,5 +1,6 @@ fileFormatVersion: 2 -guid: 1c64e57074a12a04a98c2bd95599566a +guid: 05735c0c843e6724883965982ae2da2b +folderAsset: yes DefaultImporter: externalObjects: {} userData: diff --git a/lua/app/module/battle/helper/battle_helper.lua b/lua/app/module/battle/helper/battle_helper.lua new file mode 100644 index 00000000..44127959 --- /dev/null +++ b/lua/app/module/battle/helper/battle_helper.lua @@ -0,0 +1,52 @@ +local BattleHelper = {} + +function BattleHelper:init() + self.isClear = false + self.characterPools = {} + self.characterMap = {} +end + +function BattleHelper:loadBattleHeroModel(id, parent, callback) + local pool = self.characterPools[id] + if pool and #pool > 0 then + local spineObject = table.remove(pool) + spineObject:setActive(true) + if self.characterMap then + self.characterMap[spineObject:getInstanceID()] = spineObject + end + callback(spineObject) + else + SpineManager:loadHeroAsync(id, parent, function(spineObject) + if self.characterMap then + self.characterMap[spineObject:getInstanceID()] = spineObject + callback(spineObject) + end + end) + end +end + +function BattleHelper:recycleBattleHeroModel(modelId, character) + if character:isDestroyed() then + return + end + character:setActive(false) + if self.characterMap then + self.characterMap[character:getInstanceID()] = nil + end + if self.characterPools then + local pool = self.characterPools[modelId] + if pool == nil then + pool = {} + self.characterPools[modelId] = pool + end + table.insert(pool, character) + end +end + +function BattleHelper:clear() + self.isClear = true + self.characterPools = nil + self.characterMap = nil +end + +return BattleHelper \ No newline at end of file diff --git a/lua/app/module/battle/helper/battle_helper.lua.meta b/lua/app/module/battle/helper/battle_helper.lua.meta new file mode 100644 index 00000000..8338ef0b --- /dev/null +++ b/lua/app/module/battle/helper/battle_helper.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 58d901e56ad3d444ca0bc601e83444c3 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/module/formation.meta b/lua/app/module/formation.meta new file mode 100644 index 00000000..a64e7431 --- /dev/null +++ b/lua/app/module/formation.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 711a478ba771167498a776130c47c479 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/lua/app/module/formation/formation_manager.lua b/lua/app/module/formation/formation_manager.lua new file mode 100644 index 00000000..8905c2c2 --- /dev/null +++ b/lua/app/module/formation/formation_manager.lua @@ -0,0 +1,20 @@ +local FormationManager = class("FormationManager", BaseModule) + +function FormationManager:upHeroToStageFormation(heroId, matchType) + local formation = DataManager.FormationData:getStageFormation() + if formation[matchType] == heroId then + return + end + local args = { + formationType = GConst.BattleConst.BATTLE_TYPE.STAGE, + matchType = matchType, + heroId = heroId + } + ServerDataManager:dataOperate(GConst.ServerDataConst.DATA_OP_BEHAVIOR.UPDATE_FORMATION, args, function(msgData) + if msgData.status == 0 then + DataManager.FormationData:upHeroToFormation(GConst.BattleConst.BATTLE_TYPE.STAGE, matchType, heroId) + end + end) +end + +return FormationManager \ No newline at end of file diff --git a/lua/app/module/formation/formation_manager.lua.meta b/lua/app/module/formation/formation_manager.lua.meta new file mode 100644 index 00000000..c06cd8fa --- /dev/null +++ b/lua/app/module/formation/formation_manager.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: a5234cdd00d84e543a3afe369d8a4c4d +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/module/gm/gm_const.lua b/lua/app/module/gm/gm_const.lua index d7b587be..dca5e347 100644 --- a/lua/app/module/gm/gm_const.lua +++ b/lua/app/module/gm/gm_const.lua @@ -30,98 +30,6 @@ Example: del_item]], Example: clear_item]], type = "clear_item" }, - { - title = "通关", - desc = [[通关 type:pass_chapter -Example: pass_chapter 100]], - type = "pass_chapter" - }, --- { --- title = "添加装备", --- desc = [[添加装备 type:addEquip --- arg1:equipId arg2:数量 --- Example: addEquip 10103 2]], --- type = "addEquip" --- }, --- { --- title = "设置等级", --- desc = [[清号 type:setLv --- arg1:数量 --- Example: setLv 100]], --- type = "setLv" --- }, - { - title = "全装备", - desc = [[全装备 type:all_equips -Example: all_equips]], - type = "all_equips" - }, - { - title = "全传家宝", - desc = [[全传家宝 type:all_legacies -Example: all_legacies]], - type = "all_legacies" - }, - { - title = "全符文", - desc = [[全符文 type:all_runes -Example: all_runes]], - type = "all_runes" - }, - { - title = "每日重置", - desc = [[每日重置 type:reset_by_day -Example: reset_by_day]], - type = "reset_by_day" - }, - { - title = "设置时间", - desc = [[设置时间 type:time -Example: time 2023-3-9 18:10:59]], - type = "time" - }, - { - title = "重置时间差", - desc = [[重置时间差 type:time_diff -Example: time_diff 0]], - type = "time_diff" - }, - { - title = "调整时间差", - desc = [[调整时间差 type:add_time_diff -Example: add_time_diff 1000]], - type = "add_time_diff" - }, - { - title = "设置引导任务状态", - desc = [[通关 type:task_tutor -Example: task_tutor id progress 0]], - type = "task_tutor" - }, - { - title = "设置任务进度", - desc = [[通关 type:trig_event -Example: trig_event task_type progress]], - type = "trig_event" - }, - { - title = "礼包购买", - desc = [[通关 type:add_gift 1.mall_act 2.mall_daily 3.mall_treasure -Example: add_gift 1 30001]], - type = "add_gift" - }, - { - title = "新增邮件", - desc = [[通关 type:add_mail id -Example: add_mail 1]], - type = "add_mail" - }, - { - title = "新增自定义邮件", - desc = [[通关 type:add_cumail title body attachment -Example: add_cumail title body attachment]], - type = "add_cumail" - }, } return GMConst \ No newline at end of file diff --git a/lua/app/module/item/item_const.lua b/lua/app/module/item/item_const.lua index 2de80f80..d8902b8b 100644 --- a/lua/app/module/item/item_const.lua +++ b/lua/app/module/item/item_const.lua @@ -2,6 +2,7 @@ local ItemConst = {} ItemConst.ITEM_ID_GOLD = 1 ItemConst.ITEM_ID_GEM = 2 +ItemConst.ITEM_ID_VIT = 3 ItemConst.ITEM_TYPE = { RES = 1, diff --git a/lua/app/module/login/login_manager.lua b/lua/app/module/login/login_manager.lua index 409390d5..af9a8724 100644 --- a/lua/app/module/login/login_manager.lua +++ b/lua/app/module/login/login_manager.lua @@ -37,7 +37,6 @@ end function LoginManager:goToLoginScene() ModuleManager.BattleManager:clearOnExitScene() - NetManager:closeAndClear() UIManager:backToLoginWithoutLogout() DataManager:clear() end diff --git a/lua/app/module/login/login_ui.lua b/lua/app/module/login/login_ui.lua index 5c1e1489..e6441448 100644 --- a/lua/app/module/login/login_ui.lua +++ b/lua/app/module/login/login_ui.lua @@ -38,9 +38,6 @@ function LoginUI:onLoadRootComplete() self:refreshServerList(serverList) ModuleManager.LoginManager:saveAuthArgs() ModuleManager.LoginManager:initSocket() - - local info = LocalData:getLastLoginInfo() - BIReport:postAccountLoginClick(info.type) end) -- first 可以卸载了, 此项目只会启动时检查一次热更,之后不会再次检查 diff --git a/lua/app/module/login/test_login_ui.lua b/lua/app/module/login/test_login_ui.lua index 35d1eea9..7abd3bd8 100644 --- a/lua/app/module/login/test_login_ui.lua +++ b/lua/app/module/login/test_login_ui.lua @@ -77,9 +77,6 @@ function TestLoginUI:loginGame() -- ModuleManager.LoginManager:initSocket() ModuleManager.LoginManager:loginGame() - local info = LocalData:getLastLoginInfo() - BIReport:postAccountLoginClick(info.type) - -- first 可以卸载了, 此项目只会启动时检查一次热更,之后不会再次检查 CS.BF.BFMain.Instance.LuaMgr:OnGameInitSucc() LocalData:save() diff --git a/lua/app/module/tutorial/tutorial_manager.lua b/lua/app/module/tutorial/tutorial_manager.lua index 020677bf..50a3962f 100644 --- a/lua/app/module/tutorial/tutorial_manager.lua +++ b/lua/app/module/tutorial/tutorial_manager.lua @@ -285,9 +285,7 @@ function TutorialManager:gmSkipTutorial() end -- 强制引导则先跟服务器发送消息再退出 - -- NetManager:send(ProtoMsgType.FromMsgEnum.SkipGuideReq, {}, function(data) - self:stopTutorial() - -- end) + self:stopTutorial() end return TutorialManager \ No newline at end of file diff --git a/lua/app/net/net_manager.lua b/lua/app/net/net_manager.lua deleted file mode 100644 index 2633cd9a..00000000 --- a/lua/app/net/net_manager.lua +++ /dev/null @@ -1,1159 +0,0 @@ -local NetManager = -{ - receiveCallbacks = {}, - msgCallbacks = {}, - isClosedMap = {}, - chatReconnectWaitTime = 1, - connectIPMap = {}, - receiveCallbackPool = {}, - alreadyConnected = {}, - mainReconnectWaitTime = 0, - sendQueue = {}, - tillBeforeOverCount = 0, - msgId = 0 -} - -local CSApplication = CS.UnityEngine.Application -local CSNotReachable = CS.UnityEngine.NetworkReachability.NotReachable - -local MAX_CHAT_WAIT_TIME = 16 -local MAX_MAIN_WAIT_TIME = 10 -local JOIN_CHAT_INTERVAL = 15 -local TILL_BEFORE_INTERVAL = 0.5 - -local NetErrorCode = CS.BF.NetErrorCode - -local pb = require "pb" -local ProtoMsgDispatch = require "app/proto/proto_msg_dispatch" - -local protoPaths = -{ - "assets/proto/protocol.bytes", -} - -NetManager.MAIN_SOCKET_NAME = 0 -NetManager.CHAT_SOCKET_NAME = 1 -NetManager.LOGIN_TYPE = { - TOKEN = "token", - ANONYMOUS = "anonymous", - GOOGLE = "google", - APPLE = "apple", - FACEBOOK = "facebook", -} - -function NetManager:getGate() - if EDITOR_MODE then - return "http://game.juzugame.com:3000" - else - return "https://d3ksek7t8d0wbt.cloudfront.net/" - end -end - -function NetManager:init(callback) - self.chatReconnectWaitTime = 1 - - CS.BF.BFMain.Instance.NetMgr:InitNetClientCount(1) -- 只有主链接,没有聊天,但是聊天逻辑先不删 - if self.initSucc then - if callback then - return callback() - end - end - self.initSucc = true - -- pb.option "int64_as_string" --如果需要uint64再加上 - - local loadCount = #protoPaths - for i, path in ipairs(protoPaths) do - ResourceManager:loadOriginAssetAsync(path, GConst.TYPEOF_UNITY_CLASS.TEXT_ASSET, function(_, textAsset) - pb.load(textAsset.bytes) - ResourceManager:unload(path) - loadCount = loadCount - 1 - if loadCount == 0 then - if callback then - return callback() - end - end - end) - end -end - -function NetManager:setChatUrl(url) - local arr = string.split(url, ":") - self.chatDomain = arr[1] - self.chatPort = arr[2] -end - -function NetManager:getChatDomain() - return self.chatDomain -end - -function NetManager:getChatPort() - return self.chatPort -end - -function NetManager:getIsBusy() - -- return self.lastMsgName ~= nil - return false -end - -function NetManager:isNotReachable() - return CSApplication.internetReachability == CSNotReachable -end - -function NetManager:connect(domain, port, callback, socketName) - socketName = socketName or NetManager.MAIN_SOCKET_NAME - if self:isAvailable(socketName) then - if callback then - callback() - end - return - end - - self.alreadyConnected[socketName] = false - self.isClosedMap[socketName] = false - - if socketName == NetManager.MAIN_SOCKET_NAME then - UIManager:showWaitNet(true) - end - - self.connectIPMap[socketName] = "" - - CS.BF.BFMain.Instance.NetMgr:AddLuaOnConnected(function(name) - self.alreadyConnected[name] = true - Logger.log("connect success:%s", name) - local connectIP = self:getConnectIP(name) - self.connectIPMap[socketName] = connectIP - if name == NetManager.MAIN_SOCKET_NAME then - if self.reconnectMainId then - SchedulerManager:unscheduleGlobal(self.reconnectMainId) - self.reconnectMainId = nil - end - self.mainReconnectWaitTime = 0 - UIManager:hideWaitNet() - else - self.chatReconnectWaitTime = 1 - if self.reconnectChatId then - SchedulerManager:unscheduleGlobal(self.reconnectChatId) - self.reconnectChatId = nil - end - if DataManager.ChatData then - DataManager.ChatData:onConnect() - end - self:joinChatChannel() - end - if callback then - callback() - end - end) - - CS.BF.BFMain.Instance.NetMgr:AddLuaOnDisconnected(function(name) - self:onDisconnect(name) - end) - - CS.BF.BFMain.Instance.NetMgr:AddLuaOnReceiveMessage(function(name, group, recvId, bytes) - if name == NetManager.MAIN_SOCKET_NAME then - self.recvId = recvId - if self.reconnectMainFlag then -- 如果是在重连状态下收到消息就设置下重连所需要的数据 - self:setReconnectData() - end - end - self:onReceive(group, bytes) - end) - - CS.BF.BFMain.Instance.NetMgr:AddLuaOnError(function(name, errorCode, errorMsg) - self:onError(name, errorCode, errorMsg) - end) - - CS.BF.BFMain.Instance.NetMgr:AddLuaOnReconnectSuccess(function(name) - Logger.log("reconnect succes:%s", name) - self:trySend() - if name == NetManager.MAIN_SOCKET_NAME then - if self.reconnectMainId then - SchedulerManager:unscheduleGlobal(self.reconnectMainId) - self.reconnectMainId = nil - end - self.mainReconnectWaitTime = 0 - if self.reconnectMainFlag then - self.reconnectMainFlag = false - end - if self.activeReconnectMainFlag then - self.activeReconnectMainFlag = false - UIManager:hideWaitNet() - if UIManager:getWaitNetCount() == 0 then - UIManager:hideMessageBoxByTag(GConst.GAME_OBJECT_TYPE.MESSAGEBOX_RECONNECT) - end - end - else - self.chatReconnectWaitTime = 1 - if self.reconnectChatId then - SchedulerManager:unscheduleGlobal(self.reconnectChatId) - self.reconnectChatId = nil - end - if self.joinChatId then - SchedulerManager:unscheduleGlobal(self.joinChatId) - self.joinChatId = nil - end - if DataManager.ChatData then - DataManager.ChatData:onConnect() - end - self:joinChatChannel() - end - end) - - CS.BF.BFMain.Instance.NetMgr:SetLuaOnDecodePbCallback(function(name, group, recvId, data) - local msgName = ProtoMsgDispatch:getReqMsgNameByMsgId(group) - if msgName == nil then - return - end - Logger.log("1===onReceive=== %s:%d", msgName, group) - - -- 这里保证即使协议有问题解不出来也不要卡住 - local ok, pbData = pcall(function() - local fullMsgName = ProtoMsgDispatch:getMsgFullNameByMsgName(msgName) - return pb.decode(fullMsgName, data) - end) - - if ok and pbData then - pbData.status = not pbData.err_code and 0 or ProtoMsgDispatch:getErrCodeEnum(pbData.err_code) - if pbData.status ~= 0 then - self:closeAndClear() - local lastLoginType = LocalData:getLastLoginType() - if lastLoginType == NetManager.LOGIN_TYPE.GOOGLE or lastLoginType == NetManager.LOGIN_TYPE.APPLE then - local loginType = SDKManager.BF_LOGIN_TYPE.GOOGLE - if lastLoginType == NetManager.LOGIN_TYPE.APPLE then - loginType = SDKManager.BF_LOGIN_TYPE.APPLE - end - SDKManager:login(function(params) - if not params.token then - return - end - LocalData:setLastLoginInfo(lastLoginType, params.id, params.token) - ModuleManager.LoginManager:saveAuthArgs() - ModuleManager.LoginManager:initSocket() - end, loginType) - else - LocalData:setLastLoginInfo() - ModuleManager.LoginManager:saveAuthArgs() - local params = { - content = I18N:getGlobalText(I18N.GlobalConst.DISCONNECT_RELOGIN), - okText = I18N:getGlobalText(I18N.GlobalConst.BTN_TEXT_OK), - noShowClose = true, - okFunc = function() - ModuleManager.LoginManager:initSocket() - end, - boxType = GConst.MESSAGE_BOX_TYPE.MB_OK, - top = true, - } - GFunc.showMessageBox(params) - end - else - LocalData:setLastLoginInfo(NetManager.LOGIN_TYPE.TOKEN, pbData.id, pbData.token) - LocalData:setAccountInfo(pbData) - BIReport:updateAccountId(pbData.id) - - pbData.send_id = pbData.send_id or 0 - pbData.err_code = nil - CS.BF.BFMain.Instance.NetMgr.decodePbStr = json.encode(pbData) - CS.BF.BFMain.Instance.NetMgr.rspGroup = group - CS.BF.BFMain.Instance.NetMgr.decodeFinish = true - end - end - end) - - CS.BF.BFMain.Instance.NetMgr:SetLuaAuthCallback(function(isSuccess) - if not isSuccess then - local params = { - content = I18N:getGlobalText(I18N.GlobalConst.DISCONNECT_RELOGIN), - okText = I18N:getGlobalText(I18N.GlobalConst.BTN_TEXT_OK), - noShowClose = true, - okFunc = function() - ModuleManager.LoginManager:goToLoginScene() - end, - boxType = GConst.MESSAGE_BOX_TYPE.MB_OK, - top = true, - } - GFunc.showMessageBox(params) - end - end) - - local configuration = CS.BF.NetConnectConfiguration(CS.BF.NetServiceType.TCPService, tostring(socketName)) - configuration:EnableMessageType(CS.BF.NetIncomingMessageType.DebugMessage) - configuration:EnableMessageType(CS.BF.NetIncomingMessageType.WarningMessage) - configuration:EnableMessageType(CS.BF.NetIncomingMessageType.ErrorMessage) - if socketName == NetManager.MAIN_SOCKET_NAME then - configuration.EnableSilenceReconnect = false -- game连接不用自动重连 - configuration.ReconnectTimeoutTime = GConst.WAIT_NET_RSP_TIME -- 每次重连超时时间 - configuration.AlreadySendMessageCacheCount = 3 - else - -- configuration.ReconnectTimeoutTime = 8 -- 每次重连超时时间 - -- configuration.ReconnectBaseInterval = 1 -- 每次重连间隔时间 - -- configuration.AutoReconnectCount = 5 -- 重连次数 - -- 自动重连可能有bug,先手动重连 - configuration.EnableSilenceReconnect = false -- chat连接不用自动重连 - configuration.ReconnectTimeoutTime = MAX_CHAT_WAIT_TIME -- 每次重连超时时间 - configuration.AlreadySendMessageCacheCount = 3 - end - CS.BF.BFMain.Instance.NetMgr:ConnectWithConfiguration(socketName, configuration, domain, tonumber(port)) -end - -function NetManager:isConnected(socketName) - if not self.initSucc then - return false - end - return CS.BF.BFMain.Instance.NetMgr:IsConnected(socketName) -end - -function NetManager:isAvailable(socketName) - if not self.initSucc then - return false - end - return CS.BF.BFMain.Instance.NetMgr:IsAvailable(socketName) -end - -function NetManager:isDisconnected(socketName) - if not self.initSucc then - return true - end - return CS.BF.BFMain.Instance.NetMgr:IsDisconnected(socketName) -end - -function NetManager:getConnectIP(socketName) - if not self.initSucc then - return "" - end - return CS.BF.BFMain.Instance.NetMgr:GetConnectIP(socketName) -end - -function NetManager:_sendBytes(clientName, bytes, group, cmd) - self.isSending = true - CS.BF.BFMain.Instance.NetMgr:Send(clientName, group, cmd, bytes) -end - ----- 后台发送协议,不锁定界面 -function NetManager:sendOnBackground(msgName, params, callback, socketName) - self:_send(msgName, params, callback, socketName, false) -end - ----- 后台发送协议,不锁定界面,且不会有回复 -function NetManager:sendOnBackgroundWithoutRsp(msgName, params, socketName) - self:_send(msgName, params, nil, socketName, false, true) -end - -function NetManager:saveAuthArgs(authArgs) - local msgFullName = ProtoMsgDispatch:getMsgFullNameByMsgName(ProtoMsgType.FromMsgEnum.AuthReq) - local bytes = pb.encode(msgFullName, authArgs) - CS.BF.BFMain.Instance.NetMgr.authReqData = bytes -end - -function NetManager:saveChatAuthArgs(token) - local msgFullName = ProtoMsgDispatch:getMsgFullNameByMsgName(ProtoMsgType.FromMsgEnum.ChatAuthReq) - local args = { - id = DataManager.PlayerData:getUid(), - token = token - } - CS.BF.BFMain.Instance.NetMgr.ChatAuthReqData = pb.encode(msgFullName, args) -end - -function NetManager:send(binder, msgName, params, responseData, callback, lockGame, noRsp, getType) - if responseData.rewards then - responseData.rewards = GFunc.formatRewardsToServerStruct(responseData.rewards) - end - if responseData.costs then - responseData.costs = GFunc.formatRewardsToServerStruct(responseData.costs) - end - responseData.err_code = GConst.ERROR_STR.SUCCESS - self:_send(binder, msgName, params, responseData, callback, lockGame, noRsp, getType) -end - -function NetManager:sendTillBeforeOver(binder, msgName, params, responseData, callback, lockGame, noRsp, getType) - if responseData.rewards then - responseData.rewards = GFunc.formatRewardsToServerStruct(responseData.rewards) - end - if responseData.costs then - responseData.costs = GFunc.formatRewardsToServerStruct(responseData.costs) - end - responseData.err_code = GConst.ERROR_STR.SUCCESS - self:_send(binder, msgName, params, responseData, callback, lockGame, noRsp, getType, true) -end - -function NetManager:_send(binder, msgName, params, responseData, callback, lockGame, noRsp, getType, beforeOver) - local socketName = NetManager.MAIN_SOCKET_NAME - if self:isDisconnected(socketName) then - if socketName == NetManager.MAIN_SOCKET_NAME then - if UIManager:getWaitNetCount() > 0 then - self:disconnect(socketName) - else - if self.reconnectMainId then - SchedulerManager:unscheduleGlobal(self.reconnectMainId) - self.reconnectMainId = nil - end - self:reconnectMain() - end - else - self:disconnect(socketName) - end - else - if beforeOver then - UIManager:showWaitNet() - self.tillBeforeOverCount = self.tillBeforeOverCount + 1 - end - local pipedMsgName, pipedParams = self:pipedMessage(msgName, params) - table.insert(self.sendQueue, { - binder = binder, - originMsgName = msgName, - msgName = pipedMsgName, - params = pipedParams, - responseData = responseData, - socketName = socketName, - callback = callback, - lockGame = lockGame, - noRsp = noRsp, - getType = getType, - beforeOver = beforeOver, - }) - if not self:isNotSave(msgName) then - self:saveSendQueue() - end - - self:trySend() - end -end - -function NetManager:trySend() - local binder - local originMsgName - local curMsgName - local curParams - local responseData - local getType - local curSocketName - local curCallback - local curLockGame - local noRsp - local beforeOver - if not self.isSending and self.sendQueue[1] then -- 没有正在发送的消息,并且有发送队列, 则继续发送 - local cache = self.sendQueue[1] - binder = cache.binder - originMsgName = cache.originMsgName - curMsgName = cache.msgName - curParams = GFunc.getTable(cache.params) - responseData = cache.responseData - getType = cache.getType - curSocketName = cache.socketName - curCallback = cache.callback - curLockGame = cache.lockGame - noRsp = cache.noRsp - beforeOver = cache.beforeOver - end - - if curMsgName then - if EDITOR_MODE then - local subName = curMsgName - local reqData - if curMsgName == ProtoMsgType.FromMsgEnum.PipedReq then - reqData = curParams.data - else - reqData = curParams - end - Logger.logHighlight("===onSend===:%s", subName) - print("reqData:" .. json.encode(reqData)) - end - - local msgFullName = ProtoMsgDispatch:getMsgFullNameByMsgName(curMsgName) - if curMsgName == ProtoMsgType.FromMsgEnum.PipedReq then - local msgName = ProtoMsgDispatch:getReqMsgNameByMsgId(curParams.msg_id) - local fullMsgName = ProtoMsgDispatch:getMsgFullNameByMsgName(msgName) - if curParams.data and type(curParams.data) == "table" then - curParams.data = pb.encode(fullMsgName, curParams.data) - end - end - - local bytes = pb.encode(msgFullName, curParams) - if bytes then - if curLockGame then - UIManager:showWaitNet() - end - local msgId = ProtoMsgDispatch:getMsgIdByMsgName(curMsgName) - - self:_sendBytes(curSocketName, bytes, msgId, 0) - - if noRsp then - return - end - local msg = ProtoMsgDispatch:getRspMsgByMsgName(originMsgName) - if not self.receiveCallbacks[msg] then - self.receiveCallbacks[msg] = {} - end - local receiveCallback = self:getReceiveCallback() - receiveCallback.binder = binder - receiveCallback.lockGame = curLockGame - receiveCallback.callback = curCallback - receiveCallback.responseData = responseData - receiveCallback.getType = getType - receiveCallback.beforeOver = beforeOver - table.insert(self.receiveCallbacks[msg], receiveCallback) - else - Logger.logError("NetManager send data error %s", curMsgName) - end - end -end - --- 静默重连 -function NetManager:silentReconnectMain() - self.reconnectMainFlag = true - self:setReconnectData() - CS.BF.BFMain.Instance.NetMgr:Reconnect(NetManager.MAIN_SOCKET_NAME) -end - --- 主动重连 -function NetManager:reconnectMain() - UIManager:showWaitNet(true) -- 强制重新计时 - if self.activeReconnectMainFlag then -- 说明之前已经在主动重连中,为了保证引用计数正确,这里减一 - UIManager:hideWaitNet() - else - self.activeReconnectMainFlag = true - end - self.reconnectMainFlag = true - self:setReconnectData() - CS.BF.BFMain.Instance.NetMgr:Reconnect(NetManager.MAIN_SOCKET_NAME) -end - -function NetManager:getReceiveCallback() - if #self.receiveCallbackPool > 0 then - return table.remove(self.receiveCallbackPool) - end - return {} -end - -function NetManager:recycleReceiveCallback(receiveCallback) - receiveCallback.callback = nil - receiveCallback.notLockGame = false - table.insert(self.receiveCallbackPool, receiveCallback) -end - -function NetManager:disconnectAll() - if self.alreadyConnected[NetManager.MAIN_SOCKET_NAME] then - self:showReconnectMain() - else - self:closeAll() - end -end - -function NetManager:showReconnectMain() - if self.reconnectMainId then - SchedulerManager:unscheduleGlobal(self.reconnectMainId) - self.reconnectMainId = nil - end - if UIManager:isDisconnectMsgBoxVisible() then - return - end - local params = { - content = I18N:getGlobalText(I18N.GlobalConst.RECONNECT), - okText = I18N:getGlobalText(I18N.GlobalConst.BTN_TEXT_OK), - cancelText = I18N:getGlobalText(I18N.GlobalConst.RELOGIN), - noShowClose = true, - okFunc = function() - self:reconnectMain() - end, - cancelFunc = function() - ModuleManager.LoginManager:goToLoginScene() - end, - boxType = GConst.MESSAGE_BOX_TYPE.MB_OK_CANCEL, - tag = GConst.GAME_OBJECT_TYPE.MESSAGEBOX_RECONNECT, - top = true, - } - GFunc.showMessageBox(params) -end - -function NetManager:disconnect(socketName) - if self.isClosedMap[socketName] then - return - end - if socketName == NetManager.CHAT_SOCKET_NAME then - self.isClosedMap[socketName] = true - CS.BF.BFMain.Instance.NetMgr:Close(socketName) - - if self.reconnectChatId then - return - end - - if DataManager.ChatData then - DataManager.ChatData:onDisconnect() - end - - self.reconnectChatId = self:performWithDelayGlobal(function () - self.reconnectChatId = nil - if not self:isConnected(NetManager.CHAT_SOCKET_NAME) then - ModuleManager.LoginManager:connectByChannel(nil, NetManager.CHAT_SOCKET_NAME) - end - end, self.chatReconnectWaitTime) - - self.chatReconnectWaitTime = self.chatReconnectWaitTime*2 - if self.chatReconnectWaitTime > MAX_CHAT_WAIT_TIME then - self.chatReconnectWaitTime = MAX_CHAT_WAIT_TIME - end - else - if self.alreadyConnected[socketName] then -- 如果是成功连接过 - if UIManager:getWaitNetCount() > 0 then -- 当前在等待服务器回消息 - if not self.activeReconnectMainFlag then - self:showReconnectMain() - end - else -- 否则就悄咪咪的重连 - if self.mainReconnectWaitTime > MAX_MAIN_WAIT_TIME then - self:showReconnectMain() - else - if self.reconnectMainId then - return - end - self.reconnectMainId = self:performWithDelayGlobal(function () - self.reconnectMainId = nil - self:silentReconnectMain() - end, self.mainReconnectWaitTime) - self.mainReconnectWaitTime = self.mainReconnectWaitTime + 1 - end - end - else -- 从来没有连上过 - self:closeAll() - end - end -end - -function NetManager:onDisconnect(socketName) - self:disconnect(socketName) -end - -function NetManager:performWithDelayGlobal(func, delay) - local sid = SchedulerManager:performWithDelayGlobal(func, delay) - return sid -end - -function NetManager:scheduleGlobal(func, delay) - local sid = SchedulerManager:scheduleGlobal(func, delay) - return sid -end - -function NetManager:closeAll(errorType) - if self.isClosedMap[NetManager.MAIN_SOCKET_NAME] then - return - end - self:closeAndClear() - UIManager:showDisconnect(errorType) -end - -function NetManager:onReceive(msgId, data) - self.isSending = false - --Logger.logHighlight("MSGID:"..msgId) - local msgName = ProtoMsgDispatch:getReqMsgNameByMsgId(msgId) - if msgName == nil then - return - end - if EDITOR_MODE then - Logger.logHighlight("===onReceive===%s:%d", msgName, msgId) - end - - -- 这里保证即使协议有问题解不出来也不要卡住 - - local ok, pbData = pcall(function() - local fullMsgName = ProtoMsgDispatch:getMsgFullNameByMsgName(msgName) - return pb.decode(fullMsgName, data) - end) - - local msg = ProtoMsgDispatch:getRspMsgByMsgName(msgName) - if ok and pbData then - if not pbData.err_code then - pbData.status = 0 - else - pbData.status = ProtoMsgDispatch:getErrCodeEnum(pbData.err_code) - end - if EDITOR_MODE then - print("rspData:" .. json.encode(pbData)) - end - - if NOT_PUBLISH then - Logger.printTable(pbData) - end - - self:dispatch(msgName, pbData) - else - if not ok then - local errorMsg = "NetManager:onReceive failed:" .. msgName - Logger.logError(errorMsg) - end - end - - local sendInfo - local sendMsgName - if self.sendQueue[1]then - sendMsgName = self.sendQueue[1].msgName - if sendMsgName == ProtoMsgType.FromMsgEnum.PipedReq then - sendMsgName = ProtoMsgDispatch:getReqMsgNameByMsgId(self.sendQueue[1].params.msg_id) - end - if ProtoMsgDispatch:getRspMsgByMsgName(sendMsgName) == msgName then - sendInfo = table.remove(self.sendQueue, 1) - self:saveSendQueue() - end - end - - local callbacks = self.receiveCallbacks[msg] - if callbacks and #callbacks > 0 then - local receiveCallback = table.remove(callbacks, 1) - local lockGame = false - local receiveFunc = nil - local responseData = nil - if receiveCallback then - lockGame = receiveCallback.lockGame - receiveFunc = receiveCallback.callback - responseData = receiveCallback.responseData - if NOT_PUBLISH then - Logger.printTable(responseData) - end - if pbData.rewards then - local getType = receiveCallback.getType - if sendMsgName == "MallPayReq" then - getType = PayManager:getItemGetType(pbData.mall_type, pbData.id) - elseif sendMsgName == "MallPaidResultReq" then -- 支付上报统一处理 - if pbData.gift then - for _, gift in ipairs(pbData.gift) do - getType = PayManager:getItemGetType(gift.mall_type, gift.id) - break - end - end - end - - if EDITOR_MODE and not getType then - Logger.logFatal("sendMessage server have rewards but not getType, check it! manager = ", receiveCallback.binder.__cname) - end - - GFunc.addRewards(pbData.rewards, getType) - end - if pbData.costs and not self:getNotAddCostsRsp(msgName) then - local getType = receiveCallback.getType - if sendMsgName == "MallPayReq" then - getType = PayManager:getItemGetType(pbData.mall_type, pbData.id) - elseif sendMsgName == "MallPaidResultReq" then -- 支付上报统一处理 - if pbData.gift then - for _, gift in ipairs(pbData.gift) do - getType = PayManager:getItemGetType(gift.mall_type, gift.id) - break - end - end - end - if EDITOR_MODE and not getType then - Logger.logFatal("sendMessage server have costs but not getType, check it! manager = ", receiveCallback.binder.__cname) - end - GFunc.addCosts(pbData.costs, getType) - end - if EDITOR_MODE and not self:getNotCheckResponse(ProtoMsgDispatch:getReqMsgByMsgName(msgName)) then -- 检查responseData - local fullMsgName = ProtoMsgDispatch:getMsgFullNameByMsgName(msgName) - local serverResult = pb.decode(fullMsgName, data) - self:checkCoin(responseData, serverResult) - if not GFunc.checkTableValueSame(responseData, serverResult, true) then - Logger.logWarningBox(msgName .. " : responseData not equate, please check it!") - Logger.logHighlight("------responseData not equate-------------") - Logger.printTable(responseData) - Logger.printTable(serverResult) - end - end - if receiveCallback.beforeOver then - UIManager:hideWaitNet() - self.tillBeforeOverCount = self.tillBeforeOverCount - 1 - if self.tillBeforeOverCount < 0 then - self.tillBeforeOverCount = 0 - end - end - self:recycleReceiveCallback(receiveCallback) - if lockGame then - UIManager:hideWaitNet() - end - if ok and pbData and receiveFunc then - if sendInfo then - if sendInfo.msgName == ProtoMsgType.FromMsgEnum.PipedReq then - pbData.reqData = sendInfo.params.data - else - pbData.reqData = sendInfo.params - end - end - receiveFunc(receiveCallback.binder, pbData) - end - end - end - - if sendInfo then - self:trySend() - end -end - -function NetManager:onError(socketName, errorType, errorMsg) - self.isSending = false - if socketName == NetManager.MAIN_SOCKET_NAME then - Logger.logHighlight("game net error:errorType = %d, errorMsg = %s", errorType, errorMsg) - if errorType == NetErrorCode.ConnectFailed or - errorType == NetErrorCode.ExceptionError or - errorType == NetErrorCode.ReceiveBufferError or - errorType == NetErrorCode.BeginSendError or - errorType == NetErrorCode.PeerDisconnect or - errorType == NetErrorCode.DataParseError then - self:disconnect(socketName) - elseif errorType == NetErrorCode.ServerRefuseReconnect or - errorType == NetErrorCode.ServerKickNtfClient or - errorType == NetErrorCode.OtherDeviceLogin then -- 服务器拒绝客户端的重连请求,需要关闭连接,重新登录 - self:closeAll(errorType) - elseif errorType == NetErrorCode.DNSParseDomainNameError then - self:closeAll() - else -- 未定义的error - self:disconnect(socketName) - end - elseif socketName == NetManager.CHAT_SOCKET_NAME then - Logger.logHighlight("chat net error:errorType = %d, errorMsg = %s", errorType, errorMsg) - self:disconnect(socketName) - end -end - -function NetManager:setReconnectData() - local msgFullName = ProtoMsgDispatch:getMsgFullNameByMsgName(ProtoMsgType.FromMsgEnum.ReconnectReq) - CS.BF.BFMain.Instance.NetMgr.loginReqData = pb.encode(msgFullName, { recv_id = self.recvId }) -end - -function NetManager:dispatch(msgName, data) - if self.msgCallbacks[msgName] then - for module, callback in pairs(self.msgCallbacks[msgName]) do - callback(module, data) - end - end -end - -function NetManager:getKickOutReasonEnum(enum) - return ProtoMsgDispatch:getKickOutReasonEnum(enum) -end - -function NetManager:joinChatChannel() - -- if self.joinChatId then - -- SchedulerManager:unscheduleGlobal(self.joinChatId) - -- self.joinChatId = nil - -- end - -- if DataManager.ChatData:getIsJoinWorldRoom() then - -- return - -- end - -- local wordChannelId = DataManager.ChatData:getChatWorld():getLocalChatWorldChannleId() - -- local args = { - -- id = wordChannelId, - -- adjust = true -- 登录时第一次进入房间必须能接受调整,手动切房间的时候为false - -- } - -- self:send(ProtoMsgType.FromMsgEnum.JoinWorldRoomReq, args, function(data) - -- if data.status == 0 then - -- DataManager.ChatData:initChat(data) - -- else - -- self.joinChatId = self:performWithDelayGlobal(function () - -- self.joinChatId = nil - -- self:joinChatChannel() - -- end, JOIN_CHAT_INTERVAL) - -- end - -- end, NetManager.CHAT_SOCKET_NAME, true) -end - -function NetManager:registerMsgCallback(msgName, module, callback) - if not self.msgCallbacks[msgName] then - self.msgCallbacks[msgName] = {} - end - self.msgCallbacks[msgName][module] = callback -end - -if NOT_PUBLISH then - NetManager._registerMsgCallback = NetManager.registerMsgCallback - function NetManager:registerMsgCallback(msgName, module, callback) - if debug.getinfo(2, "f").func ~= ServerPushManager.addServerPushListener then - Logger.logFatal("this method only called by ServerPushManager.addServerPushListener") - end - self:_registerMsgCallback(msgName, module, callback) - end -end - -function NetManager:unRegisterMsgCallback(msgName, module) - if self.msgCallbacks[msgName] then - self.msgCallbacks[msgName][module] = nil - end -end - -function NetManager:clearMsgCallbacks() - self.msgCallbacks = {} - self.receiveCallbacks = {} -end - -function NetManager:closeAndClear() - if not self.initSucc then - return - end - if self.tillBeforeOverSid then - SchedulerManager:unscheduleGlobal(self.tillBeforeOverSid) - self.tillBeforeOverSid = nil - end - if self.reconnectMainId then - SchedulerManager:unscheduleGlobal(self.reconnectMainId) - self.reconnectMainId = nil - end - if self.reconnectChatId then - SchedulerManager:unscheduleGlobal(self.reconnectChatId) - self.reconnectChatId = nil - end - if self.joinChatId then - SchedulerManager:unscheduleGlobal(self.joinChatId) - self.joinChatId = nil - end - - self.sendQueue = {} - self.tillBeforeOverCount = 0 - self.msgId = 0 - self.activeReconnectMainFlag = false - self.reconnectMainFlag = false - CS.BF.BFMain.Instance.NetMgr:RemoveAllLuaCallback() - local mainSocketName = NetManager.MAIN_SOCKET_NAME - local chatSocketName = NetManager.CHAT_SOCKET_NAME - - self.isClosedMap[mainSocketName] = true - self.isClosedMap[chatSocketName] = true - self.alreadyConnected[mainSocketName] = false - self.alreadyConnected[chatSocketName] = false - - CS.BF.BFMain.Instance.NetMgr:Close(mainSocketName) - -- CS.BF.BFMain.Instance.NetMgr:Close(chatSocketName) - - self:clearMsgCallbacks() - UIManager:hideWaitNet(true) -end - -function NetManager:saveSendQueue() - local list = {} - for _, info in ipairs(self.sendQueue) do - if not self:isNotSave(info.msgName) then - table.insert(list, { - msgName = info.msgName, - params = info.params, - socketName = info.socketName, - }) - end - end - LocalData:saveSendQueue(list) -end - -function NetManager:isNotSave(msgName) - if msgName == ProtoMsgType.FromMsgEnum.LoginReq or - msgName == ProtoMsgType.FromMsgEnum.SyncReq or - msgName == ProtoMsgType.FromMsgEnum.GMReq then - return true - end - return false -end - -function NetManager:getNotCheckResponse(msgName) - if not EDITOR_MODE then - return false - end - - if msgName == ProtoMsgType.FromMsgEnum.LoginReq or - msgName == ProtoMsgType.FromMsgEnum.SyncReq or - msgName == ProtoMsgType.FromMsgEnum.ArenaInfoReq or - msgName == ProtoMsgType.FromMsgEnum.SummonReq or - msgName == ProtoMsgType.FromMsgEnum.MineResearchADReq or - msgName == ProtoMsgType.FromMsgEnum.MineResearchResultReq or - msgName == ProtoMsgType.FromMsgEnum.IdleRewardReq or - msgName == ProtoMsgType.FromMsgEnum.IdleExtraRewardReq or - msgName == ProtoMsgType.FromMsgEnum.GMReq or - msgName == ProtoMsgType.FromMsgEnum.MallPayReq or - msgName == ProtoMsgType.FromMsgEnum.ChapterPassReq or - msgName == ProtoMsgType.FromMsgEnum.MallPaidResultReq or - msgName == ProtoMsgType.FromMsgEnum.MineDoReq or - msgName == ProtoMsgType.FromMsgEnum.TaskTutorRewardReq or - msgName == ProtoMsgType.FromMsgEnum.BlessingReq or - msgName == ProtoMsgType.FromMsgEnum.MarkGuideReq or - msgName == ProtoMsgType.FromMsgEnum.EnterDungeonReq or - msgName == ProtoMsgType.FromMsgEnum.FinishedArenaReq or - msgName == ProtoMsgType.FromMsgEnum.SettleArenaReq or - msgName == ProtoMsgType.FromMsgEnum.SevenDayRewardReq or - msgName == ProtoMsgType.FromMsgEnum.MonCardRewardReq or - msgName == ProtoMsgType.FromMsgEnum.ChapterStageRewardReq or - msgName == ProtoMsgType.FromMsgEnum.BattlePassRewardReq or - msgName == ProtoMsgType.FromMsgEnum.ChapterRebornReq or - msgName == ProtoMsgType.FromMsgEnum.MineReceiveAwardReq or - msgName == ProtoMsgType.FromMsgEnum.MailExtractReq or - msgName == ProtoMsgType.FromMsgEnum.MailListReq or - msgName == ProtoMsgType.FromMsgEnum.MailDeleteReq or - msgName == ProtoMsgType.FromMsgEnum.ExistReq or - msgName == ProtoMsgType.FromMsgEnum.BindReq or - msgName == ProtoMsgType.FromMsgEnum.DeleteReq - then - return true - end - return false -end - -function NetManager:getNotAddCostsRsp(msgName) - if msgName == ProtoMsgType.FromMsgEnum.ChapterTrainRsp then - return true - end - return false -end - -function NetManager:pipedMessage(msgName, params) - if msgName == ProtoMsgType.FromMsgEnum.LoginReq or - msgName == ProtoMsgType.FromMsgEnum.SyncReq or - msgName == ProtoMsgType.FromMsgEnum.IdleRewardReq or - msgName == ProtoMsgType.FromMsgEnum.IdleExtraRewardReq or - msgName == ProtoMsgType.FromMsgEnum.GMReq then - return msgName, params - end - local msgId = ProtoMsgDispatch:getMsgIdByMsgName(msgName) - self.msgId = self.msgId + 1 - local pipedStruct = { - id = self.msgId, - ts = Time:getServerTime() * 1000, - msg_id = msgId, - data = params, - } - return ProtoMsgType.FromMsgEnum.PipedReq, pipedStruct -end - -if EDITOR_MODE then - function NetManager:_checkDebugFuncMap() - if self._debugFuncMap == nil then - self._debugFuncMap = { - [BaseModule.sendMessage] = true, - [BaseModule.sendMessageTillBeforeOver] = true, - } - end - end - - NetManager._releaseSend = NetManager.send - function NetManager:send(obj, msgName, params, responseData, callback, lockGame, noRsp, getType) - -- 参数检查 - if (responseData.rewards or responseData.costs) and not getType and msgName ~= ProtoMsgType.FromMsgEnum.GMReq then - Logger.logFatal("sendMessage have rewards or have costs but not getType, check it! manager = ", self.__cname) - return - end - - if not params then - Logger.logFatal("NetManager send params is nil %s", msgName) - end - - if not responseData then - Logger.logFatal("NetManager send responseData is nil %s", msgName) - end - - local msgFullName = ProtoMsgDispatch:getMsgFullNameByMsgName(msgName) - local bytes = pb.encode(msgFullName, params) - if not bytes then - Logger.logFatal("NetManager send params error %s", msgName) - return - end - - if not self:getNotCheckResponse(msgName) then - local fullMsgName = ProtoMsgDispatch:getMsgFullNameByMsgName(ProtoMsgDispatch:getRspMsgByMsgName(msgName)) - for name, number, type in pb.fields(fullMsgName) do - if name ~= "err_code" and responseData[name] == nil then - Logger.logFatal("NetManager send responseData error %s not have %s", msgName, name) - return - end - end - end - -- end 参数检查 - - self:_checkDebugFuncMap() - local currFunc = debug.getinfo(2, "f").func - if obj ~= NetManager and self._debugFuncMap[currFunc] == nil then - Logger.logFatal("you can not call NetManager:send directly") - end - local findCallback = false - if obj ~= NetManager and obj.__cname ~= "PayManager" then - for _, fieldValue in pairs(obj.class) do - if fieldValue == callback then - findCallback = true - end - end - else - findCallback = true - end - - if not findCallback then - Logger.logFatal("callback of NetManager:send is not %s's function", obj.__cname) - end - self:_releaseSend(obj, msgName, params, responseData, callback, lockGame, noRsp, getType) - end - - NetManager._releaseSendTillBeforeOver = NetManager.sendTillBeforeOver - function NetManager:sendTillBeforeOver(obj, msgName, params, responseData, callback, ...) - self:_checkDebugFuncMap() - local currFunc = debug.getinfo(2, "f").func - if obj ~= NetManager and self._debugFuncMap[currFunc] == nil then - Logger.logFatal("you can not call NetManager:send directly") - end - self:_releaseSendTillBeforeOver(obj, msgName, params, responseData, callback, ...) - end -end - -function NetManager:checkCoin(responseData, serverResponseData) - --- 特殊处理金币 - if responseData.rewards and serverResponseData.rewards then - local coinCount = 0 - for i, info in ipairs(serverResponseData.rewards) do - if info.item and info.item.id == GConst.ItemConst.ITEM_ID_GOLD then - local serverGoldBigNum = BigNumOpt.cloneBigNum(info.item.count) - local rspGoldBigNum = BigNumOpt.cloneBigNum(responseData.rewards[i].item.count) - if serverGoldBigNum.unit > rspGoldBigNum.unit then - serverGoldBigNum.value, serverGoldBigNum.unit = BigNumOpt.numToTargetUnit(serverGoldBigNum.value, serverGoldBigNum.unit, rspGoldBigNum.unit) - elseif serverGoldBigNum.unit < rspGoldBigNum.unit then - rspGoldBigNum.value, rspGoldBigNum.unit = BigNumOpt.numToTargetUnit(rspGoldBigNum.value, rspGoldBigNum.unit, serverGoldBigNum.unit) - end - if serverGoldBigNum.unit == rspGoldBigNum.unit and serverGoldBigNum.value ~= rspGoldBigNum.value then - --- 百分之一的差距忽略不计 - local minCount = math.floor(serverGoldBigNum.value * 0.99 + 0.000001) - local maxCount = math.floor(serverGoldBigNum.value * 1.01 + 0.000001) - if minCount <= rspGoldBigNum.value and rspGoldBigNum.value <= maxCount then - responseData.rewards[i].item.count = info.item.count - if EDITOR_MODE then - Logger.logHighlight("------金币有误差,且在-1%%~1%%-------------") - else - if EDITOR_MODE then - Logger.logFatal("------金币有误差,不在-1%%~1%%-------------") - end - end - end - else - responseData.rewards[i].item.count = info.item.count - end - end - end - end - - if responseData.costs and serverResponseData.costs then - local coinCount = 0 - for i, info in ipairs(serverResponseData.costs) do - if info.item and info.item.id == GConst.ItemConst.ITEM_ID_GOLD then - local serverGoldBigNum = BigNumOpt.cloneBigNum(info.item.count) - local rspGoldBigNum = BigNumOpt.cloneBigNum(responseData.costs[i].item.count) - if serverGoldBigNum.unit > rspGoldBigNum.unit then - serverGoldBigNum.value, serverGoldBigNum.unit = BigNumOpt.numToTargetUnit(serverGoldBigNum.value, serverGoldBigNum.unit, rspGoldBigNum.unit) - elseif serverGoldBigNum.unit < rspGoldBigNum.unit then - rspGoldBigNum.value, rspGoldBigNum.unit = BigNumOpt.numToTargetUnit(rspGoldBigNum.value, rspGoldBigNum.unit, serverGoldBigNum.unit) - end - if serverGoldBigNum.unit == rspGoldBigNum.unit and serverGoldBigNum.value ~= rspGoldBigNum.value then - --- 百分之一的差距忽略不计 - local minCount = math.floor(serverGoldBigNum.value * 0.99 + 0.000001) - local maxCount = math.floor(serverGoldBigNum.value * 1.01 + 0.000001) - if minCount <= rspGoldBigNum.value and rspGoldBigNum.value <= maxCount then - responseData.costs[i].item.count = info.item.count - if EDITOR_MODE then - Logger.logHighlight("------金币有误差,且在-1%%~1%%-------------") - end - else - if EDITOR_MODE then - Logger.logFatal("------金币有误差,不在-1%%~1%%-------------") - end - end - else - responseData.costs[i].item.count = info.item.count - end - end - end - end - --- -end - -return NetManager \ No newline at end of file diff --git a/lua/app/server/data/server_formation_data.lua b/lua/app/server/data/server_formation_data.lua new file mode 100644 index 00000000..57460544 --- /dev/null +++ b/lua/app/server/data/server_formation_data.lua @@ -0,0 +1,29 @@ +local ServerFormationData = class("ServerFormationData", ServerBaseData) + +function ServerFormationData:init(data) + if data then + self.data.formations = data.formations or {} + else + self.data.formations = {} + end +end + +function ServerFormationData:getFormation(formationType) + local formation = self.data.formations[formationType] + if formation == nil then + formation = {} + self.data.formations[formationType] = formation + end + return formation +end + +function ServerFormationData:upHeroToFormation(formationType, matchType, heroId) + local formation = self:getFormation(formationType) + if formation[matchType] == heroId then + return false + end + formation[matchType] = heroId + return true +end + +return ServerFormationData \ No newline at end of file diff --git a/lua/app/server/data/server_formation_data.lua.meta b/lua/app/server/data/server_formation_data.lua.meta new file mode 100644 index 00000000..04004254 --- /dev/null +++ b/lua/app/server/data/server_formation_data.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 89bb0382eca3c184e814ee1bc10355c8 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/server/data/server_player_data.lua b/lua/app/server/data/server_player_data.lua index 42f076ba..15637f96 100644 --- a/lua/app/server/data/server_player_data.lua +++ b/lua/app/server/data/server_player_data.lua @@ -1,3 +1,11 @@ local ServerPlayerData = class("ServerPlayerData", ServerBaseData) +function ServerPlayerData:setVit(vit) + self.vit = tonumber(vit) or 0 +end + +function ServerPlayerData:getVit() + return self.vit or 0 +end + return ServerPlayerData \ No newline at end of file diff --git a/lua/app/server/manager.meta b/lua/app/server/manager.meta new file mode 100644 index 00000000..014a827a --- /dev/null +++ b/lua/app/server/manager.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 09d17db485e3192459d5fcd0a0cefb49 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/lua/app/server/manager/server_formation_manager.lua b/lua/app/server/manager/server_formation_manager.lua new file mode 100644 index 00000000..e22d8082 --- /dev/null +++ b/lua/app/server/manager/server_formation_manager.lua @@ -0,0 +1,27 @@ +local ServerFormationManager = {} + +function ServerFormationManager:updateFormation(params, callback) + local result = { + status = 1 + } + if params == nil then + if callback then + callback(result) + end + return + end + local formationType = params.formationType + local matchType = tostring(params.matchType) + local heroId = params.heroId + if formationType and matchType and heroId then + local ServerGameData = require "app/server/server_game_data" + if ServerGameData.FormationData:upHeroToFormation(formationType, matchType, heroId) then + result.status = 0 + end + end + if callback then + callback(result) + end +end + +return ServerFormationManager \ No newline at end of file diff --git a/lua/app/server/manager/server_formation_manager.lua.meta b/lua/app/server/manager/server_formation_manager.lua.meta new file mode 100644 index 00000000..54f093a9 --- /dev/null +++ b/lua/app/server/manager/server_formation_manager.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 3f6f74ff6268bec4593ef0e060480d93 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/server/server_data_const.lua b/lua/app/server/server_data_const.lua index 408973a3..f34bd71e 100644 --- a/lua/app/server/server_data_const.lua +++ b/lua/app/server/server_data_const.lua @@ -8,6 +8,7 @@ ServerDataConst.REWARD_TYPE = { ServerDataConst.DATA_OP_BEHAVIOR = { SYNC_DATA = "SYNC_DATA", CROSS_DAY = "CROSS_DAY", + UPDATE_FORMATION = "UPDATE_FORMATION" } return ServerDataConst \ No newline at end of file diff --git a/lua/app/server/server_data_manager.lua b/lua/app/server/server_data_manager.lua index c0494d6c..f69171fb 100644 --- a/lua/app/server/server_data_manager.lua +++ b/lua/app/server/server_data_manager.lua @@ -3,9 +3,7 @@ local ServerGameData = require "app/server/server_game_data" local ServerDataManager = {} function ServerDataManager:init() -end - -function ServerDataManager:saveData() + self.ServerFormationManager = require("app/server/manager/server_formation_manager") end function ServerDataManager:randomReward(weightArr, callback) @@ -40,7 +38,7 @@ function ServerDataManager:dataOperate(behavior, params, callback) end end) -- TODO临时处理 - LocalData:save() + ServerGameData:saveData() else Logger.logError("Undefined data operation function, please check :%s", behavior) end @@ -57,6 +55,70 @@ end ServerDataManager.OP_FUNC = { [GConst.ServerDataConst.DATA_OP_BEHAVIOR.SYNC_DATA] = function (...) ServerDataManager:onSyncData(...) end, + [GConst.ServerDataConst.DATA_OP_BEHAVIOR.UPDATE_FORMATION] = function (...) ServerDataManager.ServerFormationManager:updateFormation(...) end, } +function ServerDataManager:dealGM(params, callback) + if IS_PUBLISH then + return + end + if not params or not params.args then + return + end + local args = params.args + if args[1] == "add_item" then + local id = tonumber(args[2]) + local count = tonumber(args[3]) + if not id or not count then + return + end + ServerGameData.BagData.ItemData:addItem(id, count) + if id == GConst.ItemConst.ITEM_ID_EXP then + ServerGameData.PlayerData:addExp(count) + end + elseif args[1] == "add_items" then + local cfg = ConfigManager:getConfig("item") + local count = tonumber(args[2]) + if not count then + for k, v in pairs(cfg) do + if k == GConst.ItemConst.ITEM_ID_GOLD then + ServerGameData.BagData.ItemData:addItem(k, 99999999) + else + ServerGameData.BagData.ItemData:addItem(k, 2000) + end + if k == GConst.ItemConst.ITEM_ID_EXP then + ServerGameData.PlayerData:addExp(1000) + end + end + else + for k, v in pairs(cfg) do + ServerGameData.BagData:addItem(k, count) + if k == GConst.ItemConst.ITEM_ID_EXP then + ServerGameData.PlayerData:addExp(count) + end + end + end + elseif args[1] == "del_item" then + local id = tonumber(args[2]) + local count = tonumber(args[3]) + if not id or not count then + return + end + ServerGameData.BagData.ItemData:addItem(id, -count) + if id == GConst.ItemConst.ITEM_ID_EXP then + ServerGameData.PlayerData:addExp(-count) + end + elseif args[1] == "clear_item" then + local items = ServerGameData.BagData.ItemData:getAllItems() + for k, v in pairs(items) do + v.count = 0 + end + end + + ServerGameData:saveData() + if callback then + callback() + end +end + return ServerDataManager \ No newline at end of file diff --git a/lua/app/server/server_game_data.lua b/lua/app/server/server_game_data.lua index 904afdfd..28ed8337 100644 --- a/lua/app/server/server_game_data.lua +++ b/lua/app/server/server_game_data.lua @@ -16,6 +16,7 @@ function ServerGameData:init() self:initServerData("BagData", "app/server/data/server_bag_data") self:initServerData("HeroData", "app/server/data/server_hero_data") self:initServerData("ChapterData", "app/server/data/server_chapter_data") + self:initServerData("FormationData", "app/server/data/server_formation_data") end function ServerGameData:initData() @@ -23,7 +24,7 @@ function ServerGameData:initData() if self.distinctId == nil or self.distinctId == "" then self.distinctId = LocalData:getDistinctId() end - local isNewPlayer = LocalData:getIsNewPlayer() + local isNewPlayer = self:getIsNewPlayer() if isNewPlayer then for k, v in pairs(self.dataMap) do v:init() @@ -69,9 +70,8 @@ function ServerGameData:initData() end end end + self:setNotNewPlayer() self:saveData() - LocalData:setNotNewPlayer() - LocalData:save() else for k, v in pairs(self.dataMap) do v:init(v:loadLocalData()) @@ -99,6 +99,7 @@ function ServerGameData:saveData() for k, v in pairs(self.dataMap) do v:saveLocalData() end + LocalData:save() end -- 根据配置表添加奖励 @@ -197,4 +198,24 @@ function ServerGameData:setDistinctId(distinctId) self.distinctId = distinctId end +function ServerGameData:getIsNewPlayer() + return LocalData:getIsNewPlayer() +end + +function ServerGameData:setNotNewPlayer() + LocalData:setNotNewPlayer() +end + +if NOT_PUBLISH then + ServerGameData.editorGetIsNewPlayer = ServerGameData.getIsNewPlayer + function ServerGameData:getIsNewPlayer() + return LocalData:getInt(LocalData:getDistinctId() .. LocalData.KEYS.IS_NEW_PLAYER, 0) == 0 + end + + ServerGameData.editorSetNotNewPlayer = ServerGameData.setNotNewPlayer + function ServerGameData:setNotNewPlayer() + LocalData:setInt(LocalData:getDistinctId() .. LocalData.KEYS.IS_NEW_PLAYER, 1) + end +end + return ServerGameData \ No newline at end of file diff --git a/lua/app/ui/base_ui.lua b/lua/app/ui/base_ui.lua index cf5d3ed2..e95d5f4c 100644 --- a/lua/app/ui/base_ui.lua +++ b/lua/app/ui/base_ui.lua @@ -229,7 +229,7 @@ function BaseUI:isFullScreen() return true end -function BaseUI:currencyParams() +function BaseUI:getCurrencyParams() return nil, false end diff --git a/lua/app/ui/battle/battle_ui.lua b/lua/app/ui/battle/battle_ui.lua index b9f82259..a0d3b155 100644 --- a/lua/app/ui/battle/battle_ui.lua +++ b/lua/app/ui/battle/battle_ui.lua @@ -25,6 +25,7 @@ function BattleUI:_display() self.boardMask2D = uiMap["battle_ui.bg_2.board_node"]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_RECT_MASK_2D) self:initGridCell() self:initSkill() + self:initBattlefield() end function BattleUI:_addListeners() @@ -56,6 +57,15 @@ function BattleUI:initSkill() end end +function BattleUI:initBattlefield() + local uiMap = self.root:genAllChildren() + self.battleNode = uiMap["battle_ui.battle_node"] +end + +function BattleUI:getBattleNode() + return self.battleNode +end + function BattleUI:refreshSkill(elementMap) if not self.skillObjs then return diff --git a/lua/app/ui/common/cell/hero_cell.lua b/lua/app/ui/common/cell/hero_cell.lua index ace79c14..9c0f8922 100644 --- a/lua/app/ui/common/cell/hero_cell.lua +++ b/lua/app/ui/common/cell/hero_cell.lua @@ -6,27 +6,55 @@ function HeroCell:init() self.heroBg = uiMap["hero_cell.hero_bg"] self.check = uiMap["hero_cell.hero_bg.mask"] self.matchImg = uiMap["hero_cell.hero_bg.match_img"] + self.isGray = false + self.baseObject:addClickListener(function() + if self.clickCallback then + self.clickCallback() + end + end) end -function HeroCell:refresh(heroEntity) +function HeroCell:refresh(heroEntity, isGray) local heroInfo = heroEntity:getConfig() - self:_refresh(heroInfo) + self:_refresh(heroInfo, isGray) end -function HeroCell:refreshWithCfgId(id) +function HeroCell:refreshWithCfgId(id, isGray) local heroInfo = ConfigManager:getConfig("hero")[id] - self:_refresh(heroInfo) + self:_refresh(heroInfo, isGray) end -function HeroCell:_refresh(heroInfo) - self.heroBg:setSprite(GConst.ATLAS_PATH.ICON_HERO, GConst.HERO_FRAME_QLT[heroInfo.qlt]) +function HeroCell:_refresh(heroInfo, isGray) + self.clickCallback = nil + if isGray then + self.heroBg:setSprite(GConst.ATLAS_PATH.ICON_HERO, GConst.HERO_FRAME_GRAY_QLT[heroInfo.qlt]) + else + self.heroBg:setSprite(GConst.ATLAS_PATH.ICON_HERO, GConst.HERO_FRAME_QLT[heroInfo.qlt]) + end self.icon:setSprite(GConst.ATLAS_PATH.ICON_HERO, tostring(heroInfo.icon)) self.matchImg:setSprite(GConst.ATLAS_PATH.ICON_HERO, GConst.HeroConst.MATCH_ICON_NAME[heroInfo.position]) self.check:setVisible(false) + self:setGray(isGray) +end + +function HeroCell:showCheck(visible) + self.check:setVisible(visible) +end + +function HeroCell:addClickListener(callback) + self.clickCallback = callback end function HeroCell:setVisible(visible) self.baseObject:setVisible(visible) end +function HeroCell:setGray(isGray) + if self.isGray == isGray then + return + end + self.icon:setImageGray(isGray) + self.matchImg:setImageGray(isGray) +end + return HeroCell diff --git a/lua/app/ui/currency_bar/cell/currency_cell.lua b/lua/app/ui/currency_bar/cell/currency_cell.lua index 62877593..34b5955d 100644 --- a/lua/app/ui/currency_bar/cell/currency_cell.lua +++ b/lua/app/ui/currency_bar/cell/currency_cell.lua @@ -16,69 +16,40 @@ function ResourceCell:init() end function ResourceCell:show(itemId, hideAddImg) - -- hideAddImg = hideAddImg or false - -- self:hide() - -- if not itemId then - -- return - -- end - -- self.baseObject:setActive(true) - -- self.num = nil + hideAddImg = hideAddImg or false + self:hide() + if not itemId then + return + end + self.baseObject:setActive(true) - -- local obj = DataManager.BagData.ItemData:getItemById(itemId) - -- self.resImg:setSprite(obj:getIconRes()) + local obj = DataManager.BagData.ItemData:getItemById(itemId) + self.resImg:setSprite(obj:getIconRes()) - -- self:unBindAll() - -- self:bind(obj, "isDirty", function(binder, value) - -- self:refreshTextRightNow() - -- end) + self:unBindAll() + self:bind(obj, "isDirty", function(binder, value) + self:refreshTextRightNow() + end) - -- self.baseObject:removeClickListener() + self.baseObject:removeClickListener() - -- self.timeTx:setVisible(false) - -- self.itemId = itemId - -- if itemId == GConst.ItemConst.ITEM_ID_GEM then - -- self.baseObject:addClickListener(function() - -- if ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.SHOP, true) then - -- EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.CHANGE_MAIN_CITY_PAGE, {page = 5, storeIdx = 4}) - -- end - -- end) - -- self.addImg:setVisible(not hideAddImg) - -- elseif itemId == GConst.ItemConst.ITEM_ID_GOLD then - -- if ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.SHOP, true) then - -- self.baseObject:addClickListener(function() - -- EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.CHANGE_MAIN_CITY_PAGE, {page = 5, storeIdx = 2}) - -- end) - -- end - -- self.addImg:setVisible(not hideAddImg) - -- else - -- self.addImg:setVisible(not hideAddImg) - -- end - -- self:refreshCurrencyAddTx(itemId, nil) -end - -function ResourceCell:refreshCurrencyAddTx(itemId, bigNum) - -- if self.itemId == itemId then - -- if bigNum then - -- local obj = DataManager.BagData.ItemData:getItemById(self.itemId) - -- if obj:getItemType() == 6 then - -- self.addTx:setText("+" .. tostring(BigNumOpt.bigNum2Num(bigNum))) - -- else - -- self.addTx:setText("+" .. BigNumOpt.bigNum2Str(bigNum)) - -- end - -- else - -- self.addTx:setText(nil) - -- end - -- end + self.timeTx:setVisible(false) + self.itemId = itemId + if itemId == GConst.ItemConst.ITEM_ID_GOLD then + self.addImg:setVisible(not hideAddImg) + else + self.addImg:setVisible(not hideAddImg) + end end function ResourceCell:updateTime() if self.itemId then - --local curTime = DataManager.BagData:getTimelyItemRecoveryTime(self.itemId) - --if curTime <= 0 then - -- self.timeTx:setText("") - --else - -- self.timeTx:setText(GFunc.getTimeStrWithMS(curTime)) - --end + local curTime = DataManager.BagData:getTimelyItemRecoveryTime(self.itemId) + if curTime <= 0 then + self.timeTx:setText(GConst.EMPTY_STRING) + else + self.timeTx:setText(GFunc.getTimeStrWithMS(curTime)) + end end end @@ -95,18 +66,18 @@ function ResourceCell:getAnchoredPosition() end function ResourceCell:refreshTextRightNow() - -- if not self.itemId then - -- return - -- end - -- local obj = DataManager.BagData.ItemData:getItemById(self.itemId) - -- local bigNum = obj:getBigNum() - -- if bigNum.value < 0 then - -- self.numTx:setText(0) - -- elseif obj:getItemType() == 6 then - -- self.numTx:setText(BigNumOpt.bigNum2Num(bigNum)) - -- else - -- self.numTx:setText(BigNumOpt.bigNum2Str(bigNum)) - -- end + if not self.itemId then + return + end + local obj = DataManager.BagData.ItemData:getItemById(self.itemId) + local count = obj:getNum() + if count < 0 then + self.numTx:setText("0") + elseif obj:getItemType() == GConst.ItemConst.ITEM_ID_VIT then + self.numTx:setText(GFunc.num2Str(count) .. "/" .. DataManager.PlayerData:getMaxVit()) + else + self.numTx:setText(GFunc.num2Str(count)) + end end function ResourceCell:refreshText() @@ -114,7 +85,7 @@ function ResourceCell:refreshText() return end local text = self.numTx:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO).text - self.numTx:setText("") + self.numTx:setText(GConst.EMPTY_STRING) self.numTx:setText(text) end diff --git a/lua/app/ui/currency_bar/currency_bar.lua b/lua/app/ui/currency_bar/currency_bar.lua index b44781dc..025cece7 100644 --- a/lua/app/ui/currency_bar/currency_bar.lua +++ b/lua/app/ui/currency_bar/currency_bar.lua @@ -4,7 +4,7 @@ local CurrencyBar = class("CurrencyBar", Component) CurrencyBar.cellWidth = 174 CurrencyBar.cellHeight = 40 -local OFFSET_X = 200 -- -27 +local OFFSET_X = -27 local OFFSET_Y = -22 function CurrencyBar:init() @@ -97,14 +97,14 @@ function CurrencyBar:showSort() return end local w, h = GFunc.getUIExpandScreenSize() - -- local offset = (w - 720) / 2 - local offset = 0 + local offset = (w - 720) / 2 if offset <= 0 then offset = 0 end if self.params.showType == GConst.CURRENCY_TYPE.HORIZONTAL then for i,v in ipairs(self.params.itemIds) do - self.currencyList[i]:setAnchoredPosition(OFFSET_X + (i - 1)*self.cellWidth + self.offsetX - offset, OFFSET_Y + self.offsetY) + Logger.logHighlight(OFFSET_X - (i - 1)*self.cellWidth + self.offsetX - offset) + self.currencyList[i]:setAnchoredPosition(OFFSET_X - (i - 1)*self.cellWidth + self.offsetX - offset, OFFSET_Y + self.offsetY) end else for i,v in ipairs(self.params.itemIds) do diff --git a/lua/app/ui/gm/gm_tool_ui.lua b/lua/app/ui/gm/gm_tool_ui.lua index eb28a91c..5a83b59a 100644 --- a/lua/app/ui/gm/gm_tool_ui.lua +++ b/lua/app/ui/gm/gm_tool_ui.lua @@ -1,6 +1,4 @@ -local DevToolManager = require "app/module/gm/dev_tool_manager" local GMConst = require "app/module/gm/gm_const" --- local ItemConst = require "app/module/item/item_const" local GMToolUI = class("GMToolUI",BaseUI) function GMToolUI:ctor() @@ -23,16 +21,10 @@ function GMToolUI:onRefresh() local titleTx = self.uiMap['gm_tool_ui.title'] local okBtn = self.uiMap['gm_tool_ui.ok_btn'] local okBtnText = self.uiMap['gm_tool_ui.ok_btn.text'] - local helpBtn = self.uiMap['gm_tool_ui.help_btn'] local inputField = self.uiMap['gm_tool_ui.InputField'] - local inputFieldText = self.uiMap['gm_tool_ui.InputField.text'] local scrollView = self.uiMap['gm_tool_ui.ScrollView'] local textTip = self.uiMap['gm_tool_ui.text_tip'] local speedUpBtn = self.uiMap["gm_tool_ui.speed_up_btn"] - local attrBtn = self.uiMap["gm_tool_ui.attr_btn"] - local attrBtnTx = self.uiMap["gm_tool_ui.attr_btn.text"] - local heroListNode = self.uiMap["gm_tool_ui.hero_list_node"] - self.heroListNode = heroListNode self.uiMap['gm_tool_ui.close_btn']:addClickListener(function() self:closeUI() end) self.scrollRect = scrollView:getLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE) @@ -50,7 +42,6 @@ function GMToolUI:onRefresh() self.inputField = inputField titleTx:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT).text = "GM面板" okBtnText:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT).text = "确定" - attrBtnTx:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT).text = "英雄属性" okBtn:addClickListener(function() @@ -73,20 +64,6 @@ function GMToolUI:onRefresh() CS.UnityEngine.Time.timeScale = timeScale end) - attrBtn:addClickListener(function() - local allAttr = DataManager.HeroData:getMainHeroEntity():getAllAttr() - local allAttr1 = {} - local cfg = ConfigManager:getConfig("attr") - for i = 1, #cfg do - allAttr1[i] = {unit = allAttr[i].unit, value = allAttr[i].value} - end - Logger.logHighlight("============================ hero attr") - Logger.printTable(allAttr1) - Logger.logHighlight("============================ hero attr") - local str = json.encode(allAttr1) - ModuleManager.TipsManager:showHelpTips({desc = str}) - end) - self.uiMap["gm_tool_ui.fps_btn"]:addClickListener(function() local comp = UIManager.uiRoot:getComponent(typeof(CS.BF.ShowFPS)) if comp == nil then @@ -95,10 +72,6 @@ function GMToolUI:onRefresh() comp.enabled = not comp.enabled end end) - - heroListNode:addClickListener(function() - heroListNode:setActive(false) - end) end function GMToolUI:initScrollRectCell(index, cell) @@ -116,75 +89,15 @@ function GMToolUI:sendMsg(gmCommand) else local args = {} args.args = string.split(gmCommand, " ") - if args.args[1] == "time" then -- 特殊处理 - local args1 = {} - args1.args = {} - args1.args[1] = args.args[1] - args1.args[2] = args.args[2] .. " " .. args.args[3] - ModuleManager.DevToolManager:dealGM(args1) - else - ModuleManager.DevToolManager:dealGM(args) - end + ServerDataManager:dealGM(args, function() + ServerDataManager:dataOperate(GConst.ServerDataConst.DATA_OP_BEHAVIOR.SYNC_DATA, GConst.EMPTY_TABLE, function(msgData) + DataManager:initWithServerData(msgData) + ModuleManager.MaincityManager:firstEnterMainCity() + end) + end) end end -function GMToolUI:initHeroScrollRect(index, cell) - self.heroList = {} - -- local HeroConst = require "app/module/hero/hero_const" - for hid, entity in pairs(DataManager.HeroData:getAllHero()) do - local star = entity:getStar() - local qlt = entity:getQuality() - local group = entity:getGroup() - local lv = entity:getLv() - local heroId = entity:getId() - local sort = 0 - sort = heroId + group*10000000 + qlt*100000000 + star*1000000000 + lv*10000000000 - -- if self.filterType == HeroConst.FILTER_TYPE.ALL then - -- sort = heroId + group*10000000 + qlt*100000000 + star*1000000000 + lv*10000000000 - -- elseif self.filterType == HeroConst.FILTER_TYPE.STAR then - -- sort = heroId + group*10000000 + qlt*100000000 + lv*1000000000 + star*100000000000 - -- elseif self.filterType == HeroConst.FILTER_TYPE.LV then - -- sort = heroId + group*10000000 + qlt*100000000 + star*1000000000 + lv*10000000000 - -- elseif self.filterType == HeroConst.FILTER_TYPE.QLT then - -- sort = heroId + group*10000000 + star*100000000 + lv*1000000000 + qlt*100000000000 - -- elseif self.filterType == HeroConst.FILTER_TYPE.GROUP then - -- sort = heroId + qlt*10000000 + star*100000000 + lv*1000000000 + group*100000000000 - -- elseif self.filterType == HeroConst.FILTER_TYPE.USED then - -- end - table.insert(self.heroList, { - heroData = entity, - sort = sort - }) - end - table.sort(self.heroList, function (a, b) - return a.sort > b.sort - end) - if self.heroScrollRect then - self.heroScrollRect:refillCells(#self.heroList) - return - end - local uiMap = self.root:genAllChildren() - self.heroScrollRect = uiMap["gm_tool_ui.hero_list_node.ScrollView (1)"]:getLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE) - self.heroScrollRect:clearCells() - self.heroScrollRect:setFadeArgs(0, 0.3) - self.heroScrollRect:addInitCallback(function() - return GConst.TYPEOF_LUA_CLASS.HERO_CELL - end) - self.heroScrollRect:addRefreshCallback(function(index, cell) - self:refreshHeroCell(cell, self.heroList[index].heroData) - end) - self.heroScrollRect:refillCells(#self.heroList) -end - -function GMToolUI:refreshHeroCell(cell, heroData) - cell:refresh(heroData) - cell:addClickListener(function() - self.textTip:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT).text = "英雄升级 (会清空当前经验) \n arg1:英雄唯一ID arg2 目标等级" - self.inputField:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_INPUT_FIELD).text = string.format("%s %s ", "hero_upgrade", heroData:getHid()) - self.heroListNode:setActive(false) - end) -end - function GMToolUI:updateTime() local uiMap = self.root:genAllChildren() uiMap["gm_tool_ui.time"]:setText(Time:formatTimeYMDHMS(Time:getServerTime())) diff --git a/lua/app/ui/hero/cell/hero_list_cell.lua b/lua/app/ui/hero/cell/hero_list_cell.lua index fb59b24b..41bff86a 100644 --- a/lua/app/ui/hero/cell/hero_list_cell.lua +++ b/lua/app/ui/hero/cell/hero_list_cell.lua @@ -17,7 +17,7 @@ function HeroListCell:init() self.titleTx = self.uiMap["hero_list_cell.title.title_desc"] end -function HeroListCell:refresh(index, heroList, allHeroCount, activeCount) +function HeroListCell:refresh(index, heroList, stageFormation, allHeroCount, activeCount) if activeCount > 0 and index == 1 then self.title:setVisible(true) self.titleTx:setText("临时文本:已解锁") @@ -38,13 +38,20 @@ function HeroListCell:refresh(index, heroList, allHeroCount, activeCount) for i = 1, 4 do if heroIndex <= activeCount then self.heroCells[i]:setVisible(true) - self.heroCells[i]:refresh(DataManager.HeroData:getHeroById(heroList[heroStartIndex])) + local heroId = heroList[heroIndex] + local heroEntity = DataManager.HeroData:getHeroById(heroId) + local matchType = heroEntity:getMatchType() + self.heroCells[i]:refresh(heroEntity, false) + self.heroCells[i]:showCheck(stageFormation[matchType] == heroId) + self.heroCells[i]:addClickListener(function() + ModuleManager.FormationManager:upHeroToStageFormation(heroId, matchType) + end) elseif heroIndex <= allHeroCount then if heroStartIndex <= activeCount then self.heroCells[i]:setVisible(false) else self.heroCells[i]:setVisible(true) - self.heroCells[i]:refreshWithCfgId(heroList[heroStartIndex]) + self.heroCells[i]:refreshWithCfgId(heroList[heroIndex], true) end else self.heroCells[i]:setVisible(false) diff --git a/lua/app/ui/hero/hero_comp.lua b/lua/app/ui/hero/hero_comp.lua index 66813423..3ba9ba61 100644 --- a/lua/app/ui/hero/hero_comp.lua +++ b/lua/app/ui/hero/hero_comp.lua @@ -9,7 +9,7 @@ function HeroComp:init() return HERO_LIST_CELL end) self.scrollRect:addRefreshCallback(function(index, cell) - cell:refresh(index, self.heroList, self.allHeroCount, self.activeCount) + cell:refresh(index, self.heroList, self.stageFormation, self.allHeroCount, self.activeCount) end) self.heroList = {} local heroCfg = ConfigManager:getConfig("hero") @@ -19,9 +19,15 @@ function HeroComp:init() end function HeroComp:refresh() + self.stageFormation = DataManager.FormationData:getStageFormation() + self:refreshStageFormation() self:refreshScrollRect() end +function HeroComp:refreshStageFormation() + +end + function HeroComp:refreshScrollRect() self:sortHeroList() self.allHeroCount = #self.heroList diff --git a/lua/app/ui/main_city/component/main_comp.lua b/lua/app/ui/main_city/component/main_comp.lua index 229ae60b..e952236e 100644 --- a/lua/app/ui/main_city/component/main_comp.lua +++ b/lua/app/ui/main_city/component/main_comp.lua @@ -4,6 +4,7 @@ local CHAPTER_PATH = "assets/arts/textures/background/chapter/%s.png" function MainComp:init() self.uiMap = self:getBaseObject():genAllChildren() self:initChapter() + self:initStageFormation() self:initGM() end @@ -28,6 +29,16 @@ function MainComp:initChapter() end) end +function MainComp:initStageFormation() + self.heroCells = { + self.uiMap["main_comp.hero_bg.hero_cell_1"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), + self.uiMap["main_comp.hero_bg.hero_cell_2"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), + self.uiMap["main_comp.hero_bg.hero_cell_3"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), + self.uiMap["main_comp.hero_bg.hero_cell_4"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), + self.uiMap["main_comp.hero_bg.hero_cell_5"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), + } +end + function MainComp:initGM() self.btnGM = self.uiMap["main_comp.gm_btn"] self.btnGM:setVisible(not Platform:getIsPublishChannel(), 2) @@ -38,6 +49,7 @@ end function MainComp:refresh() self:refreshChapter() + self:refreshStageFormaion() end function MainComp:onFightBtnClick() @@ -59,4 +71,20 @@ function MainComp:refreshChapter() end end +function MainComp:refreshStageFormaion() + local formation = DataManager.FormationData:getStageFormation() + for i, heroCell in ipairs(self.heroCells) do + if formation[i] then + local heroEntity = DataManager.HeroData:getHeroById(formation[i]) + if heroEntity then + heroCell:refresh(heroEntity) + else + heroCell:setVisible(false) + end + else + heroCell:setVisible(false) + end + end +end + return MainComp \ No newline at end of file diff --git a/lua/app/ui/main_city/main_city_ui.lua b/lua/app/ui/main_city/main_city_ui.lua index 6feccebc..7a8e7f40 100644 --- a/lua/app/ui/main_city/main_city_ui.lua +++ b/lua/app/ui/main_city/main_city_ui.lua @@ -21,49 +21,25 @@ function MainCityUI:getUIType() return UIManager.UI_TYPE.MAIN end - function MainCityUI:currencyParams() - if self.cheat then - local params = {} - params.itemIds = {} - return params - end + function MainCityUI:getCurrencyParams() + if self.currencyParams == nil then + self.currencyParams = { + itemIds = {} + } + end self.selectedIndex = self.selectedIndex or MAIN_COMP_INDEX - local params = {} - params.showType = GConst.CURRENCY_TYPE.HORIZONTAL - if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.COMMERCE then - params.itemIds = { - GConst.ItemConst.ITEM_ID_GOLD, - GConst.ItemConst.ITEM_ID_GEM, - GConst.ItemConst.ITEM_ID_VIT, - } - elseif self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.EQUIP then - params.itemIds = { - GConst.ItemConst.ITEM_ID_GOLD, - GConst.ItemConst.ITEM_ID_GEM, - GConst.ItemConst.ITEM_ID_VIT, - } - elseif self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.MAIN then - params.itemIds = { - GConst.ItemConst.ITEM_ID_GOLD, - GConst.ItemConst.ITEM_ID_GEM, - GConst.ItemConst.ITEM_ID_VIT, - } - elseif self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.TALENT then - params.itemIds = { - GConst.ItemConst.ITEM_ID_GOLD, - GConst.ItemConst.ITEM_ID_GEM, - GConst.ItemConst.ITEM_ID_TALENT_ID, - } - elseif self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.CHALLENGE then - params.itemIds = { - GConst.ItemConst.ITEM_ID_GOLD, - GConst.ItemConst.ITEM_ID_GEM, - GConst.ItemConst.ITEM_ID_VIT, - } + self.currencyParams.showType = GConst.CURRENCY_TYPE.HORIZONTAL + for k, v in ipairs(self.currencyParams.itemIds) do + table.remove(self.currencyParams.itemIds) + end + if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.MAIN then + self.currencyParams.itemIds[1] = GConst.ItemConst.ITEM_ID_VIT + self.currencyParams.itemIds[2] = GConst.ItemConst.ITEM_ID_GOLD + elseif self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.HERO then + return nil end - return params, true - end - + return self.currencyParams +end function MainCityUI:getPrefabPath() return "assets/prefabs/ui/main_city/main_ui.prefab" @@ -119,13 +95,17 @@ function MainCityUI:_bind() self.subComps[self.selectedIndex]:refreshChapter() end end) - self:bind(DataManager.PlayerData, "dirty", function(binder, value) self:refreshRoleInfo() end, true) self:bind(DataManager.PlayerData, "lvUpDirty", function(binder, value) self:checkMainPop() end) + self:bind(DataManager.FormationData, "dirty", function(binder, value) + if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.HERO then + self.subComps[self.selectedIndex]:refresh() + end + end) -- self:bind(DataManager.BagData.ItemData, "dirty", function(binder, value) -- UIManager:refreshCurrencyBarTxt() diff --git a/lua/app/ui/ui_manager.lua b/lua/app/ui/ui_manager.lua index 02e2e8a8..9060dc70 100644 --- a/lua/app/ui/ui_manager.lua +++ b/lua/app/ui/ui_manager.lua @@ -991,37 +991,6 @@ function UIManager:backToLoginWithoutLogout() Game:showLoginUI() end --- 掉线提示处理 -function UIManager:showKickOut(msgData) - local content - local reason = NetManager:getKickOutReasonEnum(msgData.reason) - if reason == 0 then -- 服务器维护 - content = I18N:getGlobalText(I18N.GlobalConst.MAINTAIN) - elseif reason == 1 then -- 网络消息流控,也就是短时间内通信次数太多 - content = I18N:getGlobalText(I18N.GlobalConst.DISCONNECT_RELOGIN) - elseif reason == 2 then -- 封号 - content = I18N:getGlobalText(I18N.GlobalConst.FORBIDDEN) - elseif reason == 3 then -- 多点登录 - content = I18N:getGlobalText(I18N.GlobalConst.OTHER_LOGIN) - else - content = I18N:getGlobalText(I18N.GlobalConst.DISCONNECT_RELOGIN) - end - self.disconnectMsgBoxVisible = true - -- 被踢了的话就先断开连接再弹确认框 - NetManager:closeAndClear() - local params = { - content = content, - okText = I18N:getGlobalText(I18N.GlobalConst.BTN_TEXT_OK), - okFunc = function() - self.disconnectMsgBoxVisible = false - ModuleManager.LoginManager:goToLoginScene() - end, - boxType = GConst.MESSAGE_BOX_TYPE.MB_OK, - top = true, - } - GFunc.showMessageBox(params) -end - -- 掉线提示处理 function UIManager:showDisconnect() self.disconnectMsgBoxVisible = true @@ -1056,7 +1025,7 @@ function UIManager:_loadCurrencyBar(params, showBg, hidAddImg) end function UIManager:showCurrencyBar(uiObj) - local params, showBg, hidAddImg = uiObj:currencyParams() + local params, showBg, hidAddImg = uiObj:getCurrencyParams() if params then local currCurrencyBarOrder = 0 if self.currencyBarBindUI then diff --git a/lua/app/userdata/bag/item_entity.lua b/lua/app/userdata/bag/item_entity.lua index 49a60df7..2058aca8 100644 --- a/lua/app/userdata/bag/item_entity.lua +++ b/lua/app/userdata/bag/item_entity.lua @@ -1,8 +1,8 @@ local ItemEntity = class("ItemEntity", BaseData) -function ItemEntity:ctor(id, bigNum) +function ItemEntity:ctor(id, num) self.data.id = id - self.data.bigNum = bigNum + self.data.num = num self.data.isDirty = false self.config = nil @@ -30,19 +30,19 @@ function ItemEntity:getId() end -- 道具数量 -function ItemEntity:getBigNum() - return self.data.bigNum +function ItemEntity:getNum() + return self.data.num end -- 加减道具数量 function ItemEntity:addNum(num) - self.data.bigNum = BigNumOpt.bigNumAdd(self.data.bigNum, bigNum) + self.data.num = self.data.num + num self:setDirty() end -- 设置数量 -function ItemEntity:setNum(bigNum) - self.data.bigNum = bigNum +function ItemEntity:setNum(num) + self.data.num = num self:setDirty() end @@ -66,7 +66,7 @@ function ItemEntity:getFrameRes() end function ItemEntity:getIconRes() - return GConst.ATLAS_PATH.ICON_ITEM, tostring(self.config.icon) + return GConst.ATLAS_PATH.ICON_ITEM, self.config.icon end -- 类型 diff --git a/lua/app/userdata/battle/battle_data.lua b/lua/app/userdata/battle/battle_data.lua index 8e771986..950c7ecb 100644 --- a/lua/app/userdata/battle/battle_data.lua +++ b/lua/app/userdata/battle/battle_data.lua @@ -7,6 +7,9 @@ local BattleConst = GConst.BattleConst local BATTLE_GRID_ENTITY = require "app/userdata/battle/battle_grid_entity" local BATTLE_BOARD_SKILL_ENTITY = require "app/userdata/battle/skill/battle_borad_skill_entity" +local ATTR_TYPE = GConst.ATTR_TYPE +local DEFAULT_FACTOR = BattleConst.DEFAULT_FACTOR + function BattleData:init(board, skillIds, skillPool) self:clear() self.atkTeam = self:initTeam(BattleConst.SIDE_ATK) @@ -244,9 +247,54 @@ function BattleData:changeSkillId(elementType, newId) end function BattleData:initTeam(side) + local data = nil + if side == BattleConst.SIDE_ATK then + data = self:initHeroData() + end local team = BattleTeamEntity:create() - team:init(side) + team:init(side, data) return team end +function BattleData:getAtkTeam() + return self.atkTeam +end + +function BattleData:getDefTeam() + return self.defTeam +end + +function BattleData:initHeroData() + local units = {} + local formation = DataManager.FormationData:getStageFormation() + for matchType, heroId in pairs(formation) do + if heroId > 0 then + local heroEntity = DataManager.HeroData:getHeroById(heroId) + if heroEntity then + local heroAttr = heroEntity:getAllAttr() + local activeSkill = heroEntity:getActiveSkill() -- 主动技能 + local hp = heroAttr[ATTR_TYPE.hp] // DEFAULT_FACTOR + local unitData = { + id = heroId, + modelId = heroEntity:getModelId(), + level = heroEntity:getLv(), + qlt = heroEntity:getQlt(), + matchType = matchType, + activeSkill = activeSkill, + attr = { + hp = hp, + max_hp = hp, + atk = heroAttr[ATTR_TYPE.atk] // DEFAULT_FACTOR, + } + } + table.insert(units, unitData) + end + end + end + local data = { + units = units + } + return data +end + return BattleData \ No newline at end of file diff --git a/lua/app/userdata/battle/skill/battle_skill_entity.lua b/lua/app/userdata/battle/skill/battle_skill_entity.lua new file mode 100644 index 00000000..9639cdb6 --- /dev/null +++ b/lua/app/userdata/battle/skill/battle_skill_entity.lua @@ -0,0 +1,13 @@ +local BattleSkillEntity = class("BattleSkillEntity", BaseData) + +function BattleSkillEntity:ctor(skillId, skillType, owner) + self.skillType = skillType + self.skillId = skillId + self.owner = owner + self:init() +end + +function BattleSkillEntity:init() +end + +return BattleSkillEntity \ No newline at end of file diff --git a/lua/app/userdata/battle/skill/battle_skill_entity.lua.meta b/lua/app/userdata/battle/skill/battle_skill_entity.lua.meta new file mode 100644 index 00000000..b94e28fd --- /dev/null +++ b/lua/app/userdata/battle/skill/battle_skill_entity.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 0c5c8cb74597bdb46b1fcc5c941b9625 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/userdata/battle/team/battle_team_entity.lua b/lua/app/userdata/battle/team/battle_team_entity.lua index c2a76b62..5d87c085 100644 --- a/lua/app/userdata/battle/team/battle_team_entity.lua +++ b/lua/app/userdata/battle/team/battle_team_entity.lua @@ -4,10 +4,43 @@ local BattleTeamEntity = class("BattleTeamEntity", BaseData) function BattleTeamEntity:ctor() self.members = {} + self.membersCount = 0 end -function BattleTeamEntity:init(side) +function BattleTeamEntity:init(side, data) self.side = side + if data then + table.sort(data.units, function(a, b) + if a.level == b.level then + if a.qlt == b.qlt then + return a.id > b.id + else + return a.qlt > b.qlt + end + else + return a.level > b.level + end + end) + self.mainHero = nil + for i, unitData in ipairs(data.units) do + local unit = BattleUnitEntity:create() + unit:init(unitData, side, self) + self.members[unitData.matchType] = unit + self.membersCount = self.membersCount + 1 + if self.mainHero == nil then + unit:setIsMainUnit(true) + self.mainHero = unit + end + end + end +end + +function BattleTeamEntity:getAllMembers() + return self.members +end + +function BattleTeamEntity:getMembersCount() + return self.membersCount end return BattleTeamEntity \ No newline at end of file diff --git a/lua/app/userdata/battle/team/battle_unit_entity.lua b/lua/app/userdata/battle/team/battle_unit_entity.lua index e7444ba9..fa778c73 100644 --- a/lua/app/userdata/battle/team/battle_unit_entity.lua +++ b/lua/app/userdata/battle/team/battle_unit_entity.lua @@ -1,9 +1,58 @@ +local BattleSkillEntity = require "app/userdata/battle/skill/battle_skill_entity" + local BattleUnitEntity = class("BattleUnitEntity", BaseData) function BattleUnitEntity:ctor() end -function BattleUnitEntity:init() +function BattleUnitEntity:init(unitData, side, team) + self.unitData = unitData + self.side = side + self.team = team + self:initAttr() + self:initSkill() +end + +function BattleUnitEntity:initAttr() + local attr = self.attr or {} + if self.attr then -- 已经初始化过了 + for k, v in pairs(attr) do + attr[k] = self.unitData.attr[k] or 0 + end + else + for k, v in pairs(self.unitData.attr) do + attr[k] = v + end + end + self.attr = attr +end + +function BattleUnitEntity:initSkill() + self.skills = {} + if self.unitData.activeSkill then + local skill = BattleSkillEntity:create(self.unitData.activeSkill, GConst.BattleConst.SKILL_TYPE_ACTIVE, self) + table.insert(self.skills, skill) + end +end + +function BattleUnitEntity:getModelId() + return self.unitData.modelId +end + +function BattleUnitEntity:getMatchType() + return self.unitData.matchType +end + +function BattleUnitEntity:getSide() + return self.side +end + +function BattleUnitEntity:setIsMainUnit(isMainUnit) + self.isMainUnit = isMainUnit +end + +function BattleUnitEntity:getIsMainUnit() + return self.isMainUnit end return BattleUnitEntity \ No newline at end of file diff --git a/lua/app/userdata/formation.meta b/lua/app/userdata/formation.meta new file mode 100644 index 00000000..563cbbd2 --- /dev/null +++ b/lua/app/userdata/formation.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0dd4742e9835fbe41b107d5cbe1a1b5f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/lua/app/userdata/formation/formation_data.lua b/lua/app/userdata/formation/formation_data.lua new file mode 100644 index 00000000..25a92700 --- /dev/null +++ b/lua/app/userdata/formation/formation_data.lua @@ -0,0 +1,43 @@ +local FormationData = class("FormationData", BaseData) + +function FormationData:init(data) + self.data.dirty = false + self.formations = {} + if data and data.formations then + for formationType, formation in pairs(data.formations) do + local clientFormation = {} + self.formations[formationType] = clientFormation + for matchTypeStr, heroId in pairs(formation) do + clientFormation[tonumber(matchTypeStr)] = heroId + end + end + end +end + +function FormationData:getStageFormation() + return self:getFormation(GConst.BattleConst.BATTLE_TYPE.STAGE) +end + +function FormationData:getFormation(formationType) + local formation = self.formations[formationType] + if formation == nil then + formation = {} + self.formations[formationType] = formation + end + return formation +end + +function FormationData:upHeroToFormation(formationType, matchType, heroId) + local formation = self:getFormation(formationType) + if formation[matchType] == heroId then + return + end + formation[matchType] = heroId + self:setDirty() +end + +function FormationData:setDirty() + self.data.dirty = not self.data.dirty +end + +return FormationData \ No newline at end of file diff --git a/lua/app/userdata/formation/formation_data.lua.meta b/lua/app/userdata/formation/formation_data.lua.meta new file mode 100644 index 00000000..c8a20954 --- /dev/null +++ b/lua/app/userdata/formation/formation_data.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 4ed68c36ffa91694d9e2138c00b862d0 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/userdata/hero/hero_entity.lua b/lua/app/userdata/hero/hero_entity.lua index ce74f08e..7ceb7c0c 100644 --- a/lua/app/userdata/hero/hero_entity.lua +++ b/lua/app/userdata/hero/hero_entity.lua @@ -4,6 +4,8 @@ function HeroEntity:ctor(cfgId, lv) self.id = cfgId self.cfgId = cfgId self.data.lv = lv + self.atkKey = nil + self.hpKey = nil self.attrDirty = false self.config = ConfigManager:getConfig("hero")[self.cfgId] @@ -22,11 +24,19 @@ function HeroEntity:setLv(lv) if not lv then return end - + if self.data.lv == lv then + return + end self.data.lv = lv + self.atkKey = nil + self.hpKey = nil self:setDirty() end +function HeroEntity:getCfgId() + return self.cfgId +end + function HeroEntity:getLv() return self.data.lv end @@ -35,6 +45,10 @@ function HeroEntity:getQlt() return self.config.qlt end +function HeroEntity:getMatchType() + return self.config.position +end + function HeroEntity:setAttrDirty() self.attrDirty = true end @@ -52,8 +66,22 @@ function HeroEntity:updateAttr() end function HeroEntity:updateBaseAttr() - self.baseAttrOriginal[GConst.ATTR_TYPE.hp] = self.config.hp or 0 - self.baseAttrOriginal[GConst.ATTR_TYPE.atk] = self.config.atk or 0 + self.baseAttrOriginal[GConst.ATTR_TYPE.hp] = self.config[self:getHpKey()] or 0 + self.baseAttrOriginal[GConst.ATTR_TYPE.atk] = self.config[self:getAtkKey()] or 0 +end + +function HeroEntity:getHpKey() + if self.hpKey == nil then + self.hpKey = "hp_" .. self.data.lv + end + return self.hpKey +end + +function HeroEntity:getAtkKey() + if self.atkKey == nil then + self.atkKey = "atk_" .. self.data.lv + end + return self.atkKey end function HeroEntity:getAtk() @@ -99,4 +127,12 @@ function HeroEntity:getConfig() return self.config end +function HeroEntity:getModelId() + return self.config.model_id +end + +function HeroEntity:getActiveSkill() + return self.config.base_skill +end + return HeroEntity \ No newline at end of file diff --git a/lua/app/userdata/player/player_data.lua b/lua/app/userdata/player/player_data.lua index b27271dc..5a74dac1 100644 --- a/lua/app/userdata/player/player_data.lua +++ b/lua/app/userdata/player/player_data.lua @@ -3,4 +3,12 @@ local PlayerData = class("PlayerData", BaseData) function PlayerData:init(data) end + +function PlayerData:getMaxVit() + if self.maxVit == nil then + self.maxVit = ConfigManager:getConfig("recovery")[GConst.ItemConst.ITEM_ID_VIT].limit + end + return self.maxVit +end + return PlayerData \ No newline at end of file