670 lines
28 KiB
Lua
670 lines
28 KiB
Lua
local skynet = require "skynet"
|
|
local oo = require "Class"
|
|
local log = require "Log"
|
|
local pb = require "pb"
|
|
local redisKeyUrl = require "RedisKeyUrl"
|
|
local json = require "json"
|
|
local dataType = require "DataType"
|
|
local errorInfo = require "ErrorInfo"
|
|
local HouseRent = oo.class()
|
|
|
|
HouseRent.OPType_HouseRent = 1 -- 放房间
|
|
HouseRent.OPType_Bag = 2 -- 放背包
|
|
HouseRent.OPType_Move = 3 -- 移动
|
|
HouseRent.OPType_Operate = 4 -- 家具原地操作
|
|
|
|
HouseRent.DecorateStatus_Suc = 1 -- 成功装修
|
|
HouseRent.DecorateStatus_Failed = 2 -- 部分装修
|
|
|
|
HouseRent.Status_Lock = 1 -- 未解锁
|
|
HouseRent.Status_NoBuy = 2 -- 未购买
|
|
HouseRent.Status_AlreadyBuy = 3 -- 已购买
|
|
HouseRent.Status_Live = 4 -- 正在居住
|
|
|
|
HouseRent.RentType_Short = 1 -- 短租
|
|
HouseRent.RentType_Long = 2 -- 长租
|
|
|
|
-- 初始化恋家置地数据
|
|
function HouseRent:InitData(player)
|
|
local cfgHouseRent = skynet.server.gameConfig:GetPlayerAllCfg(player, "HouseRent") -- 房产咨询信息
|
|
|
|
if player.gameData.shop[ dataType.ShopType_GardenShop ] == nil then
|
|
player.gameData.shop[ dataType.ShopType_GardenShop ] = {}
|
|
player.gameData.shop[ dataType.ShopType_GardenShop ].specialGoods = {}
|
|
player.gameData.shop[ dataType.ShopType_GardenShop ].generalGoods = {}
|
|
player.gameData.shop[ dataType.ShopType_GardenShop ].nextRefreshTime = 0
|
|
|
|
player.gameData.houseRent = {}
|
|
player.gameData.houseRent.houseInfo = {}
|
|
|
|
local houseRent = player.gameData.houseRent
|
|
for k, v in pairs(cfgHouseRent) do
|
|
local houseId = v.houseId
|
|
houseRent.houseInfo[ houseId] = {}
|
|
houseRent.houseInfo[ houseId].id = houseId -- id
|
|
houseRent.houseInfo[ houseId ].leaseStatus = 1 -- //房子出租状态 1- 待租房 2- 租房中 3- 待收租
|
|
houseRent.houseInfo[ houseId ].rentType = v.rentType -- 租期类别
|
|
houseRent.houseInfo[ houseId ].rentTime = 0 -- 出租时间
|
|
houseRent.houseInfo[ houseId ].rentPrice = 0 -- 出租价格
|
|
houseRent.houseInfo[ houseId ].finishTime = 0 -- 出租剩余时间
|
|
end
|
|
|
|
houseRent.shortLeaseInfo = {}
|
|
houseRent.longLeaseInfo = {}
|
|
|
|
houseRent.showShortHistory = {} -- 短租展示历史记录
|
|
houseRent.showLongHistory = {} --长租展示历史记录
|
|
|
|
-- 短租相关初始数据
|
|
for i = 1, 3, 1 do
|
|
self:InitLease(player , self.RentType_Short , i )
|
|
end
|
|
|
|
for i = 1, 1, 1 do
|
|
self:InitLease(player , self.RentType_Long , i )
|
|
end
|
|
else
|
|
local houseInfo = player.gameData.houseRent.houseInfo
|
|
for k, v in pairs(cfgHouseRent) do
|
|
local houseId = v.houseId
|
|
if not houseInfo[ houseId ] then
|
|
houseInfo[ houseId] = {}
|
|
houseInfo[ houseId].id = houseId -- id
|
|
houseInfo[ houseId ].leaseStatus = 1 -- //房子出租状态 1- 待租房 2- 租房中 3- 待收租
|
|
houseInfo[ houseId ].rentType = v.rentType -- 租期类别
|
|
houseInfo[ houseId ].rentTime = 0 -- 出租时间
|
|
houseInfo[ houseId ].rentPrice = 0 -- 出租价格
|
|
houseInfo[ houseId ].finishTime = 0 -- 出租剩余时间
|
|
end
|
|
end
|
|
end
|
|
|
|
--[[
|
|
-- 恋家置业相关数据
|
|
player.gameData.shop[ dataType.ShopType_GardenShop ] = {}
|
|
player.gameData.houseRent = {}
|
|
player.gameData.houseRent.houseInfo = {}
|
|
player.gameData.shop[ dataType.ShopType_GardenShop ].specialGoods = {}
|
|
player.gameData.shop[ dataType.ShopType_GardenShop ].generalGoods = {}
|
|
player.gameData.shop[ dataType.ShopType_GardenShop ].nextRefreshTime = 0
|
|
|
|
local houseRent = player.gameData.houseRent
|
|
for k, v in pairs(cfgHouseRent) do
|
|
local houseId = v.houseId
|
|
houseRent.houseInfo[ houseId] = {}
|
|
houseRent.houseInfo[ houseId].id = houseId -- id
|
|
houseRent.houseInfo[ houseId ].leaseStatus = 1 -- //房子出租状态 1- 待租房 2- 租房中 3- 待收租
|
|
houseRent.houseInfo[ houseId ].rentType = v.rentType -- 租期类别
|
|
houseRent.houseInfo[ houseId ].rentTime = 0 -- 出租时间
|
|
houseRent.houseInfo[ houseId ].rentPrice = 0 -- 出租价格
|
|
houseRent.houseInfo[ houseId ].finishTime = 0 -- 出租剩余时间
|
|
end
|
|
|
|
houseRent.shortLeaseInfo = {}
|
|
houseRent.longLeaseInfo = {}
|
|
|
|
houseRent.showShortHistory = {} -- 短租展示历史记录
|
|
houseRent.showLongHistory = {} --长租展示历史记录
|
|
|
|
-- 短租相关初始数据
|
|
for i = 1, 3, 1 do
|
|
self:InitLease(player , self.RentType_Short , i )
|
|
end
|
|
|
|
for i = 1, 1, 1 do
|
|
self:InitLease(player , self.RentType_Long , i )
|
|
end
|
|
]]
|
|
end
|
|
|
|
-- 进入恋家置业
|
|
function HouseRent:HouseRentEnter(player, c2sData, s2cData)
|
|
c2sData.data = assert(pb.decode("C2SHouseRentEnter", c2sData.data))
|
|
local data = {}
|
|
-- 首次进入恋家置业的任务
|
|
skynet.server.levelTask:Modify(player, 55, 1)
|
|
skynet.server.taskListEvent:Modify( player ,55, 1)
|
|
|
|
s2cData.cmd = pb.enum("MsgType", "CMD_S2C_HouseRentEnter")
|
|
s2cData.data = assert(pb.encode("S2CHouseRentEnter", data))
|
|
end
|
|
|
|
-- 青青园艺购买
|
|
function HouseRent:HouseRentGardenShopBuy(player, c2sData, s2cData)
|
|
c2sData.data = assert(pb.decode("C2SHouseRentGardenShopBuy", c2sData.data))
|
|
local data = {}
|
|
local gardenId = c2sData.data.buyGoods.id
|
|
local count = math.abs(c2sData.data.buyGoods.count)
|
|
local cfgGarden = skynet.server.gameConfig:GetPlayerAllCfg(player, "Garden") -- 青青园艺信息
|
|
|
|
data.buyGoods = {}
|
|
-- 判断当前时间是否满足兑换时间
|
|
local canGetPay = false
|
|
-- 判断三叶币是否足够消耗数量
|
|
local eventId = pb.enum("EnumMoneyChangeEventID", "EventID_100")
|
|
local isSuc = player:MoneyChange(pb.enum("EnumGoodsType", "Clovers", eventId),
|
|
-(cfgGarden[gardenId].mapCoin * count))
|
|
-- 是否完成扣币
|
|
if isSuc then
|
|
data.buyGoods = {
|
|
id = gardenId, -- 商品ID
|
|
count = count
|
|
}
|
|
skynet.server.levelTask:Modify(player, 16, 1)
|
|
skynet.server.taskListEvent:Modify( player ,16, count)
|
|
-- 将兑换后的景观存入背包
|
|
skynet.server.bag:AddGoods(player, dataType.GoodsType_Garden, data.buyGoods.id, count)
|
|
-- 判断增加普通还是稀有的经验值
|
|
if cfgGarden[gardenId].shopType == 2 and cfgGarden[gardenId].quality == 1 and cfgGarden[gardenId].gardenType ==
|
|
1 then
|
|
player:AddExpCount(10 * count)
|
|
elseif cfgGarden[gardenId].shopType == 2 and cfgGarden[gardenId].quality == 1 and cfgGarden[gardenId].gardenType ==
|
|
2 then
|
|
player:AddExpCount(20 * count)
|
|
end
|
|
end
|
|
|
|
s2cData.cmd = pb.enum("MsgType", "CMD_S2C_HouseRentGardenShopBuy")
|
|
s2cData.data = assert(pb.encode("S2CHouseRentGardenShopBuy", data))
|
|
end
|
|
|
|
-- 恋家房产咨询展示
|
|
function HouseRent:HouseRentConsultShow(player, c2sData, s2cData)
|
|
--leaseStatus 1- 待租房 2- 租房中 3- 待收租
|
|
c2sData.data = assert(pb.decode("C2SHouseRentConsultShow", c2sData.data))
|
|
local data = {}
|
|
local cfgHouseRent = skynet.server.gameConfig:GetPlayerAllCfg(player, "HouseRent") -- 恋家房产信息
|
|
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg(player, "SValue")
|
|
|
|
local houseInfo = player.gameData.houseRent.houseInfo
|
|
for k, v in ipairs(player.gameData.houseRent.shortLeaseInfo) do
|
|
if v.leaseStatus == 2 and skynet.GetTime() >= v.remainRentTime then
|
|
v.leaseStatus = 3
|
|
v.remainRentTime = 0
|
|
houseInfo[ v.houseId ].leaseStatus = 3
|
|
end
|
|
end
|
|
|
|
for k, v in ipairs(player.gameData.houseRent.longLeaseInfo) do
|
|
if v.leaseStatus == 2 and skynet.GetTime() >= v.remainRentTime then
|
|
v.leaseStatus = 3
|
|
v.remainRentTime = 0
|
|
houseInfo[ v.houseId ].leaseStatus = 3
|
|
end
|
|
end
|
|
|
|
local shortFreeTimes = 1
|
|
if player.gameData.todayGain.shortFreeRefresh >= cfgSValue.freeRefreshRentDaily[2] then
|
|
shortFreeTimes = 0
|
|
end
|
|
local longFreeTimes = 1
|
|
if player.gameData.todayGain.longFreeRefresh >= cfgSValue.freeRefreshRentDaily[1] then
|
|
longFreeTimes = 0
|
|
end
|
|
|
|
data.longLeaseInfo = player.gameData.houseRent.longLeaseInfo
|
|
data.shortLeaseInfo = player.gameData.houseRent.shortLeaseInfo
|
|
data.shortRefreshInfo = { type = self.RentType_Short , LeaseFreeRefreshTimes = shortFreeTimes}
|
|
data.longRefreshInfo = { type = self.RentType_Long , LeaseFreeRefreshTimes = longFreeTimes}
|
|
|
|
s2cData.cmd = pb.enum("MsgType", "CMD_S2C_HouseRentConsultShow")
|
|
s2cData.data = assert(pb.encode("S2CHouseRentConsultShow", data))
|
|
end
|
|
|
|
-- 初始化房产展示
|
|
function HouseRent:ConsultRefresh( player , c2sData, s2cData )
|
|
c2sData.data = assert(pb.decode("C2SHouseRentConsultRefresh", c2sData.data))
|
|
local data = {}
|
|
local rentType = c2sData.data.message
|
|
local methodType = c2sData.data.methodType
|
|
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg(player, "SValue")
|
|
|
|
self:InitData( player )
|
|
|
|
local leaseInfo = {}
|
|
if self.RentType_Short == rentType then
|
|
leaseInfo = player.gameData.houseRent.shortLeaseInfo
|
|
elseif self.RentType_Long == rentType then
|
|
leaseInfo = player.gameData.houseRent.longLeaseInfo
|
|
end
|
|
|
|
local isRefresh = false
|
|
for k, v in pairs( leaseInfo ) do
|
|
if v.leaseStatus == self.Status_Lock then
|
|
isRefresh = true
|
|
end
|
|
end
|
|
|
|
if not isRefresh then
|
|
s2cData.code = errorInfo.ErrorCode.NotSatisfiedRefresh
|
|
else
|
|
local isSuc = false
|
|
if self.RentType_Short == rentType then
|
|
|
|
if methodType == dataType.AccelerateType_Volute then
|
|
local eventId = pb.enum("EnumMoneyChangeEventID", "EventID_113")
|
|
local needVolute = cfgSValue.voluteRefreshRentPrice
|
|
if player:MoneyChange(dataType.MoneyType_Volute, -needVolute, eventId) then
|
|
-- 使用蜗壳币进行加速 修改相关数据
|
|
player.gameData.todayGain.speedUpUseCount = player.gameData.todayGain.speedUpUseCount + 1
|
|
if player.gameData.todayGain.speedUpUseCount == cfgSValue.triggerPlantPack[1] then
|
|
skynet.server.store:TriggerPack(player, skynet.server.store.TriggerPack_SpeedUp)
|
|
end
|
|
isSuc = true
|
|
else
|
|
s2cData.code = errorInfo.ErrorCode.NoEnoughMoney
|
|
end
|
|
elseif methodType == dataType.AccelerateType_AccTicket then
|
|
if player.gameData.todayGain.shortFreeRefresh < cfgSValue.freeRefreshRentDaily[1] then
|
|
player.gameData.todayGain.shortFreeRefresh = player.gameData.todayGain.shortFreeRefresh + 1
|
|
isSuc = true
|
|
else
|
|
s2cData.code = errorInfo.ErrorCode.TodayMaxLimit
|
|
end
|
|
elseif methodType == dataType.AccelerateType_ADTicket and skynet.server.ad:CanWatch(player, "ShortHouseRentRefresh") and skynet.server.ad:PayADTicket(player, "ShortHouseRentRefresh") then
|
|
isSuc = true
|
|
elseif methodType == dataType.AccelerateType_WatchAD and skynet.server.ad:CanWatch(player, "ShortHouseRentRefresh") then
|
|
skynet.server.ad:Update(player, "ShortHouseRentRefresh")
|
|
isSuc = true
|
|
end
|
|
elseif self.RentType_Long == rentType then
|
|
|
|
if methodType == dataType.AccelerateType_Volute then
|
|
local eventId = pb.enum("EnumMoneyChangeEventID", "EventID_113")
|
|
local needVolute = cfgSValue.voluteRefreshRentPrice
|
|
if player:MoneyChange(dataType.MoneyType_Volute, -needVolute, eventId) then
|
|
-- 使用蜗壳币进行加速 修改相关数据
|
|
player.gameData.todayGain.speedUpUseCount = player.gameData.todayGain.speedUpUseCount + 1
|
|
if player.gameData.todayGain.speedUpUseCount == cfgSValue.triggerPlantPack[1] then
|
|
skynet.server.store:TriggerPack(player, skynet.server.store.TriggerPack_SpeedUp)
|
|
end
|
|
isSuc = true
|
|
else
|
|
s2cData.code = errorInfo.ErrorCode.NoEnoughMoney
|
|
end
|
|
elseif methodType == dataType.AccelerateType_AccTicket then
|
|
if player.gameData.todayGain.longFreeRefresh < cfgSValue.freeRefreshRentDaily[1] then
|
|
player.gameData.todayGain.longFreeRefresh = player.gameData.todayGain.longFreeRefresh + 1
|
|
isSuc = true
|
|
else
|
|
s2cData.code = errorInfo.ErrorCode.TodayMaxLimit
|
|
end
|
|
elseif methodType == dataType.AccelerateType_ADTicket and skynet.server.ad:CanWatch(player, "LongHouseRentRefresh") and skynet.server.ad:PayADTicket(player, "LongHouseRentRefresh") then
|
|
isSuc = true
|
|
elseif methodType == dataType.AccelerateType_WatchAD and skynet.server.ad:CanWatch(player, "LongHouseRentRefresh") then
|
|
skynet.server.ad:Update(player, "LongHouseRentRefresh")
|
|
isSuc = true
|
|
end
|
|
end
|
|
|
|
if isSuc then
|
|
for k, v in pairs( leaseInfo ) do
|
|
if 1 == v.leaseStatus then
|
|
self:InitLease(player , rentType , k )
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
data.shortLeaseInfos = player.gameData.houseRent.shortLeaseInfo
|
|
data.longLeaseInfos = player.gameData.houseRent.longLeaseInfo
|
|
local shortFreeTimes = 1
|
|
if player.gameData.todayGain.shortFreeRefresh >= cfgSValue.freeRefreshRentDaily[2] then
|
|
shortFreeTimes = 0
|
|
end
|
|
local longFreeTimes = 1
|
|
if player.gameData.todayGain.longFreeRefresh >= cfgSValue.freeRefreshRentDaily[1] then
|
|
longFreeTimes = 0
|
|
end
|
|
data.shortRefreshInfo = { type = 1 , LeaseFreeRefreshTimes = shortFreeTimes }
|
|
data.longRefreshInfo = { type = 2, LeaseFreeRefreshTimes = longFreeTimes }
|
|
|
|
s2cData.cmd = pb.enum("MsgType", "CMD_S2C_HouseRentConsultRefresh")
|
|
s2cData.data = assert(pb.encode("S2CHouseRentConsultRefresh", data))
|
|
end
|
|
|
|
-- 恋家房产咨询出租
|
|
function HouseRent:HouseRentConsultLease(player, c2sData, s2cData)
|
|
c2sData.data = assert(pb.decode("C2SHouseRentConsultLease", c2sData.data))
|
|
local houseId = c2sData.data.houseId
|
|
local data = {}
|
|
data.leaseInfo = {}
|
|
local houseInfo = player.gameData.houseRent.houseInfo
|
|
local cfgHouseRent = skynet.server.gameConfig:GetPlayerAllCfg(player, "HouseRent") -- 恋家房产信息
|
|
|
|
-- 检查玩家是否拥有该户型+
|
|
for k1, v1 in pairs(player.gameData.house) do
|
|
-- 找到对应的房间ID并且是购买了
|
|
if houseId == v1.id and (3 == v1.status or 4 == v1.status) then
|
|
-- 判断玩家房子是否满足出租条件
|
|
if houseInfo[houseId].leaseStatus == 1 then
|
|
local cfgHouseRent = skynet.server.gameConfig:GetPlayerAllCfg(player, "HouseRent") -- 恋家房产信息
|
|
--根据出租类型,添加房产信息到对应列表
|
|
local leaseInfo = {}
|
|
local curRentInfo = {}
|
|
if self.RentType_Short == houseInfo[houseId].rentType then
|
|
leaseInfo = player.gameData.houseRent.shortLeaseInfo
|
|
elseif self.RentType_Long == houseInfo[houseId].rentType then
|
|
leaseInfo = player.gameData.houseRent.longLeaseInfo
|
|
end
|
|
|
|
for k2, v2 in ipairs( leaseInfo ) do
|
|
if houseId == v2.houseId then
|
|
local expireTime = skynet.GetTime() + ( v2.rentTime * 3600 )
|
|
houseInfo[houseId].finishTime = expireTime
|
|
houseInfo[houseId].leaseStatus = 2 -- //房子出租状态 1- 待租房 2- 租房中 3- 待收租
|
|
v2.leaseStatus = 2
|
|
v2.remainRentTime = expireTime
|
|
curRentInfo = v2
|
|
break
|
|
end
|
|
end
|
|
|
|
data.leaseInfo = {
|
|
houseId = houseId,
|
|
rentTime =curRentInfo.rentTime,
|
|
leaseStatus = houseInfo[houseId].leaseStatus,
|
|
remainRentTime = houseInfo[houseId].finishTime,
|
|
tenantId = curRentInfo.tenantId,
|
|
rentPrice = curRentInfo.rentPrice,
|
|
rentType = houseInfo[houseId].rentType
|
|
}
|
|
end
|
|
elseif houseId == v1.id and 2 == v1.status or houseId == v1.id and 1 == v1.status then
|
|
s2cData.code = errorInfo.ErrorCode.HouseRentNoUnlock
|
|
end
|
|
end
|
|
|
|
s2cData.cmd = pb.enum("MsgType", "CMD_S2C_HouseRentConsultLease")
|
|
s2cData.data = assert(pb.encode("S2CHouseRentConsultLease", data))
|
|
end
|
|
|
|
-- 恋家房产咨询取消租赁
|
|
function HouseRent:HouseRentConsultCancelLease(player, c2sData, s2cData)
|
|
c2sData.data = assert(pb.decode("C2SHouseRentConsultCancelLease", c2sData.data))
|
|
local houseId = c2sData.data.houseId
|
|
local data = {}
|
|
local cfgHouseRent = skynet.server.gameConfig:GetPlayerAllCfg(player, "HouseRent") -- 恋家房产信息
|
|
local houseInfo = player.gameData.houseRent.houseInfo
|
|
|
|
--根据出租类型,添加房产信息到对应列表
|
|
local leaseInfo = {}
|
|
local curRentInfo = {}
|
|
if self.RentType_Short == houseInfo[houseId].rentType then
|
|
leaseInfo = player.gameData.houseRent.shortLeaseInfo
|
|
elseif self.RentType_Long == houseInfo[houseId].rentType then
|
|
leaseInfo = player.gameData.houseRent.longLeaseInfo
|
|
end
|
|
|
|
local newHouseId = 0
|
|
for k2, v2 in ipairs( leaseInfo ) do
|
|
if houseId == v2.houseId then
|
|
newHouseId = self:Refresh( player , houseInfo[ houseId ].rentType , k2 )
|
|
curRentInfo = leaseInfo[k2]
|
|
break
|
|
end
|
|
end
|
|
|
|
data.leaseInfo = {
|
|
houseId = newHouseId,
|
|
rentTime =curRentInfo.rentTime,
|
|
leaseStatus = houseInfo[ newHouseId ].leaseStatus,
|
|
remainRentTime = 0,
|
|
tenantId = curRentInfo.tenantId,
|
|
rentPrice = curRentInfo.rentPrice,
|
|
rentType = houseInfo[ newHouseId ].rentType
|
|
}
|
|
|
|
s2cData.cmd = pb.enum("MsgType", "CMD_S2C_HouseRentConsultCancelLease")
|
|
s2cData.data = assert(pb.encode("S2CHouseRentConsultCancelLease", data))
|
|
end
|
|
|
|
-- 恋家房产咨询收租
|
|
function HouseRent:HouseRentConsultRentCollection(player, c2sData, s2cData)
|
|
c2sData.data = assert(pb.decode("C2SHouseRentConsultRentCollection", c2sData.data))
|
|
local data = {}
|
|
local houseId = c2sData.data.houseId
|
|
|
|
local cfgHouseRent = skynet.server.gameConfig:GetPlayerAllCfg(player, "HouseRent") -- 恋家房产信息
|
|
local houseInfo = player.gameData.houseRent.houseInfo
|
|
|
|
if houseInfo[ houseId ].leaseStatus == 2 and skynet.GetTime() >= houseInfo[ houseId ].finishTime then
|
|
houseInfo[ houseId ].leaseStatus = 3
|
|
end
|
|
|
|
-- 判断是否满足收租条件
|
|
if houseInfo[ houseId ].leaseStatus == 3 then
|
|
--根据出租类型,添加房产信息到对应列表
|
|
local leaseInfo = {}
|
|
local curRentInfo = {}
|
|
if self.RentType_Short == houseInfo[houseId].rentType then
|
|
leaseInfo = player.gameData.houseRent.shortLeaseInfo
|
|
elseif self.RentType_Long == houseInfo[houseId].rentType then
|
|
leaseInfo = player.gameData.houseRent.longLeaseInfo
|
|
end
|
|
|
|
for k1, v1 in ipairs( leaseInfo ) do
|
|
if houseId == v1.houseId then
|
|
player:AddExpForType(19)
|
|
skynet.server.msgTips:Reduce(player, 86)
|
|
local eventId = pb.enum("EnumMoneyChangeEventID", "EventID_101")
|
|
skynet.server.achieveTask:Modify(player, 103, 1)
|
|
skynet.server.taskListEvent:Modify( player ,38, 1)
|
|
skynet.server.levelTask:Modify(player, 103, 1)
|
|
skynet.server.taskListEvent:Modify( player ,103, 1)
|
|
|
|
-- 奖励
|
|
local award = { type = dataType.GoodsType_Clovers, count = v1.rentPrice } -- 对应奖励增加对应三叶币
|
|
player:MoneyChange( pb.enum("EnumGoodsType", "Clovers"), v1.rentPrice, eventId )
|
|
|
|
self:InitLease( player , houseInfo[houseId].rentType , k1 )
|
|
|
|
if self.RentType_Long == houseInfo[houseId].rentType then --长租完成任务
|
|
skynet.server.npcTask:Modify(player, 112, 1)
|
|
skynet.server.taskListEvent:Modify( player , 112 , 1)
|
|
else
|
|
skynet.server.taskListEvent:Modify( player , 117 , 1)
|
|
end
|
|
|
|
data.award = award
|
|
data.leaseInfo = leaseInfo[ k1]
|
|
break
|
|
end
|
|
end
|
|
skynet.server.msgTips:ReduceAll( player , 86 )
|
|
end
|
|
|
|
s2cData.cmd = pb.enum("MsgType", "CMD_S2C_HouseRentConsultRentCollection")
|
|
s2cData.data = assert(pb.encode("S2CHouseRentConsultRentCollection", data))
|
|
end
|
|
|
|
--是否存在房间信息
|
|
function HouseRent:IsExistHouseInfo( player , houseId )
|
|
local houseRent = player.gameData.houseRent
|
|
if houseRent.houseInfo[ houseId ] then
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
|
|
--是否存在租赁信息信息
|
|
function HouseRent:IsExistLeaseInfo( player , houseId , leaseInfo )
|
|
for k, v in pairs( leaseInfo ) do
|
|
if houseId == v.houseId then
|
|
return true
|
|
end
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
--恋家房产咨初始化租赁
|
|
function HouseRent:InitLease( player , rentType , rentIndex )
|
|
--leaseStatus 1- 待租房 2- 租房中 3- 待收租
|
|
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
|
local cfgHouseRent = skynet.server.gameConfig:GetPlayerAllCfg(player, "HouseRent") -- 房产咨询信息
|
|
local houseRent = player.gameData.houseRent
|
|
|
|
local leaseInfo = {}
|
|
if rentType == self.RentType_Short then
|
|
leaseInfo = houseRent.shortLeaseInfo
|
|
elseif rentType == self.RentType_Long then
|
|
leaseInfo = houseRent.longLeaseInfo
|
|
end
|
|
|
|
local rentHouse = {}
|
|
|
|
--是否存在展示历史
|
|
local function IsExistShowHistory( houseId, rentType )
|
|
local showHistory = {}
|
|
if self.RentType_Short == rentType then
|
|
showHistory = houseRent.showShortHistory
|
|
elseif self.RentType_Long == rentType then
|
|
showHistory = houseRent.showLongHistory
|
|
end
|
|
|
|
for k, v in pairs( showHistory ) do
|
|
if houseId == v then
|
|
return true
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
|
|
local function GetLeaseRent( leaseStatus )
|
|
for k, v in ipairs(cfgHouseRent) do
|
|
local houseId = v.houseId
|
|
--只用待租房并且没有租赁才进行刷新
|
|
if self:IsExistHouseInfo( player , houseId ) and leaseStatus == houseRent.houseInfo[ houseId ].leaseStatus and
|
|
not self:IsExistLeaseInfo(player, houseId, leaseInfo ) and not IsExistShowHistory( houseId , rentType ) and rentType == v.rentType then
|
|
table.insert( rentHouse, v.id )
|
|
end
|
|
end
|
|
end
|
|
|
|
--先找已经收租的,如果没有,再找待收租的
|
|
GetLeaseRent( 3 )
|
|
if 0 == #rentHouse then
|
|
--如果还等于0 ,就直接清除记录
|
|
if self.RentType_Short == rentType then
|
|
houseRent.showShortHistory = {}
|
|
elseif self.RentType_Long == rentType then
|
|
houseRent.showLongHistory = {}
|
|
end
|
|
GetLeaseRent( 3 )
|
|
end
|
|
|
|
if 0 == #rentHouse then
|
|
GetLeaseRent( 1 )
|
|
end
|
|
|
|
if 0 == #rentHouse then
|
|
--如果还等于0 ,就直接清除记录
|
|
if self.RentType_Short == rentType then
|
|
houseRent.showShortHistory = {}
|
|
elseif self.RentType_Long == rentType then
|
|
houseRent.showLongHistory = {}
|
|
end
|
|
GetLeaseRent( 1 )
|
|
end
|
|
|
|
local randId = math.random(1, #rentHouse)
|
|
local cfgId = rentHouse[ randId ]
|
|
local curHouseId = cfgHouseRent[ cfgId ].houseId
|
|
local curRentType = cfgHouseRent[ cfgId ].rentType
|
|
|
|
--保存下展示历史
|
|
local showHistory = {}
|
|
if self.RentType_Short == curRentType then
|
|
showHistory = houseRent.showShortHistory
|
|
elseif self.RentType_Long == curRentType then
|
|
showHistory = houseRent.showLongHistory
|
|
end
|
|
table.insert( showHistory , curHouseId )
|
|
|
|
leaseInfo[ rentIndex ] = {}
|
|
leaseInfo[ rentIndex ].houseId = curHouseId
|
|
leaseInfo[ rentIndex ].rentTime = math.random(cfgHouseRent[ cfgId ].rentTime[1], cfgHouseRent[ cfgId ].rentTime[2])
|
|
leaseInfo[ rentIndex ].leaseStatus = 1
|
|
leaseInfo[ rentIndex ].remainRentTime = 0
|
|
leaseInfo[ rentIndex ].tenantId = math.random(cfgHouseRent[ cfgId ].randomGuest[1],cfgHouseRent[ cfgId ].randomGuest[2])
|
|
|
|
--计算收租价格
|
|
local rentPrice = 0
|
|
--豪华月卡权益判断
|
|
if skynet.server.luxuryCard:IsActivate( player ) then
|
|
rentPrice = math.ceil( math.random(cfgHouseRent[ cfgId ].rentPrice[1],cfgHouseRent[ cfgId ].rentPrice[2]) * cfgSValue.luxuryCardHouseRentTimes )
|
|
else
|
|
rentPrice = math.ceil( math.random(cfgHouseRent[ cfgId ].rentPrice[1],cfgHouseRent[ cfgId ].rentPrice[2]))
|
|
end
|
|
leaseInfo[ rentIndex ].rentPrice = rentPrice
|
|
leaseInfo[ rentIndex ].rentType = cfgHouseRent[ cfgId ].rentType
|
|
houseRent.houseInfo[ curHouseId ].leaseStatus = 1 -- //房子出租状态 1- 待租房 2- 租房中 3- 待收租
|
|
end
|
|
|
|
--恋家房产咨询刷新
|
|
function HouseRent:Refresh( player , rentType , rentIndex )
|
|
--easeStatus 1- 待租房 2- 租房中 3- 待收租
|
|
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
|
local cfgAllHouseRent = skynet.server.gameConfig:GetPlayerAllCfg(player, "HouseRent") -- 房产咨询信息
|
|
local houseRent = player.gameData.houseRent
|
|
|
|
local leaseInfo = {}
|
|
if rentType == self.RentType_Short then
|
|
leaseInfo = houseRent.shortLeaseInfo
|
|
elseif rentType == self.RentType_Long then
|
|
leaseInfo = houseRent.longLeaseInfo
|
|
end
|
|
|
|
local curHouseId = leaseInfo[ rentIndex ].houseId
|
|
local cfgHouseRent = nil
|
|
for k, v in ipairs(cfgAllHouseRent) do
|
|
if v.houseId == curHouseId then
|
|
cfgHouseRent = v
|
|
break
|
|
end
|
|
end
|
|
|
|
leaseInfo[ rentIndex ].rentTime = math.random( cfgHouseRent.rentTime[1], cfgHouseRent.rentTime[2])
|
|
leaseInfo[ rentIndex ].leaseStatus = 1
|
|
leaseInfo[ rentIndex ].remainRentTime = 0
|
|
leaseInfo[ rentIndex ].tenantId = math.random( cfgHouseRent.randomGuest[1] , cfgHouseRent.randomGuest[2])
|
|
|
|
--计算收租价格
|
|
local rentPrice = 0
|
|
--豪华月卡权益判断
|
|
if skynet.server.luxuryCard:IsActivate( player ) then
|
|
rentPrice = math.ceil( math.random( cfgHouseRent.rentPrice[1] , cfgHouseRent.rentPrice[2] ) * cfgSValue.luxuryCardHouseRentTimes )
|
|
else
|
|
rentPrice = math.ceil( math.random( cfgHouseRent.rentPrice[1] , cfgHouseRent.rentPrice[2] ) )
|
|
end
|
|
leaseInfo[ rentIndex ].rentPrice = rentPrice
|
|
houseRent.houseInfo[ curHouseId ].leaseStatus = 1 -- //房子出租状态 1- 待租房 2- 租房中 3- 待收租
|
|
return curHouseId
|
|
end
|
|
|
|
--是否当前显示
|
|
function HouseRent:IsShow( player , houseId )
|
|
local shortLeaseInfo = player.gameData.houseRent.shortLeaseInfo
|
|
local longLeaseInfo = player.gameData.houseRent.longLeaseInfo
|
|
local isShow = false
|
|
for k, v in ipairs( shortLeaseInfo ) do
|
|
if v.houseId == houseId then
|
|
isShow = true
|
|
break
|
|
end
|
|
end
|
|
|
|
for k, v in ipairs( longLeaseInfo ) do
|
|
if v.houseId == houseId then
|
|
isShow = true
|
|
break
|
|
end
|
|
end
|
|
|
|
return isShow
|
|
end
|
|
|
|
skynet.server.houseRent = HouseRent
|
|
return HouseRent
|