BagModel = BagModel or BaseClass(BaseVo) BagModel.OPEN_BATHANDLE_VIEW = "BagModel.OPEN_BATHANDLE_VIEW" BagModel.OPEN_ENLARGE_VIEW = "BagModel.OPEN_ENLARGE_VIEW" BagModel.OPEN_ALL_ADDITION_VIEW = "BagModel.OPEN_ALL_ADDITION_VIEW" BagModel.OPEN_SELL_VIEW = "BagModel.OPEN_SELL_VIEW" BagModel.OPEN_DEPOT_VIEW = "BagModel.OPEN_DEPOT_VIEW" BagModel.CLICK_BAG_ITEM = "BagModel.CLICK_BAG_ITEM" BagModel.OPEN_EQUIP_DECOMPOSE_VIEW = "BagModel.OPEN_EQUIP_DECOMPOSE_VIEW" BagModel.EQUIP_ITEM_GET_WAY_TIPS = "BagModel.EQUIP_ITEM_GET_WAY_TIPS" BagModel.CLOSE_EQUIP_ITEM_GET_WAY_TIPS = "BagModel.CLOSE_EQUIP_ITEM_GET_WAY_TIPS" BagModel.CLOSE_SELL_VIEW = "BagModel.CLOSE_SELL_VIEW" --吞噬 BagModel.REQUEST_PROTOCOL = "BagModel.REQUEST_PROTOCOL" BagModel.CLOSE_SWALLOW_SELECT_CONTENT = "BagModel.CLOSE_SWALLOW_SELECT_CONTENT" BagModel.SELECT_SWALLOW_TYPE = "BagModel.SELECT_SWALLOW_TYPE" BagModel.CLICK_EQUIP_ITEM = "BagModel.CLICK_EQUIP_ITEM" BagModel.REFRESH_SWALLOW_INIT = "BagModel.REFRESH_SWALLOW_INIT" BagModel.REFRESH_SWALLOW_RESULT = "BagModel.REFRESH_SWALLOW_RESULT" BagModel.CLICK_SWALLOW_CORE_ITEM = "BagModel.CLICK_SWALLOW_CORE_ITEM" BagModel.UPDATE_EQUIP_GOODS = "BagModel.UPDATE_EQUIP_GOODS" BagModel.ANS_UPDATE_EQUIP_RED = "BagModel.ANS_UPDATE_EQUIP_RED" BagModel.UPDATE_AUTO_SWALLOW_STATE = "BagModel.UPDATE_AUTO_SWALLOW_STATE" BagModel.SORT_BAG_AFTER_SWALLOW = "BagModel.SORT_BAG_AFTER_SWALLOW"--关闭吞噬界面后要整理一次背包 BagModel.UPDATE_SWALLOW_ATTR_SHOW = "BagModel.UPDATE_SWALLOW_ATTR_SHOW" BagModel.BAG_SWALLOW_CAN_STRENGTH = "BagModel.BAG_SWALLOW_CAN_STRENGTH"--吞噬数量达标,通知变强 --货币兑换 BagModel.OPEN_CURRENCY_EXCHANGE_VIEW = "BagModel.OPEN_CURRENCY_EXCHANGE_VIEW" --打开货币兑换界面 BagModel.UPDATE_CURRENCY_EXCHANGE_VIEW = "BagModel.UPDATE_CURRENCY_EXCHANGE_VIEW" --进行兑换之后刷新货币兑换界面 BagModel.UPDATE_CURRENCY_GOODS_NUM = "BagModel.UPDATE_CURRENCY_GOODS_NUM" --货币礼包数量更新 BagModel.ANS_UPDATE_CURRENCY_EXCHANGE_RED = "BagModel.ANS_UPDATE_CURRENCY_EXCHANGE_RED" --刷新交易券兑换的执行方法 BagModel.UPDATE_CURRENCY_VIEW = "BagModel.UPDATE_CURRENCY_VIEW" --刷新交易券兑换界面 BagModel.OPEN_SUIT_ACTIVE_VIEW = "BagModel.OPEN_SUIT_ACTIVE_VIEW" --打开套装激活界面 BagModel.OPEN_EQUIP_ORANGE_SUIT_VIEW = "BagModel.OPEN_EQUIP_ORANGE_SUIT_VIEW" --打开橙品套装界面 BagModel.SpiritId = 501002 --吞噬模型id BagModel.StampGoodsId = 101014 --用于兑换交易券的交易卡券物品id BagModel.FlyGoodsID = 102602 -- 小飞鞋道具id BagModel.GoodsLimitState = { Normal = 0, Limit = 1, TimeOut = 2, } function BagModel:__init() BagModel.Instance = self self.show_bag_view = false self.Swallow_data = nil self.Swallow_result_data = nil self.IsOnClickSwallow = false self.double_click_time = 0.3 self.Swallow_red = false self.is_check_swallow_red = false --是否打开过吞噬界面,打开过一次之后,本次登录不再给红点 self.swallow_lv = 0 self.pre_swallow_lv = 0 --进行吞噬之前的吞噬等级 self.swallow_exp = 0 self.pre_swallow_exp = 0 self.is_auto_swallow = false self.swallow_active_lv = 0 --激活的吞噬特殊属性等级 self.last_sort_bag_time = {} self.last_swallow_sort_bag_time = 0 --上次吞噬整理背包的时间 self.can_swallow_strength = false self.currency_exchange_daily_counts = 0 --彩钻兑换交易券今日已使用次数 self.currency_exchange_red = false --交易券兑换红点 self.currency_exchange_free_time = 0 --免费兑换时间 self.currency_exchange_props_red = false--使用道具兑换交易券红点 self.currency_exchange_diamond_red = false--使用彩钻兑换交易券红点 self.swallow_core_cfg = {} self.show_drop_timeout_props_tips = true --是否提示丢弃过期道具提示 self.bag_quick_buy_toggle = false --背包便捷购买toggle self.bag_equip_suit_active_red = false self.bag_equip_suit_active_level_list = false self.bag_equip_suit_active_task_list = false self:InitSwallowCoreCfg() end function BagModel:getInstance() if BagModel.Instance == nil then BagModel.New(); end return BagModel.Instance end function BagModel:OpenBagView() end --[[ ===================================== description: 全身加成相关的方法 ===================================== ]] --获取全身宝石数、星级和精炼数、圣印精炼数 function BagModel:GetAllAddition() local strength = 0 local star = 0 local stone = 0 local seal_stren = 0 local function callback_1(dynamic) strength = strength + (dynamic.stren or 0) local _star = Config.Equipattr[dynamic.type_id] and Config.Equipattr[dynamic.type_id].star or 0 star = star + _star if dynamic.stone_list then for i, v in ipairs(dynamic.stone_list) do local cfg = Config.Equipstonelv[v.type_id] if cfg then stone = stone + cfg.lv end end end end for k, v in pairs(GoodsModel:getInstance().wear_equip_list) do GoodsModel:getInstance():GetDynamic(v.goods_id, callback_1) end local function callback_2(dynamic) seal_stren = seal_stren + (dynamic.stren or 0) end for k, v in pairs(GoodsModel:getInstance().seal_equip_dic) do GoodsModel:getInstance():GetDynamic(v.goods_id, callback_2) end return strength, star, stone, seal_stren end --获取全身加成的等级和下一级配置 --增加参数 strength_count 精炼数 by lgj function BagModel:GetBodyPlusConfig(style, strength_count) local style = style or 1 local list = {} for i, v in pairs(Config.Equipwholereward) do if v.type == style then table.insert(list, v) end end local sort_fun = function (a, b) return a.need_lv < b.need_lv end table.sort(list, sort_fun) local now_cfg = nil local next_cfg = nil local num_list = {} local num if strength_count == nil then num_list[1], num_list[2], num_list[3], num_list[4] = self:GetAllAddition() num = num_list[style] else num = strength_count end for i, v in ipairs(list) do if num >= v.need_lv then now_cfg = v else next_cfg = v break end end return now_cfg, next_cfg end function BagModel:GetSwallowRedDot( ) return self.Swallow_red end function BagModel:CheckEquipSwallowRed() if GetModuleIsOpen(150,4) then local need_red_num = 10 -- 所需红点的可吞噬装备数 if VipModel:getInstance():IsForeverVip() then local fly_shoes = GoodsModel:getInstance():GetTypeGoods(BagModel.FlyGoodsID) if not IsTableEmpty(fly_shoes) then -- 存在一个小飞鞋以上的道具时,红点所需的装备数减少1 need_red_num = 9 end end local equips_list = {} local goods_list = GoodsModel:getInstance().bag_goods_list for k,v in pairs(goods_list) do if v.type == GoodsModel.TYPE.EQUIP and v.subtype ~= 8 and v.subtype ~= 9 and v.subtype ~= 10 and v.subtype ~= 11 and v.goods_num >0 and v.color < 3 then table.insert(equips_list,v) end end local attr_unlock_red = self:CheckSwallowAttrUnlockRed() -- if self.is_check_swallow_red then --吞噬的红点登录只给一次,但解锁红点除外 -- self.Swallow_red = attr_unlock_red -- else -- self.Swallow_red = #equips_list >= need_red_num or attr_unlock_red -- end self.Swallow_red = #equips_list >= need_red_num or attr_unlock_red self.can_swallow_strength = #equips_list >= need_red_num else self.Swallow_red = false self.can_swallow_strength = false end --超过10件可吞噬的装备,通知变强 self:Fire(BagModel.BAG_SWALLOW_CAN_STRENGTH,self.can_swallow_strength) GlobalEventSystem:Fire(EventName.UPDATE_BAG_RED) end function BagModel:GetCanSwallowStrength( ) return self.can_swallow_strength end function BagModel:CheckEquipSwallowRedByFlyShoesChanges( ) self:CheckEquipSwallowRed() local goods_model = GoodsModel:getInstance() -- 获得道具之后尝试自动吞噬 local fly_shoes_num = goods_model:GetTypeGoodsNum(BagModel.FlyGoodsID) if fly_shoes_num > 0 then goods_model:AutoSwallow() end end --检查吞噬特殊属性解锁红点 function BagModel:CheckSwallowAttrUnlockRed( ) for i,v in ipairs(self.swallow_core_cfg) do if self:SwallowCanUnlock(v.lv) then return true end end return false end function BagModel:TrySortBag( pos_type ) if not pos_type then return end if not self.last_sort_bag_time[pos_type] or Time.time - self.last_sort_bag_time[pos_type] > 5 then self.last_sort_bag_time[pos_type] = Time.time GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT,15004,pos_type) return true else Message.show("你的"..(pos_type==GoodsModel.GOODS_POS_TYPE.bag and "背包" or "仓库").."整理的太快了,请稍后再操作") end end function BagModel:GetLastSortBagTime( pos_type ) return self.last_sort_bag_time[pos_type] and self.last_sort_bag_time[pos_type] or 0 end function BagModel:SetSwallowData(vo) self.swallow_lv = vo.lv self.swallow_exp = vo.exp self.is_auto_swallow = vo.is_auto_swallow == 1 and true or false self.swallow_active_lv = vo.active end --初始化法核配置 function BagModel:InitSwallowCoreCfg( ) for k,v in pairs(Config.Goodsdevourextra) do table.insert(self.swallow_core_cfg,v) end table.sort(self.swallow_core_cfg,function(a,b) return a.lv= self.swallow_core_cfg[i].lv then return self.swallow_core_cfg[i],i end end return self.swallow_core_cfg[1],1 end --拿到当前吞噬等级所处的法核itemId function BagModel:GetNowSwallowCoreItemId() for i=#self.swallow_core_cfg,1,-1 do if self.swallow_lv >= self.swallow_core_cfg[i].lv then return i end end return 1 end --获取最大的吞噬法核itemid,其实就是配置的条数 function BagModel:GetMaxSwallowCoreItemId( ) return #self.swallow_core_cfg end --根据等级拿到法核配置 function BagModel:GetSwallCoreCfgByLv(index) return self.swallow_core_cfg[index] and self.swallow_core_cfg[index] or self.swallow_core_cfg[1] end --判断当前等级的特殊属性能否解锁 function BagModel:SwallowCanUnlock(lv) if lv>self.swallow_active_lv and lv<=self.swallow_lv then return true end return false end --道具是否过期(状态) function BagModel:GetGoodsLimitState(goods_vo, cur_time) local s = BagModel.GoodsLimitState.Normal if goods_vo and goods_vo.goods_id and goods_vo.goods_id ~= 0 and goods_vo.expire_time ~= 0 then cur_time = cur_time or TimeUtil:getServerTime() if cur_time > goods_vo.expire_time then s = BagModel.GoodsLimitState.TimeOut else s = BagModel.GoodsLimitState.Limit end end return s end --筛选出已经过期的道具 function BagModel:GetTimeOutGoodsList(goods_vo_list) local t = {} if goods_vo_list and #goods_vo_list > 0 then local cur_time = TimeUtil:getServerTime() for k,v in pairs(goods_vo_list) do if v.expire_time and v.expire_time > 0 then if v.expire_time < cur_time and v.goods_num > 0 then table.insert(t, {goods_id = v.goods_id, type_id = v.type_id, num = v.goods_num}) end end end end return t end --更新今日彩钻兑换交易券已用次数 function BagModel:SetCurrencyExchangeDailyCounts(counts) self.currency_exchange_daily_counts = counts end --获得今日彩钻兑换交易券已用次数 function BagModel:GetCurrencyExchangeDailyCounts( ) return self.currency_exchange_daily_counts end --获取拥有最高兑换次数的vip等级 function BagModel:GetCurreccyExchangeMaxVip( ) local max_vip = 0 for k,v in pairs(Config.Vipprivilege) do if v.class_id == 150 and v.lv >= max_vip then max_vip = v.lv end end return max_vip end --根据当前vip获得彩钻兑换交易券可用次数 function BagModel:GetCurrencyExchangeNumsByVip( ) local my_vip_flag = RoleManager.Instance.mainRoleInfo.vip_flag if my_vip_flag == 0 then return 0 else local privilege_type = 150 --彩钻兑换交易券的vip权限类型 local cfg = self:GetCurrencyVipPrivilege(my_vip_flag) local max_vip = self:GetCurreccyExchangeMaxVip() return cfg and cfg.value or self:GetCurrencyVipPrivilege(max_vip).value end end --获取特权表配置 function BagModel:GetCurrencyVipPrivilege(vip_flag) local privilege_type = 150--兑换交易券的vip权限类型 local cfg = Config.Vipprivilege for k,v in pairs(cfg) do if v.lv == vip_flag and v.class_id == privilege_type then return v end end return nil end --当前还剩多少次交易券兑换次数 function BagModel:GetCurrencyExchangeNumsNow( ) return self:GetCurrencyExchangeNumsByVip()-self:GetCurrencyExchangeDailyCounts() end --交易券礼包数量监听 function BagModel:OnCurrencyGiftBagGoodsChange( ) self:Fire(BagModel.UPDATE_CURRENCY_GOODS_NUM) end --交易券兑换红点 function BagModel:CheckCurrencyExchangeRed( ) local bool = false self.currency_exchange_props_red = false self.currency_exchange_diamond_red = false local stamp_goods_num = GoodsModel:getInstance():GetTypeGoodsNum(BagModel.StampGoodsId) --已有的交易券数量 if stamp_goods_num >= 10 and RoleManager.Instance.mainRoleInfo.level >= 105 then bool = true self.currency_exchange_props_red = true end --免费兑换时间 if self.currency_exchange_free_time ~= 0 and RoleManager.Instance.mainRoleInfo.level >= 96 then if not bool then bool = self.currency_exchange_free_time <= TimeUtil:getServerTime() end self.currency_exchange_diamond_red = self.currency_exchange_free_time <= TimeUtil:getServerTime() end self.currency_exchange_red = bool GlobalEventSystem:Fire(EventName.UPDATE_BAG_RED) end --获取交易券兑换红点 function BagModel:GetCurrencyExchangeRed( ) return self.currency_exchange_red end --获取道具兑换交易券红点 function BagModel:GetCurrencyExchangePropsRed( ) return self.currency_exchange_props_red end --获取彩钻兑换交易券红点 function BagModel:GetCurrencyExchangeDiamondRed( ) return self.currency_exchange_diamond_red end --交易券兑换红点免费次数的红点 function BagModel:RequestCurrencyExchangeRed( ) if self.currency_exchange_free_time ~= 0 and self.currency_exchange_free_time <= TimeUtil:getServerTime() then self:Fire(BagModel.REQUEST_PROTOCOL,15026) --打开背包的时候,在检测一次免费兑换次数,刷新红点 end end --获取套装fv激活红点 function BagModel:GetBagEquipSuitActiveRedDot( ) return self.bag_equip_suit_active_red end --刷新套装激活红点 function BagModel:UpdateBagEquipSuitActiveRedDot( ) local function delay_fun( ) local max = EquipModel.getInstance():GetCurrentOpenSuitSeries() local can_max = EquipModel.getInstance():GetCanActiveMaxSeries() local b = can_max > max if b ~= self.bag_equip_suit_active_red then self.bag_equip_suit_active_red = b GlobalEventSystem:Fire(EventName.UPDATE_BAG_RED) end end TimeManager.GetInstance():StartDalayTime("UpdateBagEquipSuitActiveRedDot",0.2,delay_fun) end --是否是套装激活的任务id function BagModel:IsBagEquipSuitActiveTask(task_id) if not self.bag_equip_suit_active_task_list then self.bag_equip_suit_active_task_list = {} local config = Config.Equipmentseriesopen for i,v in ipairs(config) do if v.task_id ~= 0 then self.bag_equip_suit_active_task_list[v.task_id] = true end end end return self.bag_equip_suit_active_task_list[task_id] end --是否是套装激活的level function BagModel:IsBagEquipSuitActiveLevel(level) if not self.bag_equip_suit_active_level_list then self.bag_equip_suit_active_level_list = {} local config = Config.Equipmentseriesopen for i,v in ipairs(config) do self.bag_equip_suit_active_level_list[v.open_lv] = true end end return self.bag_equip_suit_active_level_list[level] end