|
|
- ItemUseModel = ItemUseModel or BaseClass(BaseModel)
- ItemUseModel.IgnoreProduceType =
- {
- [274] = "GoodsShelvesDwon", --市场下架
- [350] = "GoodsTransfer", -- 背包移动
- }
-
-
- function ItemUseModel:__init()
- ItemUseModel.Instance = self
- self.goods_dic = {} --获得的物品
- self.hide_item_view = false
- self.login_use_handle = false
- self.is_delay_show = false
- end
-
- function ItemUseModel:getInstance()
- if ItemUseModel.Instance == nil then
- ItemUseModel.New()
- end
- return ItemUseModel.Instance
- end
-
- --清除缓存数据
- function ItemUseModel:ClearData()
- self.goods_dic = {} --获得的物品
- self.fashion_add_goods = {} --时装类道具增加数组
- self.hide_item_view = false
- self.login_use_handle = false
- end
-
- --针对 15017 协议
- function ItemUseModel:UpdateBagGoodsDic(vo, produce_type,add_wear_horse)
- --某些产出类型,就不处理便捷弹窗
- if self:IsIgnoreItemUseTip(produce_type) then return end
-
- local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(vo.type_id)
- local lv = RoleManager.Instance.mainRoleInfo.level
- if not basic then
- return
- end
-
- --装备,没有激活的时装,配置为可使用的物品,都弹使用框
- local bag_goods_dic = GoodsModel:getInstance():GetBagGoodsDic()
- local goodsVo = bag_goods_dic[vo.goods_id]
- local copy_vo = goodsVo
- if not copy_vo then
- copy_vo = DeepCopy(vo)
- GoodsModel:getInstance():SetBaseInfo(copy_vo)
- end
- if GoodsModel:getInstance():IsGoodsNeedShowUseTipOnGainGoods(basic,copy_vo, vo) then
- if goodsVo then
- local exist_num = goodsVo.goods_num
- local last_num = vo.goods_num
- local curr_vo = self.goods_dic[vo.goods_id]
- if add_wear_horse then --放入仓库
- if curr_vo then
- curr_vo.goods_num = curr_vo.goods_num - last_num
- if curr_vo.goods_num <= 0 then
- self.goods_dic[vo.goods_id] = nil
- end
- end
- elseif exist_num > last_num then --说明是减少
- if curr_vo then
- curr_vo.goods_num = curr_vo.goods_num - (exist_num - last_num)
- if curr_vo.goods_num <= 0 then
- self.goods_dic[vo.goods_id] = nil
- end
- end
- elseif exist_num < last_num then --说明是增加
- if curr_vo then
- curr_vo.goods_num = curr_vo.goods_num + (last_num - exist_num)
- else
- self.goods_dic[vo.goods_id] = copy_vo
- end
- else
- --道具变更,并且原来没出现在便捷使用里
- if vo.goods_num > 0 and not self.goods_dic[vo.goods_id] then
- self.goods_dic[vo.goods_id] = copy_vo
- end
- end
- else
- --道具使用完
- if vo.goods_num == 0 then
- self.goods_dic[vo.goods_id] = nil
-
- --道具添加的时候
- elseif vo.goods_num > 0 and not self.goods_dic[vo.goods_id] then
- self.goods_dic[vo.goods_id] = copy_vo
- end
- end
-
- if basic.type == GoodsModel.TYPE.EQUIP then
- if vo.goods_num > 0 then
- self.goods_dic[vo.goods_id] = copy_vo
- else
- --穿了某个装备的时候,判断下,便捷使用的其他装备,是否能够满足继续穿戴的情况
- GlobalEventSystem:DelayFire(EventName.CHECK_ITEM_USE_EQUIP_CAN_SHOW)
- end
- end
- else
- if basic.type == GoodsModel.TYPE.EQUIP then
- if vo.goods_num == 0 then
- --穿了某个装备的时候,判断下,便捷使用的其他装备,是否能够满足继续穿戴的情况
- GlobalEventSystem:DelayFire(EventName.CHECK_ITEM_USE_EQUIP_CAN_SHOW)
- end
- end
- end
-
- if basic.type == 17 and basic.subtype == 3 then --神格装备
- -- if not DeityModel:getInstance():EquipFightCompare(vo.type_id) then
- -- self.goods_dic[vo.goods_id] = nil
- -- end
- elseif basic.type == 36 and basic.subtype == 4 then
- local vip_type = RoleManager.Instance.mainRoleInfo.vip_type
- if vip_type and vip_type <= 1 then
- self.goods_dic[vo.goods_id] = nil
- end
- end
- end
-
- --添加提示
- function ItemUseModel:AddUseTip( vo )
- local copy_vo = DeepCopy(vo)
- GoodsModel:getInstance():SetBaseInfo(copy_vo)
- self.goods_dic[vo.goods_id] = copy_vo
- end
-
- --强制添加提示
- function ItemUseModel:AddForceUseTip( vo )
- local copy_vo = DeepCopy(vo)
- GoodsModel:getInstance():SetBaseInfo(copy_vo)
- copy_vo.force = true
- self.goods_dic[vo.goods_id] = copy_vo
- end
-
- --尝试去添加提示
- function ItemUseModel:TryAddUseTip( vo )
- local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(vo.type_id)
- if not basic then
- return
- end
-
- local bool = false
- if basic.type == GoodsModel.TYPE.EQUIP then
- -- if basic.career_id == 0 or basic.career_id == RoleManager.Instance.mainRoleInfo.career then
- -- bool = true
- -- end
- bool = false
- elseif basic.type == 17 and basic.subtype == 3 then
- if DeityModel:getInstance():EquipFightCompare(basic.type_id) then
- bool = true
- end
- end
-
- local cfg = Config.ConfigItemUse.Reward[vo.type_id] or Config.ConfigItemUse.TypeUse[basic.type.."@"..basic.subtype]
- if cfg then
- local lv = RoleManager.Instance.mainRoleInfo.level
- local career = RoleManager.Instance.mainRoleInfo.career
- if (cfg.limit_lv == -1 or (cfg.limit_lv ~= -1 and lv >= cfg.limit_lv)) and (not cfg.career or (cfg.career and cfg.career == career)) then
- bool = true
- else
- bool = false
- end
- end
-
- if bool then
- local copy_vo = DeepCopy(vo)
- GoodsModel:getInstance():SetBaseInfo(copy_vo)
- self.goods_dic[vo.goods_id] = copy_vo
- end
- end
- --针对 15010协议
- function ItemUseModel:HandleLoginUseTips(goods_list)
- if not self.login_use_handle and goods_list then
- print("ItemUseModel:HandleLoginUseTips()")
- for i, vo in ipairs(goods_list) do
- ItemUseModel:getInstance():TryAddUseTip(vo)
- end
- self.login_use_handle = true
- end
- end
-
- --针对 15018 协议 当出售的时候
- function ItemUseModel:UpdateBagGoodsDicWhenSell(vo)
- local bag_goods_dic = GoodsModel:getInstance():GetBagGoodsDic()
- local goodsVo = bag_goods_dic[vo.goods_id]
-
- if goodsVo then
- local exist_num = goodsVo.goods_num
- local last_num = vo.goods_num
-
- --说明是减少
- local curr_vo = self.goods_dic[vo.goods_id]
- if exist_num > last_num then
- if curr_vo then
- curr_vo.goods_num = curr_vo.goods_num - (exist_num - last_num)
- if curr_vo.goods_num <= 0 then
- self.goods_dic[vo.goods_id] = nil
- end
- end
- end
- end
- end
-
- function ItemUseModel:UpdateStarShadowBagGoods( vo )
- local bag_goods_dic = GoodsModel:getInstance().starShadow_bag_list
- local goodsVo = bag_goods_dic[vo.goods_id]
-
- if goodsVo then
- local exist_num = goodsVo.goods_num
- local last_num = vo.goods_num
-
- --说明是减少
- local curr_vo = self.goods_dic[vo.goods_id]
- if exist_num > last_num then
- if curr_vo then
- curr_vo.goods_num = curr_vo.goods_num - (exist_num - last_num)
- if curr_vo.goods_num <= 0 then
- self.goods_dic[vo.goods_id] = nil
- end
- end
- end
- end
- end
-
- --获取主界面道具使用界面Vo
- function ItemUseModel:MatchPopCondition()
- local scene_mgr = SceneManager.Instance
- if scene_mgr:IsNoonQuizScene() then
- return false
- end
-
- if GuideModel:getInstance():IsHideSmallUI() then
- return false
- end
-
- if self.is_delay_show then
- return false
- end
-
- return true
- end
-
-
- --获取主界面道具使用界面Vo
- function ItemUseModel:GetItemShowVo()
- if self.goods_dic then
- for i,vo in pairs(self.goods_dic) do
- if vo.force==true and (vo.expire_time == 0 or (vo.expire_time ~= 0 and vo.expire_time - TimeUtil:getServerTime() > 0))then --强制提示
- return vo
- else
- if vo.type == GoodsModel.TYPE.EQUIP then --如果是装备,则判断是否有更好的 才显示
- local is_can_wear = EquipModel:getInstance():EquipCanShowGoodsTip(vo)
- if is_can_wear then
- return vo, true
- end
-
- local is_auction = GoodsModel:getInstance():IsEquipCanAuctionButNoUse(vo)
- if is_auction then
- return vo
- end
- else
- if vo.expire_time == 0 or (vo.expire_time ~= 0 and vo.expire_time - TimeUtil:getServerTime() > 0) then
- return vo
- end
- end
- end
- end
- end
-
- return nil
- end
-
- function ItemUseModel:SetIgnore_Better( bool )
- self.ignore_better = bool
- if bool then
- setTimeout(function()
- self.ignore_better = false
- end,3)
- end
- end
-
- --根据物品类型获取数量
- function ItemUseModel:GetTypeGoodsNum(typeId)
- local id = tonumber(typeId)
- local theNum = 0
- if id < 1 then
- return 0
- end
- for i,vo in pairs(self.goods_dic) do
- if vo.type_id == typeId then
- theNum = theNum + vo.goods_num
- end
- end
- return theNum
- end
-
- --根据物品id获取数量
- function ItemUseModel:GetGoodsNumById(goods_id)
- return self.goods_dic[goods_id] and self.goods_dic[goods_id].goods_num or 0
- end
-
- --当当前物品被使用的时候 。查看剩下的相同type_id,有的话优先取这个Vo
- function ItemUseModel:GetVoByTypeId(typeId)
- if self.goods_dic then
- for i,vo in pairs(self.goods_dic) do
- if vo.type_id == typeId then
- return vo
- end
- end
- end
-
- return nil
- end
-
- --当当前物品被使用的时候 。查看剩下的相同type_id,有的话优先取这个Vo
- function ItemUseModel:ContainGoodsId(goods_id)
- return self.goods_dic[goods_id]
- end
-
- --根据类型id清除Vo信息
- function ItemUseModel:ClearTypeIdData(typeId)
- if self.goods_dic then
- for i,vo in pairs(self.goods_dic) do
- if vo.type_id == typeId then
- self.goods_dic[vo.goods_id] = nil
- end
- end
- end
- end
-
- --根据物品唯一id清除Vo信息
- function ItemUseModel:ClearIdData(goods_id)
- if self.goods_dic then
- print(">>>>>>>>>>> ClearIdData ", goods_id)
-
-
- for i,vo in pairs(self.goods_dic) do
- if vo.goods_id == goods_id then
- self.goods_dic[vo.goods_id] = nil
- end
- end
- -- PrintTable(self.goods_dic)
- end
- end
-
- --删除评分更低的装备
- function ItemUseModel:DelLowerEquip(goods_id)
- if self.goods_dic then
- local goods_vo = GoodsModel:getInstance():GetBagGoodsInfoById(goods_id)
- if goods_vo then
- for i,vo in pairs(self.goods_dic) do
- if vo.type_id == goods_vo.type_id and vo.rating<=goods_vo.rating then
- self.goods_dic[vo.goods_id] = nil
- end
- end
- end
- end
- end
-
- --是否小天使小恶魔
- function ItemUseModel:IsEquipSpecialType(type_id)
- local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
- if goods_basic then
- return goods_basic.type == GoodsModel.TYPE.EQUIP and goods_basic.subtype == GoodsModel.SHOUHU_EQUIP_TYPE
- end
- return false
- end
-
-
-
- --是否佩戴了或者拥有小恶魔
- function ItemUseModel:HasWearXiaoEMoOrHas( )
- local vo = GoodsModel:getInstance().wear_equip_list[GoodsModel.SHOUHU_EQUIP_TYPE]
- if not vo then --装备栏上没有装备小恶魔
- local bool = self:CheckXiaoEMo(1011000003)
- if bool then
- return
- end
- local list = GoodsModel:getInstance():GetTypeGoods(1011000001)
- if TableSize(list) ~= 0 then --背包里有小恶魔
- table.sort(list,function (a,b)
- return a.expire_time > b.expire_time
- end)
-
- for i,v in ipairs(list) do
- if TimeUtil:getServerTime() < v.expire_time then
- -- GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,v, 5)
- -- BaseDungeonModel:getInstance():Fire(BaseDungeonModel.SHOW_UES_EXP_EVIL_BTN,true,v.goods_id)
- return
- end
- end
- --这里就是续费
- -- GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,list[1], 5)
- BaseDungeonModel:getInstance():Fire(BaseDungeonModel.SHOW_UES_EXP_EVIL_BTN,true,list[1].goods_id)
- end
- else
- --local vo = GoodsModel:getInstance().wear_equip_list[11]
- -- if vo and (vo.type_id==1011000001 or vo.type_id==1011000005) and TimeUtil:getServerTime() > vo.expire_time then
- -- GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,vo, 5)
- -- end
- if vo.type_id == 1011000003 or vo.type_id == 1011000001 or vo.type_id == 1011000005 then
- if TimeUtil:getServerTime() > vo.expire_time then --物品过期了
- if vo.type_id == 1011000003 then --如果身上大的过期,就看看背包里面有没有小的没有过期的
- local bool = self:CheckXiaoEMo(1011000001)
- if not bool then --如果没有,就提醒续费
- -- GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,vo, 5)
- BaseDungeonModel:getInstance():Fire(BaseDungeonModel.SHOW_UES_EXP_EVIL_BTN,true,vo.goods_id)
- end
- elseif vo.type_id == 1011000001 then --如果身上是小的过期了,就看看背包里面有没有大的,没有就提醒续费
- local bool = self:CheckXiaoEMo(1011000003)
- if not bool then --如果没有,就提醒续费
- -- GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,vo, 5)
- BaseDungeonModel:getInstance():Fire(BaseDungeonModel.SHOW_UES_EXP_EVIL_BTN,true,vo.goods_id)
- end
- elseif vo.type_id == 1011000005 then
- local bool = self:CheckXiaoEMo(1011000003)
- if not bool then --如果没有,就提醒续费
- bool = self:CheckXiaoEMo(1011000001)
- if not bool then --如果没有,就提醒续费
- -- GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,vo, 5)
- BaseDungeonModel:getInstance():Fire(BaseDungeonModel.SHOW_UES_EXP_EVIL_BTN,true,vo.goods_id)
- end
- end
- end
- else --如果没有过期,并且身上是小的,就看看背包里有没有大的,如果是大的没有过期,就什么都不敢
- if vo.type_id == 1011000001 or vo.type_id == 1011000003 or vo.type_id == 1011000005 then
- self:CheckXiaoEMo(1011000003)
- end
- end
- else
- local bool = self:CheckXiaoEMo(1011000003)
- if not bool then
- self:CheckXiaoEMo(1011000001,true)
- end
- end
- end
- end
-
- function ItemUseModel:CheckXiaoEMo(id,show_tip)
- local list = GoodsModel:getInstance():GetTypeGoods(id)
-
- if TableSize(list) ~= 0 then --背包里有小恶魔
- table.sort(list,function (a,b)
- return a.expire_time > b.expire_time
- end)
-
- for i,v in ipairs(list) do
- if TimeUtil:getServerTime() < v.expire_time then
- GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,v, 5)
- return true
- end
- end
- --这里就是续费
- if show_tip then
- GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,list[1], 5)
- end
- end
- end
-
- --是否穿戴了守护
- function ItemUseModel:HasWearEvil( )
- local evil_id = EquipModel:getInstance():GetFollowGuardId()
- return evil_id ~= 0
- end
-
- --是否佩戴了未过期小恶魔
- function ItemUseModel:HasWearXiaoEMo( )
- local vo = GoodsModel:getInstance().wear_equip_list[11]
- if vo and (vo.type_id==1011000001 or vo.type_id==1011000005 or vo.type_id==1011000003 ) and TimeUtil:getServerTime() < vo.expire_time then
- return true
- end
- end
-
- --是否佩戴了未过期小天使
- function ItemUseModel:HasWearXiaoTianShi( )
- local vo = GoodsModel:getInstance().wear_equip_list[11]
- if vo and (vo.type_id==1011000002 or vo.type_id==1011000004 )and TimeUtil:getServerTime() < vo.expire_time then
- return true
- end
- end
-
- function ItemUseModel:HideItemUseView( )
- self.hide_item_view = true
-
- GlobalEventSystem:Fire(EventName.CLOSE_ITEM_USE_VIEW)
-
- end
-
- function ItemUseModel:GetHideState( )
- return self.hide_item_view
- end
-
- function ItemUseModel:SetHideState(bool)
- self.hide_item_view = bool
- end
-
- function ItemUseModel:ShowItemUseView( )
- if not GoodsModel:getInstance():CheckCanFlyGood() then--检查飞道具图标的条件
- return
- end
- local vo = ItemUseModel:getInstance():GetItemShowVo()
- if vo then
- self.hide_item_view = false
- GlobalEventSystem:Fire(EventName.REOPEN_ITEM_USE_VIEW)
- else
- self.hide_item_view = false
- end
- end
-
- -- 因为骑宠幻形激活道具填了use又无法再背包使用jump属性比较蛋疼,所以在这里特殊处理
- function ItemUseModel:IsHorsePetSpecial(vo)
- if vo == nil then return false end
- if vo.type == 18 and vo.subtype == 4 then -- 宠物幻形激活道具
- return PetModel:getInstance():IlluCanAvtivateByGoodsId(vo.type_id)
- elseif vo.type == 16 and vo.subtype == 3 then -- 坐骑幻形激活道具
- return HorseModel:getInstance():IlluCanAvtivateByGoodsId(vo.type_id)
- end
- return false
- end
-
- --未激活的时装弹出使用框
- function ItemUseModel:IsUnActiveFashion(vo)
- if vo then
- if vo.type == 12 and vo.subtype >= 1 and vo.subtype <= 4 then
- return FashionModel:getInstance():GetFashionByConsumable(vo.type_id)
- end
- end
- return false
- end
-
- --未激活的幻形宝宝弹出使用框
- function ItemUseModel:IsUnActiveBaby(vo)
- return false
- end
-
- function ItemUseModel:SetDelayFlag(bool,time)
- self.is_delay_show = bool
- if self.is_delay_show then
- setTimeout(function()
- self.is_delay_show = false
- self:ShowItemUseView()
- end, time)
- end
- end
-
- --是否显示使用提示界面(登录游戏时)
- function ItemUseModel:InitBagGoodsDicOnStarGame( goods_list )
- if self.is_first_init_goods_dic_on_start_game and self.is_first_init_goods_dic_on_start_game>=2 then return end
- self.is_first_init_goods_dic_on_start_game = self.is_first_init_goods_dic_on_start_game or 0
- self.is_first_init_goods_dic_on_start_game = self.is_first_init_goods_dic_on_start_game + 1
- for i,v in ipairs(goods_list) do
- local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(v.type_id)
- local is_need_show_tip_view = GoodsModel:getInstance():IsGoodsNeedShowUseTipOnStartGame(basic,v)
- if is_need_show_tip_view then
- local copy_vo = DeepCopy(v)
- GoodsModel:getInstance():SetBaseInfo(copy_vo)
- self.goods_dic[v.goods_id] = copy_vo
- end
- end
- end
-
- --玩家整理道具触发便捷使用
- function ItemUseModel:InitBagGoodsDicOnSort( goods_list )
- self.goods_dic = {}
- for i,v in ipairs(goods_list) do
- if v.goods_num ~= 0 then
- local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(v.type_id)
- local is_need_show_tip_view = GoodsModel:getInstance():IsGoodsNeedShowUseTipOnGainGoods(basic,v,v)
- if not is_need_show_tip_view then
- is_need_show_tip_view = GoodsModel:getInstance():IsGoodsNeedShowUseTipOnStartGame(basic,v)
- end
- if is_need_show_tip_view then
- local copy_vo = DeepCopy(v)
- self.goods_dic[v.goods_id] = copy_vo
- end
- end
- end
-
- local vo = self:GetItemShowVo()
- if vo then
- GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,vo)
- end
- end
-
- --是否在便捷使用忽略列表
- function ItemUseModel:IsIgnoreItemUseTip(produce_type)
- produce_type = produce_type or 0
- return ItemUseModel.IgnoreProduceType[produce_type]
- end
-
- --重新检测下,便捷使用列表中的其他装备还是否满足可以穿戴
- function ItemUseModel:CheckItemUseListOtherEquipCanWear()
- local remove_goods_id_list = {}
- local is_reopen = false
- for k,v in pairs(self.goods_dic) do
- local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(v.type_id)
- if basic and basic.type == GoodsModel.TYPE.EQUIP then
- local is_need_show = GoodsModel.getInstance():IsEquipNeedShowUseTipGoods(v)
- if not is_need_show then
- table.insert(remove_goods_id_list, v.goods_id)
- is_reopen = true
- end
- end
- end
-
- if is_reopen then
- for k,v in pairs(remove_goods_id_list) do
- self.goods_dic[v] = nil
- end
- GlobalEventSystem:Fire(EventName.REOPEN_ITEM_USE_VIEW)
- end
- end
-
- --是否数时装和称号道具增加了
- function ItemUseModel:IsAddFashionOrFashionchip(goods_vo)
- local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(goods_vo.type_id)
- if basic.type == GoodsModel.TYPE.FASHION or (basic.type == GoodsModel.TYPE.FASHIONCHIP and basic.subtype == 1) then
- local bag_goods_dic = GoodsModel:getInstance():GetBagGoodsDic()
- local bag_good_vo = bag_goods_dic[goods_vo.goods_id]
-
- self.fashion_add_goods = self.fashion_add_goods or {}
- --背包本来没有
- if not bag_good_vo then
- --道具增加
- if goods_vo.goods_num > 0 then
- local copy_new_vo = DeepCopy(goods_vo)
- table.insert(self.fashion_add_goods, copy_new_vo)
- end
- else
- --道具变更,并且增加
- if goods_vo.goods_num > bag_good_vo.goods_num then
- local copy_new_vo = DeepCopy(goods_vo)
- table.insert(self.fashion_add_goods, copy_new_vo)
- end
- end
- end
- end
-
- --检测一些特殊类型的道具的便捷使用
- function ItemUseModel:CheckReShowGood()
- if self.fashion_add_goods and #self.fashion_add_goods > 0 then
- for i,vo in ipairs(self.fashion_add_goods) do
- self:UpdateBagGoodsDic(vo, nil,nil)
- end
- GoodsModel.getInstance():DelayFire(GoodsModel.CHANGE_BAGLIST)
- end
- self.fashion_add_goods = {}
- end
|