local skynet = require "skynet" local oo = require "Class" local log = require "Log" local dataType = require "DataType" local pb = require "pb" local Task = oo.class() Task.TaskStatus_NoComplete = 1 --未完成 Task.TaskStatus_AlreadyComplete = 2 --已完成 Task.TaskStatus_AlreadyGet = 3 --已领取 Task.TaskStatus_OutOfTime = 4 --任务过期 function Task:Init() end --获取不重复的商品 function Task:GetNoRepeatItem( randCount , cfgAllItem) local randList = {} local randIndex = nil local newGoods = {} local whileCount = 0 while true do if 0 == #cfgAllItem then break end randIndex = math.random( 1, #cfgAllItem) if not randList[ randIndex ] then --不存在新的列表就添加进去 table.insert( newGoods , cfgAllItem[ randIndex ].id ) randList[ randIndex ] = true end --找够了数据或者循环了1000次就退出 if #newGoods >= randCount or whileCount >= 1000 then break end whileCount = whileCount + 1 end return newGoods end --在当前物品信息中是否存在家具ID function Task:IsExistGoodsId( goodsId , allGoods ) for k, v in pairs( allGoods ) do if goodsId == v.id then return true end end return false end --获取随机每日任务 function Task:GetRandDailyTask( player , randCount ) local cfgAllEventsDailyTask = skynet.server.gameConfig:GetPlayerAllCfg( player , "DailyTask") local cfgEventsDailyTask = {} for k, v in pairs( cfgAllEventsDailyTask ) do local isInsert = true if 8 == v.id or 12 == v.id then --领取邮箱金币3次不通过随机刷出 isInsert = false end if not player:IsUnlockSystem( dataType.UnlockSystem_Used ) and ( 1 == v.id or 2 == v.id or 7 == v.id ) then isInsert = false end --检查友圈房子是否解锁 local isUnlockHouse = false for k, v in pairs( player.gameData.friend ) do if v.isUnlockHouse then isUnlockHouse = true break end end if ( not player:IsUnlockSystem( dataType.UnlockSystem_Friend ) or not isUnlockHouse ) and 3 == v.id then isInsert = false end if not player:IsUnlockSystem( dataType.UnlockSystem_Plant ) and 4 == v.id then isInsert = false end if 11 == v.id then local cfgAllDecoration = skynet.server.gameConfig:GetPlayerAllCfg( player , "Decoration") local cfgCount = 0 --逸家商店中有的装修数量 for k, v in pairs(cfgAllDecoration) do if skynet.server.shop.BuyShopType_Coin == v.shopType then cfgCount = cfgCount + 1 end end local myCount = 0 --我的装修数量 for k, v in pairs( player.gameData.bag ) do if dataType.GoodsType_Decorate == v.type then local cfgCurDecoration = skynet.server.gameConfig:GetPlayerCurCfg( player , "Decoration" , v.id ) if skynet.server.shop.BuyShopType_Coin == cfgCurDecoration.shopType then myCount = myCount + 1 end end end --我的装修数量大于商店中的数量,就不再刷新该任务 if myCount >= cfgCount then isInsert = false end end if isInsert then table.insert( cfgEventsDailyTask , v) end end local newGoods = self:GetNoRepeatItem( randCount - 2 , cfgEventsDailyTask ) --强制插入该任务 --[[local allCount = #newGoods local rand = math.random(1,allCount) for i = 1, allCount , 1 do if i == rand then table.insert( newGoods , 8 ) break end end]] table.insert( newGoods , 8 ) table.insert( newGoods , 12 ) return newGoods end skynet.server.task = Task return Task