109 lines
3.0 KiB
Lua
109 lines
3.0 KiB
Lua
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.DailyTask
|
|
local cfgEventsDailyTask = {}
|
|
for k, v in pairs( cfgAllEventsDailyTask ) do
|
|
local isInsert = true
|
|
|
|
if 8 == 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 isInsert then
|
|
table.insert( cfgEventsDailyTask , v)
|
|
end
|
|
end
|
|
|
|
local newGoods = self:GetNoRepeatItem( randCount - 1 , 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
|
|
|
|
return newGoods
|
|
end
|
|
|
|
skynet.server.task = Task
|
|
return Task |