HomeServer/lualib-src/Server-main/AllServer/GameServer/Map/Map.lua

184 lines
5.6 KiB
Lua
Raw Permalink Normal View History

2024-11-20 15:41:09 +08:00
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:InitData( player )
--log.info('初始化地点展示data' .. skynet.server.common:TableToString(player.gameData.map))
--player.gameData.map = {}
-- if next( player.gameData.map) == nil then
for k, v in pairs( skynet.server.gameConfig.MapLoc ) 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 )
end
end
end
if not isCanEnter then
s2cData.code = errorInfo.ErrorCode.NoUnlockMap
else
local cfgCurMap = skynet.server.gameConfig:GetCurCfg("MapLoc",mapId)
data.friend = skynet.server.friend:GetFriendDetail( player , cfgCurMap.onLocNpc )
data.mapLocId = 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:GetCurCfg("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
skynet.server.map = Map
return Map