HomeServer/Server/AllServer/GameServer/Map/Map.lua
2024-11-20 15:41:37 +08:00

229 lines
6.8 KiB
Lua

local skynet = require "skynet"
local oo = require "Class"
local log = require "Log"
local pb = require "pb"
local dataType = require "DataType"
local errorInfo = require "ErrorInfo"
local Map = oo.class()
--[[
CMD_C2S_MapShow = 1143; //地图展示
CMD_S2C_MapShow = 1144;
//地图信息
message PBMapInfo
{
int32 id = 1; //地点ID
status = 2; //状态 1-未解锁 2-已解锁 3-暂未开放 4-店主外出
}
//地图展示
message C2SMapShow
{
}
//地图展示
message S2CMapShow
{
repeated PBMapInfo mapInfo = 1; --地图信息
}
]]
Map.ShopStatus_Lock = 1 --未解锁
Map.ShopStatus_UnLock = 2 --已解锁
Map.ShopStatus_Location = 3 --当前位置
--初始化地点信息
function Map:LoginInitData( player )
local cfgMapLoc = skynet.server.gameConfig:GetPlayerAllCfg( player , "MapLoc")
for k, v in pairs( cfgMapLoc ) do
if not self:IsExistMapID( player , v.id ) then
if 1 == v.id then --我的当是解锁了的
table.insert( player.gameData.map , { id = v.id , status = self.ShopStatus_Location , progress = 0 })
else
table.insert( player.gameData.map , { id = v.id , status = self.ShopStatus_Lock , progress = 0 })
end
end
end
--每次登录后,我的家是当前位置
for k, v in pairs( player.gameData.map ) do
if 1 == v.id then
v.status = self.ShopStatus_Location
else
if self.ShopStatus_Location == v.status then
v.status = self.ShopStatus_UnLock
end
end
end
end
--外出地点展示
function Map:ShowLoc( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SMapShowLoc", c2sData.data ))
local data ={}
data.pBMapLocInfo = {}
for k, v in pairs( player.gameData.map ) do
table.insert( data.pBMapLocInfo , v )
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_MapShowLoc")
s2cData.data = assert(pb.encode("S2CMapShowLoc", data))
end
--进入外出地点
function Map:EntryLoc( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SMapLocEnter", c2sData.data ))
local data ={}
local mapId = c2sData.data.mapLocId
if not mapId then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
else
local isCanEnter = false
for k, v in pairs( player.gameData.map ) do
--清除当前位置,为解锁状态
if self.ShopStatus_Location == v.status then
v.status = self.ShopStatus_UnLock
end
if mapId == v.id and v.status == self.ShopStatus_UnLock then
isCanEnter = true
v.status = self.ShopStatus_Location
if 3 == mapId then
skynet.server.levelTask:Modify( player , 26 , 1 )
skynet.server.taskListEvent:Modify( player , 26 , 1 )
end
end
end
if not isCanEnter then
s2cData.code = errorInfo.ErrorCode.NoUnlockMap
else
local cfgCurMap = skynet.server.gameConfig:GetPlayerCurCfg( player , "MapLoc",mapId)
data.friend = skynet.server.friend:GetFriendDetail( player , cfgCurMap.onLocNpc )
data.mapLocId = mapId
--添加访问地图
self:AddVisitMap( player , mapId )
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_MapLocEnter")
s2cData.data = assert(pb.encode("S2CMapLocEnter", data))
end
--NPC详情
function Map:ShowNPCDetail( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SMapShowNPCDetail", c2sData.data ))
local data ={}
local npcId = c2sData.data.npcId
local npcInfo = player.gameData.friend[ npcId ]
if not npcId or not npcInfo then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
else
data.favorabilityLevel = npcInfo.favorabilityLevel
data.favorabilityValue = npcInfo.favorabilityValue
data.giftGoods= npcInfo.giftGoods
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_MapShowNPCDetail")
s2cData.data = assert(pb.encode("S2CMapShowNPCDetail", data))
end
--是否存在地图ID
function Map:IsExistMapID( player , mapId)
for k, v in pairs( player.gameData.map ) do
if mapId == v.id then
return true
end
end
return false
end
--修改地图状态
function Map:ChangeStatus( player , mapId , status )
for k, v in pairs( player.gameData.map ) do
if mapId == v.id then
v.status = status
break
end
end
end
--获取地图某个店是解锁
function Map:IsUnlock( player , mapId )
for k, v in pairs( player.gameData.map ) do
if mapId == v.id and v.status >= self.ShopStatus_UnLock then
return true
end
end
return false
end
--查看该玩家所在地点
function Map:PresentMapLoc(player)
for k, v in pairs(player.gameData.map) do
if v.status==3 then
return v.id
end
end
end
--检查地点解锁
function Map:CheckUnlcokLoc( player )
for k, v in pairs( player.gameData.map ) do
if self.ShopStatus_Lock == v.status then
local cfgOneMapLoc = skynet.server.gameConfig:GetPlayerCurCfg( player , "MapLoc" , v.id )
local condition = skynet.server.common:Split( cfgOneMapLoc.unlockCondition , "_")
--达到指定等级就解锁
if 1 == tonumber(condition[1]) and player.gameData.level == tonumber(condition[2]) then
v.status = self.ShopStatus_UnLock
end
end
end
end
--获取解锁条件
function Map:GetUnlockCondition( player , mapId )
local cfgOneMapLoc = skynet.server.gameConfig:GetPlayerCurCfg( player , "MapLoc" , mapId )
if cfgOneMapLoc then
local condition = skynet.server.common:Split( cfgOneMapLoc.unlockCondition , "_")
condition[1] = tonumber(condition[1])
condition[2] = tonumber(condition[2])
if condition then
return condition
end
end
return nil
end
--是否访问过地图列表
function Map:IsVisitMap( player , mapId )
if nil == mapId then
return false
end
local visitMapList = player.gameData.visitMapList
local isExist = false
for k, v in pairs( visitMapList ) do
if mapId == v then
return true
end
end
return false
end
--添加访问过地图
function Map:AddVisitMap( player , mapId )
if nil == mapId then
return
end
local visitMapList = player.gameData.visitMapList
if not self:IsVisitMap( player , mapId ) then
table.insert( visitMapList , mapId )
skynet.server.friend:CheckNewMsg( player )
end
end
skynet.server.map = Map
return Map