HomeServer/Server/Common/Player/Player.lua
2024-11-20 15:41:37 +08:00

2841 lines
137 KiB
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local skynet = require "skynet"
local oo = require "Class"
local json =require "json"
local log = require "Log"
local dataType = require "DataType"
local redisKeyUrl = require "RedisKeyUrl"
local pb = require "pb"
local serverId = tonumber(skynet.getenv "serverId")
local Player = oo.class()
Player.maxLevelLimt = 85
--初始化玩家数据
function Player:ctor( userId , playerData)
self.userId = userId
self.account = playerData.basicInfo.accountName
self.basicInfo = playerData.basicInfo
self.gameData = playerData.gameData
local nowTime = skynet.GetTime()
--生成临时数据
self.tmpData = {}
self.tmpData.lastUpgradeTime = 0 --上一次升级时间
self.tmpData.cacheExp = 0 --缓存经验
self.tmpData.partner = {}
self.tmpData.partner.alreadyQueryUser = {} --已经查询的玩家
self.tmpData.group = {}
self.tmpData.group.alreadyQueryList = {} --已经查询的家园列表
self.tmpData.intoTime = nowTime
self.tmpData.lastOnlineTime = nowTime --上一次在线时间
self.tmpData.sendStorePackIds = {} --记录商城发奖表现失败的数据
self.tmpData.msgHistory = {} --消息历史
self.tmpData.officialPayDatas = {} --记录官网充值处理失败的数据{用于客户端提示}
self.tmpData.saveLevel = dataType.SaveLevel_No --保存级别
self.tmpData.unUsedGoods = {} --未使用的物品缓存
end
--添加所有未使用的物品缓存
function Player:AddAllUnUsedGoods( goodsType , goodsInfo )
if not self.tmpData.unUsedGoods[ goodsType ] then
self.tmpData.unUsedGoods[ goodsType ] = {}
end
self.tmpData.unUsedGoods[ goodsType ].goodsInfo = goodsInfo
end
--获取所有未使用的物品缓存
function Player:GetAllUnUsedGoods( goodsType , goodsInfo )
if not self.tmpData.unUsedGoods[ goodsType ] or not self.tmpData.unUsedGoods[ goodsType ].goodsInfo then
return nil
end
return self.tmpData.unUsedGoods[ goodsType ].goodsInfo
end
--重置所有未使用的物品缓存
function Player:ResetAllUnUsedGoods()
self.tmpData.unUsedGoods = {}
end
--增加未使用的物品缓存
function Player:AddOneUnUsedGoods( goodsType , goodsId , count )
if not self.tmpData.unUsedGoods[ goodsType ] or not self.tmpData.unUsedGoods[ goodsType ].goodsInfo then
return nil
end
local goodsInfo = self.tmpData.unUsedGoods[ goodsType ].goodsInfo
local isExist = false
for k, v in pairs( goodsInfo ) do
if goodsType == v.type and goodsId == v.id then
goodsInfo[ k ].count = goodsInfo[ k ].count + count
isExist = true
break
end
end
if not isExist then
local cfgFurniture = skynet.server.gameConfig:GetPlayerCurCfg( self , "Furniture" , goodsId )
if cfgFurniture.shopType ~= skynet.server.doubleSpace.ShopTypeNo then --双人空间的家具不能计算在里面
table.insert( goodsInfo , { type = goodsType , id = goodsId , count = count , gainTime = skynet.GetTime() })
end
end
end
--移除一个未使用的物品缓存
function Player:RemoveOneUnUsedGoods( goodsType , goodsId , count )
if not self.tmpData.unUsedGoods[ goodsType ] or not self.tmpData.unUsedGoods[ goodsType ].goodsInfo then
return nil
end
local goodsInfo = self.tmpData.unUsedGoods[ goodsType ].goodsInfo
for k, v in pairs( goodsInfo ) do
if goodsType == v.type and goodsId == v.id then
goodsInfo[ k ].count = goodsInfo[ k ].count - count
if goodsInfo[ k ].count <= 0 then
table.remove( goodsInfo , k)
end
break
end
end
end
--添加消息历史
function Player:AddMsgHistory( cmd , nowTime )
--如果没有该命令的消息历史或者距离上次发送时间超过3秒则更新时间
if not self.tmpData.msgHistory[ cmd ] then
self.tmpData.msgHistory[ cmd ] = {}
self.tmpData.msgHistory[ cmd ].nowTime = nowTime
self.tmpData.msgHistory[ cmd ].isInit = true
end
local msgHistory = self.tmpData.msgHistory[ cmd ]
if nowTime - msgHistory.nowTime > 3 then
msgHistory.nowTime = nowTime
msgHistory.isInit = true
end
end
--是否消息过快
function Player:IsMsgTooFast( cmd )
--存在命令并且距离上次发送时间小于等于3秒就表示消息过快
local msgHistory = self.tmpData.msgHistory[ cmd ]
if msgHistory.isInit then
msgHistory.isInit = false
return false
end
if not msgHistory.isInit and skynet.GetTime() - msgHistory.nowTime <= 3 then
return true
end
return false
end
--内部包数据,线上不能用
function Player:InnerData( player )
for i = 1, 80, 1 do
player:AddExpCount( 10000 , true , true )
end
player.gameData.coin = 100000
player.gameData.clovers = 100000
player.gameData.volute = 100000
local data = {
commandField={
[1]={
articlesNumber=5,
articlesType="Furniture",
},
[2]={
articlesNumber=1,
articlesType="Decoration",
},
[3]={
articlesNumber=1,
articlesType="Clothes",
},
[4]={
articlesNumber=1,
articlesType="PetClothes",
},
[5]={
articlesNumber=1,
articlesType="Flowerpot",
},
},
cmdType=true,
}
skynet.server.gm:WebGoods(player , data )
--[[
local needLevel = 60
local level = player.gameData.level
for i = 1, needLevel - level, 1 do
player:AddExpCount(100000, true, true)
end
local cfgTask = skynet.server.gameConfig:GetPlayerAllCfg( player , "LevelTask") --任务配置
for k, v in pairs( cfgTask ) do
if not player.gameData.levelTask[ v.id ] then --and (44 == v.id or 46 == v.id) then
player.gameData.levelTask[ v.id ] = {}
player.gameData.levelTask[ v.id ].id = v.id
player.gameData.levelTask[ v.id ].type = v.taskType --任务类型
player.gameData.levelTask[ v.id ].target = v.taskTarget --任务目标
player.gameData.levelTask[ v.id ].progress =v.value --当前进度
player.gameData.levelTask[ v.id ].status =2 --是否完成
player.gameData.levelTask[ v.id ].historyId = {}
else
player.gameData.levelTask[ v.id ].progress =v.value --当前进度
player.gameData.levelTask[ v.id ].status =2 --是否完成
end
end
local cfgTask = skynet.server.gameConfig:GetPlayerAllCfg( player , "DailyTask") --任务配置
for k, v in pairs( player.gameData.dailyTask.item ) do
v.progress = 100
v.status = 2
end
local cfgTask = skynet.server.gameConfig:GetPlayerAllCfg( player , "AchievementTask") --任务配置
local achieveTask = player.gameData.achieveTask
for k, v in pairs( cfgTask ) do
if not achieveTask[ v.id ] then
achieveTask[ v.id ] = {}
achieveTask[ v.id ].id = v.id
achieveTask[ v.id ].order = v.order
achieveTask[ v.id ].type = v.taskType --任务类型
achieveTask[ v.id ].progress =v.value --当前进度
achieveTask[ v.id ].status =2 --是否完成
else
achieveTask[ v.id ].progress =v.value --当前进度
achieveTask[ v.id ].status =2 --是否完成
end
end
--NPC任务
local cfgTask = skynet.server.gameConfig:GetPlayerAllCfg( player , "NPCTask") --任务配置
for k, v in pairs( cfgTask ) do
if not player.gameData.npcTask[ v.id ] then
player.gameData.npcTask[ v.id ] = {}
player.gameData.npcTask[ v.id ].id = v.id
player.gameData.npcTask[ v.id ].type = v.taskType --任务类型
player.gameData.npcTask[ v.id ].target = v.seedId --任务目标
player.gameData.npcTask[ v.id ].progress =v.value --当前进度
player.gameData.npcTask[ v.id ].status =2 --是否完成
player.gameData.npcTask[ v.id ].historyId = {}
else
player.gameData.npcTask[ v.id ].progress =v.value --当前进度
player.gameData.npcTask[ v.id ].status =2 --是否完成
end
end
--图鉴
local cfgAllFurniture = skynet.server.gameConfig:GetPlayerAllCfg( player , "Furniture" )
for k, v in pairs( cfgAllFurniture ) do
skynet.server.illustration:Add( player , dataType.GoodsType_Furniture , v.id )
end
local cfgAllDecoration = skynet.server.gameConfig:GetPlayerAllCfg( player , "Decoration" )
for k, v in pairs( cfgAllDecoration ) do
skynet.server.illustration:Add( player , dataType.GoodsType_Decorate , v.id )
end
local cfgAllClothes = skynet.server.gameConfig:GetPlayerAllCfg( player , "Clothes" )
for k, v in pairs( cfgAllClothes ) do
skynet.server.illustration:Add( player , dataType.GoodsType_Clothes , v.id )
end
local cfgAllPetClothes = skynet.server.gameConfig:GetPlayerAllCfg( player , "PetClothes" )
for k, v in pairs( cfgAllPetClothes ) do
skynet.server.illustration:Add( player , dataType.GoodsType_PetClothes , v.id )
end
local cfgAllPlant = skynet.server.gameConfig:GetPlayerAllCfg( player , "Plant" )
for k, v in pairs( cfgAllPlant ) do
skynet.server.illustration:Add( player , dataType.GoodsType_Plant , v.id )
end
]]
end
--初始化没有的数据
function Player:InitNoData( player )
if player.gameData.passCheck and player.gameData.passCheck[ 73 ] and not player.gameData.passCheck[ 73 ].historyId then
player.gameData.passCheck[ 73 ].historyId = {}
end
if skynet.server.house:IsBuyHouse( player , 11 ) then
skynet.server.levelTask:Modify( player , 3 , 1 )
skynet.server.taskListEvent:Modify( player , 3 , 1 )
end
local cfgAllTask = skynet.server.gameConfig:GetPlayerAllCfg( player , "LevelTask")
local levelTask = player.gameData.levelTask
for k, v in pairs( cfgAllTask ) do
if levelTask[ v.id ] and not levelTask[ v.id ].historyId then
levelTask[ v.id ].historyId = {}
end
end
local cfgAllTask = skynet.server.gameConfig:GetPlayerAllCfg( player , "NPCTask") --任务配置
local npcTask = player.gameData.npcTask
for k, v in pairs( cfgAllTask ) do
if npcTask[ v.id ] and not npcTask[ v.id ].historyId then
npcTask[ v.id ].historyId = {}
end
end
if player.gameData.shop[ dataType.ShopType_Cuisine ] then
if 3 == player.gameData.shop[ dataType.ShopType_Cuisine ].menuLevel then
if npcTask[13] and npcTask[13].progress < 3 then
player.gameData.npcTask[13].progress = 0
skynet.server.npcTask:Modify( player , 96 , 3 )
skynet.server.taskListEvent:Modify( player , 96 , 3 )
end
elseif 4 == player.gameData.shop[ dataType.ShopType_Cuisine ].menuLevel then
if npcTask[19] and player.gameData.npcTask[19].progress < 4 then
player.gameData.npcTask[19].progress = 0
skynet.server.npcTask:Modify( player , 96 , 4 )
skynet.server.taskListEvent:Modify( player , 96 , 4 )
end
end
end
if player.gameData.shop[dataType.ShopType_PetShop] then
local petShop = player.gameData.shop[dataType.ShopType_PetShop]
if npcTask[17] and player.gameData.npcTask[17].progress >= 1 and player.gameData.npcTask[17].status ==
skynet.server.task.TaskStatus_NoComplete or petShop.petStudy[3].studyLvl >= 3 and
player.gameData.npcTask[17].status == skynet.server.task.TaskStatus_NoComplete then
skynet.server.npcTask:Modify(player, 109, 1)
skynet.server.taskListEvent:Modify( player ,109, 1)
elseif npcTask[20] and player.gameData.npcTask[20].progress >= 1 and player.gameData.npcTask[20].status ==
skynet.server.task.TaskStatus_NoComplete or petShop.petStudy[1].studyLvl >= 3 and
player.gameData.npcTask[20].status == skynet.server.task.TaskStatus_NoComplete then
skynet.server.npcTask:Modify(player, 107, 1)
skynet.server.taskListEvent:Modify( player ,107, 1)
elseif npcTask[25] and player.gameData.npcTask[25].progress >= 1 and player.gameData.npcTask[25].status ==
skynet.server.task.TaskStatus_NoComplete or petShop.petStudy[2].studyLvl >= 3 and
player.gameData.npcTask[25].status == skynet.server.task.TaskStatus_NoComplete then
skynet.server.npcTask:Modify(player, 108, 1)
skynet.server.taskListEvent:Modify( player ,108, 1)
end
end
local cfgNPCTask = skynet.server.gameConfig:GetPlayerAllCfg( player , "NPCTask")
local npcTask = player.gameData.npcTask
for k, v in pairs( cfgNPCTask ) do
if npcTask[ v.id ] and not npcTask[ v.id ].historyId then
npcTask[ v.id ].historyId = {}
end
end
if not self.gameData.upTime then
self.gameData.upTime = skynet.GetTime()
end
local petStore = skynet.server.gameConfig:GetPlayerAllCfg(player, "PetStore")
-- 刷新玩家资料书购买次数
if not self.gameData.shop[dataType.ShopType_PetShop] and self.gameData.petShopRefresh == nil or not self.gameData.shop[dataType.ShopType_PetShop] and self.gameData.petShopRefresh == 1 then
self.gameData.petShopRefresh = 2
elseif self.gameData.shop[dataType.ShopType_PetShop] and self.gameData.petShopRefresh == nil or self.gameData.shop[dataType.ShopType_PetShop] and self.gameData.petShopRefresh == 1 then
self.gameData.petShopRefresh = 2
for k ,v in pairs(self.gameData.shop[dataType.ShopType_PetShop].petShopGoodInfo ) do
if next(petStore[v.id].packLimit) ~= nil and petStore[v.id].packLimit[1] == 1 then
v.buyTimes = 0
skynet.server.msgTips:Add(self, 84)
elseif next(petStore[v.id].packLimit) ~= nil and petStore[v.id].packLimit[1] == 2 then
v.buyTimes = 0
skynet.server.msgTips:Add(self, 84)
end
end
end
local curShop = self.gameData.shop[ dataType.ShopType_Coffee ]
if curShop and not curShop.noNewCoffeeCount then
curShop.noNewCoffeeCount = 0 --未抽到新咖啡的数量
end
if self.gameData.level >= 10 and not self:IsUnlockSystem(dataType.UnlockSystem_ActivityCarnival) then
self:AddUnlockSystem(dataType.UnlockSystem_ActivityCarnival)
end
local isHaveGoods = player:IsBuyGoods(dataType.GoodsType_Decorate, 262) --是否拥有
if not isHaveGoods then
skynet.server.bag:AddGoods( self , dataType.GoodsType_Decorate , 262 , 1)
end
--检查下后面加的活动是否能解锁
local cfgAllActivity = skynet.server.gameConfig:GetPlayerAllCfg( self , "Activity")
for k , v in pairs(cfgAllActivity) do
if dataType.ActivityType_DecoWeek == v.activityType and self.gameData.level >= v.level then --装修周
self:AddUnlockSystem( dataType.UnlockSystem_ActivityDecoWeek )
elseif dataType.ActivityType_DreamLife == v.activityType and self.gameData.level >= v.level then --若来向往一日
self:AddUnlockSystem( dataType.UnlockSystem_ActivityDreamLife )
elseif dataType.ActivityType_FlipCard == v.activityType and self.gameData.level >= v.level then --翻翻乐
self:AddUnlockSystem( dataType.UnlockSystem_ActivityFlipCard )
elseif dataType.ActivityType_Puzzle == v.activityType and self.gameData.level >= v.level then --拼图
self:AddUnlockSystem( dataType.UnlockSystem_ActivityPuzzle )
elseif dataType.ActivityType_MatchStuff == v.activityType and self.gameData.level >= v.level then
self:AddUnlockSystem( dataType.UnlockSystem_ActivityMatchStuff )
elseif dataType.ActivityType_SignPack == v.activityType and self.gameData.level >= v.level then
self:AddUnlockSystem( dataType.UnlockSystem_ActivitySignPack )
elseif dataType.ActivityType_SeekTreasure == v.activityType and self.gameData.level >= v.level then
self:AddUnlockSystem( dataType.UnlockSystem_ActivitySeekTreasure )
elseif dataType.ActivityType_ActivityLevelPack == v.activityType and self.gameData.level >= v.level then
self:AddUnlockSystem( dataType.UnlockSystem_ActivityLevelPack )
elseif dataType.ActivityType_ActivityStagePack == v.activityType and self.gameData.level >= v.level then
self:AddUnlockSystem( dataType.UnlockSystem_ActivityStagePack )
elseif dataType.ActivityType_DailyRiddle == v.activityType and self.gameData.level >= v.level then
self:AddUnlockSystem( dataType.UnlockSystem_ActivityDailyRiddle )
elseif dataType.ActivityType_SavingPot == v.activityType and self.gameData.level >= v.level then --存钱罐
self:AddUnlockSystem(dataType.UnlockSystem_ActivitySavingPot)
elseif dataType.ActivityType_ActivityReplicaStore == v.activityType and self.gameData.level >= v.level then
self:AddUnlockSystem( dataType.UnlockSystem_ActivityReplicaStore )
elseif dataType.ActivityType_BindBox == v.activityType and self.gameData.level >= v.level then --盲盒
self:AddUnlockSystem(dataType.UnlockSystem_ActivityBindBox)
end
end
--检查园艺铺子是否有新配置
local cfgGarden = skynet.server.gameConfig:GetPlayerAllCfg( self , "Garden") --园艺铺子配置
for k, v in pairs( cfgGarden ) do
local count = v.id
if not self.gameData.todayGain.gardenInfo[ count ] then
self.gameData.todayGain.gardenInfo[count] = {}
self.gameData.todayGain.gardenInfo[count].id = count -- 奖励id
self.gameData.todayGain.gardenInfo[count].dailyLimit = {v.dailyLimit, 0} -- 兑换限制 例如 {3,1} 3 本日可兑换次数 1 本日已兑换次数
self.gameData.todayGain.gardenInfo[count].contributeValue = v.contributeValue -- 贡献币需求兑换数
self.gameData.todayGain.gardenInfo[count].communityShop = v.communityShop -- 园艺铺子类别
self.gameData.todayGain.gardenInfo[count].unlock = false -- 园艺铺子家具是否解锁
end
end
if self.gameData.level >= 19 and self.gameData.shop[ dataType.ShopType_GardenShop ] then
--没有展示历史,就加一个
local houseRent = player.gameData.houseRent
-- 兼容老数据
if not houseRent.showShortHistory then
--黄玉平没做保底,所以玩家没有该数据,这里给老玩家加上
houseRent.showShortHistory = {}
houseRent.showLongHistory = {}
end
for k, v in pairs( houseRent.houseInfo ) do
if v.houseId then
--有些玩家数据被黄玉平搞成了houseId这里发现再变回id
v.id = v.houseId
v.houseId = nil
end
end
end
--料理店兼容老玩家数据
if self.gameData.shop[ dataType.ShopType_Cuisine ]
and next(self.gameData.shop[ dataType.ShopType_Cuisine ]) ~= nil then
if self.gameData.shop[ dataType.ShopType_Cuisine ].mealInfos[1].difficulty == nil then
--玩家菜单相关数据赋值
local difficulty = 1
local count = 1
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue") --套餐数据
self.gameData.shop[ dataType.ShopType_Cuisine ].mealInfos = {}
for k ,v in pairs(cfgSValue.foodShopSetDifficultyNum) do
for k1=1,v,1 do
self.gameData.shop[ dataType.ShopType_Cuisine ].mealInfos[ count ] = {}
self.gameData.shop[ dataType.ShopType_Cuisine ].mealInfos[ count ].id = count --套餐索引
self.gameData.shop[ dataType.ShopType_Cuisine ].mealInfos[ count ].difficulty = difficulty --套餐难度
self.gameData.shop[ dataType.ShopType_Cuisine ].mealInfos[ count ].status = 0 --套餐状态 0 未开启该套餐 1 未完成 2 可以完成 3 已完成 默认未开启该套餐
self.gameData.shop[ dataType.ShopType_Cuisine ].mealInfos[ count ].cuisineInclude = {} --套餐完成包含的菜品
count = count + 1
end
difficulty = difficulty + 1
end
for k ,v in pairs(self.gameData.shop[ dataType.ShopType_Cuisine ].cuisineInfos) do
v.setChoiceCount = 0
end
end
if self.gameData.shop[ dataType.ShopType_Cuisine ].plotInfos[1].startPlantTime == nil then
for i=1,5,1 do
self.gameData.shop[ dataType.ShopType_Cuisine ].plotInfos[ i ] = {}
self.gameData.shop[ dataType.ShopType_Cuisine ].plotInfos[ i ].id = i --菜地id
self.gameData.shop[ dataType.ShopType_Cuisine ].plotInfos[ i ].status = 0 --菜地状态 0未解锁 1未种植 2幼苗 3初枝 4成枝 5成熟 默认未种植
self.gameData.shop[ dataType.ShopType_Cuisine ].plotInfos[ i ].matId = 0 --植物id 初始为0
self.gameData.shop[ dataType.ShopType_Cuisine ].plotInfos[ i ].nextStatusTime = 0 --下个植物状态的时间戳
self.gameData.shop[ dataType.ShopType_Cuisine ].plotInfos[ i ].startPlantTime = 0 --开始种植的时间戳
end
end
end
--设计空间兼容老玩家数据
if self.gameData.design and self.gameData.design.timeCardPoolInfo.id and self.gameData.design.timeCardPoolInfo.last10FurCount == nil then
self.gameData.design.timeCardPoolInfo.last10FurCount = 0
self.gameData.design.timeCardPoolInfo.design10Count = 0
end
if not self.gameData.design.timeCardPoints then
self.gameData.design.timeCardPoints = {}
end
--审核玩家初始通行证
if self:IsAudit() then
self:AddUnlockSystem( dataType.UnlockSystem_PassCheck )
end
--兼容老玩家商城积分数据
if self.gameData.storePack then
local cfgAll = skynet.server.gameConfig:GetPlayerAllCfg( self , "ValueAccumulate" )
--玩家当前的积分挡位小于配置的积分挡位
if #self.gameData.storePack.pointsInfo < #cfgAll then
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( self , "SValue" )
for k ,v in pairs(cfgAll) do
if k > #self.gameData.storePack.pointsInfo then
self.gameData.storePack.pointsInfo[ k ] = {}
self.gameData.storePack.pointsInfo[ k ].id = v.id
self.gameData.storePack.pointsInfo[ k ].isGet = 0 --默认不可领取
end
if self.gameData.storePack.rechargeAmount * cfgSValue.valueAccumulatePoint >= v.point
and self.gameData.storePack.pointsInfo[ k ].isGet == 0 then
self.gameData.storePack.pointsInfo[k].isGet = 1 --修改为可以领取
skynet.server.msgTips:AddNoNotice(self , 49) --同时添加对应红点
end
end
end
end
--充值问题
local payAccount = skynet.server.redis:zscore(redisKeyUrl.PayServerAllPlayerPayAccountZSet,self.account)
if payAccount then
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( self , "SValue" )
--商城积分修改
self.gameData.storePack.rechargeAmount = payAccount
--限时累充积分修改
if next(player.gameData.design.timeCardPoolInfo) ~= nil then
for k , v in pairs(player.gameData.design.timeCardPoints) do
if v.raffleId == 48 then
v.points = payAccount * cfgSValue.valueAccumulatePoint
end
end
end
--移除对应数据
skynet.server.redis:zrem(redisKeyUrl.PayServerAllPlayerPayAccountZSet,self.account)
end
if self.gameData.storePack then
local cfgAll = skynet.server.gameConfig:GetPlayerAllCfg( self , "ValueAccumulate" )
--判断是否需要修改玩家对应奖励状态
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( self , "SValue" )
for k ,v in pairs(cfgAll) do
if player.gameData.storePack.rechargeAmount * cfgSValue.valueAccumulatePoint >= v.point and player.gameData.storePack.pointsInfo[k].isGet == 0 then
player.gameData.storePack.pointsInfo[k].isGet = 1 --修改为可以领取
skynet.server.msgTips:AddNoNotice(player , 49) --同时添加对应红点
end
end
--限时累充积分修改
if next(player.gameData.design.timeCardPoolInfo) ~= nil then
for k , v in pairs(player.gameData.design.timeCardPoints) do
if v.raffleId == 48 then
--判断积分是否达到可以领取对应的积分奖励
local cfgLimitedAccum = skynet.server.gameConfig:GetPlayerCurCfg( player , "LimitedAccum" , k )
for k1 ,v1 in pairs(cfgLimitedAccum.value) do
if v.points >= v1 and v.pointsInfo[k1].isGet == 0 then
v.pointsInfo[k1].isGet = 1 --修改为可以领取
skynet.server.msgTips:AddNoNotice(player , 94) --同时添加对应红点
end
end
end
end
end
end
--如果已经购买了,并且未解锁家园,就解锁一下
if not self:GetSwitch( dataType.SwitchType_GainGarden ) and skynet.server.house:IsBuyHouse( self , 11) then
self:SetSwitch( dataType.SwitchType_GainGarden , true )
end
--个人物品获取时间兼容
if self.gameData.personal.gainGoodsInfo == nil then
self.gameData.personal.gainGoodsInfo = {}
--之前获取的物品获取时间设置为当前时间
for k , v in pairs(self.gameData.personal.ownHeadIds) do
table.insert(self.gameData.personal.gainGoodsInfo , {type = dataType.GoodsType_HeadAndHeadFrame , id = v , count = 1 , gainTime = skynet.GetTime()})
end
for k , v in pairs(self.gameData.personal.ownHeadFrameIds) do
table.insert(self.gameData.personal.gainGoodsInfo , {type = dataType.GoodsType_HeadAndHeadFrame , id = v , count = 1 , gainTime = skynet.GetTime()})
end
end
local curShop = player.gameData.shop[ dataType.ShopType_GardenShop ]
if curShop and not curShop.specialGoods then
player.gameData.shop[ dataType.ShopType_GardenShop ].specialGoods = {}
player.gameData.shop[ dataType.ShopType_GardenShop ].generalGoods = {}
player.gameData.shop[ dataType.ShopType_GardenShop ].nextRefreshTime = 0
end
--人物新增服饰
local clothesData = player.gameData.personal.clothesData
if clothesData and not clothesData[ dataType.ClothesType_Earrings ] then
clothesData[ dataType.ClothesType_Earrings ] = 0
clothesData[ dataType.ClothesType_Facing ] = 0
end
--宠物新增面饰
local petType = skynet.server.pet.PetType_Cat
local petInfo =player.gameData.pet [ petType ]
if petInfo and not petInfo.facingId then
petInfo.facingId= 0
end
--同步图鉴新增的积分和花园图鉴信息
if player.gameData.illustration.pointInfo == nil or next(player.gameData.illustration.pointInfo) == nil then
skynet.server.illustration:AsycGardenIllstration(self)
if player.gameData.illustration.awardInfo ~= nil and next(player.gameData.illustration.awardInfo) ~= nil then
skynet.server.illustration:AsycPointReward(self)
end
end
--修复旧账号扭蛋图鉴功能bug
if not player.gameData.illustration.fixGashapon then
skynet.server.illustration:FixGashaponData(self)
end
--兼容之前的功能防止exp 小于 0
if self.gameData.exp < 0 then
self.gameData.exp = 0
end
--修复扭蛋图鉴红点问题
--if not player:GetSwitch( dataType.SwitchType_IllustrationRedDot ) then
skynet.server.illustration:FixGashaponRedDot(self)
--player:SetSwitch( dataType.SwitchType_IllustrationRedDot , true )
--end
--修复兑换码扩容游标问题
if not player:GetSwitch( dataType.SwitchType_RedeemCursor ) then
skynet.server.redeem:FixRedeemCursor(self)
player:SetSwitch( dataType.SwitchType_RedeemCursor , true )
end
--修复125126任务 由于先增加了等级到80级后有的成就任务导致一些玩家80级了就无法再解锁该任务。
skynet.server.achieveTask:RepairTaskType125And126( self )
--125号流泉枫植物图鉴是后面加的玩家可能存在该植物如果有就点亮一下图鉴
if not player:GetSwitch( dataType.SwitchType_IsCheck125PlantIllustration ) then
local plantId = 125 --流泉枫植物ID
local plantCount = skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_Plant , plantId )
if plantCount > 0 then
--如果存在该植物,就点亮一下图鉴
local isAchieve,illustrationId = skynet.server.illustration:IsNewAchieve( player , skynet.server.illustration.IllustrationType_Plant )
if isAchieve then
--有点亮,就加个红点
local msgId = 18
skynet.server.msgTips:Reset( player, msgId )
skynet.server.msgTips:Add( player , msgId )
end
end
player:SetSwitch( dataType.SwitchType_IsCheck125PlantIllustration , true )
end
--修复1.5版本310~368的商店ID
if not self:GetSwitch( dataType.SwitchType_Repair310To368StoreId ) then
if self.gameData.level >= 6 then
local storePackInfo = self.gameData.storePack.storePackInfo
for k , v in pairs( storePackInfo ) do
local storeId = v.storeId
if storeId and storeId >= 310 and storeId <= 368 then
storePackInfo[ k ] = nil
end
end
end
self:SetSwitch( dataType.SwitchType_Repair310To368StoreId , true )
end
--124号舒享喵浴套装图鉴是后面加的玩家可能存在该植物如果有就点亮一下图鉴
if not player:GetSwitch( dataType.SwitchType_IsCheck124PetIllustration ) then
local clothesId1 = 85 --秋浴猫束带ID
local clothesId2 = 86 --泡泡浴花ID
local clothesId3 = 87 --猫猫浴袍ID
local clothesCount1 = skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_PetClothes , clothesId1 )
local clothesCount2 = skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_PetClothes , clothesId2 )
local clothesCount3 = skynet.server.bag:GetGoodsCount( player , dataType.GoodsType_PetClothes , clothesId3 )
if clothesCount1 > 0 or clothesCount2 > 0 or clothesCount3 > 0 then
--如果存在该植物,就点亮一下图鉴
local isAchieve,illustrationId = skynet.server.
illustration:IsNewAchieve( player , skynet.server.illustration.IllustrationType_PetClothes )
if isAchieve then
--有点亮,就加个红点
local msgId = 118
skynet.server.msgTips:Reset( player, msgId )
skynet.server.msgTips:Add( player , msgId )
end
end
player:SetSwitch( dataType.SwitchType_IsCheck124PetIllustration , true )
end
end
--测试账号
function Player:InitTestAccount( isFirstInit )
--[[
testWeekA1 ~ testWeekA50 充值金额为30元、上周累积游戏时长400分钟、投稿交互次数40次
testWeekB1 ~ testWeekB50 充值金额为30元、上周累积游戏时长400分钟
testWeekC1 ~ testWeekC50 充值金额为30元、投稿交互次数40次
testWeekD1 ~ testWeekD50 上周累积游戏时长400分钟、投稿交互次数40次
testWeekE1 ~ testWeekE50 充值金额为30元
testWeekF1 ~ testWeekF50 上周累积游戏时长400分钟
testWeekG1 ~ testWeekG50 投稿交互次数40次
testWeekH1 ~ testWeekH50 都是0
]]
local account = self.basicInfo.accountName
account = string.lower(account)
local partnerId = self.gameData.partner.id
local isTest = false
if string.find( account , "testweeka") then
--充值金额为30元、上周累积游戏时长400分钟、投稿交互次数40次
skynet.server.personal:SetDetail( partnerId , "rechargeAmount" , 30 , "lastWeekGameTime" , 400 * 60 , "decoWeekOpenShowCount" , 40 )
isTest = true
elseif string.find( account , "testweekb") then
--充值金额为30元、上周累积游戏时长400分钟
skynet.server.personal:SetDetail( partnerId , "rechargeAmount" , 30 , "lastWeekGameTime" , 400 * 60)
isTest = true
elseif string.find( account , "testweekc") then
--充值金额为30元、投稿交互次数40次
skynet.server.personal:SetDetail( partnerId , "rechargeAmount" , 30 , "decoWeekOpenShowCount" , 40 )
isTest = true
elseif string.find( account , "testweekd") then
--上周累积游戏时长400分钟、投稿交互次数40次
skynet.server.personal:SetDetail( partnerId , "lastWeekGameTime" , 400 * 60 , "decoWeekOpenShowCount" , 40 )
isTest = true
elseif string.find( account , "testweeke") then
--充值金额为30元
skynet.server.personal:SetDetail( partnerId , "rechargeAmount" , 30 )
isTest = true
elseif string.find( account , "testweekf") then
--上周累积游戏时长400分钟
skynet.server.personal:SetDetail( partnerId , "lastWeekGameTime" , 400 * 60 )
isTest = true
elseif string.find( account , "testweekg") then
--投稿交互次数40次
skynet.server.personal:SetDetail( partnerId , "decoWeekOpenShowCount" , 40 )
isTest = true
elseif string.find( account , "testweekh") then
--都是0
skynet.server.personal:SetDetail( partnerId , "rechargeAmount" , 0 , "lastWeekGameTime" , 0 , "decoWeekOpenShowCount" , 0 )
isTest = true
end
--测试号直接升级
if isTest and isFirstInit then
for i = 1, 20, 1 do
self:AddExpCount( 10000 , true , true )
end
end
end
--初始化没有的Redis数据
function Player:InitNoRedisData( player , curDetail )
local myPartnerId = player.gameData.partner.id
if not curDetail.rechargeAmount then
--V3版周赛需要的兼容数据
skynet.server.personal:SetDetail( myPartnerId ,
"rechargeAmount", player.gameData.storePack.rechargeAmount ,
"lastWeekGameTime" , 0 ,
"decoWeekOpenShowCount" , 0)
end
--人物新增服饰
if not curDetail.clothesData9 then
skynet.server.personal:SetDetail( myPartnerId ,
"clothesData9", 0 ,
"clothesData10" , 0)
end
end
--检测特殊字符
function Player:CheckSpecialChar( player )
function Do()
local nickName = player.gameData.nickName --玩家昵称
if skynet.server.common:IsExistSpecialChar( nickName ) then
player.gameData.nickName = "未命名"
end
--检测昵称是否有特殊字符
for k1, v1 in pairs( player.gameData.pet ) do
if skynet.server.common:IsExistSpecialChar( v1.nickName ) then
v1.nickName = "未命名"
end
end
--检测方案名称是否有特殊字符
for k1, v1 in pairs( player.gameData.house ) do
for k2, v2 in pairs( v1.scheme ) do
if skynet.server.common:IsExistSpecialChar( v2.name ) then
v2.name = "未命名"
end
end
end
return true
end
local isDo,callData = pcall( Do )
if not isDo then
log.error("Player:CheckSpecialChar 内部错误",callData)
end
end
--初始化
function Player:Init( c2sData )
local addr = c2sData.addr
local platform = c2sData.data.platform
--切割出对应的渠道
local channel = c2sData.data.channel
if channel then
local result = skynet.server.common:SplitByNumber(channel)
channel = result[#result]
if self.basicInfo.channel == nil or self.basicInfo.channel == "" then
self.basicInfo.channel = channel
end
end
local curHardwareCode = tostring(c2sData.data.hardwareCode)
local nowTime = skynet.GetTime()
if self.basicInfo.gameCgi == nil or self.basicInfo.gameCgi == "" then
self.basicInfo.gameCgi = c2sData.data.gameCgi
end
--if self.basicInfo.system == nil or self.basicInfo.system == "" then
self.basicInfo.system = c2sData.data.system
--end
self.basicInfo.appVersion = c2sData.data.version
self:InitNoData( self )
--检测玩家是否有特殊字符
self:CheckSpecialChar( self )
--所有一级需要解锁的都放这里
if 1 == self.gameData.level then
--解锁家具
if not self:IsUnlockSystem( dataType.UnlockSystem_Furniture ) then
self:AddUnlockSystem( dataType.UnlockSystem_Furniture )
end
--礼物
if not self:IsUnlockSystem( dataType.UnlockSystem_Gift ) then
self:AddUnlockSystem( dataType.UnlockSystem_Gift )
end
--挂机
if not self:IsUnlockSystem( dataType.UnlockSystem_Hang ) then
self:AddUnlockSystem( dataType.UnlockSystem_Hang )
end
--等级任务解锁
if not self:IsUnlockSystem( dataType.UnlockSystem_LevelTask ) then
self:AddUnlockSystem( dataType.UnlockSystem_LevelTask )
--解锁时添加对应红点
skynet.server.msgTips:Add(self , 93)
end
end
--初始化每个功能的登陆数据
for key, value in pairs(skynet.server) do
if not string.find(key, "httpSocket") and not string.find(key, "tcpSocket") and not string.find(key, "webSocket") and
not string.find(key, "mongo") and not string.find(key, "redis") and value["LoginInitData"] then
function Do()
value:LoginInitData( self )
return true
end
local isSuc,err = pcall(Do)
if not isSuc then
local account = self.basicInfo.accountName
log.info("登陆功能模块有报错", account , key , err)
end
end
end
--活动管理在最后执行
skynet.server.activityManage:LoginChangeData(self)
skynet.server.activity:ActivityExpiredSendMail(self)
skynet.server.store:SendIconPackToUser(self)
--修正下成就任务
skynet.server.achieveTask:RepairTaskType43(self)
self:InitShop() --初始化商店
skynet.server.playerRecord:Add( self.userId , dataType.RecordType_1 , 0 , serverId , platform , skynet.server.common:GetStrTime(nowTime) , addr , curHardwareCode , c2sData.data.version)
if self:IsNewUser() then
self:InitPlayerData() --新用户初始化
else
--对personal的detail进行转换
skynet.server.migrateData:DetailData( self.gameData.partner.id )
end
--新的一天
if not skynet.server.common:IsSameDay(self.basicInfo.lastLoginTime , nowTime ) then
self:ResetTodayData()
end
--发送玩家月卡信息 需要在新的一天下面再进行发送
skynet.server.store:SendMonthCardInfoToUser(self)
--新的一周
if skynet.server.common:IsNewWeek(self.basicInfo.lastLoginTime) then
self:ResetWeekData()
end
--新的一月
if skynet.server.common:IsNewMonth(self.basicInfo.lastLoginTime) then
self:ResetMonthData()
end
--发送豪华月卡信息
skynet.server.luxuryCard:SendLuxuryCardInfoToUser(self)
local isCompensate = self.basicInfo.isCompensate
local curLevel = self.gameData.level
local inviteCount = self.gameData.inviteCount
if inviteCount and curLevel >= 3 and inviteCount > 1 and false == isCompensate then
self.basicInfo.isCompensate = true
local award = {}
if 2 == inviteCount then
table.insert( award , { type = dataType.GoodsType_Furniture , id = 732 , count = 1 })
table.insert( award , { type = dataType.GoodsType_Furniture , id = 720 , count = 1 })
elseif inviteCount >= 3 then
table.insert( award , { type = dataType.GoodsType_Furniture , id = 732 , count = 1 })
table.insert( award , { type = dataType.GoodsType_Furniture , id = 720 , count = 1 })
table.insert( award , { type = dataType.GoodsType_Clothes , id = 222 , count = 1 })
table.insert( award , { type = dataType.GoodsType_Clothes , id = 223 , count = 1 })
table.insert( award , { type = dataType.GoodsType_Clothes , id = 224 , count = 1 })
end
local title = "说好的官网邀请奖励来咯~"
local content = "亲爱的小蜗:\
非常感谢你对蜗居一直以来的关注与支持!因为你的盛情邀请,悠悠镇迎来了越来越多的小蜗,小镇变得更热闹啦!为表感谢,随信献上邀请奖励一份,记得及时领取哦~\
如在游戏过程中遇到任何问题或想要提出游戏建议,欢迎在游戏左上角头像处点击小齿轮中的【联系客服】提交你的问题哦!"
skynet.server.mail:AddNewMail( self , skynet.server.mail.MailType_Award , title , content , award)
end
--self:InnerData( self ) cp需要关闭
--self:InitTestAccount( true )
self.basicInfo.lastGameTime = nowTime
self.basicInfo.lastLoginTime = nowTime
self.basicInfo.appVersion = c2sData.data.version
end
--赠送默认家具到房间
function Player:InitPlayerData()
--设置界面关注有礼
skynet.server.msgTips:Add( self , 20 )
skynet.server.msgTips:Add( self , 21 )
skynet.server.msgTips:Add( self , 22 )
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( self , "SValue")
self.gameData.coin = cfgSValue.initCoin
self.gameData.clovers = cfgSValue.initMapCoin
--self.gameData.coin = 10000
--self.gameData.clovers = 10000
self.gameData.volute = cfgSValue.initVoluteCoin
self.gameData.level = 1
self.gameData.exp = 0
self.gameData.bag = {}
self.gameData.bagCount = {}
self.gameData.used.logisticsInfo = {}
--存在装修商店数据就处理一下
local shopType = dataType.ShopType_Decorate
if self.gameData.shop[ shopType ] then
self.gameData.shop[ shopType ].door = {}
self.gameData.shop[ shopType ].nextRefreshTime = 0
self.gameData.shop[ shopType ].firstRefresh = true
skynet.server.decorateShop:RefreshShop( self , shopType )
end
--赠送一个免费的物流
table.insert( self.gameData.used.logisticsInfo , { goodsId = 53 , npcNameId = 2 , copyId = 2 , goodsStatus = skynet.server.used.GoodsStatus_AlreadyReach , reachTime = 0 , deliverTime = 0 } )
skynet.server.bag:AddGoods( self , dataType.GoodsType_Furniture , 1 , 1)
skynet.server.bag:AddGoods( self , dataType.GoodsType_Furniture , 10 , 1)
skynet.server.bag:AddGoods( self , dataType.GoodsType_Decorate , 262 , 1)
--赠送默认衣服
local cfgDefalutClothes = cfgSValue.DefalutClothes
for k, v in pairs( cfgDefalutClothes ) do
skynet.server.bag:AddGoods( self , dataType.GoodsType_Clothes , v , 1)
end
--赠送房间
local houseId = 4
self.gameData.curHouseID = houseId
skynet.server.house:Add( self , houseId, {} , false )
--获取当前房间当前方案
--local schemeInfo = skynet.server.house:GetCurScheme( self )
--schemeInfo.decorate = skynet.server.house:InitDecorate( self , houseId )
--个人和宠物的装扮
skynet.server.personal:InitData( self )
self.gameData.design.basicFreeTime = skynet.GetTime()
self.gameData.design.advancedFreeTime = skynet.GetTime()
self.basicInfo.isNewPlayer = false
end
--初始化商店
function Player:InitShop()
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( self , "SValue")
for k, v in pairs( self.gameData.unlockSystem ) do
if dataType.UnlockSystem_Furniture == v then --家具和摆件,装修,套间
--刷新通用商店
for shopType = dataType.ShopType_Furniture, dataType.ShopType_Cinnabar, 1 do
if not self.gameData.shop[ shopType ] then
self.gameData.shop[ shopType ] = {}
self.gameData.shop[ shopType ].type = shopType
self.gameData.shop[ shopType ].isBuySpecialGoods = false --当前商店是否购买了特殊物品
self.gameData.shop[ shopType ].specialGoods = {}
self.gameData.shop[ shopType ].generalGoods = {}
self.gameData.shop[ shopType ].nextRefreshTime = 0
self.gameData.shop[ shopType ].consumeCoin = 0 --在这里消息的金币
self.gameData.shop[ shopType ].historySpecialGoods = {} --历史刷出来的特殊家具
self.gameData.shop[ shopType ].historyGeneralGoods = {} --历史刷出来的普通家具
skynet.server.generalShop:RefreshShop( self , shopType )
else
--时间超过了,刷新新的一批
if skynet.GetTime() >= self.gameData.shop[ shopType ].nextRefreshTime then
skynet.server.generalShop:RefreshShop( self , shopType )
end
end
end
--装修间
local shopType = dataType.ShopType_Decorate
if not self.gameData.shop[ shopType ] then
self.gameData.shop[ shopType ] = {}
self.gameData.shop[ shopType ].type = shopType
self.gameData.shop[ shopType ].wallPaper = {}
self.gameData.shop[ shopType ].floor = {}
self.gameData.shop[ shopType ].door = {}
self.gameData.shop[ shopType ].bar = {}
self.gameData.shop[ shopType ].stair = {}
self.gameData.shop[ shopType ].handrail = {}
self.gameData.shop[ shopType ].nextRefreshTime = 0
self.gameData.shop[ shopType ].firstRefresh = true
self.gameData.shop[ shopType ].unlockDecorateType = {} --解锁的装修类型
skynet.server.decorateShop:AddUnlockType( self , dataType.DecorateType_WallPaper)
skynet.server.decorateShop:AddUnlockType( self , dataType.DecorateType_Floor)
skynet.server.decorateShop:RefreshShop( self , shopType )
else
--时间超过了,刷新新的一批
if skynet.GetTime() >= self.gameData.shop[ shopType ].nextRefreshTime then
skynet.server.decorateShop:RefreshShop( self , shopType )
end
end
elseif dataType.UnlockSystem_Used == v then --闲菜
skynet.server.used:CheckRefreshGoods( self )
elseif dataType.UnlockSystem_Clothing == v then --服装
local shopType = dataType.ShopType_Clothes
if not self.gameData.shop[ shopType ] then
self.gameData.shop[ shopType ] = {}
self.gameData.shop[ shopType ].type = shopType
self.gameData.shop[ shopType ].headWear = {} --头饰
self.gameData.shop[ shopType ].clothes = {} --衣服
self.gameData.shop[ shopType ].trousers = {} --裤子
self.gameData.shop[ shopType ].shoes = {} --鞋子
self.gameData.shop[ shopType ].buyGoods = {}
self.gameData.shop[ shopType ].nextRefreshTime = 0
self.gameData.shop[ shopType ].historyGoods = {}
for i = 1, dataType.ClothesType_Max, 1 do
self.gameData.shop[ shopType ].historyGoods[ i ] = {}
end
skynet.server.clothesShop:RefreshShop( self , shopType )
else
--时间超过了,刷新新的一批
if skynet.GetTime() >= self.gameData.shop[ shopType ].nextRefreshTime then
skynet.server.clothesShop:RefreshShop( self , shopType )
end
end
elseif dataType.UnlockSystem_Plant == v then
local shopType = dataType.ShopType_Seed --种子商店
if not self.gameData.shop[ shopType ] then
self.gameData.shop[ shopType ] = {}
self.gameData.shop[ shopType ].type = shopType
self.gameData.shop[ shopType ].isBuySpecialGoods = false --当前商店是否购买了特殊物品
self.gameData.shop[ shopType ].specialGoods = {}
self.gameData.shop[ shopType ].generalGoods = {}
self.gameData.shop[ shopType ].nextRefreshTime = 0
self.gameData.shop[ shopType ].isFirstRefresh = true
self.gameData.shop[ shopType ].consumeCoin = 0 --在这里消息的金币
skynet.server.generalShop:RefreshShop( self , shopType )
else
--时间超过了,刷新新的一批
if skynet.GetTime() >= self.gameData.shop[ shopType ].nextRefreshTime then
skynet.server.generalShop:RefreshShop( self , shopType )
end
end
shopType = dataType.ShopType_Plant
if not self.gameData.shop[ shopType ] then
self.gameData.shop[ shopType ] = {}
self.gameData.shop[ shopType ].type = shopType
--初始化货架数量
self.gameData.shop[ shopType ].shopShelf = {} --货架
for i = 1, skynet.server.plantShop.MaxShelfCount , 1 do
self.gameData.shop[ shopType ].shopShelf[ i ] = { shelfId = i , goodsId = 0 , isSell = false , sellTime = 0 }
end
self.gameData.shop[ shopType ].sellCount = 0
end
elseif dataType.UnlockSystem_Map == v then
elseif dataType.UnlockSystem_FlowerShop == v then --花店解锁
local shopType = dataType.ShopType_Flower --花店
if not self.gameData.shop[ shopType ] then
self.gameData.shop[ shopType ] = {}
self.gameData.shop[ shopType ].type = shopType
self.gameData.shop[ shopType ].bagSeedId = 0 --福袋里刷到的种子
self.gameData.shop[ shopType ].furnitureId =0 --鲜花展示区刷到的家具
self.gameData.shop[ shopType ].recycleId = 0 --高价回收ID, 所有的植物都可以被随到
self.gameData.shop[ shopType ].shelfSeeds = {} --货架上的3个种子
self.gameData.shop[ shopType ].shelfFlowerpot = {} --货架上的2个花盆
self.gameData.shop[ shopType ].shelfFurniture = {} --货架上的2个家具
self.gameData.shop[ shopType ].nextRefreshTime = 0
self.gameData.shop[ shopType ].consumeCoin = 0 --在这里消息的金币
skynet.server.flowerShop:DailyRefresh( self )
end
elseif dataType.UnlockSystem_CoffeeShop == v then --咖啡店解锁
local shopType = dataType.ShopType_Coffee --咖啡店
if not self.gameData.shop[ shopType ] then
self.gameData.shop[ shopType ] = {}
self.gameData.shop[ shopType ].supplierBoxes = {} --咖啡豆,糖,奶的供货盒子
self.gameData.shop[ shopType ].grids = {} --只显示上面有东西的咖啡格子
self.gameData.shop[ shopType ].currency = {} --最高级咖啡豆,糖奶的数量
self.gameData.shop[ shopType ].coffees = {} --已经解锁的咖啡ID
self.gameData.shop[ shopType ].rewards = {} --奖励
self.gameData.shop[ shopType ].mergeCount = 0 --合成次数
self.gameData.shop[ shopType ].mergeMaxLevel = {0,0,0} --咖啡豆,糖,奶当前合成最高等级
self.gameData.shop[ shopType ].noNewCoffeeCount = 0 --未抽到新咖啡的数量
local cfgCoffeeMakingPara = cfgSValue.coffeeMakingPara
local replenishCount = cfgCoffeeMakingPara[1]
--激活了豪华月卡,数量增加
if skynet.server.luxuryCard:IsActivate( self ) then
replenishCount = replenishCount * cfgSValue.luxuryCardCoffeeClickModulus
end
--初始化领取材料
table.insert( self.gameData.shop[ shopType ].supplierBoxes , { type = dataType.CoffeeShopGoodsType_CoffeeBean , count = replenishCount , nextRefreshTime = 0 , adTimes = 0} )
table.insert( self.gameData.shop[ shopType ].supplierBoxes , { type = dataType.CoffeeShopGoodsType_Sugar , count = replenishCount , nextRefreshTime = 0 , adTimes = 0} )
table.insert( self.gameData.shop[ shopType ].supplierBoxes , { type = dataType.CoffeeShopGoodsType_Milk , count = replenishCount , nextRefreshTime = 0 , adTimes = 0} )
--初始化格子
for i = 1, 30, 1 do
table.insert( self.gameData.shop[ shopType ].grids , { index = i , type = dataType.CoffeeShopGoodsType_Empty , level = 0 } )
end
--初始化3种货币
for i = 1, 3, 1 do
table.insert( self.gameData.shop[ shopType ].currency , 1 )
end
local cfgIllustationsReward = cfgSValue.coffeeIllustationReward
local idStart = 1
for k, v in pairs( cfgIllustationsReward ) do
local reward = skynet.server.common:Split( v , "_" )
table.insert( self.gameData.shop[ shopType ].rewards , { id = idStart, status = dataType.Status_NoGain })
idStart = idStart + 1
end
skynet.server.coffeeShop:CheckMsgTips( self )
end
elseif dataType.UnlockSystem_StyleRoom == v then --造型间解锁
local shopType = dataType.ShopType_Style --造型间
if not self.gameData.shop[ shopType ] then
self.gameData.shop[ shopType ] = {}
local curShop = self.gameData.shop[ shopType ]
curShop.type = shopType
curShop.grids = skynet.server.styleShop:GenerateGrid( self ) --格子信息
curShop.energy = {} --能量数值
curShop.energy.energy = skynet.server.styleShop:GetMaxRestoreEnergy( self )
curShop.energy.nextRefillTime = 0
curShop.money ={} --货币资源
curShop.money.resource1 = 0 --卷发棒
curShop.money.resource2 = 0 --粉底刷
curShop.money.resource3 = 0 --梳子
curShop.curStyleId = 1 --当前设计的ID
curShop.gainRewards = {} --领取的造型奖励,其实就是造型id
curShop.attemptCount = 0 --设计次数
curShop.randHistoryList = {} --随机历史列表
skynet.server.msgTips:Add( self , 74)
end
elseif dataType.UnlockSystem_FishShop == v then -- 判断该玩家渔店是否解锁
local shopType = dataType.ShopType_Fish -- 渔店
if not self.gameData.shop[ shopType ] then
skynet.server.fishShop:InitData(self,shopType)
end
elseif dataType.UnlockSystem_CuisineShop == v then -- 判断该玩家料理店是否解锁
local shopType = dataType.ShopType_Cuisine -- 料理店
if not self.gameData.shop[ shopType ] then
skynet.server.cuisineShop:InitData(self,shopType)
end
elseif dataType.UnlockSystem_PetShop == v then -- 判断该玩家宠物店是否解锁
local shopType = dataType.ShopType_PetShop -- 宠物店
if not self.gameData.shop[ shopType ] then
skynet.server.petShop:InitData(self,shopType)
skynet.server.pet:Package( self , dataType.PetType_Cat ) --搬到晨曦小筑解锁猫咪
skynet.server.bag:AddGoods(self, dataType.GoodsType_PetSkin, 1, 1)
local cfgPetAnim = skynet.server.gameConfig:GetPlayerAllCfg(self, "PetAnim") -- 解锁宠物动作
for k, v in ipairs(cfgPetAnim) do
if 0 == v.getType then
skynet.server.bag:AddGoods(self, dataType.GoodsType_PetAction, v.id, 1)
end
end
end
--宠物衣服
shopType = dataType.ShopType_PetClothes
skynet.server.petClothesShop:InitData(self,shopType)
elseif dataType.UnlockSystem_HouseRent == v then -- 判断该玩家恋家置业是否解锁
local shopType = dataType.ShopType_GardenShop -- 青青园艺
if not self.gameData.shop[ shopType ] then
--self.gameData.shop[ shopType ] = {}
-- 青青园艺初始化
skynet.server.houseRent:InitData(self,shopType)
end
elseif dataType.UnlockSystem_ActivityLabyrinth == v then --迷宫活动解锁
local activityType = dataType.ActivityType_Labyrinth --迷宫
if not self.gameData.activity[ activityType ] then
--skynet.server.activityLabyrinth:InitData(self,activityType)
end
elseif dataType.UnlockSystem_ActivityCarnival == v then --嘉年华活动解锁
local activityType = dataType.ActivityType_Carnival --嘉年华
if not self.gameData.activity[ activityType ] then
skynet.server.activityCarnival:InitData(self,activityType)
end
elseif dataType.UnlockSystem_ActivityDreamLife == v then --若来活动解锁
local activityType = dataType.ActivityType_DreamLife --若来
if not self.gameData.activity[ activityType ] then
skynet.server.activityDreamLife:InitData(self,activityType)
end
elseif dataType.UnlockSystem_ActivityFlipCard == v then --翻翻乐解锁
local activityType = dataType.ActivityType_FlipCard --翻翻乐
if not self.gameData.activity[ activityType ] then
skynet.server.activityFlipCard:InitData(self,activityType)
end
elseif dataType.UnlockSystem_ActivityPuzzle == v then --拼图解锁
local activityType = dataType.ActivityType_Puzzle --拼图
if not self.gameData.activity[ activityType ] then
skynet.server.activityPuzzle:InitData(self,activityType)
end
elseif dataType.UnlockSystem_ActivitySavingPot == v then --存钱罐解锁
local activityType = dataType.ActivityType_SavingPot --存钱罐
if not self.gameData.activity[ activityType ] then
skynet.server.activitySavingPot:InitData(self,activityType)
end
elseif dataType.UnlockSystem_ActivityBindBox == v then --盲盒解锁
local activityType = dataType.ActivityType_BindBox --盲盒
if not self.gameData.activity[ activityType ] then
skynet.server.activityBindBox:InitData(self)
end
end
end
end
--新的一天
function Player:ResetTodayData()
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( self , "SValue")
--新的一天,清理今日数据
for k, v in pairs(self.gameData.todayGain) do
if "table" == type(v) then
self.gameData.todayGain[ k ] = {}
elseif "boolean" == type(v) then
self.gameData.todayGain[ k ] = false
else
self.gameData.todayGain[ k ] = 0
end
end
--通行证每日任务数据置0
for k, v in pairs( self.gameData.passCheck.tasks ) do
if skynet.server.passCheck.TaskType_Daily == v.type then
v.progress = 0
end
end
if self.gameData.level>=cfgSValue.storeUnlockLvl then
--商城每日礼包购买次数重置
for k ,v in pairs(self.gameData.storePack.storePackInfo) do
if v and v.packLimit ~=nil and v.packLimit[1]==1 then
v.buyTimes=0
end
end
--月卡相关数据修改 确保至少减去一天
local count = skynet.server.common:GetTimeGap(self.basicInfo.lastGameTime)
self.gameData.storePack.monthCard.day = self.gameData.storePack.monthCard.day - math.max(count,1)
if self.gameData.storePack.monthCard.buyStatus and self.gameData.storePack.monthCard.day >= 0 then
self.gameData.storePack.monthCard.getStatus = false
--添加相应红点
skynet.server.msgTips:AddNoNotice(self , 63)
elseif self.gameData.storePack.monthCard.buyStatus and self.gameData.storePack.monthCard.day < 0 then
--月卡过期
self.gameData.storePack.monthCard.day = -1
self.gameData.storePack.monthCard.buyStatus = false
self.gameData.storePack.monthCard.getStatus = true
--消除对应权益
skynet.server.store:MonthCardPower( self )
end
--商城每日拍屏礼包重置
for k ,v in pairs(self.gameData.storePack.popupPackInfo) do
if v.type == skynet.server.store.PopUpPack_Day and v.id ~= 61 and v.status ~= 0 then
v.status = 1
elseif v.id == 61 and not self.gameData.storePack.monthCard.buyStatus then
--月卡拍屏单独处理 没有购买才进行拍屏
v.status = 1
end
--在线玩家跨天时过期的拍屏礼包发送消息给客户端
if v.id ~= 61 and v.status ~= 0 then
local tmpEndTime = skynet.server.gameConfig:GetPlayerCurCfg( self , "StorePack" , v.id).endTime
if tmpEndTime and "" ~= tmpEndTime then
local endTime = skynet.server.common:GetTime( tmpEndTime )
if skynet.GetTime() > endTime then
local data = {}
data.popUpStoreInfo = {storeId = v.id , buyTimes = 0 , failureTime = 0 , redDot = false }
skynet.server.gameServer:SendMsgToUser( self.userId , "CMD_S2C_StoreIconPopUp" , data )
end
end
end
end
--豪华月卡过期检测
skynet.server.luxuryCard:CheckOutOfTime( skynet.GetTime() , self )
--发送豪华月卡信息
skynet.server.luxuryCard:SendLuxuryCardInfoToUser(self)
--发送普通月卡信息
skynet.server.store:SendMonthCardInfoToUser(self)
end
--友圈互动每天默认未互动
for k, v in pairs( self.gameData.friend ) do
v.isInteract = false
end
--每日第一次登录刷新常规签到和新人签到
skynet.server.signIn:InitData( self )
if next(self.gameData.playerLand.signInInfo) ~= nil then
skynet.server.playerLand:LoginChangeData( self )
end
--刷新每日奖励任务
skynet.server.dailyTask:Refresh( self )
skynet.server.msgTips:Reset(self , 75)
skynet.server.msgTips:Add(self , 75)
skynet.server.flowerShop:RefreshShop( self , dataType.ShopType_Flower )
--清空我与其它玩家的过期消息
local outOfTime = ( cfgSValue.friendChatSave ) * 3600 --好友聊天内容有效期
local myPlayerId = self.gameData.partner.id
--家园签到重置
local curDetail = skynet.server.personal:GetDetail( myPlayerId ) --获取身份信息
if curDetail and "" ~= curDetail.groupId then
skynet.server.personal:SetDetail( myPlayerId , "groupSignInType" , 0 )
skynet.server.groupRank:CheckRankStatus( self , curDetail.groupId ) --刷新下排行榜状态
end
if cfgSValue.communityUnlockLvl <= self.gameData.level then
-- 园艺铺子初始化
skynet.server.groupGardenShop:InitData(self)
end
--记录玩家每日登录时的等级
self.gameData.todayGain.level = self.gameData.level
--限时卡池的签到活动 每日刷新
if self.gameData.design.timeCardPoolInfo.id then
if self.gameData.design.timeCardPoolInfo.timeSignInCount < cfgSValue.raffleLimitRewardDays then
self.gameData.design.timeCardPoolInfo.timeSignInCount = self.gameData.design.timeCardPoolInfo.timeSignInCount + 1
for k , v in pairs(self.gameData.design.timeCardPoolInfo.timeSignIn) do
if v.day == self.gameData.design.timeCardPoolInfo.timeSignInCount and v.status == 0 then
--解锁对应限时卡池签到奖励 并添加相应红点
v.status = 1
skynet.server.msgTips:AddNoNotice(self , 69)
end
end
end
end
--迷宫活动 每日增加指南针
if self.gameData.activity[ dataType.ActivityType_Labyrinth ] and next(self.gameData.activity[ dataType.ActivityType_Labyrinth ]) ~= nil then
if self.gameData.activity[ dataType.ActivityType_Labyrinth ].compassCount < 2 then
--将指南针的数量补充至2
self.gameData.activity[ dataType.ActivityType_Labyrinth ].compassCount = 2
end
end
--签到活动
if self.gameData.activity[ dataType.ActivityType_SignActivity ] and next(self.gameData.activity[ dataType.ActivityType_SignActivity ]) ~= nil then
skynet.server.activitySign:LoginInitData( self )
end
-- 嘉年华活动
if self.gameData.activity[ dataType.ActivityType_Carnival ] and next(self.gameData.activity[ dataType.ActivityType_Carnival ]) ~= nil then
skynet.server.activityCarnival:LoginInitData( self )
end
--每日初始若来任务
if self.gameData.activity[ dataType.ActivityType_DreamLife ] and next(self.gameData.activity[ dataType.ActivityType_DreamLife ]) ~= nil then
skynet.server.activityDreamLife:InitTask( self )
end
--周赛投票券发放
if self.gameData.activity[ dataType.ActivityType_DecoWeek ] and next(self.gameData.activity[ dataType.ActivityType_DecoWeek ]) ~= nil then
skynet.server.activityDecoWeek:GetFreeVote( self )
end
--存钱罐
if self:IsUnlockSystem( dataType.UnlockSystem_ActivitySavingPot ) then
skynet.server.activitySavingPot:LoginInitData(self)--需要替换
end
--盲盒
if self:IsUnlockSystem( dataType.UnlockSystem_ActivityBindBox ) then
skynet.server.activityBindBox:ResetDailyData(self)
end
local unlockCondition = skynet.server.map:GetUnlockCondition( self , 7 )
local petStore = skynet.server.gameConfig:GetPlayerAllCfg(player, "PetStore")
-- 宠物商店每日礼包购买次数重置
if self.gameData.level >= unlockCondition[2] then
for k ,v in pairs(self.gameData.shop[dataType.ShopType_PetShop].petShopGoodInfo ) do
if next(petStore[v.id].packLimit) ~= nil and petStore[v.id].packLimit[1] == 1 then
v.packLimit = petStore[v.id].packLimit
v.buyTimes = 0
skynet.server.msgTips:Add(self, 84)
end
end
end
log.debug("玩家清理今日数据" , self.userId)
end
--新的一周
function Player:ResetWeekData()
--商城每周礼包购买次数重置
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( self , "SValue")
if self.gameData.level >= cfgSValue.storeUnlockLvl then
for k ,v in pairs(self.gameData.storePack.storePackInfo) do
if v and v.packLimit ~= nil and v.packLimit[1] == 2 then
v.buyTimes=0
end
end
end
local unlockCondition = skynet.server.map:GetUnlockCondition( self , 7 )
local petStore = skynet.server.gameConfig:GetPlayerAllCfg(player, "PetStore")
-- 宠物商店每周礼包购买次数重置
if self.gameData.level >= unlockCondition[2] then
for k ,v in pairs(self.gameData.shop[dataType.ShopType_PetShop].petShopGoodInfo ) do
if next(petStore[v.id].packLimit) ~= nil and petStore[v.id].packLimit[1] == 2 then
v.packLimit[1] = petStore[v.id].packLimit[1]
v.buyTimes = 0
skynet.server.msgTips:Add(self, 84)
end
end
end
end
--新的一月
function Player:ResetMonthData()
--新的一天,清理今日数据
for k, v in pairs(self.gameData.monthGain) do
if "table" == type(v) then
self.gameData.monthGain[ k ] = {}
elseif "boolean" == type(v) then
self.gameData.monthGain[ k ] = false
else
self.gameData.monthGain[ k ] = 0
end
end
--商城每月礼包购买次数重置
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( self , "SValue")
if self.gameData.level >= cfgSValue.storeUnlockLvl then
for k ,v in pairs(self.gameData.storePack.storePackInfo) do
if v and v.packLimit and v.packLimit[1] == 4 then
v.buyTimes = 0
end
end
end
--发送豪华月卡信息
skynet.server.luxuryCard:SendLuxuryCardInfoToUser(self)
end
--货币变化
function Player:MoneyChange( moneyType , count , eventId )
eventId = eventId or 0
local data = {}
data.money = {}
data.eventId = eventId
if dataType.MoneyType_No == moneyType then
elseif pb.enum("EnumGoodsType","Coin") == moneyType then
if self.gameData.coin + count < 0 then
log.warning("金币数量不足,无法扣除")
return false
end
self.gameData.coin = self.gameData.coin + count
self:AddTodayData("coin" , count)
data.money = { type = pb.enum("EnumGoodsType","Coin") , count = self.gameData.coin }
skynet.server.playerRecord:Add( self.userId , dataType.RecordType_50 , eventId , self.gameData.coin - count, count , self.gameData.coin )
if count < 0 then
skynet.server.achieveTask:Modify( self , 42 , math.abs(count))
skynet.server.taskListEvent:Modify( self , 42 , math.abs(count))
end
elseif pb.enum("EnumGoodsType","Clovers") == moneyType then
if self.gameData.clovers + count < 0 then
log.warning("三叶币数量不足,无法扣除")
return false
end
self.gameData.clovers = self.gameData.clovers + count
self:AddTodayData("clovers" , count)
data.money = { type = pb.enum("EnumGoodsType","Clovers") , count = self.gameData.clovers }
skynet.server.playerRecord:Add( self.userId , dataType.RecordType_51 , eventId , self.gameData.clovers - count, count , self.gameData.clovers )
elseif dataType.MoneyType_Volute == moneyType then
if self.gameData.volute + count < 0 then
log.warning("蜗壳数量不足,无法扣除")
return false
end
self.gameData.volute = self.gameData.volute + count
self:AddTodayData("volute" , count)
--存钱罐累计消费变化
skynet.server.activitySavingPot:ChangeVoluteCost( self , count )
data.money = { type = pb.enum("EnumGoodsType","VoluteCoin") , count = self.gameData.volute }
skynet.server.playerRecord:Add( self.userId , dataType.RecordType_52 , eventId , self.gameData.volute - count, count , self.gameData.volute )
elseif dataType.MoneyType_ContributeCoin == moneyType then
if self.gameData.contributeCoin + count < 0 then
log.warning("贡献币数量不足,无法扣除")
return false
end
self.gameData.contributeCoin = self.gameData.contributeCoin + count
self:AddTodayData("contributeCoin" , count)
data.money = { type = pb.enum("EnumGoodsType","ContributeCoin") , count = self.gameData.contributeCoin }
skynet.server.playerRecord:Add( self.userId , dataType.RecordType_53 , eventId , self.gameData.contributeCoin - count, count , self.gameData.contributeCoin )
elseif pb.enum("EnumGoodsType","Fragment") == moneyType then--灵感积分
if self.gameData.design.fragmentNum == nil then
self.gameData.design.fragmentNum = 0
end
if self.gameData.design.fragmentNum + count < 0 then
log.warning("灵感积分不足,无法扣除")
return false
end
self.gameData.design.fragmentNum = self.gameData.design.fragmentNum + count
self:AddTodayData("fragment" , count)
data.money = { type = pb.enum("EnumGoodsType","Fragment") , count = self.gameData.design.fragmentNum }
skynet.server.playerRecord:Add( self.userId , dataType.RecordType_54 , eventId , self.gameData.design.fragmentNum - count, count , self.gameData.design.fragmentNum )
if count < 0 then--任务
-- skynet.server.achieveTask:Modify( self , 42 , math.abs(count))
-- skynet.server.taskListEvent:Modify( self , 42 , math.abs(count))
end
else
log.warning("不存在该类型的货币")
return false
end
--log.info(string.format("玩家 %d 货币类型 %d 数量 %d" , self.userId , moneyType , count))
skynet.server.gameServer:SendMsgToUser( self.userId , "CMD_S2C_MoneyChange" , data )
return true
end
--货币变化 消息
function Player:MoneyChangeMsg()
--[[
local data = {}
data.coin = self.gameData.coin
data.clovers = self.gameData.clovers
data.volute = self.gameData.volute
data.loveCoin = self.gameData.loveCoin
data.praiseCoin = self.gameData.praiseCoin
skynet.server.gameServer:SendMsgToUser( self.userId , "CMD_S2C_MoneyChange" , data )
]]
end
--增加经验数量 isForce强制给经验不管是不是新人 isGM是否为GM命令
function Player:AddExpCount( count , isForce , isGm )
isForce = isForce or false
isGm = isGm or false
if not isForce and self.basicInfo.isNewPlayer then
return false
end
count = count or 0
if count <= 0 then
return
end
--超过80级就不增加经验
if self.gameData.level >= self.maxLevelLimt then
return true
end
if self.gameData.level < 8 and skynet.GetTime() - self.tmpData.lastUpgradeTime <= 1 and not isGm then
--由于多种加经验方式如果连续升级客户端会有问题所以1秒内只能加一次经验多的经验缓存起来下一次发放。仅限8级以下才会限制
self.tmpData.cacheExp = self.tmpData.cacheExp + count
return false
else
if self.tmpData.cacheExp > 0 then
--有缓存经验,发放给玩家
count = count + self.tmpData.cacheExp
self.tmpData.cacheExp = 0
end
end
self.gameData.exp = self.gameData.exp + count
self:AddTodayData("exp" , count)
skynet.server.playerRecord:Add( self.userId , dataType.RecordType_61 , 0 , self.gameData.exp - count, count , self.gameData.exp )
self:CheckUpgrade( isGm )
local data = {}
data.level = self.gameData.level
data.exp = self.gameData.exp
skynet.server.gameServer:SendMsgToUser( self.userId , "CMD_S2C_Upgrade" , data )
return true
end
--根据类型增加经验
function Player:AddExpForType( mainType , subType , count )
if self.basicInfo.isNewPlayer then
return false
end
--指定等级就不增加经验
if self.gameData.level >= self.maxLevelLimt then
return false
end
subType = subType or 0 --缺省参数默认为0
count = count or 1
local expValue = 0
local cfgAllExpNormal = skynet.server.gameConfig:GetPlayerAllCfg( self , "ExpNormal")
for k, v in pairs( cfgAllExpNormal ) do
if mainType == v.expIncrease and subType == v.subType then
expValue = v.expValue
end
end
--未找到相关的配置
if 0 == expValue then
return false
end
expValue = expValue * count
if skynet.GetTime() - self.tmpData.lastUpgradeTime <= 2 then
--由于多种加经验方式如果连续升级客户端会有问题所以2秒内只能加一次经验多的经验缓存起来下一次发放
self.tmpData.cacheExp = self.tmpData.cacheExp + expValue
return false
else
if self.tmpData.cacheExp > 0 then
--有缓存经验,发放给玩家
expValue = expValue + self.tmpData.cacheExp
self.tmpData.cacheExp = 0
end
end
self.gameData.exp = self.gameData.exp + expValue
self:AddTodayData("exp" , expValue)
skynet.server.playerRecord:Add( self.userId , dataType.RecordType_61 , 0 , self.gameData.exp - expValue, expValue , self.gameData.exp )
self:CheckUpgrade( false )
local data = {}
data.level = self.gameData.level
data.exp = self.gameData.exp
skynet.server.gameServer:SendMsgToUser( self.userId , "CMD_S2C_Upgrade" , data )
return true
end
--增加今日数据
function Player:AddTodayData( name ,count )
if self.gameData.todayGain[ name ] and count > 0 then
self.gameData.todayGain[ name ] = self.gameData.todayGain[ name ] + count
log.debug(string.format("玩家 %d 今日数据 %s 新增 %d", self.userId , name , count ))
end
end
--检查是否升级
function Player:CheckUpgrade( isGm )
local cfgLevel = skynet.server.gameConfig:GetPlayerCurCfg( self , "Level" , self.gameData.level )
if self.gameData.exp >= cfgLevel.requireExp then
--升级
self.tmpData.lastUpgradeTime = skynet.GetTime()
self.gameData.level = self.gameData.level + 1
self.gameData.upTime = skynet.GetTime()
self.gameData.exp = self.gameData.exp - cfgLevel.requireExp
if self.gameData.level > self.maxLevelLimt then
self.gameData.level = self.maxLevelLimt
end
skynet.server.personal:SetDetail( self.gameData.partner.id , "level" , self.gameData.level )
--用新等级再获取下奖励
cfgLevel = skynet.server.gameConfig:GetPlayerCurCfg( self , "Level" , self.gameData.level )
self:AddTodayData("Level" , 1)
log.debug(string.format("玩家 %d 升级 最新等级 %d 最新经验 %d", self.userId , self.gameData.level , self.gameData.exp))
skynet.server.playerRecord:Add( self.userId , dataType.RecordType_60 , 0 , self.gameData.level - 1, 1 , self.gameData.level )
skynet.server.playerRecord:Add( self.userId , dataType.RecordType_61 , 0 , self.gameData.exp - cfgLevel.requireExp, cfgLevel.requireExp , self.gameData.exp )
--升级奖励
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_83")
self:GiveReward( cfgLevel.reward , eventId)
--解锁系统
self:CheckUnlockSystem()
--初始化下商店信息
self:InitShop()
skynet.server.achieveTask:CheckNew( self )
skynet.server.npcTask:CheckNew( self )
skynet.server.passCheck:CheckNew( self )
skynet.server.map:CheckUnlcokLoc( self)
skynet.server.friend:CheckUnlockNpc( self )
skynet.server.friend:CheckNewMsg( self )
skynet.server.house:CheckNew( self )
skynet.server.pet:CheckNew( self )
self:CompensateOldIOS()
skynet.server.activityDecoWeek:UnlockSystemFunc( self )
--每次只升一级,如果升级后还大于就不再升
local cfgNewLevel = skynet.server.gameConfig:GetPlayerCurCfg( self , "Level" , self.gameData.level )
if self.gameData.exp >= cfgNewLevel.requireExp then
self.tmpData.cacheExp = self.gameData.exp - ( cfgNewLevel.requireExp - 10 )
self.gameData.exp = cfgNewLevel.requireExp - 10
end
--每次升级后刷新玩家可显示UI
local data = {}
data.activityInfos = skynet.server.activity:GetAllActivityInfo( self )
skynet.server.gameServer:SendMsgToUser( self.userId , "CMD_S2C_UpdateShowUI" , data )
else
return
end
end
--添加解锁系统
function Player:AddUnlockSystem( unlockType )
if not self:IsUnlockSystem( unlockType ) then
table.insert( self.gameData.unlockSystem , unlockType )
end
end
--检查是否解锁系统
function Player:CheckUnlockSystem()
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( self , "SValue")
local cfgActivity = skynet.server.gameConfig:GetPlayerAllCfg( self , "Activity")
local curLevel = self.gameData.level
if cfgSValue.SellAPPUnlockLvl == self.gameData.level then --闲菜
table.insert( self.gameData.unlockSystem , dataType.UnlockSystem_Used )
skynet.server.bag:AddGoods( self , dataType.GoodsType_Furniture , 197 , 1) --破箱子
end
if cfgSValue.ClothingAPPUnlockLvl == self.gameData.level then --服装
table.insert( self.gameData.unlockSystem , dataType.UnlockSystem_Clothing )
end
if cfgSValue.PlantAPPUnlockLvl == self.gameData.level then --植物
table.insert( self.gameData.unlockSystem , dataType.UnlockSystem_Plant )
end
if cfgSValue.MoveAPPUnlockLvl == self.gameData.level then --搬家
table.insert( self.gameData.unlockSystem , dataType.UnlockSystem_MoveHome )
end
if cfgSValue.ChatAPPUnlockLvl == self.gameData.level then --友圈
table.insert( self.gameData.unlockSystem , dataType.UnlockSystem_Friend )
end
if cfgSValue.storeUnlockLvl == self.gameData.level then --商城
table.insert( self.gameData.unlockSystem , dataType.UnlockSystem_Store )
--九级初始化商店
if next(self.gameData.storePack.storePackInfo)==nil then
skynet.server.store:InitData( self)
end
end
if cfgSValue.MapAPPUnlockLvl == self.gameData.level then --地图
table.insert( self.gameData.unlockSystem , dataType.UnlockSystem_Map )
end
local unlockCondition = skynet.server.map:GetUnlockCondition( self , 2 )
if unlockCondition and unlockCondition[ 2 ]== self.gameData.level then --花店
table.insert( self.gameData.unlockSystem , dataType.UnlockSystem_FlowerShop )
end
unlockCondition = skynet.server.map:GetUnlockCondition( self , 3 )
if unlockCondition and unlockCondition[ 2 ]== self.gameData.level then --咖啡店
table.insert( self.gameData.unlockSystem , dataType.UnlockSystem_CoffeeShop )
end
unlockCondition = skynet.server.map:GetUnlockCondition( self , 4 )
if unlockCondition and unlockCondition[ 2 ] == self.gameData.level then --造型间
table.insert( self.gameData.unlockSystem , dataType.UnlockSystem_StyleRoom )
end
unlockCondition = skynet.server.map:GetUnlockCondition( self , 5 ) --渔店
if unlockCondition and unlockCondition[ 2 ] == self.gameData.level then
table.insert( self.gameData.unlockSystem , dataType.UnlockSystem_FishShop )
end
unlockCondition = skynet.server.map:GetUnlockCondition( self , 6 ) --料理店
if unlockCondition and unlockCondition[ 2 ] == self.gameData.level then
table.insert( self.gameData.unlockSystem , dataType.UnlockSystem_CuisineShop )
end
unlockCondition = skynet.server.map:GetUnlockCondition( self , 7 ) --宠物店
if unlockCondition and unlockCondition[ 2 ] == self.gameData.level then
table.insert( self.gameData.unlockSystem , dataType.UnlockSystem_PetShop )
end
unlockCondition = skynet.server.map:GetUnlockCondition( self , 8 ) --恋家置业
if unlockCondition and unlockCondition[ 2 ] == self.gameData.level then
table.insert( self.gameData.unlockSystem , dataType.UnlockSystem_HouseRent )
end
if self.gameData.shop[dataType.ShopType_PetShop] then
local cfgPetSkin = skynet.server.gameConfig:GetPlayerAllCfg(self, "PetSkin") -- 解锁宠物皮肤
for k, v in ipairs(cfgPetSkin) do
if v.unlockLvl ~= 0 and v.unlockLvl ~= '' and self.gameData.level == v.unlockLvl then
skynet.server.bag:AddGoods(self, dataType.GoodsType_PetSkin, v.id, 1)
end
end
end
if cfgSValue.drawUnlockLvl == self.gameData.level then --设计间
table.insert( self.gameData.unlockSystem , dataType.UnlockSystem_DesignHouse )
--self:GiveReward( 292 )
--skynet.server.design:InitData( self ) --初始化相关数据
end
if cfgSValue.passCheckUnlockLvl == self.gameData.level then --通行证
self:AddUnlockSystem( dataType.UnlockSystem_PassCheck )
end
if cfgSValue.dailyTaskUnlockLvl == self.gameData.level then
self:AddUnlockSystem( dataType.UnlockSystem_DailyTask )
--刷新每日奖励任务
skynet.server.dailyTask:Refresh( self )
--解锁时添加对应红点
skynet.server.msgTips:Add(self , 90)
end
if cfgSValue.achTaskUnlockLvl == self.gameData.level then
self:AddUnlockSystem( dataType.UnlockSystem_AchieveTask )
--解锁时添加对应红点
skynet.server.msgTips:Add(self , 92)
end
if cfgSValue.npcTaskUnlockLvl == self.gameData.level then
self:AddUnlockSystem( dataType.UnlockSystem_NpcTask )
--解锁时添加对应红点
skynet.server.msgTips:Add(self , 91)
end
if cfgSValue.signInUnlockLvl == self.gameData.level then --常规签到
table.insert( self.gameData.unlockSystem , dataType.UnlockSystem_SignIn )
if next(self.gameData.signIn.signInInfo)==nil then
skynet.server.signIn:InitData(self)
end
end
if cfgSValue.playerLandUnlockLvl == self.gameData.level then --新人签到
--新人签到数据初始化
skynet.server.playerLand:InitData( self )
end
if cfgSValue.partnerUnlockLvl == self.gameData.level then
self:AddUnlockSystem( dataType.UnlockSystem_Partner )
--开启好友功能,好友可以进自己房间,所以这里将数据落下地,不然玩家可能获取不了房间数据
skynet.server.accountCenter:SavePlayerToMysql( self )
end
if cfgSValue.communityUnlockLvl == self.gameData.level then --家园
self:AddUnlockSystem( dataType.UnlockSystem_Group )
-- 园艺铺子初始化
skynet.server.groupGardenShop:InitData(self)
end
if cfgSValue.colorUnlockLvl == self.gameData.level then --巧手工坊
table.insert( self.gameData.unlockSystem , dataType.UnlockSystem_workshop )
skynet.server.dyeworkshop:InitData( self)
skynet.server.furnitureWorkShop:InitData( self)
end
if cfgSValue.schemeUnlockLvl == self.gameData.level then --装修方案
self:AddUnlockSystem( dataType.UnlockSystem_HouseScheme )
end
for k , v in pairs(cfgActivity) do
if dataType.ActivityType_Labyrinth == v.activityType and curLevel >= v.level then --活动迷宫
self:AddUnlockSystem( dataType.UnlockSystem_ActivityLabyrinth )
elseif dataType.ActivityType_DecoWeek == v.activityType and curLevel >= v.level then --装修周
self:AddUnlockSystem( dataType.UnlockSystem_ActivityDecoWeek )
elseif dataType.ActivityType_MatchStuff == v.activityType and curLevel >= v.level then
self:AddUnlockSystem( dataType.UnlockSystem_ActivityMatchStuff )
elseif dataType.ActivityType_NewPlayerRaffle == v.activityType and curLevel == v.level then
self:AddUnlockSystem( dataType.UnlockSystem_ActivityNewPlayerRaffle )
elseif dataType.ActivityType_SignPack == v.activityType and curLevel >= v.level then
self:AddUnlockSystem( dataType.UnlockSystem_ActivitySignPack )
elseif dataType.ActivityType_SeekTreasure == v.activityType and curLevel >= v.level then
self:AddUnlockSystem( dataType.UnlockSystem_ActivitySeekTreasure )
elseif dataType.ActivityType_ActivityLevelPack == v.activityType and curLevel >= v.level then
self:AddUnlockSystem( dataType.UnlockSystem_ActivityLevelPack )
elseif dataType.ActivityType_ActivityStagePack == v.activityType and curLevel >= v.level then
self:AddUnlockSystem( dataType.UnlockSystem_ActivityStagePack )
elseif dataType.ActivityType_DailyRiddle == v.activityType and curLevel >= v.level then
self:AddUnlockSystem( dataType.UnlockSystem_ActivityDailyRiddle )
elseif dataType.ActivityType_ActivityReplicaStore == v.activityType and curLevel >= v.level then
self:AddUnlockSystem( dataType.UnlockSystem_ActivityReplicaStore )
end
end
if cfgSValue.coupleHouseUnlockLvl == self.gameData.level then --双人空间解锁
self:AddUnlockSystem( dataType.UnlockSystem_DoubleSpace )
skynet.server.doubleSpace:InitData( self )
end
if cfgSValue.activityUnlockLvl == self.gameData.level then --活动管理面板解锁
skynet.server.activityManage:LoginChangeData( self , false)
end
for k , v in pairs(cfgActivity) do
if v.activityType == dataType.ActivityType_Carnival and v.level == self.gameData.level then --活动嘉年华
self:AddUnlockSystem( dataType.UnlockSystem_ActivityCarnival )
break
end
end
for k , v in pairs(cfgActivity) do
if v.activityType == dataType.ActivityType_DreamLife and v.level == self.gameData.level then --活动若来
self:AddUnlockSystem( dataType.UnlockSystem_ActivityDreamLife )
break
end
end
for k , v in pairs(cfgActivity) do
if v.activityType == dataType.ActivityType_FlipCard and v.level == self.gameData.level then --活动翻翻乐
self:AddUnlockSystem( dataType.UnlockSystem_ActivityFlipCard )
break
end
end
for k , v in pairs(cfgActivity) do
if v.activityType == dataType.ActivityType_Puzzle and v.level == self.gameData.level then --活动拼图
self:AddUnlockSystem( dataType.UnlockSystem_ActivityPuzzle )
break
end
end
for k , v in pairs(cfgActivity) do
if v.activityType == dataType.ActivityType_SavingPot and v.level == self.gameData.level then --存钱罐
self:AddUnlockSystem( dataType.UnlockSystem_ActivitySavingPot )
break
end
end
for k , v in pairs(cfgActivity) do
if v.activityType == dataType.ActivityType_BindBox and v.level == self.gameData.level then --盲盒
self:AddUnlockSystem( dataType.UnlockSystem_ActivityBindBox )
break
end
end
if cfgSValue.miniProgramSubscribeLvl == self.gameData.level then
--微信订阅
self:AddUnlockSystem( dataType.UnlockSystem_Subscription )
end
local newPlayerTriggerPack = cfgSValue.newPlayerTriggerPack
if newPlayerTriggerPack[ 2 ] == self.gameData.level then
local triggerId = skynet.server.store.TriggerPack_NewPlayerClothes
skynet.server.store:TriggerPack( self , triggerId )
end
end
--是否解锁系统
function Player:IsUnlockSystem( type )
for k, v in pairs( self.gameData.unlockSystem ) do
if type == v then
return true
end
end
return false
end
--玩家是否存在该商品
function Player:IsBuyGoods( goodsType , goodsId )
for k, v in pairs( self.gameData.bag ) do
if goodsType == v.type and goodsId == v.id then
return true
end
end
return false
end
--发奖励
function Player:GiveReward( rewardId , eventId , count )
if 0 == rewardId then
return
end
--记录要进行转换奖励的原物品信息
local conversionInfo = {}
--记录最终获得的物品信息
local finalRewardInfo = {}
count = count or 1
log.debug("开始发送奖励",rewardId , eventId ,count )
local cfgReward = skynet.server.gameConfig:GetPlayerCurCfg( self , "Reward" , rewardId )
if not cfgReward then
log.warning("未找到相关的奖励 ID",rewardId)
return
end
if cfgReward.coin > 0 then
self:MoneyChange( dataType.MoneyType_Coin , cfgReward.coin * count , eventId)
table.insert(finalRewardInfo,{goodsType = dataType.MoneyType_Coin , id = 0 , count = cfgReward.coin * count })
--log.info(string.format("玩家 %d 发放金币 %d" , self.userId,cfgReward.coin * count ))
end
if cfgReward.mapCoin > 0 then
self:MoneyChange( dataType.MoneyType_Map , cfgReward.mapCoin * count , eventId)
table.insert(finalRewardInfo,{goodsType = dataType.MoneyType_Map , id = 0 , count = cfgReward.mapCoin * count })
--log.info(string.format("玩家 %d 发放地图币 %d" , self.userId,cfgReward.mapCoin * count ))
end
if cfgReward.voluteCoin > 0 then
self:MoneyChange( dataType.MoneyType_Volute , cfgReward.voluteCoin * count , eventId)
table.insert(finalRewardInfo,{goodsType = dataType.MoneyType_Volute , id = 0 , count = cfgReward.voluteCoin * count })
--log.info(string.format("玩家 %d 发放蜗壳 %d" , self.userId,cfgReward.voluteCoin * count))
end
--场景物品
for k, v in pairs( cfgReward.sceneObject ) do
local arr = skynet.server.common:Split(v , "_")
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
if 1 == arr[1] then
skynet.server.bag:AddGoods( self , dataType.GoodsType_Furniture , arr[2] , count )
table.insert(finalRewardInfo,{goodsType = dataType.GoodsType_Furniture , id = arr[2] , count = count })
log.debug(string.format("玩家 %d 发放家具 %d" , self.userId, arr[2] ))
elseif 2 == arr[1] then
local give,replaceRewardId = self:RewardConversion(arr[2] , dataType.GoodsType_Decorate)
if give and replaceRewardId ~= rewardId then
local goodsInfo = skynet.server.bag:GetGoodsInfo(self , dataType.GoodsType_Decorate , arr[2])
if goodsInfo.gainTime then
table.insert(conversionInfo,{type = dataType.GoodsType_Decorate , id = arr[2] , count = count ,gainTime = goodsInfo.gainTime})
end
local _,replaceReward = self:GiveReward(replaceRewardId , eventId , count)
if replaceReward ~= nil and next(replaceReward) ~= nil then
for i, replaceInfo in pairs( replaceReward ) do
table.insert(finalRewardInfo,replaceInfo)
end
end
else
skynet.server.bag:AddGoods( self , dataType.GoodsType_Decorate , arr[2] , count )
table.insert(finalRewardInfo,{goodsType = dataType.GoodsType_Decorate , id = arr[2] , count = count })
log.debug(string.format("玩家 %d 发放装修 %d" , self.userId, arr[2] ))
end
elseif 3 == arr[1] then
skynet.server.bag:AddGoods( self , dataType.GoodsType_Garden , arr[2] , count )
table.insert(finalRewardInfo,{goodsType = dataType.GoodsType_Garden , id = arr[2] , count = count })
log.debug(string.format("玩家 %d 发放家园物品 %d" , self.userId, arr[2] ))
end
end
--服饰物品
for k, v in pairs( cfgReward.appearanceObject ) do
local arr = skynet.server.common:Split(v , "_")
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
if 1 == arr[1] then
local give,replaceRewardId = self:RewardConversion(arr[2] , dataType.GoodsType_Clothes)
if give and replaceRewardId ~= rewardId then
local goodsInfo = skynet.server.bag:GetGoodsInfo(self , dataType.GoodsType_Clothes , arr[2])
if goodsInfo.gainTime then
table.insert(conversionInfo,{type = dataType.GoodsType_Clothes , id = arr[2] , count = count ,gainTime = goodsInfo.gainTime})
end
local _,replaceReward = self:GiveReward(replaceRewardId , eventId , count)
if replaceReward ~= nil and next(replaceReward) ~= nil then
for i, replaceInfo in pairs( replaceReward ) do
table.insert(finalRewardInfo,replaceInfo)
end
end
else
skynet.server.bag:AddGoods( self , dataType.GoodsType_Clothes , arr[2] , count )
table.insert(finalRewardInfo,{goodsType = dataType.GoodsType_Clothes , id = arr[2] , count = count })
end
elseif 2 == arr[1] then
local give,replaceRewardId = self:RewardConversion(arr[2] , dataType.GoodsType_PetClothes)
if give and replaceRewardId ~= rewardId then
local goodsInfo = skynet.server.bag:GetGoodsInfo(self , dataType.GoodsType_PetClothes , arr[2])
if goodsInfo.gainTime then
table.insert(conversionInfo,{type = dataType.GoodsType_PetClothes , id = arr[2] , count = count ,gainTime = goodsInfo.gainTime})
end
local _,replaceReward = self:GiveReward(replaceRewardId , eventId , count)
if replaceReward ~= nil and next(replaceReward) ~= nil then
for i, replaceInfo in pairs( replaceReward ) do
table.insert(finalRewardInfo,replaceInfo)
end
end
else
skynet.server.bag:AddGoods( self , dataType.GoodsType_PetClothes , arr[2] , count )
table.insert(finalRewardInfo,{goodsType = dataType.GoodsType_PetClothes , id = arr[2] , count = count })
end
end
end
--套装物品
for k, v in pairs( cfgReward.suitObject ) do
local arr = skynet.server.common:Split(v , "_")
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
if 1 == arr[1] then
--家具
local cfgAllFurniture = skynet.server.gameConfig:GetPlayerAllCfg( self , "Furniture")
for k, v in pairs( cfgAllFurniture ) do
if arr[2] == v.suitType then
skynet.server.bag:AddGoods( self , dataType.GoodsType_Furniture , v.id , count )
table.insert(finalRewardInfo,{goodsType = dataType.GoodsType_Furniture , id = v.id , count = count })
end
end
--装修
local cfgAllDecoration = skynet.server.gameConfig:GetPlayerAllCfg( self , "Decoration")
for k, v in pairs( cfgAllDecoration ) do
if arr[2] == v.suitType then
local give,replaceRewardId = self:RewardConversion(v.id , dataType.GoodsType_Decorate)
if give and replaceRewardId ~= rewardId then
local goodsInfo = skynet.server.bag:GetGoodsInfo(self , dataType.GoodsType_Decorate , v.id)
if goodsInfo.gainTime then
table.insert(conversionInfo,{type = dataType.GoodsType_Decorate , id = v.id , count = count ,gainTime = goodsInfo.gainTime})
end
local _,replaceReward = self:GiveReward(replaceRewardId , eventId , count)
if replaceReward ~= nil and next(replaceReward) ~= nil then
for i, replaceInfo in pairs( replaceReward ) do
table.insert(finalRewardInfo,replaceInfo)
end
end
else
skynet.server.bag:AddGoods( self , dataType.GoodsType_Decorate , v.id , count )
table.insert(finalRewardInfo,{goodsType = dataType.GoodsType_Decorate , id = v.id , count = count })
log.debug(string.format("玩家 %d 发放装修 %d" , self.userId, v.id ))
end
end
end
log.debug(string.format("玩家 %d 发放家具套装 %d" , self.userId, arr[2] ))
elseif 2 == arr[1] then
local cfgClothesSuit = skynet.server.gameConfig:GetPlayerAllCfg( self , "ClothesSuit") --获取配置文件ClothesSuit中的数据
local cfgAllClothes = skynet.server.gameConfig:GetPlayerAllCfg( self , "Clothes") --人物
local cfgPetClothes = skynet.server.gameConfig:GetPlayerAllCfg( self , "PetClothes") --宠物
local type = nil
for k ,v in pairs(cfgClothesSuit) do
if v.id==arr[2] then
--获取该套装类型
type = v.type
end
end
if type == 1 then
for k, v in pairs( cfgAllClothes ) do
if arr[2] == v.suitId then
local give,replaceRewardId = self:RewardConversion(v.id , dataType.GoodsType_Clothes)
if give and replaceRewardId ~= rewardId then
local goodsInfo = skynet.server.bag:GetGoodsInfo(self , dataType.GoodsType_Clothes , v.id)
if goodsInfo.gainTime then
table.insert(conversionInfo,{type = dataType.GoodsType_Clothes , id = v.id , count = count ,gainTime = goodsInfo.gainTime})
end
local _,replaceReward = self:GiveReward(replaceRewardId , eventId , count)
if replaceReward ~= nil and next(replaceReward) ~= nil then
for i, replaceInfo in pairs( replaceReward ) do
table.insert(finalRewardInfo,replaceInfo)
end
end
else
skynet.server.bag:AddGoods( self , dataType.GoodsType_Clothes , v.id , count )
table.insert(finalRewardInfo,{goodsType = dataType.GoodsType_Clothes , id = v.id , count = count })
end
end
end
log.debug(string.format("玩家 %d 发放衣服套装 %d" , self.userId, arr[2] * count))
elseif type == 2 then
--获取动物服装对应的套装物品
for k ,v in pairs( cfgPetClothes ) do
if arr[2] == v.suitId then
local give,replaceRewardId = self:RewardConversion(v.id , dataType.GoodsType_PetClothes)
if give and replaceRewardId ~= rewardId then
local goodsInfo = skynet.server.bag:GetGoodsInfo(self , dataType.GoodsType_PetClothes , v.id)
if goodsInfo.gainTime then
table.insert(conversionInfo,{type = dataType.GoodsType_PetClothes , id = v.id , count = count ,gainTime = goodsInfo.gainTime})
end
local _,replaceReward = self:GiveReward(replaceRewardId , eventId , count)
if replaceReward ~= nil and next(replaceReward) ~= nil then
for i, replaceInfo in pairs( replaceReward ) do
table.insert(finalRewardInfo,replaceInfo)
end
end
else
skynet.server.bag:AddGoods( self , dataType.GoodsType_PetClothes , v.id , count )
table.insert(finalRewardInfo,{goodsType = dataType.GoodsType_PetClothes , id = v.id , count = count })
end
end
end
log.debug(string.format("玩家 %d 发放宠物套装 %d" , self.userId, arr[2] * count))
end
end
end
--道具类型
for k, v in pairs( cfgReward.ticket ) do
local arr = skynet.server.common:Split(v , "_")
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
skynet.server.bag:AddGoods( self , dataType.GoodsType_Prop , arr[1] , arr[2] * count )
table.insert(finalRewardInfo,{goodsType = dataType.GoodsType_Prop , id = arr[1] , count = arr[2] * count })
log.debug(string.format("玩家 %d 发放道具 %d 数量 %d" , self.userId, arr[1], arr[2] * count ))
end
--种子
for k, v in pairs( cfgReward.seed ) do
local arr = skynet.server.common:Split(v , "_")
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
skynet.server.bag:AddGoods( self , dataType.GoodsType_Seed , arr[1] , arr[2] * count)
table.insert(finalRewardInfo,{goodsType = dataType.GoodsType_Seed , id = arr[1] , count = arr[2] * count })
log.debug(string.format("玩家 %d 发放种子%d 数量 %d" , self.userId, arr[1], arr[2] * count))
end
--个人物品
for k, v in pairs( cfgReward.stuff ) do
local arr = skynet.server.common:Split(v , "_")
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
if dataType.HeadType_Head == arr[1] then
--增加玩家头像
local give,replaceRewardId = self:RewardConversion(arr[2] , dataType.GoodsType_HeadAndHeadFrame)
if give and replaceRewardId ~= rewardId then
local gainTime = 0
for k1 , v1 in pairs(self.gameData.personal.gainGoodsInfo) do
if v1.type == dataType.GoodsType_HeadAndHeadFrame and v1.id == arr[2] then
gainTime = v1.gainTime
break
end
end
table.insert(conversionInfo,{type = dataType.GoodsType_HeadAndHeadFrame , id = arr[2] , count = count , gainTime = gainTime})
local _,replaceReward = self:GiveReward(replaceRewardId , eventId , count)
if replaceReward ~= nil and next(replaceReward) ~= nil then
for i, replaceInfo in pairs( replaceReward ) do
table.insert(finalRewardInfo,replaceInfo)
end
end
else
skynet.server.personal:ChangeGainInfo(self , dataType.GoodsType_HeadAndHeadFrame , arr[2] , dataType.HeadType_Head , skynet.server.personal.AddGoods)
table.insert(finalRewardInfo,{goodsType = dataType.GoodsType_HeadAndHeadFrame , id = arr[2] , count = 1 })
end
elseif dataType.HeadType_Frame == arr[1] then
--增加玩家头像框
local give,replaceRewardId = self:RewardConversion(arr[2] , dataType.GoodsType_HeadAndHeadFrame)
if give and replaceRewardId ~= rewardId then
local gainTime = 0
for k1 , v1 in pairs(self.gameData.personal.gainGoodsInfo) do
if v1.type == dataType.GoodsType_HeadAndHeadFrame and v1.id == arr[2] then
gainTime = v1.gainTime
break
end
end
table.insert(conversionInfo,{type = dataType.GoodsType_HeadAndHeadFrame , id = arr[2] , count = count , gainTime = gainTime})
local _,replaceReward = self:GiveReward(replaceRewardId , eventId , count)
if replaceReward ~= nil and next(replaceReward) ~= nil then
for i, replaceInfo in pairs( replaceReward ) do
table.insert(finalRewardInfo,replaceInfo)
end
end
else
skynet.server.personal:ChangeGainInfo(self , dataType.GoodsType_HeadAndHeadFrame , arr[2] , dataType.HeadType_Frame , skynet.server.personal.AddGoods)
table.insert(finalRewardInfo,{goodsType = dataType.GoodsType_HeadAndHeadFrame , id = arr[2] , count = 1 })
end
end
end
--食材
for k, v in pairs( cfgReward.cuisineMaterial ) do
local arr = skynet.server.common:Split(v , "_")
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
skynet.server.bag:AddGoods( self , dataType.GoodsType_CuisineMaterial , arr[1] , arr[2] * count)
table.insert(finalRewardInfo,{goodsType = dataType.GoodsType_CuisineMaterial , id = arr[1] , count = arr[2] * count })
log.debug(string.format("玩家 %d 发放食材%d 数量 %d" , self.userId, arr[1], arr[2] * count))
end
return conversionInfo , finalRewardInfo
end
--发奖励并批指定NPC好感度
function Player:GiveRewardNpc( rewardId , npcId , eventId )
--发放其它奖励
self:GiveReward( rewardId , eventId)
--增加指定NPC好感度
local cfgReward = skynet.server.gameConfig:GetPlayerCurCfg( self , "Reward" , rewardId )
if cfgReward.relationValue > 0 then
local curNpc = self.gameData.friend[ npcId ]
if curNpc then
skynet.server.friend:AddFavorability( self , curNpc , cfgReward.relationValue)
log.debug(string.format("玩家 %d 增加好感度 %d" , self.userId,cfgReward.relationValue ))
end
end
end
--选择一个发奖励
function Player:SelectOneReward( rewardId , rewardIndex , eventId)
local data = {}
local cfgReward = skynet.server.gameConfig:GetPlayerCurCfg( self , "Reward" , rewardId )
if cfgReward.coin > 0 and rewardIndex == dataType.MoneyType_Coin then
self:MoneyChange( dataType.MoneyType_Coin , cfgReward.coin , eventId)
data = { type = dataType.MoneyType_Coin , count = cfgReward.coin }
end
if cfgReward.mapCoin > 0 and rewardIndex == dataType.MoneyType_Map then
self:MoneyChange( dataType.MoneyType_Map , cfgReward.mapCoin , eventId)
data = { type = dataType.MoneyType_Map , count = cfgReward.mapCoin }
end
if cfgReward.voluteCoin > 0 and rewardIndex == dataType.MoneyType_Volute then
self:MoneyChange( dataType.MoneyType_Volute , cfgReward.voluteCoin, eventId)
data = { type = dataType.MoneyType_Volute , count = cfgReward.voluteCoin }
end
return data
end
--获取一次性标记
function Player:GetOnceSign( key )
return self.gameData.onceSign[ key ]
end
--设置一次性标记
function Player:SetOnceSign( key , value )
self.gameData.onceSign[ key ]= value
end
--是否为新用户
function Player:IsNewUser()
if self.basicInfo.isNewPlayer then
return true
end
return false
end
--[[增加登陆历史
function Player:AddLoginHistory( player , platform)
local data = player.basicInfo.loginHistory
data.curIndex = data.curIndex + 1
--最多保存100条
if data.curIndex > 100 then
data.curIndex = 1
end
data.history[ data.curIndex ] = { serverId = serverId , platform = platform , time = skynet.server.common:GetStrTime(skynet.GetTime())}
end
]]
--设置开关
function Player:SetSwitch( id , isOpen )
if id <= 0 or "boolean" ~= type( isOpen ) then
return false
end
local switches = self.gameData.switches
switches[ id ] = isOpen
return true
end
--获取当前开关
function Player:GetSwitch( id )
if id <= 0 or nil == self.gameData.switches[ id ] then
return false
end
return self.gameData.switches[ id ]
end
--是否为审核玩家 true为审核玩家
function Player:IsAudit()
return self.basicInfo.isAudit
end
--是否为老苹果用户 true为老苹果用户
function Player:IsOldIOS()
return self.basicInfo.isOldIOS
end
--补偿老苹果用户相关,除了房子单独处理
function Player:CompensateOldIOS()
local level = self.gameData.level
if self:IsOldIOS() then
local oldData = self.gameData.oldData
local oldPayCount = self.gameData.oldPayCount or 0
local inviteCount = self.gameData.inviteCount or 0
local mobile = self.basicInfo.mobile
if 2 == level then
if oldPayCount > 0 then
local volute = 0 --补偿蜗壳币
if oldPayCount <= 2000 then
--玩家被补偿蜗壳币= 充值金额*20
volute = oldPayCount * 20
elseif oldPayCount > 2000 then
--玩家被补偿蜗壳币= (充值金额-2000)*10+2000*20
volute = ((oldPayCount - 2000) * 10 + 40000)
end
local title = "测试充值返利来咯~"
local content = "亲爱的小蜗:\
非常感谢您在【宅家避暑】和【秋日随心】的Android删档测试期间的陪伴与支持在此献上您在充值返利活动中所获得的蜗壳币有效期为30天请及时查收避免邮件过期哟\
\
具体返利规则如下:\
根据您在删档测试中的充值总金额将按照1元=10蜗壳币的标准进行倍率返还\
①累计充值金额≤2000元的可获得200%的蜗壳币返还。\
②累计充值金额>2000元的2000元以内的部分可获得200%的蜗壳币返还超出2000元的部分按照100%的比例进行蜗壳币返还。\
如有疑问,您可以点击主界面左上角的头像,依次点击右下角的小齿轮-「联系客服」进行咨询。\
\
最后,由衷地感谢您一直以来对《我的休闲时光》的支持,如在游戏体验过程中想要提出任何意见或建议欢迎在「联系客服」处告诉我们,我们将持续认真倾听每一位小蜗的意见与建议,努力为大家打造更美好的悠悠镇~"
local award = {}
table.insert( award , { type = 0 , id = dataType.GoodsType_Volute , count = volute })
skynet.server.mail:AddNewMail( self , skynet.server.mail.MailType_Award , title , content , award)
end
if inviteCount > 0 then
local award = {}
if inviteCount >= 1 then
table.insert( award , { type = dataType.GoodsType_Furniture , id = 732 , count = 1 })
table.insert( award , { type = dataType.GoodsType_Furniture , id = 720 , count = 1 })
end
if inviteCount >= 3 and inviteCount <= 4 then
table.insert( award , { type = dataType.GoodsType_Clothes , id = 222 , count = 1 })
table.insert( award , { type = dataType.GoodsType_Clothes , id = 223 , count = 1 })
table.insert( award , { type = dataType.GoodsType_Clothes , id = 224 , count = 1 })
end
if inviteCount >= 5 then
table.insert( award , { type = dataType.GoodsType_Furniture , id = 729 , count = 1 })
table.insert( award , { type = dataType.GoodsType_Furniture , id = 725 , count = 1 })
table.insert( award , { type = dataType.GoodsType_Clothes , id = 222 , count = 1 })
table.insert( award , { type = dataType.GoodsType_Clothes , id = 223 , count = 1 })
table.insert( award , { type = dataType.GoodsType_Clothes , id = 224 , count = 1 })
end
self.basicInfo.isCompensate = true
local title = "说好的官网邀请奖励来咯~"
local content = "亲爱的小蜗:\
非常感谢你对蜗居一直以来的关注与支持!因为你的盛情邀请,悠悠镇迎来了越来越多的小蜗,小镇变得更热闹啦!为表感谢,随信献上邀请奖励一份,记得及时领取哦~\
如在游戏过程中遇到任何问题或想要提出游戏建议,欢迎在游戏左上角头像处点击小齿轮中的【联系客服】提交你的问题哦!"
skynet.server.mail:AddNewMail( self , skynet.server.mail.MailType_Award , title , content , award)
end
end
--补偿存档
if oldData and oldData.coin then
if 5 == level then
local addCoin = oldData.coin
if addCoin >= 0 then
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_110")
self:MoneyChange( dataType.MoneyType_Coin , addCoin , eventId )
end
--家具
for k, v in pairs( oldData.furnitures ) do
skynet.server.bag:AddGoodsNoExp( self , dataType.GoodsType_Furniture , v.id , v.count , true )
end
--装修
for k, v in pairs( oldData.decorations ) do
skynet.server.bag:AddGoodsNoExp( self , dataType.GoodsType_Decorate , v.id , v.count , true)
end
--人物服装
for k, v in pairs( oldData.clothes ) do
skynet.server.bag:AddGoodsNoExp( self , dataType.GoodsType_Clothes , v.id , v.count , true)
end
--宠物服装
for k, v in pairs( oldData.petClothes ) do
skynet.server.bag:AddGoodsNoExp( self , dataType.GoodsType_PetClothes , v.id , v.count , true)
end
--发放复古四叶套间
local award = {}
local cfgAllFurniture = skynet.server.gameConfig:GetPlayerAllCfg( self , "Furniture")
local cfgAllDecoration = skynet.server.gameConfig:GetPlayerAllCfg( self , "Decoration")
--找出复古四叶的家具
local suitId = 13 --初始套件的ID
for k, v in pairs( cfgAllFurniture ) do
if suitId == v.suitType then
table.insert( award , { type = dataType.GoodsType_Furniture , id = v.id , count = 1})
end
end
--找出复古四叶的装修
for k, v in pairs( cfgAllDecoration ) do
if suitId == v.suitType then
table.insert( award , { type = dataType.GoodsType_Decorate , id = v.id , count = 1})
end
end
--种子
for k, v in pairs( oldData.seeds ) do
skynet.server.bag:AddGoodsNoExp( self , dataType.GoodsType_Seed , v.id , v.count, true)
end
--植物
for k, v in pairs( oldData.plants ) do
skynet.server.bag:AddGoodsNoExp( self , dataType.GoodsType_Plant , v.id , v.count , true)
end
local title = "初测iOS小蜗的专属补偿"
local content = "亲爱的小蜗:\
在22年的那个秋天很高兴能与各位小蜗在最初的蜗居里相遇。\
而在随后的八个月里,因为有你们的支持与陪伴,这个小小蜗居才能让更多小蜗关注到,并逐渐成长为如今的模样。\
随着开发的不断推进,内容不断扩充,为了给大家带来更好的游戏体验,我们优化修改了部分游戏货币:将之前测试中的货币【四叶草】删除,并加入了其他货币进行补充。\
但在与大家的交流中我们了解到许多小蜗在之前的测试中积累了不少四叶草而由于以上的修改我们无法同步该数据至正式服真的非常非常抱歉QAQ秃头技术滑跪道歉.jpg\
为了补偿参与了第一次iOS测试版的大家美术小姐姐连夜设计了一套专属套间「复古四叶」献给大家。\
希望在接下来的蜗居依旧能有你们的陪伴,我们将会持续倾听大家的意见与建议,努力优化游戏内容,争取建造一个更美好的蜗居呀~"
skynet.server.mail:AddNewMail( self , skynet.server.mail.MailType_Award , title , content , award)
else
if oldData.house then
for k, v in pairs( oldData.house ) do
local houseId = v.id
--玩家是还未拥有该房子 等级达到了该房子解锁的时间就把房子赠送s
if not skynet.server.house:IsBuyHouse( self , houseId ) then
local cfgCurHouse = skynet.server.gameConfig:GetPlayerCurCfg( self , "House" ,houseId )
if cfgCurHouse and level >= cfgCurHouse.level then
--免费赠送该房子
skynet.server.house:Add( self , houseId, {} , true )
end
end
end
end
end
end
end
end
--如果玩家有对应的服装 则换成对应的蜗壳币进行发放
function Player:RewardConversion( id , goodsType)
local ownCount = skynet.server.bag:GetGoodsCount(self , goodsType , id)
if ownCount == 0 and goodsType ~= dataType.GoodsType_HeadAndHeadFrame then
--背包物品可以通过数量判断
return false
else
if goodsType == dataType.GoodsType_Clothes then
local cfgOneClothes = skynet.server.gameConfig:GetPlayerCurCfg( self , "Clothes" , id)
--防止死循环
local cfgOneReward = skynet.server.gameConfig:GetPlayerCurCfg( self , "Reward" , cfgOneClothes.replaceReward)
if not cfgOneReward or (next(cfgOneReward.appearanceObject) ~= nil or next(cfgOneReward.suitObject) ~= nil) then
return false
end
return true,cfgOneClothes.replaceReward
elseif goodsType == dataType.GoodsType_PetClothes then
local cfgOnePetClothes = skynet.server.gameConfig:GetPlayerCurCfg( self , "PetClothes" , id)
local cfgOneReward = skynet.server.gameConfig:GetPlayerCurCfg( self , "Reward" , cfgOnePetClothes.replaceReward)
if not cfgOneReward or (next(cfgOneReward.appearanceObject) ~= nil or next(cfgOneReward.suitObject) ~= nil) then
return false
end
return true,cfgOnePetClothes.replaceReward
elseif goodsType == dataType.GoodsType_Decorate then
local cfgOneDecorate = skynet.server.gameConfig:GetPlayerCurCfg( self , "Decoration" , id)
local cfgOneReward = skynet.server.gameConfig:GetPlayerCurCfg( self , "Reward" , cfgOneDecorate.replaceReward)
if not cfgOneReward or (next(cfgOneReward.sceneObject) ~= nil or next(cfgOneReward.suitObject) ~= nil) then
return false
end
return true,cfgOneDecorate.replaceReward
elseif goodsType == dataType.GoodsType_HeadAndHeadFrame then
--个人物品处理方式不同
local cfgOneHead = skynet.server.gameConfig:GetPlayerCurCfg( self , "Head" , id)
local cfgOneReward = skynet.server.gameConfig:GetPlayerCurCfg( self , "Reward" , cfgOneHead.replaceReward)
if not cfgOneReward or next(cfgOneReward.stuff) ~= nil then
return false
end
if cfgOneHead.type == dataType.HeadType_Head then
for k , v in pairs(self.gameData.personal.ownHeadIds) do
if v == id then
return true,cfgOneHead.replaceReward
end
end
elseif cfgOneHead.type == dataType.HeadType_Frame then
for k , v in pairs(self.gameData.personal.ownHeadFrameIds) do
if v == id then
return true,cfgOneHead.replaceReward
end
end
end
return false
end
end
end
--替换奖励判断
function Player:RewardShow( rewardId , count )
local cfgReward = skynet.server.gameConfig:GetPlayerCurCfg( self , "Reward" , rewardId )
if not cfgReward then
return
end
--奖励集合
local data = {}
count = count or 1
if cfgReward.coin > 0 then
table.insert(data,{goodsType = dataType.MoneyType_Coin , id = 0 , count = cfgReward.coin * count })
end
if cfgReward.mapCoin > 0 then
table.insert(data,{goodsType = dataType.MoneyType_Map , id = 0 , count = cfgReward.mapCoin * count })
end
if cfgReward.voluteCoin > 0 then
table.insert(data,{goodsType = dataType.MoneyType_Volute , id = 0 , count = cfgReward.voluteCoin * count })
end
--场景物品
for k, v in pairs( cfgReward.sceneObject ) do
local arr = skynet.server.common:Split(v , "_")
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
if 1 == arr[1] then
table.insert(data,{goodsType = dataType.GoodsType_Furniture , id = arr[2] , count = count })
elseif 2 == arr[1] then
local give,replaceRewardId = self:RewardConversion(arr[2] , dataType.GoodsType_Decorate)
if give and replaceRewardId ~= rewardId then
local replaceReward = self:RewardShow(replaceRewardId , count)
if replaceReward ~= nil and next(replaceReward) ~= nil then
for i, replaceInfo in pairs( replaceReward ) do
table.insert(data,replaceInfo)
end
end
else
table.insert(data,{goodsType = dataType.GoodsType_Decorate , id = arr[2] , count = count })
end
elseif 3 == arr[1] then
table.insert(data,{goodsType = dataType.GoodsType_Garden , id = arr[2] , count = count })
end
end
--服饰物品
for k, v in pairs( cfgReward.appearanceObject ) do
local arr = skynet.server.common:Split(v , "_")
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
if 1 == arr[1] then
local give,replaceRewardId = self:RewardConversion(arr[2] , dataType.GoodsType_Clothes)
if give and replaceRewardId ~= rewardId then
local replaceReward = self:RewardShow(replaceRewardId , count)
if replaceReward ~= nil and next(replaceReward) ~= nil then
for i, replaceInfo in pairs( replaceReward ) do
table.insert(data,replaceInfo)
end
end
else
table.insert(data,{goodsType = dataType.GoodsType_Clothes , id = arr[2] , count = count })
end
elseif 2 == arr[1] then
local give,replaceRewardId = self:RewardConversion(arr[2] , dataType.GoodsType_PetClothes)
if give and replaceRewardId ~= rewardId then
local replaceReward = self:RewardShow(replaceRewardId , count)
if replaceReward ~= nil and next(replaceReward) ~= nil then
for i, replaceInfo in pairs( replaceReward ) do
table.insert(data,replaceInfo)
end
end
else
table.insert(data,{goodsType = dataType.GoodsType_PetClothes , id = arr[2] , count = count })
end
end
end
--套装物品
for k, v in pairs( cfgReward.suitObject ) do
local arr = skynet.server.common:Split(v , "_")
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
if 1 == arr[1] then
--家具
local cfgAllFurniture = skynet.server.gameConfig:GetPlayerAllCfg( self , "Furniture")
for k, v in pairs( cfgAllFurniture ) do
if arr[2] == v.suitType then
table.insert(data,{goodsType = dataType.GoodsType_Furniture , id = v.id , count = count })
end
end
--装修
local cfgAllDecoration = skynet.server.gameConfig:GetPlayerAllCfg( self , "Decoration")
for k, v in pairs( cfgAllDecoration ) do
if arr[2] == v.suitType then
local give,replaceRewardId = self:RewardConversion(v.id , dataType.GoodsType_Decorate)
if give and replaceRewardId ~= rewardId then
local replaceReward = self:RewardShow(replaceRewardId , count)
if replaceReward ~= nil and next(replaceReward) ~= nil then
for i, replaceInfo in pairs( replaceReward ) do
table.insert(data,replaceInfo)
end
end
else
table.insert(data,{goodsType = dataType.GoodsType_Decorate , id = v.id , count = count })
end
end
end
elseif 2 == arr[1] then
local cfgClothesSuit = skynet.server.gameConfig:GetPlayerAllCfg( self , "ClothesSuit") --获取配置文件ClothesSuit中的数据
local cfgAllClothes = skynet.server.gameConfig:GetPlayerAllCfg( self , "Clothes") --人物
local cfgPetClothes = skynet.server.gameConfig:GetPlayerAllCfg( self , "PetClothes") --宠物
local type = nil
for k ,v in pairs(cfgClothesSuit) do
if v.id==arr[2] then
--获取该套装类型
type = v.type
end
end
if type == 1 then
for k, v in pairs( cfgAllClothes ) do
if arr[2] == v.suitId then
local give,replaceRewardId = self:RewardConversion(v.id , dataType.GoodsType_Clothes)
if give and replaceRewardId ~= rewardId then
local replaceReward = self:RewardShow(replaceRewardId , count)
if replaceReward ~= nil and next(replaceReward) ~= nil then
for i, replaceInfo in pairs( replaceReward ) do
table.insert(data,replaceInfo)
end
end
else
table.insert(data,{goodsType = dataType.GoodsType_Clothes , id = v.id , count = count })
end
end
end
elseif type == 2 then
--获取动物服装对应的套装物品
for k ,v in pairs( cfgPetClothes ) do
if arr[2] == v.suitId then
local give,replaceRewardId = self:RewardConversion(v.id , dataType.GoodsType_PetClothes)
if give and replaceRewardId ~= rewardId then
local replaceReward = self:RewardShow(replaceRewardId , count)
if replaceReward ~= nil and next(replaceReward) ~= nil then
for i, replaceInfo in pairs( replaceReward ) do
table.insert(data,replaceInfo)
end
end
else
table.insert(data,{goodsType = dataType.GoodsType_PetClothes , id = v.id , count = count })
end
end
end
end
end
end
--道具类型
for k, v in pairs( cfgReward.ticket ) do
local arr = skynet.server.common:Split(v , "_")
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
table.insert(data,{goodsType = dataType.GoodsType_Prop , id = arr[1] , count = arr[2] * count })
end
--种子
for k, v in pairs( cfgReward.seed ) do
local arr = skynet.server.common:Split(v , "_")
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
table.insert(data,{goodsType = dataType.GoodsType_Seed , id = arr[1] , count = arr[2] * count })
end
--个人物品
for k, v in pairs( cfgReward.stuff ) do
local arr = skynet.server.common:Split(v , "_")
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
if dataType.HeadType_Head == arr[1] then
--增加玩家头像
local give,replaceRewardId = self:RewardConversion(arr[2] , dataType.GoodsType_HeadAndHeadFrame)
if give and replaceRewardId ~= rewardId then
local replaceReward = self:RewardShow(replaceRewardId , count)
if replaceReward ~= nil and next(replaceReward) ~= nil then
for i, replaceInfo in pairs( replaceReward ) do
table.insert(data,replaceInfo)
end
end
else
table.insert(data,{goodsType = dataType.GoodsType_HeadAndHeadFrame , id = arr[2] , count = 1 })
end
elseif dataType.HeadType_Frame == arr[1] then
--增加玩家头像框
local give,replaceRewardId = self:RewardConversion(arr[2] , dataType.GoodsType_HeadAndHeadFrame)
if give and replaceRewardId ~= rewardId then
local _,replaceReward = self:RewardShow(replaceRewardId , count)
if replaceReward ~= nil and next(replaceReward) ~= nil then
for i, replaceInfo in pairs( replaceReward ) do
table.insert(data,replaceInfo)
end
end
else
table.insert(data,{goodsType = dataType.GoodsType_HeadAndHeadFrame , id = arr[2] , count = 1 })
end
end
end
--食材
for k, v in pairs( cfgReward.cuisineMaterial ) do
local arr = skynet.server.common:Split(v , "_")
arr[1],arr[2] = tonumber(arr[1]),tonumber(arr[2])
table.insert(data,{goodsType = dataType.GoodsType_CuisineMaterial , id = arr[1] , count = arr[2] * count })
end
return data
end
--计算游戏时间
function Player:CalcGameTime( nowTime )
local gameTime = nowTime - self.tmpData.intoTime
self.basicInfo.allGameTime = self.basicInfo.allGameTime + gameTime
self.gameData.todayGain.todayGameTime = self.gameData.todayGain.todayGameTime + gameTime
self:AddLastWeekGameTime( nowTime ,gameTime )
self.tmpData.intoTime = nowTime
end
--添加上一周的游戏时间(秒)
function Player:AddLastWeekGameTime( nowTime , addTime )
local preStartTime,preEndTime = skynet.server.common:GetPreSomeDay( 7 ) --获取7天前的时间戳
local lastWeekGameTime = self.basicInfo.lastWeekGameTime
local isExist = false
for k, v in pairs( lastWeekGameTime ) do
if v.recordTime >= preEndTime then
--记录时间已经超过7天删除
table.remove(lastWeekGameTime, k)
elseif skynet.server.common:IsSameDay( nowTime , v.recordTime ) then
--累加到今天的游戏时间
v.count = v.count + addTime
isExist = true
break
end
end
if not isExist then
--今天不存在时间,就加进去
table.insert( lastWeekGameTime , { recordTime = nowTime , count = addTime } )
end
--更新一下上一周的游戏时间到个人信息
local newGameTime = 0
for k, v in pairs( lastWeekGameTime ) do
newGameTime = newGameTime + v.count
end
skynet.server.personal:SetDetail( "lastWeekGameTime" , newGameTime )
end
--添加保存等级 isForceSave 是否强制保存
function Player:AddSaveLevel( saveLevel , isForceSave )
isForceSave = isForceSave or false
if dataType.SaveLevel_Pay == self.tmpData.saveLevel and not isForceSave then --如果玩家此时的保存等级为SaveLevel_Pay其余的保存等级不用处理
return
end
self.tmpData.saveLevel = saveLevel
end
return Player